Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-10 09:16:15

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   DEFINE_STANDARD_ALLOC
0032 
0033   //! Constructor initialized by shape
0034   Standard_EXPORT BRepLib_PointCloudShape(const TopoDS_Shape& theShape = TopoDS_Shape(),
0035                                           const Standard_Real theTol   = Precision::Confusion());
0036 
0037   //! Virtual destructor
0038   Standard_EXPORT virtual ~BRepLib_PointCloudShape();
0039 
0040   //! Return loaded shape.
0041   const TopoDS_Shape& Shape() const { return myShape; }
0042 
0043   //! Set shape.
0044   void SetShape(const TopoDS_Shape& theShape) { myShape = theShape; }
0045 
0046   //! Return tolerance.
0047   Standard_Real Tolerance() const { return myTol; }
0048 
0049   //! Set tolerance.
0050   void SetTolerance(Standard_Real theTol) { myTol = theTol; }
0051 
0052   //! Returns value of the distance to define deflection of points from shape along normal to shape;
0053   //! 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   //! Compute area of the specified face.
0078   Standard_EXPORT Standard_Real faceArea(const TopoDS_Shape& theShape);
0079 
0080   //! Computes default density points per face.
0081   Standard_EXPORT Standard_Real computeDensity();
0082 
0083   //! Adds points to face in accordance with the specified density randomly in the specified range
0084   //! [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,
0088   //! Dist].
0089   Standard_EXPORT Standard_Boolean addTriangulationPoints(const TopoDS_Shape& theFace);
0090 
0091 protected:
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   TopoDS_Shape                   myShape;
0107   Standard_Real                  myDist;
0108   Standard_Real                  myTol;
0109   TopTools_DataMapOfShapeReal    myFaceArea;
0110   TopTools_DataMapOfShapeInteger myFacePoints;
0111   Standard_Integer               myNbPoints;
0112 };
0113 
0114 #endif // _BRepLib_PointCloudShape_HeaderFile