Hide menu
Loading...
Searching...
No Matches
exploring/brep_geometry/main.cxx

Refer to the B-Rep Geometry Exploration Example.

base_explorer.hxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2025, CADEX. All rights reserved.
//
// This file is part of the Manufacturing Toolkit 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.
//
// ****************************************************************************
#ifndef _BaseExplorer_HeaderFile
#define _BaseExplorer_HeaderFile
#include <cadex/Geom/Curve.hxx>
#include <cadex/Geom/Curve2d.hxx>
#include <cadex/Geom/Direction2d.hxx>
#include <cadex/Geom/Point.hxx>
#include <cadex/Geom/Point2d.hxx>
#include <cadex/Geom/Surface.hxx>
#include <cadex/ModelData/ShapeOrientation.hxx>
#include <functional>
#include <iostream>
using namespace std;
using namespace cadex;
class BaseExplorer
{
public:
template <typename T>
static void PrintElementary (const T& theGeometry)
{
PrintDomain (theGeometry);
auto const& aPosition = theGeometry.Position();
const Geom::Point& aLoc = aPosition.Location();
const Geom::Direction& anAxis = aPosition.Axis();
const Geom::Direction& aXDir = aPosition.XDirection();
const Geom::Direction& aYDir = aPosition.YDirection();
PrintParameter ("Location", aLoc);
PrintParameter ("Axis", anAxis);
PrintParameter ("X Direction", aXDir);
PrintParameter ("Y Direction", aYDir);
}
template <typename T>
static void PrintElementary2d (const T& theGeometry)
{
PrintDomain (theGeometry);
auto const& aPosition = theGeometry.Position();
const Geom::Point2d& aLoc = aPosition.Location();
const Geom::Direction2d& aXDir = aPosition.XDirection();
const Geom::Direction2d& aYDir = aPosition.YDirection();
PrintParameter ("Location", aLoc);
PrintParameter ("X Direction", aXDir.XDir());
PrintParameter ("Y Direction", aYDir.YDir());
}
static void PrintRange (const char* aName, double aFirstParameter, double aLastParameter)
{
cout << aName << " = [" << aFirstParameter << ", " << aLastParameter << "]; ";
}
static void PrintDomain (const Geom::Curve& theCurve)
{
PrintRange ("Domain", theCurve.UMin(), theCurve.UMax());
}
static void PrintDomain (const Geom::Curve2d& theCurve)
{
PrintRange ("Domain", theCurve.UMin(), theCurve.UMax());
}
static void PrintDomain (const Geom::Surface& theSurface)
{
PrintRange ("Domain U", theSurface.UMin(), theSurface.UMax());
PrintRange ("V", theSurface.VMin(), theSurface.VMax());
}
static void PrintParameter (Geom::Direction theDirection)
{
cout << "(" << theDirection.X() << ", " << theDirection.Y() << ", " << theDirection.Z() << "); ";
}
static void PrintParameter (Geom::Direction2d theDirection)
{
cout << "(" << theDirection.X() << ", " << theDirection.Y() << "); ";
}
static void PrintParameter (Geom::Point thePoint)
{
cout << "(" << thePoint.X() << ", " << thePoint.Y() << ", " << thePoint.Z() << "); ";
}
static void PrintParameter (Geom::Point2d thePoint)
{
cout << "(" << thePoint.X() << ", " << thePoint.Y() << "); ";
}
static void PrintParameter (double theValue)
{
cout << theValue << "; ";
}
template <typename T>
static void PrintParameter (const char* theName, T theValue)
{
cout << theName << " = ";
PrintParameter (theValue);
}
static void PrintName (const char* theName)
{
cout << theName << ": ";
}
static void PrintCollection (const char* theName, int theFinalIndex, std::function<void (int)> thePrintElement)
{
if (theName) {
cout << theName << " = ";
}
cout << "[";
for (int i = 1; i <= theFinalIndex; ++i) {
if (i > 3) {
cout << "...";
break;
}
thePrintElement (i);
}
cout << "]; ";
}
static void PrintCollection (const char* theName,
int theFinalIndex1,
int theFinalIndex2,
std::function<void (int, int)> thePrintElement)
{
PrintCollection (theName, theFinalIndex1, [&] (int i) {
PrintCollection (nullptr, theFinalIndex2, [&] (int j) { thePrintElement (i, j); });
});
}
static void PrintOrientation (const ModelData::ShapeOrientation& theOrientation)
{
cout << "Orientation = ";
switch (theOrientation) {
case ModelData::ShapeOrientation::Forward:
cout << "Forward";
break;
case ModelData::ShapeOrientation::Reversed:
cout << "Reversed";
break;
default:
cout << "Undefined";
break;
}
cout << "; ";
}
void PrintTabulation()
{
for (size_t i = 0; i < myNestingLevel; ++i) {
cout << "--- ";
}
}
size_t myNestingLevel = 0;
};
#endif
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.

