cgma
|
00001 00002 // Class: PointLoopFacetor 00003 // Description: 00004 // Creates a set of CubitFacets which is a Delauney triagulation of the boundary 00005 // points. No interior points are added. The points form a closed loop, and may 00006 // consist of several loops. The first loop must be the exterior loop, followed by 00007 // any internal loops (or holes). 00008 // Creator: David R. White 00009 // Owner: David R. White 00010 // Creation Date: 3/1/2003 00011 //------------------------------------------------------------------------------------ 00012 #include "PointLoopFacetor.hpp" 00013 #include "DLIList.hpp" 00014 #include "CubitPoint.hpp" 00015 #include "CubitFacet.hpp" 00016 #include "CubitFacetData.hpp" 00017 #include "CubitFacetEdge.hpp" 00018 #include "CubitPointData.hpp" 00019 #include "LoopParamTool.hpp" 00020 #include "TDVector.hpp" 00021 #include "FacetorTool.hpp" 00022 #include <stdio.h> 00023 CubitStatus PointLoopFacetor::generate_facets( PointLoopList &boundary_loops, 00024 DLIList<CubitFacet*> &resulting_triangles) 00025 { 00026 //First transform the boundary points to the XY plane. 00027 LoopParamTool *l_tool = new LoopParamTool; 00028 if ( l_tool->new_space_LoopParam(boundary_loops) != CUBIT_SUCCESS ) 00029 { 00030 delete l_tool; 00031 00032 PRINT_ERROR("Faild to generate loop u-v space for generating facets of boundary points.\n"); 00033 return CUBIT_FAILURE; 00034 } 00035 //Now transform the poins. 00036 int ii, jj; 00037 if ( l_tool->transform_loopspoints_to_uv(boundary_loops) != CUBIT_SUCCESS ) 00038 { 00039 write_xy(boundary_loops); 00040 //Now transform the points back to their original location and remomve the TDVector. 00041 CubitPoint *curr_point; 00042 ToolData *td; 00043 TDVector *td_vec; 00044 CubitVector orig_vec; 00045 PointList bounding_points, *curr_list; 00046 for ( ii = 0; ii < boundary_loops.size(); ii++) 00047 { 00048 curr_list = boundary_loops.get_and_step(); 00049 bounding_points += (*curr_list); 00050 } 00051 for ( ii = 0; ii < bounding_points.size(); ii++ ) 00052 { 00053 curr_point = bounding_points.get_and_step(); 00054 td = curr_point->get_TD(&TDVector::is_td_vector); 00055 if ( td == NULL ) 00056 { 00057 PRINT_ERROR("No TDVector on CubitPoint, can't transform back to x-y-z.\n"); 00058 assert(td !=NULL); 00059 } 00060 td_vec = CAST_TO(td, TDVector); 00061 orig_vec = td_vec->get_vector(); 00062 curr_point->set(orig_vec); 00063 curr_point->delete_TD(&TDVector::is_td_vector); 00064 } 00065 write_xyz(boundary_loops); 00066 00067 delete l_tool; 00068 PRINT_ERROR("Faild to transform loop to u-v space for generating facets of boundary points.\n"); 00069 return CUBIT_FAILURE; 00070 } 00071 delete l_tool; 00072 //now generate a triangulation for these nodes. 00073 int num_boundary_edges = 0; 00074 PointList bounding_points, *curr_list; 00075 for ( ii = 0; ii < boundary_loops.size(); ii++) 00076 { 00077 curr_list = boundary_loops.get_and_step(); 00078 num_boundary_edges += curr_list->size(); 00079 bounding_points += (*curr_list); 00080 } 00081 CubitPoint **start_nodes = new CubitPoint* [num_boundary_edges]; 00082 CubitPoint **end_nodes = new CubitPoint* [num_boundary_edges]; 00083 int array_index = 0; 00084 for ( ii = 0; ii < boundary_loops.size(); ii++ ) 00085 { 00086 curr_list = boundary_loops.get_and_step(); 00087 for ( jj = 0; jj < curr_list->size(); jj++ ) 00088 { 00089 assert(array_index < num_boundary_edges); 00090 start_nodes[array_index] = curr_list->get_and_step(); 00091 end_nodes[array_index] = curr_list->get(); 00092 array_index++; 00093 } 00094 } 00095 if ( array_index != bounding_points.size() ) 00096 { 00097 PRINT_ERROR("Problem building edge arrays for faceting.\n"); 00098 assert(array_index == bounding_points.size()); 00099 return CUBIT_FAILURE; 00100 } 00101 int dummy_variable = -1; 00102 int surf_id = 1; 00103 FacetorTool<int,CubitFacet, CubitFacetEdge, 00104 CubitPoint, CubitFacetData, CubitPointData, int> 00105 facetor = FacetorTool<int,CubitFacet, CubitFacetEdge, CubitPoint, 00106 CubitFacetData, CubitPointData, int> (&surf_id, bounding_points, 00107 start_nodes, end_nodes, num_boundary_edges, 00108 &dummy_variable, l_tool); 00109 if (facetor.mesh_surfwoIP(resulting_triangles) != CUBIT_SUCCESS ) 00110 { 00111 PRINT_ERROR("The facetor tool failed.\n"); 00112 return CUBIT_FAILURE; 00113 } 00114 //Now transform the points back to their original location and remomve the TDVector. 00115 CubitPoint *curr_point; 00116 ToolData *td; 00117 TDVector *td_vec; 00118 CubitVector orig_vec; 00119 for ( ii = 0; ii < bounding_points.size(); ii++ ) 00120 { 00121 curr_point = bounding_points.get_and_step(); 00122 td = curr_point->get_TD(&TDVector::is_td_vector); 00123 if ( td == NULL ) 00124 { 00125 PRINT_ERROR("No TDVector on CubitPoint, can't transform back to x-y-z.\n"); 00126 assert(td !=NULL); 00127 } 00128 td_vec = CAST_TO(td, TDVector); 00129 orig_vec = td_vec->get_vector(); 00130 curr_point->set(orig_vec); 00131 curr_point->delete_TD(&TDVector::is_td_vector); 00132 } 00133 //Now update the facet planes... 00134 CubitFacet *facet; 00135 for ( ii = 0; ii < resulting_triangles.size(); ii++ ) 00136 { 00137 facet = resulting_triangles.get_and_step(); 00138 facet->reset_bounding_box(); 00139 facet->update_plane(); 00140 } 00141 return CUBIT_SUCCESS; 00142 } 00143 void PointLoopFacetor::write_xyz(PointLoopList &boundary_loops) 00144 { 00145 00146 FILE *fp = fopen("Loop.txt", "w"); 00147 if (!fp) 00148 { 00149 PRINT_ERROR("Couldn't open temp file for writing.\n"); 00150 return; 00151 } 00152 PointList *node_loop; 00153 CubitPoint *point_ptr; 00154 CubitVector coords; 00155 fprintf(fp, "Real locations\n"); 00156 int ii, jj; 00157 for ( ii = boundary_loops.size(); ii > 0; ii-- ) 00158 { 00159 node_loop = boundary_loops.get_and_step(); 00160 fprintf(fp, "Loop %d, contains %d nodes\n", ii, node_loop->size()); 00161 node_loop->reset(); 00162 for(jj=0; jj<node_loop->size(); jj++) 00163 { 00164 point_ptr = node_loop->get_and_step(); 00165 coords = point_ptr->coordinates(); 00166 fprintf(fp,"%d\t%f\t%f\t%f\n", jj, coords.x(), coords.y(), coords.z()); 00167 } 00168 } 00169 fclose(fp); 00170 } 00171 void PointLoopFacetor::write_xy(PointLoopList &boundary_loops) 00172 { 00173 00174 FILE *fp = fopen("Loop_transformed.txt", "w"); 00175 if (!fp) 00176 { 00177 PRINT_ERROR("Couldn't open temp file for writing.\n"); 00178 return; 00179 } 00180 PointList *node_loop; 00181 CubitPoint *point_ptr; 00182 CubitVector coords; 00183 fprintf(fp, "Transformed locations\n"); 00184 int ii, jj; 00185 for ( ii = boundary_loops.size(); ii > 0; ii-- ) 00186 { 00187 node_loop = boundary_loops.get_and_step(); 00188 fprintf(fp, "Loop %d, contains %d nodes\n", ii, node_loop->size()); 00189 node_loop->reset(); 00190 for(jj=0; jj<node_loop->size(); jj++) 00191 { 00192 point_ptr = node_loop->get_and_step(); 00193 coords = point_ptr->coordinates(); 00194 fprintf(fp,"%d\t%f\t%f\n", jj, coords.x(), coords.y()); 00195 00196 } 00197 } 00198 fclose(fp); 00199 }