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();
Object[][] aProjectionDataCollection = new Object[][]{{new UTF16String("X"), Direction.XDir()},
{new UTF16String("Y"), Direction.YDir()},
{new UTF16String("Z"), Direction.ZDir()}};
for (Object[] aProjectionData : aProjectionDataCollection) {
UTF16String aProjectionName = (UTF16String) aProjectionData[0];
Direction aProjectionDirection = (Direction) aProjectionData[1];
UTF16String anOutFilePath = new UTF16String(anOutFolder + "projection_" + aProjectionName + ".stl");
if (ComputeProjection(aModel, aProjectionDirection, aProjectionName, anOutFilePath)) {
System.out.println("The output projection is written: " + anOutFilePath);
} else {
System.out.println("Failed to save the result: " + anOutFilePath);
}
System.out.println();
}
}
static void PrintProjectionInfo(Part thePart, UTF16String theDirectionName, Projector_Projection theProjection) {
System.out.println("Part [" + thePart.Name() + "], projection " + theDirectionName + ":");
if (theProjection != null) {
System.out.println(" area = " + theProjection.Area() + " mm");
System.out.println(" outer perimeter = " + theProjection.OuterPerimeter() + " mm");
} else {
System.out.println(" undefined");
}
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) {
if (myPartProjections.size() == 0) {
return false;
}
Part aPart = new Part(new UTF16String("Projections"));
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);
if (aProjection != null) {
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