curve_explorer.hxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2025, CADEX. All rights reserved.
//
// This file is part of the Manufacturing Toolkit 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.
//
// ****************************************************************************
#ifndef _CurveExplorer_HeaderFile
#define _CurveExplorer_HeaderFile
#include <cadex/Geom/BSplineCurve.hxx>
#include <cadex/Geom/BezierCurve.hxx>
#include <cadex/Geom/Circle.hxx>
#include <cadex/Geom/Ellipse.hxx>
#include <cadex/Geom/Hyperbola.hxx>
#include <cadex/Geom/Line.hxx>
#include <cadex/Geom/OffsetCurve.hxx>
#include <cadex/Geom/Parabola.hxx>
#include <base_explorer.hxx>
using namespace std;
using namespace cadex;
class CurveExplorer : public BaseExplorer
{
public:
static void PrintCurveInfo (const Geom::Curve& theCurve)
{
switch (theCurve.Type()) {
case Geom::CurveType::Line:
PrintLine (static_cast<const Geom::Line&> (theCurve));
break;
case Geom::CurveType::Circle:
PrintCircle (static_cast<const Geom::Circle&> (theCurve));
break;
case Geom::CurveType::Ellipse:
PrintEllipse (static_cast<const Geom::Ellipse&> (theCurve));
break;
case Geom::CurveType::Hyperbola:
PrintHyperbola (static_cast<const Geom::Hyperbola&> (theCurve));
break;
case Geom::CurveType::Parabola:
PrintParabola (static_cast<const Geom::Parabola&> (theCurve));
break;
case Geom::CurveType::Bezier:
PrintBezierCurve (static_cast<const Geom::BezierCurve&> (theCurve));
break;
case Geom::CurveType::BSpline:
PrintBSplineCurve (static_cast<const Geom::BSplineCurve&> (theCurve));
break;
case Geom::CurveType::Offset:
PrintOffsetCurve (static_cast<const Geom::OffsetCurve&> (theCurve));
break;
default:
break;
}
}
static void PrintLine (const Geom::Line& theLine)
{
PrintName ("Line");
const Geom::Point& aLoc = theLine.Location();
const Geom::Direction& aDir = theLine.Direction();
PrintDomain (theLine);
PrintParameter ("Location", aLoc);
PrintParameter ("Direction", aDir);
}
static void PrintCircle (const Geom::Circle& theCircle)
{
PrintName ("Circle");
double aRadius = theCircle.Radius();
PrintElementary (theCircle);
PrintParameter ("Radius", aRadius);
}
static void PrintEllipse (const Geom::Ellipse& theEllipse)
{
PrintName ("Ellipse");
double aMajorRadius = theEllipse.MajorRadius();
double aMinorRadius = theEllipse.MinorRadius();
PrintElementary (theEllipse);
PrintParameter ("Major Radius", aMajorRadius);
PrintParameter ("Minor Radius", aMinorRadius);
}
static void PrintHyperbola (const Geom::Hyperbola& theHyperbola)
{
PrintName ("Hyperbola");
double aMajorRadius = theHyperbola.MajorRadius();
double aMinorRadius = theHyperbola.MinorRadius();
PrintElementary (theHyperbola);
PrintParameter ("Major Radius", aMajorRadius);
PrintParameter ("Minor Radius", aMinorRadius);
}
static void PrintParabola (const Geom::Parabola& theParabola)
{
PrintName ("Parabola");
double aFocal = theParabola.Focal();
PrintElementary (theParabola);
PrintParameter ("Focal", aFocal);
}
static void PrintBezierCurve (const Geom::BezierCurve& theBezier)
{
PrintName ("Bezier Curve");
int aDegree = theBezier.Degree();
int aNumberOfPoles = theBezier.NumberOfPoles();
PrintDomain (theBezier);
PrintParameter ("Degree", aDegree);
PrintParameter ("Number Of Poles", aNumberOfPoles);
PrintCollection ("Poles", aNumberOfPoles, [&] (int i) {
auto aPole = theBezier.Pole (i);
PrintParameter (aPole);
});
PrintCollection ("Weights", aNumberOfPoles, [&] (int i) {
double aWeight = theBezier.Weight (i);
PrintParameter (aWeight);
});
}
static void PrintBSplineCurve (const Geom::BSplineCurve& theBSpline)
{
PrintName ("BSpline Curve");
int aDegree = theBSpline.Degree();
int aNumberOfKnots = theBSpline.NumberOfKnots();
int aNumberOfPoles = theBSpline.NumberOfPoles();
PrintDomain (theBSpline);
PrintParameter ("Degree", aDegree);
PrintParameter ("Number Of Knots", aNumberOfKnots);
PrintParameter ("Number Of Poles", aNumberOfPoles);
PrintCollection ("Knots", aNumberOfKnots, [&] (int i) {
double aKnot = theBSpline.Knot (i);
PrintParameter (aKnot);
});
PrintCollection ("Multiplicities", aNumberOfKnots, [&] (int i) {
int aMultiplicity = theBSpline.Multiplicity (i);
PrintParameter (aMultiplicity);
});
PrintCollection ("Poles", aNumberOfPoles, [&] (int i) {
auto aPole = theBSpline.Pole (i);
PrintParameter (aPole);
});
PrintCollection ("Weights", aNumberOfPoles, [&] (int i) {
double aWeight = theBSpline.Weight (i);
PrintParameter (aWeight);
});
}
static void PrintOffsetCurve (const Geom::OffsetCurve& theOffset)
{
PrintName ("Offset Curve");
const Geom::Direction& aDir = theOffset.Direction();
double anOffset = theOffset.Offset();
PrintDomain (theOffset);
PrintParameter ("Direction", aDir);
PrintParameter ("Offset", anOffset);
cout << "Basis Curve = ";
PrintCurveInfo (theOffset.BasisCurve());
}
};
#endif

