/src/contrib/geom-5.1.2.7/src/GEOMAlgo/GEOMAlgo_VertexSolid.cpp

http://pythonocc.googlecode.com/ · C++ · 239 lines · 160 code · 12 blank · 67 comment · 22 complexity · 624caf7c992c0afd3238139813f1c49c MD5 · raw file

  1. // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
  2. //
  3. // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
  4. // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
  5. //
  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.
  10. //
  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.
  15. //
  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
  19. //
  20. // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
  21. //
  22. // File: GEOMAlgo_VertexSolid.cxx
  23. // Created: Wed Jan 12 16:36:40 2005
  24. // Author: Peter KURNEV
  25. // <pkv@irinox>
  26. //
  27. #include <GEOMAlgo_VertexSolid.ixx>
  28. #include <gp_Pnt.hxx>
  29. #include <TopAbs_ShapeEnum.hxx>
  30. #include <TopAbs_State.hxx>
  31. #include <TopTools_ListIteratorOfListOfShape.hxx>
  32. #include <TopTools_ListOfShape.hxx>
  33. #include <TopTools_IndexedMapOfShape.hxx>
  34. #include <TopoDS.hxx>
  35. #include <TopoDS_Solid.hxx>
  36. #include <TopoDS_Vertex.hxx>
  37. #include <TopExp.hxx>
  38. #include <BRep_Tool.hxx>
  39. #include <BRepClass3d_SolidClassifier.hxx>
  40. #include <BOPTColStd_Dump.hxx>
  41. #include <IntTools_Context.hxx>
  42. #include <BooleanOperations_StateOfShape.hxx>
  43. #include <BooleanOperations_ShapesDataStructure.hxx>
  44. #include <BOPTools_InterferencePool.hxx>
  45. #include <BOPTools_CArray1OfVVInterference.hxx>
  46. #include <BOPTools_VVInterference.hxx>
  47. #include <BOPTools_PaveFiller.hxx>
  48. #include <BOPTools_DSFiller.hxx>
  49. //=======================================================================
  50. //function : GEOMAlgo_VertexSolid
  51. //purpose :
  52. //=======================================================================
  53. GEOMAlgo_VertexSolid::GEOMAlgo_VertexSolid()
  54. :
  55. GEOMAlgo_ShapeSolid()
  56. {
  57. }
  58. //=======================================================================
  59. //function : ~
  60. //purpose :
  61. //=======================================================================
  62. GEOMAlgo_VertexSolid::~GEOMAlgo_VertexSolid()
  63. {
  64. }
  65. //=======================================================================
  66. // function: Perform
  67. // purpose:
  68. //=======================================================================
  69. void GEOMAlgo_VertexSolid::Perform()
  70. {
  71. myErrorStatus=0;
  72. //
  73. try {
  74. if (myDSFiller==NULL) {
  75. myErrorStatus=10;
  76. return;
  77. }
  78. if(!myDSFiller->IsDone()) {
  79. myErrorStatus=11;
  80. return;
  81. }
  82. //
  83. Standard_Boolean bIsNewFiller;
  84. Standard_Integer aNbF;
  85. TopTools_IndexedMapOfShape aM;
  86. //
  87. const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
  88. const TopoDS_Shape& aObj=aDS.Object();
  89. //
  90. TopExp::MapShapes(aObj, TopAbs_FACE, aM);
  91. aNbF=aM.Extent();
  92. myRank=(aNbF) ? 2 : 1;
  93. //
  94. bIsNewFiller=myDSFiller->IsNewFiller();
  95. if (bIsNewFiller) {
  96. Prepare();
  97. myDSFiller->SetNewFiller(!bIsNewFiller);
  98. }
  99. BuildResult();
  100. }
  101. //
  102. catch (Standard_Failure) {
  103. myErrorStatus = 12;
  104. }
  105. }
  106. //=======================================================================
  107. // function: Prepare
  108. // purpose:
  109. //=======================================================================
  110. void GEOMAlgo_VertexSolid::Prepare()
  111. {
  112. Standard_Integer i, iBeg, iEnd, aNbVV, j, n1, n2, iFound;
  113. Standard_Real aTol;
  114. TopAbs_State aSt;
  115. TopAbs_ShapeEnum aType;
  116. BooleanOperations_StateOfShape aState;
  117. gp_Pnt aP3D;
  118. //
  119. const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
  120. BooleanOperations_ShapesDataStructure* pDS=(BooleanOperations_ShapesDataStructure*)&aDS;
  121. const BOPTools_InterferencePool& aIP=myDSFiller->InterfPool();
  122. BOPTools_InterferencePool* pIP=(BOPTools_InterferencePool*) &aIP;
  123. BOPTools_CArray1OfVVInterference& aVVs=pIP->VVInterferences();
  124. const BOPTools_PaveFiller& aPF=myDSFiller->PaveFiller();
  125. BOPTools_PaveFiller* pPF=(BOPTools_PaveFiller*)&aPF;
  126. IntTools_Context& aCtx=pPF->ChangeContext();
  127. //
  128. const TopoDS_Shape& aObj=aDS.Object();
  129. const TopoDS_Shape& aTool=aDS.Tool();
  130. //
  131. const TopoDS_Solid& aSolid=(myRank==1) ? TopoDS::Solid(aTool) : TopoDS::Solid(aObj);
  132. const TopoDS_Shape& aSV =(myRank==1)? aObj : aTool;
  133. //
  134. BRepClass3d_SolidClassifier& aSC=aCtx.SolidClassifier(aSolid);
  135. //
  136. iBeg=1;
  137. iEnd=aDS.NumberOfShapesOfTheObject();
  138. if (myRank==2) {
  139. iBeg=iEnd+1;
  140. iEnd=aDS.NumberOfSourceShapes();
  141. }
  142. //
  143. for (i=iBeg; i<=iEnd; ++i) {
  144. aType=aDS.GetShapeType(i);
  145. if (aType!=TopAbs_VERTEX) {
  146. continue;
  147. }
  148. //
  149. const TopoDS_Vertex& aV=TopoDS::Vertex(aDS.Shape(i));
  150. //
  151. aState=aDS.GetState(i);
  152. if (aState==BooleanOperations_ON ||
  153. aState==BooleanOperations_IN ||
  154. aState==BooleanOperations_OUT) {
  155. continue;
  156. }
  157. //
  158. iFound=0;
  159. aNbVV=aVVs.Extent();
  160. for (j=1; j<=aNbVV; ++j) {
  161. BOPTools_VVInterference& aVV=aVVs(j);
  162. aVV.Indices(n1, n2);
  163. if (n1==i || n2==i) {
  164. pDS->SetState (n1, BooleanOperations_ON);
  165. pDS->SetState (n2, BooleanOperations_ON);
  166. iFound=1;
  167. break;
  168. }
  169. }
  170. if (iFound) {
  171. continue;
  172. }
  173. //
  174. aP3D=BRep_Tool::Pnt(aV);
  175. aTol=1.E-7;
  176. aSC.Perform(aP3D, aTol);
  177. aSt=aSC.State();
  178. if (aSt==TopAbs_IN) {
  179. pDS->SetState (i, BooleanOperations_IN);
  180. }
  181. else if (aSt==TopAbs_OUT) {
  182. pDS->SetState (i, BooleanOperations_OUT);
  183. }
  184. }
  185. }
  186. //=======================================================================
  187. // function: BuildResult
  188. // purpose:
  189. //=======================================================================
  190. void GEOMAlgo_VertexSolid::BuildResult()
  191. {
  192. const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
  193. //
  194. Standard_Integer i, iBeg, iEnd;
  195. TopAbs_ShapeEnum aType;
  196. BooleanOperations_StateOfShape aState;
  197. //
  198. myLSIN.Clear();
  199. myLSOUT.Clear();
  200. myLSON.Clear();
  201. //
  202. iBeg=1;
  203. iEnd=aDS.NumberOfShapesOfTheObject();
  204. if (myRank==2) {
  205. iBeg=iEnd+1;
  206. iEnd=aDS.NumberOfSourceShapes();
  207. }
  208. //
  209. for (i=iBeg; i<=iEnd; ++i) {
  210. aType=aDS.GetShapeType(i);
  211. if (aType!=TopAbs_VERTEX) {
  212. continue;
  213. }
  214. const TopoDS_Shape& aV=aDS.Shape(i);
  215. aState=aDS.GetState(i);
  216. //
  217. if (aState==BooleanOperations_IN) {
  218. myLSIN.Append(aV);
  219. }
  220. else if (aState==BooleanOperations_OUT) {
  221. myLSOUT.Append(aV);
  222. }
  223. else if (aState==BooleanOperations_ON) {
  224. myLSON.Append(aV);
  225. }
  226. }
  227. }