1 // Copyright (C) 2007-2008 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.
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
22 // SMESH SMESH : implementaion of SMESH idl descriptions
23 // File : StdMeshers_Regular_1D.cxx
24 // Moved here from SMESH_Regular_1D.cxx
25 // Author : Paul RASCLE, EDF
28 #include "StdMeshers_Regular_1D.hxx"
29 #include "StdMeshers_Distribution.hxx"
31 #include "StdMeshers_Arithmetic1D.hxx"
32 #include "StdMeshers_AutomaticLength.hxx"
33 #include "StdMeshers_Deflection1D.hxx"
34 #include "StdMeshers_LocalLength.hxx"
35 #include "StdMeshers_MaxLength.hxx"
36 #include "StdMeshers_NumberOfSegments.hxx"
37 #include "StdMeshers_Propagation.hxx"
38 #include "StdMeshers_SegmentLengthAroundVertex.hxx"
39 #include "StdMeshers_StartEndLength.hxx"
41 #include "SMESH_Gen.hxx"
42 #include "SMESH_Mesh.hxx"
43 #include "SMESH_HypoFilter.hxx"
44 #include "SMESH_subMesh.hxx"
45 #include "SMESH_subMeshEventListener.hxx"
46 #include "SMESH_Comment.hxx"
48 #include "SMDS_MeshElement.hxx"
49 #include "SMDS_MeshNode.hxx"
51 #include "Utils_SALOME_Exception.hxx"
52 #include "utilities.h"
54 #include <BRepAdaptor_Curve.hxx>
55 #include <BRep_Tool.hxx>
56 #include <GCPnts_AbscissaPoint.hxx>
57 #include <GCPnts_UniformAbscissa.hxx>
58 #include <GCPnts_UniformDeflection.hxx>
59 #include <Precision.hxx>
61 #include <TopExp_Explorer.hxx>
63 #include <TopoDS_Edge.hxx>
69 //=============================================================================
73 //=============================================================================
75 StdMeshers_Regular_1D::StdMeshers_Regular_1D(int hypId, int studyId,
76 SMESH_Gen * gen):SMESH_1D_Algo(hypId, studyId, gen)
78 MESSAGE("StdMeshers_Regular_1D::StdMeshers_Regular_1D");
80 _shapeType = (1 << TopAbs_EDGE);
82 _compatibleHypothesis.push_back("LocalLength");
83 _compatibleHypothesis.push_back("MaxLength");
84 _compatibleHypothesis.push_back("NumberOfSegments");
85 _compatibleHypothesis.push_back("StartEndLength");
86 _compatibleHypothesis.push_back("Deflection1D");
87 _compatibleHypothesis.push_back("Arithmetic1D");
88 _compatibleHypothesis.push_back("AutomaticLength");
90 _compatibleHypothesis.push_back("QuadraticMesh"); // auxiliary !!!
91 _compatibleHypothesis.push_back("Propagation"); // auxiliary !!!
94 //=============================================================================
98 //=============================================================================
100 StdMeshers_Regular_1D::~StdMeshers_Regular_1D()
104 //=============================================================================
108 //=============================================================================
110 bool StdMeshers_Regular_1D::CheckHypothesis
112 const TopoDS_Shape& aShape,
113 SMESH_Hypothesis::Hypothesis_Status& aStatus)
116 _quadraticMesh = false;
118 const bool ignoreAuxiliaryHyps = false;
119 const list <const SMESHDS_Hypothesis * > & hyps =
120 GetUsedHypothesis(aMesh, aShape, ignoreAuxiliaryHyps);
122 // find non-auxiliary hypothesis
123 const SMESHDS_Hypothesis *theHyp = 0;
124 list <const SMESHDS_Hypothesis * >::const_iterator h = hyps.begin();
125 for ( ; h != hyps.end(); ++h ) {
126 if ( static_cast<const SMESH_Hypothesis*>(*h)->IsAuxiliary() ) {
127 if ( strcmp( "QuadraticMesh", (*h)->GetName() ) == 0 )
128 _quadraticMesh = true;
132 theHyp = *h; // use only the first non-auxiliary hypothesis
138 aStatus = SMESH_Hypothesis::HYP_MISSING;
139 return false; // can't work without a hypothesis
142 string hypName = theHyp->GetName();
144 if (hypName == "LocalLength")
146 const StdMeshers_LocalLength * hyp =
147 dynamic_cast <const StdMeshers_LocalLength * >(theHyp);
149 _value[ BEG_LENGTH_IND ] = hyp->GetLength();
150 _value[ PRECISION_IND ] = hyp->GetPrecision();
151 ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
152 _hypType = LOCAL_LENGTH;
153 aStatus = SMESH_Hypothesis::HYP_OK;
156 else if (hypName == "MaxLength")
158 const StdMeshers_MaxLength * hyp =
159 dynamic_cast <const StdMeshers_MaxLength * >(theHyp);
161 _value[ BEG_LENGTH_IND ] = hyp->GetLength();
162 if ( hyp->GetUsePreestimatedLength() ) {
163 if ( int nbSeg = aMesh.GetGen()->GetBoundaryBoxSegmentation() )
164 _value[ BEG_LENGTH_IND ] = aMesh.GetShapeDiagonalSize() / nbSeg;
166 ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
167 _hypType = MAX_LENGTH;
168 aStatus = SMESH_Hypothesis::HYP_OK;
171 else if (hypName == "NumberOfSegments")
173 const StdMeshers_NumberOfSegments * hyp =
174 dynamic_cast <const StdMeshers_NumberOfSegments * >(theHyp);
176 _ivalue[ NB_SEGMENTS_IND ] = hyp->GetNumberOfSegments();
177 ASSERT( _ivalue[ NB_SEGMENTS_IND ] > 0 );
178 _ivalue[ DISTR_TYPE_IND ] = (int) hyp->GetDistrType();
179 switch (_ivalue[ DISTR_TYPE_IND ])
181 case StdMeshers_NumberOfSegments::DT_Scale:
182 _value[ SCALE_FACTOR_IND ] = hyp->GetScaleFactor();
183 _revEdgesIDs = hyp->GetReversedEdges();
185 case StdMeshers_NumberOfSegments::DT_TabFunc:
186 _vvalue[ TAB_FUNC_IND ] = hyp->GetTableFunction();
187 _revEdgesIDs = hyp->GetReversedEdges();
189 case StdMeshers_NumberOfSegments::DT_ExprFunc:
190 _svalue[ EXPR_FUNC_IND ] = hyp->GetExpressionFunction();
191 _revEdgesIDs = hyp->GetReversedEdges();
193 case StdMeshers_NumberOfSegments::DT_Regular:
199 if (_ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_TabFunc ||
200 _ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_ExprFunc)
201 _ivalue[ CONV_MODE_IND ] = hyp->ConversionMode();
202 _hypType = NB_SEGMENTS;
203 aStatus = SMESH_Hypothesis::HYP_OK;
206 else if (hypName == "Arithmetic1D")
208 const StdMeshers_Arithmetic1D * hyp =
209 dynamic_cast <const StdMeshers_Arithmetic1D * >(theHyp);
211 _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
212 _value[ END_LENGTH_IND ] = hyp->GetLength( false );
213 ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
214 _hypType = ARITHMETIC_1D;
216 _revEdgesIDs = hyp->GetReversedEdges();
218 aStatus = SMESH_Hypothesis::HYP_OK;
221 else if (hypName == "StartEndLength")
223 const StdMeshers_StartEndLength * hyp =
224 dynamic_cast <const StdMeshers_StartEndLength * >(theHyp);
226 _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
227 _value[ END_LENGTH_IND ] = hyp->GetLength( false );
228 ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
229 _hypType = BEG_END_LENGTH;
231 _revEdgesIDs = hyp->GetReversedEdges();
233 aStatus = SMESH_Hypothesis::HYP_OK;
236 else if (hypName == "Deflection1D")
238 const StdMeshers_Deflection1D * hyp =
239 dynamic_cast <const StdMeshers_Deflection1D * >(theHyp);
241 _value[ DEFLECTION_IND ] = hyp->GetDeflection();
242 ASSERT( _value[ DEFLECTION_IND ] > 0 );
243 _hypType = DEFLECTION;
244 aStatus = SMESH_Hypothesis::HYP_OK;
247 else if (hypName == "AutomaticLength")
249 StdMeshers_AutomaticLength * hyp = const_cast<StdMeshers_AutomaticLength *>
250 (dynamic_cast <const StdMeshers_AutomaticLength * >(theHyp));
252 _value[ BEG_LENGTH_IND ] = _value[ END_LENGTH_IND ] = hyp->GetLength( &aMesh, aShape );
253 // _value[ BEG_LENGTH_IND ] = hyp->GetLength( &aMesh, aShape );
254 // _value[ END_LENGTH_IND ] = Precision::Confusion(); // ?? or set to zero?
255 ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
256 _hypType = MAX_LENGTH;
257 aStatus = SMESH_Hypothesis::HYP_OK;
260 aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
262 return ( _hypType != NONE );
265 static bool computeParamByFunc(Adaptor3d_Curve& C3d, double first, double last,
266 double length, bool theReverse,
267 int nbSeg, Function& func,
268 list<double>& theParams)
271 //OSD::SetSignal( true );
276 MESSAGE( "computeParamByFunc" );
278 int nbPnt = 1 + nbSeg;
279 vector<double> x(nbPnt, 0.);
281 if (!buildDistribution(func, 0.0, 1.0, nbSeg, x, 1E-4))
284 MESSAGE( "Points:\n" );
286 for ( int i=0; i<=nbSeg; i++ )
288 sprintf( buf, "%f\n", float(x[i] ) );
294 // apply parameters in range [0,1] to the space of the curve
295 double prevU = first;
302 for( int i = 1; i < nbSeg; i++ )
304 double curvLength = length * (x[i] - x[i-1]) * sign;
305 GCPnts_AbscissaPoint Discret( C3d, curvLength, prevU );
306 if ( !Discret.IsDone() )
308 double U = Discret.Parameter();
309 if ( U > first && U < last )
310 theParams.push_back( U );
319 //================================================================================
321 * \brief adjust internal node parameters so that the last segment length == an
322 * \param a1 - the first segment length
323 * \param an - the last segment length
324 * \param U1 - the first edge parameter
325 * \param Un - the last edge parameter
326 * \param length - the edge length
327 * \param C3d - the edge curve
328 * \param theParams - internal node parameters to adjust
329 * \param adjustNeighbors2an - to adjust length of segments next to the last one
330 * and not to remove parameters
332 //================================================================================
334 static void compensateError(double a1, double an,
335 double U1, double Un,
337 Adaptor3d_Curve& C3d,
338 list<double> & theParams,
339 bool adjustNeighbors2an = false)
341 int i, nPar = theParams.size();
342 if ( a1 + an < length && nPar > 1 )
344 bool reverse = ( U1 > Un );
345 GCPnts_AbscissaPoint Discret(C3d, reverse ? an : -an, Un);
346 if ( !Discret.IsDone() )
348 double Utgt = Discret.Parameter(); // target value of the last parameter
349 list<double>::reverse_iterator itU = theParams.rbegin();
350 double Ul = *itU++; // real value of the last parameter
351 double dUn = Utgt - Ul; // parametric error of <an>
352 if ( Abs(dUn) <= Precision::Confusion() )
354 double dU = Abs( Ul - *itU ); // parametric length of the last but one segment
355 if ( adjustNeighbors2an || Abs(dUn) < 0.5 * dU ) { // last segment is a bit shorter than it should
356 // move the last parameter to the edge beginning
358 else { // last segment is much shorter than it should -> remove the last param and
359 theParams.pop_back(); nPar--; // move the rest points toward the edge end
360 dUn = Utgt - theParams.back();
363 double q = dUn / ( nPar - 1 );
364 if ( !adjustNeighbors2an ) {
365 for ( itU = theParams.rbegin(), i = 1; i < nPar; itU++, i++ ) {
371 theParams.back() += dUn;
372 double sign = reverse ? -1 : 1;
373 double prevU = theParams.back();
374 itU = theParams.rbegin();
375 for ( ++itU, i = 2; i < nPar; ++itU, i++ ) {
376 double newU = *itU + dUn;
377 if ( newU*sign < prevU*sign ) {
381 else { // set U between prevU and next valid param
382 list<double>::reverse_iterator itU2 = itU;
385 while ( (*itU2)*sign > prevU*sign ) {
388 dU = ( *itU2 - prevU ) / nb;
389 while ( itU != itU2 ) {
399 //================================================================================
401 * \brief Class used to clean mesh on edges when 0D hyp modified.
402 * Common approach doesn't work when 0D algo is missing because the 0D hyp is
403 * considered as not participating in computation whereas it is used by 1D algo.
405 //================================================================================
407 // struct VertexEventListener : public SMESH_subMeshEventListener
409 // VertexEventListener():SMESH_subMeshEventListener(0) // won't be deleted by submesh
412 // * \brief Clean mesh on edges
413 // * \param event - algo_event or compute_event itself (of SMESH_subMesh)
414 // * \param eventType - ALGO_EVENT or COMPUTE_EVENT (of SMESH_subMesh)
415 // * \param subMesh - the submesh where the event occures
417 // void ProcessEvent(const int event, const int eventType, SMESH_subMesh* subMesh,
418 // EventListenerData*, const SMESH_Hypothesis*)
420 // if ( eventType == SMESH_subMesh::ALGO_EVENT) // all algo events
422 // subMesh->ComputeStateEngine( SMESH_subMesh::MODIF_ALGO_STATE );
425 // }; // struct VertexEventListener
427 //=============================================================================
429 * \brief Sets event listener to vertex submeshes
430 * \param subMesh - submesh where algo is set
432 * This method is called when a submesh gets HYP_OK algo_state.
433 * After being set, event listener is notified on each event of a submesh.
435 //=============================================================================
437 void StdMeshers_Regular_1D::SetEventListener(SMESH_subMesh* subMesh)
439 StdMeshers_Propagation::SetPropagationMgr( subMesh );
442 //=============================================================================
445 * \param subMesh - restored submesh
447 * This method is called only if a submesh has HYP_OK algo_state.
449 //=============================================================================
451 void StdMeshers_Regular_1D::SubmeshRestored(SMESH_subMesh* subMesh)
455 //=============================================================================
457 * \brief Return StdMeshers_SegmentLengthAroundVertex assigned to vertex
459 //=============================================================================
461 const StdMeshers_SegmentLengthAroundVertex*
462 StdMeshers_Regular_1D::getVertexHyp(SMESH_Mesh & theMesh,
463 const TopoDS_Vertex & theV)
465 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName("SegmentAroundVertex_0D"));
466 if ( const SMESH_Hypothesis * h = theMesh.GetHypothesis( theV, filter, true ))
468 SMESH_Algo* algo = const_cast< SMESH_Algo* >( static_cast< const SMESH_Algo* > ( h ));
469 const list <const SMESHDS_Hypothesis *> & hypList = algo->GetUsedHypothesis( theMesh, theV, 0 );
470 if ( !hypList.empty() && string("SegmentLengthAroundVertex") == hypList.front()->GetName() )
471 return static_cast<const StdMeshers_SegmentLengthAroundVertex*>( hypList.front() );
476 //================================================================================
478 * \brief Tune parameters to fit "SegmentLengthAroundVertex" hypothesis
479 * \param theC3d - wire curve
480 * \param theLength - curve length
481 * \param theParameters - internal nodes parameters to modify
482 * \param theVf - 1st vertex
483 * \param theVl - 2nd vertex
485 //================================================================================
487 void StdMeshers_Regular_1D::redistributeNearVertices (SMESH_Mesh & theMesh,
488 Adaptor3d_Curve & theC3d,
490 std::list< double > & theParameters,
491 const TopoDS_Vertex & theVf,
492 const TopoDS_Vertex & theVl)
494 double f = theC3d.FirstParameter(), l = theC3d.LastParameter();
495 int nPar = theParameters.size();
496 for ( int isEnd1 = 0; isEnd1 < 2; ++isEnd1 )
498 const TopoDS_Vertex & V = isEnd1 ? theVf : theVl;
499 const StdMeshers_SegmentLengthAroundVertex* hyp = getVertexHyp (theMesh, V );
501 double vertexLength = hyp->GetLength();
502 if ( vertexLength > theLength / 2.0 )
504 if ( isEnd1 ) { // to have a segment of interest at end of theParameters
505 theParameters.reverse();
508 if ( _hypType == NB_SEGMENTS )
510 compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
512 else if ( nPar <= 3 )
515 vertexLength = -vertexLength;
516 GCPnts_AbscissaPoint Discret(theC3d, vertexLength, l);
517 if ( Discret.IsDone() ) {
519 theParameters.push_back( Discret.Parameter());
521 double L = GCPnts_AbscissaPoint::Length( theC3d, theParameters.back(), l);
522 if ( vertexLength < L / 2.0 )
523 theParameters.push_back( Discret.Parameter());
525 compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
531 // recompute params between the last segment and a middle one.
532 // find size of a middle segment
533 int nHalf = ( nPar-1 ) / 2;
534 list< double >::reverse_iterator itU = theParameters.rbegin();
535 std::advance( itU, nHalf );
537 double Lm = GCPnts_AbscissaPoint::Length( theC3d, Um, *itU);
538 double L = GCPnts_AbscissaPoint::Length( theC3d, *itU, l);
539 StdMeshers_Regular_1D algo( *this );
540 algo._hypType = BEG_END_LENGTH;
541 algo._value[ BEG_LENGTH_IND ] = Lm;
542 algo._value[ END_LENGTH_IND ] = vertexLength;
543 double from = *itU, to = l;
545 std::swap( from, to );
546 std::swap( algo._value[ BEG_LENGTH_IND ], algo._value[ END_LENGTH_IND ]);
549 if ( algo.computeInternalParameters( theMesh, theC3d, L, from, to, params, false ))
551 if ( isEnd1 ) params.reverse();
552 while ( 1 + nHalf-- )
553 theParameters.pop_back();
554 theParameters.splice( theParameters.end(), params );
558 compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
562 theParameters.reverse();
567 //=============================================================================
571 //=============================================================================
572 bool StdMeshers_Regular_1D::computeInternalParameters(SMESH_Mesh & theMesh,
573 Adaptor3d_Curve& theC3d,
577 list<double> & theParams,
578 const bool theReverse,
579 bool theConsiderPropagation)
583 double f = theFirstU, l = theLastU;
592 if ( _hypType == MAX_LENGTH )
594 double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
596 nbseg = 1; // degenerated edge
597 eltSize = theLength / nbseg;
599 else if ( _hypType == LOCAL_LENGTH )
601 // Local Length hypothesis
602 double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
605 bool isFound = false;
606 if (theConsiderPropagation && !_mainEdge.IsNull()) // propagated from some other edge
608 // Advanced processing to assure equal number of segments in case of Propagation
609 SMESH_subMesh* sm = theMesh.GetSubMeshContaining(_mainEdge);
611 bool computed = sm->IsMeshComputed();
613 if (sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE) {
614 sm->ComputeStateEngine(SMESH_subMesh::COMPUTE);
615 computed = sm->IsMeshComputed();
619 SMESHDS_SubMesh* smds = sm->GetSubMeshDS();
620 int nb_segments = smds->NbElements();
621 if (nbseg - 1 <= nb_segments && nb_segments <= nbseg + 1) {
628 if (!isFound) // not found by meshed edge in the propagation chain, use precision
630 double aPrecision = _value[ PRECISION_IND ];
631 double nbseg_prec = ceil((theLength / _value[ BEG_LENGTH_IND ]) - aPrecision);
632 if (nbseg_prec == (nbseg - 1)) nbseg--;
636 nbseg = 1; // degenerated edge
637 eltSize = theLength / nbseg;
641 // Number Of Segments hypothesis
642 int NbSegm = _ivalue[ NB_SEGMENTS_IND ];
643 if ( NbSegm < 1 ) return false;
644 if ( NbSegm == 1 ) return true;
646 switch (_ivalue[ DISTR_TYPE_IND ])
648 case StdMeshers_NumberOfSegments::DT_Scale:
650 double scale = _value[ SCALE_FACTOR_IND ];
652 if (fabs(scale - 1.0) < Precision::Confusion()) {
653 // special case to avoid division by zero
654 for (int i = 1; i < NbSegm; i++) {
655 double param = f + (l - f) * i / NbSegm;
656 theParams.push_back( param );
659 // general case of scale distribution
663 double alpha = pow(scale, 1.0 / (NbSegm - 1));
664 double factor = (l - f) / (1.0 - pow(alpha, NbSegm));
666 for (int i = 1; i < NbSegm; i++) {
667 double param = f + factor * (1.0 - pow(alpha, i));
668 theParams.push_back( param );
674 case StdMeshers_NumberOfSegments::DT_TabFunc:
676 FunctionTable func(_vvalue[ TAB_FUNC_IND ], _ivalue[ CONV_MODE_IND ]);
677 return computeParamByFunc(theC3d, f, l, theLength, theReverse,
678 _ivalue[ NB_SEGMENTS_IND ], func,
682 case StdMeshers_NumberOfSegments::DT_ExprFunc:
684 FunctionExpr func(_svalue[ EXPR_FUNC_IND ].c_str(), _ivalue[ CONV_MODE_IND ]);
685 return computeParamByFunc(theC3d, f, l, theLength, theReverse,
686 _ivalue[ NB_SEGMENTS_IND ], func,
690 case StdMeshers_NumberOfSegments::DT_Regular:
691 eltSize = theLength / _ivalue[ NB_SEGMENTS_IND ];
697 GCPnts_UniformAbscissa Discret(theC3d, eltSize, f, l);
698 if ( !Discret.IsDone() )
699 return error( "GCPnts_UniformAbscissa failed");
701 int NbPoints = Discret.NbPoints();
702 for ( int i = 2; i < NbPoints; i++ )
704 double param = Discret.Parameter(i);
705 theParams.push_back( param );
707 compensateError( eltSize, eltSize, f, l, theLength, theC3d, theParams ); // for PAL9899
711 case BEG_END_LENGTH: {
713 // geometric progression: SUM(n) = ( a1 - an * q ) / ( 1 - q ) = theLength
715 double a1 = _value[ BEG_LENGTH_IND ];
716 double an = _value[ END_LENGTH_IND ];
717 double q = ( theLength - a1 ) / ( theLength - an );
719 double U1 = theReverse ? l : f;
720 double Un = theReverse ? f : l;
722 double eltSize = theReverse ? -a1 : a1;
724 // computes a point on a curve <theC3d> at the distance <eltSize>
725 // from the point of parameter <param>.
726 GCPnts_AbscissaPoint Discret( theC3d, eltSize, param );
727 if ( !Discret.IsDone() ) break;
728 param = Discret.Parameter();
729 if ( f < param && param < l )
730 theParams.push_back( param );
735 compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
736 if (theReverse) theParams.reverse(); // NPAL18025
740 case ARITHMETIC_1D: {
742 // arithmetic progression: SUM(n) = ( an - a1 + q ) * ( a1 + an ) / ( 2 * q ) = theLength
744 double a1 = _value[ BEG_LENGTH_IND ];
745 double an = _value[ END_LENGTH_IND ];
747 double q = ( an - a1 ) / ( 2 *theLength/( a1 + an ) - 1 );
748 int n = int( 1 + ( an - a1 ) / q );
750 double U1 = theReverse ? l : f;
751 double Un = theReverse ? f : l;
758 while ( n-- > 0 && eltSize * ( Un - U1 ) > 0 ) {
759 // computes a point on a curve <theC3d> at the distance <eltSize>
760 // from the point of parameter <param>.
761 GCPnts_AbscissaPoint Discret( theC3d, eltSize, param );
762 if ( !Discret.IsDone() ) break;
763 param = Discret.Parameter();
764 if ( param > f && param < l )
765 theParams.push_back( param );
770 compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
771 if (theReverse) theParams.reverse(); // NPAL18025
778 GCPnts_UniformDeflection Discret(theC3d, _value[ DEFLECTION_IND ], f, l, true);
779 if ( !Discret.IsDone() )
782 int NbPoints = Discret.NbPoints();
783 for ( int i = 2; i < NbPoints; i++ )
785 double param = Discret.Parameter(i);
786 theParams.push_back( param );
797 //=============================================================================
801 //=============================================================================
803 bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & theShape)
805 if ( _hypType == NONE )
808 SMESHDS_Mesh * meshDS = theMesh.GetMeshDS();
810 const TopoDS_Edge & EE = TopoDS::Edge(theShape);
811 TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
812 int shapeID = meshDS->ShapeToIndex( E );
815 Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
817 TopoDS_Vertex VFirst, VLast;
818 TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l
820 ASSERT(!VFirst.IsNull());
821 ASSERT(!VLast.IsNull());
822 const SMDS_MeshNode * idFirst = SMESH_Algo::VertexNode( VFirst, meshDS );
823 const SMDS_MeshNode * idLast = SMESH_Algo::VertexNode( VLast, meshDS );
824 if (!idFirst || !idLast)
825 return error( COMPERR_BAD_INPUT_MESH, "No node on vertex");
829 list< double > params;
830 bool reversed = false;
831 if ( theMesh.GetShapeToMesh().ShapeType() >= TopAbs_WIRE )
832 reversed = ( EE.Orientation() == TopAbs_REVERSED );
833 if ( !_mainEdge.IsNull() )
834 reversed = ( _mainEdge.Orientation() == TopAbs_REVERSED );
835 else if ( _revEdgesIDs.size() > 0 ) {
836 for ( int i = 0; i < _revEdgesIDs.size(); i++)
837 if ( _revEdgesIDs[i] == shapeID )
838 reversed = !reversed;
841 BRepAdaptor_Curve C3d( E );
842 double length = EdgeLength( E );
843 if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, reversed, true )) {
846 redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
848 // edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
849 // only internal nodes receive an edge position with param on curve
851 const SMDS_MeshNode * idPrev = idFirst;
865 for (list<double>::iterator itU = params.begin(); itU != params.end(); itU++) {
867 gp_Pnt P = Curve->Value(param);
869 //Add the Node in the DataStructure
870 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
871 meshDS->SetNodeOnEdge(node, shapeID, param);
874 // create medium node
875 double prm = ( parPrev + param )/2;
876 gp_Pnt PM = Curve->Value(prm);
877 SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
878 meshDS->SetNodeOnEdge(NM, shapeID, prm);
879 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node, NM);
880 meshDS->SetMeshElementOnShape(edge, shapeID);
883 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
884 meshDS->SetMeshElementOnShape(edge, shapeID);
891 double prm = ( parPrev + parLast )/2;
892 gp_Pnt PM = Curve->Value(prm);
893 SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
894 meshDS->SetNodeOnEdge(NM, shapeID, prm);
895 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast, NM);
896 meshDS->SetMeshElementOnShape(edge, shapeID);
899 SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast);
900 meshDS->SetMeshElementOnShape(edge, shapeID);
905 //MESSAGE("************* Degenerated edge! *****************");
907 // Edge is a degenerated Edge : We put n = 5 points on the edge.
908 const int NbPoints = 5;
909 BRep_Tool::Range( E, f, l ); // PAL15185
910 double du = (l - f) / (NbPoints - 1);
912 gp_Pnt P = BRep_Tool::Pnt(VFirst);
914 const SMDS_MeshNode * idPrev = idFirst;
915 for (int i = 2; i < NbPoints; i++) {
916 double param = f + (i - 1) * du;
917 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
919 // create medium node
920 double prm = param - du/2.;
921 SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
922 meshDS->SetNodeOnEdge(NM, shapeID, prm);
923 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node, NM);
924 meshDS->SetMeshElementOnShape(edge, shapeID);
927 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
928 meshDS->SetMeshElementOnShape(edge, shapeID);
930 meshDS->SetNodeOnEdge(node, shapeID, param);
934 // create medium node
935 double prm = l - du/2.;
936 SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
937 meshDS->SetNodeOnEdge(NM, shapeID, prm);
938 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast, NM);
939 meshDS->SetMeshElementOnShape(edge, shapeID);
942 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast);
943 meshDS->SetMeshElementOnShape(edge, shapeID);
950 //=============================================================================
954 //=============================================================================
956 bool StdMeshers_Regular_1D::Evaluate(SMESH_Mesh & theMesh,
957 const TopoDS_Shape & theShape,
958 MapShapeNbElems& aResMap)
960 if ( _hypType == NONE )
963 SMESHDS_Mesh * meshDS = theMesh.GetMeshDS();
965 const TopoDS_Edge & EE = TopoDS::Edge(theShape);
966 TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
967 // int shapeID = meshDS->ShapeToIndex( E );
970 Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
972 TopoDS_Vertex VFirst, VLast;
973 TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l
975 ASSERT(!VFirst.IsNull());
976 ASSERT(!VLast.IsNull());
978 std::vector<int> aVec(17);
979 for(int i=0; i<17; i++) aVec[i] = 0;
981 if (!Curve.IsNull()) {
982 list< double > params;
984 BRepAdaptor_Curve C3d( E );
985 double length = EdgeLength( E );
986 if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, false, true )) {
987 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
988 aResMap.insert(std::make_pair(sm,aVec));
989 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
990 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
993 redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
996 aVec[0] = 2*params.size() + 1;
997 aVec[2] = params.size() + 1;
1000 aVec[0] = params.size();
1001 aVec[1] = params.size() + 1;
1006 //MESSAGE("************* Degenerated edge! *****************");
1007 // Edge is a degenerated Edge : We put n = 5 points on the edge.
1008 if(_quadraticMesh) {
1018 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1019 aResMap.insert(std::make_pair(sm,aVec));
1025 //=============================================================================
1027 * See comments in SMESH_Algo.cxx
1029 //=============================================================================
1031 const list <const SMESHDS_Hypothesis *> &
1032 StdMeshers_Regular_1D::GetUsedHypothesis(SMESH_Mesh & aMesh,
1033 const TopoDS_Shape & aShape,
1034 const bool ignoreAuxiliary)
1036 _usedHypList.clear();
1037 _mainEdge.Nullify();
1039 SMESH_HypoFilter auxiliaryFilter, compatibleFilter;
1040 auxiliaryFilter.Init( SMESH_HypoFilter::IsAuxiliary() );
1041 const bool ignoreAux = true;
1042 InitCompatibleHypoFilter( compatibleFilter, ignoreAux );
1044 // get non-auxiliary assigned to aShape
1045 int nbHyp = aMesh.GetHypotheses( aShape, compatibleFilter, _usedHypList, false );
1047 if (nbHyp == 0 && aShape.ShapeType() == TopAbs_EDGE)
1049 // Check, if propagated from some other edge
1050 _mainEdge = StdMeshers_Propagation::GetPropagationSource( aMesh, aShape );
1051 if ( !_mainEdge.IsNull() )
1053 // Propagation of 1D hypothesis from <aMainEdge> on this edge;
1054 // get non-auxiliary assigned to _mainEdge
1055 nbHyp = aMesh.GetHypotheses( _mainEdge, compatibleFilter, _usedHypList, true );
1059 if (nbHyp == 0) // nothing propagated nor assigned to aShape
1061 SMESH_Algo::GetUsedHypothesis( aMesh, aShape, ignoreAuxiliary );
1062 nbHyp = _usedHypList.size();
1066 // get auxiliary hyps from aShape
1067 aMesh.GetHypotheses( aShape, auxiliaryFilter, _usedHypList, true );
1069 if ( nbHyp > 1 && ignoreAuxiliary )
1070 _usedHypList.clear(); //only one compatible non-auxiliary hypothesis allowed
1072 return _usedHypList;