pcurve_explorer.hxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2025, CADEX. All rights reserved.
//
// This file is part of the Manufacturing Toolkit 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.
//
// ****************************************************************************
#ifndef _PCurveExplorer_HeaderFile
#define _PCurveExplorer_HeaderFile
#include <cadex/Geom/BSplineCurve2d.hxx>
#include <cadex/Geom/BezierCurve2d.hxx>
#include <cadex/Geom/Circle2d.hxx>
#include <cadex/Geom/Ellipse2d.hxx>
#include <cadex/Geom/Hyperbola2d.hxx>
#include <cadex/Geom/Line2d.hxx>
#include <cadex/Geom/OffsetCurve2d.hxx>
#include <cadex/Geom/Parabola2d.hxx>
#include <base_explorer.hxx>
using namespace std;
using namespace cadex;
class PCurveExplorer : public BaseExplorer
{
public:
static void PrintPCurveInfo (const Geom::Curve2d& theCurve)
{
switch (theCurve.Type()) {
case Geom::CurveType::Line:
PrintLine (static_cast<const Geom::Line2d&> (theCurve));
break;
case Geom::CurveType::Circle:
PrintCircle (static_cast<const Geom::Circle2d&> (theCurve));
break;
case Geom::CurveType::Ellipse:
PrintEllipse (static_cast<const Geom::Ellipse2d&> (theCurve));
break;
case Geom::CurveType::Hyperbola:
PrintHyperbola (static_cast<const Geom::Hyperbola2d&> (theCurve));
break;
case Geom::CurveType::Parabola:
PrintParabola (static_cast<const Geom::Parabola2d&> (theCurve));
break;
case Geom::CurveType::Bezier:
PrintBezierCurve (static_cast<const Geom::BezierCurve2d&> (theCurve));
break;
case Geom::CurveType::BSpline:
PrintBSplineCurve (static_cast<const Geom::BSplineCurve2d&> (theCurve));
break;
case Geom::CurveType::Offset:
PrintOffsetCurve (static_cast<const Geom::OffsetCurve2d&> (theCurve));
break;
default:
break;
}
}
static void PrintLine (const Geom::Line2d& theLine)
{
PrintName ("Line 2d");
const Geom::Point2d& aLoc = theLine.Location();
const Geom::Direction2d& aDir = theLine.Direction();
PrintDomain (theLine);
PrintParameter ("Location", aLoc);
PrintParameter ("Direction", aDir);
}
static void PrintCircle (const Geom::Circle2d& theCircle)
{
PrintName ("Circle 2d");
double aRadius = theCircle.Radius();
PrintElementary2d (theCircle);
PrintParameter ("Radius", aRadius);
}
static void PrintEllipse (const Geom::Ellipse2d& theEllipse)
{
PrintName ("Ellipse 2d");
double aMajorRadius = theEllipse.MajorRadius();
double aMinorRadius = theEllipse.MinorRadius();
PrintElementary2d (theEllipse);
PrintParameter ("Major Radius", aMajorRadius);
PrintParameter ("Minor Radius", aMinorRadius);
}
static void PrintHyperbola (const Geom::Hyperbola2d& theHyperbola)
{
PrintName ("Hyperbola 2d");
double aMajorRadius = theHyperbola.MajorRadius();
double aMinorRadius = theHyperbola.MinorRadius();
PrintElementary2d (theHyperbola);
PrintParameter ("Major Radius", aMajorRadius);
PrintParameter ("Minor Radius", aMinorRadius);
}
static void PrintParabola (const Geom::Parabola2d& theParabola)
{
PrintName ("Parabola 2d");
double aFocal = theParabola.Focal();
PrintElementary2d (theParabola);
PrintParameter ("Focal", aFocal);
}
static void PrintBezierCurve (const Geom::BezierCurve2d& theBezier)
{
PrintName ("Bezier Curve 2d");
int aDegree = theBezier.Degree();
int aNumberOfPoles = theBezier.NumberOfPoles();
PrintDomain (theBezier);
PrintParameter ("Degree", aDegree);
PrintParameter ("Number Of Poles", aNumberOfPoles);
PrintCollection ("Poles", aNumberOfPoles, [&] (int i) {
auto aPole = theBezier.Pole (i);
PrintParameter (aPole);
});
PrintCollection ("Weights", aNumberOfPoles, [&] (int i) {
double aWeight = theBezier.Weight (i);
PrintParameter (aWeight);
});
}
static void PrintBSplineCurve (const Geom::BSplineCurve2d& theBSpline)
{
PrintName ("BSpline Curve 2d");
int aDegree = theBSpline.Degree();
int aNumberOfKnots = theBSpline.NumberOfKnots();
int aNumberOfPoles = theBSpline.NumberOfPoles();
PrintDomain (theBSpline);
PrintParameter ("Degree", aDegree);
PrintParameter ("Number Of Knots", aNumberOfKnots);
PrintParameter ("Number Of Poles", aNumberOfPoles);
PrintCollection ("Knots", aNumberOfKnots, [&] (int i) {
double aKnot = theBSpline.Knot (i);
PrintParameter (aKnot);
});
PrintCollection ("Multiplicities", aNumberOfKnots, [&] (int i) {
int aMultiplicity = theBSpline.Multiplicity (i);
PrintParameter (aMultiplicity);
});
PrintCollection ("Poles", aNumberOfPoles, [&] (int i) {
auto aPole = theBSpline.Pole (i);
PrintParameter (aPole);
});
PrintCollection ("Weights", aNumberOfPoles, [&] (int i) {
double aWeight = theBSpline.Weight (i);
PrintParameter (aWeight);
});
}
static void PrintOffsetCurve (const Geom::OffsetCurve2d& theOffset)
{
PrintName ("Offset Curve 2d");
double anOffset = theOffset.Offset();
PrintDomain (theOffset);
PrintParameter ("Offset", anOffset);
cout << "Basis Curve = ";
PrintPCurveInfo (theOffset.BasisCurve());
}
};
#endif

