Hello, I want to extract cells using two specified points. I was looking into vtkPolyData and I found the function GetPointCells, but that is only for one point. And I need it for two points instead of one.<br><br>So I used this example : <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/ExtractCellsUsingPoints">http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/ExtractCellsUsingPoints</a><br>
<br>I modified a little, instead of working with a spheresource I try to make it work with a triangle strip (taken from this example : <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/TriangleStrip">http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/TriangleStrip</a> )<br>
<br>In this last example, there are 2 triangles, and (as in the code is showed), I want the cell that uses the point 0.<div>But as shown in the result, it returns the 2 triangles instead of only one.<br><div><br></div><div>
Maybe it is because the vtkTriangleStrip ? Is ok my idea?</div><div><br></div><div><br></div><div>Thank you.!</div><div><br></div><div><br></div><div><br></div><div><div>#include <vtkVersion.h></div><div>#include <vtkSmartPointer.h></div>
<div>#include <vtkInformation.h></div><div>#include <vtkSphereSource.h></div><div>#include <vtkExtractSelection.h></div><div>#include <vtkSelection.h></div><div>#include <vtkSelectionNode.h></div>
<div>#include <vtkPolyData.h></div><div>#include <vtkUnstructuredGrid.h></div><div>#include <vtkIdTypeArray.h></div><div>#include <vtkDataSetMapper.h></div><div>#include <vtkProperty.h></div>
<div>#include <vtkRenderWindow.h></div><div>#include <vtkRenderWindowInteractor.h></div><div>#include <vtkRenderer.h></div><div>#include <vtkSphereSource.h></div><div>#include <vtkVertexGlyphFilter.h></div>
<div>#include <vtkTriangleStrip.h></div><div>#include <vtkCellArray.h></div><div><br></div><div>#include <vtkActor.h></div><div>#include <vtkDataSetMapper.h></div><div>#include <vtkPoints.h></div>
<div><br></div><div> </div><div>int main(int, char *[])</div><div>{</div><div><br></div><div> vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();</div><div> points->InsertNextPoint(0,0,0);</div>
<div> points->InsertNextPoint(0,1,0);</div><div> points->InsertNextPoint(1,0,0);</div><div> points->InsertNextPoint(1.5,1,0);</div><div> </div><div> vtkSmartPointer<vtkTriangleStrip> triangleStrip = vtkSmartPointer<vtkTriangleStrip>::New();</div>
<div> triangleStrip->GetPointIds()->SetNumberOfIds(4);</div><div> triangleStrip->GetPointIds()->SetId(0,0);</div><div> triangleStrip->GetPointIds()->SetId(1,1);</div><div> triangleStrip->GetPointIds()->SetId(2,2);</div>
<div> triangleStrip->GetPointIds()->SetId(3,3);</div><div> </div><div> vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();</div><div> cells->InsertNextCell(triangleStrip);</div>
<div> </div><div> vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();</div><div> polydata->SetPoints(points);</div><div> polydata->SetStrips(cells);</div><div><br></div><div>
vtkSmartPointer<vtkIdTypeArray> ids = vtkSmartPointer<vtkIdTypeArray>::New();</div>
<div> ids->SetNumberOfComponents(1);</div><div> ids->InsertNextValue(0);</div><div> </div><div><br></div><div> vtkSmartPointer<vtkSelectionNode> selectionNode =</div><div> vtkSmartPointer<vtkSelectionNode>::New();</div>
<div> selectionNode->SetFieldType(vtkSelectionNode::POINT);</div><div> selectionNode->SetContentType(vtkSelectionNode::INDICES);</div><div> selectionNode->SetSelectionList(ids);</div><div> selectionNode->GetProperties()->Set(vtkSelectionNode::CONTAINING_CELLS(), 1);</div>
<div> </div><div> vtkSmartPointer<vtkSelection> selection =</div><div> vtkSmartPointer<vtkSelection>::New();</div><div> selection->AddNode(selectionNode);</div><div> </div><div> vtkSmartPointer<vtkExtractSelection> extractSelection = vtkSmartPointer<vtkExtractSelection>::New();</div>
<div> extractSelection->SetInput(0, polydata);</div><div>#if VTK_MAJOR_VERSION <= 5</div><div> extractSelection->SetInput(1, selection);</div><div>#else</div><div> extractSelection->SetInputData(1, selection);</div>
<div>#endif</div><div> extractSelection->Update();</div><div> </div><div> // In selection</div><div> vtkSmartPointer<vtkUnstructuredGrid> selected =</div><div> vtkSmartPointer<vtkUnstructuredGrid>::New();</div>
<div> selected->ShallowCopy(extractSelection->GetOutput());</div><div> </div><div> std::cout << "There are " << selected->GetNumberOfPoints()</div><div> << " points in the selection." << std::endl;</div>
<div> std::cout << "There are " << selected->GetNumberOfCells()</div><div> << " cells in the selection." << std::endl;</div><div> </div><div> // Get points that are NOT in the selection</div>
<div> selectionNode->GetProperties()->Set(vtkSelectionNode::INVERSE(), 1); //invert the selection</div><div> extractSelection->Update();</div><div> </div><div> vtkSmartPointer<vtkUnstructuredGrid> notSelected =</div>
<div> vtkSmartPointer<vtkUnstructuredGrid>::New();</div><div> notSelected->ShallowCopy(extractSelection->GetOutput());</div><div> </div><div> std::cout << "There are " << notSelected->GetNumberOfPoints()</div>
<div> << " points NOT in the selection." << std::endl;</div><div> std::cout << "There are " << notSelected->GetNumberOfCells()</div><div> << " cells NOT in the selection." << std::endl;</div>
<div> </div><div> vtkSmartPointer<vtkDataSetMapper> inputMapper =</div><div> vtkSmartPointer<vtkDataSetMapper>::New();</div><div> inputMapper->SetInput(polydata);</div><div> vtkSmartPointer<vtkActor> inputActor =</div>
<div> vtkSmartPointer<vtkActor>::New();</div><div> inputActor->SetMapper(inputMapper);</div><div> </div><div> vtkSmartPointer<vtkDataSetMapper> selectedMapper =</div><div> vtkSmartPointer<vtkDataSetMapper>::New();</div>
<div>#if VTK_MAJOR_VERSION <= 5</div><div> selectedMapper->SetInputConnection(selected->GetProducerPort());</div><div>#else</div><div> selectedMapper->SetInputData(selected);</div><div>#endif</div><div> vtkSmartPointer<vtkActor> selectedActor =</div>
<div> vtkSmartPointer<vtkActor>::New();</div><div> selectedActor->SetMapper(selectedMapper);</div><div> </div><div> vtkSmartPointer<vtkDataSetMapper> notSelectedMapper =</div><div> vtkSmartPointer<vtkDataSetMapper>::New();</div>
<div>#if VTK_MAJOR_VERSION <= 5</div><div> notSelectedMapper->SetInputConnection(notSelected->GetProducerPort());</div><div>#else</div><div> notSelectedMapper->SetInputData(notSelected);</div><div>#endif</div>
<div> vtkSmartPointer<vtkActor> notSelectedActor =</div><div> vtkSmartPointer<vtkActor>::New();</div><div> notSelectedActor->SetMapper(notSelectedMapper);</div><div> </div><div> // There will be one render window</div>
<div> vtkSmartPointer<vtkRenderWindow> renderWindow =</div><div> vtkSmartPointer<vtkRenderWindow>::New();</div><div> renderWindow->SetSize(900, 300);</div><div> </div><div> // And one interactor</div>
<div> vtkSmartPointer<vtkRenderWindowInteractor> interactor =</div><div> vtkSmartPointer<vtkRenderWindowInteractor>::New();</div><div> interactor->SetRenderWindow(renderWindow);</div><div> </div><div>
// Define viewport ranges</div>
<div> // (xmin, ymin, xmax, ymax)</div><div> double leftViewport[4] = {0.0, 0.0, 0.5, 1.0};</div><div> double centerViewport[4] = {0.33, 0.0, .66, 1.0};</div><div> double rightViewport[4] = {0.66, 0.0, 1.0, 1.0};</div>
<div> </div><div> // Setup the renderers</div><div> vtkSmartPointer<vtkRenderer> leftRenderer =</div><div> vtkSmartPointer<vtkRenderer>::New();</div><div> renderWindow->AddRenderer(leftRenderer);</div>
<div> leftRenderer->SetViewport(leftViewport);</div><div> leftRenderer->SetBackground(.6, .5, .4);</div><div> </div><div> vtkSmartPointer<vtkRenderer> centerRenderer =</div><div> vtkSmartPointer<vtkRenderer>::New();</div>
<div> renderWindow->AddRenderer(centerRenderer);</div><div> centerRenderer->SetViewport(centerViewport);</div><div> centerRenderer->SetBackground(.3, .1, .4);</div><div> </div><div> vtkSmartPointer<vtkRenderer> rightRenderer =</div>
<div> vtkSmartPointer<vtkRenderer>::New();</div><div> renderWindow->AddRenderer(rightRenderer);</div><div> rightRenderer->SetViewport(rightViewport);</div><div> rightRenderer->SetBackground(.4, .5, .6);</div>
<div> </div><div> leftRenderer->AddActor(inputActor);</div><div> centerRenderer->AddActor(selectedActor);</div><div> rightRenderer->AddActor(notSelectedActor);</div><div> </div><div> leftRenderer->ResetCamera();</div>
<div> centerRenderer->ResetCamera();</div><div> rightRenderer->ResetCamera();</div><div> </div><div> renderWindow->Render();</div><div> interactor->Start();</div><div> </div><div> return EXIT_SUCCESS;</div>
<div>}</div><div><br></div><div><br></div>-- <br>--------<br>Gonzalo Amadio<br><br>
</div></div>