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

janehu at mcs.anl.gov janehu at mcs.anl.gov
Wed Jun 4 15:32:48 CDT 2008


Author: janehu
Date: 2008-06-04 15:32:48 -0500 (Wed, 04 Jun 2008)
New Revision: 1874

Modified:
   cgm/trunk/geom/OCC/OCCBody.cpp
   cgm/trunk/geom/OCC/OCCBody.hpp
   cgm/trunk/geom/OCC/OCCLump.cpp
   cgm/trunk/geom/OCC/OCCModifyEngine.cpp
   cgm/trunk/geom/OCC/OCCQueryEngine.cpp
   cgm/trunk/geom/OCC/OCCShell.cpp
   cgm/trunk/geom/OCC/OCCSurface.cpp
   cgm/trunk/test/modify.cpp
Log:
fixed the Error of Edge with no vertices problem after impriinting, when use the edge to imprint, the edge become one part of the imprinted shape, so if this edge belongs to tool_shape, has to make a copy.

Modified: cgm/trunk/geom/OCC/OCCBody.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCBody.cpp	2008-06-04 18:38:23 UTC (rev 1873)
+++ cgm/trunk/geom/OCC/OCCBody.cpp	2008-06-04 20:32:48 UTC (rev 1874)
@@ -87,7 +87,6 @@
 {
   if(myTopoDSShape)
     delete myTopoDSShape;
-
   myTopoDSShape = new TopoDS_CompSolid(theshape);
 }
 
@@ -393,7 +392,56 @@
     points.get_and_step()->set_myMarked(CUBIT_FALSE);
 
 }
+
 //----------------------------------------------------------------
+// Function: TopoDS_Shape level function to update the core Body
+//           for any Boolean operation of the body.
+// Author: Jane Hu
+//----------------------------------------------------------------
+CubitStatus OCCBody::update_OCC_entity(TopoDS_Shape& old_shape,
+                                       TopoDS_Shape& new_shape,
+                                       BRepBuilderAPI_MakeShape *op)
+{
+  //set the Shells
+  TopTools_IndexedMapOfShape M;
+  TopExp::MapShapes(old_shape, TopAbs_SOLID, M);
+  TopTools_ListOfShape shapes;
+  TopoDS_Shape shape;
+
+  for(int ii=1; ii<=M.Extent(); ii++)
+  {
+    TopoDS_Solid solid = TopoDS::Solid(M(ii));
+
+    TopTools_ListOfShape shapes;
+    shapes.Assign(op->Modified(solid));
+    if (shapes.Extent() == 1)
+      shape = shapes.First();
+
+    else if(shapes.Extent() > 1)
+      shape.Nullify();
+
+    else if(op->IsDeleted(solid))
+    {
+       TopTools_IndexedMapOfShape M_new;
+       TopExp::MapShapes(new_shape, TopAbs_SOLID, M_new);
+       if (M_new.Extent()== 1)
+         shape = M_new(1);
+       else
+         shape.Nullify();
+    }
+    else
+    {
+       shape = solid;
+       continue;
+    }
+
+    if(shapes.Extent() > 0 || op->IsDeleted(solid))
+      OCCLump::update_OCC_entity(solid, shape, op);
+  }
+  if(!old_shape.IsSame(new_shape))
+    OCCQueryEngine::instance()->update_OCC_map(old_shape, new_shape);
+}
+//----------------------------------------------------------------
 // Function: update_bounding_box
 // Description: calculate for bounding box of this OCCBody
 //

Modified: cgm/trunk/geom/OCC/OCCBody.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCBody.hpp	2008-06-04 18:38:23 UTC (rev 1873)
+++ cgm/trunk/geom/OCC/OCCBody.hpp	2008-06-04 20:32:48 UTC (rev 1874)
@@ -40,6 +40,7 @@
 class OCCPoint;
 class BRepBuilderAPI_Transform;
 class BRepAlgoAPI_BooleanOperation;
+class BRepBuilderAPI_MakeShape;
 // ********** END FORWARD DECLARATIONS     **********
 
 class OCCBody : public BodySM
@@ -178,6 +179,10 @@
   CubitStatus update_OCC_entity( BRepBuilderAPI_Transform *aBRepTrsf,
                                  BRepAlgoAPI_BooleanOperation *op = NULL);
 
