Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:10

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