[cgma-dev] r2110 - in cgm/trunk: geom/ACIS_SRC test

janehu at mcs.anl.gov janehu at mcs.anl.gov
Tue Sep 30 14:09:48 CDT 2008


Author: janehu
Date: 2008-09-30 14:09:48 -0500 (Tue, 30 Sep 2008)
New Revision: 2110

Added:
   cgm/trunk/test/hollow.sat
   cgm/trunk/test/hollow_acis.cpp
Modified:
   cgm/trunk/geom/ACIS_SRC/AcisModifyEngine.cpp
   cgm/trunk/test/Makefile.am
Log:
Added hollow function in ACIS engine, passed test.

Modified: cgm/trunk/geom/ACIS_SRC/AcisModifyEngine.cpp
===================================================================
--- cgm/trunk/geom/ACIS_SRC/AcisModifyEngine.cpp	2008-09-30 17:49:44 UTC (rev 2109)
+++ cgm/trunk/geom/ACIS_SRC/AcisModifyEngine.cpp	2008-09-30 19:09:48 UTC (rev 2110)
@@ -5923,13 +5923,111 @@
   return CUBIT_SUCCESS;
 }
 
+//-------------------------------------------------------------------------
+// Purpose       : To hollow a solid body to form a thick body
+//
+// Special Notes :
+//
+// Creator       : Jane Hu 
+//
+// Creation Date : 09/30/08
+//-------------------------------------------------------------------------
+
 CubitStatus AcisModifyEngine::hollow( DLIList<BodySM*>& bodies,
                                       DLIList<Surface*>& surfs_to_remove,
                                       DLIList<BodySM*>& new_body_list,
                                       double depth) const
 {
-   
-  return CUBIT_FAILURE;
+  if(bodies.size() < 1 || surfs_to_remove.size() < 1)
+  {
+    PRINT_ERROR("Making thick solid in ACIS will take one body and at least one surface at a time.\n");
+    return CUBIT_FAILURE;
+  } 
+
+  DLIList<BodySM*> shell_bodies;
+  for(int i = bodies.size(); i >= 1 ; i-- )
+  {
+    BodySM* BodyPtr = bodies.get_and_step();
+    BodyACIS* acis_body = dynamic_cast<BodyACIS*>(BodyPtr);
+    if (!acis_body)
+    {
+       PRINT_ERROR("Non-ACIS BodySM passed to AcisModifyEngine::hollow.\n");
+       continue;
+    }  
+    DLIList<ShellSM*> shells;
+    acis_body->shellsms(shells);
+    if(shells.size() > 1)
+    {
+      PRINT_ERROR("A solid body is required.\n");
+      continue;
+    }
+    
+    DLIList<Surface*> surfaces;
+    acis_body->surfaces(surfaces);
+    int size = surfaces.size();
+    if(size < 2)
+    {
+      PRINT_ERROR("Body must have at least 2 surfaces for hollow operation.\n");
+      continue;
+    } 
+    
+    for(int j = 0; j < surfs_to_remove.size(); j++)
+    {
+      Surface* surface =surfs_to_remove.get_and_step();
+      if(surfaces.move_to(surface))
+        surfaces.change_to((Surface*) NULL);
+    }
+    surfaces.remove_all_with_value(NULL);
+    if(size == surfaces.size())
+    {
+      PRINT_ERROR("Must remove at least one surfaces to make thick body.\n");
+      continue;
+    }
+    
+    // Copy the surfaces since we will use them to create new body.
+    DLIList<SurfaceACIS*> copied_surface_list(surfaces.size());
+    for(int j = 0; j < surfaces.size(); j++)
+    {
+      Surface* surf = surfaces.get_and_step();
+      FACE* FACE_ptr = CAST_TO(surf, SurfaceACIS)->get_FACE_ptr();
+      ENTITY *new_face;
+      api_copy_entity_contents( (ENTITY*)FACE_ptr, new_face);
+      FACE* copied_face = (FACE*)new_face;
+      ATTRIB_CUBIT_OWNER::remove_cubit_owner( (ENTITY *)copied_face,                                                          CUBIT_TRUE );
+      SurfaceACIS* acis_surf = new SurfaceACIS(copied_face); 
+      if(acis_surf)
+        copied_surface_list.append(acis_surf);
+    }
+    if ( surfaces.size() != copied_surface_list.size())
+    {
+      PRINT_ERROR("Failed to copy surfaces.\n");
+      continue;
+    }
+ 
+    DLIList<BodySM*> bodysm_list; 
+    //Create surface body out of copied_surface_list.
+    for(int j = 0; j < copied_surface_list.size(); j++)
+    {
+      Surface* copy_surf = make_Surface(copied_surface_list.get_and_step(),
+                                        CUBIT_FALSE);
+      if(copy_surf)
+      {
+        DLIList<BodySM*> bodies;
+        copy_surf->bodysms(bodies);
+        bodysm_list.append(bodies.get());
+      }
+    }
+    BodySM* stitched_body = NULL;
+    CubitStatus stat = stitch_surfs(bodysm_list, stitched_body);
+    if(stat && stitched_body != NULL)
+      shell_bodies.append(stitched_body);  
+  }
+
+  if(shell_bodies.size() == 0)
+    return CUBIT_FAILURE;
+
+  CubitStatus stat = thicken(shell_bodies, new_body_list, depth, CUBIT_FALSE);
+  return stat;
 }
 
 //-------------------------------------------------------------------------

