Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/opencascade/BRepBuilderAPI_FastSewing.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //! Created on: 2015-04-24
0002 //! Created by: NIKOLAI BUKHALOV
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 _BRepBuilderAPI_FastSewing_HeaderFile
0017 #define _BRepBuilderAPI_FastSewing_HeaderFile
0018 
0019 #include <Standard_Transient.hxx>
0020 #include <BRep_Builder.hxx>
0021 
0022 #include <NCollection_List.hxx>
0023 #include <NCollection_Sequence.hxx>
0024 #include <NCollection_Vector.hxx>
0025 #include <NCollection_CellFilter.hxx>
0026 
0027 #include <TopoDS_Edge.hxx>
0028 #include <TopoDS_Face.hxx>
0029 #include <TopoDS_Vertex.hxx>
0030 #include <TopoDS_Wire.hxx>
0031 
0032 
0033 //! This class performs fast sewing of surfaces (faces). It supposes
0034 //! that all surfaces are finite and are naturally restricted by their bounds.
0035 //! Moreover, it supposes that stitched together surfaces have the same parameterization
0036 //! along common boundaries, therefore it does not perform time-consuming check for
0037 //! SameParameter property of edges.
0038 //!
0039 //! For sewing, use this function as following:
0040 //! - set tolerance value (default tolerance is 1.E-06)
0041 //! - add all necessary surfaces (faces)
0042 //! - check status if adding is correctly completed.
0043 //! - compute -> Perform
0044 //! - retrieve the error status if any
0045 //! - retrieve the resulted shape
0046 class BRepBuilderAPI_FastSewing : public Standard_Transient
0047 {
0048 public: 
0049   typedef unsigned int FS_VARStatuses;
0050 
0051   //! Enumeration of result statuses
0052   //ATTENTION!!! If you add new status, please
0053   //    describe it in GetStatuses() method
0054   enum FS_Statuses
0055   {
0056     FS_OK                         = 0x00000000,
0057     FS_Degenerated                = 0x00000001,
0058     FS_FindVertexError            = 0x00000002,
0059     FS_FindEdgeError              = 0x00000004,
0060     FS_FaceWithNullSurface        = 0x00000008,
0061     FS_NotNaturalBoundsFace       = 0x00000010,
0062     FS_InfiniteSurface            = 0x00000020,
0063     FS_EmptyInput                 = 0x00000040,
0064     FS_Exception                  = 0x00000080
0065   };
0066 
0067 
0068   //! Creates an object with tolerance of connexity
0069   Standard_EXPORT BRepBuilderAPI_FastSewing(const Standard_Real theTolerance = 1.0e-06);
0070   
0071   //! Adds faces of a shape
0072   Standard_EXPORT Standard_Boolean Add(const TopoDS_Shape& theShape);
0073 
0074   //! Adds a surface
0075   Standard_EXPORT Standard_Boolean Add(const Handle(Geom_Surface)& theSurface);
0076 
0077   //! Compute resulted shape
0078   Standard_EXPORT void Perform (void) ;
0079   
0080   //! Sets tolerance
0081   void SetTolerance (const Standard_Real theToler)
0082   {
0083     myTolerance = theToler;
0084   }
0085   
0086   //! Returns tolerance
0087   Standard_Real GetTolerance() const
0088   {
0089     return myTolerance;
0090   }
0091 
0092   //! Returns resulted shape
0093   const TopoDS_Shape& GetResult() const 
0094   {
0095     return myResShape;
0096   }
0097   
0098   //! Returns list of statuses. Print message if theOS != 0
0099   Standard_EXPORT FS_VARStatuses GetStatuses(Standard_OStream* const theOS = 0);
0100 
0101   DEFINE_STANDARD_RTTIEXT(BRepBuilderAPI_FastSewing,Standard_Transient)
0102 
0103 protected:
0104   class NodeInspector;
0105 
0106   Standard_EXPORT void FindVertexes(const Standard_Integer theSurfID,
0107                                       NCollection_CellFilter<NodeInspector>& theCells);
0108   Standard_EXPORT void FindEdges(const Standard_Integer theSurfID);
0109   Standard_EXPORT void UpdateEdgeInfo(const Standard_Integer theIDPrevVertex,
0110                                       const Standard_Integer theIDCurrVertex,
0111                                       const Standard_Integer theFaceID,
0112                                       const Standard_Integer theIDCurvOnFace);
0113   Standard_EXPORT void CreateNewEdge( const Standard_Integer theIDPrevVertex,
0114                                       const Standard_Integer theIDCurrVertex,
0115                                       const Standard_Integer theFaceID,
0116                                       const Standard_Integer theIDCurvOnFace);
0117 
0118   Standard_EXPORT Standard_Real Compute3DRange();
0119 
0120   //! Sets status. Returns numeric value of the status set
0121   FS_VARStatuses SetStatus(FS_Statuses theStatus)
0122   {
0123     const FS_VARStatuses aStatusID = (FS_VARStatuses)(theStatus);
0124     myStatusList |= aStatusID;
0125     return aStatusID;
0126   }
0127 
0128   class FS_Edge;
0129 
0130   // Classes FS_Vertex, FS_Face and FS_Edge keep information about
0131   // relations between resulted members (e.g. which faces share this vertex? etc.)
0132   
0133   //! The struct corresponding to a vertex
0134   struct FS_Vertex
0135   {
0136   public:
0137     FS_Vertex(): myID(-1){};
0138 
0139     //! Creates topological member (vertex)
0140     void CreateTopologicalVertex(const Standard_Real theToler)
0141     {
0142       BRep_Builder aBuilder;
0143       aBuilder.MakeVertex(myTopoVert, myPnt, theToler);
0144     }
0145     
0146     //! Geometry point of this Vertex
0147     gp_Pnt myPnt;
0148     TopoDS_Vertex myTopoVert;
0149 
0150     //! List of faces and edges which share this vertex
0151     NCollection_List<Standard_Integer> myFaces;
0152     NCollection_List<Standard_Integer> myEdges;
0153 
0154     //! Identifies the place of this Vertex in
0155     //! BRepBuilderAPI_FastSewing::myVertexVec list
0156     Standard_Integer myID;
0157   };
0158 
0159   //! The struct corresponding to an face
0160   struct FS_Face
0161   {
0162     FS_Face(): myID(-1)
0163     {
0164       for (Standard_Integer i = 0; i < 4; i++)
0165       {
0166         myVertices[i] = -1;
0167         myEdges[i] = -1;
0168       }
0169     };
0170     //! Creates topological members (wire and face)
0171     void CreateTopologicalWire(const NCollection_Vector<FS_Edge>& theEdgeVec,
0172                                const Standard_Real theToler);
0173     void CreateTopologicalFace();
0174     
0175     //! Sets vertex
0176     void SetVertex(const Standard_Integer thePlaceID, const Standard_Integer theVertID)
0177     {
0178       Standard_RangeError_Raise_if((thePlaceID < 0) || (thePlaceID > 3),
0179                                       "FS_Face::SetVertex(): OUT of Range");
0180 
0181       myVertices[thePlaceID] = theVertID;
0182     }
0183 
0184     //! Sets edge
0185     void SetEdge(const Standard_Integer thePlaceID, const Standard_Integer theEdgeID)
0186     {
0187       Standard_RangeError_Raise_if((thePlaceID < 0) || (thePlaceID > 3),
0188                                       "FS_Face::SetEdge(): OUT of Range");
0189 
0190       myEdges[thePlaceID] = theEdgeID;
0191     }
0192 
0193     TopoDS_Face mySrcFace;
0194     TopoDS_Wire myWire;
0195     TopoDS_Face myRetFace;
0196 
0197     //! myEdges[i] number of the edge in myEdgeVec
0198     //! (i==0) <-> (V=Vf); (i==1) <-> (U=Ul);
0199     //! (i==2) <-> (V=Vl); (i==3) <-> (U=Uf)
0200     Standard_Integer myEdges[4];
0201     //! myVertices[i] is Start point of myEdges[i]
0202     Standard_Integer myVertices[4];
0203 
0204     //! Identifies the place of this Face in
0205     //! BRepBuilderAPI_FastSewing::myFaceVec list
0206     Standard_Integer myID;
0207   };
0208 
0209   //! The struct corresponding to a edge
0210   class FS_Edge
0211   {
0212   public:
0213     FS_Edge(): myID(-1)
0214     {
0215       myVertices[0] = -1;
0216       myVertices[1] = -1;
0217     }
0218 
0219     FS_Edge(const Standard_Integer theIDVert1, const Standard_Integer theIDVert2): myID(-1)
0220     {
0221       myVertices[0] = theIDVert1;
0222       myVertices[1] = theIDVert2;
0223     };
0224 
0225     //! Creates topological member (TopoDS_Edge)
0226     void CreateTopologicalEdge( const NCollection_Vector<FS_Vertex>& theVertexVec,
0227                                 const NCollection_Vector<FS_Face>& theFaceVec,
0228                                 const Standard_Real theTol);
0229     
0230     //! Sets vertex
0231     void SetVertex(const Standard_Integer thePlaceID, const Standard_Integer theVertID)
0232     {
0233       Standard_RangeError_Raise_if((thePlaceID < 0) || (thePlaceID > 1),
0234                                       "FS_Face::SetVertex(): OUT of Range");
0235 
0236       myVertices[thePlaceID] = theVertID;
0237     }
0238 
0239     Standard_Boolean IsDegenerated() const
0240     {
0241       return (myVertices[0] == myVertices[1]);
0242     }
0243 
0244     //! List of faces which are shared with this edge
0245     //! Value is the index of this shape in myFaceVec array
0246     NCollection_Sequence<Standard_Integer> myFaces;
0247 
0248     //! Identifies the place of this Edge in
0249     //! BRepBuilderAPI_FastSewing::myEdgeVec list
0250     Standard_Integer myID;
0251 
0252     TopoDS_Edge myTopoEdge;
0253   private:
0254     //! Index of the vertex in myVertexVec array   
0255     Standard_Integer myVertices[2];
0256   };
0257 
0258   //! This inspector will find a node nearest to the given point
0259   //! not far than on the given tolerance
0260   class NodeInspector: public NCollection_CellFilter_InspectorXYZ
0261   {
0262   public:
0263     typedef Standard_Integer Target;  
0264 
0265     NodeInspector(const NCollection_Vector<FS_Vertex>& theVec,
0266       const gp_Pnt& thePnt, const Standard_Real theTol);
0267 
0268     Standard_EXPORT NCollection_CellFilter_Action Inspect (const Target theId);
0269 
0270     Target GetResult()
0271     {
0272       return myResID;
0273     }
0274 
0275   private:
0276     NodeInspector& operator = (const NodeInspector&);    
0277     const NCollection_Vector<FS_Vertex>& myVecOfVertexes;
0278     gp_Pnt myPoint;
0279     Standard_Real mySQToler;
0280     Target myResID;
0281     Standard_Boolean myIsFindingEnable;
0282   };
0283 private: 
0284   TopoDS_Shape myResShape;
0285 
0286   // myFaceVec, myVertexVec and myEdgeVec lists are filled only once!!!!!
0287 
0288   //! Vector of faces
0289   NCollection_Vector<FS_Face> myFaceVec;
0290   //! Vector of Vertices
0291   NCollection_Vector<FS_Vertex> myVertexVec;
0292   //! Vector of edges
0293   NCollection_Vector<FS_Edge> myEdgeVec;
0294 
0295   //! Tolerance
0296   Standard_Real myTolerance;
0297 
0298   //! Bits of computation status
0299   FS_VARStatuses myStatusList;
0300 };
0301 
0302 DEFINE_STANDARD_HANDLE(BRepBuilderAPI_FastSewing, Standard_Transient)
0303 
0304 #endif // _BRepBuilderAPI_FastSewing_HeaderFile