cgma
|
00001 //----------------------------------------------------------- 00002 // Class: MedialTool2D 00003 // Description: Creates medials for 2D surfaces. Uses the CMU 00004 // code for creating the medial. This class 00005 // serves as the interface to that. 00006 // Creator: David white 00007 // Date: 6/21/2002 00008 //----------------------------------------------------------- 00009 #include "MedialTool2D.hpp" 00010 #include "CubitMessage.hpp" 00011 #ifdef USING_MEDIAL 00012 #include "GfxDebug.hpp" 00013 #include "CubitVector.hpp" 00014 #include "RefEdge.hpp" 00015 #include "RefFace.hpp" 00016 #include "CoEdge.hpp" 00017 #include "Curve.hpp" 00018 #include "RefVertex.hpp" 00019 #include "GeometryQueryEngine.hpp" 00020 #include "VirtualGeometryEngine.hpp" 00021 //----------medial includes--------------------- 00022 #include "medial/medial_util/MedialDefines.hpp" 00023 #include "medial/medial2D/Medial2DAPI.hpp" 00024 #include "medial/medial_util/Vec3D.hpp" 00025 #include "medial/medial2D/MedialVertex.hpp" 00026 #include "medial/medial2D/MedialSegment.hpp" 00027 //----------medial includes--------------------- 00028 #endif //USING_MEDIAL 00029 00030 00031 MedialTool2D::MedialTool2D(RefFace *ref_face) 00032 { 00033 myRefFace = ref_face; 00034 } 00035 MedialTool2D::~MedialTool2D() 00036 { 00037 //do nothing for now. 00038 } 00039 #ifndef USING_MEDIAL 00040 CubitStatus MedialTool2D::create_medial_axis(DLIList <RefEdge*>&, double, double) 00041 { 00042 PRINT_ERROR("Medial Axis Code is not included with this version of CGM.\n"); 00043 return CUBIT_FAILURE; 00044 } 00045 #endif //USING_MEDIAL 00046 //--------------------------------------------------------------------------- 00047 //Functions that get compiled only when compiling in the medial stuff 00048 //--------------------------------------------------------------------------- 00049 #ifdef USING_MEDIAL 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 CubitStatus MedialTool2D::create_medial_axis( DLIList <RefEdge*> &medial_axis, 00064 double cell_size, 00065 double angle_tol) 00066 { 00067 //first get the loop of edges. 00068 PointLoopList boundary_point_loops; 00069 CubitStatus stat = get_boundary_points(myRefFace, 00070 boundary_point_loops); 00071 00072 //Now convert these to segments. 00073 MedialSegmentPLoop boundary_segments; 00074 stat = convert_to_segments(boundary_point_loops, boundary_segments); 00075 00076 MedialSegmentPArray output_segments; 00077 MedialVertexPArray output_points; 00078 int results = Medial2DAPI::create_medial(boundary_segments, output_points, 00079 output_segments, cell_size, 00080 angle_tol); 00081 if ( results != 1 ) 00082 { 00083 PRINT_ERROR("Medial Extraction Failed.\n"); 00084 return CUBIT_FAILURE; 00085 } 00086 00087 // create geometry from the medial results 00088 // create_medial_geometry( output_points, output_segments, medial_axis ); 00089 draw_results(output_points, output_segments); 00090 00091 free_medial_memory(output_points, output_segments); 00092 00093 return CUBIT_SUCCESS; 00094 } 00095 00097 void MedialTool2D::draw_results( MedialVertexPArray &output_points, 00098 MedialSegmentPArray &output_segments ) 00099 { 00100 int ii; 00101 CubitVector vec, vec_2; 00102 Vec3D point, start_point, end_point; 00103 MedialVertex *vertex, *start, *end; 00104 MedialSegment *seg; 00105 for ( ii = 0; ii < output_points.size(); ii++ ) 00106 { 00107 vertex = output_points[ii]; 00108 point = vertex->coordinates(); 00109 convert_from_vec3d(point,vec); 00110 GfxDebug::draw_point(&vec,CUBIT_RED_INDEX); 00111 GfxDebug::flush(); 00112 } 00113 GfxDebug::flush(); 00114 00115 for ( ii = 0; ii < output_segments.size(); ii++ ) 00116 { 00117 seg = output_segments[ii]; 00118 start = seg->get_start(); 00119 end = seg->get_end(); 00120 start_point = start->coordinates(); 00121 end_point = end->coordinates(); 00122 GfxDebug::draw_line( start_point.x, start_point.y, 00123 start_point.z, end_point.x, 00124 end_point.y, end_point.z, 00125 CUBIT_CYAN_INDEX); 00126 GfxDebug::flush(); 00127 } 00128 GfxDebug::flush(); 00129 } 00130 00138 void MedialTool2D::free_medial_memory(MedialVertexPArray &vertices, 00139 MedialSegmentPArray &segments) 00140 { 00141 int ii; 00142 MedialSegment *currs; 00143 MedialVertex *currv; 00144 00145 for(ii=0; ii < segments.size(); ii++) 00146 { 00147 currs = segments[ii]; 00148 delete currs; 00149 } 00150 00151 for(ii=0; ii < vertices.size(); ii++) 00152 { 00153 currv = vertices[ii]; 00154 delete currv; 00155 } 00156 } 00157 00158 00159 00160 CubitStatus MedialTool2D::convert_to_segments( 00161 PointLoopList &boundary_point_loops, 00162 MedialSegmentPLoop &boundary_segments) 00163 { 00164 int ii; 00165 PointList *point_loop; 00166 int jj; 00167 MedialVertex *start_vert, *end_vert; 00168 MedialSegment *new_seg; 00169 MedialSegmentPArray *new_vector; 00170 for ( ii = 0; ii < boundary_point_loops.size(); ii++ ) 00171 { 00172 point_loop = boundary_point_loops.get_and_step(); 00173 new_vector = new MedialSegmentPArray; 00174 for ( jj = 0; jj < point_loop->size(); jj++ ) 00175 { 00176 start_vert = point_loop->get_and_step(); 00177 end_vert = point_loop->get(); 00178 new_seg = new MedialSegment(start_vert, end_vert); 00179 new_vector->push_back(new_seg); 00180 } 00181 boundary_segments.push_back(new_vector); 00182 } 00183 return CUBIT_SUCCESS; 00184 } 00185 00186 00187 CubitStatus MedialTool2D::get_boundary_points( RefFace *ref_face, 00188 PointLoopList &boundary_point_loops ) 00189 { 00190 DLIList<DLIList<CoEdge*>*> co_edge_loops; 00191 ref_face->co_edge_loops(co_edge_loops); 00192 int ii, jj; 00193 DLIList <CoEdge*> *co_edge_list_ptr; 00194 PointList *new_point_loop_ptr, tmp_point_list; 00195 RefEdge *ref_edge_ptr; 00196 CoEdge *co_edge_ptr; 00197 CubitStatus stat; 00198 CubitSense sense; 00199 RefVertex *temp_vert; 00200 double tolerance = 500*GEOMETRY_RESABS; 00201 00202 00203 for ( ii = co_edge_loops.size(); ii > 0; ii-- ) 00204 { 00205 co_edge_list_ptr = co_edge_loops.get_and_step(); 00206 new_point_loop_ptr = new PointList; 00207 for ( jj = co_edge_list_ptr->size(); jj > 0; jj-- ) 00208 { 00209 co_edge_ptr = co_edge_list_ptr->get_and_step(); 00210 ref_edge_ptr = co_edge_ptr->get_ref_edge_ptr(); 00211 tmp_point_list.clean_out(); 00212 stat = get_curve_facets( ref_edge_ptr, tmp_point_list ); 00213 PRINT_DEBUG_129("curve %d has %d points\n", 00214 ref_edge_ptr->id(), 00215 tmp_point_list.size()); 00216 if ( stat != CUBIT_SUCCESS ) 00217 return CUBIT_FAILURE; 00218 tmp_point_list.reset(); 00219 //the points are in order from start vertex to end vertex. 00220 //append them now according to the loop. 00221 00222 //Assign the points to be part owned by the vertex, rather than the 00223 //curve. 00224 if ( ref_edge_ptr->start_vertex() != 00225 ref_edge_ptr->end_vertex() ) 00226 { 00227 MedialVertex *temp_point = tmp_point_list.get(); 00228 Vec3D temp_v1 = temp_point->coordinates(); 00229 CubitVector v1; 00230 convert_from_vec3d(temp_v1, v1); 00231 CubitVector v2 = ref_edge_ptr->start_vertex()->coordinates(); 00232 if ( !v1.within_tolerance(v2, tolerance) ) 00233 { 00234 PRINT_ERROR("Problem with surface geometry\n" 00235 "Check surface %d, especially curve %d\n", 00236 myRefFace->id(), ref_edge_ptr->id()); 00237 return CUBIT_FAILURE; 00238 } 00239 temp_vert = ref_edge_ptr->start_vertex(); 00240 temp_point = tmp_point_list.prev(); 00241 temp_v1 = temp_point->coordinates(); 00242 convert_from_vec3d(temp_v1, v1); 00243 v2 = ref_edge_ptr->end_vertex()->coordinates(); 00244 if (!v1.within_tolerance(v2, tolerance)) 00245 { 00246 PRINT_ERROR("Problem with surface geometry\n" 00247 "Check surface %d and %d, especially curve %d\n", 00248 myRefFace->id(), ref_edge_ptr->id()); 00249 return CUBIT_FAILURE; 00250 } 00251 temp_vert = ref_edge_ptr->end_vertex(); 00252 } 00253 else 00254 { 00255 00256 } 00257 tmp_point_list.reset(); 00258 sense = co_edge_ptr->get_sense(); 00259 if ( CUBIT_FORWARD != sense ) 00260 tmp_point_list.reverse(); 00261 //Now take off the last point as it is a duplicate with the 00262 //other list... 00263 tmp_point_list.reset(); 00264 if ( co_edge_list_ptr->size() != 1 ) 00265 tmp_point_list.pop(); 00266 (*new_point_loop_ptr) += tmp_point_list; 00267 } 00268 boundary_point_loops.append(new_point_loop_ptr); 00269 } 00270 //clean up the list memory. 00271 for(ii = co_edge_loops.size(); ii>0; ii-- ) 00272 delete co_edge_loops.pop(); 00273 co_edge_loops.clean_out(); 00274 00275 return CUBIT_SUCCESS; 00276 } 00277 00278 CubitStatus MedialTool2D::get_curve_facets( RefEdge* curve, PointList &segments ) 00279 { 00280 const double COS_ANGLE_TOL = 0.996194698091745545198705; // cos(5) 00281 GMem curve_graphics; 00282 double tolerance = 500*GEOMETRY_RESABS; 00283 00284 const double dist_tol = tolerance; 00285 const double dist_tol_sqr = dist_tol*dist_tol; 00286 int n; 00287 curve->get_curve_ptr()->get_geometry_query_engine()->get_graphics_edges( 00288 curve, n, &curve_graphics ); 00289 00290 GPoint* gp = curve_graphics.point_list(); 00291 CubitVector lastv(gp[0].x, gp[0].y, gp[0].z); 00292 Vec3D last_v3d; 00293 convert_to_vec3d(lastv, last_v3d); 00294 MedialVertex* last = new MedialVertex(last_v3d); 00295 int num_points = curve_graphics.pointListCount; 00296 segments.append( last ); 00297 int ii; 00298 CubitBoolean remove_second_to_end = CUBIT_FALSE; 00299 for ( ii = 1; ii < num_points; ii++ ) 00300 { 00301 CubitVector pos( gp[ii].x, gp[ii].y, gp[ii].z ); 00302 CubitVector step1 = (pos - lastv); 00303 double len1 = step1.length(); 00304 if( len1 < dist_tol && ii != num_points - 1) 00305 continue; 00306 else if ( len1 < dist_tol && ii == num_points-1 ) 00307 { 00308 remove_second_to_end = CUBIT_TRUE; 00309 } 00310 Vec3D point; 00311 convert_to_vec3d(pos,point); 00312 last = new MedialVertex(point); 00313 segments.append( last ); 00314 lastv = pos; 00315 } 00316 // Now check if the segment list is reversed wrt the curve direction. 00317 segments.reset(); 00318 if ( remove_second_to_end ) 00319 { 00320 if ( segments.size() == 2 ) 00321 { 00322 } 00323 else 00324 { 00325 //Remove the second to last one. To do 00326 //this efficiently (don't do remove), pop 00327 //the last one, then save that and 00328 //re-add it after poping the second one. 00329 MedialVertex *temp = segments.pop(); 00330 segments.pop(); 00331 segments.append(temp); 00332 } 00333 } 00334 segments.reset(); 00335 if( curve->start_vertex() != curve->end_vertex() ) 00336 { 00337 CubitVector start_vec, end_vec; 00338 start_vec = curve->start_vertex()->coordinates(); 00339 end_vec = curve->end_vertex()->coordinates(); 00340 Vec3D temp_pos = segments.get()->coordinates(); 00341 CubitVector start_seg; 00342 convert_from_vec3d(temp_pos, start_seg); 00343 double dist_1 = (start_seg - start_vec).length_squared(); 00344 double dist_2 = (start_seg - end_vec).length_squared(); 00345 if ( dist_1 > dist_2 ) 00346 segments.reverse(); 00347 } 00348 else 00349 { 00350 double u1, u2; 00351 CubitVector next_1, next_2; 00352 Vec3D temp_next_1, temp_next_2; 00353 temp_next_1 = segments.next(1)->coordinates(); 00354 temp_next_2 = segments.next(2)->coordinates(); 00355 convert_from_vec3d(temp_next_1, next_1); 00356 convert_from_vec3d(temp_next_2, next_2); 00357 u1 = curve->u_from_position( next_1 ); 00358 u2 = curve->u_from_position( next_2 ); 00359 if( (u2 < u1) && (curve->start_param() <= curve->end_param()) ) 00360 segments.reverse(); 00361 } 00362 //clean up the periodic curve case (last seg may be too small.) 00363 if ( curve->start_vertex() == curve->end_vertex() ) 00364 { 00365 segments.reset(); 00366 CubitVector start_v, last_v; 00367 Vec3D temp_start_v, temp_last_v; 00368 temp_start_v = segments.get()->coordinates(); 00369 temp_last_v = segments.prev()->coordinates(); 00370 convert_from_vec3d(temp_start_v, start_v); 00371 convert_from_vec3d(temp_last_v, last_v); 00372 double dist = (start_v - last_v).length(); 00373 if ( dist < dist_tol ) 00374 { 00375 //remove the last one. 00376 segments.pop(); 00377 } 00378 } 00379 if ( segments.size() < 2 ) 00380 { 00381 PRINT_ERROR("Problem with getting boundary segments.\n"); 00382 return CUBIT_FAILURE; 00383 } 00384 return CUBIT_SUCCESS; 00385 } 00386 void MedialTool2D::convert_from_vec3d(Vec3D &vec, CubitVector &new_vec) 00387 { 00388 new_vec.set(vec.x, vec.y, vec.z); 00389 } 00390 void MedialTool2D::convert_to_vec3d(CubitVector& vec, Vec3D &new_vec) 00391 { 00392 new_vec.x = vec.x(); 00393 new_vec.y = vec.y(); 00394 new_vec.z = vec.z(); 00395 } 00396 00404 CubitStatus MedialTool2D::create_medial_geometry(MedialVertexPArray &output_points, 00405 MedialSegmentPArray &output_segments, 00406 DLIList<RefEdge*> &medial_axis) 00407 { 00408 int ii; 00409 int jj; 00410 int iii; 00411 int jjj; 00412 int r=0; 00413 MedialSegment *seg1, *seg2, *curr_seg; 00414 MedialVertex *start1, *start2, *end1, *end2; 00415 Vec3D start_point1, start_point2, end_point1, end_point2; 00416 for( ii=0; ii < output_segments.size(); ii++)//finding a segment attached to only one segment 00417 { 00418 seg1 = output_segments[ii]; 00419 start1 = seg1->get_start(); 00420 end1 = seg1->get_end(); 00421 start_point1 = start1->coordinates(); 00422 end_point1 = end1->coordinates(); 00423 for ( jj = 0; jj < output_segments.size(); jj++) 00424 { 00425 seg2 = output_segments[jj]; 00426 start2 = seg2->get_start(); 00427 end2 = seg2->get_end(); 00428 start_point2 = start2->coordinates(); 00429 end_point2 = end2->coordinates(); 00430 if ( start_point1 == start_point2 || start_point1 == end_point2 || end_point1 == start_point2 || end_point1 == end_point2) 00431 r=r+1; 00432 } 00433 if( r == 2) 00434 break; 00435 else 00436 r=0; 00437 } 00438 00439 curr_seg = output_segments[ii]; 00440 DLIList<DLIList<MedialSegment*>*> segment_listoflist; 00441 DLIList<MedialSegment*> *seg_list; 00442 00443 r = 0;// 00444 int w = 0; 00445 int b = 0; 00446 int y = 0; 00447 int x = 0; //no. of points at which more than one medial are emerging 00448 int a[50];//tracks number of medials attached to a particular point ( used as a[x] ) 00449 int v[50];//tracks segments attached to a particular segment in the output_segments list 00450 int u[50];//no. of medials emerging from a point 00451 int z[50][50];//first subscript represents no. of diverging points ; second represents no.of medial attached to a particular diverging point 00452 u[0] = -1; 00453 int flag = 0; 00454 00455 seg_list = new DLIList<MedialSegment*>; 00456 seg_list->append(curr_seg); 00457 output_segments[ii] = NULL; 00458 seg1 = curr_seg; 00459 00460 for( ii=0; ii < output_segments.size()-1; ii++) 00461 { 00462 00463 start1 = seg1->get_start(); 00464 end1 = seg1->get_end(); 00465 start_point1 = start1->coordinates(); 00466 end_point1 = end1->coordinates(); 00467 00468 for ( jj = 0; jj < output_segments.size(); jj++) 00469 { 00470 if( output_segments[jj] == NULL) 00471 continue; 00472 else 00473 { 00474 for ( jjj = 0; jjj <= b; jjj++) 00475 { 00476 if ( jj == u[jjj] ) 00477 { 00478 flag = 1; 00479 break; 00480 } 00481 } 00482 if ( flag ) 00483 00484 { 00485 flag = 0; 00486 continue; 00487 } 00488 else 00489 { 00490 seg2 = output_segments[jj]; 00491 start2 = seg2->get_start(); 00492 end2 = seg2->get_end(); 00493 start_point2 = start2->coordinates(); 00494 end_point2 = end2->coordinates(); 00495 } 00496 } 00497 00498 00499 00500 if ( start_point1 == start_point2 || start_point1 == end_point2 || end_point1 == start_point2 || end_point1 == end_point2) 00501 { 00502 w = r; 00503 v[w] = jj; 00504 curr_seg = output_segments[jj]; 00505 r = r+1; 00506 00507 } 00508 }//endof for jj 00509 00510 if( r == 1)// only one segment attached to a given segment 00511 { 00512 seg_list->append(curr_seg); 00513 seg1 = curr_seg; 00514 output_segments[v[w]] = NULL; 00515 curr_seg = NULL; 00516 r = 0; 00517 if ( ii == output_segments.size()-2 ) 00518 { 00519 segment_listoflist.append(seg_list); 00520 } 00521 00522 }// end of if ( r == 1 ) 00523 00524 else 00525 { 00526 if( r == 0)// no segment attached to a given segment 00527 { 00528 segment_listoflist.append(seg_list); 00529 if ( x == 0 && y == 0 )//getting a segment with only one segment attached to it 00530 { 00531 for( ii=0; ii < output_segments.size(); ii++) 00532 { 00533 if ( output_segments [ii] == NULL) 00534 continue; 00535 else 00536 { 00537 seg1 = output_segments[ii]; 00538 start1 = seg1->get_start(); 00539 end1 = seg1->get_end(); 00540 start_point1 = start1->coordinates(); 00541 end_point1 = end1->coordinates(); 00542 } 00543 for ( jj = 0; jj < output_segments.size(); jj++) 00544 { 00545 if ( output_segments[jj] == NULL ) 00546 continue; 00547 else 00548 { 00549 seg2 = output_segments[jj]; 00550 start2 = seg2->get_start(); 00551 end2 = seg2->get_end(); 00552 start_point2 = start2->coordinates(); 00553 end_point2 = end2->coordinates(); 00554 }// end of if ( output_segments[jj] == NULL ) 00555 if ( start_point1 == start_point2 || start_point1 == end_point2 || end_point1 == start_point2 || end_point1 == end_point2) 00556 r=r+1; 00557 }// end of for ( jj = 0; jj < output_segments.size(); jj++) 00558 if( r == 2) 00559 break; 00560 else 00561 r=0; 00562 }// end of for( ii=0; ii < output_segments.size(); ii++) 00563 seg1 = output_segments[ii]; 00564 output_segments[ii] = NULL; 00565 seg_list = new DLIList<MedialSegment*>; 00566 seg_list->append(seg1); 00567 r = 0; 00568 00569 } 00570 else 00571 { 00572 while( output_segments[z[x][y]] == NULL) 00573 { 00574 y = y-1; 00575 if( y < 0) 00576 { 00577 x = x-1; 00578 if( x < 1 ) 00579 break; 00580 else 00581 y = a[x]; 00582 }// end of if ( y < 0 ) 00583 00584 } //end of while( output_segments[z[x][y]] == NULL) 00585 if ( x <= 0 && y <= -1 ) 00586 { 00587 for( ii=0; ii < output_segments.size(); ii++) 00588 { 00589 if ( output_segments [ii] == NULL) 00590 continue; 00591 else 00592 { 00593 seg1 = output_segments[ii]; 00594 start1 = seg1->get_start(); 00595 end1 = seg1->get_end(); 00596 start_point1 = start1->coordinates(); 00597 end_point1 = end1->coordinates(); 00598 }// end of if ( output_segments [ii] == NULL) 00599 for ( jj = 0; jj < output_segments.size(); jj++) 00600 { 00601 if ( output_segments[jj] == NULL ) 00602 continue; 00603 else 00604 { 00605 seg2 = output_segments[jj]; 00606 start2 = seg2->get_start(); 00607 end2 = seg2->get_end(); 00608 start_point2 = start2->coordinates(); 00609 end_point2 = end2->coordinates(); 00610 }// end of else to if ( output_segments[jj] == NULL ) 00611 if ( start_point1 == start_point2 || start_point1 == end_point2 || end_point1 == start_point2 || end_point1 == end_point2) 00612 r=r+1; 00613 }// end of for ( jj = 0; jj < output_segments.size(); jj++) 00614 if( r == 2) 00615 break; 00616 else 00617 r=0; 00618 }// end of for( ii=0; ii < output_segments.size(); ii++) 00619 seg1 = output_segments[ii]; 00620 output_segments[ii] = NULL; 00621 seg_list = new DLIList<MedialSegment*>; 00622 seg_list->append(seg1); 00623 r = 0; 00624 x = 0; 00625 y = 0; 00626 } 00627 else 00628 { 00629 seg1 = output_segments[z[x][y]]; 00630 output_segments[z[x][y]] = NULL; 00631 seg_list = new DLIList<MedialSegment*>; 00632 seg_list->append(seg1); 00633 r = 0; 00634 00635 } 00636 } 00637 00638 }// end of if ( r == 0 ) 00639 00640 else 00641 { 00642 if ( r>1 )//more than one segments attached to a given segment 00643 { 00644 segment_listoflist.append(seg_list); 00645 x = x+1; 00646 a[x] = w; 00647 y = w; 00648 b = w; 00649 for( iii = 0; iii < r; iii++) 00650 { 00651 z[x][iii] = v[iii]; 00652 u[iii] = v[iii]; 00653 } 00654 seg1 = output_segments[z[x][y]]; 00655 output_segments[z[x][y]] = NULL; 00656 seg_list = new DLIList<MedialSegment*>; 00657 seg_list->append(seg1); 00658 r = 0; 00659 }// end of if ( r > 1) 00660 }// end of else to if ( r == 0 ) 00661 }// end of else to if ( r == 1) 00662 }// end of for( ii=0; ii < output_segments.size()-1; ii++) 00663 00664 segment_listoflist.reset(); 00665 MedialSegment *first_seg, *second_seg; 00666 MedialVertex *start, *end, *intermediate_start, *intermediate_end, *secondseg_start, *secondseg_end ; 00667 Vec3D start_point, end_point, intermediate_prev_end_point, intermediate_curr_start_point, intermediate_curr_end_point, secondseg_startpoint, secondseg_endpoint; 00668 DLIList<CubitVector*> curve_vectors; 00669 CubitVector cubit_start_vertex, cubit_end_vertex, cubit_intermediate_vertex; 00670 00671 for ( ii = 0; ii < segment_listoflist.size(); ii++) 00672 { 00673 seg_list = new DLIList<MedialSegment*>; 00674 seg_list = segment_listoflist.get_and_step(); 00675 curve_vectors.clean_out(); 00676 for ( jj = 0; jj < seg_list->size(); jj++) 00677 { 00678 first_seg = seg_list->next(jj); 00679 00680 if ( seg_list->size() == 1 )//seg_list contains only one segment 00681 { 00682 start =first_seg->get_start(); 00683 end =first_seg->get_end(); 00684 start_point = start->coordinates(); 00685 end_point = end->coordinates(); 00686 convert_from_vec3d(start_point,cubit_start_vertex); 00687 convert_from_vec3d(end_point,cubit_end_vertex); 00688 }// end of if ( seg_list->size() == 1 ) 00689 else 00690 { 00691 if ( jj == 0)//for the first segment in the seg_list list 00692 { 00693 start =first_seg->get_start(); 00694 end =first_seg->get_end(); 00695 start_point = start->coordinates(); 00696 end_point = end->coordinates(); 00697 second_seg = seg_list->next(jj+1); 00698 secondseg_start = second_seg->get_start(); 00699 secondseg_end = second_seg->get_end(); 00700 secondseg_startpoint = secondseg_start->coordinates(); 00701 secondseg_endpoint = secondseg_end->coordinates(); 00702 00703 if ( end_point == secondseg_startpoint || end_point == secondseg_endpoint ) 00704 { 00705 convert_from_vec3d(start_point,cubit_start_vertex); 00706 intermediate_prev_end_point = end_point; 00707 }// end of if ( end_point == secondseg_startpoint || end_point == secondseg_endpoint ) 00708 else if ( start_point == secondseg_startpoint || start_point == secondseg_endpoint ) 00709 { 00710 convert_from_vec3d(end_point,cubit_start_vertex); 00711 intermediate_prev_end_point = start_point; 00712 00713 }//end of if ( start_point == secondseg_startpoint || start_point == secondseg_endpoint ) 00714 00715 }// end of if ( jj== 0 ) 00716 else 00717 { 00718 intermediate_start =first_seg->get_start(); 00719 intermediate_end =first_seg->get_end(); 00720 intermediate_curr_start_point = intermediate_start->coordinates(); 00721 intermediate_curr_end_point = intermediate_end->coordinates(); 00722 if ( intermediate_curr_start_point == intermediate_prev_end_point ) 00723 { 00724 convert_from_vec3d(intermediate_curr_start_point,cubit_intermediate_vertex); 00725 intermediate_prev_end_point = intermediate_curr_end_point; 00726 00727 }// end of if ( intermediate_curr_start_point == intermediate_prev_end_point ) 00728 else if ( intermediate_curr_end_point == intermediate_prev_end_point ) 00729 { 00730 convert_from_vec3d(intermediate_curr_end_point,cubit_intermediate_vertex); 00731 intermediate_prev_end_point = intermediate_curr_start_point; 00732 00733 }// end of if ( intermediate_curr_end_point == intermediate_prev_end_point ) 00734 00735 curve_vectors.append(&cubit_intermediate_vertex); 00736 00737 if ( jj == seg_list->size()-1 )//for the last segment in the seg_list 00738 { 00739 convert_from_vec3d(intermediate_prev_end_point,cubit_end_vertex); 00740 00741 }// end of if ( jj == seg_list->size()-1 ) 00742 00743 }//end of else to if ( jj == 0 ) 00744 }//end of else to if ( seg_list->size() == 1 ) 00745 }// end of for ( jj = 0; jj < seg_list->size(); jj++) 00746 00747 RefVertex *first_ref = VirtualGeometryEngine::instance()->create_VirtualVertex(cubit_start_vertex); 00748 RefVertex *last_ref = VirtualGeometryEngine::instance()->create_VirtualVertex(cubit_end_vertex);; 00749 assert( first_ref && last_ref ); 00750 RefEdge *ref_edge = NULL; 00751 if ( curve_vectors.size() == 0)//only one segment 00752 { 00753 00754 ref_edge = VirtualGeometryEngine::instance()->create_VirtualEdge(first_ref, last_ref); 00755 medial_axis.append( ref_edge ); 00756 00757 }//end of if ( curve_vectors.size() == 0) 00758 else 00759 { 00760 00761 ref_edge = VirtualGeometryEngine::instance()->create_VirtualEdge(first_ref, last_ref, curve_vectors); 00762 medial_axis.append( ref_edge ); 00763 00764 00765 }// end of if ( curve_vectors.size() == 0) 00766 00767 seg_list->clean_out(); 00768 00769 }//end of for ( ii = 0; ii < segment_listoflist.size(); ii++) 00770 00771 00772 return CUBIT_SUCCESS; 00773 } 00774 00775 #endif //USING_MEDIAL