[vtkusers] My interactor style doesn't work
kenichiro yoshimi
rccm.kyoshimi at gmail.com
Sat Oct 21 08:36:00 EDT 2017
Hello,
It seems to work to change as follows:
#include <vtkSmartPointer.h>
#include <vtkImageViewer2.h>
#include <vtkInteractorStyleImage.h>
#include <vtkDICOMImageReader.h>
#include <vtkObjectFactory.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
class MyStyle : public vtkInteractorStyleImage {
public:
static MyStyle* New();
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();
}
};
vtkStandardNewMacro(MyStyle);
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];
// Read all the DICOM files in the specified directory.
vtkSmartPointer<vtkDICOMImageReader> reader =
vtkSmartPointer<vtkDICOMImageReader>::New();
reader->SetFileName(inputFilename.c_str());
reader->Update();
// Visualize
vtkSmartPointer<vtkImageViewer2> imageViewer =
vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection(reader->GetOutputPort());
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<MyStyle> style = vtkSmartPointer<MyStyle>::New();
imageViewer->SetupInteractor(renderWindowInteractor);
imageViewer->Render();
imageViewer->GetRenderer()->ResetCamera();
imageViewer->Render();
renderWindowInteractor->SetInteractorStyle(style);
style->SetDefaultRenderer(imageViewer->GetRenderer());
style->SetCurrentRenderer(imageViewer->GetRenderer());
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
Hope that helps you.
2017-10-21 20:42 GMT+09:00 arwtyxouymz <arw.tyx-ouy_mz at ezweb.ne.jp>:
> 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
> _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list