//===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== #include "bbcreaVtkPointPicker.h" #include "bbcreaVtkPackage.h" #include #include #include #include #include #include #include #include namespace bbcreaVtk { creaVtkCallbackPointPicker::creaVtkCallbackPointPicker(void) { boxPointPicker = NULL; } void creaVtkCallbackPointPicker::setBox(PointPicker *box) { boxPointPicker = box; } void creaVtkCallbackPointPicker::Execute(vtkObject *caller, unsigned long, void*) { if (boxPointPicker!=NULL) { if (boxPointPicker->bbGetInputActive()==true) { vtkRenderWindowInteractor *iren = static_cast(caller); int *pos = iren->GetEventPosition(); vtkCellPicker *picker = vtkCellPicker::New(); picker->SetTolerance(0.0005); if (boxPointPicker->bbGetInputProp3D()!=NULL ) { picker->AddPickList( boxPointPicker->bbGetInputProp3D() ); picker->PickFromListOn(); } picker->Pick(pos[0], pos[1], 0, iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer() ); double point[3]; if(picker->GetCellId() != -1) { picker->GetPickPosition(point); std::vector vecPoint; vecPoint.push_back( point[0] ); vecPoint.push_back( point[1] ); vecPoint.push_back( point[2] ); boxPointPicker->bbSetOutputPoint( vecPoint ); boxPointPicker->bbSetOutputMesh( picker->GetProp3D() ); boxPointPicker->bbSetOutputPointId( picker->GetPointId() ); boxPointPicker->bbSetOutputCellId( picker->GetCellId() ); vtkDataSet *dataset = picker->GetDataSet(); if (strcmp(dataset->GetClassName(),"vtkPolyData")==0) { vtkPolyData *polydata = (vtkPolyData*)dataset; vtkPointData *pointdata = polydata->GetPointData(); vtkDataArray *dataarray; double *pValue; /* int i,size=pointdata->GetNumberOfArrays(); for(i=0;iGetArray(i); printf("EED creaVtkCallbackPointPicker::Execute dataarray=%s n=%ld p=%ld\n", dataarray->GetName(),dataarray->GetNumberOfValues() ,polydata->GetNumberOfPoints() ); } // for i */ dataarray = pointdata->GetNormals(); if (dataarray!=NULL) { pValue = dataarray->GetTuple3( picker->GetPointId() ); std::vector lstNormal; lstNormal.push_back(pValue[0]); lstNormal.push_back(pValue[1]); lstNormal.push_back(pValue[2]); boxPointPicker->bbSetOutputNormal( lstNormal ); } // if dataarray } // if ClassName boxPointPicker->bbSignalOutputModification(); } // if } // if Active } // if boxPoiintPicker /* { std::cout << "Pick position is: " << worldPosition[0] << " " << worldPosition[1] << " " << worldPosition[2] << endl; vtkSmartPointer ids = vtkSmartPointer::New()creaVtkCallbackPointPicker *callPicker; ids->SetNumberOfComponents(1); ids->InsertNextValue(picker->GetCellId()); vtkSmartPointer selectionNode = vtkSmartPointer::New(); selectionNode->SetFieldType(vtkSelectionNode::CELL); selectionNode->SetContentType(vtkSelectionNode::INDICES); selectionNode->SetSelectionList(ids); vtkSmartPointer selection = vtkSmartPointer::New(); selection->AddNode(selectionNode); vtkSmartPointer extractSelection = vtkSmartPointer::New(); #if VTK_MAJOR_VERSION <= 5 extractSelection->SetInput(0, this->Data); extractSelection->SetInput(1, selection); #else extractSelection->SetInputData(0, this->Data); extractSelection->SetInputData(1, selection); #endif extractSelection->Update(); // In selection vtkSmartPointer selected = vtkSmartPointer::New(); selected->ShallowCopy(extractSelection->GetOutput()); std::cout << "There are " << selected->GetNumberOfPoints() << " points in the selection." << std::endl; std::cout << "There are " << selected->GetNumberOfCells() << " cells in the selection." << std::endl; #if VTK_MAJOR_VERSION <= 5 selectedMapper->SetInputConnection( selected->GetProducerPort()); #else selectedMapper->SetInputData(selected); #endif selectedActor->SetMapper(selectedMapper); selectedActor->GetProperty()->EdgeVisibilityOn(); selectedActor->GetProperty()->SetEdgeColor(1,0,0); selectedActor->GetProperty()->SetLineWidth(3); this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(selectedActor); } */ } //-------------------------------------------------------- //-------------------------------------------------------- //-------------------------------------------------------- BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,PointPicker) BBTK_BLACK_BOX_IMPLEMENTATION(PointPicker,bbtk::AtomicBlackBox); //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void PointPicker::Process() { // THE MAIN PROCESSING METHOD BODY // Here we simply set the input 'In' value to the output 'Out' // And print out the output value // INPUT/OUTPUT ACCESSORS ARE OF THE FORM : // void bbSet{Input|Output}NAME(const TYPE&) // const TYPE& bbGet{Input|Output}NAME() const // Where : // * NAME is the name of the input/output // (the one provided in the attribute 'name' of the tag 'input') // * TYPE is the C++ type of the input/output // (the one provided in the attribute 'type' of the tag 'input') // bbSetOutputOut( bbGetInputIn() ); // std::cout << "Output value = " <SetTolerance(0.005); // picker->AddObserver("EndPickEvent", annotatePick) // iren = vtk.vtkRenderWindowInteractor() // iren.SetPicker(picker) /* creaVtkCallbackPointPicker *callPicker = creaVtkCallbackPointPicker::New(); picker->AddObserver( vtkCommand::EndPickEvent , callPicker ); picker->AddObserver( vtkCommand::StartPickEvent , callPicker ); picker->AddObserver( vtkCommand::MouseMoveEvent , callPicker ); bbGetInputRenderer()->GetRenderWindow()->GetInteractor()->SetPicker(picker); */ callPicker = creaVtkCallbackPointPicker::New(); callPicker->setBox( this ); } // if firsttime if (bbGetInputRenderer()!=NULL) { vtkRenderWindowInteractor *vrwi = bbGetInputRenderer()->GetRenderWindow()->GetInteractor(); vrwi->RemoveObserver( callPicker ); if (bbGetInputTypeEvent()==0) { // Nothing } else if (bbGetInputTypeEvent()==1) { vrwi->AddObserver( vtkCommand::MouseMoveEvent , callPicker ); } else if (bbGetInputTypeEvent()==2) { vrwi->AddObserver( vtkCommand::LeftButtonPressEvent , callPicker ); } else if (bbGetInputTypeEvent()==3) { #if VTK_MAJOR_VERSION >= 9 vrwi->AddObserver( vtkCommand::LeftButtonDoubleClickEvent , callPicker ); #else printf("EED Warnning! PointPicker LeftButtonPressEvent since vtk 9 \n"); #endif } // if TypeEvent // ....See vtkCommand EventIds } // if bbGetInputRenderer() // std::vector lstPoint; // lstPoint.push_back(0); // lstPoint.push_back(0); // lstPoint.push_back(1); // bbSetOutputPoint( lstPoint ); // BORRAME bbSetOutputPoint( bbGetInputDefaultPoint() ); // bbSetOutputMesh( NULL ); // Borrame bbSetOutputPointId( bbGetInputDefaultPointId() ); // bbSetOutputCellId( -1 ); // bbSetOutputNormal( lstPoint ); } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void PointPicker::bbUserSetDefaultValues() { // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX // Here we initialize the input 'In' to 0 // bbSetInputIn(0); bbSetInputActive(true); bbSetInputTypeEvent(0); bbSetInputDefaultPointId( -1 ); bbSetOutputMesh(NULL); bbSetOutputPointId(-1); bbSetOutputCellId(-1); firsttime=true; callPicker=NULL; bbSetInputProp3D(NULL); std::vector lstNormal; lstNormal.push_back(0); lstNormal.push_back(0); lstNormal.push_back(1); bbSetOutputNormal( lstNormal ); } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void PointPicker::bbUserInitializeProcessing() { // THE INITIALIZATION METHOD BODY : // Here does nothing // but this is where you should allocate the internal/output pointers // if any } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void PointPicker::bbUserFinalizeProcessing() { // THE FINALIZATION METHOD BODY : // Here does nothing // but this is where you should desallocate the internal/output pointers // if any } }// EO namespace bbcreaVtk