shape_explorer.hxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2025, CADEX. All rights reserved.
//
// This file is part of the Manufacturing Toolkit 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.
//
// ****************************************************************************
#ifndef _ShapeExplorer_HeaderFile
#define _ShapeExplorer_HeaderFile
#include <cadex/ModelData/Body.hxx>
#include <cadex/ModelData/Edge.hxx>
#include <cadex/ModelData/Face.hxx>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/ModelElementVisitor.hxx>
#include <cadex/ModelData/ModelReader.hxx>
#include <cadex/ModelData/Part.hxx>
#include <cadex/ModelData/Shape.hxx>
#include <cadex/ModelData/SheetBody.hxx>
#include <cadex/ModelData/Shell.hxx>
#include <cadex/ModelData/SolidBody.hxx>
#include <cadex/ModelData/Vertex.hxx>
#include <cadex/ModelData/Wire.hxx>
#include <cadex/ModelData/WireframeBody.hxx>
#include <base_explorer.hxx>
#include <curve_explorer.hxx>
#include <pcurve_explorer.hxx>
#include <surface_explorer.hxx>
#include <array>
#include <functional>
#include <iostream>
#include <unordered_map>
using namespace std;
using namespace cadex;
// Visits directly each part and calls B-Rep bodies exploring if a part has one
class ShapeExplorer : public ModelData::ModelElementVoidVisitor, public BaseExplorer
{
protected:
void operator() (const ModelData::Part& thePart) override
{
cout << "Part = \"" << thePart.Name() << "\"" << endl;
const auto& aBodies = thePart.Bodies();
if (!aBodies.empty()) {
ExploreBRep (aBodies);
}
}
private:
void ExploreBRep (const std::vector<ModelData::Body>& theBodies)
{
// Iterate over bodies
for (size_t i = 0; i < theBodies.size(); ++i) {
const auto& aBody = theBodies[i];
cout << "Body " << i << " " << BodyType (aBody) << endl;
for (ModelData::ShapeIterator j (aBody); j.HasNext();) {
const ModelData::Shape& aShape = j.Next();
ExploreShape (aShape);
}
}
}
// Recursive iterating over the Shape until reaching vertices
void ExploreShape (const ModelData::Shape& theShape)
{
if (theShape.Type() == ModelData::ShapeType::Face) {
myCurrentFace = ModelData::Face::Cast (theShape);
}
++myNestingLevel;
ModelData::ShapeIterator aShapeIt (theShape);
while (aShapeIt.HasNext()) {
const ModelData::Shape& aShape = aShapeIt.Next();
PrintShape (aShape);
ExploreShape (aShape);
}
if (theShape.Type() == ModelData::ShapeType::Face) {
myCurrentFace = ModelData::Face();
}
--myNestingLevel;
}
// Returns body type name
const char* BodyType (const ModelData::Body& theBody)
{
if (theBody.IsOfType<ModelData::SheetBody>()) {
return "Sheet";
} else if (theBody.IsOfType<ModelData::SolidBody>()) {
return "Solid";
} else if (theBody.IsOfType<ModelData::WireframeBody>()) {
return "Wireframe";
}
return "Undefined";
}
// Returns shape type name and prints shape info in some cases
void PrintShape (const ModelData::Shape& theShape)
{
PrintTabulation();
switch (theShape.Type()) {
case ModelData::ShapeType::Solid:
cout << "Solid";
break;
case ModelData::ShapeType::Shell:
PrintShell (ModelData::Shell::Cast (theShape));
break;
case ModelData::ShapeType::Wire:
PrintWire (ModelData::Wire::Cast (theShape));
break;
case ModelData::ShapeType::Face:
PrintFace (ModelData::Face::Cast (theShape));
break;
case ModelData::ShapeType::Edge:
PrintEdge (ModelData::Edge::Cast (theShape));
break;
case ModelData::ShapeType::Vertex:
PrintVertex (ModelData::Vertex::Cast (theShape));
break;
default:
cout << "Undefined";
break;
}
cout << endl;
}
void PrintShell (const ModelData::Shell& theWire)
{
PrintName ("Shell");
++myNestingLevel;
PrintOrientation (theWire.Orientation());
--myNestingLevel;
}
void PrintWire (const ModelData::Wire& theWire)
{
PrintName ("Wire");
++myNestingLevel;
PrintOrientation (theWire.Orientation());
--myNestingLevel;
}
void PrintFace (const ModelData::Face& theFace)
{
PrintName ("Face");
++myNestingLevel;
PrintOrientation (theFace.Orientation());
cout << endl;
Geom::Surface aSurface = theFace.Surface();
PrintTabulation();
cout << "Surface: ";
SurfaceExplorer::PrintSurface (aSurface);
--myNestingLevel;
}
void PrintEdge (const ModelData::Edge& theEdge)
{
PrintName ("Edge");
++myNestingLevel;
if (theEdge.IsDegenerated()) {
cout << "Degenerated: ";
}
PrintOrientation (theEdge.Orientation());
PrintParameter ("Tolerance", theEdge.Tolerance());
if (!theEdge.IsDegenerated()) {
pair<double, double> aParameters;
Geom::Curve aCurve = theEdge.Curve (aParameters.first, aParameters.second);
cout << endl;
PrintTabulation();
PrintName ("Curve");
PrintRange ("Edge Range", aParameters.first, aParameters.second);
CurveExplorer::PrintCurveInfo (aCurve);
}
if (myCurrentFace) {
pair<double, double> aParameters2d;
const Geom::Curve2d& aPCurve =
theEdge.PCurve (myCurrentFace, aParameters2d.first, aParameters2d.second);
cout << endl;
PrintTabulation();
PrintName ("PCurve");
PrintRange ("Edge Range", aParameters2d.first, aParameters2d.second);
PCurveExplorer::PrintPCurveInfo (aPCurve);
}
--myNestingLevel;
}
void PrintVertex (const ModelData::Vertex& theVertex)
{
PrintName ("Vertex");
Geom::Point aLoc = theVertex.Point();
double aTolerance = theVertex.Tolerance();
PrintOrientation (theVertex.Orientation());
PrintParameter ("Tolerance", aTolerance);
PrintParameter ("Location", aLoc);
}
private:
ModelData::Face myCurrentFace;
};
#endif

