0028639: Improve performance of the IntPolyh_MaillageAffinage algorithm
[occt.git] / src / IntPolyh / IntPolyh_Triangle.hxx
CommitLineData
42cf5bc1 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 <Standard.hxx>
21#include <Standard_DefineAlloc.hxx>
22#include <Standard_Handle.hxx>
23
24#include <Standard_Integer.hxx>
25#include <Standard_Real.hxx>
68b07699 26#include <Bnd_Box.hxx>
42cf5bc1 27#include <IntPolyh_ArrayOfPoints.hxx>
28#include <IntPolyh_ArrayOfTriangles.hxx>
29#include <IntPolyh_ArrayOfEdges.hxx>
42cf5bc1 30class Adaptor3d_HSurface;
42cf5bc1 31class IntPolyh_StartPoint;
32
68b07699 33//! The class represents the triangle built from three IntPolyh points
34//! and three IntPolyh edges.
42cf5bc1 35class IntPolyh_Triangle
36{
37public:
38
39 DEFINE_STANDARD_ALLOC
40
68b07699 41 //! Constructor
42 IntPolyh_Triangle() :
43 myHasIntersection(Standard_False),
44 myIsIntersectionPossible(Standard_True),
45 myIsDegenerated(Standard_False),
46 myDeflection(0.0)
47 {
48 myPoints[0] = -1;
49 myPoints[1] = -1;
50 myPoints[2] = -1;
51 myEdges[0] = -1;
52 myEdges[1] = -1;
53 myEdges[2] = -1;
54 myEdgesOrientations[0] = 0;
55 myEdgesOrientations[1] = 0;
56 myEdgesOrientations[2] = 0;
57 }
42cf5bc1 58
68b07699 59 //! Constructor
60 IntPolyh_Triangle(const Standard_Integer thePoint1,
61 const Standard_Integer thePoint2,
62 const Standard_Integer thePoint3)
63 :
64 myHasIntersection(Standard_False),
65 myIsIntersectionPossible(Standard_True),
66 myIsDegenerated(Standard_False),
67 myDeflection(0.0)
68 {
69 myPoints[0] = thePoint1;
70 myPoints[1] = thePoint2;
71 myPoints[2] = thePoint3;
72 myEdges[0] = -1;
73 myEdges[1] = -1;
74 myEdges[2] = -1;
75 myEdgesOrientations[0] = 0;
76 myEdgesOrientations[1] = 0;
77 myEdgesOrientations[2] = 0;
78 }
42cf5bc1 79
68b07699 80 //! Returns the first point
81 Standard_Integer FirstPoint() const
82 {
83 return myPoints[0];
84 }
85 //! Returns the second point
86 Standard_Integer SecondPoint() const
87 {
88 return myPoints[1];
89 }
90 //! Returns the third point
91 Standard_Integer ThirdPoint() const
92 {
93 return myPoints[2];
94 }
95 //! Returns the first edge
96 Standard_Integer FirstEdge() const
97 {
98 return myEdges[0];
99 }
100 //! Returns the orientation of the first edge
101 Standard_Integer FirstEdgeOrientation() const
102 {
103 return myEdgesOrientations[0];
104 }
105 //! Returns the second edge
106 Standard_Integer SecondEdge() const
107 {
108 return myEdges[1];
109 }
110 //! Returns the orientation of the second edge
111 Standard_Integer SecondEdgeOrientation() const
112 {
113 return myEdgesOrientations[1];
114 }
115 //! Returns the third edge
116 Standard_Integer ThirdEdge() const
117 {
118 return myEdges[2];
119 }
120 //! Returns the orientation of the third edge
121 Standard_Integer ThirdEdgeOrientation() const
122 {
123 return myEdgesOrientations[2];
124 }
125 //! Returns the deflection of the triangle
126 Standard_Real Deflection() const
127 {
128 return myDeflection;
129 }
130 //! Returns possibility of the intersection
131 Standard_Boolean IsIntersectionPossible() const
132 {
133 return myIsIntersectionPossible;
134 }
135 //! Returns true if the triangle has interfered the other triangle
136 Standard_Boolean HasIntersection() const
137 {
138 return myHasIntersection;
139 }
140 //! Returns the Degenerated flag
141 Standard_Boolean IsDegenerated() const
142 {
143 return myIsDegenerated;
144 }
145 //! Sets the first point
146 void SetFirstPoint(const Standard_Integer thePoint)
147 {
148 myPoints[0] = thePoint;
149 }
150 //! Sets the second point
151 void SetSecondPoint(const Standard_Integer thePoint)
152 {
153 myPoints[1] = thePoint;
154 }
155 //! Sets the third point
156 void SetThirdPoint(const Standard_Integer thePoint)
157 {
158 myPoints[2] = thePoint;
159 }
160 //! Sets the first edge
161 void SetFirstEdge(const Standard_Integer theEdge,
162 const Standard_Integer theEdgeOrientation)
163 {
164 myEdges[0] = theEdge;
165 myEdgesOrientations[0] = theEdgeOrientation;
166 }
167 //! Sets the second edge
168 void SetSecondEdge(const Standard_Integer theEdge,
169 const Standard_Integer theEdgeOrientation)
170 {
171 myEdges[1] = theEdge;
172 myEdgesOrientations[1] = theEdgeOrientation;
173 }
174 //! Sets the third edge
175 void SetThirdEdge(const Standard_Integer theEdge,
176 const Standard_Integer theEdgeOrientation)
177 {
178 myEdges[2] = theEdge;
179 myEdgesOrientations[2] = theEdgeOrientation;
180 }
181 //! Sets the deflection
182 void SetDeflection(const Standard_Real theDeflection)
183 {
184 myDeflection = theDeflection;
185 }
186 //! Sets the flag of possibility of intersection
187 void SetIntersectionPossible(const Standard_Boolean theIP)
188 {
189 myIsIntersectionPossible = theIP;
190 }
191 //! Sets the flag of intersection
192 void SetIntersection(const Standard_Boolean theInt)
193 {
194 myHasIntersection = theInt;
195 }
196 //! Sets the degenerated flag
197 void SetDegenerated(const Standard_Boolean theDegFlag)
198 {
199 myIsDegenerated = theDegFlag;
200 }
201 //! Gets the edge number by the index
202 Standard_Integer GetEdgeNumber(const Standard_Integer theEdgeIndex) const
203 {
204 return ((theEdgeIndex >= 1 && theEdgeIndex <= 3) ? myEdges[theEdgeIndex - 1] : 0);
205 }
206 //! Sets the edge by the index
207 void SetEdge(const Standard_Integer theEdgeIndex,
208 const Standard_Integer theEdgeNumber)
209 {
210 if (theEdgeIndex >= 1 && theEdgeIndex <= 3) {
211 myEdges[theEdgeIndex - 1] = theEdgeNumber;
212 }
213 }
214 //! Gets the edges orientation by the index
215 Standard_Integer GetEdgeOrientation(const Standard_Integer theEdgeIndex) const
216 {
217 return ((theEdgeIndex >= 1 && theEdgeIndex <= 3) ?
218 myEdgesOrientations[theEdgeIndex - 1] : 0);
219 }
220 //! Sets the edges orientation by the index
221 void SetEdgeOrientation(const Standard_Integer theEdgeIndex,
222 const Standard_Integer theEdgeOrientation)
223 {
224 if (theEdgeIndex >= 1 && theEdgeIndex <= 3) {
225 myEdgesOrientations[theEdgeIndex - 1] = theEdgeOrientation;
226 }
227 }
42cf5bc1 228
68b07699 229 //! Computes the deflection for the triangle
230 Standard_EXPORT Standard_Real ComputeDeflection(const Handle(Adaptor3d_HSurface)& theSurface,
231 const IntPolyh_ArrayOfPoints& thePoints);
42cf5bc1 232
68b07699 233 //! Gets the adjacent triangle
234 Standard_EXPORT Standard_Integer GetNextTriangle(const Standard_Integer theTriangle,
235 const Standard_Integer theEdgeNum,
236 const IntPolyh_ArrayOfEdges& TEdges) const;
42cf5bc1 237
68b07699 238 //! Splits the triangle on two to decrease its deflection
239 Standard_EXPORT void MiddleRefinement(const Standard_Integer theTriangleNumber,
240 const Handle(Adaptor3d_HSurface)& theSurface,
241 IntPolyh_ArrayOfPoints& TPoints,
242 IntPolyh_ArrayOfTriangles& TTriangles,
243 IntPolyh_ArrayOfEdges& TEdges);
42cf5bc1 244
68b07699 245 //! Splits the current triangle and new triangles until the refinement
246 //! criterion is not achieved
247 Standard_EXPORT void MultipleMiddleRefinement(const Standard_Real theRefineCriterion,
248 const Bnd_Box& theBox,
249 const Standard_Integer theTriangleNumber,
250 const Handle(Adaptor3d_HSurface)& theSurface,
251 IntPolyh_ArrayOfPoints& TPoints,
252 IntPolyh_ArrayOfTriangles& TTriangles,
253 IntPolyh_ArrayOfEdges& TEdges);
42cf5bc1 254
68b07699 255 //! Links edges to triangle
256 Standard_EXPORT void LinkEdges2Triangle(const IntPolyh_ArrayOfEdges& TEdges,
257 const Standard_Integer theEdge1,
258 const Standard_Integer theEdge2,
259 const Standard_Integer theEdge3);
42cf5bc1 260
68b07699 261 //! Sets the appropriate edge and orientation for the triangle.
262 Standard_EXPORT void SetEdgeAndOrientation(const IntPolyh_Edge& theEdge,
263 const Standard_Integer theEdgeIndex);
42cf5bc1 264
68b07699 265 //! Returns the bounding box of the triangle.
266 Standard_EXPORT const Bnd_Box& BoundingBox(const IntPolyh_ArrayOfPoints& thePoints);
42cf5bc1 267
68b07699 268 //! Dumps the contents of the triangle.
269 Standard_EXPORT void Dump (const Standard_Integer v) const;
42cf5bc1 270
68b07699 271protected:
42cf5bc1 272
68b07699 273private:
42cf5bc1 274
68b07699 275 Standard_Integer myPoints[3];
276 Standard_Integer myEdges[3];
277 Standard_Integer myEdgesOrientations[3];
278 Standard_Boolean myHasIntersection:1;
279 Standard_Boolean myIsIntersectionPossible:1;
280 Standard_Boolean myIsDegenerated:1;
281 Standard_Real myDeflection;
282 Bnd_Box myBox;
42cf5bc1 283
284};
285
42cf5bc1 286#endif // _IntPolyh_Triangle_HeaderFile