1 // Copyright (c) 2021 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _BRepLib_PointCloudShape_HeaderFile
15 #define _BRepLib_PointCloudShape_HeaderFile
17 #include <TopTools_DataMapOfShapeInteger.hxx>
18 #include <TopTools_DataMapOfShapeReal.hxx>
19 #include <Quantity_Color.hxx>
20 #include <Precision.hxx>
22 //! This tool is intended to get points from shape with specified distance from shape along normal.
23 //! Can be used to simulation of points obtained in result of laser scan of shape.
24 //! There are 2 ways for generation points by shape:
25 //! 1. Generation points with specified density
26 //! 2. Generation points using triangulation Nodes
27 //! Generation of points by density using the GeneratePointsByDensity() function is not thread safe.
28 class BRepLib_PointCloudShape
34 //! Constructor initialized by shape
35 Standard_EXPORT BRepLib_PointCloudShape (const TopoDS_Shape& theShape = TopoDS_Shape(),
36 const Standard_Real theTol = Precision::Confusion());
38 //! Virtual destructor
39 Standard_EXPORT virtual ~BRepLib_PointCloudShape();
41 //! Return loaded shape.
42 const TopoDS_Shape& Shape() const { return myShape; }
45 void SetShape (const TopoDS_Shape& theShape) { myShape = theShape; }
48 Standard_Real Tolerance() const { return myTol; }
51 void SetTolerance (Standard_Real theTol) { myTol = theTol; }
53 //! Returns value of the distance to define deflection of points from shape along normal to shape; 0.0 by default.
54 Standard_Real GetDistance() const { return myDist; }
56 //! Sets value of the distance to define deflection of points from shape along normal to shape.
57 //! Negative values of theDist parameter are ignored.
58 void SetDistance (const Standard_Real theDist) { myDist = theDist; }
60 //! Returns size of the point cloud for specified density.
61 Standard_EXPORT Standard_Integer NbPointsByDensity (const Standard_Real theDensity = 0.0);
63 //! Returns size of the point cloud for using triangulation.
64 Standard_EXPORT Standard_Integer NbPointsByTriangulation() const;
66 //! Computes points with specified density for initial shape.
67 //! If parameter Density is equal to 0 then density will be computed automatically by criterion:
68 //! - 10 points per minimal unreduced face area.
70 //! Note: this function should not be called from concurrent threads without external lock.
71 Standard_EXPORT Standard_Boolean GeneratePointsByDensity (const Standard_Real theDensity = 0.0);
73 //! Get points from triangulation existing in the shape.
74 Standard_EXPORT Standard_Boolean GeneratePointsByTriangulation();
78 //! Compute area of the specified face.
79 Standard_EXPORT Standard_Real faceArea (const TopoDS_Shape& theShape);
81 //! Computes default density points per face.
82 Standard_EXPORT Standard_Real computeDensity();
84 //! Adds points to face in accordance with the specified density randomly in the specified range [0, Dist].
85 Standard_EXPORT Standard_Boolean addDensityPoints (const TopoDS_Shape& theFace);
87 //! Adds points to face by nodes of the existing triangulation randomly in the specified range [0, Dist].
88 Standard_EXPORT Standard_Boolean addTriangulationPoints (const TopoDS_Shape& theFace);
92 //! Method to clear maps.
93 Standard_EXPORT virtual void clear();
95 //! Method to add point, normal to surface in this point and face for which point computed.
96 //! @param[in] thePoint 3D point on the surface
97 //! @param[in] theNorm surface normal at this point
98 //! @param[in] theUV surface UV parameters
99 //! @param[in] theFace surface (face) definition
100 Standard_EXPORT virtual void addPoint (const gp_Pnt& thePoint,
101 const gp_Vec& theNorm,
102 const gp_Pnt2d& theUV,
103 const TopoDS_Shape& theFace) = 0;
107 TopoDS_Shape myShape;
108 Standard_Real myDist;
110 TopTools_DataMapOfShapeReal myFaceArea;
111 TopTools_DataMapOfShapeInteger myFacePoints;
112 Standard_Integer myNbPoints;
116 #endif // _BRepLib_PointCloudShape_HeaderFile