File indexing completed on 2026-09-16 09:18:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _RWMesh_TriangulationReader_HeaderFile
0015 #define _RWMesh_TriangulationReader_HeaderFile
0016
0017 #include <Poly_Triangulation.hxx>
0018 #include <RWMesh_CoordinateSystemConverter.hxx>
0019
0020 #include <mutex>
0021
0022 class OSD_FileSystem;
0023 class RWMesh_TriangulationSource;
0024
0025
0026 class RWMesh_TriangulationReader : public Standard_Transient
0027 {
0028 DEFINE_STANDARD_RTTIEXT(RWMesh_TriangulationReader, Standard_Transient)
0029 public:
0030 struct LoadingStatistic
0031 {
0032 LoadingStatistic()
0033 : ExpectedNodesNb(0),
0034 LoadedNodesNb(0),
0035 ExpectedTrianglesNb(0),
0036 DegeneratedTrianglesNb(0),
0037 LoadedTrianglesNb(0)
0038 {
0039 }
0040
0041 void Reset()
0042 {
0043 ExpectedNodesNb = 0;
0044 LoadedNodesNb = 0;
0045 ExpectedTrianglesNb = 0;
0046 DegeneratedTrianglesNb = 0;
0047 LoadedTrianglesNb = 0;
0048 }
0049
0050 Standard_EXPORT void PrintStatistic(const TCollection_AsciiString& thePrefix = "") const;
0051
0052 int ExpectedNodesNb;
0053 int LoadedNodesNb;
0054 int ExpectedTrianglesNb;
0055 int DegeneratedTrianglesNb;
0056 int LoadedTrianglesNb;
0057 };
0058
0059
0060 Standard_EXPORT RWMesh_TriangulationReader();
0061
0062
0063 Standard_EXPORT ~RWMesh_TriangulationReader() override;
0064
0065
0066 const TCollection_AsciiString& FileName() const { return myFileName; }
0067
0068
0069 void SetFileName(const TCollection_AsciiString& theFileName) { myFileName = theFileName; }
0070
0071
0072 const RWMesh_CoordinateSystemConverter& CoordinateSystemConverter() const
0073 {
0074 return myCoordSysConverter;
0075 }
0076
0077
0078 void SetCoordinateSystemConverter(const RWMesh_CoordinateSystemConverter& theConverter)
0079 {
0080 myCoordSysConverter = theConverter;
0081 }
0082
0083
0084 bool IsDoublePrecision() const { return myIsDoublePrecision; }
0085
0086
0087 void SetDoublePrecision(bool theIsDouble) { myIsDoublePrecision = theIsDouble; }
0088
0089
0090
0091 bool ToSkipDegenerates() const { return myToSkipDegenerateTris; }
0092
0093
0094 void SetToSkipDegenerates(const bool theToSkip) { myToSkipDegenerateTris = theToSkip; }
0095
0096
0097 bool ToPrintDebugMessages() const { return myToPrintDebugMessages; }
0098
0099
0100 void SetToPrintDebugMessages(const bool theToPrint) { myToPrintDebugMessages = theToPrint; }
0101
0102
0103
0104 void StartStatistic()
0105 {
0106 if (myLoadingStatistic)
0107 {
0108 myLoadingStatistic->Reset();
0109 }
0110 else
0111 {
0112 myLoadingStatistic = new LoadingStatistic();
0113 }
0114 }
0115
0116
0117
0118 void StopStatistic()
0119 {
0120 if (myLoadingStatistic)
0121 {
0122 delete myLoadingStatistic;
0123 myLoadingStatistic = nullptr;
0124 }
0125 }
0126
0127
0128
0129
0130 void PrintStatistic() const
0131 {
0132 if (myLoadingStatistic)
0133 {
0134 myLoadingStatistic->PrintStatistic(TCollection_AsciiString("[Mesh reader. File '")
0135 + myFileName + "']. ");
0136 }
0137 }
0138
0139
0140 Standard_EXPORT bool Load(const occ::handle<RWMesh_TriangulationSource>& theSourceMesh,
0141 const occ::handle<Poly_Triangulation>& theDestMesh,
0142 const occ::handle<OSD_FileSystem>& theFileSystem) const;
0143
0144 protected:
0145
0146 Standard_EXPORT virtual bool load(const occ::handle<RWMesh_TriangulationSource>& theSourceMesh,
0147 const occ::handle<Poly_Triangulation>& theDestMesh,
0148 const occ::handle<OSD_FileSystem>& theFileSystem) const = 0;
0149
0150
0151 Standard_EXPORT virtual bool finalizeLoading(
0152 const occ::handle<RWMesh_TriangulationSource>& theSourceMesh,
0153 const occ::handle<Poly_Triangulation>& theDestMesh) const;
0154
0155 protected:
0156
0157
0158
0159
0160
0161 virtual bool setNbPositionNodes(const occ::handle<Poly_Triangulation>& theMesh,
0162 int theNbNodes,
0163 bool theToCopyData = false) const
0164 {
0165 if (theNbNodes <= 0)
0166 {
0167 return false;
0168 }
0169 theMesh->ResizeNodes(theNbNodes, theToCopyData);
0170 return true;
0171 }
0172
0173
0174
0175
0176
0177 virtual void setNodePosition(const occ::handle<Poly_Triangulation>& theMesh,
0178 int theIndex,
0179 const gp_Pnt& thePnt) const
0180 {
0181 theMesh->SetNode(theIndex, thePnt);
0182 }
0183
0184
0185
0186
0187
0188 virtual bool setNbUVNodes(const occ::handle<Poly_Triangulation>& theMesh, int theNbNodes) const
0189 {
0190 if (theNbNodes <= 0 || theMesh->NbNodes() != theNbNodes)
0191 {
0192 return false;
0193 }
0194 theMesh->AddUVNodes();
0195 return true;
0196 }
0197
0198
0199
0200
0201
0202 virtual void setNodeUV(const occ::handle<Poly_Triangulation>& theMesh,
0203 int theIndex,
0204 const gp_Pnt2d& theUV) const
0205 {
0206 theMesh->SetUVNode(theIndex, theUV);
0207 }
0208
0209
0210
0211
0212
0213 virtual bool setNbNormalNodes(const occ::handle<Poly_Triangulation>& theMesh,
0214 int theNbNodes) const
0215 {
0216 if (theNbNodes <= 0 || theMesh->NbNodes() != theNbNodes)
0217 {
0218 return false;
0219 }
0220 theMesh->AddNormals();
0221 return true;
0222 }
0223
0224
0225
0226
0227
0228 virtual void setNodeNormal(const occ::handle<Poly_Triangulation>& theMesh,
0229 int theIndex,
0230 const NCollection_Vec3<float>& theNormal) const
0231 {
0232 theMesh->SetNormal(theIndex, theNormal);
0233 }
0234
0235
0236
0237
0238
0239
0240 virtual bool setNbTriangles(const occ::handle<Poly_Triangulation>& theMesh,
0241 int theNbTris,
0242 bool theToCopyData = false) const
0243 {
0244 if (theNbTris >= 1)
0245 {
0246 theMesh->ResizeTriangles(theNbTris, theToCopyData);
0247 return true;
0248 }
0249 return false;
0250 }
0251
0252
0253
0254
0255
0256
0257
0258
0259 virtual int setTriangle(const occ::handle<Poly_Triangulation>& theMesh,
0260 int theIndex,
0261 const Poly_Triangle& theTriangle) const
0262 {
0263 if (theTriangle.Value(1) < 1 || theTriangle.Value(1) > theMesh->NbNodes()
0264 || theTriangle.Value(2) < 1 || theTriangle.Value(2) > theMesh->NbNodes()
0265 || theTriangle.Value(3) < 1 || theTriangle.Value(3) > theMesh->NbNodes())
0266 {
0267 return 0;
0268 }
0269 if (myToSkipDegenerateTris
0270 && (theTriangle.Value(1) == theTriangle.Value(2)
0271 || theTriangle.Value(1) == theTriangle.Value(3)
0272 || theTriangle.Value(2) == theTriangle.Value(3)))
0273 {
0274 return -1;
0275 }
0276 theMesh->SetTriangle(theIndex, theTriangle);
0277 return 1;
0278 }
0279
0280
0281
0282
0283
0284
0285 Standard_EXPORT virtual bool setNbEdges(const occ::handle<Poly_Triangulation>& theMesh,
0286 const int theNbEdges,
0287 const bool theToCopyData = false) const;
0288
0289
0290
0291
0292
0293
0294
0295 Standard_EXPORT virtual int setEdge(const occ::handle<Poly_Triangulation>& theMesh,
0296 const int theIndex,
0297 const int theEdge) const;
0298
0299 protected:
0300 RWMesh_CoordinateSystemConverter myCoordSysConverter;
0301
0302 TCollection_AsciiString myFileName;
0303 mutable std::mutex myMutex;
0304 mutable LoadingStatistic* myLoadingStatistic;
0305 bool myIsDoublePrecision;
0306 bool myToSkipDegenerateTris;
0307 bool myToPrintDebugMessages;
0308
0309 };
0310
0311 #endif