0029325: Modeling Algorithms - add tool BRepLib_PointCloudShape for generation point...
[occt.git] / src / BRepLib / BRepLib_PointCloudShape.hxx
1 // Copyright (c) 2021 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _BRepLib_PointCloudShape_HeaderFile
15 #define _BRepLib_PointCloudShape_HeaderFile
16
17 #include <TopTools_DataMapOfShapeInteger.hxx>
18 #include <TopTools_DataMapOfShapeReal.hxx>
19 #include <Quantity_Color.hxx>
20 #include <Precision.hxx>
21
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
29 {
30 public:
31
32   DEFINE_STANDARD_ALLOC
33
34   //! Constructor initialized by shape
35   Standard_EXPORT BRepLib_PointCloudShape (const TopoDS_Shape& theShape = TopoDS_Shape(),
36                                            const Standard_Real theTol = Precision::Confusion());
37
38   //! Virtual destructor
39   Standard_EXPORT virtual ~BRepLib_PointCloudShape();
40
41   //! Return loaded shape.
42   const TopoDS_Shape& Shape() const { return myShape; }
43
44   //! Set shape.
45   void SetShape (const TopoDS_Shape& theShape) { myShape = theShape; }
46
47   //! Return tolerance.
48   Standard_Real Tolerance() const { return myTol; }
49
50   //! Set tolerance.
51   void SetTolerance (Standard_Real theTol) { myTol = theTol; }
52
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; }
55
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; }
59
60   //! Returns size of the point cloud for specified density.
61   Standard_EXPORT Standard_Integer NbPointsByDensity (const Standard_Real theDensity = 0.0);
62
63   //! Returns size of the point cloud for using triangulation.
64   Standard_EXPORT Standard_Integer NbPointsByTriangulation() const;
65
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.
69   //!
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);
72
73   //! Get points from triangulation existing in the shape.
74   Standard_EXPORT Standard_Boolean GeneratePointsByTriangulation();
75
76 protected:
77
78   //! Compute area of the specified face.
79   Standard_EXPORT Standard_Real faceArea (const TopoDS_Shape& theShape);
80
81   //! Computes default density points per face.
82   Standard_EXPORT Standard_Real computeDensity();
83
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);
86
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);
89
90 protected:
91
92   //! Method to clear maps.
93   Standard_EXPORT virtual void clear();
94
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;
104
105 protected:
106
107   TopoDS_Shape  myShape;
108   Standard_Real myDist;
109   Standard_Real myTol;
110   TopTools_DataMapOfShapeReal    myFaceArea;
111   TopTools_DataMapOfShapeInteger myFacePoints;
112   Standard_Integer myNbPoints;
113
114 };
115
116 #endif // _BRepLib_PointCloudShape_HeaderFile