surface_explorer.hxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2025, CADEX. All rights reserved.
//
// This file is part of the Manufacturing Toolkit 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.
//
// ****************************************************************************
#ifndef _SurfaceExplorer_HeaderFile
#define _SurfaceExplorer_HeaderFile
#include <cadex/Geom/BSplineSurface.hxx>
#include <cadex/Geom/BezierSurface.hxx>
#include <cadex/Geom/ConicalSurface.hxx>
#include <cadex/Geom/CylindricalSurface.hxx>
#include <cadex/Geom/OffsetSurface.hxx>
#include <cadex/Geom/Plane.hxx>
#include <cadex/Geom/SphericalSurface.hxx>
#include <cadex/Geom/SurfaceOfLinearExtrusion.hxx>
#include <cadex/Geom/SurfaceOfRevolution.hxx>
#include <cadex/Geom/ToroidalSurface.hxx>
#include <base_explorer.hxx>
using namespace std;
using namespace cadex;
class SurfaceExplorer : public BaseExplorer
{
public:
static void PrintSurface (const Geom::Surface& theSurface)
{
switch (theSurface.Type()) {
case Geom::SurfaceType::Plane:
PrintPlane (static_cast<const Geom::Plane&> (theSurface));
break;
case Geom::SurfaceType::Cylinder:
PrintCylinder (static_cast<const Geom::CylindricalSurface&> (theSurface));
break;
case Geom::SurfaceType::Cone:
PrintCone (static_cast<const Geom::ConicalSurface&> (theSurface));
break;
case Geom::SurfaceType::Sphere:
PrintSphere (static_cast<const Geom::SphericalSurface&> (theSurface));
break;
case Geom::SurfaceType::Torus:
PrintTorus (static_cast<const Geom::ToroidalSurface&> (theSurface));
break;
case Geom::SurfaceType::LinearExtrusion:
PrintLinearExtrusion (static_cast<const Geom::SurfaceOfLinearExtrusion&> (theSurface));
break;
case Geom::SurfaceType::Revolution:
PrintRevolution (static_cast<const Geom::SurfaceOfRevolution&> (theSurface));
break;
case Geom::SurfaceType::Bezier:
PrintBezierSurface (static_cast<const Geom::BezierSurface&> (theSurface));
break;
case Geom::SurfaceType::BSpline:
PrintBSplineSurface (static_cast<const Geom::BSplineSurface&> (theSurface));
break;
case Geom::SurfaceType::Offset:
PrintOffsetSurface (static_cast<const Geom::OffsetSurface&> (theSurface));
break;
default:
break;
}
}
static void PrintPlane (const Geom::Plane& thePlane)
{
PrintName ("Plane");
PrintElementary (thePlane);
}
static void PrintCylinder (const Geom::CylindricalSurface& theCylinder)
{
PrintName ("Cylinder");
double aRadius = theCylinder.Radius();
PrintElementary (theCylinder);
PrintParameter ("Radius", aRadius);
}
static void PrintCone (const Geom::ConicalSurface& theCone)
{
PrintName ("Cone");
double aRadius = theCone.Radius();
double aSemiAngle = theCone.SemiAngle();
PrintElementary (theCone);
PrintParameter ("Radius", aRadius);
PrintParameter ("Semi-Angle", aSemiAngle);
}
static void PrintSphere (const Geom::SphericalSurface& theSphere)
{
PrintName ("Sphere");
double aRadius = theSphere.Radius();
PrintElementary (theSphere);
PrintParameter ("Radius", aRadius);
}
static void PrintTorus (const Geom::ToroidalSurface& theTorus)
{
PrintName ("Torus");
double aMajorRadius = theTorus.MajorRadius();
double aMinorRadius = theTorus.MinorRadius();
PrintElementary (theTorus);
PrintParameter ("Major Radius", aMajorRadius);
PrintParameter ("Minor Radius", aMinorRadius);
}
static void PrintLinearExtrusion (const Geom::SurfaceOfLinearExtrusion& theLinearExtrusion)
{
PrintName ("Linear Extrusion Surface");
const Geom::Direction& aDir = theLinearExtrusion.Direction();
PrintDomain (theLinearExtrusion);
PrintParameter ("Direction", aDir);
cout << "Basis Curve = ";
CurveExplorer::PrintCurveInfo (theLinearExtrusion.BasisCurve());
}
static void PrintRevolution (const Geom::SurfaceOfRevolution& theRevolution)
{
PrintName ("Revolution Surface");
const Geom::Direction& aDir = theRevolution.Direction();
const Geom::Point& aLoc = theRevolution.Location();
PrintDomain (theRevolution);
PrintParameter ("Location", aLoc);
PrintParameter ("Direction", aDir);
cout << "Basis Curve = ";
CurveExplorer::PrintCurveInfo (theRevolution.BasisCurve());
}
static void PrintBezierSurface (const Geom::BezierSurface& theBezier)
{
PrintName ("Bezier Surface");
int aUDegree = theBezier.UDegree();
int aVDegree = theBezier.VDegree();
int aNumberOfUPoles = theBezier.NumberOfUPoles();
int aNumberOfVPoles = theBezier.NumberOfVPoles();
PrintDomain (theBezier);
PrintParameter ("U Degree", aUDegree);
PrintParameter ("V Degree", aVDegree);
PrintParameter ("Number Of U Poles", aNumberOfUPoles);
PrintParameter ("Number Of V Poles", aNumberOfVPoles);
PrintCollection ("Poles", aNumberOfUPoles, aNumberOfVPoles, [&] (int i, int j) {
auto aPole = theBezier.Pole (i, j);
PrintParameter (aPole);
});
PrintCollection ("Weights", aNumberOfUPoles, aNumberOfVPoles, [&] (int i, int j) {
double aWeight = theBezier.Weight (i, j);
PrintParameter (aWeight);
});
}
static void PrintBSplineSurface (const Geom::BSplineSurface& theBSpline)
{
PrintName ("BSpline Surface");
int aUDegree = theBSpline.UDegree();
int aVDegree = theBSpline.VDegree();
int aNumberOfUKnots = theBSpline.NumberOfUKnots();
int aNumberOfVKnots = theBSpline.NumberOfVKnots();
int aNumberOfUPoles = theBSpline.NumberOfUPoles();
int aNumberOfVPoles = theBSpline.NumberOfVPoles();
PrintDomain (theBSpline);
PrintParameter ("U Degree", aUDegree);
PrintParameter ("V Degree", aVDegree);
PrintParameter ("Number Of U Knots", aNumberOfUKnots);
PrintParameter ("Number Of V Knots", aNumberOfVKnots);
PrintParameter ("Number Of U Poles", aNumberOfUPoles);
PrintParameter ("Number Of V Poles", aNumberOfVPoles);
PrintCollection ("U Knots", aNumberOfUKnots, [&] (int i) {
double aKnot = theBSpline.UKnot (i);
PrintParameter (aKnot);
});
PrintCollection ("V Knots", aNumberOfVKnots, [&] (int i) {
double aKnot = theBSpline.VKnot (i);
PrintParameter (aKnot);
});
PrintCollection ("U Multiplicities", aNumberOfUKnots, [&] (int i) {
int aUMultiplicity = theBSpline.UMultiplicity (i);
PrintParameter (aUMultiplicity);
});
PrintCollection ("V Multiplicities", aNumberOfVKnots, [&] (int i) {
int aVMultiplicity = theBSpline.VMultiplicity (i);
PrintParameter (aVMultiplicity);
});
PrintCollection ("Poles", aNumberOfUPoles, aNumberOfVPoles, [&] (int i, int j) {
auto aPole = theBSpline.Pole (i, j);
PrintParameter (aPole);
});
PrintCollection ("Weights", aNumberOfUPoles, aNumberOfVPoles, [&] (int i, int j) {
double aWeight = theBSpline.Weight (i, j);
PrintParameter (aWeight);
});
}
static void PrintOffsetSurface (const Geom::OffsetSurface& theOffset)
{
PrintName ("Offset Surface");
double anOffset = theOffset.Offset();
PrintDomain (theOffset);
PrintParameter ("Offset", anOffset);
cout << "Basis Surface = ";
PrintSurface (theOffset.BasisSurface());
}
};
#endif

main.cxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2025, CADEX. All rights reserved.
//
// This file is part of the Manufacturing Toolkit 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/ModelReader.hxx>
#include <shape_explorer.hxx>
#include "../../mtk_license.cxx"
using namespace std;
using namespace cadex;
int main (int argc, char* argv[])
{
auto aKey = MTKLicenseKey::Value();
// Activate the license (aKey must be defined in mtk_license.cxx)
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate Manufacturing Toolkit license." << endl;
return 1;
}
// Get the input
if (argc != 2) {
cerr << "Usage: " << argv[0] << " <input_file>, where:" << endl;
cerr << " <input_file> is a name of the file to be read" << endl;
return 1;
}
const char* aSource = argv[1];
ModelData::Model aModel;
if (!ModelData::ModelReader().Read (aSource, aModel)) {
cerr << "Failed to read the file " << aSource << endl;
return 1;
}
// Explore B-Rep representation of model parts
ShapeExplorer aVisitor;
aModel.Accept (aVisitor);
return 0;
}