PolygonReduction Manual
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.
A PolygonReduction object can be created with the usual tools, see Entity Creation and Destruction Manual (Classic) .
A PolygonReduction object has to be initialized. It will pre-process the given PolygonObject .
The PolygonReductionData argument has these members:
opolyreduxgen.h
.
// set polygon reduction settings BaseContainer settings; 设置。 SetBool ( POLYREDUXOBJECT_PRESERVE_3D_BOUNDARY , true ); 设置。 SetBool ( POLYREDUXOBJECT_PRESERVE_UV_BOUNDARY , true ); PolygonReductionData data; data. _op = polyObject; data. _doc = doc; data. _settings = settings; data. _thread = nullptr ; // synchronous pre-processing and reduction
// pre process if (polyReduction-> PreProcess (data) == false ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION , "The function exited unexpectedly during data pre-processing." _s);
// reduce polyReduction-> SetReductionStrengthLevel (0.75);
// update polyObject-> 消息 ( MSG_UPDATE );
若 PolygonReductionData::_thread member is set the pre-process is running asynchronously in a background thread.
// pre process if (polyReduction-> PreProcess (data) == false ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION , "The function exited unexpectedly during data pre-processing." _s); Int32 count = 0;
// wait until preprocessing has finished while (polyReduction-> IsPreprocessing ()) { ApplicationOutput ( "Pre Process..." ); GeSleep (100); count++; if (count > 100) { ApplicationOutput ( "Timeout!" ); polyReduction-> StopPreprocessing (); return maxon::UnknownError( MAXON_SOURCE_LOCATION ); } }
After the pre-process the PolygonReduction object is ready:
The linked PolygonObject can be reduced by defining the overall reduction strength or the target triangle, vertex or edge count.
The desired triangle count is defined with:
// return gracefully if the specified triangle count is smaller than the minimum number of triangles after reduction pre-processing if (triTargetCount < polyReduction->GetMinTriangleLevel()) return maxon::OK ;
// return gracefully if the specified triangle count is greater than the initial number of triangles if (triTargetCount > polyReduction-> GetMaxTriangleLevel ()) return maxon::OK ; polyReduction-> SetTriangleLevel (triTargetCount); const Int32 realTriangleResult = polyReduction-> GetTriangleLevel (); ApplicationOutput ( "Triangle Result: @" , realTriangleResult);
The vertex count is defined with:
// return gracefully if the specified vertex count is smaller than the minimum number of vertexes after reduction pre-processing if (vertexTargetCount < polyReduction->GetMinVertexLevel()) return maxon::OK ;
// return gracefully if the specified vertex count is greater than the initial number of vertexes if (vertexTargetCount > polyReduction-> GetMaxVertexLevel ()) return maxon::OK ; polyReduction-> SetVertexLevel (vertexTargetCount); const Int32 realVertexResult = polyReduction-> GetVertexLevel (); ApplicationOutput ( "Vertex Result: @" , realVertexResult);
Finally the edge count can be defined:
// return gracefully if the specified edges count is smaller than the remained number of edges after reduction pre-processing if (edgeTargetCount > polyReduction-> GetMaxRemainingEdgesLevel ()) return maxon::OK ; polyReduction-> SetRemainingEdgesLevel (edgeTargetCount); const Int32 realEdgeResult = polyReduction-> GetRemainingEdgesLevel (); ApplicationOutput ( "Edge Result: @" , realEdgeResult);