cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : FacetBody.cpp 00003 // 00004 // Purpose : 00005 // 00006 // Special Notes : 00007 // 00008 // Creator : David White 00009 // 00010 // Creation Date : 7/18/00 00011 // 00012 //------------------------------------------------------------------------- 00013 00014 // ********** BEGIN STANDARD INCLUDES ********** 00015 #include <assert.h> 00016 // ********** END STANDARD INCLUDES ********** 00017 00018 00019 // ********** BEGIN CUBIT INCLUDES ********** 00020 #include "CubitDefines.h" 00021 #include "CubitString.hpp" 00022 #include "CubitPoint.hpp" 00023 #include "CastTo.hpp" 00024 #include "BodySM.hpp" 00025 #include "Body.hpp" 00026 #include "FacetBody.hpp" 00027 #include "CubitSimpleAttrib.hpp" 00028 #include "FacetQueryEngine.hpp" 00029 #include "DLIList.hpp" 00030 #include "FacetEvalTool.hpp" 00031 #include "CurveFacetEvalTool.hpp" 00032 #include "Surface.hpp" 00033 #include "FacetSurface.hpp" 00034 #include "CubitTransformMatrix.hpp" 00035 #include "FacetPoint.hpp" 00036 #include "FacetCurve.hpp" 00037 #include "FacetCoEdge.hpp" 00038 #include "FacetLoop.hpp" 00039 #include "FacetShell.hpp" 00040 #include "FacetLump.hpp" 00041 #include "CubitFacetEdge.hpp" 00042 #include "FacetModifyEngine.hpp" 00043 #include "FacetAttrib.hpp" 00044 #include "GfxDebug.hpp" 00045 #include "CubitSimpleAttrib.hpp" 00046 #include "CubitPointData.hpp" 00047 00048 //------------------------------------------------------------------------- 00049 // Purpose : A constructor with a list of lumps that are attached. 00050 // 00051 // Special Notes : 00052 // 00053 //------------------------------------------------------------------------- 00054 FacetBody::FacetBody(DLIList<Lump*>& my_lumps) 00055 { 00056 myLumps += my_lumps; 00057 } 00058 FacetBody::~FacetBody() 00059 { 00060 //Not sure what to do.. 00061 } 00062 00063 GeometryQueryEngine* FacetBody::get_geometry_query_engine() const 00064 { 00065 return FacetQueryEngine::instance(); 00066 } 00067 00068 void FacetBody::append_simple_attribute_virt(const CubitSimpleAttrib &csa) 00069 { attribSet.append_attribute(csa); } 00070 00071 void FacetBody::remove_simple_attribute_virt(const CubitSimpleAttrib &csa) 00072 { attribSet.remove_attribute(csa); } 00073 00074 void FacetBody::remove_all_simple_attribute_virt() 00075 { attribSet.remove_all_attributes(); } 00076 00077 CubitStatus FacetBody::get_simple_attribute(DLIList<CubitSimpleAttrib>& csa_list) 00078 { return attribSet.get_attributes(csa_list); } 00079 00080 CubitStatus FacetBody::get_simple_attribute( const CubitString& name, 00081 DLIList<CubitSimpleAttrib>& csa_list ) 00082 { return attribSet.get_attributes( name, csa_list ); } 00083 00084 CubitStatus FacetBody::save_attribs( FILE *file_ptr ) 00085 { return attribSet.save_attributes( file_ptr); } 00086 00087 CubitStatus FacetBody::restore_attribs( FILE *file_ptr, unsigned int endian ) 00088 { return attribSet.restore_attributes( file_ptr, endian ); } 00089 00090 00091 00092 //---------------------------------------------------------------- 00093 // Function: copy 00094 // Description: create a new copy of the body. 00095 // Author: sjowen 00096 //---------------------------------------------------------------- 00097 BodySM* FacetBody::copy() 00098 { 00099 CubitStatus rv; 00100 00101 // ----------Copy the points on the body------------------------ 00102 00103 std::map<TopologyBridge*, TopologyBridge*> old_to_new_map; 00104 00105 std::map<CubitPoint*, CubitPoint*> old_to_new_cubit_pts; 00106 00107 int ii; 00108 DLIList<FacetPoint*> point_list; 00109 get_points(point_list); 00110 DLIList<TBPoint*> copy_points; 00111 point_list.reset(); 00112 TBPoint *point_ptr; 00113 TBPoint *point_copy; 00114 for(ii=0; ii<point_list.size(); ii++) 00115 { 00116 point_ptr = point_list.get_and_step(); 00117 CubitVector temp_vector = point_ptr->coordinates(); 00118 00119 CubitPoint *new_cubit_point = new CubitPointData( temp_vector ); 00120 00121 rv = FacetModifyEngine::instance()->make_facet_point( new_cubit_point, 00122 point_copy); 00123 00124 if(rv != CUBIT_SUCCESS) 00125 { 00126 PRINT_ERROR("Couldn't copy points"); 00127 return (BodySM *)NULL; 00128 } 00129 copy_points.append( point_copy ); 00130 00131 FacetPoint *old_fp = static_cast<FacetPoint*>(point_ptr); 00132 00133 old_to_new_cubit_pts.insert( 00134 std::make_pair(old_fp->get_cubit_point(), new_cubit_point ) ); 00135 00136 old_to_new_map.insert( 00137 std::make_pair( point_ptr, point_copy ) ); 00138 } 00139 00140 // ------------------Copy the curves------------------------- 00141 00142 int jj; 00143 std::map<FacetCurve*, FacetCurve*> hard_line_curve_map; 00144 DLIList<FacetCurve*> curve_list; 00145 get_curves( curve_list ); 00146 DLIList<Curve*> copy_curves; 00147 curve_list.reset(); 00148 Curve *curve_ptr, *curve_copy; 00149 FacetCurve *fcurve; 00150 TBPoint *ptsm_ptr; 00151 TBPoint *start_ptr, *end_ptr, *copy_start = NULL, *copy_end = NULL; 00152 for (ii=0; ii<curve_list.size(); ii++) 00153 { 00154 curve_ptr = curve_list.get_and_step(); 00155 fcurve = CAST_TO( curve_ptr, FacetCurve ); 00156 start_ptr = fcurve->start_point(); 00157 end_ptr = fcurve->end_point(); 00158 int found0 = 0; 00159 int found1 = 0; 00160 00161 // find the end points 00162 00163 point_list.reset(); 00164 copy_points.reset(); 00165 for (jj=0; jj<point_list.size() && (!found0 || !found1); jj++) 00166 { 00167 point_ptr = point_list.get_and_step(); 00168 ptsm_ptr = CAST_TO(point_ptr, TBPoint); 00169 point_copy = copy_points.get_and_step(); 00170 if (ptsm_ptr == start_ptr) 00171 { 00172 copy_start = point_copy; 00173 found0 = 1; 00174 } 00175 if (ptsm_ptr == end_ptr) 00176 { 00177 copy_end = point_copy; 00178 found1 = 1; 00179 } 00180 } 00181 00182 // create the new curve and update the points 00183 00184 rv = FacetModifyEngine::instance()->make_facet_curve(copy_start, 00185 copy_end, 00186 curve_copy); 00187 if(rv != CUBIT_SUCCESS) 00188 { 00189 PRINT_ERROR("Couldn't copy curves"); 00190 return (BodySM *)NULL; 00191 } 00192 00193 00194 CurveFacetEvalTool *eval_tool = fcurve->get_eval_tool(); 00195 DLIList<CubitFacetEdge*> facet_edges; 00196 eval_tool->get_facets( facet_edges ); 00197 CubitFacetEdge *tmp_facet_edge = facet_edges.get(); 00198 DLIList<CubitFacet*> adj_facets; 00199 tmp_facet_edge->facets( adj_facets ); 00200 CubitFacet *tmp_facet = adj_facets.get_and_step(); 00201 tmp_facet->tool_id(); 00202 00203 for( int k=adj_facets.size(); k--; ) 00204 { 00205 if( tmp_facet_edge->num_adj_facets_on_surf( adj_facets.get_and_step()->tool_id() ) > 1 ) 00206 { 00207 hard_line_curve_map.insert( 00208 std::map<FacetCurve*, FacetCurve*>::value_type( static_cast<FacetCurve*>( CAST_TO( curve_copy, FacetCurve )),fcurve )); 00209 break; 00210 } 00211 } 00212 00213 old_to_new_map.insert( 00214 std::make_pair( curve_ptr, curve_copy ) ); 00215 00216 copy_curves.append( curve_copy ); 00217 } 00218 00219 // ------------------copy coedges----------------------- 00220 00221 DLIList<FacetCoEdge*> coedge_list; 00222 get_coedges( coedge_list ); 00223 DLIList<CoEdgeSM*> copy_coedges; 00224 coedge_list.reset(); 00225 Curve *curvsm_ptr; 00226 Curve *curvsm_copy = NULL; 00227 CoEdgeSM *coedge_ptr, *coedge_copy; 00228 FacetCoEdge *fcoedge; 00229 for (ii=0; ii<coedge_list.size(); ii++) 00230 { 00231 coedge_ptr = coedge_list.get_and_step(); 00232 fcoedge = CAST_TO( coedge_ptr, FacetCoEdge ); 00233 Curve *curve_at_coedge = fcoedge->curve(); 00234 int found = 0; 00235 00236 // find the associated curve 00237 00238 curve_list.reset(); 00239 copy_curves.reset(); 00240 for (jj=0; jj<curve_list.size() && !found; jj++) 00241 { 00242 curve_ptr = curve_list.get_and_step(); 00243 curvsm_ptr = CAST_TO(curve_ptr, Curve); 00244 curvsm_copy = copy_curves.get_and_step(); 00245 if (curve_at_coedge == curvsm_ptr) 00246 { 00247 found = 1; 00248 } 00249 } 00250 00251 // create the new coedge 00252 00253 CubitSense sense = fcoedge->sense(); 00254 rv = FacetModifyEngine::instance()->make_facet_coedge(curvsm_copy, 00255 sense, coedge_copy); 00256 if(rv != CUBIT_SUCCESS) 00257 { 00258 PRINT_ERROR("Couldn't copy coedge"); 00259 return (BodySM *)NULL; 00260 } 00261 copy_coedges.append( coedge_copy ); 00262 } 00263 00264 // ----------------------copy loops-------------------------- 00265 00266 int kk; 00267 DLIList<FacetLoop*> loop_list; 00268 get_loops( loop_list ); 00269 DLIList<LoopSM*> copy_loops; 00270 loop_list.reset(); 00271 LoopSM *loop_ptr, *loop_copy; 00272 FacetLoop *floop; 00273 for (ii=0; ii<loop_list.size(); ii++) 00274 { 00275 floop = loop_list.get_and_step(); 00276 DLIList<FacetCoEdge *>coedges_on_loop; 00277 floop->get_coedges(coedges_on_loop); 00278 DLIList<CoEdgeSM *>copy_coedges_on_loop; 00279 00280 // find all associated coedges on the loop 00281 00282 for(kk=0; kk<coedges_on_loop.size(); kk++) 00283 { 00284 int found = 0; 00285 coedge_list.reset(); 00286 copy_coedges.reset(); 00287 CoEdgeSM *coedge_on_loop = coedges_on_loop.get_and_step(); 00288 for (jj=0; jj<coedge_list.size() && !found; jj++) 00289 { 00290 coedge_ptr = coedge_list.get_and_step(); 00291 coedge_copy = copy_coedges.get_and_step(); 00292 if (coedge_on_loop == coedge_ptr) 00293 { 00294 found = 1; 00295 copy_coedges_on_loop.append(coedge_copy); 00296 } 00297 } 00298 } 00299 00300 // create the new loop 00301 00302 rv = FacetModifyEngine::instance()->make_facet_loop(copy_coedges_on_loop, 00303 loop_copy); 00304 if(rv != CUBIT_SUCCESS) 00305 { 00306 PRINT_ERROR("Couldn't copy loops"); 00307 return (BodySM *)NULL; 00308 } 00309 copy_loops.append( loop_copy ); 00310 } 00311 00312 // ----------------------copy surfaces-------------------------- 00313 DLIList<FacetSurface*> surface_list; 00314 get_surfaces(surface_list); 00315 DLIList<Surface*> copy_surfaces; 00316 surface_list.reset(); 00317 Surface *surface_ptr, *surface_copy; 00318 FacetSurface *fsurface; 00319 for (ii=0; ii<surface_list.size(); ii++) 00320 { 00321 fsurface = surface_list.get_and_step(); 00322 DLIList<FacetLoop *>loops_on_surface; 00323 fsurface->get_loops(loops_on_surface); 00324 DLIList<LoopSM *>copy_loops_on_surface; 00325 00326 // find all associated loops on the surface 00327 00328 for(kk=0; kk<loops_on_surface.size(); kk++) 00329 { 00330 int found = 0; 00331 loop_list.reset(); 00332 copy_loops.reset(); 00333 LoopSM *loop_on_surface = loops_on_surface.get_and_step(); 00334 for (jj=0; jj<loop_list.size() && !found; jj++) 00335 { 00336 loop_ptr = loop_list.get_and_step(); 00337 loop_copy = copy_loops.get_and_step(); 00338 if (loop_on_surface == loop_ptr) 00339 { 00340 found = 1; 00341 copy_loops_on_surface.append(loop_copy); 00342 } 00343 } 00344 } 00345 00346 // create the new surface 00347 00348 DLIList<CubitFacet*>facet_list; 00349 DLIList<CubitPoint*>cpoint_list; 00350 rv = fsurface->copy_facets( facet_list, cpoint_list, old_to_new_cubit_pts ); 00351 if (rv != CUBIT_SUCCESS) 00352 { 00353 return (BodySM *)NULL; 00354 } 00355 int interp_order = fsurface->interp_order(); 00356 double min_dot = fsurface->min_dot(); 00357 const CubitEvaluatorData *eval_data = fsurface->evaluator_data(); 00358 CubitBoolean use_point_addresses = CUBIT_FALSE; 00359 rv = FacetModifyEngine::instance()->make_facet_surface(eval_data, 00360 facet_list, 00361 cpoint_list, 00362 copy_loops_on_surface, 00363 interp_order, 00364 min_dot, 00365 surface_copy, 00366 use_point_addresses, 00367 NULL, 00368 &hard_line_curve_map); 00369 if(rv != CUBIT_SUCCESS) 00370 { 00371 PRINT_ERROR("Couldn't copy surfaces"); 00372 return (BodySM *)NULL; 00373 } 00374 00375 old_to_new_map.insert( 00376 std::make_pair( fsurface, surface_copy ) ); 00377 00378 copy_surfaces.append( surface_copy ); 00379 } 00380 00381 // ----------------------copy shells-------------------------- 00382 00383 DLIList<FacetShell*> shell_list; 00384 get_shells(shell_list); 00385 DLIList<ShellSM*> copy_shells; 00386 shell_list.reset(); 00387 ShellSM *shell_ptr, *shell_copy; 00388 FacetShell *fshell; 00389 for (ii=0; ii<shell_list.size(); ii++) 00390 { 00391 fshell = shell_list.get_and_step(); 00392 DLIList<FacetSurface *>surfaces_on_shell; 00393 fshell->get_surfaces(surfaces_on_shell); 00394 DLIList<Surface *>copy_surfaces_on_shell; 00395 00396 // find all associated loops on the surface 00397 00398 for(kk=0; kk<surfaces_on_shell.size(); kk++) 00399 { 00400 int found = 0; 00401 surface_list.reset(); 00402 copy_surfaces.reset(); 00403 Surface *surface_on_shell = surfaces_on_shell.get_and_step(); 00404 for (jj=0; jj<surface_list.size() && !found; jj++) 00405 { 00406 surface_ptr = surface_list.get_and_step(); 00407 surface_copy = copy_surfaces.get_and_step(); 00408 if (surface_on_shell == surface_ptr) 00409 { 00410 found = 1; 00411 copy_surfaces_on_shell.append(surface_copy); 00412 } 00413 } 00414 } 00415 00416 // create the new shell 00417 00418 rv = FacetModifyEngine::instance()->make_facet_shell(copy_surfaces_on_shell, 00419 shell_copy); 00420 if(rv != CUBIT_SUCCESS) 00421 { 00422 PRINT_ERROR("Couldn't copy shell"); 00423 return (BodySM *)NULL; 00424 } 00425 00426 // set the sense of the surfaces on the shell - copy from the old shell 00427 00428 FacetShell *fshell_copy = CAST_TO(shell_copy, FacetShell); 00429 surfaces_on_shell.reset(); 00430 copy_surfaces_on_shell.reset(); 00431 for (kk=0; kk<surfaces_on_shell.size(); kk++) 00432 { 00433 Surface *surface_on_shell = surfaces_on_shell.get_and_step(); 00434 Surface *copy_surface_on_shell = copy_surfaces_on_shell.get_and_step(); 00435 fsurface = CAST_TO( surface_on_shell, FacetSurface ); 00436 CubitSense sense = fsurface->get_shell_sense(fshell); 00437 FacetSurface *copy_fsurface = CAST_TO( copy_surface_on_shell, FacetSurface ); 00438 copy_fsurface->set_shell_sense( fshell_copy, sense ); 00439 } 00440 copy_shells.append( shell_copy ); 00441 } 00442 00443 // ----------------------copy lumps-------------------------- 00444 00445 DLIList<FacetLump*> lump_list; 00446 get_lumps(lump_list); 00447 DLIList<Lump*> copy_lumps; 00448 lump_list.reset(); 00449 Lump *lump_copy; 00450 FacetLump *flump; 00451 for (ii=0; ii<lump_list.size(); ii++) 00452 { 00453 flump = lump_list.get_and_step(); 00454 DLIList<FacetShell *>shells_on_lump; 00455 flump->get_shells(shells_on_lump); 00456 DLIList<ShellSM *>copy_shells_on_lump; 00457 00458 // find all associated loops on the surface 00459 00460 for(kk=0; kk<shells_on_lump.size(); kk++) 00461 { 00462 int found = 0; 00463 shell_list.reset(); 00464 copy_shells.reset(); 00465 ShellSM *shell_on_lump = shells_on_lump.get_and_step(); 00466 for (jj=0; jj<shell_list.size() && !found; jj++) 00467 { 00468 shell_ptr = shell_list.get_and_step(); 00469 shell_copy = copy_shells.get_and_step(); 00470 if (shell_on_lump == shell_ptr) 00471 { 00472 found = 1; 00473 copy_shells_on_lump.append(shell_copy); 00474 } 00475 } 00476 } 00477 00478 // create the new lump 00479 00480 rv = FacetModifyEngine::instance()->make_facet_lump(copy_shells_on_lump, 00481 lump_copy); 00482 if(rv != CUBIT_SUCCESS) 00483 { 00484 PRINT_ERROR("Couldn't copy lump"); 00485 return (BodySM *)NULL; 00486 } 00487 00488 old_to_new_map.insert( 00489 std::make_pair( flump, lump_copy ) ); 00490 00491 copy_lumps.append( lump_copy ); 00492 } 00493 00494 // ----------------------copy body-------------------------- 00495 00496 BodySM *body_copy; 00497 rv = FacetModifyEngine::instance()->make_facet_body(copy_lumps, 00498 body_copy); 00499 if(rv != CUBIT_SUCCESS) 00500 { 00501 PRINT_ERROR("Couldn't copy lump"); 00502 return (BodySM *)NULL; 00503 } 00504 00505 //copy the attributes from old to new 00506 std::map<TopologyBridge*, TopologyBridge*>::iterator iter; 00507 for( iter= old_to_new_map.begin(); iter != old_to_new_map.end(); iter++ ) 00508 { 00509 TopologyBridge *old_tb = iter->first; 00510 TopologyBridge *new_tb = iter->second; 00511 00512 DLIList<CubitSimpleAttrib> old_attribs; 00513 old_tb->get_simple_attribute( old_attribs ); 00514 00515 for( int i=old_attribs.size(); i--; ) 00516 { 00517 const CubitSimpleAttrib& copy = old_attribs.get_and_step(); 00518 new_tb->append_simple_attribute_virt( copy ); 00519 } 00520 } 00521 00522 return (BodySM*)body_copy; 00523 } 00524 //---------------------------------------------------------------- 00525 // Function: can_be_deleted 00526 // Description: determine if the body can be deleted 00527 // 00528 // Author: sjowen 00529 //---------------------------------------------------------------- 00530 CubitBoolean FacetBody::can_be_deleted( DLIList <Body*> &body_list ) 00531 { 00532 CubitBoolean delete_ok = CUBIT_TRUE; 00533 DLIList<FacetSurface *>surf_list; 00534 get_surfaces(surf_list); 00535 int ii; 00536 for (ii=0; ii<surf_list.size() && delete_ok; ii++) 00537 { 00538 FacetSurface *surf_ptr = surf_list.get_and_step(); 00539 DLIList<FacetBody*>my_body_list; 00540 surf_ptr->get_bodies(my_body_list); 00541 int jj; 00542 if (my_body_list.size() >= 2) 00543 { 00544 for (jj=0; jj<my_body_list.size() && delete_ok; jj++) 00545 { 00546 BodySM *my_body_ptr = my_body_list.get_and_step(); 00547 if (my_body_ptr != this) 00548 { 00549 int kk; 00550 int found = 0; 00551 for (kk=0; kk<body_list.size() && !found; kk++) 00552 { 00553 Body *body_ptr = body_list.get_and_step(); 00554 FacetBody* fbody_ptr = CAST_TO(body_ptr->get_body_sm_ptr(), FacetBody); 00555 if (fbody_ptr) 00556 { 00557 if (my_body_ptr == fbody_ptr) 00558 found = 1; 00559 } 00560 } 00561 if (!found) 00562 { 00563 delete_ok = CUBIT_FALSE; 00564 PRINT_ERROR("Body cannot be deleted because it is merged with adjacent Body\n"); 00565 PRINT_INFO(" Mesh Based Geometry entities cannot be unmerged.\n" 00566 " Try using the no_merge option when importing the mesh\n"); 00567 } 00568 } 00569 } 00570 } 00571 } 00572 return delete_ok; 00573 } 00574 00575 //---------------------------------------------------------------- 00576 // Function: move 00577 // Description: translate the body and its child entities 00578 // 00579 // Author: sjowen 00580 //---------------------------------------------------------------- 00581 CubitStatus FacetBody::move(double dx, double dy, double dz) 00582 { 00583 CubitTransformMatrix tfmat; 00584 tfmat.translate( dx, dy, dz ); 00585 00586 CubitStatus stat = transform( tfmat, CUBIT_FALSE ); 00587 00588 if (stat == CUBIT_SUCCESS) 00589 myTransforms.translate( dx, dy, dz ); 00590 00591 return stat; 00592 } 00593 00594 00595 //---------------------------------------------------------------- 00596 // Function: rotate 00597 // Description: rotate the body and its child entities 00598 // 00599 // Author: sjowen 00600 //---------------------------------------------------------------- 00601 CubitStatus FacetBody::rotate( double x, double y, double z, 00602 double angle_in_degrees ) 00603 { 00604 00605 CubitTransformMatrix rotmat; 00606 CubitVector axis( x, y, z ); 00607 rotmat.rotate( angle_in_degrees, axis ); 00608 00609 CubitStatus stat = transform( rotmat, CUBIT_TRUE ); 00610 00611 if (stat == CUBIT_SUCCESS) 00612 myTransforms.rotate( angle_in_degrees, axis ); 00613 00614 return stat; 00615 } 00616 00617 //---------------------------------------------------------------- 00618 // Function: scale 00619 // Description: scale the body and its child entities 00620 // use a constant scale factor 00621 // 00622 // Author: sjowen 00623 //---------------------------------------------------------------- 00624 CubitStatus FacetBody::scale(double scale_factor ) 00625 { 00626 return scale(scale_factor,scale_factor,scale_factor); 00627 } 00628 00629 //---------------------------------------------------------------- 00630 // Function: scale 00631 // Description: scale the body and its child entities 00632 // 00633 // Author: sjowen 00634 //---------------------------------------------------------------- 00635 CubitStatus FacetBody::scale(double scale_factor_x, 00636 double scale_factor_y, 00637 double scale_factor_z ) 00638 { 00639 CubitTransformMatrix scalemat; 00640 scalemat.scale_about_origin( scale_factor_x, 00641 scale_factor_y, 00642 scale_factor_z ); 00643 00644 CubitStatus stat = transform( scalemat, CUBIT_FALSE ); 00645 00646 if (stat == CUBIT_SUCCESS) 00647 myTransforms.scale_about_origin( scale_factor_x, 00648 scale_factor_y, 00649 scale_factor_z ); 00650 00651 // scale the facetcurve 00652 00653 DLIList<FacetCurve *> curve_list; 00654 get_curves(curve_list); 00655 Curve *curv_ptr; 00656 for (int ii=0; ii<curve_list.size(); ii++) 00657 { 00658 curv_ptr = curve_list.get_and_step(); 00659 FacetCurve *fcurve = CAST_TO( curv_ptr, FacetCurve ); 00660 if (fcurve) 00661 { 00662 fcurve->reset_length(); 00663 } 00664 } 00665 00666 return stat; 00667 } 00668 00669 //---------------------------------------------------------------- 00670 // Function: restore 00671 // Description: restore the body and its child entities 00672 // to its original coordinates using the inverse 00673 // transformation matrix 00674 // 00675 // Author: sjowen 00676 //---------------------------------------------------------------- 00677 CubitStatus FacetBody::restore() 00678 { 00679 // invert the transformation matrix and apply to entities 00680 // (assumes an orthogonal matrix (ie. no shear or non-uniform scaling) 00681 00682 CubitTransformMatrix inverse_mat; 00683 inverse_mat = myTransforms.inverse(); 00684 00685 CubitStatus stat = transform( inverse_mat, CUBIT_TRUE ); 00686 00687 if (stat == CUBIT_SUCCESS) 00688 myTransforms.set_to_identity(); 00689 00690 return stat; 00691 } 00692 00693 //---------------------------------------------------------------- 00694 // Function: reflect 00695 // Description: reflect the body about a exis 00696 // 00697 // Author: sjowen 00698 //---------------------------------------------------------------- 00699 CubitStatus FacetBody::reflect( double reflect_axis_x, 00700 double reflect_axis_y, 00701 double reflect_axis_z ) 00702 { 00703 CubitTransformMatrix reflectmat; 00704 CubitVector reflect_vector( reflect_axis_x, 00705 reflect_axis_y, 00706 reflect_axis_z ); 00707 reflectmat.reflect( reflect_vector ); 00708 00709 CubitStatus stat = transform( reflectmat, CUBIT_TRUE ); 00710 00711 if (stat == CUBIT_SUCCESS) 00712 myTransforms.reflect( reflect_vector ); 00713 00714 return stat; 00715 } 00716 00717 //---------------------------------------------------------------- 00718 // Function: transform 00719 // Description: transform the body based on a transformation matrix 00720 // main function for applying transformations to 00721 // facet-based bodies 00722 // 00723 // Author: sjowen 00724 //---------------------------------------------------------------- 00725 CubitStatus FacetBody::transform( CubitTransformMatrix &tfmat, 00726 CubitBoolean is_rotation ) 00727 { 00728 int ii; 00729 00730 // get the list of surfaces on the body 00731 00732 DLIList<FacetSurface *>surf_list; 00733 get_surfaces( surf_list ); 00734 Surface *surf; 00735 FacetSurface *fsurf; 00736 FacetEvalTool *ftool; 00737 //CubitVector min, max; 00738 00739 // go through all the surfaces and collect the list of all points. 00740 // (some may be listed on multiple surfaces) 00741 00742 DLIList<CubitPoint *>point_list; 00743 for (ii=0; ii<surf_list.size(); ii++) 00744 { 00745 surf = surf_list.get_and_step(); 00746 fsurf = CAST_TO( surf, FacetSurface ); 00747 fsurf->get_my_points( point_list ); 00748 } 00749 00750 // unmark all the points so we can keep track of the ones that have 00751 // already been transformed 00752 00753 CubitPoint *cp; 00754 for (ii=0; ii<point_list.size(); ii++) 00755 { 00756 cp = point_list.get_and_step(); 00757 cp->marked( 0 ); 00758 } 00759 00760 // transform the points 00761 00762 //CubitVector norm, du, dv; 00763 for (ii=0; ii<point_list.size(); ii++) 00764 { 00765 cp = point_list.get_and_step(); 00766 if (!cp->marked()) 00767 { 00768 cp->transform( tfmat ); 00769 if (is_rotation) 00770 cp->rotate_normal( tfmat ); 00771 cp->marked( 1 ); 00772 } 00773 } 00774 00775 // check the vertices - make sure they are transformed 00776 00777 FacetPoint *fpt; 00778 TBPoint *pt; 00779 DLIList<FacetPoint*>gpoint_list; 00780 get_points(gpoint_list); 00781 for (ii=0; ii<gpoint_list.size(); ii++) 00782 { 00783 pt = gpoint_list.get_and_step(); 00784 fpt = CAST_TO( pt, FacetPoint ); 00785 00786 // only transform the point if it isn't already part of the facets 00787 // (they could be points by themselves) 00788 00789 cp = fpt->get_cubit_point(); 00790 if (cp->num_adj_facets() == 0) 00791 { 00792 cp->transform( tfmat ); 00793 if (is_rotation) 00794 cp->rotate_normal( tfmat ); 00795 } 00796 } 00797 00798 // reset the bounding box and update the facet normal and plane 00799 00800 // init flags on edges to 0 00801 DLIList<Surface*> tmp_surf_list( surf_list.size() ); 00802 CAST_LIST_TO_PARENT( surf_list, tmp_surf_list ); 00803 init_edge_flags( tmp_surf_list, 0 ); 00804 for (ii=0; ii<surf_list.size(); ii++) 00805 { 00806 surf = surf_list.get_and_step(); 00807 fsurf = CAST_TO( surf, FacetSurface ); 00808 00809 // if we are using a bspline representation, then we also need to 00810 // transform the control points on the edges and facets 00811 00812 ftool = fsurf->get_eval_tool(); 00813 if (ftool->interp_order() == 4) 00814 { 00815 ftool->transform_control_points( tfmat ); 00816 } 00817 00818 DLIList<CubitFacet *>flist; 00819 DLIList<CubitPoint *>plist; 00820 fsurf->get_my_facets( flist, plist); 00821 int jj; 00822 CubitFacet *facet_ptr; 00823 for (jj=0; jj<flist.size(); jj++) 00824 { 00825 facet_ptr = flist.get_and_step(); 00826 facet_ptr->update_plane(); 00827 facet_ptr->reset_bounding_box(); 00828 } 00829 //must be done after facet's are reset... 00830 ftool->reset_bounding_box(); 00831 // if this facet surface has a primitive evaluator, then we need 00832 // to tell it about the transformation also. 00833 fsurf->add_transformation( tfmat ); 00834 00835 //re-calculate the area of the surface in case it changed 00836 fsurf->update_measurement(); 00837 } 00838 init_edge_flags( tmp_surf_list, 0 ); 00839 00840 // Some transforms (those incorporating reflections) 00841 // invert the geometry. Correct for it. 00842 // -- jason k. 00843 if ( tfmat.sub_matrix(3,3).determinant() < 0.0 ) 00844 { 00845 // Flip CoFace senses 00846 DLIList<FacetShell*> shells; 00847 get_shells( shells ); 00848 //modified. mbrewer. doing both a reverse and a 00849 //reverse_surfaces. the latter actually changes the 00850 // underlying surfaces so that the normals can all 00851 // still be outward pointing. It automatically changes 00852 // the sense, therefore we also still need excplicity 00853 // call reverse so that sense is corrected. 00854 while (shells.size()){ 00855 shells.get()->reverse_surfaces(); 00856 shells.pop()->reverse(); 00857 } 00858 } 00859 00860 return CUBIT_SUCCESS; 00861 } 00862 00863 //---------------------------------------------------------------- 00864 // Function: init_edge_flags 00865 // Description: set the flags on the facet edges 00866 // Note: Only done for facet eval tool with order 4 interpolation 00867 // Author: sjowen 00868 //---------------------------------------------------------------- 00869 void FacetBody::init_edge_flags( DLIList<Surface *>&surf_list, 00870 int ) 00871 { 00872 int ii, jj; 00873 Surface *surf; 00874 FacetSurface *fsurf; 00875 FacetEvalTool *ftool; 00876 CubitFacetEdge *edge_ptr; 00877 00878 for (ii=0; ii<surf_list.size(); ii++) 00879 { 00880 DLIList<CubitFacetEdge*>edge_list; 00881 surf = surf_list.get_and_step(); 00882 fsurf = CAST_TO( surf, FacetSurface ); 00883 ftool = fsurf->get_eval_tool(); 00884 if (ftool->interp_order() == 4) 00885 { 00886 ftool->get_edges( edge_list ); 00887 for (jj=0; jj<edge_list.size(); jj++) 00888 { 00889 edge_ptr = edge_list.get_and_step(); 00890 edge_ptr->set_flag( 0 ); 00891 } 00892 } 00893 } 00894 } 00895 00896 CubitStatus FacetBody::get_transforms( CubitTransformMatrix &tfm ) 00897 { 00898 tfm = myTransforms; 00899 return CUBIT_SUCCESS; 00900 } 00901 00902 CubitStatus FacetBody::set_transforms( CubitTransformMatrix tfm ) 00903 { 00904 myTransforms = tfm; 00905 return CUBIT_SUCCESS; 00906 } 00907 00908 int FacetBody::validate(const CubitString &, DLIList <TopologyEntity*>&) 00909 { 00910 PRINT_ERROR("This option is not available for mesh defined geometry.\n"); 00911 return 0; 00912 } 00913 00914 void FacetBody::get_parents_virt( DLIList<TopologyBridge*>& ) 00915 {} 00916 00917 void FacetBody::get_children_virt( DLIList<TopologyBridge*>& lumps ) 00918 { CAST_LIST_TO_PARENT( myLumps, lumps ); } 00919 00920 void FacetBody::get_lumps( DLIList<FacetLump*>& result_list ) 00921 { 00922 myLumps.reset(); 00923 for ( int i = 0; i < myLumps.size(); i++ ) 00924 if ( FacetLump* lump = dynamic_cast<FacetLump*>(myLumps.next(i)) ) 00925 result_list.append(lump); 00926 } 00927 00928 void FacetBody::get_shells( DLIList<FacetShell*>& result_list ) 00929 { 00930 DLIList<FacetLump*> lump_list; 00931 get_lumps( lump_list ); 00932 lump_list.reset(); 00933 for ( int i = 0; i < lump_list.size(); i++ ) 00934 lump_list.next(i)->get_shells( result_list ); 00935 } 00936 00937 void FacetBody::get_surfaces( DLIList<FacetSurface*>& result_list ) 00938 { 00939 DLIList<FacetShell*> shell_list; 00940 DLIList<FacetSurface*> tmp_list; 00941 get_shells(shell_list); 00942 shell_list.reset(); 00943 for ( int i = 0; i < shell_list.size(); i++ ) 00944 { 00945 tmp_list.clean_out(); 00946 shell_list.next(i)->get_surfaces( tmp_list ); 00947 result_list.merge_unique( tmp_list ); 00948 } 00949 } 00950 00951 void FacetBody::get_loops( DLIList<FacetLoop*>& result_list ) 00952 { 00953 DLIList<FacetSurface*> surface_list; 00954 get_surfaces( surface_list ); 00955 surface_list.reset(); 00956 for ( int i = 0; i < surface_list.size(); i++ ) 00957 surface_list.next(i)->get_loops( result_list ); 00958 } 00959 00960 void FacetBody::get_coedges( DLIList<FacetCoEdge*>& result_list ) 00961 { 00962 DLIList<FacetSurface*> surface_list; 00963 get_surfaces( surface_list ); 00964 surface_list.reset(); 00965 for ( int i = 0; i < surface_list.size(); i++ ) 00966 surface_list.next(i)->get_coedges( result_list ); 00967 } 00968 00969 void FacetBody::get_curves( DLIList<FacetCurve*>& result_list ) 00970 { 00971 DLIList<FacetCoEdge*> coedge_list; 00972 get_coedges( coedge_list ); 00973 coedge_list.reset(); 00974 for ( int i = coedge_list.size(); i--; ) 00975 { 00976 FacetCoEdge* coedge = coedge_list.get_and_step(); 00977 FacetCurve* curve = dynamic_cast<FacetCurve*>(coedge->curve()); 00978 if (curve) 00979 result_list.append_unique(curve); 00980 } 00981 } 00982 00983 void FacetBody::get_points( DLIList<FacetPoint*>& result_list ) 00984 { 00985 DLIList<FacetCurve*> curve_list; 00986 get_curves( curve_list ); 00987 curve_list.reset(); 00988 for ( int i = curve_list.size(); i--; ) 00989 { 00990 FacetCurve* curve = curve_list.get_and_step(); 00991 FacetPoint* point = dynamic_cast<FacetPoint*>(curve->start_point()); 00992 if (point) 00993 result_list.append_unique(point); 00994 point = dynamic_cast<FacetPoint*>(curve->end_point()); 00995 if (point) 00996 result_list.append_unique(point); 00997 } 00998 } 00999 01000 void FacetBody::add_lump( FacetLump *lump_to_add ) 01001 { 01002 Lump* lump = dynamic_cast<Lump*>(lump_to_add); 01003 if (lump) 01004 { 01005 lump_to_add->add_body(this); 01006 myLumps.append( lump ); 01007 } 01008 } 01009 01010 void FacetBody::remove_lump( FacetLump *lump_to_remove ) 01011 { 01012 FacetLump* lump = dynamic_cast<FacetLump*>(lump_to_remove); 01013 if (lump) 01014 { 01015 assert(lump_to_remove->get_body() == this); 01016 lump_to_remove->remove_body(); 01017 myLumps.remove( lump ); 01018 } 01019 } 01020 01021 01022 //------------------------------------------------------------------------- 01023 // Purpose : Tear down topology 01024 // 01025 // Special Notes : 01026 // 01027 // Creator : Jason Kraftcheck 01028 // 01029 // Creation Date : 09/29/03 01030 //------------------------------------------------------------------------- 01031 void FacetBody::disconnect_all_lumps() 01032 { 01033 myLumps.reset(); 01034 for (int i = myLumps.size(); i--; ) 01035 { 01036 Lump* sm_ptr = myLumps.get_and_step(); 01037 FacetLump* lump = dynamic_cast<FacetLump*>(sm_ptr); 01038 if (lump) 01039 { 01040 assert(lump->get_body() == this); 01041 lump->remove_body(); 01042 } 01043 } 01044 myLumps.clean_out(); 01045 } 01046 01047 //------------------------------------------------------------------------- 01048 // Purpose : Find centroid 01049 // 01050 // Special Notes : 01051 // 01052 // Creator : Jason Kraftcheck 01053 // 01054 // Creation Date : 05/10/04 01055 //------------------------------------------------------------------------- 01056 CubitStatus FacetBody::mass_properties( CubitVector& centroid, 01057 double& volume ) 01058 { 01059 centroid.set( 0.0, 0.0, 0.0 ); 01060 volume = 0.0; 01061 01062 DLIList<FacetLump*> lumps (myLumps.size()); 01063 CAST_LIST( myLumps, lumps, FacetLump ); 01064 assert( myLumps.size() == lumps.size() ); 01065 for (int i = lumps.size(); i--; ) 01066 { 01067 CubitVector cent; 01068 double vol; 01069 if (CUBIT_SUCCESS != lumps.get_and_step()->mass_properties(cent,vol)) 01070 return CUBIT_FAILURE; 01071 centroid += vol*cent; 01072 volume += vol; 01073 } 01074 if (volume > CUBIT_RESABS) 01075 { 01076 centroid /= volume; 01077 } 01078 else 01079 { 01080 centroid.set( 0.0, 0.0, 0.0 ); 01081 volume = 0.0; 01082 } 01083 01084 return CUBIT_SUCCESS; 01085 } 01086 01087 //------------------------------------------------------------------------- 01088 // Purpose : Used to be FacetQueryEngine::is_point_in_body 01089 // 01090 // Special Notes : 01091 // 01092 // Creator : Jason Kraftcheck 01093 // 01094 // Creation Date : 05/10/04 01095 //------------------------------------------------------------------------- 01096 CubitPointContainment FacetBody::point_containment( const CubitVector &point, double tolerance ) 01097 { 01098 CubitPointContainment pc_value; 01099 FacetLump *facet_lump; 01100 01101 int i; 01102 for(i=myLumps.size(); i--;) 01103 { 01104 facet_lump = dynamic_cast<FacetLump*>(myLumps.get_and_step()); 01105 pc_value = facet_lump->point_containment( point, tolerance ); 01106 if( pc_value == CUBIT_PNT_INSIDE ) 01107 return CUBIT_PNT_INSIDE; 01108 else if( pc_value == CUBIT_PNT_BOUNDARY ) 01109 return CUBIT_PNT_BOUNDARY; 01110 } 01111 01112 return CUBIT_PNT_OUTSIDE; 01113 } 01114 01115