cgma
GMem Class Reference

#include <GMem.hpp>

List of all members.

Public Member Functions

 GMem ()
 ~GMem ()
void allocate_tri (int num_tri)
void allocate_polylines (int num_lines)
void allocate_more_polylines (int num_lines)
void clean_out ()
void points_consolidated (CubitBoolean yes_no)
CubitBoolean points_consolidated ()
void consolidate_points (double tolerance)
GPointpoint_list ()
int * facet_list ()
void replace_point_list (GPoint new_point_list[], int num_valid_points, int array_size)
void replace_facet_list (int new_facet_list[], int num_valid_entries, int array_size)
int point_list_size ()
int facet_list_size ()
 GMem (const GMem &from)
GMemoperator= (const GMem &from)
void transform (CubitTransformMatrix &transform)

Public Attributes

int pointListCount
int fListCount

Private Member Functions

void consolidate_few_points (double tolerance)
void consolidate_many_points (double tolerance)

Private Attributes

GPointpointList
int ptsSize
int fListSize
int * facetList
CubitBoolean pointsConsolidated

Detailed Description

Definition at line 28 of file GMem.hpp.


Constructor & Destructor Documentation

Definition at line 8 of file GMem.cpp.

Definition at line 19 of file GMem.cpp.

{
   if (pointList)
      delete [] pointList;
   if (facetList)
      delete [] facetList;
}
GMem::GMem ( const GMem from)

Definition at line 123 of file GMem.cpp.

{
     // Set the array pointers to NULL
   pointList = NULL;
   facetList = NULL;
     // Set one equal to the other
   *this = from;
}

Member Function Documentation

void GMem::allocate_more_polylines ( int  num_lines)

Definition at line 62 of file GMem.cpp.

{
     // Make sure we need to do something
   if (num_additional_segs <= 0)
      return;
     // If there are no points, we need space for one additional point
   if (pointListCount == 0)
      num_additional_segs++;
     // Make sure we need to grow
   if (ptsSize >= pointListCount + num_additional_segs)
      return;

     // Make a big enough array of points
   GPoint *new_points = new GPoint[pointListCount + num_additional_segs];
     // Copy the old data to the new array
   if (pointList)
   {
      memcpy (new_points, pointList, pointListCount*sizeof(GPoint));
      delete []pointList;
   }
     // Store the new array in 'pointList'
   pointList = new_points;
   ptsSize = pointListCount + num_additional_segs;
}
void GMem::allocate_polylines ( int  num_lines)

Definition at line 47 of file GMem.cpp.

{
   num_lines++;
   if (num_lines > ptsSize)
   {
      if (pointList)
         delete [] pointList;
      ptsSize = num_lines;
      pointList = new GPoint[ptsSize];
   }
}
void GMem::allocate_tri ( int  num_tri)

Definition at line 27 of file GMem.cpp.

{
   if (num_tri*3 > ptsSize) 
   {
      if (pointList)
         delete [] pointList;
      ptsSize = 3 * num_tri;
      pointList = new GPoint[ptsSize];
   } 
   if (num_tri*4 > fListSize) 
   {
      if (facetList)
         delete [] facetList;
      fListSize = 4 * num_tri;
      facetList = new int[fListSize]; 
   }
}
void GMem::clean_out ( )

Definition at line 87 of file GMem.cpp.

{
   pointListCount = 0;
   fListCount = 0;
}
void GMem::consolidate_few_points ( double  tolerance) [private]

Definition at line 162 of file GMem.cpp.

{
  const double tolsqr = tolerance * tolerance;
  int* index_map = new int[pointListCount];
    
    // Consolidate the point list.  index_map is used
    // to maintain a map between the old index of a point
    // (the index into index_map) and the new index of a
    // point (the value in index_map).
  int write = 0, read, comp;
  for( read = 0; read < pointListCount; read++ )
  {
    const GPoint& pti = pointList[read];
    for( comp = 0; comp < write; comp++ )
    {
      const GPoint& ptj = pointList[comp];
      double x = pti.x - ptj.x;
      double y = pti.y - ptj.y;
      double z = pti.z - ptj.z;
      if( (x*x+y*y+z*z) <= tolsqr )
        break;
    }
    
    index_map[read] = comp;
    if( comp == write )
    {
      pointList[comp] = pointList[read];
      write++;
    }
  }
  pointListCount = write;  

    // Update the facet list using values from index_map.
  int *itor = facetList;
  const int* end = facetList + fListCount;
  while( itor < end )
    for( int count = *(itor++); count--; itor++ )
      *itor = index_map[*itor];

  delete [] index_map;
  pointsConsolidated = CUBIT_TRUE;
}
void GMem::consolidate_many_points ( double  tolerance) [private]

Definition at line 210 of file GMem.cpp.

