cgma
PartitionLump Class Reference

#include <PartitionLump.hpp>

Inheritance diagram for PartitionLump:
Lump PartitionEntity GeometryEntity TopologyBridge

List of all members.

Public Member Functions

 PartitionLump (Lump *real_lump)
 PartitionLump (PartitionLump *split_from)
virtual ~PartitionLump ()
Lumpreal_lump () const
PartitionShellfirst_shell () const
PartitionShellnext_shell (PartitionShell *after_this=0) const
CubitStatus add (PartitionShell *shell)
CubitStatus remove (PartitionShell *shell)
void remove_all_shells ()
PartitionBodyget_body () const
TopologyBridgefind_parent_body () const
virtual CubitStatus save (CubitSimpleAttrib &)
void get_parents_virt (DLIList< TopologyBridge * > &)
void get_children_virt (DLIList< TopologyBridge * > &)
int layer () const
GeometryQueryEngineget_geometry_query_engine () const
void append_simple_attribute_virt (const CubitSimpleAttrib &)
void remove_simple_attribute_virt (const CubitSimpleAttrib &)
void remove_all_simple_attribute_virt ()
CubitStatus get_simple_attribute (DLIList< CubitSimpleAttrib > &)
CubitStatus get_simple_attribute (const CubitString &name, DLIList< CubitSimpleAttrib > &)
CubitBox bounding_box () const
double measure ()
void reverse_sense ()
void transform (const CubitTransformMatrix &)
void notify_split (FacetEntity *, FacetEntity *)
void get_all_children (DLIList< PartitionEntity * > &result)
CubitStatus mass_properties (CubitVector &volume_centrioid, double &volume)
CubitPointContainment point_containment (const CubitVector &pos, double tolerance=-1)

Private Attributes

PartitionShelllistHead

Friends

class PartitionBody

Detailed Description

Definition at line 25 of file PartitionLump.hpp.


Constructor & Destructor Documentation

Definition at line 9 of file PartitionLump.cpp.

  : listHead(0)
{
  assert( dynamic_cast<SubEntitySet*>(real_lump->owner()) == 0 );
  new SubEntitySet( real_lump, this );
}

Definition at line 16 of file PartitionLump.cpp.

  : listHead(0)
{
  split_from->sub_entity_set().add_partition( this );
}

Definition at line 22 of file PartitionLump.cpp.


Member Function Documentation

Definition at line 33 of file PartitionLump.cpp.

{
  assert( shell->myLump == 0 );
  shell->lumpNext = listHead;
  shell->myLump = this;
  listHead = shell;
  return CUBIT_SUCCESS;
}

Implements TopologyBridge.

Definition at line 105 of file PartitionLump.cpp.

{ sub_entity_set().add_attribute( this, csa ); }
CubitBox PartitionLump::bounding_box ( void  ) const [virtual]

Implements PartitionEntity.

Definition at line 142 of file PartitionLump.cpp.

{
  return real_lump() ? real_lump()->bounding_box() : CubitBox();
}

Definition at line 238 of file PartitionLump.cpp.

{
  if( get_body() ) 
    return get_body();
  
  Lump* lump = real_lump();
  if(!lump) return 0;
  
  DLIList<TopologyBridge*> list;
  lump->get_parents_virt(list);
  return list.size() ? list.get() : 0;
}

Definition at line 83 of file PartitionLump.hpp.

  { return listHead; }

Definition at line 285 of file PartitionLump.cpp.

{
  PartitionShell* shell = 0;
  while( (shell = next_shell(shell)) )
  {
    PartitionCoSurf* cosurf = 0;
    while( (cosurf = shell->next_co_surface(cosurf)) )
    {
      PartitionSurface* surface = cosurf->get_surface();
      list.append( surface );
      PartitionLoop* loop = 0;
      while( (loop = surface->next_loop(loop)) )
      {
        PartitionCoEdge* coedge = loop->first_coedge();
        do {
          PartitionCurve* curve = coedge->get_curve();
          list.append( curve );
          list.append( curve->start_point() );
          list.append( curve->end_point() );
          coedge = loop->next_coedge( coedge );
        } while( coedge != loop->first_coedge() );
      }
    }
  }
  
  int i;
  for( i = list.size(); i--; )
    list.step_and_get()->mark = 0;
  for( i = list.size(); i--; )
    list.step_and_get()->mark++;
  for( i = list.size(); i--; )
  {
    list.step_and_get()->mark--;
    if( list.get()->mark != 0 )
      list.change_to(0);
  }
  list.remove_all_with_value(0);
}

Definition at line 235 of file PartitionLump.cpp.

  { return sub_entity_set().body(); }
void PartitionLump::get_children_virt ( DLIList< TopologyBridge * > &  list) [virtual]

Implements TopologyBridge.

Definition at line 88 of file PartitionLump.cpp.

{
  PartitionShell* shell = first_shell();
  while( shell )
  {
    list.append( shell );
    shell = next_shell( shell );
  }
}

Implements TopologyBridge.

