1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 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
24 // File : StdMeshers_Regular_1D.cxx
25 // Moved here from SMESH_Regular_1D.cxx
26 // Author : Paul RASCLE, EDF
30 #include "StdMeshers_Regular_1D.hxx"
31 #include "StdMeshers_Distribution.hxx"
33 #include "StdMeshers_LocalLength.hxx"
34 #include "StdMeshers_NumberOfSegments.hxx"
35 #include "StdMeshers_Arithmetic1D.hxx"
36 #include "StdMeshers_StartEndLength.hxx"
37 #include "StdMeshers_Deflection1D.hxx"
38 #include "StdMeshers_AutomaticLength.hxx"
39 #include "StdMeshers_SegmentLengthAroundVertex.hxx"
40 #include "StdMeshers_Propagation.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>
70 //=============================================================================
74 //=============================================================================
76 StdMeshers_Regular_1D::StdMeshers_Regular_1D(int hypId, int studyId,
77 SMESH_Gen * gen):SMESH_1D_Algo(hypId, studyId, gen)
79 MESSAGE("StdMeshers_Regular_1D::StdMeshers_Regular_1D");
81 _shapeType = (1 << TopAbs_EDGE);
83 _compatibleHypothesis.push_back("LocalLength");
84 _compatibleHypothesis.push_back("NumberOfSegments");
85 _compatibleHypothesis.push_back("StartEndLength");
86 _compatibleHypothesis.push_back("Deflection1D");
87 _compatibleHypothesis.push_back("Arithmetic1D");
88 _compatibleHypothesis.push_back("AutomaticLength");
90 _compatibleHypothesis.push_back("QuadraticMesh"); // auxiliary !!!
91 _compatibleHypothesis.push_back("Propagation"); // auxiliary !!!
94 //=============================================================================
98 //=============================================================================
100 StdMeshers_Regular_1D::~StdMeshers_Regular_1D()
104 //=============================================================================
108 //=============================================================================
110 bool StdMeshers_Regular_1D::CheckHypothesis
112 const TopoDS_Shape& aShape,
113 SMESH_Hypothesis::Hypothesis_Status& aStatus)
116 _quadraticMesh = false;
118 const bool ignoreAuxiliaryHyps = false;
119 const list <const SMESHDS_Hypothesis * > & hyps =
120 GetUsedHypothesis(aMesh, aShape, ignoreAuxiliaryHyps);
122 // find non-auxiliary hypothesis
123 const SMESHDS_Hypothesis *theHyp = 0;
124 list <const SMESHDS_Hypothesis * >::const_iterator h = hyps.begin();
125 for ( ; h != hyps.end(); ++h ) {
126 if ( static_cast<const SMESH_Hypothesis*>(*h)->IsAuxiliary() ) {
127 if ( strcmp( "QuadraticMesh", (*h)->GetName() ) == 0 )
128 _quadraticMesh = true;
132 theHyp = *h; // use only the first non-auxiliary hypothesis
138 aStatus = SMESH_Hypothesis::HYP_MISSING;
139 return false; // can't work without a hypothesis
142 string hypName = theHyp->GetName();
144 if (hypName == "LocalLength")
146 const StdMeshers_LocalLength * hyp =
147 dynamic_cast <const StdMeshers_LocalLength * >(theHyp);
149 _value[ BEG_LENGTH_IND ] = _value[ END_LENGTH_IND ] = hyp->GetLength();
150 ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
151 _hypType = LOCAL_LENGTH;
152 aStatus = SMESH_Hypothesis::HYP_OK;
155 else if (hypName == "NumberOfSegments")
157 const StdMeshers_NumberOfSegments * hyp =
158 dynamic_cast <const StdMeshers_NumberOfSegments * >(theHyp);
160 _ivalue[ NB_SEGMENTS_IND ] = hyp->GetNumberOfSegments();
161 ASSERT( _ivalue[ NB_SEGMENTS_IND ] > 0 );
162 _ivalue[ DISTR_TYPE_IND ] = (int) hyp->GetDistrType();
163 switch (_ivalue[ DISTR_TYPE_IND ])
165 case StdMeshers_NumberOfSegments::DT_Scale:
166 _value[ SCALE_FACTOR_IND ] = hyp->GetScaleFactor();
168 case StdMeshers_NumberOfSegments::DT_TabFunc:
169 _vvalue[ TAB_FUNC_IND ] = hyp->GetTableFunction();
171 case StdMeshers_NumberOfSegments::DT_ExprFunc:
172 _svalue[ EXPR_FUNC_IND ] = hyp->GetExpressionFunction();
174 case StdMeshers_NumberOfSegments::DT_Regular:
180 if (_ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_TabFunc ||
181 _ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_ExprFunc)
182 _ivalue[ CONV_MODE_IND ] = hyp->ConversionMode();
183 _hypType = NB_SEGMENTS;
184 aStatus = SMESH_Hypothesis::HYP_OK;
187 else if (hypName == "Arithmetic1D")
189 const StdMeshers_Arithmetic1D * hyp =
190 dynamic_cast <const StdMeshers_Arithmetic1D * >(theHyp);
192 _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
193 _value[ END_LENGTH_IND ] = hyp->GetLength( false );
194 ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
195 _hypType = ARITHMETIC_1D;
196 aStatus = SMESH_Hypothesis::HYP_OK;
199 else if (hypName == "StartEndLength")
201 const StdMeshers_StartEndLength * hyp =
202 dynamic_cast <const StdMeshers_StartEndLength * >(theHyp);
204 _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
205 _value[ END_LENGTH_IND ] = hyp->GetLength( false );
206 ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
207 _hypType = BEG_END_LENGTH;
208 aStatus = SMESH_Hypothesis::HYP_OK;
211 else if (hypName == "Deflection1D")
213 const StdMeshers_Deflection1D * hyp =
214 dynamic_cast <const StdMeshers_Deflection1D * >(theHyp);
216 _value[ DEFLECTION_IND ] = hyp->GetDeflection();
217 ASSERT( _value[ DEFLECTION_IND ] > 0 );
218 _hypType = DEFLECTION;
219 aStatus = SMESH_Hypothesis::HYP_OK;
222 else if (hypName == "AutomaticLength")
224 StdMeshers_AutomaticLength * hyp = const_cast<StdMeshers_AutomaticLength *>
225 (dynamic_cast <const StdMeshers_AutomaticLength * >(theHyp));
227 _value[ BEG_LENGTH_IND ] = _value[ END_LENGTH_IND ] = hyp->GetLength( &aMesh, aShape );
228 ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
229 _hypType = LOCAL_LENGTH;
230 aStatus = SMESH_Hypothesis::HYP_OK;
233 aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
235 return ( _hypType != NONE );
238 static bool computeParamByFunc(Adaptor3d_Curve& C3d, double first, double last,
239 double length, bool theReverse,
240 int nbSeg, Function& func,
241 list<double>& theParams)
244 //OSD::SetSignal( true );
249 MESSAGE( "computeParamByFunc" );
251 int nbPnt = 1 + nbSeg;
252 vector<double> x(nbPnt, 0.);
254 if( !buildDistribution( func, 0.0, 1.0, nbSeg, x, 1E-4 ) )
257 MESSAGE( "Points:\n" );
259 for( int i=0; i<=nbSeg; i++ )
261 sprintf( buf, "%f\n", float(x[i] ) );
267 // apply parameters in range [0,1] to the space of the curve
268 double prevU = first;
275 for( int i = 1; i < nbSeg; i++ )
277 double curvLength = length * (x[i] - x[i-1]) * sign;
278 GCPnts_AbscissaPoint Discret( C3d, curvLength, prevU );
279 if ( !Discret.IsDone() )
281 double U = Discret.Parameter();
282 if ( U > first && U < last )
283 theParams.push_back( U );
292 //================================================================================
294 * \brief adjust internal node parameters so that the last segment length == an
295 * \param a1 - the first segment length
296 * \param an - the last segment length
297 * \param U1 - the first edge parameter
298 * \param Un - the last edge parameter
299 * \param length - the edge length
300 * \param C3d - the edge curve
301 * \param theParams - internal node parameters to adjust
302 * \param adjustNeighbors2an - to adjust length of segments next to the last one
303 * and not to remove parameters
305 //================================================================================
307 static void compensateError(double a1, double an,
308 double U1, double Un,
310 Adaptor3d_Curve& C3d,
311 list<double> & theParams,
312 bool adjustNeighbors2an = false)
314 int i, nPar = theParams.size();
315 if ( a1 + an < length && nPar > 1 )
317 bool reverse = ( U1 > Un );
318 GCPnts_AbscissaPoint Discret(C3d, reverse ? an : -an, Un);
319 if ( !Discret.IsDone() )
321 double Utgt = Discret.Parameter(); // target value of the last parameter
322 list<double>::reverse_iterator itU = theParams.rbegin();
323 double Ul = *itU++; // real value of the last parameter
324 double dUn = Utgt - Ul; // parametric error of <an>
325 if ( Abs(dUn) <= Precision::Confusion() )
327 double dU = Abs( Ul - *itU ); // parametric length of the last but one segment
328 if ( adjustNeighbors2an || Abs(dUn) < 0.5 * dU ) { // last segment is a bit shorter than it should
329 // move the last parameter to the edge beginning
331 else { // last segment is much shorter than it should -> remove the last param and
332 theParams.pop_back(); nPar--; // move the rest points toward the edge end
333 dUn = Utgt - theParams.back();
336 double q = dUn / ( nPar - 1 );
337 if ( !adjustNeighbors2an ) {
338 for ( itU = theParams.rbegin(), i = 1; i < nPar; itU++, i++ ) {
344 theParams.back() += dUn;
345 double sign = reverse ? -1 : 1;
346 double prevU = theParams.back();
347 itU = theParams.rbegin();
348 for ( ++itU, i = 2; i < nPar; ++itU, i++ ) {
349 double newU = *itU + dUn;
350 if ( newU*sign < prevU*sign ) {
354 else { // set U between prevU and next valid param
355 list<double>::reverse_iterator itU2 = itU;
358 while ( (*itU2)*sign > prevU*sign ) {
361 dU = ( *itU2 - prevU ) / nb;
362 while ( itU != itU2 ) {
372 //================================================================================
374 * \brief Class used to clean mesh on edges when 0D hyp modified.
375 * Common approach doesn't work when 0D algo is missing because the 0D hyp is
376 * considered as not participating in computation whereas it is used by 1D algo.
378 //================================================================================
380 // struct VertexEventListener : public SMESH_subMeshEventListener
382 // VertexEventListener():SMESH_subMeshEventListener(0) // won't be deleted by submesh
385 // * \brief Clean mesh on edges
386 // * \param event - algo_event or compute_event itself (of SMESH_subMesh)
387 // * \param eventType - ALGO_EVENT or COMPUTE_EVENT (of SMESH_subMesh)
388 // * \param subMesh - the submesh where the event occures
390 // void ProcessEvent(const int event, const int eventType, SMESH_subMesh* subMesh,
391 // EventListenerData*, const SMESH_Hypothesis*)
393 // if ( eventType == SMESH_subMesh::ALGO_EVENT) // all algo events
395 // subMesh->ComputeStateEngine( SMESH_subMesh::MODIF_ALGO_STATE );
398 // }; // struct VertexEventListener
400 //=============================================================================
402 * \brief Sets event listener to vertex submeshes
403 * \param subMesh - submesh where algo is set
405 * This method is called when a submesh gets HYP_OK algo_state.
406 * After being set, event listener is notified on each event of a submesh.
408 //=============================================================================
410 void StdMeshers_Regular_1D::SetEventListener(SMESH_subMesh* subMesh)
412 // static VertexEventListener listener;
413 // SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
414 // while (smIt->more()) {
415 // subMesh->SetEventListener( &listener, 0, smIt->next() );
417 StdMeshers_Propagation::SetPropagationMgr( subMesh );
420 //=============================================================================
423 * \param subMesh - restored submesh
425 * This method is called only if a submesh has HYP_OK algo_state.
427 //=============================================================================
429 void StdMeshers_Regular_1D::SubmeshRestored(SMESH_subMesh* subMesh)
433 //=============================================================================
435 * \brief Return StdMeshers_SegmentLengthAroundVertex assigned to vertex
437 //=============================================================================
439 const StdMeshers_SegmentLengthAroundVertex*
440 StdMeshers_Regular_1D::getVertexHyp(SMESH_Mesh & theMesh,
441 const TopoDS_Vertex & theV)
443 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName("SegmentAroundVertex_0D"));
444 if ( const SMESH_Hypothesis * h = theMesh.GetHypothesis( theV, filter, true ))
446 SMESH_Algo* algo = const_cast< SMESH_Algo* >( static_cast< const SMESH_Algo* > ( h ));
447 const list <const SMESHDS_Hypothesis *> & hypList = algo->GetUsedHypothesis( theMesh, theV, 0 );
448 if ( !hypList.empty() && string("SegmentLengthAroundVertex") == hypList.front()->GetName() )
449 return static_cast<const StdMeshers_SegmentLengthAroundVertex*>( hypList.front() );
454 //================================================================================
456 * \brief Tune parameters to fit "SegmentLengthAroundVertex" hypothesis
457 * \param theC3d - wire curve
458 * \param theLength - curve length
459 * \param theParameters - internal nodes parameters to modify
460 * \param theVf - 1st vertex
461 * \param theVl - 2nd vertex
463 //================================================================================
465 void StdMeshers_Regular_1D::redistributeNearVertices (SMESH_Mesh & theMesh,
466 Adaptor3d_Curve & theC3d,
468 std::list< double > & theParameters,
469 const TopoDS_Vertex & theVf,
470 const TopoDS_Vertex & theVl)
472 double f = theC3d.FirstParameter(), l = theC3d.LastParameter();
473 int nPar = theParameters.size();
474 for ( int isEnd1 = 0; isEnd1 < 2; ++isEnd1 )
476 const TopoDS_Vertex & V = isEnd1 ? theVf : theVl;
477 const StdMeshers_SegmentLengthAroundVertex* hyp = getVertexHyp (theMesh, V );
479 double vertexLength = hyp->GetLength();
480 if ( vertexLength > theLength / 2.0 )
482 if ( isEnd1 ) { // to have a segment of interest at end of theParameters
483 theParameters.reverse();
486 if ( _hypType == NB_SEGMENTS )
488 compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
490 else if ( nPar <= 3 )
493 vertexLength = -vertexLength;
494 GCPnts_AbscissaPoint Discret(theC3d, vertexLength, l);
495 if ( Discret.IsDone() ) {
497 theParameters.push_back( Discret.Parameter());
499 double L = GCPnts_AbscissaPoint::Length( theC3d, theParameters.back(), l);
500 if ( vertexLength < L / 2.0 )
501 theParameters.push_back( Discret.Parameter());
503 compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
509 // recompute params between the last segment and a middle one.
510 // find size of a middle segment
511 int nHalf = ( nPar-1 ) / 2;
512 list< double >::reverse_iterator itU = theParameters.rbegin();
513 std::advance( itU, nHalf );
515 double Lm = GCPnts_AbscissaPoint::Length( theC3d, Um, *itU);
516 double L = GCPnts_AbscissaPoint::Length( theC3d, *itU, l);
517 StdMeshers_Regular_1D algo( *this );
518 algo._hypType = BEG_END_LENGTH;
519 algo._value[ BEG_LENGTH_IND ] = Lm;
520 algo._value[ END_LENGTH_IND ] = vertexLength;
521 double from = *itU, to = l;
523 std::swap( from, to );
524 std::swap( algo._value[ BEG_LENGTH_IND ], algo._value[ END_LENGTH_IND ]);
527 if ( algo.computeInternalParameters( theC3d, L, from, to, params, false ))
529 if ( isEnd1 ) params.reverse();
530 while ( 1 + nHalf-- )
531 theParameters.pop_back();
532 theParameters.splice( theParameters.end(), params );
536 compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
540 theParameters.reverse();
545 //=============================================================================
549 //=============================================================================
550 bool StdMeshers_Regular_1D::computeInternalParameters(Adaptor3d_Curve& theC3d,
554 list<double> & theParams,
555 const bool theReverse)
559 double f = theFirstU, l = theLastU;
567 if ( _hypType == LOCAL_LENGTH )
569 // Local Length hypothesis
570 double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
572 nbseg = 1; // degenerated edge
573 eltSize = theLength / nbseg;
577 // Number Of Segments hypothesis
578 int NbSegm = _ivalue[ NB_SEGMENTS_IND ];
579 if ( NbSegm < 1 ) return false;
580 if ( NbSegm == 1 ) return true;
582 switch (_ivalue[ DISTR_TYPE_IND ])
584 case StdMeshers_NumberOfSegments::DT_Scale:
586 double scale = _value[ SCALE_FACTOR_IND ];
588 if (fabs(scale - 1.0) < Precision::Confusion()) {
589 // special case to avoid division on zero
590 for (int i = 1; i < NbSegm; i++) {
591 double param = f + (l - f) * i / NbSegm;
592 theParams.push_back( param );
595 // general case of scale distribution
599 double alpha = pow(scale, 1.0 / (NbSegm - 1));
600 double factor = (l - f) / (1.0 - pow(alpha, NbSegm));
602 for (int i = 1; i < NbSegm; i++) {
603 double param = f + factor * (1.0 - pow(alpha, i));
604 theParams.push_back( param );
610 case StdMeshers_NumberOfSegments::DT_TabFunc:
612 FunctionTable func(_vvalue[ TAB_FUNC_IND ], _ivalue[ CONV_MODE_IND ]);
613 return computeParamByFunc(theC3d, f, l, theLength, theReverse,
614 _ivalue[ NB_SEGMENTS_IND ], func,
618 case StdMeshers_NumberOfSegments::DT_ExprFunc:
620 FunctionExpr func(_svalue[ EXPR_FUNC_IND ].c_str(), _ivalue[ CONV_MODE_IND ]);
621 return computeParamByFunc(theC3d, f, l, theLength, theReverse,
622 _ivalue[ NB_SEGMENTS_IND ], func,
626 case StdMeshers_NumberOfSegments::DT_Regular:
627 eltSize = theLength / _ivalue[ NB_SEGMENTS_IND ];
633 GCPnts_UniformAbscissa Discret(theC3d, eltSize, f, l);
634 if ( !Discret.IsDone() )
635 return error( "GCPnts_UniformAbscissa failed");
637 int NbPoints = Discret.NbPoints();
638 for ( int i = 2; i < NbPoints; i++ )
640 double param = Discret.Parameter(i);
641 theParams.push_back( param );
643 compensateError( eltSize, eltSize, f, l, theLength, theC3d, theParams ); // for PAL9899
647 case BEG_END_LENGTH: {
649 // geometric progression: SUM(n) = ( a1 - an * q ) / ( 1 - q ) = theLength
651 double a1 = _value[ BEG_LENGTH_IND ];
652 double an = _value[ END_LENGTH_IND ];
653 double q = ( theLength - a1 ) / ( theLength - an );
655 double U1 = theReverse ? l : f;
656 double Un = theReverse ? f : l;
658 double eltSize = theReverse ? -a1 : a1;
660 // computes a point on a curve <theC3d> at the distance <eltSize>
661 // from the point of parameter <param>.
662 GCPnts_AbscissaPoint Discret( theC3d, eltSize, param );
663 if ( !Discret.IsDone() ) break;
664 param = Discret.Parameter();
665 if ( f < param && param < l )
666 theParams.push_back( param );
671 compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
672 if (theReverse) theParams.reverse(); // NPAL18025
676 case ARITHMETIC_1D: {
678 // arithmetic progression: SUM(n) = ( an - a1 + q ) * ( a1 + an ) / ( 2 * q ) = theLength
680 double a1 = _value[ BEG_LENGTH_IND ];
681 double an = _value[ END_LENGTH_IND ];
683 double q = ( an - a1 ) / ( 2 *theLength/( a1 + an ) - 1 );
684 int n = int( 1 + ( an - a1 ) / q );
686 double U1 = theReverse ? l : f;
687 double Un = theReverse ? f : l;
694 while ( n-- > 0 && eltSize * ( Un - U1 ) > 0 ) {
695 // computes a point on a curve <theC3d> at the distance <eltSize>
696 // from the point of parameter <param>.
697 GCPnts_AbscissaPoint Discret( theC3d, eltSize, param );
698 if ( !Discret.IsDone() ) break;
699 param = Discret.Parameter();
700 if ( param > f && param < l )
701 theParams.push_back( param );
706 compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
707 if (theReverse) theParams.reverse(); // NPAL18025
714 GCPnts_UniformDeflection Discret(theC3d, _value[ DEFLECTION_IND ], f, l, true);
715 if ( !Discret.IsDone() )
718 int NbPoints = Discret.NbPoints();
719 for ( int i = 2; i < NbPoints; i++ )
721 double param = Discret.Parameter(i);
722 theParams.push_back( param );
733 //=============================================================================
737 //=============================================================================
739 bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
741 if ( _hypType == NONE )
744 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
746 const TopoDS_Edge & EE = TopoDS::Edge(aShape);
747 TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
748 int shapeID = meshDS->ShapeToIndex( E );
751 Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
753 TopoDS_Vertex VFirst, VLast;
754 TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l
756 ASSERT(!VFirst.IsNull());
757 ASSERT(!VLast.IsNull());
758 const SMDS_MeshNode * idFirst = SMESH_Algo::VertexNode( VFirst, meshDS );
759 const SMDS_MeshNode * idLast = SMESH_Algo::VertexNode( VLast, meshDS );
760 if (!idFirst || !idLast)
761 return error( COMPERR_BAD_INPUT_MESH, "No node on vertex");
765 list< double > params;
766 bool reversed = false;
767 if ( !_mainEdge.IsNull() )
768 reversed = ( _mainEdge.Orientation() == TopAbs_REVERSED );
770 BRepAdaptor_Curve C3d( E );
771 double length = EdgeLength( E );
772 if ( ! computeInternalParameters( C3d, length, f, l, params, reversed )) {
775 redistributeNearVertices( aMesh, C3d, length, params, VFirst, VLast );
777 // edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
778 // only internal nodes receive an edge position with param on curve
780 const SMDS_MeshNode * idPrev = idFirst;
794 for (list<double>::iterator itU = params.begin(); itU != params.end(); itU++) {
796 gp_Pnt P = Curve->Value(param);
798 //Add the Node in the DataStructure
799 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
800 meshDS->SetNodeOnEdge(node, shapeID, param);
803 // create medium node
804 double prm = ( parPrev + param )/2;
805 gp_Pnt PM = Curve->Value(prm);
806 SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
807 meshDS->SetNodeOnEdge(NM, shapeID, prm);
808 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node, NM);
809 meshDS->SetMeshElementOnShape(edge, shapeID);
812 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
813 meshDS->SetMeshElementOnShape(edge, shapeID);
820 double prm = ( parPrev + parLast )/2;
821 gp_Pnt PM = Curve->Value(prm);
822 SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
823 meshDS->SetNodeOnEdge(NM, shapeID, prm);
824 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast, NM);
825 meshDS->SetMeshElementOnShape(edge, shapeID);
828 SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast);
829 meshDS->SetMeshElementOnShape(edge, shapeID);
834 //MESSAGE("************* Degenerated edge! *****************");
836 // Edge is a degenerated Edge : We put n = 5 points on the edge.
837 const int NbPoints = 5;
838 BRep_Tool::Range( E, f, l ); // PAL15185
839 double du = (l - f) / (NbPoints - 1);
841 gp_Pnt P = BRep_Tool::Pnt(VFirst);
843 const SMDS_MeshNode * idPrev = idFirst;
844 for (int i = 2; i < NbPoints; i++) {
845 double param = f + (i - 1) * du;
846 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
848 // create medium node
849 double prm = param - du/2.;
850 SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
851 meshDS->SetNodeOnEdge(NM, shapeID, prm);
852 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node, NM);
853 meshDS->SetMeshElementOnShape(edge, shapeID);
856 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
857 meshDS->SetMeshElementOnShape(edge, shapeID);
859 meshDS->SetNodeOnEdge(node, shapeID, param);
863 // create medium node
864 double prm = l - du/2.;
865 SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
866 meshDS->SetNodeOnEdge(NM, shapeID, prm);
867 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast, NM);
868 meshDS->SetMeshElementOnShape(edge, shapeID);
871 SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast);
872 meshDS->SetMeshElementOnShape(edge, shapeID);
878 //=============================================================================
880 * See comments in SMESH_Algo.cxx
882 //=============================================================================
884 const list <const SMESHDS_Hypothesis *> &
885 StdMeshers_Regular_1D::GetUsedHypothesis(SMESH_Mesh & aMesh,
886 const TopoDS_Shape & aShape,
887 const bool ignoreAuxiliary)
889 _usedHypList.clear();
892 SMESH_HypoFilter auxiliaryFilter, compatibleFilter;
893 auxiliaryFilter.Init( SMESH_HypoFilter::IsAuxiliary() );
894 const bool ignoreAux = true;
895 InitCompatibleHypoFilter( compatibleFilter, ignoreAux );
897 // get non-auxiliary assigned to aShape
898 int nbHyp = aMesh.GetHypotheses( aShape, compatibleFilter, _usedHypList, false );
900 if (nbHyp == 0 && aShape.ShapeType() == TopAbs_EDGE)
902 // Check, if propagated from some other edge
903 _mainEdge = StdMeshers_Propagation::GetPropagationSource( aMesh, aShape );
904 if ( !_mainEdge.IsNull() )
906 // Propagation of 1D hypothesis from <aMainEdge> on this edge;
907 // get non-auxiliary assigned to _mainEdge
908 nbHyp = aMesh.GetHypotheses( _mainEdge, compatibleFilter, _usedHypList, true );
912 if (nbHyp == 0) // nothing propagated nor assigned to aShape
914 SMESH_Algo::GetUsedHypothesis( aMesh, aShape, ignoreAuxiliary );
915 nbHyp = _usedHypList.size();
919 // get auxiliary hyps from aShape
920 aMesh.GetHypotheses( aShape, auxiliaryFilter, _usedHypList, true );
922 if ( nbHyp > 1 && ignoreAuxiliary )
923 _usedHypList.clear(); //only one compatible non-auxiliary hypothesis allowed