Salome HOME
6292333569651bded3dcf446c8246ecc0e41d716
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ITestOperations.cxx
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 #include <GEOMImpl_ITestOperations.hxx>
24
25 #include <GEOMUtils.hxx>
26
27 #include <BRepBuilderAPI_Copy.hxx>
28
29 #include <utilities.h>
30
31 #ifndef MAX2
32 #define MAX2(X, Y)    (Abs(X) > Abs(Y) ? Abs(X) : Abs(Y))
33 #endif
34 #ifndef MAX3
35 #define MAX3(X, Y, Z) (MAX2(MAX2(X, Y), Z))
36 #endif
37
38 //=============================================================================
39 /*!
40  *   constructor:
41  */
42 //=============================================================================
43 GEOMImpl_ITestOperations::GEOMImpl_ITestOperations(GEOM_Engine* theEngine)
44 : GEOM_IOperations(theEngine)
45 {
46   MESSAGE("GEOMImpl_ITestOperations::GEOMImpl_ITestOperations");
47 }
48
49 //=============================================================================
50 /*!
51  *  destructor
52  */
53 //=============================================================================
54 GEOMImpl_ITestOperations::~GEOMImpl_ITestOperations()
55 {
56   MESSAGE("GEOMImpl_ITestOperations::~GEOMImpl_ITestOperations");
57 }
58
59
60 //=============================================================================
61 /*!
62  *  \brief Build a mesh on (a copy of ) the given shape.
63  *
64  *  This test function is aimed for checking performance of OCCT tesselation
65  *  algorithm on particlar geometrical shapes.
66  *
67  *  \param theShape is a source object
68  *  \param theLinearDeflection is a value of deflection coefficient
69  *  \param theIsRelative says if given value of deflection is relative to shape's bounding box
70  *  \param theAngularDeflection is a angular deflection for edges in radians
71  *  \return \c true in case of success; otherwise \c false.
72  */
73 //=============================================================================
74 bool GEOMImpl_ITestOperations::Tesselate(Handle(GEOM_Object) theShape,
75                                          double theLinearDeflection,
76                                          bool theIsRelative,
77                                          double theAngularDeflection)
78 {
79   // ATTENTION!
80   // We don't need results of this method to be present in the data tree;
81   // so we don't need a driver for it.
82
83   // reset error code
84   SetErrorCode(KO);
85
86   // create a copy of the source shape
87   TopoDS_Shape aShape = BRepBuilderAPI_Copy(theShape->GetValue()).Shape();
88
89   // use default deflection if necessary
90   if (theLinearDeflection <= 0)
91     theLinearDeflection = 0.001;
92
93   // use default deviation angle if necessary: 20 degrees
94   if (theAngularDeflection <= 0)
95     theAngularDeflection = 20. * M_PI / 180.;
96
97   // compute triangulation
98   GEOMUtils::MeshShape(aShape, theLinearDeflection, /*theForced*/ true,
99                        theAngularDeflection, theIsRelative);
100
101   // set OK status and return
102   SetErrorCode(OK);
103   return true;
104 }