0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / IntPolyh / IntPolyh_Triangle.hxx
1 // Created on: 1999-03-05
2 // Created by: Fabrice SERVANT
3 // Copyright (c) 1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _IntPolyh_Triangle_HeaderFile
18 #define _IntPolyh_Triangle_HeaderFile
19
20 #include <Adaptor3d_Surface.hxx>
21 #include <Bnd_Box.hxx>
22 #include <IntPolyh_ArrayOfPoints.hxx>
23 #include <IntPolyh_ArrayOfTriangles.hxx>
24 #include <IntPolyh_ArrayOfEdges.hxx>
25
26
27 //! The class represents the triangle built from three IntPolyh points
28 //! and three IntPolyh edges.
29 class IntPolyh_Triangle 
30 {
31 public:
32
33   DEFINE_STANDARD_ALLOC
34
35   //! Constructor
36   IntPolyh_Triangle() :
37     myHasIntersection(Standard_False),
38     myIsIntersectionPossible(Standard_True),
39     myIsDegenerated(Standard_False),
40     myDeflection(0.0)
41   {
42     myPoints[0] = -1;
43     myPoints[1] = -1;
44     myPoints[2] = -1;
45     myEdges[0] = -1;
46     myEdges[1] = -1;
47     myEdges[2] = -1;
48     myEdgesOrientations[0] = 0;
49     myEdgesOrientations[1] = 0;
50     myEdgesOrientations[2] = 0;
51   }
52
53   //! Constructor
54   IntPolyh_Triangle(const Standard_Integer thePoint1,
55                     const Standard_Integer thePoint2,
56                     const Standard_Integer thePoint3)
57   :
58     myHasIntersection(Standard_False),
59     myIsIntersectionPossible(Standard_True),
60     myIsDegenerated(Standard_False),
61     myDeflection(0.0)
62   {
63     myPoints[0] = thePoint1;
64     myPoints[1] = thePoint2;
65     myPoints[2] = thePoint3;
66     myEdges[0] = -1;
67     myEdges[1] = -1;
68     myEdges[2] = -1;
69     myEdgesOrientations[0] = 0;
70     myEdgesOrientations[1] = 0;
71     myEdgesOrientations[2] = 0;
72   }
73
74   //! Returns the first point
75   Standard_Integer FirstPoint() const
76   {
77     return myPoints[0];
78   }
79   //! Returns the second point
80   Standard_Integer SecondPoint() const
81   {
82     return myPoints[1];
83   }
84   //! Returns the third point
85   Standard_Integer ThirdPoint() const
86   {
87     return myPoints[2];
88   }
89   //! Returns the first edge
90   Standard_Integer FirstEdge() const
91   {
92     return myEdges[0];
93   }
94   //! Returns the orientation of the first edge
95   Standard_Integer FirstEdgeOrientation() const
96   {
97     return myEdgesOrientations[0];
98   }
99   //! Returns the second edge
100   Standard_Integer SecondEdge() const
101   {
102     return myEdges[1];
103   }
104   //! Returns the orientation of the second edge
105   Standard_Integer SecondEdgeOrientation() const
106   {
107     return myEdgesOrientations[1];
108   }
109   //! Returns the third edge
110   Standard_Integer ThirdEdge() const
111   {
112     return myEdges[2];
113   }
114   //! Returns the orientation of the third edge
115   Standard_Integer ThirdEdgeOrientation() const
116   {
117     return myEdgesOrientations[2];
118   }
119   //! Returns the deflection of the triangle
120   Standard_Real Deflection() const
121   {
122     return myDeflection;
123   }
124   //! Returns possibility of the intersection
125   Standard_Boolean IsIntersectionPossible() const
126   {
127     return myIsIntersectionPossible;
128   }
129   //! Returns true if the triangle has interfered the other triangle
130   Standard_Boolean HasIntersection() const
131   {
132     return myHasIntersection;
133   }
134   //! Returns the Degenerated flag
135   Standard_Boolean IsDegenerated() const
136   {
137     return myIsDegenerated;
138   }
139   //! Sets the first point
140   void SetFirstPoint(const Standard_Integer thePoint)
141   {
142     myPoints[0] = thePoint;
143   }
144   //! Sets the second point
145   void SetSecondPoint(const Standard_Integer thePoint)
146   {
147     myPoints[1] = thePoint;
148   }
149   //! Sets the third point
150   void SetThirdPoint(const Standard_Integer thePoint)
151   {
152     myPoints[2] = thePoint;
153   }
154   //! Sets the first edge
155   void SetFirstEdge(const Standard_Integer theEdge,
156                     const Standard_Integer theEdgeOrientation)
157   {
158     myEdges[0] = theEdge;
159     myEdgesOrientations[0] = theEdgeOrientation;
160   }
161   //! Sets the second edge
162   void SetSecondEdge(const Standard_Integer theEdge,
163                      const Standard_Integer theEdgeOrientation)
164   {
165     myEdges[1] = theEdge;
166     myEdgesOrientations[1] = theEdgeOrientation;
167   }
168   //! Sets the third edge
169   void SetThirdEdge(const Standard_Integer theEdge,
170                     const Standard_Integer theEdgeOrientation)
171   {
172     myEdges[2] = theEdge;
173     myEdgesOrientations[2] = theEdgeOrientation;
174   }
175   //! Sets the deflection
176   void SetDeflection(const Standard_Real theDeflection)
177   {
178     myDeflection = theDeflection;
179   }
180   //! Sets the flag of possibility of intersection
181   void SetIntersectionPossible(const Standard_Boolean theIP)
182   {
183     myIsIntersectionPossible = theIP;
184   }
185   //! Sets the flag of intersection
186   void SetIntersection(const Standard_Boolean theInt)
187   {
188     myHasIntersection = theInt;
189   }
190   //! Sets the degenerated flag
191   void SetDegenerated(const Standard_Boolean theDegFlag)
192   {
193     myIsDegenerated = theDegFlag;
194   }
195   //! Gets the edge number by the index
196   Standard_Integer GetEdgeNumber(const Standard_Integer theEdgeIndex) const
197   {
198     return ((theEdgeIndex >= 1 && theEdgeIndex <= 3) ? myEdges[theEdgeIndex - 1] : 0);
199   }
200   //! Sets the edge by the index
201   void SetEdge(const Standard_Integer theEdgeIndex,
202                const Standard_Integer theEdgeNumber)
203   {
204     if (theEdgeIndex >= 1 && theEdgeIndex <= 3) {
205       myEdges[theEdgeIndex - 1] = theEdgeNumber;
206     }
207   }
208   //! Gets the edges orientation by the index
209   Standard_Integer GetEdgeOrientation(const Standard_Integer theEdgeIndex) const
210   {
211     return ((theEdgeIndex >= 1 && theEdgeIndex <= 3) ?
212       myEdgesOrientations[theEdgeIndex - 1] : 0);
213   }
214   //! Sets the edges orientation by the index
215   void SetEdgeOrientation(const Standard_Integer theEdgeIndex,
216                           const Standard_Integer theEdgeOrientation)
217   {
218     if (theEdgeIndex >= 1 && theEdgeIndex <= 3) {
219       myEdgesOrientations[theEdgeIndex - 1] = theEdgeOrientation;
220     }
221   }
222
223   //! Computes the deflection for the triangle
224   Standard_EXPORT Standard_Real ComputeDeflection(const Handle(Adaptor3d_Surface)& theSurface,
225                                                   const IntPolyh_ArrayOfPoints& thePoints);
226
227   //! Gets the adjacent triangle
228   Standard_EXPORT Standard_Integer GetNextTriangle(const Standard_Integer theTriangle,
229                                                    const Standard_Integer theEdgeNum,
230                                                    const IntPolyh_ArrayOfEdges& TEdges) const;
231
232   //! Splits the triangle on two to decrease its deflection
233   Standard_EXPORT void MiddleRefinement(const Standard_Integer theTriangleNumber,
234                                         const Handle(Adaptor3d_Surface)& theSurface,
235                                         IntPolyh_ArrayOfPoints& TPoints,
236                                         IntPolyh_ArrayOfTriangles& TTriangles,
237                                         IntPolyh_ArrayOfEdges& TEdges);
238
239   //! Splits the current triangle and new triangles until the refinement
240   //! criterion is not achieved
241   Standard_EXPORT void MultipleMiddleRefinement(const Standard_Real theRefineCriterion,
242                                                 const Bnd_Box& theBox,
243                                                 const Standard_Integer theTriangleNumber,
244                                                 const Handle(Adaptor3d_Surface)& theSurface,
245                                                 IntPolyh_ArrayOfPoints& TPoints,
246                                                 IntPolyh_ArrayOfTriangles& TTriangles,
247                                                 IntPolyh_ArrayOfEdges& TEdges);
248
249   //! Links edges to triangle
250   Standard_EXPORT void LinkEdges2Triangle(const IntPolyh_ArrayOfEdges& TEdges,
251                                           const Standard_Integer theEdge1,
252                                           const Standard_Integer theEdge2,
253                                           const Standard_Integer theEdge3);
254
255   //! Sets the appropriate edge and orientation for the triangle.
256   Standard_EXPORT void SetEdgeAndOrientation(const IntPolyh_Edge& theEdge,
257                                              const Standard_Integer theEdgeIndex);
258
259   //! Returns the bounding box of the triangle.
260   Standard_EXPORT const Bnd_Box& BoundingBox(const IntPolyh_ArrayOfPoints& thePoints);
261
262   //! Dumps the contents of the triangle.
263   Standard_EXPORT void Dump (const Standard_Integer v) const;
264
265 protected:
266
267 private:
268
269   Standard_Integer myPoints[3];
270   Standard_Integer myEdges[3];
271   Standard_Integer myEdgesOrientations[3];
272   Standard_Boolean myHasIntersection:1;
273   Standard_Boolean myIsIntersectionPossible:1;
274   Standard_Boolean myIsDegenerated:1;
275   Standard_Real myDeflection;
276   Bnd_Box myBox;
277
278 };
279
280 #endif // _IntPolyh_Triangle_HeaderFile