[cgma-dev] r1807 - in cgm/trunk: geom/OCC test

janehu at mcs.anl.gov janehu at mcs.anl.gov
Tue May 13 12:44:25 CDT 2008


Author: janehu
Date: 2008-05-13 12:44:25 -0500 (Tue, 13 May 2008)
New Revision: 1807

Modified:
   cgm/trunk/geom/OCC/OCCBody.cpp
   cgm/trunk/geom/OCC/OCCBody.hpp
   cgm/trunk/geom/OCC/OCCCurve.cpp
   cgm/trunk/geom/OCC/OCCCurve.hpp
   cgm/trunk/geom/OCC/OCCLoop.cpp
   cgm/trunk/geom/OCC/OCCLoop.hpp
   cgm/trunk/geom/OCC/OCCLump.cpp
   cgm/trunk/geom/OCC/OCCLump.hpp
   cgm/trunk/geom/OCC/OCCPoint.cpp
   cgm/trunk/geom/OCC/OCCPoint.hpp
   cgm/trunk/geom/OCC/OCCQueryEngine.cpp
   cgm/trunk/geom/OCC/OCCSurface.cpp
   cgm/trunk/geom/OCC/OCCSurface.hpp
   cgm/trunk/test/modify.cpp
Log:
Solved the memory leak problem, passed subtract operation test, in which surface and downbelow entities are reused as possible. This is a big step for boolean operation.

Modified: cgm/trunk/geom/OCC/OCCBody.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCBody.cpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCBody.cpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -81,8 +81,17 @@
 {
   myLumps.clean_out();
   myLumps += my_lumps;
+  myTopoDSShape = NULL;
 }
 
+void OCCBody::set_TopoDS_Shape( TopoDS_CompSolid theshape)
+{
+  if(myTopoDSShape)
+    *myTopoDSShape = theshape;
+  else
+    myTopoDSShape = new TopoDS_CompSolid(theshape);
+}
+
 OCCBody::OCCBody(DLIList<Lump*>& my_lumps)
 {
   myLumps += my_lumps;

Modified: cgm/trunk/geom/OCC/OCCBody.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCBody.hpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCBody.hpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -67,7 +67,7 @@
     //- associated with the object.
   
   TopoDS_CompSolid *get_TopoDS_Shape() {return myTopoDSShape; }
-  void set_TopoDS_Shape( TopoDS_CompSolid theshape){*myTopoDSShape = theshape;}
+  void set_TopoDS_Shape( TopoDS_CompSolid theshape);
 
   virtual CubitStatus get_transforms( CubitTransformMatrix &tfm );
   //R CubitStatus

Modified: cgm/trunk/geom/OCC/OCCCurve.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCCurve.cpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCCurve.cpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -115,6 +115,13 @@
     delete myTopoDSEdge;
 }
 
+void OCCCurve::set_TopoDS_Edge(TopoDS_Edge edge)
+{
+  if(!myTopoDSEdge)
+    myTopoDSEdge = new TopoDS_Edge;
+  *myTopoDSEdge = edge;
+}
+
 //-------------------------------------------------------------------------
 // Purpose       : The purpose of this function is to append a
 //                 attribute to the GE. The name is attached to the 

Modified: cgm/trunk/geom/OCC/OCCCurve.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCCurve.hpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCCurve.hpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -321,7 +321,7 @@
 
   TopoDS_Edge *get_TopoDS_Edge( )
     { return myTopoDSEdge; } 
-  void set_TopoDS_Edge(TopoDS_Edge edge){*myTopoDSEdge = edge;}
+  void set_TopoDS_Edge(TopoDS_Edge edge);
 
   void update_OCC_entity( BRepBuilderAPI_Transform *aBRepTrsf,
                           BRepAlgoAPI_BooleanOperation *op = NULL );

Modified: cgm/trunk/geom/OCC/OCCLoop.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCLoop.cpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCLoop.cpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -66,6 +66,12 @@
     delete myTopoDSWire;
 }
 
+void OCCLoop::set_TopoDS_Wire(TopoDS_Wire loop)
+{
+   if(!myTopoDSWire)
+     myTopoDSWire = new TopoDS_Wire;
+   *myTopoDSWire = loop;
+}
 //-------------------------------------------------------------------------
 // Purpose       : Tear down topology
 //

