#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 (
const ModelData::Part& thePart,
const UTF16String& theDirectionName,
const Projector_Projection& theProjection)
{
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;
}
class ProjectionComputer : public ModelData::ModelElementVoidVisitor
{
public:
ProjectionComputer (const Geom::Direction& theDirection, const UTF16String& theDirectionName) :
myDirection (theDirection),
myDirectionName (theDirectionName)
{}
bool SaveProjection (const UTF16String& theFileName) const
{
ModelData::Part aPart (UTF16String ("Projections"));
for (const auto& aProjection : myPartProjections) {
ModelData::MeshBody aMeshBody (aProjection.Mesh());
aPart.AddBody (aMeshBody);
}
ModelData::Model anOutModel (UTF16String ("Projector"));
anOutModel.AddRoot (aPart);
ModelData::ModelWriter aWriter;
return aWriter.Write (anOutModel, theFileName);
}
protected:
void operator() (const ModelData::Part& thePart) override
{
Projector_Projection aProjection = myProjector.Perform (thePart, myDirection);
PrintProjectionInfo (thePart, myDirectionName, aProjection);
myPartProjections.push_back (aProjection);
}
private:
Geom::Direction myDirection;
const UTF16String& myDirectionName;
Projector_PolyProjector myProjector;
std::vector<Projector_Projection> myPartProjections;
};
static bool ComputeProjection (
const ModelData::Model& theModel,
const Geom::Direction& theDirection,
const UTF16String& theDirectionName,
const UTF16String& theOutFileName)
{
ProjectionComputer aComputer (theDirection, theDirectionName);
theModel.Accept (aComputer);
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;
}
const UTF16String aSource (argv[1]);
const UTF16String anOutFolder (argv[2]);
ModelData::Model aModel;
ModelData::ModelReader aReader;
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;
}
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.