X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH%2FSMESH_Regular_1D.cxx;h=1f4e6ebfe619090304f45f5cc4885866c4d8582a;hb=d65fdaa969d2e3de5ca395e0829546d4597dba16;hp=aec7b53678216d219a20945e31fc3fa1587f33ca;hpb=8b4ba0cdff7660465a9ea7b26ef0df0757afed97;p=modules%2Fsmesh.git diff --git a/src/SMESH/SMESH_Regular_1D.cxx b/src/SMESH/SMESH_Regular_1D.cxx index aec7b5367..1f4e6ebfe 100644 --- a/src/SMESH/SMESH_Regular_1D.cxx +++ b/src/SMESH/SMESH_Regular_1D.cxx @@ -1,12 +1,31 @@ -using namespace std; -//============================================================================= -// File : SMESH_Regular_1D.cxx -// Created : sam mai 18 08:11:58 CEST 2002 -// Author : Paul RASCLE, EDF -// Project : SALOME -// Copyright : EDF 2002 -// $Header$ -//============================================================================= +// SMESH SMESH : implementaion of SMESH idl descriptions +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESH_Regular_1D.cxx +// Author : Paul RASCLE, EDF +// Module : SMESH +// $Header$ + using namespace std; #include "SMESH_Regular_1D.hxx" @@ -16,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" @@ -40,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); } //============================================================================= @@ -94,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; } //============================================================================= @@ -105,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; } //============================================================================= @@ -116,49 +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(); - _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; } //============================================================================= @@ -167,139 +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 param = Discret.Parameter(i); - 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; + double nbseg = ceil(length / _localLength); // integer sup + if (nbseg <= 0) + nbseg = 1; // degenerated edge + eltSize = length / nbseg; } - int edgeId = meshDS->AddEdge(idPrev, idLast); - Handle (SMDS_MeshElement) elt = meshDS->FindElement(edgeId); - meshDS->SetMeshElementOnShape(elt, E); - } - else - { + else + { + ASSERT(_numberOfSegments > 0); + eltSize = length / _numberOfSegments; + } + + 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; + } + SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast); + meshDS->SetMeshElementOnShape(edge, E); + } + 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; }