Hide menu
Loading...
Searching...
No Matches
MTK Converter Example

Demonstrates how to generate view and manufacturing information files for the imported model, that can be easily acessed through web interface for downstream analysis.

Overview

The example demonstrates how to create a console application to convert your STEP model to compressed *.mtkweb format, generate useful manufacturing information about it with chosen data processor into *.json file). The model will be imported by ModelData::ModelReader . Then the choosen by input parameter certain part processor class will analyze a model. The list of possible analysis can be found in table below.

Process tools description
Process Tools Supported representation Description
CNC Machining Machining_FeatureRecognizer BRep Recognize features such as machining faces, holes, etc.
DFMMachining_Analyzer

Analyse possible CNC Machining milling – drilling / milling / turning design issues.

Sheet Metal SheetMetal_FeatureRecognizer Recognize features such as bends, cutouts, holes, etc.
SheetMetal_Unfolder Unfold sheet metal models.
DFMSheetMetal_Analyzer

Analyse possible Sheet Metal design issues.

Finally, the converted *.mtkweb model will be saved to ${export_dir}/model.mtkweb and all computed process data to ${export_dir}/process_data.json

Running the example

Application needs 6 following input arguments to run:

Usage: MTKConverter -i <import_file> -p <process> -e <export_folder> where:
<import_file> -- filename of a model, that will be imported
<process> -- what analysis should be performed on model
<export_folder> -- export folder name where an output will be saved


Possible process parameter values
Parameter value Process Description
machining_milling CNC Machining Milling feature recognition and dfm analysis
machining_turning Lathe+Milling feature recognition and dfm analysis
sheet_metal Sheet Metal Feature recognition, unfolding and dfm analysis

Example:

MTKConverter -i C:\\models\\test.step -p machining_milling -e C:\\models\\test

Implementation

The ModelData::ModelReader is used to import the models.

MTKConverter_ReturnCode Import (const UTF16String& theFilePath, ModelData::Model& theModel)
{
std::cout << "Importing " << theFilePath << "..." << std::flush;
ModelData::ModelReader aReader;
if (!aReader.Read (theFilePath, theModel)) {
std::cerr << std::endl << "ERROR: Failed to import " << theFilePath << ". Exiting" << std::endl;
return MTKConverter_RC_ImportError;
}
return MTKConverter_RC_OK;
}

Then Process method was created for a model analysis with chosen by process_param_table value processor. The ModelData::Model::AssignUuids() method is used to assign persistent id's to unique parts of the model. These id's will be used to connect parts with process data saved in json file. The processor is a MTKConverter_PartProcessor class, that can analyse all parts of the imported model. The ProcessType method can parse a process_param_table parameter value to choose MTKConverter_PartProcessor class, which will run relative analyzer tools. The ModelData::ModelElementUniqueVisitor
is used to traverse and retrieve only unique parts of the imported model.

MTKConverter_ReturnCode Process (const UTF16String& theProcess,
ModelData::Model& theModel,
MTKConverter_Report& theReport,
ModelData::Model& theProcessModel)
{
std::cout << "Processing " << theProcess << "..." << std::flush;
theModel.AssignUuids();
auto ApplyProcessorToModel = [&theModel, &theReport] (MTKConverter_PartProcessor& theProcessor) {
ModelData::ModelElementUniqueVisitor aVisitor (theProcessor);
theModel.Accept (aVisitor);
for (const auto& i : theProcessor.myData) {
theReport.AddData (i);
}
};
auto aProcessType = ProcessType (theProcess);
switch (aProcessType) {
case MTKConverter_PT_MachiningMilling:
{
MTKConverter_MachiningProcessor aProcessor (Machining_OT_Milling);
ApplyProcessorToModel (aProcessor);
break;
}
case MTKConverter_PT_MachiningTurning:
{
MTKConverter_MachiningProcessor aProcessor (Machining_OT_LatheMilling);
ApplyProcessorToModel (aProcessor);
break;
}
case MTKConverter_PT_Molding:
{
MTKConverter_MoldingProcessor aProcessor;
ApplyProcessorToModel (aProcessor);
break;
}
case MTKConverter_PT_SheetMetal:
{
theProcessModel.SetName (theModel.Name() + "_unfolded");
MTKConverter_SheetMetalProcessor aProcessor (theProcessModel);
ApplyProcessorToModel (aProcessor);
break;
}
case MTKConverter_PT_Undefined:
default : return MTKConverter_RC_InvalidArgument;
}
return MTKConverter_RC_OK;
}
@ Machining_OT_Milling
Milling operation type.
Definition Machining_OperationType.hxx:29
@ Machining_OT_LatheMilling
Lathe + Milling operation type.
Definition Machining_OperationType.hxx:30

