cgma
operation.cpp
Go to the documentation of this file.
00001 
00010 #undef NDEBUG
00011 #include <cassert>
00012 
00013 #include "GeometryModifyTool.hpp"
00014 #include "GeometryQueryTool.hpp"
00015 #include "CubitMessage.hpp"
00016 #include "Body.hpp"
00017 #include "RefVolume.hpp"
00018 #include "RefFace.hpp"
00019 #include "RefEdge.hpp"
00020 #include "RefVertex.hpp"
00021 #include "InitCGMA.hpp"
00022 #include "OCCModifyEngine.hpp"
00023 #include "CubitCompat.hpp"
00024 
00025 #include <algorithm>
00026 
00027 #ifndef SRCDIR
00028 # define SRCDIR .
00029 #endif
00030 
00031 #define STRINGIFY_(X) #X
00032 #define STRINGIFY(X) STRINGIFY_(X)
00033 #define SRCPATH STRINGIFY(SRCDIR) "/"
00034 
00035 // forward declare some functions used and defined later
00036 CubitStatus read_geometry(int, char **, bool local = false);
00037 CubitStatus make_Point();
00038 // macro for printing a separator line
00039 #define PRINT_SEPARATOR   PRINT_INFO("=======================================\n");
00040 
00041 
00042 // main program - initialize, then send to proper function
00043 int main (int argc, char **argv)
00044 {
00045   CubitStatus status = InitCGMA::initialize_cgma("OCC");
00046   if (CUBIT_SUCCESS != status) return 1;
00047 
00048   //Do make point.
00049   status = make_Point();
00050   if (status == CUBIT_FAILURE) 
00051      PRINT_INFO("Operation Failed");
00052 
00053   int ret_val = ( CubitMessage::instance()->error_count() );
00054   if ( ret_val > 0 )
00055   {
00056     PRINT_ERROR("Errors found during Mergechk session.\n");
00057   }
00058   return ret_val;
00059   
00060 }
00061 
00062 std::string type_from_file_name( const std::string& filename )
00063 {
00064   size_t dot_pos = filename.find_last_of( '.' );
00065   if (dot_pos == std::string::npos)
00066     return std::string();
00067  
00068   std::string extension = filename.substr( dot_pos + 1 );
00069   std::transform( extension.begin(), extension.end(), extension.begin(), ::tolower );
00070   if (extension == "occ" || extension == "brep")
00071     return "OCC";
00072   else if (extension == "step" || extension == "stp")
00073     return "STEP";
00074   else if (extension == "iges" || extension == "igs")
00075     return "IGES";
00076   else
00077     return std::string();
00078 }
00079 
00084 CubitStatus read_geometry(int num_files, const char **argv, bool local) 
00085 {
00086   CubitStatus status = CUBIT_SUCCESS;
00087   GeometryQueryTool *gti = GeometryQueryTool::instance();
00088   assert(gti);
00089   int i;
00090   
00091   PRINT_SEPARATOR;
00092 
00093   for (i = 0; i < num_files; i++) {
00094     std::string type = type_from_file_name( argv[i] );
00095     if (type.empty()) // just guess OCC
00096       type = "OCC";
00097     std::string filename( local ? "./" : SRCPATH );
00098     filename += argv[i];
00099     status = CubitCompat_import_solid_model(filename.c_str(), type.c_str());
00100     if (status != CUBIT_SUCCESS) {
00101       PRINT_ERROR("Problems reading geometry file %s.\n", filename.c_str());
00102       abort();
00103     }
00104   }
00105   PRINT_SEPARATOR;
00106 
00107   return CUBIT_SUCCESS;
00108 }
00109 
00110 CubitStatus make_Point()
00111 {
00112   GeometryQueryTool *gti = GeometryQueryTool::instance();
00113   GeometryModifyTool *gmti = GeometryModifyTool::instance();
00114 
00115   DLIList<Body*> bodies;
00116   DLIList<RefEntity*>  free_entities;
00117 
00118   // Read in the geometry from files specified on the command line
00119   const char *argv = "stitch.name_occ";
00120   CubitStatus status = read_geometry(1, &argv, false);
00121   if (status == CUBIT_FAILURE) exit(1);
00122   //Read in 2 volumes.
00123 
00124   gti->bodies(bodies);
00125   DLIList<Body*> new_bodies;
00126   DLIList<Body*> from_bodies;
00127   BodySM* from_body = bodies.get()->get_body_sm_ptr();
00128   from_bodies.append(bodies.get());
00129   CubitVector v1(.5,1,3);
00130   CubitVector v2(.5,2,2);
00131   CubitVector v3(.5,1,1);
00132   BodySM* midplane_bodysm = 0;
00133   status = OCCModifyEngine::instance()->get_mid_plane(v1, v2, v3, from_body, midplane_bodysm);
00134   if(midplane_bodysm)
00135   {
00136     Body *midplane_body;
00137     midplane_body = gti->make_Body(midplane_bodysm);
00138     double d = midplane_body->measure();
00139     assert( d > 99.9999 && d < 100.00001);
00140   }
00141 
00142   v1.x(2);
00143   v2.x(2);
00144   v3.x(2);
00145   
00146   midplane_bodysm = 0;
00147   status = OCCModifyEngine::instance()->get_mid_plane(v1, v2, v3, from_body, midplane_bodysm);
00148   if(midplane_bodysm)
00149   {
00150     Body *midplane_body;
00151     midplane_body = gti->make_Body(midplane_bodysm);
00152     double d = midplane_body->measure();
00153     assert( d > 69.9999 && d < 70.00001);
00154   }
00155 
00156   DLIList<Body*> neighbor_list;
00157   status = gmti->webcut_with_plane(from_bodies, v1, v2, v3, new_bodies, neighbor_list, ONLY_INVOLVED_BODIES);
00158   double d = new_bodies.step_and_get()->measure();
00159   //CubitVector v = new_bodies.get()->center_point();
00160   int n = new_bodies.get()->num_ref_faces();
00161   assert(n==8);
00162   assert(d <= 710 && d > 709.999999);
00163   // n = 8
00164   //new bodies has 2 bodies, one has a volume = 170 and the other has a 
00165   //volume = 710; each of them has 8 ref_faces. 
00166 
00167   bodies.clean_out();
00168   gti->bodies(bodies);
00169   //delete all entities
00170   gti->delete_Body(bodies); 
00171   
00172   gti->get_free_ref_entities(free_entities);
00173   assert(free_entities.size() ==0);
00174 
00175   return CUBIT_SUCCESS;
00176 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines