1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <GEOMImpl_ITestOperations.hxx>
25 #include <BRepBndLib.hxx>
26 #include <BRepBuilderAPI_Copy.hxx>
27 #include <BRepMesh_IncrementalMesh.hxx>
28 #include <BRepTools.hxx>
29 #include <Bnd_Box.hxx>
30 #include <utilities.h>
33 #define MAX2(X, Y) (Abs(X) > Abs(Y) ? Abs(X) : Abs(Y))
36 #define MAX3(X, Y, Z) (MAX2(MAX2(X, Y), Z))
39 //=============================================================================
43 //=============================================================================
44 GEOMImpl_ITestOperations::GEOMImpl_ITestOperations(GEOM_Engine* theEngine)
45 : GEOM_IOperations(theEngine)
47 MESSAGE("GEOMImpl_ITestOperations::GEOMImpl_ITestOperations");
50 //=============================================================================
54 //=============================================================================
55 GEOMImpl_ITestOperations::~GEOMImpl_ITestOperations()
57 MESSAGE("GEOMImpl_ITestOperations::~GEOMImpl_ITestOperations");
61 //=============================================================================
63 * \brief Build a mesh on (a copy of ) the given shape.
65 * This test function is aimed for checking performance of OCCT tesselation
66 * algorithm on particlar geometrical shapes.
68 * \param theShape is a source object
69 * \param theLinearDeflection is a value of deflection coefficient
70 * \param theIsRelative says if given value of deflection is relative to shape's bounding box
71 * \param theAngularDeflection is a angular deflection for edges in radians
72 * \return \c true in case of success; otherwise \c false.
74 //=============================================================================
75 bool GEOMImpl_ITestOperations::Tesselate(Handle(GEOM_Object) theShape,
76 double theLinearDeflection,
78 double theAngularDeflection)
81 // We don't need results of this method to be present in the data tree;
82 // so we don't need a driver for it.
86 // create a copy of the source shape
87 TopoDS_Shape aShape = BRepBuilderAPI_Copy(theShape->GetValue()).Shape();
88 // use default deflection if necessary
89 if (theLinearDeflection <= 0)
90 theLinearDeflection = 0.001;
91 // compute absolute deflection if necessary: 0.001
93 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
95 BRepBndLib::Add(aShape, bndBox);
96 bndBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
97 theLinearDeflection = MAX3(aXmax-aXmin, aYmax-aYmin, aZmax-aZmin) * theLinearDeflection * 4;
99 // use default deviation angle if necessary: 20 degrees
100 if (theAngularDeflection <= 0)
101 theAngularDeflection = 20. * M_PI / 180.;
102 // compute triangulation
103 BRepTools::Clean(aShape);
104 BRepMesh_IncrementalMesh aMesh(aShape, theLinearDeflection, Standard_False, theAngularDeflection);
105 // set OK status and return