Before we dive into how the model is processed with MTKConverter_PartProcessor class after the ApplyProcessorToModel was ran, the inheritance hierarchy should be observed.

  • First, the MTKConverter_PartProcessor class, which inherits from ModelData::ModelElementVoidVisitor , was created with the overridden void operator()(const ModelData::Part& thePart) method to traverse the model and collect each ModelData::Part . Then, ModelData::Solid and ModelData::Shell are extracted using ModelData::ModelElementVoidVisitor . The ProcessSolid, ProcessShell is developed to analyze the certain shapes of ModelData::Part . Additionally, some analyses require post-processing, which is handled by the PostPartProcess method. These four methods will be described in detail later.

    void MTKConverter_PartProcessor::operator() (const ModelData::Part& thePart)
    {
    const auto& aBodies = thePart.Bodies();
    for (const auto& aBody : aBodies) {
    ModelData::ShapeIterator aShapeIt (aBody);
    while (aShapeIt.HasNext()) {
    const auto& aShape = aShapeIt.Next();
    if (aShape.Type() == ModelData::ShapeType::Solid) {
    ProcessSolid (thePart, ModelData::Solid::Cast (aShape));
    } else if (aShape.Type() == ModelData::ShapeType::Shell) {
    ProcessShell (thePart, ModelData::Shell::Cast (aShape));
    }
    }
    }
    PostPartProcess (thePart);
    }

    MTKConverter_VoidPartProcessor was inherited from MTKConverter_PartProcessor at first with empty defined methods for processing, because not all processor can analyse Shell, Mesh and requires postprocessing. Then for each process different class, inherited from MTKConverter_VoidPartProcessor, was developed. The table below demonstrates what classes were created for each process and which methods were overriden.

    Processor classes
    Process Class ProcessSolid ProcessShell ProcessMesh PostPartProcess
    CNC Machining MTKConverter_MachiningProcessor + - - -
    Sheet Metal MTKConverter_SheetMetalProcessor + - +

  • Let's take the MTKConverter_SheetMetalProcessor as example, because it supports almost all methods of MTKConverter_PartProcessor. It uses SheetMetal_Analyzer for shape processing. In constructor both supported tools (SheetMetal_FeatureRecognizer, SheetMetal_Unfolder) were added to SheetMetal_Analyzer. Analyzer classes can be used to run all tools together, however it should be mentioned, that such tools allow separated calls. The example of such separate call for SheetMetal_Unfolder can be found here.

    MTKConverter_SheetMetalProcessor::MTKConverter_SheetMetalProcessor (cadex::ModelData::Model& theUnfoldedModel) :
    myUnfoldedModel (theUnfoldedModel)
    {
    myAnalyzer.AddTool (SheetMetal_FeatureRecognizer());
    myAnalyzer.AddTool (SheetMetal_Unfolder());
    }
    Provides MTK data model.
    Definition Model.hxx:40

    The Perform method of SheetMetal_Analyzer will be called to run analysis with added tools for Solid and Shell respectively.

    void MTKConverter_SheetMetalProcessor::ProcessSolid (
    const cadex::ModelData::Part& thePart, const cadex::ModelData::Solid& theSolid)
    {
    auto anSMData = myAnalyzer.Perform (theSolid);
    UpdateProcessData (anSMData, thePart);
    }
    void MTKConverter_SheetMetalProcessor::ProcessShell (
    const cadex::ModelData::Part& thePart, const cadex::ModelData::Shell& theShell)
    {
    auto anSMData = myAnalyzer.Perform (theShell);
    UpdateProcessData (anSMData, thePart);
    }
    Defines a leaf node in the scene graph hiearchy.
    Definition Part.hxx:34
    Defines a connected set of faces.
    Definition Shell.hxx:32
    Defines a topological solid.
    Definition Solid.hxx:32

    After the analysis was done the PostPartProcess method will be run.

    void MTKConverter_SheetMetalProcessor::PostPartProcess (const ModelData::Part& thePart)
    {
    if (!myCurrentUnfoldedBody) {
    return;
    }
    ModelData::Part anUnfoldedPart (thePart.Name());
    anUnfoldedPart.SetUuid (thePart.Uuid());
    anUnfoldedPart.AddBody (myCurrentUnfoldedBody);
    myUnfoldedModel.AddRoot (anUnfoldedPart);
    myCurrentUnfoldedBody = ModelData::SheetBody();
    }

    Finally, after the processing, the model will be converted to *.mtkweb format.

    MTKConverter_ReturnCode Export (const UTF16String& theFolderPath,
    const ModelData::Model& theModel,
    const MTKConverter_Report& theReport,
    const ModelData::Model& theProcessModel)
    {
    std::cout << "Exporting " << theFolderPath << "..." << std::flush;
    UTF16String aModelPath = theFolderPath + "/" + theModel.Name() + ".mtkweb" + "/scenegraph.mtkweb";
    if (!theModel.Save (aModelPath, ModelData::Model::FileFormatType::MTKWEB)) {
    std::cerr << std::endl << "ERROR: Failed to export " << aModelPath << ". Exiting" << std::endl;
    return MTKConverter_RC_ExportError;
    }
    return MTKConverter_RC_OK;
    }

    An unfolded representation, if the SheetMetal process was performed also will be converted to *.mtkweb format and saved.

    if (!theProcessModel.IsEmpty()) {
    UTF16String aProcessModelPath = theFolderPath + "/" + theProcessModel.Name() + ".mtkweb" + "/scenegraph.mtkweb";
    if (!theProcessModel.Save (aProcessModelPath, ModelData::Model::FileFormatType::MTKWEB)) {
    std::cerr << std::endl << "ERROR: Failed to export " << aProcessModelPath << ". Exiting" << std::endl;
    return MTKConverter_RC_ExportError;
    }
    }


    A result of processing will be saved to a json file with the custom MTKConverter_Report class. However, other premade solutions can be used too.

    UTF16String aJsonPath = theFolderPath + "/process_data.json";
    if (!theReport.WriteToJSON (aJsonPath)) {
    std::cerr << std::endl << "ERROR: Failed to create JSON file " << aJsonPath << ". Exiting" << std::endl;
    return MTKConverter_RC_ExportError;
    }
    return MTKConverter_RC_OK;
    }

    Most of MTKConverter_Report methods were designed to generate a json file itself, but there are several distinct methods:

    • WriteFeatures run sorts and generates a text representation of features.
    • SortFeatures sorts and groups features to make an output compact. The MTKBase_FeatureComparator was used for comparison of features by types and parameters. An order of features is preserved with a map.
    • GetShapesId gets the id of a Shape for a BRepRepresentation. A relative Shape of converted model can be found with the Id.
    • Methods like AddShapeFeature / AddDrillingIssue / etc. make a text representation of features with their relative parameters.

      All features have the same to text export pattern, therefore only the example for Machining_Countersink was present.

      else if (aFeature.IsOfType<Machining_Countersink>()) {
      const auto& aCountersink = static_cast<const Machining_Countersink&> (aFeature);
      auto aFeatureData = WriteFeatureDataToString (
      "Radius", "mm", aCountersink.Radius(),
      "Depth", "mm", aCountersink.Depth(),
      "Axis", "", aCountersink.Axis().Axis(),
      theShapeIdVector);
      theManager.AddGroupData ("Countersink(s)", "(55, 125, 34)", aFeatureData, theCount);
      }