+  static CubitStatus update_OCC_entity(TopoDS_Shape& old_shape,
+                                       TopoDS_Shape& new_shape,
+                                       BRepBuilderAPI_MakeShape *op);
+
   OCCSurface* my_sheet_surface(){if(IsSheetBody) return mySheetSurface;
 				 return (OCCSurface*) NULL;} 
   void set_sheet_surface(OCCSurface* surface); 

Modified: cgm/trunk/geom/OCC/OCCLump.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCLump.cpp	2008-06-04 18:38:23 UTC (rev 1873)
+++ cgm/trunk/geom/OCC/OCCLump.cpp	2008-06-04 20:32:48 UTC (rev 1874)
@@ -400,5 +400,6 @@
     if(shapes.Extent() > 0 || op->IsDeleted(shell))
       OCCShell::update_OCC_entity(shell, shape, op);
   }
-  OCCQueryEngine::instance()->update_OCC_map(old_solid, new_solid);
+  if(!old_solid.IsSame(new_shape))
+    OCCQueryEngine::instance()->update_OCC_map(old_solid, new_solid);
 }

Modified: cgm/trunk/geom/OCC/OCCModifyEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCModifyEngine.cpp	2008-06-04 18:38:23 UTC (rev 1873)
+++ cgm/trunk/geom/OCC/OCCModifyEngine.cpp	2008-06-04 20:32:48 UTC (rev 1874)
@@ -2268,38 +2268,38 @@
         topo_changed = CUBIT_FALSE;
         if(splitor.IsDone())
         {
-          //take care of on_faces list first.
-          if (on_faces && on_faces->size())
+          //take care of on_faces list first:after operation, the on_faces
+          // will have at least one face changed, update the pointer.
+          if (on_faces)
           {
-            TopoDS_Face* compare_face = on_faces->get();
-            if(from_face.IsSame(*compare_face))
+            for(int k = 0; k < on_faces->size(); k++)
             {
-              on_faces->remove(compare_face);
-              TopTools_ListOfShape shapes;
-              shapes.Assign(splitor.Modified(from_face)); 
-              while(shapes.Extent() > 0)
+              TopoDS_Face* compare_face = on_faces->get_and_step();
+              if(from_face.IsSame(*compare_face))
               {
-                TopoDS_Face* face = 
-                  new TopoDS_Face(TopoDS::Face(shapes.First())); 
-                shapes.RemoveFirst();
-                on_faces->append(face);
-                list_for_delete.append(face);
+                on_faces->remove(compare_face);
+                TopTools_ListOfShape shapes;
+                shapes.Assign(splitor.Modified(from_face)); 
+                while(shapes.Extent() > 0)
+                {
+                  TopoDS_Face* face = 
+                    new TopoDS_Face(TopoDS::Face(shapes.First())); 
+                  shapes.RemoveFirst();
+                  on_faces->append(face);
+                  list_for_delete.append(face);
+                }
               }
             }
           }
+
           TopoDS_Shape new_from_shape = splitor.Shape();
           if(from_shape->TShape()->ShapeType() == TopAbs_COMPSOLID)
           {
-            TopTools_IndexedMapOfShape M;
-            TopExp::MapShapes(*from_shape, TopAbs_SOLID, M);
-            if (M.Extent() == 1)
-            {
-              TopoDS_Solid old_solid = TopoDS::Solid(M(1));
-              OCCLump::update_OCC_entity(old_solid, new_from_shape, &splitor);
-              from_shape->Nullify();
-              delete from_shape;
-              from_shape = new TopoDS_Shape(new_from_shape);
-            }
+            TopoDS_CompSolid old_csolid = TopoDS::CompSolid(*from_shape);
+            OCCBody::update_OCC_entity(old_csolid, new_from_shape, &splitor);
+            from_shape->Nullify();
+            delete from_shape;
+            from_shape = new TopoDS_Shape(new_from_shape);
           }
 
           else if(from_shape->TShape()->ShapeType() == TopAbs_SOLID)
@@ -2399,7 +2399,12 @@
     if (shapes.First().TShape()->ShapeType() != TopAbs_EDGE)
       continue;
     if(edge == NULL)
-      edge = new TopoDS_Edge(TopoDS::Edge(shapes.First()));
+    {
+      TopoDS_Edge common_edge = TopoDS::Edge(shapes.First());
+       BRepBuilderAPI_Copy api_copy(common_edge);
+       TopoDS_Shape newShape = api_copy.ModifiedShape(common_edge);
+       edge = new TopoDS_Edge(TopoDS::Edge(newShape));
+    }
     from_faces.append(new TopoDS_Face(face));
   }
   return edge;
