Vtk juce and OpenGLComponent

Hi,
I’m trying to integrate vtk inside Juce (using OpenGLComponent) but when i’m moving vtk objects with my mouse, at some point, Juce application event doesn’t work fine. (i’ve only tested it with linux)

the vtk-juce component is built using Glut style, but by example (included in .tgz file) Fast Light Toolkit vtk component (FlvtkRenderWindowInteractor) uses DisplayId (only in linux) and WindowId (linux mac and windows). Is there any method to obtain DisplayId? I think Fl implementation is cleaner than mine.

here is the link:
http://mkarmona2.dnsalias.com/vtkJuce.tgz


and the screenshot link:
http://mkarmona2.dnsalias.com/sshot.png

so, could somebody help me?

thanks!

Here, a component to use vtkJuce:

vtkCanvas:

#include <juce_Config.h>
#include <juce.h>
#include "vtkJuceRenderWindowInteractor.h"
class vtkCanvas : public Component {
		public:
			vtkCanvas();
			virtual ~vtkCanvas();

			// events
			void resized();


		private:
			vtkJuceRenderWindowInteractor *iren;
			Toolbar *tbar;

			vtkCanvas(const vtkCanvas &canvas); // not implemented
			void operator=(const vtkCanvas &canvas); // not implemented
			
	};

and the implementation:


#include <vtkConeSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyDataNormals.h>
#include <vtkRenderWindow.h>
#include <vtkVolume16Reader.h>
#include <vtkOutlineFilter.h>
#include <vtkContourFilter.h>
#include <vtkStripper.h>
#include <vtkLookupTable.h>
#include <vtkImageData.h>
#include <vtkImageMapToColors.h>
#include <vtkImageDataGeometryFilter.h>
#include <vtkProperty.h>
#include <vtkOpenGLRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCamera.h>
#include <vtkActor.h>
#include <vtkImageActor.h>
#include <vtkRenderer.h>
#include <vtkOpenGLRenderer.h>
#include <vtkCommand.h>
#include <vtkBoxWidget.h>
#include <vtkTransform.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkOrientationMarkerWidget.h>

