cgma
CompositeBody.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : CompositeBody.cpp
00003 //
00004 // Purpose       : Composite of BodySMs
00005 //
00006 // Special Notes : 
00007 //
00008 // Creator       : Jason Kraftcheck
00009 //
00010 // Creation Date : 01/11/02
00011 //-------------------------------------------------------------------------
00012 
00013 #include "DLIList.hpp"
00014 #include "CompositeBody.hpp"
00015 #include "CompositeLump.hpp"
00016 #include "VirtualQueryEngine.hpp"
00017 #include "CompositeEngine.hpp"
00018 
00019 CompositeBody::CompositeBody()
00020   : firstLump(0)
00021 {
00022 }
00023 
00024 CompositeBody::~CompositeBody()
00025 {
00026   int i;
00027   
00028   for( i = 0; i < realBodies.size(); i++ )
00029     if( realBodies[i]->owner() == this )
00030       realBodies[i]->owner(0);
00031   
00032   while( firstLump )
00033     remove( firstLump );
00034 }
00035 
00036 
00037 CompositeLump* CompositeBody::next_lump( CompositeLump* prev ) const
00038 {
00039   return prev ? prev->nextLump : firstLump;
00040 }
00041 
00042 CubitStatus CompositeBody::add( CompositeLump* lump )
00043 {
00044   if( lump->myBody != 0 )
00045     return CUBIT_FAILURE;
00046     
00047   lump->myBody = this;
00048   lump->nextLump = firstLump;
00049   firstLump = lump;
00050   return CUBIT_SUCCESS;
00051 }
00052 
00053 CubitStatus CompositeBody::remove( CompositeLump* lump )
00054 {
00055   if( lump->myBody != this )
00056     return CUBIT_FAILURE;
00057   
00058   if( firstLump == lump )
00059   {
00060     firstLump = lump->nextLump;
00061   }
00062   else
00063   {
00064     CompositeLump* prev = firstLump; 
00065     while( prev && prev->nextLump != lump )
00066       prev = prev->nextLump;
00067     assert( prev != NULL );
00068     
00069     prev->nextLump = lump->nextLump;
00070   }
00071   
00072   lump->myBody = 0;
00073   lump->nextLump = 0;
00074   return CUBIT_SUCCESS;
00075 }
00076 
00077 CubitStatus CompositeBody::add( BodySM* body )
00078 {
00079   if( index_of( body ) >= 0  )
00080     return CUBIT_FAILURE;
00081     
00082   if( body->owner() )
00083     body->owner()->swap_bridge( body, this, false );
00084   body->owner(this);
00085   
00086   realBodies.push( body );
00087   return CUBIT_SUCCESS;
00088 }
00089 
00090 CubitStatus CompositeBody::remove( BodySM* body )
00091   { return remove_body( index_of( body ) ); }
00092 
00093 CubitStatus CompositeBody::remove_body( int index )
00094 {
00095   if( index < 0 ) return CUBIT_FAILURE;
00096   
00097   if( realBodies[index]->owner() == this )
00098     realBodies[index]->owner(0);
00099   realBodies.remove(index);
00100   return CUBIT_SUCCESS;
00101 }
00102 /*
00103 CubitStatus CompositeBody::move( const CubitVector& offset )
00104 {
00105   int i;
00106   for (i = 0; i < realBodies.size(); i++)
00107     if (CUBIT_SUCCESS != realBodies[i]->move( offset ))
00108       break;
00109   
00110   if (i == realBodies.size())
00111     return CUBIT_SUCCESS;
00112   
00113   for (int j = 0; j < i; j++)
00114     realBodies[j]->move( -offset );
00115   return CUBIT_FAILURE;
00116 }
00117 
00118 
00119 CubitStatus CompositeBody::rotate( const CubitVector& axis, double angle )
00120 {
00121   int i;
00122   for (i = 0; i < realBodies.size(); i++)
00123     if (CUBIT_SUCCESS != realBodies[i]->rotate( axis, angle ))
00124       break;
00125   
00126   if (i == realBodies.size())
00127     return CUBIT_SUCCESS;
00128   
00129   for (int j = 0; j < i; j++)
00130     realBodies[j]->rotate( axis, -angle );
00131   return CUBIT_FAILURE;
00132 }
00133 
00134 CubitStatus CompositeBody::scale( double factor )
00135 {
00136   int i;
00137   for (i = 0; i < realBodies.size(); i++)
00138     if (CUBIT_SUCCESS != realBodies[i]->scale( factor ))
00139       break;
00140   
00141   if (i == realBodies.size())
00142     return CUBIT_SUCCESS;
00143   
00144   for (int j = 0; j < i; j++)
00145     realBodies[j]->scale( 1.0/factor );
00146   return CUBIT_FAILURE;
00147 }
00148 
00149 CubitStatus CompositeBody::scale( const CubitVector& factors )
00150 {
00151   int i;
00152   for (i = 0; i < realBodies.size(); i++)
00153     if (CUBIT_SUCCESS != realBodies[i]->scale( factors ))
00154       break;
00155   
00156   if (i == realBodies.size())
00157     return CUBIT_SUCCESS;
00158   
00159   const CubitVector unscale( 1.0/factors.x(), 1.0/factors.y(), 1.0/factors.z() );
00160   for (int j = 0; j < i; j++)
00161     realBodies[j]->scale( unscale );
00162   return CUBIT_FAILURE;
00163 }
00164 
00165   
00166 CubitStatus CompositeBody::reflect( const CubitVector& axis )
00167 {
00168   int i;
00169   for (i = 0; i < realBodies.size(); i++)
00170     if (CUBIT_SUCCESS != realBodies[i]->reflect( axis ))
00171       break;
00172   
00173   if (i == realBodies.size())
00174     return CUBIT_SUCCESS;
00175   
00176   for (int j = 0; j < i; j++)
00177     realBodies[j]->reflect( axis );
00178   return CUBIT_FAILURE;
00179 }
00180     
00181 
00182 CubitStatus CompositeBody::restore()
00183   { return CUBIT_FAILURE; }
00184 
00185 CubitStatus CompositeBody::reverse()
00186   { return CUBIT_FAILURE; }
00187 */
00188 CubitStatus CompositeBody::get_transforms( CubitTransformMatrix& )
00189   { return CUBIT_FAILURE; }
00190 
00191 void CompositeBody::get_parents_virt( DLIList<TopologyBridge*>& )
00192   { }
00193 
00194 void CompositeBody::get_children_virt( DLIList<TopologyBridge*>& children )
00195 {
00196   for( CompositeLump* lump = firstLump; lump; lump = lump->nextLump )
00197     children.append( lump );
00198 }
00199 
00200 
00201 //-------------------------------------------------------------------------
00202 // Purpose       : Get CompositeEngine
00203 //
00204 // Special Notes : 
00205 //
00206 // Creator       : Jason Kraftcheck
00207 //
00208 // Creation Date : 01/11/02
00209 //-------------------------------------------------------------------------
00210 GeometryQueryEngine* CompositeBody::get_geometry_query_engine() const
00211   { return VirtualQueryEngine::instance(); }
00212 
00213   
00214 CubitStatus CompositeBody::remove_bridge( TopologyBridge* bridge )
00215 {
00216   int i;
00217   for (i = realBodies.size() - 1; i >= 0 && realBodies[i] != bridge; --i);
00218   if (i < 0)
00219     return CUBIT_FAILURE;
00220   
00221   assert( bridge->owner() == this );
00222   bridge->owner( 0 );
00223   realBodies.remove( i );
00224   
00225   if (realBodies.size() == 0)
00226     CompositeEngine::instance().notify_deactivated( this );
00227   
00228   return CUBIT_SUCCESS;
00229 }
00230   
00231   
00232 CubitStatus CompositeBody::swap_bridge( TopologyBridge* old_tb, 
00233                                         TopologyBridge* new_tb,
00234                                         bool )
00235 {
00236   if( new_tb->owner() )
00237     return CUBIT_FAILURE;
00238   
00239   BodySM* new_body = dynamic_cast<BodySM*>(new_tb);
00240   BodySM* old_body = dynamic_cast<BodySM*>(old_tb);
00241   int index = realBodies.find( old_body );
00242   if( index >= 0 && new_body != 0 && realBodies.find(new_body) < 0 )
00243   {
00244     if( old_body->owner() == this )
00245       old_body->owner(0);
00246     new_body->owner(this);
00247     realBodies[index] = new_body;
00248     return CUBIT_SUCCESS;
00249   }
00250   
00251   return CUBIT_FAILURE;
00252 }
00253   
00254 CubitBoolean CompositeBody::contains_bridge( TopologyBridge* bridge ) const
00255 {
00256   return index_of(dynamic_cast<BodySM*>(bridge)) < 0 ? CUBIT_FALSE : CUBIT_TRUE;
00257 }
00258 
00259 void CompositeBody::notify_reversed( TopologyBridge* )
00260   { assert(0); }
00261 
00262 //-------------------------------------------------------------------------
00263 // Purpose       : Attribute functions
00264 //
00265 // Special Notes : 
00266 //
00267 // Creator       : Jason Kraftcheck
00268 //
00269 // Creation Date : 01/11/02
00270 //-------------------------------------------------------------------------
00271 void CompositeBody::append_simple_attribute_virt( const CubitSimpleAttrib& )
00272 { }
00273 void CompositeBody::remove_simple_attribute_virt( const CubitSimpleAttrib& )
00274 { }
00275 void CompositeBody::remove_all_simple_attribute_virt()
00276 { }
00277 CubitStatus CompositeBody::get_simple_attribute( DLIList<CubitSimpleAttrib>& )
00278 { return CUBIT_FAILURE; }
00279 CubitStatus CompositeBody::get_simple_attribute(
00280           const CubitString& , DLIList<CubitSimpleAttrib>& )
00281 { return CUBIT_FAILURE; }
00282 
00283 //-------------------------------------------------------------------------
00284 // Purpose       : 
00285 //
00286 // Special Notes : 
00287 //
00288 // Creator       : Jason Kraftcheck
00289 //
00290 // Creation Date : 05/10/04
00291 //-------------------------------------------------------------------------
00292 CubitPointContainment CompositeBody::point_containment( const CubitVector& pos, double tolerance )
00293 {
00294   int inside = 0;
00295   int boundary = 0;
00296   
00297   for (int i = 0; i < realBodies.size(); ++i)
00298   {
00299     switch( realBodies[i]->point_containment( pos, tolerance ) )
00300     {
00301       case CUBIT_PNT_BOUNDARY:
00302         boundary++;
00303         break;
00304       case CUBIT_PNT_INSIDE:
00305         inside++;
00306         break;
00307       case CUBIT_PNT_OUTSIDE:
00308         break;
00309       default:
00310         return CUBIT_PNT_UNKNOWN;
00311     }
00312   }
00313   
00314   if (inside)
00315     return CUBIT_PNT_INSIDE;
00316   else if (boundary > 1)
00317     return CUBIT_PNT_INSIDE;
00318   else if (boundary)
00319     return CUBIT_PNT_BOUNDARY;
00320   else
00321     return CUBIT_PNT_OUTSIDE;
00322 }
00323 
00324 //-------------------------------------------------------------------------
00325 // Purpose       : 
00326 //
00327 // Special Notes : 
00328 //
00329 // Creator       : Jason Kraftcheck
00330 //
00331 // Creation Date : 05/10/04
00332 //-------------------------------------------------------------------------
00333 CubitStatus CompositeBody::mass_properties( CubitVector& result,
00334                                             double& volume )
00335 {
00336   double vol;
00337   CubitVector centroid;
00338   result.set( 0.0, 0.0, 0.0 );
00339   volume = 0;
00340   
00341   for (int i = 0; i < realBodies.size(); ++i)
00342   {
00343     if (CUBIT_FAILURE == realBodies[i]->mass_properties( centroid, vol ))
00344       return CUBIT_FAILURE;
00345     
00346     result += vol * centroid;
00347     volume += vol;
00348   }
00349   
00350   if (volume > CUBIT_RESABS)
00351     result /= volume;
00352   return CUBIT_SUCCESS;
00353 }
00354 
00355 //-------------------------------------------------------------------------
00356 // Purpose       : Combine
00357 //
00358 // Special Notes : 
00359 //
00360 // Creator       : Jason Kraftcheck
00361 //
00362 // Creation Date : 06/11/04
00363 //-------------------------------------------------------------------------
00364 void CompositeBody::combine( CompositeBody* other )
00365 {
00366   int oldsize = realBodies.size();
00367   realBodies.size( oldsize + other->realBodies.size() );
00368   for (int i = 0; i < other->realBodies.size(); i++)
00369   {
00370     BodySM* bod = other->realBodies[i];
00371     realBodies[i+oldsize] = bod;
00372     bod->owner(this);
00373   }
00374   other->realBodies.size(0);
00375 }
00376   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines