cgma
loft.cpp
Go to the documentation of this file.
00001 
00010 #undef NDEBUG
00011 #include <cassert>
00012 
00013 #include "GeometryModifyEngine.hpp"
00014 #include "GeometryModifyTool.hpp"
00015 #include "GeometryQueryTool.hpp"
00016 #include "CubitMessage.hpp"
00017 #include "Body.hpp"
00018 #include "RefVolume.hpp"
00019 #include "RefFace.hpp"
00020 #include "RefEdge.hpp"
00021 #include "RefVertex.hpp"
00022 #include "InitCGMA.hpp"
00023 #include "OCCBody.hpp"
00024 #include "OCCSurface.hpp"
00025 #include "OCCCurve.hpp"
00026 #include "OCCDrawTool.hpp"
00027 #include "CubitCompat.hpp"
00028 
00029 #ifndef SRCDIR
00030 # define SRCDIR .
00031 #endif
00032 
00033 #define STRINGIFY_(X) #X
00034 #define STRINGIFY(X) STRINGIFY_(X)
00035 #define SRCPATH STRINGIFY(SRCDIR) "/"
00036 
00037 // forward declare some functions used and defined later
00038 CubitStatus read_geometry(int, const char **, bool local = false);
00039 CubitStatus make_Point();
00040 // macro for printing a separator line
00041 #define PRINT_SEPARATOR   PRINT_INFO("=======================================\n");
00042 
00043 
00044 // main program - initialize, then send to proper function
00045 int main (int argc, char **argv)
00046 {
00047   CubitStatus status = InitCGMA::initialize_cgma("OCC");
00048   if (CUBIT_SUCCESS != status) return 1;
00049 
00050   //Do make point.
00051   status = make_Point();
00052   if (status == CUBIT_FAILURE) 
00053      PRINT_INFO("Operation Failed");
00054 
00055   int ret_val = ( CubitMessage::instance()->error_count() );
00056   if ( ret_val > 0 )
00057   {
00058     PRINT_ERROR("Errors found during Mergechk session.\n");
00059   }
00060   return ret_val;
00061   
00062 }
00063 
00068 CubitStatus read_geometry(int num_files, const char **argv, bool local) 
00069 {
00070   CubitStatus status = CUBIT_SUCCESS;
00071   GeometryQueryTool *gti = GeometryQueryTool::instance();
00072   assert(gti);
00073   int i;
00074   
00075   PRINT_SEPARATOR;
00076 
00077   for (i = 0; i < num_files; i++) {
00078     std::string filename( local ? "./" : SRCPATH );
00079     filename += argv[i];
00080     status = CubitCompat_import_solid_model(filename.c_str(), "OCC");
00081     if (status != CUBIT_SUCCESS) {
00082       PRINT_ERROR("Problems reading geometry file %s.\n", filename.c_str());
00083     }
00084   }
00085   PRINT_SEPARATOR;
00086 
00087   return CUBIT_SUCCESS;
00088 }
00089 
00090 CubitStatus make_Point()
00091 {
00092   GeometryQueryTool *gti = GeometryQueryTool::instance();
00093   GeometryModifyTool *gmti = GeometryModifyTool::instance();
00094 
00095   //test for loft two surfaces:
00096   Body* body = gmti->brick(10, 10, 10);
00097   CubitVector vector1(23,13,11);
00098   DLIList<Body*> bods;
00099   bods.append(body);
00100   gti->translate(bods, vector1);
00101   Body* body2 = gmti->brick(10, 10, 10);
00102 
00103   //use the surface1 and surface8 to make a loft
00104   DLIList<RefFace*> face_list;
00105   body->ref_faces(face_list);
00106   DLIList<RefFace*> loft_surfaces;
00107   face_list.last();
00108   loft_surfaces.append(face_list.get());
00109   face_list.clean_out();
00110   body2->ref_faces(face_list);
00111   face_list.last();
00112   face_list.back();
00113   loft_surfaces.append(face_list.get());
00114 
00115   //Do loft
00116   Body* new_body = NULL;
00117   DLIList<double> takeoff_factor_list;
00118   DLIList<RefFace*> takeoff_vector_surface_list;
00119   DLIList<CubitVector> surface_takeoff_vector_list;
00120   DLIList<RefEdge*> takeoff_vector_curve_list;
00121   DLIList<CubitVector> curve_takeoff_vector_list;
00122   DLIList<RefEdge*> guides;
00123   DLIList<RefVertex*> match_vertices_list;
00124   gmti->loft_surfaces_to_body(loft_surfaces, takeoff_factor_list, 
00125                            takeoff_vector_surface_list, 
00126                            surface_takeoff_vector_list, 
00127                            takeoff_vector_curve_list,
00128                            curve_takeoff_vector_list, guides,
00129                            match_vertices_list, new_body,
00130                            false, false, false, false);
00131   double volume = new_body->measure();
00132   assert(fabs(volume - 2100) < 0.000001);
00133 
00134   DLIList<RefEntity*> ref_entity_list;
00135   const CubitString cubit_version="12.2";
00136   int num_ents_exported=0;
00137   const char *filename = "loft.brep";
00138   const char *filetype = "OCC";
00139   CubitStatus rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
00140                                  num_ents_exported, cubit_version);
00141 
00142   assert(rsl);
00143   remove(filename);
00144   DLIList<Body*> bodies;
00145   gti->bodies(bodies);
00146 
00147   //delete all entities
00148   gti->delete_Body(bodies);
00149   
00150   CubitVector p1(0, 0 ,0);
00151   CubitVector p2(1, 0 ,0);
00152   CubitVector p3(0, 1 ,0);
00153   CubitVector p4(1, 1 ,0);
00154 
00155   gmti->make_RefVertex(p1,5);
00156   gmti->make_RefVertex(p2,5);
00157   gmti->make_RefVertex(p3,5);
00158   gmti->make_RefVertex(p4,5);
00159   DLIList<RefEntity*>  free_entities;
00160   gti->get_free_ref_entities(free_entities);
00161 
00162   RefVertex* vertex1 = CAST_TO(free_entities.step_and_get(),RefVertex);
00163   RefVertex* vertex2 = CAST_TO(free_entities.step_and_get(),RefVertex);
00164   RefVertex* vertex3 = CAST_TO(free_entities.step_and_get(),RefVertex);
00165   RefVertex* vertex4 = CAST_TO(free_entities.step_and_get(),RefVertex);
00166   RefEdge* new_edge1 = gmti->make_RefEdge(STRAIGHT_CURVE_TYPE, vertex1, vertex2);
00167   RefEdge* new_edge2 = gmti->make_RefEdge(STRAIGHT_CURVE_TYPE, vertex3, vertex4);
00168   DLIList<RefEdge*> edges;
00169   edges.append(new_edge1);
00170   edges.append(new_edge2);
00171   gmti->create_skin_surface(edges, new_body, guides); 
00172   CubitVector center = new_body->center_point();
00173   CubitVector comp (0.5, 0.5, 0);
00174   assert(center.distance_between(comp) < 0.00001);
00175   CubitBoolean is_sheet = new_body->is_sheet_body();
00176   assert(is_sheet == CUBIT_TRUE);  
00177   return CUBIT_SUCCESS;
00178 }
00179 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines