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