cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : PartitionBody.cpp 00003 // 00004 // Purpose : 00005 // 00006 // Special Notes : 00007 // 00008 // Creator : Jason Kraftcheck 00009 // 00010 // Creation Date : 02/14/03 00011 //------------------------------------------------------------------------- 00012 00013 #include "PartitionBody.hpp" 00014 #include "CubitTransformMatrix.hpp" 00015 #include "CubitFacetData.hpp" 00016 #include "CubitPointData.hpp" 00017 #include "PartitionPoint.hpp" 00018 #include "PartitionSurface.hpp" 00019 #include "SegmentedCurve.hpp" 00020 #include "PartitionCoEdge.hpp" 00021 #include "PartitionLump.hpp" 00022 #include "VirtualQueryEngine.hpp" 00023 00024 //------------------------------------------------------------------------- 00025 // Purpose : Constructor 00026 // 00027 // Special Notes : 00028 // 00029 // Creator : Jason Kraftcheck 00030 // 00031 // Creation Date : 02/14/03 00032 //------------------------------------------------------------------------- 00033 PartitionBody::PartitionBody( BodySM* body ) 00034 : childList(0) 00035 { 00036 SubEntitySet* set = new SubEntitySet( body,this ); 00037 set->bodyNext = 0; 00038 set->bodyPtr = this; 00039 } 00040 00041 00042 //------------------------------------------------------------------------- 00043 // Purpose : Desturctor 00044 // 00045 // Special Notes : 00046 // 00047 // Creator : Jason Kraftcheck 00048 // 00049 // Creation Date : 02/14/03 00050 //------------------------------------------------------------------------- 00051 PartitionBody::~PartitionBody() 00052 { 00053 assert(! sub_entity_set().bodyNext); 00054 sub_entity_set().bodyPtr = 0; 00055 00056 while( SubEntitySet* dead = childList ) 00057 { 00058 childList = dead->bodyNext; 00059 dead->bodyNext = 0; 00060 dead->bodyPtr = 0; 00061 } 00062 } 00063 00064 //------------------------------------------------------------------------- 00065 // Purpose : Get transform matrix 00066 // 00067 // Special Notes : 00068 // 00069 // Creator : Jason Kraftcheck 00070 // 00071 // Creation Date : 02/14/03 00072 //------------------------------------------------------------------------- 00073 CubitStatus PartitionBody::get_transforms( CubitTransformMatrix& xforms ) 00074 { 00075 return real_body()->get_transforms( xforms ); 00076 } 00077 00078 //------------------------------------------------------------------------- 00079 // Purpose : Attributes 00080 // 00081 // Special Notes : 00082 // 00083 // Creator : Jason Kraftcheck 00084 // 00085 // Creation Date : 02/14/03 00086 //------------------------------------------------------------------------- 00087 void PartitionBody::append_simple_attribute_virt(const CubitSimpleAttrib& csa) 00088 { real_body()->append_simple_attribute_virt(csa); } 00089 void PartitionBody::remove_simple_attribute_virt(const CubitSimpleAttrib& csa) 00090 { real_body()->remove_simple_attribute_virt(csa); } 00091 void PartitionBody::remove_all_simple_attribute_virt() 00092 { real_body()->remove_all_simple_attribute_virt(); } 00093 CubitStatus PartitionBody::get_simple_attribute(DLIList<CubitSimpleAttrib>& list) 00094 { return real_body()->get_simple_attribute(list); } 00095 CubitStatus PartitionBody::get_simple_attribute(const CubitString& name, 00096 DLIList<CubitSimpleAttrib>& list) 00097 { return real_body()->get_simple_attribute(name,list); } 00098 00099 //------------------------------------------------------------------------- 00100 // Purpose : Which layer 00101 // 00102 // Special Notes : 00103 // 00104 // Creator : Jason Kraftcheck 00105 // 00106 // Creation Date : 02/14/03 00107 //------------------------------------------------------------------------- 00108 int PartitionBody::layer() const 00109 { return sub_entity_set().get_owner_layer(); } 00110 00111 //------------------------------------------------------------------------- 00112 // Purpose : get children 00113 // 00114 // Special Notes : 00115 // 00116 // Creator : Jason Kraftcheck 00117 // 00118 // Creation Date : 02/14/03 00119 //------------------------------------------------------------------------- 00120 void PartitionBody::get_parents_virt( DLIList<TopologyBridge*>& ) 00121 { } 00122 void PartitionBody::get_children_virt( DLIList<TopologyBridge*>& list ) 00123 { real_body()->get_children_virt(list); } 00124 00125 //------------------------------------------------------------------------- 00126 // Purpose : get GQE 00127 // 00128 // Special Notes : 00129 // 00130 // Creator : Jason Kraftcheck 00131 // 00132 // Creation Date : 02/14/03 00133 //------------------------------------------------------------------------- 00134 GeometryQueryEngine* PartitionBody::get_geometry_query_engine() const 00135 { return VirtualQueryEngine::instance(); } 00136 00137 //------------------------------------------------------------------------- 00138 // Purpose : misc. junk from PartitionEntity 00139 // 00140 // Special Notes : 00141 // 00142 // Creator : Jason Kraftcheck 00143 // 00144 // Creation Date : 02/14/03 00145 //------------------------------------------------------------------------- 00146 void PartitionBody::reverse_sense() { assert(0); } 00147 void PartitionBody::notify_split(FacetEntity*, FacetEntity* ) { assert(0); } 00148 CubitStatus PartitionBody::save(CubitSimpleAttrib&) { return CUBIT_FAILURE; } 00149 00150 00151 //------------------------------------------------------------------------- 00152 // Purpose : get bounding box 00153 // 00154 // Special Notes : 00155 // 00156 // Creator : Jason Kraftcheck 00157 // 00158 // Creation Date : 02/14/03 00159 //------------------------------------------------------------------------- 00160 CubitBox PartitionBody::bounding_box() const 00161 { 00162 DLIList<TopologyBridge*> lumps; 00163 real_body()->get_children_virt(lumps); 00164 00165 CubitBox result = dynamic_cast<Lump*>(lumps.step_and_get())->bounding_box(); 00166 for( int i = 1; i < lumps.size(); i++ ) 00167 result |= dynamic_cast<Lump*>(lumps.step_and_get())->bounding_box(); 00168 00169 return result; 00170 } 00171 00172 00173 //------------------------------------------------------------------------- 00174 // Purpose : Get BodySM 00175 // 00176 // Special Notes : 00177 // 00178 // Creator : Jason Kraftcheck 00179 // 00180 // Creation Date : 02/14/03 00181 //------------------------------------------------------------------------- 00182 BodySM* PartitionBody::real_body() const 00183 { return dynamic_cast<BodySM*>(partitioned_entity()); } 00184 00185 00186 //------------------------------------------------------------------------- 00187 // Purpose : Add an entity to the list we need to transform 00188 // 00189 // Special Notes : 00190 // 00191 // Creator : Jason Kraftcheck 00192 // 00193 // Creation Date : 02/14/03 00194 //------------------------------------------------------------------------- 00195 void PartitionBody::add( SubEntitySet& set ) 00196 { 00197 assert(!set.bodyPtr); 00198 set.bodyPtr = this; 00199 set.bodyNext = childList; 00200 childList = &set; 00201 } 00202 00203 //------------------------------------------------------------------------- 00204 // Purpose : Remove an entity from the list of entities to transform 00205 // 00206 // Special Notes : 00207 // 00208 // Creator : Jason Kraftcheck 00209 // 00210 // Creation Date : 02/14/03 00211 //------------------------------------------------------------------------- 00212 void PartitionBody::remove( SubEntitySet& set ) 00213 { 00214 assert(set.bodyPtr == this); 00215 if( childList == &set ) 00216 { 00217 childList = set.bodyNext; 00218 } 00219 else 00220 { 00221 SubEntitySet* ptr = childList; 00222 while( ptr->bodyNext != &set ) 00223 { 00224 ptr = ptr->bodyNext; 00225 assert(!!ptr); 00226 } 00227 ptr->bodyNext = set.bodyNext; 00228 } 00229 set.bodyNext = 0; 00230 set.bodyPtr = 0; 00231 } 00232 00233 00234 //------------------------------------------------------------------------- 00235 // Purpose : Remove all child partition geometry (body deleted) 00236 // 00237 // Special Notes : 00238 // 00239 // Creator : Jason Kraftcheck 00240 // 00241 // Creation Date : 04/04/03 00242 //------------------------------------------------------------------------- 00243 void PartitionBody::destroy_all_children() 00244 { 00245 DLIList<PartitionLump*> lumps; 00246 DLIList<PartitionSurface*> surfs; 00247 DLIList<PartitionCoEdge*> coedges; 00248 DLIList<PartitionCurve*> curves; 00249 DLIList<PartitionPoint*> points; 00250 00251 DLIList<PartitionEntity*> sub_geom, split_geom; 00252 for ( SubEntitySet* ptr = childList; ptr; ptr = ptr->next_in_body() ) 00253 { 00254 ptr->get_sub_entities( sub_geom ); 00255 ptr->get_lower_order( split_geom ); 00256 sub_geom += split_geom; 00257 split_geom.clean_out(); 00258 while( sub_geom.size() ) 00259 { 00260 PartitionEntity* ent = sub_geom.pop(); 00261 if ( PartitionPoint* point = dynamic_cast<PartitionPoint*>(ent) ) 00262 points.append(point); 00263 else if( PartitionCoEdge* coedge = dynamic_cast<PartitionCoEdge*>(ent) ) 00264 coedges.append(coedge); 00265 else if( PartitionCurve* curve = dynamic_cast<PartitionCurve*>(ent) ) 00266 curves.append(curve); 00267 else if( PartitionSurface* surf = dynamic_cast<PartitionSurface*>(ent) ) 00268 surfs.append(surf); 00269 else if ( PartitionLump* lump = dynamic_cast<PartitionLump*>(ent) ) 00270 lumps.append(lump); 00271 else 00272 assert(0); 00273 } 00274 } 00275 00276 while( lumps.size() ) 00277 { 00278 PartitionLump* lump = lumps.pop(); 00279 while( PartitionShell* shell = lump->first_shell() ) 00280 { 00281 lump->remove(shell); 00282 shell->remove_all_surfaces(); 00283 delete shell; 00284 } 00285 delete lump; 00286 } 00287 00288 while( surfs.size() ) 00289 { 00290 PartitionSurface* surf = surfs.pop(); 00291 while( PartitionLoop* loop = surf->next_loop(NULL) ) 00292 { 00293 surf->remove(loop); 00294 loop->remove_all_coedges(); 00295 delete loop; 00296 } 00297 delete surf; 00298 } 00299 00300 while( coedges.size() ) 00301 { 00302 PartitionCoEdge* coedge = coedges.pop(); 00303 if (coedge->get_curve() != NULL) 00304 coedge->get_curve()->remove( coedge ); 00305 delete coedge; 00306 } 00307 00308 while( curves.size() ) 00309 { 00310 PartitionCurve* curve = curves.pop(); 00311 assert( !curve->next_coedge(NULL) ); 00312 delete curve; 00313 } 00314 00315 while( points.size() ) 00316 { 00317 PartitionPoint* point = points.pop(); 00318 assert( !point->num_curves() ); 00319 delete point; 00320 } 00321 00322 // All child SubEntitySets should have been deleted when they 00323 // became empty, and should be removed from the list in this 00324 // body as they are destroyed. However, when the last SubEntitySet 00325 // in this body is destroyed, this body will be destroyed as well. 00326 // So don't do this check! 00327 //assert(!childList); 00328 } 00329 00330 //------------------------------------------------------------------------- 00331 // Purpose : 00332 // 00333 // Special Notes : 00334 // 00335 // Creator : Jason Kraftcheck 00336 // 00337 // Creation Date : 05/10/04 00338 //------------------------------------------------------------------------- 00339 CubitStatus PartitionBody::mass_properties( CubitVector& result, double& volume ) 00340 { 00341 DLIList<Lump*> lump_list; 00342 lumps( lump_list ); 00343 00344 DLIList<PartitionLump*> part_list; 00345 CAST_LIST( lump_list, part_list, PartitionLump ); 00346 if (part_list.size() < lump_list.size()) 00347 return real_body()->mass_properties( result, volume ); 00348 00349 CubitVector centroid(0.0, 0.0, 0.0), tmp_centroid; 00350 volume = 0.0; 00351 double tmp_volume; 00352 for (int i = part_list.size(); i--; ) 00353 { 00354 if (CUBIT_FAILURE == 00355 part_list.get_and_step()->mass_properties( tmp_centroid, tmp_volume )) 00356 return CUBIT_FAILURE; 00357 00358 centroid += tmp_volume * tmp_centroid; 00359 volume += tmp_volume; 00360 } 00361 00362 if (volume > CUBIT_RESABS) 00363 { 00364 result = centroid / volume; 00365 } 00366 else 00367 { 00368 result.set( 0.0, 0.0, 0.0 ); 00369 volume = 0.0; 00370 } 00371 return CUBIT_SUCCESS; 00372 } 00373 00374 //------------------------------------------------------------------------- 00375 // Purpose : 00376 // 00377 // Special Notes : 00378 // 00379 // Creator : Jason Kraftcheck 00380 // 00381 // Creation Date : 05/10/04 00382 //------------------------------------------------------------------------- 00383 CubitPointContainment PartitionBody::point_containment( const CubitVector& pos, 00384 double tolerance ) 00385 { 00386 DLIList<Lump*> lump_list; 00387 lumps( lump_list ); 00388 00389 DLIList<PartitionLump*> part_list; 00390 CAST_LIST( lump_list, part_list, PartitionLump ); 00391 00392 if (part_list.size() < lump_list.size()) 00393 { 00394 return real_body()->point_containment( pos, tolerance ); 00395 } 00396 00397 bool inside = false, on = false; 00398 part_list.reset(); 00399 for (int i = part_list.size(); i--; ) 00400 { 00401 switch( part_list.get_and_step()->point_containment( pos ) ) 00402 { 00403 case CUBIT_PNT_INSIDE: 00404 inside = true; 00405 break; 00406 case CUBIT_PNT_BOUNDARY: 00407 on = true; 00408 break; 00409 case CUBIT_PNT_OUTSIDE: 00410 break; 00411 default: 00412 return CUBIT_PNT_UNKNOWN; 00413 } 00414 } 00415 00416 if (inside) 00417 return CUBIT_PNT_INSIDE; 00418 else if(on) 00419 return CUBIT_PNT_BOUNDARY; 00420 else 00421 return CUBIT_PNT_OUTSIDE; 00422 } 00423 00424 //------------------------------------------------------------------------- 00425 // Purpose : 00426 // 00427 // Special Notes : 00428 // 00429 // Creator : Jason Kraftcheck 00430 // 00431 // Creation Date : 05/26/04 00432 //------------------------------------------------------------------------- 00433 void PartitionBody::get_all_children( DLIList<PartitionEntity*>& list ) 00434 { 00435 DLIList<PartitionEntity*> tmp; 00436 for (SubEntitySet* ptr = childList; ptr; ptr = ptr->bodyNext ) 00437 { 00438 tmp.clean_out(); 00439 ptr->get_sub_entities( tmp ); 00440 list += tmp; 00441 00442 tmp.clean_out(); 00443 ptr->get_lower_order( tmp ); 00444 list += tmp; 00445 } 00446 }