コード例 #1
0
ファイル: PointGridSearch.cpp プロジェクト: chrismullins/cgma
//
// Constructor / Destructor ...................................................
//
PointGridSearch::PointGridSearch( DLIList<CubitPoint*> *point_list,
                                  DLIList<CubitFacet*> *facet_list,
                                  float grid_scale)
{
    // find the geometric bounding range mesh
  assert( point_list && point_list->size() );
  bounding_range( *point_list );

    //find an estimate of the cell size based on the average square distance
    //of the edges on the surface of the geometry

  double grid_cell_size = 1.;
  
    // edge lengths
  double sum = 0.0;
  int i;
  maxEdgeLength = CUBIT_DBL_MIN;
  assert( facet_list || facet_list->size());
  for ( i = 0; i < facet_list->size(); i++)
  {
    CubitPoint *p1, *p2;
    facet_list->next(i)->get_edge_1(p1, p2);
    CubitVector temp = p2->coordinates() - p1->coordinates();
    double tmp_lsqrd =  temp.length_squared();
    sum += tmp_lsqrd;
  }
  grid_cell_size = sqrt( sum / facet_list->size() );

  maxEdgeLength = grid_cell_size;
    // evaluate grid parameters
  CubitVector cell(1.0, 1.0, 1.0);
  double grid_cell_width = grid_scale * grid_cell_size;
  cell *= ( GRID_EXTENSION + 5.0 ) * grid_cell_width;
  gridRangeMinimum = boundingRangeMinimum - cell;
  gridRangeMaximum = boundingRangeMaximum + cell;
  
  CubitVector range_width = gridRangeMaximum - gridRangeMinimum;
  
  numberGridCellsX = (int) ceil(range_width.x() / grid_cell_width + 0.5);
  numberGridCellsY = (int) ceil(range_width.y() / grid_cell_width + 0.5);
  numberGridCellsZ = (int) ceil(range_width.z() / grid_cell_width + 0.5);
  numberGridCells  = numberGridCellsX * numberGridCellsY * numberGridCellsZ;
  
  gridCellWidth.x(range_width.x() / ((double) numberGridCellsX));
  gridCellWidth.y(range_width.y() / ((double) numberGridCellsY));
  gridCellWidth.z(range_width.z() / ((double) numberGridCellsZ));
  
  gridCellWidthInverse.x(1.0 / gridCellWidth.x());
  gridCellWidthInverse.y(1.0 / gridCellWidth.y());
  gridCellWidthInverse.z(1.0 / gridCellWidth.z());
  
    // allocate neighborhood list array
  neighborhoodList = new DLIList<CubitPoint*>* [numberGridCells];
  assert(neighborhoodList != NULL);
  for ( i = 0; i < numberGridCells; i++)
  {
    neighborhoodList[i] = NULL;
  }
}
コード例 #2
0
ファイル: PST_Data.cpp プロジェクト: chrismullins/cgma
double PST_Edge::closest_on_line( const CubitVector& P )
{
  CubitVector B = start_coord();
  CubitVector M   = end_coord() - B;
  if( M.length_squared() < RESABS_SQR )
    return 0.0;
  return ( M % ( P - B ) ) / ( M % M );
}
コード例 #3
0
ファイル: PST_Data.cpp プロジェクト: chrismullins/cgma
double PST_Edge::closest_on_line( const CubitVector& B2, 
                                  const CubitVector& M2 )
{
  CubitVector B1 = start_coord();
  CubitVector M1 = direction();
  
  if( M1.length_squared() < RESABS_SQR )
    return 0.0;
  
  if( M2.length_squared() < RESABS_SQR )
    return closest_on_line( B2 );
  
  CubitVector cross = M2 * M1;
  if( cross.length_squared() < CUBIT_RESABS ) //parallel
    return 0.0;
  
  CubitVector N = M2 * cross;
  double      D = -( N % B2 );
  return -( N % B1 + D ) / ( N % M1 );
}
コード例 #4
0
ファイル: PointGridSearch.cpp プロジェクト: chrismullins/cgma
void PointGridSearch::get_neighborhood_points_sorted(
  DLIList<CubitPoint*> &point_list,
  const CubitVector& center, double cut_off)
{
  point_list.clean_out();
  DLIList<CubitPoint*> temp_point_list;
  int i;

  for (int k = boundingCellMinimumZ; k <= boundingCellMaximumZ; k++)
  {
    int kn = numberGridCellsY * k;
    for (int j = boundingCellMinimumY; j <= boundingCellMaximumY; j++)
    {
      int jn = numberGridCellsX * (kn + j);
      for ( i = boundingCellMinimumX; i <= boundingCellMaximumX; i++)
      {
	int in = jn + i;
        if (neighborhoodList[in])
        {
          temp_point_list += *(neighborhoodList[in]);
        }
      }
    }
  }

  // evaluate point distance to center ... remove those larger than cut_off
  SDLByDouble sorted_index_list;
  IndexedDouble *ID;  
  CubitVector vec;
  cut_off *= cut_off;
  temp_point_list.reset();
  for ( i = 0; i < temp_point_list.size(); i++)
  {
    vec = center - temp_point_list.get_and_step()->coordinates();
    double distance = vec.length_squared();
    if (distance < cut_off)
    {
      ID = new IndexedDouble( i, distance );
      sorted_index_list.append( ID );
    }
  }

  sorted_index_list.sort();
  temp_point_list.reset();
  for ( i = 0; i < sorted_index_list.size(); i++ )
  {
    ID = sorted_index_list.get_and_step();
    point_list.append( temp_point_list.next( ID->index() ) );
    delete ID;
  }
}
コード例 #5
0
ファイル: Faceter.cpp プロジェクト: chrismullins/cgma
void Faceter::max_min_edge_ratio( DLIList <DLIList <CubitPoint*>*> &boundary_point_loops,
                                  double &ratio,
                                  double &cell_size)
{
  double max_edge_length = CUBIT_DBL_MIN;
  double min_edge_length = CUBIT_DBL_MAX;
  double sum = 0.0;
  int total_count = 0;
  DLIList<CubitPoint*> *loopPtr;
  CubitPoint *node1, *node2;
  CubitVector edge;
  for (int i = boundary_point_loops.size(); i > 0; i--) {
    loopPtr = boundary_point_loops.get_and_step();
    node2 = loopPtr->prev();
    for (int j = loopPtr->size(); j > 0; j--) {
      node1 = node2;
      node2 = loopPtr->get_and_step();
      CubitVector p1 = node1->coordinates();
      CubitVector p2 = node2->coordinates();
      edge = p2-p1;
      double edge_length = edge.length_squared();
      if (edge_length > max_edge_length) max_edge_length = edge_length;
      if (edge_length < min_edge_length) min_edge_length = edge_length;
      total_count++;
      sum += edge_length;
    }
  }

  if (min_edge_length > CUBIT_RESABS) {
    ratio = sqrt(max_edge_length/min_edge_length);
  }
  else {
    ratio = sqrt(max_edge_length);
  }
  if ( total_count > 0 && sum > 0 )
    cell_size = sqrt(sum/total_count);
  else
    cell_size = 0.0;
}