1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_Regular_1D.cxx
24 // Moved here from SMESH_Regular_1D.cxx
25 // Author : Paul RASCLE, EDF
28 #include "StdMeshers_Regular_1D.hxx"
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"
53 #include <Utils_SALOME_Exception.hxx>
54 #include <utilities.h>
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>
63 #include <TopExp_Explorer.hxx>
65 #include <TopoDS_Edge.hxx>
66 #include <TopoDS_Vertex.hxx>
72 using namespace StdMeshers;
74 //=============================================================================
78 //=============================================================================
80 StdMeshers_Regular_1D::StdMeshers_Regular_1D(int hypId,
82 :SMESH_1D_Algo( hypId, gen )
85 _shapeType = (1 << TopAbs_EDGE);
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");
99 _compatibleHypothesis.push_back("QuadraticMesh");
100 _compatibleHypothesis.push_back("Propagation");
101 _compatibleHypothesis.push_back("PropagOfDistribution");
104 //=============================================================================
108 //=============================================================================
110 StdMeshers_Regular_1D::~StdMeshers_Regular_1D()
114 //=============================================================================
118 //=============================================================================
120 bool StdMeshers_Regular_1D::CheckHypothesis( SMESH_Mesh& aMesh,
121 const TopoDS_Shape& aShape,
122 Hypothesis_Status& aStatus )
125 _quadraticMesh = false;
126 _onlyUnaryInput = true;
128 // check propagation in a redefined GetUsedHypothesis()
129 const list <const SMESHDS_Hypothesis * > hyps =
130 GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliaryHyps=*/false);
131 const SMESH_HypoFilter & propagFilter = StdMeshers_Propagation::GetFilter();
133 // find non-auxiliary hypothesis
134 const SMESHDS_Hypothesis *theHyp = 0;
135 set< string > propagTypes;
136 //std::cout << "For shape " << aShape.HashCode(1) << " of type "<< aShape.ShapeType() <<
137 // "CheckHypothesis" << std::endl;
138 // for(auto hyp:hyps){
139 // SMESH_Comment hypStr;
140 // hypStr << hyp << " " << hyp->GetName() << " ";
141 // ((SMESHDS_Hypothesis*)hyp)->SaveTo( hypStr.Stream() );
143 // std::cout << hypStr << std::endl;
145 list <const SMESHDS_Hypothesis * >::const_iterator h = hyps.begin();
146 for ( ; h != hyps.end(); ++h ) {
147 if ( static_cast<const SMESH_Hypothesis*>(*h)->IsAuxiliary() ) {
148 if ( strcmp( "QuadraticMesh", (*h)->GetName() ) == 0 )
149 _quadraticMesh = true;
150 if ( propagFilter.IsOk( static_cast< const SMESH_Hypothesis*>( *h ), aShape ))
151 propagTypes.insert( (*h)->GetName() );
155 theHyp = *h; // use only the first non-auxiliary hypothesis
161 aStatus = SMESH_Hypothesis::HYP_MISSING;
162 return false; // can't work without a hypothesis
165 string hypName = theHyp->GetName();
167 if ( !_mainEdge.IsNull() && _hypType == DISTRIB_PROPAGATION )
169 aStatus = SMESH_Hypothesis::HYP_OK;
171 else if ( hypName == "LocalLength" )
173 const StdMeshers_LocalLength * hyp =
174 dynamic_cast <const StdMeshers_LocalLength * >(theHyp);
176 _value[ BEG_LENGTH_IND ] = hyp->GetLength();
177 _value[ PRECISION_IND ] = hyp->GetPrecision();
178 ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
179 _hypType = LOCAL_LENGTH;
180 aStatus = SMESH_Hypothesis::HYP_OK;
183 else if ( hypName == "MaxLength" )
185 const StdMeshers_MaxLength * hyp =
186 dynamic_cast <const StdMeshers_MaxLength * >(theHyp);
188 _value[ BEG_LENGTH_IND ] = hyp->GetLength();
189 if ( hyp->GetUsePreestimatedLength() ) {
190 if ( int nbSeg = aMesh.GetGen()->GetBoundaryBoxSegmentation() )
191 _value[ BEG_LENGTH_IND ] = aMesh.GetShapeDiagonalSize() / nbSeg;
193 ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
194 _hypType = MAX_LENGTH;
195 aStatus = SMESH_Hypothesis::HYP_OK;
198 else if ( hypName == "NumberOfSegments" )
200 const StdMeshers_NumberOfSegments * hyp =
201 dynamic_cast <const StdMeshers_NumberOfSegments * >(theHyp);
203 _ivalue[ NB_SEGMENTS_IND ] = hyp->GetNumberOfSegments();
204 ASSERT( _ivalue[ NB_SEGMENTS_IND ] > 0 );
205 _ivalue[ DISTR_TYPE_IND ] = (int) hyp->GetDistrType();
206 switch (_ivalue[ DISTR_TYPE_IND ])
208 case StdMeshers_NumberOfSegments::DT_Scale:
209 _value[ SCALE_FACTOR_IND ] = hyp->GetScaleFactor();
210 _revEdgesIDs = hyp->GetReversedEdges();
212 case StdMeshers_NumberOfSegments::DT_TabFunc:
213 _vvalue[ TAB_FUNC_IND ] = hyp->GetTableFunction();
214 _revEdgesIDs = hyp->GetReversedEdges();
216 case StdMeshers_NumberOfSegments::DT_ExprFunc:
217 _svalue[ EXPR_FUNC_IND ] = hyp->GetExpressionFunction();
218 _revEdgesIDs = hyp->GetReversedEdges();
220 case StdMeshers_NumberOfSegments::DT_Regular:
226 if (_ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_TabFunc ||
227 _ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_ExprFunc)
228 _ivalue[ CONV_MODE_IND ] = hyp->ConversionMode();
229 _hypType = NB_SEGMENTS;
230 aStatus = SMESH_Hypothesis::HYP_OK;
233 else if ( hypName == "Arithmetic1D" )
235 const StdMeshers_Arithmetic1D * hyp =
236 dynamic_cast <const StdMeshers_Arithmetic1D * >(theHyp);
238 _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
239 _value[ END_LENGTH_IND ] = hyp->GetLength( false );
240 ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
241 _hypType = ARITHMETIC_1D;
243 _revEdgesIDs = hyp->GetReversedEdges();
245 aStatus = SMESH_Hypothesis::HYP_OK;
248 else if ( hypName == "GeometricProgression" )
250 const StdMeshers_Geometric1D * hyp =
251 dynamic_cast <const StdMeshers_Geometric1D * >(theHyp);
253 _value[ BEG_LENGTH_IND ] = hyp->GetStartLength();
254 _value[ END_LENGTH_IND ] = hyp->GetCommonRatio();
255 ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
256 _hypType = GEOMETRIC_1D;
258 _revEdgesIDs = hyp->GetReversedEdges();
260 aStatus = SMESH_Hypothesis::HYP_OK;
263 else if ( hypName == "FixedPoints1D" ) {
264 _fpHyp = dynamic_cast <const StdMeshers_FixedPoints1D*>(theHyp);
266 _hypType = FIXED_POINTS_1D;
268 _revEdgesIDs = _fpHyp->GetReversedEdges();
270 aStatus = SMESH_Hypothesis::HYP_OK;
273 else if ( hypName == "StartEndLength" )
275 const StdMeshers_StartEndLength * hyp =
276 dynamic_cast <const StdMeshers_StartEndLength * >(theHyp);
278 _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
279 _value[ END_LENGTH_IND ] = hyp->GetLength( false );
280 ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
281 _hypType = BEG_END_LENGTH;
283 _revEdgesIDs = hyp->GetReversedEdges();
285 aStatus = SMESH_Hypothesis::HYP_OK;
288 else if ( hypName == "Deflection1D" )
290 const StdMeshers_Deflection1D * hyp =
291 dynamic_cast <const StdMeshers_Deflection1D * >(theHyp);
293 _value[ DEFLECTION_IND ] = hyp->GetDeflection();
294 ASSERT( _value[ DEFLECTION_IND ] > 0 );
295 _hypType = DEFLECTION;
296 aStatus = SMESH_Hypothesis::HYP_OK;
299 else if ( hypName == "AutomaticLength" )
301 StdMeshers_AutomaticLength * hyp = const_cast<StdMeshers_AutomaticLength *>
302 (dynamic_cast <const StdMeshers_AutomaticLength * >(theHyp));
304 _value[ BEG_LENGTH_IND ] = _value[ END_LENGTH_IND ] = hyp->GetLength( &aMesh, aShape );
305 ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
306 _hypType = MAX_LENGTH;
307 aStatus = SMESH_Hypothesis::HYP_OK;
309 else if ( hypName == "Adaptive1D" )
311 _adaptiveHyp = dynamic_cast < const StdMeshers_Adaptive1D* >(theHyp);
312 ASSERT(_adaptiveHyp);
314 _onlyUnaryInput = false;
315 aStatus = SMESH_Hypothesis::HYP_OK;
319 aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
322 if ( propagTypes.size() > 1 && aStatus == HYP_OK )
324 // detect concurrent Propagation hyps
325 _usedHypList.clear();
326 list< TopoDS_Shape > assignedTo;
327 if ( aMesh.GetHypotheses( aShape, propagFilter, _usedHypList, true, &assignedTo ) > 1 )
329 // find most simple shape and a hyp on it
330 int simpleShape = TopAbs_COMPOUND;
331 const SMESHDS_Hypothesis* localHyp = 0;
332 list< TopoDS_Shape >::iterator shape = assignedTo.begin();
333 list< const SMESHDS_Hypothesis *>::iterator hyp = _usedHypList.begin();
334 for ( ; shape != assignedTo.end(); ++shape )
335 if ( shape->ShapeType() > simpleShape )
337 simpleShape = shape->ShapeType();
340 // check if there a different hyp on simpleShape
341 shape = assignedTo.begin();
342 hyp = _usedHypList.begin();
343 for ( ; hyp != _usedHypList.end(); ++hyp, ++shape )
344 if ( shape->ShapeType() == simpleShape &&
345 !localHyp->IsSameName( **hyp ))
347 aStatus = HYP_INCOMPAT_HYPS;
348 return error( SMESH_Comment("Hypotheses of both \"")
349 << StdMeshers_Propagation::GetName() << "\" and \""
350 << StdMeshers_PropagOfDistribution::GetName()
351 << "\" types can't be applied to the same edge");
356 return ( aStatus == SMESH_Hypothesis::HYP_OK );
359 static bool computeParamByFunc(Adaptor3d_Curve& C3d,
360 double first, double last, double length,
361 bool theReverse, smIdType nbSeg, Function& func,
362 list<double>& theParams)
365 //OSD::SetSignal( true );
370 smIdType nbPnt = 1 + nbSeg;
371 vector<double> x( nbPnt, 0. );
374 const double eps = Min( 1E-4, 0.01 / double( nbSeg ));
376 if ( !buildDistribution( func, 0.0, 1.0, nbSeg, x, eps ))
379 // apply parameters in range [0,1] to the space of the curve
380 double prevU = first;
388 for ( smIdType i = 1; i < nbSeg; i++ )
390 double curvLength = length * (x[i] - x[i-1]) * sign;
391 double tol = Min( Precision::Confusion(), curvLength / 100. );
392 GCPnts_AbscissaPoint Discret( tol, C3d, curvLength, prevU );
393 if ( !Discret.IsDone() )
395 double U = Discret.Parameter();
396 if ( U > first && U < last )
397 theParams.push_back( U );
409 //================================================================================
411 * \brief adjust internal node parameters so that the last segment length == an
412 * \param a1 - the first segment length
413 * \param an - the last segment length
414 * \param U1 - the first edge parameter
415 * \param Un - the last edge parameter
416 * \param length - the edge length
417 * \param C3d - the edge curve
418 * \param theParams - internal node parameters to adjust
419 * \param adjustNeighbors2an - to adjust length of segments next to the last one
420 * and not to remove parameters
422 //================================================================================
424 static void compensateError(double a1, double an,
425 double U1, double Un,
427 Adaptor3d_Curve& C3d,
428 list<double> & theParams,
429 bool adjustNeighbors2an = false)
431 smIdType i, nPar = theParams.size();
432 if ( a1 + an <= length && nPar > 1 )
434 bool reverse = ( U1 > Un );
435 double tol = Min( Precision::Confusion(), 0.01 * an );
436 GCPnts_AbscissaPoint Discret( tol, C3d, reverse ? an : -an, Un );
437 if ( !Discret.IsDone() )
439 double Utgt = Discret.Parameter(); // target value of the last parameter
440 list<double>::reverse_iterator itU = theParams.rbegin();
441 double Ul = *itU++; // real value of the last parameter
442 double dUn = Utgt - Ul; // parametric error of <an>
443 double dU = Abs( Ul - *itU ); // parametric length of the last but one segment
444 if ( Abs(dUn) <= 1e-3 * dU )
446 if ( adjustNeighbors2an || Abs(dUn) < 0.5 * dU ) { // last segment is a bit shorter than it should
447 // move the last parameter to the edge beginning
449 else { // last segment is much shorter than it should -> remove the last param and
450 theParams.pop_back(); nPar--; // move the rest points toward the edge end
451 dUn = Utgt - theParams.back();
454 if ( !adjustNeighbors2an )
456 double q = dUn / ( Utgt - Un ); // (signed) factor of segment length change
457 for ( itU = theParams.rbegin(), i = 1; i < nPar; i++ ) {
461 dUn = q * (*itU - prevU) * (prevU-U1)/(Un-U1);
464 else if ( nPar == 1 )
466 theParams.back() += dUn;
470 double q = dUn / double( nPar - 1 );
471 theParams.back() += dUn;
472 double sign = reverse ? -1 : 1;
473 double prevU = theParams.back();
474 itU = theParams.rbegin();
475 for ( ++itU, i = 2; i < nPar; ++itU, i++ ) {
476 double newU = *itU + dUn;
477 if ( newU*sign < prevU*sign ) {
481 else { // set U between prevU and next valid param
482 list<double>::reverse_iterator itU2 = itU;
485 while ( (*itU2)*sign > prevU*sign ) {
488 dU = ( *itU2 - prevU ) / nb;
489 while ( itU != itU2 ) {
499 //================================================================================
501 * \brief Class used to clean mesh on edges when 0D hyp modified.
502 * Common approach doesn't work when 0D algo is missing because the 0D hyp is
503 * considered as not participating in computation whereas it is used by 1D algo.
505 //================================================================================
507 // struct VertexEventListener : public SMESH_subMeshEventListener
509 // VertexEventListener():SMESH_subMeshEventListener(0) // won't be deleted by submesh
512 // * \brief Clean mesh on edges
513 // * \param event - algo_event or compute_event itself (of SMESH_subMesh)
514 // * \param eventType - ALGO_EVENT or COMPUTE_EVENT (of SMESH_subMesh)
515 // * \param subMesh - the submesh where the event occurs
517 // void ProcessEvent(const int event, const int eventType, SMESH_subMesh* subMesh,
518 // EventListenerData*, const SMESH_Hypothesis*)
520 // if ( eventType == SMESH_subMesh::ALGO_EVENT) // all algo events
522 // subMesh->ComputeStateEngine( SMESH_subMesh::MODIF_ALGO_STATE );
525 // }; // struct VertexEventListener
527 //=============================================================================
529 * \brief Sets event listener to vertex submeshes
530 * \param subMesh - submesh where algo is set
532 * This method is called when a submesh gets HYP_OK algo_state.
533 * After being set, event listener is notified on each event of a submesh.
535 //=============================================================================
537 void StdMeshers_Regular_1D::SetEventListener(SMESH_subMesh* subMesh)
539 StdMeshers_Propagation::SetPropagationMgr( subMesh );
542 //=============================================================================
545 * \param subMesh - restored submesh
547 * This method is called only if a submesh has HYP_OK algo_state.
549 //=============================================================================
551 void StdMeshers_Regular_1D::SubmeshRestored(SMESH_subMesh* /*subMesh*/)
555 //=============================================================================
557 * \brief Return StdMeshers_SegmentLengthAroundVertex assigned to vertex
559 //=============================================================================
561 const StdMeshers_SegmentLengthAroundVertex*
562 StdMeshers_Regular_1D::getVertexHyp(SMESH_Mesh & theMesh,
563 const TopoDS_Vertex & theV)
565 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName("SegmentAroundVertex_0D"));
566 if ( const SMESH_Hypothesis * h = theMesh.GetHypothesis( theV, filter, true ))
568 SMESH_Algo* algo = const_cast< SMESH_Algo* >( static_cast< const SMESH_Algo* > ( h ));
569 const list <const SMESHDS_Hypothesis *> & hypList = algo->GetUsedHypothesis( theMesh, theV, 0 );
570 if ( !hypList.empty() && string("SegmentLengthAroundVertex") == hypList.front()->GetName() )
571 return static_cast<const StdMeshers_SegmentLengthAroundVertex*>( hypList.front() );
576 //================================================================================
578 * \brief Divide a curve into equal segments
580 //================================================================================
582 bool StdMeshers_Regular_1D::divideIntoEqualSegments( SMESH_Mesh & theMesh,
583 Adaptor3d_Curve & theC3d,
584 smIdType theNbPoints,
589 std::list<double> & theParameters )
592 if ( theNbPoints < IntegerLast() )
594 int nbPnt = FromSmIdType<int>( theNbPoints );
595 GCPnts_UniformAbscissa discret(theC3d, nbPnt, theFirstU, theLastU, theTol );
596 if ( !discret.IsDone() )
597 return error( "GCPnts_UniformAbscissa failed");
598 if ( discret.NbPoints() < nbPnt )
599 discret.Initialize(theC3d, nbPnt + 1, theFirstU, theLastU, theTol );
601 int nbPoints = Min( discret.NbPoints(), nbPnt );
602 for ( int i = 2; i < nbPoints; i++ ) // skip 1st and last points
604 double param = discret.Parameter(i);
605 theParameters.push_back( param );
609 else // huge nb segments
611 // use FIXED_POINTS_1D method
612 StdMeshers_FixedPoints1D fixedPointsHyp( GetGen()->GetANewId(), GetGen() );
613 _fpHyp = &fixedPointsHyp;
614 std::vector<double> params = { 0., 1. };
615 std::vector<smIdType> nbSegs = { theNbPoints - 1 };
616 fixedPointsHyp.SetPoints( params );
617 fixedPointsHyp.SetNbSegments( nbSegs );
619 HypothesisType curType = _hypType;
620 _hypType = FIXED_POINTS_1D;
622 ok = computeInternalParameters( theMesh, theC3d, theLength, theFirstU, theLastU,
623 theParameters, /*reverse=*/false );
630 //================================================================================
632 * \brief Tune parameters to fit "SegmentLengthAroundVertex" hypothesis
633 * \param theC3d - wire curve
634 * \param theLength - curve length
635 * \param theParameters - internal nodes parameters to modify
636 * \param theVf - 1st vertex
637 * \param theVl - 2nd vertex
639 //================================================================================
641 void StdMeshers_Regular_1D::redistributeNearVertices (SMESH_Mesh & theMesh,
642 Adaptor3d_Curve & theC3d,
644 std::list< double > & theParameters,
645 const TopoDS_Vertex & theVf,
646 const TopoDS_Vertex & theVl)
648 double f = theC3d.FirstParameter(), l = theC3d.LastParameter();
649 size_t nPar = theParameters.size();
650 for ( int isEnd1 = 0; isEnd1 < 2; ++isEnd1 )
652 const TopoDS_Vertex & V = isEnd1 ? theVf : theVl;
653 const StdMeshers_SegmentLengthAroundVertex* hyp = getVertexHyp (theMesh, V );
655 double vertexLength = hyp->GetLength();
656 if ( vertexLength > theLength / 2.0 )
658 if ( isEnd1 ) { // to have a segment of interest at end of theParameters
659 theParameters.reverse();
662 if ( _hypType == NB_SEGMENTS )
664 compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
666 else if ( nPar <= 3 )
669 vertexLength = -vertexLength;
670 double tol = Min( Precision::Confusion(), 0.01 * vertexLength );
671 GCPnts_AbscissaPoint Discret( tol, theC3d, vertexLength, l );
672 if ( Discret.IsDone() ) {
674 theParameters.push_back( Discret.Parameter());
676 double L = GCPnts_AbscissaPoint::Length( theC3d, theParameters.back(), l);
677 if ( vertexLength < L / 2.0 )
678 theParameters.push_back( Discret.Parameter());
680 compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
686 // recompute params between the last segment and a middle one.
687 // find size of a middle segment
688 smIdType nHalf = ( nPar-1 ) / 2;
689 list< double >::reverse_iterator itU = theParameters.rbegin();
690 std::advance( itU, nHalf );
692 double Lm = GCPnts_AbscissaPoint::Length( theC3d, Um, *itU);
693 double L = GCPnts_AbscissaPoint::Length( theC3d, *itU, l);
694 static StdMeshers_Regular_1D* auxAlgo = 0;
696 auxAlgo = new StdMeshers_Regular_1D( _gen->GetANewId(), _gen );
697 auxAlgo->_hypType = BEG_END_LENGTH;
699 auxAlgo->_value[ BEG_LENGTH_IND ] = Lm;
700 auxAlgo->_value[ END_LENGTH_IND ] = vertexLength;
701 double from = *itU, to = l;
703 std::swap( from, to );
704 std::swap( auxAlgo->_value[ BEG_LENGTH_IND ], auxAlgo->_value[ END_LENGTH_IND ]);
707 if ( auxAlgo->computeInternalParameters( theMesh, theC3d, L, from, to, params, false ))
709 if ( isEnd1 ) params.reverse();
710 while ( 1 + nHalf-- )
711 theParameters.pop_back();
712 theParameters.splice( theParameters.end(), params );
716 compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
720 theParameters.reverse();
725 //=============================================================================
729 //=============================================================================
730 bool StdMeshers_Regular_1D::computeInternalParameters(SMESH_Mesh & theMesh,
731 Adaptor3d_Curve& theC3d,
735 list<double> & theParams,
736 const bool theReverse,
737 bool theConsiderPropagation)
741 double f = theFirstU, l = theLastU;
743 // Propagation Of Distribution
745 if ( !_mainEdge.IsNull() && _hypType == DISTRIB_PROPAGATION )
747 TopoDS_Edge mainEdge = TopoDS::Edge( _mainEdge ); // should not be a reference!
748 _gen->Compute( theMesh, mainEdge, SMESH_Gen::SHAPE_ONLY_UPWARD );
750 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( mainEdge );
752 return error("No mesh on the source edge of Propagation Of Distribution");
753 if ( smDS->NbNodes() < 1 )
754 return true; // 1 segment
756 map< double, const SMDS_MeshNode* > mainEdgeParamsOfNodes;
757 if ( ! SMESH_Algo::GetSortedNodesOnEdge( theMesh.GetMeshDS(), mainEdge, _quadraticMesh,
758 mainEdgeParamsOfNodes, SMDSAbs_Edge ))
759 return error("Bad node parameters on the source edge of Propagation Of Distribution");
760 vector< double > segLen( mainEdgeParamsOfNodes.size() - 1 );
762 BRepAdaptor_Curve mainEdgeCurve( mainEdge );
763 map< double, const SMDS_MeshNode* >::iterator
764 u_n2 = mainEdgeParamsOfNodes.begin(), u_n1 = u_n2++;
765 for ( size_t i = 1; i < mainEdgeParamsOfNodes.size(); ++i, ++u_n1, ++u_n2 )
767 segLen[ i-1 ] = GCPnts_AbscissaPoint::Length( mainEdgeCurve,
770 totalLen += segLen[ i-1 ];
772 for ( size_t i = 0; i < segLen.size(); ++i )
773 segLen[ i ] *= theLength / totalLen;
775 size_t iSeg = theReverse ? segLen.size()-1 : 0;
776 size_t dSeg = theReverse ? -1 : +1;
777 double param = theFirstU;
779 for ( size_t i = 1; i < segLen.size(); ++i, iSeg += dSeg )
781 double tol = Min( Precision::Confusion(), 0.01 * segLen[ iSeg ]);
782 GCPnts_AbscissaPoint Discret( tol, theC3d, segLen[ iSeg ], param );
783 if ( !Discret.IsDone() ) break;
784 param = Discret.Parameter();
785 theParams.push_back( param );
788 if ( nbParams != segLen.size()-1 )
789 return error( SMESH_Comment("Can't divide into ") << segLen.size() << " segments");
791 compensateError( segLen[ theReverse ? segLen.size()-1 : 0 ],
792 segLen[ theReverse ? 0 : segLen.size()-1 ],
793 f, l, theLength, theC3d, theParams, true );
806 if ( _hypType == MAX_LENGTH )
808 double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
810 nbseg = 1; // degenerated edge
811 eltSize = theLength / nbseg * ( 1. - 1e-9 );
812 nbSegments = ToSmIdType( nbseg );
814 else if ( _hypType == LOCAL_LENGTH )
816 // Local Length hypothesis
817 double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
820 bool isFound = false;
821 if (theConsiderPropagation && !_mainEdge.IsNull()) // propagated from some other edge
823 // Advanced processing to assure equal number of segments in case of Propagation
824 SMESH_subMesh* sm = theMesh.GetSubMeshContaining(_mainEdge);
826 bool computed = sm->IsMeshComputed();
828 if (sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE) {
829 _gen->Compute( theMesh, _mainEdge, /*anUpward=*/true);
830 computed = sm->IsMeshComputed();
834 SMESHDS_SubMesh* smds = sm->GetSubMeshDS();
835 smIdType nb_segments = smds->NbElements();
836 if (nbseg - 1 <= nb_segments && nb_segments <= nbseg + 1) {
838 nbseg = FromSmIdType<double>( nb_segments );
843 if (!isFound) // not found by meshed edge in the propagation chain, use precision
845 double aPrecision = _value[ PRECISION_IND ];
846 double nbseg_prec = ceil((theLength / _value[ BEG_LENGTH_IND ]) - aPrecision);
847 if (nbseg_prec == (nbseg - 1)) nbseg--;
851 nbseg = 1; // degenerated edge
852 eltSize = theLength / nbseg;
853 nbSegments = ToSmIdType( nbseg );
857 // Number Of Segments hypothesis
858 nbSegments = _ivalue[ NB_SEGMENTS_IND ];
859 if ( nbSegments < 1 ) {
862 if ( nbSegments == 1 ) {
866 switch (_ivalue[ DISTR_TYPE_IND ])
868 case StdMeshers_NumberOfSegments::DT_Scale:
870 double scale = _value[ SCALE_FACTOR_IND ];
872 if (fabs(scale - 1.0) < Precision::Confusion()) {
873 // special case to avoid division by zero
874 for ( smIdType i = 1; i < nbSegments; i++) {
875 double param = f + (l - f) * double( i ) / double( nbSegments );
876 theParams.push_back( param );
879 else { // general case of scale distribution
883 double alpha = pow(scale, 1.0 / double( nbSegments - 1 ));
884 double factor = (l - f) / (1.0 - pow(alpha, nbSegments));
886 for ( smIdType i = 1; i < nbSegments; i++) {
887 double param = f + factor * (1.0 - pow(alpha, i));
888 theParams.push_back( param );
891 const double lenFactor = theLength/(l-f);
892 const double minSegLen = Min( theParams.front() - f, l - theParams.back() );
893 const double tol = Min( Precision::Confusion(), 0.01 * minSegLen );
894 list<double>::iterator u = theParams.begin(), uEnd = theParams.end();
895 for ( ; u != uEnd; ++u )
897 GCPnts_AbscissaPoint Discret( tol, theC3d, ((*u)-f) * lenFactor, f );
898 if ( Discret.IsDone() )
899 *u = Discret.Parameter();
904 case StdMeshers_NumberOfSegments::DT_TabFunc:
906 FunctionTable func(_vvalue[ TAB_FUNC_IND ], FromSmIdType<int>( _ivalue[ CONV_MODE_IND ]));
907 return computeParamByFunc(theC3d, f, l, theLength, theReverse,
908 _ivalue[ NB_SEGMENTS_IND ], func,
912 case StdMeshers_NumberOfSegments::DT_ExprFunc:
914 FunctionExpr func(_svalue[ EXPR_FUNC_IND ].c_str(),
915 FromSmIdType<int>( _ivalue[ CONV_MODE_IND ]));
916 return computeParamByFunc(theC3d, f, l, theLength, theReverse,
917 _ivalue[ NB_SEGMENTS_IND ], func,
921 case StdMeshers_NumberOfSegments::DT_Regular:
922 eltSize = theLength / double( nbSegments );
929 double tol = Min( Precision::Confusion(), 0.01 * eltSize );
930 divideIntoEqualSegments( theMesh, theC3d, nbSegments + 1, tol,
931 theLength, theFirstU, theLastU, theParams );
933 compensateError( eltSize, eltSize, f, l, theLength, theC3d, theParams, true ); // for PAL9899
938 case BEG_END_LENGTH: {
940 // geometric progression: SUM(n) = ( a1 - an * q ) / ( 1 - q ) = theLength
942 double a1 = _value[ BEG_LENGTH_IND ];
943 double an = _value[ END_LENGTH_IND ];
944 double q = ( theLength - a1 ) / ( theLength - an );
945 if ( q < theLength/1e6 || 1.01*theLength < a1 + an)
946 return error ( SMESH_Comment("Invalid segment lengths (")<<a1<<" and "<<an<<") "<<
947 "for an edge of length "<<theLength);
949 double U1 = theReverse ? l : f;
950 double Un = theReverse ? f : l;
952 double eltSize = theReverse ? -a1 : a1;
953 double tol = Min( Precision::Confusion(), 0.01 * Min( a1, an ));
955 // computes a point on a curve <theC3d> at the distance <eltSize>
956 // from the point of parameter <param>.
957 GCPnts_AbscissaPoint Discret( tol, theC3d, eltSize, param );
958 if ( !Discret.IsDone() ) break;
959 param = Discret.Parameter();
960 if ( f < param && param < l )
961 theParams.push_back( param );
966 compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
967 if (theReverse) theParams.reverse(); // NPAL18025
973 // arithmetic progression: SUM(n) = ( an - a1 + q ) * ( a1 + an ) / ( 2 * q ) = theLength
975 double a1 = _value[ BEG_LENGTH_IND ];
976 double an = _value[ END_LENGTH_IND ];
977 if ( 1.01*theLength < a1 + an )
978 return error ( SMESH_Comment("Invalid segment lengths (")<<a1<<" and "<<an<<") "<<
979 "for an edge of length "<<theLength);
981 double q = ( an - a1 ) / ( 2 *theLength/( a1 + an ) - 1 );
982 int n = int(fabs(q) > numeric_limits<double>::min() ? ( 1+( an-a1 )/q ) : ( 1+theLength/a1 ));
984 double U1 = theReverse ? l : f;
985 double Un = theReverse ? f : l;
988 double tol = Min( Precision::Confusion(), 0.01 * Min( a1, an ));
993 while ( n-- > 0 && eltSize * ( Un - U1 ) > 0 ) {
994 // computes a point on a curve <theC3d> at the distance <eltSize>
995 // from the point of parameter <param>.
996 GCPnts_AbscissaPoint Discret( tol, theC3d, eltSize, param );
997 if ( !Discret.IsDone() ) break;
998 param = Discret.Parameter();
999 if ( param > f && param < l )
1000 theParams.push_back( param );
1005 compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
1006 if ( theReverse ) theParams.reverse(); // NPAL18025
1013 double a1 = _value[ BEG_LENGTH_IND ], an = 0;
1014 double q = _value[ END_LENGTH_IND ];
1016 double U1 = theReverse ? l : f;
1017 double Un = theReverse ? f : l;
1019 double eltSize = a1;
1025 // computes a point on a curve <theC3d> at the distance <eltSize>
1026 // from the point of parameter <param>.
1027 double tol = Min( Precision::Confusion(), 0.01 * eltSize );
1028 GCPnts_AbscissaPoint Discret( tol, theC3d, eltSize, param );
1029 if ( !Discret.IsDone() ) break;
1030 param = Discret.Parameter();
1031 if ( f < param && param < l )
1032 theParams.push_back( param );
1038 if ( q < 1. && eltSize < 1e-100 )
1039 return error("Too small common ratio causes too many segments");
1043 if ( Abs( param - Un ) < 0.2 * Abs( param - theParams.back() ))
1045 compensateError( a1, Abs(eltSize), U1, Un, theLength, theC3d, theParams );
1047 else if ( Abs( Un - theParams.back() ) <
1048 0.2 * Abs( theParams.back() - *(++theParams.rbegin())))
1050 theParams.pop_back();
1051 compensateError( a1, Abs(an), U1, Un, theLength, theC3d, theParams );
1054 if (theReverse) theParams.reverse(); // NPAL18025
1059 case FIXED_POINTS_1D:
1061 const std::vector<double>& aPnts = _fpHyp->GetPoints();
1062 std::vector<smIdType> nbsegs = _fpHyp->GetNbSegments();
1064 // sort normalized params, taking into account theReverse
1065 TColStd_SequenceOfReal Params;
1067 for ( size_t i = 0; i < aPnts.size(); i++ )
1069 if( aPnts[i] < tol || aPnts[i] > 1 - tol )
1071 double u = theReverse ? ( 1 - aPnts[i] ) : aPnts[i];
1073 bool IsExist = false;
1074 for ( ; j <= Params.Length() && !IsExist; j++ )
1076 IsExist = ( Abs( u - Params.Value(j) ) < tol );
1077 if ( u < Params.Value(j) ) break;
1079 if ( !IsExist ) Params.InsertBefore( j, u );
1081 Params.InsertBefore( 1, 0.0 );
1082 Params.Append( 1.0 );
1086 if ((int) nbsegs.size() > Params.Length() - 1 )
1087 nbsegs.resize( Params.Length() - 1 );
1088 std::reverse( nbsegs.begin(), nbsegs.end() );
1090 if ( nbsegs.empty() )
1092 nbsegs.push_back( 1 );
1094 if ((int) nbsegs.size() < Params.Length() - 1 )
1095 nbsegs.resize( Params.Length() - 1, nbsegs[0] );
1097 // care of huge nbsegs - additionally divide diapasons
1098 for ( int i = 2; i <= Params.Length(); i++ )
1100 smIdType nbTot = nbsegs[ i-2 ];
1101 if ( nbTot <= IntegerLast() )
1103 smIdType nbDiapason = nbTot / IntegerLast() + 1;
1104 smIdType nbSegPerDiap = nbTot / nbDiapason;
1105 double par0 = Params( i - 1 ), par1 = Params( i );
1106 for ( smIdType iDiap = 0; iDiap < nbDiapason - 1; ++iDiap )
1108 double r = double( nbSegPerDiap * ( iDiap + 1 )) / double( nbTot );
1109 double parI = par0 + ( par1 - par0 ) * r;
1110 Params.InsertBefore( i, parI );
1111 auto it = nbsegs.begin();
1112 smIdType incr_it = i - 2 + iDiap;
1113 nbsegs.insert( it + incr_it, nbSegPerDiap );
1115 nbsegs[ i-2 + nbDiapason - 1 ] = nbSegPerDiap + nbTot % nbDiapason;
1118 // transform normalized Params into real ones
1119 std::vector< double > uVec( Params.Length() );
1120 uVec[ 0 ] = theFirstU;
1122 for ( int i = 2; i < Params.Length(); i++ )
1124 abscissa = Params( i ) * theLength;
1125 tol = Min( Precision::Confusion(), 0.01 * abscissa );
1126 GCPnts_AbscissaPoint APnt( tol, theC3d, abscissa, theFirstU );
1127 if ( !APnt.IsDone() )
1128 return error( "GCPnts_AbscissaPoint failed");
1129 uVec[ i-1 ] = APnt.Parameter();
1131 uVec.back() = theLastU;
1134 double eltSize, segmentSize, par1, par2;
1135 for ( int i = 0; i < (int)uVec.size()-1; i++ )
1139 smIdType nbseg = ( i < (int) nbsegs.size() ) ? nbsegs[i] : nbsegs[0];
1142 segmentSize = ( Params( i+2 ) - Params( i+1 )) * theLength;
1143 eltSize = segmentSize / double( nbseg );
1144 tol = Min( Precision::Confusion(), 0.01 * eltSize );
1145 if ( !divideIntoEqualSegments( theMesh, theC3d, nbseg + 1, tol,
1146 segmentSize, par1, par2, theParams ))
1149 theParams.push_back( par2 );
1151 theParams.pop_back();
1158 GCPnts_UniformDeflection Discret( theC3d, _value[ DEFLECTION_IND ], f, l, true );
1159 if ( !Discret.IsDone() )
1162 int NbPoints = Discret.NbPoints();
1163 for ( int i = 2; i < NbPoints; i++ )
1165 double param = Discret.Parameter(i);
1166 theParams.push_back( param );
1177 //=============================================================================
1181 //=============================================================================
1183 bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & theShape)
1185 SMESH_Hypothesis::Hypothesis_Status hyp_status;
1187 bool ret = this->CheckHypothesis(theMesh, theShape, hyp_status);
1188 int hypType = _hypType;
1191 if ( hypType == NONE )
1194 if ( hypType == ADAPTIVE )
1196 _adaptiveHyp->GetAlgo()->InitComputeError();
1197 _adaptiveHyp->GetAlgo()->Compute( theMesh, theShape );
1198 return error( _adaptiveHyp->GetAlgo()->GetComputeError() );
1201 SMESHDS_Mesh * meshDS = theMesh.GetMeshDS();
1205 const TopoDS_Edge & EE = TopoDS::Edge(theShape);
1206 TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
1207 int shapeID = meshDS->ShapeToIndex( E );
1210 Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
1212 TopoDS_Vertex VFirst, VLast;
1213 TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l
1215 ASSERT(!VFirst.IsNull());
1216 ASSERT(!VLast.IsNull());
1217 const SMDS_MeshNode * nFirst = SMESH_Algo::VertexNode( VFirst, meshDS );
1218 const SMDS_MeshNode * nLast = SMESH_Algo::VertexNode( VLast, meshDS );
1219 if ( !nFirst || !nLast ){
1221 //std::cout << "exit no node" << std::endl;
1222 return error( COMPERR_BAD_INPUT_MESH, "No node on vertex");
1224 // remove elements created by e.g. pattern mapping (PAL21999)
1225 // CLEAN event is incorrectly ptopagated seemingly due to Propagation hyp
1226 // so TEMPORARY solution is to clean the submesh manually
1227 if (SMESHDS_SubMesh * subMeshDS = meshDS->MeshElements(theShape))
1229 SMDS_ElemIteratorPtr ite = subMeshDS->GetElements();
1231 meshDS->RemoveFreeElement(ite->next(), subMeshDS);
1232 SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes();
1233 while (itn->more()) {
1234 const SMDS_MeshNode * node = itn->next();
1235 if ( node->NbInverseElements() == 0 )
1236 meshDS->RemoveFreeNode(node, subMeshDS);
1238 meshDS->RemoveNode(node);
1242 double length = EdgeLength( E );
1243 if ( !Curve.IsNull() && length > 0 )
1245 list< double > params;
1246 bool reversed = false;
1247 if ( theMesh.GetShapeToMesh().ShapeType() >= TopAbs_WIRE && _revEdgesIDs.empty() ) {
1248 // if the shape to mesh is WIRE or EDGE
1249 reversed = ( EE.Orientation() == TopAbs_REVERSED );
1251 if ( !_mainEdge.IsNull() ) {
1252 // take into account reversing the edge the hypothesis is propagated from
1253 // (_mainEdge.Orientation() marks mutual orientation of EDGEs in propagation chain)
1254 reversed = ( _mainEdge.Orientation() == TopAbs_REVERSED );
1255 if ( hypType != DISTRIB_PROPAGATION ) {
1256 int mainID = meshDS->ShapeToIndex(_mainEdge);
1257 if ( std::find( _revEdgesIDs.begin(), _revEdgesIDs.end(), mainID) != _revEdgesIDs.end())
1258 reversed = !reversed;
1261 // take into account this edge reversing
1262 if ( std::find( _revEdgesIDs.begin(), _revEdgesIDs.end(), shapeID) != _revEdgesIDs.end())
1263 reversed = !reversed;
1265 BRepAdaptor_Curve C3d( E );
1266 if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, reversed, true )) {
1268 //std::cout << "exit Compute internal failed" << std::endl;
1272 redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
1274 // edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
1275 // only internal nodes receive an edge position with param on curve
1277 const SMDS_MeshNode * nPrev = nFirst;
1281 for (list<double>::iterator itU = params.begin(); itU != params.end(); itU++) {
1282 double param = *itU;
1283 gp_Pnt P = Curve->Value(param);
1285 //Add the Node in the DataStructure
1286 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
1287 meshDS->SetNodeOnEdge(node, shapeID, param);
1289 if(_quadraticMesh) {
1290 // create medium node
1291 double prm = ( parPrev + param )/2;
1292 gp_Pnt PM = Curve->Value(prm);
1293 SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
1294 meshDS->SetNodeOnEdge(NM, shapeID, prm);
1295 SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node, NM);
1296 meshDS->SetMeshElementOnShape(edge, shapeID);
1299 SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node);
1300 meshDS->SetMeshElementOnShape(edge, shapeID);
1306 if(_quadraticMesh) {
1307 double prm = ( parPrev + parLast )/2;
1308 gp_Pnt PM = Curve->Value(prm);
1309 SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
1310 meshDS->SetNodeOnEdge(NM, shapeID, prm);
1311 SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, nLast, NM);
1312 meshDS->SetMeshElementOnShape(edge, shapeID);
1315 SMDS_MeshEdge* edge = meshDS->AddEdge(nPrev, nLast);
1316 meshDS->SetMeshElementOnShape(edge, shapeID);
1321 // Edge is a degenerated Edge : We put n = 5 points on the edge.
1322 const int NbPoints = 5;
1323 BRep_Tool::Range( E, f, l ); // PAL15185
1324 double du = (l - f) / (NbPoints - 1);
1326 gp_Pnt P = BRep_Tool::Pnt(VFirst);
1328 const SMDS_MeshNode * nPrev = nFirst;
1329 for (int i = 2; i < NbPoints; i++) {
1330 double param = f + (i - 1) * du;
1331 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
1332 if(_quadraticMesh) {
1333 // create medium node
1334 double prm = param - du/2.;
1335 SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
1336 meshDS->SetNodeOnEdge(NM, shapeID, prm);
1337 SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node, NM);
1338 meshDS->SetMeshElementOnShape(edge, shapeID);
1341 SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node);
1342 meshDS->SetMeshElementOnShape(edge, shapeID);
1344 meshDS->SetNodeOnEdge(node, shapeID, param);
1347 if(_quadraticMesh) {
1348 // create medium node
1349 double prm = l - du/2.;
1350 SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
1351 meshDS->SetNodeOnEdge(NM, shapeID, prm);
1352 SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, nLast, NM);
1353 meshDS->SetMeshElementOnShape(edge, shapeID);
1356 SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, nLast);
1357 meshDS->SetMeshElementOnShape(edge, shapeID);
1361 //std::cout << "exit normal" << std::endl;
1367 //=============================================================================
1371 //=============================================================================
1373 bool StdMeshers_Regular_1D::Evaluate(SMESH_Mesh & theMesh,
1374 const TopoDS_Shape & theShape,
1375 MapShapeNbElems& theResMap)
1377 if ( _hypType == NONE )
1380 if ( _hypType == ADAPTIVE )
1382 _adaptiveHyp->GetAlgo()->InitComputeError();
1383 _adaptiveHyp->GetAlgo()->Evaluate( theMesh, theShape, theResMap );
1384 return error( _adaptiveHyp->GetAlgo()->GetComputeError() );
1387 const TopoDS_Edge & EE = TopoDS::Edge(theShape);
1388 TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
1391 Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
1393 TopoDS_Vertex VFirst, VLast;
1394 TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l
1396 ASSERT(!VFirst.IsNull());
1397 ASSERT(!VLast.IsNull());
1399 std::vector<smIdType> aVec(SMDSEntity_Last,0);
1401 double length = EdgeLength( E );
1402 if ( !Curve.IsNull() && length > 0 )
1404 list< double > params;
1405 BRepAdaptor_Curve C3d( E );
1406 if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, false, true )) {
1407 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1408 theResMap.insert(std::make_pair(sm,aVec));
1409 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
1410 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
1413 redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
1415 if(_quadraticMesh) {
1416 aVec[SMDSEntity_Node ] = 2*params.size() + 1;
1417 aVec[SMDSEntity_Quad_Edge] = params.size() + 1;
1420 aVec[SMDSEntity_Node] = params.size();
1421 aVec[SMDSEntity_Edge] = params.size() + 1;
1426 // Edge is a degenerated Edge : We put n = 5 points on the edge.
1427 if ( _quadraticMesh ) {
1428 aVec[SMDSEntity_Node ] = 11;
1429 aVec[SMDSEntity_Quad_Edge] = 6;
1432 aVec[SMDSEntity_Node] = 5;
1433 aVec[SMDSEntity_Edge] = 6;
1437 SMESH_subMesh * sm = theMesh.GetSubMesh( theShape );
1438 theResMap.insert( std::make_pair( sm, aVec ));
1444 //=============================================================================
1446 * See comments in SMESH_Algo.cxx
1448 //=============================================================================
1450 const list <const SMESHDS_Hypothesis *> &
1451 StdMeshers_Regular_1D::GetUsedHypothesis(SMESH_Mesh & aMesh,
1452 const TopoDS_Shape & aShape,
1453 const bool ignoreAuxiliary)
1455 _usedHypList.clear();
1456 _mainEdge.Nullify();
1458 SMESH_HypoFilter auxiliaryFilter( SMESH_HypoFilter::IsAuxiliary() );
1459 const SMESH_HypoFilter* compatibleFilter = GetCompatibleHypoFilter(/*ignoreAux=*/true );
1461 // get non-auxiliary assigned directly to aShape
1462 int nbHyp = aMesh.GetHypotheses( aShape, *compatibleFilter, _usedHypList, false );
1464 if (nbHyp == 0 && aShape.ShapeType() == TopAbs_EDGE)
1466 // Check, if propagated from some other edge
1467 bool isPropagOfDistribution = false;
1468 _mainEdge = StdMeshers_Propagation::GetPropagationSource( aMesh, aShape,
1469 isPropagOfDistribution );
1470 if ( !_mainEdge.IsNull() )
1472 if ( isPropagOfDistribution )
1473 _hypType = DISTRIB_PROPAGATION;
1474 // Propagation of 1D hypothesis from <aMainEdge> on this edge;
1475 // get non-auxiliary assigned to _mainEdge
1476 nbHyp = aMesh.GetHypotheses( _mainEdge, *compatibleFilter, _usedHypList, true );
1480 if (nbHyp == 0) // nothing propagated nor assigned to aShape
1482 SMESH_Algo::GetUsedHypothesis( aMesh, aShape, ignoreAuxiliary );
1483 nbHyp = (int)_usedHypList.size();
1487 // get auxiliary hyps from aShape
1488 aMesh.GetHypotheses( aShape, auxiliaryFilter, _usedHypList, true );
1490 if ( nbHyp > 1 && ignoreAuxiliary )
1491 _usedHypList.clear(); //only one compatible non-auxiliary hypothesis allowed
1493 return _usedHypList;
1496 //================================================================================
1498 * \brief Pass CancelCompute() to a child algorithm
1500 //================================================================================
1502 void StdMeshers_Regular_1D::CancelCompute()
1504 SMESH_Algo::CancelCompute();
1505 if ( _hypType == ADAPTIVE )
1506 _adaptiveHyp->GetAlgo()->CancelCompute();