cgma
|
00001 #undef NDEBUG 00002 #include <cassert> 00003 #include <cstdio> 00004 #include <cstdlib> 00005 #include <list> 00006 #include <map> 00007 #include <string> 00008 00009 #include "GeometryModifyTool.hpp" 00010 #include "GeometryQueryTool.hpp" 00011 #include "GMem.hpp" 00012 #include "OCCModifyEngine.hpp" 00013 #include "OCCQueryEngine.hpp" 00014 #include "RefVertex.hpp" 00015 #include "RefEdge.hpp" 00016 #include "RefFace.hpp" 00017 #include "RefVolume.hpp" 00018 #include "InitCGMA.hpp" 00019 #include "CubitCompat.hpp" 00020 00021 #define STRINGIFY(S) XSTRINGIFY(S) 00022 #define XSTRINGIFY(S) #S 00023 #ifndef SRCDIR 00024 # define SRCDIR "." 00025 #endif 00026 00027 using std::list; 00028 using std::pair; 00029 using std::set; 00030 using std::map; 00031 using std::vector; 00032 00033 int main( int argc, char** argv ) { 00034 00035 CubitStatus status = InitCGMA::initialize_cgma("OCC"); 00036 if (CUBIT_SUCCESS != status) return 1; 00037 GeometryQueryTool *gti = GeometryQueryTool::instance(); 00038 00039 // Read in the geometry from files specified on the command line 00040 const char* filename = STRINGIFY(SRCDIR) "/LeverArm.brep"; 00041 status = CubitCompat_import_solid_model(filename, "OCC"); 00042 if (status != CUBIT_SUCCESS) { 00043 PRINT_ERROR("Problems reading geometry file %s.\n", filename); 00044 return 1; 00045 } 00046 00047 DLIList<RefEdge*> my_curvs; 00048 DLIList<RefFace*> my_surfs; 00049 gti->ref_edges(my_curvs); 00050 gti->ref_faces(my_surfs); 00051 00052 // ***** Discretize the curves ***** // 00053 00054 map< RefEdge*, list<double> > discrete_curves; 00055 00056 for(int i = 0; i < my_curvs.size(); ++i) { 00057 00058 list<double> sample_params; 00059 RefEdge* this_curv = my_curvs.get_and_step(); 00060 //Insert nine arbitrary points on each curves 00061 double delta = this_curv->end_param() - this_curv->start_param(); 00062 for(int j = 1; j < 10; ++j) 00063 sample_params.push_back( this_curv->start_param() + (static_cast<double>(j) * delta / 10.) ); 00064 00065 discrete_curves.insert( std::make_pair(this_curv, sample_params) ); 00066 00067 } 00068 00069 //Pick one of the surfaces arbitrarily and attempt to find the u-v coordinates 00070 //of the points discretizing the boundary of this surface. 00071 00072 { 00073 00074 RefFace* this_surf = my_surfs.next(7); 00075 DLIList<RefVertex*> surf_points; 00076 DLIList<RefEdge*> surf_curves; 00077 this_surf->ref_vertices(surf_points); 00078 this_surf->ref_edges(surf_curves); 00079 00080 CubitVector coord0, coord1; 00081 double u, v; 00082 00083 double max_u, min_u, max_v, min_v; 00084 this_surf->get_param_range_U(min_u, max_u); 00085 this_surf->get_param_range_V(min_v, max_v); 00086 00087 //Deals with curve end points. 00088 00089 for(int i = 0; i < surf_points.size(); ++i) { 00090 00091 RefVertex* this_point = surf_points.get_and_step(); 00092 00093 u = v = -1.e300; 00094 coord0 = this_point->coordinates(); 00095 this_surf->u_v_from_position(coord0, u, v, &coord1); 00096 00097 if( u < min_u || v < min_v ) { 00098 printf("Failed to find a parameter with valid range for an apex point\n"); 00099 printf(" point coords: %e %e %e\n", coord0.x(), coord0.y(), coord0.z()); 00100 printf(" projected coords: %e %e %e\n", coord1.x(), coord1.y(), coord1.z()); 00101 printf(" params returned: %e %e\n\n", u, v); 00102 return 1; 00103 } 00104 00105 } 00106 00107 //Deals with discretization points on curves. 00108 00109 for(int i = 0; i < surf_curves.size(); ++i) { 00110 00111 RefEdge* this_curv = surf_curves.get_and_step(); 00112 00113 assert(discrete_curves.count(this_curv) == 1); 00114 list<double> curve_params = discrete_curves.find(this_curv)->second; 00115 list<double>::iterator it = curve_params.begin(), it_end = curve_params.end(); 00116 00117 for( ; it != it_end; ++it) { 00118 00119 u = v = -1.e300; 00120 this_curv->position_from_u(*it, coord0); 00121 this_surf->u_v_from_position(coord0, u, v, &coord1); 00122 00123 if( u < min_u || v < min_v ) { 00124 printf("Failed to find a parameter with valid range for a curve point\n"); 00125 printf(" point coords: %e %e %e\n", coord0.x(), coord0.y(), coord0.z()); 00126 printf(" projected coords: %e %e %e\n", coord1.x(), coord1.y(), coord1.z()); 00127 printf(" params returned: %e %e\n\n", u, v); 00128 return 1; 00129 } 00130 00131 } 00132 00133 } 00134 00135 } 00136 00137 printf("done...\n"); 00138 00139 return(0); 00140 00141 }