Definition at line 98 of file PartitionLump.cpp.

void PartitionLump::get_parents_virt ( DLIList< TopologyBridge * > &  list) [virtual]

Implements TopologyBridge.

Definition at line 77 of file PartitionLump.cpp.

{
  if( get_body() )
    list.append( get_body() );
  else
  {
    real_lump()->get_parents_virt( list );
//    PartitionEngine::fix_up_query_results( list );
  }
}

Implements TopologyBridge.

Definition at line 111 of file PartitionLump.cpp.

{ 
  sub_entity_set().get_attributes( this, list ); 
  return CUBIT_SUCCESS;
}

Implements TopologyBridge.

Definition at line 116 of file PartitionLump.cpp.

{ 
  sub_entity_set().get_attributes( this, name.c_str(), list ); 
  return CUBIT_SUCCESS;
}
int PartitionLump::layer ( ) const [inline, virtual]

Reimplemented from TopologyBridge.

Definition at line 51 of file PartitionLump.hpp.

CubitStatus PartitionLump::mass_properties ( CubitVector volume_centrioid,
double &  volume 
) [virtual]

Implements Lump.

Definition at line 333 of file PartitionLump.cpp.

{
  PartitionShell* shell = 0;
  CubitVector s_cent;
  double s_vol;
  volume = 0.0;
  centroid.set( 0.0, 0.0, 0.0 );
  
  while ((shell = next_shell( shell )))
  {
    if (CUBIT_SUCCESS != shell->mass_properties( s_cent, s_vol ))
      return CUBIT_FAILURE;
    centroid += s_vol * s_cent;
    volume += s_vol;
  }
  
  if (volume > CUBIT_RESABS)
    centroid /= volume;
  else
    centroid.set( 0.0, 0.0, 0.0 );
  return CUBIT_SUCCESS;
}
double PartitionLump::measure ( ) [virtual]

Implements GeometryEntity.

Definition at line 147 of file PartitionLump.cpp.

{
    // Calculate volume of this lump from surface facets.
    // Volume is calculated as the sum of the signed
    // volumes of the tetrahedrons formed by this point
    // with triagle.
  CubitVector p0 = bounding_box().center();
  
  double result = 0.0;
  PartitionShell* shell = 0;
  PartitionCoSurf* cosurf = 0;
  DLIList<CubitFacetData*> facets;
  CubitVector p1, normal;
  
    // calculate area around this point
  while ( (shell = next_shell(shell)) )
  {
      // mark surfaces with a count of how many times they 
      // occur in the shell
    cosurf = 0;
    while ( (cosurf = shell->next_co_surface(cosurf)) )
      cosurf->get_surface()->mark = 0;
    cosurf = 0;
    while ( (cosurf = shell->next_co_surface(cosurf)) )
      cosurf->get_surface()->mark++;
    
      // calculate partial area for each surface
    cosurf = 0;
    while ( (cosurf = shell->next_co_surface(cosurf)) )
    {
      PartitionSurface* surf = cosurf->get_surface();
      
        // skip non-manifold surfaces
      if( surf->mark > 1 ) continue;
      
      facets.clean_out();
      surf->get_facet_data( facets );
      for  ( int i = facets.size(); i--; )
      {
          // Tetrahedron volume is Ah/3
          // Calculate 2Ah and add to result.
          // Divide result by 6 when all done.
        
        CubitFacet* facet = facets.step_and_get();
        p1 = facet->point(0)->coordinates();
        normal = (facet->point(2)->coordinates() - p1) 
               * (facet->point(1)->coordinates() - p1);
        
          // Triangle area is 1/2 length of edge product
        double two_area = normal.length();
        
        if ( two_area > CUBIT_RESABS )
        {
            // Calculating signed area - need to 
            // reverse facet normal for reversed
            // cosurfaces.
          if ( cosurf->sense() == CUBIT_REVERSED )
            normal = -normal;
          
            // Make normal a unit vector.  Already
            // calculated length, so reuse that 
            // value.
          normal /= two_area;
          
            // This is where the signed part of the
            // calculation comes in.  If normal is 
            // in opposite direction as the vector
            // (p0-p1), then the height is negative.
          double height = normal % (p0 - p1);
          
            // Add the signed height value times 
            // twice the triangle area to result.
          result += two_area * height;
        }
      }
    }
    
      // clear marks
    cosurf = 0;
    while ( (cosurf = shell->next_co_surface(cosurf)) )
      cosurf->get_surface()->mark = 0;
  }
  
    // Calculated 2Ah for each tetrahedron, so divide
    // by 6 to get Ah/3.
  return result / 6.0;
}
PartitionShell * PartitionLump::next_shell ( PartitionShell after_this = 0) const [inline]

Definition at line 86 of file PartitionLump.hpp.

  { return !prev ? listHead : (prev->myLump == this) ? prev->lumpNext : 0; }
void PartitionLump::notify_split ( FacetEntity ,
FacetEntity  
) [virtual]

Implements PartitionEntity.

