#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <cadex/LicenseManager_Activate.h>
#include <cadex/ModelAlgo/MeshGenerator.hxx>
#include <cadex/ModelData/Body.hxx>
#include <cadex/ModelData/Face.hxx>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/ModelReader.hxx>
#include <cadex/ModelData/Part.hxx>
#include <cadex/ModelData/ShapeIterator.hxx>
#include <cmath>
#include <iostream>
#include "../../mtk_license.cxx"
using namespace std;
class FirstFaceGetter : public ModelData::ModelElementVoidVisitor
{
public:
void operator() (const ModelData::Part& thePart) override
{
if (myFace.IsNull()) {
ExploreBRep (thePart.Bodies());
}
}
const ModelData::Face& FirstFace()
{
return myFace;
};
private:
void ExploreBRep (const std::vector<ModelData::Body>& theBodies)
{
for (const auto& aBody : theBodies) {
ModelData::ShapeIterator aFaceIt (aBody, ModelData::ShapeType::Face);
if (aFaceIt.HasNext()) {
const auto& aFirstShape = aFaceIt.Next();
const auto& aFirstFace = ModelData::Face::Cast (aFirstShape);
myFace = aFirstFace;
break;
}
}
};
ModelData::Face myFace;
};
void PrintFaceTriangulationInfo (const ModelData::Face& theFace)
{
ModelData::IndexedTriangleSet anITS = theFace.Triangulation();
cout << "Face triangulation contains " << anITS.NumberOfTriangles() << " triangles." << endl;
const size_t aNumberOfTrianglesToPrint = std::min (size_t (4), anITS.NumberOfTriangles());
for (size_t i = 0; i < aNumberOfTrianglesToPrint; ++i) {
cout << "Triangle index " << i << " with vertices: " << endl;
for (size_t j = 0; j < 3; ++j) {
auto aVertexIndex = anITS.TriangleVertexIndex (i, j);
cout << " Vertex index " << aVertexIndex << " with coords (";
auto aPoint = anITS.TriangleVertex (i, j);
cout << "X: " << aPoint.X() << ", ";
cout << "Y: " << aPoint.Y() << ", ";
cout << "Z: " << aPoint.Z() << ")" << endl;
}
}
}
int main (int argc, char* argv[])
{
auto aKey = MTKLicenseKey::Value();
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate Manufacturing Toolkit license." << endl;
return 1;
}
if (argc != 2) {
cerr << "Usage: " << argv[0] << " <input_file>, where:" << endl;
cerr << " <input_file> is a name of the file to be read" << endl;
return 1;
}
const char* aSource = argv[1];
ModelData::Model aModel;
ModelData::ModelReader aReader;
if (!aReader.Read (aSource, aModel)) {
cerr << "Failed to read the file " << aSource << endl;
return 1;
}
ModelAlgo::MeshGeneratorParameters aParam;
aParam.SetAngularDeflection (M_PI * 10 / 180);
aParam.SetChordalDeflection (0.003);
ModelAlgo::MeshGenerator aMesher (aParam);
aMesher.Generate (aModel);
FirstFaceGetter aVisitor;
aModel.Accept (aVisitor);
ModelData::Face aFace = aVisitor.FirstFace();
PrintFaceTriangulationInfo (aFace);
return 0;
}
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.