Refer to the mtk_mesh_representation_example_page.
#include <cadex/LicenseManager_Activate.h>
#include <cadex/ModelAlgo/MeshGenerator.hxx>
#include <cadex/ModelData/IndexedTriangleSet.hxx>
#include <cadex/ModelData/MeshBody.hxx>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/ModelReader.hxx>
#include <cadex/ModelData/ModelReaderParameters.hxx>
#include <cadex/ModelData/Part.hxx>
#include <cadex/ModelData/PointSet.hxx>
#include <cadex/ModelData/Polyline2dSet.hxx>
#include <cadex/ModelData/PolylineSet.hxx>
#include <cadex/ModelData/ShapeIterator.hxx>
#include <cadex/ModelData/ModelElementIterator.hxx>
#include <iostream>
#include "../../mtk_license.cxx"
using namespace std;
{
cout << "PointSet: " << aNumberOfPoints << " points" << endl;
for (size_t i = 0; i < aNumberOfPoints; ++i) {
cout << "Point " << i << ":";
const auto& aP = thePS.
Point (i);
cout << "(" << aP.X() << ", " << aP.Y() << ", " << aP.Z() << ")" << endl;
}
}
{
cout << "PolyineSet: " << aNumberOfPolylines << " polylines" << endl;
for (size_t i = 0; i < aNumberOfPolylines; ++i) {
cout << "Polyline " << i << ":" << endl;
cout << " Node coordinates:" << endl;
for (
size_t j = 0; j < thePLS.
Polyline (i).NumberOfPoints(); ++j) {
const auto& aP = thePLS.
Polyline (i).Point (j);
cout << "(" << aP.X() << ", " << aP.Y() << ", " << aP.Z() << ")" << endl;
}
}
}
{
cout << "Polyine2dSet: " << aNumberOfPolylines2d << " polylines" << endl;
for (size_t i = 0; i < aNumberOfPolylines2d; ++i) {
cout << "Polyline2d " << i << ":" << endl;
cout << " Node coordinates:" << endl;
for (
size_t j = 0; j < thePLS.
Polyline (i).NumberOfPoints(); ++j) {
const auto& aP = thePLS.
Polyline (i).Point (j);
cout << "(" << aP.X() << ", " << aP.Y() << ")" << endl;
}
}
}
{
cout << "IndexedTriangleSet: " << aNumberOfTriangles << " triangles:" << endl;
for (size_t i = 0; i < aNumberOfTriangles; ++i) {
cout << "Triangle " << i << ":" << endl;
for (size_t j = 0; j < 3; ++j) {
cout << " Node " << j << ": ";
cout << "Vertex " << aVI << " (" << aV.X() << ", " << aV.Y() << ", " << aV.Z() << ")" << endl;
cout << "Normal: (" << aN.X() << ", " << aN.Y() << ", " << aN.Z() << ")" << endl;
}
}
}
}
{
if (ModelData::IndexedTriangleSet::CompareType (theMeshShape)) {
cout << " IndexedTriangleSet type." << endl;
DumpTriangleSet (anITS);
} else if (ModelData::PolylineSet::CompareType (theMeshShape)) {
cout << " PolyLineSet type" << endl;
DumpPolylineSet (aPLS);
} else if (ModelData::Polyline2dSet::CompareType (theMeshShape)) {
cout << " PolyLine2dSet type" << endl;
DumpPolyline2dSet (aPL2dS);
} else if (ModelData::PointSet::CompareType (theMeshShape)) {
cout << " PolyPointSet type" << endl;
DumpPointSet (aPPS);
} else {
cout << " Undefined type" << endl;
}
}
static void ExploreMeshBodies (const std::vector<ModelData::Body>& theBodies)
{
for (size_t i = 0; i < theBodies.size(); ++i) {
const auto& aBody = theBodies[i];
if (ModelData::MeshBody::CompareType (aBody)) {
cout << "MeshBody " << i << endl;
const auto& aMeshShapes = aMeshBody.
Shapes();
for (size_t j = 0; j < aMeshShapes.size(); j++) {
const auto& aMeshShape = aMeshShapes[j];
cout << "MeshShape " << j;
PrintMeshShapeInfo (aMeshShape);
}
}
}
}
{
protected:
{
cout <<
"Part = \"" << thePart.
Name() <<
"\"" << endl;
const auto& aBodies = thePart.
Bodies();
if (!aBodies.empty()) {
ExploreMeshBodies (aBodies);
}
}
};
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];
if (!aReader.
Read (aSource, aModel)) {
cerr << "Failed to read the file " << aSource << endl;
return 1;
}
PartMeshVisitor aVisitor;
return 0;
}
Defines a polygonal shape consisting of triangles.
Definition IndexedTriangleSet.cs:76
cadex.Geom.Point TriangleVertex(uint theTriangleIndex, uint theVertexSlot)
Returns a vertex of a triangle.
Definition IndexedTriangleSet.cs:188
cadex.Geom.Vector TriangleVertexNormal(uint theTriangleIndex, uint theVertexSlot)
Returns a normal at vertex in a triangle.
Definition IndexedTriangleSet.cs:213
int TriangleVertexIndex(uint theTriangleIndex, uint theVertexSlot)
Returns a vertex index in a triangle.
Definition IndexedTriangleSet.cs:202
uint NumberOfTriangles()
Returns a number of triangles.
Definition IndexedTriangleSet.cs:245
bool HasNormals()
Returns true if the triangle set has explicitly defined normals.
Definition IndexedTriangleSet.cs:163
Defines a body that represents a polygonal mesh (faceted or tessellated).
Definition MeshBody.cs:19
Base class for all polygonal geometry containers.
Definition MeshShape.cs:19
cadex.UTF16String Name()
Returns a name.
Definition ModelElement.cs:67
Element visitor with empty implementation.
Definition ModelElementVoidVisitor.cs:20
Provides MTK data model.
Definition Model.cs:30
void Accept(cadex.ModelData.ModelElementVisitor theVisitor)
Accepts a visitor.
Definition Model.cs:179
Reads supported formats, see Import section.
Definition ModelReader.cs:17
bool Read(cadex.UTF16String theFilePath, cadex.ModelData.Model theModel)
Reads the file at the specified path into the specified model.
Definition ModelReader.cs:86
Defines parameters of the ModelReader.
Definition ModelReaderParameters.cs:19
Defines a leaf node in the scene graph hierarchy.
Definition Part.cs:23
Describes drawing elements composed of 2D points.
Definition ModelData/PointSet.cs:22
uint NumberOfPoints()
Definition ModelData/PointSet.cs:93
cadex.Geom.Point Point(uint theIndex)
Definition ModelData/PointSet.cs:85
Defines a polygonal shape consisting of polylines.
Definition Polyline2dSet.cs:17
cadex.Geom.Polyline2d Polyline(uint theIndex)
Returns the polyline at position theIndex in polyline set.
Definition Polyline2dSet.cs:76
uint NumberOfPolylines()
Returns a number of polylines in polyline set.
Definition Polyline2dSet.cs:86
Defines a polygonal shape consisting of polylines.
Definition PolylineSet.cs:17
uint NumberOfPolylines()
Returns a number of polylines in polyline set.
Definition PolylineSet.cs:86
cadex.Geom.Polyline Polyline(uint theIndex)
Returns the polyline at position theIndex in polyline set.
Definition PolylineSet.cs:76
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition BaseObject.cs:12