Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:15

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 
0027 //! Light weighted structure representing triangle 
0028 //! of mesh consisting of oriented links.
0029 class BRepMesh_Triangle
0030 {
0031 public:
0032 
0033   DEFINE_STANDARD_ALLOC
0034 
0035   //! Default constructor.
0036   BRepMesh_Triangle()
0037     : myMovability  (BRepMesh_Free)
0038   {
0039     myEdges[0] = 0;
0040     myEdges[1] = 0;
0041     myEdges[2] = 0;
0042     myOrientations[0] = Standard_False;
0043     myOrientations[1] = Standard_False;
0044     myOrientations[2] = Standard_False;
0045   }
0046 
0047   //! Constructor.
0048   //! @param theEdges array of edges of triangle.
0049   //! @param theOrientations array of edge's orientations.
0050   //! @param theMovability movability of triangle.
0051   BRepMesh_Triangle(
0052     const Standard_Integer          (&theEdges)[3],
0053     const Standard_Boolean          (&theOrientations)[3],
0054     const BRepMesh_DegreeOfFreedom  theMovability)
0055   {
0056     Initialize(theEdges, theOrientations, theMovability);
0057   }
0058   
0059   //! Initializes the triangle by the given parameters.
0060   //! @param theEdges array of edges of triangle.
0061   //! @param theOrientations array of edge's orientations.
0062   //! @param theMovability movability of triangle.
0063   void Initialize(
0064     const Standard_Integer          (&theEdges)[3],
0065     const Standard_Boolean          (&theOrientations)[3],
0066     const BRepMesh_DegreeOfFreedom  theMovability)
0067   {
0068     memcpy(myEdges, theEdges, sizeof(theEdges));
0069     memcpy(myOrientations, theOrientations, sizeof(theOrientations));
0070     myMovability   = theMovability;
0071   }
0072   
0073   //! Gets edges with orientations composing the triangle.
0074   //! @param[out] theEdges array edges are stored to.
0075   //! @param[out] theOrientations array orientations are stored to.
0076   void Edges(Standard_Integer (&theEdges)[3],
0077              Standard_Boolean (&theOrientations)[3]) const
0078   {
0079     memcpy(theEdges, myEdges, sizeof(myEdges));
0080     memcpy(theOrientations, myOrientations, sizeof(myOrientations));
0081   }
0082   
0083   //! Returns movability of the triangle.
0084   BRepMesh_DegreeOfFreedom Movability() const 
0085   {
0086     return myMovability;
0087   }
0088   
0089   //! Sets movability of the triangle.
0090   void SetMovability(const BRepMesh_DegreeOfFreedom theMovability)
0091   {
0092     myMovability = theMovability;
0093   }
0094 
0095   //! Checks for equality with another triangle.
0096   //! @param theOther triangle to be checked against this one.
0097   //! @return TRUE if equal, FALSE if not.
0098   Standard_Boolean IsEqual(const BRepMesh_Triangle& theOther) const
0099   {
0100     if (myMovability == BRepMesh_Deleted || theOther.myMovability == BRepMesh_Deleted)
0101       return Standard_False;
0102 
0103     if (myEdges[0] == theOther.myEdges[0] &&
0104         myEdges[1] == theOther.myEdges[1] &&
0105         myEdges[2] == theOther.myEdges[2])
0106     {
0107       return Standard_True;
0108     }
0109 
0110     if (myEdges[0] == theOther.myEdges[1] &&
0111         myEdges[1] == theOther.myEdges[2] &&
0112         myEdges[2] == theOther.myEdges[0])
0113     {
0114       return Standard_True;
0115     }
0116 
0117     if (myEdges[0] == theOther.myEdges[2] &&
0118         myEdges[1] == theOther.myEdges[0] &&
0119         myEdges[2] == theOther.myEdges[1])
0120     {
0121       return Standard_True;
0122     }
0123 
0124     return Standard_False;
0125   }
0126   
0127   //! Alias for IsEqual.
0128   Standard_Boolean operator ==(const BRepMesh_Triangle& theOther) const
0129   {
0130     return IsEqual(theOther);
0131   }
0132 
0133   Standard_Integer          myEdges[3];
0134   Standard_Boolean          myOrientations[3];
0135   BRepMesh_DegreeOfFreedom  myMovability;
0136 };
0137 
0138 namespace std
0139 {
0140   template <>
0141   struct hash<BRepMesh_Triangle>
0142   {
0143     size_t operator()(const BRepMesh_Triangle& theTriangle) const noexcept
0144     {
0145       int aCombination[3] = { theTriangle.myEdges[0], theTriangle.myEdges[1], theTriangle.myEdges[2] };
0146       std::sort(aCombination, aCombination + 3); // Sort the numbers in ascending order
0147       return opencascade::hashBytes(aCombination, sizeof(aCombination));
0148     }
0149   };
0150 }
0151 
0152 #endif