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

janehu at mcs.anl.gov janehu at mcs.anl.gov
Fri Apr 4 14:12:40 CDT 2008


Author: janehu
Date: 2008-04-04 14:12:40 -0500 (Fri, 04 Apr 2008)
New Revision: 1743

Modified:
   cgm/trunk/geom/OCC/OCCModifyEngine.cpp
   cgm/trunk/test/modify.cpp
Log:
Succeeded in doing body body imprinting, test passed.

Modified: cgm/trunk/geom/OCC/OCCModifyEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCModifyEngine.cpp	2008-04-04 15:05:29 UTC (rev 1742)
+++ cgm/trunk/geom/OCC/OCCModifyEngine.cpp	2008-04-04 19:12:40 UTC (rev 1743)
@@ -44,6 +44,7 @@
 #include "BRepOffsetAPI_ThruSections.hxx"
 #include "BRepPrimAPI_MakeTorus.hxx"
 #include "BRepPrimAPI_MakeCylinder.hxx"
+#include "BRepBuilderAPI_Transform.hxx"
 #include "GC_MakeEllipse.hxx"
 #include "BRepBuilderAPI_MakeEdge.hxx"
 #include "BRepAdaptor_Surface.hxx"
@@ -1791,6 +1792,7 @@
 
   //list of face on from_shape that has been imprinted
   DLIList<TopoDS_Face*> from_faces; 
+  double tol = OCCQueryEngine::instance()->get_sme_resabs_tolerance();
   while( more_face)
   {
       TopOpeBRep_ShapeIntersector intersector;
@@ -1821,6 +1823,8 @@
 
 	  TopoDS_Shape face2 = intersector.ChangeFacesIntersector().Face(2);
 	  BRepAlgoAPI_Section section(face1, face2);
+
+          //intersection edges between face1 and face2
 	  TopTools_ListOfShape temp_list_of_edges;
 	  temp_list_of_edges.Assign(section.SectionEdges());
 	  int num_edges = temp_list_of_edges.Extent();
@@ -1856,10 +1860,17 @@
               TopoDS_Edge temp_edge = TopoDS::Edge(temp_Itor.Value());
               Itor.Initialize(list_of_edges);
               CubitBoolean same_edge = CUBIT_FALSE;
+              
+              GProp_GProps myProps1;
+              BRepGProp::LinearProperties(temp_edge, myProps1);
+              gp_Pnt center1 = myProps1.CentreOfMass();
               for(; Itor.More(); Itor.Next())
               {
                 TopoDS_Edge edge = TopoDS::Edge(Itor.Value());
-                if(edge.IsSame(temp_edge))
+                GProp_GProps myProps2;
+                BRepGProp::LinearProperties(edge, myProps2);
+                gp_Pnt center2 = myProps2.CentreOfMass();
+                if(center1.IsEqual(center2, tol))
                 {
 		  same_edge = CUBIT_TRUE;
                   break;
@@ -1881,46 +1892,58 @@
       }
   
       TopTools_ListIteratorOfListOfShape Itor;
+
+      //list_of_edges is the intersection edges on from_face from all tool_faces
       Itor.Initialize(list_of_edges);
+      int total_edges = list_of_edges.Extent();
       DLIList<Curve*> curve_list;
       CubitBoolean topo_changed = CUBIT_FALSE;
       tool_faces.reset();
-      double tol = OCCQueryEngine::instance()->get_sme_resabs_tolerance();
+
+      //check to see if the intersecting edge is overlapping with any
+      //of the edges on from_edge. It's possible that the tool_face is
+      //adjacent with the from_face and cutting it with one overlapping
+      //edge, the intersector will crash when the edge from the from_face
+      //intersect with the "edge" at one of the vertices.
+      //To avoid this, scale the from_face of 10%
+      TopoDS_Face extended_from_face = from_face;
+      GProp_GProps myProps;
+      BRepGProp::SurfaceProperties(from_face, myProps);
+      gp_Pnt pt = myProps.CentreOfMass();
+      gp_Trsf aTrsf;
+      aTrsf.SetScale(pt, 1.1 );
+
+      BRepBuilderAPI_Transform aBRepTrsf(from_face, aTrsf);
+      extended_from_face =
+              TopoDS::Face(aBRepTrsf.ModifiedShape(from_face));
+
       Bnd_Box aBox2;
-      BRepAdaptor_Surface asurface(from_face);
+      BRepAdaptor_Surface asurface(extended_from_face);
       BndLib_AddSurface::Add(asurface, tol, aBox2);
       for(; Itor.More(); Itor.Next())
       {
         TopoDS_Edge edge = TopoDS::Edge(Itor.Value());
-        Curve* curve = OCCQueryEngine::instance()->populate_topology_bridge(edge);
       	//check if the edge is on from_face edges, add such edge on existing 
         //edge to split it.
-        //note: even if the edge is on one of from_face edges, if it's not 
-        //shorter than the from_face edge, we won't need to added it either.
-        //For this reason, do the length check out first, because there's a bug
-        //in TopOpeBRep_EdgesIntersector so that when the two edges are
-        //overlapping and has the same length, but on two non-parallel faces
-        //the sector will crash.
 	TopExp_Explorer Ex;
 	CubitBoolean added = CUBIT_FALSE;
         CubitBoolean skipped = CUBIT_FALSE;
         GProp_GProps myProps1;
         BRepGProp::LinearProperties(edge, myProps1);
         double d1 = myProps1.Mass();
+        TopoDS_Face face = *(tool_faces.get_and_step());
+        BRepAdaptor_Surface asurface(face);
+        Bnd_Box aBox1;
+        BndLib_AddSurface::Add(asurface, tol, aBox1);
 
 	for (Ex.Init(from_face, TopAbs_EDGE); Ex.More(); Ex.Next())
 	{
 	  TopoDS_Edge from_edge = TopoDS::Edge(Ex.Current());
-          Curve* curve = OCCQueryEngine::instance()->populate_topology_bridge(from_edge);
          
           TopOpeBRep_EdgesIntersector intersector;
-          TopoDS_Face face = *(tool_faces.get_and_step());
-          BRepAdaptor_Surface asurface(face);
-          Bnd_Box aBox1;
-          BndLib_AddSurface::Add(asurface, tol, aBox1); 
 
-   	  intersector.SetFaces(face, from_face, aBox1, aBox2);
-          intersector.Perform(edge, from_edge);
+   	  intersector.SetFaces(extended_from_face, face, aBox2, aBox1);
+          intersector.Perform(from_edge, edge);
           int num_edges = intersector.NbSegments();
 	  if(num_edges == 1) //overlap
  	  {
@@ -1940,7 +1963,7 @@
             }
             else
 	      skipped = CUBIT_TRUE;
-            max_edge--;
+            total_edges--;
             break;
 	  }
         } 
@@ -1957,7 +1980,7 @@
       }
 
       DLIList<DLIList<TopoDS_Edge*>*> edge_lists;
-      if (max_edge >= 1)
+      if (total_edges >= 1)
 	{      
 	  sort_curves(curve_list, edge_lists); 
 	  DLIList<TopoDS_Edge*>* edge_list;
@@ -1980,6 +2003,14 @@
 	  delete from_shape;
           from_shape = new TopoDS_Shape(splitor.Shape());
           TopTools_ListOfShape shapes;
+          for(int i = 0; i < from_faces.size(); i++)
+          {
+             TopoDS_Face* topo_face = from_faces.get();
+             shapes.Assign(splitor.Modified(*topo_face));
+             topo_face = new TopoDS_Face(TopoDS::Face(shapes.First()));
+             from_faces.change_to(topo_face);
+             from_faces.step();
+          } 
           shapes.Assign(splitor.Modified(from_face)); 
           TopTools_ListIteratorOfListOfShape It(shapes);
           for(; It.More(); It.Next())
@@ -1997,7 +2028,7 @@
       } 
   }
   
