Salome HOME
Update copyrights
[modules/smesh.git] / src / StdMeshers / StdMeshers_Regular_1D.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D, 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 //  File   : StdMeshers_Regular_1D.cxx
24 //           Moved here from SMESH_Regular_1D.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //
28 #include "StdMeshers_Regular_1D.hxx"
29
30 #include "SMDS_MeshElement.hxx"
31 #include "SMDS_MeshNode.hxx"
32 #include "SMESHDS_Mesh.hxx"
33 #include "SMESH_Comment.hxx"
34 #include "SMESH_Gen.hxx"
35 #include "SMESH_HypoFilter.hxx"
36 #include "SMESH_Mesh.hxx"
37 #include "SMESH_subMesh.hxx"
38 #include "SMESH_subMeshEventListener.hxx"
39 #include "StdMeshers_Adaptive1D.hxx"
40 #include "StdMeshers_Arithmetic1D.hxx"
41 #include "StdMeshers_AutomaticLength.hxx"
42 #include "StdMeshers_Geometric1D.hxx"
43 #include "StdMeshers_Deflection1D.hxx"
44 #include "StdMeshers_Distribution.hxx"
45 #include "StdMeshers_FixedPoints1D.hxx"
46 #include "StdMeshers_LocalLength.hxx"
47 #include "StdMeshers_MaxLength.hxx"
48 #include "StdMeshers_NumberOfSegments.hxx"
49 #include "StdMeshers_Propagation.hxx"
50 #include "StdMeshers_SegmentLengthAroundVertex.hxx"
51 #include "StdMeshers_StartEndLength.hxx"
52
53 #include <Utils_SALOME_Exception.hxx>
54 #include <utilities.h>
55
56 #include <BRepAdaptor_Curve.hxx>
57 #include <BRep_Tool.hxx>
58 #include <GCPnts_AbscissaPoint.hxx>
59 #include <GCPnts_UniformAbscissa.hxx>
60 #include <GCPnts_UniformDeflection.hxx>
61 #include <Precision.hxx>
62 #include <TopExp.hxx>
63 #include <TopExp_Explorer.hxx>
64 #include <TopoDS.hxx>
65 #include <TopoDS_Edge.hxx>
66 #include <TopoDS_Vertex.hxx>
67
68 #include <string>
69 #include <limits>
70
71 using namespace std;
72 using namespace StdMeshers;
73
74 //=============================================================================
75 /*!
76  *
77  */
78 //=============================================================================
79
80 StdMeshers_Regular_1D::StdMeshers_Regular_1D(int         hypId,
81                                              SMESH_Gen * gen)
82   :SMESH_1D_Algo( hypId, gen )
83 {
84   _name = "Regular_1D";
85   _shapeType = (1 << TopAbs_EDGE);
86   _fpHyp = 0;
87
88   _compatibleHypothesis.push_back("LocalLength");
89   _compatibleHypothesis.push_back("MaxLength");
90   _compatibleHypothesis.push_back("NumberOfSegments");
91   _compatibleHypothesis.push_back("StartEndLength");
92   _compatibleHypothesis.push_back("Deflection1D");
93   _compatibleHypothesis.push_back("Arithmetic1D");
94   _compatibleHypothesis.push_back("GeometricProgression");
95   _compatibleHypothesis.push_back("FixedPoints1D");
96   _compatibleHypothesis.push_back("AutomaticLength");
97   _compatibleHypothesis.push_back("Adaptive1D");
98   // auxiliary:
99   _compatibleHypothesis.push_back("QuadraticMesh");
100   _compatibleHypothesis.push_back("Propagation");
101   _compatibleHypothesis.push_back("PropagOfDistribution");
102 }
103
104 //=============================================================================
105 /*!
106  *
107  */
108 //=============================================================================
109
110 StdMeshers_Regular_1D::~StdMeshers_Regular_1D()
111 {
112 }
113
114 //=============================================================================
115 /*!
116  *
117  */
118 //=============================================================================
119
120 bool StdMeshers_Regular_1D::CheckHypothesis( SMESH_Mesh&         aMesh,
121                                              const TopoDS_Shape& aShape,
122                                              Hypothesis_Status&  aStatus )
123 {
124   _hypType        = NONE;
125   _quadraticMesh  = false;
126   _onlyUnaryInput = true;
127
128   // check propagation in a redefined GetUsedHypothesis()
129   const list <const SMESHDS_Hypothesis * > & hyps =
130     GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliaryHyps=*/false);
131
132   const SMESH_HypoFilter & propagFilter = StdMeshers_Propagation::GetFilter();
133
134   // find non-auxiliary hypothesis
135   const SMESHDS_Hypothesis *theHyp = 0;
136   set< string > propagTypes;
137   list <const SMESHDS_Hypothesis * >::const_iterator h = hyps.begin();
138   for ( ; h != hyps.end(); ++h ) {
139     if ( static_cast<const SMESH_Hypothesis*>(*h)->IsAuxiliary() ) {
140       if ( strcmp( "QuadraticMesh", (*h)->GetName() ) == 0 )
141         _quadraticMesh = true;
142       if ( propagFilter.IsOk( static_cast< const SMESH_Hypothesis*>( *h ), aShape ))
143         propagTypes.insert( (*h)->GetName() );
144     }
145     else {
146       if ( !theHyp )
147         theHyp = *h; // use only the first non-auxiliary hypothesis
148     }
149   }
150
151   if ( !theHyp )
152   {
153     aStatus = SMESH_Hypothesis::HYP_MISSING;
154     return false;  // can't work without a hypothesis
155   }
156
157   string hypName = theHyp->GetName();
158
159   if ( !_mainEdge.IsNull() && _hypType == DISTRIB_PROPAGATION )
160   {
161     aStatus = SMESH_Hypothesis::HYP_OK;
162   }
163   else if ( hypName == "LocalLength" )
164   {
165     const StdMeshers_LocalLength * hyp =
166       dynamic_cast <const StdMeshers_LocalLength * >(theHyp);
167     ASSERT(hyp);
168     _value[ BEG_LENGTH_IND ] = hyp->GetLength();
169     _value[ PRECISION_IND  ] = hyp->GetPrecision();
170     ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
171     _hypType = LOCAL_LENGTH;
172     aStatus = SMESH_Hypothesis::HYP_OK;
173   }
174
175   else if ( hypName == "MaxLength" )
176   {
177     const StdMeshers_MaxLength * hyp =
178       dynamic_cast <const StdMeshers_MaxLength * >(theHyp);
179     ASSERT(hyp);
180     _value[ BEG_LENGTH_IND ] = hyp->GetLength();
181     if ( hyp->GetUsePreestimatedLength() ) {
182       if ( int nbSeg = aMesh.GetGen()->GetBoundaryBoxSegmentation() )
183         _value[ BEG_LENGTH_IND ] = aMesh.GetShapeDiagonalSize() / nbSeg;
184     }
185     ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
186     _hypType = MAX_LENGTH;
187     aStatus = SMESH_Hypothesis::HYP_OK;
188   }
189
190   else if ( hypName == "NumberOfSegments" )
191   {
192     const StdMeshers_NumberOfSegments * hyp =
193       dynamic_cast <const StdMeshers_NumberOfSegments * >(theHyp);
194     ASSERT(hyp);
195     _ivalue[ NB_SEGMENTS_IND  ] = hyp->GetNumberOfSegments();
196     ASSERT( _ivalue[ NB_SEGMENTS_IND ] > 0 );
197     _ivalue[ DISTR_TYPE_IND ] = (int) hyp->GetDistrType();
198     switch (_ivalue[ DISTR_TYPE_IND ])
199     {
200     case StdMeshers_NumberOfSegments::DT_Scale:
201       _value[ SCALE_FACTOR_IND ] = hyp->GetScaleFactor();
202       _revEdgesIDs = hyp->GetReversedEdges();
203       break;
204     case StdMeshers_NumberOfSegments::DT_TabFunc:
205       _vvalue[ TAB_FUNC_IND ] = hyp->GetTableFunction();
206       _revEdgesIDs = hyp->GetReversedEdges();
207       break;
208     case StdMeshers_NumberOfSegments::DT_ExprFunc:
209       _svalue[ EXPR_FUNC_IND ] = hyp->GetExpressionFunction();
210       _revEdgesIDs = hyp->GetReversedEdges();
211       break;
212     case StdMeshers_NumberOfSegments::DT_Regular:
213       break;
214     default:
215       ASSERT(0);
216       break;
217     }
218     if (_ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_TabFunc ||
219         _ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_ExprFunc)
220         _ivalue[ CONV_MODE_IND ] = hyp->ConversionMode();
221     _hypType = NB_SEGMENTS;
222     aStatus = SMESH_Hypothesis::HYP_OK;
223   }
224
225   else if ( hypName == "Arithmetic1D" )
226   {
227     const StdMeshers_Arithmetic1D * hyp =
228       dynamic_cast <const StdMeshers_Arithmetic1D * >(theHyp);
229     ASSERT(hyp);
230     _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
231     _value[ END_LENGTH_IND ] = hyp->GetLength( false );
232     ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
233     _hypType = ARITHMETIC_1D;
234
235     _revEdgesIDs = hyp->GetReversedEdges();
236
237     aStatus = SMESH_Hypothesis::HYP_OK;
238   }
239
240   else if ( hypName == "GeometricProgression" )
241   {
242     const StdMeshers_Geometric1D * hyp =
243       dynamic_cast <const StdMeshers_Geometric1D * >(theHyp);
244     ASSERT(hyp);
245     _value[ BEG_LENGTH_IND ] = hyp->GetStartLength();
246     _value[ END_LENGTH_IND ] = hyp->GetCommonRatio();
247     ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
248     _hypType = GEOMETRIC_1D;
249
250     _revEdgesIDs = hyp->GetReversedEdges();
251
252     aStatus = SMESH_Hypothesis::HYP_OK;
253   }
254
255   else if ( hypName == "FixedPoints1D" ) {
256     _fpHyp = dynamic_cast <const StdMeshers_FixedPoints1D*>(theHyp);
257     ASSERT(_fpHyp);
258     _hypType = FIXED_POINTS_1D;
259
260     _revEdgesIDs = _fpHyp->GetReversedEdges();
261
262     aStatus = SMESH_Hypothesis::HYP_OK;
263   }
264
265   else if ( hypName == "StartEndLength" )
266   {
267     const StdMeshers_StartEndLength * hyp =
268       dynamic_cast <const StdMeshers_StartEndLength * >(theHyp);
269     ASSERT(hyp);
270     _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
271     _value[ END_LENGTH_IND ] = hyp->GetLength( false );
272     ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
273     _hypType = BEG_END_LENGTH;
274
275     _revEdgesIDs = hyp->GetReversedEdges();
276
277     aStatus = SMESH_Hypothesis::HYP_OK;
278   }
279
280   else if ( hypName == "Deflection1D" )
281   {
282     const StdMeshers_Deflection1D * hyp =
283       dynamic_cast <const StdMeshers_Deflection1D * >(theHyp);
284     ASSERT(hyp);
285     _value[ DEFLECTION_IND ] = hyp->GetDeflection();
286     ASSERT( _value[ DEFLECTION_IND ] > 0 );
287     _hypType = DEFLECTION;
288     aStatus = SMESH_Hypothesis::HYP_OK;
289   }
290
291   else if ( hypName == "AutomaticLength" )
292   {
293     StdMeshers_AutomaticLength * hyp = const_cast<StdMeshers_AutomaticLength *>
294       (dynamic_cast <const StdMeshers_AutomaticLength * >(theHyp));
295     ASSERT(hyp);
296     _value[ BEG_LENGTH_IND ] = _value[ END_LENGTH_IND ] = hyp->GetLength( &aMesh, aShape );
297     ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
298     _hypType = MAX_LENGTH;
299     aStatus = SMESH_Hypothesis::HYP_OK;
300   }
301   else if ( hypName == "Adaptive1D" )
302   {
303     _adaptiveHyp = dynamic_cast < const StdMeshers_Adaptive1D* >(theHyp);
304     ASSERT(_adaptiveHyp);
305     _hypType = ADAPTIVE;
306     _onlyUnaryInput = false;
307     aStatus = SMESH_Hypothesis::HYP_OK;
308   }
309   else
310   {
311     aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
312   }
313
314   if ( propagTypes.size() > 1 && aStatus == HYP_OK )
315   {
316     // detect concurrent Propagation hyps
317     _usedHypList.clear();
318     list< TopoDS_Shape > assignedTo;
319     if ( aMesh.GetHypotheses( aShape, propagFilter, _usedHypList, true, &assignedTo ) > 1 )
320     {
321       // find most simple shape and a hyp on it
322       int simpleShape = TopAbs_COMPOUND;
323       const SMESHDS_Hypothesis* localHyp = 0;
324       list< TopoDS_Shape >::iterator            shape = assignedTo.begin();
325       list< const SMESHDS_Hypothesis *>::iterator hyp = _usedHypList.begin();
326       for ( ; shape != assignedTo.end(); ++shape )
327         if ( shape->ShapeType() > simpleShape )
328         {
329           simpleShape = shape->ShapeType();
330           localHyp = (*hyp);
331         }
332       // check if there a different hyp on simpleShape
333       shape = assignedTo.begin();
334       hyp = _usedHypList.begin();
335       for ( ; hyp != _usedHypList.end(); ++hyp, ++shape )
336         if ( shape->ShapeType() == simpleShape &&
337              !localHyp->IsSameName( **hyp ))
338         {
339           aStatus = HYP_INCOMPAT_HYPS;
340           return error( SMESH_Comment("Hypotheses of both \"")
341                         << StdMeshers_Propagation::GetName() << "\" and \""
342                         << StdMeshers_PropagOfDistribution::GetName()
343                         << "\" types can't be applied to the same edge");
344         }
345     }
346   }
347
348   return ( aStatus == SMESH_Hypothesis::HYP_OK );
349 }
350
351 static bool computeParamByFunc(Adaptor3d_Curve& C3d,
352                                double first, double last, double length,
353                                bool theReverse, int nbSeg, Function& func,
354                                list<double>& theParams)
355 {
356   // never do this way
357   //OSD::SetSignal( true );
358
359   if ( nbSeg <= 0 )
360     return false;
361
362   int nbPnt = 1 + nbSeg;
363   vector<double> x( nbPnt, 0. );
364
365   if ( !buildDistribution( func, 0.0, 1.0, nbSeg, x, 1E-4 ))
366      return false;
367
368   // apply parameters in range [0,1] to the space of the curve
369   double prevU = first;
370   double  sign = 1.;
371   if ( theReverse )
372   {
373     prevU = last;
374     sign  = -1.;
375   }
376
377   for ( int i = 1; i < nbSeg; i++ )
378   {
379     double curvLength = length * (x[i] - x[i-1]) * sign;
380     double tol        = Min( Precision::Confusion(), curvLength / 100. );
381     GCPnts_AbscissaPoint Discret( tol, C3d, curvLength, prevU );
382     if ( !Discret.IsDone() )
383       return false;
384     double U = Discret.Parameter();
385     if ( U > first && U < last )
386       theParams.push_back( U );
387     else
388       return false;
389     prevU = U;
390   }
391   if ( theReverse )
392     theParams.reverse();
393
394   return true;
395 }
396
397
398 //================================================================================
399 /*!
400  * \brief adjust internal node parameters so that the last segment length == an
401  *  \param a1 - the first segment length
402  *  \param an - the last segment length
403  *  \param U1 - the first edge parameter
404  *  \param Un - the last edge parameter
405  *  \param length - the edge length
406  *  \param C3d - the edge curve
407  *  \param theParams - internal node parameters to adjust
408  *  \param adjustNeighbors2an - to adjust length of segments next to the last one
409  *   and not to remove parameters
410  */
411 //================================================================================
412
413 static void compensateError(double a1, double an,
414                             double U1, double Un,
415                             double            length,
416                             Adaptor3d_Curve&  C3d,
417                             list<double> &    theParams,
418                             bool              adjustNeighbors2an = false)
419 {
420   int i, nPar = theParams.size();
421   if ( a1 + an <= length && nPar > 1 )
422   {
423     bool reverse = ( U1 > Un );
424     double tol   = Min( Precision::Confusion(), 0.01 * an );
425     GCPnts_AbscissaPoint Discret( tol, C3d, reverse ? an : -an, Un );
426     if ( !Discret.IsDone() )
427       return;
428     double Utgt = Discret.Parameter(); // target value of the last parameter
429     list<double>::reverse_iterator itU = theParams.rbegin();
430     double Ul = *itU++; // real value of the last parameter
431     double dUn = Utgt - Ul; // parametric error of <an>
432     double dU = Abs( Ul - *itU ); // parametric length of the last but one segment
433     if ( Abs(dUn) <= 1e-3 * dU )
434       return;
435     if ( adjustNeighbors2an || Abs(dUn) < 0.5 * dU ) { // last segment is a bit shorter than it should
436       // move the last parameter to the edge beginning
437     }
438     else {  // last segment is much shorter than it should -> remove the last param and
439       theParams.pop_back(); nPar--; // move the rest points toward the edge end
440       dUn = Utgt - theParams.back();
441     }
442
443     if ( !adjustNeighbors2an )
444     {
445       double q = dUn / ( Utgt - Un ); // (signed) factor of segment length change
446       for ( itU = theParams.rbegin(), i = 1; i < nPar; i++ ) {
447         double prevU = *itU;
448         (*itU) += dUn;
449         ++itU;
450         dUn = q * (*itU - prevU) * (prevU-U1)/(Un-U1);
451       }
452     }
453     else if ( nPar == 1 )
454     {
455       theParams.back() += dUn;
456     }
457     else
458     {
459       double q  = dUn / ( nPar - 1 );
460       theParams.back() += dUn;
461       double sign = reverse ? -1 : 1;
462       double prevU = theParams.back();
463       itU = theParams.rbegin();
464       for ( ++itU, i = 2; i < nPar; ++itU, i++ ) {
465         double newU = *itU + dUn;
466         if ( newU*sign < prevU*sign ) {
467           prevU = *itU = newU;
468           dUn -= q;
469         }
470         else { // set U between prevU and next valid param
471           list<double>::reverse_iterator itU2 = itU;
472           ++itU2;
473           int nb = 2;
474           while ( (*itU2)*sign > prevU*sign ) {
475             ++itU2; ++nb;
476           }
477           dU = ( *itU2 - prevU ) / nb;
478           while ( itU != itU2 ) {
479             *itU += dU; ++itU;
480           }
481           break;
482         }
483       }
484     }
485   }
486 }
487
488 //================================================================================
489 /*!
490  * \brief Class used to clean mesh on edges when 0D hyp modified.
491  * Common approach doesn't work when 0D algo is missing because the 0D hyp is
492  * considered as not participating in computation whereas it is used by 1D algo.
493  */
494 //================================================================================
495
496 // struct VertexEventListener : public SMESH_subMeshEventListener
497 // {
498 //   VertexEventListener():SMESH_subMeshEventListener(0) // won't be deleted by submesh
499 //   {}
500 //   /*!
501 //    * \brief Clean mesh on edges
502 //    * \param event - algo_event or compute_event itself (of SMESH_subMesh)
503 //    * \param eventType - ALGO_EVENT or COMPUTE_EVENT (of SMESH_subMesh)
504 //    * \param subMesh - the submesh where the event occurs
505 //    */
506 //   void ProcessEvent(const int event, const int eventType, SMESH_subMesh* subMesh,
507 //                     EventListenerData*, const SMESH_Hypothesis*)
508 //   {
509 //     if ( eventType == SMESH_subMesh::ALGO_EVENT) // all algo events
510 //     {
511 //       subMesh->ComputeStateEngine( SMESH_subMesh::MODIF_ALGO_STATE );
512 //     }
513 //   }
514 // }; // struct VertexEventListener
515
516 //=============================================================================
517 /*!
518  * \brief Sets event listener to vertex submeshes
519  * \param subMesh - submesh where algo is set
520  *
521  * This method is called when a submesh gets HYP_OK algo_state.
522  * After being set, event listener is notified on each event of a submesh.
523  */
524 //=============================================================================
525
526 void StdMeshers_Regular_1D::SetEventListener(SMESH_subMesh* subMesh)
527 {
528   StdMeshers_Propagation::SetPropagationMgr( subMesh );
529 }
530
531 //=============================================================================
532 /*!
533  * \brief Do nothing
534  * \param subMesh - restored submesh
535  *
536  * This method is called only if a submesh has HYP_OK algo_state.
537  */
538 //=============================================================================
539
540 void StdMeshers_Regular_1D::SubmeshRestored(SMESH_subMesh* subMesh)
541 {
542 }
543
544 //=============================================================================
545 /*!
546  * \brief Return StdMeshers_SegmentLengthAroundVertex assigned to vertex
547  */
548 //=============================================================================
549
550 const StdMeshers_SegmentLengthAroundVertex*
551 StdMeshers_Regular_1D::getVertexHyp(SMESH_Mesh &          theMesh,
552                                     const TopoDS_Vertex & theV)
553 {
554   static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName("SegmentAroundVertex_0D"));
555   if ( const SMESH_Hypothesis * h = theMesh.GetHypothesis( theV, filter, true ))
556   {
557     SMESH_Algo* algo = const_cast< SMESH_Algo* >( static_cast< const SMESH_Algo* > ( h ));
558     const list <const SMESHDS_Hypothesis *> & hypList = algo->GetUsedHypothesis( theMesh, theV, 0 );
559     if ( !hypList.empty() && string("SegmentLengthAroundVertex") == hypList.front()->GetName() )
560       return static_cast<const StdMeshers_SegmentLengthAroundVertex*>( hypList.front() );
561   }
562   return 0;
563 }
564
565 //================================================================================
566 /*!
567  * \brief Tune parameters to fit "SegmentLengthAroundVertex" hypothesis
568   * \param theC3d - wire curve
569   * \param theLength - curve length
570   * \param theParameters - internal nodes parameters to modify
571   * \param theVf - 1st vertex
572   * \param theVl - 2nd vertex
573  */
574 //================================================================================
575
576 void StdMeshers_Regular_1D::redistributeNearVertices (SMESH_Mesh &          theMesh,
577                                                       Adaptor3d_Curve &     theC3d,
578                                                       double                theLength,
579                                                       std::list< double > & theParameters,
580                                                       const TopoDS_Vertex & theVf,
581                                                       const TopoDS_Vertex & theVl)
582 {
583   double f = theC3d.FirstParameter(), l = theC3d.LastParameter();
584   int nPar = theParameters.size();
585   for ( int isEnd1 = 0; isEnd1 < 2; ++isEnd1 )
586   {
587     const TopoDS_Vertex & V = isEnd1 ? theVf : theVl;
588     const StdMeshers_SegmentLengthAroundVertex* hyp = getVertexHyp (theMesh, V );
589     if ( hyp ) {
590       double vertexLength = hyp->GetLength();
591       if ( vertexLength > theLength / 2.0 )
592         continue;
593       if ( isEnd1 ) { // to have a segment of interest at end of theParameters
594         theParameters.reverse();
595         std::swap( f, l );
596       }
597       if ( _hypType == NB_SEGMENTS )
598       {
599         compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
600       }
601       else if ( nPar <= 3 )
602       {
603         if ( !isEnd1 )
604           vertexLength = -vertexLength;
605         double tol = Min( Precision::Confusion(), 0.01 * vertexLength );
606         GCPnts_AbscissaPoint Discret( tol, theC3d, vertexLength, l );
607         if ( Discret.IsDone() ) {
608           if ( nPar == 0 )
609             theParameters.push_back( Discret.Parameter());
610           else {
611             double L = GCPnts_AbscissaPoint::Length( theC3d, theParameters.back(), l);
612             if ( vertexLength < L / 2.0 )
613               theParameters.push_back( Discret.Parameter());
614             else
615               compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
616           }
617         }
618       }
619       else
620       {
621         // recompute params between the last segment and a middle one.
622         // find size of a middle segment
623         int nHalf = ( nPar-1 ) / 2;
624         list< double >::reverse_iterator itU = theParameters.rbegin();
625         std::advance( itU, nHalf );
626         double Um = *itU++;
627         double Lm = GCPnts_AbscissaPoint::Length( theC3d, Um, *itU);
628         double L = GCPnts_AbscissaPoint::Length( theC3d, *itU, l);
629         static StdMeshers_Regular_1D* auxAlgo = 0;
630         if ( !auxAlgo ) {
631           auxAlgo = new StdMeshers_Regular_1D( _gen->GetANewId(), _gen );
632           auxAlgo->_hypType = BEG_END_LENGTH;
633         }
634         auxAlgo->_value[ BEG_LENGTH_IND ] = Lm;
635         auxAlgo->_value[ END_LENGTH_IND ] = vertexLength;
636         double from = *itU, to = l;
637         if ( isEnd1 ) {
638           std::swap( from, to );
639           std::swap( auxAlgo->_value[ BEG_LENGTH_IND ], auxAlgo->_value[ END_LENGTH_IND ]);
640         }
641         list<double> params;
642         if ( auxAlgo->computeInternalParameters( theMesh, theC3d, L, from, to, params, false ))
643         {
644           if ( isEnd1 ) params.reverse();
645           while ( 1 + nHalf-- )
646             theParameters.pop_back();
647           theParameters.splice( theParameters.end(), params );
648         }
649         else
650         {
651           compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
652         }
653       }
654       if ( isEnd1 )
655         theParameters.reverse();
656     }
657   }
658 }
659
660 //=============================================================================
661 /*!
662  *  
663  */
664 //=============================================================================
665 bool StdMeshers_Regular_1D::computeInternalParameters(SMESH_Mesh &     theMesh,
666                                                       Adaptor3d_Curve& theC3d,
667                                                       double           theLength,
668                                                       double           theFirstU,
669                                                       double           theLastU,
670                                                       list<double> &   theParams,
671                                                       const bool       theReverse,
672                                                       bool             theConsiderPropagation)
673 {
674   theParams.clear();
675
676   double f = theFirstU, l = theLastU;
677
678   // Propagation Of Distribution
679   //
680   if ( !_mainEdge.IsNull() && _hypType == DISTRIB_PROPAGATION )
681   {
682     TopoDS_Edge mainEdge = TopoDS::Edge( _mainEdge ); // should not be a reference!
683     _gen->Compute( theMesh, mainEdge, SMESH_Gen::SHAPE_ONLY_UPWARD );
684
685     SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( mainEdge );
686     if ( !smDS )
687       return error("No mesh on the source edge of Propagation Of Distribution");
688     if ( smDS->NbNodes() < 1 )
689       return true; // 1 segment
690
691     map< double, const SMDS_MeshNode* > mainEdgeParamsOfNodes;
692     if ( ! SMESH_Algo::GetSortedNodesOnEdge( theMesh.GetMeshDS(), mainEdge, _quadraticMesh,
693                                              mainEdgeParamsOfNodes, SMDSAbs_Edge ))
694       return error("Bad node parameters on the source edge of Propagation Of Distribution");
695     vector< double > segLen( mainEdgeParamsOfNodes.size() - 1 );
696     double totalLen = 0;
697     BRepAdaptor_Curve mainEdgeCurve( mainEdge );
698     map< double, const SMDS_MeshNode* >::iterator
699       u_n2 = mainEdgeParamsOfNodes.begin(), u_n1 = u_n2++;
700     for ( size_t i = 1; i < mainEdgeParamsOfNodes.size(); ++i, ++u_n1, ++u_n2 )
701     {
702       segLen[ i-1 ] = GCPnts_AbscissaPoint::Length( mainEdgeCurve,
703                                                     u_n1->first,
704                                                     u_n2->first);
705       totalLen += segLen[ i-1 ];
706     }
707     for ( size_t i = 0; i < segLen.size(); ++i )
708       segLen[ i ] *= theLength / totalLen;
709
710     size_t  iSeg = theReverse ? segLen.size()-1 : 0;
711     size_t  dSeg = theReverse ? -1 : +1;
712     double param = theFirstU;
713     size_t nbParams = 0;
714     for ( int i = 0, nb = segLen.size()-1; i < nb; ++i, iSeg += dSeg )
715     {
716       double tol = Min( Precision::Confusion(), 0.01 * segLen[ iSeg ]);
717       GCPnts_AbscissaPoint Discret( tol, theC3d, segLen[ iSeg ], param );
718       if ( !Discret.IsDone() ) break;
719       param = Discret.Parameter();
720       theParams.push_back( param );
721       ++nbParams;
722     }
723     if ( nbParams != segLen.size()-1 )
724       return error( SMESH_Comment("Can't divide into ") << segLen.size() << " segments");
725
726     compensateError( segLen[ theReverse ? segLen.size()-1 : 0 ],
727                      segLen[ theReverse ? 0 : segLen.size()-1 ],
728                      f, l, theLength, theC3d, theParams, true );
729     return true;
730   }
731
732
733   switch( _hypType )
734   {
735   case LOCAL_LENGTH:
736   case MAX_LENGTH:
737   case NB_SEGMENTS:
738   {
739     double eltSize = 1;
740     int nbSegments;
741     if ( _hypType == MAX_LENGTH )
742     {
743       double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
744       if (nbseg <= 0)
745         nbseg = 1; // degenerated edge
746       eltSize = theLength / nbseg * ( 1. - 1e-9 );
747       nbSegments = (int) nbseg;
748     }
749     else if ( _hypType == LOCAL_LENGTH )
750     {
751       // Local Length hypothesis
752       double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
753
754       // NPAL17873:
755       bool isFound = false;
756       if (theConsiderPropagation && !_mainEdge.IsNull()) // propagated from some other edge
757       {
758         // Advanced processing to assure equal number of segments in case of Propagation
759         SMESH_subMesh* sm = theMesh.GetSubMeshContaining(_mainEdge);
760         if (sm) {
761           bool computed = sm->IsMeshComputed();
762           if (!computed) {
763             if (sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE) {
764               _gen->Compute( theMesh, _mainEdge, /*anUpward=*/true);
765               computed = sm->IsMeshComputed();
766             }
767           }
768           if (computed) {
769             SMESHDS_SubMesh* smds = sm->GetSubMeshDS();
770             int       nb_segments = smds->NbElements();
771             if (nbseg - 1 <= nb_segments && nb_segments <= nbseg + 1) {
772               isFound = true;
773               nbseg = nb_segments;
774             }
775           }
776         }
777       }
778       if (!isFound) // not found by meshed edge in the propagation chain, use precision
779       {
780         double aPrecision = _value[ PRECISION_IND ];
781         double nbseg_prec = ceil((theLength / _value[ BEG_LENGTH_IND ]) - aPrecision);
782         if (nbseg_prec == (nbseg - 1)) nbseg--;
783       }
784
785       if (nbseg <= 0)
786         nbseg = 1;                        // degenerated edge
787       eltSize = theLength / nbseg;
788       nbSegments = (int) nbseg;
789     }
790     else
791     {
792       // Number Of Segments hypothesis
793       nbSegments = _ivalue[ NB_SEGMENTS_IND ];
794       if ( nbSegments < 1 )  return false;
795       if ( nbSegments == 1 ) return true;
796
797       switch (_ivalue[ DISTR_TYPE_IND ])
798       {
799       case StdMeshers_NumberOfSegments::DT_Scale:
800         {
801           double scale = _value[ SCALE_FACTOR_IND ];
802
803           if (fabs(scale - 1.0) < Precision::Confusion()) {
804             // special case to avoid division by zero
805             for (int i = 1; i < nbSegments; i++) {
806               double param = f + (l - f) * i / nbSegments;
807               theParams.push_back( param );
808             }
809           } else {
810             // general case of scale distribution
811             if ( theReverse )
812               scale = 1.0 / scale;
813
814             double  alpha = pow(scale, 1.0 / (nbSegments - 1));
815             double factor = (l - f) / (1.0 - pow(alpha, nbSegments));
816
817             for (int i = 1; i < nbSegments; i++) {
818               double param = f + factor * (1.0 - pow(alpha, i));
819               theParams.push_back( param );
820             }
821           }
822           const double lenFactor = theLength/(l-f);
823           const double minSegLen = Min( theParams.front() - f, l - theParams.back() );
824           const double       tol = Min( Precision::Confusion(), 0.01 * minSegLen );
825           list<double>::iterator u = theParams.begin(), uEnd = theParams.end();
826           for ( ; u != uEnd; ++u )
827           {
828             GCPnts_AbscissaPoint Discret( tol, theC3d, ((*u)-f) * lenFactor, f );
829             if ( Discret.IsDone() )
830               *u = Discret.Parameter();
831           }
832           return true;
833         }
834         break;
835       case StdMeshers_NumberOfSegments::DT_TabFunc:
836         {
837           FunctionTable func(_vvalue[ TAB_FUNC_IND ], _ivalue[ CONV_MODE_IND ]);
838           return computeParamByFunc(theC3d, f, l, theLength, theReverse,
839                                     _ivalue[ NB_SEGMENTS_IND ], func,
840                                     theParams);
841         }
842         break;
843       case StdMeshers_NumberOfSegments::DT_ExprFunc:
844         {
845           FunctionExpr func(_svalue[ EXPR_FUNC_IND ].c_str(), _ivalue[ CONV_MODE_IND ]);
846           return computeParamByFunc(theC3d, f, l, theLength, theReverse,
847                                     _ivalue[ NB_SEGMENTS_IND ], func,
848                                     theParams);
849         }
850         break;
851       case StdMeshers_NumberOfSegments::DT_Regular:
852         eltSize = theLength / nbSegments;
853         break;
854       default:
855         return false;
856       }
857     }
858
859     double tol = Min( Precision::Confusion(), 0.01 * eltSize );
860     GCPnts_UniformAbscissa Discret(theC3d, nbSegments + 1, f, l, tol );
861     if ( !Discret.IsDone() )
862       return error( "GCPnts_UniformAbscissa failed");
863     if ( Discret.NbPoints() < nbSegments + 1 )
864       Discret.Initialize(theC3d, nbSegments + 2, f, l, tol );
865
866     int NbPoints = Min( Discret.NbPoints(), nbSegments + 1 );
867     for ( int i = 2; i < NbPoints; i++ ) // skip 1st and last points
868     {
869       double param = Discret.Parameter(i);
870       theParams.push_back( param );
871     }
872     compensateError( eltSize, eltSize, f, l, theLength, theC3d, theParams, true ); // for PAL9899
873     return true;
874   }
875
876
877   case BEG_END_LENGTH: {
878
879     // geometric progression: SUM(n) = ( a1 - an * q ) / ( 1 - q ) = theLength
880
881     double a1 = _value[ BEG_LENGTH_IND ];
882     double an = _value[ END_LENGTH_IND ];
883     double q  = ( theLength - a1 ) / ( theLength - an );
884     if ( q < theLength/1e6 || 1.01*theLength < a1 + an)
885       return error ( SMESH_Comment("Invalid segment lengths (")<<a1<<" and "<<an<<") "<<
886                      "for an edge of length "<<theLength);
887
888     double      U1 = theReverse ? l : f;
889     double      Un = theReverse ? f : l;
890     double   param = U1;
891     double eltSize = theReverse ? -a1 : a1;
892     double     tol = Min( Precision::Confusion(), 0.01 * Min( a1, an ));
893     while ( 1 ) {
894       // computes a point on a curve <theC3d> at the distance <eltSize>
895       // from the point of parameter <param>.
896       GCPnts_AbscissaPoint Discret( tol, theC3d, eltSize, param );
897       if ( !Discret.IsDone() ) break;
898       param = Discret.Parameter();
899       if ( f < param && param < l )
900         theParams.push_back( param );
901       else
902         break;
903       eltSize *= q;
904     }
905     compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
906     if (theReverse) theParams.reverse(); // NPAL18025
907     return true;
908   }
909
910   case ARITHMETIC_1D:
911   {
912     // arithmetic progression: SUM(n) = ( an - a1 + q ) * ( a1 + an ) / ( 2 * q ) = theLength
913
914     double a1 = _value[ BEG_LENGTH_IND ];
915     double an = _value[ END_LENGTH_IND ];
916     if ( 1.01*theLength < a1 + an )
917       return error ( SMESH_Comment("Invalid segment lengths (")<<a1<<" and "<<an<<") "<<
918                      "for an edge of length "<<theLength);
919
920     double q = ( an - a1 ) / ( 2 *theLength/( a1 + an ) - 1 );
921     int    n = int(fabs(q) > numeric_limits<double>::min() ? ( 1+( an-a1 )/q ) : ( 1+theLength/a1 ));
922
923     double      U1 = theReverse ? l : f;
924     double      Un = theReverse ? f : l;
925     double   param = U1;
926     double eltSize = a1;
927     double     tol = Min( Precision::Confusion(), 0.01 * Min( a1, an ));
928     if ( theReverse ) {
929       eltSize = -eltSize;
930       q = -q;
931     }
932     while ( n-- > 0 && eltSize * ( Un - U1 ) > 0 ) {
933       // computes a point on a curve <theC3d> at the distance <eltSize>
934       // from the point of parameter <param>.
935       GCPnts_AbscissaPoint Discret( tol, theC3d, eltSize, param );
936       if ( !Discret.IsDone() ) break;
937       param = Discret.Parameter();
938       if ( param > f && param < l )
939         theParams.push_back( param );
940       else
941         break;
942       eltSize += q;
943     }
944     compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
945     if ( theReverse ) theParams.reverse(); // NPAL18025
946
947     return true;
948   }
949
950   case GEOMETRIC_1D:
951   {
952     double a1 = _value[ BEG_LENGTH_IND ], an = 0;
953     double q  = _value[ END_LENGTH_IND ];
954
955     double U1 = theReverse ? l : f;
956     double Un = theReverse ? f : l;
957     double param = U1;
958     double eltSize = a1;
959     if ( theReverse )
960       eltSize = -eltSize;
961
962     int nbParams = 0;
963     while ( true ) {
964       // computes a point on a curve <theC3d> at the distance <eltSize>
965       // from the point of parameter <param>.
966       double tol = Min( Precision::Confusion(), 0.01 * eltSize );
967       GCPnts_AbscissaPoint Discret( tol, theC3d, eltSize, param );
968       if ( !Discret.IsDone() ) break;
969       param = Discret.Parameter();
970       if ( f < param && param < l )
971         theParams.push_back( param );
972       else
973         break;
974       an = eltSize;
975       eltSize *= q;
976       ++nbParams;
977     }
978     if ( nbParams > 1 )
979     {
980       if ( Abs( param - Un ) < 0.2 * Abs( param - theParams.back() ))
981       {
982         compensateError( a1, Abs(eltSize), U1, Un, theLength, theC3d, theParams );
983       }
984       else if ( Abs( Un - theParams.back() ) <
985                 0.2 * Abs( theParams.back() - *(++theParams.rbegin())))
986       {
987         theParams.pop_back();
988         compensateError( a1, Abs(an), U1, Un, theLength, theC3d, theParams );
989       }
990     }
991     if (theReverse) theParams.reverse(); // NPAL18025
992
993     return true;
994   }
995
996   case FIXED_POINTS_1D:
997   {
998     const std::vector<double>& aPnts = _fpHyp->GetPoints();
999     std::vector<int>          nbsegs = _fpHyp->GetNbSegments();
1000
1001     // sort normalized params, taking into account theReverse
1002     TColStd_SequenceOfReal Params;
1003     double tol = 1e-7 / theLength; // GCPnts_UniformAbscissa allows u2-u1 > 1e-7
1004     for ( size_t i = 0; i < aPnts.size(); i++ )
1005     {
1006       if( aPnts[i] < tol || aPnts[i] > 1 - tol )
1007         continue;
1008       double u = theReverse ? ( 1 - aPnts[i] ) : aPnts[i];
1009       int    j = 1;
1010       bool IsExist = false;
1011       for ( ; j <= Params.Length(); j++ ) {
1012         if ( Abs( u - Params.Value(j) ) < tol ) {
1013           IsExist = true;
1014           break;
1015         }
1016         if ( u < Params.Value(j) ) break;
1017       }
1018       if ( !IsExist ) Params.InsertBefore( j, u );
1019     }
1020
1021     // transform normalized Params into real ones
1022     std::vector< double > uVec( Params.Length() + 2 );
1023     uVec[ 0 ] = theFirstU;
1024     double abscissa;
1025     for ( int i = 1; i <= Params.Length(); i++ )
1026     {
1027       abscissa = Params( i ) * theLength;
1028       tol      = Min( Precision::Confusion(), 0.01 * abscissa );
1029       GCPnts_AbscissaPoint APnt( tol, theC3d, abscissa, theFirstU );
1030       if ( !APnt.IsDone() )
1031         return error( "GCPnts_AbscissaPoint failed");
1032       uVec[ i ] = APnt.Parameter();
1033     }
1034     uVec.back() = theLastU;
1035
1036     // divide segments
1037     if ( theReverse )
1038     {
1039       if ((int) nbsegs.size() > Params.Length() + 1 )
1040         nbsegs.resize( Params.Length() + 1 );
1041       std::reverse( nbsegs.begin(), nbsegs.end() );
1042     }
1043     if ( nbsegs.empty() )
1044     {
1045       nbsegs.push_back( 1 );
1046     }
1047     Params.InsertBefore( 1, 0.0 );
1048     Params.Append( 1.0 );
1049     double eltSize, segmentSize, par1, par2;
1050     for ( size_t i = 0; i < uVec.size()-1; i++ )
1051     {
1052       par1 = uVec[ i   ];
1053       par2 = uVec[ i+1 ];
1054       int nbseg = ( i < nbsegs.size() ) ? nbsegs[i] : nbsegs[0];
1055       if ( nbseg == 1 )
1056       {
1057         theParams.push_back( par2 );
1058       }
1059       else
1060       {
1061         segmentSize = ( Params( i+2 ) - Params( i+1 )) * theLength;
1062         eltSize     = segmentSize / nbseg;
1063         tol         = Min( Precision::Confusion(), 0.01 * eltSize );
1064         GCPnts_UniformAbscissa Discret( theC3d, eltSize, par1, par2, tol );
1065         if ( !Discret.IsDone() )
1066           return error( "GCPnts_UniformAbscissa failed");
1067         if ( Discret.NbPoints() < nbseg + 1 ) {
1068           eltSize = segmentSize / ( nbseg + 0.5 );
1069           Discret.Initialize( theC3d, eltSize, par1, par2, tol );
1070         }
1071         int NbPoints = Discret.NbPoints();
1072         for ( int i = 2; i <= NbPoints; i++ ) {
1073           double param = Discret.Parameter(i);
1074           theParams.push_back( param );
1075         }
1076       }
1077     }
1078     theParams.pop_back();
1079
1080     return true;
1081   }
1082
1083   case DEFLECTION:
1084   {
1085     GCPnts_UniformDeflection Discret( theC3d, _value[ DEFLECTION_IND ], f, l, true );
1086     if ( !Discret.IsDone() )
1087       return false;
1088
1089     int NbPoints = Discret.NbPoints();
1090     for ( int i = 2; i < NbPoints; i++ )
1091     {
1092       double param = Discret.Parameter(i);
1093       theParams.push_back( param );
1094     }
1095     return true;
1096   }
1097
1098   default:;
1099   }
1100
1101   return false;
1102 }
1103
1104 //=============================================================================
1105 /*!
1106  *  
1107  */
1108 //=============================================================================
1109
1110 bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & theShape)
1111 {
1112   if ( _hypType == NONE )
1113     return false;
1114
1115   if ( _hypType == ADAPTIVE )
1116   {
1117     _adaptiveHyp->GetAlgo()->InitComputeError();
1118     _adaptiveHyp->GetAlgo()->Compute( theMesh, theShape );
1119     return error( _adaptiveHyp->GetAlgo()->GetComputeError() );
1120   }
1121
1122   SMESHDS_Mesh * meshDS = theMesh.GetMeshDS();
1123
1124   const TopoDS_Edge & EE = TopoDS::Edge(theShape);
1125   TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
1126   int shapeID = meshDS->ShapeToIndex( E );
1127
1128   double f, l;
1129   Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
1130
1131   TopoDS_Vertex VFirst, VLast;
1132   TopExp::Vertices(E, VFirst, VLast);   // Vfirst corresponds to f and Vlast to l
1133
1134   ASSERT(!VFirst.IsNull());
1135   ASSERT(!VLast.IsNull());
1136   const SMDS_MeshNode * nFirst = SMESH_Algo::VertexNode( VFirst, meshDS );
1137   const SMDS_MeshNode *  nLast = SMESH_Algo::VertexNode( VLast,  meshDS );
1138   if ( !nFirst || !nLast )
1139     return error( COMPERR_BAD_INPUT_MESH, "No node on vertex");
1140
1141   // remove elements created by e.g. pattern mapping (PAL21999)
1142   // CLEAN event is incorrectly ptopagated seemingly due to Propagation hyp
1143   // so TEMPORARY solution is to clean the submesh manually
1144   if (SMESHDS_SubMesh * subMeshDS = meshDS->MeshElements(theShape))
1145   {
1146     SMDS_ElemIteratorPtr ite = subMeshDS->GetElements();
1147     while (ite->more())
1148       meshDS->RemoveFreeElement(ite->next(), subMeshDS);
1149     SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes();
1150     while (itn->more()) {
1151       const SMDS_MeshNode * node = itn->next();
1152       if ( node->NbInverseElements() == 0 )
1153         meshDS->RemoveFreeNode(node, subMeshDS);
1154       else
1155         meshDS->RemoveNode(node);
1156     }
1157   }
1158
1159   double length = EdgeLength( E );
1160   if ( !Curve.IsNull() && length > 0 )
1161   {
1162     list< double > params;
1163     bool reversed = false;
1164     if ( theMesh.GetShapeToMesh().ShapeType() >= TopAbs_WIRE && _revEdgesIDs.empty() ) {
1165       // if the shape to mesh is WIRE or EDGE
1166       reversed = ( EE.Orientation() == TopAbs_REVERSED );
1167     }
1168     if ( !_mainEdge.IsNull() ) {
1169       // take into account reversing the edge the hypothesis is propagated from
1170       // (_mainEdge.Orientation() marks mutual orientation of EDGEs in propagation chain)
1171       reversed = ( _mainEdge.Orientation() == TopAbs_REVERSED );
1172       if ( _hypType != DISTRIB_PROPAGATION ) {
1173         int mainID = meshDS->ShapeToIndex(_mainEdge);
1174         if ( std::find( _revEdgesIDs.begin(), _revEdgesIDs.end(), mainID) != _revEdgesIDs.end())
1175           reversed = !reversed;
1176       }
1177     }
1178     // take into account this edge reversing
1179     if ( std::find( _revEdgesIDs.begin(), _revEdgesIDs.end(), shapeID) != _revEdgesIDs.end())
1180       reversed = !reversed;
1181
1182     BRepAdaptor_Curve C3d( E );
1183     if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, reversed, true )) {
1184       return false;
1185     }
1186     redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
1187
1188     // edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
1189     // only internal nodes receive an edge position with param on curve
1190
1191     const SMDS_MeshNode * nPrev = nFirst;
1192     double parPrev = f;
1193     double parLast = l;
1194
1195     for (list<double>::iterator itU = params.begin(); itU != params.end(); itU++) {
1196       double param = *itU;
1197       gp_Pnt P = Curve->Value(param);
1198
1199       //Add the Node in the DataStructure
1200       SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
1201       meshDS->SetNodeOnEdge(node, shapeID, param);
1202
1203       if(_quadraticMesh) {
1204         // create medium node
1205         double prm = ( parPrev + param )/2;
1206         gp_Pnt  PM = Curve->Value(prm);
1207         SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
1208         meshDS->SetNodeOnEdge(NM, shapeID, prm);
1209         SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node, NM);
1210         meshDS->SetMeshElementOnShape(edge, shapeID);
1211       }
1212       else {
1213         SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node);
1214         meshDS->SetMeshElementOnShape(edge, shapeID);
1215       }
1216
1217       nPrev   = node;
1218       parPrev = param;
1219     }
1220     if(_quadraticMesh) {
1221       double prm = ( parPrev + parLast )/2;
1222       gp_Pnt PM = Curve->Value(prm);
1223       SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
1224       meshDS->SetNodeOnEdge(NM, shapeID, prm);
1225       SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, nLast, NM);
1226       meshDS->SetMeshElementOnShape(edge, shapeID);
1227     }
1228     else {
1229       SMDS_MeshEdge* edge = meshDS->AddEdge(nPrev, nLast);
1230       meshDS->SetMeshElementOnShape(edge, shapeID);
1231     }
1232   }
1233   else
1234   {
1235     // Edge is a degenerated Edge : We put n = 5 points on the edge.
1236     const int NbPoints = 5;
1237     BRep_Tool::Range( E, f, l ); // PAL15185
1238     double du = (l - f) / (NbPoints - 1);
1239
1240     gp_Pnt P = BRep_Tool::Pnt(VFirst);
1241
1242     const SMDS_MeshNode * nPrev = nFirst;
1243     for (int i = 2; i < NbPoints; i++) {
1244       double param = f + (i - 1) * du;
1245       SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
1246       if(_quadraticMesh) {
1247         // create medium node
1248         double prm = param - du/2.;
1249         SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
1250         meshDS->SetNodeOnEdge(NM, shapeID, prm);
1251         SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node, NM);
1252         meshDS->SetMeshElementOnShape(edge, shapeID);
1253       }
1254       else {
1255         SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node);
1256         meshDS->SetMeshElementOnShape(edge, shapeID);
1257       }
1258       meshDS->SetNodeOnEdge(node, shapeID, param);
1259       nPrev = node;
1260     }
1261     if(_quadraticMesh) {
1262       // create medium node
1263       double prm = l - du/2.;
1264       SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
1265       meshDS->SetNodeOnEdge(NM, shapeID, prm);
1266       SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, nLast, NM);
1267       meshDS->SetMeshElementOnShape(edge, shapeID);
1268     }
1269     else {
1270       SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, nLast);
1271       meshDS->SetMeshElementOnShape(edge, shapeID);
1272     }
1273   }
1274   return true;
1275 }
1276
1277
1278 //=============================================================================
1279 /*!
1280  *  
1281  */
1282 //=============================================================================
1283
1284 bool StdMeshers_Regular_1D::Evaluate(SMESH_Mesh &         theMesh,
1285                                      const TopoDS_Shape & theShape,
1286                                      MapShapeNbElems&     theResMap)
1287 {
1288   if ( _hypType == NONE )
1289     return false;
1290
1291   if ( _hypType == ADAPTIVE )
1292   {
1293     _adaptiveHyp->GetAlgo()->InitComputeError();
1294     _adaptiveHyp->GetAlgo()->Evaluate( theMesh, theShape, theResMap );
1295     return error( _adaptiveHyp->GetAlgo()->GetComputeError() );
1296   }
1297
1298   const TopoDS_Edge & EE = TopoDS::Edge(theShape);
1299   TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
1300
1301   double f, l;
1302   Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
1303
1304   TopoDS_Vertex VFirst, VLast;
1305   TopExp::Vertices(E, VFirst, VLast);   // Vfirst corresponds to f and Vlast to l
1306
1307   ASSERT(!VFirst.IsNull());
1308   ASSERT(!VLast.IsNull());
1309
1310   std::vector<int> aVec(SMDSEntity_Last,0);
1311
1312   double length = EdgeLength( E );
1313   if ( !Curve.IsNull() && length > 0 )
1314   {
1315     list< double > params;
1316     BRepAdaptor_Curve C3d( E );
1317     if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, false, true )) {
1318       SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1319       theResMap.insert(std::make_pair(sm,aVec));
1320       SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
1321       smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
1322       return false;
1323     }
1324     redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
1325
1326     if(_quadraticMesh) {
1327       aVec[SMDSEntity_Node     ] = 2*params.size() + 1;
1328       aVec[SMDSEntity_Quad_Edge] = params.size() + 1;
1329     }
1330     else {
1331       aVec[SMDSEntity_Node] = params.size();
1332       aVec[SMDSEntity_Edge] = params.size() + 1;
1333     }
1334
1335   }
1336   else {
1337     // Edge is a degenerated Edge : We put n = 5 points on the edge.
1338     if ( _quadraticMesh ) {
1339       aVec[SMDSEntity_Node     ] = 11;
1340       aVec[SMDSEntity_Quad_Edge] = 6;
1341     }
1342     else {
1343       aVec[SMDSEntity_Node] = 5;
1344       aVec[SMDSEntity_Edge] = 6;
1345     }
1346   }
1347
1348   SMESH_subMesh * sm = theMesh.GetSubMesh( theShape );
1349   theResMap.insert( std::make_pair( sm, aVec ));
1350
1351   return true;
1352 }
1353
1354
1355 //=============================================================================
1356 /*!
1357  *  See comments in SMESH_Algo.cxx
1358  */
1359 //=============================================================================
1360
1361 const list <const SMESHDS_Hypothesis *> &
1362 StdMeshers_Regular_1D::GetUsedHypothesis(SMESH_Mesh &         aMesh,
1363                                          const TopoDS_Shape & aShape,
1364                                          const bool           ignoreAuxiliary)
1365 {
1366   _usedHypList.clear();
1367   _mainEdge.Nullify();
1368
1369   SMESH_HypoFilter auxiliaryFilter( SMESH_HypoFilter::IsAuxiliary() );
1370   const SMESH_HypoFilter* compatibleFilter = GetCompatibleHypoFilter(/*ignoreAux=*/true );
1371
1372   // get non-auxiliary assigned directly to aShape
1373   int nbHyp = aMesh.GetHypotheses( aShape, *compatibleFilter, _usedHypList, false );
1374
1375   if (nbHyp == 0 && aShape.ShapeType() == TopAbs_EDGE)
1376   {
1377     // Check, if propagated from some other edge
1378     bool isPropagOfDistribution = false;
1379     _mainEdge = StdMeshers_Propagation::GetPropagationSource( aMesh, aShape,
1380                                                               isPropagOfDistribution );
1381     if ( !_mainEdge.IsNull() )
1382     {
1383       if ( isPropagOfDistribution )
1384         _hypType = DISTRIB_PROPAGATION;
1385       // Propagation of 1D hypothesis from <aMainEdge> on this edge;
1386       // get non-auxiliary assigned to _mainEdge
1387       nbHyp = aMesh.GetHypotheses( _mainEdge, *compatibleFilter, _usedHypList, true );
1388     }
1389   }
1390
1391   if (nbHyp == 0) // nothing propagated nor assigned to aShape
1392   {
1393     SMESH_Algo::GetUsedHypothesis( aMesh, aShape, ignoreAuxiliary );
1394     nbHyp = _usedHypList.size();
1395   }
1396   else
1397   {
1398     // get auxiliary hyps from aShape
1399     aMesh.GetHypotheses( aShape, auxiliaryFilter, _usedHypList, true );
1400   }
1401   if ( nbHyp > 1 && ignoreAuxiliary )
1402     _usedHypList.clear(); //only one compatible non-auxiliary hypothesis allowed
1403
1404   return _usedHypList;
1405 }
1406
1407 //================================================================================
1408 /*!
1409  * \brief Pass CancelCompute() to a child algorithm
1410  */
1411 //================================================================================
1412
1413 void StdMeshers_Regular_1D::CancelCompute()
1414 {
1415   SMESH_Algo::CancelCompute();
1416   if ( _hypType == ADAPTIVE )
1417     _adaptiveHyp->GetAlgo()->CancelCompute();
1418 }