Пример #1
0
MatrixIr CellPartition::get_cell_faces(const size_t cell_id) const {
    const size_t num_faces = m_faces.rows();
    std::vector<VectorI> cell_faces;
    for (size_t i=0; i<num_faces; i++) {
        const size_t patch_id = m_patches[i];
        if (m_cells(patch_id,0) == cell_id) {
            cell_faces.push_back(m_faces.row(i).reverse());
        } else if (m_cells(patch_id,1) == cell_id) {
            cell_faces.push_back(m_faces.row(i));
        }
    }
    MatrixIr faces = MatrixUtils::rowstack(cell_faces);
    return faces;
}
void AccelerationGrid::add_element(size_t idx, const Vec3d& xmin, const Vec3d& xmax)
{
    if(m_elementidxs.size() <= idx)
    {
        m_elementidxs.resize(idx+1);
        m_elementxmins.resize(idx+1);
        m_elementxmaxs.resize(idx+1);
        m_elementquery.resize(idx+1);
    }
    
    m_elementxmins[idx] = xmin;
    m_elementxmaxs[idx] = xmax;
    m_elementquery[idx] = 0;
    
    Vec3i xmini, xmaxi;
    boundstoindices(xmin, xmax, xmini, xmaxi);
    
    for(int i = xmini[0]; i <= xmaxi[0]; i++)
    {
        for(int j = xmini[1]; j <= xmaxi[1]; j++)
        {
            for(int k = xmini[2]; k <= xmaxi[2]; k++)
            {
                std::vector<size_t>*& cell = m_cells(i, j, k);
                if(!cell)
                    cell = new std::vector<size_t>();
                
                cell->push_back(idx);
                m_elementidxs[idx].push_back(Vec3st(i, j, k));
            }
        }
    }
}
Пример #3
0
void AccelerationGrid::find_overlapping_elements( const Vec3d& xmin, const Vec3d& xmax, std::vector<unsigned int>& results ) 
{
   if(m_lastquery == std::numeric_limits<unsigned int>::max())
   {
      std::vector<unsigned int>::iterator iter = m_elementquery.begin();
      for( ; iter != m_elementquery.end(); ++iter )
      {
         *iter = 0;
      }
      m_lastquery = 0;
   }

   ++m_lastquery;
   
   results.clear();
      
   Vec3i xmini, xmaxi;
   boundstoindices(xmin, xmax, xmini, xmaxi);
   
   for(int i = xmini[0]; i <= xmaxi[0]; ++i)
   {
      for(int j = xmini[1]; j <= xmaxi[1]; ++j)
      {
         for(int k = xmini[2]; k <= xmaxi[2]; ++k)
         {
            std::vector<unsigned int>* cell = m_cells(i, j, k);
            
            if(cell)
            {
               for( std::vector<unsigned int>::const_iterator citer = cell->begin(); citer != cell->end(); ++citer)
               {
                  unsigned int oidx = *citer;
                  
                  // Check if the object has already been found during this query
                  
                  if(m_elementquery[oidx] < m_lastquery)
                  {
                     
                     // Object has not been found.  Set m_elementquery so that it will not be tested again during this query.
                     
                     m_elementquery[oidx] = m_lastquery;
                  
                     const Vec3d& oxmin = m_elementxmins[oidx];
                     const Vec3d& oxmax = m_elementxmaxs[oidx];
                     
                     if( (xmin[0] <= oxmax[0] && xmin[1] <= oxmax[1] && xmin[2] <= oxmax[2]) &&
                         (xmax[0] >= oxmin[0] && xmax[1] >= oxmin[1] && xmax[2] >= oxmin[2]) )
                     {
                        results.push_back(oidx);
                     }
                  
                  }
               }
            }
            
         }
      }
   }
}
Пример #4
0
void AccelerationGrid::remove_element(unsigned int idx)
{
   for(unsigned int c = 0; c < m_elementidxs[idx].size(); c++)
   {
      Vec3ui cellcoords = m_elementidxs[idx][c];
      std::vector<unsigned int>* cell = m_cells(cellcoords[0], cellcoords[1], cellcoords[2]);
      
      std::vector<unsigned int>::iterator it = cell->begin();
      while(*it != idx)
      {
         it++;
      }
      
      cell->erase(it);
   }
   
   m_elementidxs[idx].clear();
}
void AccelerationGrid::remove_element(size_t idx)
{
    
    if ( idx >= m_elementidxs.size() ) { return; }
    
    for(size_t c = 0; c < m_elementidxs[idx].size(); c++)
    {
        Vec3st cellcoords = m_elementidxs[idx][c];
        std::vector<size_t>* cell = m_cells(cellcoords[0], cellcoords[1], cellcoords[2]);
        
        std::vector<size_t>::iterator it = cell->begin();
        while(*it != idx)
        {
            it++;
        }
        
        cell->erase(it);
    }
    
    m_elementidxs[idx].clear();
}