import java.util.ArrayList;
public class poly_projector {
static {
try {
System.loadLibrary("MTKCore");
} 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 != 2) {
System.out.println("Usage: java poly_projector <input_file> <output_folder>, where:");
System.out.println(" <input_file> is a name of the file to be read");
System.out.println(" <output_folder> is a folder to save projections to (must end with '/' or '\\\\')");
System.out.println();
System.exit(1);
}
String aSource = args[0];
String anOutFolder = args[1];
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);
}
System.out.println("Model: " + aModel.Name());
System.out.println();
UTF16String anOutX = new UTF16String(anOutFolder + "projection_X.mtk");
UTF16String anOutY = new UTF16String(anOutFolder + "projection_Y.mtk");
UTF16String anOutZ = new UTF16String(anOutFolder + "projection_Z.mtk");
if (!ComputeProjection(aModel, Direction.XDir(), new UTF16String("X"), anOutX)) {
System.out.println("Failed to write X projection.");
System.exit(1);
}
if (!ComputeProjection(aModel, Direction.YDir(), new UTF16String("Y"), anOutY)) {
System.out.println("Failed to write Y projection.");
System.exit(1);
}
if (!ComputeProjection(aModel, Direction.ZDir(), new UTF16String("Z"), anOutZ)) {
System.out.println("Failed to write Z projection.");
System.exit(1);
}
System.out.println("Output written:");
System.out.println(" " + anOutX);
System.out.println(" " + anOutY);
System.out.println(" " + anOutZ);
}
static void PrintProjectionInfo(Part thePart,
UTF16String theDirectionName,
Projector_Projection theProjection) {
System.out.println("Part [" + thePart.Name() + "], projection " + theDirectionName + ":");
System.out.println(" area = " + theProjection.Area() + " mm");
System.out.println(" outer perimeter = " + theProjection.OuterPerimeter() + " mm");
System.out.println();
}
static class ProjectionComputer extends ModelElementVoidVisitor {
public ProjectionComputer(Direction theDirection,
UTF16String theDirectionName) {
myDirection = theDirection;
myDirectionName = theDirectionName;
myProjector = new Projector_PolyProjector();
myPartProjections = new ArrayList<Projector_Projection>();
}
public boolean SaveProjection(UTF16String theFileName) {
Part aPart = new Part(new UTF16String("Projection"));
for (Projector_Projection aProjection : myPartProjections) {
MeshBody aMeshBody = new MeshBody(aProjection.Mesh());
aPart.AddBody(aMeshBody);
}
Model anOutModel = new Model(new UTF16String("Projector"));
anOutModel.AddRoot(aPart);
ModelWriter aWriter = new ModelWriter();
return aWriter.Write(anOutModel, theFileName);
}
@Override
public void Apply(Part thePart) {
Projector_Projection aProjection = myProjector.Perform(thePart, myDirection);
PrintProjectionInfo(thePart, myDirectionName, aProjection);
myPartProjections.add(aProjection);
}
private Direction myDirection;
private UTF16String myDirectionName;
private Projector_PolyProjector myProjector;
private ArrayList<Projector_Projection> myPartProjections;
}
static boolean ComputeProjection(Model theModel,
Direction theDirection,
UTF16String theDirectionName,
UTF16String theOutFileName) {
ProjectionComputer aComputer = new ProjectionComputer(theDirection, theDirectionName);
theModel.Accept(aComputer);
return aComputer.SaveProjection(theOutFileName);
}
}
Defines a 3D Direction.
Definition Direction.hxx:32
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.
Definition LicenseManager_LicenseError.hxx:29