-
-//=============================================================================
-/*!
- * LoadEdgePoints2
- */
-//=============================================================================
-UVPtStruct* StdMeshers_Quadrangle_2D::LoadEdgePoints2 (SMESH_Mesh & aMesh,
- const TopoDS_Face& F,
- const TopoDS_Edge& E,
- bool IsReverse)
-{
- //MESSAGE("StdMeshers_Quadrangle_2D::LoadEdgePoints");
- // --- IDNodes of first and last Vertex
- TopoDS_Vertex VFirst, VLast;
- TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
-
- ASSERT(!VFirst.IsNull());
- SMDS_NodeIteratorPtr lid = aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes();
- if (!lid->more()) {
- MESSAGE ( "NO NODE BUILT ON VERTEX" );
- return 0;
- }
- const SMDS_MeshNode* idFirst = lid->next();
-
- ASSERT(!VLast.IsNull());
- lid = aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes();
- if (!lid->more()) {
- MESSAGE ( "NO NODE BUILT ON VERTEX" );
- return 0;
- }
- const SMDS_MeshNode* idLast = lid->next();
-
- // --- edge internal IDNodes (relies on good order storage, not checked)
-
- map<double, const SMDS_MeshNode *> params;
- SMDS_NodeIteratorPtr ite = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes();
- int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
-
- if(!_quadraticMesh) {
- while(ite->more()) {
- const SMDS_MeshNode* node = ite->next();
- const SMDS_EdgePosition* epos =
- static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
- double param = epos->GetUParameter();
- params[param] = node;
- }
- }
- else {
- vector<const SMDS_MeshNode*> nodes(nbPoints+2);
- nodes[0] = idFirst;
- nodes[nbPoints+1] = idLast;
- nbPoints = nbPoints/2;
- int nn = 1;
- while(ite->more()) {
- const SMDS_MeshNode* node = ite->next();
- nodes[nn++] = node;
- // check if node is medium
- bool IsMedium = false;
- SMDS_ElemIteratorPtr itn = node->GetInverseElementIterator();
- while (itn->more()) {
- const SMDS_MeshElement* elem = itn->next();
- if ( elem->GetType() != SMDSAbs_Edge )
- continue;
- if(elem->IsMediumNode(node)) {
- IsMedium = true;
- break;
- }
- }
- if(IsMedium)
- continue;
- const SMDS_EdgePosition* epos =
- static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
- double param = epos->GetUParameter();
- params[param] = node;
- }
- }
-
- if (nbPoints != params.size()) {
- MESSAGE( "BAD NODE ON EDGE POSITIONS" );
- return 0;
- }
- UVPtStruct* uvslf = new UVPtStruct[nbPoints + 2];
-
- double f, l;
- Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
-
- const TopoDS_Wire& W = BRepTools::OuterWire(F);
- bool FisF = (F.Orientation()==TopAbs_FORWARD);
- bool WisF = (W.Orientation()==TopAbs_FORWARD);
- bool isForward = (E.Orientation()==TopAbs_FORWARD);
- //if(isForward) cout<<"E is FORWARD"<<endl;
- //else cout<<"E is REVERSED"<<endl;
- if(!WisF) isForward = !isForward;
- if(!FisF) isForward = !isForward;
- //bool isForward = !(E.Orientation()==TopAbs_FORWARD);
- if(IsReverse) isForward = !isForward;
- double paramin = 0;
- double paramax = 0;
- if (isForward) {
- paramin = f;
- paramax = l;
- gp_Pnt2d p = C2d->Value(f); // first point = Vertex Forward
- uvslf[0].x = p.X();
- uvslf[0].y = p.Y();
- uvslf[0].param = f;
- uvslf[0].node = idFirst;
- //MESSAGE("__ f "<<f<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
- map < double, const SMDS_MeshNode* >::iterator itp = params.begin();
- for (int i = 1; i <= nbPoints; i++) { // nbPoints internal
- double param = (*itp).first;
- gp_Pnt2d p = C2d->Value(param);
- uvslf[i].x = p.X();
- uvslf[i].y = p.Y();
- uvslf[i].param = param;
- uvslf[i].node = (*itp).second;
- //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
- itp++;
- }
- p = C2d->Value(l); // last point = Vertex Reversed
- uvslf[nbPoints + 1].x = p.X();
- uvslf[nbPoints + 1].y = p.Y();
- uvslf[nbPoints + 1].param = l;
- uvslf[nbPoints + 1].node = idLast;
- //MESSAGE("__ l "<<l<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
- }
- else {
- paramin = l;
- paramax = f;
- gp_Pnt2d p = C2d->Value(l); // first point = Vertex Reversed
- uvslf[0].x = p.X();
- uvslf[0].y = p.Y();
- uvslf[0].param = l;
- uvslf[0].node = idLast;
- //MESSAGE("__ l "<<l<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
- map < double, const SMDS_MeshNode* >::reverse_iterator itp = params.rbegin();
- for (int j = nbPoints; j >= 1; j--) { // nbPoints internal
- double param = (*itp).first;
- int i = nbPoints + 1 - j;
- gp_Pnt2d p = C2d->Value(param);
- uvslf[i].x = p.X();
- uvslf[i].y = p.Y();
- uvslf[i].param = param;
- uvslf[i].node = (*itp).second;
- //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
- itp++;
- }
- p = C2d->Value(f); // last point = Vertex Forward
- uvslf[nbPoints + 1].x = p.X();
- uvslf[nbPoints + 1].y = p.Y();
- uvslf[nbPoints + 1].param = f;
- uvslf[nbPoints + 1].node = idFirst;
- //MESSAGE("__ f "<<f<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
- }
-
- ASSERT(paramin != paramax);
- for (int i = 0; i < nbPoints + 2; i++) {
- uvslf[i].normParam = (uvslf[i].param - paramin) / (paramax - paramin);
- }
-
- return uvslf;
-}
-
-
-//=============================================================================
-/*!
- * LoadEdgePoints
- */
-//=============================================================================
-UVPtStruct* StdMeshers_Quadrangle_2D::LoadEdgePoints (SMESH_Mesh & aMesh,
- const TopoDS_Face& F,
- const TopoDS_Edge& E,
- double first, double last)
-// bool isForward)
-{
- //MESSAGE("StdMeshers_Quadrangle_2D::LoadEdgePoints");
-
- // --- IDNodes of first and last Vertex
-
- TopoDS_Vertex VFirst, VLast;
- TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
-
- ASSERT(!VFirst.IsNull());
- SMDS_NodeIteratorPtr lid = aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes();
- if (!lid->more())
- {
- MESSAGE ( "NO NODE BUILT ON VERTEX" );
- return 0;
- }
- const SMDS_MeshNode* idFirst = lid->next();
-
- ASSERT(!VLast.IsNull());
- lid = aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes();
- if (!lid->more())
- {
- MESSAGE ( "NO NODE BUILT ON VERTEX" );
- return 0;
- }
- const SMDS_MeshNode* idLast = lid->next();
-
- // --- edge internal IDNodes (relies on good order storage, not checked)
-
-// if(_quadraticMesh) {
- // fill myNLinkNodeMap
-// SMDS_ElemIteratorPtr iter = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetElements();
-// while(iter->more()) {
-// const SMDS_MeshElement* elem = iter->next();
-// SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
-// const SMDS_MeshNode* n1 = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
-// const SMDS_MeshNode* n2 = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
-// const SMDS_MeshNode* n3 = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
-// NLink link(( n1 < n2 ? n1 : n2 ), ( n1 < n2 ? n2 : n1 ));
-// myNLinkNodeMap.insert(NLinkNodeMap::value_type(link,n3));
-// myNLinkNodeMap[link] = n3;
-// }
-// }
-
- map<double, const SMDS_MeshNode *> params;
- SMDS_NodeIteratorPtr ite = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes();
- int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
-
- if(!_quadraticMesh) {
- while(ite->more()) {
- const SMDS_MeshNode* node = ite->next();
- const SMDS_EdgePosition* epos =
- static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
- double param = epos->GetUParameter();
- params[param] = node;
- }
- }
- else {
- nbPoints = nbPoints/2;
- while(ite->more()) {
- const SMDS_MeshNode* node = ite->next();
- // check if node is medium
- bool IsMedium = false;
- SMDS_ElemIteratorPtr itn = node->GetInverseElementIterator();
- while (itn->more()) {
- const SMDS_MeshElement* elem = itn->next();
- if ( elem->GetType() != SMDSAbs_Edge )
- continue;
- if(elem->IsMediumNode(node)) {
- IsMedium = true;
- break;
- }
- }
- if(IsMedium)
- continue;
- const SMDS_EdgePosition* epos =
- static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
- double param = epos->GetUParameter();
- params[param] = node;
- }
- }
-
- if (nbPoints != params.size()) {
- MESSAGE( "BAD NODE ON EDGE POSITIONS" );
- return 0;
- }
- UVPtStruct* uvslf = new UVPtStruct[nbPoints + 2];
-
- double f, l;
- Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
-
- bool isForward = (((l - f) * (last - first)) > 0);
- double paramin = 0;
- double paramax = 0;
- if (isForward)
- {
- paramin = f;
- paramax = l;
- gp_Pnt2d p = C2d->Value(f); // first point = Vertex Forward
- uvslf[0].x = p.X();
- uvslf[0].y = p.Y();
- uvslf[0].param = f;
- uvslf[0].node = idFirst;
- //MESSAGE("__ f "<<f<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
- map < double, const SMDS_MeshNode* >::iterator itp = params.begin();
- for (int i = 1; i <= nbPoints; i++) // nbPoints internal
- {
- double param = (*itp).first;
- gp_Pnt2d p = C2d->Value(param);
- uvslf[i].x = p.X();
- uvslf[i].y = p.Y();
- uvslf[i].param = param;
- uvslf[i].node = (*itp).second;
- //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
- itp++;
- }
- p = C2d->Value(l); // last point = Vertex Reversed
- uvslf[nbPoints + 1].x = p.X();
- uvslf[nbPoints + 1].y = p.Y();
- uvslf[nbPoints + 1].param = l;
- uvslf[nbPoints + 1].node = idLast;
- //MESSAGE("__ l "<<l<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
- } else
- {
- paramin = l;
- paramax = f;
- gp_Pnt2d p = C2d->Value(l); // first point = Vertex Reversed
- uvslf[0].x = p.X();
- uvslf[0].y = p.Y();
- uvslf[0].param = l;
- uvslf[0].node = idLast;
- //MESSAGE("__ l "<<l<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
- map < double, const SMDS_MeshNode* >::reverse_iterator itp = params.rbegin();
-
- for (int j = nbPoints; j >= 1; j--) // nbPoints internal
- {
- double param = (*itp).first;
- int i = nbPoints + 1 - j;
- gp_Pnt2d p = C2d->Value(param);
- uvslf[i].x = p.X();
- uvslf[i].y = p.Y();
- uvslf[i].param = param;
- uvslf[i].node = (*itp).second;
- //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
- itp++;
- }
- p = C2d->Value(f); // last point = Vertex Forward
- uvslf[nbPoints + 1].x = p.X();
- uvslf[nbPoints + 1].y = p.Y();
- uvslf[nbPoints + 1].param = f;
- uvslf[nbPoints + 1].node = idFirst;
- //MESSAGE("__ f "<<f<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
- }
-
- ASSERT(paramin != paramax);
- for (int i = 0; i < nbPoints + 2; i++)
- {
- uvslf[i].normParam = (uvslf[i].param - paramin) / (paramax - paramin);
- }
-
- return uvslf;
-}
-
-//=============================================================================
-/*!
- * MakeEdgePoints
- */
-//=============================================================================
-UVPtStruct* StdMeshers_Quadrangle_2D::MakeEdgePoints (SMESH_Mesh & aMesh,
- const TopoDS_Face& F,
- const TopoDS_Edge& E,
- double first, double last,
- int nb_segm)
-{
-// MESSAGE("StdMeshers_Quadrangle_2D::MakeEdgePoints");
-
- UVPtStruct* uvslf = new UVPtStruct[nb_segm + 1];
- list<double> params;
-
- // --- edge internal points
- double fi, li;
- Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, fi, li);
- if (!Curve.IsNull()) {
- try {
- GeomAdaptor_Curve C3d (Curve);
- double length = EdgeLength(E);
- double eltSize = length / nb_segm;
- GCPnts_UniformAbscissa Discret (C3d, eltSize, fi, li);
- if (!Discret.IsDone()) return false;
- int NbPoints = Discret.NbPoints();
- for (int i = 1; i <= NbPoints; i++) {
- double param = Discret.Parameter(i);
- params.push_back(param);
- }
- }
- catch (Standard_Failure) {
- return 0;
- }
- }
- else
- {
- // Edge is a degenerated Edge
- BRep_Tool::Range(E, fi, li);
- double du = (li - fi) / nb_segm;
- for (int i = 1; i <= nb_segm + 1; i++)
- {
- double param = fi + (i - 1) * du;
- params.push_back(param);
- }
- }
-
- double f, l;
- Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
- ASSERT(f != l);
-
- bool isForward = (((l - f) * (last - first)) > 0);
- if (isForward) {
- list<double>::iterator itU = params.begin();
- for (int i = 0; i <= nb_segm; i++) // nbPoints internal
- {
- double param = *itU;
- gp_Pnt2d p = C2d->Value(param);
- uvslf[i].x = p.X();
- uvslf[i].y = p.Y();
- uvslf[i].param = param;
- uvslf[i].normParam = (param - f) / (l - f);
- itU++;
- }
- } else {
- list<double>::reverse_iterator itU = params.rbegin();
- for (int j = nb_segm; j >= 0; j--) // nbPoints internal
- {
- double param = *itU;
- int i = nb_segm - j;
- gp_Pnt2d p = C2d->Value(param);
- uvslf[i].x = p.X();
- uvslf[i].y = p.Y();
- uvslf[i].param = param;
- uvslf[i].normParam = (param - l) / (f - l);
- itU++;
- }
- }
-
- return uvslf;
-}
-
-
-//=============================================================================
-/*!
- *
- */
-//=============================================================================
-
-ostream & StdMeshers_Quadrangle_2D::SaveTo(ostream & save)
-{
- return save;
-}
-
-//=============================================================================
-/*!
- *
- */
-//=============================================================================
-
-istream & StdMeshers_Quadrangle_2D::LoadFrom(istream & load)
-{
- return load;
-}
-
-//=============================================================================
-/*!
- *
- */
-//=============================================================================
-
-ostream & operator <<(ostream & save, StdMeshers_Quadrangle_2D & hyp)
-{
- return hyp.SaveTo( save );
-}
-
-//=============================================================================
-/*!
- *
- */
-//=============================================================================
-
-istream & operator >>(istream & load, StdMeshers_Quadrangle_2D & hyp)
-{
- return hyp.LoadFrom( load );
-}