Modified: cgm/trunk/test/Makefile.am
===================================================================
--- cgm/trunk/test/Makefile.am	2008-09-30 17:49:44 UTC (rev 2109)
+++ cgm/trunk/test/Makefile.am	2008-09-30 19:09:48 UTC (rev 2110)
@@ -14,7 +14,7 @@
 LINK_FLAGS = 
 TESTS = sheet
 if build_ACIS
-  TESTS += webcut
+  TESTS += webcut hollow_acis
   LINK_FLAGS += -R$(ACIS_LIB_DIR)
 endif
 if WITH_OCC
@@ -27,12 +27,14 @@
 check_PROGRAMS = $(TESTS)
 
 webcut_SOURCES = webcut.cpp
+hollow_acis_SOURCES = hollow_acis.cpp
 makept_SOURCES = makept.cpp
 modify_SOURCES = modify.cpp
 sheet_SOURCES  = sheet.cpp
 r_w_SOURCES    = r_w.cpp
 LDADD = ../libcgm.la
 webcut_LDFLAGS = $(LDFLAGS) $(LINK_FLAGS)
+hollow_acis_LDFLAGS = $(LDFLAGS) $(LINK_FLAGS)
 makept_LDFLAGS = $(LDFLAGS) $(LINK_FLAGS)
 modify_LDFLAGS = $(LDFLAGS) $(LINK_FLAGS)
 sheet_LDFLAGS = $(LDFLAGS) $(LINK_FLAGS)
@@ -58,6 +60,7 @@
              model5.sat \
              model6.sat \
              model7.sat \
+             hollow.sat \
              stitch.occ_name \
              webcut_with_brick.sat \
              webcut_with_curve_loop.sat \

