cgma
modify.cpp
Go to the documentation of this file.
00001 
00010 #undef NDEBUG
00011 #include <cassert>
00012 #include <Standard_Version.hxx>
00013 
00014 #include "GeometryModifyTool.hpp"
00015 #include "GeometryQueryTool.hpp"
00016 #include "OCCQueryEngine.hpp"
00017 #include "CubitMessage.hpp"
00018 #include "Body.hpp"
00019 #include "RefVolume.hpp"
00020 #include "RefFace.hpp"
00021 #include "RefEdge.hpp"
00022 #include "RefVertex.hpp"
00023 #include "CastTo.hpp"
00024 #include "OCCModifyEngine.hpp"
00025 #include "OCCLump.hpp"
00026 #include "OCCBody.hpp"
00027 #include "OCCSurface.hpp"
00028 #include "OCCCurve.hpp"
00029 #include "OCCShell.hpp"
00030 #include "TopoDS_Shape.hxx"
00031 #include "InitCGMA.hpp"
00032 #include "CubitCompat.hpp"
00033 
00034 #ifndef SRCDIR
00035 # define SRCDIR .
00036 #endif
00037 
00038 #define STRINGIFY_(X) #X
00039 #define STRINGIFY(X) STRINGIFY_(X)
00040 #define SRCPATH STRINGIFY(SRCDIR) "/"
00041 
00042 // forward declare some functions used and defined later
00043 CubitStatus read_geometry(int, const char **, bool local = false);
00044 CubitStatus make_Point();
00045 // macro for printing a separator line
00046 #define PRINT_SEPARATOR   PRINT_INFO("=======================================\n");
00047 
00048 
00049 // main program - initialize, then send to proper function
00050 int main (int argc, char **argv)
00051 {
00052   CubitStatus status = InitCGMA::initialize_cgma("OCC");
00053   if (CUBIT_SUCCESS != status) return 1;
00054 
00055   //Do make point.
00056   status = make_Point();
00057   if (status == CUBIT_FAILURE) 
00058      PRINT_INFO("Operation Failed");
00059 
00060   int ret_val = ( CubitMessage::instance()->error_count() );
00061   if ( ret_val != 7 )
00062   {
00063     PRINT_ERROR("Errors found during Mergechk session.\n");
00064   }
00065   else
00066     ret_val = 0;
00067 
00068   return ret_val;
00069   
00070 }
00071 
00076 CubitStatus read_geometry(int num_files, const char **argv, bool local)
00077 {
00078   CubitStatus status = CUBIT_SUCCESS;
00079   GeometryQueryTool *gti = GeometryQueryTool::instance();
00080   assert(gti);
00081   int i;
00082   
00083   PRINT_SEPARATOR;
00084 
00085   for (i = 0; i < num_files; i++) {
00086     std::string filename( local ? "./" : SRCPATH );
00087     filename += argv[i];
00088     status = CubitCompat_import_solid_model(filename.c_str(), "OCC");
00089     if (status != CUBIT_SUCCESS) {
00090       PRINT_ERROR("Problems reading geometry file %s.\n", filename.c_str());
00091       abort();
00092     }
00093   }
00094   PRINT_SEPARATOR;
00095 
00096   return CUBIT_SUCCESS;
00097 }
00098 
00099 CubitStatus make_Point()
00100 {
00101   GeometryQueryTool *gti = GeometryQueryTool::instance();
00102   GeometryModifyTool *gmti = GeometryModifyTool::instance();
00103 
00104   OCCModifyEngine* ome = OCCModifyEngine::instance();
00105 
00106   //test for tweak fillet and chamfer
00107   Body* body = gmti->brick(10, 10, 10);
00108   //Added for code development testing, can be removed later.
00109   DLIList<RefFace*> test_ref_faces;
00110   DLIList<RefFace*> test_ref_faces2;
00111   body->ref_faces(test_ref_faces);
00112   test_ref_faces2.append(test_ref_faces.pop());
00113   CubitVector sweep_direction(0,0,6);
00114   DLIList<Body*> all_bodies;
00115   CubitStatus sta = gmti->tweak_move(test_ref_faces2, sweep_direction, all_bodies);
00116   if (CUBIT_SUCCESS != sta) {
00117     PRINT_ERROR("GeometryModifyTool::tweak_move failed.\n");
00118     return sta;
00119   }
00120   assert(all_bodies.size() == 1);
00121   double volume = all_bodies.get()->measure();
00122   assert(fabs(volume-1600) <= 0.00001);
00123   int n = all_bodies.get()->num_ref_faces();
00124   assert(n == 10);
00125 
00126   test_ref_faces.clean_out();
00127   test_ref_faces2.clean_out();
00128   all_bodies.get()->ref_faces(test_ref_faces);
00129   for(int i = 0 ; i < test_ref_faces.size(); i++)
00130   {
00131     double max = test_ref_faces.get()->bounding_box().max_z();
00132     double min = test_ref_faces.get()->bounding_box().min_z();
00133     if(max-11. < 0.000001 && max-11. > -0.000001 &&
00134        min-11. < 0.000001 && min-11. > -0.000001)
00135       test_ref_faces2.append(test_ref_faces.get());
00136     test_ref_faces.step();
00137   }
00138   sweep_direction.set(0,0,-6);
00139   all_bodies.clean_out();
00140   sta = gmti->tweak_move(test_ref_faces2, sweep_direction, all_bodies);
00141   assert(all_bodies.size() == 1);
00142   volume = all_bodies.get()->measure();
00143   assert(fabs(volume-1000) <= 0.00001);
00144   n = all_bodies.get()->num_ref_faces();
00145   assert(n == 6);
00146   body = all_bodies.get();
00147   
00148   Body* body2 = gmti->brick(10, 10, 10);
00149   CubitVector scale(1, 2, 5);
00150   CubitVector p1(0, 0, 0);
00151   gmti->scale(body2, p1, scale);
00152   assert(fabs(body2->measure()-10000)< 0.0001);
00153   CubitBox box1;
00154   box1 = body2->bounding_box();
00155   assert(fabs(box1.max_x()-5)<0.001 && fabs(box1.min_x() + 5) < 0.001);
00156   assert(fabs(box1.max_y()-10)<0.001 && fabs(box1.min_y() + 10) < 0.001);
00157   assert(fabs(box1.max_z()-25)<0.001 && fabs(box1.min_z() + 25) < 0.001);
00158   scale.z(0.2);
00159   scale.y(0.5);
00160   gmti->scale(body2, p1, scale);
00161   assert(fabs(body2->measure()-1000)< 0.0001);
00162 
00163   CubitVector away(11, 0 , 0);
00164   DLIList<Body*> bods;
00165   bods.append(body2);
00166   gti->translate(bods,away);
00167   DLIList<RefEdge*> ref_edges;
00168   body->ref_edges(ref_edges);
00169   DLIList<Body*> new_bodies;
00170   int isize=ref_edges.size();
00171   //isize = 12
00172   for(int i = 2; i < isize; i++)
00173     ref_edges.pop();
00174 
00175   DLIList<RefVertex*> ref_vertices, ref_vertices2;
00176   body->ref_vertices(ref_vertices);
00177   RefVertex* vtx1 ;
00178   ref_vertices2.append(ref_vertices.pop());
00179   ref_vertices2.append(ref_vertices.pop());
00180 
00181   CubitStatus status = gmti->tweak_fillet(ref_vertices2, 1, new_bodies);
00182   assert(status == CUBIT_FAILURE);
00183 
00184   //make a sheet surfaces to do fillet on vertices
00185   DLIList<RefFace*> ref_faces;
00186   body->ref_faces(ref_faces);
00187   RefFace* face = gmti->make_RefFace(ref_faces.get());
00188   RefFace* face2 = gmti->make_RefFace(ref_faces.get());
00189   RefFace* tweak_face = gmti->make_RefFace(ref_faces.get());
00190   DLIList<RefEdge*> tweak_edges;
00191   tweak_face->ref_edges(tweak_edges);
00192   tweak_edges.pop();
00193   tweak_edges.pop();
00194   tweak_edges.pop();
00195   Body* tweak_body = tweak_face->body();
00196   away *= 3;
00197   DLIList<Body*> tweak_bods;
00198   bods.append(tweak_body);
00199   gti->translate(tweak_bods, away);
00200   away /= 3;
00201   CubitVector delta(-1,0, 0);
00202   DLIList<Body*> tweak_bodies;
00203   gmti->tweak_move( tweak_edges, delta, tweak_bodies, CUBIT_FALSE,
00204                     CUBIT_FALSE);
00205   assert(tweak_bodies.size() == 1);
00206   CubitBoolean is_sheet = tweak_bodies.get()->is_sheet_body();
00207   assert(is_sheet == CUBIT_FALSE);
00208   DLIList<OCCSurface*> _surfaces;
00209   OCCBody *occ_body;
00210   occ_body = CAST_TO(tweak_bodies.get()->get_body_sm_ptr(), OCCBody);
00211   occ_body->get_all_surfaces(_surfaces);
00212   double area = _surfaces.get_and_step()->measure() + _surfaces.get()->measure();
00213   assert(fabs(area - 110) <= 0.00001);
00214 
00215   Body* sheet_body = face->body();
00216   Body* sheet_body2 = face2->body();
00217   away *= 5;
00218   DLIList<Body*> sheet_bods;
00219   sheet_bods.append(sheet_body);
00220   gti->translate(sheet_bods, away);
00221   away /= 2;
00222   DLIList<Body*> sheet_bods2;
00223   sheet_bods2.append(sheet_body2);
00224   gti->translate(sheet_bods2, away);
00225 
00226   ref_vertices2.clean_out();
00227   ref_vertices.clean_out();
00228   face->ref_vertices(ref_vertices2);
00229   isize=ref_vertices2.size();
00230   for(int i = 2; i < isize; i++)
00231     ref_vertices.append(ref_vertices2.pop());
00232   
00233   status = gmti->tweak_fillet(ref_vertices2, 1, new_bodies);
00234   DLIList<RefEdge*> ref_edges_check;
00235   new_bodies.get()->ref_edges(ref_edges_check);
00236   isize=ref_edges_check.size();
00237   assert(isize == 6);
00238 
00239   status = gmti->tweak_chamfer(ref_vertices, 1, new_bodies);
00240   ref_edges_check.clean_out();
00241   new_bodies.get()->ref_edges(ref_edges_check);
00242   isize=ref_edges_check.size();
00243   assert(isize == 8);
00244 
00245   ref_vertices.clean_out();
00246   face2->ref_vertices(ref_vertices);
00247   ref_vertices.pop();
00248   ref_vertices.pop();
00249   ref_vertices.pop();
00250   ref_edges_check.clean_out();
00251   ref_vertices.get()->ref_edges(ref_edges_check);
00252   new_bodies.clean_out();
00253   status = gmti->tweak_chamfer(ref_vertices, 1, new_bodies,ref_edges_check.pop(), 0.5, ref_edges_check.pop());
00254  
00255   ref_edges_check.clean_out();
00256   new_bodies.get()->ref_edges(ref_edges_check);
00257   isize=ref_edges_check.size();
00258   assert(isize == 5);
00259 
00260   new_bodies.clean_out();
00261   gmti->tweak_fillet(ref_edges, 1, new_bodies, CUBIT_FALSE, CUBIT_FALSE);
00262 
00263   ref_edges.clean_out();
00264   new_bodies.get()->ref_edges(ref_edges);
00265   isize=ref_edges.size();
00266   assert(isize == 21);
00267 
00268   ref_edges.clean_out();
00269   new_bodies.clean_out(); 
00270 
00271   body2->ref_edges(ref_edges);
00272   isize=ref_edges.size();
00273   assert(isize == 12);
00274   for(int i = 2; i < isize; i++)
00275     ref_edges.pop(); 
00276   
00277   gmti->tweak_chamfer(ref_edges, 1, new_bodies, 1);
00278 
00279   ref_edges.clean_out();
00280   new_bodies.get()->ref_edges(ref_edges);
00281   isize=ref_edges.size();
00282   assert(isize == 17);
00283 
00284   ref_vertices.clean_out();
00285   ref_vertices2.clean_out();
00286   new_bodies.get()->ref_vertices(ref_vertices);
00287   
00288   for(int i = 0; i < 3; i++)
00289   {
00290     vtx1 = ref_vertices.pop();
00291     ref_vertices2.append(vtx1);
00292   }
00293 
00294   new_bodies.clean_out();
00295   ref_edges.clean_out();
00296   ref_vertices2.get()->ref_edges(ref_edges);
00297   status = gmti->tweak_chamfer(ref_vertices2, 1, new_bodies, ref_edges.pop(), 
00298                          0.7, ref_edges.pop(), 0.5, ref_edges.pop());
00299   assert(status == CUBIT_FAILURE);
00300 
00301   ref_vertices.clean_out();
00302   ref_vertices2.pop();
00303   ref_vertices2.pop();
00304   ref_vertices2.get()->ref_edges(ref_edges);
00305   gmti->tweak_chamfer(ref_vertices2, 2, new_bodies, ref_edges.pop(), 1,
00306                       ref_edges.pop(), 0.5, ref_edges.pop());
00307 
00308   new_bodies.get()->ref_vertices(ref_vertices);
00309   new_bodies.clean_out();
00310   int v_size = ref_vertices.size();
00311   for (int i=0; i < v_size; i++)
00312   {
00313     RefVertex* vertex = ref_vertices.get_and_step();
00314     if(vertex->coordinates().x() != 16)
00315     {
00316       ref_vertices.remove(vertex); 
00317       continue;
00318     }
00319     if((vertex->coordinates().y()== 5 && vertex->coordinates().z() == 5)
00320    || (vertex->coordinates().y()== -5 && vertex->coordinates().z() == -5))
00321     continue;
00322     else
00323       ref_vertices.remove(vertex);
00324   }
00325    
00326   assert (ref_vertices.size() ==2);
00327   gmti->tweak_chamfer(ref_vertices, 1, new_bodies);
00328 
00329   ref_edges.clean_out();
00330   new_bodies.get()->ref_edges(ref_edges);
00331   isize=ref_edges.size();
00332   assert(isize == 26);
00333  
00334   CubitStatus rsl = CUBIT_SUCCESS;
00335   DLIList<RefEntity*> ref_entity_list;
00336   int num_ents_exported=0;
00337   const CubitString cubit_version="10.2";
00338   const char * filename = "fillet.occ";
00339   const char * filetype = "OCC";
00340 
00341   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
00342                                  num_ents_exported, cubit_version);
00343   assert(num_ents_exported == 5);
00344   remove(filename);
00345 
00346   DLIList<Body*> bodies;
00347   DLIList<RefEntity*>  free_entities;
00348   gti->bodies(bodies);
00349   gti->get_free_ref_entities(free_entities);
00350 
00351   //delete all entities
00352   gti->delete_Body(bodies);
00353 
00354   //bug fixing for creating arc curve.
00355    CubitVector vti(6.0, 0.0, 0.0);
00356    RefVertex* vert1 = GeometryModifyTool::instance()->make_RefVertex(vti);
00357    CubitVector vtii(6.0, 8.0, 0.0);
00358    RefVertex* vert2 = GeometryModifyTool::instance()->make_RefVertex(vtii);
00359    CubitVector v3(0, 8.0, 0.0);
00360    RefEdge* edge6 = gmti->make_RefEdge(ARC_CURVE_TYPE, vert1, vert2, &v3 );
00361    double d = edge6->measure();
00362    assert(d - 22.14297 < 0.00001);
00363 
00364    DLIList<RefEntity*> listVertexEdge;
00365    edge6->get_child_ref_entities(listVertexEdge);
00366    int numVertexEdge = listVertexEdge.size();
00367    RefVertex* tmpVertex = NULL;
00368    CubitVector coord;
00369    for (int i = 0; i < numVertexEdge; i++)
00370    {
00371        tmpVertex = CAST_TO(listVertexEdge.get_and_step(), RefVertex);
00372        coord = tmpVertex->coordinates();
00373    }
00374    int numTotalVertex  = GeometryQueryTool::instance()->num_ref_vertices();
00375    DLIList<RefVertex*> ref_v;
00376    GeometryQueryTool::instance()->ref_vertices(ref_v);
00377    for (int i = 0; i < numTotalVertex; i++)
00378    {
00379        tmpVertex = ref_v.get_and_step();
00380        coord = tmpVertex->coordinates();
00381    }
00382 
00383   bodies.clean_out();
00384   free_entities.clean_out();
00385   gti->bodies(bodies);
00386   gti->get_free_ref_entities(free_entities);
00387 
00388   //delete all entities
00389   gti->delete_Body(bodies);
00390 
00391   for (int j = free_entities.size(); j--;)
00392     {
00393       gti->delete_RefEntity( free_entities.get_and_step());
00394     }
00395 
00396   //other tests
00397   body = gmti->brick(10, 10, 10);
00398   CubitVector v(15,0,0);
00399   BodySM* bodysm = body->get_body_sm_ptr();
00400   DLIList<OCCSurface*> occ_surfaces;
00401   CAST_TO(bodysm, OCCBody)->get_all_surfaces(occ_surfaces);  
00402   ref_faces.clean_out();
00403   ref_edges.clean_out();
00404   body->ref_faces(ref_faces);
00405 
00406   DLIList<RefFace*> faces_to_stitch;
00407   RefFace* test_face = NULL;
00408   for(int i = 0 ; i < ref_faces.size(); i++)
00409   {
00410     RefFace* refface = gmti->make_RefFace(ref_faces.get_and_step());
00411     if(refface)
00412     faces_to_stitch.append(refface);
00413   }
00414 
00415   DLIList<Surface*> surface_list;
00416   test_face = gmti->make_RefFace(ref_faces.get());
00417   surface_list.append(test_face->get_surface_ptr());
00418   CubitVector v_test(-5,0,0);
00419   CubitVector normal, test_normal(-1,0,0);
00420   normal = test_face->normal_at(v_test); //(-1,0,0)
00421   assert(normal == test_normal);
00422   ome->flip_normals(surface_list);
00423   normal = test_face->normal_at(v_test); //(1,0, 0)
00424   assert(normal == -test_normal);
00425   bodies.clean_out();
00426   test_face->bodies(bodies);
00427   gti->delete_Body(bodies);
00428   surface_list.clean_out();
00429   bodies.clean_out(); 
00430   gti->delete_Body(body);
00431 
00432   DLIList<BodySM*> bodysm_list;
00433   DLIList<RefFace*> face_list;
00434   DLIList<RefVertex*> vertices;
00435   for(int i = 0; i < faces_to_stitch.size(); i++)
00436   {
00437     //move each refface by (15,0,0)
00438     RefFace* refface = faces_to_stitch.get_and_step();
00439     refface->ref_vertices(vertices);
00440     Body* body = refface->ref_volume()->get_body_ptr();
00441     bodysm = body->get_body_sm_ptr();
00442     Surface* surface = refface->get_surface_ptr();
00443     surface_list.append(surface);
00444     bodysm_list.append(bodysm);
00445     bods.clean_out();
00446     bods.append(body);
00447     gti->translate(bods, v);
00448     body->ref_faces(face_list);
00449     occ_surfaces.clean_out();
00450     CAST_TO(bodysm, OCCBody)->get_all_surfaces(occ_surfaces);
00451   }
00452 
00453   //create solid from surfaces 
00454   //GeometryModifyEngine *gme = gmti->get_engine(occ_surfaces.get());
00455   new_bodies.clean_out();
00456   gmti->create_solid_bodies_from_surfs(face_list, new_bodies);
00457 
00458   ref_entity_list.clean_out();
00459   num_ents_exported=0;
00460   filename = "stitch.occ";
00461 
00462   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
00463                                  num_ents_exported, cubit_version);
00464   assert(num_ents_exported == 1);
00465 
00466   gti->bodies(bodies);
00467   free_entities.clean_out();
00468   gti->get_free_ref_entities(free_entities);
00469   //delete all entities
00470   gti->delete_Body(bodies);
00471 
00472   for (int j = free_entities.size(); j--;)
00473     {
00474       gti->delete_RefEntity( free_entities.get_and_step());
00475     }
00476 
00477   // Read in the geometry from files specified on the command line
00478   const char *argv = "stitch.occ";
00479   status = read_geometry(1, &argv, true);
00480   if (status == CUBIT_FAILURE) exit(1);
00481   //Read in 1 volume.
00482   remove(filename);
00483 
00484   bodies.clean_out();
00485   free_entities.clean_out();
00486   gti->bodies(bodies); 
00487   gti->get_free_ref_entities(free_entities);
00488 
00489   //delete all entities
00490   gti->delete_Body(bodies);
00491 
00492   for (int j = free_entities.size(); j--;)
00493     {
00494       gti->delete_RefEntity( free_entities.get_and_step());
00495     }
00496 
00497   //test for cylinder making
00498   Body* from_body = gmti->cylinder(10, 4, 3, 2);
00499   Body* from_body2 = gmti->cylinder(8, 4, 2, 0);
00500   Body* tool_body = gmti->cylinder(10, 1, 1, 1);
00501   d = from_body->measure(); //d = 219.91
00502   assert(d - 219.91 < 0.01 && d > 219.91);
00503   bodysm = from_body->get_body_sm_ptr();
00504   CubitVector center1;
00505   CAST_TO(bodysm, OCCBody)->mass_properties(center1, d);
00506   d = from_body2->measure();//d = 67.02
00507   assert(d - 67.02 < 0.01&& d > 67.02);
00508   d = tool_body->measure(); //d = 31.41
00509   assert(d - 31.41 < 0.01 && d > 31.41);
00510   
00511   // test for sphere making
00512   Body* test_body = gmti->sphere(5);
00513   d = test_body->measure(); //d = 523.598 
00514   assert(d - 523.598 < 0.01 && d >  523.598);
00515   //test for prism making
00516   test_body = gmti->prism(10, 4, 4,2);
00517   d =  test_body->measure(); //d = 320
00518   assert(-d + 320 < 0.1 && d < 320);
00519   //test for pyramid making
00520   test_body = gmti->pyramid(10, 4, 5, 2, 3);
00521   d =  test_body->measure(); //d = 130.6666
00522   assert(d - 130.666 < 0.001&& d > 130.666);
00523 
00524   //test for torus making
00525   test_body =  gmti->torus(10,5);
00526   d =  test_body->measure(); //d = 4934.8
00527   assert(d - 4934.8 < 0.1&& d > 4934.8);
00528 
00529   CubitVector factors(1,1,0.5);
00530   gmti->scale(test_body, p1, factors);  
00531   d = test_body->measure();
00532   assert( d > 2475 && d < 2475.5);
00533 
00534   //test for planar_sheet making
00535   CubitVector p2(0, 0, 1);
00536   CubitVector p3(0, 1, 1);
00537   CubitVector p4(0, 1, 0);
00538   test_body =  gmti->planar_sheet(p1, p2, p3, p4);
00539   d =  test_body->measure(); //d = 1
00540   assert(1-d < 0.001 && d < 1);
00541   bodies.clean_out();
00542   gti->bodies(bodies);
00543   //delete all entities
00544   gti->delete_Body(bodies); 
00545 
00546   //test for subtract
00547   from_body = gmti->brick(10, 10, 10);
00548   int width = 10; //we can also test for width < 10
00549   from_body2 = gmti->brick(4, width, 4);
00550   tool_body = gmti->brick(10, 10, 10);  
00551   CubitVector v_move(3,width/2.0,1);
00552   CubitVector v_movei(5,5,6);
00553   CubitVector v_moveii(5,5,5);
00554   DLIList<Body*> from_bods2;
00555   from_bods2.append(from_body2);
00556   gti->translate(from_bods2,v_move);
00557   DLIList<Body*> tool_bods;
00558   tool_bods.append(tool_body);
00559   gti->translate(tool_bods, v_movei);
00560   DLIList<Body*> from_bods;
00561   from_bods.append(from_body);
00562   gti->translate(from_bods, v_moveii);
00563   DLIList<Body*> from_bodies;
00564   from_bodies.append(from_body);
00565   new_bodies.clean_out();
00566   rsl = gmti->subtract(from_body2, from_bodies, new_bodies, 
00567                        CUBIT_TRUE, CUBIT_FALSE);
00568   //new bodies has one body, new body has 10 ref-faces, 5 of them are remaining
00569   //with old id, 5 of them are new faces.
00570   assert(new_bodies.size() == 1);
00571   assert(new_bodies.get()->num_ref_faces() == 10);
00572 
00573   from_bodies=new_bodies;
00574   new_bodies.clean_out();
00575   rsl = gmti->subtract(tool_body,from_bodies, new_bodies,
00576                        CUBIT_TRUE, CUBIT_FALSE);
00577   d = new_bodies.step_and_get()->measure(); //d = 50
00578   v = new_bodies.get()->center_point(); //v = (5, 5, .05)
00579   n = new_bodies.get()->num_ref_faces();
00580   assert(new_bodies.size() == 1);
00581   assert( n == 12);
00582   assert (60 -d < 0.0001 && d <= 60);
00583   CubitVector test_v(5, 5, .5);
00584   assert (v == test_v);
00585   //new bodies has 1 body with 2 volumes, a volume = 10 and the other  
00586   //volume = 50; each of them has 6 ref_faces, of which 3 are new and 3 are
00587   //remaining (unchanged or modified).
00588 
00589   bodies.clean_out();
00590   gti->bodies(bodies);
00591   //delete all entities
00592   gti->delete_Body(bodies); 
00593   
00594   free_entities.clean_out();
00595   gti->get_free_ref_entities(free_entities);
00596   assert(free_entities.size() == 0);
00597   //there shouldn't be any free_entites.
00598 
00599   from_body = gmti->brick(10, 10, 10);
00600   tool_body = gmti->brick(11, 1, 1);
00601   CubitVector v_move4(5,6,4);
00602   CubitVector v_move4i(5.5,0.5,0.5);
00603   from_bods.clean_out();
00604   from_bods.append(from_body);
00605   gti->translate(from_bods,v_move4);
00606   tool_bods.clean_out();
00607   tool_bods.append(tool_body);
00608   gti->translate(tool_bods,v_move4i);
00609   Body* cp_from_body = gmti->copy_body(from_body);
00610   Body* cp_from_body2 = gmti->copy_body(cp_from_body);
00611 
00612   //test edge imprint on body
00613   ref_edges.clean_out();
00614   tool_body->ref_edges(ref_edges);
00615   from_bodies.clean_out();
00616   from_bodies.append(cp_from_body);
00617   new_bodies.clean_out();
00618   CubitStatus stat = gmti->imprint(from_bodies, ref_edges, new_bodies, CUBIT_FALSE, CUBIT_TRUE );
00619   assert(new_bodies.get()->num_ref_faces() == 8);
00620 
00621   //test edge imprint on surface
00622   CubitVector vv(5,1,4.0);
00623   face_list.clean_out();
00624   cp_from_body2->ref_faces(face_list);
00625   int size = face_list.size();
00626   DLIList<RefFace*> unimprint_faces;
00627   for(int i = 0; i < size; i++)
00628   {
00629     CubitVector v = face_list.get()->center_point();
00630     if(!v.about_equal(vv))
00631       unimprint_faces.append(face_list.remove());
00632     else
00633       face_list.step();
00634   }
00635   assert(face_list.size() == 1);
00636   ref_edges.step_and_get()->ref_vertices(vertices);
00637   new_bodies.clean_out();
00638   stat = gmti->imprint(unimprint_faces, ref_edges, new_bodies, CUBIT_FALSE);
00639   assert(new_bodies.get()->num_ref_faces() == 6);
00640 
00641   new_bodies.clean_out();
00642   face_list.clean_out();
00643 
00644   //imprint a point on an edge, split it
00645   CubitVector pp1(10,1,8);
00646   CubitVector pp2(10,5,9);
00647   CubitVector pp3(10,1,6);
00648   DLIList<CubitVector> vectors;
00649   vectors.append(pp1);
00650   vectors.append(pp2);
00651   vectors.append(pp3);
00652   from_bodies.clean_out();
00653   from_bodies.append(cp_from_body2);
00654   new_bodies.clean_out(); 
00655   stat = gmti->imprint(from_bodies, vectors, new_bodies, CUBIT_FALSE);
00656 
00657   n = new_bodies.get()->num_ref_edges();//n = 17
00658   assert( n == 17);
00659 
00660   new_bodies.get()->ref_faces(face_list);
00661   for(int i = 0; i < size; i++)
00662   {
00663     CubitVector v = face_list.get()->center_point();
00664     if(!v.about_equal(vv))
00665       face_list.remove();
00666     else
00667       face_list.step();
00668   }
00669   new_bodies.clean_out();
00670   stat = gmti->imprint(face_list, ref_edges, new_bodies, CUBIT_FALSE);
00671 
00672   n = new_bodies.get()->num_ref_edges();//n = 21
00673   assert( n == 21);
00674 
00675   //test for multi-cut imprint for subtract.
00676   from_bodies.clean_out();
00677   from_bodies.append(from_body);
00678   new_bodies.clean_out();
00679   rsl = gmti->subtract(tool_body, from_bodies, new_bodies,
00680                        CUBIT_TRUE, CUBIT_FALSE);
00681 
00682   n = new_bodies.get()->num_ref_faces();
00683   assert(n == 8);
00684   n = new_bodies.get()->num_ref_edges();
00685   assert(n == 18);
00686 
00687   bodies.clean_out();
00688   gti->bodies(bodies);
00689   //delete all entities
00690   gti->delete_Body(bodies);
00691 
00692   free_entities.clean_out();
00693   gti->get_free_ref_entities(free_entities);
00694   assert(free_entities.size() == 0);
00695   //there shouldn't be any free_entites.
00696 
00697   //test for shell body subtract.
00698   tool_body = gmti->brick(1, 1, 1);
00699   CubitVector new_move(0.5,0.5,0.5);
00700   tool_bods.clean_out();
00701   tool_bods.append(tool_body);
00702   gti->translate(tool_bods,new_move);
00703   //just need two surfaces.
00704   DLIList<RefFace*> reffaces;
00705   tool_body->ref_faces(reffaces);
00706   CubitVector v1(1, 0.5, 0.5);
00707   CubitVector v2(0.5, 0.5, 1);
00708   DLIList<Surface*> surfaces;
00709   for (int i = 0; i < tool_body->num_ref_faces(); i++)
00710   {
00711     RefFace* face = reffaces.get_and_step();
00712     CubitVector v = face->center_point();
00713     if (v.about_equal(v1) || v.about_equal(v2))
00714       surfaces.append(face->get_surface_ptr());
00715   } 
00716   assert(surfaces.size() == 2);
00717   DLIList<BodySM*> body_list;
00718   for (int i = 0; i < surfaces.size(); i++)
00719   {
00720     Surface* surface = surfaces.get_and_step();
00721     surface = ome->make_Surface(surface);
00722     body_list.append(CAST_TO(surface,OCCSurface)->my_body());
00723   } 
00724   bodysm = NULL;
00725 
00726   //test stitch surfaces operation
00727   DLIList<BodySM*> new_surf_bodies;
00728   ome->stitch(body_list, new_surf_bodies, CUBIT_FALSE, 1E-6);
00729   assert(new_surf_bodies.size() == 1);
00730  
00731   bodies.clean_out();
00732   bodies.append(tool_body);
00733   gti->delete_Body(bodies);
00734 
00735   //test flip_normal for a shell body.
00736   bodysm = new_surf_bodies.get();
00737   from_body2 = gti->make_Body(bodysm); 
00738   test_body = gmti->copy_body(from_body2);
00739   is_sheet = test_body->is_sheet_body();
00740   assert(is_sheet == CUBIT_FALSE); //2 faces shell
00741 
00742   RefEntity* ref_body =  CAST_TO(test_body, RefEntity);
00743   DLIList<RefEntity*> ref_entities;
00744   ref_faces.clean_out();
00745   ref_body->get_all_child_ref_entities(ref_entities);
00746   for(int i = 0; i < ref_entities.size(); i++) 
00747   {
00748     RefFace *face = CAST_TO(ref_entities.get_and_step(), RefFace);
00749     if (face != NULL)
00750       ref_faces.append(face);
00751   }
00752   CubitVector test_normal0(1,0,0);
00753   CubitVector test_normal2(0,0,1);
00754   normal = ref_faces.get()->normal_at(v1); //(1,0,0)
00755   if (normal != test_normal0)
00756   {
00757     assert( normal ==test_normal2);
00758     ref_faces.step();
00759   }
00760   normal = ref_faces.step_and_get()->normal_at(v2); //(0,0,1)
00761   assert(normal == test_normal2);
00762   surfaces.clean_out();
00763   surfaces.append(ref_faces.step_and_get()->get_surface_ptr());
00764   ome->flip_normals(surfaces);
00765   normal = ref_faces.get()->normal_at(v1); //(-1,0,0)
00766   assert(normal == -test_normal0);
00767   normal = ref_faces.step_and_get()->normal_at(v2); //(0,0,1)
00768   assert(normal == test_normal2);
00769   gti->delete_Body(test_body);
00770   surfaces.clean_out();
00771    
00772 
00773   tool_body  = gmti->brick(4, 4, 4);
00774   CubitVector v_move3(2,3,2);
00775   tool_bods.clean_out();
00776   tool_bods.append(tool_body);
00777   gti->translate(tool_bods,v_move3);
00778   Body* copy_tool_body = gmti->copy_body(tool_body);
00779   Body* copy_tool_body2 = gmti->copy_body(tool_body);
00780 
00781   from_bodies.clean_out();
00782   new_bodies.clean_out();
00783   from_bodies.append(copy_tool_body);
00784   from_bodies.append(from_body2);
00785   stat = gmti->imprint(from_bodies, new_bodies, CUBIT_FALSE); 
00786   assert(new_bodies.size() == 1 && from_bodies.size() == 2);
00787   assert(new_bodies.get()->num_ref_faces() == 7);
00788 
00789   //test body imprinted by curves.
00790   ref_edges.clean_out();
00791   from_body2->ref_edges(ref_edges);
00792   from_bodies.clean_out();
00793   new_bodies.clean_out();
00794   from_bodies.append(copy_tool_body2);
00795   stat = gmti->imprint(from_bodies, ref_edges, new_bodies, CUBIT_FALSE, CUBIT_TRUE );
00796   assert(new_bodies.get()->num_ref_faces() == 6);
00797 
00798   //test body cutting a shell, one surface got cut as the result. 
00799   CubitVector v_move6(1,-1,0);
00800   tool_bods.clean_out();
00801   tool_bods.append(tool_body);
00802   gti->translate(tool_bods,v_move6);
00803   from_bodies.clean_out();
00804   from_bodies.append(from_body2);
00805   new_bodies.clean_out();
00806   rsl = gmti->subtract(tool_body, from_bodies, new_bodies,
00807                        CUBIT_TRUE, CUBIT_TRUE);
00808 
00809   d = new_bodies.step_and_get()->measure();
00810   v = new_bodies.get()->center_point();
00811   n = new_bodies.get()->num_ref_faces();
00812   assert( n == 1);
00813   assert(1-d<0.00001 && d < 1);
00814   CubitVector test_v1(0.5,0.5,1);
00815   assert(v == test_v1);
00816  
00817   from_bodies.clean_out();
00818   from_bodies.append(tool_body);
00819   
00820   //test a shell cutting a body, failed operation with an Error message.
00821   rsl = gmti->subtract(from_body2, from_bodies, new_bodies,
00822                        CUBIT_TRUE, CUBIT_TRUE);
00823   //WARNING: Surfaces or Shells can't be used to cut a body.
00824   //ERROR: Subtract FAILED
00825   assert (rsl == CUBIT_FAILURE);
00826 
00827   //test solid solid imprint
00828   tool_body  = gmti->brick(4, 4, 4);
00829   CubitVector v_move5(2,2.5,2);
00830   tool_bods.clean_out();
00831   tool_bods.append(tool_body);
00832   gti->translate(tool_bods,v_move5);
00833   from_body = gmti->brick(1,1,1);
00834   from_bods.clean_out();
00835   from_bods.append(from_body);
00836   gti->translate(from_bods, new_move);
00837   from_bodies.clean_out();
00838   new_bodies.clean_out();
00839   from_bodies.append(from_body);
00840   from_bodies.append(tool_body);
00841   stat =  gmti->imprint(from_bodies, new_bodies, CUBIT_FALSE);
00842   //one body gets 4 cuts, the other 3.
00843   //one body gets 10 faces, the other 9.
00844   assert(new_bodies.size() == 2);
00845   assert(new_bodies.get()->num_ref_faces() == 10);
00846   assert(new_bodies.step_and_get()->num_ref_faces() == 9);
00847  
00848   //test imprint projected edges
00849   bodies.clean_out();
00850   gti->bodies(bodies);
00851   //delete all entities
00852   gti->delete_Body(bodies);
00853 
00854   free_entities.clean_out();
00855   gti->get_free_ref_entities(free_entities);  
00856   assert(free_entities.size() == 0);
00857  
00858   from_body  = gmti->brick(4, 4, 4);
00859   CubitVector v_move9(2,5,2);
00860   from_bods.clean_out();
00861   from_bods.append(from_body);
00862   gti->translate(from_bods,v_move9);
00863   ref_faces.clean_out();
00864   from_body->ref_faces(ref_faces);
00865   tool_body = gmti->brick(11, 1, 1);  
00866   tool_bods.clean_out();
00867   tool_bods.append(tool_body);
00868   gti->translate(tool_bods, v_move4i);
00869   ref_edges.clean_out();
00870   tool_body->ref_edges(ref_edges);
00871   new_bodies.clean_out();
00872   gmti->imprint_projected_edges(ref_faces,ref_edges, new_bodies, CUBIT_TRUE,
00873        CUBIT_FALSE); 
00874   if(new_bodies.size())
00875   {
00876     n = new_bodies.get()->num_ref_faces();//n = 8, new_bodies.size() == 1
00877     assert(n == 8 && new_bodies.size() == 1);
00878   }
00879   //delete all bodies.
00880   bodies.clean_out();
00881   gti->bodies(bodies);
00882   //delete all entities
00883   gti->delete_Body(bodies);
00884 
00885   free_entities.clean_out();
00886   gti->get_free_ref_entities(free_entities);
00887   assert(free_entities.size() == 0);
00888   //test body-body intersect.
00889   //1. from body is the commom body, no update
00890   tool_body  = gmti->brick(4, 4, 4);
00891   from_body = gmti->brick(1,1,1);
00892   from_bods.clean_out();
00893   from_bods.append(from_body);
00894   gti->translate(from_bods, new_move);
00895   CubitVector new_move2(2, 2, 2);
00896   tool_bods.clean_out();
00897   tool_bods.append(tool_body);
00898   gti->translate(tool_bods, new_move2);
00899   from_bodies.clean_out();
00900   new_bodies.clean_out();
00901   from_bodies.append(from_body);
00902   stat =  gmti->intersect(tool_body, from_bodies, new_bodies, CUBIT_FALSE);
00903   d = new_bodies.get()->measure(); //d = 1
00904   assert(1-d < 0.00001 && d <= 1); 
00905 
00906   //2. common body is part of from body, update the correponding face
00907   tool_body  = gmti->brick(4, 4, 4);
00908   tool_bods.clean_out();
00909   tool_bods.append(tool_body);
00910   gti->translate(tool_bods,v_move5);
00911   from_bodies.clean_out();
00912   from_bodies.append(from_body);
00913   new_bodies.clean_out();
00914   stat =  gmti->intersect(tool_body, from_bodies, new_bodies, CUBIT_FALSE);
00915   d = new_bodies.get()->measure(); //d = 0.5
00916   assert(0.5-d < 0.0001 && d < 0.5);
00917 
00918   //3. there's no common body, from body is deleted or kept depending on
00919   //keep-old flag. 
00920   tool_body  = gmti->brick(4, 4, 4);
00921   tool_bods.clean_out();
00922   tool_bods.append(tool_body);
00923   gti->translate(tool_bods,v_move5);
00924   CubitVector v_m(0, 0.5, 0);
00925   gti->translate(tool_bods,v_m);
00926   from_bodies.clean_out();
00927   new_bodies.clean_out();
00928   from_bodies.append(from_body);
00929   //nothing changed 
00930   stat =  gmti->intersect(tool_body, from_bodies, new_bodies, CUBIT_TRUE);
00931   //"The 1 body did not have common part with the tool_body."
00932   assert(0 == new_bodies.size());
00933 
00934   //from_body get deleted
00935   stat =  gmti->intersect(tool_body, from_bodies, new_bodies, CUBIT_FALSE);
00936   //"The 1 body did not have common part with the tool_body."
00937   assert(0 == new_bodies.size());
00938   //Destroyed volume(s): 44, 46
00939 
00940   bodies.clean_out();
00941   gti->bodies(bodies);
00942   //delete all entities
00943   gti->delete_Body(bodies);
00944 
00945   free_entities.clean_out();
00946   gti->get_free_ref_entities(free_entities);
00947   assert(free_entities.size() == 0);
00948 
00949   //test chop operation
00950   tool_body  = gmti->brick(4, 4, 4);
00951   from_body = gmti->brick(1,1,1);
00952   tool_bods.clean_out();
00953   tool_bods.append(tool_body);
00954   gti->translate(tool_bods,v_move5);
00955   from_bods.clean_out();
00956   from_bods.append(from_body);
00957   gti->translate(from_bods, new_move);
00958   from_bodies.clean_out();
00959   from_bodies.append(from_body);
00960   from_bodies.append(tool_body);
00961   new_bodies.clean_out();
00962 
00963   //new_bodies = intersect bodies;bodies = outside bodies; body is dummy 
00964   stat =  gmti->chop(from_bodies, new_bodies, bodies, body, CUBIT_FALSE);
00965   d = new_bodies.get()->measure(); //d = 0.5
00966   assert(0.5-d<0.00001 && d < 0.5);
00967 
00968   bodies.clean_out();
00969   gti->bodies(bodies);
00970   //delete all entities
00971   gti->delete_Body(bodies);
00972 
00973   free_entities.clean_out();
00974   gti->get_free_ref_entities(free_entities);
00975   assert(free_entities.size() == 0);
00976   //test chop 2
00977   from_body = gmti->brick(4, 4, 4);
00978   tool_body = gmti->brick(1,1,1);
00979   CubitVector v_move7(0.5, 1, 0.5);
00980   tool_bods.clean_out();
00981   tool_bods.append(tool_body);
00982   gti->translate(tool_bods,v_move7);
00983 
00984   from_bods.clean_out();
00985   from_bods.append(from_body);
00986   gti->translate(from_bods, new_move2);
00987   from_bodies.clean_out();
00988   from_bodies.append(from_body);
00989   from_bodies.append(tool_body);
00990   new_bodies.clean_out();
00991   bodies.clean_out();
00992   stat =  gmti->chop(from_bodies, new_bodies, bodies, body, CUBIT_FALSE);
00993   d = bodies.get()->measure();//d = 63
00994   assert(d-63<0.0001 && d>63); 
00995 
00996   bodies.clean_out();
00997   gti->bodies(bodies);
00998   //delete all entities
00999   gti->delete_Body(bodies);
01000 
01001   free_entities.clean_out();
01002   gti->get_free_ref_entities(free_entities);
01003   assert(free_entities.size() == 0);
01004 
01005   //test unite 1
01006   tool_body = gmti->brick(1,1,1);
01007   tool_bods.clean_out();
01008   tool_bods.append(tool_body);
01009   gti->translate(tool_bods,v_move7);
01010   gti->translate(tool_bods,v_m);
01011   from_body = gmti->brick(1,1,1);
01012   from_bods.clean_out();
01013   from_bods.append(from_body);
01014   gti->translate(from_bods, new_move);
01015   from_bodies.append(from_body);
01016   from_bodies.append(tool_body);
01017   new_bodies.clean_out();
01018   stat = gmti->unite(from_bodies, new_bodies, CUBIT_FALSE);
01019   d = new_bodies.get()->measure(); //d = 2
01020   n = new_bodies.get()->num_ref_faces(); //n = 10  
01021   assert(fabs(d-2)<0.0001 && n == 10); 
01022 
01023   filename = "glue.occ";
01024   filetype = "OCC";
01025   ref_entity_list.clean_out();
01026  
01027   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
01028                                 num_ents_exported, cubit_version);
01029   remove(filename);
01030 
01031   bodies.clean_out();
01032   gti->bodies(bodies); //bodies.size() = 1
01033   free_entities.clean_out();
01034   gti->get_free_ref_entities(free_entities); //free_entities.size() = 0
01035   assert(free_entities.size() == 0);
01036   //delete all entities
01037   gti->delete_Body(bodies);
01038   free_entities.clean_out();
01039   gti->get_free_ref_entities(free_entities); //free_entities.size() = 0
01040   assert(free_entities.size() == 0);
01041   //test unite 2
01042   tool_body = gmti->brick(4, 4, 4);
01043   tool_bods.clean_out();
01044   tool_bods.append(tool_body);
01045   gti->translate(tool_bods,v_move5);
01046   from_body = gmti->brick(1,1,1);
01047   from_bods.clean_out();
01048   from_bods.append(from_body);
01049   gti->translate(from_bods, new_move);
01050   from_bodies.clean_out();
01051   from_bodies.append(from_body);
01052   from_bodies.append(tool_body);
01053   new_bodies.clean_out();
01054   stat = gmti->unite(from_bodies, new_bodies, CUBIT_FALSE);
01055   d = new_bodies.get()->measure(); //d = 64.5
01056   n = new_bodies.get()->num_ref_faces(); 
01057   assert(fabs(d-64.5)<0.00001 && n == 13);
01058   //n = 13. because fusion keeps the imprintings.
01059 
01060   bodies.clean_out();
01061   gti->bodies(bodies); //bodies.size() = 1
01062   free_entities.clean_out();
01063   gti->get_free_ref_entities(free_entities); //free_entities.size() = 0
01064   assert(free_entities.size() == 0);
01065   //delete all entities
01066   gti->delete_Body(bodies);
01067   free_entities.clean_out();
01068   gti->get_free_ref_entities(free_entities); //free_entities.size() = 0
01069   assert(free_entities.size() == 0);
01070 
01071   //test making thick body.
01072   from_body = gmti->cylinder(10, 4, 4, 4); 
01073   tool_body = gmti->cylinder(5,1,1,1);
01074   CubitVector v_move8(0,0,12.5);
01075   CubitVector v_move8i(0 , 0 , 5);
01076   tool_bods.clean_out();
01077   tool_bods.append(tool_body);
01078   gti->translate(tool_bods,v_move8);
01079   from_bods.clean_out();
01080   from_bods.append(from_body);
01081   gti->translate(from_bods, v_move8i);
01082   from_bodies.clean_out();
01083   from_bodies.append(from_body);
01084   from_bodies.append(tool_body);
01085   new_bodies.clean_out();
01086   stat = gmti->unite(from_bodies, new_bodies, CUBIT_FALSE);
01087   d = new_bodies.get()->measure(); //d = 518.3627
01088   n = new_bodies.get()->num_ref_faces(); //n = 5
01089   assert(d-518.3627<0.0001 && d > 518.3627 && n==5);
01090 
01091   //find the top most surface as the opening of the thick body.
01092   ref_faces.clean_out();
01093   new_bodies.get()->ref_faces(ref_faces);
01094   CubitVector center(0,0,15);
01095   for(int i = 0; i < n; i++)
01096   {
01097     if(ref_faces.step_and_get()->is_planar() && 
01098        ref_faces.get()->center_point() == center )
01099       break;
01100   }
01101   RefFace* sweep_face = gmti->make_RefFace(ref_faces.get());
01102   DLIList<RefFace*> faces_to_remove;
01103   faces_to_remove.append(ref_faces.get());
01104   from_bodies = new_bodies;
01105   new_bodies.clean_out();
01106   stat = gmti->hollow(from_bodies, faces_to_remove, new_bodies, -.2);
01107   n = new_bodies.get()->num_ref_faces(); //n = 9
01108   d = new_bodies.get()->measure(); //d = 72.4074
01109   assert(n == 9 && d-72.4074<0.0001 && d>72.4074);
01110 
01111   bodies.clean_out();
01112   gti->bodies(bodies); //bodies.size() = 2
01113   free_entities.clean_out();
01114   gti->get_free_ref_entities(free_entities); //free_entities.size() = 0
01115   assert(free_entities.size() == 0);
01116   //delete hollowed body and keep sweep_face. 
01117   gti->delete_Body(new_bodies);
01118   free_entities.clean_out();
01119   gti->get_free_ref_entities(free_entities); //free_entities.size() = 0
01120   assert(free_entities.size() == 0);
01121 
01122   DLIList<RefEntity*> refentities;
01123   refentities.append(sweep_face);
01124   RefFace* draft_face = gmti->make_RefFace(sweep_face);
01125   RefFace* draft_face2 = gmti->make_RefFace(sweep_face);
01126   RefFace* perp_face = gmti->make_RefFace(sweep_face);
01127   RefFace* rotate_face = gmti->make_RefFace(sweep_face);
01128  
01129   new_bodies.clean_out();
01130   gmti->sweep_translational(refentities, v_move8, 0.0, 1, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, new_bodies);  
01131   body = new_bodies.get();
01132   d = body->measure();
01133   assert(d - 39.2699 < 0.0001 && d >39.2699);
01134 
01135   refentities.clean_out();
01136   refentities.append(draft_face);
01137   CubitVector v_move8ii(0,0,10);
01138   new_bodies.clean_out();
01139   gmti->sweep_translational(refentities, v_move8ii, 0.087, 1, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, new_bodies); 
01140   body = new_bodies.get();
01141   d = body->measure();
01142   //d = 66.3676  theoretical calculation is 66.7833, error 0.62%
01143   assert(d - 66.3676 < 0.0001 && d > 66.3676);
01144 
01145   v_move8ii.z(-10);
01146   refentities.clean_out();
01147   refentities.append(draft_face2);
01148   new_bodies.clean_out();
01149   gmti->sweep_translational(refentities, v_move8ii, 0.087, 1, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, new_bodies);
01150   body = new_bodies.get();
01151   d = body->measure();
01152   //d = 66.3676  theoretical calculation is 66.7833, error 0.62%
01153   assert(d - 66.3676 < 0.0001 && d > 66.3676);
01154 
01155   v_move8ii.z(10);
01156   DLIList<RefEdge*> edges;
01157   body->ref_edges(edges);
01158   refentities.clean_out();
01159   for (int i = 0; i < edges.size(); i++)
01160   {
01161     RefEdge* edge = edges.get();
01162     double length = edge->measure();
01163     if (length > 6.28  && length < 6.3)
01164     {
01165       refentities.append(edge);
01166       break;
01167     }
01168     edges.step();
01169   }
01170   new_bodies.clean_out();
01171   gmti->sweep_translational(refentities, v_move8ii, 0.087, 1, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, new_bodies);
01172   body = new_bodies.get();
01173   d = body->measure();
01174   //d = area = 90.1292 theoretica calculation is 90.5754, error 0.49%
01175   assert(d - 90.1292 < 0.0001 && d > 90.1292);
01176 
01177   refentities.clean_out();
01178   refentities.append(perp_face);
01179   new_bodies.clean_out();
01180   gmti->sweep_perpendicular(refentities, 10.0, 0.087, 1, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, new_bodies);
01181   body = new_bodies.get();
01182   d = body->measure();
01183   //d = 66.3676  theoretical calculation is 66.7833, error 0.62%
01184   assert(d - 66.3676 < 0.0001 && d > 66.3676);
01185   
01186   //Testing for sweep_rotational function
01187   //1. Negative testing: surface rotates along an intersection axis, fails.
01188   refentities.clean_out();
01189   refentities.append(rotate_face); 
01190   DLIList<RefEdge*> rotate_edges;
01191   rotate_face->ref_edges(rotate_edges);
01192   CubitVector sweep_axis(1,0,0);   
01193   CubitVector point(0, 2, 15);
01194   double angle = 1.57;
01195   new_bodies.clean_out();
01196   stat =gmti->sweep_rotational(refentities, center, sweep_axis, angle, 
01197                          new_bodies, CUBIT_FALSE, CUBIT_TRUE, 0, 0.0, 1,
01198                          CUBIT_FALSE, CUBIT_TRUE, CUBIT_FALSE);
01199   assert(stat == CUBIT_FAILURE);
01200 
01201   //2. surface rotates along a non-intersection axis
01202   refentities.append(rotate_face);
01203   new_bodies.clean_out();
01204   gmti->sweep_rotational(refentities, point, sweep_axis, angle, 
01205                          new_bodies, CUBIT_FALSE, CUBIT_TRUE, 0, 0, 1,
01206                          CUBIT_FALSE, CUBIT_TRUE, CUBIT_FALSE);
01207   body = new_bodies.get();
01208   d = body->measure();
01209   assert(d - 9.8646 < 0.0001 && d > 9.8646);
01210 
01211   //3. closed curve rotates along an intersecting axis, fails
01212   refentities.clean_out();
01213   refentities.append(rotate_edges.get());
01214   new_bodies.clean_out();
01215   stat =gmti->sweep_rotational(refentities, center, sweep_axis, angle, 
01216                          new_bodies, CUBIT_FALSE, CUBIT_TRUE, 0, 0, 1,
01217                          CUBIT_FALSE, CUBIT_TRUE, CUBIT_FALSE); 
01218   assert(stat == CUBIT_FAILURE);
01219 
01220   //4. closed curve rotates along a non-intersecting axis with make_solid
01221   //   option set to be true.
01222   refentities.append(rotate_edges.get());
01223   gmti->sweep_rotational(refentities, point, sweep_axis, angle, 
01224                          new_bodies, CUBIT_FALSE, CUBIT_TRUE, 0, 0, 1,
01225                          CUBIT_FALSE, CUBIT_TRUE, CUBIT_FALSE);
01226   body = new_bodies.get();
01227   d = body->measure();
01228   assert(d - 9.8646 < 0.0001 && d > 9.8646);
01229 
01230   //5. closed curve rotates along a non-intersecting axis with make_solid
01231   //   option set to be false.
01232   refentities.clean_out();
01233   refentities.append(rotate_edges.get());
01234   new_bodies.clean_out();
01235   gmti->sweep_rotational(refentities, point, sweep_axis, -angle, 
01236                          new_bodies, CUBIT_FALSE, CUBIT_TRUE, 0, 0, 1,
01237                          CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE);
01238   body = new_bodies.get();
01239   d = body->measure();
01240   assert(d - 19.7292 < 0.0001 && d> 19.7292);
01241 
01242   //6. open curve rotates along an intersecting axis with make_solid
01243   //   option set to be true. Failed
01244   CubitVector pt1(0,1,15);
01245   CubitVector pt2(0,-1,15);
01246   CubitVector pt3(-1,0,15);
01247   RefVertex* vt1 = gmti->make_RefVertex(pt1);
01248   RefVertex* vt2 = gmti->make_RefVertex(pt2);
01249   RefEdge* edge1 = gmti->make_RefEdge(ARC_CURVE_TYPE, vt1, vt2, &pt3); 
01250   CubitVector apoint(0,-0.5,15);
01251   refentities.clean_out();
01252   refentities.append(edge1);
01253   new_bodies.clean_out();
01254   stat=gmti->sweep_rotational(refentities, apoint, sweep_axis, angle, 
01255                               new_bodies, CUBIT_FALSE, CUBIT_TRUE, 0, 0, 1,
01256                               CUBIT_FALSE, CUBIT_TRUE, CUBIT_FALSE);
01257   assert(stat == CUBIT_FAILURE);
01258 
01259   //7. open curve rotates along an intersecting axis at end points with 
01260   //   make_solid option set to be true.
01261   refentities.append(edge1);
01262   CubitVector rotate_axis(0, 1, 0);
01263   gmti->sweep_rotational(refentities, center, rotate_axis, angle, 
01264                          new_bodies, CUBIT_FALSE, CUBIT_TRUE, 0, 0, 1,
01265                          CUBIT_FALSE, CUBIT_TRUE, CUBIT_FALSE);
01266   body = new_bodies.get();
01267   d = body->measure();
01268   assert(1.046667-d < 0.0001 && d < 1.046667);
01269 
01270   //8. open curve rotates along an intersecting axis at end points with
01271   //   make_solid option set to be false.
01272   refentities.clean_out();
01273   refentities.append(edge1);
01274   new_bodies.clean_out();
01275   gmti->sweep_rotational(refentities, center, rotate_axis, -angle, 
01276                          new_bodies, CUBIT_FALSE, CUBIT_TRUE, 0, 0, 1,
01277                          CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE);
01278   body = new_bodies.get();
01279   d = body->measure();
01280   assert( d - 3.14 > -0.0001 && d < 3.14);
01281 
01282   //9. staight line rotate about itself fails.
01283   RefEdge* edge2 = gmti->make_RefEdge(vt1, vt2, rotate_face);
01284   refentities.clean_out();
01285   refentities.append(edge2);
01286   new_bodies.clean_out();
01287   stat=gmti->sweep_rotational(refentities, center, rotate_axis, -angle, 
01288                          new_bodies, CUBIT_FALSE, CUBIT_TRUE, 0, 0, 1,
01289                          CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE); 
01290   assert(stat == CUBIT_FAILURE);
01291 
01292   //10. open curve rotates along a non-intersect axis with make_solid option
01293   //    set to be true.
01294   refentities.clean_out();
01295   refentities.append(edge1);
01296   CubitVector off_center(1,0,15);
01297   gmti->sweep_rotational(refentities, off_center, rotate_axis, angle, 
01298                          new_bodies, CUBIT_FALSE, CUBIT_TRUE, 0, 0, 1,
01299                          CUBIT_FALSE, CUBIT_TRUE, CUBIT_FALSE);
01300   body = new_bodies.get();
01301   d = body->measure();
01302   assert(d - 5.0828 < 0.0001 && d > 5.0828);
01303 
01304   //11. open curve rotates along a non-intersect axis with make_solid option
01305   //    set to be false.
01306   refentities.clean_out();
01307   refentities.append(edge1);
01308   new_bodies.clean_out();
01309   gmti->sweep_rotational(refentities, off_center, rotate_axis, -angle, 
01310                          new_bodies, CUBIT_FALSE, CUBIT_TRUE, 0, 0, 1,
01311                          CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE);
01312   body = new_bodies.get();
01313   d = body->measure();
01314   assert(d - 8.07227 < 0.001 && d > 8.07227);
01315 
01316   //test sweep_along_curve function
01317   //sweep along a straight curve with draft
01318   refentities.clean_out();
01319   refentities.append(rotate_face);
01320   CubitVector pt4(0,1,0);
01321   RefVertex* vt4 = gmti->make_RefVertex(pt4);
01322   RefEdge* edge3 = gmti->make_RefEdge(STRAIGHT_CURVE_TYPE, vt1, vt4);
01323   edges.clean_out();
01324   edges.append(edge3);
01325   new_bodies.clean_out();
01326   gmti->sweep_along_curve(refentities, edges, new_bodies, CUBIT_FALSE, 
01327                           CUBIT_TRUE,0.087,1);
01328   body = new_bodies.get();
01329   d = body->measure();
01330   //d = 134.7152, theoretical calculation is 135.66363, error 0.67%
01331   assert(d -134.7152 < 0.0001 && d > 134.7152);
01332 
01333   //sweep along two curves which make a G1 continous wire, no draft is performed
01334   refentities.clean_out();
01335   refentities.append(rotate_face);
01336   CubitVector pt5(0,2,7.5);
01337   CubitVector pt6(0,0,-7.5);
01338   CubitVector pt7(0,1,-15);
01339   RefVertex* vt5 = gmti->make_RefVertex(pt7);
01340   DLIList<CubitVector*> vector_list;
01341   CubitVector coord1 = vt1->coordinates();
01342   CubitVector coord2 = vt4->coordinates();
01343   vector_list.append(&coord1);
01344   vector_list.append(&pt5);
01345   vector_list.append(&coord2);
01346   
01347   RefEdge* edge4 = gmti->make_RefEdge( SPLINE_CURVE_TYPE, vt1, vt4, vector_list);
01348   vector_list.clean_out();
01349   vector_list.append(&coord2);
01350   vector_list.append(&pt6);
01351   CubitVector coord3 = vt5->coordinates();
01352   vector_list.append(&coord3);
01353   RefEdge* edge5 = gmti->make_RefEdge( SPLINE_CURVE_TYPE, vt4, vt5, vector_list);  
01354   edges.clean_out();
01355   edges.append(edge4);
01356   edges.append(edge5);
01357   new_bodies.clean_out();
01358   gmti->sweep_along_curve(refentities, edges, new_bodies, CUBIT_FALSE, 
01359                           CUBIT_TRUE, 0.087,1);
01360   body = new_bodies.get();
01361   d = body->measure();
01362   //d = 93.697, no effect of draft angle.
01363 #if OCC_VERSION_MINOR > 5
01364   assert(d - 92.1335 < 0.001 && d > 92.1335);
01365 #else
01366   OCCQueryEngine* oqe = OCCQueryEngine::instance();
01367   if(oqe->get_subminor_version() >= 2)
01368     assert(d - 92.1335 < 0.001 && d > 92.1335);
01369   else
01370     assert(d - 93.697 < 0.001 && d > 93.697);
01371 #endif
01372 
01373   bodies.clean_out();
01374   gti->bodies(bodies);
01375   //delete all entities
01376   gti->delete_Body(bodies);
01377 
01378   free_entities.clean_out();
01379   gti->get_free_ref_entities(free_entities);
01380   for(int i = 0; i < free_entities.size(); i++)
01381     gti->delete_RefEntity(free_entities.get_and_step());
01382 
01383   //So far created volume 80.
01384 
01385   // Read in the geometry from files specified on the command line
01386   argv = "Cylinder_1.brep";
01387   status = read_geometry(1, &argv);
01388   argv = "Cylinder_2.brep";
01389   status = read_geometry(1, &argv);
01390   if (status == CUBIT_FAILURE) exit(1);
01391   //Read in 2 volumes.
01392 
01393   from_bodies.clean_out();
01394   new_bodies.clean_out();
01395   gti->bodies(from_bodies);
01396   stat = gmti->imprint(from_bodies, new_bodies, CUBIT_FALSE);
01397 
01398   num_ents_exported=0;
01399   filename = "imprint.brep";
01400   ref_entity_list.clean_out();
01401   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
01402                                  num_ents_exported, cubit_version);
01403   assert(num_ents_exported == 2);
01404   assert (CAST_TO(ref_entity_list.get(), Body)->num_ref_faces() == 7);
01405   assert (CAST_TO(ref_entity_list.get_and_step(), Body)->num_ref_edges() == 11);
01406   assert (CAST_TO(ref_entity_list.get(), Body)->num_ref_volumes() == 1);
01407   remove(filename);
01408 
01409   bodies.clean_out();
01410   gti->bodies(bodies);
01411   //delete all entities
01412   gti->delete_Body(bodies);
01413 
01414   free_entities.clean_out();
01415   gti->get_free_ref_entities(free_entities);
01416   for(int i = 0; i < free_entities.size(); i++)
01417     gti->delete_RefEntity(free_entities.get_and_step());
01418 
01419   // Read in the geometry from files specified on the command line
01420   argv = "webcut.brep";
01421   read_geometry(1, &argv, false);
01422 
01423   DLIList<Body*> old_bodies, junk;
01424   new_bodies.clean_out();
01425   gti->bodies(old_bodies);
01426   CubitVector center_l(0, 0, 0);
01427   CubitVector axis(0.,0.,1.);
01428   double radius = 0.5;
01429   rsl= gmti->webcut_with_cylinder(old_bodies,radius,axis, center_l,new_bodies,junk);
01430   if (rsl== CUBIT_FAILURE)
01431      return rsl;
01432 
01433   num_ents_exported=0;
01434   filename = "after_webcut.brep";
01435   ref_entity_list.clean_out();
01436   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
01437                                  num_ents_exported, cubit_version);
01438   assert(num_ents_exported == 2);
01439   remove(filename);
01440 
01441   bodies.clean_out();
01442   gti->bodies(bodies);
01443   //delete all entities
01444   gti->delete_Body(bodies);
01445 
01446   free_entities.clean_out();
01447   gti->get_free_ref_entities(free_entities);
01448   for(int i = 0; i < free_entities.size(); i++)
01449     gti->delete_RefEntity(free_entities.get_and_step());
01450 
01451   //test for webcut with curve sweep option
01452   argv = "webcut.brep";
01453   read_geometry(1, &argv, false);
01454   argv = "Line_1.brep";
01455   read_geometry(1, &argv, false);
01456   argv = "Line_2.brep";
01457   read_geometry(1, &argv, false);
01458   
01459   old_bodies.clean_out();
01460   new_bodies.clean_out();
01461   gti->bodies(old_bodies);
01462   free_entities.clean_out();
01463   gti->get_free_ref_entities(free_entities);
01464   DLIList<RefEdge*> curves;
01465   for(int i = 0; i < free_entities.size(); i++)
01466   {
01467     RefEdge* free_edge = CAST_TO(free_entities.get_and_step(), RefEdge);
01468     curves.append(free_edge);
01469   }
01470 
01471   axis.set(0.,1.,0.);
01472 
01473   rsl= gmti->webcut_with_sweep_curves(old_bodies,curves,axis,true,NULL,NULL,new_bodies,junk);
01474   if (rsl== CUBIT_FAILURE)
01475      return rsl;
01476   
01477   num_ents_exported=0;
01478   filename = "webcut_sweep.brep";
01479   ref_entity_list.clean_out();
01480   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
01481                                  num_ents_exported, cubit_version);
01482   assert(num_ents_exported == 4);
01483   remove(filename);
01484   return CUBIT_SUCCESS;
01485 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines