|
|
(14 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
− | ==ExtractSelectionCells.cxx== | + | = '''See [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ExtractSelectionCells ExtractSelectionCells] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' = |
− | <source lang="cpp">
| |
− | #include <vtkSmartPointer.h>
| |
− | #include <vtkInformation.h>
| |
− | #include <vtkPointSource.h>
| |
− | #include <vtkExtractSelection.h>
| |
− | #include <vtkSelection.h>
| |
− | #include <vtkSelectionNode.h>
| |
− | #include <vtkPolyData.h>
| |
− | #include <vtkUnstructuredGrid.h>
| |
− | #include <vtkIdTypeArray.h>
| |
− | | |
− | int main(int argc, char *argv[])
| |
− | {
| |
− | vtkSmartPointer<vtkPointSource> pointSource =
| |
− | vtkSmartPointer<vtkPointSource>::New();
| |
− | pointSource->SetNumberOfPoints(50);
| |
− | pointSource->Update();
| |
− |
| |
− | cout << "There are " << pointSource->GetOutput()->GetNumberOfPoints() << " input points." << endl;
| |
− |
| |
− | vtkSmartPointer<vtkIdTypeArray> ids =
| |
− | vtkSmartPointer<vtkIdTypeArray>::New();
| |
− | ids->SetNumberOfComponents(1);
| |
− |
| |
− | //set values
| |
− | for(unsigned int i = 10; i < 20; i++)
| |
− | {
| |
− | ids->InsertNextValue(i);
| |
− | }
| |
− |
| |
− | 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<vtkExtractSelection> extractSelection =
| |
− | vtkSmartPointer<vtkExtractSelection>::New();
| |
− |
| |
− | //extractSelection->SetInput(0, selection);
| |
− | //extractSelection->SetInput(1, pointSource->GetOutput());
| |
− |
| |
− | extractSelection->SetInput(0, pointSource->GetOutput());
| |
− | extractSelection->SetInput(1, selection);
| |
− |
| |
− | extractSelection->Update();
| |
− |
| |
− | //in selection
| |
− | vtkDataSet* ds = vtkDataSet::SafeDownCast (extractSelection->GetOutput());
| |
− | cout << "There are " << ds->GetNumberOfPoints() << " points in the selection." << endl;
| |
− | cout << "There are " << ds->GetNumberOfCells() << " cells in the selection." << endl;
| |
− |
| |
− | //not in selection
| |
− | selectionNode->GetProperties()->Set(vtkSelectionNode::INVERSE(), 1); //invert the selection
| |
− | extractSelection->Update();
| |
− | cout << "There are " << vtkDataSet::SafeDownCast (extractSelection->GetOutput())->GetNumberOfPoints() << " points not in the selection." << endl;
| |
− |
| |
− | return EXIT_SUCCESS;
| |
− | }
| |
− | | |
− | </source>
| |
− | | |
− | ==CMakeLists.txt==
| |
− | <source lang="cmake">
| |
− | cmake_minimum_required(VERSION 2.6)
| |
− | PROJECT(ExtractSelection)
| |
− | | |
− | FIND_PACKAGE(VTK REQUIRED)
| |
− | INCLUDE(${VTK_USE_FILE})
| |
− | | |
− | ADD_EXECUTABLE(ExtractSelectionCells ExtractSelectionCells.cxx)
| |
− | TARGET_LINK_LIBRARIES(ExtractSelectionCells vtkHybrid)
| |
− | | |
− | </source>
| |