[vtkusers] Pick & delete cell

Alex Malyushytskyy alexmalvtk at gmail.com
Tue Feb 19 16:41:12 EST 2013


I have never done it, but here is an example which might or might not
help cause it is marked 'broken'
http://www.itk.org/Wiki/VTK/Examples/Cxx/Broken/PolyData/DeleteCells


On Mon, Feb 18, 2013 at 7:15 AM, Massinissa Bandou
<Massinissa.Bandou at usherbrooke.ca> wrote:
> Hello everyone,
>
> I'm trying to pick come cells on a mesh file and delete or remove them. But
> I'm having some trouble with the code. I don't know how to delete the
> selected cells from the extracted data. Is there any example or project I
> can refer to?
>
> I have the incomplete following code:
>
> class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
> {
> public:
>     static KeyPressInteractorStyle* New();
>     vtkTypeMacro(KeyPressInteractorStyle,vtkInteractorStyleTrackballCamera);
>
> virtual void OnKeyPress(){
>
>         std::string key = this->Interactor->GetKeySym();
>         if(key.compare("l")==0){
>             int* pos = this->GetInteractor()->GetEventPosition();
>             vtkSmartPointer<vtkCellPicker> picker =
> vtkSmartPointer<vtkCellPicker>::New();
>             picker->SetTolerance(0.0005);
>             picker->Pick(pos[0],pos[1],pos[2],this->GetCurrentRenderer());
>
>             if(picker->GetCellId() != -1){
>                 vtkSmartPointer<vtkIdTypeArray> ids =
> vtkSmartPointer<vtkIdTypeArray>::New();
>                 ids->SetNumberOfComponents(1);
>                 ids->InsertNextValue(picker->GetCellId());
>
>                 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,this->Data);
>                 extractSelection->SetInput(1,selection);
>                 extractSelection->Update();
>
>                 vtkSmartPointer<vtkUnstructuredGrid> selected =
> vtkSmartPointer<vtkUnstructuredGrid>::New();
>                 selected->ShallowCopy(extractSelection->GetOutput());
>
>                 vtkSmartPointer<vtkDataSetMapper> mapper =
> vtkSmartPointer<vtkDataSetMapper>::New();
>
> mapper->SetInputConnection(extractSelection->GetOutputPort());
>                 vtkSmartPointer<vtkActor> actor =
> vtkSmartPointer<vtkActor>::New();
>
>                 mapper->SetInputConnection(selected->GetProducerPort());
>                 actor->SetMapper(mapper);
>                 actor->GetProperty()->EdgeVisibilityOn();
>                 actor->GetProperty()->SetEdgeColor(1,0,0);
>                 actor->GetProperty()->SetLineWidth(3);
>
>
> this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(actor);
>             }
>             vtkInteractorStyleTrackballCamera::OnKeyPress();
>         }
>     }
>
>     vtkPolyData* Data;
>     vtkRenderer* Renderer;
> }
>
>
>
> void DataProcessing::ExtractCells(){
>
>         vtkSmartPointer<vtkOBJReader> obj =
> vtkSmartPointer<vtkOBJReader>::New();
>         obj->SetFileName(file);
>         obj->Update();
>
> //*********I have to write some codes to delete the selected
> cells**********//
> //*************************************************************//
>         vtkSmartPointer<vtkPolyDataMapper> Mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
>         Mapper->SetInputConnection(obj->GetOutputPort());
>         vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
>         actor->SetMapper(Mapper);
>
>         vtkSmartPointer<KeyPressInteractorStyle> style =
> vtkSmartPointer<KeyPressInteractorStyle>::New();
>         vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
>         style->Renderer = renderer;
>         style->SetDefaultRenderer(renderer);
>         style->Data = obj->GetOutput();
>
>         vtkSmartPointer<vtkRenderWindow> renderWindow =
> vtkSmartPointer<vtkRenderWindow>::New();
>         renderWindow->AddRenderer(renderer);
>         renderer->AddActor(actor);
>         renderer->ResetCamera();
>
>         iwidget.qvtkWidget->SetRenderWindow(renderWindow);
>         iwidget.qvtkWidget->GetInteractor()->SetInteractorStyle(style);
>         iwidget.qvtkWidget->update();
> }
>
>
> Any ideas, thanks for your help!!!
>
> Massi
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/Pick-delete-cell-tp5718594.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list