About

The PolygonReduction class allows to reduce the polygon count of a given PolygonObject while retaining its overall shape. The class gives access to the functionality used within the "Polygon Reduction" generator. It is defined in the lib_polygonreduction.h header file.

Allocation/Deallocation

A PolygonReduction object can be created with the usual tools, see Entity Creation and Destruction Manual.

// This example creates a new PolygonReduction object.
if (!polyReduction)
return false;

Init

A PolygonReduction object has to be initialized. It will pre-process the given PolygonObject.

The PolygonReductionData argument has these members:

Note
In order to be able to abort the reduction operation and to retain the original mesh, it is advised to operate on a copy of the original PolygonObject.
// This example configures the given PolygonReduction object and
// reduces the given PolygonObject to 25%.
BaseContainer settings;
data._op = polyObject;
data._doc = doc;
data._settings = settings;
data._thread = nullptr; // synchronous pre-processing and reduction
// pre process
if (!polyReduction->PreProcess(data))
return false;
// reduce
polyReduction->SetReductionStrengthLevel(0.75);
// update
polyObject->Message(MSG_UPDATE);

If the PolygonReductionData::_thread member is set the pre-process is running asynchronously in a background thread.

Note
This asynchronous mode may be used e.g. in a generator object.
// This example initializes the given PolygonReduction object asynchronously.
data._op = polyObject;
data._doc = doc;
data._settings = settings;
data._thread = GeGetDummyThread(); // asynchronous pre-processing
// pre process
if (!polyReduction->PreProcess(data))
return false;
Int32 count = 0;
// wait until preprocessing has finished
while (polyReduction->IsPreprocessing())
{
GePrint("Pre Process...");
GeSleep(100);
count++;
if (count > 100)
{
GePrint("Timeout!");
polyReduction->StopPreprocessing();
return false;
}
}

After the pre-process the PolygonReduction object is ready:

Reduce

The linked PolygonObject can be reduced by defining the overall reduction strength or the target triangle, vertex or edge count.

The triangle count is defined with:

// This example reduces the PolygonObject to the given triangle count.
if (triTargetCount < polyReduction->GetMinTriangleLevel())
return false;
if (triTargetCount > polyReduction->GetMaxTriangleLevel())
return false;
polyReduction->SetTriangleLevel(triTargetCount);
const Int32 realTriangleResult = polyReduction->GetTriangleLevel();
GePrint("Triangle Result: " + String::IntToString(realTriangleResult));

The vertex count is defined with:

// This example reduces the PolygonObject to the given vertex count.
if (vertexTargetCount < polyReduction->GetMinVertexLevel())
return false;
if (vertexTargetCount > polyReduction->GetMaxVertexLevel())
return false;
polyReduction->SetVertexLevel(vertexTargetCount);
const Int32 realVertexResult = polyReduction->GetVertexLevel();
GePrint("Vertex Result: " + String::IntToString(realVertexResult));

Finally the edge count can be defined:

// This example reduces the given PolygonObject to the given edge count.
if (edgeTargetCount > polyReduction->GetMaxRemainingEdgesLevel())
return false;
polyReduction->SetRemainingEdgesLevel(edgeTargetCount);
const Int32 realEdgeResult = polyReduction->GetRemainingEdgesLevel();
GePrint("Edge Result: " + String::IntToString(realEdgeResult));

Further Reading