X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=bbtk_creaVtk_PKG%2Fsrc%2FbbcreaVtkPointPicker.cxx;fp=bbtk_creaVtk_PKG%2Fsrc%2FbbcreaVtkPointPicker.cxx;h=03181ce549a755723c5c5fe0dacbb91cfe21d42d;hb=89f100d62b34e0248551ba2ce51de2c1ec7aa890;hp=0000000000000000000000000000000000000000;hpb=175699379042403d48be1c75d24a6aa9308eb2c1;p=creaVtk.git diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.cxx new file mode 100644 index 0000000..03181ce --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.cxx @@ -0,0 +1,200 @@ +//===== +// 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 + +namespace bbcreaVtk +{ + + + +void creaVtkCallbackPointPicker::Execute(vtkObject *caller, unsigned long, void*) +{ + printf("creaVtkCallbackPointPicker EED Picker\n"); + vtkRenderWindowInteractor *iren = static_cast(caller); + + int* pos = iren->GetEventPosition(); + vtkCellPicker *picker = vtkCellPicker::New(); + picker->SetTolerance(0.0005); + picker->Pick(pos[0], pos[1], 0, iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer() ); + + if(picker->GetCellId() != -1) + { + printf("creaVtkCallbackPointPicker EED picker OK\n"); + } else { + printf("creaVtkCallbackPointPicker EED picker --\n"); + } // if + + +/* +{ + + std::cout << "Pick position is: " << worldPosition[0] << " " << worldPosition[1] + << " " << worldPosition[2] << endl; + + vtkSmartPointer ids = + vtkSmartPointer::New(); + 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); +*/ + + creaVtkCallbackPointPicker *callPicker = creaVtkCallbackPointPicker::New(); + callPicker->_renderer = bbGetInputRenderer(); + vtkRenderWindowInteractor *vrwi = bbGetInputRenderer()->GetRenderWindow()->GetInteractor(); + vrwi->AddObserver( vtkCommand::EndPickEvent , callPicker ); + vrwi->AddObserver( vtkCommand::StartPickEvent , callPicker ); + vrwi->AddObserver( vtkCommand::MouseMoveEvent , callPicker ); + + } // if firsttime + +} +//===== +// 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); + + firsttime=true; +} +//===== +// 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 + +