Refer to the B-Rep Geometry Exploration Example.
base_explorer.hxx
#ifndef _BaseExplorer_HeaderFile
#define _BaseExplorer_HeaderFile
#include <cadex/ModelData_Axis2Placement2d.hxx>
#include <cadex/ModelData_Curve2d.hxx>
#include <cadex/ModelData_Direction.hxx>
#include <cadex/ModelData_Direction2d.hxx>
#include <cadex/ModelData_Point.hxx>
#include <cadex/ModelData_Point2d.hxx>
#include <cadex/ModelData_ShapeOrientation.hxx>
#include <cadex/ModelData_Surface.hxx>
#include <cadex/ModelData_XY.hxx>
#include <cadex/ModelData_XYZ.hxx>
#include <functional>
#include <iostream>
class BaseExplorer
{
public:
template <typename T>
static void PrintElementary (const T& theGeometry)
{
PrintDomain (theGeometry);
auto& aPosition = theGeometry.Position();
PrintParameter ("Location", aLoc.Coord());
PrintParameter ("Axis", anAxis.Coord());
PrintParameter ("X Direction", aXDir.Coord());
PrintParameter ("Y Direction", aYDir.Coord());
}
template <typename T>
static void PrintElementary2d (const T& theGeometry)
{
PrintDomain (theGeometry);
auto& aPosition = theGeometry.Position();
PrintParameter ("Location", aLoc.Coord());
PrintParameter ("X Direction", aXDir.Coord());
PrintParameter ("Y Direction", aYDir.Coord());
}
static void PrintRange (const char* aName, double aFirstParameter, double aLastParameter)
{
cout << aName << " = [" << aFirstParameter << ", " << aLastParameter << "]; ";
}
{
PrintRange (
"Domain", theCurve.
UMin(), theCurve.
UMax());
}
{
PrintRange (
"Domain", theCurve.
UMin(), theCurve.
UMax());
}
{
PrintRange (
"Domain U", theSurface.
UMin(), theSurface.
UMax());
PrintRange (
"V", theSurface.
VMin(), theSurface.
VMax());
}
static void PrintParameter (ModelData_XYZd thePoint)
{
cout << "(" << thePoint.X() << ", " << thePoint.Y() << ", " << thePoint.Z() << "); ";
}
static void PrintParameter (ModelData_XYd 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); });
});
}
{
cout << "Orientation = ";
switch (theOrientation) {
case ModelData_SO_Forward: cout << "Forward"; break;
case ModelData_SO_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
curve_explorer.hxx
#ifndef _CurveExplorer_HeaderFile
#define _CurveExplorer_HeaderFile
#include <cadex/ModelData_Axis2Placement.hxx>
#include <cadex/ModelData_BezierCurve.hxx>
#include <cadex/ModelData_BSplineCurve.hxx>
#include <cadex/ModelData_Circle.hxx>
#include <cadex/ModelData_Ellipse.hxx>
#include <cadex/ModelData_Hyperbola.hxx>
#include <cadex/ModelData_Line.hxx>
#include <cadex/ModelData_OffsetCurve.hxx>
#include <cadex/ModelData_Parabola.hxx>
#include <cadex/ModelData_TrimmedCurve.hxx>
#include <base_explorer.hxx>
class CurveExplorer : public BaseExplorer
{
public:
{
switch (theCurve.
Type()) {
case ModelData_CT_Line:
PrintLine (static_cast <const ModelData_Line&> (theCurve));
break;
case ModelData_CT_Circle:
PrintCircle (static_cast <const ModelData_Circle&> (theCurve));
break;
case ModelData_CT_Ellipse:
PrintEllipse (static_cast <const ModelData_Ellipse&> (theCurve));
break;
case ModelData_CT_Hyperbola:
PrintHyperbola (static_cast <const ModelData_Hyperbola&> (theCurve));
break;
case ModelData_CT_Parabola:
PrintParabola (static_cast <const ModelData_Parabola&> (theCurve));
break;
case ModelData_CT_Bezier:
PrintBezierCurve (static_cast <const ModelData_BezierCurve&> (theCurve));
break;
case ModelData_CT_BSpline:
PrintBSplineCurve (static_cast <const ModelData_BSplineCurve&> (theCurve));
break;
case ModelData_CT_Offset:
PrintOffsetCurve (static_cast <const ModelData_OffsetCurve&> (theCurve));
break;
case ModelData_CT_Trimmed:
PrintTrimmedCurve (static_cast <const ModelData_TrimmedCurve&> (theCurve));
break;
default:
break;
}
}
{
PrintName ("Line");
PrintDomain (theLine);
PrintParameter ("Location", aLoc.Coord());
PrintParameter ("Direction", aDir.Coord());
}
{
PrintName ("Circle");
double aRadius = theCircle.
Radius();
PrintElementary (theCircle);
PrintParameter ("Radius", aRadius);
}
{
PrintName ("Ellipse");
PrintElementary (theEllipse);
PrintParameter ("Major Radius", aMajorRadius);
PrintParameter ("Minor Radius", aMinorRadius);
}
{
PrintName ("Hyperbola");
PrintElementary (theHyperbola);
PrintParameter ("Major Radius", aMajorRadius);
PrintParameter ("Minor Radius", aMinorRadius);
}
{
PrintName ("Parabola");
double aFocal = theParabola.
Focal();
PrintElementary (theParabola);
PrintParameter ("Focal", aFocal);
}
{
PrintName ("Bezier Curve");
int aDegree = theBezier.
Degree();
PrintDomain (theBezier);
PrintParameter ("Degree", aDegree);
PrintParameter ("Number Of Poles", aNumberOfPoles);
PrintCollection ("Poles", aNumberOfPoles, [&](int i)
{
auto aPole = theBezier.
Pole (i);
PrintParameter (aPole.Coord());
});
PrintCollection ("Weights", aNumberOfPoles, [&](int i)
{
double aWeight = theBezier.
Weight (i);
PrintParameter (aWeight);
});
}
{
PrintName ("BSpline Curve");
int aDegree = theBSpline.
Degree();
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)
{
PrintParameter (aMultiplicity);
});
PrintCollection ("Poles", aNumberOfPoles, [&](int i)
{
auto aPole = theBSpline.
Pole (i);
PrintParameter (aPole.Coord());
});
PrintCollection ("Weights", aNumberOfPoles, [&](int i)
{
double aWeight = theBSpline.
Weight (i);
PrintParameter (aWeight);
});
}
{
PrintName ("Offset Curve");
double anOffset = theOffset.
Offset();
PrintDomain (theOffset);
PrintParameter ("Direction", aDir.Coord());
PrintParameter ("Offset", anOffset);
cout << "Basis Curve = ";
}
{
PrintName ("Trimmed Curve");
PrintDomain (theTrimmed);
cout << "Basis Curve = ";
PrintCurveInfo (theTrimmed.
BasisCurve());
}
};
#endif
pcurve_explorer.hxx
#ifndef _PCurveExplorer_HeaderFile
#define _PCurveExplorer_HeaderFile
#include <base_explorer.hxx>
#include <cadex/ModelData_Axis2Placement.hxx>
#include <cadex/ModelData_BezierCurve2d.hxx>
#include <cadex/ModelData_BSplineCurve2d.hxx>
#include <cadex/ModelData_Circle2d.hxx>
#include <cadex/ModelData_Ellipse2d.hxx>
#include <cadex/ModelData_Hyperbola2d.hxx>
#include <cadex/ModelData_Line2d.hxx>
#include <cadex/ModelData_OffsetCurve2d.hxx>
#include <cadex/ModelData_Parabola2d.hxx>
#include <cadex/ModelData_TrimmedCurve2d.hxx>
class PCurveExplorer : public BaseExplorer
{
public:
{
switch (theCurve.
Type()) {
case ModelData_CT_Line:
PrintLine (static_cast <const ModelData_Line2d&> (theCurve));
break;
case ModelData_CT_Circle:
PrintCircle (static_cast <const ModelData_Circle2d&> (theCurve));
break;
case ModelData_CT_Ellipse:
PrintEllipse (static_cast <const ModelData_Ellipse2d&> (theCurve));
break;
case ModelData_CT_Hyperbola:
PrintHyperbola (static_cast <const ModelData_Hyperbola2d&> (theCurve));
break;
case ModelData_CT_Parabola:
PrintParabola (static_cast <const ModelData_Parabola2d&> (theCurve));
break;
case ModelData_CT_Bezier:
PrintBezierCurve (static_cast <const ModelData_BezierCurve2d&> (theCurve));
break;
case ModelData_CT_BSpline:
PrintBSplineCurve (static_cast <const ModelData_BSplineCurve2d&> (theCurve));
break;
case ModelData_CT_Offset:
PrintOffsetCurve (static_cast <const ModelData_OffsetCurve2d&> (theCurve));
break;
case ModelData_CT_Trimmed:
PrintTrimmedCurve (static_cast <const ModelData_TrimmedCurve2d&> (theCurve));
break;
default:
break;
}
}
{
PrintName ("Line 2d");
PrintDomain (theLine);
PrintParameter ("Location", aLoc.Coord());
PrintParameter ("Direction", aDir.Coord());
}
{
PrintName ("Circle 2d");
double aRadius = theCircle.
Radius();
PrintElementary2d (theCircle);
PrintParameter ("Radius", aRadius);
}
{
PrintName ("Ellipse 2d");
PrintElementary2d (theEllipse);
PrintParameter ("Major Radius", aMajorRadius);
PrintParameter ("Minor Radius", aMinorRadius);
}
{
PrintName ("Hyperbola 2d");
PrintElementary2d (theHyperbola);
PrintParameter ("Major Radius", aMajorRadius);
PrintParameter ("Minor Radius", aMinorRadius);
}
{
PrintName ("Parabola 2d");
double aFocal = theParabola.
Focal();
PrintElementary2d (theParabola);
PrintParameter ("Focal", aFocal);
}
{
PrintName ("Bezier Curve 2d");
int aDegree = theBezier.
Degree();
PrintDomain (theBezier);
PrintParameter ("Degree", aDegree);
PrintParameter ("Number Of Poles", aNumberOfPoles);
PrintCollection ("Poles", aNumberOfPoles, [&](int i)
{
auto aPole = theBezier.
Pole (i);
PrintParameter (aPole.Coord());
});
PrintCollection ("Weights", aNumberOfPoles, [&](int i)
{
double aWeight = theBezier.
Weight (i);
PrintParameter (aWeight);
});
}
{
PrintName ("BSpline Curve 2d");
int aDegree = theBSpline.
Degree();
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)
{
PrintParameter (aMultiplicity);
});
PrintCollection ("Poles", aNumberOfPoles, [&](int i)
{
auto aPole = theBSpline.
Pole (i);
PrintParameter (aPole.Coord());
});
PrintCollection ("Weights", aNumberOfPoles, [&](int i)
{
double aWeight = theBSpline.
Weight (i);
PrintParameter (aWeight);
});
}
{
PrintName ("Offset Curve 2d");
double anOffset = theOffset.
Offset();
PrintDomain (theOffset);
PrintParameter ("Offset", anOffset);
cout << "Basis Curve = ";
PrintPCurveInfo (theOffset.
BasisCurve());
}
{
PrintName ("Trimmed Curve 2d");
PrintDomain (theTrimmed);
cout << "Basis Curve = ";
PrintPCurveInfo (theTrimmed.
BasisCurve());
}
};
#endif
shape_explorer.hxx
#ifndef _ShapeExplorer_HeaderFile
#define _ShapeExplorer_HeaderFile
#include <curve_explorer.hxx>
#include <base_explorer.hxx>
#include <pcurve_explorer.hxx>
#include <surface_explorer.hxx>
#include <cadex/ModelData_Body.hxx>
#include <cadex/ModelData_BodyList.hxx>
#include <cadex/ModelData_BodyType.hxx>
#include <cadex/ModelData_BRepRepresentation.hxx>
#include <cadex/ModelData_Curve.hxx>
#include <cadex/ModelData_Curve2d.hxx>
#include <cadex/ModelData_Edge.hxx>
#include <cadex/ModelData_Face.hxx>
#include <cadex/ModelData_Model.hxx>
#include <cadex/ModelData_Part.hxx>
#include <cadex/ModelData_Shell.hxx>
#include <cadex/ModelData_Surface.hxx>
#include <cadex/ModelData_Vertex.hxx>
#include <cadex/ModelData_Wire.hxx>
#include <array>
#include <functional>
#include <iostream>
#include <unordered_map>
{
protected:
{
if (aBRep) {
cout <<
"Part = \"" << thePart.
Name() <<
"\"" << endl;
ExploreBRep (aBRep);
}
}
private:
{
for (ModelData_BodyList::SizeType i = 0; i < aBodyList.
Size(); ++i) {
cout << "Body " << i << ": " << BodyType (aBody) << endl;
ExploreShape (aBody);
}
}
{
if (theShape.
Type() == ModelData_ST_Face) {
myCurrentFace = ModelData_Face::Cast (theShape);
}
++myNestingLevel;
while (aShapeIt.
HasNext()) {
PrintShape (aShape);
ExploreShape (aShape);
}
if (theShape.
Type() == ModelData_ST_Face) {
}
--myNestingLevel;
}
{
default:
break;
}
return "Undefined";
}
{
PrintTabulation();
switch (theShape.
Type()) {
case ModelData_ST_Solid: cout << "Solid"; break;
case ModelData_ST_Shell: PrintShell (ModelData_Shell::Cast (theShape)); break;
case ModelData_ST_Wire: PrintWire (ModelData_Wire::Cast (theShape)); break;
case ModelData_ST_Face: PrintFace (ModelData_Face::Cast (theShape)); break;
case ModelData_ST_Edge: PrintEdge (ModelData_Edge::Cast (theShape)); break;
case ModelData_ST_Vertex: PrintVertex (ModelData_Vertex::Cast (theShape)); break;
default:
cout << "Undefined"; break;
}
cout << endl;
}
{
PrintName ("Shell");
++myNestingLevel;
--myNestingLevel;
}
{
PrintName ("Wire");
++myNestingLevel;
--myNestingLevel;
}
{
PrintName ("Face");
++myNestingLevel;
cout << endl;
PrintTabulation();
cout << "Surface: ";
SurfaceExplorer::PrintSurface (aSurface);
--myNestingLevel;
}
{
PrintName ("Edge");
++myNestingLevel;
cout << "Degenerated: ";
}
PrintParameter (
"Tolerance", theEdge.
Tolerance());
pair<double, double> aParameters;
cout << endl;
PrintTabulation();
PrintName ("Curve");
PrintRange ("Edge Range", aParameters.first, aParameters.second);
CurveExplorer::PrintCurveInfo (aCurve);
}
if (myCurrentFace) {
pair<double, double> aParameters2d;
aParameters2d.first,
aParameters2d.second);
cout << endl;
PrintTabulation();
PrintName ("PCurve");
PrintRange ("Edge Range", aParameters2d.first, aParameters2d.second);
PCurveExplorer::PrintPCurveInfo (aPCurve);
}
--myNestingLevel;
}
{
PrintName ("Vertex");
PrintParameter ("Tolerance", aTolerance);
PrintParameter ("Location", aLoc.Coord());
}
private:
};
#endif
surface_explorer.hxx
#ifndef _SurfaceExplorer_HeaderFile
#define _SurfaceExplorer_HeaderFile
#include <base_explorer.hxx>
#include <cadex/ModelData_Axis3Placement.hxx>
#include <cadex/ModelData_BezierSurface.hxx>
#include <cadex/ModelData_BSplineSurface.hxx>
#include <cadex/ModelData_ConicalSurface.hxx>
#include <cadex/ModelData_CylindricalSurface.hxx>
#include <cadex/ModelData_OffsetSurface.hxx>
#include <cadex/ModelData_Plane.hxx>
#include <cadex/ModelData_RectangularTrimmedSurface.hxx>
#include <cadex/ModelData_SphericalSurface.hxx>
#include <cadex/ModelData_SurfaceOfLinearExtrusion.hxx>
#include <cadex/ModelData_SurfaceOfRevolution.hxx>
#include <cadex/ModelData_ToroidalSurface.hxx>
class SurfaceExplorer : public BaseExplorer
{
public:
{
switch (theSurface.
Type()) {
case ModelData_ST_Plane:
PrintPlane (static_cast <const ModelData_Plane&> (theSurface));
break;
case ModelData_ST_Cylinder:
PrintCylinder (static_cast <const ModelData_CylindricalSurface&> (theSurface));
break;
case ModelData_ST_Cone:
PrintCone (static_cast <const ModelData_ConicalSurface&> (theSurface));
break;
case ModelData_ST_Sphere:
PrintSphere (static_cast <const ModelData_SphericalSurface&> (theSurface));
break;
case ModelData_ST_Torus:
PrintTorus (static_cast <const ModelData_ToroidalSurface&> (theSurface));
break;
case ModelData_ST_LinearExtrusion:
PrintLinearExtrusion (static_cast <const ModelData_SurfaceOfLinearExtrusion&> (theSurface));
break;
case ModelData_ST_Revolution:
PrintRevolution (static_cast <const ModelData_SurfaceOfRevolution&> (theSurface));
break;
case ModelData_ST_Bezier:
PrintBezierSurface (static_cast <const ModelData_BezierSurface&> (theSurface));
break;
case ModelData_ST_BSpline:
PrintBSplineSurface (static_cast <const ModelData_BSplineSurface&> (theSurface));
break;
case ModelData_ST_Offset:
PrintOffsetSurface (static_cast <const ModelData_OffsetSurface&> (theSurface));
break;
case ModelData_ST_Trimmed:
PrintTrimmedSurface (static_cast <const ModelData_RectangularTrimmedSurface&> (theSurface));
break;
default:
break;
}
}
{
PrintName ("Plane");
PrintElementary (thePlane);
}
{
PrintName ("Cylinder");
double aRadius = theCylinder.
Radius();
PrintElementary (theCylinder);
PrintParameter ("Radius", aRadius);
}
{
PrintName ("Cone");
double aRadius = theCone.
Radius();
PrintElementary (theCone);
PrintParameter ("Radius", aRadius);
PrintParameter ("Semi-Angle", aSemiAngle);
}
{
PrintName ("Sphere");
double aRadius = theSphere.
Radius();
PrintElementary (theSphere);
PrintParameter ("Radius", aRadius);
}
{
PrintName ("Torus");
PrintElementary (theTorus);
PrintParameter ("Major Radius", aMajorRadius);
PrintParameter ("Minor Radius", aMinorRadius);
}
{
PrintName ("Linear Extrusion Surface");
PrintDomain (theLinearExtrusion);
PrintParameter ("Direction", aDir.Coord());
cout << "Basis Curve = ";
CurveExplorer::PrintCurveInfo (theLinearExtrusion.
BasisCurve());
}
{
PrintName ("Revolution Surface");
PrintDomain (theRevolution);
PrintParameter ("Location", aLoc.Coord());
PrintParameter ("Direction", aDir.Coord());
cout << "Basis Curve = ";
CurveExplorer::PrintCurveInfo (theRevolution.BasisCurve());
}
{
PrintName ("Bezier Surface");
int aUDegree = theBezier.
UDegree();
int aVDegree = theBezier.
VDegree();
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.Coord());
});
PrintCollection ("Weights", aNumberOfUPoles, aNumberOfVPoles, [&](int i, int j)
{
double aWeight = theBezier.
Weight (i, j);
PrintParameter (aWeight);
});
}
{
PrintName ("BSpline Surface");
int aUDegree = theBSpline.
UDegree();
int aVDegree = theBSpline.
VDegree();
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)
{
PrintParameter (aUMultiplicity);
});
PrintCollection ("V Multiplicities", aNumberOfVKnots, [&](int i)
{
PrintParameter (aVMultiplicity);
});
PrintCollection ("Poles", aNumberOfUPoles, aNumberOfVPoles, [&](int i, int j)
{
auto aPole = theBSpline.
Pole (i, j);
PrintParameter (aPole.Coord());
});
PrintCollection ("Weights", aNumberOfUPoles, aNumberOfVPoles, [&](int i, int j)
{
double aWeight = theBSpline.
Weight (i, j);
PrintParameter (aWeight);
});
}
{
PrintName ("Offset Surface");
double anOffset = theOffset.
Offset();
PrintDomain (theOffset);
PrintParameter ("Offset", anOffset);
cout << "Basis Surface = ";
}
{
PrintName ("Trimmed Surface");
PrintDomain (theTrimmed);
cout << "Basis Surface = ";
}
};
#endif
main.cxx
#include <shape_explorer.hxx>
#include <cadex/ModelData_ModelReader.hxx>
#include <cadex/LicenseManager_Activate.h>
#include "../../cadex_license.cxx"
int main (int argc, char* argv[])
{
auto aKey = LicenseKey::Value();
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate CAD Exchanger license." << endl;
return 1;
}
if (argc != 2) {
cerr << "Usage: " << argv[0] << " <input_file>, where:" << endl;
cerr << " <input_file> is a name of the XML 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;
}
ShapeExplorer aVisitor;
aModel.Accept (aVisitor);
return 0;
}