using System;
using System.Collections.Generic;
namespace poly_projector
{
class Program
{
static int Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("Usage: poly_projector <input_file> <output_folder>, where:");
Console.WriteLine(" <input_file> is a name of the file to be read");
Console.WriteLine(" <output_folder> is a folder to save projections to (must end with '/' or '\\\\')");
return 1;
}
string aKey = MTKLicenseKey.Value();
if (!LicenseHelper.SetupRuntimeKey())
{
return 1;
}
try
{
}
{
Console.WriteLine(
"Failed to activate Manufacturing Toolkit license: " + theException.
what());
return 1;
}
UTF16String aSource = new UTF16String(args[0]);
string anOutFolder = args[1];
if (!aReader.
Read(aSource, aModel))
{
Console.WriteLine("Failed to read the file " + args[0]);
return 1;
}
Console.WriteLine(
"Model: " + aModel.
Name());
Console.WriteLine("");
var aProjectionDataCollection = new List<KeyValuePair<UTF16String, Direction>>
{
new KeyValuePair<UTF16String, Direction>(
new UTF16String(
"X"),
Direction.
XDir()),
new KeyValuePair<UTF16String, Direction>(
new UTF16String(
"Y"),
Direction.
YDir()),
new KeyValuePair<UTF16String, Direction>(
new UTF16String(
"Z"),
Direction.
ZDir())
};
foreach (var aProjectionData in aProjectionDataCollection)
{
UTF16String aProjectionName = aProjectionData.Key;
Direction aProjectionDirection = aProjectionData.Value;
UTF16String anOutFilePath = new UTF16String(anOutFolder + "projection_" + aProjectionName + ".stl");
if (ComputeProjection(aModel, aProjectionDirection, aProjectionName, anOutFilePath))
{
Console.WriteLine("The output projection is written: " + anOutFilePath);
}
else
{
Console.WriteLine("Failed to save the result: " + anOutFilePath);
}
Console.WriteLine("");
}
return 0;
}
private static void PrintProjectionInfo(
Part thePart,
UTF16String theDirectionName,
{
Console.WriteLine(
"Part [" + thePart.
Name() +
"], projection " + theDirectionName +
":");
if (theProjection != null)
{
Console.WriteLine(
" area = " + theProjection.
Area() +
" mm");
Console.WriteLine(
" outer perimeter = " + theProjection.
OuterPerimeter() +
" mm");
}
else
{
Console.WriteLine(" undefined");
}
Console.WriteLine("");
}
{
public ProjectionComputer(
Direction theDirection,
UTF16String theDirectionName)
{
myDirection = theDirection;
myDirectionName = theDirectionName;
}
public bool SaveProjection(UTF16String theFileName)
{
if (myPartProjections.Count == 0)
{
return false;
}
Part aPart =
new Part(
new UTF16String(
"Projections"));
{
aPart.AddBody(aMeshBody);
}
Model anOutModel =
new Model(
new UTF16String(
"Projector"));
return aWriter.
Write(anOutModel, theFileName);
}
public override void Apply(
Part thePart)
{
PrintProjectionInfo(thePart, myDirectionName, aProjection);
if (aProjection != null)
{
myPartProjections.Add(aProjection);
}
}
private readonly UTF16String myDirectionName;
private List<Projector_Projection> myPartProjections = new List<Projector_Projection>();
}
static bool ComputeProjection(
Model theModel,
UTF16String theDirectionName,
UTF16String theOutFileName)
{
ProjectionComputer aComputer = new ProjectionComputer(theDirection, theDirectionName);
return aComputer.SaveProjection(theOutFileName);
}
}
}
Defines a 3D Direction.
Definition Direction.hxx:32
Defines a body that represents a polygonal mesh (faceted or tessellated).
Definition MeshBody.hxx:30
UTF16String Name() const
Returns a name.
Definition ModelElement.cxx:54
Element visitor with empty implementation.
Definition ModelElementVisitor.hxx:63
Provides MTK data model.
Definition Model.hxx:39
void AddRoot(const ModelElement &theElement)
Adds a root element to the model.
Definition Model.cxx:218
UTF16String Name() const
Returns a model name.
Definition Model.cxx:255
void Accept(ModelElementVisitor &theVisitor) const
Accepts a visitor.
Definition Model.cxx:275
Reads supported formats, see Import section.
Definition ModelReader.hxx:32
bool Read(const UTF16String &theFilePath, ModelData::Model &theModel)
Reads the file at the specified path into the specified model.
Definition ModelReader.cxx:358
Writes supported formats, see Import and Export section.
Definition ModelWriter.hxx:32
bool Write(const ModelData::Model &theModel, const UTF16String &theFilePath)
Writes the specified model to the file at the specified path.
Definition ModelWriter.cxx:104
Defines a leaf node in the scene graph hierarchy.
Definition Part.hxx:32
The poly projection tool.
Definition Projector_PolyProjector.hxx:43
Provides a computed projection results.
Definition Projector_Projection.hxx:64
double Area() const
Returns the total area of the projection.
Definition Projector_Projection.cxx:178
const ModelData::IndexedTriangleSet & Mesh() const
Returns the complete mesh representation of the projection.
Definition Projector_Projection.cxx:230
double OuterPerimeter() const
Returns the sum of regions' outer perimeter.
Definition Projector_Projection.cxx:198
Defines an exception thrown by a license manager when a valid license could not be acquired.
Definition LicenseError.hxx:37
const char * what() const noexcept override
Returns an error string.
Definition LicenseError.cxx:50
Provides MTK licensing activation and deactivation API.
Definition LicenseManager.hxx:33
static bool Deactivate()
Closes the active licensing session.
Definition LicenseManager.cxx:619
static bool Activate(const std::string &theDeveloperKey)
Activates MTK licensing using the development license key.
Definition LicenseManager.cxx:190
Contains classes, types, enums, and functions related to geometric entities.
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
The mtk namespace is intended to become the primary namespace for MTK and replace direct use of the c...
Definition LicenseError.hxx:27
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition LicenseError.hxx:27