{
  const double tolsqr = tolerance * tolerance;
  
    // build OctTree
  DLIList<GPoint*> point_list(pointListCount);
  GPoint* p_itor = pointList;
  GPoint* p_end  = p_itor + pointListCount;
  while( p_itor < p_end )
    point_list.append( p_itor++ );
  OctTree<GPoint, GPointOctTreeEval> tree( point_list, tolerance );
  point_list.clean_out();
  
    // Consolidate the point list.  index_map is used
    // to maintain a map between the old index of a point
    // (the index into index_map) and the new index of a
    // point (the value in index_map).
  int* index_map = new int[pointListCount];
  GPoint* new_array = new GPoint[pointListCount];
  int read, write = 0;
  for ( read = 0; read < pointListCount; read++)
  {
    GPoint* pt = pointList + read;
    CubitVector v(pt->x, pt->y, pt->z);
    index_map[read] = write;
    point_list.clean_out();
    tree.nodes_near( v, point_list );
    while ( point_list.size() )
    {
      GPoint* p = point_list.pop();
      int index = p - pointList;
      assert( (index >= 0) && (index < pointListCount) );
      CubitVector v2(p->x, p->y, p->z);
      if ( (index < read) && ((v - v2).length_squared() < tolsqr) )
      {
        index_map[read] = index_map[index];
        break;
      }
    }
    
    if ( index_map[read] == write )
    {
      new_array[write++] = pointList[read];
    }
  }
  pointListCount = write;  
  delete [] pointList;
  pointList = new_array;
  
    // Update the facet list using values from index_map.
  int *itor = facetList;
  const int* end = facetList + fListCount;
  while( itor < end )
    for( int count = *(itor++); count--; itor++ )
      *itor = index_map[*itor];

  delete [] index_map;
  pointsConsolidated = CUBIT_TRUE;
}
void GMem::consolidate_points ( double  tolerance)

Definition at line 154 of file GMem.cpp.

{
  if ( pointListCount < 1000 )
    consolidate_few_points( tolerance );
  else 
    consolidate_many_points( tolerance );
}
int* GMem::facet_list ( ) [inline]

Definition at line 71 of file GMem.hpp.

      { return facetList; }
int GMem::facet_list_size ( ) [inline]

Definition at line 88 of file GMem.hpp.

      { return fListSize; }
GMem & GMem::operator= ( const GMem from)

Definition at line 133 of file GMem.cpp.

{
   if (this != &from)
   {
        // Make a copy of the point array
      GPoint* temp1 = new GPoint[from.ptsSize];
      memcpy (temp1, from.pointList, from.ptsSize*sizeof(GPoint));
        // Put it in the receiving GMem
      replace_point_list(temp1, from.pointListCount, from.ptsSize);
        // Make a copy of the facet array
      int* temp2 = new int[from.fListSize];
      memcpy (temp2, from.facetList, from.fListSize*sizeof(int));
        // Put it in the receiving GMem
      replace_facet_list(temp2, from.fListCount, from.fListSize);
        // Set whether it's consolidated
      pointsConsolidated = from.pointsConsolidated;
   }
   return *this;
}
GPoint* GMem::point_list ( ) [inline]

Definition at line 69 of file GMem.hpp.

      { return pointList; }
int GMem::point_list_size ( ) [inline]

Definition at line 86 of file GMem.hpp.

      { return ptsSize; }
void GMem::points_consolidated ( CubitBoolean  yes_no) [inline]

Definition at line 61 of file GMem.hpp.

      { pointsConsolidated = yes_no; }

Definition at line 63 of file GMem.hpp.

      { return pointsConsolidated; }
void GMem::replace_facet_list ( int  new_facet_list[],
int  num_valid_entries,
int  array_size 
)

Definition at line 108 of file GMem.cpp.

{
     // First, delete the old memory
   if (facetList)
      delete [] facetList;
     // Now replace it with the new
   facetList = new_facet_list;
     // Set the array size
   fListSize = array_size;
     // Set the number of valid entries
   fListCount = num_valid_entries;
}
void GMem::replace_point_list ( GPoint  new_point_list[],
int  num_valid_points,
int  array_size 
)

Definition at line 94 of file GMem.cpp.

{
     // First, delete the old memory
   if (pointList)
      delete [] pointList;
     // Now replace it with the new
   pointList = new_point_list;
     // Set the array size
   ptsSize = array_size;
     // Set the number of valid entries
   pointListCount = num_valid_points;
}
void GMem::transform ( CubitTransformMatrix transform)

Definition at line 270 of file GMem.cpp.

{
  int i=0;
  CubitVector temp_point;
  for (i=0; i<this->pointListCount; i++)
  {
    temp_point.set(pointList[i].x, pointList[i].y, pointList[i].z);
    temp_point = transform * temp_point;
    pointList[i].x = (float)temp_point.x();
    pointList[i].y = (float)temp_point.y();
    pointList[i].z = (float)temp_point.z();
  }
}

Member Data Documentation

int* GMem::facetList [private]

Definition at line 36 of file GMem.hpp.

Definition at line 44 of file GMem.hpp.

int GMem::fListSize [private]

Definition at line 35 of file GMem.hpp.

GPoint* GMem::pointList [private]

Definition at line 33 of file GMem.hpp.

Definition at line 43 of file GMem.hpp.

Definition at line 37 of file GMem.hpp.

int GMem::ptsSize [private]

Definition at line 34 of file GMem.hpp.


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