cgma
|
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 point_project(); 00040 // macro for printing a separator line 00041 #define PRINT_SEPARATOR PRINT_INFO("=======================================\n"); 00042 00043 // main program - initialize, then send to proper function 00044 int main (int argc, char **argv) 00045 { 00046 CubitStatus status = InitCGMA::initialize_cgma("OCC"); 00047 if (CUBIT_SUCCESS != status) return 1; 00048 00049 //Do make point. 00050 status = point_project(); 00051 if (status == CUBIT_FAILURE) 00052 PRINT_INFO("Operation Failed"); 00053 00054 int ret_val = ( CubitMessage::instance()->error_count() ); 00055 if ( ret_val > 0 ) 00056 { 00057 PRINT_ERROR("Errors found during Mergechk session.\n"); 00058 } 00059 return ret_val; 00060 00061 } 00062 00067 CubitStatus read_geometry(int num_files, const char **argv, bool local) 00068 { 00069 CubitStatus status = CUBIT_SUCCESS; 00070 GeometryQueryTool *gti = GeometryQueryTool::instance(); 00071 assert(gti); 00072 int i; 00073 00074 PRINT_SEPARATOR; 00075 00076 for (i = 0; i < num_files; i++) { 00077 std::string filename( local ? "./" : SRCPATH ); 00078 filename += argv[i]; 00079 status = CubitCompat_import_solid_model(filename.c_str(), "OCC"); 00080 if (status != CUBIT_SUCCESS) { 00081 PRINT_ERROR("Problems reading geometry file %s.\n", filename.c_str()); 00082 } 00083 } 00084 PRINT_SEPARATOR; 00085 00086 return CUBIT_SUCCESS; 00087 } 00088 00089 CubitStatus point_project() 00090 { 00091 GeometryQueryTool *gti = GeometryQueryTool::instance(); 00092 00093 const char *argv = "box-w-hole.brep"; 00094 CubitStatus status = read_geometry(1, &argv); 00095 if (status == CUBIT_FAILURE) exit(1); 00096 00097 DLIList<Body*> test_bodies; 00098 gti->bodies(test_bodies); 00099 DLIList<Surface*> surfaces; 00100 BodySM* body = test_bodies.get()->get_body_sm_ptr(); 00101 body->surfaces(surfaces); 00102 Surface* surf = NULL; 00103 for (int i = 0 ; i < surfaces.size(); i++) 00104 { 00105 surf = surfaces.get_and_step(); 00106 double d = surf->measure(); 00107 if (d < 82.1 && d > 81.9) 00108 break; 00109 } 00110 CubitVector point(1,1,-5); 00111 CubitVector on_surf; 00112 surf->closest_point_trimmed(point, on_surf); 00113 std::cout << "Point on surface closest to (1, 1, -5) is (" << on_surf.x() 00114 << ", " << on_surf.y() << ", " << on_surf.z() << ")" << std::endl; 00115 assert (fabs(on_surf.z() + 5) < 0.0001); 00116 if (on_surf.y() < on_surf.x()) 00117 { 00118 assert (on_surf.y() < 1.001 && on_surf.y() > 0.999); 00119 assert (on_surf.x() < 2.122 && on_surf.x() > 2.121 ); 00120 } 00121 else 00122 { 00123 assert (on_surf.y() < 2.122 && on_surf.y() > 2.121 ); 00124 assert (on_surf.x() < 1.001 && on_surf.x() > 0.999); 00125 } 00126 00127 CubitVector p1(0, 1.5, -6 ); 00128 surf->closest_point_trimmed(p1, on_surf); 00129 std::cout << "Point on surface closest to (0, 1.5, -6) is (" << on_surf.x() 00130 << ", " << on_surf.y() << ", " << on_surf.z() << ")" << std::endl; 00131 assert (fabs(on_surf.z() + 5) < 0.0001); 00132 assert (on_surf.y() < 2.122 && on_surf.y() > 2.121); 00133 assert (on_surf.x() < 0.0001 && on_surf.x() > -0.0001 ); 00134 return CUBIT_SUCCESS; 00135 }