1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, 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 // SMESH StdMeshers_Deflection1D : implementation of SMESH idl descriptions
24 // File : StdMeshers_Deflection1D.cxx
27 #include "StdMeshers_Deflection1D.hxx"
28 #include "utilities.h"
30 #include "SMESH_Mesh.hxx"
31 #include "SMESH_Algo.hxx"
33 #include <BRep_Tool.hxx>
34 #include <GeomAdaptor_Curve.hxx>
35 #include <Geom_Curve.hxx>
37 #include <TopLoc_Location.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <TopoDS_Edge.hxx>
46 //=============================================================================
50 //=============================================================================
52 StdMeshers_Deflection1D::StdMeshers_Deflection1D(int hypId,
54 :SMESH_Hypothesis(hypId, gen)
57 _name = "Deflection1D";
58 _param_algo_dim = 1; // is used by SMESH_Regular_1D
61 //=============================================================================
65 //=============================================================================
67 StdMeshers_Deflection1D::~StdMeshers_Deflection1D()
71 //=============================================================================
75 //=============================================================================
77 void StdMeshers_Deflection1D::SetDeflection(double value)
79 if (_value != value) {
81 throw SALOME_Exception(LOCALIZED("Value must be positive"));
83 NotifySubMeshesHypothesisModification();
89 //=============================================================================
93 //=============================================================================
95 double StdMeshers_Deflection1D::GetDeflection() const
100 //=============================================================================
104 //=============================================================================
106 ostream & StdMeshers_Deflection1D::SaveTo(ostream & save)
112 //=============================================================================
116 //=============================================================================
118 istream & StdMeshers_Deflection1D::LoadFrom(istream & load)
120 bool isOK = static_cast<bool>(load >> _value);
122 load.clear(ios::badbit | load.rdstate());
126 //=============================================================================
130 //=============================================================================
132 ostream & operator <<(ostream & save, StdMeshers_Deflection1D & hyp)
134 return hyp.SaveTo( save );
137 //=============================================================================
141 //=============================================================================
143 istream & operator >>(istream & load, StdMeshers_Deflection1D & hyp)
145 return hyp.LoadFrom( load );
147 //================================================================================
149 * \brief Evaluate curve deflection between two points
150 * \param theCurve - the curve
151 * \param theU1 - the parameter of the first point
152 * \param theU2 - the parameter of the second point
153 * \retval double - deflection value
155 //================================================================================
157 static double deflection(const GeomAdaptor_Curve & theCurve,
161 if ( theCurve.GetType() == GeomAbs_Line )
163 // line between theU1 and theU2
164 gp_Pnt p1 = theCurve.Value( theU1 ), p2 = theCurve.Value( theU2 );
165 gp_Lin segment( p1, gp_Vec( p1, p2 ));
167 // evaluate square distance of theCurve from the segment
168 Standard_Real dist2 = 0;
170 const double step = ( theU2 - theU1 ) / nbPnt;
171 while (( theU1 += step ) < theU2 )
172 dist2 = Max( dist2, segment.SquareDistance( theCurve.Value( theU1 )));
174 return sqrt( dist2 );
177 //================================================================================
179 * \brief Initialize deflection value by the mesh built on the geometry
180 * \param theMesh - the built mesh
181 * \param theShape - the geometry of interest
182 * \retval bool - true if parameter values have been successfully defined
184 //================================================================================
186 bool StdMeshers_Deflection1D::SetParametersByMesh(const SMESH_Mesh* theMesh,
187 const TopoDS_Shape& theShape)
189 if ( !theMesh || theShape.IsNull() )
194 Standard_Real UMin, UMax;
198 TopTools_IndexedMapOfShape edgeMap;
199 TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap );
201 for ( int iE = 1; iE <= edgeMap.Extent(); ++iE )
203 const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( iE ));
204 Handle(Geom_Curve) C = BRep_Tool::Curve( edge, L, UMin, UMax );
205 GeomAdaptor_Curve AdaptCurve(C, UMin, UMax);
206 if ( AdaptCurve.GetType() != GeomAbs_Line )
208 vector< double > params;
209 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
210 if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params ))
213 for ( size_t i = 1; i < params.size(); ++i )
214 _value = Max( _value, deflection( AdaptCurve, params[ i-1 ], params[ i ]));
223 //================================================================================
225 * \brief Initialize my parameter values by default parameters.
226 * \retval bool - true if parameter values have been successfully defined
228 //================================================================================
230 bool StdMeshers_Deflection1D::SetParametersByDefaults(const TDefaults& /*dflts*/,
231 const SMESH_Mesh* /*theMesh*/)