@@ -2811,34 +2816,10 @@
         TopExp_Explorer Ex;
         TopoDS_Face the_face;
         TopoDS_Shape ashape = *(body->get_TopoDS_Shape());
-        if (OCCQueryEngine::instance()->OCCMap->IsBound(ashape))
-          TopExp::MapShapesAndAncestors(ashape, TopAbs_FACE, TopAbs_SOLID, M);
-        else
-	{
-          DLIList<Lump*> lumps = body->lumps();
-          for(int i = 0; i < lumps.size(); i++)
-          {
-            OCCLump *occ_lump = (OCCLump *) lumps.get_and_step();
-            TopExp::MapShapesAndAncestors(*occ_lump->get_TopoDS_Solid(),
-                                    TopAbs_FACE, TopAbs_SOLID, M);
-          }
-        }  
+        TopExp::MapShapesAndAncestors(ashape, TopAbs_FACE, TopAbs_COMPSOLID, M);
         if(!M.Contains(*topo_face))
           continue; 
-        const TopTools_ListOfShape& ListOfShapes =
-                              M.FindFromKey(*topo_face);
-        if (!ListOfShapes.IsEmpty())
-        {
-          TopTools_ListIteratorOfListOfShape it(ListOfShapes) ;
-          for (;it.More(); it.Next())
-          {
-            TopoDS_Solid solid = TopoDS::Solid(it.Value());
-            int k = oqe->OCCMap->Find(solid);
-            OCCLump* lump = (OCCLump*)oqe->OccToCGM->find(k)->second;
-            if(lump && lump->get_TopoDS_Solid())
-              shape_list.append_unique(lump->get_TopoDS_Solid());
-          }
-        }
+        shape_list.append_unique(body->get_TopoDS_Shape());
       }
     }
   }
@@ -2880,6 +2861,8 @@
     if (edge->IsNull())
       continue;
 
+    DLIList<OCCPoint*> point_list;
+    curve->get_points(point_list);
     for(int j = 0; j < shape_list.size(); j ++)
     {
       TopoDS_Shape* shape = shape_list.get_and_step();
@@ -2891,8 +2874,23 @@
   {
     DLIList<TopologyBridge*> tbs;
     TopoDS_Shape* shape = shape_list.get_and_step();
-    tbs += OCCQueryEngine::instance()->populate_topology_bridge(*shape);
-    new_body_list.append(CAST_TO(tbs.get(),BodySM));
+    if (shape->TShape()->ShapeType() == TopAbs_COMPSOLID)
+    {
+      if(!OCCQueryEngine::instance()->OCCMap->IsBound(*shape)) 
+      {
+        TopExp_Explorer Ex;
+        for (Ex.Init(*shape, TopAbs_SOLID);Ex.More(); Ex.Next())
+        {
+          tbs += OCCQueryEngine::instance()->populate_topology_bridge(Ex.Current());
+          new_body_list.append_unique(CAST_TO(tbs.get(),BodySM));
+        }
+      }
+    }
+    else
+    {
+      tbs += OCCQueryEngine::instance()->populate_topology_bridge(*shape);
+      new_body_list.append_unique(CAST_TO(tbs.get(),BodySM));
+    }
   }
 
   if (keep_old)

Modified: cgm/trunk/geom/OCC/OCCQueryEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2008-06-04 18:38:23 UTC (rev 1873)
+++ cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2008-06-04 20:32:48 UTC (rev 1874)
@@ -1170,16 +1170,13 @@
   {
     int k = OCCMap->Find(aShape);
     lump = (OCCLump*)(OccToCGM->find(k))->second;
-    if (!aShape.IsSame(*lump->get_TopoDS_Solid()))
-    {
-      lump->set_TopoDS_Solid(aShape);
-      OCCBody* body = CAST_TO(lump->get_body(), OCCBody);
-      DLIList<Lump*> lumps = body->lumps();
-      TopoDS_CompSolid* new_top = body->make_CompSolid(lumps);
-      body->set_TopoDS_Shape(*new_top);
-      new_top->Nullify();
-      delete new_top;
-    }
+    lump->set_TopoDS_Solid(aShape);
+    OCCBody* body = CAST_TO(lump->get_body(), OCCBody);
+    DLIList<Lump*> lumps = body->lumps();
+    TopoDS_CompSolid* new_top = body->make_CompSolid(lumps);
+    body->set_TopoDS_Shape(*new_top);
+    new_top->Nullify();
+    delete new_top;
   }
  
   TopExp_Explorer Ex;
@@ -1349,6 +1346,7 @@
   {
     Curve* curve = populate_topology_bridge(Ex.Current());
     OCCCurve *occ_curve = CAST_TO(curve, OCCCurve);
+    DLIList<OCCLoop*> loops = occ_curve->loops();
     CubitBoolean exist = CUBIT_FALSE;
     OCCCoEdge * coedge = NULL;
     int size = coedges_old.size();
@@ -1368,8 +1366,29 @@
         break;
       }
     }   