Added: cgm/trunk/test/hollow.sat
===================================================================
--- cgm/trunk/test/hollow.sat	                        (rev 0)
+++ cgm/trunk/test/hollow.sat	2008-09-30 19:09:48 UTC (rev 2110)
@@ -0,0 +1,49 @@
+1600 0 1 0           
+10 Cubit 10.2 17 ACIS 16.0.1 Linux 24 Tue Sep 30 13:45:56 2008 
+1 9.9999999999999995e-07 1e-10 
+body $-1 -1 -1 $-1 $1 $-1 $-1 T -4 -4 -5 4 4 10 #
+lump $-1 -1 -1 $-1 $-1 $2 $0 T -4 -4 -5 4 4 10 #
+shell $-1 -1 -1 $-1 $-1 $-1 $3 $-1 $1 T -4 -4 -5 4 4 10 #
+face $-1 -1 -1 $-1 $4 $5 $2 $-1 $6 forward single T -1 -1 5 1 1 10 F #
+face $-1 -1 -1 $-1 $7 $8 $2 $-1 $9 forward single T -1 -1 10 1 1 10 F #
+loop $-1 -1 -1 $-1 $10 $11 $3 T -1 -1 5 1 1 5 unknown #
+cone-surface $-1 -1 -1 $-1 0 0 7.5 0 0 1 1 0 0 1 I I 0 1 1 forward I I I I #
+face $-1 -1 -1 $-1 $12 $13 $2 $-1 $14 forward single T -4 -4 -5 4 4 5 F #
+loop $-1 -1 -1 $-1 $-1 $15 $4 T -1 -1 10 1 1 10 unknown #
+plane-surface $-1 -1 -1 $-1 0 0 10 0 0 1 1 0 0 forward_v I I I I #
+loop $-1 -1 -1 $-1 $-1 $16 $3 T -1 -1 10 1 1 10 unknown #
+coedge $-1 -1 -1 $-1 $11 $11 $17 $18 reversed $5 $-1 #
+face $-1 -1 -1 $-1 $19 $20 $2 $-1 $21 forward single T -4 -4 -5 4 4 -5 F #
+loop $-1 -1 -1 $-1 $22 $23 $7 T -4 -4 -5 4 4 -5 unknown #
+cone-surface $-1 -1 -1 $-1 0 0 0 0 0 1 4 0 0 1 I I 0 1 4 forward I I I I #
+coedge $-1 -1 -1 $-1 $15 $15 $16 $24 forward $8 $-1 #
+coedge $-1 -1 -1 $-1 $16 $16 $15 $24 reversed $10 $-1 #
+coedge $-1 -1 -1 $-1 $17 $17 $11 $18 forward $25 $-1 #
+edge $-1 -1 -1 $-1 $26 0 $26 6.2831853071795862 $17 $27 forward @7 unknown T -1 -1 5 1 1 5 #
+face $-1 -1 -1 $-1 $-1 $25 $2 $-1 $28 forward single T -4 -4 5 4 4 5 F #
+loop $-1 -1 -1 $-1 $-1 $29 $12 T -4 -4 -5 4 4 -5 unknown #
+plane-surface $-1 -1 -1 $-1 0 0 -5 0 0 -1 -1 0 0 forward_v I I I I #
+loop $-1 -1 -1 $-1 $-1 $30 $7 T -4 -4 5 4 4 5 unknown #
+coedge $-1 -1 -1 $-1 $23 $23 $29 $31 reversed $13 $-1 #
+edge $-1 -1 -1 $-1 $32 0 $32 6.2831853071795862 $15 $33 forward @7 unknown T -1 -1 10 1 1 10 #
+loop $-1 -1 -1 $-1 $34 $17 $19 T -1 -1 5 1 1 5 unknown #
+vertex $-1 -1 -1 $-1 $18 $35 #
+ellipse-curve $-1 -1 -1 $-1 0 0 5 -0 -0 -1 1 0 0 1 I I #
+plane-surface $-1 -1 -1 $-1 0 0 5 0 0 1 1 0 0 forward_v I I I I #
+coedge $-1 -1 -1 $-1 $29 $29 $23 $31 forward $20 $-1 #
+coedge $-1 -1 -1 $-1 $30 $30 $36 $37 reversed $22 $-1 #
+edge $-1 -1 -1 $-1 $38 0 $38 6.2831853071795862 $29 $39 forward @7 unknown T -4 -4 -5 4 4 -5 #
+vertex $-1 -1 -1 $-1 $24 $40 #
+ellipse-curve $-1 -1 -1 $-1 0 0 10 0 0 1 1 0 0 1 I I #
+loop $-1 -1 -1 $-1 $-1 $36 $19 T -4 -4 5 4 4 5 unknown #
+point $-1 -1 -1 $-1 1 0 5 #
+coedge $-1 -1 -1 $-1 $36 $36 $30 $37 forward $34 $-1 #
+edge $-1 -1 -1 $-1 $41 0 $41 6.2831853071795862 $36 $42 forward @7 unknown T -4 -4 5 4 4 5 #
+vertex $-1 -1 -1 $-1 $31 $43 #
+ellipse-curve $-1 -1 -1 $-1 0 0 -5 0 0 -1 4 0 0 1 I I #
+point $-1 -1 -1 $-1 1 0 10 #
+vertex $-1 -1 -1 $-1 $37 $44 #
+ellipse-curve $-1 -1 -1 $-1 0 0 5 0 0 1 4 0 0 1 I I #
+point $-1 -1 -1 $-1 4 0 -5 #
+point $-1 -1 -1 $-1 4 0 5 #
+End-of-ACIS-data 
\ No newline at end of file

