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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _IntPolyh_Triangle_HeaderFile
18 #define _IntPolyh_Triangle_HeaderFile
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>
27 //! The class represents the triangle built from three IntPolyh points
28 //! and three IntPolyh edges.
29 class IntPolyh_Triangle
37 myHasIntersection(Standard_False),
38 myIsIntersectionPossible(Standard_True),
39 myIsDegenerated(Standard_False),
48 myEdgesOrientations[0] = 0;
49 myEdgesOrientations[1] = 0;
50 myEdgesOrientations[2] = 0;
54 IntPolyh_Triangle(const Standard_Integer thePoint1,
55 const Standard_Integer thePoint2,
56 const Standard_Integer thePoint3)
58 myHasIntersection(Standard_False),
59 myIsIntersectionPossible(Standard_True),
60 myIsDegenerated(Standard_False),
63 myPoints[0] = thePoint1;
64 myPoints[1] = thePoint2;
65 myPoints[2] = thePoint3;
69 myEdgesOrientations[0] = 0;
70 myEdgesOrientations[1] = 0;
71 myEdgesOrientations[2] = 0;
74 //! Returns the first point
75 Standard_Integer FirstPoint() const
79 //! Returns the second point
80 Standard_Integer SecondPoint() const
84 //! Returns the third point
85 Standard_Integer ThirdPoint() const
89 //! Returns the first edge
90 Standard_Integer FirstEdge() const
94 //! Returns the orientation of the first edge
95 Standard_Integer FirstEdgeOrientation() const
97 return myEdgesOrientations[0];
99 //! Returns the second edge
100 Standard_Integer SecondEdge() const
104 //! Returns the orientation of the second edge
105 Standard_Integer SecondEdgeOrientation() const
107 return myEdgesOrientations[1];
109 //! Returns the third edge
110 Standard_Integer ThirdEdge() const
114 //! Returns the orientation of the third edge
115 Standard_Integer ThirdEdgeOrientation() const
117 return myEdgesOrientations[2];
119 //! Returns the deflection of the triangle
120 Standard_Real Deflection() const
124 //! Returns possibility of the intersection
125 Standard_Boolean IsIntersectionPossible() const
127 return myIsIntersectionPossible;
129 //! Returns true if the triangle has interfered the other triangle
130 Standard_Boolean HasIntersection() const
132 return myHasIntersection;
134 //! Returns the Degenerated flag
135 Standard_Boolean IsDegenerated() const
137 return myIsDegenerated;
139 //! Sets the first point
140 void SetFirstPoint(const Standard_Integer thePoint)
142 myPoints[0] = thePoint;
144 //! Sets the second point
145 void SetSecondPoint(const Standard_Integer thePoint)
147 myPoints[1] = thePoint;
149 //! Sets the third point
150 void SetThirdPoint(const Standard_Integer thePoint)
152 myPoints[2] = thePoint;
154 //! Sets the first edge
155 void SetFirstEdge(const Standard_Integer theEdge,
156 const Standard_Integer theEdgeOrientation)
158 myEdges[0] = theEdge;
159 myEdgesOrientations[0] = theEdgeOrientation;
161 //! Sets the second edge
162 void SetSecondEdge(const Standard_Integer theEdge,
163 const Standard_Integer theEdgeOrientation)
165 myEdges[1] = theEdge;
166 myEdgesOrientations[1] = theEdgeOrientation;
168 //! Sets the third edge
169 void SetThirdEdge(const Standard_Integer theEdge,
170 const Standard_Integer theEdgeOrientation)
172 myEdges[2] = theEdge;
173 myEdgesOrientations[2] = theEdgeOrientation;
175 //! Sets the deflection
176 void SetDeflection(const Standard_Real theDeflection)
178 myDeflection = theDeflection;
180 //! Sets the flag of possibility of intersection
181 void SetIntersectionPossible(const Standard_Boolean theIP)
183 myIsIntersectionPossible = theIP;
185 //! Sets the flag of intersection
186 void SetIntersection(const Standard_Boolean theInt)
188 myHasIntersection = theInt;
190 //! Sets the degenerated flag
191 void SetDegenerated(const Standard_Boolean theDegFlag)
193 myIsDegenerated = theDegFlag;
195 //! Gets the edge number by the index
196 Standard_Integer GetEdgeNumber(const Standard_Integer theEdgeIndex) const
198 return ((theEdgeIndex >= 1 && theEdgeIndex <= 3) ? myEdges[theEdgeIndex - 1] : 0);
200 //! Sets the edge by the index
201 void SetEdge(const Standard_Integer theEdgeIndex,
202 const Standard_Integer theEdgeNumber)
204 if (theEdgeIndex >= 1 && theEdgeIndex <= 3) {
205 myEdges[theEdgeIndex - 1] = theEdgeNumber;
208 //! Gets the edges orientation by the index
209 Standard_Integer GetEdgeOrientation(const Standard_Integer theEdgeIndex) const
211 return ((theEdgeIndex >= 1 && theEdgeIndex <= 3) ?
212 myEdgesOrientations[theEdgeIndex - 1] : 0);
214 //! Sets the edges orientation by the index
215 void SetEdgeOrientation(const Standard_Integer theEdgeIndex,
216 const Standard_Integer theEdgeOrientation)
218 if (theEdgeIndex >= 1 && theEdgeIndex <= 3) {
219 myEdgesOrientations[theEdgeIndex - 1] = theEdgeOrientation;
223 //! Computes the deflection for the triangle
224 Standard_EXPORT Standard_Real ComputeDeflection(const Handle(Adaptor3d_Surface)& theSurface,
225 const IntPolyh_ArrayOfPoints& thePoints);
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;
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);
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);
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);
255 //! Sets the appropriate edge and orientation for the triangle.
256 Standard_EXPORT void SetEdgeAndOrientation(const IntPolyh_Edge& theEdge,
257 const Standard_Integer theEdgeIndex);
259 //! Returns the bounding box of the triangle.
260 Standard_EXPORT const Bnd_Box& BoundingBox(const IntPolyh_ArrayOfPoints& thePoints);
262 //! Dumps the contents of the triangle.
263 Standard_EXPORT void Dump (const Standard_Integer v) const;
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;
280 #endif // _IntPolyh_Triangle_HeaderFile