X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FARCHIMEDE%2FArchimede_VolumeSection.cxx;h=0aee99aadef63d6e3da04cfd7b821d62b25a408c;hb=8744c2334bea619eb89e9df365374ff9ab1a7f7b;hp=fecd0f99920b56caadb1f50be01c56554c091377;hpb=ecb53a73db547cbbb50f2df55faa344e3ad41594;p=modules%2Fgeom.git diff --git a/src/ARCHIMEDE/Archimede_VolumeSection.cxx b/src/ARCHIMEDE/Archimede_VolumeSection.cxx index fecd0f999..0aee99aad 100644 --- a/src/ARCHIMEDE/Archimede_VolumeSection.cxx +++ b/src/ARCHIMEDE/Archimede_VolumeSection.cxx @@ -1,19 +1,34 @@ -using namespace std; -// File : Archimede_VolumeSection.cxx -// Created : Fri Feb 22 09:28:13 CET 2002 -// Author : PULV +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// -// Modified : Fri Feb 22 09:28:13 CET 2002 -// Author : Nicolas REJNERI -// Project : SALOME -// Module : GEOM -// Copyright : Open CASCADE 2002 +// GEOM ARCHIMEDE : algorithm implementation +// File : Archimede_VolumeSection.cxx +// Author : Nicolas REJNERI +// Module : GEOM // $Header$ - +// #include "Archimede_VolumeSection.hxx" #include "utilities.h" -#include #include #include #include @@ -24,14 +39,10 @@ using namespace std; #include #include #include -#include -#include -#include #include #include #include #include -#include #include #include @@ -78,33 +89,33 @@ void VolumeSection::CenterOfGravity() TopoDS_Face F = TopoDS::Face(ex.Current()); Handle(Poly_Triangulation) Tr = BRep_Tool::Triangulation(F, L); if(Tr.IsNull()) - MESSAGE("Error, null layer" ) + MESSAGE("Error, null layer" ) nbNodes = Tr->NbNodes(); const TColgp_Array1OfPnt& Nodes = Tr->Nodes(); // Calcul des dimensions de la boite englobante du solide for(i=1;i<=nbNodes;i++) - { - InitPoint = Nodes(i).Transformed(L.Transformation()); - if(InitPoint.X() < Xmin) - Xmin = InitPoint.X(); - if(InitPoint.X() > Xmax) - Xmax = InitPoint.X(); - if(InitPoint.Y() < Ymin) - Ymin = InitPoint.Y(); - if(InitPoint.Y() > Ymax) - Ymax = InitPoint.Y(); - if(InitPoint.Z() < Zmin) - Zmin = InitPoint.Z(); - if(InitPoint.Z() > Zmax) - Zmax = InitPoint.Z(); - - } + { + InitPoint = Nodes(i).Transformed(L.Transformation()); + if(InitPoint.X() < Xmin) + Xmin = InitPoint.X(); + if(InitPoint.X() > Xmax) + Xmax = InitPoint.X(); + if(InitPoint.Y() < Ymin) + Ymin = InitPoint.Y(); + if(InitPoint.Y() > Ymax) + Ymax = InitPoint.Y(); + if(InitPoint.Z() < Zmin) + Zmin = InitPoint.Z(); + if(InitPoint.Z() > Zmax) + Zmax = InitPoint.Z(); + + } } - // Creation du point d'initialisation, c'est à dire le centre de gravité - //géométrique de la boite englobante + // Creation du point d'initialisation, c'est € dire le centre de gravit‰ + //g‰om‰trique de la boite englobante InitPoint.SetX(0.5 * (Xmin + Xmax)); InitPoint.SetY(0.5 * (Ymin + Ymax)); @@ -131,80 +142,80 @@ Standard_Real VolumeSection::CalculateVolume(Standard_Real Elevation) TopoDS_Face F = TopoDS::Face(ex.Current()); Handle(Poly_Triangulation) Tr = BRep_Tool::Triangulation(F, L); if(Tr.IsNull()) - MESSAGE("Error, null layer" ) + MESSAGE("Error, null layer" ) const Poly_Array1OfTriangle& triangles = Tr->Triangles(); Standard_Integer nbTriangles = Tr->NbTriangles(); nbNodes = Tr->NbNodes(); const TColgp_Array1OfPnt& Nodes = Tr->Nodes(); // Calcul des volumes de chaque triangle, de chaque face - //en tenant compte des triangles coupés par le plan de section + //en tenant compte des triangles coup‰s par le plan de section for (i=1;i<=nbTriangles;i++) - { - Determinant=0; - //Gardons la meme orientation des noeuds - if (F.Orientation() == TopAbs_REVERSED) - triangles(i).Get(noeud[0], noeud[2], noeud[1]); - else - triangles(i).Get(noeud[0], noeud[1], noeud[2]); - + { + Determinant=0; + //Gardons la meme orientation des noeuds + if (F.Orientation() == TopAbs_REVERSED) + triangles(i).Get(noeud[0], noeud[2], noeud[1]); + else + triangles(i).Get(noeud[0], noeud[1], noeud[2]); + P[0] = Nodes(noeud[0]).Transformed(L.Transformation()); - z[0] = P[0].Z(); - P[1] = Nodes(noeud[1]).Transformed(L.Transformation()); - z[1] = P[1].Z(); + z[0] = P[0].Z(); + P[1] = Nodes(noeud[1]).Transformed(L.Transformation()); + z[1] = P[1].Z(); P[2] = Nodes(noeud[2]).Transformed(L.Transformation()); z[2] = P[2].Z(); - // Determination des cas aux limites pour les triangles - Standard_Integer i,compteur=0; + // Determination des cas aux limites pour les triangles + Standard_Integer i,compteur=0; - for (i=0;i<=2;i++) - { + for (i=0;i<=2;i++) + { flag[i]=Standard_False; - if(z[i]>=Elevation) - { - flag[i]=Standard_True; - compteur++; - } - } - - switch(compteur) - { - case 0: - Determinant = ElementaryVolume(P[0],P[1],P[2]); - break; - - case 1: - for (i=0;i<=2;i++) - { - if (flag[i]==Standard_True) - { - gp_Pnt Result1 = Intersection(P[i],P[(i+1)%3],Elevation); - gp_Pnt Result2 = Intersection(P[i],P[(i+2)%3],Elevation); - Determinant = ElementaryVolume(Result1,P[(i+1)%3],P[(i+2)%3]) - + ElementaryVolume(Result1,P[(i+2)%3],Result2); - } - } - break; - - case 2: - for (i=0;i<=2;i++) - { - if (flag[i]==Standard_False) - { - gp_Pnt Result1 = Intersection(P[i],P[(i+1)%3],Elevation); - gp_Pnt Result2 = Intersection(P[i],P[(i+2)%3],Elevation); - Determinant = ElementaryVolume(P[i],Result1,Result2); - } - } - break; - - case 3: - break; - } - Volume += Determinant; - } + if(z[i]>=Elevation) + { + flag[i]=Standard_True; + compteur++; + } + } + + switch(compteur) + { + case 0: + Determinant = ElementaryVolume(P[0],P[1],P[2]); + break; + + case 1: + for (i=0;i<=2;i++) + { + if (flag[i]==Standard_True) + { + gp_Pnt Result1 = Intersection(P[i],P[(i+1)%3],Elevation); + gp_Pnt Result2 = Intersection(P[i],P[(i+2)%3],Elevation); + Determinant = ElementaryVolume(Result1,P[(i+1)%3],P[(i+2)%3]) + + ElementaryVolume(Result1,P[(i+2)%3],Result2); + } + } + break; + + case 2: + for (i=0;i<=2;i++) + { + if (flag[i]==Standard_False) + { + gp_Pnt Result1 = Intersection(P[i],P[(i+1)%3],Elevation); + gp_Pnt Result2 = Intersection(P[i],P[(i+2)%3],Elevation); + Determinant = ElementaryVolume(P[i],Result1,Result2); + } + } + break; + + case 3: + break; + } + Volume += Determinant; + } } return Volume; @@ -248,30 +259,30 @@ Standard_Real VolumeSection::Archimede(Standard_Real Constante , Standard_Real E else { while((Bsup-Binf)>Epsilon) - { - if((tempBinfVolume-Constante)*(tempCVolume-Constante)>0 && Abs(tempCVolume-Constante)>Epsilon) - { - Binf = c; - tempBinfVolume=tempCVolume; - - c = ((Binf*(tempBsupVolume-Constante))-(Bsup*(tempBinfVolume-Constante))) - /((tempBsupVolume-Constante)-(tempBinfVolume-Constante)); + { + if((tempBinfVolume-Constante)*(tempCVolume-Constante)>0 && Abs(tempCVolume-Constante)>Epsilon) + { + Binf = c; + tempBinfVolume=tempCVolume; + + c = ((Binf*(tempBsupVolume-Constante))-(Bsup*(tempBinfVolume-Constante))) + /((tempBsupVolume-Constante)-(tempBinfVolume-Constante)); tempCVolume=CalculateVolume(c); - } - else if((tempBinfVolume-Constante)*(tempCVolume-Constante)<0 && Abs(tempCVolume-Constante)>Epsilon) - { - Bsup = c; - tempBsupVolume =tempCVolume; + } + else if((tempBinfVolume-Constante)*(tempCVolume-Constante)<0 && Abs(tempCVolume-Constante)>Epsilon) + { + Bsup = c; + tempBsupVolume =tempCVolume; - c = ((Binf*(tempBsupVolume-Constante))-(Bsup*(tempBinfVolume-Constante))) - /((tempBsupVolume-Constante)-(tempBinfVolume-Constante)); + c = ((Binf*(tempBsupVolume-Constante))-(Bsup*(tempBinfVolume-Constante))) + /((tempBsupVolume-Constante)-(tempBinfVolume-Constante)); tempCVolume=CalculateVolume(c); - } - else - { - goto endMethod; - } - } + } + else + { + goto endMethod; + } + } goto endMethod; } @@ -362,7 +373,7 @@ gp_Pnt VolumeSection::Intersection(gp_Pnt P1,gp_Pnt P2,Standard_Real Hauteur) return Point; } -//Fonction calculant le volume élémentaire de chaque tétraedre à partir de 3 points +//Fonction calculant le volume ‰l‰mentaire de chaque t‰traedre € partir de 3 points Standard_Real VolumeSection::ElementaryVolume(gp_Pnt P1,gp_Pnt P2,gp_Pnt P3) { Standard_Real Determinant; @@ -389,3 +400,4 @@ void VolumeSection::getZ( double& min, double& max) min = Zmin; max = Zmax; } +