Salome HOME
Update copyright
[modules/smesh.git] / src / SMESH / SMESH_Algo.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESH : implementaion of SMESH idl descriptions
24 //  File   : SMESH_Algo.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //
28 #include "SMESH_Algo.hxx"
29 #include "SMESH_Comment.hxx"
30 #include "SMESH_Gen.hxx"
31 #include "SMESH_Mesh.hxx"
32 #include "SMESH_HypoFilter.hxx"
33 #include "SMDS_FacePosition.hxx"
34 #include "SMDS_EdgePosition.hxx"
35 #include "SMDS_MeshElement.hxx"
36 #include "SMDS_MeshNode.hxx"
37 #include "SMESHDS_Mesh.hxx"
38 #include "SMESHDS_SubMesh.hxx"
39
40 #include <BRepAdaptor_Curve.hxx>
41 #include <BRepLProp.hxx>
42 #include <BRep_Tool.hxx>
43 #include <GCPnts_AbscissaPoint.hxx>
44 #include <GeomAdaptor_Curve.hxx>
45 #include <Geom_Surface.hxx>
46 #include <TopExp.hxx>
47 #include <TopLoc_Location.hxx>
48 #include <TopTools_ListIteratorOfListOfShape.hxx>
49 #include <TopTools_ListOfShape.hxx>
50 #include <TopoDS.hxx>
51 #include <TopoDS_Edge.hxx>
52 #include <TopoDS_Face.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <gp_Pnt.hxx>
55 #include <gp_Pnt2d.hxx>
56 #include <gp_Vec.hxx>
57
58 #include <Standard_ErrorHandler.hxx>
59 #include <Standard_Failure.hxx>
60
61 #include "utilities.h"
62
63 #include <algorithm>
64 #include <limits>
65
66 using namespace std;
67
68 //=============================================================================
69 /*!
70  *  
71  */
72 //=============================================================================
73
74 SMESH_Algo::SMESH_Algo (int hypId, int studyId, SMESH_Gen * gen)
75   : SMESH_Hypothesis(hypId, studyId, gen)
76 {
77   gen->_mapAlgo[hypId] = this;
78
79   _onlyUnaryInput = _requireDescretBoundary = _requireShape = true;
80   _quadraticMesh = _supportSubmeshes = false;
81   _error = COMPERR_OK;
82 }
83
84 //=============================================================================
85 /*!
86  *  
87  */
88 //=============================================================================
89
90 SMESH_Algo::~SMESH_Algo()
91 {
92 }
93
94 //=============================================================================
95 /*!
96  * Usually an algoritm has nothing to save
97  */
98 //=============================================================================
99
100 ostream & SMESH_Algo::SaveTo(ostream & save) { return save; }
101 istream & SMESH_Algo::LoadFrom(istream & load) { return load; }
102
103 //=============================================================================
104 /*!
105  *  
106  */
107 //=============================================================================
108
109 const vector < string > &SMESH_Algo::GetCompatibleHypothesis()
110 {
111   return _compatibleHypothesis;
112 }
113
114 //=============================================================================
115 /*!
116  *  List the hypothesis used by the algorithm associated to the shape.
117  *  Hypothesis associated to father shape -are- taken into account (see
118  *  GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
119  *  the algorithm. This method could be surcharged by specific algorithms, in 
120  *  case of several hypothesis simultaneously applicable.
121  */
122 //=============================================================================
123
124 const list <const SMESHDS_Hypothesis *> &
125 SMESH_Algo::GetUsedHypothesis(SMESH_Mesh &         aMesh,
126                               const TopoDS_Shape & aShape,
127                               const bool           ignoreAuxiliary)
128 {
129   _usedHypList.clear();
130   SMESH_HypoFilter filter;
131   if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
132   {
133     aMesh.GetHypotheses( aShape, filter, _usedHypList, true );
134     if ( ignoreAuxiliary && _usedHypList.size() > 1 )
135       _usedHypList.clear(); //only one compatible hypothesis allowed
136   }
137   return _usedHypList;
138 }
139
140 //=============================================================================
141 /*!
142  *  List the relevant hypothesis associated to the shape. Relevant hypothesis
143  *  have a name (type) listed in the algorithm. Hypothesis associated to
144  *  father shape -are not- taken into account (see GetUsedHypothesis)
145  */
146 //=============================================================================
147
148 const list<const SMESHDS_Hypothesis *> &
149 SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh &         aMesh,
150                                  const TopoDS_Shape & aShape,
151                                  const bool           ignoreAuxiliary)
152 {
153   _appliedHypList.clear();
154   SMESH_HypoFilter filter;
155   if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
156     aMesh.GetHypotheses( aShape, filter, _appliedHypList, false );
157
158   return _appliedHypList;
159 }
160
161 //=============================================================================
162 /*!
163  *  Compute length of an edge
164  */
165 //=============================================================================
166
167 double SMESH_Algo::EdgeLength(const TopoDS_Edge & E)
168 {
169   double UMin = 0, UMax = 0;
170   if (BRep_Tool::Degenerated(E))
171     return 0;
172   TopLoc_Location L;
173   Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
174   GeomAdaptor_Curve AdaptCurve(C);
175   double length = GCPnts_AbscissaPoint::Length(AdaptCurve, UMin, UMax);
176   return length;
177 }
178
179 //================================================================================
180 /*!
181  * \brief Calculate normal of a mesh face
182  */
183 //================================================================================
184
185 bool SMESH_Algo::FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized)
186 {
187   if ( !F || F->GetType() != SMDSAbs_Face )
188     return false;
189
190   normal.SetCoord(0,0,0);
191   int nbNodes = F->IsQuadratic() ? F->NbNodes()/2 : F->NbNodes();
192   for ( int i = 0; i < nbNodes-2; ++i )
193   {
194     gp_XYZ p[3];
195     for ( int n = 0; n < 3; ++n )
196     {
197       const SMDS_MeshNode* node = F->GetNode( i + n );
198       p[n].SetCoord( node->X(), node->Y(), node->Z() );
199     }
200     normal += ( p[2] - p[1] ) ^ ( p[0] - p[1] );
201   }
202   double size2 = normal.SquareModulus();
203   bool ok = ( size2 > numeric_limits<double>::min() * numeric_limits<double>::min());
204   if ( normalized && ok )
205     normal /= sqrt( size2 );
206
207   return ok;
208 }
209
210 //================================================================================
211 /*!
212  * \brief Find out elements orientation on a geometrical face
213  * \param theFace - The face correctly oriented in the shape being meshed
214  * \param theMeshDS - The mesh data structure
215  * \retval bool - true if the face normal and the normal of first element
216  *                in the correspoding submesh point in different directions
217  */
218 //================================================================================
219
220 bool SMESH_Algo::IsReversedSubMesh (const TopoDS_Face&  theFace,
221                                     SMESHDS_Mesh*       theMeshDS)
222 {
223   if ( theFace.IsNull() || !theMeshDS )
224     return false;
225
226   // find out orientation of a meshed face
227   int faceID = theMeshDS->ShapeToIndex( theFace );
228   TopoDS_Shape aMeshedFace = theMeshDS->IndexToShape( faceID );
229   bool isReversed = ( theFace.Orientation() != aMeshedFace.Orientation() );
230
231   const SMESHDS_SubMesh * aSubMeshDSFace = theMeshDS->MeshElements( faceID );
232   if ( !aSubMeshDSFace )
233     return isReversed;
234
235   // find element with node located on face and get its normal
236   const SMDS_FacePosition* facePos = 0;
237   int vertexID = 0;
238   gp_Pnt nPnt[3];
239   gp_Vec Ne;
240   bool normalOK = false;
241   SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
242   while ( iteratorElem->more() ) // loop on elements on theFace
243   {
244     const SMDS_MeshElement* elem = iteratorElem->next();
245     if ( elem && elem->NbNodes() > 2 ) {
246       SMDS_ElemIteratorPtr nodesIt = elem->nodesIterator();
247       const SMDS_FacePosition* fPos = 0;
248       int i = 0, vID = 0;
249       while ( nodesIt->more() ) { // loop on nodes
250         const SMDS_MeshNode* node
251           = static_cast<const SMDS_MeshNode *>(nodesIt->next());
252         if ( i == 3 ) i = 2;
253         nPnt[ i++ ].SetCoord( node->X(), node->Y(), node->Z() );
254         // check position
255         const SMDS_PositionPtr& pos = node->GetPosition();
256         if ( !pos ) continue;
257         if ( pos->GetTypeOfPosition() == SMDS_TOP_FACE ) {
258           fPos = dynamic_cast< const SMDS_FacePosition* >( pos );
259         }
260         else if ( pos->GetTypeOfPosition() == SMDS_TOP_VERTEX ) {
261           vID = node->getshapeId();
262         }
263       }
264       if ( fPos || ( !normalOK && vID )) {
265         // compute normal
266         gp_Vec v01( nPnt[0], nPnt[1] ), v02( nPnt[0], nPnt[2] );
267         if ( v01.SquareMagnitude() > RealSmall() &&
268              v02.SquareMagnitude() > RealSmall() )
269         {
270           Ne = v01 ^ v02;
271           normalOK = ( Ne.SquareMagnitude() > RealSmall() );
272         }
273         // we need position on theFace or at least on vertex
274         if ( normalOK ) {
275           vertexID = vID;
276           if ((facePos = fPos))
277             break;
278         }
279       }
280     }
281   }
282   if ( !normalOK )
283     return isReversed;
284
285   // node position on face
286   double u,v;
287   if ( facePos ) {
288     u = facePos->GetUParameter();
289     v = facePos->GetVParameter();
290   }
291   else if ( vertexID ) {
292     TopoDS_Shape V = theMeshDS->IndexToShape( vertexID );
293     if ( V.IsNull() || V.ShapeType() != TopAbs_VERTEX )
294       return isReversed;
295     gp_Pnt2d uv = BRep_Tool::Parameters( TopoDS::Vertex( V ), theFace );
296     u = uv.X();
297     v = uv.Y();
298   }
299   else
300   {
301     return isReversed;
302   }
303
304   // face normal at node position
305   TopLoc_Location loc;
306   Handle(Geom_Surface) surf = BRep_Tool::Surface( theFace, loc );
307   if ( surf.IsNull() || surf->Continuity() < GeomAbs_C1 ) return isReversed;
308   gp_Vec d1u, d1v;
309   surf->D1( u, v, nPnt[0], d1u, d1v );
310   gp_Vec Nf = (d1u ^ d1v).Transformed( loc );
311
312   if ( theFace.Orientation() == TopAbs_REVERSED )
313     Nf.Reverse();
314
315   return Ne * Nf < 0.;
316 }
317
318 //================================================================================
319 /*!
320  * \brief Just return false as the algorithm does not hold parameters values
321  */
322 //================================================================================
323
324 bool SMESH_Algo::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
325                                      const TopoDS_Shape& /*theShape*/)
326 {
327   return false;
328 }
329 bool SMESH_Algo::SetParametersByDefaults(const TDefaults& , const SMESH_Mesh*)
330 {
331   return false;
332 }
333 //================================================================================
334 /*!
335  * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
336  * \param theMesh - The mesh containing nodes
337  * \param theEdge - The geometrical edge of interest
338  * \param theParams - The resulting vector of sorted node parameters
339  * \retval bool - false if not all parameters are OK
340  */
341 //================================================================================
342
343 bool SMESH_Algo::GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh,
344                                     const TopoDS_Edge&  theEdge,
345                                     vector< double > &  theParams)
346 {
347   theParams.clear();
348
349   if ( !theMesh || theEdge.IsNull() )
350     return false;
351
352   SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge );
353   if ( !eSubMesh || !eSubMesh->GetElements()->more() )
354     return false; // edge is not meshed
355
356   //int nbEdgeNodes = 0;
357   set < double > paramSet;
358   if ( eSubMesh )
359   {
360     // loop on nodes of an edge: sort them by param on edge
361     SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes();
362     while ( nIt->more() )
363     {
364       const SMDS_MeshNode* node = nIt->next();
365       const SMDS_PositionPtr& pos = node->GetPosition();
366       if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE )
367         return false;
368       const SMDS_EdgePosition* epos =
369         static_cast<const SMDS_EdgePosition*>(node->GetPosition());
370       if ( !paramSet.insert( epos->GetUParameter() ).second )
371         return false; // equal parameters
372     }
373   }
374   // add vertex nodes params
375   TopoDS_Vertex V1,V2;
376   TopExp::Vertices( theEdge, V1, V2);
377   if ( VertexNode( V1, theMesh ) &&
378        !paramSet.insert( BRep_Tool::Parameter(V1,theEdge) ).second )
379     return false; // there are equal parameters
380   if ( VertexNode( V2, theMesh ) &&
381        !paramSet.insert( BRep_Tool::Parameter(V2,theEdge) ).second )
382     return false; // there are equal parameters
383
384   // fill the vector
385   theParams.resize( paramSet.size() );
386   set < double >::iterator   par    = paramSet.begin();
387   vector< double >::iterator vecPar = theParams.begin();
388   for ( ; par != paramSet.end(); ++par, ++vecPar )
389     *vecPar = *par;
390
391   return theParams.size() > 1;
392 }
393
394 //================================================================================
395 /*!
396  * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
397  * \param theMesh - The mesh containing nodes
398  * \param theEdge - The geometrical edge of interest
399  * \param theParams - The resulting vector of sorted node parameters
400  * \retval bool - false if not all parameters are OK
401  */
402 //================================================================================
403
404 bool SMESH_Algo::GetSortedNodesOnEdge(const SMESHDS_Mesh*                   theMesh,
405                                       const TopoDS_Edge&                    theEdge,
406                                       const bool                            ignoreMediumNodes,
407                                       map< double, const SMDS_MeshNode* > & theNodes)
408 {
409   theNodes.clear();
410
411   if ( !theMesh || theEdge.IsNull() )
412     return false;
413
414   SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge );
415   if ( !eSubMesh || !eSubMesh->GetElements()->more() )
416     return false; // edge is not meshed
417
418   int nbNodes = 0;
419   set < double > paramSet;
420   if ( eSubMesh )
421   {
422     // loop on nodes of an edge: sort them by param on edge
423     SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes();
424     while ( nIt->more() )
425     {
426       const SMDS_MeshNode* node = nIt->next();
427       if ( ignoreMediumNodes ) {
428         SMDS_ElemIteratorPtr elemIt = node->GetInverseElementIterator();
429         if ( elemIt->more() && elemIt->next()->IsMediumNode( node ))
430           continue;
431       }
432       const SMDS_PositionPtr& pos = node->GetPosition();
433       if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE )
434         return false;
435       const SMDS_EdgePosition* epos =
436         static_cast<const SMDS_EdgePosition*>(node->GetPosition());
437       theNodes.insert( make_pair( epos->GetUParameter(), node ));
438       //MESSAGE("U " << epos->GetUParameter() << " ID " << node->GetID());
439       ++nbNodes;
440     }
441   }
442   // add vertex nodes
443   TopoDS_Vertex v1, v2;
444   TopExp::Vertices(theEdge, v1, v2);
445   const SMDS_MeshNode* n1 = VertexNode( v1, (SMESHDS_Mesh*) theMesh );
446   const SMDS_MeshNode* n2 = VertexNode( v2, (SMESHDS_Mesh*) theMesh );
447   //MESSAGE("Vertices ID " << n1->GetID() << " " << n2->GetID());
448   Standard_Real f, l;
449   BRep_Tool::Range(theEdge, f, l);
450   if ( v1.Orientation() != TopAbs_FORWARD )
451     std::swap( f, l );
452   if ( n1 && ++nbNodes )
453     theNodes.insert( make_pair( f, n1 ));
454   if ( n2 && ++nbNodes )
455     theNodes.insert( make_pair( l, n2 ));
456
457   return theNodes.size() == nbNodes;
458 }
459
460 //================================================================================
461 /*!
462  * \brief Make filter recognize only compatible hypotheses
463  * \param theFilter - the filter to initialize
464  * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses
465  */
466 //================================================================================
467
468 bool SMESH_Algo::InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
469                                            const bool         ignoreAuxiliary) const
470 {
471   if ( !_compatibleHypothesis.empty() )
472   {
473     theFilter.Init( theFilter.HasName( _compatibleHypothesis[0] ));
474     for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
475       theFilter.Or( theFilter.HasName( _compatibleHypothesis[ i ] ));
476
477     if ( ignoreAuxiliary )
478       theFilter.AndNot( theFilter.IsAuxiliary() );
479
480     return true;
481   }
482   return false;
483 }
484
485 //================================================================================
486 /*!
487  * \brief Return continuity of two edges
488  * \param E1 - the 1st edge
489  * \param E2 - the 2nd edge
490  * \retval GeomAbs_Shape - regularity at the junction between E1 and E2
491  */
492 //================================================================================
493
494 GeomAbs_Shape SMESH_Algo::Continuity(TopoDS_Edge E1,
495                                      TopoDS_Edge E2)
496 {
497   //E1.Orientation(TopAbs_FORWARD), E2.Orientation(TopAbs_FORWARD); // avoid pb with internal edges
498   if (E1.Orientation() > TopAbs_REVERSED) // INTERNAL
499       E1.Orientation( TopAbs_FORWARD );
500   if (E2.Orientation() > TopAbs_REVERSED) // INTERNAL
501       E2.Orientation( TopAbs_FORWARD );
502   TopoDS_Vertex V = TopExp::LastVertex (E1, true);
503   if ( !V.IsSame( TopExp::FirstVertex(E2, true )))
504     if ( !TopExp::CommonVertex( E1, E2, V ))
505       return GeomAbs_C0;
506   Standard_Real u1 = BRep_Tool::Parameter( V, E1 );
507   Standard_Real u2 = BRep_Tool::Parameter( V, E2 );
508   BRepAdaptor_Curve C1( E1 ), C2( E2 );
509   Standard_Real tol = BRep_Tool::Tolerance( V );
510   Standard_Real angTol = 2e-3;
511   try {
512 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
513     OCC_CATCH_SIGNALS;
514 #endif
515     return BRepLProp::Continuity(C1, C2, u1, u2, tol, angTol);
516   }
517   catch (Standard_Failure) {
518   }
519   return GeomAbs_C0;
520 }
521
522 //================================================================================
523 /*!
524  * \brief Return the node built on a vertex
525  * \param V - the vertex
526  * \param meshDS - mesh
527  * \retval const SMDS_MeshNode* - found node or NULL
528  */
529 //================================================================================
530
531 const SMDS_MeshNode* SMESH_Algo::VertexNode(const TopoDS_Vertex& V,
532                                             const SMESHDS_Mesh*  meshDS)
533 {
534   if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(V) ) {
535     SMDS_NodeIteratorPtr nIt= sm->GetNodes();
536     if (nIt->more())
537       return nIt->next();
538   }
539   return 0;
540 }
541
542 //=======================================================================
543 //function : GetCommonNodes
544 //purpose  : Return nodes common to two elements
545 //=======================================================================
546
547 vector< const SMDS_MeshNode*> SMESH_Algo::GetCommonNodes(const SMDS_MeshElement* e1,
548                                                          const SMDS_MeshElement* e2)
549 {
550   vector< const SMDS_MeshNode*> common;
551   for ( int i = 0 ; i < e1->NbNodes(); ++i )
552     if ( e2->GetNodeIndex( e1->GetNode( i )) >= 0 )
553       common.push_back( e1->GetNode( i ));
554   return common;
555 }
556
557 //================================================================================
558 /*!
559  * \brief Sets event listener to submeshes if necessary
560  * \param subMesh - submesh where algo is set
561  * 
562  * After being set, event listener is notified on each event of a submesh.
563  * By default non listener is set
564  */
565 //================================================================================
566
567 void SMESH_Algo::SetEventListener(SMESH_subMesh* /*subMesh*/)
568 {
569 }
570
571 //================================================================================
572 /*!
573  * \brief Allow algo to do something after persistent restoration
574  * \param subMesh - restored submesh
575  *
576  * This method is called only if a submesh has HYP_OK algo_state.
577  */
578 //================================================================================
579
580 void SMESH_Algo::SubmeshRestored(SMESH_subMesh* /*subMesh*/)
581 {
582 }
583
584 //================================================================================
585 /*!
586  * \brief Computes mesh without geometry
587  * \param aMesh - the mesh
588  * \param aHelper - helper that must be used for adding elements to \aaMesh
589  * \retval bool - is a success
590  */
591 //================================================================================
592
593 bool SMESH_Algo::Compute(SMESH_Mesh & /*aMesh*/, SMESH_MesherHelper* /*aHelper*/)
594 {
595   return error( COMPERR_BAD_INPUT_MESH, "Mesh built on shape expected");
596 }
597
598 #ifdef WITH_SMESH_CANCEL_COMPUTE
599 void SMESH_Algo::CancelCompute()
600 {
601 }
602 #endif
603
604 //================================================================================
605 /*!
606  * \brief store error and comment and then return ( error == COMPERR_OK )
607  */
608 //================================================================================
609
610 bool SMESH_Algo::error(int error, const SMESH_Comment& comment)
611 {
612   _error   = error;
613   _comment = comment;
614   return ( error == COMPERR_OK );
615 }
616
617 //================================================================================
618 /*!
619  * \brief store error and return ( error == COMPERR_OK )
620  */
621 //================================================================================
622
623 bool SMESH_Algo::error(SMESH_ComputeErrorPtr error)
624 {
625   if ( error ) {
626     _error   = error->myName;
627     _comment = error->myComment;
628     _badInputElements = error->myBadElements;
629     return error->IsOK();
630   }
631   return true;
632 }
633
634 //================================================================================
635 /*!
636  * \brief return compute error
637  */
638 //================================================================================
639
640 SMESH_ComputeErrorPtr SMESH_Algo::GetComputeError() const
641 {
642   SMESH_ComputeErrorPtr err = SMESH_ComputeError::New( _error, _comment, this );
643   // hope this method is called by only SMESH_subMesh after this->Compute()
644   err->myBadElements.splice( err->myBadElements.end(),
645                              (list<const SMDS_MeshElement*>&) _badInputElements );
646   return err;
647 }
648
649 //================================================================================
650 /*!
651  * \brief initialize compute error
652  */
653 //================================================================================
654
655 void SMESH_Algo::InitComputeError()
656 {
657   _error = COMPERR_OK;
658   _comment.clear();
659   list<const SMDS_MeshElement*>::iterator elem = _badInputElements.begin();
660   for ( ; elem != _badInputElements.end(); ++elem )
661     if ( (*elem)->GetID() < 1 )
662       delete *elem;
663   _badInputElements.clear();
664 }
665
666 //================================================================================
667 /*!
668  * \brief store a bad input element preventing computation,
669  *        which may be a temporary one i.e. not residing the mesh,
670  *        then it will be deleted by InitComputeError()
671  */
672 //================================================================================
673
674 void SMESH_Algo::addBadInputElement(const SMDS_MeshElement* elem)
675 {
676   if ( elem )
677     _badInputElements.push_back( elem );
678 }