Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Created on: 2015-04-26
0002 // Created by: Denis BOGOLEPOV
0003 // Copyright (c) 2015 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _BRepExtrema_SelfIntersection_HeaderFile
0017 #define _BRepExtrema_SelfIntersection_HeaderFile
0018 
0019 #include <BRepExtrema_OverlapTool.hxx>
0020 
0021 #include <TopoDS.hxx>
0022 
0023 //! Tool class for detection of self-sections in the given shape.
0024 //! This class is based on BRepExtrema_OverlapTool and thus uses
0025 //! shape tessellation to detect incorrect mesh fragments (pairs
0026 //! of overlapped triangles belonging to different faces). Thus,
0027 //! a result depends critically on the quality of mesh generator
0028 //! (e.g., BREP mesh is not always a good choice, because it can
0029 //! contain gaps between adjacent face triangulations, which may
0030 //! not share vertices on common edge; thus false overlap can be
0031 //! detected). As a result, this tool can be used for relatively
0032 //! fast approximated test which provides sub-set of potentially
0033 //! overlapped faces.
0034 class BRepExtrema_SelfIntersection : public BRepExtrema_ElementFilter
0035 {
0036   friend class BRepExtrema_OverlapTool;
0037 
0038 public:
0039 
0040   //! Creates uninitialized self-intersection tool.
0041   Standard_EXPORT BRepExtrema_SelfIntersection (const Standard_Real theTolerance = 0.0);
0042 
0043   //! Creates self-intersection tool for the given shape.
0044   Standard_EXPORT BRepExtrema_SelfIntersection (const TopoDS_Shape& theShape, const Standard_Real theTolerance = 0.0);
0045 
0046 public:
0047 
0048   //! Returns tolerance value used for self-intersection test.
0049   Standard_Real Tolerance() const
0050   {
0051     return myTolerance;
0052   }
0053 
0054   //! Sets tolerance value used for self-intersection test.
0055   void SetTolerance (const Standard_Real theTolerance)
0056   {
0057     myTolerance = theTolerance;
0058   }
0059 
0060   //! Loads shape for detection of self-intersections.
0061   Standard_EXPORT Standard_Boolean LoadShape (const TopoDS_Shape& theShape);
0062 
0063   //! Performs detection of self-intersections.
0064   Standard_EXPORT void Perform();
0065 
0066   //! True if the detection is completed.
0067   Standard_Boolean IsDone() const
0068   { 
0069     return myOverlapTool.IsDone();
0070   }
0071 
0072   //! Returns set of IDs of overlapped sub-shapes (started from 0).
0073   const BRepExtrema_MapOfIntegerPackedMapOfInteger& OverlapElements() const
0074   {
0075     return myOverlapTool.OverlapSubShapes1();
0076   }
0077 
0078   //! Returns sub-shape from the shape for the given index (started from 0).
0079   const TopoDS_Face& GetSubShape (const Standard_Integer theID) const
0080   {
0081     return TopoDS::Face(myFaceList.Value(theID));
0082   }
0083 
0084   //! Returns set of all the face triangles of the shape.
0085   const Handle(BRepExtrema_TriangleSet)& ElementSet() const
0086   {
0087     return myElementSet;
0088   }
0089 
0090 #ifdef OVERLAP_TOOL_OUTPUT_TRIANGLES
0091   //! Returns set of overlapped mesh elements (only triangles).
0092   const TColStd_PackedMapOfInteger& OverlapTriangles() const
0093   {
0094     return myOverlapTool.OverlapTriangles1();
0095   }
0096 #endif
0097 
0098 protected:
0099 
0100   //! Filter out correct adjacent mesh elements.
0101   Standard_EXPORT virtual BRepExtrema_ElementFilter::FilterResult PreCheckElements (const Standard_Integer theIndex1,
0102                                                                                     const Standard_Integer theIndex2);
0103 
0104   //! Checks if the given triangles have only single common vertex.
0105   Standard_EXPORT BRepExtrema_ElementFilter::FilterResult isRegularSharedVertex (const BVH_Vec3d& theSharedVert,
0106                                                                                  const BVH_Vec3d& theTrng1Vtxs1,
0107                                                                                  const BVH_Vec3d& theTrng1Vtxs2,
0108                                                                                  const BVH_Vec3d& theTrng2Vtxs1,
0109                                                                                  const BVH_Vec3d& theTrng2Vtxs2);
0110 
0111   //! Checks if the given triangles have only single common edge.
0112   Standard_EXPORT BRepExtrema_ElementFilter::FilterResult isRegularSharedEdge (const BVH_Vec3d& theTrng1Vtxs0,
0113                                                                                const BVH_Vec3d& theTrng1Vtxs1,
0114                                                                                const BVH_Vec3d& theTrng1Vtxs2,
0115                                                                                const BVH_Vec3d& theTrng2Vtxs2);
0116 
0117 private:
0118 
0119   //! Self-intersection tolerance.
0120   Standard_Real myTolerance;
0121 
0122   //! Is the input shape inited?
0123   Standard_Boolean myIsInit;
0124 
0125   //! List of triangulated faces of the shape.
0126   BRepExtrema_ShapeList myFaceList;
0127 
0128   //! Set of all the face triangles of the shape.
0129   Handle(BRepExtrema_TriangleSet) myElementSet;
0130 
0131   //! Overlap tool used for self-intersection test.
0132   BRepExtrema_OverlapTool myOverlapTool;
0133 
0134 };
0135 
0136 #endif // _BRepExtrema_SelfIntersection_HeaderFile