Refer to the mtk_mesh_representation_example_page.
using cadex.Collections;
using System;
namespace mesh
{
class Program
{
static int Main(string[] args)
{
string aKey = MTKLicenseKey.Value();
if (!LicenseManager.Activate(aKey))
{
Console.WriteLine("Failed to activate Manufacturing Toolkit license.");
return 1;
}
if (args.Length != 1)
{
Console.WriteLine("Usage: " +
$"{System.Reflection.Assembly.GetExecutingAssembly().Location} <input_file>, where:");
Console.WriteLine($" <input_file> is a name of the file to be read");
Console.WriteLine($"");
return 1;
}
string aSource = args[0];
var aModel = new Model();
var aReader = new ModelReader();
if (!aReader.Read(new UTF16String(aSource), aModel))
{
Console.WriteLine("Failed to read the file " + aSource);
return 1;
}
PartMeshVisitor aVisitor = new PartMeshVisitor();
aModel.Accept(aVisitor);
return 0;
}
class PartMeshVisitor : ModelElementVoidVisitor
{
public override void Apply(Part thePart)
{
Console.WriteLine($"Part = \"{thePart.Name()}\"");
var aBodies = thePart.Bodies();
if (!aBodies.IsEmpty)
{
ExploreMeshBodies(aBodies);
}
}
private void ExploreMeshBodies(BodyList theBodies)
{
for (int i = 0; i < theBodies.Count; ++i)
{
var aBody = theBodies[i];
if (MeshBody.CompareType(aBody))
{
var aMeshBody = MeshBody.Cast(aBody);
Console.WriteLine($"MeshBody {i}");
var aMeshShapes = aMeshBody.Shapes();
for (int j = 0; j < aMeshShapes.Count; ++j)
{
var aMeshShape = aMeshShapes[j];
Console.Write($"MeshShape {j}");
PrintMeshShapeInfo(aMeshShape);
}
}
}
}
private void PrintMeshShapeInfo(MeshShape theMeshShape)
{
if (IndexedTriangleSet.CompareType(theMeshShape))
{
var aITS = IndexedTriangleSet.Cast(theMeshShape);
Console.WriteLine(" IndexedTriangleSet type.");
DumpTriangleSet(aITS);
}
else if (PolylineSet.CompareType(theMeshShape)) {
var aPLS = PolylineSet.Cast(theMeshShape);
Console.WriteLine(" PolyLineSet type");
DumpPolylineSet(aPLS);
}
else if (Polyline2dSet.CompareType(theMeshShape)) {
var aPL2dS = Polyline2dSet.Cast(theMeshShape);
Console.WriteLine(" PolyLine2dSet type");
DumpPolyline2dSet(aPL2dS);
}
else if (PointSet.CompareType(theMeshShape)) {
var aPPS = PointSet.Cast(theMeshShape);
Console.WriteLine(" PolyPointSet type");
DumpPointSet(aPPS);
}
else
{
Console.WriteLine(" Undefined type");
}
}
private void DumpPointSet(PointSet thePS)
{
uint aNumberOfPoints = thePS.NumberOfPoints();
Console.WriteLine($"PointSet: {aNumberOfPoints} points");
for (uint i = 0; i < aNumberOfPoints; ++i)
{
var aP = thePS.Point(i);
Console.WriteLine($"Point {i}: ({aP.X()}, {aP.Y()}, {aP.Z()})");
}
}
private void DumpPolylineSet(PolylineSet thePLS)
{
uint aNumberOfPolylines = thePLS.NumberOfPolylines();
Console.WriteLine($"PolylineSet: {aNumberOfPolylines} polylines");
for (uint i = 0; i < aNumberOfPolylines; ++i)
{
Console.WriteLine($"Polyline {i}:");
Console.WriteLine(" Node coordinates:");
var aPoly = thePLS.Polyline(i);
for (uint j = 0; j < aPoly.NumberOfPoints(); ++j)
{
var aP = aPoly.Point(j);
Console.WriteLine($"({aP.X()}, {aP.Y()}, {aP.Z()})");
}
}
}
private void DumpPolyline2dSet(Polyline2dSet thePLS)
{
uint aNumberOfPolylines2d = thePLS.NumberOfPolylines();
Console.WriteLine($"Polyline2dSet: {aNumberOfPolylines2d} polylines");
for (uint i = 0; i < aNumberOfPolylines2d; ++i)
{
Console.WriteLine($"Polyline2d {i}:");
Console.WriteLine(" Node coordinates:");
var aPoly = thePLS.Polyline(i);
for (uint j = 0; j < aPoly.NumberOfPoints(); ++j)
{
var aP = aPoly.Point(j);
Console.WriteLine($"({aP.X()}, {aP.Y()})");
}
}
}
private void DumpTriangleSet(IndexedTriangleSet theITS)
{
int aNumberOfTriangles = (int)theITS.NumberOfTriangles();
Console.WriteLine($"IndexedTriangleSet: {aNumberOfTriangles} triangles:");
for (uint i = 0; i < aNumberOfTriangles; ++i)
{
Console.WriteLine($"Triangle {i}:");
for (uint j = 0; j < 3; ++j)
{
int aVI = theITS.TriangleVertexIndex(i, j);
var aV = theITS.TriangleVertex(i, j);
Console.WriteLine($" Node {j}: Vertex {aVI} ({aV.X()}, {aV.Y()}, {aV.Z()})");
if (theITS.HasNormals())
{
var aN = theITS.TriangleVertexNormal(i, j);
Console.WriteLine($" Normal: ({aN.X()}, {aN.Y()}, {aN.Z()})");
}
}
}
}
}
}
}
Contains classes, types, enums, and functions related to geometric entities.
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.