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 s, it's need to create an inheritor from the ModelData::ModelElementVoidVisitor and override the part processing method void operator() (const ModelData::Part& thePart)
. For this purpose, the PartProcessor
class was created. In operator()
method a ModelData::Part is examined for the presence of B-Rep Geometry and Topology B-Rep Geometry and ModelData::Solid or ModelData::Shell shapes in it.
void operator() (const ModelData::Part& thePart) override
{
auto aPartName = thePart.Name().IsEmpty() ? "noname" : thePart.Name();
size_t aBodyNumber = 0;
auto aBodies = thePart.GetBodies();
for (const auto& aBody : aBodies) {
ModelData::ShapeIterator aShapeIt (aBody);
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;
}
ProcessSolid
and ProcessShell
methods are used to run sheet metal unfolder for given entities.
void ProcessSolid (const ModelData::Solid& theSolid, const UTF16String& , size_t )
{
auto aFlatPattern = myUnfolder.Perform (theSolid);
PrintFlatPatternInfo (aFlatPattern);
}
void ProcessShell (const ModelData::Shell& theShell, const UTF16String& , size_t )
{
auto aFlatPattern = myUnfolder.Perform (theShell);
PrintFlatPatternInfo (aFlatPattern);
}
To traverse only unique parts of the imported model, the ModelData::ModelElementUniqueVisitor class is used.
PartProcessor aPartProcessor ();
ModelData::ModelElementUniqueVisitor aVisitor (aPartProcessor);
aModel.Accept (aVisitor);
Method PrintFlatPattern
is used to explore and print flat pattern parameters.
void PrintFlatPattern (const SheetMetal_FlatPattern& theFlatPattern)
{
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