cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : FacetSurface.cpp 00003 // 00004 // Purpose : 00005 // 00006 // Special Notes : 00007 // 00008 // Creator : David R. White 00009 // 00010 // Creation Date : 06/06/00 00011 // 00012 // Owner : David R. White 00013 //------------------------------------------------------------------------- 00014 #include "CubitSimpleAttrib.hpp" 00015 #include "CubitVector.hpp" 00016 #include "GeometryDefines.h" 00017 #include "FacetSurface.hpp" 00018 #include "RefFace.hpp" 00019 #include "FacetQueryEngine.hpp" 00020 #include "FacetAttrib.hpp" 00021 00022 #include "CubitUtil.hpp" 00023 #include "CastTo.hpp" 00024 #include "RefVolume.hpp" 00025 #include "GeometryQueryEngine.hpp" 00026 #include "DLIList.hpp" 00027 #include "FacetEvalTool.hpp" 00028 #include "ShellSM.hpp" 00029 #include "Lump.hpp" 00030 #include "LoopSM.hpp" 00031 #include "CubitPointData.hpp" 00032 #include "CubitFacetData.hpp" 00033 #include "CubitFacetEdge.hpp" 00034 #include "FacetBody.hpp" 00035 #include "FacetLump.hpp" 00036 #include "FacetShell.hpp" 00037 #include "FacetLoop.hpp" 00038 #include "FacetCoEdge.hpp" 00039 #include "FacetCurve.hpp" 00040 #include "FacetPoint.hpp" 00041 #include "CubitEvaluator.hpp" 00042 #include "SphereEvaluator.hpp" 00043 #include "CylinderEvaluator.hpp" 00044 00045 #include <map> 00046 #include "GfxDebug.hpp" 00047 // ********** END CUBIT INCLUDES ********** 00048 00049 // ********** BEGIN STATIC DECLARATIONS ********** 00050 // ********** END STATIC DECLARATIONS ********** 00051 00052 // ********** BEGIN PUBLIC FUNCTIONS ********** 00053 //------------------------------------------------------------------------- 00054 // Purpose : The constructor with a pointer to the FacetEvalTool. 00055 // 00056 // Special Notes : 00057 // 00058 //------------------------------------------------------------------------- 00059 FacetSurface::FacetSurface(FacetEvalTool *facet_tool, 00060 DLIList<ShellSM*> &shellsms, 00061 DLIList<LoopSM*> &loopsms) 00062 { 00063 // Calculate a bounding box if there isn't one already 00064 facetEvalTool = facet_tool; 00065 //sense_ = CUBIT_FORWARD; 00066 myShells += shellsms; 00067 myLoops += loopsms; 00068 myShellSense = CUBIT_UNKNOWN; 00069 myEvaluator = NULL; 00070 } 00071 00072 //------------------------------------------------------------------------- 00073 // Purpose : The constructor with a pointer to the FacetEvalTool. 00074 // 00075 // Special Notes : Used for save/restore 00076 // 00077 //------------------------------------------------------------------------- 00078 FacetSurface::FacetSurface( const SphereEvaluatorData *sphere_data, 00079 FacetEvalTool *facet_tool, 00080 DLIList<ShellSM*> &shellsms, 00081 DLIList<LoopSM*> &loopsms ) 00082 { 00083 facetEvalTool = facet_tool; 00084 //sense_ = CUBIT_FORWARD; 00085 myShells += shellsms; 00086 myLoops += loopsms; 00087 myShellSense = CUBIT_UNKNOWN; 00088 00089 myEvaluator = new SphereEvaluator( sphere_data ); 00090 } 00091 //------------------------------------------------------------------------- 00092 // Purpose : The constructor with a pointer to the FacetEvalTool. 00093 // 00094 // Special Notes : Used for save/restore 00095 // 00096 //------------------------------------------------------------------------- 00097 FacetSurface::FacetSurface( const CylinderEvaluatorData *cylinder_data, 00098 FacetEvalTool *facet_tool, 00099 DLIList<ShellSM*> &shellsms, 00100 DLIList<LoopSM*> &loopsms ) 00101 { 00102 facetEvalTool = facet_tool; 00103 //sense_ = CUBIT_FORWARD; 00104 myShells += shellsms; 00105 myLoops += loopsms; 00106 myShellSense = CUBIT_UNKNOWN; 00107 00108 myEvaluator = new CylinderEvaluator( cylinder_data ); 00109 } 00110 00111 //------------------------------------------------------------------------- 00112 // Purpose : The constructor with a pointer to the FacetEvalTool. 00113 // 00114 // Special Notes : Used for save/restore 00115 // 00116 //------------------------------------------------------------------------- 00117 FacetSurface::FacetSurface(FacetEvalTool *facet_tool, 00118 CubitSense sense, 00119 CubitSense shell_sense0, 00120 CubitBoolean use_facets, 00121 DLIList<LoopSM*> &loopsms) 00122 { 00123 // Calculate a bounding box if there isn't one already 00124 facetEvalTool = facet_tool; 00125 //sense_ = CUBIT_FORWARD; 00126 myLoops += loopsms; 00127 myShellSense = shell_sense0; 00128 myEvaluator = NULL; 00129 } 00130 //------------------------------------------------------------------------- 00131 // Purpose : The default destructor. 00132 // 00133 // Special Notes : 00134 // 00135 //------------------------------------------------------------------------- 00136 FacetSurface::~FacetSurface() 00137 { 00138 if ( facetEvalTool ) 00139 { 00140 delete facetEvalTool; 00141 } 00142 if ( myEvaluator ) 00143 { 00144 delete myEvaluator; 00145 } 00146 } 00147 00148 00149 //------------------------------------------------------------------------- 00150 // Purpose : get the interpolation order of the FacetEvalTool 00151 // 00152 // Special Notes : 00153 // 00154 //------------------------------------------------------------------------- 00155 int FacetSurface::interp_order() 00156 { 00157 assert(facetEvalTool != NULL); 00158 00159 return facetEvalTool->interp_order(); 00160 } 00161 00162 //------------------------------------------------------------------------- 00163 // Purpose : get the min dot of the FacetEvalTool 00164 // 00165 // Special Notes : 00166 // 00167 //------------------------------------------------------------------------- 00168 double FacetSurface::min_dot() 00169 { 00170 assert(facetEvalTool != NULL); 00171 00172 return facetEvalTool->get_min_dot(); 00173 } 00174 00175 //------------------------------------------------------------------------- 00176 // Purpose : The purpose of this function is to append a 00177 // attribute to the GE. The name is attached to the 00178 // underlying solid model entity this one points to. 00179 // 00180 // 00181 // Special Notes : 00182 // 00183 //------------------------------------------------------------------------- 00184 void FacetSurface::append_simple_attribute_virt(const CubitSimpleAttrib &csa) 00185 { attribSet.append_attribute(csa); } 00186 00187 //------------------------------------------------------------------------- 00188 // Purpose : The purpose of this function is to remove a simple 00189 // attribute attached to this geometry entity. The name is 00190 // removed from the underlying BODY this points to. 00191 // 00192 // Special Notes : 00193 // 00194 //------------------------------------------------------------------------- 00195 void FacetSurface::remove_simple_attribute_virt(const CubitSimpleAttrib &csa) 00196 { attribSet.remove_attribute( csa ); } 00197 00198 //------------------------------------------------------------------------- 00199 // Purpose : The purpose of this function is to remove all simple 00200 // attributes attached to this geometry entity. Also 00201 // removes lingering GTC attributes. 00202 // 00203 // 00204 // Special Notes : 00205 // 00206 //------------------------------------------------------------------------- 00207 void FacetSurface::remove_all_simple_attribute_virt() 00208 { attribSet.remove_all_attributes(); } 00209 00210 //------------------------------------------------------------------------- 00211 // Purpose : The purpose of this function is to get the 00212 // attributes attached to this geometry entity. The name is 00213 // attached to the underlying BODY this points to. 00214 // 00215 // Special Notes : 00216 // 00217 //------------------------------------------------------------------------- 00218 CubitStatus FacetSurface::get_simple_attribute(DLIList<CubitSimpleAttrib>& 00219 csa_list) 00220 { return attribSet.get_attributes(csa_list); } 00221 CubitStatus FacetSurface::get_simple_attribute(const CubitString& name, 00222 DLIList<CubitSimpleAttrib>& csa_list ) 00223 { return attribSet.get_attributes( name, csa_list ); } 00224 00225 CubitStatus FacetSurface::save_attribs( FILE *file_ptr ) 00226 { return attribSet.save_attributes(file_ptr); } 00227 00228 CubitStatus FacetSurface::restore_attribs( FILE *file_ptr, unsigned int endian ) 00229 { return attribSet.restore_attributes( file_ptr, endian ); } 00230 00231 00232 //------------------------------------------------------------------------- 00233 // Purpose : Get geometry modeling engine: FacetQueryEngine 00234 // 00235 // Special Notes : 00236 // 00237 //------------------------------------------------------------------------- 00238 GeometryQueryEngine* 00239 FacetSurface::get_geometry_query_engine() const 00240 { 00241 return FacetQueryEngine::instance(); 00242 } 00243 00244 //------------------------------------------------------------------------- 00245 // Purpose : Get the bounding box of the object. 00246 // 00247 // Special Notes : 00248 // 00249 //------------------------------------------------------------------------- 00250 CubitBox FacetSurface::bounding_box() const 00251 { 00252 if ( myEvaluator ) 00253 return myEvaluator->bounding_box(); 00254 else 00255 return facetEvalTool->bounding_box(); 00256 } 00257 00258 00259 CubitStatus FacetSurface::get_point_normal( CubitVector& location, 00260 CubitVector& normal ) 00261 { 00262 return closest_point( location, NULL, &normal ); 00263 } 00264 00265 CubitStatus FacetSurface::closest_point_uv_guess( 00266 CubitVector const& location, 00267 double& , double& , 00268 CubitVector* closest_location, 00269 CubitVector* unit_normal ) 00270 { 00271 // don't use u and v guesses 00272 return closest_point(location, closest_location, unit_normal); 00273 } 00274 00275 00276 //------------------------------------------------------------------------- 00277 // Purpose : Computes the closest_point on the surface to the input 00278 // location. Optionally, it also computes and returns 00279 // the normal to the surface and the principal curvatures 00280 // at closest_location. 00281 // 00282 //------------------------------------------------------------------------- 00283 CubitStatus FacetSurface::closest_point( CubitVector const& location, 00284 CubitVector* closest_location, 00285 CubitVector* unit_normal_ptr, 00286 CubitVector* curvature1_ptr, 00287 CubitVector* curvature2_ptr) 00288 { 00289 CubitStatus rv = CUBIT_SUCCESS; 00290 if ( myEvaluator ) 00291 return myEvaluator->closest_point( location, 00292 closest_location, 00293 unit_normal_ptr, 00294 curvature1_ptr, 00295 curvature2_ptr ); 00296 00297 // Only need to compute the closest location 00298 if (unit_normal_ptr == NULL && 00299 curvature1_ptr == NULL && 00300 curvature2_ptr == NULL) 00301 { 00302 CubitVector temp = location; 00303 rv=facetEvalTool->closest_point( temp, 00304 closest_location, NULL ); 00305 if(!rv){ 00306 return rv; 00307 } 00308 } 00309 00310 // Need to compute the closest location and the normal, but not the 00311 // curvatures 00312 else if ( (unit_normal_ptr != NULL) && 00313 (curvature1_ptr == NULL && curvature2_ptr == NULL) ) 00314 { 00315 CubitVector temp = location; 00316 rv =facetEvalTool->closest_point( temp, closest_location, unit_normal_ptr); 00317 if(!rv){ 00318 return rv; 00319 } 00320 // if ( get_relative_surface_sense() == CUBIT_REVERSED ) 00321 // { 00322 // *unit_normal_ptr = -1.0*(*unit_normal_ptr); 00323 // } 00324 } 00325 else 00326 { 00327 PRINT_ERROR("Faceted geometry currently doesn't support curvature requests.\n"); 00328 return CUBIT_FAILURE; 00329 } 00330 00331 return CUBIT_SUCCESS; 00332 } 00333 00334 00335 00336 CubitStatus FacetSurface::closest_point_along_vector(CubitVector& from_point, 00337 CubitVector& along_vector, 00338 CubitVector& point_on_surface) 00339 { 00340 CubitVector other_point = from_point+along_vector; 00341 DLIList<CubitVector*> intersection_list; 00342 facetEvalTool->get_intersections( from_point, other_point, intersection_list ); 00343 00344 if( intersection_list.size() == 0 ) 00345 return CUBIT_FAILURE; 00346 00347 if( intersection_list.size() == 1 ) 00348 { 00349 point_on_surface = *intersection_list.get(); 00350 delete intersection_list.get(); 00351 return CUBIT_SUCCESS; 00352 } 00353 00354 //get the closest intersection 00355 double closest_dist_sq = CUBIT_DBL_MAX; 00356 for( int k=intersection_list.size(); k--; ) 00357 { 00358 CubitVector *int_pt = intersection_list.get_and_step(); 00359 00360 double tmp_dist_sq = from_point.distance_between_squared( *int_pt ); 00361 00362 if( tmp_dist_sq < closest_dist_sq ) 00363 { 00364 point_on_surface = *int_pt; 00365 closest_dist_sq = tmp_dist_sq; 00366 } 00367 00368 delete int_pt; 00369 } 00370 00371 return CUBIT_SUCCESS; 00372 } 00373 00374 00375 00376 //------------------------------------------------------------------------- 00377 // Purpose : Computes the closest_point on the trimmed surface to the 00378 // input location. 00379 // 00380 // Special Notes : 00381 //------------------------------------------------------------------------- 00382 void FacetSurface::closest_point_trimmed( CubitVector from_point, 00383 CubitVector& point_on_surface) 00384 { 00385 CubitBoolean on_surf; 00386 facetEvalTool->closest_point_trimmed( from_point, &point_on_surface, 00387 on_surf); 00388 return; 00389 } 00390 00391 //------------------------------------------------------------------------- 00392 // Purpose : This functions computes the point on the surface that is 00393 // closest to the input location and then calculates the 00394 // magnitudes of the principal curvatures at this (possibly, 00395 // new) point on the surface. Specifying the RefVolume for 00396 // reference is optional. 00397 // 00398 // Special Notes : 00399 // 00400 //------------------------------------------------------------------------- 00401 CubitStatus FacetSurface::principal_curvatures( 00402 CubitVector const& location, 00403 double& curvature_1, 00404 double& curvature_2, 00405 CubitVector* closest_location ) 00406 { 00407 if ( myEvaluator ) 00408 { 00409 return myEvaluator->principal_curvatures( location, 00410 curvature_1, 00411 curvature_2, 00412 closest_location ); 00413 } 00414 00415 PRINT_ERROR("Faceted geometry currently does not support curvature requests.\n"); 00416 return CUBIT_FAILURE; 00417 } 00418 00419 00420 00421 CubitStatus FacetSurface::evaluate( double u, double v, 00422 CubitVector *position, 00423 CubitVector *normal, 00424 CubitVector *curvature1, 00425 CubitVector *curvature2 ) 00426 { 00427 return CUBIT_FAILURE; 00428 } 00429 00430 00431 //------------------------------------------------------------------------- 00432 // Purpose : Given values of the two parameters, get the position. 00433 // 00434 // Special Notes : 00435 // 00436 //------------------------------------------------------------------------- 00437 CubitVector FacetSurface::position_from_u_v (double u, double v) 00438 { 00439 if ( myEvaluator ) 00440 return myEvaluator->position_from_u_v( u, v ); 00441 00442 PRINT_ERROR("Faceted geometry currently does not support u-v parameterization.\n"); 00443 return CubitVector (0,0,0); 00444 } 00445 00446 //------------------------------------------------------------------------- 00447 // Purpose : This function returns the {u, v} coordinates of the point 00448 // on the Surface closest to the input point (specified in 00449 // global space). The closest_location is also returned. 00450 // 00451 // Special Notes : 00452 // 00453 //------------------------------------------------------------------------- 00454 CubitStatus FacetSurface::u_v_from_position( CubitVector const& location, 00455 double& u, 00456 double& v, 00457 CubitVector* closest_location ) 00458 { 00459 if ( myEvaluator ) 00460 return myEvaluator->u_v_from_position( location, u, v, closest_location ); 00461 00462 PRINT_ERROR("Faceted geometry currently does not support u-v parameterization.\n"); 00463 return CUBIT_FAILURE; 00464 } 00465 00466 //------------------------------------------------------------------------- 00467 // Purpose : Determines whether the Facet surface is periodic. Not 00468 // available yet. 00469 // 00470 // 00471 //------------------------------------------------------------------------- 00472 CubitBoolean FacetSurface::is_periodic() 00473 { 00474 if ( myEvaluator ) 00475 return myEvaluator->is_periodic(); 00476 00477 //I'm sure we can do something later to calculate this. But for now... 00478 //PRINT_ERROR("FacetSurface::is_periodic not implemented yet\n"); 00479 return CUBIT_FALSE; 00480 00481 } 00482 00483 //------------------------------------------------------------------------- 00484 // Purpose : Determines if the face is periodic in the given parameter 00485 // direction. Not available yet. 00486 // 00487 //------------------------------------------------------------------------- 00488 CubitBoolean FacetSurface::is_periodic_in_U( double& period ) 00489 { 00490 if ( myEvaluator ) 00491 return myEvaluator->is_periodic_in_U( period ); 00492 00493 //PRINT_ERROR("FacetSurface::is_periodic_in_U not implemented yet\n"); 00494 return CUBIT_FALSE; 00495 } 00496 00497 //------------------------------------------------------------------------- 00498 // Purpose : Determines if the face is periodic in the given parameter 00499 // direction. Not available yet. 00500 // 00501 // 00502 //------------------------------------------------------------------------- 00503 CubitBoolean FacetSurface::is_periodic_in_V( double& period ) 00504 { 00505 if ( myEvaluator ) 00506 return myEvaluator->is_periodic_in_V( period ); 00507 00508 //PRINT_ERROR("FacetSurface::is_periodic_in_V not implemented yet\n"); 00509 return CUBIT_FALSE; 00510 } 00511 00512 //------------------------------------------------------------------------- 00513 // Purpose : Determines if the face is singular in the given parameter 00514 // direction. Not available yet. 00515 // 00516 //------------------------------------------------------------------------- 00517 CubitBoolean FacetSurface::is_singular_in_U( double ) 00518 { 00519 if ( myEvaluator ) 00520 return myEvaluator->is_singular_in_U(); 00521 00522 //PRINT_ERROR("FacetSurface::is_singular_in_U not implemented yet\n"); 00523 return CUBIT_FALSE; 00524 } 00525 00526 //------------------------------------------------------------------------- 00527 // Purpose : Determines if the face is singular in the given parameter 00528 // direction. Not available yet. 00529 //------------------------------------------------------------------------- 00530 CubitBoolean FacetSurface::is_singular_in_V( double ) 00531 { 00532 if ( myEvaluator ) 00533 return myEvaluator->is_singular_in_V(); 00534 00535 //PRINT_ERROR("FacetSurface::is_singular_in_V not implemented yet\n"); 00536 return CUBIT_FALSE; 00537 } 00538 00539 //------------------------------------------------------------------------- 00540 // Purpose : Determines if the face is closed in the U parameter. 00541 // 00542 //------------------------------------------------------------------------- 00543 CubitBoolean FacetSurface::is_closed_in_U() 00544 { 00545 if ( myEvaluator ) 00546 return myEvaluator->is_closed_in_U(); 00547 00548 //PRINT_ERROR("FacetSurface::is_closed_in_U not implemented yet\n"); 00549 return CUBIT_FALSE; 00550 } 00551 00552 //------------------------------------------------------------------------- 00553 // Purpose : Determines if the face is closed in the V parameter. 00554 //------------------------------------------------------------------------- 00555 CubitBoolean FacetSurface::is_closed_in_V() 00556 { 00557 if ( myEvaluator ) 00558 return myEvaluator->is_closed_in_V(); 00559 00560 //PRINT_ERROR("FacetSurface::is_closed_in_V not implemented yet\n"); 00561 return CUBIT_FALSE; 00562 } 00563 00564 //------------------------------------------------------------------------- 00565 // Purpose : Calculates the derivitives at a given parameter location. 00566 // 00567 //------------------------------------------------------------------------- 00568 CubitStatus FacetSurface::uv_derivitives( double , 00569 double , 00570 CubitVector &, 00571 CubitVector & ) 00572 { 00573 PRINT_ERROR("Derivitives on a surface not supported on faceted geometry yet.\n"); 00574 return CUBIT_FAILURE; 00575 } 00576 00577 //------------------------------------------------------------------------- 00578 // Purpose : Determines whether the surface is parametrically defined. 00579 // Hopefully later this will be available. 00580 // 00581 //------------------------------------------------------------------------- 00582 CubitBoolean FacetSurface::is_parametric() 00583 { 00584 if ( myEvaluator ) 00585 { 00586 return myEvaluator->is_parametric(); 00587 } 00588 00589 //PRINT_ERROR("FacetSurface::is_parametric not implemented\n"); 00590 return CUBIT_FALSE; 00591 } 00592 00593 //------------------------------------------------------------------------- 00594 // Purpose : Returns the lower and upper parametric bounds of the 00595 // surface in U, if it is parametric. Otherwise, it returns 00596 // CUBIT_FALSE and zeroes for the upper and lower parametric 00597 // bounds. 00598 // 00599 // Creator : Malcolm J. Panthaki 00600 // 00601 // Creation Date : 12/17/96 00602 //------------------------------------------------------------------------- 00603 CubitBoolean FacetSurface::get_param_range_U( double& lower_bound, 00604 double& upper_bound ) 00605 { 00606 if ( myEvaluator ) 00607 return myEvaluator->get_param_range_U( lower_bound, upper_bound ); 00608 00609 lower_bound = 0.0; 00610 upper_bound = 1.0; 00611 //PRINT_ERROR("FacetSurface::get_param_range_U not implemented\n"); 00612 return CUBIT_FALSE; 00613 } 00614 00615 //------------------------------------------------------------------------- 00616 // Purpose : Returns the lower and upper parametric bounds of the 00617 // surface in V, if it is parametric. Otherwise, it returns 00618 // CUBIT_FALSE and zeroes for the upper and lower parametric 00619 // bounds. 00620 // 00621 //------------------------------------------------------------------------- 00622 CubitBoolean FacetSurface::get_param_range_V( double& lower_bound, 00623 double& upper_bound ) 00624 { 00625 if ( myEvaluator ) 00626 return myEvaluator->get_param_range_V( lower_bound, upper_bound ); 00627 00628 lower_bound = 0.0; 00629 upper_bound = 1.0; 00630 //PRINT_ERROR("FacetSurface::get_param_range_V not implemented\n"); 00631 return CUBIT_FALSE; 00632 } 00633 00634 //------------------------------------------------------------------------- 00635 // Purpose : Returns a surface type ID 00636 // 00637 //------------------------------------------------------------------------- 00638 GeometryType FacetSurface::geometry_type() 00639 { 00640 if ( is_flat() ) 00641 { 00642 return PLANE_SURFACE_TYPE; 00643 } 00644 else if ( is_spherical() ) 00645 { 00646 return SPHERE_SURFACE_TYPE; 00647 } 00648 else if ( is_conical() ) 00649 { 00650 return CONE_SURFACE_TYPE; 00651 } 00652 else 00653 { 00654 return FACET_SURFACE_TYPE; 00655 } 00656 } 00657 00658 //------------------------------------------------------------------------- 00659 // Purpose : Returns the area of the Surface 00660 // 00661 //------------------------------------------------------------------------- 00662 double FacetSurface::measure() 00663 { 00664 return facetEvalTool->area(); 00665 } 00666 00667 //------------------------------------------------------------------------- 00668 // Purpose : Updates the (cached) area of the Surface so that if 00669 // measure() is called, the correct value is returned. 00670 //------------------------------------------------------------------------- 00671 void FacetSurface::update_measurement() 00672 { 00673 facetEvalTool->calculate_area(); 00674 } 00675 00676 //------------------------------------------------------------------------- 00677 // Purpose : Returns whether the facet surface is completely flat 00678 // 00679 //------------------------------------------------------------------------- 00680 CubitBoolean FacetSurface::is_flat() 00681 { 00682 return (facetEvalTool->is_flat() == 1) ? CUBIT_TRUE : CUBIT_FALSE; 00683 } 00684 00685 //------------------------------------------------------------------------- 00686 // Purpose : Returns whether the facet surface is spherical 00687 // 00688 //------------------------------------------------------------------------- 00689 CubitBoolean FacetSurface::is_spherical() 00690 { 00691 if ( myEvaluator && myEvaluator->ask_type() == SPHERE_SURFACE_TYPE ) 00692 { 00693 return CUBIT_TRUE; 00694 } 00695 return CUBIT_FALSE; 00696 } 00697 00698 //------------------------------------------------------------------------- 00699 // Purpose : Returns whether the facet surface is spherical 00700 // 00701 //------------------------------------------------------------------------- 00702 CubitBoolean FacetSurface::is_conical() 00703 { 00704 if ( myEvaluator && myEvaluator->ask_type() == CONE_SURFACE_TYPE ) 00705 { 00706 return CUBIT_TRUE; 00707 } 00708 return CUBIT_FALSE; 00709 } 00710 00711 const CubitEvaluatorData *FacetSurface::evaluator_data( void ) 00712 { 00713 if ( myEvaluator ) 00714 { 00715 return myEvaluator->evaluator_data(); 00716 } 00717 return NULL; 00718 } 00719 00720 //------------------------------------------------------------------------- 00721 // Purpose : This function tests the passed in position to see if 00722 // is on the underlying surface. 00723 // 00724 //------------------------------------------------------------------------- 00725 CubitBoolean FacetSurface::is_position_on( CubitVector &test_position ) 00726 { 00727 CubitVector new_point; 00728 CubitStatus stat = closest_point(test_position, &new_point, NULL,NULL,NULL); 00729 if ( !stat ) 00730 return CUBIT_FALSE; 00731 CubitVector result_vec = test_position - new_point; 00732 if ( result_vec.length_squared() < GEOMETRY_RESABS ) 00733 return CUBIT_TRUE; 00734 return CUBIT_FALSE; 00735 } 00736 CubitPointContainment FacetSurface::point_containment( const CubitVector &/*point*/ ) 00737 { 00738 return CUBIT_PNT_UNKNOWN; 00739 } 00740 CubitPointContainment FacetSurface::point_containment( double /*u_param*/, 00741 double /*v_param*/ ) 00742 { 00743 return CUBIT_PNT_UNKNOWN; 00744 } 00745 //CubitPointContainment FacetSurface::point_containment( const CubitVector &/*point*/, 00746 // double /*u_param*/, 00747 // double /*v_param*/ ) 00748 //{ 00749 // return CUBIT_PNT_UNKNOWN; 00750 //} 00751 CubitSense FacetSurface::get_geometry_sense() 00752 { 00753 //not sure if this is right for the facet surface... 00754 CubitSense sense = CUBIT_FORWARD;//get_relative_surface_sense(); 00755 return sense; 00756 } 00757 // CubitSense FacetSurface::get_relative_surface_sense() 00758 // { 00759 // //not sure if this is right for the facet surface... 00760 // return sense_; 00761 // } 00762 00763 /* 00764 00765 void FacetSurface::bodysms(DLIList<BodySM*> &bodies) 00766 { 00767 int ii; 00768 for ( ii = myShells.size(); ii > 0; ii-- ) 00769 { 00770 myShells.get_and_step()->bodysms(bodies); 00771 } 00772 } 00773 00774 void FacetSurface::lumps(DLIList<Lump*> &lumps) 00775 { 00776 int ii; 00777 for ( ii = myShells.size(); ii > 0; ii-- ) 00778 { 00779 myShells.get_and_step()->lumps(lumps); 00780 } 00781 } 00782 00783 void FacetSurface::shellsms(DLIList<ShellSM*> &shellsms) 00784 { 00785 int ii; 00786 for ( ii = myShells.size(); ii > 0; ii-- ) 00787 { 00788 shellsms.append_unique(myShells.get_and_step()); 00789 } 00790 } 00791 00792 void FacetSurface::surfaces(DLIList<Surface*> &surfaces) 00793 { 00794 surfaces.append_unique(this); 00795 } 00796 00797 void FacetSurface::loopsms(DLIList<LoopSM*> &loopsms) 00798 { 00799 int ii; 00800 for ( ii = myLoops.size(); ii > 0; ii-- ) 00801 { 00802 loopsms.append_unique(myLoops.get_and_step()); 00803 } 00804 } 00805 void FacetSurface::coedgesms(DLIList<CoEdgeSM*> &coedgesms) 00806 { 00807 int ii; 00808 for ( ii = myLoops.size(); ii > 0; ii-- ) 00809 { 00810 myLoops.get_and_step()->coedgesms(coedgesms); 00811 } 00812 } 00813 00814 void FacetSurface::curves(DLIList<Curve*> &curves) 00815 { 00816 int ii; 00817 for ( ii = myLoops.size(); ii > 0; ii-- ) 00818 { 00819 myLoops.get_and_step()->curves(curves); 00820 } 00821 } 00822 void FacetSurface::points(DLIList<Point*> &points) 00823 { 00824 int ii; 00825 for ( ii = myLoops.size(); ii > 0; ii-- ) 00826 { 00827 myLoops.get_and_step()->points(points); 00828 } 00829 } 00830 */ 00831 00832 00833 void FacetSurface::get_parents_virt( DLIList<TopologyBridge*>& parents ) 00834 { CAST_LIST_TO_PARENT( myShells, parents ); } 00835 void FacetSurface::get_children_virt( DLIList<TopologyBridge*>& children ) 00836 { CAST_LIST_TO_PARENT( myLoops, children ); } 00837 00838 00839 00840 CubitStatus FacetSurface::get_my_facets(DLIList<CubitFacet*> &facet_list, 00841 DLIList<CubitPoint*>& point_list) 00842 { 00843 facetEvalTool->get_facets(facet_list); 00844 facetEvalTool->get_points(point_list); 00845 return CUBIT_SUCCESS; 00846 } 00847 00848 void FacetSurface::tris(DLIList<CubitFacet *> &facet_list) 00849 { 00850 facetEvalTool->get_facets(facet_list); 00851 } 00852 00853 void FacetSurface::get_my_points(DLIList<CubitPoint*> &point_list) 00854 { 00855 facetEvalTool->get_points(point_list); 00856 } 00857 00858 void FacetSurface::get_my_facetedges(DLIList<CubitFacetEdge*> &edge_list) 00859 { 00860 facetEvalTool->get_edges(edge_list); 00861 } 00862 00863 void FacetSurface::get_shell_sense( CubitSense &sense0) 00864 { 00865 sense0 = myShellSense; 00866 } 00867 00868 00869 // return the sense with respect to the given shell 00870 CubitSense FacetSurface::get_shell_sense( ShellSM* shell_ptr ) const 00871 { 00872 // work around non-constness of DLIList functions 00873 FacetSurface* nonconst = const_cast<FacetSurface*>(this); 00874 00875 int idx = nonconst->myShells.get_index(); 00876 if(idx > 0){ 00877 PRINT_ERROR("Muliple shells attached to surface.\n"); 00878 return CUBIT_UNKNOWN; 00879 } 00880 ShellSM *ashell = myShells.get(); 00881 if (ashell == shell_ptr) 00882 { 00883 return myShellSense; 00884 } 00885 // else 00886 // { 00887 // nonconst->myShells.step(); 00888 // idx = nonconst->myShells.get_index(); 00889 // ashell = myShells.get(); 00890 // if (ashell == shell_ptr) 00891 // { 00892 // return myShellSense[idx]; 00893 // } 00894 // } 00895 return CUBIT_UNKNOWN; 00896 } 00897 00898 // set the sense of the surface with respect to the shell 00899 void FacetSurface::set_shell_sense( FacetShell *facet_shell, 00900 CubitSense thesense ) 00901 { 00902 // if(thesense == CUBIT_REVERSED){ 00903 // PRINT_INFO("should not do this."); 00904 // } 00905 int idx = myShells.get_index(); 00906 if(idx > 0){ 00907 PRINT_ERROR("Multiple shells attached to a single surface.\n"); 00908 return; 00909 } 00910 ShellSM *shell_ptr = (ShellSM *)facet_shell; 00911 ShellSM *ashell = myShells.get(); 00912 if (ashell == shell_ptr) 00913 { 00914 myShellSense = thesense; 00915 } 00916 // else 00917 // { 00918 // myShells.step(); 00919 // idx = myShells.get_index(); 00920 // ashell = myShells.get(); 00921 // if (ashell == shell_ptr) 00922 // { 00923 // myShellSense[idx] = thesense; 00924 // } 00925 // } 00926 } 00927 00928 //---------------------------------------------------------------- 00929 // Function: copy_facets 00930 // Description: copy the points and facets 00931 // 00932 // Author: sjowen 00933 //---------------------------------------------------------------- 00934 CubitStatus FacetSurface::copy_facets(DLIList<CubitFacet*>©_facet_list, 00935 DLIList<CubitPoint*>©_point_list, 00936 std::map<CubitPoint*, CubitPoint*>&old_to_new_cubit_pts) 00937 { 00938 if (!facetEvalTool) 00939 { 00940 PRINT_ERROR("Couldn't copy facets."); 00941 return CUBIT_FAILURE; 00942 } 00943 int ii; 00944 DLIList<CubitFacet*>facet_list; 00945 DLIList<CubitPoint*>point_list; 00946 facetEvalTool->get_facets( facet_list ); 00947 facetEvalTool->get_points( point_list ); 00948 CubitPoint **point_array = new CubitPoint* [point_list.size()]; 00949 00950 //- copy the points 00951 std::map<CubitPoint*, CubitPoint*>::iterator iter; 00952 point_list.reset(); 00953 CubitPoint *new_point, *the_point; 00954 for(ii=0; ii<point_list.size(); ii++) 00955 { 00956 the_point = point_list.get_and_step(); 00957 00958 iter = old_to_new_cubit_pts.find( the_point ); 00959 if( old_to_new_cubit_pts.end() == iter ) 00960 { 00961 new_point = new CubitPointData( the_point->coordinates() ); 00962 copy_point_list.append( new_point ); 00963 point_array[ii] = new_point; 00964 old_to_new_cubit_pts.insert( std::make_pair( the_point, new_point) ); 00965 } 00966 else 00967 { 00968 point_array[ii] = iter->second; 00969 copy_point_list.append( iter->second ); 00970 } 00971 00972 the_point->marked( ii ); 00973 } 00974 00975 //- copy the facets 00976 00977 int jj, idx; 00978 CubitFacet *new_facet, *the_facet; 00979 CubitPoint *points[3]; 00980 for (ii=0; ii<facet_list.size(); ii++) 00981 { 00982 the_facet = facet_list.get_and_step(); 00983 for (jj=0; jj<3; jj++) 00984 { 00985 idx = the_facet->point(jj)->marked(); 00986 points[jj] = point_array[idx]; 00987 } 00988 new_facet = new CubitFacetData( points[0], points[1], points[2] ); 00989 copy_facet_list.append( new_facet ); 00990 } 00991 00992 delete [] point_array; 00993 00994 return CUBIT_SUCCESS; 00995 } 00996 00997 void FacetSurface::get_bodies( DLIList<FacetBody*>& result_list ) 00998 { 00999 DLIList<FacetLump*> lump_list; 01000 get_lumps( lump_list ); 01001 lump_list.reset(); 01002 for ( int i = lump_list.size(); i--; ) 01003 { 01004 FacetLump* lump = lump_list.get_and_step(); 01005 FacetBody* body = dynamic_cast<FacetBody*>(lump->get_body()); 01006 if (body) 01007 result_list.append_unique(body); 01008 } 01009 } 01010 01011 void FacetSurface::get_lumps( DLIList<FacetLump*>& result_list ) 01012 { 01013 DLIList<FacetShell*> shell_list; 01014 get_shells( shell_list ); 01015 shell_list.reset(); 01016 for ( int i = shell_list.size(); i--; ) 01017 { 01018 FacetShell* shell = shell_list.get_and_step(); 01019 shell->get_lumps( result_list ); 01020 FacetLump* lump = dynamic_cast<FacetLump*>(shell->get_lump()); 01021 if (lump) 01022 result_list.append_unique(lump); 01023 } 01024 } 01025 01026 void FacetSurface::get_shells( DLIList<FacetShell*>& result_list ) 01027 { 01028 myShells.reset(); 01029 for ( int i = 0; i < myShells.size(); i++ ) 01030 if ( FacetShell* shell = dynamic_cast<FacetShell*>(myShells.next(i)) ) 01031 result_list.append(shell); 01032 } 01033 01034 01035 void FacetSurface::get_loops( DLIList<FacetLoop*>& result_list ) 01036 { 01037 myLoops.reset(); 01038 for ( int i = 0; i < myLoops.size(); i++ ) 01039 if ( FacetLoop* loop = dynamic_cast<FacetLoop*>(myLoops.next(i)) ) 01040 result_list.append(loop); 01041 } 01042 01043 void FacetSurface::get_coedges( DLIList<FacetCoEdge*>& result_list ) 01044 { 01045 DLIList<FacetLoop*> loop_list; 01046 get_loops( loop_list ); 01047 loop_list.reset(); 01048 for ( int i = 0; i < loop_list.size(); i++ ) 01049 loop_list.next(i)->get_coedges( result_list ); 01050 } 01051 01052 void FacetSurface::get_curves( DLIList<FacetCurve*>& result_list ) 01053 { 01054 DLIList<FacetCoEdge*> coedge_list; 01055 get_coedges( coedge_list ); 01056 coedge_list.reset(); 01057 for ( int i = coedge_list.size(); i--; ) 01058 { 01059 FacetCoEdge* coedge = coedge_list.get_and_step(); 01060 FacetCurve* curve = dynamic_cast<FacetCurve*>(coedge->curve()); 01061 if (curve) 01062 result_list.append_unique(curve); 01063 } 01064 } 01065 01066 01067 //------------------------------------------------------------------------- 01068 // Purpose : Remove Shell from shell list 01069 // 01070 // Special Notes : 01071 // 01072 // Creator : Jason Kraftcheck 01073 // 01074 // Creation Date : 09/29/03 01075 //------------------------------------------------------------------------- 01076 CubitStatus FacetSurface::remove_shell(FacetShell* shell) 01077 { 01078 // Something strange here -- A DLIList of Shells and a 01079 // two-element array for senses? Try to keep the senses 01080 // intact anyway... 01081 myShells.reset(); 01082 if (myShells.get() == shell) 01083 myShellSense = CUBIT_UNKNOWN; 01084 01085 if (!myShells.move_to(shell)) 01086 return CUBIT_FAILURE; 01087 01088 myShells.remove(); 01089 return CUBIT_SUCCESS; 01090 } 01091 01092 //------------------------------------------------------------------------- 01093 // Purpose : Tear down topology 01094 // 01095 // Special Notes : 01096 // 01097 // Creator : Jason Kraftcheck 01098 // 01099 // Creation Date : 09/29/03 01100 //------------------------------------------------------------------------- 01101 void FacetSurface::disconnect_all_loops() 01102 { 01103 myLoops.reset(); 01104 for (int i = myLoops.size(); i--; ) 01105 { 01106 LoopSM* sm_ptr = myLoops.get_and_step(); 01107 FacetLoop* loop = dynamic_cast<FacetLoop*>(sm_ptr); 01108 if (loop) 01109 { 01110 assert(loop->get_surface() == this); 01111 loop->remove_surface(); 01112 } 01113 } 01114 myLoops.clean_out(); 01115 } 01116 01117 void FacetSurface::add_transformation( CubitTransformMatrix &tfmat ) 01118 { 01119 if ( myEvaluator ) 01120 myEvaluator->add_transformation( tfmat ); 01121 } 01122 01123 // ********** END PUBLIC FUNCTIONS ********** 01124 01125 // ********** BEGIN PROTECTED FUNCTIONS ********** 01126 // ********** END PROTECTED FUNCTIONS ********** 01127 01128 // ********** BEGIN PRIVATE FUNCTIONS ********** 01129 void FacetSurface::reverse_sense() 01130 { 01131 facetEvalTool->reverse_facets(); 01132 myLoops.reset(); 01133 int i,j; 01134 FacetLoop* this_loop; 01135 LoopSM* this_loop_sm; 01136 DLIList<FacetCoEdge *> this_coedge_list; 01137 for(i=0;i<myLoops.size();i++){ 01138 this_loop_sm= myLoops.get_and_step(); 01139 this_loop = dynamic_cast<FacetLoop*>(this_loop_sm); 01140 if(!this_loop){ 01141 PRINT_ERROR("Unexpected null pointer for loop.\n"); 01142 return; 01143 } 01144 this_loop->reverse(); 01145 this_coedge_list.clean_out(); 01146 this_loop->get_coedges(this_coedge_list); 01147 for(j=0; j<this_coedge_list.size(); j++){ 01148 this_coedge_list.get_and_step()->reverse_sense(); 01149 } 01150 } 01151 01152 //sense_ = CubitUtil::opposite_sense( sense_ ); 01153 myShellSense = CubitUtil::opposite_sense( myShellSense ); 01154 //myShellSense[1] = CubitUtil::opposite_sense( myShellSense[1] ); 01155 } 01156 01157 CubitStatus FacetSurface::get_projected_distance_on_surface( CubitVector *pos1, 01158 CubitVector *pos2, 01159 double &distance ) 01160 { 01161 return CUBIT_FAILURE; 01162 } 01163 01164 CubitStatus FacetSurface::get_sphere_params 01165 ( 01166 CubitVector ¢er, 01167 double &radius 01168 ) const 01169 { 01170 PRINT_ERROR("Currently, Cubit is unable to determine sphere parameters for FacetSurfaces.\n"); 01171 return CUBIT_FAILURE; 01172 } 01173 01174 CubitStatus FacetSurface::get_cone_params 01175 ( 01176 CubitVector ¢er, 01177 CubitVector &normal, 01178 CubitVector &major_axis, 01179 double &radius_ratio, 01180 double &sine_angle, 01181 double &cos_angle 01182 ) const 01183 { 01184 PRINT_ERROR("Currently, Cubit is unable to determine cone parameters for FacetSurfaces.\n"); 01185 return CUBIT_FAILURE; 01186 } 01187 01188 CubitStatus FacetSurface::get_torus_params 01189 ( 01190 CubitVector ¢er, 01191 CubitVector &normal, 01192 double &major_radius, 01193 double &minor_radius 01194 ) const 01195 { 01196 PRINT_ERROR("Currently, Cubit is unable to determine torus parameters for FacetSurfaces.\n"); 01197 return CUBIT_FAILURE; 01198 } 01199 01200 01201 CubitStatus FacetSurface::get_nurb_params 01202 ( 01203 bool &rational, 01204 int °ree_u, 01205 int °ree_v, 01206 int &num_cntrl_pts_u, 01207 int &num_cntrl_pts_v, 01208 DLIList<CubitVector> &cntrl_pts, 01209 DLIList<double> &cntrl_pt_weights, 01210 DLIList<double> &u_knots, 01211 DLIList<double> &v_knots 01212 ) const 01213 { 01214 PRINT_ERROR("Currently, Cubit is unable to determine nurbs parameters for FacetSurface.\n"); 01215 return CUBIT_FAILURE; 01216 } 01217 01218 // ********** END PRIVATE FUNCTIONS ********** 01219 01220 // ********** BEGIN HELPER CLASSES ********** 01221 // ********** END HELPER CLASSES ********** 01222 01223 // ********** BEGIN EXTERN FUNCTIONS ********** 01224 // ********** END EXTERN FUNCTIONS ********** 01225 01226 // ********** BEGIN STATIC FUNCTIONS ********** 01227 // ********** END STATIC FUNCTIONS **********