#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
-#include <Standard_Macro.hxx>
+#include <Standard_HashUtils.hxx>
#include <BRepMesh_DegreeOfFreedom.hxx>
-class BRepMesh_Triangle {
+
+//! Light weighted structure representing triangle
+//! of mesh consisting of oriented links.
+class BRepMesh_Triangle
+{
public:
DEFINE_STANDARD_ALLOC
+ //! Default constructor.
+ BRepMesh_Triangle()
+ : myMovability (BRepMesh_Free)
+ {
+ myEdges[0] = 0;
+ myEdges[1] = 0;
+ myEdges[2] = 0;
+ myOrientations[0] = Standard_False;
+ myOrientations[1] = Standard_False;
+ myOrientations[2] = Standard_False;
+ }
+
+ //! Constructor.
+ //! @param theEdges array of edges of triangle.
+ //! @param theOrientations array of edge's orientations.
+ //! @param theMovability movability of triangle.
+ BRepMesh_Triangle(
+ const Standard_Integer (&theEdges)[3],
+ const Standard_Boolean (&theOrientations)[3],
+ const BRepMesh_DegreeOfFreedom theMovability)
+ {
+ Initialize(theEdges, theOrientations, theMovability);
+ }
- Standard_EXPORT BRepMesh_Triangle();
-
- Standard_EXPORT BRepMesh_Triangle(const Standard_Integer theEdge1,
- const Standard_Integer theEdge2,
- const Standard_Integer theEdge3,
- const Standard_Boolean theOrientation1,
- const Standard_Boolean theOrientation2,
- const Standard_Boolean theOrientation3,
- const BRepMesh_DegreeOfFreedom isCanMove);
-
- Standard_EXPORT void Initialize(const Standard_Integer theEdge1,
- const Standard_Integer theEdge2,
- const Standard_Integer theEdge3,
- const Standard_Boolean theOrientation1,
- const Standard_Boolean theOrientation2,
- const Standard_Boolean theOrientation3,
- const BRepMesh_DegreeOfFreedom isCanMove) ;
+ //! Initializes the triangle by the given parameters.
+ //! @param theEdges array of edges of triangle.
+ //! @param theOrientations array of edge's orientations.
+ //! @param theMovability movability of triangle.
+ void Initialize(
+ const Standard_Integer (&theEdges)[3],
+ const Standard_Boolean (&theOrientations)[3],
+ const BRepMesh_DegreeOfFreedom theMovability)
+ {
+ memcpy(myEdges, theEdges, sizeof(theEdges));
+ memcpy(myOrientations, theOrientations, sizeof(theOrientations));
+ myMovability = theMovability;
+ }
- Standard_EXPORT void Edges(Standard_Integer& theEdge1,
- Standard_Integer& theEdge2,
- Standard_Integer& theEdge3,
- Standard_Boolean& theOrientation1,
- Standard_Boolean& theOrientation2,
- Standard_Boolean& theOrientation3) const;
+ //! Gets edges with orientations composing the triangle.
+ //! @param[out] theEdges array edges are stored to.
+ //! @param[out] theOrientations array orientations are stored to.
+ void Edges(Standard_Integer (&theEdges)[3],
+ Standard_Boolean (&theOrientations)[3]) const
+ {
+ memcpy(theEdges, myEdges, sizeof(myEdges));
+ memcpy(theOrientations, myOrientations, sizeof(myOrientations));
+ }
- inline BRepMesh_DegreeOfFreedom Movability() const
+ //! Returns movability of the triangle.
+ BRepMesh_DegreeOfFreedom Movability() const
{
return myMovability;
}
- Standard_EXPORT void SetMovability(const BRepMesh_DegreeOfFreedom theMovability) ;
-
- Standard_EXPORT Standard_Integer HashCode(const Standard_Integer theUpper) const;
-
- Standard_EXPORT Standard_Boolean IsEqual(const BRepMesh_Triangle& theOther) const;
+ //! Sets movability of the triangle.
+ void SetMovability(const BRepMesh_DegreeOfFreedom theMovability)
+ {
+ myMovability = theMovability;
+ }
+
+ //! Checks for equality with another triangle.
+ //! @param theOther triangle to be checked against this one.
+ //! @return TRUE if equal, FALSE if not.
+ Standard_Boolean IsEqual(const BRepMesh_Triangle& theOther) const
+ {
+ if (myMovability == BRepMesh_Deleted || theOther.myMovability == BRepMesh_Deleted)
+ return Standard_False;
+
+ if (myEdges[0] == theOther.myEdges[0] &&
+ myEdges[1] == theOther.myEdges[1] &&
+ myEdges[2] == theOther.myEdges[2])
+ {
+ return Standard_True;
+ }
+
+ if (myEdges[0] == theOther.myEdges[1] &&
+ myEdges[1] == theOther.myEdges[2] &&
+ myEdges[2] == theOther.myEdges[0])
+ {
+ return Standard_True;
+ }
+
+ if (myEdges[0] == theOther.myEdges[2] &&
+ myEdges[1] == theOther.myEdges[0] &&
+ myEdges[2] == theOther.myEdges[1])
+ {
+ return Standard_True;
+ }
+
+ return Standard_False;
+ }
+ //! Alias for IsEqual.
Standard_Boolean operator ==(const BRepMesh_Triangle& theOther) const
{
return IsEqual(theOther);
}
-private:
-
- Standard_Integer myEdge1;
- Standard_Integer myEdge2;
- Standard_Integer myEdge3;
- Standard_Boolean myOrientation1;
- Standard_Boolean myOrientation2;
- Standard_Boolean myOrientation3;
+ Standard_Integer myEdges[3];
+ Standard_Boolean myOrientations[3];
BRepMesh_DegreeOfFreedom myMovability;
};
-// Inline functions
-inline Standard_Integer HashCode(const BRepMesh_Triangle& theTriangle,
- const Standard_Integer theUpper)
+namespace std
{
- return theTriangle.HashCode(theUpper);
+ template <>
+ struct hash<BRepMesh_Triangle>
+ {
+ size_t operator()(const BRepMesh_Triangle& theTriangle) const noexcept
+ {
+ int aCombination[3] = { theTriangle.myEdges[0], theTriangle.myEdges[1], theTriangle.myEdges[2] };
+ std::sort(aCombination, aCombination + 3); // Sort the numbers in ascending order
+ return opencascade::hashBytes(aCombination, sizeof(aCombination));
+ }
+ };
}
#endif