import cadex.Collections.*;
public class mesh_generation {
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 PrintFaceTriangulationInfo(Face theFace) {
IndexedTriangleSet anITS = theFace.Triangulation();
System.out.println("Face triangulation contains " + anITS.NumberOfTriangles() + " triangles.");
long aNumberOfTrianglesToPrint = Math.min(4, anITS.NumberOfTriangles());
for (long i = 0; i < aNumberOfTrianglesToPrint; ++i) {
System.out.println("Triangle index " + i + " with vertices: ");
for (long j = 0; j < 3; ++j) {
int aVertexIndex = anITS.TriangleVertexIndex(i, j);
System.out.print(" Vertex index " + aVertexIndex + " with coords (");
Point aPoint = anITS.TriangleVertex(i, j);
System.out.print("X: " + aPoint.X() + ", ");
System.out.print("Y: " + aPoint.Y() + ", ");
System.out.println("Z: " + aPoint.Z() + ")");
}
}
}
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");
System.exit(1);
}
MeshGeneratorParameters aParam = new MeshGeneratorParameters();
aParam.SetAngularDeflection(Math.PI * 10 / 180);
aParam.SetChordalDeflection(0.003);
MeshGenerator aMesher = new MeshGenerator(aParam);
aMesher.Generate(aModel);
FirstFaceGetter aVisitor = new FirstFaceGetter();
aModel.Accept(aVisitor);
Face aFace = aVisitor.FirstFace();
PrintFaceTriangulationInfo(aFace);
}
}
class FirstFaceGetter extends ModelElementVoidVisitor {
@Override
public void Apply(Part thePart) {
if (myFace == null) {
ExploreBRep(thePart.Bodies());
}
}
public Face FirstFace() {
return myFace;
}
private void ExploreBRep(BodyList theBodies) {
for (Body aBody : theBodies) {
ShapeIterator aFaceIt =
new ShapeIterator(aBody,
ShapeType.Face);
if (aFaceIt.HasNext()) {
Shape aFirstShape = aFaceIt.Next();
Face aFirstFace = Face.Cast(aFirstShape);
myFace = aFirstFace;
break;
}
}
}
private Face myFace = null;
};
Contains classes, types, enums, and functions related to geometric entities.
Contains classes, and functions related to model processing.
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
ShapeType
Defines shape type.
Definition ShapeType.hxx:27
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition LicenseManager_LicenseError.hxx:30