8 #include "../include/STEPFilter.h"
13 #include <QInputDialog>
23 #include "BRepBuilderAPI_MakeFace.hxx"
24 #include "BRepBuilderAPI_MakePolygon.hxx"
25 #include "BRepBuilderAPI_MakeSolid.hxx"
26 #include "BRepBuilderAPI_Sewing.hxx"
27 #include "BRepMesh_FastDiscret.hxx"
28 #include "BRepMesh_IncrementalMesh.hxx"
29 #include "BRepTools.hxx"
30 #include "BRep_Builder.hxx"
31 #include "IFSelect_PrintCount.hxx"
32 #include "IFSelect_ReturnStatus.hxx"
33 #include "Interface_Static.hxx"
34 #include "NCollection_List.hxx"
35 #include "Poly_Triangulation.hxx"
36 #include "STEPControl_Reader.hxx"
37 #include "TColgp_Array1OfPnt.hxx"
38 #include "TopAbs_ShapeEnum.hxx"
40 #include "TopExp_Explorer.hxx"
41 #include "TopTools.hxx"
42 #include "TopTools_ListOfShape.hxx"
44 #include "TopoDS_Compound.hxx"
45 #include "TopoDS_Shell.hxx"
46 #include "TopoDS_Solid.hxx"
51 {TopAbs_COMPOUND,
"TopAbs_COMPOUND"},
52 {TopAbs_COMPSOLID,
"TopAbs_COMPSOLID"},
53 {TopAbs_SOLID,
"TopAbs_SOLID"},
54 {TopAbs_SHELL,
"TopAbs_SHELL"},
55 {TopAbs_FACE,
"TopAbs_FACE"},
56 {TopAbs_WIRE,
"TopAbs_WIRE"},
57 {TopAbs_EDGE,
"TopAbs_EDGE"},
58 {TopAbs_VERTEX,
"TopAbs_VERTEX"},
59 {TopAbs_SHAPE,
"TopAbs_SHAPE"}};
64 QStringList{
"step",
"stp"},
"step",
65 QStringList{
"STEP CAD file (*.step *.stp)"}, QStringList(),
86 QFileInfo fi(fullFilename);
94 linearDeflection = QInputDialog::getDouble(
115 const QString& fullFileName,
116 double linearDeflection,
118 Interface_Static::SetCVal(
"xstep.cascade.unit",
"M");
120 STEPControl_Reader aReader;
121 IFSelect_ReturnStatus aStatus =
122 aReader.ReadFile(qUtf8Printable(fullFileName));
123 if (aStatus != IFSelect_ReturnStatus::IFSelect_RetDone) {
134 int rootCount = aReader.NbRootsForTransfer();
139 CVLog::Print(QString(
"[STEP] Number of root(s): %1").arg(rootCount));
141 for (Standard_Integer n = 1; n <= rootCount; n++) {
142 if (!aReader.TransferRoot(n)) {
144 QString(
"[STEP] Failed to transfer root #%1").arg(n));
148 int transferredRootCount = aReader.TransferRoots();
149 if (transferredRootCount < 1) {
150 CVLog::Warning(
"No root could be transferred from the STEP file.");
154 Standard_Integer shapeCount = aReader.NbShapes();
155 if (shapeCount == 0) {
159 CVLog::Print(QString(
"[STEP] Number of shapes: %1").arg(shapeCount));
161 TopoDS_Shape aShape = aReader.OneShape();
164 BRepMesh_IncrementalMesh incrementalMesh(
165 aShape, linearDeflection,
174 mesh->
setName(
"unnamed - tesselated");
178 unsigned faceCount = 0;
181 unsigned vertCount = 0;
182 TopExp_Explorer expFaces;
183 for (expFaces.Init(aShape, TopAbs_FACE); expFaces.More(); expFaces.Next()) {
184 const TopoDS_Face&
face = TopoDS::Face(expFaces.Current());
187 TopLoc_Location location;
188 Poly_Triangulation facing = BRep_Tool::Triangulation(
face, location);
190 vertCount +=
static_cast<unsigned>(facing.NbNodes());
191 triCount +=
static_cast<unsigned>(facing.NbTriangles());
197 if (vertCount > vertices->
capacity() &&
198 !vertices->
reserve(vertCount + 65536)) {
203 gp_Trsf nodeTransformation = location;
204 TColgp_Array1OfPnt nodes = facing.Nodes();
205 Poly_Array1OfTriangle tri = facing.Triangles();
207 for (
int j = 1; j <= facing.NbTriangles(); j++) {
208 Standard_Integer index1, index2, index3;
209 tri.Value(j).Get(index1, index2, index3);
210 gp_Pnt p1 = nodes.Value(index1).Transformed(nodeTransformation);
211 gp_Pnt p2 = nodes.Value(index2).Transformed(nodeTransformation);
212 gp_Pnt p3 = nodes.Value(index3).Transformed(nodeTransformation);
214 unsigned vertIndexes[3];
215 vertIndexes[0] = vertices->
size();
217 vertIndexes[1] = vertices->
size();
219 vertIndexes[2] = vertices->
size();
222 mesh->
addTriangle(vertIndexes[0], vertIndexes[1], vertIndexes[2]);
229 CVLog::Print(
"[STEP] Number of CAD faces = " + QString::number(faceCount));
230 CVLog::Print(
"[STEP] Number of triangles (after tesselation) = " +
231 QString::number(triCount));
232 CVLog::Print(
"[STEP] Number of vertices (after tesselation) = " +
233 QString::number(vertCount));
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
CC_FILE_ERROR
Typical I/O filter errors.
@ CC_FERR_CANCELED_BY_USER
@ CC_FERR_THIRD_PARTY_LIB_FAILURE
@ CC_FERR_THIRD_PARTY_LIB_EXCEPTION
@ CC_FERR_NOT_ENOUGH_MEMORY
static double s_defaultLinearDeflection
static std::map< TopAbs_ShapeEnum, QString > ShapeTypes
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static bool Print(const char *format,...)
Prints out a formatted message in console.
static constexpr float DEFAULT_PRIORITY
static void SetDefaultLinearDeflection(double value)
Sets the default linear deflection.
CC_FILE_ERROR loadFile(const QString &fullFilename, ccHObject &container, LoadParameters ¶meters) override
Loads one or more entities from a file.
CC_FILE_ERROR importStepFile(ccHObject &container, const QString &fullFilename, double linearDeflection, LoadParameters ¶meters)
Specific loading method.
void showNormals(bool state) override
Sets normals visibility.
Hierarchical CLOUDVIEWER Object.
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
bool computePerTriangleNormals()
Computes per-triangle normals.
bool reserve(std::size_t n)
Reserves the memory to store the vertex indexes (3 per triangle)
void addTriangle(unsigned i1, unsigned i2, unsigned i3)
Adds a triangle to the mesh.
static const unsigned char DefaultMergeDulicateVerticesLevel
Default octree level for the 'mergeDuplicatedVertices' algorithm.
bool mergeDuplicatedVertices(unsigned char octreeLevel=DefaultMergeDulicateVerticesLevel, QWidget *parentWidget=nullptr)
Merges duplicated vertices.
void shrinkToFit()
Removes unused capacity.
unsigned capacity() const override
Returns max capacity.
virtual void setName(const QString &name)
Sets object name.
virtual void setEnabled(bool state)
Sets the "enabled" property.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool reserve(unsigned numberOfPoints) override
Reserves memory for all the active features.
void shrinkToFit()
Removes unused capacity.
void addPoint(const CCVector3 &P)
Adds a 3D point to the database.
unsigned size() const override
unsigned capacity() const
Returns cloud capacity (i.e. reserved size)
std::vector< unsigned int > face
static void error(char *msg)
Generic loading parameters.
QWidget * parentWidget
Parent widget (if any)