[vtkusers] Pick & delete cell

Massinissa Bandou Massinissa.Bandou at USherbrooke.ca
Mon Feb 18 10:15:03 EST 2013


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.



More information about the vtkusers mailing list