Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-20 08:16:39

0001 // Created on: 1993-09-23
0002 // Created by: Didier PIFFAULT
0003 // Copyright (c) 1993-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _BRepMesh_Triangle_HeaderFile
0018 #define _BRepMesh_Triangle_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_HashUtils.hxx>
0023 
0024 #include <BRepMesh_DegreeOfFreedom.hxx>
0025 
0026 //! Light weighted structure representing triangle
0027 //! of mesh consisting of oriented links.
0028 class BRepMesh_Triangle
0029 {
0030 public:
0031   DEFINE_STANDARD_ALLOC
0032 
0033   //! Default constructor.
0034   BRepMesh_Triangle()
0035       : myMovability(BRepMesh_Free)
0036   {
0037     myEdges[0]        = 0;
0038     myEdges[1]        = 0;
0039     myEdges[2]        = 0;
0040     myOrientations[0] = Standard_False;
0041     myOrientations[1] = Standard_False;
0042     myOrientations[2] = Standard_False;
0043   }
0044 
0045   //! Constructor.
0046   //! @param theEdges array of edges of triangle.
0047   //! @param theOrientations array of edge's orientations.
0048   //! @param theMovability movability of triangle.
0049   BRepMesh_Triangle(const Standard_Integer (&theEdges)[3],
0050                     const Standard_Boolean (&theOrientations)[3],
0051                     const BRepMesh_DegreeOfFreedom theMovability)
0052   {
0053     Initialize(theEdges, theOrientations, theMovability);
0054   }
0055 
0056   //! Initializes the triangle by the given parameters.
0057   //! @param theEdges array of edges of triangle.
0058   //! @param theOrientations array of edge's orientations.
0059   //! @param theMovability movability of triangle.
0060   void Initialize(const Standard_Integer (&theEdges)[3],
0061                   const Standard_Boolean (&theOrientations)[3],
0062                   const BRepMesh_DegreeOfFreedom theMovability)
0063   {
0064     memcpy(myEdges, theEdges, sizeof(theEdges));
0065     memcpy(myOrientations, theOrientations, sizeof(theOrientations));
0066     myMovability = theMovability;
0067   }
0068 
0069   //! Gets edges with orientations composing the triangle.
0070   //! @param[out] theEdges array edges are stored to.
0071   //! @param[out] theOrientations array orientations are stored to.
0072   void Edges(Standard_Integer (&theEdges)[3], Standard_Boolean (&theOrientations)[3]) const
0073   {
0074     memcpy(theEdges, myEdges, sizeof(myEdges));
0075     memcpy(theOrientations, myOrientations, sizeof(myOrientations));
0076   }
0077 
0078   //! Returns movability of the triangle.
0079   BRepMesh_DegreeOfFreedom Movability() const { return myMovability; }
0080 
0081   //! Sets movability of the triangle.
0082   void SetMovability(const BRepMesh_DegreeOfFreedom theMovability) { myMovability = theMovability; }
0083 
0084   //! Checks for equality with another triangle.
0085   //! @param theOther triangle to be checked against this one.
0086   //! @return TRUE if equal, FALSE if not.
0087   Standard_Boolean IsEqual(const BRepMesh_Triangle& theOther) const
0088   {
0089     if (myMovability == BRepMesh_Deleted || theOther.myMovability == BRepMesh_Deleted)
0090       return Standard_False;
0091 
0092     if (myEdges[0] == theOther.myEdges[0] && myEdges[1] == theOther.myEdges[1]
0093         && myEdges[2] == theOther.myEdges[2])
0094     {
0095       return Standard_True;
0096     }
0097 
0098     if (myEdges[0] == theOther.myEdges[1] && myEdges[1] == theOther.myEdges[2]
0099         && myEdges[2] == theOther.myEdges[0])
0100     {
0101       return Standard_True;
0102     }
0103 
0104     if (myEdges[0] == theOther.myEdges[2] && myEdges[1] == theOther.myEdges[0]
0105         && myEdges[2] == theOther.myEdges[1])
0106     {
0107       return Standard_True;
0108     }
0109 
0110     return Standard_False;
0111   }
0112 
0113   //! Alias for IsEqual.
0114   Standard_Boolean operator==(const BRepMesh_Triangle& theOther) const { return IsEqual(theOther); }
0115 
0116   Standard_Integer         myEdges[3];
0117   Standard_Boolean         myOrientations[3];
0118   BRepMesh_DegreeOfFreedom myMovability;
0119 };
0120 
0121 namespace std
0122 {
0123 template <>
0124 struct hash<BRepMesh_Triangle>
0125 {
0126   size_t operator()(const BRepMesh_Triangle& theTriangle) const noexcept
0127   {
0128     int aCombination[3] = {theTriangle.myEdges[0], theTriangle.myEdges[1], theTriangle.myEdges[2]};
0129     std::sort(aCombination, aCombination + 3); // Sort the numbers in ascending order
0130     return opencascade::hashBytes(aCombination, sizeof(aCombination));
0131   }
0132 };
0133 } // namespace std
0134 
0135 #endif