1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : StdMeshers_Regular_1D.cxx
25 // Moved here from SMESH_Regular_1D.cxx
26 // Author : Paul RASCLE, EDF
29 #include "StdMeshers_Regular_1D.hxx"
30 #include "StdMeshers_Distribution.hxx"
32 #include "StdMeshers_Arithmetic1D.hxx"
33 #include "StdMeshers_AutomaticLength.hxx"
34 #include "StdMeshers_Deflection1D.hxx"
35 #include "StdMeshers_LocalLength.hxx"
36 #include "StdMeshers_MaxLength.hxx"
37 #include "StdMeshers_NumberOfSegments.hxx"
38 #include "StdMeshers_Propagation.hxx"
39 #include "StdMeshers_SegmentLengthAroundVertex.hxx"
40 #include "StdMeshers_StartEndLength.hxx"
42 #include "SMESH_Gen.hxx"
43 #include "SMESH_Mesh.hxx"
44 #include "SMESH_HypoFilter.hxx"
45 #include "SMESH_subMesh.hxx"
46 #include "SMESH_subMeshEventListener.hxx"
47 #include "SMESH_Comment.hxx"
49 #include "SMDS_MeshElement.hxx"
50 #include "SMDS_MeshNode.hxx"
52 #include "Utils_SALOME_Exception.hxx"
53 #include "utilities.h"
55 #include <BRepAdaptor_Curve.hxx>
56 #include <BRep_Tool.hxx>
57 #include <GCPnts_AbscissaPoint.hxx>
58 #include <GCPnts_UniformAbscissa.hxx>
59 #include <GCPnts_UniformDeflection.hxx>
60 #include <Precision.hxx>
62 #include <TopExp_Explorer.hxx>
64 #include <TopoDS_Edge.hxx>
71 //=============================================================================
75 //=============================================================================
77 StdMeshers_Regular_1D::StdMeshers_Regular_1D(int hypId, int studyId,
78 SMESH_Gen * gen):SMESH_1D_Algo(hypId, studyId, gen)
80 MESSAGE("StdMeshers_Regular_1D::StdMeshers_Regular_1D");
82 _shapeType = (1 << TopAbs_EDGE);
85 _compatibleHypothesis.push_back("LocalLength");
86 _compatibleHypothesis.push_back("MaxLength");
87 _compatibleHypothesis.push_back("NumberOfSegments");
88 _compatibleHypothesis.push_back("StartEndLength");
89 _compatibleHypothesis.push_back("Deflection1D");
90 _compatibleHypothesis.push_back("Arithmetic1D");
91 _compatibleHypothesis.push_back("FixedPoints1D");
92 _compatibleHypothesis.push_back("AutomaticLength");
94 _compatibleHypothesis.push_back("QuadraticMesh"); // auxiliary !!!
95 _compatibleHypothesis.push_back("Propagation"); // auxiliary !!!
98 //=============================================================================
102 //=============================================================================
104 StdMeshers_Regular_1D::~StdMeshers_Regular_1D()
108 //=============================================================================
112 //=============================================================================
114 bool StdMeshers_Regular_1D::CheckHypothesis
116 const TopoDS_Shape& aShape,
117 SMESH_Hypothesis::Hypothesis_Status& aStatus)
120 _quadraticMesh = false;
122 const bool ignoreAuxiliaryHyps = false;
123 const list <const SMESHDS_Hypothesis * > & hyps =
124 GetUsedHypothesis(aMesh, aShape, ignoreAuxiliaryHyps);
126 // find non-auxiliary hypothesis
127 const SMESHDS_Hypothesis *theHyp = 0;
128 list <const SMESHDS_Hypothesis * >::const_iterator h = hyps.begin();
129 for ( ; h != hyps.end(); ++h ) {
130 if ( static_cast<const SMESH_Hypothesis*>(*h)->IsAuxiliary() ) {
131 if ( strcmp( "QuadraticMesh", (*h)->GetName() ) == 0 )
132 _quadraticMesh = true;
136 theHyp = *h; // use only the first non-auxiliary hypothesis
142 aStatus = SMESH_Hypothesis::HYP_MISSING;
143 return false; // can't work without a hypothesis
146 string hypName = theHyp->GetName();
148 if (hypName == "LocalLength")
150 const StdMeshers_LocalLength * hyp =
151 dynamic_cast <const StdMeshers_LocalLength * >(theHyp);
153 _value[ BEG_LENGTH_IND ] = hyp->GetLength();
154 _value[ PRECISION_IND ] = hyp->GetPrecision();
155 ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
156 _hypType = LOCAL_LENGTH;
157 aStatus = SMESH_Hypothesis::HYP_OK;
160 else if (hypName == "MaxLength")
162 const StdMeshers_MaxLength * hyp =
163 dynamic_cast <const StdMeshers_MaxLength * >(theHyp);
165 _value[ BEG_LENGTH_IND ] = hyp->GetLength();
166 if ( hyp->GetUsePreestimatedLength() ) {
167 if ( int nbSeg = aMesh.GetGen()->GetBoundaryBoxSegmentation() )
168 _value[ BEG_LENGTH_IND ] = aMesh.GetShapeDiagonalSize() / nbSeg;
170 ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
171 _hypType = MAX_LENGTH;
172 aStatus = SMESH_Hypothesis::HYP_OK;
175 else if (hypName == "NumberOfSegments")
177 const StdMeshers_NumberOfSegments * hyp =
178 dynamic_cast <const StdMeshers_NumberOfSegments * >(theHyp);
180 _ivalue[ NB_SEGMENTS_IND ] = hyp->GetNumberOfSegments();
181 ASSERT( _ivalue[ NB_SEGMENTS_IND ] > 0 );
182 _ivalue[ DISTR_TYPE_IND ] = (int) hyp->GetDistrType();
183 switch (_ivalue[ DISTR_TYPE_IND ])
185 case StdMeshers_NumberOfSegments::DT_Scale:
186 _value[ SCALE_FACTOR_IND ] = hyp->GetScaleFactor();
187 _revEdgesIDs = hyp->GetReversedEdges();
189 case StdMeshers_NumberOfSegments::DT_TabFunc:
190 _vvalue[ TAB_FUNC_IND ] = hyp->GetTableFunction();
191 _revEdgesIDs = hyp->GetReversedEdges();
193 case StdMeshers_NumberOfSegments::DT_ExprFunc:
194 _svalue[ EXPR_FUNC_IND ] = hyp->GetExpressionFunction();
195 _revEdgesIDs = hyp->GetReversedEdges();
197 case StdMeshers_NumberOfSegments::DT_Regular:
203 if (_ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_TabFunc ||
204 _ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_ExprFunc)
205 _ivalue[ CONV_MODE_IND ] = hyp->ConversionMode();
206 _hypType = NB_SEGMENTS;
207 aStatus = SMESH_Hypothesis::HYP_OK;
210 else if (hypName == "Arithmetic1D")
212 const StdMeshers_Arithmetic1D * hyp =
213 dynamic_cast <const StdMeshers_Arithmetic1D * >(theHyp);
215 _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
216 _value[ END_LENGTH_IND ] = hyp->GetLength( false );
217 ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
218 _hypType = ARITHMETIC_1D;
220 _revEdgesIDs = hyp->GetReversedEdges();
222 aStatus = SMESH_Hypothesis::HYP_OK;
225 else if (hypName == "FixedPoints1D") {
226 _fpHyp = dynamic_cast <const StdMeshers_FixedPoints1D*>(theHyp);
228 _hypType = FIXED_POINTS_1D;
230 _revEdgesIDs = _fpHyp->GetReversedEdges();
232 aStatus = SMESH_Hypothesis::HYP_OK;
235 else if (hypName == "StartEndLength")
237 const StdMeshers_StartEndLength * hyp =
238 dynamic_cast <const StdMeshers_StartEndLength * >(theHyp);
240 _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
241 _value[ END_LENGTH_IND ] = hyp->GetLength( false );
242 ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
243 _hypType = BEG_END_LENGTH;
245 _revEdgesIDs = hyp->GetReversedEdges();
247 aStatus = SMESH_Hypothesis::HYP_OK;
250 else if (hypName == "Deflection1D")
252 const StdMeshers_Deflection1D * hyp =
253 dynamic_cast <const StdMeshers_Deflection1D * >(theHyp);
255 _value[ DEFLECTION_IND ] = hyp->GetDeflection();
256 ASSERT( _value[ DEFLECTION_IND ] > 0 );
257 _hypType = DEFLECTION;
258 aStatus = SMESH_Hypothesis::HYP_OK;
261 else if (hypName == "AutomaticLength")
263 StdMeshers_AutomaticLength * hyp = const_cast<StdMeshers_AutomaticLength *>
264 (dynamic_cast <const StdMeshers_AutomaticLength * >(theHyp));
266 _value[ BEG_LENGTH_IND ] = _value[ END_LENGTH_IND ] = hyp->GetLength( &aMesh, aShape );
267 // _value[ BEG_LENGTH_IND ] = hyp->GetLength( &aMesh, aShape );
268 // _value[ END_LENGTH_IND ] = Precision::Confusion(); // ?? or set to zero?
269 ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
270 _hypType = MAX_LENGTH;
271 aStatus = SMESH_Hypothesis::HYP_OK;
274 aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
276 return ( _hypType != NONE );
279 static bool computeParamByFunc(Adaptor3d_Curve& C3d, double first, double last,
280 double length, bool theReverse,
281 int nbSeg, Function& func,
282 list<double>& theParams)
285 //OSD::SetSignal( true );
290 MESSAGE( "computeParamByFunc" );
292 int nbPnt = 1 + nbSeg;
293 vector<double> x(nbPnt, 0.);
295 if (!buildDistribution(func, 0.0, 1.0, nbSeg, x, 1E-4))
298 MESSAGE( "Points:\n" );
300 for ( int i=0; i<=nbSeg; i++ )
302 sprintf( buf, "%f\n", float(x[i] ) );
308 // apply parameters in range [0,1] to the space of the curve
309 double prevU = first;
316 for( int i = 1; i < nbSeg; i++ )
318 double curvLength = length * (x[i] - x[i-1]) * sign;
319 GCPnts_AbscissaPoint Discret( C3d, curvLength, prevU );
320 if ( !Discret.IsDone() )
322 double U = Discret.Parameter();
323 if ( U > first && U < last )
324 theParams.push_back( U );
335 //================================================================================
337 * \brief adjust internal node parameters so that the last segment length == an
338 * \param a1 - the first segment length
339 * \param an - the last segment length
340 * \param U1 - the first edge parameter
341 * \param Un - the last edge parameter
342 * \param length - the edge length
343 * \param C3d - the edge curve
344 * \param theParams - internal node parameters to adjust
345 * \param adjustNeighbors2an - to adjust length of segments next to the last one
346 * and not to remove parameters
348 //================================================================================
350 static void compensateError(double a1, double an,
351 double U1, double Un,
353 Adaptor3d_Curve& C3d,
354 list<double> & theParams,
355 bool adjustNeighbors2an = false)
357 int i, nPar = theParams.size();
358 if ( a1 + an < length && nPar > 1 )
360 bool reverse = ( U1 > Un );
361 GCPnts_AbscissaPoint Discret(C3d, reverse ? an : -an, Un);
362 if ( !Discret.IsDone() )
364 double Utgt = Discret.Parameter(); // target value of the last parameter
365 list<double>::reverse_iterator itU = theParams.rbegin();
366 double Ul = *itU++; // real value of the last parameter
367 double dUn = Utgt - Ul; // parametric error of <an>
368 if ( Abs(dUn) <= Precision::Confusion() )
370 double dU = Abs( Ul - *itU ); // parametric length of the last but one segment
371 if ( adjustNeighbors2an || Abs(dUn) < 0.5 * dU ) { // last segment is a bit shorter than it should
372 // move the last parameter to the edge beginning
374 else { // last segment is much shorter than it should -> remove the last param and
375 theParams.pop_back(); nPar--; // move the rest points toward the edge end
376 dUn = Utgt - theParams.back();
379 double q = dUn / ( nPar - 1 );
380 if ( !adjustNeighbors2an ) {
381 for ( itU = theParams.rbegin(), i = 1; i < nPar; itU++, i++ ) {
387 theParams.back() += dUn;
388 double sign = reverse ? -1 : 1;
389 double prevU = theParams.back();
390 itU = theParams.rbegin();
391 for ( ++itU, i = 2; i < nPar; ++itU, i++ ) {
392 double newU = *itU + dUn;
393 if ( newU*sign < prevU*sign ) {
397 else { // set U between prevU and next valid param
398 list<double>::reverse_iterator itU2 = itU;
401 while ( (*itU2)*sign > prevU*sign ) {
404 dU = ( *itU2 - prevU ) / nb;
405 while ( itU != itU2 ) {
415 //================================================================================
417 * \brief Class used to clean mesh on edges when 0D hyp modified.
418 * Common approach doesn't work when 0D algo is missing because the 0D hyp is
419 * considered as not participating in computation whereas it is used by 1D algo.
421 //================================================================================
423 // struct VertexEventListener : public SMESH_subMeshEventListener
425 // VertexEventListener():SMESH_subMeshEventListener(0) // won't be deleted by submesh
428 // * \brief Clean mesh on edges
429 // * \param event - algo_event or compute_event itself (of SMESH_subMesh)
430 // * \param eventType - ALGO_EVENT or COMPUTE_EVENT (of SMESH_subMesh)
431 // * \param subMesh - the submesh where the event occures
433 // void ProcessEvent(const int event, const int eventType, SMESH_subMesh* subMesh,
434 // EventListenerData*, const SMESH_Hypothesis*)
436 // if ( eventType == SMESH_subMesh::ALGO_EVENT) // all algo events
438 // subMesh->ComputeStateEngine( SMESH_subMesh::MODIF_ALGO_STATE );
441 // }; // struct VertexEventListener
443 //=============================================================================
445 * \brief Sets event listener to vertex submeshes
446 * \param subMesh - submesh where algo is set
448 * This method is called when a submesh gets HYP_OK algo_state.
449 * After being set, event listener is notified on each event of a submesh.
451 //=============================================================================
453 void StdMeshers_Regular_1D::SetEventListener(SMESH_subMesh* subMesh)
455 StdMeshers_Propagation::SetPropagationMgr( subMesh );
458 //=============================================================================
461 * \param subMesh - restored submesh
463 * This method is called only if a submesh has HYP_OK algo_state.
465 //=============================================================================
467 void StdMeshers_Regular_1D::SubmeshRestored(SMESH_subMesh* subMesh)
471 //=============================================================================
473 * \brief Return StdMeshers_SegmentLengthAroundVertex assigned to vertex
475 //=============================================================================
477 const StdMeshers_SegmentLengthAroundVertex*
478 StdMeshers_Regular_1D::getVertexHyp(SMESH_Mesh & theMesh,
479 const TopoDS_Vertex & theV)
481 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName("SegmentAroundVertex_0D"));
482 if ( const SMESH_Hypothesis * h = theMesh.GetHypothesis( theV, filter, true ))
484 SMESH_Algo* algo = const_cast< SMESH_Algo* >( static_cast< const SMESH_Algo* > ( h ));
485 const list <const SMESHDS_Hypothesis *> & hypList = algo->GetUsedHypothesis( theMesh, theV, 0 );
486 if ( !hypList.empty() && string("SegmentLengthAroundVertex") == hypList.front()->GetName() )
487 return static_cast<const StdMeshers_SegmentLengthAroundVertex*>( hypList.front() );
492 //================================================================================
494 * \brief Tune parameters to fit "SegmentLengthAroundVertex" hypothesis
495 * \param theC3d - wire curve
496 * \param theLength - curve length
497 * \param theParameters - internal nodes parameters to modify
498 * \param theVf - 1st vertex
499 * \param theVl - 2nd vertex
501 //================================================================================
503 void StdMeshers_Regular_1D::redistributeNearVertices (SMESH_Mesh & theMesh,
504 Adaptor3d_Curve & theC3d,
506 std::list< double > & theParameters,
507 const TopoDS_Vertex & theVf,
508 const TopoDS_Vertex & theVl)
510 double f = theC3d.FirstParameter(), l = theC3d.LastParameter();
511 int nPar = theParameters.size();
512 for ( int isEnd1 = 0; isEnd1 < 2; ++isEnd1 )
514 const TopoDS_Vertex & V = isEnd1 ? theVf : theVl;
515 const StdMeshers_SegmentLengthAroundVertex* hyp = getVertexHyp (theMesh, V );
517 double vertexLength = hyp->GetLength();
518 if ( vertexLength > theLength / 2.0 )
520 if ( isEnd1 ) { // to have a segment of interest at end of theParameters
521 theParameters.reverse();
524 if ( _hypType == NB_SEGMENTS )
526 compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
528 else if ( nPar <= 3 )
531 vertexLength = -vertexLength;
532 GCPnts_AbscissaPoint Discret(theC3d, vertexLength, l);
533 if ( Discret.IsDone() ) {
535 theParameters.push_back( Discret.Parameter());
537 double L = GCPnts_AbscissaPoint::Length( theC3d, theParameters.back(), l);
538 if ( vertexLength < L / 2.0 )
539 theParameters.push_back( Discret.Parameter());
541 compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
547 // recompute params between the last segment and a middle one.
548 // find size of a middle segment
549 int nHalf = ( nPar-1 ) / 2;
550 list< double >::reverse_iterator itU = theParameters.rbegin();
551 std::advance( itU, nHalf );
553 double Lm = GCPnts_AbscissaPoint::Length( theC3d, Um, *itU);
554 double L = GCPnts_AbscissaPoint::Length( theC3d, *itU, l);
555 StdMeshers_Regular_1D algo( *this );
556 algo._hypType = BEG_END_LENGTH;
557 algo._value[ BEG_LENGTH_IND ] = Lm;
558 algo._value[ END_LENGTH_IND ] = vertexLength;
559 double from = *itU, to = l;
561 std::swap( from, to );
562 std::swap( algo._value[ BEG_LENGTH_IND ], algo._value[ END_LENGTH_IND ]);
565 if ( algo.computeInternalParameters( theMesh, theC3d, L, from, to, params, false ))
567 if ( isEnd1 ) params.reverse();
568 while ( 1 + nHalf-- )
569 theParameters.pop_back();
570 theParameters.splice( theParameters.end(), params );
574 compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
578 theParameters.reverse();
583 //=============================================================================
587 //=============================================================================
588 bool StdMeshers_Regular_1D::computeInternalParameters(SMESH_Mesh & theMesh,
589 Adaptor3d_Curve& theC3d,
593 list<double> & theParams,
594 const bool theReverse,
595 bool theConsiderPropagation)
599 double f = theFirstU, l = theLastU;
608 if ( _hypType == MAX_LENGTH )
610 double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
612 nbseg = 1; // degenerated edge
613 eltSize = theLength / nbseg;
615 else if ( _hypType == LOCAL_LENGTH )
617 // Local Length hypothesis
618 double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
621 bool isFound = false;
622 if (theConsiderPropagation && !_mainEdge.IsNull()) // propagated from some other edge
624 // Advanced processing to assure equal number of segments in case of Propagation
625 SMESH_subMesh* sm = theMesh.GetSubMeshContaining(_mainEdge);
627 bool computed = sm->IsMeshComputed();
629 if (sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE) {
630 sm->ComputeStateEngine(SMESH_subMesh::COMPUTE);
631 computed = sm->IsMeshComputed();
635 SMESHDS_SubMesh* smds = sm->GetSubMeshDS();
636 int nb_segments = smds->NbElements();
637 if (nbseg - 1 <= nb_segments && nb_segments <= nbseg + 1) {
644 if (!isFound) // not found by meshed edge in the propagation chain, use precision
646 double aPrecision = _value[ PRECISION_IND ];
647 double nbseg_prec = ceil((theLength / _value[ BEG_LENGTH_IND ]) - aPrecision);
648 if (nbseg_prec == (nbseg - 1)) nbseg--;
652 nbseg = 1; // degenerated edge
653 eltSize = theLength / nbseg;
657 // Number Of Segments hypothesis
658 int NbSegm = _ivalue[ NB_SEGMENTS_IND ];
659 if ( NbSegm < 1 ) return false;
660 if ( NbSegm == 1 ) return true;
662 switch (_ivalue[ DISTR_TYPE_IND ])
664 case StdMeshers_NumberOfSegments::DT_Scale:
666 double scale = _value[ SCALE_FACTOR_IND ];
668 if (fabs(scale - 1.0) < Precision::Confusion()) {
669 // special case to avoid division by zero
670 for (int i = 1; i < NbSegm; i++) {
671 double param = f + (l - f) * i / NbSegm;
672 theParams.push_back( param );
675 // general case of scale distribution
679 double alpha = pow(scale, 1.0 / (NbSegm - 1));
680 double factor = (l - f) / (1.0 - pow(alpha, NbSegm));
682 for (int i = 1; i < NbSegm; i++) {
683 double param = f + factor * (1.0 - pow(alpha, i));
684 theParams.push_back( param );
690 case StdMeshers_NumberOfSegments::DT_TabFunc:
692 FunctionTable func(_vvalue[ TAB_FUNC_IND ], _ivalue[ CONV_MODE_IND ]);
693 return computeParamByFunc(theC3d, f, l, theLength, theReverse,
694 _ivalue[ NB_SEGMENTS_IND ], func,
698 case StdMeshers_NumberOfSegments::DT_ExprFunc:
700 FunctionExpr func(_svalue[ EXPR_FUNC_IND ].c_str(), _ivalue[ CONV_MODE_IND ]);
701 return computeParamByFunc(theC3d, f, l, theLength, theReverse,
702 _ivalue[ NB_SEGMENTS_IND ], func,
706 case StdMeshers_NumberOfSegments::DT_Regular:
707 eltSize = theLength / _ivalue[ NB_SEGMENTS_IND ];
713 GCPnts_UniformAbscissa Discret(theC3d, eltSize, f, l);
714 if ( !Discret.IsDone() )
715 return error( "GCPnts_UniformAbscissa failed");
717 int NbPoints = Discret.NbPoints();
718 for ( int i = 2; i < NbPoints; i++ )
720 double param = Discret.Parameter(i);
721 theParams.push_back( param );
723 compensateError( eltSize, eltSize, f, l, theLength, theC3d, theParams ); // for PAL9899
727 case BEG_END_LENGTH: {
729 // geometric progression: SUM(n) = ( a1 - an * q ) / ( 1 - q ) = theLength
731 double a1 = _value[ BEG_LENGTH_IND ];
732 double an = _value[ END_LENGTH_IND ];
733 double q = ( theLength - a1 ) / ( theLength - an );
735 double U1 = theReverse ? l : f;
736 double Un = theReverse ? f : l;
738 double eltSize = theReverse ? -a1 : a1;
740 // computes a point on a curve <theC3d> at the distance <eltSize>
741 // from the point of parameter <param>.
742 GCPnts_AbscissaPoint Discret( theC3d, eltSize, param );
743 if ( !Discret.IsDone() ) break;
744 param = Discret.Parameter();
745 if ( f < param && param < l )
746 theParams.push_back( param );
751 compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
752 if (theReverse) theParams.reverse(); // NPAL18025
756 case ARITHMETIC_1D: {
758 // arithmetic progression: SUM(n) = ( an - a1 + q ) * ( a1 + an ) / ( 2 * q ) = theLength
760 double a1 = _value[ BEG_LENGTH_IND ];
761 double an = _value[ END_LENGTH_IND ];
763 double q = ( an - a1 ) / ( 2 *theLength/( a1 + an ) - 1 );
764 int n = int(fabs(q) > numeric_limits<double>::min() ? ( 1+( an-a1 )/q ) : ( 1+theLength/a1 ));
766 double U1 = theReverse ? l : f;
767 double Un = theReverse ? f : l;
774 while ( n-- > 0 && eltSize * ( Un - U1 ) > 0 ) {
775 // computes a point on a curve <theC3d> at the distance <eltSize>
776 // from the point of parameter <param>.
777 GCPnts_AbscissaPoint Discret( theC3d, eltSize, param );
778 if ( !Discret.IsDone() ) break;
779 param = Discret.Parameter();
780 if ( param > f && param < l )
781 theParams.push_back( param );
786 compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
787 if (theReverse) theParams.reverse(); // NPAL18025
792 case FIXED_POINTS_1D: {
793 const std::vector<double>& aPnts = _fpHyp->GetPoints();
794 const std::vector<int>& nbsegs = _fpHyp->GetNbSegments();
796 TColStd_SequenceOfReal Params;
797 for(; i<aPnts.size(); i++) {
798 if( aPnts[i]<0.0001 || aPnts[i]>0.9999 ) continue;
800 bool IsExist = false;
801 for(; j<=Params.Length(); j++) {
802 if( fabs(aPnts[i]-Params.Value(j)) < 1e-4 ) {
806 if( aPnts[i]<Params.Value(j) ) break;
808 if(!IsExist) Params.InsertBefore(j,aPnts[i]);
810 double par2, par1, lp;
819 double eltSize, segmentSize = 0.;
820 double currAbscissa = 0;
821 for(i=0; i<Params.Length(); i++) {
822 int nbseg = ( i > nbsegs.size()-1 ) ? nbsegs[0] : nbsegs[i];
823 segmentSize = Params.Value(i+1)*theLength - currAbscissa;
824 currAbscissa += segmentSize;
825 GCPnts_AbscissaPoint APnt(theC3d, sign*segmentSize, par1);
827 return error( "GCPnts_AbscissaPoint failed");
828 par2 = APnt.Parameter();
829 eltSize = segmentSize/nbseg;
830 GCPnts_UniformAbscissa Discret(theC3d, eltSize, par1, par2);
832 Discret.Initialize(theC3d, eltSize, par2, par1);
834 Discret.Initialize(theC3d, eltSize, par1, par2);
835 if ( !Discret.IsDone() )
836 return error( "GCPnts_UniformAbscissa failed");
837 int NbPoints = Discret.NbPoints();
838 list<double> tmpParams;
839 for(int i=2; i<NbPoints; i++) {
840 double param = Discret.Parameter(i);
841 tmpParams.push_back( param );
844 compensateError( eltSize, eltSize, par2, par1, segmentSize, theC3d, tmpParams );
848 compensateError( eltSize, eltSize, par1, par2, segmentSize, theC3d, tmpParams );
850 list<double>::iterator itP = tmpParams.begin();
851 for(; itP != tmpParams.end(); itP++) {
852 theParams.push_back( *(itP) );
854 theParams.push_back( par2 );
859 int nbseg = ( nbsegs.size() > Params.Length() ) ? nbsegs[Params.Length()] : nbsegs[0];
860 segmentSize = theLength - currAbscissa;
861 eltSize = segmentSize/nbseg;
862 GCPnts_UniformAbscissa Discret;
864 Discret.Initialize(theC3d, eltSize, par1, lp);
866 Discret.Initialize(theC3d, eltSize, lp, par1);
867 if ( !Discret.IsDone() )
868 return error( "GCPnts_UniformAbscissa failed");
869 int NbPoints = Discret.NbPoints();
870 list<double> tmpParams;
871 for(int i=2; i<NbPoints; i++) {
872 double param = Discret.Parameter(i);
873 tmpParams.push_back( param );
876 compensateError( eltSize, eltSize, lp, par1, segmentSize, theC3d, tmpParams );
880 compensateError( eltSize, eltSize, par1, lp, segmentSize, theC3d, tmpParams );
882 list<double>::iterator itP = tmpParams.begin();
883 for(; itP != tmpParams.end(); itP++) {
884 theParams.push_back( *(itP) );
888 theParams.reverse(); // NPAL18025
895 GCPnts_UniformDeflection Discret(theC3d, _value[ DEFLECTION_IND ], f, l, true);
896 if ( !Discret.IsDone() )
899 int NbPoints = Discret.NbPoints();
900 for ( int i = 2; i < NbPoints; i++ )
902 double param = Discret.Parameter(i);
903 theParams.push_back( param );
914 //=============================================================================
918 //=============================================================================
920 bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & theShape)
922 if ( _hypType == NONE )
925 SMESHDS_Mesh * meshDS = theMesh.GetMeshDS();
927 const TopoDS_Edge & EE = TopoDS::Edge(theShape);
928 TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
929 int shapeID = meshDS->ShapeToIndex( E );
932 Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
934 TopoDS_Vertex VFirst, VLast;
935 TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l
937 ASSERT(!VFirst.IsNull());
938 ASSERT(!VLast.IsNull());
939 const SMDS_MeshNode * idFirst = SMESH_Algo::VertexNode( VFirst, meshDS );
940 const SMDS_MeshNode * idLast = SMESH_Algo::VertexNode( VLast, meshDS );
941 if (!idFirst || !idLast)
942 return error( COMPERR_BAD_INPUT_MESH, "No node on vertex");
946 list< double > params;
947 bool reversed = false;
948 if ( theMesh.GetShapeToMesh().ShapeType() >= TopAbs_WIRE ) {
949 reversed = ( EE.Orientation() == TopAbs_REVERSED );
951 if ( !_mainEdge.IsNull() ) {
952 reversed = ( _mainEdge.Orientation() == TopAbs_REVERSED );
954 else if ( _revEdgesIDs.size() > 0 ) {
955 for ( int i = 0; i < _revEdgesIDs.size(); i++) {
956 if ( _revEdgesIDs[i] == shapeID ) {
957 reversed = !reversed;
962 BRepAdaptor_Curve C3d( E );
963 double length = EdgeLength( E );
964 if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, reversed, true )) {
967 redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
969 // edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
970 // only internal nodes receive an edge position with param on curve
972 const SMDS_MeshNode * idPrev = idFirst;
986 for (list<double>::iterator itU = params.begin(); itU != params.end(); itU++) {
988 gp_Pnt P = Curve->Value(param);
990 //Add the Node in the DataStructure
991 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
992 meshDS->SetNodeOnEdge(node, shapeID, param);
995 // create medium node
996 double prm = ( parPrev + param )/2;
997 gp_Pnt PM = Curve->Value(prm);
998 SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
999 meshDS->SetNodeOnEdge(NM, shapeID, prm);
1000 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node, NM);
1001 meshDS->SetMeshElementOnShape(edge, shapeID);
1004 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
1005 meshDS->SetMeshElementOnShape(edge, shapeID);
1011 if(_quadraticMesh) {
1012 double prm = ( parPrev + parLast )/2;
1013 gp_Pnt PM = Curve->Value(prm);
1014 SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
1015 meshDS->SetNodeOnEdge(NM, shapeID, prm);
1016 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast, NM);
1017 meshDS->SetMeshElementOnShape(edge, shapeID);
1020 SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast);
1021 meshDS->SetMeshElementOnShape(edge, shapeID);
1026 //MESSAGE("************* Degenerated edge! *****************");
1028 // Edge is a degenerated Edge : We put n = 5 points on the edge.
1029 const int NbPoints = 5;
1030 BRep_Tool::Range( E, f, l ); // PAL15185
1031 double du = (l - f) / (NbPoints - 1);
1033 gp_Pnt P = BRep_Tool::Pnt(VFirst);
1035 const SMDS_MeshNode * idPrev = idFirst;
1036 for (int i = 2; i < NbPoints; i++) {
1037 double param = f + (i - 1) * du;
1038 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
1039 if(_quadraticMesh) {
1040 // create medium node
1041 double prm = param - du/2.;
1042 SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
1043 meshDS->SetNodeOnEdge(NM, shapeID, prm);
1044 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node, NM);
1045 meshDS->SetMeshElementOnShape(edge, shapeID);
1048 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
1049 meshDS->SetMeshElementOnShape(edge, shapeID);
1051 meshDS->SetNodeOnEdge(node, shapeID, param);
1054 if(_quadraticMesh) {
1055 // create medium node
1056 double prm = l - du/2.;
1057 SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
1058 meshDS->SetNodeOnEdge(NM, shapeID, prm);
1059 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast, NM);
1060 meshDS->SetMeshElementOnShape(edge, shapeID);
1063 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast);
1064 meshDS->SetMeshElementOnShape(edge, shapeID);
1071 //=============================================================================
1075 //=============================================================================
1077 bool StdMeshers_Regular_1D::Evaluate(SMESH_Mesh & theMesh,
1078 const TopoDS_Shape & theShape,
1079 MapShapeNbElems& aResMap)
1081 if ( _hypType == NONE )
1084 //SMESHDS_Mesh * meshDS = theMesh.GetMeshDS();
1086 const TopoDS_Edge & EE = TopoDS::Edge(theShape);
1087 TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
1088 // int shapeID = meshDS->ShapeToIndex( E );
1091 Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
1093 TopoDS_Vertex VFirst, VLast;
1094 TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l
1096 ASSERT(!VFirst.IsNull());
1097 ASSERT(!VLast.IsNull());
1099 std::vector<int> aVec(SMDSEntity_Last,0);
1101 if (!Curve.IsNull()) {
1102 list< double > params;
1104 BRepAdaptor_Curve C3d( E );
1105 double length = EdgeLength( E );
1106 if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, false, true )) {
1107 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1108 aResMap.insert(std::make_pair(sm,aVec));
1109 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
1110 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
1113 redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
1115 if(_quadraticMesh) {
1116 aVec[SMDSEntity_Node] = 2*params.size() + 1;
1117 aVec[SMDSEntity_Quad_Edge] = params.size() + 1;
1120 aVec[SMDSEntity_Node] = params.size();
1121 aVec[SMDSEntity_Edge] = params.size() + 1;
1126 //MESSAGE("************* Degenerated edge! *****************");
1127 // Edge is a degenerated Edge : We put n = 5 points on the edge.
1128 if(_quadraticMesh) {
1129 aVec[SMDSEntity_Node] = 11;
1130 aVec[SMDSEntity_Quad_Edge] = 6;
1133 aVec[SMDSEntity_Node] = 5;
1134 aVec[SMDSEntity_Edge] = 6;
1138 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1139 aResMap.insert(std::make_pair(sm,aVec));
1145 //=============================================================================
1147 * See comments in SMESH_Algo.cxx
1149 //=============================================================================
1151 const list <const SMESHDS_Hypothesis *> &
1152 StdMeshers_Regular_1D::GetUsedHypothesis(SMESH_Mesh & aMesh,
1153 const TopoDS_Shape & aShape,
1154 const bool ignoreAuxiliary)
1156 _usedHypList.clear();
1157 _mainEdge.Nullify();
1159 SMESH_HypoFilter auxiliaryFilter, compatibleFilter;
1160 auxiliaryFilter.Init( SMESH_HypoFilter::IsAuxiliary() );
1161 const bool ignoreAux = true;
1162 InitCompatibleHypoFilter( compatibleFilter, ignoreAux );
1164 // get non-auxiliary assigned to aShape
1165 int nbHyp = aMesh.GetHypotheses( aShape, compatibleFilter, _usedHypList, false );
1167 if (nbHyp == 0 && aShape.ShapeType() == TopAbs_EDGE)
1169 // Check, if propagated from some other edge
1170 _mainEdge = StdMeshers_Propagation::GetPropagationSource( aMesh, aShape );
1171 if ( !_mainEdge.IsNull() )
1173 // Propagation of 1D hypothesis from <aMainEdge> on this edge;
1174 // get non-auxiliary assigned to _mainEdge
1175 nbHyp = aMesh.GetHypotheses( _mainEdge, compatibleFilter, _usedHypList, true );
1179 if (nbHyp == 0) // nothing propagated nor assigned to aShape
1181 SMESH_Algo::GetUsedHypothesis( aMesh, aShape, ignoreAuxiliary );
1182 nbHyp = _usedHypList.size();
1186 // get auxiliary hyps from aShape
1187 aMesh.GetHypotheses( aShape, auxiliaryFilter, _usedHypList, true );
1189 if ( nbHyp > 1 && ignoreAuxiliary )
1190 _usedHypList.clear(); //only one compatible non-auxiliary hypothesis allowed
1192 return _usedHypList;