Hide menu
Loading...
Searching...
No Matches
CNC Machining Feature Recognizer Example

Demonstrates how to perform recognition of machining 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 machining features on a 3D model using machining feature recognition tool (Machining_FeatureRecognizer). For this purpose, used a console application that imports a model, traverses through unique ModelData::Part , creates and runs Machining_FeatureRecognizer, groups and prints information about found features and their parameters into console. Machining feature recognition will be performed for each unique ModelData::Part , but only for the scope of accepted geometries.


Application needs 2 input arguments to run:

Usage: machining_feature_recognizer <input_file> <operation>, where:
<input_file> is a name of the file to be read
<operation> is a name of desired machining operation
Supported operations:
milling: CNC Machining Milling feature recognition
turning: CNC Machining Lathe+Milling feature recognition


For more information about feature recognition visit CNC Machining page.

Implementation

PartProcessor class is inherited from SolidProcessor and overrides ProcessSolid method that are used to run Machining_FeatureRecognizer on given shape. The Machining_FeatureRecognizerParameters.SetOperation() method of the tool parameters is used to set the type of operation (Milling or LatheMilling). The operation type will be taking into account during recognition process and the recognition result will be different depending on it. 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 SolidProcessor class implementation.

using namespace cadex;
class PartProcessor : public SolidProcessor
{
public:
PartProcessor (Machining_OperationType theOperation) : myOperation (theOperation)
{}
void ProcessSolid (const ModelData::Solid& theSolid) override
{
aRecognizer.Parameters().SetOperation (myOperation);
auto aFeatureList = aRecognizer.Perform (theSolid);
PrintFeatures (aFeatureList);
}
private:
Machining_OperationType myOperation = Machining_OT_Undefined;
};
Provides an interface to recognizing machining features tool.
Definition Machining_FeatureRecognizer.hxx:45
MTKBase_FeatureList Perform(const ModelData::Solid &theSolid, const cadex::ProgressStatus &theProgressStatus=cadex::ProgressStatus())
Runs features recognition process.
Definition Machining_FeatureRecognizer.cxx:301
const Machining_FeatureRecognizerParameters & Parameters() const
Returns parameters.
Definition Machining_FeatureRecognizer.cxx:320
void SetOperation(Machining_OperationType theOperation)
Definition Machining_FeatureRecognizerParameters.cxx:221
Defines a topological solid.
Definition Solid.hxx:32
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition LicenseManager_LicenseError.hxx:30
Machining_OperationType
Defines an operation type in machining.
Definition Machining_OperationType.hxx:28

To traverse only unique parts of the imported model, the ModelData::ModelElementUniqueVisitor class is used.

PartProcessor aPartProcessor;
ModelData::ModelElementUniqueVisitor aVisitor (aPartProcessor);
aModel.Accept (aVisitor);
Defines a visitor that visits each unique element only once.
Definition ModelElementVisitor.hxx:87

After performing feature recognition, the object of FeatureGroupManager class is used to group and sort found machining features. For this purpose, there is a traverse through all found features and add each of them to FeatureGroupManager with a specified name.

for (size_t i = 0; i < theFeatureList.Size(); i++) {
const auto& aFeature = theFeatureList[i];
if (aFeature.IsOfType<Machining_TurningFace>()) {
const auto& aTurningFace = static_cast<const Machining_TurningFace&> (aFeature);
aManager.AddFeature (FaceTypeToString (aTurningFace.Type()), "Turning Face(s)", true, aFeature);
} else if (aFeature.IsOfType<Machining_Face>()) {
const auto& aFace = static_cast<const Machining_Face&> (aFeature);
aManager.AddFeature (FaceTypeToString (aFace.Type()), "", false, aFeature);
} else if ...
}
Describes a face produced by a specified machining operation.
Definition Machining_Face.hxx:38
Describes a face with radius produced by a specified machining operation. Cutting material from workp...
Definition Machining_TurningFace.hxx:29

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 feature parameters. It uses as an input parameter of Print method.

auto PrintFeatureParameters = [] (const MTKBase_Feature& theFeature)
{
if (theFeature.IsOfType<Machining_TurningFace>()) {
const auto& aTurningFace = static_cast<const Machining_TurningFace&> (theFeature);
FeatureGroupManager::PrintFeatureParameter ("radius", aTurningFace.Radius(), "mm");
} else if (theFeature.IsOfType<Machining_Face>()) {
//no parameters
} else if ...
};
aManager.Print ("features", PrintFeatureParameters);
Describes a base class of MTK based features.
Definition MTKBase_Feature.hxx:33

Visit Feature Group Helper Implementation page for more information about FeatureGroupManager class implementation.

Example output

The first is an example output for model from ./examples/models/Fresamento_CAM1_v3.stp and operation set to Milling. and the second one is an output for model from ./examples/models/senthi.step and operation set to Lathe+Milling.

Model Example output
Model: Fresamento_CAM1_v3

Part #0 ["Fresamento_CAM1"] - solid #0 has:
    Concave Fillet Edge Milling Face(s): 14
        14 Turning Face(s) with
          radius: 5 mm
    Convex Profile Edge Milling Face(s): 7
        4 Turning Face(s) with
          radius: 10 mm
        3 Turning Face(s) with
          radius: 15 mm
    ...

    Total features: 44
Model: senthi

Part #0 ["drawing no 1"] - solid #0 has:
    Turn Diameter Face(s): 7
        1 Turning Face(s) with
          radius: 50 mm
        1 Turning Face(s) with
          radius: 75 mm
        1 Turning Face(s) with
          radius: 80 mm
        1 Turning Face(s) with
          radius: 86 mm
        1 Turning Face(s) with
          radius: 90 mm
        1 Turning Face(s) with
          radius: 96.4288 mm
        1 Turning Face(s) with
          radius: 155 mm
    ...

    Total features: 17

Files