Salome HOME
Updated copyright comment
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IMeasureOperations.hxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef _GEOMImpl_IMeasureOperations_HXX_
24 #define _GEOMImpl_IMeasureOperations_HXX_
25
26 #include "GEOM_IOperations.hxx"
27
28 #include <BRepCheck_Analyzer.hxx>
29 #include <BRepCheck_Status.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TCollection_AsciiString.hxx>
32 #include <TColStd_HSequenceOfInteger.hxx>
33 #include <TColStd_HSequenceOfReal.hxx>
34 #include <TopTools_DataMapOfIntegerListOfShape.hxx>
35 #include <TopTools_MapOfShape.hxx>
36 #include <Geom_Surface.hxx>
37 #include <Precision.hxx>
38
39 class GEOM_Engine;
40 class GEOM_Object;
41
42 class GEOMImpl_IMeasureOperations : public GEOM_IOperations {
43  public:
44   Standard_EXPORT GEOMImpl_IMeasureOperations(GEOM_Engine* theEngine);
45   Standard_EXPORT ~GEOMImpl_IMeasureOperations();
46
47   enum ShapeKind {
48     SK_NO_SHAPE,
49     // COMPOSITEs
50     SK_COMPOUND,
51     SK_COMPSOLID,
52     SK_SHELL,
53     SK_WIRE,
54     // SOLIDs
55     SK_SPHERE,       // full sphere
56     SK_CYLINDER,     // cylinder
57     SK_BOX,          // box with faces, parallel to global coordinate planes
58     SK_ROTATED_BOX,  // other box
59     SK_TORUS,        // full torus
60     SK_CONE,         // cone
61     SK_POLYHEDRON,   // solid, bounded by polygons
62     SK_SOLID,        // other solid
63     // FACEs
64     SK_SPHERE2D,     // spherical face (closed)
65     SK_CYLINDER2D,   // cylindrical face with defined height
66     SK_TORUS2D,      // toroidal face (closed)
67     SK_CONE2D,       // conical face with defined height
68     SK_DISK_CIRCLE,  // planar, bounded by circle
69     SK_DISK_ELLIPSE, // planar, bounded by ellipse
70     SK_POLYGON,      // planar, bounded by segments
71     SK_PLANE,        // infinite planar
72     SK_PLANAR,       // other planar
73     SK_FACE,         // other face
74     // EDGEs
75     SK_CIRCLE,       // full circle
76     SK_ARC_CIRCLE,   // arc of circle
77     SK_ELLIPSE,      // full ellipse
78     SK_ARC_ELLIPSE,  // arc of ellipse
79     SK_LINE,         // infinite segment
80     SK_SEGMENT,      // segment
81     SK_CRV_BSPLINE,  // B-Spline curve (open or closed)
82     SK_CRV_BEZIER,   // Bezier curve (open or closed)
83     SK_HYPERBOLA,    // hyperbola
84     SK_PARABOLA,     // parabola
85     SK_EDGE,         // other edge
86     // VERTEX
87     SK_VERTEX,       // vertex
88     // ADVANCED shapes
89     SK_LCS,          // local coordinate system
90     // (other advanced shapes)
91     SK_ADVANCED,     // all advanced shapes (temporary implementation)
92   };
93
94   /**
95    * This enumeration represents the level of checking shape on
96    * self-interference. It defines which interferferences will be checked.
97    */
98   enum SICheckLevel
99   {
100     SI_V_V = 0, // only V/V interferences
101     SI_V_E,     // V/V and V/E interferences
102     SI_E_E,     // V/V, V/E and E/E interferences
103     SI_V_F,     // V/V, V/E, E/E and V/F interferences
104     SI_E_F,     // V/V, V/E, E/E, V/F and E/F interferences
105     SI_ALL      // all interferences
106   };
107
108   Standard_EXPORT ShapeKind KindOfShape (Handle(GEOM_Object) theShape,
109                                          Handle(TColStd_HSequenceOfInteger)& theIntegers,
110                                          Handle(TColStd_HSequenceOfReal)&    theDoubles);
111
112   Standard_EXPORT void GetPosition (Handle(GEOM_Object) theShape,
113                                     Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
114                                     Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
115                                     Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz);
116
117   Standard_EXPORT Handle(GEOM_Object) GetCentreOfMass (Handle(GEOM_Object) theShape);
118
119   Standard_EXPORT Handle(GEOM_Object) GetVertexByIndex (Handle(GEOM_Object) theShape,
120                                                         Standard_Integer theIndex,
121                                                         Standard_Boolean theUseOri);
122
123   Standard_EXPORT Handle(GEOM_Object) GetNormal (Handle(GEOM_Object) theFace,
124                                                  Handle(GEOM_Object) theOptionalPoint);
125
126   Standard_EXPORT void GetBasicProperties (Handle(GEOM_Object) theShape,
127                                            const Standard_Real theTolerance,
128                                            Standard_Real& theLength,
129                                            Standard_Real& theSurfArea,
130                                            Standard_Real& theVolume);
131
132   Standard_EXPORT void GetInertia (Handle(GEOM_Object) theShape,
133                                    Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
134                                    Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
135                                    Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
136                                    Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz);
137
138   Standard_EXPORT void GetBoundingBox (Handle(GEOM_Object) theShape,
139                                        const Standard_Boolean precise,
140                                        Standard_Real& Xmin, Standard_Real& Xmax,
141                                        Standard_Real& Ymin, Standard_Real& Ymax,
142                                        Standard_Real& Zmin, Standard_Real& Zmax);
143
144   Standard_EXPORT Handle(GEOM_Object) GetBoundingBox (Handle(GEOM_Object) theShape,
145                                                       const Standard_Boolean precise);
146
147   Standard_EXPORT void GetTolerance (Handle(GEOM_Object) theShape,
148                                      Standard_Real& FaceMin, Standard_Real& FaceMax,
149                                      Standard_Real& EdgeMin, Standard_Real& EdgeMax,
150                                      Standard_Real& VertMin, Standard_Real& VertMax);
151
152   struct ShapeError {
153     BRepCheck_Status error;
154     std::list<int>   incriminated;
155   };
156
157   Standard_EXPORT bool CheckShape (Handle(GEOM_Object)     theShape,
158                                    const Standard_Boolean  theIsCheckGeom,
159                                    std::list<ShapeError>  &theErrors);
160
161   Standard_EXPORT TCollection_AsciiString PrintShapeErrors
162                                   (Handle(GEOM_Object)          theShape,
163                                    const std::list<ShapeError> &theErrors);
164
165   Standard_EXPORT bool CheckSelfIntersections (Handle(GEOM_Object) theShape,
166                                                const SICheckLevel  theCheckLevel,
167                                                Handle(TColStd_HSequenceOfInteger)& theIntersections);
168   
169   Standard_EXPORT bool CheckSelfIntersectionsFast (Handle(GEOM_Object) theShape,
170                                                    float  deflection, 
171                                                    double tolerance,
172                                                    Handle(TColStd_HSequenceOfInteger)& theIntersections);
173
174   Standard_EXPORT bool CheckBOPArguments (const Handle(GEOM_Object) &theShape);
175   
176   Standard_EXPORT bool FastIntersect (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
177                                       double tolerance, float deflection,
178                                       Handle(TColStd_HSequenceOfInteger)& theIntersections1,
179                                       Handle(TColStd_HSequenceOfInteger)& theIntersections2);
180
181   Standard_EXPORT TCollection_AsciiString IsGoodForSolid (Handle(GEOM_Object) theShape);
182
183   Standard_EXPORT TCollection_AsciiString WhatIs (Handle(GEOM_Object) theShape);
184
185   Standard_EXPORT std::vector<bool> AreCoordsInside (Handle(GEOM_Object) theShape,
186                                                      const std::vector<double>& coords,
187                                                      double tolerance = Precision::Confusion());
188
189   Standard_EXPORT Standard_Real GetMinDistance (Handle(GEOM_Object) theShape1,
190                                                 Handle(GEOM_Object) theShape2,
191                                                 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
192                                                 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2);
193
194   Standard_EXPORT Standard_Integer ClosestPoints (Handle(GEOM_Object) theShape1,
195                                                   Handle(GEOM_Object) theShape2,
196                                                   Handle(TColStd_HSequenceOfReal)& theDoubles);
197
198   Standard_EXPORT void PointCoordinates (Handle(GEOM_Object) theShape,
199                                          Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ);
200
201   Standard_EXPORT Standard_Real GetAngle (Handle(GEOM_Object) theLine1, Handle(GEOM_Object) theLine2);
202
203   Standard_EXPORT Standard_Real GetAngleBtwVectors (Handle(GEOM_Object) theVec1, Handle(GEOM_Object) theVec2);
204
205   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) PatchFace(Handle(GEOM_Object) theShape);
206
207   // Methods for receiving radiuses of curvature of curves and surfaces
208   // in the given point
209   Standard_EXPORT Standard_Real CurveCurvatureByParam (Handle(GEOM_Object) theCurve,
210                                                        Standard_Real& theParam);
211   Standard_EXPORT Standard_Real CurveCurvatureByPoint (Handle(GEOM_Object) theCurve,
212                                                        Handle(GEOM_Object) thePoint);
213   Standard_EXPORT Standard_Real MaxSurfaceCurvatureByParam (Handle(GEOM_Object) theSurf,
214                                                             Standard_Real& theUParam,
215                                                             Standard_Real& theVParam);
216   Standard_EXPORT Standard_Real MaxSurfaceCurvatureByPoint (Handle(GEOM_Object) theSurf,
217                                                             Handle(GEOM_Object) thePoint);
218   Standard_EXPORT Standard_Real MinSurfaceCurvatureByParam (Handle(GEOM_Object) theSurf,
219                                                             Standard_Real& theUParam,
220                                                             Standard_Real& theVParam);
221   Standard_EXPORT Standard_Real MinSurfaceCurvatureByPoint (Handle(GEOM_Object) theSurf,
222                                                             Handle(GEOM_Object) thePoint);
223
224   // Methods checking the shapes which are not applicable to modelling operations
225   typedef std::pair< Handle(GEOM_Object), Handle(GEOM_Object)> CoupleOfObjects;
226   struct FailedChecks
227   {
228     Standard_Integer TypeOfCheck;
229     CoupleOfObjects FailedShapes;
230   };
231
232   Standard_EXPORT std::list<CoupleOfObjects> SelfIntersected2D(const std::list<FailedChecks>& theChecks);
233   Standard_EXPORT std::list<CoupleOfObjects> InterferingSubshapes(const std::list<FailedChecks>& theChecks,
234                                                                   const int theShapeType1,
235                                                                   const int theShapeType2);
236   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) SmallEdges(const std::list<FailedChecks>& theChecks);
237   Standard_EXPORT std::list<CoupleOfObjects> DistantShapes(const std::list<FailedChecks>& theChecks,
238                                                            const int theShapeType,
239                                                            const int theSubShapeType,
240                                                            double theTolerance);
241   Standard_EXPORT void CheckConformityShape(Handle(GEOM_Object) theShape, std::list<FailedChecks>& theChecks);
242
243   Standard_EXPORT double ComputeTolerance(Handle(GEOM_Object) theEdge, Handle(GEOM_Object) theFace);
244   Standard_EXPORT double UpdateTolerance(Handle(GEOM_Object) theShape);
245
246   Standard_EXPORT Handle(GEOM_Object) SurfaceCurvatureByPointAndDirection
247                                       (Handle(GEOM_Object) theSurf,
248                                        Handle(GEOM_Object) thePoint,
249                                        Handle(GEOM_Object) theDirection);
250
251   // Methods to convert X,Y,Z coordinates of point to U,V parameters on surface and back
252   Standard_EXPORT Handle(TColStd_HArray1OfReal) XYZtoUV
253                                       (Handle(GEOM_Object) theSurf,
254                                        const Handle(TColStd_HArray1OfReal)& theXYZlist,
255                                        bool isNormalized);
256
257   Standard_EXPORT Handle(TColStd_HArray1OfReal) UVtoXYZ
258                                       (Handle(GEOM_Object) theSurf,
259                                        const Handle(TColStd_HArray1OfReal)& theUVlist,
260                                        bool isNormalized);
261
262   // Methods to compute proximity between two shapes
263   Standard_EXPORT Handle(GEOM_Object) ShapeProximityCalculator(Handle(GEOM_Object) theShape1,
264                                                                Handle(GEOM_Object) theShape2);
265   Standard_EXPORT Standard_Real GetCoarseProximity(Handle(GEOM_Object) theCalculator,
266                                                    bool doPythonDump = true);
267   Standard_EXPORT Standard_Real GetPreciseProximity(Handle(GEOM_Object) theCalculator);
268   Standard_EXPORT void SetShapeSampling(Handle(GEOM_Object) theCalculator,
269                                         Handle(GEOM_Object) theShape,
270                                         const Standard_Integer theNbSamples);
271
272  private:
273
274    void FillErrorsSub
275            (const BRepCheck_Analyzer                   &theAna,
276             const TopoDS_Shape                         &theShape,
277             const TopAbs_ShapeEnum                     theSubType,
278                   TopTools_DataMapOfIntegerListOfShape &theMapErrors) const;
279    void FillErrors
280              (const BRepCheck_Analyzer                   &theAna,
281               const TopoDS_Shape                         &theShape,
282                     TopTools_DataMapOfIntegerListOfShape &theMapErrors,
283                     TopTools_MapOfShape                  &theMapShapes) const;
284
285   void FillErrors (const BRepCheck_Analyzer &theAna,
286                    const TopoDS_Shape       &theShape,
287                    std::list<ShapeError>    &theErrors) const;
288
289   Standard_Real getSurfaceCurvatures (const Handle(Geom_Surface)& aSurf,
290                                       Standard_Real theUParam,
291                                       Standard_Real theVParam,
292                                       Standard_Boolean theNeedMaxCurv);
293 };
294
295 #endif