#include <cadex/Base/UTF16String.hxx>
#include <cadex/Geom/Direction.hxx>
#include <cadex/LicenseManager_Activate.h>
#include <cadex/LicenseManager_LicenseError.hxx>
#include <cadex/ModelData/IndexedTriangleSet.hxx>
#include <cadex/ModelData/MeshBody.hxx>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/ModelReader.hxx>
#include <cadex/ModelData/ModelWriter.hxx>
#include <cadex/ModelData/Part.hxx>
#include <cadex/Projector_PolyProjector.hxx>
#include <cadex/Projector_Projection.hxx>
#include <iostream>
#include <vector>
#include "../../mtk_license.cxx"
using namespace std;
static void PrintProjectionInfo (
{
std::cout <<
"Part [" << thePart.
Name() <<
"], projection " << theDirectionName <<
":" << std::endl;
std::cout <<
" area = " << theProjection.
Area() <<
" mm" << std::endl;
std::cout <<
" outer perimeter = " << theProjection.
OuterPerimeter() <<
" mm" << std::endl;
std::cout << std::endl;
}
{
public:
myDirection (theDirection),
myDirectionName (theDirectionName)
{}
bool SaveProjection (
const UTF16String& theFileName)
const
{
for (const auto& aProjection : myPartProjections) {
aPart.AddBody (aMeshBody);
}
anOutModel.AddRoot (aPart);
return aWriter.
Write (anOutModel, theFileName);
}
protected:
{
PrintProjectionInfo (thePart, myDirectionName, aProjection);
myPartProjections.push_back (aProjection);
}
private:
std::vector<Projector_Projection> myPartProjections;
};
static bool ComputeProjection (
{
ProjectionComputer aComputer (theDirection, theDirectionName);
return aComputer.SaveProjection (theOutFileName);
}
int main (int argc, char* argv[])
{
auto aKey = MTKLicenseKey::Value();
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate Manufacturing Toolkit license." << endl;
return 1;
}
if (argc != 3) {
cerr << "Usage: " << argv[0] << " <input_file> <output_folder>, where:" << endl;
cerr << " <input_file> is a name of the file to be read" << endl;
cerr << " <output_folder> is a folder to save projections to (must end with '/' or '\\\\')" << endl;
return 1;
}
if (!aReader.
Read (aSource, aModel)) {
cerr << "Failed to read the file " << argv[1] << endl;
return 1;
}
cout <<
"Model: " << aModel.
Name() <<
"\n" << endl;
std::vector<std::pair<UTF16String, Geom::Direction>> aProjectionDataCollection = {
{ "X", Geom::Direction::XDir() },
{ "Y", Geom::Direction::YDir() },
{ "Z", Geom::Direction::ZDir() }
};
for (const auto& aProjectionData : aProjectionDataCollection) {
const auto& aProjectionName = aProjectionData.first;
const auto& aProjectionDirection = aProjectionData.second;
UTF16String anOutFilePath = anOutFolder +
"projection_" + aProjectionName +
".stl";
if (ComputeProjection (aModel, aProjectionDirection, aProjectionName, anOutFilePath)) {
cout << "The output projection is written: " << anOutFilePath << endl << endl;
} else {
cerr << "Failed to write the output file: " << anOutFilePath << endl;
}
}
return 0;
}
Defines a 3D Direction.
Definition Direction.cs:17
Defines a body that represents a polygonal mesh (faceted or tessellated).
Definition MeshBody.cs:19
cadex.UTF16String Name()
Returns empty string if the model element has no name (by default).
Definition ModelElement.cs:67
Element visitor with empty implementation.
Definition ModelElementVoidVisitor.cs:20
Provides MTK data model.
Definition Model.cs:31
void Accept(cadex.ModelData.ModelElementVisitor theVisitor)
Accepts a visitor.
Definition Model.cs:176
cadex.UTF16String Name()
Returns empty string if the model has no name (by default).
Definition Model.cs:90
Reads supported formats, see Import section.
Definition ModelReader.cs:17
bool Read(cadex.UTF16String theFilePath, cadex.ModelData.Model theModel)
Reads the file at the specified path into the specified model.
Definition ModelReader.cs:82
Writes supported formats, see Import and Export section.
Definition ModelWriter.cs:17
bool Write(cadex.ModelData.Model theModel, cadex.UTF16String theFilePath)
Writes the specified model to the file at the specified path.
Definition ModelWriter.cs:73
Defines a leaf node in the scene graph hierarchy.
Definition Part.cs:23
The poly projection tool.
Definition Projector_PolyProjector.cs:22
Provides a computed projection results.
Definition Projector_Projection.cs:21
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition UTF16String.cs:17
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition BaseObject.cs:12