cgma
|
00001 00008 #ifdef NT 00009 //#include "stdafx.h" 00010 #endif 00011 00012 #include <math.h> 00013 #include "AppUtil.hpp" 00014 #include "CGMApp.hpp" 00015 #include "GeometryQueryTool.hpp" 00016 #include "FacetModifyEngine.hpp" 00017 #include "FacetQueryEngine.hpp" 00018 #include "CubitObserver.hpp" 00019 #include "CubitPointData.hpp" 00020 #include "CubitFacetData.hpp" 00021 00022 #include "TopologyBridge.hpp" 00023 #include "DLIList.hpp" 00024 #include "Surface.hpp" 00025 #include "ShellSM.hpp" 00026 #include "Lump.hpp" 00027 #include "Body.hpp" 00028 #include "RefFace.hpp" 00029 #include "RefVertex.hpp" 00030 00031 extern "C" void gl_cleanup() 00032 {} 00033 00035 int main (int argc, char **argv) 00036 { 00037 00038 if (argc == 1) { 00039 PRINT_INFO("Usage: facets <angle_val>\n" 00040 " where <angle_val> is the facet dihedral angle below which a\n" 00041 " model edge will be constructed.\n"); 00042 return 0; 00043 } 00044 00045 // first argument should be an angle 00046 double angle = atof(argv[1]); 00047 00048 // Initialize the GeometryTool 00049 GeometryQueryTool *gqt = GeometryQueryTool::instance(); 00050 FacetModifyEngine *fme = FacetModifyEngine::instance(); 00051 00052 DLIList<CubitFacet*> f_list; 00053 DLIList <CubitPoint*> p_list; 00054 00055 // define some really simple facets, corresponding to the 00056 // facets for a brick 00057 typedef CubitPointData CPD; typedef CubitFacetData CFD; 00058 CPD *p1 = new CPD(0, 0, 0); CPD *p2 = new CPD(1, 0, 0); 00059 CPD *p3 = new CPD(1, 1, 0); CPD *p4 = new CPD(0, 1, 0); 00060 CPD *p5 = new CPD(0, 0, 1); CPD *p6 = new CPD(1, 0, 1); 00061 CPD *p7 = new CPD(1, 1, 1); CPD *p8 = new CPD(0, 1, 1); 00062 p_list.append(p1); p_list.append(p2); 00063 p_list.append(p3); p_list.append(p4); 00064 p_list.append(p5); p_list.append(p6); 00065 p_list.append(p7); p_list.append(p8); 00066 CFD *f1 = new CFD(p1,p3,p2); CFD *f2 = new CFD(p1,p4,p3); // xy- 00067 CFD *f3 = new CFD(p5,p6,p8); CFD *f4 = new CFD(p6,p7,p8); // xy+ 00068 CFD *f5 = new CFD(p1,p8,p4); CFD *f6 = new CFD(p1,p5,p8); // yz- 00069 CFD *f7 = new CFD(p3,p7,p6); CFD *f8 = new CFD(p3,p6,p2); // yz+ 00070 CFD *f9 = new CFD(p1,p6,p5); CFD *f10 = new CFD(p1,p2,p6); // xz- 00071 CFD *f11 = new CFD(p3,p4,p8); CFD *f12 = new CFD(p3,p8,p7); // xz+ 00072 f_list.append(f1); f_list.append(f2); f_list.append(f3); 00073 f_list.append(f4); f_list.append(f5); f_list.append(f6); 00074 f_list.append(f7); f_list.append(f8); f_list.append(f9); 00075 f_list.append(f10); f_list.append(f11); f_list.append(f12); 00076 DLIList<LoopSM*> my_loops; 00077 00078 DLIList<Surface*> surf_list; 00079 CubitStatus result; 00080 result = fme->build_facet_surface(NULL, f_list, p_list, angle, 4, 00081 false, false, surf_list); 00082 00083 if ( surf_list.size() == 0 || result != CUBIT_SUCCESS ) 00084 { 00085 PRINT_ERROR("Problems building mesh based surfaces.\n"); 00086 return result; 00087 } 00088 else 00089 PRINT_INFO("Constructed %d surfaces.\n", surf_list.size()); 00090 00091 //Now build the shell. If we had it set up right this would be 00092 //in a loop. We need to store list of DLBlockSurfaceLists on each 00093 //blockvolumemesh to store the shell information. But that will 00094 //be saved for later. 00095 ShellSM *shell_ptr; 00096 result = fme->make_facet_shell(surf_list, shell_ptr); 00097 00098 if ( shell_ptr == NULL || result != CUBIT_SUCCESS ) 00099 { 00100 PRINT_ERROR("Problems building mesh based shell entity.\n"); 00101 return result; 00102 } 00103 DLIList<ShellSM*> shell_list; 00104 shell_list.append(shell_ptr); 00105 Lump *lump_ptr; 00106 result = fme->make_facet_lump(shell_list, lump_ptr); 00107 00108 if ( lump_ptr == NULL || result != CUBIT_SUCCESS ) 00109 { 00110 PRINT_ERROR("Problems building mesh based lump entity.\n"); 00111 return result; 00112 } 00113 DLIList<Lump*> lump_list; 00114 lump_list.append(lump_ptr); 00115 00116 BodySM *bodysm_ptr; 00117 Body *body_ptr; 00118 result = fme->make_facet_body(lump_list, bodysm_ptr); 00119 00120 body_ptr = GeometryQueryTool::instance()->make_Body(bodysm_ptr); 00121 00122 if ( body_ptr == NULL || result != CUBIT_SUCCESS ) 00123 { 00124 PRINT_ERROR("Problems building mesh based body entity.\n"); 00125 return result; 00126 } 00127 00128 if (!body_ptr) { 00129 exit(1); 00130 } 00131 00132 PRINT_INFO("Body successfully created.\n"); 00133 00134 PRINT_INFO("Number of vertices = %d\n", gqt->num_ref_vertices()); 00135 PRINT_INFO("Number of edges = %d\n", gqt->num_ref_edges()); 00136 PRINT_INFO("Number of faces = %d\n", gqt->num_ref_faces()); 00137 PRINT_INFO("Number of volumes = %d\n", gqt->num_ref_volumes()); 00138 PRINT_INFO("Number of bodies = %d\n", gqt->num_bodies()); 00139 00140 // print vertex positions 00141 DLIList<RefVertex*> verts; 00142 gqt->ref_vertices(verts); 00143 int i; 00144 for (i = verts.size(); i > 0; i--) { 00145 CubitVector coords = verts.get_and_step()->coordinates(); 00146 PRINT_INFO("Vertex %d: %4.2f, %4.2f, %4.2f.\n", 00147 8-i, coords.x(), coords.y(), coords.z()); 00148 } 00149 00150 RefFace *face = gqt->get_first_ref_face(); 00151 00152 // find closest point on each coordinate plane face center 00153 CubitVector test_position, result_position, normal; 00154 00155 test_position.set(.5, .5, 0); 00156 face->find_closest_point_trimmed(test_position, result_position); 00157 normal = face->normal_at(result_position); 00158 PRINT_INFO("Point (%4.2f, %4.2f, %4.2f):\n " 00159 "closest=(%4.2f, %4.2f, %4.2f), normal=(%4.2f, %4.2f, %4.2f).\n", 00160 test_position.x(), test_position.y(), test_position.z(), 00161 result_position.x(), result_position.y(), result_position.z(), 00162 normal.x(), normal.y(), normal.z()); 00163 00164 test_position.set(.5, .5, 1); 00165 face->find_closest_point_trimmed(test_position, result_position); 00166 normal = face->normal_at(result_position); 00167 PRINT_INFO("Point (%4.2f, %4.2f, %4.2f):\n " 00168 "closest=(%4.2f, %4.2f, %4.2f), normal=(%4.2f, %4.2f, %4.2f).\n", 00169 test_position.x(), test_position.y(), test_position.z(), 00170 result_position.x(), result_position.y(), result_position.z(), 00171 normal.x(), normal.y(), normal.z()); 00172 00173 test_position.set(.5, 0, .5); 00174 face->find_closest_point_trimmed(test_position, result_position); 00175 normal = face->normal_at(result_position); 00176 PRINT_INFO("Point (%4.2f, %4.2f, %4.2f):\n " 00177 "closest=(%4.2f, %4.2f, %4.2f), normal=(%4.2f, %4.2f, %4.2f).\n", 00178 test_position.x(), test_position.y(), test_position.z(), 00179 result_position.x(), result_position.y(), result_position.z(), 00180 normal.x(), normal.y(), normal.z()); 00181 00182 test_position.set(.5, 1, .5); 00183 face->find_closest_point_trimmed(test_position, result_position); 00184 normal = face->normal_at(result_position); 00185 PRINT_INFO("Point (%4.2f, %4.2f, %4.2f):\n " 00186 "closest=(%4.2f, %4.2f, %4.2f), normal=(%4.2f, %4.2f, %4.2f).\n", 00187 test_position.x(), test_position.y(), test_position.z(), 00188 result_position.x(), result_position.y(), result_position.z(), 00189 normal.x(), normal.y(), normal.z()); 00190 00191 test_position.set(0, .5, .5); 00192 face->find_closest_point_trimmed(test_position, result_position); 00193 normal = face->normal_at(result_position); 00194 PRINT_INFO("Point (%4.2f, %4.2f, %4.2f):\n " 00195 "closest=(%4.2f, %4.2f, %4.2f), normal=(%4.2f, %4.2f, %4.2f).\n", 00196 test_position.x(), test_position.y(), test_position.z(), 00197 result_position.x(), result_position.y(), result_position.z(), 00198 normal.x(), normal.y(), normal.z()); 00199 00200 test_position.set(1, .5, .5); 00201 face->find_closest_point_trimmed(test_position, result_position); 00202 normal = face->normal_at(result_position); 00203 PRINT_INFO("Point (%4.2f, %4.2f, %4.2f):\n " 00204 "closest=(%4.2f, %4.2f, %4.2f), normal=(%4.2f, %4.2f, %4.2f).\n", 00205 test_position.x(), test_position.y(), test_position.z(), 00206 result_position.x(), result_position.y(), result_position.z(), 00207 normal.x(), normal.y(), normal.z()); 00208 00209 double a = 1.0/3.0; 00210 double b = 1.0/3.0; 00211 double c = 1.0/3.0; 00212 CubitVector temp_point(a,b,c); 00213 CubitVector eval_point; 00214 00215 f1->evaluate( temp_point, &eval_point ); 00216 PRINT_INFO("Evaluation of facet 1 at (%4.2f, %4.2f, %4.2f) is " 00217 "(%4.2f, %4.2f, %4.2f).\n", 00218 a, b, c, eval_point.x(), eval_point.y(), eval_point.z() ); 00219 00220 a = 0.0; b = 1.0; c = 0.0; 00221 temp_point.set(a,b,c); 00222 f2->evaluate( temp_point, &eval_point ); 00223 PRINT_INFO("Evaluation of facet 2 at (%4.2f, %4.2f, %4.2f) is (%4.2f, %4.2f, %4.2f).\n", 00224 a, b, c, eval_point.x(), eval_point.y(), eval_point.z() ); 00225 a = 0.5; b = 0.5; c = 0.0; 00226 temp_point.set(a,b,c); 00227 f3->evaluate( temp_point, &eval_point ); 00228 PRINT_INFO("Evaluation of facet 3 at (%4.2f, %4.2f, %4.2f) is (%4.2f, %4.2f, %4.2f).\n", 00229 a, b, c, eval_point.x(), eval_point.y(), eval_point.z() ); 00230 a = 0.0; b = 0.5; c = 0.5; 00231 temp_point.set(a,b,c); 00232 f4->evaluate( temp_point, &eval_point ); 00233 PRINT_INFO("Evaluation of facet 4 at (%4.2f, %4.2f, %4.2f) is (%4.2f, %4.2f, %4.2f).\n", 00234 a, b, c, eval_point.x(), eval_point.y(), eval_point.z() ); 00235 00236 int ret_val = ( CubitMessage::instance()->error_count() ); 00237 00238 FacetQueryEngine * fqe = FacetQueryEngine::instance(); 00239 DLIList<TopologyBridge*> model; 00240 model.append( (TopologyBridge*)bodysm_ptr); 00241 ModelExportOptions opts; 00242 const char *arg = "brick.facet"; 00243 fqe->export_solid_model( 00244 model, arg, FACET_TYPE, 00245 CubitString(), opts); 00246 PRINT_INFO( "Wrote %s \n", arg); 00247 return ret_val; 00248 }