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) {
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) {
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;
}
const PointType & Point(size_t theIndex) const
Returns the point at position theIndex in polyline.
Definition Polyline2d.cxx:83
const PointType & Point(size_t theIndex) const
Returns the point at position theIndex in polyline.
Definition Polyline.cxx:83
Defines a polygonal shape consisting of triangles.
Definition IndexedTriangleSet.hxx:33
bool HasNormals() const
Returns true if the triangle set has explicitly defined normals.
Definition IndexedTriangleSet.cxx:213
size_t NumberOfTriangles() const
Returns a number of triangles.
Definition IndexedTriangleSet.cxx:326
const VertexType & TriangleVertex(size_t theTriangleIndex, size_t theVertexSlot) const
Returns a vertex of a triangle.
Definition IndexedTriangleSet.cxx:241
const NormalType & TriangleVertexNormal(size_t theTriangleIndex, size_t theVertexSlot) const
Returns a normal at vertex in a triangle.
Definition IndexedTriangleSet.cxx:273
int TriangleVertexIndex(size_t theTriangleIndex, size_t theVertexSlot) const
Returns a vertex index in a triangle.
Definition IndexedTriangleSet.cxx:254
Defines a body that represents a polygonal mesh (faceted or tessellated) of .
Definition MeshBody.hxx:32
Base class for all polygonal geometry containers.
Definition MeshShape.hxx:29
UTF16String Name() const
Returns a name.
Definition ModelElement.cxx:55
Element visitor with empty implementation.
Definition ModelElementVisitor.hxx:64
Provides MTK data model.
Definition Model.hxx:40
void Accept(ModelElementVisitor &theVisitor) const
Accepts a visitor.
Definition Model.cxx:274
Reads supported formats, see Import section.
Definition ModelReader.hxx:33
bool Read(const UTF16String &theFilePath, ModelData::Model &theModel)
Reads the file at the specified path into the specified model.
Definition ModelReader.cxx:266
Defines parameters of the ModelReader.
Definition ModelReaderParameters.hxx:29
Defines a leaf node in the scene graph hiearchy.
Definition Part.hxx:34
Defines a polygonal shape consisting of individual points.
Definition PointSet.hxx:32
size_t NumberOfPoints() const
Returns a number of points in point set.
Definition PointSet.cxx:67
const Geom::Point & Point(size_t theIndex) const
Returns the point at position theIndex in point set.
Definition PointSet.cxx:61
Defines a polygonal shape consisting of polylines.
Definition Polyline2dSet.hxx:32
const Geom::Polyline2d & Polyline(size_t theIndex) const
Returns the polyline at position theIndex in polyline set.
Definition Polyline2dSet.cxx:64
size_t NumberOfPolylines() const
Returns a number of polylines in polyline set.
Definition Polyline2dSet.cxx:70
Defines a polygonal shape consisting of polylines.
Definition PolylineSet.hxx:32
size_t NumberOfPolylines() const
Returns a number of polylines in polyline set.
Definition PolylineSet.cxx:72
const Geom::Polyline & Polyline(size_t theIndex) const
Returns the polyline at position theIndex in polyline set.
Definition PolylineSet.cxx:66
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition LicenseManager_LicenseError.hxx:30