-  /*
+  
   TopExp_Explorer Ex;
   int num_face = 0;
   for (Ex.Init(*from_shape, TopAbs_FACE); Ex.More(); Ex.Next())
@@ -2005,7 +2036,8 @@
      TopoDS_Face face = TopoDS::Face(Ex.Current());
      num_face++;
   }
-  */ 
+  
+  PRINT_INFO("Total %d cuts performed, with from_shape having %d faces.\n", count, num_face); 
   if (count > 0)
      return CUBIT_SUCCESS;
   return CUBIT_FAILURE;

Modified: cgm/trunk/test/modify.cpp
===================================================================
--- cgm/trunk/test/modify.cpp	2008-04-04 15:05:29 UTC (rev 1742)
+++ cgm/trunk/test/modify.cpp	2008-04-04 19:12:40 UTC (rev 1743)
@@ -27,9 +27,13 @@
 #include "RefEntityFactory.hpp"
 #include "RefEdge.hpp"
 #include "BodySM.hpp"
+#include "Lump.hpp"
+#include "OCCLump.hpp"
 #include "OCCBody.hpp"
 #include "OCCSurface.hpp"
 #include "OCCCurve.hpp"
+#include "OCCShell.hpp"
+#include "TopoDS_Shape.hxx"
 
 // forward declare some functions used and defined later
 CubitStatus read_geometry(int, char **);
