0031467: Foundation Classes, OSD_MemInfo - disable reading /proc/%d/status with Emscr...
[occt.git] / src / BRepMesh / BRepMesh_Triangle.hxx
CommitLineData
304c45c8 1// Created on: 1993-09-23
2// Created by: Didier PIFFAULT
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
304c45c8 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
304c45c8 7//
d5f74e42 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
973c2be1 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.
304c45c8 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
304c45c8 16
17#ifndef _BRepMesh_Triangle_HeaderFile
18#define _BRepMesh_Triangle_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_DefineAlloc.hxx>
22#include <Standard_Macro.hxx>
23
24#include <BRepMesh_DegreeOfFreedom.hxx>
25
fc9b36d6 26
27//! Light weighted structure representing triangle
28//! of mesh consisting of oriented links.
29class BRepMesh_Triangle
30{
304c45c8 31public:
32
33 DEFINE_STANDARD_ALLOC
34
fc9b36d6 35 //! Default constructor.
be5c3602 36 BRepMesh_Triangle()
7bd071ed 37 : myMovability (BRepMesh_Free)
fc9b36d6 38 {
7bd071ed 39 myEdges[0] = 0;
40 myEdges[1] = 0;
41 myEdges[2] = 0;
42 myOrientations[0] = Standard_False;
43 myOrientations[1] = Standard_False;
44 myOrientations[2] = Standard_False;
fc9b36d6 45 }
46
47 //! Constructor.
848fa7e3 48 //! @param theEdges array of edges of triangle.
49 //! @param theOrientations array of edge's orientations.
50 //! @param theMovability movability of triangle.
be5c3602 51 BRepMesh_Triangle(
fc9b36d6 52 const Standard_Integer (&theEdges)[3],
53 const Standard_Boolean (&theOrientations)[3],
54 const BRepMesh_DegreeOfFreedom theMovability)
55 {
56 Initialize(theEdges, theOrientations, theMovability);
57 }
304c45c8 58
fc9b36d6 59 //! Initializes the triangle by the given parameters.
848fa7e3 60 //! @param theEdges array of edges of triangle.
61 //! @param theOrientations array of edge's orientations.
62 //! @param theMovability movability of triangle.
fc9b36d6 63 inline void Initialize(
64 const Standard_Integer (&theEdges)[3],
65 const Standard_Boolean (&theOrientations)[3],
66 const BRepMesh_DegreeOfFreedom theMovability)
67 {
7bd071ed 68 memcpy(myEdges, theEdges, sizeof(theEdges));
69 memcpy(myOrientations, theOrientations, sizeof(theOrientations));
fc9b36d6 70 myMovability = theMovability;
71 }
304c45c8 72
fc9b36d6 73 //! Gets edges with orientations composing the triangle.
848fa7e3 74 //! @param[out] theEdges array edges are stored to.
75 //! @param[out] theOrientations array orientations are stored to.
fc9b36d6 76 inline void Edges(Standard_Integer (&theEdges)[3],
77 Standard_Boolean (&theOrientations)[3]) const
78 {
7bd071ed 79 memcpy(theEdges, myEdges, sizeof(myEdges));
80 memcpy(theOrientations, myOrientations, sizeof(myOrientations));
fc9b36d6 81 }
304c45c8 82
fc9b36d6 83 //! Returns movability of the triangle.
304c45c8 84 inline BRepMesh_DegreeOfFreedom Movability() const
85 {
86 return myMovability;
87 }
88
fc9b36d6 89 //! Sets movability of the triangle.
90 inline void SetMovability(const BRepMesh_DegreeOfFreedom theMovability)
91 {
92 myMovability = theMovability;
93 }
2b2be3fb 94
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
fc9b36d6 99 {
2b2be3fb 100 return ::HashCode (myEdges[0] + myEdges[1] + myEdges[2], theUpperBound);
fc9b36d6 101 }
2b2be3fb 102
fc9b36d6 103 //! Checks for equality with another triangle.
848fa7e3 104 //! @param theOther triangle to be checked against this one.
105 //! @return TRUE if equal, FALSE if not.
7bd071ed 106 inline Standard_Boolean IsEqual(const BRepMesh_Triangle& theOther) const
fc9b36d6 107 {
108 if (myMovability == BRepMesh_Deleted || theOther.myMovability == BRepMesh_Deleted)
109 return Standard_False;
110
7bd071ed 111 if (myEdges[0] == theOther.myEdges[0] &&
112 myEdges[1] == theOther.myEdges[1] &&
113 myEdges[2] == theOther.myEdges[2])
fc9b36d6 114 {
115 return Standard_True;
116 }
117
7bd071ed 118 if (myEdges[0] == theOther.myEdges[1] &&
119 myEdges[1] == theOther.myEdges[2] &&
120 myEdges[2] == theOther.myEdges[0])
fc9b36d6 121 {
122 return Standard_True;
123 }
124
7bd071ed 125 if (myEdges[0] == theOther.myEdges[2] &&
126 myEdges[1] == theOther.myEdges[0] &&
127 myEdges[2] == theOther.myEdges[1])
fc9b36d6 128 {
129 return Standard_True;
130 }
131
132 return Standard_False;
133 }
304c45c8 134
fc9b36d6 135 //! Alias for IsEqual.
7bd071ed 136 inline Standard_Boolean operator ==(const BRepMesh_Triangle& theOther) const
304c45c8 137 {
138 return IsEqual(theOther);
139 }
140
7bd071ed 141 Standard_Integer myEdges[3];
142 Standard_Boolean myOrientations[3];
304c45c8 143 BRepMesh_DegreeOfFreedom myMovability;
144};
145
2b2be3fb 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]
150inline Standard_Integer HashCode (const BRepMesh_Triangle& theTriangle, const Standard_Integer theUpperBound)
304c45c8 151{
2b2be3fb 152 return theTriangle.HashCode (theUpperBound);
304c45c8 153}
154
155#endif