Common/DataModel/vtkUnstructuredGrid.cxx
//----------------------------------------------------------------------------
// Return the cells that use the ptIds provided. This is a set (intersection)
// operation - it can have significant performance impacts on certain filters
// like vtkGeometryFilter. It would be nice to make this faster.
Return the cells that use the ptIds provided. This is a set (intersection)
operation - it can have significant performance impacts on certain filters
like vtkGeometryFilter. It would be nice to make this faster.
Return the cells that use the ptIds provided . This is a set ( intersection ) operation - it can have significant performance impacts on certain filters like vtkGeometryFilter . It would be nice to make this faster .
void vtkUnstructuredGrid::GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
                                           vtkIdList *cellIds)
{
  if ( ! this->Links )
  {
    this->BuildLinks();
  }
  cellIds->Reset();
  vtkIdType numPts = ptIds->GetNumberOfIds();
  if (numPts <= 0)
  {
    return;
  }
  vtkIdType numCells, ptId, *pts = ptIds->GetPointer(0);
  int minNumCells = VTK_INT_MAX;
  vtkIdType *minCells = nullptr;
  vtkIdType minPtId = 0;
  if ( ! this->Editable )
  {
    vtkStaticCellLinks *links =
      static_cast<vtkStaticCellLinks*>(this->Links);
    for (auto i=0; i<numPts; ++i)
    {
      ptId = pts[i];
      numCells = links->GetNcells(ptId);
      if ( numCells < minNumCells )
      {
        minNumCells = numCells;
        minPtId = ptId;
      }
    }
    minCells = links->GetCells(minPtId);
  }
  else
  {
    vtkCellLinks *links =
      static_cast<vtkCellLinks*>(this->Links);
    for (auto i=0; i<numPts; ++i)
    {
      ptId = pts[i];
      numCells = links->GetNcells(ptId);
      if ( numCells < minNumCells )
      {
        minNumCells = numCells;
        minPtId = ptId;
      }
    }
    minCells = links->GetCells(minPtId);
  }
  bool match;
  for (auto i=0; i<minNumCells; ++i)
  {
    if ( minCells[i] != cellId ) 
    {
      vtkIdType *cellPts;
      vtkIdType npts;
      this->GetCellPoints(minCells[i],npts,cellPts);
      match=true;
      for (auto j=0; j<numPts && match; ++j) 
      {
        if ( pts[j] != minPtId ) 
        {
          match=false;
          for (auto k=0; k<npts; ++k) 
          {
            if ( pts[j] == cellPts[k] )
            {
              match = true; 
              break;
            }
          }
        }
      }
      if ( match )
      {
        cellIds->InsertNextId(minCells[i]);
      }
    }
  }
}
void vtkUnstructuredGrid :: GetCellNeighbors ( vtkIdType cellId , vtkIdList * ptIds , vtkIdList * cellIds ) { if ( ! this -> Links ) { this -> BuildLinks ( ) ; } cellIds -> Reset ( ) ; vtkIdType numPts = ptIds -> GetNumberOfIds ( ) ; if ( numPts <= 0 ) { return ; } vtkIdType numCells , ptId , * pts = ptIds -> GetPointer ( 0 ) ; int minNumCells = VTK_INT_MAX ; vtkIdType * minCells = nullptr ; vtkIdType minPtId = 0 ; if ( ! this -> Editable ) { vtkStaticCellLinks * links = static_cast < vtkStaticCellLinks * > ( this -> Links ) ; for ( auto i = 0 ; i < numPts ; ++ i ) { ptId = pts [ i ] ; numCells = links -> GetNcells ( ptId ) ; if ( numCells < minNumCells ) { minNumCells = numCells ; minPtId = ptId ; } } minCells = links -> GetCells ( minPtId ) ; } else { vtkCellLinks * links = static_cast < vtkCellLinks * > ( this -> Links ) ; for ( auto i = 0 ; i < numPts ; ++ i ) { ptId = pts [ i ] ; numCells = links -> GetNcells ( ptId ) ; if ( numCells < minNumCells ) { minNumCells = numCells ; minPtId = ptId ; } } minCells = links -> GetCells ( minPtId ) ; } bool match ; for ( auto i = 0 ; i < minNumCells ; ++ i ) { if ( minCells [ i ] != cellId ) { vtkIdType * cellPts ; vtkIdType npts ; this -> GetCellPoints ( minCells [ i ] , npts , cellPts ) ; match = true ; for ( auto j = 0 ; j < numPts && match ; ++ j ) { if ( pts [ j ] != minPtId ) { match = false ; for ( auto k = 0 ; k < npts ; ++ k ) { if ( pts [ j ] == cellPts [ k ] ) { match = true ; break ; } } } } if ( match ) { cellIds -> InsertNextId ( minCells [ i ] ) ; } } } }
Return the cells that use the ptIds provided.
Return the cells that use the ptIds provided .
// Ensure links are built. // Ensure that a proper neighborhood request is made. // Find the point used by the fewest number of cells as a starting set. // Note the explicit cast to locator type. Several experiments were // undertaken using virtual methods, switch statements, etc. but there were // significant performance impacts. This includes using different // instantiations of vtkStaticCellLinksTemplate<> of various types (to // reduce memory footprint) - the lesson learned is that the code here is // very sensitive to compiler optimizations so if you make changes, make // sure to test the impacts on performance. // Now for each cell, see if it contains all the points // in the ptIds list. If so, add the cellId to the neighbor list. //don't include current cell //for all pts in input cell //of course minPtId is contained by cell //for all points in candidate cell //a match was found //for all points in current cell //if not guaranteed match //for all points in input cell //if not the reference cell //for all candidate cells attached to point