[vtkusers] Extracting cells from vtkImageData

majinsaha saiya-jin at yandex.ru
Wed Mar 29 18:42:55 EDT 2017


Hello!

I am trying to extract a certain number of cells from vtkImageData object
and make them a separate actor. If I had vtkPolyData instead, that would be
easy to do as follows:

vtkSmartPointer<vtkIdTypeArray> ids =
vtkSmartPointer<vtkIdTypeArray>::New();
ids->SetNumberOfComponents(1);

// TODO: Filling ids with the cell indices of interest

vtkSmartPointer<vtkSelectionNode> selectionNode =
vtkSmartPointer<vtkSelectionNode>::New();
selectionNode->SetFieldType(vtkSelectionNode::CELL);
selectionNode->SetContentType(vtkSelectionNode::INDICES);
selectionNode->SetSelectionList(ids);

vtkSmartPointer<vtkSelection> selection =
vtkSmartPointer<vtkSelection>::New();
selection->AddNode(selectionNode);

vtkSmartPointer<vtkExtractSelectedPolyDataIds> extractSelection =
vtkSmartPointer<vtkExtractSelectedPolyDataIds>::New();
extractSelection->SetInputData(0, myPolyData);
extractSelection->SetInputData(1, selection);
extractSelection->Update();

vtkSmartPointer<vtkPolyDataMapper> cellsMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
cellsMapper->SetInputData(extractSelection->GetOutput());

Is there a way to do it similarly for vtkImageData?

If not, I assume I should then transform vtkImageData to vtkPolyData to use
all the shown benefits, right? However, what is a nice and painless way to
do this transformation? I know there is ImageDataGeometryFilter that's
supposed to do it, but I've only seen how it works for sources such as here:


vtkSmartPointer<vtkImageCanvasSource2D> source1 = 
    vtkSmartPointer<vtkImageCanvasSource2D>::New();
  // TODO: DO SOMETHING WITH SOURCE

  // Convert the image to a polydata
  vtkSmartPointer<vtkImageDataGeometryFilter> imageDataGeometryFilter = 
    vtkSmartPointer<vtkImageDataGeometryFilter>::New();
  imageDataGeometryFilter->SetInputConnection(source1->GetOutputPort());
  imageDataGeometryFilter->Update();


Is there a way to attach vtkImageData itself to a pipeline like this instead
of a source? It doesn't have GetOutputPort() method so I can't seem to be
able to use this approach.

The answers to both questions are greatly appreciated!

P.S. I realize I can do this in brute-force way by remaking entire
vtkImageData from the selected cells, but that would take a long time. Don't
want to reinvent the wheel here.



--
View this message in context: http://vtk.1045678.n5.nabble.com/Extracting-cells-from-vtkImageData-tp5742666.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list