Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright (c) 2021 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _BRepLib_PointCloudShape_HeaderFile
0015 #define _BRepLib_PointCloudShape_HeaderFile
0016 
0017 #include <TopTools_DataMapOfShapeInteger.hxx>
0018 #include <TopTools_DataMapOfShapeReal.hxx>
0019 #include <Quantity_Color.hxx>
0020 #include <Precision.hxx>
0021 
0022 //! This tool is intended to get points from shape with specified distance from shape along normal.
0023 //! Can be used to simulation of points obtained in result of laser scan of shape.
0024 //! There are 2 ways for generation points by shape:
0025 //! 1. Generation points with specified density
0026 //! 2. Generation points using triangulation Nodes
0027 //! Generation of points by density using the GeneratePointsByDensity() function is not thread safe.
0028 class BRepLib_PointCloudShape
0029 {
0030 public:
0031 
0032   DEFINE_STANDARD_ALLOC
0033 
0034   //! Constructor initialized by shape
0035   Standard_EXPORT BRepLib_PointCloudShape (const TopoDS_Shape& theShape = TopoDS_Shape(),
0036                                            const Standard_Real theTol = Precision::Confusion());
0037 
0038   //! Virtual destructor
0039   Standard_EXPORT virtual ~BRepLib_PointCloudShape();
0040 
0041   //! Return loaded shape.
0042   const TopoDS_Shape& Shape() const { return myShape; }
0043 
0044   //! Set shape.
0045   void SetShape (const TopoDS_Shape& theShape) { myShape = theShape; }
0046 
0047   //! Return tolerance.
0048   Standard_Real Tolerance() const { return myTol; }
0049 
0050   //! Set tolerance.
0051   void SetTolerance (Standard_Real theTol) { myTol = theTol; }
0052 
0053   //! Returns value of the distance to define deflection of points from shape along normal to shape; 0.0 by default.
0054   Standard_Real GetDistance() const { return myDist; }
0055 
0056   //! Sets value of the distance to define deflection of points from shape along normal to shape.
0057   //! Negative values of theDist parameter are ignored.
0058   void SetDistance (const Standard_Real theDist) { myDist = theDist; }
0059 
0060   //! Returns size of the point cloud for specified density.
0061   Standard_EXPORT Standard_Integer NbPointsByDensity (const Standard_Real theDensity = 0.0);
0062 
0063   //! Returns size of the point cloud for using triangulation.
0064   Standard_EXPORT Standard_Integer NbPointsByTriangulation() const;
0065 
0066   //! Computes points with specified density for initial shape.
0067   //! If parameter Density is equal to 0 then density will be computed automatically by criterion:
0068   //! - 10 points per minimal unreduced face area.
0069   //!
0070   //! Note: this function should not be called from concurrent threads without external lock.
0071   Standard_EXPORT Standard_Boolean GeneratePointsByDensity (const Standard_Real theDensity = 0.0);
0072 
0073   //! Get points from triangulation existing in the shape.
0074   Standard_EXPORT Standard_Boolean GeneratePointsByTriangulation();
0075 
0076 protected:
0077 
0078   //! Compute area of the specified face.
0079   Standard_EXPORT Standard_Real faceArea (const TopoDS_Shape& theShape);
0080 
0081   //! Computes default density points per face.
0082   Standard_EXPORT Standard_Real computeDensity();
0083 
0084   //! Adds points to face in accordance with the specified density randomly in the specified range [0, Dist].
0085   Standard_EXPORT Standard_Boolean addDensityPoints (const TopoDS_Shape& theFace);
0086 
0087   //! Adds points to face by nodes of the existing triangulation randomly in the specified range [0, Dist].
0088   Standard_EXPORT Standard_Boolean addTriangulationPoints (const TopoDS_Shape& theFace);
0089 
0090 protected:
0091 
0092   //! Method to clear maps.
0093   Standard_EXPORT virtual void clear();
0094 
0095   //! Method to add point, normal to surface in this point and face for which point computed.
0096   //! @param[in] thePoint 3D point on the surface
0097   //! @param[in] theNorm  surface normal at this point
0098   //! @param[in] theUV    surface UV parameters
0099   //! @param[in] theFace  surface (face) definition
0100   Standard_EXPORT virtual void addPoint (const gp_Pnt& thePoint,
0101                                          const gp_Vec& theNorm,
0102                                          const gp_Pnt2d& theUV,
0103                                          const TopoDS_Shape& theFace) = 0;
0104 
0105 protected:
0106 
0107   TopoDS_Shape  myShape;
0108   Standard_Real myDist;
0109   Standard_Real myTol;
0110   TopTools_DataMapOfShapeReal    myFaceArea;
0111   TopTools_DataMapOfShapeInteger myFacePoints;
0112   Standard_Integer myNbPoints;
0113 
0114 };
0115 
0116 #endif // _BRepLib_PointCloudShape_HeaderFile