Modified: cgm/trunk/geom/OCC/OCCLoop.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCLoop.hpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCLoop.hpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -48,7 +48,7 @@
   void disconnect_all_curves();
 
   inline TopoDS_Wire* get_TopoDS_Wire() {return myTopoDSWire;}
-  void set_TopoDS_Wire(TopoDS_Wire loop){ *myTopoDSWire = loop;}
+  void set_TopoDS_Wire(TopoDS_Wire loop);
 
   virtual ~OCCLoop() ;
     //- The destructor

Modified: cgm/trunk/geom/OCC/OCCLump.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCLump.cpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCLump.cpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -78,6 +78,13 @@
     delete myTopoDSSolid;
 }
 
+void OCCLump::set_TopoDS_Solid(TopoDS_Solid solid)
+{
+  if(myTopoDSSolid)
+    *myTopoDSSolid = solid;
+  else
+    myTopoDSSolid = new TopoDS_Solid(solid);
+}
 //-------------------------------------------------------------------------
 // Purpose       : Find centroid
 //
@@ -351,8 +358,9 @@
   TopTools_IndexedMapOfShape M;
   TopoDS_Shape shape;
   TopExp::MapShapes(new_shape, TopAbs_SOLID,M);
+  CubitBoolean is_null_new_shape = CUBIT_FALSE;
   if(M.Extent() > 1)
-    new_shape.Nullify();
+    is_null_new_shape = CUBIT_TRUE;
 
   M.Clear();
   TopExp::MapShapes(old_solid, TopAbs_SHELL, M);
@@ -389,7 +397,7 @@
       OCCShell::update_OCC_entity(shell, shape, op);
   }
   TopoDS_Solid new_solid;
-  if(!new_shape.IsNull() && !op->IsDeleted(old_solid))
+  if(!is_null_new_shape && !op->IsDeleted(old_solid))
     new_solid = TopoDS::Solid(new_shape);
   OCCQueryEngine::instance()->update_OCC_map(old_solid, new_solid);
 }

Modified: cgm/trunk/geom/OCC/OCCLump.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCLump.hpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCLump.hpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -59,7 +59,7 @@
     {myBodyPtr = new_body;}
     
   TopoDS_Solid *get_TopoDS_Solid(){ return myTopoDSSolid; }
-  void set_TopoDS_Solid(TopoDS_Solid solid) {*myTopoDSSolid = solid;}
+  void set_TopoDS_Solid(TopoDS_Solid solid); 
 
   virtual void append_simple_attribute_virt(CubitSimpleAttrib*);
     //R void

Modified: cgm/trunk/geom/OCC/OCCPoint.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCPoint.cpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCPoint.cpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -86,6 +86,12 @@
     delete myTopoDSVertex;
 }
 
+void OCCPoint::set_TopoDS_Vertex(TopoDS_Vertex vertex)
+{
+  if(!myTopoDSVertex)
+    myTopoDSVertex = new TopoDS_Vertex;
+  *myTopoDSVertex = vertex;
+}
 //-------------------------------------------------------------------------
 // Purpose       : The purpose of this function is to append a
 //                 attribute to the GE. The name is attached to the 

Modified: cgm/trunk/geom/OCC/OCCPoint.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCPoint.hpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCPoint.hpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -67,7 +67,7 @@
   void set_myMarked(CubitBoolean marked) {myMarked = marked;}
 
   TopoDS_Vertex *get_TopoDS_Vertex(){return myTopoDSVertex; }
-  void set_TopoDS_Vertex(TopoDS_Vertex vertex){*myTopoDSVertex = vertex;}
+  void set_TopoDS_Vertex(TopoDS_Vertex vertex);
 
   virtual void append_simple_attribute_virt(CubitSimpleAttrib*);
     //R void

Modified: cgm/trunk/geom/OCC/OCCQueryEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -1636,9 +1636,8 @@
      unhook_Lump_from_OCC(lump);
   }
 
-  delete shape;
-  TopoDS_CompSolid Nullshape;
-  occ_body->set_TopoDS_Shape(Nullshape);
+  if (!shape->IsNull())
+    shape->Nullify();
   return CUBIT_SUCCESS;
 } 
   
@@ -1689,9 +1688,8 @@
   if (occ_lump->get_body() != NULL)
     BodyList->remove(CAST_TO(occ_lump->get_body(), OCCBody));
 
