4a31d72ab048fff23432597f6eaac3641fa90315
[occt.git] / src / Poly / Poly_CoherentNode.hxx
1 // Created on: 2007-12-08
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef Poly_CoherentNode_HeaderFile
17 #define Poly_CoherentNode_HeaderFile
18
19 #include <gp_XYZ.hxx>
20 #include <Poly_CoherentTriPtr.hxx>
21 #include <Precision.hxx>
22
23 class NCollection_BaseAllocator;
24
25 /**
26  * Node of coherent triangulation. Contains:
27  * <ul>
28  * <li>Coordinates of a 3D point defining the node location</li>
29  * <li>2D point coordinates</li>
30  * <li>List of triangles that use this Node</li>
31  * <li>Integer index, normally the index of the node in the original
32  *     triangulation</li>
33  * </ul>
34  */
35
36 class Poly_CoherentNode : public gp_XYZ 
37 {
38  public:
39   // ---------- PUBLIC METHODS ----------
40
41
42   /**
43    * Empty constructor.
44    */
45   inline Poly_CoherentNode ()
46     : gp_XYZ            (0., 0., 0.),
47       myTriangles       (0L),
48       myIndex           (-1)
49   { myUV[0] = Precision::Infinite(); myUV[1] = Precision::Infinite(); }
50
51   /**
52    * Constructor.
53    */
54   inline Poly_CoherentNode (const gp_XYZ& thePnt)
55     : gp_XYZ            (thePnt),
56       myTriangles       (0L),
57       myIndex           (-1)
58   { myUV[0] = Precision::Infinite(); myUV[1] = Precision::Infinite(); myNormal[0] = 0.f; myNormal[1] = 0.f; myNormal[2] = 0.f; }
59
60   /**
61    * Set the UV coordinates of the Node.
62    */
63   inline void             SetUV         (const Standard_Real theU,
64                                          const Standard_Real theV)
65   { myUV[0] = theU; myUV[1] = theV; }
66
67   /**
68    * Get U coordinate of the Node.
69    */
70   inline Standard_Real    GetU          () const
71   { return myUV[0]; }
72
73   /**
74    * Get V coordinate of the Node.
75    */
76   inline Standard_Real    GetV          () const
77   { return myUV[1]; }
78
79   /**
80    * Define the normal vector in the Node.
81    */
82   Standard_EXPORT void    SetNormal     (const gp_XYZ& theVector);
83
84   /**
85    * Query if the Node contains a normal vector.
86    */
87   inline Standard_Boolean HasNormal     () const
88   { return ((myNormal[0]*myNormal[0] + myNormal[1]*myNormal[1] +
89              myNormal[2]*myNormal[2]) > Precision::Confusion()); }
90
91   /**
92    * Get the stored normal in the node.
93    */
94   inline gp_XYZ           GetNormal    () const
95   { return gp_XYZ (myNormal[0], myNormal[1], myNormal[2]); }
96
97   /**
98    * Set the value of node Index.
99    */
100   inline void             SetIndex     (const Standard_Integer theIndex)
101   { myIndex = theIndex; }
102
103   /**
104    * Get the value of node Index.
105    */
106   inline Standard_Integer GetIndex      () const
107   { return myIndex; }
108
109   /**
110    * Check if this is a free node, i.e., a node without a single
111    * incident triangle.
112    */
113   inline Standard_Boolean IsFreeNode    () const
114   { return myTriangles == 0L; }
115
116   /**
117    * Reset the Node to void.
118    */
119   Standard_EXPORT void  Clear   (const Handle_NCollection_BaseAllocator&);
120
121   /**
122    * Connect a triangle to this Node.
123    */
124   Standard_EXPORT void  AddTriangle
125                                 (const Poly_CoherentTriangle&            theTri,
126                                  const Handle_NCollection_BaseAllocator& theA);
127
128   /**
129    * Disconnect a triangle from this Node.
130    */
131   Standard_EXPORT Standard_Boolean
132                         RemoveTriangle
133                                 (const Poly_CoherentTriangle&            theTri,
134                                  const Handle_NCollection_BaseAllocator& theA);
135
136   /**
137    * Create an iterator of incident triangles.
138    */
139   inline Poly_CoherentTriPtr::Iterator
140                         TriangleIterator () const
141   { return * myTriangles; }
142
143   Standard_EXPORT void  Dump    (Standard_OStream& theStream) const;
144
145 //   /**
146 //    * Destructor.
147 //    */
148 //   Standard_EXPORT virtual ~Poly_CoherentNode ();
149
150
151
152  protected:
153   // ---------- PROTECTED METHODS ----------
154
155
156
157  private:
158   // ---------- PRIVATE FIELDS ----------
159
160   Standard_Real         myUV[2];
161   Poly_CoherentTriPtr   * myTriangles;
162   Standard_Integer      myIndex;
163   Standard_ShortReal    myNormal[3];
164 };
165
166 #endif