@@ -103,12 +107,12 @@
   GeometryModifyTool *gmti = GeometryModifyTool::instance();
 
   OCCQueryEngine::instance();
-  OCCModifyEngine::instance();
+  OCCModifyEngine* ome = OCCModifyEngine::instance();
 
   Body* body = gmti->brick(10, 10, 10);
   BodySM* bodysm = body->get_body_sm_ptr();
-  DLIList<OCCSurface*> surfaces;
-  CAST_TO(bodysm, OCCBody)->get_all_surfaces(surfaces);  
+  DLIList<OCCSurface*> occ_surfaces;
+  CAST_TO(bodysm, OCCBody)->get_all_surfaces(occ_surfaces);  
   DLIList<RefFace*> ref_faces;
   body->ref_faces(ref_faces);
   
@@ -134,7 +138,7 @@
   }
 
   //stitch surfaces together
-  GeometryModifyEngine *gme = gmti->get_engine(surfaces.get());
+  GeometryModifyEngine *gme = gmti->get_engine(occ_surfaces.get());
   BodySM* stitched_body = NULL;
   CubitStatus stat = gme->stitch_surfs(bodysm_list, stitched_body);
   Body* body2;
@@ -201,15 +205,116 @@
   from_body = gmti->brick(10, 10, 10);
   from_body2 = gmti->brick(4, 4, 4);
   tool_body = gmti->brick(1, 1, 1);  
-  CubitVector v_move(1,0,0);
+  CubitVector v_move(1,0,-1);
   gti->translate(from_body2,v_move);
   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);
+  d = new_bodies.step_and_get()->measure();
+  v = new_bodies.get()->center_point();
+
+  from_bodies.clean_out();
+  from_bodies += new_bodies;
+  new_bodies.clean_out();
+  CubitVector v_move2(0, -2, -2);
+  Body* body_new = from_bodies.step_and_get();
+  d = body_new->measure();
+  v = body_new->center_point();
+  gti->translate(body_new,v_move2);
+  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_edges();
+
+  bodies.clean_out();
+  gti->bodies(bodies);
+  //delete all entities
+  gti->delete_Body(bodies); 
+  
+  //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);
+  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_TRUE); 
+  n = new_bodies.get()->num_ref_faces();
+  n = new_bodies.get()->num_ref_edges();
+
+  bodies.clean_out();
+  gti->bodies(bodies);
+  //delete all entities
+  gti->delete_Body(bodies);
+
+  //test for shell body subtract.
+  tool_body = gmti->brick(1, 1, 1);
+  //just need two surfaces.
+  DLIList<RefFace*> reffaces;
+  tool_body->ref_faces(reffaces);
+  CubitVector v1(1, 0.5, 0.5);
+  CubitVector v2(0.5, 0.5, 1);
+  DLIList<Surface*> surfaces;
+  for (int i = 0; i < tool_body->num_ref_faces(); i++)
+  {
+    RefFace* face = reffaces.get_and_step();
+    v = face->center_point();
+    if (v.about_equal(v1) || v.about_equal(v2))
+      surfaces.append(face->get_surface_ptr());
+  } 
+  assert(surfaces.size() == 2);
+  DLIList<BodySM*> body_list;
+  for (int i = 0; i < surfaces.size(); i++)
+  {
+    Surface* surface = surfaces.get_and_step();
+    surface = ome->make_Surface(surface);
+    body_list.append(CAST_TO(surface,OCCSurface)->my_body());
+  } 
+  bodysm = NULL;
+
+  //test stitch surfaces operation
+  ome->stitch_surfs(body_list, bodysm);
+
+  bodies.clean_out();
+  bodies.append(tool_body);
+  gti->delete_Body(bodies);
+
+  from_body2 = gti->make_Body(bodysm); 
+
+  tool_body  = gmti->brick(4, 4, 4);
+  CubitVector v_move3(1,0,0);
+  gti->translate(tool_body,v_move3);
+  from_bodies.clean_out();
+  from_bodies.append(from_body2);
+  new_bodies.clean_out();
+
+  //test body cutting a shell, one surface got cut as the result. 
+  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();
+ 
+  from_bodies.clean_out();
+  from_bodies.append(tool_body);
+  
+  //test a shell cutting a body, failed operation with a warning message.
+  rsl = gmti->subtract(from_body2, from_bodies, new_bodies,
+                       CUBIT_TRUE, CUBIT_TRUE);
+
+  //test solid solid imprint
+  tool_body  = gmti->brick(4, 4, 4);
+  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();
+  ome->imprint_toposhapes(tool_shape, from_shape);
+  ome->imprint_toposhapes(from_shape, tool_shape);
   return stat;
 }




More information about the cgma-dev mailing list