[vtkusers] My interactor style doesn't work
arwtyxouymz
arw.tyx-ouy_mz at ezweb.ne.jp
Sat Oct 21 07:42:01 EDT 2017
Hi,
I'm trying to create my style subclass of vtkInteractorStyleImage.
I want to callback click event and mouse move event.
I referred to this example to display my dicom image,
https://lorensen.github.io/VTKExamples/site/Cxx/IO/ReadDICOM/
and referred to this to create my style class.
https://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/MarkKeypoints
DICOM image appear, but my mouse event does not work.
Following my code:
class MyStyle : public vtkInteractorStyleImage {
public:
static MyStyle* New() {
return nullptr;
}
vtkTypeMacro(MyStyle, vtkInteractorStyleImage);
void OnLeftButtonDown() override {
std::cout << "Left Button Clicked!" << std::endl;
vtkInteractorStyleImage::OnLeftButtonDown();
}
void OnMouseMove() override {
std::cout << "Mouse Moving!" << std::endl;
vtkInteractorStyleImage::OnMouseMove();
}
};
int main(int argc, char** argv) {
// Verify input arguments
if ( argc != 2 )
{
std::cout << "Usage: " << argv[0]
<< " Filename(.img)" << std::endl;
return EXIT_FAILURE;
}
std::string inputFilename = argv[1];
vtkSmartPointer<vtkDICOMImageReader> reader =
vtkSmartPointer<vtkDICOMImageReader>::New();
reader->SetFileName(inputFilename.c_str());
reader->Update();
vtkSmartPointer<vtkImageViewer2> imageViewer =
vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection(reader->GetOutputPort());
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<MyStyle> style = vtkSmartPointer<MyStyle>::New();
renderWindowInteractor->SetInteractorStyle( style );
imageViewer->SetupInteractor(renderWindowInteractor);
imageViewer->Render();
imageViewer->GetRenderer()->ResetCamera();
imageViewer->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
How change my code?
please help me!
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
More information about the vtkusers
mailing list