-  delete solid;
-  TopoDS_Solid Nullsolid;
-  occ_lump->set_TopoDS_Solid(Nullsolid);
+  if(!solid->IsNull())
+     solid->Nullify();
   return CUBIT_SUCCESS;
 } 
 
@@ -1729,9 +1727,8 @@
         PRINT_ERROR("The OccSurface and TopoDS_Face pair is not in the map!");
     }
 
-  delete Shell;
-  TopoDS_Shell Nullshell;
-  occ_shell->set_TopoDS_Shell(Nullshell);
+  if(!Shell->IsNull())
+    Shell->Nullify();
   return CUBIT_SUCCESS;
 }
 
@@ -1826,9 +1823,8 @@
         PRINT_WARNING("The OccSurface and TopoDS_Face pair is not in the map!");
     }
   SurfaceList->remove(fsurf);
-  delete face;
-  TopoDS_Face Nullface;
-  fsurf->set_TopoDS_Face(Nullface);
+  if(!face->IsNull())
+    face->Nullify();
   return CUBIT_SUCCESS;
 }
 
@@ -1907,9 +1903,8 @@
         PRINT_ERROR("The OccLoop and TopoDS_Wire pair is not in the map!");
     }
 
-  delete wire; 
-  TopoDS_Wire Nullwire;
-  occ_loop->set_TopoDS_Wire(Nullwire);
+  if(!wire->IsNull())
+    wire->Nullify(); 
   return CUBIT_SUCCESS;
 }
 
@@ -2012,9 +2007,8 @@
         PRINT_WARNING("The OccCurve and TopoDS_Edge pair is not in the map!");
     }
   CurveList->remove(fcurve); 
-  delete edge;
-  TopoDS_Edge Nulledge;
-  fcurve->set_TopoDS_Edge(Nulledge);
+  if(!edge->IsNull())
+    edge->Nullify();
   return CUBIT_SUCCESS;
 }
 //-------------------------------------------------------------------------
@@ -2071,9 +2065,8 @@
       if(!OccToCGM->erase(k))
         PRINT_ERROR("The OccPoint and TopoDS_Vertex pair is not in the map!");
     }
-  delete vertex;
-  TopoDS_Vertex Nullvertex;
-  fpoint->set_TopoDS_Vertex(Nullvertex);
+  if(!vertex->IsNull())
+    vertex->Nullify();
   return CUBIT_SUCCESS;
 }
 

Modified: cgm/trunk/geom/OCC/OCCSurface.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCSurface.cpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCSurface.cpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -98,7 +98,14 @@
     delete myTopoDSFace;
 }
 
+void OCCSurface::set_TopoDS_Face(TopoDS_Face face)
+{
+  if(!myTopoDSFace)
+    myTopoDSFace = new TopoDS_Face; 
+  *myTopoDSFace = face;
+}
 
+
 //-------------------------------------------------------------------------
 // Purpose       : The purpose of this function is to append a
 //                 attribute to the GE. The name is attached to the 

Modified: cgm/trunk/geom/OCC/OCCSurface.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCSurface.hpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/geom/OCC/OCCSurface.hpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -302,7 +302,7 @@
     //- values.
   
   TopoDS_Face *get_TopoDS_Face(){return myTopoDSFace;}
-  void set_TopoDS_Face(TopoDS_Face face) {*myTopoDSFace = face;}
+  void set_TopoDS_Face(TopoDS_Face face); 
 
   void get_loops(DLIList<OCCLoop*>&);
 

Modified: cgm/trunk/test/modify.cpp
===================================================================
--- cgm/trunk/test/modify.cpp	2008-05-12 23:09:12 UTC (rev 1806)
+++ cgm/trunk/test/modify.cpp	2008-05-13 17:44:25 UTC (rev 1807)
@@ -34,6 +34,8 @@
 #include "OCCCurve.hpp"
 #include "OCCShell.hpp"
 #include "TopoDS_Shape.hxx"
+#include "RefEntityName.hpp"
+#include "RefEntityFactory.hpp"
 
 // forward declare some functions used and defined later
 CubitStatus read_geometry(int, char **);
