[cgma-dev] r1677 - cgm/trunk/geom/OCC

janehu at mcs.anl.gov janehu at mcs.anl.gov
Fri Mar 21 11:59:20 CDT 2008


Author: janehu
Date: 2008-03-21 11:59:20 -0500 (Fri, 21 Mar 2008)
New Revision: 1677

Modified:
   cgm/trunk/geom/OCC/OCCModifyEngine.cpp
   cgm/trunk/geom/OCC/OCCModifyEngine.hpp
Log:
Separated the sort_curves funtion, and used it in imprint_toposhapes; Added for imprint_toposhapes; Viewed the discussion on the OCC forum about it, this function of spliting surfaces is not guaranteed to work yet. At least not from the forum, no details on the document found.

Modified: cgm/trunk/geom/OCC/OCCModifyEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCModifyEngine.cpp	2008-03-21 15:20:14 UTC (rev 1676)
+++ cgm/trunk/geom/OCC/OCCModifyEngine.cpp	2008-03-21 16:59:20 UTC (rev 1677)
@@ -67,7 +67,9 @@
 #include "CubitMessage.hpp"
 #include "CubitDefines.h"
 #include "TopTools_DataMapOfShapeInteger.hxx"
+#include "BRepFeat_SplitShape.hxx"
 #include "TopOpeBRep_ShapeIntersector.hxx"
+#include "TopTools_ListIteratorOfListOfShape.hxx"
 #include "CubitUtil.hpp"
 #include "CubitPoint.hpp"
 #include "CubitPointData.hpp"
@@ -659,12 +661,8 @@
                                  bool check_edges) const
 {
   //Create TopoDS_Edge list to make a surface.
-  DLIList<TopoDS_Edge*> topo_edges[curve_list.size()];
   DLIList<DLIList<TopoDS_Edge*>*> topo_edges_loops;
   curve_list.reset() ;
-  Curve const* curve_ptr = NULL ;
-  OCCCurve* occ_curve = NULL;
-  TopoDS_Edge* topo_edge = NULL;
     
   //check no intersections of the TopoDS_Edge's.
   //need to check that no intersection in the middle of the curves, not at
@@ -723,26 +721,66 @@
       return (Surface *)NULL;
   }
 
