Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:38

0001 // Created on: 2007-11-24
0002 // Created by: Alexander GRIGORIEV
0003 // Copyright (c) 2007-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef Poly_CoherentTriangulation_HeaderFile
0017 #define Poly_CoherentTriangulation_HeaderFile
0018 
0019 #include <Poly_Triangulation.hxx>
0020 #include <Poly_CoherentNode.hxx>
0021 #include <Poly_CoherentTriangle.hxx>
0022 #include <Poly_CoherentLink.hxx>
0023 #include <NCollection_Vector.hxx>
0024 
0025 class Poly_CoherentTriangulation;
0026 template <class A> class NCollection_List;
0027 
0028 typedef NCollection_Vector<Poly_CoherentTriangle>::Iterator
0029                                 Poly_BaseIteratorOfCoherentTriangle;
0030 typedef NCollection_Vector<Poly_CoherentNode>::Iterator
0031                                 Poly_BaseIteratorOfCoherentNode;
0032 typedef NCollection_Vector<Poly_CoherentLink>::Iterator
0033                                 Poly_BaseIteratorOfCoherentLink;
0034 
0035 //! Definition of HANDLE object using Standard_DefineHandle.hxx
0036 #include <Standard_Type.hxx>
0037 DEFINE_STANDARD_HANDLE (Poly_CoherentTriangulation, Standard_Transient)
0038 
0039 /**
0040  * Triangulation structure that allows to:
0041  * <ul>
0042  * <li>Store the connectivity of each triangle with up to 3 neighbouring ones and with the corresponding 3rd nodes on them,</li>
0043  * <li>Store the connectivity of each node with all triangles that share this node</li>
0044  * <li>Add nodes and triangles to the structure,</li>
0045  * <li>Find all triangles sharing a single or a couple of nodes</li>
0046  * <li>Remove triangles from structure</li>
0047  * <li>Optionally create Links between pairs of nodes according to the current triangulation.</li>
0048  * <li>Convert from/to Poly_Triangulation structure.</li>
0049  * </ul>
0050  *
0051  * This class is useful for algorithms that need to analyse and/or edit a triangulated mesh -- for example for mesh refining.
0052  * The connectivity model follows the idea that all Triangles in a mesh should have coherent orientation like on a surface of a solid body.
0053  * Connections between more than 2 triangles are not suppoorted.
0054  *
0055  * @section Poly_CoherentTriangulation Architecture
0056  * The data types used in this structure are:
0057  * <ul>
0058  * <li><b>Poly_CoherentNode</b>: Inherits go_XYZ therefore provides the full public API of gp_XYZ.
0059  * Contains references to all incident triangles. You can add new nodes but you cannot remove existing ones.
0060  * However each node that has no referenced triangle is considered as "free" (use the method IsFreeNode() to check this).
0061  * Free nodes are not available to further processing, particularly they are not exported in Poly_Triangulation.
0062  * </li>
0063  * <li><b>Poly_CoherentTriangle</b>: Main data type. Refers three Nodes, three connected Triangles, three opposite (connected) Nodes and three Links.
0064  * If there is boundary then 1, 2 or 3 references to Triangles/connected Nodes/Links are assigned to NULL (for pointers) or -1 (for integer node index).
0065  *
0066  * You can find a triangle by one node using its triangle iterator or by
0067  * two nodes - creating a temporary Poly_CoherentLink and calling the method FindTriangle().
0068  *
0069  * Triangles can be removed but they are never deleted from the containing array. Removed triangles have all nodes equal to -1.
0070  * You can use the method IsEmpty() to check that.
0071  * </li>
0072  * <li><b>Poly_CoherentLink</b>: Auxiliary data type. Normally the array of Links is empty, because for many algorithms it is sufficient to define only Triangles.
0073  * You can explicitly create the Links at least once, calling the method ComputeLinks(). Each Link is oriented couple of Poly_CoherentNode (directed to the ascending Node index).
0074  * It refers two connected triangulated Nodes - on the left and on the right,
0075  * therefore a Poly_CoherentLink instance refers the full set of nodes that constitute a couple of connected Triangles.
0076  * A boundary Link has either the first (left) or the second (right) connected node index equal to -1.
0077  *
0078  * When the array of Links is created, all subsequent calls to AddTriangle and RemoveTriangle try to preserve the connectivity Triangle-Link in addition to the connectivity Triangle-Triangle.
0079  * Particularly, new Links are created by method AddTriangle() and existing ones are removed by method RemoveTriangle(), in each case whenever necessary.
0080  *
0081  * Similarly to Poly_CoherentTriangle, a Link can be removed but not destroyed separately from others.
0082  * Removed Link can be recogniosed using the method IsEmpty(). To destroy all Links, call the method ClearLinks(),
0083  * this method also nullifies Link references in all Triangles.
0084  * </li>
0085  * All objects (except for free Nodes and empty Triangles and Links) can be visited by the corresponding Iterator.
0086  * Direct access is provided only for Nodes (needed to resolve Node indexed commonly used as reference).
0087  * Triangles and Links can be retrieved by their index only internally, the public API provides only references or pointers to C++ objects.
0088  * If you need a direct access to Triangles and Links, you can subclass Poly_CoherentTriangulation and use the protected API for your needs.
0089  *
0090  * Memory management: All data objects are stored in NCollection_Vector containers that prove to be efficient for the performance.
0091  * In addition references to triangles are stored in ring lists, with an instance of such list per Poly_CoherentNode.
0092  * These lists are allocated in a memory allocator that is provided in the constructor of Poly_CoherentTriangulation.
0093  * By default the standard OCCT allocator (aka NCollection_BaseAllocator) is used.
0094  * But if you need to increase the performance you can use NCollection_IncAllocator instead.
0095  * </ul>
0096  */
0097 class Poly_CoherentTriangulation : public Standard_Transient
0098 {
0099  public:
0100   /**
0101    * Subclass Iterator - allows to iterate all triangles skipping those that
0102    * have been removed.
0103    */
0104   class IteratorOfTriangle : public Poly_BaseIteratorOfCoherentTriangle
0105   {
0106   public:
0107     //! Constructor
0108     Standard_EXPORT IteratorOfTriangle
0109                           (const Handle(Poly_CoherentTriangulation)& theTri);
0110     //! Make step
0111     Standard_EXPORT virtual void Next ();
0112   };
0113 
0114   /**
0115    * Subclass Iterator - allows to iterate all nodes skipping the free ones.
0116    */
0117   class IteratorOfNode : public Poly_BaseIteratorOfCoherentNode
0118   {
0119   public:
0120     //! Constructor
0121     Standard_EXPORT IteratorOfNode
0122                         (const Handle(Poly_CoherentTriangulation)& theTri);
0123     //! Make step
0124     Standard_EXPORT virtual void Next ();
0125   };
0126 
0127   /**
0128    * Subclass Iterator - allows to iterate all links skipping invalid ones.
0129    */
0130   class IteratorOfLink : public Poly_BaseIteratorOfCoherentLink
0131   {
0132   public:
0133     //! Constructor
0134     Standard_EXPORT IteratorOfLink
0135                         (const Handle(Poly_CoherentTriangulation)& theTri);
0136     //! Make step
0137     Standard_EXPORT virtual void Next ();
0138   };
0139 
0140   //! Couple of integer indices (used in RemoveDegenerated()).
0141   struct TwoIntegers
0142   {
0143     Standard_Integer myValue[2];
0144     TwoIntegers() {}
0145     TwoIntegers(Standard_Integer i0, Standard_Integer i1) {
0146       myValue[0] = i0; myValue[1] = i1;
0147     }
0148   };
0149 
0150  public:
0151   // ---------- PUBLIC METHODS ----------
0152 
0153 
0154   /**
0155    * Empty constructor.
0156    */
0157   Standard_EXPORT Poly_CoherentTriangulation
0158                 (const Handle(NCollection_BaseAllocator)& theAlloc = 0L);
0159 
0160   /**
0161    * Constructor. It does not create Links, you should call ComputeLinks
0162    * following this constructor if you need these links.
0163    */
0164   Standard_EXPORT Poly_CoherentTriangulation
0165                 (const Handle(Poly_Triangulation)&        theTriangulation,
0166                  const Handle(NCollection_BaseAllocator)& theAlloc = 0L);
0167 
0168   /**
0169    * Destructor.
0170    */
0171   Standard_EXPORT virtual ~Poly_CoherentTriangulation ();
0172 
0173   /**
0174    * Create an instance of Poly_Triangulation from this object.
0175    */
0176   Standard_EXPORT Handle(Poly_Triangulation)
0177                                    GetTriangulation () const;
0178 
0179   /**
0180    * Find and remove degenerated triangles in Triangulation.
0181    * @param theTol
0182    *   Tolerance for the degeneration case. If any two nodes of a triangle have
0183    *   the distance less than this tolerance, this triangle is considered
0184    *   degenerated and therefore removed by this method.
0185    * @param pLstRemovedNode
0186    *   Optional parameter. If defined, then it will receive the list of arrays
0187    *   where the first number is the index of removed node and the second -
0188    *   the index of remaining node to which the mesh was reconnected.
0189    */
0190   Standard_EXPORT Standard_Boolean RemoveDegenerated
0191                         (const Standard_Real             theTol,
0192                          NCollection_List<TwoIntegers> * pLstRemovedNode = 0L);
0193 
0194   /**
0195    * Create a list of free nodes. These nodes may appear as a result of any
0196    * custom mesh decimation or RemoveDegenerated() call. This analysis is
0197    * necessary if you support additional data structures based on the
0198    * triangulation (e.g., edges on the surface boundary).
0199    * @param lstNodes
0200    *   <tt>[out]</tt> List that receives the indices of free nodes.
0201    */
0202   Standard_EXPORT Standard_Boolean GetFreeNodes
0203                         (NCollection_List<Standard_Integer>& lstNodes) const;
0204 
0205   /**
0206    * Query the index of the last node in the triangulation
0207    */
0208   inline Standard_Integer          MaxNode      () const
0209   { return myNodes.Length() - 1; }
0210 
0211   /**
0212    * Query the index of the last triangle in the triangulation
0213    */
0214   inline Standard_Integer          MaxTriangle  () const
0215   { return myTriangles.Length() - 1; }
0216 
0217   /**
0218    * Set the Deflection value as the parameter of the given triangulation.
0219    */
0220   inline void                      SetDeflection(const Standard_Real theDefl)
0221   { myDeflection = theDefl; }
0222 
0223   /**
0224    * Query the Deflection parameter (default value 0. -- if never initialized)
0225    */
0226   inline Standard_Real             Deflection   () const
0227   { return myDeflection; }
0228 
0229   /**
0230    * Initialize a node
0231    * @param thePoint
0232    *   3D Coordinates of the node.
0233    * @param iN
0234    *   Index of the node. If negative (default), the node is added to the
0235    *   end of the current array of nodes.
0236    * @return
0237    *   Index of the added node.
0238    */
0239   Standard_EXPORT Standard_Integer SetNode      (const gp_XYZ&          thePnt,
0240                                                  const Standard_Integer iN= -1);
0241 
0242   /**
0243    * Get the node at the given index 'i'.
0244    */
0245   inline const Poly_CoherentNode&  Node         (const Standard_Integer i) const
0246   { return myNodes.Value(i); }
0247 
0248   /**
0249    * Get the node at the given index 'i'.
0250    */
0251   inline Poly_CoherentNode&        ChangeNode   (const Standard_Integer i) 
0252   { return myNodes.ChangeValue(i); }
0253 
0254   /**
0255    * Query the total number of active nodes (i.e. nodes used by 1 or more
0256    * triangles)
0257    */
0258   Standard_EXPORT Standard_Integer NNodes       () const;
0259 
0260   /**
0261    * Get the triangle at the given index 'i'.
0262    */
0263   inline const Poly_CoherentTriangle&  Triangle (const Standard_Integer i) const
0264   { return myTriangles.Value(i); }
0265 
0266   /**
0267    * Query the total number of active triangles (i.e. triangles that refer
0268    * nodes, non-empty ones)
0269    */
0270   Standard_EXPORT Standard_Integer NTriangles   () const;
0271 
0272   /**
0273    * Query the total number of active Links.
0274    */
0275   Standard_EXPORT Standard_Integer NLinks       () const;  
0276 
0277   /**
0278    * Removal of a single triangle from the triangulation.
0279    */
0280   Standard_EXPORT Standard_Boolean RemoveTriangle(Poly_CoherentTriangle& theTr);
0281 
0282   /**
0283    * Removal of a single link from the triangulation.
0284    */
0285   Standard_EXPORT void             RemoveLink   (Poly_CoherentLink& theLink);
0286 
0287   /**
0288    * Add a triangle to the triangulation.
0289    * @return
0290    *   Pointer to the added triangle instance or NULL if an error occurred.
0291    */
0292   Standard_EXPORT Poly_CoherentTriangle *
0293                                    AddTriangle  (const Standard_Integer iNode0,
0294                                                  const Standard_Integer iNode1,
0295                                                  const Standard_Integer iNode2);
0296 
0297   /**
0298    * Replace nodes in the given triangle.
0299    * @return
0300    *   True if operation succeeded.
0301    */
0302   Standard_EXPORT Standard_Boolean ReplaceNodes
0303                     (Poly_CoherentTriangle& theTriangle,
0304                      const Standard_Integer iNode0,
0305                      const Standard_Integer iNode1,
0306                      const Standard_Integer iNode2);
0307 
0308   /**
0309    * Add a single link to triangulation, based on a triangle and its side index.
0310    * This method does not check for coincidence with already present links.
0311    * @param theTri
0312    *   Triangle that contains the link to be added.
0313    * @param theConn
0314    *   Index of the side (i.e., 0, 1 0r 2) defining the added link.
0315    */
0316   Standard_EXPORT Poly_CoherentLink *
0317                                    AddLink (const Poly_CoherentTriangle& theTri,
0318                                             const Standard_Integer    theConn);
0319 
0320   /**
0321    * Find one or two triangles that share the given couple of nodes.
0322    * @param theLink
0323    *   Link (in fact, just a couple of nodes) on which the triangle is
0324    *   searched.
0325    * @param pTri
0326    *   <tt>[out]</tt> Array of two pointers to triangle. pTri[0] stores the
0327    *   triangle to the left of the link, while pTri[1] stores the one to the
0328    *   right of the link.
0329    * @return
0330    *   True if at least one triangle is found and output as pTri.
0331    */ 
0332   Standard_EXPORT Standard_Boolean FindTriangle
0333                                 (const Poly_CoherentLink&       theLink,
0334                                  const Poly_CoherentTriangle*   pTri[2]) const;
0335 
0336   /**
0337    * (Re)Calculate all links in this Triangulation.
0338    */
0339   Standard_EXPORT Standard_Integer ComputeLinks ();
0340 
0341   /**
0342    * Clear all Links data from the Triangulation data.
0343    */
0344   Standard_EXPORT void             ClearLinks   ();
0345 
0346   /**
0347    * Query the allocator of elements, this allocator can be used for other
0348    * objects 
0349    */
0350   inline const Handle(NCollection_BaseAllocator)&
0351                                 Allocator       () const
0352   {
0353     return myAlloc;
0354   }
0355   /**
0356    * Create a copy of this Triangulation, using the given allocator.
0357    */
0358   Standard_EXPORT Handle(Poly_CoherentTriangulation)  Clone
0359                 (const Handle(NCollection_BaseAllocator)& theAlloc) const;
0360 
0361   /**
0362    * Debugging output.
0363    */
0364   Standard_EXPORT void             Dump         (Standard_OStream&) const;
0365 
0366  protected:
0367   // ---------- PROTECTED METHODS ----------
0368 
0369 
0370 
0371  protected:
0372   // ---------- PROTECTED FIELDS ----------
0373 
0374   NCollection_Vector<Poly_CoherentTriangle> myTriangles;
0375   NCollection_Vector<Poly_CoherentNode>     myNodes;
0376   NCollection_Vector<Poly_CoherentLink>     myLinks;
0377   Handle(NCollection_BaseAllocator)          myAlloc;
0378   Standard_Real                             myDeflection;
0379 
0380  public:
0381 // Declaration of CASCADE RTTI
0382 DEFINE_STANDARD_RTTIEXT(Poly_CoherentTriangulation,Standard_Transient)
0383 
0384   friend class IteratorOfTriangle;
0385   friend class IteratorOfNode;
0386   friend class IteratorOfLink;
0387 };
0388 
0389 #include <Poly_CoherentTriangulation.hxx>
0390 
0391 #endif