@@ -103,6 +105,7 @@
 
 CubitStatus make_Point()
 {
+  RefEntityFactory* ref = RefEntityFactory::instance();
   GeometryQueryTool *gti = GeometryQueryTool::instance();
   GeometryModifyTool *gmti = GeometryModifyTool::instance();
 
@@ -114,8 +117,8 @@
   DLIList<OCCSurface*> occ_surfaces;
   CAST_TO(bodysm, OCCBody)->get_all_surfaces(occ_surfaces);  
   DLIList<RefFace*> ref_faces;
+  DLIList<RefEdge*> ref_edges;
   body->ref_faces(ref_faces);
-  
 
   DLIList<RefFace*> faces_to_stitch;
   for(int i = 0 ; i < ref_faces.size(); i++)
@@ -125,28 +128,39 @@
 	faces_to_stitch.append(refface);
   }
 
+  gti->delete_Body(body);
+
   DLIList<BodySM*> bodysm_list;
+  DLIList<RefFace*> face_list;
+  DLIList<Surface*> surface_list;
+  DLIList<RefVertex*> vertices;
+  CubitVector v(15,0,0);
   for(int i = 0; i < faces_to_stitch.size(); i++)
   {
     //move each refface by (15,0,0)
     RefFace* refface = faces_to_stitch.get_and_step();
+    refface->ref_vertices(vertices);
     Body* body = refface->ref_volume()->get_body_ptr();
-    BodySM* bodysm = body->get_body_sm_ptr();
+    bodysm = body->get_body_sm_ptr();
+    Surface* surface = refface->get_surface_ptr();
+    surface_list.append(surface);
     bodysm_list.append(bodysm);
-    CubitVector v(15,0,0);
     gti->translate(body, v);
+    body->ref_faces(face_list);
+    occ_surfaces.clean_out();
+    CAST_TO(bodysm, OCCBody)->get_all_surfaces(occ_surfaces);
   }
 
-  //stitch surfaces together
+  //create solid from surfaces 
   GeometryModifyEngine *gme = gmti->get_engine(occ_surfaces.get());
   BodySM* stitched_body = NULL;
-  CubitStatus stat = gme->stitch_surfs(bodysm_list, stitched_body);
-  Body* body2;
-  if (stat)
-    body2 = gti->make_Body(stitched_body);
-     
-  CubitVector v = body2->center_point();
-  
+  DLIList<Body*> new_bodies;
+  gmti->create_solid_bodies_from_surfs(face_list, new_bodies);
+  //ome->stitch_surfs(bodysm_list, bodysm);
+  //Lump* lump = ome->make_Lump(surface_list);
+  //bodysm = CAST_TO(lump, OCCLump)->get_body();
+  //gti->make_Body(bodysm);
+
   CubitStatus rsl = CUBIT_SUCCESS;
   DLIList<RefEntity*> ref_entity_list;
   int num_ents_exported=0;
@@ -203,19 +217,33 @@
 
   //test for subtract
   from_body = gmti->brick(10, 10, 10);
-  from_body2 = gmti->brick(4, 4, 4);
-  tool_body = gmti->brick(1, 1, 1);  
+  int width = 10; //we can also test for width < 10
+  from_body2 = gmti->brick(4, width, 4);
+  tool_body = gmti->brick(10, 10, 10);  
   CubitVector v_move(1,0,-1);
+  CubitVector v_movei(0,0,1);
   gti->translate(from_body2,v_move);
+  gti->translate(tool_body, v_movei);
   DLIList<Body*> from_bodies;
   from_bodies.append(from_body);
-  from_bodies.append(from_body2);
-  DLIList<Body*>  new_bodies;
-  rsl = gmti->subtract(tool_body, from_bodies, new_bodies, 
-                       CUBIT_TRUE, CUBIT_TRUE);
+  new_bodies.clean_out();
+  rsl = gmti->subtract(from_body2, from_bodies, new_bodies, 
+                       CUBIT_TRUE, CUBIT_FALSE);
+  //new bodies has one body, new body has 10 ref-faces, 5 of them are remaining
+  //with old id, 5 of them are new faces.
+  from_bodies=new_bodies;
+  new_bodies.clean_out();
+  rsl = gmti->subtract(tool_body,from_bodies, new_bodies,
+                       CUBIT_TRUE, CUBIT_FALSE);
   d = new_bodies.step_and_get()->measure();
   v = new_bodies.get()->center_point();
