Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:13

0001 // Copyright (c) 2013 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 _BRepMesh_DataStructureOfDelaun_HeaderFile
0015 #define _BRepMesh_DataStructureOfDelaun_HeaderFile
0016 
0017 #include <Standard_Transient.hxx>
0018 #include <BRepMesh_VertexTool.hxx>
0019 
0020 class BRepMesh_Edge;
0021 
0022 //! Describes the data structure necessary for the mesh algorithms in 
0023 //! two dimensions plane or on surface by meshing in UV space.
0024 class BRepMesh_DataStructureOfDelaun : public Standard_Transient
0025 {
0026 public:
0027 
0028   //! Constructor.
0029   //! @param theAllocator memory allocator to be used by internal structures.
0030   //! @param theReservedNodeSize presumed number of nodes in this mesh.
0031   Standard_EXPORT BRepMesh_DataStructureOfDelaun(
0032     const Handle(NCollection_IncAllocator)& theAllocator,
0033     const Standard_Integer                  theReservedNodeSize = 100);
0034 
0035 
0036 
0037 public: //! @name API for accessing mesh nodes.
0038 
0039   //! Returns number of nodes.
0040   Standard_Integer NbNodes() const
0041   {
0042     return myNodes->Extent();
0043   }
0044 
0045 
0046   //! Adds node to the mesh if it is not already in the mesh.
0047   //! @param theNode node to be added to the mesh.
0048   //! @param isForceAdd adds the given node to structure without 
0049   //! checking on coincidence with other nodes.
0050   //! @return index of the node in the structure.
0051   Standard_EXPORT Standard_Integer AddNode(
0052     const BRepMesh_Vertex& theNode,
0053     const Standard_Boolean isForceAdd = Standard_False);
0054 
0055   //! Finds the index of the given node.
0056   //! @param theNode node to find.
0057   //! @return index of the given element of zero if node is not in the mesh.
0058   Standard_Integer IndexOf(const BRepMesh_Vertex& theNode)
0059   {
0060     return myNodes->FindIndex(theNode);
0061   }
0062 
0063   //! Get node by the index.
0064   //! @param theIndex index of a node.
0065   //! @return node with the given index.
0066   const BRepMesh_Vertex& GetNode(const Standard_Integer theIndex)
0067   {
0068     return myNodes->FindKey(theIndex);
0069   }
0070 
0071   //! Alias for GetNode.
0072   const BRepMesh_Vertex& operator ()(const Standard_Integer theIndex)
0073   {
0074     return GetNode(theIndex);
0075   }
0076 
0077   //! Substitutes the node with the given index by new one.
0078   //! @param theIndex index of node to be substituted.
0079   //! @param theNewNode substituting node.
0080   //! @return FALSE in case if new node is already in the structure, TRUE elsewhere.
0081   Standard_EXPORT Standard_Boolean SubstituteNode(
0082     const Standard_Integer theIndex,
0083     const BRepMesh_Vertex& theNewNode);
0084 
0085   //! Removes node from the mesh in case if it has no connected links 
0086   //! and its type is Free.
0087   //! @param theIndex index of node to be removed.
0088   //! @param isForce if TRUE node will be removed even if movability
0089   //! is not Free.
0090   void RemoveNode(const Standard_Integer theIndex,
0091                   const Standard_Boolean isForce = Standard_False)
0092   {
0093     if (isForce || myNodes->FindKey(theIndex).Movability() == BRepMesh_Free)
0094     {
0095       if (LinksConnectedTo(theIndex).Extent()==0)
0096         myNodes->DeleteVertex(theIndex);
0097     }
0098   }
0099 
0100   //! Get list of links attached to the node with the given index.
0101   //! @param theIndex index of node whose links should be retrieved.
0102   //! @return list of links attached to the node.
0103   const IMeshData::ListOfInteger& LinksConnectedTo(
0104     const Standard_Integer theIndex) const
0105   {
0106     return linksConnectedTo(theIndex);
0107   }
0108 
0109 
0110 public: //! @name API for accessing mesh links.
0111 
0112   //! Returns number of links.
0113   Standard_Integer NbLinks() const
0114   {
0115     return myLinks.Extent();
0116   }
0117 
0118   //! Adds link to the mesh if it is not already in the mesh.
0119   //! @param theLink link to be added to the mesh.
0120   //! @return index of the link in the structure.
0121   Standard_EXPORT Standard_Integer AddLink(const BRepMesh_Edge& theLink);
0122 
0123   //! Finds the index of the given link.
0124   //! @param theLink link to find.
0125   //! @return index of the given element of zero if link is not in the mesh.
0126   Standard_Integer IndexOf(const BRepMesh_Edge& theLink) const
0127   {
0128     return myLinks.FindIndex(theLink);
0129   }
0130 
0131   //! Get link by the index.
0132   //! @param theIndex index of a link.
0133   //! @return link with the given index.
0134   const BRepMesh_Edge& GetLink(const Standard_Integer theIndex)
0135   {
0136     return myLinks.FindKey(theIndex);
0137   }
0138 
0139   //! Returns map of indices of links registered in mesh.
0140   const IMeshData::MapOfInteger& LinksOfDomain() const
0141   {
0142     return myLinksOfDomain;
0143   }
0144 
0145   //! Substitutes the link with the given index by new one.
0146   //! @param theIndex index of link to be substituted.
0147   //! @param theNewLink substituting link.
0148   //! @return FALSE in case if new link is already in the structure, TRUE elsewhere.
0149   Standard_EXPORT Standard_Boolean SubstituteLink(const Standard_Integer theIndex,
0150                                                   const BRepMesh_Edge&   theNewLink);
0151 
0152   //! Removes link from the mesh in case if it has no connected elements 
0153   //! and its type is Free.
0154   //! @param theIndex index of link to be removed.
0155   //! @param isForce if TRUE link will be removed even if movability
0156   //! is not Free.
0157   Standard_EXPORT void RemoveLink(const Standard_Integer theIndex,
0158                                   const Standard_Boolean isForce = Standard_False);
0159 
0160   //! Returns indices of elements connected to the link with the given index.
0161   //! @param theLinkIndex index of link whose data should be retrieved.
0162   //! @return indices of elements connected to the link.
0163   const BRepMesh_PairOfIndex& ElementsConnectedTo(
0164     const Standard_Integer theLinkIndex) const
0165   {
0166     return myLinks.FindFromIndex(theLinkIndex);
0167   }
0168 
0169 
0170 
0171 public: //! @name API for accessing mesh elements.
0172 
0173   //! Returns number of links.
0174   Standard_Integer NbElements() const
0175   {
0176     return myElements.Size();
0177   }
0178 
0179   //! Adds element to the mesh if it is not already in the mesh.
0180   //! @param theElement element to be added to the mesh.
0181   //! @return index of the element in the structure.
0182   Standard_EXPORT Standard_Integer AddElement(const BRepMesh_Triangle& theElement);
0183 
0184   //! Get element by the index.
0185   //! @param theIndex index of an element.
0186   //! @return element with the given index.
0187   const BRepMesh_Triangle& GetElement(const Standard_Integer theIndex)
0188   {
0189     return myElements.ChangeValue(theIndex - 1);
0190   }
0191 
0192   //! Returns map of indices of elements registered in mesh.
0193   const IMeshData::MapOfInteger& ElementsOfDomain() const
0194   {
0195     return myElementsOfDomain;
0196   }
0197 
0198   //! Substitutes the element with the given index by new one.
0199   //! @param theIndex index of element to be substituted.
0200   //! @param theNewLink substituting element.
0201   //! @return FALSE in case if new element is already in the structure, TRUE elsewhere.
0202   Standard_EXPORT Standard_Boolean SubstituteElement(const Standard_Integer   theIndex,
0203                                                      const BRepMesh_Triangle& theNewElement);
0204 
0205   //! Removes element from the mesh.
0206   //! @param theIndex index of element to be removed.
0207   Standard_EXPORT void RemoveElement(const Standard_Integer theIndex);
0208 
0209   //! Returns indices of nodes forming the given element.
0210   //! @param theElement element which nodes should be retrieved.
0211   //! @param[out] theNodes nodes of the given element.
0212   Standard_EXPORT void ElementNodes(
0213     const BRepMesh_Triangle& theElement,
0214     Standard_Integer         (&theNodes)[3]);
0215 
0216   Standard_EXPORT void Dump(Standard_CString theFileNameStr);
0217 
0218 
0219 
0220 public: //! @name Auxiliary API
0221 
0222   //! Dumps information about this structure.
0223   //! @param theStream stream to be used for dump.
0224   Standard_EXPORT void Statistics(Standard_OStream& theStream) const;
0225   
0226   //! Returns memory allocator used by the structure.
0227   const Handle(NCollection_IncAllocator)& Allocator() const
0228   {
0229     return myAllocator;
0230   }
0231 
0232   //! Gives the data structure for initialization of cell size and tolerance.
0233   const Handle(BRepMesh_VertexTool)& Data()
0234   {
0235     return myNodes;
0236   }
0237 
0238   //! Removes all elements.
0239   Standard_EXPORT void ClearDomain();
0240 
0241   //! Substitutes deleted items by the last one from corresponding map 
0242   //! to have only non-deleted elements, links or nodes in the structure.
0243   void ClearDeleted()
0244   {
0245     clearDeletedLinks();
0246     clearDeletedNodes();
0247   }
0248 
0249   DEFINE_STANDARD_RTTIEXT(BRepMesh_DataStructureOfDelaun, Standard_Transient)
0250 
0251 private: 
0252 
0253   //! Get list of links attached to the node with the given index.
0254   //! @param theIndex index of node whose links should be retrieved.
0255   //! @return list of links attached to the node.
0256   IMeshData::ListOfInteger& linksConnectedTo(
0257     const Standard_Integer theIndex) const
0258   {
0259     return (IMeshData::ListOfInteger&)myNodeLinks.Find(theIndex);
0260   }
0261 
0262   //! Substitutes deleted links by the last one from corresponding map 
0263   //! to have only non-deleted links in the structure.
0264   Standard_EXPORT void clearDeletedLinks();
0265 
0266   //! Substitutes deleted nodes by the last one from corresponding map 
0267   //! to have only non-deleted nodes in the structure.
0268   Standard_EXPORT void clearDeletedNodes();
0269 
0270   //! Cleans dependent structures from the given link.
0271   //! @param theIndex index of link in the data structure.
0272   //! @param theLink reference to the link to avoid double accessing 
0273   //! to map of links.
0274   void cleanLink(const Standard_Integer theIndex,
0275                  const BRepMesh_Edge&   theLink);
0276 
0277   //! Cleans dependent structures from the given element.
0278   //! @param theIndex index of element in the data structure.
0279   //! @param theElement reference to the element to avoid double accessing 
0280   //! to map of elements.
0281   void cleanElement(const Standard_Integer   theIndex,
0282                     const BRepMesh_Triangle& theElement);
0283 
0284   //! Removes element index from the given pair. Used by cleanElement.
0285   //! @param theIndex index of element to be removed.
0286   //! @param thePair pair of elements to be cleaned.
0287   void removeElementIndex(const Standard_Integer theIndex,
0288                           BRepMesh_PairOfIndex&  thePair);
0289 
0290 
0291 private:
0292 
0293   Handle(NCollection_IncAllocator)      myAllocator;
0294   Handle(BRepMesh_VertexTool)           myNodes;
0295   IMeshData::DMapOfIntegerListOfInteger myNodeLinks;
0296   IMeshData::IDMapOfLink                myLinks;
0297   IMeshData::ListOfInteger              myDelLinks;
0298   IMeshData::VectorOfElements           myElements;
0299   IMeshData::MapOfInteger               myElementsOfDomain;
0300   IMeshData::MapOfInteger               myLinksOfDomain;
0301 };
0302 
0303 #endif