Definition at line 123 of file PartitionLump.cpp.

  { assert(0); }
CubitPointContainment PartitionLump::point_containment ( const CubitVector pos,
double  tolerance = -1 
)

Definition at line 356 of file PartitionLump.cpp.

{
  PartitionCoSurf* closest_surf = NULL;
  double closest_dist = CUBIT_DBL_MAX;
  CubitVector closest, normal;
  
  PartitionShell* shell = 0;
  while ((shell = next_shell( shell )))
  {
    PartitionCoSurf* cosurf = 0;
    while ((cosurf = shell->next_co_surface( cosurf )))
    {
      PartitionSurface* surf = cosurf->get_surface();
      if (!shell->is_nonmanifold( surf ))
      {
        surf->closest_point( pos, &closest );
        double dist = (pos - closest).length_squared();
        if (dist < closest_dist)
        {
          closest_dist = dist;
          closest_surf = cosurf;
        }
      }
    }
  }
  
  if (!closest_surf)
    return CUBIT_PNT_UNKNOWN;

  if( tolerance < 0 )
    tolerance = GEOMETRY_RESABS;
  
  closest_surf->get_surface()->closest_point( pos, &closest, &normal );
  if ((closest - pos).length_squared() < tolerance * tolerance )
    return CUBIT_PNT_BOUNDARY;
  
  if (closest_surf->sense() == CUBIT_REVERSED)
    normal = -normal;
  
  double dot = normal % (closest - pos);
  return dot < CUBIT_RESABS ? CUBIT_PNT_OUTSIDE :
         dot > CUBIT_RESABS ? CUBIT_PNT_INSIDE  :
                              CUBIT_PNT_UNKNOWN;
}

Definition at line 27 of file PartitionLump.cpp.

{
  return dynamic_cast<Lump*>(partitioned_entity());
}

Definition at line 42 of file PartitionLump.cpp.

{
  if( shell->myLump != this )
    return CUBIT_FAILURE;
  
  if( listHead == shell )
  {
    listHead = shell->lumpNext;
  }
  else
  {
    PartitionShell* sh = listHead;
    while( sh && sh->lumpNext != shell )
      sh = sh->lumpNext;
    assert( sh && sh->lumpNext == shell );
    sh->lumpNext = shell->lumpNext;
  }
  
  shell->myLump = 0;
  shell->lumpNext = 0;
  return CUBIT_SUCCESS;
}

Definition at line 65 of file PartitionLump.cpp.

{
  while( listHead )
  {
    CubitStatus s = remove( listHead );
    assert( s );
    if (CUBIT_SUCCESS != s) {
      PRINT_ERROR("Failed to remove all shells.\n");
    }
  }
}

Implements TopologyBridge.

Definition at line 109 of file PartitionLump.cpp.

Implements TopologyBridge.

Definition at line 107 of file PartitionLump.cpp.

{ sub_entity_set().rem_attribute( this, csa ); }
void PartitionLump::reverse_sense ( ) [virtual]

Implements PartitionEntity.

Definition at line 126 of file PartitionLump.cpp.

{
  PartitionShell* shell = 0;
  while( (shell = next_shell(shell)) )
  {
    PartitionCoSurf* cosurf = 0;
    while( (cosurf = shell->next_co_surface( cosurf )) )
    {
      bool reversed = (cosurf->sense() == CUBIT_REVERSED);
      cosurf->sense( reversed ? CUBIT_FORWARD : CUBIT_REVERSED );
    }
  }
}

Implements PartitionEntity.

Definition at line 251 of file PartitionLump.cpp.

{
  DLIList<int> surf_list;
  
  PartitionShell* shell = 0;
  while( (shell = next_shell(shell)) )
  {
    PartitionCoSurf* cosurf = 0;
    int cosurf_count = 0;
    while( (cosurf = shell->next_co_surface(cosurf)) )
      cosurf_count++;
    
    surf_list.append(cosurf_count);
    cosurf = 0;
    while( (cosurf = shell->next_co_surface(cosurf)) )
    {
      PartitionSurface* surf = cosurf->get_surface();
      int set_id = 0;
      int surf_id = surf->sub_entity_set().get_id(surf);
      if( &(surf->sub_entity_set()) != &sub_entity_set() )
        set_id = surf->sub_entity_set().get_unique_id();
    
      if ( cosurf->sense() == CUBIT_REVERSED )
        surf_id = -surf_id;
        
      surf_list.append( set_id );
      surf_list.append( surf_id );
    }
  }
  
  int id = sub_entity_set().get_id(this);
  return sub_entity_set().save_geometry( id, 3, 0, 0, &surf_list, 0, attrib );
}
void PartitionLump::transform ( const CubitTransformMatrix ) [virtual]

Implements PartitionEntity.

Definition at line 140 of file PartitionLump.cpp.

{;}    

Friends And Related Function Documentation

friend class PartitionBody [friend]

Definition at line 29 of file PartitionLump.hpp.


Member Data Documentation

Definition at line 80 of file PartitionLump.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines