Hide menu
Loading...
Searching...
No Matches
wall_thickness/analyzer/main.cxx

Refer to the Wall Thickness Analyzer Example

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#include <cadex/LicenseManager_Activate.h>
#include <cadex/ModelData_Body.hxx>
#include <cadex/ModelData_BodyList.hxx>
#include <cadex/ModelData_BRepRepresentation.hxx>
#include <cadex/ModelData_IndexedTriangleSet.hxx>
#include <cadex/ModelData_ModelReader.hxx>
#include <cadex/ModelData_PolyRepresentation.hxx>
#include <cadex/ModelData_PolyShapeList.hxx>
#include <cadex/ModelData_PolyVertexSet.hxx>
#include <cadex/ModelData_SceneGraphElementUniqueVisitor.hxx>
#include <cadex/ModelData_Solid.hxx>
#include <cadex/WallThickness_Data.hxx>
#include <cadex/WallThickness_Analyzer.hxx>
#include <iostream>
#include "../../../cadex_license.cxx"
#include "../../../mtk_license.cxx"
using namespace cadex;
using namespace std;
class PartProcessor : public ModelData_Model::VoidElementVisitor
{
public:
void operator() (const ModelData_Part& thePart) override
{
auto aPartName = thePart.Name().IsEmpty() ? "noname" : thePart.Name();
if (auto aBRep = thePart.BRepRepresentation()) {
const auto& aBodyList = aBRep.Get();
for (size_t i = 0, n = aBodyList.Size(); i < n; ++i) {
const auto& aBody = aBodyList[i];
ModelData_Shape::Iterator aShapeIt (aBody);
while (aShapeIt.HasNext()) {
const auto& aShape = aShapeIt.Next();
if (aShape.Type() == ModelData_ST_Solid) {
cout << "Part #" << myPartIndex << " [\"" << aPartName << "\"] - solid #" << std::to_string (i) << " has:" << endl;
ProcessSolid (ModelData_Solid::Cast (aShape));
}
}
}
} else if (auto aPolyRep = thePart.PolyRepresentation (ModelData_RM_Poly)) {
const auto& aPolyList = aPolyRep.Get();
for (size_t i = 0; i < aPolyList.Size(); ++i) {
const auto& aPVS = aPolyList[i];
if (aPVS.IsOfType<ModelData_IndexedTriangleSet>()) {
cout << "Part #" << myPartIndex << " [\"" << aPartName << "\"] - mesh #" << std::to_string (i) << " has:" << endl;
ProcessMesh (static_cast<const ModelData_IndexedTriangleSet&> (aPVS));
}
}
}
++myPartIndex;
}
void ProcessSolid (const ModelData_Solid& theSolid)
{
auto aWTData = myAnalyzer.Perform (theSolid, myResolution);
PrintWTData (aWTData);
}
void ProcessMesh (const ModelData_IndexedTriangleSet& theMesh)
{
auto aWTData = myAnalyzer.Perform (theMesh, myResolution);
PrintWTData (aWTData);
}
void PrintWTData (const WallThickness_Data& theData)
{
if (!theData.IsEmpty()) {
cout << " Min thickness = " << theData.MinThickness() << " mm" << endl;
cout << " Max thickness = " << theData.MaxThickness() << " mm\n" << endl;
} else {
cerr << " Failed to analyze the wall thickness of this entity.\n";
}
}
__CADEX_DEFINE_INITIALIZED_PRIMITIVE_PROPERTY (size_t, Resolution, 1000)
private:
size_t myPartIndex = 0;
};
int main (int argc, char* argv[])
{
auto aKey = LicenseKey::Value();
auto anMTKKey = MTKLicenseKey::Value();
// Activate the license (aKey must be defined in cadex_license.cxx
// and anMTKKey must be defined in mtk_license.cxx)
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate CAD Exchanger license." << endl;
return 1;
}
if (!CADExLicense_Activate (anMTKKey)) {
cerr << "Failed to activate Manufacturing Toolkit license." << endl;
return 1;
}
if (argc < 2 || argc > 3) {
cerr << "Usage: " << argv[0] << " <input_file> <input_resolution>, where:" << endl;
cerr << " <input_file> is a name of the file to be read" << endl;
cerr << " <input_resolution> is an optional argument that determine accuracy"
<< " of wall thickness calculation."
<< " The larger the value, the higher the accuracy of the calculations,"
<< " but greatly increase computation time and memory usage."
<< " Should be at least 100." << endl;
return 1;
}
const char* aSource = argv[1];
size_t aResolution = 1000;
if (argc == 3) {
aResolution = std::atoi (argv[2]);
}
if (aResolution < 100) {
cout << "WARNING: Input resolution \"" << aResolution << "\" < 100. Will be used default resolution." << "\n" << endl;
aResolution = 1000;
}
// Reading the file
if (!aReader.Read (aSource, aModel)) {
cerr << "Failed to read the file " << aSource << endl;
return 1;
}
cout << "Model: " << aModel.Name() << "\n" << endl;
//processing
PartProcessor aPartProcessor;
aPartProcessor.Resolution() = aResolution;
ModelData_SceneGraphElementUniqueVisitor aVisitor (aPartProcessor);
aModel.Accept (aVisitor);
return 0;
}
bool IsEmpty() const
Returns true if the string is empty.
Definition: Base_UTF16String.cxx:233
Base_UTF16String Name() const
Definition: ModelData_BaseObject.cxx:218
Defines a polygonal shape consisting of triangles.
Definition: ModelData_IndexedTriangleSet.hxx:35
Element visitor with empty implementation.
Definition: ModelData_Model.hxx:113
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
const Base_UTF16String & Name() const
Returns a model name.
Definition: ModelData_Model.cxx:358
void Accept(ElementVisitor &theVisitor) const
Accepts a visitor.
Definition: ModelData_Model.cxx:882
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33
bool Read(const Base_UTF16String &theFilePath, ModelData_Model &theModel)
Reads the file at the specified path into the specified model.
Definition: ModelData_ModelReader.cxx:182
Defines a leaf node in the scene graph hiearchy.
Definition: ModelData_Part.hxx:35
ModelData_BRepRepresentation BRepRepresentation() const
Definition: ModelData_Part.cxx:360
ModelData_PolyRepresentation PolyRepresentation(ModelData_RepresentationMask theRepresentationMask) const
Definition: ModelData_Part.cxx:371
Defines a visitor that visits each unique element only once.
Definition: ModelData_SceneGraphElementUniqueVisitor.hxx:33
Iterates over subshapes in a shape.
Definition: ModelData_Shape.hxx:41
Defines a topological solid.
Definition: ModelData_Solid.hxx:31
The wall thickness analyzing tool.
Definition: WallThickness_Analyzer.hxx:42
Contains information about minimum and maximum wall thicknesses.
Definition: WallThickness_Data.hxx:39
double MaxThickness() const
Returns the maximum wall thickness in mm.
Definition: WallThickness_Data.cxx:69
bool IsEmpty() const
Returns true if WallThickness_Data is empty.
Definition: WallThickness_Data.cxx:97
double MinThickness() const
Returns the minimum wall thickness in mm.
Definition: WallThickness_Data.cxx:63
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22