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