cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : PartitionCurve-new.cpp 00003 // 00004 // Purpose : 00005 // 00006 // Special Notes : 00007 // 00008 // Creator : Jason Kraftcheck 00009 // 00010 // Creation Date : 04/10/02 00011 //------------------------------------------------------------------------- 00012 00013 #include "PartitionCurve.hpp" 00014 #include "PartitionPoint.hpp" 00015 #include "PartitionCoEdge.hpp" 00016 #include "PartitionSurface.hpp" 00017 #include "VirtualQueryEngine.hpp" 00018 #include "PartSurfFacetTool.hpp" 00019 00020 #include "TDVGFacetOwner.hpp" 00021 #include "CubitFacetEdgeData.hpp" 00022 #include "CubitPointData.hpp" 00023 #include "CubitFacetData.hpp" 00024 #include "CubitTransformMatrix.hpp" 00025 #include "Surface.hpp" 00026 00027 #include "GfxDebug.hpp" 00028 #include "GMem.hpp" 00029 00030 /* 00031 void print_point_list( PartitionPoint* point ) 00032 { 00033 PRINT_INFO(" Point %p: (%d curves)\n", point, point ? point->num_curves() : 0 ); 00034 if(!point) { PRINT_INFO("\n\n"); return; } 00035 00036 PartitionCurve* curve = 0; 00037 while( curve = point->next_curve(curve) ) 00038 PRINT_INFO("%10p",curve); 00039 PRINT_INFO("\n"); 00040 curve = 0; 00041 00042 while( curve = point->next_curve(curve) ) 00043 PRINT_INFO("%10s", 00044 curve->start_point() == point && curve->end_point() == point ? "(both)" : 00045 curve->start_point() == point ? "(start)" : 00046 curve->end_point() == point ? "(end)" : "(none)" ); 00047 PRINT_INFO("\n"); 00048 } 00049 */ 00050 00051 PartitionCurve::PartitionCurve( ) 00052 : firstCoEdge(0), 00053 startPoint(0), 00054 endPoint(0), 00055 startNext(0), 00056 endNext(0) 00057 { 00058 } 00059 00060 PartitionCurve::~PartitionCurve() 00061 { 00062 start_point(0); 00063 end_point(0); 00064 00065 remove_all_coedges(); 00066 remove_facet_data(); 00067 } 00068 00069 CubitStatus PartitionCurve::add( PartitionCoEdge* coedge ) 00070 { 00071 if( coedge->myCurve ) 00072 return CUBIT_FAILURE; 00073 00074 coedge->curveNext = firstCoEdge; 00075 firstCoEdge = coedge; 00076 coedge->myCurve = this; 00077 return CUBIT_SUCCESS; 00078 } 00079 00080 CubitStatus PartitionCurve::remove( PartitionCoEdge* coedge ) 00081 { 00082 if( coedge->myCurve != this ) 00083 return CUBIT_FAILURE; 00084 00085 if( firstCoEdge == coedge ) 00086 { 00087 firstCoEdge = coedge->curveNext; 00088 } 00089 else 00090 { 00091 PartitionCoEdge* prev = firstCoEdge; 00092 while( prev && prev->curveNext != coedge ) 00093 prev = prev->curveNext; 00094 00095 if( !prev ) 00096 { 00097 assert(0); 00098 return CUBIT_FAILURE; 00099 } 00100 00101 prev->curveNext = coedge->curveNext; 00102 } 00103 00104 coedge->curveNext = 0; 00105 coedge->myCurve = 0; 00106 return CUBIT_SUCCESS; 00107 } 00108 00109 int PartitionCurve::num_coedges() const 00110 { 00111 int count = 0; 00112 for( PartitionCoEdge* coe = firstCoEdge; coe; coe = coe->curveNext ) 00113 count++; 00114 return count; 00115 } 00116 00117 void PartitionCurve::remove_all_coedges( ) 00118 { 00119 while( firstCoEdge && remove(firstCoEdge) ) {;} 00120 assert( !firstCoEdge ); 00121 } 00122 00123 CubitStatus PartitionCurve::start_point( PartitionPoint* point ) 00124 { 00125 if( point == startPoint ) 00126 return CUBIT_SUCCESS; 00127 00128 if( !remove_start_point() ) 00129 { assert(0); return CUBIT_FAILURE; } 00130 00131 if( !point ) 00132 return CUBIT_SUCCESS; 00133 00134 startPoint = point; 00135 if( point == endPoint ) 00136 { 00137 startNext = endNext; 00138 endNext = 0; 00139 } 00140 else 00141 { 00142 startNext = point->firstCurve; 00143 point->firstCurve = this; 00144 point->curveCount++; 00145 } 00146 00147 return CUBIT_SUCCESS; 00148 } 00149 00150 CubitStatus PartitionCurve::end_point( PartitionPoint* point ) 00151 { 00152 if( point == endPoint ) 00153 return CUBIT_SUCCESS; 00154 00155 if( !remove_end_point() ) 00156 { assert(0); return CUBIT_FAILURE; } 00157 00158 if( !point ) 00159 return CUBIT_SUCCESS; 00160 00161 endPoint = point; 00162 if( point != startPoint ) 00163 { 00164 endNext = point->firstCurve; 00165 point->firstCurve = this; 00166 point->curveCount++; 00167 } 00168 00169 return CUBIT_SUCCESS; 00170 } 00171 00172 CubitStatus PartitionCurve::remove_start_point() 00173 { 00174 if( startPoint == endPoint ) 00175 endNext = startNext; 00176 else if( startPoint && !remove_from_point( startPoint, startNext ) ) 00177 return CUBIT_FAILURE; 00178 00179 startPoint = 0; 00180 startNext = 0; 00181 00182 return CUBIT_SUCCESS; 00183 } 00184 00185 CubitStatus PartitionCurve::remove_end_point() 00186 { 00187 assert( startPoint != endPoint || !endNext ); 00188 // endNext should be null if points are the same 00189 00190 if( endPoint && endPoint != startPoint && 00191 !remove_from_point( endPoint, endNext ) ) 00192 return CUBIT_FAILURE; 00193 00194 endPoint = 0; 00195 endNext = 0; 00196 00197 return CUBIT_SUCCESS; 00198 } 00199 00200 CubitStatus PartitionCurve::remove_from_point( PartitionPoint* point, 00201 PartitionCurve* next ) 00202 { 00203 point->curveCount--; 00204 if( point->firstCurve == this ) 00205 { 00206 point->firstCurve = next; 00207 } 00208 else 00209 { 00210 PartitionCurve* prev = point->firstCurve; 00211 while( prev ) 00212 { 00213 PartitionCurve* temp = prev->next_curve(point); 00214 if( temp == this ) 00215 break; 00216 prev = temp; 00217 } 00218 00219 if( !prev ) 00220 { 00221 assert(0); 00222 return CUBIT_FAILURE; 00223 } 00224 00225 if( prev->startPoint == point ) 00226 prev->startNext = next; 00227 else if( prev->endPoint == point ) 00228 prev->endNext = next; 00229 else 00230 assert(0); 00231 } 00232 00233 return CUBIT_SUCCESS; 00234 } 00235 00236 00237 00238 00239 bool PartitionCurve::is_nonmanifold( const PartitionSurface* surf ) const 00240 { 00241 int count = 0; 00242 PartitionCoEdge* coedge = 0; 00243 while ( (coedge = next_coedge(coedge)) ) 00244 if ( coedge->get_loop() && coedge->get_loop()->get_surface() == surf ) 00245 count++; 00246 return count > 1; 00247 } 00248 00249 bool PartitionCurve::is_in_surface( const PartitionSurface* surf, 00250 bool manifold_only ) const 00251 { 00252 int count = 0; 00253 PartitionCoEdge* coedge = 0; 00254 while ( (coedge = next_coedge(coedge)) ) 00255 if ( coedge->get_loop() && coedge->get_loop()->get_surface() == surf ) 00256 count++; 00257 00258 if (manifold_only) 00259 return count == 1; 00260 else 00261 return count > 0; 00262 } 00263 00264 00265 CubitStatus PartitionCurve::move_to_geometry( CubitVector& position ) 00266 { 00267 const CubitVector copy(position); 00268 return closest_point( copy, position ); 00269 } 00270 00271 void PartitionCurve::get_parents_virt( DLIList<TopologyBridge*>& result ) 00272 { 00273 for( PartitionCoEdge* coe = firstCoEdge; coe; coe = coe->curveNext ) 00274 result.append( coe ); 00275 } 00276 00277 void PartitionCurve::get_children_virt( DLIList<TopologyBridge*>& result ) 00278 { 00279 result.append( startPoint ); 00280 if( startPoint != endPoint ) 00281 result.append( endPoint ); 00282 } 00283 00284 GeometryQueryEngine* PartitionCurve::get_geometry_query_engine() const 00285 { 00286 return VirtualQueryEngine::instance(); 00287 } 00288 00289 void PartitionCurve::print_debug_info( const char* prefix, 00290 bool entset ) const 00291 { 00292 const bool print_children = true; 00293 00294 if( prefix == 0 ) prefix = ""; 00295 char* new_prefix = new char[strlen(prefix)+3]; 00296 strcpy( new_prefix, prefix ); 00297 strcat( new_prefix, " "); 00298 PRINT_INFO("%sPartitionCurve %p\n", prefix, (void*)this ); 00299 00300 if(entset) 00301 sub_entity_set().print_debug_info( new_prefix ); 00302 else 00303 print_partitioned_entity(); 00304 00305 PartitionCoEdge* coedge = 0; 00306 DLIList<Surface*> surface_list(1); 00307 while( (coedge = next_coedge(coedge)) ) 00308 { 00309 surface_list.clean_out(); 00310 coedge->surfaces(surface_list); 00311 Surface* surf_ptr = surface_list.size() == 1 ? surface_list.get() : 0; 00312 PRINT_INFO("%s %s on Surface %p\n", prefix, 00313 coedge->sense() == CUBIT_FORWARD ? "FORWARD" : 00314 coedge->sense() == CUBIT_REVERSED ? "REVERSE" : "UNKNOWN", 00315 (void*)surf_ptr ); 00316 } 00317 00318 PRINT_INFO("%s start point: %p\n", prefix, (void*)start_point() ); 00319 if( start_point() && print_children ) 00320 start_point()->print_debug_info( new_prefix, false ); 00321 00322 if( end_point() && end_point() == start_point() ) 00323 PRINT_INFO("%s end point SAME as start point\n", prefix ); 00324 else 00325 PRINT_INFO("%s end point: %p\n", prefix, (void*)end_point() ); 00326 if( end_point() && end_point() != start_point() && print_children ) 00327 end_point()->print_debug_info( new_prefix, false ); 00328 00329 delete [] new_prefix; 00330 } 00331 00332 void PartitionCurve::append_simple_attribute_virt(const CubitSimpleAttrib& csa) 00333 { sub_entity_set().add_attribute( this, csa ); } 00334 void PartitionCurve::remove_simple_attribute_virt(const CubitSimpleAttrib& csa) 00335 { sub_entity_set().rem_attribute( this, csa ); } 00336 void PartitionCurve::remove_all_simple_attribute_virt() 00337 { sub_entity_set().rem_all_attrib( this ); } 00338 CubitStatus PartitionCurve::get_simple_attribute(DLIList<CubitSimpleAttrib>& list) 00339 { 00340 sub_entity_set().get_attributes( this, list ); 00341 return CUBIT_SUCCESS; 00342 } 00343 CubitStatus PartitionCurve::get_simple_attribute(const CubitString& name, 00344 DLIList<CubitSimpleAttrib>& list) 00345 { 00346 sub_entity_set().get_attributes( this, name.c_str(), list ); 00347 return CUBIT_SUCCESS; 00348 } 00349 00350 void PartitionCurve::reverse_point_order() 00351 { 00352 if( startPoint != endPoint ) 00353 { 00354 PartitionPoint* tmp_pt = startPoint; 00355 startPoint = endPoint; 00356 endPoint = tmp_pt; 00357 00358 PartitionCurve* tmp_cv = startNext; 00359 startNext = endNext; 00360 endNext = tmp_cv; 00361 } 00362 } 00363 00364 void PartitionCurve::get_facet_data( DLIList<CubitFacetEdgeData*>& result_list ) const 00365 { result_list = facetEdges; } 00366 00367 void PartitionCurve::set_facet_data( const DLIList<CubitFacetEdgeData*>& new_list ) 00368 { 00369 remove_facet_data(); 00370 facetEdges = new_list; 00371 for( int i = facetEdges.size(); i--; ) 00372 TDVGFacetOwner::set( facetEdges.step_and_get(), this ); 00373 } 00374 00375 void PartitionCurve::remove_facet_data( ) 00376 { 00377 while( facetEdges.size() ) 00378 TDVGFacetOwner::remove( facetEdges.pop() ); 00379 } 00380 00381 00382 void PartitionCurve::notify_split( FacetEntity* old_entity, FacetEntity* new_entity ) 00383 { 00384 CubitFacetEdgeData* old_ptr = dynamic_cast<CubitFacetEdgeData*>(old_entity); 00385 CubitFacetEdgeData* new_ptr = dynamic_cast<CubitFacetEdgeData*>(new_entity); 00386 assert(TDVGFacetOwner::get(old_entity) == this); 00387 assert(TDVGFacetOwner::get(new_entity) == 0); 00388 assert(old_ptr && new_ptr); 00389 00390 facetEdges.reset(); 00391 if (facetEdges.get() == old_ptr) 00392 { 00393 if (new_ptr->contains(start_point()->facet_point())) 00394 facetEdges.insert_first(new_ptr); 00395 else 00396 facetEdges.insert(new_ptr); 00397 } 00398 else if (facetEdges.move_to(old_ptr)) 00399 { 00400 CubitFacetEdgeData* prev = facetEdges.prev(); 00401 if (prev->shared_point(new_ptr)) 00402 facetEdges.back(); 00403 facetEdges.insert(new_ptr); 00404 } 00405 else 00406 { 00407 assert( 0 /*old_entity not in list*/); 00408 } 00409 00410 facetEdges.reset(); 00411 TDVGFacetOwner::set( new_ptr, this ); 00412 } 00413 00414 00415 CubitStatus PartitionCurve::fix_facet_data( PartitionCurve* new_curve ) 00416 { 00417 if ( !facetEdges.size() ) 00418 return CUBIT_SUCCESS; 00419 00420 00421 DLIList<CubitFacetEdgeData*> my_edges(facetEdges); 00422 assert( end_point() == new_curve->start_point() ); 00423 CubitVector pos( end_point()->coordinates() ); 00424 00425 double min_edge_len_sqr = CUBIT_DBL_MAX; 00426 double min_edge_dst_sqr = CUBIT_DBL_MAX; 00427 CubitFacetEdgeData* closest_edge = 0; 00428 CubitVector point, vect, edge_pos; 00429 int i; 00430 00431 for ( i = my_edges.size(); i--; ) { 00432 CubitFacetEdgeData* edge = my_edges.step_and_get(); 00433 point = edge->point(0)->coordinates(); 00434 vect = edge->point(1)->coordinates() - point; 00435 00436 double len_sqr = vect.length_squared(); 00437 if ( len_sqr < min_edge_len_sqr ) 00438 min_edge_len_sqr = len_sqr; 00439 00440 point -= pos; 00441 double t = (vect % -point) / len_sqr; 00442 if ( t < 0.0 ) t = 0.0; 00443 else if( t > 1.0 ) t = 1.0; 00444 double dst_sqr = (point + t * vect).length_squared(); 00445 00446 if ( dst_sqr < min_edge_dst_sqr ) { 00447 min_edge_dst_sqr = dst_sqr; 00448 closest_edge = edge; 00449 edge_pos = edge->point(0)->coordinates() + t * vect; 00450 } 00451 } 00452 00453 my_edges.reset(); 00454 DLIList<CubitFacetEdgeData*> new_curve_edges; 00455 my_edges.last(); 00456 while( my_edges.get() != closest_edge ) { 00457 new_curve_edges.append( my_edges.pop() ); 00458 my_edges.last(); 00459 } 00460 00461 min_edge_len_sqr *= 0.2; 00462 double dst_tol_sqr = CUBIT_MAX( min_edge_len_sqr, GEOMETRY_RESABS*GEOMETRY_RESABS ); 00463 00464 bool edge_reversed = false; 00465 if ( my_edges.size() > 1 ) 00466 { 00467 my_edges.last(); 00468 CubitFacetEdgeData* other = my_edges.prev(); 00469 edge_reversed = other->contains( closest_edge->point(1) ); 00470 } 00471 else if( new_curve_edges.size() > 1 ) 00472 { 00473 new_curve_edges.last(); 00474 CubitFacetEdgeData* other = new_curve_edges.get(); 00475 edge_reversed = other->contains( closest_edge->point(0) ); 00476 } 00477 else 00478 { 00479 edge_reversed = (start_point()->facet_point() == closest_edge->point(1)); 00480 assert(edge_reversed || start_point()->facet_point() == closest_edge->point(0)); 00481 } 00482 00483 00484 CubitPoint* new_point = 0; 00485 double d1 = (pos - closest_edge->point(0)->coordinates()).length_squared(); 00486 double d2 = (pos - closest_edge->point(1)->coordinates()).length_squared(); 00487 if ( (!TDVGFacetOwner::get(closest_edge->point(0)) && d1 < dst_tol_sqr) || 00488 (d1 < GEOMETRY_RESABS*GEOMETRY_RESABS) ) 00489 { 00490 if ( !edge_reversed ) 00491 new_curve_edges.append( my_edges.pop() ); 00492 new_point = closest_edge->point(0); 00493 } 00494 else if( (!TDVGFacetOwner::get(closest_edge->point(1)) && d2 < dst_tol_sqr) || 00495 (d2 < GEOMETRY_RESABS*GEOMETRY_RESABS) ) 00496 { 00497 if( edge_reversed ) 00498 new_curve_edges.append( my_edges.pop() ); 00499 new_point = closest_edge->point(1); 00500 } 00501 else 00502 { 00503 CubitFacetEdge* new_edge; 00504 CubitFacet* new_facet; 00505 TDVGFacetOwner::remove(closest_edge); 00506 PartSurfFacetTool::split_edge(closest_edge, edge_pos, 0, new_point, new_edge, new_facet ); 00507 TDVGFacetOwner::set(closest_edge, this); 00508 00509 if ( edge_reversed ) { 00510 new_curve_edges.append( my_edges.pop() ); 00511 my_edges.append( dynamic_cast<CubitFacetEdgeData*>(new_edge) ); 00512 } else { 00513 new_curve_edges.append( dynamic_cast<CubitFacetEdgeData*>(new_edge) ); 00514 //TDVGFacetOwner::remove(new_edge); 00515 } 00516 } 00517 00518 CubitPointData* new_point_d = dynamic_cast<CubitPointData*>(new_point); 00519 new_point_d->set(end_point()->coordinates()); 00520 end_point()->facet_point( new_point_d ); 00521 set_facet_data(my_edges); 00522 new_curve_edges.reverse(); 00523 new_curve->set_facet_data(new_curve_edges); 00524 00525 PartitionCoEdge* coedge = 0; 00526 while ((coedge = next_coedge(coedge)) != NULL ) 00527 { 00528 PartitionLoop* loop = coedge->get_loop(); 00529 if (!loop) continue; 00530 00531 PartitionSurface* surf = loop->get_surface(); 00532 if (!surf->notify_moving_point( new_point, pos )) 00533 return CUBIT_FAILURE; 00534 } 00535 00536 new_point->set(pos); 00537 return CUBIT_SUCCESS; 00538 } 00539 00540 void PartitionCurve::remove_dead_facet( CubitFacetEdgeData* edge ) 00541 { 00542 facetEdges.remove(edge); 00543 } 00544 00545 CubitStatus PartitionCurve::get_save_topology( DLIList<int>& end_points ) 00546 { 00547 for( int i = 0; i < 2; i++ ) 00548 { 00549 PartitionPoint* point = i ? end_point() : start_point(); 00550 int set_id, pt_id; 00551 if( &(point->sub_entity_set()) == &sub_entity_set() ) 00552 set_id = 0; 00553 else 00554 set_id = point->sub_entity_set().get_unique_id(); 00555 pt_id = point->sub_entity_set().get_id(point); 00556 end_points.append(set_id); 00557 end_points.append(pt_id); 00558 } 00559 return CUBIT_SUCCESS; 00560 } 00561 00562 00563 00564 void PartitionCurve::transform(const CubitTransformMatrix& xform) 00565 { 00566 int i; 00567 00568 DLIList<CubitPoint*> points(facetEdges.size()); 00569 for ( i = facetEdges.size(); i--; ) 00570 { 00571 CubitFacetEdgeData* edge = facetEdges.step_and_get(); 00572 edge->point(0)->marked(1); 00573 edge->point(1)->marked(1); 00574 } 00575 for ( i = facetEdges.size(); i--; ) 00576 { 00577 CubitFacetEdgeData* edge = facetEdges.step_and_get(); 00578 for ( int j = 0; j < 2; j++ ) 00579 { 00580 CubitPoint* pt = edge->point(j); 00581 if( pt->marked() ) 00582 { 00583 pt->marked(0); 00584 00585 if( TDVGFacetOwner::get(pt) == 0 ) 00586 points.append(pt); 00587 } 00588 } 00589 } 00590 00591 for( i = points.size(); i--; ) 00592 { 00593 CubitPoint* pt = points.get_and_step(); 00594 pt->set( xform * pt->coordinates() ); 00595 } 00596 } 00597 00598 void PartitionCurve::replace_facet(CubitFacetEdgeData* dead_facet, 00599 DLIList<CubitFacetEdgeData*> &new_facets) 00600 { 00601 assert(new_facets.size() > 1); // doesn't make sense to replace 1 to 1 00602 00603 DLIList<CubitFacetEdgeData*> new_copy = new_facets; 00604 00605 new_facets.reset(); 00606 facetEdges.reset(); 00607 int dead_index = facetEdges.where_is_item(dead_facet); 00608 assert(-1 != dead_index); 00609 00610 // special case for a single facet on the edge 00611 // - use curve endpoints to determine order 00612 if (facetEdges.size() == 1) 00613 { 00614 facetEdges.clean_out(); 00615 00616 new_copy.last(); 00617 if (new_copy.get()->contains(start_point()->facet_point()) ) 00618 new_copy.reverse(); 00619 00620 new_copy.reset(); 00621 assert( new_copy.get()->contains(start_point()->facet_point()) ); 00622 new_copy.last(); 00623 assert( new_copy.get()->contains(end_point()->facet_point()) ); 00624 00625 facetEdges = new_copy; 00626 } 00627 else 00628 { 00629 DLIList<CubitFacetEdgeData*> ordered_edges; 00630 int i; 00631 00632 // copy the edges before the dead edge into a new list 00633 for (i=0; i< dead_index; i++) 00634 ordered_edges.append(facetEdges.next(i)); 00635 00636 // if there are edges before the new edges, find out whether the first or last 00637 // new edge is adjacent to the one before the dead edge 00638 CubitFacetEdgeData *prev = NULL; 00639 CubitFacetEdgeData *next = NULL; 00640 CubitPoint *new_start_pt = NULL; 00641 CubitPoint *new_end_pt = NULL; 00642 if (dead_index > 0) 00643 { 00644 prev = facetEdges.next(dead_index-1); 00645 new_start_pt = prev->shared_point(dead_facet); 00646 assert(new_start_pt != NULL); 00647 } 00648 00649 if (dead_index < (facetEdges.size() - 1) ) 00650 { 00651 next = facetEdges.next(dead_index+1); 00652 new_end_pt = next->shared_point(dead_facet); 00653 assert(new_end_pt != NULL); 00654 } 00655 00656 if (prev) 00657 { 00658 new_copy.last(); 00659 if (new_copy.get()->contains(new_start_pt)) 00660 new_copy.reverse(); 00661 } 00662 else 00663 { 00664 // use the edge after the dead edge to find out whether to reverse the new 00665 // edges or not 00666 assert(next != NULL); 00667 new_copy.reset(); 00668 if (new_copy.get()->contains(new_end_pt)) 00669 new_copy.reverse(); 00670 } 00671 00672 if (prev) 00673 { 00674 new_copy.reset(); 00675 assert( prev->shared_point(new_copy.get()) != NULL); 00676 } 00677 if (next) 00678 { 00679 new_copy.last(); 00680 assert( next->shared_point(new_copy.get()) != NULL); 00681 } 00682 00683 // copy the new edges into place in the ordered list 00684 new_copy.reset(); 00685 for (i=new_copy.size(); i>0; i--) 00686 ordered_edges.append(new_copy.get_and_step()); 00687 00688 // add the rest of the edges to the list 00689 facetEdges.reset(); 00690 for (i=dead_index+1; i<facetEdges.size(); i++) 00691 ordered_edges.append(facetEdges.next(i)); 00692 00693 00694 facetEdges.clean_out(); 00695 facetEdges = ordered_edges; 00696 } 00697 00698 TDVGFacetOwner::remove(dead_facet); 00699 for( int j = 0; j < new_facets.size(); j++ ) 00700 TDVGFacetOwner::set(new_facets.step_and_get(),this); 00701 00702 // TODO - memory management - where should the facets get deleted 00703 } 00704 00705 void PartitionCurve::draw_facets( int color) 00706 { 00707 if( !facetEdges.size() ) 00708 { 00709 PRINT_ERROR("No facet data.\n"); 00710 return ; 00711 } 00712 00713 int i; 00714 GPoint* pts = new GPoint[facetEdges.size() + 1]; 00715 00716 facetEdges.reset(); 00717 CubitPoint* pt = 0; 00718 if( facetEdges.size() == 1 ) 00719 { 00720 pt = facetEdges.get()->point(0); 00721 } 00722 else 00723 { 00724 pt = facetEdges.get()->shared_point(facetEdges.next()); 00725 pt = facetEdges.get()->other_point(pt); 00726 } 00727 00728 CubitVector v = pt->coordinates(); 00729 pts[0].x = (float)v.x(); 00730 pts[0].y = (float)v.y(); 00731 pts[0].z = (float)v.z(); 00732 00733 for( i = 1; i <= facetEdges.size(); i++ ) 00734 { 00735 pt = facetEdges.get_and_step()->other_point(pt); 00736 CubitVector v = pt->coordinates(); 00737 pts[i].x = (float)v.x(); 00738 pts[i].y = (float)v.y(); 00739 pts[i].z = (float)v.z(); 00740 } 00741 00742 GfxDebug::draw_polyline( pts, facetEdges.size() + 1, color ); 00743 for ( i = 0; i <= facetEdges.size(); i++ ) 00744 { 00745 GfxDebug::draw_point( pts[i].x, pts[i].y, pts[i].z, color ); 00746 } 00747 00748 facetEdges.reset(); 00749 for ( i = 0; i < facetEdges.size(); i++ ) 00750 { 00751 CubitFacetEdge* edge = facetEdges.get_and_step(); 00752 CubitVector mid = 0.5*(edge->point(0)->coordinates()+edge->point(1)->coordinates()); 00753 GfxDebug::draw_label( i, (float)mid.x(), (float)mid.y(), (float)mid.z(), color ); 00754 } 00755 GfxDebug::flush(); 00756 00757 delete [] pts; 00758 } 00759 00760 void PartitionCurve::do_facet_cleanup() 00761 { 00762 int i; 00763 const double tol = 10.0 * GEOMETRY_RESABS; 00764 const double tol_sqr = tol * tol; 00765 00766 DLIList<CubitFacetEdgeData*> edge_list(facetEdges); 00767 CubitFacetEdgeData* prev_edge = 0; 00768 edge_list.reset(); 00769 00770 for ( i = edge_list.size(); i--; ) 00771 { 00772 CubitFacetEdgeData* edge = edge_list.get_and_step(); 00773 PartitionEntity* start_pt = TDVGFacetOwner::get(edge->point(0)); 00774 PartitionEntity* end_pt = TDVGFacetOwner::get(edge->point(1)); 00775 if ( start_pt && end_pt ) 00776 { 00777 prev_edge = edge; 00778 continue; 00779 } 00780 00781 CubitVector edge_vect(edge->point(1)->coordinates()); 00782 edge_vect -= edge->point(0)->coordinates(); 00783 if ( edge_vect.length_squared() > tol_sqr ) 00784 { 00785 prev_edge = edge; 00786 continue; 00787 } 00788 00789 CubitPoint *keep, *dead; 00790 if ( start_pt ) 00791 { 00792 keep = edge->point(0); 00793 dead = edge->point(1); 00794 } 00795 else if ( end_pt ) 00796 { 00797 keep = edge->point(1); 00798 dead = edge->point(0); 00799 } 00800 else 00801 { 00802 double prev = (prev_edge->point(0)->coordinates() - 00803 prev_edge->point(1)->coordinates()).length_squared(); 00804 double next = (edge_list.get()->point(0)->coordinates() - 00805 edge_list.get()->point(1)->coordinates()).length_squared(); 00806 if ( prev < next ) 00807 { 00808 dead = prev_edge->shared_point(edge); 00809 keep = edge_list.get()->shared_point(edge); 00810 } 00811 else 00812 { 00813 dead = edge_list.get()->shared_point(edge); 00814 keep = prev_edge->shared_point(edge); 00815 } 00816 assert( dead && keep ); 00817 } 00818 00819 if ( PartSurfFacetTool::collapse_edge( keep, dead ) ) 00820 { 00821 ; 00822 } 00823 else 00824 { 00825 prev_edge = edge; 00826 } 00827 } 00828 } 00829 00830 00831 CubitStatus PartitionCurve::move_to_geometry( CubitPoint* point ) 00832 { 00833 CubitVector new_pos; 00834 if (!closest_point( point->coordinates(), new_pos )) 00835 return CUBIT_FAILURE; 00836 00837 point->set(new_pos); 00838 00839 DLIList<PartitionSurface*> surfaces; 00840 PartitionCoEdge* coedge = 0; 00841 while ((coedge = next_coedge(coedge)) != NULL ) 00842 { 00843 PartitionLoop* loop = coedge->get_loop(); 00844 if (!loop) 00845 continue; 00846 00847 PartitionSurface* surf = loop->get_surface(); 00848 surfaces.append_unique(surf); 00849 00850 coedge = coedge->next(); 00851 } 00852 00853 int i; 00854 surfaces.reset(); 00855 for ( i = 0; i < surfaces.size(); i++ ) 00856 if (!surfaces.get_and_step()->notify_moving_point( point, new_pos )) 00857 break; 00858 00859 if (i < surfaces.size()) 00860 return CUBIT_FAILURE; 00861 00862 point->set(new_pos); 00863 return CUBIT_SUCCESS; 00864 }