Refer to the mtk_mesh_representation_example_page.
import java.util.*;
public class mesh {
static {
try {
System.loadLibrary("CadExMTK");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String[] args) {
String aKey = MTKLicenseKey.Value();
if (!LicenseManager.Activate(aKey)) {
System.out.println("Failed to activate Manufacturing Toolkit license.");
System.exit(1);
}
if (args.length != 1) {
System.out.println("Usage: " + " <input_file>, where:");
System.out.println(" <input_file> is a name of the file to be read");
System.exit(1);
}
String aSource = args[0];
Model aModel = new Model();
ModelReader aReader = new ModelReader();
if (!aReader.Read(new UTF16String(aSource), aModel)) {
System.out.println("Failed to read the file " + aSource);
System.exit(1);
}
PartMeshVisitor aVisitor = new PartMeshVisitor();
aModel.Accept(aVisitor);
System.exit(0);
}
static class PartMeshVisitor extends ModelElementVoidVisitor {
@Override
public void Apply(Part thePart) {
System.out.println("Part = \"" + thePart.Name() + "\"");
BodyList aBodies = thePart.Bodies();
if (!aBodies.isEmpty()) {
ExploreMeshBodies(aBodies);
}
}
private void ExploreMeshBodies(BodyList theBodies) {
for (int i = 0; i < theBodies.size(); ++i) {
Body aBody = theBodies.get(i);
if (MeshBody.CompareType(aBody)) {
MeshBody aMeshBody = MeshBody.Cast(aBody);
System.out.println("MeshBody " + i);
MeshShapeList aMeshShapes = aMeshBody.Shapes();
for (int j = 0; j < aMeshShapes.size(); ++j) {
MeshShape aMeshShape = aMeshShapes.get(j);
System.out.print("MeshShape " + j);
PrintMeshShapeInfo(aMeshShape);
}
}
}
}
private void PrintMeshShapeInfo(MeshShape theMeshShape) {
if (IndexedTriangleSet.CompareType(theMeshShape)) {
IndexedTriangleSet aITS = IndexedTriangleSet.Cast(theMeshShape);
System.out.println(" IndexedTriangleSet type.");
DumpTriangleSet(aITS);
} else if (PolylineSet.CompareType(theMeshShape)) {
PolylineSet aPLS = PolylineSet.Cast(theMeshShape);
System.out.println(" PolyLineSet type");
DumpPolylineSet(aPLS);
} else if (Polyline2dSet.CompareType(theMeshShape)) {
Polyline2dSet aPL2dS = Polyline2dSet.Cast(theMeshShape);
System.out.println(" PolyLine2dSet type");
DumpPolyline2dSet(aPL2dS);
} else if (PointSet.CompareType(theMeshShape)) {
PointSet aPPS = PointSet.Cast(theMeshShape);
System.out.println(" PolyPointSet type");
DumpPointSet(aPPS);
} else {
System.out.println(" Undefined type");
}
}
private void DumpPointSet(PointSet thePS) {
int aNumberOfPoints = (int) thePS.NumberOfPoints();
System.out.println("PointSet: " + aNumberOfPoints + " points");
for (int i = 0; i < aNumberOfPoints; ++i) {
Point aP = thePS.Point(i);
System.out.println("Point " + i + ": (" + aP.X() + ", " + aP.Y() + ", " + aP.Z() + ")");
}
}
private void DumpPolylineSet(PolylineSet thePLS) {
int aNumberOfPolylines = (int) thePLS.NumberOfPolylines();
System.out.println("PolylineSet: " + aNumberOfPolylines + " polylines");
for (int i = 0; i < aNumberOfPolylines; ++i) {
System.out.println("Polyline " + i + ":");
System.out.println(" Node coordinates:");
Polyline aPoly = thePLS.Polyline(i);
int n = (int) aPoly.NumberOfPoints();
for (int j = 0; j < n; ++j) {
Point aP = aPoly.Point(j);
System.out.println("(" + aP.X() + ", " + aP.Y() + ", " + aP.Z() + ")");
}
}
}
private void DumpPolyline2dSet(Polyline2dSet thePLS) {
int aNumberOfPolylines2d = (int) thePLS.NumberOfPolylines();
System.out.println("Polyline2dSet: " + aNumberOfPolylines2d + " polylines");
for (int i = 0; i < aNumberOfPolylines2d; ++i) {
System.out.println("Polyline2d " + i + ":");
System.out.println(" Node coordinates:");
Polyline2d aPoly = thePLS.Polyline(i);
int n = (int) aPoly.NumberOfPoints();
for (int j = 0; j < n; ++j) {
Point2d aP = aPoly.Point(j);
System.out.println("(" + aP.X() + ", " + aP.Y() + ")");
}
}
}
private void DumpTriangleSet(IndexedTriangleSet theITS) {
int aNumberOfTriangles = (int) theITS.NumberOfTriangles();
System.out.println("IndexedTriangleSet: " + aNumberOfTriangles + " triangles:");
for (int i = 0; i < aNumberOfTriangles; ++i) {
System.out.println("Triangle " + i + ":");
for (int j = 0; j < 3; ++j) {
int aVI = theITS.TriangleVertexIndex(i, j);
Point aV = theITS.TriangleVertex(i, j);
System.out.println(" Node " + j + ": Vertex " + aVI + " (" + aV.X() + ", " + aV.Y() + ", " + aV.Z() + ")");
if (theITS.HasNormals()) {
System.out.println(
" Normal: (" + aN.
X() +
", " + aN.
Y() +
", " + aN.
Z() +
")");
}
}
}
}
}
}
Defines a 3D vector.
Definition Vector.cs:17
Definition ArrayDouble2.cs:12
Contains classes, types, enums, and functions related to geometric entities.
Definition Axis1d.cs:12
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
Definition AngleUnit.cs:12
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition BaseObject.cs:12