Demonstrates how to perform recognition of sheet metal features on a 3D model and print information about found features and their parameters in a console.
Overview
In this example demonstrates how to perform recognition of sheet metal features on a 3D model using sheet metal feature recognition tool (SheetMetal_FeatureRecognizer). For this purpose, used a console application that imports a model, traverses through unique ModelData::Part , creates and runs SheetMetal_FeatureRecognizer, groups and prints information about found features and their parameters into console. Sheet metal feature recognition will be performed for each unique ModelData::Part , but only for the scope of accepted geometries.
Application needs 1 input argument to run:
Usage: sheet_metal_feature_recognizer <input_file>, where:
<input_file> is a name of the file to be read
For more information about feature recognition visit Overview page.
Implementation
PartProcessor
class is inherited from ShapeProcessor
and overrides ProcessSolid
and ProcessShell
methods that are used to run SheetMetal_FeatureRecognizer on given shapes. Then PrintFeatures
method is used to print information about found features and their parameters in a console.
Visit Model Explore Helper Implementation page for more information about base ShapeProcessor
class implementation.
class PartProcessor : public ShapeProcessor
{
public:
void ProcessSolid (const ModelData::Solid& theSolid) override
{
auto aFeatureList = myRecognizer.Perform (theSolid);
PrintFeatures (aFeatureList);
}
void ProcessShell (const ModelData::Shell& theShell) override
{
auto aFeatureList = myRecognizer.Perform (theShell);
PrintFeatures (aFeatureList);
}
private:
SheetMetal_FeatureRecognizer myRecognizer;
};
To traverse only unique parts of the imported model, the ModelData::ModelElementUniqueVisitor class is used.
PartProcessor aPartProcessor;
ModelData::ModelElementUniqueVisitor aVisitor (aPartProcessor);
aModel.Accept (aVisitor);
After performing feature recognition, the object of FeatureGroupManager
class is used to group and sort found sheet metal features. For this purpose, there is a traverse through all found features and add each of them to FeatureGroupManager
with a specified name.
std::function<void(MTKBase_FeatureList)> GroupByParameters = [&] (const MTKBase_FeatureList& theFeatures) -> void {
for (size_t i = 0; i < theFeatures.Size(); ++i) {
const auto& aFeature = theFeatures[i];
if (aFeature.IsOfType<SheetMetal_Bead>()) {
aManager.AddFeature ("Bead(s)", "Bead(s)", true, aFeature);
} else if (aFeature.IsOfType<SheetMetal_Cutout>()) {
aManager.AddFeature ("Cutout(s)", "Cutout(s)", true, aFeature);
} else if (aFeature.IsOfType<SheetMetal_Louver>()) {
aManager.AddFeature ("Louver(s)", "", true, aFeature);
} else if (aFeature.IsOfType<SheetMetal_Bridge>()) {
aManager.AddFeature ("Bridge(s)", "Bridge(s)", true, aFeature);
} else if (aFeature.IsOfType<SheetMetal_Hole>()) {
const auto& aHole = static_cast<const SheetMetal_Hole&> (aFeature);
aManager.AddFeature (HoleName (aHole), "Hole(s)", true, aFeature);
} else if (aFeature.IsOfType<SheetMetal_Bend>()) {
const auto& aBend = static_cast<const SheetMetal_Bend&> (aFeature);
aManager.AddFeature (BendName (aBend), "Bend(s)", true, aFeature);
} else if (aFeature.IsOfType<SheetMetal_Notch>()) {
const auto& aNotch = static_cast<const SheetMetal_Notch&> (aFeature);
aManager.AddFeature (NotchName (aNotch), "Notch(es)", true, aFeature);
} else if (aFeature.IsOfType<SheetMetal_Tab>()) {
aManager.AddFeature ("Tab(s)", "Tab(s)", true, aFeature);
} else if (aFeature.IsOfType<SheetMetal_CompoundBend>()) {
const auto& aCompoundBend = static_cast<const SheetMetal_CompoundBend&> (aFeature);
GroupByParameters (aCompoundBend.FeatureList());
}
}
};
GroupByParameters (theFeatureList);
After adding all found features to FeatureGroupManager
, a Print
method of the manager is used to print information about found features and their parameters in a console. PrintFeatureParameters
is created to explore and print MTK feature parameters. It uses as an input parameter of Print
method.
auto PrintFeatureParameters = [] (const MTKBase_Feature& theFeature)
{
if (theFeature.IsOfType<SheetMetal_Bead>()) {
const auto& aBead = static_cast<const SheetMetal_Bead&> (theFeature);
FeatureGroupManager::PrintFeatureParameter ("depth", aBead.Depth(), "mm");
} else if (theFeature.IsOfType<SheetMetal_Cutout>()) {
const auto& aCutout = static_cast<const SheetMetal_Cutout&> (theFeature);
FeatureGroupManager::PrintFeatureParameter ("perimeter", aCutout.Perimeter(), "mm");
} else if (theFeature.IsOfType<SheetMetal_Louver>()) {
const auto& aLouver = static_cast<const SheetMetal_Louver&> (theFeature);
FeatureGroupManager::PrintFeatureParameter ("depth", aLouver.Depth(), "mm");
} else if (theFeature.IsOfType<SheetMetal_Bridge>()) {
const auto& aBridge = static_cast<const SheetMetal_Bridge&> (theFeature);
FeatureGroupManager::PrintFeatureParameter ("length", aBridge.Length(), "mm");
FeatureGroupManager::PrintFeatureParameter ("depth", aBridge.Depth(), "mm");
} else if (theFeature.IsOfType<SheetMetal_Hole>()) {
const auto& aHole = static_cast<const SheetMetal_Hole&> (theFeature);
FeatureGroupManager::PrintFeatureParameter ("radius", aHole.Radius(), "mm");
FeatureGroupManager::PrintFeatureParameter ("depth", aHole.Depth(), "mm");
FeatureGroupManager::PrintFeatureParameter ("axis", aHole.Axis().Axis(), "");
} else if (theFeature.IsOfType<SheetMetal_Bend>()) {
const auto& aBend = static_cast<const SheetMetal_Bend&> (theFeature);
FeatureGroupManager::PrintFeatureParameter ("radius", aBend.Radius(), "mm");
FeatureGroupManager::PrintFeatureParameter ("angle", ToDegrees (aBend.Angle()), "deg");
FeatureGroupManager::PrintFeatureParameter ("length", aBend.Length(), "mm");
FeatureGroupManager::PrintFeatureParameter ("width", aBend.Width(), "mm");
} else if (theFeature.IsOfType<SheetMetal_Notch>()) {
const auto& aNotch = static_cast<const SheetMetal_Notch&> (theFeature);
FeatureGroupManager::PrintFeatureParameter ("length", aNotch.Length(), "mm");
FeatureGroupManager::PrintFeatureParameter ("width", aNotch.Width(), "mm");
if (aNotch.IsOfType<SheetMetal_StraightNotch>()) {
const auto& aStraightNotch = static_cast<const SheetMetal_StraightNotch&> (aNotch);
FeatureGroupManager::PrintFeatureParameter ("corner fillet radius", aStraightNotch.CornerFilletRadius(), "mm");
} else if (aNotch.IsOfType<SheetMetal_VNotch>()) {
const auto& aVNotch = static_cast<const SheetMetal_VNotch&> (aNotch);
FeatureGroupManager::PrintFeatureParameter ("angle", ToDegrees (aVNotch.Angle()), "deg");
}
} else if (theFeature.IsOfType<SheetMetal_Tab>()) {
const auto& aTab = static_cast<const SheetMetal_Tab&> (theFeature);
FeatureGroupManager::PrintFeatureParameter ("length", aTab.Length(), "mm");
FeatureGroupManager::PrintFeatureParameter ("width", aTab.Width(), "mm");
}
};
aManager.Print ("features", PrintFeatureParameters);
Visit Feature Group Helper Implementation page for more information about FeatureGroupManager
class implementation.
Example output
Below is the example output for model from ./examples/models/Power_box_Chasis.stp
.
The model | Example output |
| Model: Power_box_Chasis.STEP
Part #0 ["power box sheetmetal"] - solid #0 has:
Bend(s): 9
1 Bend(s) with
radius: 0.7366 mm
angle: 90 deg
length: 1.15705 mm
width: 20 mm
1 Bend(s) with
radius: 0.7366 mm
angle: 90 deg
length: 1.15705 mm
width: 53 mm
1 Bend(s) with
radius: 0.7366 mm
angle: 90 deg
length: 1.15705 mm
width: 59 mm
2 Bend(s) with
radius: 0.7366 mm
angle: 90 deg
length: 1.15705 mm
width: 60 mm
1 Bend(s) with
radius: 0.7366 mm
angle: 90 deg
length: 1.15705 mm
width: 108 mm
2 Bend(s) with
radius: 0.7366 mm
angle: 90 deg
length: 1.15705 mm
width: 137.327 mm
1 Bend(s) with
radius: 0.7366 mm
angle: 90 deg
length: 1.15705 mm
width: 148 mm
Hole(s): 12
4 Hole(s) with
radius: 1 mm
depth: 0.6 mm
axis: (1.00, 0.00, 0.00)
4 Hole(s) with
radius: 1.5 mm
depth: 0.6 mm
axis: (-0.00, 1.00, -0.00)
4 Hole(s) with
radius: 1.5 mm
depth: 0.6 mm
axis: (1.00, 0.00, 0.00)
Complex Hole(s): 3
3 Hole(s) with
radius: 1.5 mm
depth: 2.89072 mm
axis: (-0.00, -1.00, -0.00)
Bead(s): 1
1 Bead(s) with
depth: 5 mm
Bridge(s): 4
4 Bridge(s) with
length: 13.3989 mm
depth: 4 mm
Cutout(s): 46
8 Cutout(s) with
perimeter: 25.8192 mm
4 Cutout(s) with
perimeter: 36.9425 mm
8 Cutout(s) with
perimeter: 37.1155 mm
16 Cutout(s) with
perimeter: 49.4248 mm
8 Cutout(s) with
perimeter: 52.4844 mm
1 Cutout(s) with
perimeter: 94 mm
1 Cutout(s) with
perimeter: 114 mm
Notch(es): 2
2 Notch(es) with
length: 2.75744 mm
width: 7.61577 mm
Total features: 77
|
Files