Example output

Below are outputs for different processes.

Machining Milling

The ./examples/models/Fresamento_CAM1_v3.stp model can be used to run machining_milling process.

Output
Original Model

{
"version": "1",
"parts": [
{
"partId": "e31092b7-fc4e-4c02-8021-c0bbbcd21bfa",
"process": "CNC Machining Milling",
"featureRecognition": {
"name": "Feature Recognition",
"totalFeatureCount": "51",
"featureGroups": [
{
"name": "Concave Fillet Edge Milling Face(s)",
"color": "(129, 127, 38)",
"totalGroupFeatureCount": "14",
"subGroupCount": "1",
"subGroups": [
{
"parametersCount": "1",
"parameters": [
{
"name": "Radius",
"units": "mm",
"value": "5.00"
}
],
"featureCount": "14",
"features": [
{
"shapeIDCount": "1",
"shapeIDs": [
{
"id": "555"
}
]
},
...
{
"shapeIDCount": "1",
"shapeIDs": [
{
"id": "669"
}
]
}
]
}
]
},
...
"dfm": {
"name": "Design for Manufacturing",
"totalFeatureCount": "23",
"featureGroups": [
{
"name": "Deep Hole(s)",
"color": "(0, 35, 245)",
"totalGroupFeatureCount": "4",
"subGroupCount": "1",
"subGroups": [
{
"parametersCount": "2",
"parameters": [
{
"name": "Expected Maximum Depth",
"units": "mm",
"value": "29.84"
},
{
"name": "Actual Depth",
"units": "mm",
"value": "31.32"
}
],
"featureCount": "4",
"features": [
{
"shapeIDCount": "2",
"shapeIDs": [
{
"id": "435"
},
{
"id": "423"
}
]
},
{
"shapeIDCount": "2",
"shapeIDs": [
{
"id": "450"
},
{
"id": "438"
}
]
},
{
"shapeIDCount": "2",
"shapeIDs": [
{
"id": "465"
},
{
"id": "453"
}
]
},
{
"shapeIDCount": "2",
"shapeIDs": [
{
"id": "480"
},
{
"id": "468"
}
]
}
]
}
]
},
...

Machining Turning

The ./examples/models/senthi.step model can be used to run machining_turning process. The processing result has the same structure as for a Machining milling, thus it was omitted.

Output
Original Model

Sheet Metal

The ./examples/models/Part2.stp is suitable to run SheetMetal process. The first part of a json file is the same as in Machining milling and turning, but it also contains the infromation about unfolding analysis.

Output
Original Model
Unfolded Model

...
"featureRecognitionUnfolded": {
"name": "Feature Recognition",
"parametersCount": "3",
"parameters": [
{
"name": "Length",
"units": "mm",
"value": "220.71"
},
{
"name": "Width",
"units": "mm",
"value": "167.84"
},
{
"name": "Thickness",
"units": "mm",
"value": "1.00"
}
]
},
"dfmUnfolded": {
"name": "Design for Manufacturing",
"totalFeatureCount": "1",
"featureGroups": [
{
"name": "Non Standard Sheet Size(s)",
"color": "(0, 0, 0)",
"totalGroupFeatureCount": "1",
"subGroupCount": "1",
"subGroups": [
{
"parametersCount": "2",
"parameters": [
{
"name": "Nearest Standard Size (LxW)",
"units": "mm",
"value": "300.00 x 200.00"
},
{
"name": "Actual Size (LxW)",
"units": "mm",
"value": "220.71 x 167.84"
}
],
"featureCount": "1",
"features": [
{
"shapeIDCount": "0",
"shapeIDs": []
}
]
}
]
}
]
}
}
]
}

Files