-  //sort the curves so they are in order and make closed loop
+  CubitStatus stat = sort_curves(curve_list, topo_edges_loops); 
+  if( stat == CUBIT_FAILURE ) //case of one disconnected curve 
+     return (Surface*) NULL;
+ 
+  // Use the topo_edges to make a topo_face
+  const TopoDS_Face* topo_face = make_TopoDS_Face(surface_type,
+					topo_edges_loops, old_surface_ptr) ;
+ 
+  if(topo_face == NULL)
+  {
+     PRINT_ERROR("In OCCModifyEngine::make_Surface\n"
+                 "       Cannot make Surface object.\n");
+     return (Surface *)NULL;
+  }
+
+  // make the topology bridges for the face
+  TopoDS_Face the_face = *topo_face;
+  Surface *surface = OCCQueryEngine::instance()->populate_topology_bridge(
+                               the_face, CUBIT_TRUE); 
+  return surface ;
+}
+
+//===============================================================================
+// Function   : sort_curves
+// Member Type: PROTECTED
+// Description: sort the curves so they are in order and make closed loop 
+// Author     : Jane Hu
+// Date       : 03/08
+//===============================================================================
+CubitStatus OCCModifyEngine::sort_curves(DLIList<Curve*> curve_list,
+                                          DLIList<DLIList<TopoDS_Edge*>*>& topo_edges_loops)const
+{
+  topo_edges_loops.clean_out();
+
+  DLIList<TopoDS_Edge*> topo_edges[curve_list.size()];
+  curve_list.reset() ;
+  Curve const* curve_ptr = NULL ;
+  OCCCurve* occ_curve = NULL;
+  TopoDS_Edge* topo_edge = NULL;
+
   OCCPoint* start = NULL;
   OCCPoint* end = NULL;
   DLIList<OCCPoint*> point_list;
   double tol = OCCQueryEngine::instance()->get_sme_resabs_tolerance();
   CubitBoolean new_end = CUBIT_TRUE;
   int size = curve_list.size();
-  count = 0;
+
+  int count = 0;
   for ( int i = 0 ; i < size ; i++ )
   {
      for(int j = 0; j < curve_list.size(); j ++)
      {
-        curve_ptr = curve_list.get() ;  
+        curve_ptr = curve_list.get() ; 
         occ_curve = CAST_TO(const_cast<Curve*>(curve_ptr), OCCCurve);
 
         if(occ_curve ==  NULL)
         {
-           PRINT_ERROR("In OCCModifyEngine::make_Surface\n"
+           PRINT_ERROR("In OCCModifyEngine::sort_curves\n"
                        "       Got a NULL pointer to OCCCurve\n") ;
-	   return (Surface*) NULL;
+           return CUBIT_FAILURE;
         }
 
         point_list.clean_out();
@@ -750,72 +788,55 @@
         //assert(point_list.size()==2);
 
         if (i == 0)
-        { 
+        {
           start = point_list.get();
-  	  end = point_list.pop();   
+          end = point_list.pop();  
           break;
         }
 
         if(end->is_equal(*(point_list.get()), tol) ||
-	        end->is_equal(*(point_list.step_and_get()),tol))
-	{
-	   end = point_list.step_and_get();
-	   new_end = CUBIT_TRUE;
+                end->is_equal(*(point_list.step_and_get()),tol))
+        {
+           end = point_list.step_and_get();
+           new_end = CUBIT_TRUE;
            break;
-	}
+        }
      }
 
-     if (new_end)//found next curve
+     if (new_end)//found next curve 
      {
         topo_edge = occ_curve->get_TopoDS_Edge();
         topo_edges[count].append(topo_edge);
-        curve_list.remove(); 
+        curve_list.remove();
         if(start->is_equal( *end, tol))  //formed a closed loop
         {
- 	  i = 0;
-	  size = curve_list.size() ;
+          i = 0;
+          size = curve_list.size() ;
           topo_edges_loops.append(&topo_edges[count]);
           count++;
-        } 
+        }
         else
           new_end = CUBIT_FALSE;
      }
      else
      {
-        PRINT_ERROR("In OCCModifyEngine::make_Surface\n"
+        PRINT_ERROR("In OCCModifyEngine::sort_curves\n"
                     "  Curve list  can't  form closed loops    \n") ;
-        return (Surface*) NULL;
+        return CUBIT_FAILURE;
      }
   }
-  
-  if( new_end == CUBIT_FALSE ) //case of one disconnected curve 
+
+  if( new_end == CUBIT_FALSE ) //case of one disconnected curve
   {
-     PRINT_ERROR("In OCCModifyEngine::make_Surface\n"
+     PRINT_ERROR("In OCCModifyEngine::sort_curves\n"
                  "  Curve list  can't  form closed loops    \n") ;
-     return (Surface*) NULL;
+     return CUBIT_FAILURE;
   }
- 
-  // Use the topo_edges to make a topo_face
-  const TopoDS_Face* topo_face = make_TopoDS_Face(surface_type,
-					topo_edges_loops, old_surface_ptr) ;
- 
-  if(topo_face == NULL)
-  {
-     PRINT_ERROR("In OCCModifyEngine::make_Surface\n"
-                 "       Cannot make Surface object.\n");
-     return (Surface *)NULL;
-  }
-
-  // make the topology bridges for the face
-  TopoDS_Face the_face = *topo_face;
-  Surface *surface = OCCQueryEngine::instance()->populate_topology_bridge(
-                               the_face, CUBIT_TRUE); 
-  return surface ;
-}
-
+  return CUBIT_SUCCESS;
+} 
 //===============================================================================
 // Function   : make_TopoDS_Face
-// Member Type: PUBLIC
+// Member Type: PROTECTED
 // Description: make a opoDS_Face of type surface_type, given the list of 
 //              TopoDS_Edge. the TopoDS_Edge's should be in order in loops.
 //              check edges option is done in GeometryModifyTool level, so
@@ -1631,7 +1652,7 @@
       //bodies overlap, proceed with the subtract
       TopoDS_Shape cut_shape = BRepAlgoAPI_Cut(*from_shape, *tool_shape);
  
-      //compare to see if the from_shape is getting cut.
+      //compare to see if the from_shape has gotten cut.
       if(is_volume[i])
       {
         GProp_GProps myProps;
@@ -1686,7 +1707,7 @@
        if ((100 - frac_done) < fraction_remaining)
        {
           fraction_remaining = 100 - frac_done;
-          PRINT_INFO("%d% remaining.\n ", fraction_remaining+1);
+          PRINT_INFO("%d\% remaining.\n ", fraction_remaining+1);
        }
     }
   }
