Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-11 10:39:22

0001 // Copyright (c) 2021 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _RWMesh_TriangulationSource_HeaderFile
0015 #define _RWMesh_TriangulationSource_HeaderFile
0016 
0017 #include <Poly_Triangulation.hxx>
0018 #include <NCollection_Array1.hxx>
0019 
0020 class RWMesh_TriangulationReader;
0021 
0022 //! Mesh data wrapper for delayed triangulation loading.
0023 //! Class inherits Poly_Triangulation so that it can be put temporarily into TopoDS_Face within
0024 //! assembly structure.
0025 class RWMesh_TriangulationSource : public Poly_Triangulation
0026 {
0027   DEFINE_STANDARD_RTTIEXT(RWMesh_TriangulationSource, Poly_Triangulation)
0028 public:
0029   //! Constructor.
0030   Standard_EXPORT RWMesh_TriangulationSource();
0031 
0032   //! Destructor.
0033   Standard_EXPORT ~RWMesh_TriangulationSource() override;
0034 
0035   //! Returns reader allowing to read data from the buffer.
0036   const occ::handle<RWMesh_TriangulationReader>& Reader() const { return myReader; }
0037 
0038   //! Sets reader allowing to read data from the buffer.
0039   void SetReader(const occ::handle<RWMesh_TriangulationReader>& theReader) { myReader = theReader; }
0040 
0041   //! Returns number of degenerated triangles collected during data reading.
0042   //! Used for debug statistic purpose.
0043   int DegeneratedTriNb() const { return myStatisticOfDegeneratedTriNb; }
0044 
0045   //! Gets access to number of degenerated triangles to collect them during data reading.
0046   int& ChangeDegeneratedTriNb() { return myStatisticOfDegeneratedTriNb; }
0047 
0048   //! Returns TRUE if triangulation has some geometry.
0049   bool HasGeometry() const override
0050   {
0051     return !myNodes.IsEmpty() && (!myTriangles.IsEmpty() || !myEdges.IsEmpty());
0052   }
0053 
0054   //! Returns the number of edges for this triangulation.
0055   int NbEdges() const { return myEdges.Length(); }
0056 
0057   //! Returns edge at the given index.
0058   //! @param[in] theIndex edge index within [1, NbEdges()] range
0059   //! @return edge node indices, with each node defined within [1, NbNodes()] range
0060   int Edge(int theIndex) const { return myEdges.Value(theIndex); }
0061 
0062   //! Sets an edge.
0063   //! @param[in] theIndex edge index within [1, NbEdges()] range
0064   //! @param[in] theEdge edge node indices, with each node defined within [1, NbNodes()] range
0065   void SetEdge(int theIndex, int theEdge) { myEdges.SetValue(theIndex, theEdge); }
0066 
0067 public: //! @name late-load deferred data interface
0068   //! Returns number of nodes for deferred loading.
0069   //! Note: this is estimated values defined in object header, which might be different from
0070   //! actually loaded values (due to broken header or extra mesh processing). Always check
0071   //! triangulation size of actually loaded data in code to avoid out-of-range issues.
0072   int NbDeferredNodes() const override { return myNbDefNodes; }
0073 
0074   //! Sets number of nodes for deferred loading.
0075   void SetNbDeferredNodes(const int theNbNodes) { myNbDefNodes = theNbNodes; }
0076 
0077   //! Returns number of triangles for deferred loading.
0078   //! Note: this is estimated values defined in object header, which might be different from
0079   //! actually loaded values (due to broken header or extra mesh processing). Always check
0080   //! triangulation size of actually loaded data in code to avoid out-of-range issues.
0081   int NbDeferredTriangles() const override { return myNbDefTriangles; }
0082 
0083   //! Sets number of triangles for deferred loading.
0084   void SetNbDeferredTriangles(const int theNbTris) { myNbDefTriangles = theNbTris; }
0085 
0086   //! Returns an internal array of edges.
0087   //! Edge()/SetEdge() should be used instead in portable code.
0088   NCollection_Array1<int>& InternalEdges() { return myEdges; }
0089 
0090   //! Method resizing an internal array of triangles.
0091   //! @param[in] theNbTriangles  new number of triangles
0092   //! @param[in] theToCopyOld    copy old triangles into the new array
0093   Standard_EXPORT void ResizeEdges(int theNbEdges, bool theToCopyOld);
0094 
0095 protected:
0096   //! Loads triangulation data from deferred storage using specified shared input file system.
0097   Standard_EXPORT bool loadDeferredData(
0098     const occ::handle<OSD_FileSystem>&     theFileSystem,
0099     const occ::handle<Poly_Triangulation>& theDestTriangulation) const override;
0100 
0101 protected:
0102   occ::handle<RWMesh_TriangulationReader> myReader;
0103   NCollection_Array1<int>                 myEdges;
0104   int                                     myNbDefNodes;
0105   int                                     myNbDefTriangles;
0106   mutable int                             myStatisticOfDegeneratedTriNb;
0107 };
0108 
0109 #endif // _RWMesh_TriangulationSource_HeaderFile