1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: GEOMAlgo_GetInPlace_2.cxx
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_GetInPlace.hxx>
28 #include <TopAbs_ShapeEnum.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <TopoDS_Compound.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Vertex.hxx>
37 #include <BRep_Tool.hxx>
38 #include <BRep_Builder.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <GProp_GProps.hxx>
47 #include <BRepGProp.hxx>
51 Standard_Integer Dimension(const TopAbs_ShapeEnum aType);
53 void PointProperties(const TopoDS_Shape& aS,
54 GProp_GProps& aGProps);
56 //=======================================================================
57 //function : CheckGProps
59 //=======================================================================
60 void GEOMAlgo_GetInPlace::CheckGProps()
62 myFound=Standard_False;
63 CheckGProps(myArgument);
65 //=======================================================================
66 //function : CheckGProps
68 //=======================================================================
69 void GEOMAlgo_GetInPlace::CheckGProps(const TopoDS_Shape& aS1)
71 Standard_Boolean bOnlyClosed;
72 Standard_Integer iDim, aNbS2;
73 Standard_Real aMass1, aMass2, aD2, aTolCG2, dM;
74 TopAbs_ShapeEnum aType1;
79 TopTools_ListIteratorOfListOfShape aItLS;
83 aType1=aS1.ShapeType();
84 if (aType1==TopAbs_COMPOUND) {
86 for(; aIt.More(); aIt.Next()) {
87 const TopoDS_Shape& aS1x=aIt.Value();
95 iDim=Dimension(aType1);
97 if (!myImages.IsBound(aS1)) {
101 const TopTools_ListOfShape& aLS2=myImages.Find(aS1);
108 aBB.MakeCompound(aC2);
109 aItLS.Initialize(aLS2);
110 for (; aItLS.More(); aItLS.Next()) {
111 const TopoDS_Shape& aS2x=aItLS.Value();
114 //-------------------------
115 GProp_GProps aG1, aG2;
117 aTolCG2=myTolCG*myTolCG;
118 bOnlyClosed=Standard_False;
121 PointProperties(aS1, aG1);
122 PointProperties(aC2, aG2);
125 BRepGProp::LinearProperties(aS1, aG1);
126 BRepGProp::LinearProperties(aC2, aG2);
129 BRepGProp::SurfaceProperties(aS1, aG1);
130 BRepGProp::SurfaceProperties(aC2, aG2);
133 BRepGProp::VolumeProperties(aS1, aG1, bOnlyClosed);
134 BRepGProp::VolumeProperties(aC2, aG2, bOnlyClosed);
139 aCG1=aG1.CentreOfMass();
140 aCG2=aG2.CentreOfMass();
142 dM=fabs(aMass1-aMass2);
143 if (aMass1 > myTolMass) {
147 aD2=aCG1.SquareDistance(aCG2);
149 if ((dM > myTolMass) || (aD2 > aTolCG2)) {
150 myFound=Standard_False;
153 myFound=Standard_True;
155 //=======================================================================
156 //function : Dimension
158 //=======================================================================
159 Standard_Integer Dimension(const TopAbs_ShapeEnum aType)
161 Standard_Integer iDim;
177 case TopAbs_COMPSOLID:
185 //=======================================================================
186 //class : GEOMAlgo_GProps
188 //=======================================================================
189 class GEOMAlgo_GProps : public GProp_GProps {
191 GEOMAlgo_GProps() : GProp_GProps() {
194 GEOMAlgo_GProps(const gp_Pnt& aPLoc) : GProp_GProps(aPLoc) {
200 void SetMass(const Standard_Real aMass) {
204 void SetCG(const gp_Pnt& aPCG) {
208 //=======================================================================
209 //function : PointProperties
211 //=======================================================================
212 void PointProperties(const TopoDS_Shape& aS, GProp_GProps& aGProps)
214 Standard_Integer i, aNbS;
215 Standard_Real aDensity;
217 TopTools_IndexedMapOfShape aMS;
221 TopExp::MapShapes(aS, TopAbs_VERTEX, aMS);
223 for (i=1; i<=aNbS; ++i) {
224 GEOMAlgo_GProps aGPropsX;
226 const TopoDS_Vertex& aVX=*((TopoDS_Vertex*)&aMS(i));
227 aPX=BRep_Tool::Pnt(aVX);
228 aGPropsX.SetMass(1.);
230 aGProps.Add(aGPropsX, aDensity);