Added: cgm/trunk/test/hollow_acis.cpp
===================================================================
--- cgm/trunk/test/hollow_acis.cpp	                        (rev 0)
+++ cgm/trunk/test/hollow_acis.cpp	2008-09-30 19:09:48 UTC (rev 2110)
@@ -0,0 +1,152 @@
+/**
+ * \file mergechk.cpp
+ *
+ * \brief mergechk, another simple C++ driver for CGM
+ *
+ * This program acts as a simple driver for CGM.  It reads in a geometry,
+ * performs imprints between all the bodies, merges them, and writes information
+ * on the results.  It also performs pairwise intersections between the
+ * bodies to check for overlaps.  Results are written to stardard output.
+ *
+ */
+
+#include "CpuTimer.hpp"
+#include "GeometryModifyTool.hpp"
+#include "GeometryQueryTool.hpp"
+#include "AcisQueryEngine.hpp"
+#include "MergeTool.hpp"
+#include "CubitUtil.hpp"
+#include "CubitMessage.hpp"
+#include "CubitDefines.h"
+#include "RefEntity.hpp"
+#include "Body.hpp"
+#include "RefVolume.hpp"
+#include "RefFace.hpp"
+#include "RefEdge.hpp"
+#include "RefVertex.hpp"
+#include "CubitObserver.hpp"
+#include "CastTo.hpp"
+#include "AcisQueryEngine.hpp"
+#include "AcisModifyEngine.hpp"
+#include "AppUtil.hpp"
+#include "RefEntityFactory.hpp"
+#include "RefEdge.hpp"
+
+#define STRINGIFY(S) XSTRINGIFY(S)
+#define XSTRINGIFY(S) #S
+
+// forward declare some functions used and defined later
+CubitStatus read_geometry(int, char **);
+CubitStatus evaluate_overlaps();
+CubitStatus imprint_bodies();
+CubitStatus print_unmerged_surfaces();
+CubitStatus hollow();
+// macro for printing a separator line
+#define PRINT_SEPARATOR   PRINT_INFO("=======================================\n");
+
+
+// main program - initialize, then send to proper function
+int main (int argc, char **argv)
+{
+
+  CubitObserver::init_static_observers();
+    // Initialize the GeometryTool
+  
+  CGMApp::instance()->startup( argc, argv );
+  GeometryQueryTool *gti = GeometryQueryTool::instance();
+  AcisQueryEngine::instance();
+  AcisModifyEngine::instance();
+
+    // If there aren't any file arguments, print usage and exit
+  //if (argc == 1) {
+  //  PRINT_INFO("Usage: mergechk <geom_file> [<geom_file> ...]\n");
+  //  exit(0);
+  //}
+  
+  CubitStatus status = CUBIT_SUCCESS;
+
+
+
+  //Do hollow operation to make thick body.
+  status = hollow();
+  if (status == CUBIT_FAILURE) 
+     PRINT_INFO("Operation Failed");
+
+  int ret_val = ( CubitMessage::instance()->error_count() );
+  if ( ret_val > 0 )
+  {
+    PRINT_ERROR("Errors found during Mergechk session.\n");
+  }
+  return ret_val;
+  
+}
+
+/// attribs module: list, modify attributes in a give model or models
+/// 
+/// Arguments: file name(s) of geometry files in which to look
+///
+CubitStatus read_geometry(int num_files, char **argv) 
+{
+  CubitStatus status = CUBIT_SUCCESS;
+  GeometryQueryTool *gti = GeometryQueryTool::instance();
+  assert(gti);
+  int i;
+  
+    // For each file, open and read the geometry
+  FILE *file_ptr;
+
+  PRINT_SEPARATOR;
+
+  for (i = 0; i < num_files; i++) {
+    status = gti->import_solid_model(argv[i], "ACIS_SAT");
+    if (status != CUBIT_SUCCESS) {
+      PRINT_ERROR("Problems reading geometry file %s.\n", argv[i]);
+    }
+  }
+  PRINT_SEPARATOR;
+
+  return CUBIT_SUCCESS;
+}
+
+CubitStatus hollow()
+{
+  GeometryQueryTool *gti = GeometryQueryTool::instance();
+  GeometryModifyTool *gmti = GeometryModifyTool::instance();
+
+  // Read in the geometry from files specified on the command line
+  char *argv = STRINGIFY(SRCDIR) "/hollow.sat";
+  CubitStatus status = read_geometry(1, &argv);
+  if (status == CUBIT_FAILURE) exit(1);
+  else if (gti->num_bodies() == 0) {
+    PRINT_WARNING("No bodies read; exiting.\n");
+    int ret_val = ( CubitMessage::instance()->error_count() );
+
+    exit(ret_val);
+  }
+  
+  //test making thick body.
+  DLIList<Body*> new_bodies;
+  gti->bodies(new_bodies);
+  double d = new_bodies.get()->measure(); //d = 518.3627
+  int n = new_bodies.get()->num_ref_faces(); //n = 5
+  //find the top most surface as the opening of the thick body.
+  DLIList<RefFace*> ref_faces;
+  new_bodies.get()->ref_faces(ref_faces);
+  CubitVector center(0,0,10);
+  for(int i = 0; i < n; i++)
+  {
+    if(ref_faces.step_and_get()->is_planar() &&
+       ref_faces.get()->center_point() == center )
+      break;
+  }
+  DLIList<RefFace*> faces_to_remove;
+  faces_to_remove.append(ref_faces.get());
+  DLIList<Body*> from_bodies;
+  from_bodies = new_bodies;
+  new_bodies.clean_out();
+  CubitStatus stat = gmti->hollow(from_bodies, faces_to_remove, new_bodies, -.2);
+  n = new_bodies.get()->num_ref_faces(); //n = 9
+  d = new_bodies.get()->measure(); //d = 72.4074
+  return CUBIT_SUCCESS;
+}
+




More information about the cgma-dev mailing list