+    
     if(!exist)
     {
+      //search through the curve loops
+      for(int i = 0; i < loops.size() ; i++)
+      {
+        OCCLoop* loop = loops.get_and_step();
+        if (!OCCMap->IsBound(*loop->get_TopoDS_Wire()))
+        { 
+          DLIList<OCCCoEdge*> coedge_list = loop->coedges();
+          for(int j = 0; j < coedge_list.size(); j++)
+          {
+            OCCCoEdge * test_coedge = coedge_list.get_and_step();
+            if (test_coedge->curve() == curve)
+            {
+              loop->remove_coedge(test_coedge);
+              occ_curve->remove_loop(loop);
+              delete test_coedge;
+            }
+          }
+          delete loop;
+        }
+      }
       coedge = new OCCCoEdge( curve, loop, sense);
       coedges_new.append(coedge);
       occ_curve->add_loop(loop);

Modified: cgm/trunk/geom/OCC/OCCShell.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCShell.cpp	2008-06-04 18:38:23 UTC (rev 1873)
+++ cgm/trunk/geom/OCC/OCCShell.cpp	2008-06-04 20:32:48 UTC (rev 1874)
@@ -279,7 +279,8 @@
     if(shapes.Extent() > 0 || op->IsDeleted(face))
       OCCSurface::update_OCC_entity(face,shape, op);
   }
-  OCCQueryEngine::instance()->update_OCC_map(old_shell, new_shell);
+  if(!old_shell.IsSame(new_shell))
+    OCCQueryEngine::instance()->update_OCC_map(old_shell, new_shell);
   return CUBIT_SUCCESS;
 }
 // ********** END PUBLIC FUNCTIONS         **********

Modified: cgm/trunk/geom/OCC/OCCSurface.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCSurface.cpp	2008-06-04 18:38:23 UTC (rev 1873)
+++ cgm/trunk/geom/OCC/OCCSurface.cpp	2008-06-04 20:32:48 UTC (rev 1874)
@@ -895,14 +895,17 @@
        else
          shape_vertex.Nullify();
 
-       if(shapes.Extent() > 0 || op->IsDeleted(vertex))
+       if(!vertex.IsSame(shape_vertex) && (shapes.Extent() > 0 || op->IsDeleted(vertex)))
          OCCQueryEngine::instance()->update_OCC_map(vertex, shape_vertex);
 
-       OCCQueryEngine::instance()->update_OCC_map(edge, shape_edge);
+       if (!edge.IsSame(shape_edge))
+         OCCQueryEngine::instance()->update_OCC_map(edge, shape_edge);
      }
-     OCCQueryEngine::instance()->update_OCC_map(wire, shape);
+     if (!wire.IsSame(shape))
+       OCCQueryEngine::instance()->update_OCC_map(wire, shape);
   }
-  OCCQueryEngine::instance()->update_OCC_map(old_surface, new_surface);
+  if (!old_surface.IsSame(new_surface))
+    OCCQueryEngine::instance()->update_OCC_map(old_surface, new_surface);
   return CUBIT_SUCCESS;
 }
 

Modified: cgm/trunk/test/modify.cpp
===================================================================
--- cgm/trunk/test/modify.cpp	2008-06-04 18:38:23 UTC (rev 1873)
+++ cgm/trunk/test/modify.cpp	2008-06-04 20:32:48 UTC (rev 1874)
@@ -167,10 +167,6 @@
   BodySM* stitched_body = NULL;
   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;
