1 // Created on: 1993-09-23
2 // Created by: Didier PIFFAULT
3 // Copyright (c) 1993-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 _BRepMesh_Triangle_HeaderFile
18 #define _BRepMesh_Triangle_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Macro.hxx>
24 #include <BRepMesh_DegreeOfFreedom.hxx>
27 //! Light weighted structure representing triangle
28 //! of mesh consisting of oriented links.
29 class BRepMesh_Triangle
35 //! Default constructor.
37 : myMovability (BRepMesh_Free)
42 myOrientations[0] = Standard_False;
43 myOrientations[1] = Standard_False;
44 myOrientations[2] = Standard_False;
48 //! @param theEdges array of edges of triangle.
49 //! @param theOrientations array of edge's orientations.
50 //! @param theMovability movability of triangle.
52 const Standard_Integer (&theEdges)[3],
53 const Standard_Boolean (&theOrientations)[3],
54 const BRepMesh_DegreeOfFreedom theMovability)
56 Initialize(theEdges, theOrientations, theMovability);
59 //! Initializes the triangle by the given parameters.
60 //! @param theEdges array of edges of triangle.
61 //! @param theOrientations array of edge's orientations.
62 //! @param theMovability movability of triangle.
63 inline void Initialize(
64 const Standard_Integer (&theEdges)[3],
65 const Standard_Boolean (&theOrientations)[3],
66 const BRepMesh_DegreeOfFreedom theMovability)
68 memcpy(myEdges, theEdges, sizeof(theEdges));
69 memcpy(myOrientations, theOrientations, sizeof(theOrientations));
70 myMovability = theMovability;
73 //! Gets edges with orientations composing the triangle.
74 //! @param[out] theEdges array edges are stored to.
75 //! @param[out] theOrientations array orientations are stored to.
76 inline void Edges(Standard_Integer (&theEdges)[3],
77 Standard_Boolean (&theOrientations)[3]) const
79 memcpy(theEdges, myEdges, sizeof(myEdges));
80 memcpy(theOrientations, myOrientations, sizeof(myOrientations));
83 //! Returns movability of the triangle.
84 inline BRepMesh_DegreeOfFreedom Movability() const
89 //! Sets movability of the triangle.
90 inline void SetMovability(const BRepMesh_DegreeOfFreedom theMovability)
92 myMovability = theMovability;
95 //! Computes a hash code for this triangle, in the range [1, theUpperBound]
96 //! @param theUpperBound the upper bound of the range a computing hash code must be within
97 //! @return a computed hash code, in the range [1, theUpperBound]
98 inline Standard_Integer HashCode (const Standard_Integer theUpperBound) const
100 return ::HashCode (myEdges[0] + myEdges[1] + myEdges[2], theUpperBound);
103 //! Checks for equality with another triangle.
104 //! @param theOther triangle to be checked against this one.
105 //! @return TRUE if equal, FALSE if not.
106 inline Standard_Boolean IsEqual(const BRepMesh_Triangle& theOther) const
108 if (myMovability == BRepMesh_Deleted || theOther.myMovability == BRepMesh_Deleted)
109 return Standard_False;
111 if (myEdges[0] == theOther.myEdges[0] &&
112 myEdges[1] == theOther.myEdges[1] &&
113 myEdges[2] == theOther.myEdges[2])
115 return Standard_True;
118 if (myEdges[0] == theOther.myEdges[1] &&
119 myEdges[1] == theOther.myEdges[2] &&
120 myEdges[2] == theOther.myEdges[0])
122 return Standard_True;
125 if (myEdges[0] == theOther.myEdges[2] &&
126 myEdges[1] == theOther.myEdges[0] &&
127 myEdges[2] == theOther.myEdges[1])
129 return Standard_True;
132 return Standard_False;
135 //! Alias for IsEqual.
136 inline Standard_Boolean operator ==(const BRepMesh_Triangle& theOther) const
138 return IsEqual(theOther);
141 Standard_Integer myEdges[3];
142 Standard_Boolean myOrientations[3];
143 BRepMesh_DegreeOfFreedom myMovability;
146 //! Computes a hash code for the given triangle, in the range [1, theUpperBound]
147 //! @param theTriangle the triangle which hash code is to be computed
148 //! @param theUpperBound the upper bound of the range a computing hash code must be within
149 //! @return a computed hash code, in the range [1, theUpperBound]
150 inline Standard_Integer HashCode (const BRepMesh_Triangle& theTriangle, const Standard_Integer theUpperBound)
152 return theTriangle.HashCode (theUpperBound);