cgma
|
00001 //- Class: ChollaCurve 00002 //- Description: Temporary class for constructing the facet-based geometry 00003 //- 00004 //- Owner: Steven J. Owen 00005 //- Checked by: 00006 //- Version: 00007 00008 #include "CubitVector.hpp" 00009 #include "ChollaCurve.hpp" 00010 #include "ChollaSurface.hpp" 00011 #include "ChollaPoint.hpp" 00012 #include "TDGeomFacet.hpp" 00013 #include "CastTo.hpp" 00014 #include "CubitFacet.hpp" 00015 #include "CubitFacetData.hpp" 00016 #include "CubitFacetEdge.hpp" 00017 #include "CubitFacetEdgeData.hpp" 00018 #include "ChollaDebug.hpp" 00019 #include "GfxDebug.hpp" 00020 #include "CurveFacetEvalTool.hpp" 00021 #include "ChollaEngine.hpp" 00022 #include "ChollaVolume.hpp" 00023 #include "CubitMessage.hpp" 00024 00025 00026 //=============================================================================== 00027 //Function: ChollaCurve (PUBLIC) (constructor) 00028 //=============================================================================== 00029 ChollaCurve::ChollaCurve( int block_id ) 00030 { 00031 static int count = 1; 00032 id = count++; 00033 myCurve = NULL; 00034 myEvalTool = NULL; 00035 startPoint = NULL; 00036 endPoint = NULL; 00037 blockID = block_id; 00038 myLength = MYLENGTH_UNINITIALIZED; 00039 myMergePartner = NULL; 00040 } 00041 00042 //=============================================================================== 00043 //Function: ~ChollaCurve (PUBLIC) (destructor) 00044 //=============================================================================== 00045 ChollaCurve::~ChollaCurve() 00046 { 00047 } 00048 00049 //=============================================================================== 00050 //Function: remove_td_associativity (PUBLIC) 00051 //=============================================================================== 00052 void ChollaCurve::remove_td_associativity( ChollaSurface *fsm_ptr ) 00053 { 00054 int i; 00055 TDGeomFacet *td; 00056 FacetEntity *edge_ptr; 00057 for(i=0; i<curveEdgeList.size(); i++) 00058 { 00059 edge_ptr = curveEdgeList.get_and_step(); 00060 td = TDGeomFacet::get_geom_facet( edge_ptr ); 00061 if (td) 00062 { 00063 td->remove_cholla_curve( this ); 00064 td->remove_cholla_surf( fsm_ptr ); 00065 } 00066 } 00067 } 00068 00069 00070 //============================================================================= 00071 //Function: get_ends (PUBLIC) 00072 //Description: returns the end locations of the curve. Determines their 00073 // location if not yet defined 00074 //Author: sjowen 00075 //Date: 12/4/00 00076 //============================================================================= 00077 CubitStatus ChollaCurve::get_ends( CubitVector &start, CubitVector &end ) 00078 { 00079 if (startPoint && endPoint) 00080 { 00081 start = startPoint->coordinates(); 00082 end = endPoint->coordinates(); 00083 } 00084 else 00085 { 00086 CubitStatus stat = determine_ends(); 00087 if (stat == CUBIT_FAILURE) 00088 return stat; 00089 start = startPoint->coordinates(); 00090 end = endPoint->coordinates(); 00091 } 00092 return CUBIT_SUCCESS; 00093 } 00094 00095 //============================================================================= 00096 //Function: get_ends (PUBLIC) 00097 //Description: returns the end nodes of the curve. Determines the 00098 // nodes if not yet defined 00099 //Author: sjowen 00100 //Date: 12/4/00 00101 //============================================================================= 00102 CubitStatus ChollaCurve::get_ends( CubitPoint *&start_ptr, CubitPoint *&end_ptr ) 00103 { 00104 if (startPoint && endPoint ) 00105 { 00106 start_ptr = startPoint; 00107 end_ptr = endPoint; 00108 } 00109 else 00110 { 00111 CubitStatus stat = determine_ends(); 00112 if (stat == CUBIT_FAILURE) 00113 return stat; 00114 start_ptr = startPoint; 00115 end_ptr = endPoint; 00116 } 00117 return CUBIT_SUCCESS; 00118 } 00119 00120 //============================================================================= 00121 //Function: split_curve (PRIVATE) 00122 //Description: split this curve into multiple ChollaCurve where there are 00123 // discontinuous strings of edges. Define start and end nodes 00124 // for each curve while we are at it 00125 //Author: sjowen 00126 //Date: 12/4/00 00127 //============================================================================= 00128 CubitStatus ChollaCurve::split_curve( 00129 DLIList<ChollaCurve*> &facet_curve_list) 00130 { 00131 DLIList<ChollaCurve*> new_curve_list; 00132 00133 // Go through the curveEdgeList and pull edges off one by one as we 00134 // determine which curve it belongs to. Continue until we have depleted 00135 // the list 00136 00137 int periodic = 0; 00138 int start_size = curveEdgeList.size(); 00139 int icount = 0; 00140 00141 curveEdgeList.reset(); 00142 while( curveEdgeList.size() > 0) 00143 { 00144 00145 // First, find an edge that has a start point on it 00146 00147 CubitFacetEdge *start_edge_ptr = (CubitFacetEdge *)curveEdgeList.get_and_step(); 00148 CubitPoint *point0_ptr = start_edge_ptr->point(0); 00149 CubitPoint *point1_ptr = start_edge_ptr->point(1); 00150 CubitPoint *start_point = NULL; 00151 if (periodic) 00152 { 00153 start_point = startPoint; 00154 } 00155 else 00156 { 00157 if (next_edge( point0_ptr, start_edge_ptr ) == NULL) 00158 start_point = point0_ptr; 00159 else if(next_edge( point1_ptr, start_edge_ptr ) == NULL) 00160 start_point = point1_ptr; 00161 } 00162 if (start_point != NULL || periodic) 00163 { 00164 00165 // create a new curve to hold the edge info 00166 00167 TDGeomFacet *td_gm_edge = TDGeomFacet::get_geom_facet(start_edge_ptr); 00168 int block_id = (td_gm_edge == NULL) ? -1 : td_gm_edge->get_block_id(); 00169 ChollaCurve *fcm_ptr = new ChollaCurve( block_id ); 00170 new_curve_list.append( fcm_ptr ); 00171 00172 // assign the edges to the new curve in the correct order and orientation 00173 00174 CubitStatus rv = fcm_ptr->build_curve_from_edges( start_point, periodic, start_size, start_edge_ptr, this ); 00175 if (rv != CUBIT_SUCCESS) 00176 return rv; 00177 00178 // remove the edges in the new curve from this curve 00179 00180 int ii; 00181 DLIList<FacetEntity *> flist = fcm_ptr->get_facet_list(); 00182 DLIList<CubitFacetEdge *> elist; 00183 CubitFacetEdge *edge_ptr; 00184 CAST_LIST( flist, elist, CubitFacetEdge ); 00185 for ( ii = elist.size(); ii > 0; ii-- ) 00186 { 00187 edge_ptr = elist.get_and_step(); 00188 curveEdgeList.remove( edge_ptr ); 00189 } 00190 start_size = curveEdgeList.size(); 00191 icount = 0; 00192 periodic = 0; 00193 } 00194 00195 // if we have gone through all of the edges without finding an end, 00196 // then we have a periodic curve. Choose an arbirary node to act as 00197 // the beginning and end 00198 00199 if (curveEdgeList.size() > 0) 00200 { 00201 icount++; 00202 if (icount > start_size) 00203 { 00204 curveEdgeList.reset(); 00205 CubitFacetEdge *edge = (CubitFacetEdge *)curveEdgeList.get(); 00206 CubitPoint *point_ptr = edge->point(0); 00207 startPoint = point_ptr; 00208 endPoint = point_ptr; 00209 periodic = 1; 00210 } 00211 } 00212 } 00213 00214 // add the new curves to the global curve list 00215 00216 int ii, jj; 00217 for (ii=new_curve_list.size(); ii>0; ii--) 00218 { 00219 ChollaCurve *fcm_ptr = new_curve_list.get_and_step(); 00220 00221 facet_curve_list.append( fcm_ptr ); 00222 00223 // update the surface info 00224 00225 for (jj=surfaceList.size(); jj>0; jj--) 00226 { 00227 ChollaSurface *fsm_ptr = surfaceList.get_and_step(); 00228 fcm_ptr->add_surface( fsm_ptr ); 00229 fsm_ptr->remove_curve( this ); 00230 fsm_ptr->add_curve( fcm_ptr ); 00231 } 00232 00233 // update the geometric curve pointer 00234 00235 fcm_ptr->assign_geometric_curve( NULL ); 00236 00237 // update the curve pointers in the edge tool data 00238 00239 DLIList<FacetEntity*> facet_list = fcm_ptr->get_facet_list(); 00240 for (jj=facet_list.size(); jj > 0; jj--) 00241 { 00242 FacetEntity *edge_ptr = facet_list.get_and_step(); 00243 TDGeomFacet *td_gm_edge = TDGeomFacet::get_geom_facet(edge_ptr); 00244 td_gm_edge->remove_cholla_curve( this ); 00245 td_gm_edge->add_cholla_curve( fcm_ptr ); 00246 } 00247 } 00248 00249 return CUBIT_SUCCESS; 00250 } 00251 00252 //============================================================================= 00253 //Function: build_curve_from_edges 00254 //Description: insert the ordered and oriented edges into this cholla curve 00255 //Notes: traverses starting at start_point and gathers facet edges until it 00256 // runs into another curve. 00257 // start_point is an existing CubitPoint at either end of the curve 00258 // max_edges is the maximum number of edges on this curve. should be 00259 // known beforehand (used for error checking). 00260 // 00261 // ***this function used to be part of split_curve. *** 00262 //Author: sjowen 00263 //Return: 00264 //Date: 09/07/2009 00265 //============================================================================= 00266 CubitStatus ChollaCurve::build_curve_from_edges( CubitPoint *start_point, 00267 int periodic, 00268 int max_edges, 00269 CubitFacetEdge *start_edge_ptr, 00270 ChollaCurve *parent_curve ) 00271 { 00272 00273 // find the first edge. Match the chollacurve owner with this curve 00274 // do this only if the start_edge_ptr was not passed in 00275 00276 DLIList<CubitFacetEdge *> point_edge_list; 00277 start_point->edges(point_edge_list); 00278 CubitFacetEdge *edge_ptr; 00279 if (start_edge_ptr == NULL) 00280 { 00281 for (int ii=0; ii<point_edge_list.size() && !start_edge_ptr; ii++) 00282 { 00283 edge_ptr = point_edge_list.get_and_step(); 00284 TDGeomFacet *td_geom = TDGeomFacet::get_geom_facet( edge_ptr ); 00285 00286 // assumes that the TDGeomFacet info has already been set up for the edges 00287 assert(td_geom != NULL); 00288 00289 DLIList<ChollaCurve *> cholla_curves; 00290 td_geom->get_cholla_curves(cholla_curves); 00291 00292 // currently should be only one-to-one relationship 00293 // could also be edge on surface in which case no curves associated 00294 assert(cholla_curves.size() <= 1); 00295 if (cholla_curves.size()) 00296 { 00297 if (cholla_curves.get() == this) 00298 start_edge_ptr = edge_ptr; 00299 } 00300 } 00301 assert(start_edge_ptr != NULL); // didn't find an edge that marched this chollacurve 00302 } 00303 00304 // create a new curve to hold the edge info 00305 00306 this->set_start( start_point ); 00307 start_point->set_as_feature(); 00308 00309 this->add_facet( start_edge_ptr ); 00310 int iedgecount = 0; 00311 edge_ptr = start_edge_ptr; 00312 CubitPoint *point0_ptr = start_point, *point1_ptr; 00313 CubitPoint *end_point = NULL; 00314 while(!end_point) 00315 { 00316 point1_ptr = edge_ptr->other_point( point0_ptr ); 00317 if ((edge_ptr = parent_curve->next_edge( point1_ptr, edge_ptr )) == NULL) 00318 { 00319 end_point = point1_ptr; 00320 } 00321 else 00322 { 00323 iedgecount++; 00324 if (iedgecount > max_edges) 00325 { 00326 PRINT_ERROR("ChollaCurve has start, but no end\n"); 00327 return CUBIT_FAILURE; 00328 } 00329 00330 this->add_facet( edge_ptr ); 00331 if (periodic && point1_ptr == start_point) 00332 end_point = start_point; 00333 point0_ptr = point1_ptr; 00334 } 00335 } 00336 this->set_end( end_point ); 00337 end_point->set_as_feature(); 00338 00339 // make sure all the edges are oriented correctly 00340 00341 int i; 00342 DLIList<FacetEntity *> flist = this->get_facet_list(); 00343 flist.reset(); 00344 DLIList<CubitFacetEdge *> elist; 00345 CAST_LIST( flist, elist, CubitFacetEdge ); 00346 elist.reset(); 00347 CubitPoint *cur_pt = start_point, *tmp_pt; 00348 for ( i = elist.size(); i > 0; i-- ) 00349 { 00350 edge_ptr = elist.get_and_step(); 00351 point0_ptr = edge_ptr->point(0); 00352 point1_ptr = edge_ptr->point(1); 00353 if (point0_ptr != cur_pt) 00354 { 00355 assert( cur_pt == point1_ptr ); 00356 edge_ptr->flip(); 00357 tmp_pt = point0_ptr; 00358 point0_ptr = point1_ptr; 00359 point1_ptr = tmp_pt; 00360 assert( point0_ptr == edge_ptr->point(0) && 00361 point1_ptr == edge_ptr->point(1) ); 00362 } 00363 cur_pt = point1_ptr; 00364 } 00365 00366 int mydebug = 0; 00367 if (mydebug) 00368 { 00369 int i; 00370 DLIList<FacetEntity *> flist = this->get_facet_list(); 00371 flist.reset(); 00372 DLIList<CubitFacetEdge *> elist; 00373 CAST_LIST( flist, elist, CubitFacetEdge ); 00374 elist.reset(); 00375 for ( i = elist.size(); i > 0; i-- ) { 00376 CubitFacetEdge *edge = elist.get_and_step(); 00377 CubitVector pt0_v = edge->point(0)->coordinates(); 00378 CubitVector pt1_v = edge->point(1)->coordinates(); 00379 GfxDebug::draw_point(pt0_v, CUBIT_GREEN_INDEX ); 00380 GfxDebug::draw_point(pt1_v, CUBIT_RED_INDEX ); 00381 GfxDebug::draw_line( pt0_v, pt1_v, CUBIT_YELLOW_INDEX ); 00382 GfxDebug::flush(); 00383 int view = 0; 00384 if (view) 00385 dview(); 00386 } 00387 } 00388 return CUBIT_SUCCESS; 00389 } 00390 00391 CubitStatus ChollaCurve::order_edges() 00392 { 00393 int i; 00394 bool periodic = false; 00395 if (NULL == startPoint) 00396 { 00397 DLIList<ChollaPoint *> cholla_points = get_points(); 00398 periodic = (cholla_points.size() == 1); 00399 00400 ChollaPoint *chpt = cholla_points.get(); 00401 CubitPoint *start_point = dynamic_cast<CubitPoint *> (chpt->get_facets()); 00402 00403 this->set_start( start_point ); 00404 if (NULL == start_point) 00405 return CUBIT_FAILURE; 00406 start_point->set_as_feature(); 00407 00408 if (periodic) 00409 { 00410 this->set_end(start_point); 00411 } 00412 else 00413 { 00414 chpt = cholla_points.step_and_get(); 00415 CubitPoint *end_point = dynamic_cast<CubitPoint *> (chpt->get_facets()); 00416 if (NULL == end_point) 00417 return CUBIT_FAILURE; 00418 this->set_end(end_point); 00419 end_point->set_as_feature(); 00420 } 00421 } 00422 00423 assert(startPoint); 00424 assert(endPoint); 00425 00426 if (curveEdgeList.size() > 1) 00427 { 00428 DLIList<CubitFacetEdge*> edges_ordered; 00429 CAST_LIST(curveEdgeList, edges_ordered, CubitFacetEdge); 00430 00431 CubitStatus stat = CubitFacetEdge::order_edge_list(edges_ordered, startPoint, endPoint); 00432 00433 if (CUBIT_FAILURE == stat) 00434 return CUBIT_FAILURE; 00435 00436 // store the edges in the correct order 00437 clean_out_edges(); 00438 00439 edges_ordered.reset(); 00440 for (i=0; i< edges_ordered.size(); i++) 00441 { 00442 this->add_facet(edges_ordered.get_and_step()); 00443 } 00444 } 00445 00446 00447 // make sure all the edges are oriented correctly 00448 DLIList<FacetEntity *> flist = this->get_facet_list(); 00449 flist.reset(); 00450 DLIList<CubitFacetEdge *> elist; 00451 CAST_LIST( flist, elist, CubitFacetEdge ); 00452 elist.reset(); 00453 CubitPoint *cur_pt = startPoint, *tmp_pt; 00454 for ( i = elist.size(); i > 0; i-- ) 00455 { 00456 CubitFacetEdge *edge_ptr = elist.get_and_step(); 00457 CubitPoint *point0_ptr = edge_ptr->point(0); 00458 CubitPoint *point1_ptr = edge_ptr->point(1); 00459 if (point0_ptr != cur_pt) 00460 { 00461 assert( cur_pt == point1_ptr ); 00462 edge_ptr->flip(); 00463 tmp_pt = point0_ptr; 00464 point0_ptr = point1_ptr; 00465 point1_ptr = tmp_pt; 00466 assert( point0_ptr == edge_ptr->point(0) && 00467 point1_ptr == edge_ptr->point(1) ); 00468 } 00469 cur_pt = point1_ptr; 00470 } 00471 00472 int mydebug = 0; 00473 if (mydebug) 00474 { 00475 int i; 00476 DLIList<FacetEntity *> flist = this->get_facet_list(); 00477 flist.reset(); 00478 DLIList<CubitFacetEdge *> elist; 00479 CAST_LIST( flist, elist, CubitFacetEdge ); 00480 elist.reset(); 00481 for ( i = elist.size(); i > 0; i-- ) { 00482 CubitFacetEdge *edge = elist.get_and_step(); 00483 CubitVector pt0_v = edge->point(0)->coordinates(); 00484 CubitVector pt1_v = edge->point(1)->coordinates(); 00485 GfxDebug::draw_point(pt0_v, CUBIT_GREEN_INDEX ); 00486 GfxDebug::draw_point(pt1_v, CUBIT_RED_INDEX ); 00487 GfxDebug::draw_line( pt0_v, pt1_v, CUBIT_YELLOW_INDEX ); 00488 GfxDebug::flush(); 00489 int view = 0; 00490 if (view) 00491 dview(); 00492 } 00493 } 00494 return CUBIT_SUCCESS; 00495 } 00496 00497 //============================================================================= 00498 //Function: length 00499 //Description: 00500 //Author: sjowen 00501 //Date: 04/21/2009 00502 //============================================================================ 00503 double ChollaCurve::length() 00504 { 00505 if (myLength > MYLENGTH_UNINITIALIZED) 00506 return myLength; 00507 00508 CubitFacetEdge *edge; 00509 FacetEntity *fent; 00510 myLength = 0.0; 00511 for (int iedge=0; iedge<curveEdgeList.size(); iedge++) 00512 { 00513 fent = curveEdgeList.get_and_step(); 00514 edge = dynamic_cast<CubitFacetEdge *> (fent); 00515 myLength += edge->length(); 00516 } 00517 00518 return myLength; 00519 } 00520 00521 //============================================================================= 00522 //Function: find adjacent edges at a point that lie on the curve 00523 //Description: determine the next edge from a given edge - return NULL if at the end 00524 //Author: william roshan quadros 00525 //Return: returns false if no adj_edges can be found 00526 //Date: 04/21/2009 00527 //============================================================================= 00528 bool ChollaCurve::adj_facet_edges( CubitPoint *node_ptr, CubitFacetEdge *&adj_edge1, CubitFacetEdge *&adj_edge2 ) 00529 { 00530 // initialize adj_edge1 and adj_edge2 00531 adj_edge1 = adj_edge2 = NULL; 00532 00533 DLIList<CubitFacetEdge*> node_edge_list; 00534 node_ptr->edges( node_edge_list ); 00535 00536 DLIList<CubitFacetEdge*> curve_edge_list; 00537 CAST_LIST(curveEdgeList, curve_edge_list, CubitFacetEdge); 00538 00539 curve_edge_list.intersect(node_edge_list); 00540 assert(curve_edge_list.size() < 3); 00541 00542 if (0 == curve_edge_list.size()) 00543 return false; 00544 00545 curve_edge_list.reset(); 00546 adj_edge1 = curve_edge_list.get(); 00547 00548 if (curve_edge_list.size() > 1) 00549 adj_edge2 = curve_edge_list.next(); 00550 00551 return true; 00552 } 00553 00554 //============================================================================= 00555 //Function: next_edge (PRIVATE) 00556 //Description: determine the next edge from a given edge - return NULL if at 00557 // the end 00558 //Author: sjowen 00559 //Date: 12/4/00 00560 //============================================================================= 00561 CubitFacetEdge *ChollaCurve::next_edge( CubitPoint *node_ptr, 00562 CubitFacetEdge *edge_ptr ) 00563 { 00564 // check if this node has its hit flag set - we are at a feature break. 00565 00566 TDGeomFacet *td_gm_node = TDGeomFacet::get_geom_facet(node_ptr); 00567 if (td_gm_node->get_hit_flag() == 1 || node_ptr->is_feature()) 00568 return NULL; 00569 00570 int jj, kk; 00571 00572 // find the next edge 00573 00574 CubitFacetEdge *next_edge_on_curve = NULL; 00575 DLIList<CubitFacetEdge*> edge_list; 00576 node_ptr->edges( edge_list ); 00577 int num_adj_curves = 1; // keep track of the number of curves at this node 00578 for (jj=0; jj<edge_list.size(); jj++) 00579 { 00580 CubitFacetEdge *node_edge_ptr = edge_list.get_and_step(); 00581 if (node_edge_ptr != edge_ptr) 00582 { 00583 TDGeomFacet *td_gm_edge = TDGeomFacet::get_geom_facet(node_edge_ptr); 00584 if (td_gm_edge != NULL) 00585 { 00586 DLIList<ChollaCurve*> fcurve_list; 00587 td_gm_edge->get_cholla_curves( fcurve_list ); 00588 if (fcurve_list.size() > 0) 00589 { 00590 00591 // if 3 or more curves meet at this node, then force the curve to terminate here 00592 00593 num_adj_curves++; 00594 if (num_adj_curves >= 3) 00595 { 00596 return NULL; 00597 } 00598 00599 // otherwise try to match the curve to the edge to find the next edge 00600 00601 for (kk=0; kk<fcurve_list.size(); kk++) 00602 { 00603 ChollaCurve *fcm_ptr = fcurve_list.get_and_step(); 00604 if (fcm_ptr == this) 00605 { 00606 next_edge_on_curve = node_edge_ptr; 00607 } 00608 } 00609 } 00610 } 00611 } 00612 } 00613 return next_edge_on_curve; 00614 } 00615 00616 00617 //============================================================================= 00618 //Function: determine_ends (PRIVATE) 00619 //Description: determine the end nodes of the curve 00620 // Assumes that there is one continuous string of edges 00621 // (may need to call split_curve first) 00622 //Author: sjowen 00623 //Date: 12/4/00 00624 //============================================================================= 00625 CubitStatus ChollaCurve::determine_ends( ) 00626 { 00627 int ii, jj, kk, inode; 00628 CubitFacetEdge *edge_ptr; 00629 CubitPoint *node0_ptr, *node1_ptr, *node_ptr; 00630 startPoint = endPoint = NULL; 00631 int done = 0; 00632 for(ii=0; ii<curveEdgeList.size() && !done; ii++) 00633 { 00634 edge_ptr = (CubitFacetEdge *)curveEdgeList.get_and_step(); 00635 node0_ptr = edge_ptr->point(0); 00636 node1_ptr = edge_ptr->point(1); 00637 for (inode=0; inode<2 && !done; inode++) 00638 { 00639 node_ptr = (inode==0) ? node0_ptr : node1_ptr; 00640 DLIList<CubitFacetEdge*> edge_list; 00641 node_ptr->edges( edge_list ); 00642 for (jj=0; jj<edge_list.size() && !done; jj++) 00643 { 00644 CubitFacetEdge *node_edge_ptr = edge_list.get_and_step(); 00645 if (node_edge_ptr != edge_ptr) 00646 { 00647 TDGeomFacet *td_gm_edge = TDGeomFacet::get_geom_facet(node_edge_ptr); 00648 if (td_gm_edge != NULL) 00649 { 00650 int found = 0; 00651 DLIList<ChollaCurve*> fcurve_list; 00652 td_gm_edge->get_cholla_curves( fcurve_list ); 00653 for (kk=0; kk<fcurve_list.size() && !found; kk++) 00654 { 00655 ChollaCurve *fcm_ptr = fcurve_list.get_and_step(); 00656 if (fcm_ptr == this) 00657 found = 1; 00658 } 00659 if (!found) 00660 { 00661 if (startPoint == NULL) 00662 { 00663 startPoint = node_ptr; 00664 } 00665 else 00666 { 00667 endPoint = node_ptr; 00668 done = 1; 00669 } 00670 } 00671 } 00672 } 00673 } 00674 } 00675 00676 } 00677 00678 // check for periodic condition - just choose an arbitrary node to serve as 00679 // both start and end of the curve 00680 00681 if (startPoint == NULL && endPoint == NULL) 00682 { 00683 curveEdgeList.reset(); 00684 edge_ptr = (CubitFacetEdge *)curveEdgeList.get(); 00685 node_ptr = edge_ptr->point(0); 00686 startPoint = node_ptr; 00687 endPoint = node_ptr; 00688 } 00689 else if ( ( startPoint == NULL && endPoint != NULL ) || 00690 ( startPoint != NULL && endPoint == NULL ) ) 00691 { 00692 PRINT_ERROR("Could not determine start and end of curve in ChollaCurve\n"); 00693 return CUBIT_FAILURE; 00694 } 00695 return CUBIT_SUCCESS; 00696 } 00697 00698 00699 CubitStatus ChollaCurve::build_curve_facet_eval_tool( void ) 00700 { 00701 //debug this function as point list is not valid 00702 00703 if( this->get_eval_tool() ) 00704 { 00705 assert(false); //WARNING: Curve facet eval tool already exist! 00706 } 00707 00708 CurveFacetEvalTool *curv_eval_tool_ptr = new CurveFacetEvalTool(); 00709 00710 // Step 1: Initialize facet_edge_list and point_list 00711 CubitStatus stat; 00712 DLIList<CubitPoint *> point_list; 00713 int i; 00714 // insert start point of every facet_edge 00715 curveEdgeList.reset(); 00716 for( i = 0; i < curveEdgeList.size(); i++ ) 00717 { 00718 point_list.append( CAST_TO( curveEdgeList.get_and_step(), CubitFacetEdge )->point(0) ); 00719 } 00720 // insert end point of last facet_edge 00721 curveEdgeList.step( curveEdgeList.size() - 1 ); 00722 point_list.append( CAST_TO( curveEdgeList.get(), CubitFacetEdge )->point(1) ); 00723 00724 DLIList<CubitFacetEdge *> edge_list; 00725 CAST_LIST( curveEdgeList, edge_list, CubitFacetEdge ); 00726 stat = curv_eval_tool_ptr->initialize( edge_list, point_list ); 00727 if( stat != CUBIT_SUCCESS ) 00728 { 00729 return stat; 00730 } 00731 00732 /* 00733 // Step 2: find sense of curve_facet_eval_tool /// this is done internally in next Step in initialize() 00734 if( this->startPoint ) 00735 { 00736 stat = curv_eval_tool_ptr->find_curv_sense( this->startPoint ); 00737 if( stat != CUBIT_SUCCESS ) 00738 { 00739 return stat; 00740 } 00741 } 00742 */ 00743 // Step 2: Initialize adj_surface_facet_eval_tool with orientation_wrt_surface 00744 if( surfaceList.size() ) 00745 { 00746 CubitSense orientation_wrt_surface; 00747 if( CUBIT_SUCCESS == ChollaEngine::determine_curve_orientation( surfaceList.get(), this, orientation_wrt_surface ) ) 00748 { 00749 if( this->startPoint && this->endPoint ) 00750 { 00751 stat = curv_eval_tool_ptr->initialize( surfaceList.get()->get_eval_tool(), 00752 this->startPoint, 00753 this->endPoint, 00754 orientation_wrt_surface); 00755 } 00756 } 00757 else 00758 { 00759 assert(false); 00760 } 00761 00762 if( stat != CUBIT_SUCCESS ) 00763 { 00764 assert( false ); 00765 return stat; 00766 } 00767 } 00768 else 00769 { 00770 assert(false); //WARNING: No adjacent cholla surface available 00771 } 00772 00773 // Step 4: assign the new curv_eval_tool to cholla_curve 00774 assign_eval_tool( curv_eval_tool_ptr ); 00775 00776 return stat; 00777 } 00778 00779 //============================================================================= 00780 //Function: feature_angle (PRIVATE) 00781 //Description: compute angles at nodes on the curve to see if we need to split 00782 // the curve. Mark the node tooldata hitflag if the node will 00783 // break the curve (this is refernced in next_edge) 00784 //Author: sjowen 00785 //Date: 12/4/00 00786 //============================================================================= 00787 CubitStatus ChollaCurve::feature_angle( 00788 double min_dot ) 00789 { 00790 // first compute all of the edge vector and store with the edge tooldata 00791 00792 int ii, jj; 00793 FacetEntity *facet_ptr; 00794 CubitFacetEdge *edge_ptr; 00795 CubitPoint *start_node; 00796 CubitPoint *end_node; 00797 CubitVector tangent; 00798 TDGeomFacet *td_gm; 00799 for (ii=0; ii<curveEdgeList.size(); ii++) 00800 { 00801 00802 // compute the tangent vector of the edge and store it with its tooldata 00803 00804 facet_ptr = curveEdgeList.get_and_step(); 00805 edge_ptr = CAST_TO( facet_ptr, CubitFacetEdge ); 00806 start_node = edge_ptr->point(0); 00807 end_node = edge_ptr->point(1); 00808 tangent = end_node->coordinates() - start_node->coordinates(); 00809 tangent.normalize(); 00810 td_gm = TDGeomFacet::get_geom_facet( edge_ptr ); 00811 td_gm->set_normal( tangent ); 00812 00813 // initialize the nodes tooldata hit flags - set them all to -1 00814 00815 td_gm = TDGeomFacet::get_geom_facet(start_node); 00816 td_gm->set_hit_flag(-1); 00817 td_gm = TDGeomFacet::get_geom_facet(end_node); 00818 td_gm->set_hit_flag(-1); 00819 } 00820 00821 // now go through them again and compute the dot product between edges 00822 00823 CubitVector tang0; 00824 CubitVector tang1; 00825 double dot; 00826 CubitPoint *node_ptr; 00827 CubitFacetEdge *next_edge_ptr; 00828 TDGeomFacet *td_gm_node; 00829 00830 for (ii=0; ii<curveEdgeList.size(); ii++) 00831 { 00832 facet_ptr = curveEdgeList.get_and_step(); 00833 edge_ptr = CAST_TO( facet_ptr, CubitFacetEdge ); 00834 start_node = edge_ptr->point(0); 00835 end_node = edge_ptr->point(1); 00836 for (jj=0; jj<2; jj++) 00837 { 00838 node_ptr = (jj==0) ? start_node : end_node; 00839 td_gm_node = TDGeomFacet::get_geom_facet( node_ptr ); 00840 if (td_gm_node->get_hit_flag() == -1) 00841 { 00842 next_edge_ptr = next_edge( node_ptr, edge_ptr ); 00843 if (next_edge_ptr == NULL) 00844 { 00845 td_gm_node->set_hit_flag( 1 ); 00846 node_ptr->set_as_feature(); 00847 } 00848 else 00849 { 00850 td_gm = TDGeomFacet::get_geom_facet( edge_ptr ); 00851 tang0 = td_gm->get_normal(); 00852 td_gm = TDGeomFacet::get_geom_facet( next_edge_ptr ); 00853 tang1 = td_gm->get_normal(); 00854 00855 // change the sign of the tangent vectors if the 00856 // sense of the edges are not the same 00857 00858 if (node_ptr == start_node) 00859 { 00860 if (node_ptr != next_edge_ptr->point(1)) 00861 tang0 = -tang0; 00862 } 00863 else 00864 { 00865 if (node_ptr != next_edge_ptr->point(0)) 00866 tang0 = -tang0; 00867 } 00868 00869 // compute the dot product between tangemt vectors 00870 00871 dot = tang0 % tang1; 00872 00873 // set the hit flag if there needs to be a feature break here 00874 00875 if (dot <= min_dot) 00876 { 00877 td_gm_node->set_hit_flag( 1 ); 00878 node_ptr->set_as_feature(); 00879 } 00880 else 00881 { 00882 td_gm_node->set_hit_flag( 0 ); 00883 } 00884 } 00885 } 00886 } 00887 } 00888 return CUBIT_SUCCESS; 00889 } 00890 00891 static int icolor = 0; 00892 void ChollaCurve::debug_draw() 00893 { 00894 icolor++; 00895 icolor = icolor%15; 00896 dcolor(icolor); 00897 dldraw(curveEdgeList); 00898 } 00899 00900 void ChollaCurve::print() 00901 { 00902 FILE *fp = fopen("debug.curve", "a"); 00903 fprintf(fp,"*** Curve %d ***\n", id); 00904 for (int ii=0; ii<curveEdgeList.size(); ii++) 00905 { 00906 FacetEntity *fe_ptr = curveEdgeList.get_and_step(); 00907 CubitFacetEdge *cfe_ptr = CAST_TO(fe_ptr, CubitFacetEdge ); 00908 CubitPoint *cp0_ptr = cfe_ptr->point(0); 00909 CubitPoint *cp1_ptr = cfe_ptr->point(1); 00910 fprintf(fp," Edge (%d)\n", cfe_ptr->id() ); 00911 fprintf(fp," Point (%d) %8.4f %8.4f %8.4f\n", 00912 cp0_ptr->id(), cp0_ptr->x(), cp0_ptr->y(), cp0_ptr->z()); 00913 fprintf(fp," Point (%d) %8.4f %8.4f %8.4f\n", 00914 cp1_ptr->id(), cp1_ptr->x(), cp1_ptr->y(), cp1_ptr->z()); 00915 } 00916 fclose(fp); 00917 } 00918 00919 00920 // disassociate from cholla points 00921 CubitStatus ChollaCurve::disassociate_from_points( void ) 00922 { 00923 00924 /* 00925 if( startPoint ) 00926 { 00927 startPoint->remove_curve( this ); 00928 startPoint = NULL; 00929 } 00930 if( endPoint ) 00931 { 00932 endPoint->remove_curve( this ); 00933 endPoint = NULL; 00934 } 00935 */ 00936 00937 int i; 00938 for( i = 0; i < pointList.size(); i++ ) 00939 { 00940 pointList.get_and_step()->remove_curve( this ); 00941 } 00942 pointList.clean_out(); 00943 00944 return CUBIT_SUCCESS; 00945 } 00946 00947 // disassociate from cholla surface 00948 CubitStatus ChollaCurve::disassociate_from_surfaces( void) 00949 { 00950 int i; 00951 for( i = 0; i < surfaceList.size(); i++ ) 00952 { 00953 surfaceList.get_and_step()->remove_curve( this ); 00954 } 00955 surfaceList.clean_out(); 00956 return CUBIT_SUCCESS; 00957 } 00958 00959 00960 CubitStatus ChollaCurve::replace_facet( FacetEntity *remove_edge, FacetEntity *replace_edge ) 00961 { 00962 curveEdgeList.move_to( remove_edge ); 00963 curveEdgeList.insert( replace_edge ); 00964 curveEdgeList.remove( remove_edge ); 00965 myLength = MYLENGTH_UNINITIALIZED; 00966 return CUBIT_SUCCESS; 00967 } 00968 00969 CubitStatus ChollaCurve::insert_facet( FacetEntity *old_edge, FacetEntity *new_edge ) 00970 { 00971 curveEdgeList.move_to( old_edge ); 00972 curveEdgeList.insert( new_edge ); 00973 00974 return CUBIT_SUCCESS; 00975 } 00976 00977 CubitStatus ChollaCurve::is_contain( FacetEntity *edge ) 00978 { 00979 if( curveEdgeList.is_in_list( edge ) ) 00980 return CUBIT_SUCCESS; 00981 else 00982 return CUBIT_FAILURE; 00983 } 00984 00985 00986 //============================================================================= 00987 //Function: is_in_volume (PUBLIC) 00988 //Description: return whether this curve is contained within the specified volume 00989 //Author: sjowen 00990 //Date: 9/11/2009 00991 //============================================================================= 00992 CubitBoolean ChollaCurve::is_in_volume( ChollaVolume *chvol_ptr ) 00993 { 00994 for (int ii=0; ii<surfaceList.size(); ii++) 00995 { 00996 ChollaSurface *chsurf_ptr = surfaceList.get_and_step(); 00997 DLIList<ChollaVolume *> chvol_list; 00998 chsurf_ptr->get_volumes(chvol_list); 00999 for (int jj=0; jj<chvol_list.size(); jj++) 01000 { 01001 ChollaVolume *mychvol_ptr = chvol_list.get_and_step(); 01002 if (mychvol_ptr == chvol_ptr) 01003 return CUBIT_TRUE; 01004 } 01005 } 01006 return CUBIT_FALSE; 01007 } 01008 01009 //============================================================================= 01010 //Function: is_in_surface (PUBLIC) 01011 //Description: return whether this curve is contained within the specified surface 01012 //Author: sjowen 01013 //Date: 9/18/2009 01014 //============================================================================= 01015 CubitBoolean ChollaCurve::is_in_surface( ChollaSurface *chsurf_ptr ) 01016 { 01017 for (int ii=0; ii<surfaceList.size(); ii++) 01018 { 01019 ChollaSurface *mysurf_ptr = surfaceList.get_and_step(); 01020 if (mysurf_ptr == chsurf_ptr) 01021 { 01022 return CUBIT_TRUE; 01023 } 01024 } 01025 return CUBIT_FALSE; 01026 } 01027 01028 01029 //============================================================================= 01030 //Function: get_facet_points (PUBLIC) 01031 //Description: return the list of facet points on this chollacurve 01032 //Notes: inclusive = true will return end points as well, otherwise only 01033 // interior points will be returned 01034 //Author: sjowen 01035 //Date: 9/11/2009 01036 //============================================================================= 01037 void ChollaCurve::get_facet_points( DLIList<CubitPoint *> &point_list, CubitBoolean inclusive) 01038 { 01039 FacetEntity *fe_ptr; 01040 CubitFacetEdge *edge_ptr; 01041 CubitPoint *pts[2]; 01042 for (int ii=0; ii<curveEdgeList.size(); ii++) 01043 { 01044 fe_ptr = curveEdgeList.get_and_step(); 01045 edge_ptr = dynamic_cast<CubitFacetEdge *> (fe_ptr); 01046 assert(edge_ptr != NULL); 01047 for (int jj=0; jj<2; jj++) 01048 { 01049 pts[jj] = edge_ptr->point(jj); 01050 if (inclusive) 01051 { 01052 point_list.append(pts[jj]); 01053 } 01054 else 01055 { 01056 if (pts[jj] != startPoint && pts[jj] != endPoint) 01057 { 01058 point_list.append(pts[jj]); 01059 } 01060 } 01061 } 01062 } 01063 point_list.uniquify_ordered(); 01064 } 01065 01066 //============================================================================= 01067 //Function: has_point (PUBLIC) 01068 //Description: return whether the curve contains the gicen point 01069 //Notes: 01070 //============================================================================= 01071 CubitBoolean ChollaCurve::has_point( ChollaPoint *chpt ) 01072 { 01073 for(int ii=0; ii<pointList.size(); ii++) 01074 { 01075 ChollaPoint *pt = pointList.get_and_step(); 01076 if (pt == chpt) 01077 return CUBIT_TRUE; 01078 } 01079 return CUBIT_FALSE; 01080 } 01081 01082 //============================================================================= 01083 //Function: verify_points (PUBLIC) 01084 //Description: verify that all points on this curve have this curve as an adjacency 01085 //Notes: 01086 //============================================================================= 01087 CubitStatus ChollaCurve::verify_points() 01088 { 01089 for(int ii=0; ii<pointList.size(); ii++) 01090 { 01091 ChollaPoint *pt = pointList.get_and_step(); 01092 if (!pt->is_in_curve(this)) 01093 return CUBIT_FAILURE; 01094 } 01095 return CUBIT_SUCCESS; 01096 } 01097 01098 int ChollaCurve::num_volumes() 01099 { 01100 01101 DLIList<ChollaVolume *> chvol_list; 01102 for (int i=0; i<surfaceList.size(); i++) 01103 { 01104 ChollaSurface *chsurf_ptr = surfaceList.get_and_step(); 01105 DLIList<ChollaVolume*> tmp_vols; 01106 chsurf_ptr->get_volumes(tmp_vols); 01107 chvol_list += tmp_vols; 01108 } 01109 01110 chvol_list.uniquify_unordered(); 01111 return chvol_list.size(); 01112 } 01113 01114 //EOF 01115