Demonstrates how to perform unfolding of 3D model.
Overview
In this example demonstrates how to perform unfolding of 3D model using sheet metal unfolder tool (SheetMetal_Unfolder). For this purpose, used a console application that imports a model, collects unique ModelData::Part s, traverses through unique ModelData::Part s, creates and runs SheetMetal_Unfolder, prints information about flat pattern parameters into console.
Unfolding will be performed for each unique ModelData::Part , but only for the scope of accepted geometries.
Application needs one input arguments to run:
Usage: sheet_metal_unfolder <input_file>, where:
<input_file> is a name of the file to be read
For more information about unfolding visit Sheet Metal Unfolding page.
Implementation
To explore the model and process ModelData::Part you need to derive a class from the ModelData::ModelElementVoidVisitor and override the part processing method void operator() (const ModelData::Part& thePart)
. In this example we use the PartProcessor
class for this purpose. The operator()
method is implemented to check each ModelData::Part for the presence of B-Rep Geometry and ModelData::Solid or ModelData::Shell shapes in it.
{
size_t aBodyNumber = 0;
auto aBodies = thePart.GetBodies();
for (const auto& aBody : aBodies) {
while (aShapeIt.HasNext()) {
const auto& aShape = aShapeIt.Next();
if (aShape.Type() == ModelData::ShapeType::Solid) {
cout << "Part #" << myPartIndex << " [\"" << aPartName << "\"] - solid #" << std::to_string (aBodyNumber) << " has:" << endl;
ProcessSolid (ModelData::Solid::Cast (aShape), aPartName, aBodyNumber);
} else if (aShape.Type() == ModelData::ShapeType::Shell) {
cout << "Part #" << myPartIndex << " [\"" << aPartName << "\"] - shell #" << std::to_string (aBodyNumber) << " has:" << endl;
ProcessShell (ModelData::Shell::Cast (aShape), aPartName, aBodyNumber);
}
}
++aBodyNumber;
}
++myPartIndex;
}
UTF16String Name() const
Returns a name.
Definition ModelElement.cxx:55
Defines a leaf node in the scene graph hiearchy.
Definition Part.hxx:34
Iterates over subshapes in a shape.
Definition ShapeIterator.hxx:32
bool IsEmpty() const
Returns true if the string is empty.
Definition UTF16String.cxx:336
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition LicenseManager_LicenseError.hxx:30
ProcessSolid
and ProcessShell
methods are used to run sheet metal unfolder for given entities.
{
auto aFlatPattern = myUnfolder.Perform (theSolid);
PrintFlatPatternInfo (aFlatPattern);
}
{
auto aFlatPattern = myUnfolder.Perform (theShell);
PrintFlatPatternInfo (aFlatPattern);
}
Defines a connected set of faces.
Definition Shell.hxx:32
Defines a topological solid.
Definition Solid.hxx:32
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition UTF16String.hxx:30
To traverse only unique parts of the imported model, the ModelData::ModelElementUniqueVisitor class is used.
PartProcessor aPartProcessor ();
aModel.Accept (aVisitor);
Defines a visitor that visits each unique element only once.
Definition ModelElementVisitor.hxx:87
Method PrintFlatPattern
is used to explore and print flat pattern parameters.
{
cout << " Flat Pattern with:" << endl;
cout <<
" length: " << theFlatPattern.
Length() <<
" mm" << endl;
cout <<
" width: " << theFlatPattern.
Width() <<
" mm" << endl;
cout <<
" thickness: " << theFlatPattern.
Thickness() <<
" mm" << endl;
cout <<
" perimeter: " << theFlatPattern.
Perimeter() <<
" mm" << endl;
}
Example output
Below is the example output for model from ./examples/models/Part2.stp
.
Model: Part2
Part #0 ["Part2"] - solid #0 has:
Flat Pattern with:
length: 220.712 mm
width: 167.838 mm
thickness: 1 mm
perimeter: 1121.37 mm
|
Original model
|
Unfolded view
|
Files