Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-02 09:12:55

0001 // Created on: 1999-03-05
0002 // Created by: Fabrice SERVANT
0003 // Copyright (c) 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 _IntPolyh_Triangle_HeaderFile
0018 #define _IntPolyh_Triangle_HeaderFile
0019 
0020 #include <Adaptor3d_Surface.hxx>
0021 #include <Bnd_Box.hxx>
0022 #include <IntPolyh_ArrayOfPoints.hxx>
0023 #include <IntPolyh_ArrayOfTriangles.hxx>
0024 #include <IntPolyh_ArrayOfEdges.hxx>
0025 
0026 //! The class represents the triangle built from three IntPolyh points
0027 //! and three IntPolyh edges.
0028 class IntPolyh_Triangle
0029 {
0030 public:
0031   DEFINE_STANDARD_ALLOC
0032 
0033   //! Constructor
0034   IntPolyh_Triangle()
0035       : myHasIntersection(false),
0036         myIsIntersectionPossible(true),
0037         myIsDegenerated(false),
0038         myDeflection(0.0)
0039   {
0040     myPoints[0]            = -1;
0041     myPoints[1]            = -1;
0042     myPoints[2]            = -1;
0043     myEdges[0]             = -1;
0044     myEdges[1]             = -1;
0045     myEdges[2]             = -1;
0046     myEdgesOrientations[0] = 0;
0047     myEdgesOrientations[1] = 0;
0048     myEdgesOrientations[2] = 0;
0049   }
0050 
0051   //! Constructor
0052   IntPolyh_Triangle(const int thePoint1, const int thePoint2, const int thePoint3)
0053       : myHasIntersection(false),
0054         myIsIntersectionPossible(true),
0055         myIsDegenerated(false),
0056         myDeflection(0.0)
0057   {
0058     myPoints[0]            = thePoint1;
0059     myPoints[1]            = thePoint2;
0060     myPoints[2]            = thePoint3;
0061     myEdges[0]             = -1;
0062     myEdges[1]             = -1;
0063     myEdges[2]             = -1;
0064     myEdgesOrientations[0] = 0;
0065     myEdgesOrientations[1] = 0;
0066     myEdgesOrientations[2] = 0;
0067   }
0068 
0069   //! Returns the first point
0070   int FirstPoint() const { return myPoints[0]; }
0071 
0072   //! Returns the second point
0073   int SecondPoint() const { return myPoints[1]; }
0074 
0075   //! Returns the third point
0076   int ThirdPoint() const { return myPoints[2]; }
0077 
0078   //! Returns the first edge
0079   int FirstEdge() const { return myEdges[0]; }
0080 
0081   //! Returns the orientation of the first edge
0082   int FirstEdgeOrientation() const { return myEdgesOrientations[0]; }
0083 
0084   //! Returns the second edge
0085   int SecondEdge() const { return myEdges[1]; }
0086 
0087   //! Returns the orientation of the second edge
0088   int SecondEdgeOrientation() const { return myEdgesOrientations[1]; }
0089 
0090   //! Returns the third edge
0091   int ThirdEdge() const { return myEdges[2]; }
0092 
0093   //! Returns the orientation of the third edge
0094   int ThirdEdgeOrientation() const { return myEdgesOrientations[2]; }
0095 
0096   //! Returns the deflection of the triangle
0097   double Deflection() const { return myDeflection; }
0098 
0099   //! Returns possibility of the intersection
0100   bool IsIntersectionPossible() const { return myIsIntersectionPossible; }
0101 
0102   //! Returns true if the triangle has interfered the other triangle
0103   bool HasIntersection() const { return myHasIntersection; }
0104 
0105   //! Returns the Degenerated flag
0106   bool IsDegenerated() const { return myIsDegenerated; }
0107 
0108   //! Sets the first point
0109   void SetFirstPoint(const int thePoint) { myPoints[0] = thePoint; }
0110 
0111   //! Sets the second point
0112   void SetSecondPoint(const int thePoint) { myPoints[1] = thePoint; }
0113 
0114   //! Sets the third point
0115   void SetThirdPoint(const int thePoint) { myPoints[2] = thePoint; }
0116 
0117   //! Sets the first edge
0118   void SetFirstEdge(const int theEdge, const int theEdgeOrientation)
0119   {
0120     myEdges[0]             = theEdge;
0121     myEdgesOrientations[0] = theEdgeOrientation;
0122   }
0123 
0124   //! Sets the second edge
0125   void SetSecondEdge(const int theEdge, const int theEdgeOrientation)
0126   {
0127     myEdges[1]             = theEdge;
0128     myEdgesOrientations[1] = theEdgeOrientation;
0129   }
0130 
0131   //! Sets the third edge
0132   void SetThirdEdge(const int theEdge, const int theEdgeOrientation)
0133   {
0134     myEdges[2]             = theEdge;
0135     myEdgesOrientations[2] = theEdgeOrientation;
0136   }
0137 
0138   //! Sets the deflection
0139   void SetDeflection(const double theDeflection) { myDeflection = theDeflection; }
0140 
0141   //! Sets the flag of possibility of intersection
0142   void SetIntersectionPossible(const bool theIP) { myIsIntersectionPossible = theIP; }
0143 
0144   //! Sets the flag of intersection
0145   void SetIntersection(const bool theInt) { myHasIntersection = theInt; }
0146 
0147   //! Sets the degenerated flag
0148   void SetDegenerated(const bool theDegFlag) { myIsDegenerated = theDegFlag; }
0149 
0150   //! Gets the edge number by the index
0151   int GetEdgeNumber(const int theEdgeIndex) const
0152   {
0153     return ((theEdgeIndex >= 1 && theEdgeIndex <= 3) ? myEdges[theEdgeIndex - 1] : 0);
0154   }
0155 
0156   //! Sets the edge by the index
0157   void SetEdge(const int theEdgeIndex, const int theEdgeNumber)
0158   {
0159     if (theEdgeIndex >= 1 && theEdgeIndex <= 3)
0160     {
0161       myEdges[theEdgeIndex - 1] = theEdgeNumber;
0162     }
0163   }
0164 
0165   //! Gets the edges orientation by the index
0166   int GetEdgeOrientation(const int theEdgeIndex) const
0167   {
0168     return ((theEdgeIndex >= 1 && theEdgeIndex <= 3) ? myEdgesOrientations[theEdgeIndex - 1] : 0);
0169   }
0170 
0171   //! Sets the edges orientation by the index
0172   void SetEdgeOrientation(const int theEdgeIndex, const int theEdgeOrientation)
0173   {
0174     if (theEdgeIndex >= 1 && theEdgeIndex <= 3)
0175     {
0176       myEdgesOrientations[theEdgeIndex - 1] = theEdgeOrientation;
0177     }
0178   }
0179 
0180   //! Computes the deflection for the triangle
0181   Standard_EXPORT double ComputeDeflection(const occ::handle<Adaptor3d_Surface>& theSurface,
0182                                            const IntPolyh_ArrayOfPoints&         thePoints);
0183 
0184   //! Gets the adjacent triangle
0185   Standard_EXPORT int GetNextTriangle(const int                    theTriangle,
0186                                       const int                    theEdgeNum,
0187                                       const IntPolyh_ArrayOfEdges& TEdges) const;
0188 
0189   //! Splits the triangle on two to decrease its deflection
0190   Standard_EXPORT void MiddleRefinement(const int                             theTriangleNumber,
0191                                         const occ::handle<Adaptor3d_Surface>& theSurface,
0192                                         IntPolyh_ArrayOfPoints&               TPoints,
0193                                         IntPolyh_ArrayOfTriangles&            TTriangles,
0194                                         IntPolyh_ArrayOfEdges&                TEdges);
0195 
0196   //! Splits the current triangle and new triangles until the refinement
0197   //! criterion is not achieved
0198   Standard_EXPORT void MultipleMiddleRefinement(const double   theRefineCriterion,
0199                                                 const Bnd_Box& theBox,
0200                                                 const int      theTriangleNumber,
0201                                                 const occ::handle<Adaptor3d_Surface>& theSurface,
0202                                                 IntPolyh_ArrayOfPoints&               TPoints,
0203                                                 IntPolyh_ArrayOfTriangles&            TTriangles,
0204                                                 IntPolyh_ArrayOfEdges&                TEdges);
0205 
0206   //! Links edges to triangle
0207   Standard_EXPORT void LinkEdges2Triangle(const IntPolyh_ArrayOfEdges& TEdges,
0208                                           const int                    theEdge1,
0209                                           const int                    theEdge2,
0210                                           const int                    theEdge3);
0211 
0212   //! Sets the appropriate edge and orientation for the triangle.
0213   Standard_EXPORT void SetEdgeAndOrientation(const IntPolyh_Edge& theEdge, const int theEdgeIndex);
0214 
0215   //! Returns the bounding box of the triangle.
0216   Standard_EXPORT const Bnd_Box& BoundingBox(const IntPolyh_ArrayOfPoints& thePoints);
0217 
0218   //! Dumps the contents of the triangle.
0219   Standard_EXPORT void Dump(const int v) const;
0220 
0221 private:
0222   int     myPoints[3];
0223   int     myEdges[3];
0224   int     myEdgesOrientations[3];
0225   bool    myHasIntersection : 1;
0226   bool    myIsIntersectionPossible : 1;
0227   bool    myIsDegenerated : 1;
0228   double  myDeflection;
0229   Bnd_Box myBox;
0230 };
0231 
0232 #endif // _IntPolyh_Triangle_HeaderFile