#include "vtkCanvas.h"
#include <vtkJuceRenderWindowInteractor.h>
#include <vtkJuceOpenGLRenderWindow.h>


	vtkCanvas::vtkCanvas() {
/*
		vtkRenderer *aRen2 = vtkRenderer::New();
		aRen2->SetViewport(0.5,0.,1.0,1.0);
		aRen2->SetBackground(0.2,0.3,0.5);
*/

		vtkRenderer *aRenderer = vtkRenderer::New();
//			aRenderer->SetBackground(0.2,0.2,0.2);
		aRenderer->SetBackground(.2,.3,.5);
//				aRenderer->SetViewport(0.,0.,0.5,1.0);


		vtkJuceOpenGLRenderWindow *renWin = vtkJuceOpenGLRenderWindow::New();
		iren = vtkJuceRenderWindowInteractor::New();
		iren->SetRenderWindow(renWin);
		renWin->AddRenderer(aRenderer);
//				renWin->AddRenderer(aRen2);


		vtkVolume16Reader *v16 = vtkVolume16Reader::New();
			v16->SetDataDimensions(64,64);
			v16->SetDataByteOrderToLittleEndian();
			v16->SetFilePrefix ("/usr/share/VTKData/Data/headsq/quarter");
			v16->SetImageRange(1, 93);
			v16->SetDataSpacing (3.2, 3.2, 1.5);

		vtkContourFilter *skinExtractor = vtkContourFilter::New();
			skinExtractor->SetInputConnection( v16->GetOutputPort());
			skinExtractor->SetValue(0, 500);
		vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
			skinNormals->SetInputConnection(skinExtractor->GetOutputPort());
			skinNormals->SetFeatureAngle(60.0);
		vtkStripper *skinStripper = vtkStripper::New();
			skinStripper->SetInputConnection(skinNormals->GetOutputPort());
		vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
			skinMapper->SetInputConnection(skinStripper->GetOutputPort());
			skinMapper->ScalarVisibilityOff();
		vtkActor *skin = vtkActor::New();
			skin->SetMapper(skinMapper);
			skin->GetProperty()->SetDiffuseColor(1, .49, .25);
			skin->GetProperty()->SetSpecular(.3);
			skin->GetProperty()->SetSpecularPower(20);

		vtkContourFilter *boneExtractor = vtkContourFilter::New();
			boneExtractor->SetInputConnection(v16->GetOutputPort());
			boneExtractor->SetValue(0, 1150);
		vtkPolyDataNormals *boneNormals = vtkPolyDataNormals::New();
			boneNormals->SetInputConnection(boneExtractor->GetOutputPort());
			boneNormals->SetFeatureAngle(60.0);
		vtkStripper *boneStripper = vtkStripper::New();
			boneStripper->SetInputConnection(boneNormals->GetOutputPort());
		vtkPolyDataMapper *boneMapper = vtkPolyDataMapper::New();
			boneMapper->SetInputConnection(boneStripper->GetOutputPort());
			boneMapper->ScalarVisibilityOff();
		vtkActor *bone = vtkActor::New();
			bone->SetMapper(boneMapper);
			bone->GetProperty()->SetDiffuseColor(1, 1, .9412);

		vtkOutlineFilter *outlineData = vtkOutlineFilter::New();
			outlineData->SetInputConnection(v16->GetOutputPort());
		vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New();
			mapOutline->SetInputConnection(outlineData->GetOutputPort());
		vtkActor *outline = vtkActor::New();
			outline->SetMapper(mapOutline);
			outline->GetProperty()->SetColor(0,0,0);

		vtkLookupTable *bwLut = vtkLookupTable::New();
			bwLut->SetTableRange (0, 2000);
			bwLut->SetSaturationRange (0, 0);
			bwLut->SetHueRange (0, 0);
			bwLut->SetValueRange (0, 1);
			bwLut->Build(); //effective built

		vtkLookupTable *hueLut = vtkLookupTable::New();
			hueLut->SetTableRange (0, 2000);
			hueLut->SetHueRange (0, 1);
			hueLut->SetSaturationRange (1, 1);
			hueLut->SetValueRange (1, 1);
			hueLut->Build(); //effective built

		vtkLookupTable *satLut = vtkLookupTable::New();
			satLut->SetTableRange (0, 2000);
			satLut->SetHueRange (.6, .6);
			satLut->SetSaturationRange (0, 1);
			satLut->SetValueRange (1, 1);
			satLut->Build(); //effective built

		vtkImageMapToColors *saggitalColors = vtkImageMapToColors::New();
			saggitalColors->SetInputConnection(v16->GetOutputPort());
			saggitalColors->SetLookupTable(bwLut);
		vtkImageActor *saggital = vtkImageActor::New();
			saggital->SetInput(saggitalColors->GetOutput());
			saggital->SetDisplayExtent(32,32, 0,63, 0,92);

		vtkImageMapToColors *axialColors = vtkImageMapToColors::New();
			axialColors->SetInputConnection(v16->GetOutputPort());
			axialColors->SetLookupTable(hueLut);
		vtkImageActor *axial = vtkImageActor::New();
			axial->SetInput(axialColors->GetOutput());
			axial->SetDisplayExtent(0,63, 0,63, 46,46);

		vtkImageMapToColors *coronalColors = vtkImageMapToColors::New();
			coronalColors->SetInputConnection(v16->GetOutputPort());
			coronalColors->SetLookupTable(satLut);
		vtkImageActor *coronal = vtkImageActor::New();
			coronal->SetInput(coronalColors->GetOutput());
			coronal->SetDisplayExtent(0,63, 32,32, 0,92);

		vtkCamera *aCamera = vtkCamera::New();
			aCamera->SetViewUp (0, 0, -1);
			aCamera->SetPosition (0, 1, 0);
			aCamera->SetFocalPoint (0, 0, 0);
			aCamera->ComputeViewPlaneNormal();


		aRenderer->AddActor(outline);
		aRenderer->AddActor(saggital);
		aRenderer->AddActor(axial);
		aRenderer->AddActor(coronal);
		aRenderer->AddActor(skin);
		aRenderer->AddActor(bone);

		bone->VisibilityOff();

		skin->GetProperty()->SetOpacity(0.5);

		aRenderer->SetActiveCamera(aCamera);
		aRenderer->Render();
		aRenderer->ResetCamera ();
		aCamera->Dolly(1.0);

		aRenderer->ResetCameraClippingRange ();


		iren->Initialize();
		iren->Start(); 

		// eliminamos las referencias reservadas de vtk, el componente interactor iren ya contiene
		// un shared ptr de cada uno de estos

		v16->Delete();
		skinExtractor->Delete();
		skinNormals->Delete();
		skinStripper->Delete();
		skinMapper->Delete();
		skin->Delete();
		boneExtractor->Delete();
		boneNormals->Delete();
		boneStripper->Delete();
		boneMapper->Delete();
		bone->Delete();
		outlineData->Delete();
		mapOutline->Delete();
		outline->Delete();
		bwLut->Delete();
		hueLut->Delete();
		satLut->Delete();
		saggitalColors->Delete();
		saggital->Delete();
		axialColors->Delete();
		axial->Delete();
		coronalColors->Delete();
		coronal->Delete();
		aCamera->Delete();
		aRenderer->Delete();
	//	aRen2->Delete();
		renWin->Delete();


		tbar = new Toolbar();

		addAndMakeVisible(tbar);
		addAndMakeVisible(iren);
	}

	vtkCanvas::~vtkCanvas() {
		iren->Delete();
		deleteAllChildren();
	}


	void vtkCanvas::resized() {
		//iren->setBounds(5,21,getWidth()-10,getHeight()-26);
		iren->setBoundsInset(BorderSize(26,10,10,10));
		tbar->setBounds(0,0,getWidth(),16);
	}