@@ -1698,7 +1719,7 @@
       new_bodies.append(bodysm);
   }    
 
-  //ok, we're done wih all cuts, construct new Body's 
+  //ok, we're done wih all cuts, delete unnecessaries. 
   while (tool_boxes.size())
     delete tool_boxes.pop();
   while (tool_bodies_copy.size())
@@ -1712,18 +1733,61 @@
   return CUBIT_SUCCESS; 
 }
 
+//===============================================================================
+// Function   : imprint_toposhapes
+// Member Type: PROTECTED
+// Description: imprint boolean operation on OCC-based bodies
+// Author     : Jane HU
+// Date       : 03/08
+//===============================================================================
 CubitStatus OCCModifyEngine::imprint_toposhapes(TopoDS_Shape*& from_shape, 
                                                 TopoDS_Shape* tool_shape)const
 {
   TopOpeBRep_ShapeIntersector intersector;
   intersector.InitIntersection(*from_shape, *tool_shape);
   TopTools_ListOfShape list_of_edges;
+  BRepFeat_SplitShape splitor(*from_shape);
+
   for(; intersector.MoreIntersection(); intersector.NextIntersection())
   {
     TopoDS_Shape face1 = intersector.ChangeFacesIntersector().Face(1);
     TopoDS_Shape face2 = intersector.ChangeFacesIntersector().Face(2);
     BRepAlgoAPI_Section section(face1, face2);
     list_of_edges.Assign(section.SectionEdges());
+    int num_edges = list_of_edges.Extent();
+
+    TopTools_ListIteratorOfListOfShape Itor;
+    Itor.Initialize(list_of_edges);
+    DLIList<Curve*> curve_list;
+    for(; Itor.More(); Itor.Next())
+    {
+      TopoDS_Edge edge = TopoDS::Edge(Itor.Value());
+      if (num_edges == 1) //surface solid imprint
+      {
+        splitor.Add(edge, TopoDS::Face(face1));  
+        break;
+      }
+      Curve* curve = OCCQueryEngine::instance()->populate_topology_bridge(edge);
+      curve_list.append(curve);
+    }
+    if (num_edges > 1)
+    {      
+      DLIList<DLIList<TopoDS_Edge*>*> edge_lists;
+      CubitStatus stat = sort_curves(curve_list, edge_lists); 
+      if (!stat)
+      {
+        PRINT_ERROR("can't do solid solid imprint without a closed loop.\n");
+        return CUBIT_FAILURE;
+      }  
+      assert(edge_lists.size() == 1);
+      DLIList<TopoDS_Edge*> edge_list;
+      edge_list = *(edge_lists.get());
+      BRepBuilderAPI_MakeWire myWire;
+      for(int i = 0; i < edge_list.size(); i++)
+        myWire.Add(*(edge_list.get_and_step())); 
+      splitor.Add(TopoDS::Wire(myWire.Shape()),TopoDS::Face(face1));
+    }
+    splitor.Build();
   } 
 }
 //===============================================================================

Modified: cgm/trunk/geom/OCC/OCCModifyEngine.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCModifyEngine.hpp	2008-03-21 15:20:14 UTC (rev 1676)
+++ cgm/trunk/geom/OCC/OCCModifyEngine.hpp	2008-03-21 16:59:20 UTC (rev 1677)
@@ -660,6 +660,9 @@
                                 Surface* old_surface_ptr) const;     
 
  CubitStatus imprint_toposhapes(TopoDS_Shape*&, TopoDS_Shape*) const;
+ 
+ CubitStatus sort_curves(DLIList<Curve*> curve_list,
+                         DLIList<DLIList<TopoDS_Edge*>*>& topo_edges_loops)const;
 private:
   
 } ;




More information about the cgma-dev mailing list