[vtkusers] ButtonSource Callback does not fire

itkvtk123 at gmx.net itkvtk123 at gmx.net
Tue Nov 10 17:45:48 EST 2009


Hello vtkusers

I have two questions concerning the VTK interactors.

1.
I wrote the piece of code below to test the usage of the VTK buttons.
However, the callback seems not to fire when I click on the button.
Is it a problem with the interactor? How do I have to set it up that
the callback is fired when the button is clicked?

#include <vtkRectangularButtonSource.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkCamera.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>
#include "vtkJPEGReader.h"
#include "vtkTexture.h"
#include "vtkImageData.h"
#include "vtkCommand.h"
#include "vtkImageViewer2.h"

class ButtonCallback : public vtkCommand
{
public:
	static ButtonCallback *New()
	{
		return new ButtonCallback;
	}

	virtual void Execute(vtkObject* caller, unsigned long, void*)
	{
		cout << "event" << endl;
	}
};

void main()
{
	vtkRectangularButtonSource* button=vtkRectangularButtonSource::New();
	button->SetWidth(100);
	button->SetHeight(50);
	button->SetCenter(100.0, 100.0, 0.0);
	button->SetTextureStyleToFitImage();

	vtkJPEGReader* reader = vtkJPEGReader::New();
	reader->SetFileName("button.jpg");
	reader->Update();

	vtkTexture* texture = vtkTexture::New();
	texture->SetInputConnection(reader->GetOutputPort());
	int dims[3];
	reader->GetOutput()->GetDimensions(dims);
	button->SetTextureDimensions(dims[0], dims[1]);

	//Add Observer
	ButtonCallback* callback = ButtonCallback::New();
	button->AddObserver(vtkCommand::AnyEvent, callback);

	vtkPolyDataMapper *mapper=vtkPolyDataMapper::New();
	mapper->SetInput(button->GetOutput());

	vtkActor *actor=vtkActor::New();
	actor->SetMapper(mapper);
	actor->SetTexture(texture);

	vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
	vtkImageViewer2* viewer = vtkImageViewer2::New();
	//simply use same image for the viewer as for the button
	viewer->SetInput(reader->GetOutput());
	viewer->GetRenderer()->AddActor(actor);
	viewer->SetupInteractor(iren);
	viewer->Render();
	iren->Initialize();
	iren->Start();
}

2.
Is there a way to use multiple interactors in one render window?
I would like to have one interactor for my viewer (intensity windowing) and one interactor for my widgets.
This way you could use a widget to toggle the intensity windowing on and off.
(it is not possible with one interactor since if you toggle the intensity windowing off,
you are not able to reactivate it anymore, because you cannot interact with the widgets anymore as well)
I tried to add two interactors, but the second one is not active because I can only call iren1->Start() on the first one (the code execution stops at this point so there is no way of calling iren2->Start() ).

Regards
-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01



More information about the vtkusers mailing list