1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SMESH SMESH : implementaion of SMESH idl descriptions
21 // File : StdMeshers_RadialQuadrangle_1D2D.cxx
24 #include "StdMeshers_RadialQuadrangle_1D2D.hxx"
26 #include "StdMeshers_NumberOfLayers.hxx"
27 #include "StdMeshers_LayerDistribution.hxx"
28 #include "StdMeshers_Regular_1D.hxx"
29 #include "StdMeshers_NumberOfSegments.hxx"
31 #include "SMDS_MeshNode.hxx"
32 #include "SMESHDS_SubMesh.hxx"
33 #include "SMESH_Gen.hxx"
34 #include "SMESH_HypoFilter.hxx"
35 #include "SMESH_Mesh.hxx"
36 #include "SMESH_MesherHelper.hxx"
37 #include "SMESH_subMesh.hxx"
38 #include "SMESH_subMeshEventListener.hxx"
40 #include "utilities.h"
42 #include <BRepAdaptor_Curve.hxx>
43 #include <BRepBuilderAPI_MakeEdge.hxx>
44 #include <BRep_Tool.hxx>
45 #include <GeomAPI_ProjectPointOnSurf.hxx>
46 #include <Geom_Circle.hxx>
47 #include <Geom_Line.hxx>
48 #include <Geom_TrimmedCurve.hxx>
49 #include <TColgp_SequenceOfPnt.hxx>
50 #include <TColgp_SequenceOfPnt2d.hxx>
52 #include <TopExp_Explorer.hxx>
53 #include <TopTools_ListIteratorOfListOfShape.hxx>
59 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
60 #define gpXYZ(n) gp_XYZ(n->X(),n->Y(),n->Z())
63 //=======================================================================
64 //function : StdMeshers_RadialQuadrangle_1D2D
66 //=======================================================================
68 StdMeshers_RadialQuadrangle_1D2D::StdMeshers_RadialQuadrangle_1D2D(int hypId,
71 :SMESH_2D_Algo(hypId, studyId, gen)
73 _name = "RadialQuadrangle_1D2D";
74 _shapeType = (1 << TopAbs_FACE); // 1 bit per shape type
76 _compatibleHypothesis.push_back("LayerDistribution2D");
77 _compatibleHypothesis.push_back("NumberOfLayers2D");
78 _requireDiscreteBoundary = false;
79 _supportSubmeshes = true;
80 _neededLowerHyps[ 1 ] = true; // suppress warning on hiding a global 1D algo
83 myDistributionHypo = 0;
87 //================================================================================
91 //================================================================================
93 StdMeshers_RadialQuadrangle_1D2D::~StdMeshers_RadialQuadrangle_1D2D()
97 //=======================================================================
98 //function : CheckHypothesis
100 //=======================================================================
102 bool StdMeshers_RadialQuadrangle_1D2D::CheckHypothesis
104 const TopoDS_Shape& aShape,
105 SMESH_Hypothesis::Hypothesis_Status& aStatus)
109 myDistributionHypo = 0;
111 list <const SMESHDS_Hypothesis * >::const_iterator itl;
113 const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape);
114 if ( hyps.size() == 0 ) {
115 aStatus = SMESH_Hypothesis::HYP_OK;
116 return true; // can work with no hypothesis
119 if ( hyps.size() > 1 ) {
120 aStatus = SMESH_Hypothesis::HYP_ALREADY_EXIST;
124 const SMESHDS_Hypothesis *theHyp = hyps.front();
126 string hypName = theHyp->GetName();
128 if (hypName == "NumberOfLayers2D") {
129 myNbLayerHypo = static_cast<const StdMeshers_NumberOfLayers *>(theHyp);
130 aStatus = SMESH_Hypothesis::HYP_OK;
133 if (hypName == "LayerDistribution2D") {
134 myDistributionHypo = static_cast<const StdMeshers_LayerDistribution *>(theHyp);
135 aStatus = SMESH_Hypothesis::HYP_OK;
138 aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
144 // ------------------------------------------------------------------------------
146 * \brief Listener used to mark edges meshed by StdMeshers_RadialQuadrangle_1D2D
148 class TEdgeMarker : public SMESH_subMeshEventListener
150 TEdgeMarker(): SMESH_subMeshEventListener(/*isDeletable=*/false,
151 "StdMeshers_RadialQuadrangle_1D2D::TEdgeMarker") {}
153 //!< Return static listener
154 static SMESH_subMeshEventListener* getListener()
156 static TEdgeMarker theEdgeMarker;
157 return &theEdgeMarker;
159 //! Clear face sumbesh if something happens on edges
160 void ProcessEvent(const int event,
162 SMESH_subMesh* edgeSubMesh,
163 EventListenerData* data,
164 const SMESH_Hypothesis* /*hyp*/)
166 if ( data && !data->mySubMeshes.empty() && eventType == SMESH_subMesh::ALGO_EVENT)
168 ASSERT( data->mySubMeshes.front() != edgeSubMesh );
169 SMESH_subMesh* faceSubMesh = data->mySubMeshes.front();
170 faceSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
175 // ------------------------------------------------------------------------------
177 * \brief Mark an edge as computed by StdMeshers_RadialQuadrangle_1D2D
179 void markEdgeAsComputedByMe(const TopoDS_Edge& edge, SMESH_subMesh* faceSubMesh)
181 if ( SMESH_subMesh* edgeSM = faceSubMesh->GetFather()->GetSubMeshContaining( edge ))
183 if ( !edgeSM->GetEventListenerData( TEdgeMarker::getListener() ))
184 faceSubMesh->SetEventListener( TEdgeMarker::getListener(),
185 SMESH_subMeshEventListenerData::MakeData(faceSubMesh),
189 // ------------------------------------------------------------------------------
191 * \brief Return true if a radial edge was meshed with StdMeshers_RadialQuadrangle_1D2D with
192 * the same radial distribution
194 // bool isEdgeCompatiballyMeshed(const TopoDS_Edge& edge, SMESH_subMesh* faceSubMesh)
196 // if ( SMESH_subMesh* edgeSM = faceSubMesh->GetFather()->GetSubMeshContaining( edge ))
198 // if ( SMESH_subMeshEventListenerData* otherFaceData =
199 // edgeSM->GetEventListenerData( TEdgeMarker::getListener() ))
201 // // compare hypothesis aplied to two disk faces sharing radial edges
202 // SMESH_Mesh& mesh = *faceSubMesh->GetFather();
203 // SMESH_Algo* radialQuadAlgo = mesh.GetGen()->GetAlgo(mesh, faceSubMesh->GetSubShape() );
204 // SMESH_subMesh* otherFaceSubMesh = otherFaceData->mySubMeshes.front();
205 // list <const SMESHDS_Hypothesis *> hyps1 =
206 // radialQuadAlgo->GetUsedHypothesis( mesh, faceSubMesh->GetSubShape());
207 // list <const SMESHDS_Hypothesis *> hyps2 =
208 // radialQuadAlgo->GetUsedHypothesis( mesh, otherFaceSubMesh->GetSubShape());
209 // if( hyps1.empty() && hyps2.empty() )
210 // return true; // defaul hyps
211 // if ( hyps1.size() != hyps2.size() )
213 // return *hyps1.front() == *hyps2.front();
219 //================================================================================
221 * \brief Return base curve of the edge and extremum parameters
223 //================================================================================
225 Handle(Geom_Curve) getCurve(const TopoDS_Edge& edge, double* f=0, double* l=0)
227 Handle(Geom_Curve) C;
228 if ( !edge.IsNull() )
230 double first = 0., last = 0.;
231 C = BRep_Tool::Curve(edge, first, last);
234 Handle(Geom_TrimmedCurve) tc = Handle(Geom_TrimmedCurve)::DownCast(C);
235 while( !tc.IsNull() ) {
236 C = tc->BasisCurve();
237 tc = Handle(Geom_TrimmedCurve)::DownCast(C);
246 //================================================================================
248 * \brief Return edges of the face
249 * \retval int - nb of edges
251 //================================================================================
253 int analyseFace(const TopoDS_Shape& face,
254 TopoDS_Edge& CircEdge,
255 TopoDS_Edge& LinEdge1,
256 TopoDS_Edge& LinEdge2)
258 CircEdge.Nullify(); LinEdge1.Nullify(); LinEdge2.Nullify();
261 for ( TopExp_Explorer exp( face, TopAbs_EDGE ); exp.More(); exp.Next(), ++nbe )
263 const TopoDS_Edge& E = TopoDS::Edge( exp.Current() );
265 Handle(Geom_Curve) C = getCurve(E,&f,&l);
268 if ( C->IsKind( STANDARD_TYPE(Geom_Circle)))
270 if ( CircEdge.IsNull() )
275 else if ( LinEdge1.IsNull() )
283 //================================================================================
285 * \brief Checks if the common vertex between LinEdge's lies inside the circle
287 * \param [in] CircEdge -
288 * \param [in] LinEdge1 -
289 * \param [in] LinEdge2 -
290 * \return bool - false if there are 3 EDGEs and the corner is outside
292 //================================================================================
294 bool isCornerInsideCircle(const TopoDS_Edge& CircEdge,
295 const TopoDS_Edge& LinEdge1,
296 const TopoDS_Edge& LinEdge2)
298 if ( !CircEdge.IsNull() &&
299 !LinEdge1.IsNull() &&
302 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast( getCurve( CircEdge ));
303 TopoDS_Vertex aCommonV;
304 if ( !aCirc.IsNull() &&
305 TopExp::CommonVertex( LinEdge1, LinEdge2, aCommonV ))
307 gp_Pnt aCommonP = BRep_Tool::Pnt( aCommonV );
308 gp_Pnt aCenter = aCirc->Location();
309 double dist = aCenter.Distance( aCommonP );
310 return dist < 0.1 * aCirc->Radius();
316 //================================================================================
317 //================================================================================
319 * \brief Class computing layers distribution using data of
320 * StdMeshers_LayerDistribution hypothesis
322 //================================================================================
323 //================================================================================
325 class TNodeDistributor: public StdMeshers_Regular_1D
327 list <const SMESHDS_Hypothesis *> myUsedHyps;
329 // -----------------------------------------------------------------------------
330 static TNodeDistributor* GetDistributor(SMESH_Mesh& aMesh)
332 const int myID = -1001;
333 TNodeDistributor* myHyp = dynamic_cast<TNodeDistributor*>( aMesh.GetHypothesis( myID ));
335 myHyp = new TNodeDistributor( myID, 0, aMesh.GetGen() );
338 // -----------------------------------------------------------------------------
339 //! Computes distribution of nodes on a straight line ending at pIn and pOut
340 bool Compute( vector< double > & positions,
344 const SMESH_Hypothesis* hyp1d)
346 if ( !hyp1d ) return error( "Invalid LayerDistribution hypothesis");
348 double len = pIn.Distance( pOut );
349 if ( len <= DBL_MIN ) return error("Too close points of inner and outer shells");
352 myUsedHyps.push_back( hyp1d );
354 TopoDS_Edge edge = BRepBuilderAPI_MakeEdge( pIn, pOut );
355 SMESH_Hypothesis::Hypothesis_Status aStatus;
356 if ( !StdMeshers_Regular_1D::CheckHypothesis( aMesh, edge, aStatus ))
357 return error( "StdMeshers_Regular_1D::CheckHypothesis() failed "
358 "with LayerDistribution hypothesis");
360 BRepAdaptor_Curve C3D(edge);
361 double f = C3D.FirstParameter(), l = C3D.LastParameter();
362 list< double > params;
363 if ( !StdMeshers_Regular_1D::computeInternalParameters( aMesh, C3D, len, f, l, params, false ))
364 return error("StdMeshers_Regular_1D failed to compute layers distribution");
367 positions.reserve( params.size() );
368 for (list<double>::iterator itU = params.begin(); itU != params.end(); itU++)
369 positions.push_back( *itU / len );
372 // -----------------------------------------------------------------------------
373 //! Make mesh on an adge using assigned 1d hyp or defaut nb of segments
374 bool ComputeCircularEdge(SMESH_Mesh& aMesh,
375 const TopoDS_Edge& anEdge)
377 _gen->Compute( aMesh, anEdge);
378 SMESH_subMesh *sm = aMesh.GetSubMesh(anEdge);
379 if ( sm->GetComputeState() != SMESH_subMesh::COMPUTE_OK)
381 // find any 1d hyp assigned (there can be a hyp w/o algo)
382 myUsedHyps = SMESH_Algo::GetUsedHypothesis(aMesh, anEdge, /*ignoreAux=*/true);
383 Hypothesis_Status aStatus;
384 if ( !StdMeshers_Regular_1D::CheckHypothesis( aMesh, anEdge, aStatus ))
386 // no valid 1d hyp assigned, use default nb of segments
387 _hypType = NB_SEGMENTS;
388 _ivalue[ DISTR_TYPE_IND ] = StdMeshers_NumberOfSegments::DT_Regular;
389 _ivalue[ NB_SEGMENTS_IND ] = _gen->GetDefaultNbSegments();
391 return StdMeshers_Regular_1D::Compute( aMesh, anEdge );
395 // -----------------------------------------------------------------------------
396 //! Make mesh on an adge using assigned 1d hyp or defaut nb of segments
397 bool EvaluateCircularEdge(SMESH_Mesh& aMesh,
398 const TopoDS_Edge& anEdge,
399 MapShapeNbElems& aResMap)
401 _gen->Evaluate( aMesh, anEdge, aResMap );
402 if ( aResMap.count( aMesh.GetSubMesh( anEdge )))
405 // find any 1d hyp assigned
406 myUsedHyps = SMESH_Algo::GetUsedHypothesis(aMesh, anEdge, /*ignoreAux=*/true);
407 Hypothesis_Status aStatus;
408 if ( !StdMeshers_Regular_1D::CheckHypothesis( aMesh, anEdge, aStatus ))
410 // no valid 1d hyp assigned, use default nb of segments
411 _hypType = NB_SEGMENTS;
412 _ivalue[ DISTR_TYPE_IND ] = StdMeshers_NumberOfSegments::DT_Regular;
413 _ivalue[ NB_SEGMENTS_IND ] = _gen->GetDefaultNbSegments();
415 return StdMeshers_Regular_1D::Evaluate( aMesh, anEdge, aResMap );
418 // -----------------------------------------------------------------------------
419 TNodeDistributor( int hypId, int studyId, SMESH_Gen* gen)
420 : StdMeshers_Regular_1D( hypId, studyId, gen)
423 // -----------------------------------------------------------------------------
424 virtual const list <const SMESHDS_Hypothesis *> &
425 GetUsedHypothesis(SMESH_Mesh &, const TopoDS_Shape &, const bool)
429 // -----------------------------------------------------------------------------
433 //=======================================================================
435 * \brief Allow algo to do something after persistent restoration
436 * \param subMesh - restored submesh
438 * call markEdgeAsComputedByMe()
440 //=======================================================================
442 void StdMeshers_RadialQuadrangle_1D2D::SubmeshRestored(SMESH_subMesh* faceSubMesh)
444 if ( !faceSubMesh->IsEmpty() )
446 TopoDS_Edge CircEdge, LinEdge1, LinEdge2;
447 analyseFace( faceSubMesh->GetSubShape(), CircEdge, LinEdge1, LinEdge2 );
448 if ( !CircEdge.IsNull() ) markEdgeAsComputedByMe( CircEdge, faceSubMesh );
449 if ( !LinEdge1.IsNull() ) markEdgeAsComputedByMe( LinEdge1, faceSubMesh );
450 if ( !LinEdge2.IsNull() ) markEdgeAsComputedByMe( LinEdge2, faceSubMesh );
454 //=======================================================================
457 //=======================================================================
459 bool StdMeshers_RadialQuadrangle_1D2D::Compute(SMESH_Mesh& aMesh,
460 const TopoDS_Shape& aShape)
462 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
464 myHelper = new SMESH_MesherHelper( aMesh );
465 // to delete helper at exit from Compute()
466 SMESHUtils::Deleter<SMESH_MesherHelper> helperDeleter( myHelper );
468 TNodeDistributor* algo1d = TNodeDistributor::GetDistributor(aMesh);
470 TopoDS_Edge CircEdge, LinEdge1, LinEdge2;
471 int nbe = analyseFace( aShape, CircEdge, LinEdge1, LinEdge2 );
472 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast( getCurve( CircEdge ));
473 if( nbe > 3 || nbe < 1 || aCirc.IsNull() )
474 return error("The face must be a full circle or a part of circle (i.e. the number "
475 "of edges is less or equal to 3 and one of them is a circle curve)");
478 // points for rotation
479 TColgp_SequenceOfPnt Points;
480 // angles for rotation
481 TColStd_SequenceOfReal Angles;
482 // Nodes1 and Nodes2 - nodes along radiuses
483 // CNodes - nodes on circle edge
484 vector< const SMDS_MeshNode* > Nodes1, Nodes2, CNodes;
486 // parameters edge nodes on face
487 TColgp_SequenceOfPnt2d Pnts2d1;
490 int faceID = meshDS->ShapeToIndex(aShape);
491 TopoDS_Face F = TopoDS::Face(aShape);
492 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
497 if (!algo1d->ComputeCircularEdge( aMesh, CircEdge ))
498 return error( algo1d->GetComputeError() );
499 map< double, const SMDS_MeshNode* > theNodes;
500 if ( !GetSortedNodesOnEdge(aMesh.GetMeshDS(),CircEdge,true,theNodes))
501 return error("Circular edge is incorrectly meshed");
503 myHelper->IsQuadraticSubMesh( aShape );
506 map< double, const SMDS_MeshNode* >::iterator itn = theNodes.begin();
507 const SMDS_MeshNode* NF = (*itn).second;
508 CNodes.push_back( (*itn).second );
509 double fang = (*itn).first;
510 if ( itn != theNodes.end() ) {
512 for(; itn != theNodes.end(); itn++ ) {
513 CNodes.push_back( (*itn).second );
514 double ang = (*itn).first - fang;
515 if( ang>M_PI ) ang = ang - 2.*M_PI;
516 if( ang<-M_PI ) ang = ang + 2.*M_PI;
517 Angles.Append( ang );
520 P1 = gp_Pnt( NF->X(), NF->Y(), NF->Z() );
521 P0 = aCirc->Location();
523 if ( !computeLayerPositions(P0,P1))
526 TopoDS_Vertex V1 = myHelper->IthVertex(0, CircEdge );
527 gp_Pnt2d p2dV = BRep_Tool::Parameters( V1, TopoDS::Face(aShape) );
529 NC = meshDS->AddNode(P0.X(), P0.Y(), P0.Z());
530 GeomAPI_ProjectPointOnSurf PPS(P0,S);
532 PPS.Parameters(1,U0,V0);
533 meshDS->SetNodeOnFace(NC, faceID, U0, V0);
534 PC = gp_Pnt2d(U0,V0);
537 gp_Vec2d aVec2d(PC,p2dV);
538 Nodes1.resize( myLayerPositions.size()+1 );
539 Nodes2.resize( myLayerPositions.size()+1 );
541 for ( ; i < myLayerPositions.size(); i++ ) {
542 gp_Pnt P( P0.X() + aVec.X()*myLayerPositions[i],
543 P0.Y() + aVec.Y()*myLayerPositions[i],
544 P0.Z() + aVec.Z()*myLayerPositions[i] );
546 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
549 double U = PC.X() + aVec2d.X()*myLayerPositions[i];
550 double V = PC.Y() + aVec2d.Y()*myLayerPositions[i];
551 meshDS->SetNodeOnFace( node, faceID, U, V );
552 Pnts2d1.Append(gp_Pnt2d(U,V));
554 Nodes1[Nodes1.size()-1] = NF;
555 Nodes2[Nodes1.size()-1] = NF;
557 else if(nbe==2 && LinEdge1.Orientation() != TopAbs_INTERNAL )
559 // one curve must be a half of circle and other curve must be
562 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast( getCurve( CircEdge, &fp, &lp ));
563 if( fabs(fabs(lp-fp)-M_PI) > Precision::Confusion() ) {
564 // not half of circle
565 return error(COMPERR_BAD_SHAPE);
567 Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast( getCurve( LinEdge1 ));
568 if( aLine.IsNull() ) {
569 // other curve not line
570 return error(COMPERR_BAD_SHAPE);
573 if ( !algo1d->ComputeCircularEdge( aMesh, CircEdge ))
574 return error( algo1d->GetComputeError() );
575 map< double, const SMDS_MeshNode* > theNodes;
576 if ( !GetSortedNodesOnEdge(aMesh.GetMeshDS(),CircEdge,true,theNodes) )
577 return error("Circular edge is incorrectly meshed");
579 myHelper->IsQuadraticSubMesh( aShape );
581 map< double, const SMDS_MeshNode* >::iterator itn = theNodes.begin();
583 CNodes.push_back( itn->second );
584 double fang = (*itn).first;
586 for(; itn != theNodes.end(); itn++ ) {
587 CNodes.push_back( (*itn).second );
588 double ang = (*itn).first - fang;
589 if( ang>M_PI ) ang = ang - 2.*M_PI;
590 if( ang<-M_PI ) ang = ang + 2.*M_PI;
591 Angles.Append( ang );
593 const SMDS_MeshNode* NF = theNodes.begin()->second;
594 const SMDS_MeshNode* NL = theNodes.rbegin()->second;
595 P1 = gp_Pnt( NF->X(), NF->Y(), NF->Z() );
596 gp_Pnt P2( NL->X(), NL->Y(), NL->Z() );
597 P0 = aCirc->Location();
599 bool linEdgeComputed;
600 if ( !computeLayerPositions(P0,P1,LinEdge1,&linEdgeComputed))
603 if ( linEdgeComputed )
605 if (!GetSortedNodesOnEdge(aMesh.GetMeshDS(),LinEdge1,true,theNodes))
606 return error("Invalid mesh on a straight edge");
608 Nodes1.resize( myLayerPositions.size()+1 );
609 Nodes2.resize( myLayerPositions.size()+1 );
610 vector< const SMDS_MeshNode* > *pNodes1 = &Nodes1, *pNodes2 = &Nodes2;
611 bool nodesFromP0ToP1 = ( theNodes.rbegin()->second == NF );
612 if ( !nodesFromP0ToP1 ) std::swap( pNodes1, pNodes2 );
614 map< double, const SMDS_MeshNode* >::reverse_iterator ritn = theNodes.rbegin();
615 itn = theNodes.begin();
616 for ( int i = Nodes1.size()-1; i > -1; ++itn, ++ritn, --i )
618 (*pNodes1)[i] = ritn->second;
619 (*pNodes2)[i] = itn->second;
620 Points.Prepend( gpXYZ( Nodes1[i]));
621 Pnts2d1.Prepend( myHelper->GetNodeUV( F, Nodes1[i]));
623 NC = const_cast<SMDS_MeshNode*>( itn->second );
624 Points.Remove( Nodes1.size() );
629 int edgeID = meshDS->ShapeToIndex(LinEdge1);
631 Handle(Geom_Curve) Crv = BRep_Tool::Curve(LinEdge1,fp,lp);
635 if( P1.Distance(Ptmp) > Precision::Confusion() )
637 // get UV points for edge
639 BRep_Tool::UVPoints( LinEdge1, TopoDS::Face(aShape), PF, PL );
640 PC = gp_Pnt2d( (PF.X()+PL.X())/2, (PF.Y()+PL.Y())/2 );
642 if(ori) V2d = gp_Vec2d(PC,PF);
643 else V2d = gp_Vec2d(PC,PL);
645 double cp = (fp+lp)/2;
646 double dp2 = (lp-fp)/2;
647 NC = meshDS->AddNode(P0.X(), P0.Y(), P0.Z());
648 meshDS->SetNodeOnEdge(NC, edgeID, cp);
649 Nodes1.resize( myLayerPositions.size()+1 );
650 Nodes2.resize( myLayerPositions.size()+1 );
652 for(; i<myLayerPositions.size(); i++) {
653 gp_Pnt P( P0.X() + aVec.X()*myLayerPositions[i],
654 P0.Y() + aVec.Y()*myLayerPositions[i],
655 P0.Z() + aVec.Z()*myLayerPositions[i] );
657 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
661 param = fp + dp2*(1-myLayerPositions[i]);
663 param = cp + dp2*myLayerPositions[i];
664 meshDS->SetNodeOnEdge(node, edgeID, param);
665 P = gp_Pnt( P0.X() - aVec.X()*myLayerPositions[i],
666 P0.Y() - aVec.Y()*myLayerPositions[i],
667 P0.Z() - aVec.Z()*myLayerPositions[i] );
668 node = meshDS->AddNode(P.X(), P.Y(), P.Z());
671 param = fp + dp2*(1-myLayerPositions[i]);
673 param = cp + dp2*myLayerPositions[i];
674 meshDS->SetNodeOnEdge(node, edgeID, param);
675 // parameters on face
676 gp_Pnt2d P2d( PC.X() + V2d.X()*myLayerPositions[i],
677 PC.Y() + V2d.Y()*myLayerPositions[i] );
680 Nodes1[ myLayerPositions.size() ] = NF;
681 Nodes2[ myLayerPositions.size() ] = NL;
682 // create 1D elements on edge
683 vector< const SMDS_MeshNode* > tmpNodes;
684 tmpNodes.resize(2*Nodes1.size()+1);
685 for(i=0; i<Nodes2.size(); i++)
686 tmpNodes[Nodes2.size()-i-1] = Nodes2[i];
687 tmpNodes[Nodes2.size()] = NC;
688 for(i=0; i<Nodes1.size(); i++)
689 tmpNodes[Nodes2.size()+1+i] = Nodes1[i];
690 for(i=1; i<tmpNodes.size(); i++) {
691 SMDS_MeshEdge* ME = myHelper->AddEdge( tmpNodes[i-1], tmpNodes[i] );
692 if(ME) meshDS->SetMeshElementOnShape(ME, edgeID);
694 markEdgeAsComputedByMe( LinEdge1, aMesh.GetSubMesh( F ));
697 else // nbe==3 or ( nbe==2 && linEdge is INTERNAL )
699 if (nbe==2 && LinEdge1.Orientation() == TopAbs_INTERNAL )
702 // one curve must be a part of circle and other curves must be
705 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast( getCurve( CircEdge ));
706 Handle(Geom_Line) aLine1 = Handle(Geom_Line )::DownCast( getCurve( LinEdge1 ));
707 Handle(Geom_Line) aLine2 = Handle(Geom_Line )::DownCast( getCurve( LinEdge2 ));
708 if ( aCirc.IsNull() || aLine1.IsNull() || aLine2.IsNull() )
709 return error(COMPERR_BAD_SHAPE);
710 if ( !isCornerInsideCircle( CircEdge, LinEdge1, LinEdge2 ))
711 return error(COMPERR_BAD_SHAPE);
713 if ( !algo1d->ComputeCircularEdge( aMesh, CircEdge ))
714 return error( algo1d->GetComputeError() );
715 map< double, const SMDS_MeshNode* > theNodes;
716 if ( !GetSortedNodesOnEdge( aMesh.GetMeshDS(), CircEdge, true, theNodes ))
717 return error("Circular edge is incorrectly meshed");
719 myHelper->IsQuadraticSubMesh( aShape );
721 const SMDS_MeshNode* NF = theNodes.begin()->second;
722 const SMDS_MeshNode* NL = theNodes.rbegin()->second;
724 CNodes.push_back( NF );
725 map< double, const SMDS_MeshNode* >::iterator itn = theNodes.begin();
726 double fang = (*itn).first;
728 for(; itn != theNodes.end(); itn++ ) {
729 CNodes.push_back( (*itn).second );
730 double ang = (*itn).first - fang;
731 if( ang>M_PI ) ang = ang - 2.*M_PI;
732 if( ang<-M_PI ) ang = ang + 2.*M_PI;
733 Angles.Append( ang );
735 P1 = gp_Pnt( NF->X(), NF->Y(), NF->Z() );
736 gp_Pnt P2( NL->X(), NL->Y(), NL->Z() );
737 P0 = aCirc->Location();
739 // make P1 belong to LinEdge1
740 TopoDS_Vertex V1 = myHelper->IthVertex( 0, LinEdge1 );
741 TopoDS_Vertex V2 = myHelper->IthVertex( 1, LinEdge1 );
742 gp_Pnt PE1 = BRep_Tool::Pnt(V1);
743 gp_Pnt PE2 = BRep_Tool::Pnt(V2);
744 if( ( P1.Distance(PE1) > Precision::Confusion() ) &&
745 ( P1.Distance(PE2) > Precision::Confusion() ) )
746 std::swap( LinEdge1, LinEdge2 );
748 bool linEdge1Computed, linEdge2Computed;
749 if ( !computeLayerPositions(P0,P1,LinEdge1,&linEdge1Computed))
752 Nodes1.resize( myLayerPositions.size()+1 );
753 Nodes2.resize( myLayerPositions.size()+1 );
755 // check that both linear edges have same hypotheses
756 if ( !computeLayerPositions(P0,P2,LinEdge2, &linEdge2Computed))
758 if ( Nodes1.size() != myLayerPositions.size()+1 )
759 return error("Different hypotheses apply to radial edges");
761 // find the central vertex
762 TopoDS_Vertex VC = V2;
763 if( ( P1.Distance(PE1) > Precision::Confusion() ) &&
764 ( P2.Distance(PE1) > Precision::Confusion() ) )
766 int vertID = meshDS->ShapeToIndex(VC);
769 if ( linEdge1Computed )
771 if (!GetSortedNodesOnEdge(aMesh.GetMeshDS(),LinEdge1,true,theNodes))
772 return error("Invalid mesh on a straight edge");
774 bool nodesFromP0ToP1 = ( theNodes.rbegin()->second == NF );
775 NC = const_cast<SMDS_MeshNode*>
776 ( nodesFromP0ToP1 ? theNodes.begin()->second : theNodes.rbegin()->second );
777 size_t i = 0, ir = Nodes1.size()-1;
778 size_t * pi = nodesFromP0ToP1 ? &i : &ir;
779 itn = theNodes.begin();
780 if ( nodesFromP0ToP1 ) ++itn;
781 for ( ; i < Nodes1.size(); ++i, --ir, ++itn )
783 Nodes1[*pi] = itn->second;
785 for ( i = 0; i < Nodes1.size()-1; ++i )
787 Points.Append( gpXYZ( Nodes1[i]));
788 Pnts2d1.Append( myHelper->GetNodeUV( F, Nodes1[i]));
793 int edgeID = meshDS->ShapeToIndex(LinEdge1);
796 Handle(Geom_Curve) Crv = BRep_Tool::Curve(LinEdge1,fp,lp);
797 gp_Pnt Ptmp = Crv->Value(fp);
799 if( P1.Distance(Ptmp) > Precision::Confusion() )
801 // get UV points for edge
803 BRep_Tool::UVPoints( LinEdge1, TopoDS::Face(aShape), PF, PL );
806 V2d = gp_Vec2d(PF,PL);
810 V2d = gp_Vec2d(PL,PF);
813 NC = const_cast<SMDS_MeshNode*>( VertexNode( VC, meshDS ));
816 NC = meshDS->AddNode(P0.X(), P0.Y(), P0.Z());
817 meshDS->SetNodeOnVertex(NC, vertID);
821 for ( ; i < myLayerPositions.size(); i++ ) {
822 gp_Pnt P( P0.X() + aVec.X()*myLayerPositions[i],
823 P0.Y() + aVec.Y()*myLayerPositions[i],
824 P0.Z() + aVec.Z()*myLayerPositions[i] );
826 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
830 param = fp + dp*(1-myLayerPositions[i]);
832 param = fp + dp*myLayerPositions[i];
833 meshDS->SetNodeOnEdge(node, edgeID, param);
834 // parameters on face
835 gp_Pnt2d P2d( PC.X() + V2d.X()*myLayerPositions[i],
836 PC.Y() + V2d.Y()*myLayerPositions[i] );
839 Nodes1[ myLayerPositions.size() ] = NF;
840 // create 1D elements on edge
841 SMDS_MeshEdge* ME = myHelper->AddEdge( NC, Nodes1[0] );
842 if(ME) meshDS->SetMeshElementOnShape(ME, edgeID);
843 for ( i = 1; i < Nodes1.size(); i++ ) {
844 ME = myHelper->AddEdge( Nodes1[i-1], Nodes1[i] );
845 if(ME) meshDS->SetMeshElementOnShape(ME, edgeID);
847 if ( nbe == 2 && LinEdge1.Orientation() == TopAbs_INTERNAL )
850 markEdgeAsComputedByMe( LinEdge1, aMesh.GetSubMesh( F ));
853 if ( linEdge2Computed )
855 if (!GetSortedNodesOnEdge(aMesh.GetMeshDS(),LinEdge2,true,theNodes))
856 return error("Invalid mesh on a straight edge");
858 bool nodesFromP0ToP2 = ( theNodes.rbegin()->second == NL );
859 size_t i = 0, ir = Nodes1.size()-1;
860 size_t * pi = nodesFromP0ToP2 ? &i : &ir;
861 itn = theNodes.begin();
862 if ( nodesFromP0ToP2 ) ++itn;
863 for ( ; i < Nodes2.size(); ++i, --ir, ++itn )
864 Nodes2[*pi] = itn->second;
868 int edgeID = meshDS->ShapeToIndex(LinEdge2);
869 gp_Vec aVec = gp_Vec(P0,P2);
871 Handle(Geom_Curve) Crv = BRep_Tool::Curve(LinEdge2,fp,lp);
872 gp_Pnt Ptmp = Crv->Value(fp);
874 if( P2.Distance(Ptmp) > Precision::Confusion() )
876 // get UV points for edge
878 BRep_Tool::UVPoints( LinEdge2, TopoDS::Face(aShape), PF, PL );
881 V2d = gp_Vec2d(PF,PL);
885 V2d = gp_Vec2d(PL,PF);
889 for ( size_t i = 0; i < myLayerPositions.size(); i++ ) {
890 gp_Pnt P( P0.X() + aVec.X()*myLayerPositions[i],
891 P0.Y() + aVec.Y()*myLayerPositions[i],
892 P0.Z() + aVec.Z()*myLayerPositions[i] );
893 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
897 param = fp + dp*(1-myLayerPositions[i]);
899 param = fp + dp*myLayerPositions[i];
900 meshDS->SetNodeOnEdge(node, edgeID, param);
901 // parameters on face
902 gp_Pnt2d P2d( PC.X() + V2d.X()*myLayerPositions[i],
903 PC.Y() + V2d.Y()*myLayerPositions[i] );
905 Nodes2[ myLayerPositions.size() ] = NL;
906 // create 1D elements on edge
907 SMDS_MeshEdge* ME = myHelper->AddEdge( NC, Nodes2[0] );
908 if ( ME ) meshDS->SetMeshElementOnShape(ME, edgeID);
909 for ( size_t i = 1; i < Nodes2.size(); i++ ) {
910 ME = myHelper->AddEdge( Nodes2[i-1], Nodes2[i] );
911 if(ME) meshDS->SetMeshElementOnShape(ME, edgeID);
914 markEdgeAsComputedByMe( LinEdge2, aMesh.GetSubMesh( F ));
916 markEdgeAsComputedByMe( CircEdge, aMesh.GetSubMesh( F ));
919 bool IsForward = ( CircEdge.Orientation()==TopAbs_FORWARD );
920 const double angleSign = ( F.Orientation() == TopAbs_REVERSED ? -1.0 : 1.0 );
922 // create nodes and mesh elements on face
923 // find axis of rotation
924 gp_Pnt P2 = gp_Pnt( CNodes[1]->X(), CNodes[1]->Y(), CNodes[1]->Z() );
927 gp_Vec Axis = Vec1.Crossed(Vec2);
930 //cout<<"Angles.Length() = "<<Angles.Length()<<" Points.Length() = "<<Points.Length()<<endl;
931 //cout<<"Nodes1.size() = "<<Nodes1.size()<<" Pnts2d1.Length() = "<<Pnts2d1.Length()<<endl;
932 for(; i<Angles.Length(); i++) {
933 vector< const SMDS_MeshNode* > tmpNodes;
935 gp_Ax1 theAxis(P0,gp_Dir(Axis));
936 aTrsf.SetRotation( theAxis, Angles.Value(i) );
938 aTrsf2d.SetRotation( PC, Angles.Value(i) * angleSign );
941 for(; j<=Points.Length(); j++) {
943 Points.Value(j).Coord( cx, cy, cz );
944 aTrsf.Transforms( cx, cy, cz );
945 SMDS_MeshNode* node = myHelper->AddNode( cx, cy, cz );
946 // find parameters on face
947 Pnts2d1.Value(j).Coord( cx, cy );
948 aTrsf2d.Transforms( cx, cy );
950 meshDS->SetNodeOnFace( node, faceID, cx, cy );
951 tmpNodes.push_back(node);
954 tmpNodes.push_back( CNodes[i] );
956 for ( j = 0; j < (int)Nodes1.size() - 1; j++ ) {
959 MF = myHelper->AddFace( tmpNodes[j], Nodes1[j],
960 Nodes1[j+1], tmpNodes[j+1] );
962 MF = myHelper->AddFace( tmpNodes[j], tmpNodes[j+1],
963 Nodes1[j+1], Nodes1[j] );
964 if(MF) meshDS->SetMeshElementOnShape(MF, faceID);
969 MF = myHelper->AddFace( NC, Nodes1[0], tmpNodes[0] );
971 MF = myHelper->AddFace( NC, tmpNodes[0], Nodes1[0] );
972 if ( MF ) meshDS->SetMeshElementOnShape(MF, faceID);
973 for ( j = 0; j < (int) Nodes1.size(); j++ ) {
974 Nodes1[j] = tmpNodes[j];
979 for ( i = 0; i < (int)Nodes1.size()-1; i++ ) {
982 MF = myHelper->AddFace( Nodes2[i], Nodes1[i],
983 Nodes1[i+1], Nodes2[i+1] );
985 MF = myHelper->AddFace( Nodes2[i], Nodes2[i+1],
986 Nodes1[i+1], Nodes1[i] );
987 if(MF) meshDS->SetMeshElementOnShape(MF, faceID);
992 MF = myHelper->AddFace( NC, Nodes1[0], Nodes2[0] );
994 MF = myHelper->AddFace( NC, Nodes2[0], Nodes1[0] );
995 if(MF) meshDS->SetMeshElementOnShape(MF, faceID);
1000 //================================================================================
1002 * \brief Compute positions of nodes on the radial edge
1003 * \retval bool - is a success
1005 //================================================================================
1007 bool StdMeshers_RadialQuadrangle_1D2D::computeLayerPositions(const gp_Pnt& p1,
1009 const TopoDS_Edge& linEdge,
1010 bool* linEdgeComputed)
1012 // First, try to compute positions of layers
1014 myLayerPositions.clear();
1016 SMESH_Mesh * mesh = myHelper->GetMesh();
1018 const SMESH_Hypothesis* hyp1D = myDistributionHypo ? myDistributionHypo->GetLayerDistribution() : 0;
1019 int nbLayers = myNbLayerHypo ? myNbLayerHypo->GetNumberOfLayers() : 0;
1021 if ( !hyp1D && !nbLayers )
1023 // No own algo hypotheses assigned, so first try to find any 1D hypothesis.
1024 // We need some edge
1025 TopoDS_Shape edge = linEdge;
1026 if ( edge.IsNull() && !myHelper->GetSubShape().IsNull())
1027 for ( TopExp_Explorer e(myHelper->GetSubShape(), TopAbs_EDGE); e.More(); e.Next())
1029 if ( !edge.IsNull() )
1031 // find a hyp usable by TNodeDistributor
1032 const SMESH_HypoFilter* hypKind =
1033 TNodeDistributor::GetDistributor(*mesh)->GetCompatibleHypoFilter(/*ignoreAux=*/true);
1034 hyp1D = mesh->GetHypothesis( edge, *hypKind, /*fromAncestors=*/true);
1037 if ( hyp1D ) // try to compute with hyp1D
1039 if ( !TNodeDistributor::GetDistributor(*mesh)->Compute( myLayerPositions,p1,p2,*mesh,hyp1D )) {
1040 if ( myDistributionHypo ) { // bad hyp assigned
1041 return error( TNodeDistributor::GetDistributor(*mesh)->GetComputeError() );
1044 // bad hyp found, its Ok, lets try with default nb of segnents
1049 if ( myLayerPositions.empty() ) // try to use nb of layers
1052 nbLayers = _gen->GetDefaultNbSegments();
1056 myLayerPositions.resize( nbLayers - 1 );
1057 for ( int z = 1; z < nbLayers; ++z )
1058 myLayerPositions[ z - 1 ] = double( z )/ double( nbLayers );
1062 // Second, check presence of a mesh built by other algo on linEdge
1063 // and mesh conformity to my hypothesis
1065 bool meshComputed = (!linEdge.IsNull() && !mesh->GetSubMesh(linEdge)->IsEmpty() );
1066 if ( linEdgeComputed ) *linEdgeComputed = meshComputed;
1070 vector< double > nodeParams;
1071 GetNodeParamOnEdge( mesh->GetMeshDS(), linEdge, nodeParams );
1073 // nb of present nodes must be different in cases of 1 and 2 straight edges
1075 TopoDS_Vertex VV[2];
1076 TopExp::Vertices( linEdge, VV[0], VV[1]);
1077 const gp_Pnt* points[] = { &p1, &p2 };
1078 gp_Pnt vPoints[] = { BRep_Tool::Pnt(VV[0]), BRep_Tool::Pnt(VV[1]) };
1079 const double tol[] = { BRep_Tool::Tolerance(VV[0]), BRep_Tool::Tolerance(VV[1]) };
1080 bool pointsAreOnVertices = true;
1081 for ( int iP = 0; iP < 2 && pointsAreOnVertices; ++iP )
1082 pointsAreOnVertices = ( points[iP]->Distance( vPoints[0] ) < tol[0] ||
1083 points[iP]->Distance( vPoints[1] ) < tol[1] );
1085 int nbNodes = nodeParams.size() - 2; // 2 straight edges
1086 if ( !pointsAreOnVertices )
1087 nbNodes = ( nodeParams.size() - 3 ) / 2; // 1 straight edge
1089 if ( myLayerPositions.empty() )
1091 myLayerPositions.resize( nbNodes );
1093 else if ( myDistributionHypo || myNbLayerHypo )
1095 // linEdge is computed by other algo. Check if there is a meshed face
1096 // using nodes on linEdge
1097 bool nodesAreUsed = false;
1098 TopTools_ListIteratorOfListOfShape ancestIt = mesh->GetAncestors( linEdge );
1099 for ( ; ancestIt.More() && !nodesAreUsed; ancestIt.Next() )
1100 if ( ancestIt.Value().ShapeType() == TopAbs_FACE )
1101 nodesAreUsed = (!mesh->GetSubMesh( ancestIt.Value() )->IsEmpty());
1102 if ( !nodesAreUsed ) {
1104 mesh->GetSubMesh( linEdge )->ComputeStateEngine( SMESH_subMesh::CLEAN );
1105 if ( linEdgeComputed ) *linEdgeComputed = false;
1109 if ((int) myLayerPositions.size() != nbNodes )
1110 return error("Radial edge is meshed by other algorithm");
1115 return !myLayerPositions.empty();
1119 //=======================================================================
1120 //function : Evaluate
1122 //=======================================================================
1124 bool StdMeshers_RadialQuadrangle_1D2D::Evaluate(SMESH_Mesh& aMesh,
1125 const TopoDS_Shape& aShape,
1126 MapShapeNbElems& aResMap)
1128 if( aShape.ShapeType() != TopAbs_FACE ) {
1131 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1132 if( aResMap.count(sm) )
1135 vector<int>& aResVec =
1136 aResMap.insert( make_pair(sm, vector<int>(SMDSEntity_Last,0))).first->second;
1138 myHelper = new SMESH_MesherHelper( aMesh );
1139 myHelper->SetSubShape( aShape );
1140 auto_ptr<SMESH_MesherHelper> helperDeleter( myHelper );
1142 TNodeDistributor* algo1d = TNodeDistributor::GetDistributor(aMesh);
1144 TopoDS_Edge CircEdge, LinEdge1, LinEdge2;
1145 int nbe = analyseFace( aShape, CircEdge, LinEdge1, LinEdge2 );
1146 if( nbe>3 || nbe < 1 || CircEdge.IsNull() )
1149 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast( getCurve( CircEdge ));
1150 if( aCirc.IsNull() )
1151 return error(COMPERR_BAD_SHAPE);
1153 gp_Pnt P0 = aCirc->Location();
1154 gp_Pnt P1 = aCirc->Value(0.);
1155 computeLayerPositions( P0, P1, LinEdge1 );
1157 int nb0d=0, nb2d_tria=0, nb2d_quad=0;
1158 bool isQuadratic = false, ok = true;
1161 // C1 must be a circle
1162 ok = algo1d->EvaluateCircularEdge( aMesh, CircEdge, aResMap );
1164 const vector<int>& aVec = aResMap[aMesh.GetSubMesh(CircEdge)];
1165 isQuadratic = aVec[SMDSEntity_Quad_Edge]>aVec[SMDSEntity_Edge];
1168 nb0d = (aVec[SMDSEntity_Node]+1) * myLayerPositions.size();
1169 // radial medium nodes
1170 nb0d += (aVec[SMDSEntity_Node]+1) * (myLayerPositions.size()+1);
1171 // other medium nodes
1172 nb0d += (aVec[SMDSEntity_Node]+1) * myLayerPositions.size();
1175 nb0d = (aVec[SMDSEntity_Node]+1) * myLayerPositions.size();
1177 nb2d_tria = aVec[SMDSEntity_Node] + 1;
1181 else if(nbe==2 && LinEdge1.Orientation() != TopAbs_INTERNAL)
1183 // one curve must be a half of circle and other curve must be
1184 // a segment of line
1186 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast( getCurve( CircEdge, &fp, &lp ));
1187 if( fabs(fabs(lp-fp)-M_PI) > Precision::Confusion() ) {
1188 // not half of circle
1189 return error(COMPERR_BAD_SHAPE);
1191 Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast( getCurve( LinEdge1 ));
1192 if( aLine.IsNull() ) {
1193 // other curve not line
1194 return error(COMPERR_BAD_SHAPE);
1196 ok = !aResMap.count( aMesh.GetSubMesh(LinEdge1) );
1198 const vector<int>& aVec = aResMap[ aMesh.GetSubMesh(LinEdge1) ];
1199 ok = ( aVec[SMDSEntity_Node] == (int) myLayerPositions.size() );
1202 ok = algo1d->EvaluateCircularEdge( aMesh, CircEdge, aResMap );
1205 const vector<int>& aVec = aResMap[ aMesh.GetSubMesh(CircEdge) ];
1206 isQuadratic = aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge];
1209 nb0d = aVec[SMDSEntity_Node] * myLayerPositions.size();
1210 // radial medium nodes
1211 nb0d += aVec[SMDSEntity_Node] * (myLayerPositions.size()+1);
1212 // other medium nodes
1213 nb0d += (aVec[SMDSEntity_Node]+1) * myLayerPositions.size();
1216 nb0d = aVec[SMDSEntity_Node] * myLayerPositions.size();
1218 nb2d_tria = aVec[SMDSEntity_Node] + 1;
1219 nb2d_quad = nb2d_tria * myLayerPositions.size();
1220 // add evaluation for edges
1221 vector<int> aResVec(SMDSEntity_Last,0);
1223 aResVec[SMDSEntity_Node] = 4*myLayerPositions.size() + 3;
1224 aResVec[SMDSEntity_Quad_Edge] = 2*myLayerPositions.size() + 2;
1227 aResVec[SMDSEntity_Node] = 2*myLayerPositions.size() + 1;
1228 aResVec[SMDSEntity_Edge] = 2*myLayerPositions.size() + 2;
1230 aResMap[ aMesh.GetSubMesh(LinEdge1) ] = aResVec;
1233 else // nbe==3 or ( nbe==2 && linEdge is INTERNAL )
1235 if (nbe==2 && LinEdge1.Orientation() == TopAbs_INTERNAL )
1236 LinEdge2 = LinEdge1;
1238 // one curve must be a part of circle and other curves must be
1240 Handle(Geom_Line) aLine1 = Handle(Geom_Line)::DownCast( getCurve( LinEdge1 ));
1241 Handle(Geom_Line) aLine2 = Handle(Geom_Line)::DownCast( getCurve( LinEdge2 ));
1242 if( aLine1.IsNull() || aLine2.IsNull() ) {
1243 // other curve not line
1244 return error(COMPERR_BAD_SHAPE);
1246 size_t nbLayers = myLayerPositions.size();
1247 computeLayerPositions( P0, P1, LinEdge2 );
1248 if ( nbLayers != myLayerPositions.size() )
1249 return error("Different hypotheses apply to radial edges");
1251 bool ok = !aResMap.count( aMesh.GetSubMesh(LinEdge1));
1253 if ( myDistributionHypo || myNbLayerHypo )
1254 ok = true; // override other 1d hyps
1256 const vector<int>& aVec = aResMap[ aMesh.GetSubMesh(LinEdge1) ];
1257 ok = ( aVec[SMDSEntity_Node] == (int) myLayerPositions.size() );
1260 if( ok && aResMap.count( aMesh.GetSubMesh(LinEdge2) )) {
1261 if ( myDistributionHypo || myNbLayerHypo )
1262 ok = true; // override other 1d hyps
1264 const vector<int>& aVec = aResMap[ aMesh.GetSubMesh(LinEdge2) ];
1265 ok = ( aVec[SMDSEntity_Node] == (int) myLayerPositions.size() );
1269 ok = algo1d->EvaluateCircularEdge( aMesh, CircEdge, aResMap );
1272 const vector<int>& aVec = aResMap[ aMesh.GetSubMesh(CircEdge) ];
1273 isQuadratic = aVec[SMDSEntity_Quad_Edge]>aVec[SMDSEntity_Edge];
1276 nb0d = aVec[SMDSEntity_Node] * myLayerPositions.size();
1277 // radial medium nodes
1278 nb0d += aVec[SMDSEntity_Node] * (myLayerPositions.size()+1);
1279 // other medium nodes
1280 nb0d += (aVec[SMDSEntity_Node]+1) * myLayerPositions.size();
1283 nb0d = aVec[SMDSEntity_Node] * myLayerPositions.size();
1285 nb2d_tria = aVec[SMDSEntity_Node] + 1;
1286 nb2d_quad = nb2d_tria * myLayerPositions.size();
1287 // add evaluation for edges
1288 vector<int> aResVec(SMDSEntity_Last, 0);
1290 aResVec[SMDSEntity_Node] = 2*myLayerPositions.size() + 1;
1291 aResVec[SMDSEntity_Quad_Edge] = myLayerPositions.size() + 1;
1294 aResVec[SMDSEntity_Node] = myLayerPositions.size();
1295 aResVec[SMDSEntity_Edge] = myLayerPositions.size() + 1;
1297 sm = aMesh.GetSubMesh(LinEdge1);
1298 aResMap[sm] = aResVec;
1299 sm = aMesh.GetSubMesh(LinEdge2);
1300 aResMap[sm] = aResVec;
1307 aResVec[SMDSEntity_Quad_Triangle] = nb2d_tria;
1308 aResVec[SMDSEntity_Quad_Quadrangle] = nb2d_quad;
1311 aResVec[SMDSEntity_Triangle] = nb2d_tria;
1312 aResVec[SMDSEntity_Quadrangle] = nb2d_quad;
1318 sm = aMesh.GetSubMesh(aShape);
1319 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
1320 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,
1321 "Submesh can not be evaluated",this));
1326 //================================================================================
1328 * \brief Return true if the algorithm can compute mesh on this shape
1330 //================================================================================
1332 bool StdMeshers_RadialQuadrangle_1D2D::IsApplicable( const TopoDS_Shape & aShape, bool toCheckAll )
1334 int nbFoundFaces = 0;
1335 for (TopExp_Explorer exp( aShape, TopAbs_FACE ); exp.More(); exp.Next(), ++nbFoundFaces )
1337 TopoDS_Edge CircEdge, LinEdge1, LinEdge2;
1338 int nbe = analyseFace( exp.Current(), CircEdge, LinEdge1, LinEdge2 );
1339 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast( getCurve( CircEdge ));
1340 bool ok = ( nbe <= 3 && nbe >= 1 && !aCirc.IsNull() &&
1341 isCornerInsideCircle( CircEdge, LinEdge1, LinEdge2 ));
1342 if( toCheckAll && !ok ) return false;
1343 if( !toCheckAll && ok ) return true;
1345 if( toCheckAll && nbFoundFaces != 0 ) return true;