An update will be applied January 25th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

Commit db4c2233 authored by Francois Bertel's avatar Francois Bertel
Browse files

ENH:Adding EXPERIMENTAL code for support of 3DConnexion (TDx) devices such as the SpaceNavigator.

parent e9cb73c0
......@@ -185,6 +185,12 @@
// - A pointer to a double value between 0.0 and 1.0
// - vtkCommand::VolumeMapperComputeGradientsProgressEvent
// - A pointer to a double value between 0.0 and 1.0
// - vtkCommand::TDxMotionEvent (TDx=3DConnexion)
// - A vtkTDxMotionEventInfo*
// - vtkCommand::TDxButtonPressEvent
// - A int* being the number of the button
// - vtkCommand::TDxButtonReleaseEvent
// - A int* being the number of the button
//
// .SECTION See Also
// vtkObject vtkCallbackCommand vtkOldStyleCallbackCommand
......@@ -343,6 +349,9 @@ public:
UpdateDataEvent,
CurrentChangedEvent,
ComputeVisiblePropBoundsEvent,
TDxMotionEvent, // 3D Connexion device event
TDxButtonPressEvent, // 3D Connexion device event
TDxButtonReleaseEvent, // 3D Connexion device event
UserEvent = 1000
};
//ETX
......
......@@ -322,6 +322,34 @@ IF(VTK_USE_X)
SET( Kit_SRCS ${Kit_SRCS} vtkXRenderWindowInteractor.cxx)
ENDIF(VTK_USE_X)
# -----------------------------------------------------------------------------
# 3DConnexion device (SpaceNavigator, etc... ) on Unix.
IF(VTK_USE_X)
OPTION(VTK_USE_TDX "Use 3Dconnexion device" OFF)
MARK_AS_ADVANCED(VTK_USE_TDX)
IF(VTK_USE_TDX)
SET(VTK_TDX_INCLUDE_PATH CACHE PATH "Directory path to xdrvlib.h for 3DConnexion device")
SET(VTK_TDX_OBJECT_PATH CACHE FILEPATH "File path to xdrvlib.a for 3DConnexion device")
SET(Kit_SRCS ${Kit_SRCS} vtkTDxDevice.cxx vtkTDxUnixDevice.cxx)
INCLUDE_DIRECTORIES(${VTK_TDX_INCLUDE_PATH})
SET_SOURCE_FILES_PROPERTIES(vtkTDxDevice.cxx ABSTRACT)
LIST(APPEND KIT_INTERFACE_LIBRARIES ${VTK_TDX_OBJECT_PATH})
ENDIF()
ENDIF()
# -----------------------------------------------------------------------------
# 3DConnexion device (SpaceNavigator, etc... ) on Windows.
IF(WIN32)
OPTION(VTK_USE_3DX "Use 3Dconnextion device" OFF)
MARK_AS_ADVANCED(VTK_USE_TDX)
IF(VTK_USE_TDX)
SET(Kit_SRCS ${Kit_SRCS} vtkTDxDevice.cxx vtkTDxWinDevice.cxx)
SET_SOURCE_FILES_PROPERTIES(vtkTDxDevice.cxx ABSTRACT)
ENDIF()
ENDIF()
# -----------------------------------------------------------------------------
CONFIGURE_FILE(${VTK_SOURCE_DIR}/Rendering/vtkTDxConfigure.h.in
${VTK_BINARY_DIR}/Rendering/vtkTDxConfigure.h @ONLY IMMEDIATE)
IF(VTK_USE_QT)
SET(QT_DONT_USE_QTGUI)
INCLUDE(${QT_USE_FILE})
......
......@@ -47,6 +47,7 @@ IF(VTK_USE_DISPLAY)
TestTextActorDepthPeeling.cxx
TestTextActor3DAlphaBlending.cxx
TestTextActor3DDepthPeeling.cxx
TestTDx.cxx
TestTilingCxx.cxx
TestTranslucentLUTAlphaBlending.cxx
TestTranslucentLUTDepthPeeling.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestTDx.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// This test covers the 3DConnexion device interface.
//
// The command line arguments are:
// -I => run in interactive mode; unless this is used, the program will
// not allow interaction and exit
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkActor.h"
#include "vtkPolyDataMapper.h"
#include "vtkCamera.h"
#include "vtkConeSource.h"
#include "vtkProperty.h"
#include "vtkTDxMotionEventInfo.h"
#include "vtkCommand.h"
class myCommand : public vtkCommand
{
public:
myCommand()
{
this->Camera=0;
}
void Execute(vtkObject *caller, unsigned long eventId,
void *callData)
{
cout << "myCommand::Execute()" << endl;
if(eventId==vtkCommand::TDxMotionEvent)
{
vtkTDxMotionEventInfo *i=
static_cast<vtkTDxMotionEventInfo *>(callData);
cout << "x=" << i->X << " y=" << i->Y << " z=" << i->Z
<< " a=" << i->A << " b=" << i->B << " c=" << i->C << endl;
const double sensitivity=0.02;
this->Camera->Roll(i->B*sensitivity);
this->RenderWindowInteractor->Render();
}
else
{
cout << "unexpected VTK event" << endl;
}
}
void SetCamera(vtkCamera *c)
{
this->Camera=c;
}
void SetRenderWindowInteractor(vtkRenderWindowInteractor *i)
{
this->RenderWindowInteractor=i;
}
protected:
vtkCamera *Camera;
vtkRenderWindowInteractor *RenderWindowInteractor;
};
int TestTDx(int argc, char* argv[])
{
vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
iren->SetUseTDx(true);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->SetMultiSamples(0);
renWin->SetAlphaBitPlanes(1);
iren->SetRenderWindow(renWin);
renWin->Delete();
vtkRenderer *renderer = vtkRenderer::New();
renWin->AddRenderer(renderer);
renderer->Delete();
vtkConeSource *coneSource1=vtkConeSource::New();
vtkPolyDataMapper *coneMapper1=vtkPolyDataMapper::New();
coneMapper1->SetInputConnection(coneSource1->GetOutputPort());
coneSource1->Delete();
vtkActor *coneActor1=vtkActor::New();
coneActor1->SetMapper(coneMapper1);
coneMapper1->Delete();
coneActor1->SetPosition(-2.0,0.0,0.0);
renderer->AddActor(coneActor1);
coneActor1->Delete();
vtkConeSource *coneSource2=vtkConeSource::New();
vtkPolyDataMapper *coneMapper2=vtkPolyDataMapper::New();
coneMapper2->SetInputConnection(coneSource2->GetOutputPort());
coneSource2->Delete();
vtkActor *coneActor2=vtkActor::New();
coneActor2->SetMapper(coneMapper2);
coneMapper2->Delete();
coneActor2->SetPosition(0.0,0.0,0.0);
coneActor2->GetProperty()->SetLighting(false);
renderer->AddActor(coneActor2);
coneActor2->Delete();
vtkConeSource *coneSource3=vtkConeSource::New();
vtkPolyDataMapper *coneMapper3=vtkPolyDataMapper::New();
coneMapper3->SetInputConnection(coneSource3->GetOutputPort());
coneSource3->Delete();
vtkActor *coneActor3=vtkActor::New();
coneActor3->SetMapper(coneMapper3);
coneMapper3->Delete();
coneActor3->SetPosition(2.0,0.0,0.0);
renderer->AddActor(coneActor3);
coneActor3->Delete();
renderer->SetBackground(0.1,0.3,0.0);
renWin->SetSize(200,200);
renWin->Render();
vtkCamera *camera=renderer->GetActiveCamera();
camera->Azimuth(-40.0);
camera->Elevation(20.0);
renderer->ResetCamera();
renWin->Render();
myCommand *c=new myCommand;
c->Register(0);
c->SetCamera(camera);
c->SetRenderWindowInteractor(iren);
iren->AddObserver(vtkCommand::TDxMotionEvent,c,0);
int retVal = vtkRegressionTestImage( renWin );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
iren->Delete();
c->Delete();
c->Delete();
return !retVal;
}
......@@ -27,7 +27,7 @@
#include "vtkObserverMediator.h"
#include <vtkstd/map>
vtkCxxRevisionMacro(vtkRenderWindowInteractor, "1.121");
vtkCxxRevisionMacro(vtkRenderWindowInteractor, "1.122");
// PIMPL'd class to keep track of timers. It maps the ids returned by CreateTimer()
// to the platform-specific representation for timer ids.
......@@ -108,6 +108,8 @@ vtkRenderWindowInteractor::vtkRenderWindowInteractor()
this->TimerDuration = 10;
this->ObserverMediator = 0;
this->HandleEventLoop = false;
this->UseTDx=false; // 3DConnexion device.
}
//----------------------------------------------------------------------
......
......@@ -412,6 +412,14 @@ public:
// the particular request (default versus non-default cursor shape).
vtkObserverMediator *GetObserverMediator();
// Description:
// Use a 3DConnexion device. Initial value is false.
// If VTK is not build with the TDx option, this is no-op.
// If VTK is build with the TDx option, and a device is not connected,
// a warning is emitted.
vtkSetMacro(UseTDx,bool);
vtkGetMacro(UseTDx,bool);
protected:
vtkRenderWindowInteractor();
~vtkRenderWindowInteractor();
......@@ -490,6 +498,8 @@ protected:
// interactor.)
int HandleEventLoop;
bool UseTDx; // 3DConnexion device.
private:
vtkRenderWindowInteractor(const vtkRenderWindowInteractor&); // Not implemented.
void operator=(const vtkRenderWindowInteractor&); // Not implemented.
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTDxConfigure.h.in
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef __vtkTDxConfigure_h
#define __vtkTDxConfigure_h
/* Whether the 3Dconnexion devices are being used */
#cmakedefine VTK_USE_TDX
#endif /* __vtkTDxConfigure_h */
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTDxDevice.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkTDxDevice.h"
#include <assert.h>
vtkCxxRevisionMacro(vtkTDxDevice,"1.1");
// ----------------------------------------------------------------------------
vtkTDxDevice::vtkTDxDevice()
{
this->Initialized=false;
this->Interactor=0;
}
// ----------------------------------------------------------------------------
// Description:
// Destructor.
vtkTDxDevice::~vtkTDxDevice()
{
}
// ----------------------------------------------------------------------------
// Description:
// Tell if the device is initialized. Initial value is false.
bool vtkTDxDevice::GetInitialized() const
{
return this->Initialized;
}
// ----------------------------------------------------------------------------
// Description:
// Get the interactor on which events will be invoked.
// Initial value is 0.
// Called by the Interactor itself ONLY.
vtkRenderWindowInteractor *vtkTDxDevice::GetInteractor() const
{
return this->Interactor;
}
// ----------------------------------------------------------------------------
// Description:
// Set the interactor on which events will be invoked.
// Initial value is 0.
// Called by the Interactor itself ONLY.
// \pre not_yet_initialized: !GetInitialized()
void vtkTDxDevice::SetInteractor(vtkRenderWindowInteractor *i)
{
assert("pre: not_yet_initialized" && !this->GetInitialized());
if(this->Interactor!=i)
{
this->Interactor=i;
this->Modified();
}
}
// ----------------------------------------------------------------------------
void vtkTDxDevice::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTDxDevice.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkTDxDevice - API to access a 3DConnexion input device
// .SECTION Description
// vtkTDxDevice is an abstract class providing access to a 3DConnexion
// input device, such as the SpaceNavigator.
//
// Concrete classes are platform-dependent
// .SECTION See Also
// vtkTDxUnixDevice, vtkTDxWinDevice
// .SECTION Caveats
// THIS IS EXPERIMENTAL CODE. THE API MIGHT CHANGE.
#ifndef __vtkTDxDevice_h
#define __vtkTDxDevice_h
#include "vtkObject.h"
class vtkRenderWindowInteractor;
class VTK_RENDERING_EXPORT vtkTDxDevice : public vtkObject
{
public:
vtkTypeRevisionMacro(vtkTDxDevice,vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Tell if the device is initialized. Initial value is false.
bool GetInitialized() const;
// Description:
// Close the device. This is called by the destructor.
// You don't have to close the device explicitly, as the destructor do it
// automatically, but you can.
// \pre initialized: GetInitialized().
// \post restored: !GetInitialized()
virtual void Close()=0;
// Description:
// Get the interactor on which events will be invoked.
// Initial value is 0.
// Called by the Interactor itself ONLY.
vtkRenderWindowInteractor *GetInteractor() const;
// Description:
// Set the interactor on which events will be invoked.
// Initial value is 0.
// Called by the Interactor itself ONLY.
// \pre not_yet_initialized: !GetInitialized()
void SetInteractor(vtkRenderWindowInteractor *i);
protected:
// Description:
// Default constructor. Just set initial values for Initialized (false).
vtkTDxDevice();
// Description:
// Destructor. If the device is not initialized, do nothing. If the device
// is initialized, close the device. This behavior has to be implemented
// in subclasses.
virtual ~vtkTDxDevice();
bool Initialized;
vtkRenderWindowInteractor *Interactor;
private:
vtkTDxDevice(const vtkTDxDevice&); // Not implemented.
void operator=(const vtkTDxDevice&); // Not implemented.
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTDxMotionEventInfo.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkTDxMotionEventInfo - Store motion information from a 3DConnexion input device
// .SECTION Description
// vtkTDxMotionEventInfo is a data structure that stores the information about
// a motion event from a 3DConnexion input device.
//
// .SECTION See Also
// vtkTDxDevice
#ifndef __vtkTDxMotionEventInfo_h
#define __vtkTDxMotionEventInfo_h
#include "vtkObject.h" // for the export macro
class VTK_RENDERING_EXPORT vtkTDxMotionEventInfo
{
public:
// Description:
// Translation coordinates (deltas)
double X;
double Y;
double Z;
// Description:
// Rotation angles (deltas)
double A;
double B;
double C;
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTDxUnixDevice.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkTDxUnixDevice.h"
#include <assert.h>
#define SGI // Used in xdrvlib.h to define ParameterCheck
// xdrvlib.h does not have the usual __cplusplus extern "C" guard
extern "C" {
#include "xdrvlib.h" // Magellan X-Window driver API.
}
#include "vtkTDxMotionEventInfo.h"
#include "vtkCommand.h"
#include "vtkObjectFactory.h"
#include "vtkRenderWindowInteractor.h"
vtkCxxRevisionMacro(vtkTDxUnixDevice,"1.1");
vtkStandardNewMacro(vtkTDxUnixDevice);
// ----------------------------------------------------------------------------
// Description:
// Default constructor. Just set initial values for
// DisplayId (0), WindowId (0)), TranslationScale (1.0),
// RotationScale (1.0).
vtkTDxUnixDevice::vtkTDxUnixDevice()
{
this->DisplayId=0;
this->WindowId=0;
this->TranslationScale=1.0;
this->RotationScale=1.0;
this->Interactor=0;
// this->DebugOn();
}
// ----------------------------------------------------------------------------
// Description:
// Destructor. If the device is not initialized, do nothing. If the device
// is initialized, close the device.
vtkTDxUnixDevice::~vtkTDxUnixDevice()
{
if(this->Initialized)
{
this->Close();
}
}
// ----------------------------------------------------------------------------
// Description:
// Get the ID of the X Display. Initial value is 0.
Display *vtkTDxUnixDevice::GetDisplayId() const
{
return this->DisplayId;
}
// ----------------------------------------------------------------------------
// Description:
// Get the ID of the X Window. Initial value is 0.
Window vtkTDxUnixDevice::GetWindowId() const
{
return this->WindowId;
}
// ----------------------------------------------------------------------------
// Description:
// Set the ID of the X Display.
// \pre not_yet_initialized: !GetInitialized()
void vtkTDxUnixDevice::SetDisplayId(Display *id)
{
assert("pre: not_yet_initialized" && !this->GetInitialized());
if(this->DisplayId!=id)
{
this->DisplayId=id;
this->Modified();
}
}
// ----------------------------------------------------------------------------
// Description:
// Set the ID of the X Window.
// \pre not_yet_initialized: !GetInitialized()
void vtkTDxUnixDevice::SetWindowId(Window id)
{
assert("pre: not_yet_initialized" && !this->GetInitialized());
if(this->WindowId!=id)
{
this->WindowId=id;
this->Modified();
}
}
// ----------------------------------------------------------------------------
// Description:
// Initialize the device with the current display and window ids.
// It updates the value of GetInitialized().
// Initialization can fail. You must look for the value of
// GetInitialized() before processing further.
// \pre not_yet_initialized: !GetInitialized()
// \pre valid_display: GetDisplayId()!=0
// \pre valid_window: GetWindowId()!=0
// \pre valid_interactor: GetInteractor()!=0
void vtkTDxUnixDevice::Initialize()
{
assert("pre: not_yet_initialized" && !this->GetInitialized());
assert("pre: valid_display" && this->GetDisplayId()!=0);
assert("pre: valid_window" && this->GetWindowId()!=0);
assert("pre: valid_interactor" && this->GetInteractor()!=0);
int status=MagellanInit(this->DisplayId,this->WindowId);
this->Initialized=status==1;
}