+  int n = new_bodies.get()->num_ref_faces();
+  // n = 6
+  //new bodies has 2 bodies, one has a volume = 10 and the other has a 
+  //volume = 50; each of them has 6 ref_faces, of which 3 are new and 3 are
+  //remaining (unchanged or modified).
 
+/*
   from_bodies.clean_out();
   from_bodies += new_bodies;
   new_bodies.clean_out();
@@ -227,8 +255,10 @@
   rsl = gmti->subtract(tool_body, from_bodies, new_bodies,
                        CUBIT_TRUE, CUBIT_FALSE);
   d = new_bodies.step_and_get()->measure();
-  int n = new_bodies.get()->num_ref_faces();
+  n = new_bodies.get()->num_ref_faces();
+  // n = 8
   n = new_bodies.get()->num_ref_edges();
+  // n = 22
 
   bodies.clean_out();
   gti->bodies(bodies);
@@ -246,8 +276,10 @@
   rsl = gmti->subtract(tool_body, from_bodies, new_bodies,
                        CUBIT_TRUE, CUBIT_TRUE); 
   n = new_bodies.get()->num_ref_faces();
+  //n = 8
   n = new_bodies.get()->num_ref_edges();
-
+  //n = 18
+*/
   bodies.clean_out();
   gti->bodies(bodies);
   //delete all entities
@@ -264,7 +296,7 @@
   for (int i = 0; i < tool_body->num_ref_faces(); i++)
   {
     RefFace* face = reffaces.get_and_step();
-    v = face->center_point();
+    CubitVector v = face->center_point();
     if (v.about_equal(v1) || v.about_equal(v2))
       surfaces.append(face->get_surface_ptr());
   } 
@@ -288,17 +320,31 @@
   from_body2 = gti->make_Body(bodysm); 
 
   tool_body  = gmti->brick(4, 4, 4);
-  CubitVector v_move3(1,0,0);
+  BodySM* copy_bodysm = ome->copy_body(tool_body->get_body_sm_ptr());
+  CubitVector v_move3(0,1,0);
   gti->translate(tool_body,v_move3);
-  from_bodies.clean_out();
+/*  from_bodies.clean_out();
   from_bodies.append(from_body2);
   new_bodies.clean_out();
 
+  //test face body imprint
+  TopoDS_Shape* tool_shape = CAST_TO(copy_bodysm,OCCBody)->get_TopoDS_Shape();  
+  TopoDS_Shape* from_shape = CAST_TO(body_list[0],OCCBody)->my_sheet_surface()->get_TopoDS_Face(); 
+  ome->imprint_toposhapes(tool_shape, from_shape);
+
+  //test shell body imprint.
+  from_shape = CAST_TO(bodysm,OCCBody)->shell()->get_TopoDS_Shell();
+  ome->imprint_toposhapes(tool_shape, from_shape);
+
   //test body cutting a shell, one surface got cut as the result. 
+  CubitVector v_move6(1,-1,0);
+  gti->translate(tool_body,v_move6);
   rsl = gmti->subtract(tool_body, from_bodies, new_bodies,
                        CUBIT_TRUE, CUBIT_TRUE);
   d = new_bodies.step_and_get()->measure();
   v = new_bodies.get()->center_point();
+  n = new_bodies.get()->num_ref_faces();
+  // n = 1
  
   from_bodies.clean_out();
   from_bodies.append(tool_body);
@@ -312,9 +358,10 @@
   CubitVector v_move5(0,0.5,0);
   gti->translate(tool_body,v_move5);
   from_body = gmti->brick(1,1,1);
-  TopoDS_Shape* from_shape = CAST_TO(from_body->get_body_sm_ptr(), OCCBody)->get_TopoDS_Shape();
-  TopoDS_Shape* tool_shape = CAST_TO(tool_body->get_body_sm_ptr(),OCCBody)->get_TopoDS_Shape();
+  from_shape = CAST_TO(from_body->get_body_sm_ptr(), OCCBody)->get_TopoDS_Shape();
+  tool_shape = CAST_TO(tool_body->get_body_sm_ptr(),OCCBody)->get_TopoDS_Shape();
   ome->imprint_toposhapes(tool_shape, from_shape);
   ome->imprint_toposhapes(from_shape, tool_shape);
   return stat;
+*/
 }




More information about the cgma-dev mailing list