X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH%2FSMESH_Regular_1D.cxx;h=1f4e6ebfe619090304f45f5cc4885866c4d8582a;hb=f7fbf1c62246f439c35746c731f64dab57391c1b;hp=920cd77dccf3a8affb78a5b90bc52687161c9fc6;hpb=789d7f7415a1e465aee36232e7633eea548ff1fb;p=modules%2Fsmesh.git diff --git a/src/SMESH/SMESH_Regular_1D.cxx b/src/SMESH/SMESH_Regular_1D.cxx index 920cd77dc..1f4e6ebfe 100644 --- a/src/SMESH/SMESH_Regular_1D.cxx +++ b/src/SMESH/SMESH_Regular_1D.cxx @@ -27,7 +27,7 @@ // $Header$ using namespace std; -using namespace std; + #include "SMESH_Regular_1D.hxx" #include "SMESH_Gen.hxx" #include "SMESH_Mesh.hxx" @@ -35,8 +35,6 @@ using namespace std; #include "SMESH_LocalLength.hxx" #include "SMESH_NumberOfSegments.hxx" -#include "SMESHDS_ListOfPtrHypothesis.hxx" -#include "SMESHDS_ListIteratorOfListOfPtrHypothesis.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" #include "SMDS_EdgePosition.hxx" @@ -59,20 +57,20 @@ using namespace std; */ //============================================================================= -SMESH_Regular_1D::SMESH_Regular_1D(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_1D_Algo(hypId, studyId, gen) +SMESH_Regular_1D::SMESH_Regular_1D(int hypId, int studyId, + SMESH_Gen * gen):SMESH_1D_Algo(hypId, studyId, gen) { - MESSAGE("SMESH_Regular_1D::SMESH_Regular_1D"); - _name = "Regular_1D"; - // _shapeType = TopAbs_EDGE; - _shapeType = (1<> (*this); + return load >> (*this); } //============================================================================= @@ -113,9 +111,9 @@ istream & SMESH_Regular_1D::LoadFrom(istream & load) */ //============================================================================= -ostream& operator << (ostream & save, SMESH_Regular_1D & hyp) +ostream & operator <<(ostream & save, SMESH_Regular_1D & hyp) { - return save; + return save; } //============================================================================= @@ -124,9 +122,9 @@ ostream& operator << (ostream & save, SMESH_Regular_1D & hyp) */ //============================================================================= -istream& operator >> (istream & load, SMESH_Regular_1D & hyp) +istream & operator >>(istream & load, SMESH_Regular_1D & hyp) { - return load; + return load; } //============================================================================= @@ -135,50 +133,51 @@ istream& operator >> (istream & load, SMESH_Regular_1D & hyp) */ //============================================================================= -bool SMESH_Regular_1D::CheckHypothesis(SMESH_Mesh& aMesh, - const TopoDS_Shape& aShape) +bool SMESH_Regular_1D::CheckHypothesis(SMESH_Mesh & aMesh, + const TopoDS_Shape & aShape) { - //MESSAGE("SMESH_Regular_1D::CheckHypothesis"); - - list::const_iterator itl; - SMESHDS_Hypothesis* theHyp; - - const list& hyps = GetUsedHypothesis(aMesh, aShape); - int nbHyp = hyps.size(); - if (nbHyp != 1) return false; // only one compatible hypothesis allowed - - itl = hyps.begin(); - theHyp = (*itl); - - string hypName = theHyp->GetName(); - int hypId = theHyp->GetID(); - //SCRUTE(hypName); - - bool isOk = false; - - if (hypName == "LocalLength") - { - _hypLocalLength = dynamic_cast (theHyp); - ASSERT(_hypLocalLength); - _localLength = _hypLocalLength->GetLength(); - _numberOfSegments = 0; - isOk =true; - } - - if (hypName == "NumberOfSegments") - { - _hypNumberOfSegments = dynamic_cast (theHyp); - ASSERT(_hypNumberOfSegments); - _numberOfSegments = _hypNumberOfSegments->GetNumberOfSegments(); - _scaleFactor = _hypNumberOfSegments->GetScaleFactor(); - _localLength = 0; - isOk = true; - } - - //SCRUTE(_localLength); - //SCRUTE(_numberOfSegments); - - return isOk; + //MESSAGE("SMESH_Regular_1D::CheckHypothesis"); + + list ::const_iterator itl; + const SMESHDS_Hypothesis *theHyp; + + const list &hyps = GetUsedHypothesis(aMesh, aShape); + int nbHyp = hyps.size(); + if (nbHyp != 1) return false; // only one compatible hypothesis allowed + + itl = hyps.begin(); + theHyp = (*itl); + + string hypName = theHyp->GetName(); + int hypId = theHyp->GetID(); + //SCRUTE(hypName); + + bool isOk = false; + + if (hypName == "LocalLength") + { + _hypLocalLength = dynamic_cast (theHyp); + ASSERT(_hypLocalLength); + _localLength = _hypLocalLength->GetLength(); + _numberOfSegments = 0; + isOk = true; + } + + if (hypName == "NumberOfSegments") + { + _hypNumberOfSegments = + dynamic_cast (theHyp); + ASSERT(_hypNumberOfSegments); + _numberOfSegments = _hypNumberOfSegments->GetNumberOfSegments(); + _scaleFactor = _hypNumberOfSegments->GetScaleFactor(); + _localLength = 0; + isOk = true; + } + + //SCRUTE(_localLength); + //SCRUTE(_numberOfSegments); + + return isOk; } //============================================================================= @@ -187,151 +186,137 @@ bool SMESH_Regular_1D::CheckHypothesis(SMESH_Mesh& aMesh, */ //============================================================================= -bool SMESH_Regular_1D::Compute(SMESH_Mesh& aMesh, - const TopoDS_Shape& aShape) +bool SMESH_Regular_1D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) { - //MESSAGE("SMESH_Regular_1D::Compute"); + MESSAGE("SMESH_Regular_1D::Compute"); - const Handle(SMESHDS_Mesh)& meshDS = aMesh.GetMeshDS(); - SMESH_subMesh* theSubMesh = aMesh.GetSubMesh(aShape); + SMESHDS_Mesh * meshDS = aMesh.GetMeshDS(); + SMESH_subMesh *theSubMesh = aMesh.GetSubMesh(aShape); - const TopoDS_Edge& EE = TopoDS::Edge(aShape); - TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD)); + const TopoDS_Edge & EE = TopoDS::Edge(aShape); + TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD)); - double f,l; - Handle(Geom_Curve) Curve = BRep_Tool::Curve(E,f,l); + double f, l; + Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l); - TopoDS_Vertex VFirst, VLast; - TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l + TopoDS_Vertex VFirst, VLast; + TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l - double length = EdgeLength(E); - //SCRUTE(length); + double length = EdgeLength(E); + //SCRUTE(length); - double eltSize = 1; + double eltSize = 1; // if (_localLength > 0) eltSize = _localLength; - if (_localLength > 0) - { - double nbseg = ceil(length/_localLength); // integer sup - if (nbseg <=0) nbseg = 1; // degenerated edge - eltSize = length/nbseg; - } - else - { - ASSERT(_numberOfSegments> 0); - eltSize = length/_numberOfSegments; - } - - ASSERT(!VFirst.IsNull()); - SMESH_subMesh* firstSubMesh = aMesh.GetSubMesh(VFirst); - const TColStd_ListOfInteger& lidf - = firstSubMesh->GetSubMeshDS()->GetIDNodes(); - int idFirst= lidf.First(); - //SCRUTE(idFirst); - - ASSERT(!VLast.IsNull()); - SMESH_subMesh* lastSubMesh = aMesh.GetSubMesh(VLast); - const TColStd_ListOfInteger& lidl - = lastSubMesh->GetSubMeshDS()->GetIDNodes(); - int idLast= lidl.First(); - //SCRUTE(idLast); - - if (!Curve.IsNull()) - { - GeomAdaptor_Curve C3d(Curve); - GCPnts_UniformAbscissa Discret(C3d,eltSize,f,l); - int NbPoints = Discret.NbPoints(); - //MESSAGE("nb points on edge : "< 0) + { + double nbseg = ceil(length / _localLength); // integer sup + if (nbseg <= 0) + nbseg = 1; // degenerated edge + eltSize = length / nbseg; + } + else { - double param = Discret.Parameter(i); + ASSERT(_numberOfSegments > 0); + eltSize = length / _numberOfSegments; + } - if(_numberOfSegments > 1) - { - double epsilon = 0.001; - if( fabs(_scaleFactor-1.0) > epsilon ) + ASSERT(!VFirst.IsNull()); + SMDS_Iterator * lid= + aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes(); + const SMDS_MeshNode * idFirst = lid->next(); + delete lid; + + ASSERT(!VLast.IsNull()); + lid=aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes(); + const SMDS_MeshNode * idLast = lid->next(); + delete lid; + + if (!Curve.IsNull()) + { + GeomAdaptor_Curve C3d(Curve); + GCPnts_UniformAbscissa Discret(C3d, eltSize, f, l); + int NbPoints = Discret.NbPoints(); + //MESSAGE("nb points on edge : "< 1) + { + double epsilon = 0.001; + if (fabs(_scaleFactor - 1.0) > epsilon) + { + double alpha = + pow(_scaleFactor, 1.0 / (_numberOfSegments - 1)); + double d = + length * (1 - pow(alpha, i - 1)) / (1 - pow(alpha, + _numberOfSegments)); + param = d; + } + } + + gp_Pnt P = Curve->Value(param); + + //Add the Node in the DataStructure + //MESSAGE("point "<AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnEdge(node, E); + + // **** edgePosition associe au point = param. + SMDS_EdgePosition* epos=dynamic_cast(node->GetPosition()); + epos->SetUParameter(param); + + SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node); + meshDS->SetMeshElementOnShape(edge, E); + idPrev = node; } - } - - gp_Pnt P = Curve->Value(param); - - //Add the Node in the DataStructure - int nodeId = meshDS->AddNode(P.X(), P.Y(), P.Z()); - //MESSAGE("point "<FindNode(nodeId); - Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt); - meshDS->SetNodeOnEdge(node, E); - - // **** edgePosition associe au point = param. -// Handle (SMDS_EdgePosition) epos -// = new SMDS_EdgePosition(theSubMesh->GetId(),param); // non, deja cree -// node->SetPosition(epos); - Handle (SMDS_EdgePosition) epos - = Handle (SMDS_EdgePosition)::DownCast(node->GetPosition()); - epos->SetUParameter(param); - - int edgeId = meshDS->AddEdge(idPrev, nodeId); - elt = meshDS->FindElement(edgeId); - meshDS->SetMeshElementOnShape(elt, E); - idPrev = nodeId; + SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast); + meshDS->SetMeshElementOnShape(edge, E); } - int edgeId = meshDS->AddEdge(idPrev, idLast); - Handle (SMDS_MeshElement) elt = meshDS->FindElement(edgeId); - meshDS->SetMeshElementOnShape(elt, E); - } - else - { + else + { // MESSAGE ("Edge Degeneree non traitee --- arret"); // ASSERT(0); - if (BRep_Tool::Degenerated(E)) - { - // Edge is a degenerated Edge : We put n = 5 points on the edge. - int NbPoints = 5; - BRep_Tool::Range(E,f,l); - double du = (l-f)/(NbPoints-1); - MESSAGE("************* Degenerated edge! *****************"); - - TopoDS_Vertex V1,V2; - TopExp::Vertices (E,V1,V2); - gp_Pnt P = BRep_Tool::Pnt(V1); - - int idPrev = idFirst; - for (int i=2; iAddNode(P.X(), P.Y(), P.Z()); - //MESSAGE("point "<FindNode(nodeId); - Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt); - meshDS->SetNodeOnEdge(node, E); - -// Handle (SMDS_EdgePosition) epos -// = new SMDS_EdgePosition(theSubMesh->GetId(),param); -// node->SetPosition(epos); - Handle (SMDS_EdgePosition) epos - = Handle (SMDS_EdgePosition)::DownCast(node->GetPosition()); - epos->SetUParameter(param); - - int edgeId = meshDS->AddEdge(idPrev, nodeId); - elt = meshDS->FindElement(edgeId); - meshDS->SetMeshElementOnShape(elt, E); - idPrev = nodeId; - } - int edgeId = meshDS->AddEdge(idPrev, idLast); - Handle (SMDS_MeshElement) elt = meshDS->FindElement(edgeId); - meshDS->SetMeshElementOnShape(elt, E); + if (BRep_Tool::Degenerated(E)) + { + // Edge is a degenerated Edge : We put n = 5 points on the edge. + int NbPoints = 5; + BRep_Tool::Range(E, f, l); + double du = (l - f) / (NbPoints - 1); + MESSAGE("************* Degenerated edge! *****************"); + + TopoDS_Vertex V1, V2; + TopExp::Vertices(E, V1, V2); + gp_Pnt P = BRep_Tool::Pnt(V1); + + const SMDS_MeshNode * idPrev = idFirst; + for (int i = 2; i < NbPoints; i++) + { + double param = f + (i - 1) * du; + SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnEdge(node, E); + +// Handle (SMDS_EdgePosition) epos +// = new SMDS_EdgePosition(theSubMesh->GetId(),param); +// node->SetPosition(epos); + SMDS_EdgePosition* epos + = dynamic_cast(node->GetPosition()); + epos->SetUParameter(param); + + SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node); + meshDS->SetMeshElementOnShape(edge, E); + idPrev = node; + } + SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast); + meshDS->SetMeshElementOnShape(edge, E); + } + else + ASSERT(0); } - else ASSERT(0); - } - return true; + return true; }