@@ -223,19 +219,19 @@
 
   // test for sphere making
   Body* test_body = gmti->sphere(5);
-  d = test_body->measure(); //d = 
+  d = test_body->measure(); //d = 523.598 
 
   //test for prism making
   test_body = gmti->prism(10, 4, 4,2);
-  d =  test_body->measure(); //d =
+  d =  test_body->measure(); //d = 320
 
   //test for pyramid making
   test_body = gmti->pyramid(10, 4, 5, 2, 3);
-  d =  test_body->measure(); //d =
+  d =  test_body->measure(); //d = 320
 
   //test for torus making
   test_body =  gmti->torus(10,5);
-  d =  test_body->measure(); //d =
+  d =  test_body->measure(); //d = 4934.8
 
   //test for planar_sheet making
   CubitVector p1(0, 0, 0);
@@ -287,29 +283,19 @@
   gti->get_free_ref_entities(free_entities);
   //there shouldn't be any free_entites.
 
-  //test for multi-cut imprint for subtract.
   from_body = gmti->brick(10, 10, 10);
   tool_body = gmti->brick(11, 1, 1);
   CubitVector v_move4(0,1,-1);
   gti->translate(from_body,v_move4);
   Body* cp_from_body = gmti->copy_body(from_body);
-  Body* cp_from_body2 = gmti->copy_body(from_body);
-  Body* cp_tool_body = gmti->copy_body(tool_body);
-  from_bodies.clean_out();
-  from_bodies.append(from_body);
-  new_bodies.clean_out();
-  rsl = gmti->subtract(tool_body, from_bodies, new_bodies,
-                       CUBIT_TRUE, CUBIT_FALSE); 
-  n = new_bodies.get()->num_ref_faces();
-  //n = 8
-  n = new_bodies.get()->num_ref_edges();
-  //n = 18
+  Body* cp_from_body2 = gmti->copy_body(cp_from_body);
 
   //test edge imprint on body
   ref_edges.clean_out();
-  cp_tool_body->ref_edges(ref_edges);
+  tool_body->ref_edges(ref_edges);
   from_bodies.clean_out();
   from_bodies.append(cp_from_body);
+  new_bodies.clean_out();
   CubitStatus stat = gmti->imprint(from_bodies, ref_edges, new_bodies, CUBIT_FALSE, CUBIT_TRUE );
 
   //test edge imprint on surface
@@ -317,17 +303,54 @@
   face_list.clean_out();
   cp_from_body2->ref_faces(face_list);
   int size = face_list.size();
+  DLIList<RefFace*> unimprint_faces;
   for(int i = 0; i < size; i++)
   {
     CubitVector v = face_list.get()->center_point();
     if(!v.about_equal(vv))
+      unimprint_faces.append(face_list.remove());
+    else
+      face_list.step();
+  }
+  assert(face_list.size() == 1);
+  new_bodies.clean_out();
+  vertices.clean_out();
+  cp_from_body2->ref_vertices(vertices);
+  vertices.clean_out();
+  ref_edges.step_and_get()->ref_vertices(vertices);
+  stat = gmti->imprint(unimprint_faces, ref_edges, new_bodies, CUBIT_FALSE);
+
+  new_bodies.clean_out();
+  face_list.clean_out();
+  cp_from_body2->ref_faces(face_list);
+  for(int i = 0; i < size; i++)
+  {
+    CubitVector v = face_list.get()->center_point();
+    if(!v.about_equal(vv))
       face_list.remove();
     else
       face_list.step();
   }
-  assert(face_list.size() == 1);
+
+  vertices.clean_out();
+  face_list.get()->ref_vertices(vertices);
+  vertices.clean_out();
+  ref_edges.step_and_get()->ref_vertices(vertices);
+
+  OCCBody* check_body = CAST_TO(face_list.get()->body()->get_body_sm_ptr(), OCCBody);
   stat = gmti->imprint(face_list, ref_edges, new_bodies, CUBIT_FALSE);
 
+  //test for multi-cut imprint for subtract.
+  from_bodies.clean_out();
+  from_bodies.append(from_body);
+  new_bodies.clean_out();
+  rsl = gmti->subtract(tool_body, from_bodies, new_bodies,
+                       CUBIT_TRUE, CUBIT_FALSE);
+  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




More information about the cgma-dev mailing list