Ejemplo n.º 1
0
void mitk::ImageToUnstructuredGridFilter::
           ExtractPoints(const itk::Image<TPixel, VImageDimension>* image)
{
  typedef itk::Image<TPixel, VImageDimension> InputImageType;
  typename itk::ImageRegionConstIterator<InputImageType> it(image, image->GetRequestedRegion());

  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();

  it.GoToBegin();
  while( !it.IsAtEnd() )
  {
    if(it.Get() >= m_Threshold)
    {
      mitk::Point3D imagePoint;
      mitk::Point3D worldPoint;

      imagePoint[0] = it.GetIndex()[0];
      imagePoint[1] = it.GetIndex()[1];
      imagePoint[2] = it.GetIndex()[2];

      m_Geometry->IndexToWorld(imagePoint, worldPoint);

      points->InsertNextPoint(worldPoint[0],worldPoint[1],worldPoint[2]);
      m_NumberOfExtractedPoints++;
    }
    ++it;
  }

  vtkSmartPointer<vtkPolyVertex> verts = vtkSmartPointer<vtkPolyVertex>::New();

  verts->GetPointIds()->SetNumberOfIds(m_NumberOfExtractedPoints);
  for(int i=0; i<m_NumberOfExtractedPoints; i++)
  {
    verts->GetPointIds()->SetId(i,i);
  }

  vtkSmartPointer<vtkUnstructuredGrid> uGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();
  uGrid->Allocate(1);

  uGrid->InsertNextCell(verts->GetCellType(), verts->GetPointIds());
  uGrid->SetPoints(points);

  m_UnstructGrid->SetVtkUnstructuredGrid(uGrid);
}
Ejemplo n.º 2
0
std::vector<itk::Index<2> > Mask::GetHolePixelsInRegion(const itk::ImageRegion<2>& inputRegion) const
{
  itk::ImageRegion<2> region = inputRegion;
  region.Crop(this->GetLargestPossibleRegion());

  std::vector<itk::Index<2> > holePixels;

  typename itk::ImageRegionConstIterator<Mask> iterator(this, region);

  while(!iterator.IsAtEnd())
    {
    if(this->IsHole(iterator.GetIndex()))
      {
      holePixels.push_back(iterator.GetIndex());
      }

    ++iterator;
    }
  return holePixels;
}