From 6415d635327ce5d9058a45cc6f350551af2adff5 Mon Sep 17 00:00:00 2001 From: guigues Date: Mon, 3 Mar 2008 13:13:56 +0000 Subject: [PATCH] *** empty log message *** --- packages/CMakeLists.txt | 2 +- packages/vtk/bbs/boxes/bbLoadHola.bbs | 2 +- packages/wxvtk/CMakeLists.txt | 1 + .../wxvtk/bbs/appli/ExampleSimpleSlicer.bbs | 18 + packages/wxvtk/bbs/appli/ExampleViewer2D.bbs | 19 + packages/wxvtk/bbs/boxes/bbSimpleSlicer.bbs | 38 + packages/wxvtk/src/bbwxvtkMIPViewer.cxx | 178 +++++ packages/wxvtk/src/bbwxvtkMIPViewer.h | 126 +++ packages/wxvtk/src/bbwxvtkViewer2D.cxx | 185 +++++ packages/wxvtk/src/bbwxvtkViewer2D.h | 108 +++ packages/wxvtk/src/bbwxvtkViewer3D.cxx | 171 ++++ packages/wxvtk/src/bbwxvtkViewer3D.h | 114 +++ ...wInteractorTovtkRenderWindowInteractor.cxx | 32 + ...dowInteractorTovtkRenderWindowInteractor.h | 0 .../wxvtk/src/wxVTKRenderWindowInteractor.cxx | 747 ++++++++++++++++++ .../wxvtk/src/wxVTKRenderWindowInteractor.h | 187 +++++ 16 files changed, 1926 insertions(+), 2 deletions(-) create mode 100644 packages/wxvtk/bbs/appli/ExampleSimpleSlicer.bbs create mode 100644 packages/wxvtk/bbs/appli/ExampleViewer2D.bbs create mode 100644 packages/wxvtk/bbs/boxes/bbSimpleSlicer.bbs create mode 100644 packages/wxvtk/src/bbwxvtkMIPViewer.cxx create mode 100644 packages/wxvtk/src/bbwxvtkMIPViewer.h create mode 100644 packages/wxvtk/src/bbwxvtkViewer2D.cxx create mode 100644 packages/wxvtk/src/bbwxvtkViewer2D.h create mode 100644 packages/wxvtk/src/bbwxvtkViewer3D.cxx create mode 100644 packages/wxvtk/src/bbwxvtkViewer3D.h create mode 100644 packages/wxvtk/src/bbwxvtkwxVTKRenderWindowInteractorTovtkRenderWindowInteractor.cxx create mode 100644 packages/wxvtk/src/bbwxvtkwxVTKRenderWindowInteractorTovtkRenderWindowInteractor.h create mode 100644 packages/wxvtk/src/wxVTKRenderWindowInteractor.cxx create mode 100644 packages/wxvtk/src/wxVTKRenderWindowInteractor.h diff --git a/packages/CMakeLists.txt b/packages/CMakeLists.txt index 58b90b2..e1c3f6b 100644 --- a/packages/CMakeLists.txt +++ b/packages/CMakeLists.txt @@ -6,6 +6,6 @@ SUBDIRS(itk) SUBDIRS(vtk) SUBDIRS(toolsbbtk) SUBDIRS(test) -#SUBDIRS(wxvtk) +SUBDIRS(wxvtk) SUBDIRS(itkvtk) #----------------------------------------------------------------------------- diff --git a/packages/vtk/bbs/boxes/bbLoadHola.bbs b/packages/vtk/bbs/boxes/bbLoadHola.bbs index 58658f2..bf2da32 100644 --- a/packages/vtk/bbs/boxes/bbLoadHola.bbs +++ b/packages/vtk/bbs/boxes/bbLoadHola.bbs @@ -1,7 +1,7 @@ load vtk include std/boxes/bbPrependPackageDataPath -define LoadHola +define LoadHola vtk description "Loads the image 'hola.mhd'" author "laurent.guigues at creatis.insa-lyon.fr" category "image;read/write" diff --git a/packages/wxvtk/CMakeLists.txt b/packages/wxvtk/CMakeLists.txt index 7a4fd1f..d13d2e4 100644 --- a/packages/wxvtk/CMakeLists.txt +++ b/packages/wxvtk/CMakeLists.txt @@ -110,6 +110,7 @@ SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS # - bbtk dirs # - automatically handled libraries or packages : wx, vtk... (see above) # - the dirs automatically set by other libraries found by FIND_PACKAGE + ../std/src ) #=========================================================================== diff --git a/packages/wxvtk/bbs/appli/ExampleSimpleSlicer.bbs b/packages/wxvtk/bbs/appli/ExampleSimpleSlicer.bbs new file mode 100644 index 0000000..38f596a --- /dev/null +++ b/packages/wxvtk/bbs/appli/ExampleSimpleSlicer.bbs @@ -0,0 +1,18 @@ +description "Example of the box SimpleSlicer." +author "laurent.guigues@creatis.insa-lyon.fr" +category "example" + +include vtk/boxes/bbLoadHola +include wxvtk/boxes/bbSimpleSlicer + +new LoadHola image +new SimpleSlicer viewer +connect image.Out viewer.In + +load std +set viewer.WinTitle "ExampleSimpleSlicer" +set viewer.WinWidth 350 +set viewer.WinHeight 400 + +exec viewer + diff --git a/packages/wxvtk/bbs/appli/ExampleViewer2D.bbs b/packages/wxvtk/bbs/appli/ExampleViewer2D.bbs new file mode 100644 index 0000000..af26503 --- /dev/null +++ b/packages/wxvtk/bbs/appli/ExampleViewer2D.bbs @@ -0,0 +1,19 @@ +description "Example of the box Viewer2D." +author "laurent.guigues@creatis.insa-lyon.fr" +category "example" + +include vtk/boxes/bbLoadHola +load wxvtk +load wx + +new LoadHola image +new Viewer2D viewer +connect image.Out viewer.In + +load std +set viewer.WinTitle "ExampleViewer2D" +set viewer.Slice 20 + +set viewer.WinWidth 400 +set viewer.WinHeight 400 + diff --git a/packages/wxvtk/bbs/boxes/bbSimpleSlicer.bbs b/packages/wxvtk/bbs/boxes/bbSimpleSlicer.bbs new file mode 100644 index 0000000..6f2e5b4 --- /dev/null +++ b/packages/wxvtk/bbs/boxes/bbSimpleSlicer.bbs @@ -0,0 +1,38 @@ +load std +load wx +load wxvtk + +define SimpleSlicer + + description "Simple 2D viewer of a slice of a 3D image. The slice is controlled by a slider. See DemoSimpleSlicer.bbs. Screenshot :
" + author "laurent.guigues@creatis.insa-lyon.fr" + category "viewer" + + new LayoutLine main + new Viewer2D slicer + new Slider slider + # WE NEED A MultipleInputs BOX TO CONNECT BOTH + # slider.BoxChange AND THE INPUT BoxExecute + # OF THE COMPLEX BOX TO slicer.BoxExecute + new MultipleInputs refresh + + connect slicer.Widget main.Widget1 + connect slider.Widget main.Widget2 + connect slider.Out slicer.Slice + + connect slider.BoxChange refresh.In1 + connect refresh.Out slicer.BoxExecute + + #set main.Proportion 80 + set slider.Title "Slice" + + input In slicer.In "Input image" + input WinTitle main.WinTitle "Title of the window" + input WinWidth main.WinWidth "Width of the window" + input WinHeight main.WinHeight "Height of the window" + input BoxExecute refresh.In2 "Execute the box" + output Widget main.Widget "Widget" + + # EXECUTING THE COMPLEX BOX EXECUTES slicer + exec main +endefine diff --git a/packages/wxvtk/src/bbwxvtkMIPViewer.cxx b/packages/wxvtk/src/bbwxvtkMIPViewer.cxx new file mode 100644 index 0000000..3ea04c0 --- /dev/null +++ b/packages/wxvtk/src/bbwxvtkMIPViewer.cxx @@ -0,0 +1,178 @@ +/*========================================================================= + + Program: bbtk + Module: $RCSfile: bbwxvtkMIPViewer.cxx,v $ + Language: C++ + Date: $Date: 2008/03/03 13:14:27 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/bbtk/License.html 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 notices for more information. + +=========================================================================*/ +/** + * \file + * \brief + */ + + + +#ifdef _USE_WXWIDGETS_ + + +#include "bbwxvtkMIPViewer.h" +#include "bbwxvtkPackage.h" +//#include + +#include "vtkInteractorStyleImage.h" +#include "vtkCamera.h" +#include "vtkRenderer.h" + + + +namespace bbwxvtk +{ + + BBTK_ADD_BLACK_BOX_TO_PACKAGE(wxvtk,MIPViewer); + + + MIPViewerWidget::MIPViewerWidget(MIPViewer* v, wxWindow *parent) + : + wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), + mBox(v) + { + wxPanel *panel = this; + + mImageData = NULL; + + // Create the pipeline + mCast = vtkImageShiftScale::New(); + mCast->SetOutputScalarTypeToUnsignedChar(); + mCast->ClampOverflowOn(); + + mMIP = vtkVolumeRayCastMIPFunction::New(); + mMIP->SetMaximizeMethodToScalarValue(); + + mMapper = vtkVolumeRayCastMapper::New(); + mMapper->SetVolumeRayCastFunction(mMIP); + mMapper->SetInput(mCast->GetOutput()); // (smoother.GetOutput()) + + + // Actor + mActor = vtkVolume::New(); + mActor->SetMapper(mMapper); + + // Pipeline Viewer + // Camera + mCamera = vtkCamera::New(); + mCamera->SetViewUp(0, 0, -1); + mCamera->SetPosition(0, 1, 0); + mCamera->SetFocalPoint(0, 0, 0); + mCamera->ComputeViewPlaneNormal(); + mCamera->Dolly(1.5); + // Renderer + mRenderer = vtkRenderer::New(); + mRenderer->AddActor(mActor); + mRenderer->SetActiveCamera(mCamera); + mRenderer->ResetCamera(); + mRenderer->SetBackground(1,1,1); + mRenderer->ResetCameraClippingRange(); + // Window + mRenderWindow = vtkRenderWindow::New(); + mRenderWindow->SetSize(640, 480); + mRenderWindow->AddRenderer(mRenderer); + + mRenderWindowInteractor = new wxVTKRenderWindowInteractor(panel,-1); + mRenderWindowInteractor->UseCaptureMouseOn(); + wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); + sizer -> Add( mRenderWindowInteractor , 1, wxEXPAND, 0); + panel -> SetSizer(sizer); + panel -> SetAutoLayout(true); + panel -> Layout(); + mRenderWindowInteractor->SetRenderWindow(mRenderWindow); + + mBox->bbSetOutputInteractor(mRenderWindowInteractor); + } + //------------------------------------------------------------------------- + + MIPViewerWidget::~MIPViewerWidget() + { + } + + //------------------------------------------------------------------------- + void MIPViewerWidget::Update() + { + + + if ( mImageData != mBox->bbGetInputIn() ) + { + mImageData = mBox->bbGetInputIn(); + + mCast->SetShift(0); + mCast->SetScale(1.0); + mCast->SetInput(mImageData); + + int x1,x2,y1,y2,z1,z2; + double spx,spy,spz; + mImageData->GetSpacing(spx,spy,spz); + mImageData->GetExtent (x1,x2,y1,y2,z1,z2); + + mCamera->SetViewUp ( spx*0, -spy*1, spz*0); + mCamera->SetPosition( spx*(x1+x2)/2, spy*(y1+y2)/2, -spz*z2*2 ); + mCamera->SetFocalPoint ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*(z1+z2)/2); + mCamera->SetClippingRange( 0.01, 1000000 ); + mCamera->ComputeViewPlaneNormal(); + mCamera->Zoom( 1 ); + } + mCast->SetScale( mBox->bbGetInputScale() / 100. ); + mCast->SetShift( - mBox->bbGetInputShift() ); + + mRenderWindowInteractor->Refresh(); + + Refresh(); + } + + + + + //-------------------------------------------------------------------------- + //------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + + + BBTK_USER_BLACK_BOX_IMPLEMENTATION(MIPViewer,bbtk::WxBlackBox); + + + void MIPViewer::Process() + { + ((MIPViewerWidget*)bbGetOutputWidget())->Update(); + } + + + /** + * \brief Create wxWidget . + * + * + */ + void MIPViewer::CreateWidget() + { + bbtkDebugMessageInc("Core",9,"MIPViewer::CreateWidget()"<Update(); + bbSetOutputWidget(w); + + bbtkDebugDecTab("Core",9); + } + + +}//namespace bbtk + +#endif + diff --git a/packages/wxvtk/src/bbwxvtkMIPViewer.h b/packages/wxvtk/src/bbwxvtkMIPViewer.h new file mode 100644 index 0000000..3295ed2 --- /dev/null +++ b/packages/wxvtk/src/bbwxvtkMIPViewer.h @@ -0,0 +1,126 @@ +/*========================================================================= + + Program: bbtk + Module: $RCSfile: bbwxvtkMIPViewer.h,v $ + Language: C++ + Date: $Date: 2008/03/03 13:14:27 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/bbtk/License.html 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 notices for more information. + +=========================================================================*//** + * \brief Short description in one line + * + * Long description which + * can span multiple lines + */ +/** + * \file + * \brief Pattern for the definition of a new type of Node (header) + */ +/** + * \class bbtk::NodePatern + * \brief Pattern for the definition of a new type of Node + */ + + +#ifdef _USE_WXWIDGETS_ +#ifdef _USE_VTK_ + + +#ifndef __bbwxvtkMIPViewer_h_INCLUDED__ +#define __bbwxvtkMIPViewer_h_INCLUDED__ + +#include "vtkImageData.h" +#include "vtkImageViewer2.h" + +#include "bbtkWxBlackBox.h" +#include "wxVTKRenderWindowInteractor.h" + +#include +#include +#include +#include +#include +#include + +namespace bbwxvtk +{ + + class MIPViewer; + + //-------------------------------------------------------------------------- + class MIPViewerWidget : public wxPanel + { + public: + MIPViewerWidget(MIPViewer* box, wxWindow *parent); + ~MIPViewerWidget(); + void Update(); + vtkRenderWindowInteractor* GetInteractor() { return mRenderWindowInteractor; } + private: + MIPViewer *mBox; + vtkImageData *mImageData; + + wxVTKRenderWindowInteractor *mRenderWindowInteractor; + + /* + vtkContourFilter* mContourFilter; + vtkSmoothPolyDataFilter* mSmoothPolyDataFilter; + vtkPolyDataNormals* mPolyDataNormals; + vtkPolyDataMapper* mPolyDataMapper; + */ + vtkImageShiftScale* mCast; + vtkVolumeRayCastMIPFunction* mMIP; + vtkVolumeRayCastMapper* mMapper; + + vtkVolume* mActor; + vtkCamera* mCamera; + vtkRenderer* mRenderer; + vtkRenderWindow* mRenderWindow; + }; + + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + + class /*BBTK_EXPORT*/ MIPViewer : public bbtk::WxBlackBox + { + BBTK_USER_BLACK_BOX_INTERFACE(MIPViewer,bbtk::WxBlackBox); + // BBTK_DECLARE_INPUT(Contour,int); + BBTK_DECLARE_INPUT(In,vtkImageData *); + BBTK_DECLARE_INPUT(Shift,int); + BBTK_DECLARE_INPUT(Scale,float); + BBTK_DECLARE_OUTPUT(Interactor,vtkRenderWindowInteractor*); + BBTK_PROCESS(Process); + void Process(); + BBTK_CREATE_WIDGET(CreateWidget); + void CreateWidget(); + }; + + //================================================================= + // UserBlackBox description + BBTK_BEGIN_DESCRIBE_BLACK_BOX(MIPViewer,bbtk::WxBlackBox); + BBTK_NAME("MIPViewer"); + BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr"); + BBTK_DESCRIPTION("Maximum Intensity Projection (MIP) view of a 3D image"); + BBTK_CATEGORY("viewer"); + BBTK_INPUT(MIPViewer,Shift,"Gray scale shift",int); + BBTK_INPUT(MIPViewer,Scale,"Gray scale scaling",float); + BBTK_INPUT(MIPViewer,In,"Input Image",vtkImageData *); + BBTK_OUTPUT(MIPViewer,Interactor,"Interactor",vtkRenderWindowInteractor *); + BBTK_END_DESCRIBE_BLACK_BOX(MIPViewer); + //================================================================= + + +}//namespace bbwxvtk + +#endif //__bbtwxvtkMIPViewer_h__ + +#endif //_USE_VTK_ +#endif //_USE_WXWIDGETS_ diff --git a/packages/wxvtk/src/bbwxvtkViewer2D.cxx b/packages/wxvtk/src/bbwxvtkViewer2D.cxx new file mode 100644 index 0000000..18882c4 --- /dev/null +++ b/packages/wxvtk/src/bbwxvtkViewer2D.cxx @@ -0,0 +1,185 @@ +/*========================================================================= + + Program: bbtk + Module: $RCSfile: bbwxvtkViewer2D.cxx,v $ + Language: C++ + Date: $Date: 2008/03/03 13:14:27 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/bbtk/License.html 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 notices for more information. + +=========================================================================*/ +/** + * \file + * \brief + */ + + +#ifdef _USE_WXWIDGETS_ + + +#include "bbwxvtkViewer2D.h" +#include "bbwxvtkPackage.h" +//#include + +#include "vtkInteractorStyleImage.h" +#include "vtkCamera.h" +#include "vtkRenderer.h" + + + + +namespace bbwxvtk +{ + + BBTK_ADD_BLACK_BOX_TO_PACKAGE(wxvtk,Viewer2D); + + + Viewer2DWidget::Viewer2DWidget(Viewer2D* box, + wxWindow *parent) + : + wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), + mBox(box) + { + wxPanel *panel = this; + + wxvtkrenderwindowinteractor = new wxVTKRenderWindowInteractor(panel,-1); + wxvtkrenderwindowinteractor->UseCaptureMouseOn(); + wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); + sizer -> Add( wxvtkrenderwindowinteractor , 1, wxEXPAND, 0); + panel -> SetSizer(sizer); + panel -> SetAutoLayout(true); + panel -> Layout(); + + backImageData = NULL; + imageViewer = NULL; + + + } + //------------------------------------------------------------------------- + + Viewer2DWidget::~Viewer2DWidget() + { + delete wxvtkrenderwindowinteractor; +// pourquoi pas wxvtkrenderwindowinteractor->Delete(); // JP + } + + //------------------------------------------------------------------------- + + + + + void Viewer2DWidget::Update() + { + + if (imageViewer==NULL){ + imageViewer = vtkImageViewer2::New(); + imageViewer->SetupInteractor ( wxvtkrenderwindowinteractor ); + } + + // Viewer2D* mbbtkViewer2D = (Viewer2D*)GetBlackBox(); + + + + // imageViewer->SetSliceOrientation(((Viewer2D*)GetBlackBox())->bbGetInputOrientation()); + + + if ( backImageData != mBox->bbGetInputIn() ) + { + backImageData = mBox->bbGetInputIn(); + imageViewer->SetInput( backImageData ); + backImageData->Update(); + int x1,x2,y1,y2,z1,z2; + double spx,spy,spz; + backImageData->GetSpacing(spx,spy,spz); + backImageData->GetExtent (x1,x2,y1,y2,z1,z2); + + bbtkMessage("Output",2,"Viewer2D '"<bbGetName()<<"' - Image :"<GetRenderer()->GetActiveCamera(); + + camera->SetViewUp ( spx*0, -spy*1, spz*0); + camera->SetPosition( spx*(x1+x2)/2, spy*(y1+y2)/2, -spz*10000000); + camera->SetFocalPoint ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*0); + + + camera->ComputeViewPlaneNormal(); + camera->SetParallelScale( spx*(x2-x1)/2.0 ); + // imageViewer->GetRenderer()->ResetCamera(x1,x2,y1,y2,z1,z2); + } + + + if (backImageData!=NULL) + { + int z = mBox->bbGetInputSlice(); + + int ext[6]; + backImageData->GetWholeExtent(ext); + + + if (z=ext[5]) { z=ext[5]-1; } + // LG : SetZSlice does not exist anymore in vtk 5 ! + +#if (VTK_MAJOR_VERSION >= 5) + imageViewer->SetSlice( z ); +#else + imageViewer->SetZSlice( z ); +#endif + + } + + wxvtkrenderwindowinteractor->Render(); + // wxvtkrenderwindowinteractor->Refresh(); + + // Refresh(); + } + + + + + //-------------------------------------------------------------------------- + //------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + + + BBTK_USER_BLACK_BOX_IMPLEMENTATION(Viewer2D,bbtk::WxBlackBox); + + + void Viewer2D::Process() + { + ((Viewer2DWidget*)bbGetOutputWidget())->Update(); + bbSetOutputOut( bbGetInputSlice() ); + } + + + /** + * \brief Create wxWidget . + * + * + */ + void Viewer2D::CreateWidget() + { + bbtkDebugMessageInc("Core",9,"Viewer2D::CreateWidget()"<Update(); + bbSetOutputWidget(w); + + bbtkDebugDecTab("Core",9); + } + + +}//namespace bbtk + +#endif + diff --git a/packages/wxvtk/src/bbwxvtkViewer2D.h b/packages/wxvtk/src/bbwxvtkViewer2D.h new file mode 100644 index 0000000..9fed719 --- /dev/null +++ b/packages/wxvtk/src/bbwxvtkViewer2D.h @@ -0,0 +1,108 @@ +/*========================================================================= + + Program: bbtk + Module: $RCSfile: bbwxvtkViewer2D.h,v $ + Language: C++ + Date: $Date: 2008/03/03 13:14:27 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/bbtk/License.html 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 notices for more information. + +=========================================================================*//** + * \brief Short description in one line + * + * Long description which + * can span multiple lines + */ +/** + * \file + * \brief + */ +/** + * \class Viewer2D + * \brief + */ + + +#ifdef _USE_WXWIDGETS_ +#ifdef _USE_VTK_ + + +#ifndef __bbwxvtkViewer2D_h__ +#define __bbwxvtkViewer2D_h__ + +#include "vtkImageData.h" +#include "vtkImageViewer2.h" +#include "vtkImplicitPlaneWidget.h" + +#include "bbtkWxBlackBox.h" +#include "wxVTKRenderWindowInteractor.h" + + + +namespace bbwxvtk +{ + class Viewer2D; + + + //-------------------------------------------------------------------------- + class Viewer2DWidget : public wxPanel + { + public: + Viewer2DWidget(Viewer2D* box, wxWindow *parent); + ~Viewer2DWidget(); + void Update(); + private: + Viewer2D *mBox; + vtkImageViewer2 *imageViewer; + vtkImageData *backImageData; + wxVTKRenderWindowInteractor *wxvtkrenderwindowinteractor; + + vtkImplicitPlaneWidget * maPlane1, * maPlane2, * mbPlane1, * mbPlane2; + + }; + + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + + class /*BBTK_EXPORT*/ Viewer2D : public bbtk::WxBlackBox + { + BBTK_USER_BLACK_BOX_INTERFACE(Viewer2D,bbtk::WxBlackBox); + BBTK_DECLARE_INPUT(Slice,int); + BBTK_DECLARE_INPUT(Orientation,int); + BBTK_DECLARE_INPUT(In,vtkImageData *); + BBTK_DECLARE_OUTPUT(Out,int); + BBTK_PROCESS(Process); + void Process(); + BBTK_CREATE_WIDGET(CreateWidget); + void CreateWidget(); + }; + + //================================================================= + // UserBlackBox description + BBTK_BEGIN_DESCRIBE_BLACK_BOX(Viewer2D,bbtk::WxBlackBox); + BBTK_NAME("Viewer2D"); + BBTK_AUTHOR("eduardo.davila@creatis.insa-lyon.fr"); + BBTK_DESCRIPTION("Viewer2D widget (vtk)"); + BBTK_CATEGORY("viewer"); + BBTK_INPUT(Viewer2D,Slice,"Position of the slider",int); + BBTK_INPUT(Viewer2D,Orientation,"Slicing orientation : 0:yz / 1:xz / 2:xy",int); + BBTK_INPUT(Viewer2D,In,"Input Image",vtkImageData *); + BBTK_OUTPUT(Viewer2D,Out,"Position of the slider",int); + BBTK_END_DESCRIBE_BLACK_BOX(Viewer2D); + //================================================================= + + +}//namespace bbwxvtk + +#endif //__bbwxvtkViewer2D_h__ + +#endif //_USE_VTK_ +#endif //_USE_WXWIDGETS_ diff --git a/packages/wxvtk/src/bbwxvtkViewer3D.cxx b/packages/wxvtk/src/bbwxvtkViewer3D.cxx new file mode 100644 index 0000000..0cab9e8 --- /dev/null +++ b/packages/wxvtk/src/bbwxvtkViewer3D.cxx @@ -0,0 +1,171 @@ +/*========================================================================= + + Program: bbtk + Module: $RCSfile: bbwxvtkViewer3D.cxx,v $ + Language: C++ + Date: $Date: 2008/03/03 13:14:27 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/bbtk/License.html 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 notices for more information. + +=========================================================================*/ +/** + * \file + * \brief + */ + + +#ifdef _USE_WXWIDGETS_ + + +#include "bbwxvtkViewer3D.h" +#include "bbwxvtkPackage.h" + +#include "vtkCamera.h" +#include "vtkInteractorStyleTrackballCamera.h" + + + +namespace bbwxvtk +{ + BBTK_ADD_BLACK_BOX_TO_PACKAGE(wxvtk,Viewer3D); + + //------------------------------------------------------------------------- + Viewer3DWidget::Viewer3DWidget(Viewer3D* box, wxWindow *parent) + : + wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), + mBox(box) + { + wxPanel *panel = this; + + wxvtkrenderwindowinteractor = new wxVTKRenderWindowInteractor(panel,-1); + wxvtkrenderwindowinteractor->UseCaptureMouseOn(); + + renderer = vtkRenderer::New(); + renderwindow = vtkRenderWindow::New(); + renderwindow->AddRenderer(renderer); + wxvtkrenderwindowinteractor->SetRenderWindow(renderwindow); + + vtkInteractorStyleTrackballCamera *interactorstyle = vtkInteractorStyleTrackballCamera ::New(); + interactorstyle->SetInteractor ( wxvtkrenderwindowinteractor ); + wxvtkrenderwindowinteractor->SetInteractorStyle( interactorstyle ); + + int x1=0,x2=200,y1=0,y2=200,z1=0,z2=200; + double spx=1,spy=1,spz=1; + vtkCamera *camera = renderer->GetActiveCamera(); + camera->SetViewUp ( spx*0, -spy*1, spz*0); + camera->SetPosition( spx*(x1+x2)/2, spy*(y1+y2)/2, -spz*10000000); + camera->SetFocalPoint ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*0); + // camera->SetParallelScale( spx*(x2-x1)/2.0 ); + renderer->ResetCamera(x1,x2,y1,y2,z1,z2); + + + wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); + sizer->Add( wxvtkrenderwindowinteractor , 1, wxEXPAND, 0); + panel->SetSizer(sizer); + panel->SetAutoLayout(true); + panel->Layout(); + + } + //------------------------------------------------------------------------- + + //------------------------------------------------------------------------- + Viewer3DWidget::~Viewer3DWidget() + { + wxvtkrenderwindowinteractor->Delete(); + } + //------------------------------------------------------------------------- + + //------------------------------------------------------------------------- + void Viewer3DWidget::Update() + { + wxvtkrenderwindowinteractor->Render(); + } + //------------------------------------------------------------------------- + + //------------------------------------------------------------------------- + vtkRenderer *Viewer3DWidget::GetRenderer() + { + return renderer; + } + //------------------------------------------------------------------------- + + //------------------------------------------------------------------------- + wxVTKRenderWindowInteractor * Viewer3DWidget::GetInteractor() + { + return wxvtkrenderwindowinteractor; + } + //------------------------------------------------------------------------- + + //-------------------------------------------------------------------------- + //------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + + + BBTK_USER_BLACK_BOX_IMPLEMENTATION(Viewer3D,bbtk::WxBlackBox); + + void Viewer3D::bbUserConstructor() + { + bbSetInputIn1(NULL); + bbSetInputIn2(NULL); + bbSetInputIn3(NULL); + bbSetInputIn4(NULL); + bbSetInputIn5(NULL); + bbSetOutputRenderer( NULL ); + bbSetOutputInteractor( NULL ); + } + + + void Viewer3D::Process() + { + ((Viewer3DWidget*)bbGetOutputWidget())->Update(); + } + + + /** + * \brief Create Widget . + * + * + */ + void Viewer3D::CreateWidget() + { + bbtkDebugMessageInc("Core",9,"Viewer3D::CreateWidget()"<Update(); + + bbSetOutputInteractor( w->GetInteractor() ); + + vtkRenderer *renderer = w->GetRenderer(); + if (renderer!=NULL) + { + vtkRenderer *renderer = w->GetRenderer(); + if (bbGetInputIn1()!=NULL) {renderer->AddActor( bbGetInputIn1() ); } + if (bbGetInputIn2()!=NULL) {renderer->AddActor( bbGetInputIn2() ); } + if (bbGetInputIn3()!=NULL) {renderer->AddActor( bbGetInputIn3() ); } + if (bbGetInputIn4()!=NULL) {renderer->AddActor( bbGetInputIn4() ); } + if (bbGetInputIn5()!=NULL) {renderer->AddActor( bbGetInputIn5() ); } + renderer->ResetCamera(); + bbSetOutputRenderer( w->GetRenderer() ); + + + } + + bbSetOutputWidget(w); + + bbtkDebugDecTab("Core",9); + + } + + +}//namespace bbwxvtk + +#endif + diff --git a/packages/wxvtk/src/bbwxvtkViewer3D.h b/packages/wxvtk/src/bbwxvtkViewer3D.h new file mode 100644 index 0000000..43b924d --- /dev/null +++ b/packages/wxvtk/src/bbwxvtkViewer3D.h @@ -0,0 +1,114 @@ +/*========================================================================= + + Program: bbtk + Module: $RCSfile: bbwxvtkViewer3D.h,v $ + Language: C++ + Date: $Date: 2008/03/03 13:14:27 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/bbtk/License.html 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 notices for more information. + +=========================================================================*//** + * \brief Short description in one line + * + * Long description which + * can span multiple lines + */ +/** + * \file + * \brief Pattern for the definition of a new type of Node (header) + */ +/** + * \class bbtk::NodePatern + * \brief Pattern for the definition of a new type of Node + */ + + +#ifdef _USE_WXWIDGETS_ +#ifdef _USE_VTK_ + + +#ifndef __bbWxViewer3D_h__ +#define __bbWxViewer3D_h__ + +#include +#include + +#include "bbtkWxBlackBox.h" +#include "wxVTKRenderWindowInteractor.h" + + + +namespace bbwxvtk +{ + class Viewer3D; + //-------------------------------------------------------------------------- + class Viewer3DWidget : public wxPanel + { + public: + Viewer3DWidget(Viewer3D* box, wxWindow *parent); + ~Viewer3DWidget(); + + void Update(); + vtkRenderer *GetRenderer(); + wxVTKRenderWindowInteractor * GetInteractor(); + private: + Viewer3D *mBox; + vtkRenderer *renderer; + vtkRenderWindow *renderwindow; + wxVTKRenderWindowInteractor *wxvtkrenderwindowinteractor; + }; + + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + + class /*BBTK_EXPORT*/ Viewer3D : public bbtk::WxBlackBox + { + BBTK_USER_BLACK_BOX_INTERFACE(Viewer3D,bbtk::WxBlackBox); + BBTK_DECLARE_INPUT(In1, vtkProp3D *); + BBTK_DECLARE_INPUT(In2, vtkProp3D *); + BBTK_DECLARE_INPUT(In3, vtkProp3D *); + BBTK_DECLARE_INPUT(In4, vtkProp3D *); + BBTK_DECLARE_INPUT(In5, vtkProp3D *); + BBTK_DECLARE_OUTPUT(Renderer,vtkRenderer*); + BBTK_DECLARE_OUTPUT(Interactor,wxVTKRenderWindowInteractor*); + BBTK_PROCESS(Process); + void Process(); + BBTK_CREATE_WIDGET(CreateWidget); + void CreateWidget(); + + protected: + virtual void bbUserConstructor(); + }; + + //================================================================= + // UserBlackBox description + BBTK_BEGIN_DESCRIBE_BLACK_BOX(Viewer3D,bbtk::WxBlackBox); + BBTK_NAME("Viewer3D"); + BBTK_AUTHOR("eduardo.davila@creatis.insa-lyon.fr"); + BBTK_DESCRIPTION("3D Viewer (vtk)"); + BBTK_INPUT(Viewer3D,In1,"Input actor",vtkProp3D *); + BBTK_INPUT(Viewer3D,In2,"Input actor",vtkProp3D *); + BBTK_INPUT(Viewer3D,In3,"Input actor",vtkProp3D *); + BBTK_INPUT(Viewer3D,In4,"Input actor",vtkProp3D *); + BBTK_INPUT(Viewer3D,In5,"Input actor",vtkProp3D *); + BBTK_OUTPUT(Viewer3D,Renderer,"Renderer to which actors can be added.",vtkRenderer*); + BBTK_OUTPUT(Viewer3D,Interactor,"Interactor with which vtk widgets can interact",wxVTKRenderWindowInteractor*); + BBTK_END_DESCRIBE_BLACK_BOX(Viewer3D); + //================================================================= + + +}//namespace bbtk + +#endif //__bbtkWxViewer3D_h__ + +#endif //_USE_VTK_ +#endif //_USE_WXWIDGETS_ + diff --git a/packages/wxvtk/src/bbwxvtkwxVTKRenderWindowInteractorTovtkRenderWindowInteractor.cxx b/packages/wxvtk/src/bbwxvtkwxVTKRenderWindowInteractorTovtkRenderWindowInteractor.cxx new file mode 100644 index 0000000..21c8a90 --- /dev/null +++ b/packages/wxvtk/src/bbwxvtkwxVTKRenderWindowInteractorTovtkRenderWindowInteractor.cxx @@ -0,0 +1,32 @@ +#ifdef _USE_VTK_ + +#include "bbstdCast.h" +#include "wxVTKRenderWindowInteractor.h" +#include "bbwxvtkPackage.h" + + +namespace bbstd +{ + //==================================================================== + BBTK_USER_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(Cast, + bbtk::AtomicBlackBox); + //==================================================================== + + +} + + +using namespace bbstd; +namespace bbwxvtk +{ + //==================================================================== + // Add the specialized adaptors to the package + typedef wxVTKRenderWindowInteractor* I; + typedef vtkRenderWindowInteractor* O; + + BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(wxvtk,Cast,I,O); + +} + + +#endif // _USE_VTK_ diff --git a/packages/wxvtk/src/bbwxvtkwxVTKRenderWindowInteractorTovtkRenderWindowInteractor.h b/packages/wxvtk/src/bbwxvtkwxVTKRenderWindowInteractorTovtkRenderWindowInteractor.h new file mode 100644 index 0000000..e69de29 diff --git a/packages/wxvtk/src/wxVTKRenderWindowInteractor.cxx b/packages/wxvtk/src/wxVTKRenderWindowInteractor.cxx new file mode 100644 index 0000000..a7ac807 --- /dev/null +++ b/packages/wxvtk/src/wxVTKRenderWindowInteractor.cxx @@ -0,0 +1,747 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: $RCSfile: wxVTKRenderWindowInteractor.cxx,v $ + Language: C++ + Date: $Date: 2008/03/03 13:14:28 $ + Version: $Revision: 1.1 $ + + Copyright (c) 1993-2002 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 "wxVTKRenderWindowInteractor.h" + +//This is needed for vtk 3.1 : +#ifndef VTK_MAJOR_VERSION +# include "vtkVersion.h" +#endif + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +# include "vtkCommand.h" +#else +# include "vtkInteractorStyle.h" +#endif + +//======================================================================= +// LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS +namespace bbwxvtk +{ + + //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0 +#if (!wxCHECK_VERSION(2, 4, 0)) + wxWindow* wxGetTopLevelParent(wxWindow *win) + { + while ( win && !win->IsTopLevel() ) + win = win->GetParent(); + return win; + } +#endif +} +// LG : EO namespace bbwxvtk +//======================================================================= + +// To access objc calls on cocoa +#ifdef __WXCOCOA__ +#ifdef VTK_USE_COCOA +#import +// This trick is no longer need in VTK CVS, should get rid of that: +#define id Id +#else +#error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work +#endif //VTK_USE_COCOA +#endif //__WXCOCOA__ + +#ifdef __WXGTK__ +# include // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0 +# include "gdk/gdkprivate.h" +#ifdef __WXGTK20__ +#include +#else +#include +#endif +#define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \ + GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \ + GDK_WINDOW_XWINDOW((wxwin)->m_widget->window) +#endif + +#ifdef __WXX11__ +#include "wx/x11/privx.h" +#define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle()) +#endif + + +//For more info on this class please go to: +//http://wxvtk.sf.net +//This hack is for some buggy wxGTK version: +#if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__) +# define WX_USE_X_CAPTURE 0 +#else +# define WX_USE_X_CAPTURE 1 +#endif + +#define ID_wxVTKRenderWindowInteractor_TIMER 1001 + +//======================================================================= +// LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS +namespace bbwxvtk +{ + +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) +IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas) +#else +IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow) +#endif //__WXGTK__ + +//--------------------------------------------------------------------------- +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) +BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas) +#else +BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow) +#endif //__WXGTK__ + //refresh window by doing a Render + EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint) + EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground) + EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion) + + //Bind the events to the event converters + EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown) + EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown) + EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown) + EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp) + EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp) + EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp) +#if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1) + EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter) + EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave) + EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel) +// If we use EVT_KEY_DOWN instead of EVT_CHAR, capital versions +// of all characters are always returned. EVT_CHAR also performs +// other necessary keyboard-dependent translations. + //EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown) + EVT_CHAR (wxVTKRenderWindowInteractor::OnKeyDown) + EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp) +#endif + EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer) + EVT_SIZE (wxVTKRenderWindowInteractor::OnSize) +END_EVENT_TABLE() + +//--------------------------------------------------------------------------- +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) +wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : vtkRenderWindowInteractor(), wxGLCanvas() +#else +wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : vtkRenderWindowInteractor(), wxWindow() +#endif //__WXGTK__ + , timer(this, ID_wxVTKRenderWindowInteractor_TIMER) + , ActiveButton(wxEVT_NULL) + , RenderAllowed(0) + , Stereo(0) + , Handle(0) + , Created(true) + , RenderWhenDisabled(1) + , UseCaptureMouse(0) +{ + + this->RenderWindow = NULL; + this->SetRenderWindow(vtkRenderWindow::New()); + this->RenderWindow->Delete(); + + //this->SetBackgroundColour( wxColour(255,0,255) ); +} +//--------------------------------------------------------------------------- +wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent, + wxWindowID id, + const wxPoint &pos, + const wxSize &size, + long style, + const wxString &name) +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) + : vtkRenderWindowInteractor(), wxGLCanvas(parent, id, pos, size, style, name) +#else + : vtkRenderWindowInteractor(), wxWindow(parent, id, pos, size, style, name) +#endif //__WXGTK__ + , timer(this, ID_wxVTKRenderWindowInteractor_TIMER) + , ActiveButton(wxEVT_NULL) + , RenderAllowed(0) + , Stereo(0) + , Handle(0) + , Created(true) + , RenderWhenDisabled(1) + , UseCaptureMouse(0) +{ + + this->RenderWindow = NULL; + this->SetRenderWindow(vtkRenderWindow::New()); + this->RenderWindow->Delete(); + + // this->SetBackgroundColour( wxColour(255,0,0) ); +} +//--------------------------------------------------------------------------- +wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor() +{ + // LG : trompe la mort ! + SetReferenceCount(0); +} +//--------------------------------------------------------------------------- +wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New() +{ + // we don't make use of the objectfactory, because we're not registered + return new wxVTKRenderWindowInteractor; +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::Initialize() +{ + int *size = RenderWindow->GetSize(); + // enable everything and start rendering + Enable(); + //RenderWindow->Start(); + + // set the size in the render window interactor + Size[0] = size[0]; + Size[1] = size[1]; + + // this is initialized + Initialized = 1; +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::Enable() +{ + // if already enabled then done + if (Enabled) + return; + + // that's it + Enabled = 1; +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) + SetCurrent(); +#endif + Modified(); +} +//--------------------------------------------------------------------------- +bool wxVTKRenderWindowInteractor::Enable(bool enable) +{ +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) + return wxGLCanvas::Enable(enable); +#else + return wxWindow::Enable(enable); +#endif +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::Disable() +{ + // if already disabled then done + if (!Enabled) + return; + + // that's it (we can't remove the event handler like it should be...) + Enabled = 0; + Modified(); +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::Start() +{ + // the interactor cannot control the event loop + vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() " + "interactor cannot control event loop."); +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::UpdateSize(int x, int y) +{ + if( RenderWindow ) + { + // if the size changed tell render window + if ( x != Size[0] || y != Size[1] ) + { + // adjust our (vtkRenderWindowInteractor size) + Size[0] = x; + Size[1] = y; + // and our RenderWindow's size + RenderWindow->SetSize(x, y); + } + } +} +//--------------------------------------------------------------------------- +int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype)) +{ + // it's a one shot timer + if (!timer.Start(10, TRUE)) + assert(false); + + return 1; + +} +//--------------------------------------------------------------------------- +int wxVTKRenderWindowInteractor::DestroyTimer() +{ + // do nothing + return 1; +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event)) +{ + if (!Enabled) + return; + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::TimerEvent, NULL); +#else + // old style + InteractorStyle->OnTimer(); +#endif +} + +//--------------------------------------------------------------------------- +// NOTE on implementation: +// Bad luck you ended up in the only tricky place of this code. +// A few note, wxWidgets still refuse to provide such convenient method +// so I have to maintain it myself, eventhough this is completely integrated +// in wxPython... +// Anyway if this happen to break for you then compare to a recent version of wxPython +// and look for the function long wxPyGetWinHandle(wxWindow* win) +// in wxPython/src/helpers.cpp +long wxVTKRenderWindowInteractor::GetHandleHack() +{ + //helper function to hide the MSW vs GTK stuff + long handle_tmp = 0; + +// __WXMSW__ is for Win32 +//__WXMAX__ stands for using Carbon C-headers, using either the CarbonLib/CFM or the native Mach-O builds (which then also use the latest features available) +// __WXGTK__ is for both gtk 1.2.x and gtk 2.x +#if defined(__WXMSW__) || defined(__WXMAC__) + handle_tmp = (long)this->GetHandle(); +#endif //__WXMSW__ + +//__WXCOCOA__ stands for using the objective-c Cocoa API +#ifdef __WXCOCOA__ + // Here is how to find the NSWindow + wxTopLevelWindow* toplevel = dynamic_cast( + wxGetTopLevelParent( this ) ); + if (toplevel != NULL ) + { + handle_tmp = (long)toplevel->GetNSWindow(); + } + // The NSView will be deducted from + // [(NSWindow*)Handle contentView] + // if only I knew how to write that in c++ +#endif //__WXCOCOA__ + + // Find and return the actual X-Window. +#if defined(__WXGTK__) || defined(__WXX11__) + return (long)GetXWindow(this); +#endif + +//#ifdef __WXMOTIF__ +// handle_tmp = (long)this->GetXWindow(); +//#endif + + return handle_tmp; +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event)) +{ + + //must always be here + wxPaintDC pDC(this); + + //do it here rather than in the cstor: this is safer. + if(!Handle) + { + Handle = GetHandleHack(); + RenderWindow->SetWindowId(reinterpret_cast(Handle)); +#ifdef __WXMSW__ + RenderWindow->SetParentId(reinterpret_cast(this->GetParent()->GetHWND())); +#endif //__WXMSW__ + } + // get vtk to render to the wxWindows + //bbtkDebugMessage("Wx",9,"wxVTKRenderWindowInteractor::OnPaint"< 0) + InvokeEvent(vtkCommand::ConfigureEvent, NULL); +#endif + //this will check for Handle + //Render(); +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event) +{ + if (!Enabled) + { + return; + } + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); + + InvokeEvent(vtkCommand::MouseMoveEvent, NULL); +#else + InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif +} +//--------------------------------------------------------------------------- +#if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1) +void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event) +{ + if (!Enabled) + { + return; + } + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); + + InvokeEvent(vtkCommand::EnterEvent, NULL); +#else + // old style + InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event) +{ + if (!Enabled) + { + return; + } + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); + + InvokeEvent(vtkCommand::LeaveEvent, NULL); +#else + // old style + InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event) +{ + if (!Enabled) + { + return; + } + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + int keycode = event.GetKeyCode(); + char key = '\0'; + if (keycode < 256) + { + // TODO: Unicode in non-Unicode mode ?? + key = (char)keycode; + } + + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), key, 0, NULL); + + InvokeEvent(vtkCommand::KeyPressEvent, NULL); + InvokeEvent(vtkCommand::CharEvent, NULL); +#else + InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(), + event.GetKeyCode(), 1); +#endif + event.Skip(); +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event) +{ + if (!Enabled) + { + return; + } + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + int keycode = event.GetKeyCode(); + char key = '\0'; + if (keycode < 256) + { + // TODO: Unicode in non-Unicode mode ?? + key = (char)keycode; + } + + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), key, 0, NULL); + InvokeEvent(vtkCommand::KeyReleaseEvent, NULL); +#else + InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(), + event.GetKeyCode(), 1); +#endif + event.Skip(); +} +#endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1) +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event) +{ + if (!Enabled || (ActiveButton != wxEVT_NULL)) + { + return; + } + ActiveButton = event.GetEventType(); + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); +#endif + + if(event.RightDown()) + { +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::RightButtonPressEvent, NULL); +#else + // old style + InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif + } + else if(event.LeftDown()) + { +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL); +#else + // old style + InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif + } + else if(event.MiddleDown()) + { +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL); +#else + // old style + InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif + } + //save the button and capture mouse until the button is released + //Only if : + //1. it is possible (WX_USE_X_CAPTURE) + //2. user decided to. + if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse) + { + CaptureMouse(); + } +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event) +{ + //EVT_xxx_DOWN == EVT_xxx_UP - 1 + //This is only needed if two mouse buttons are pressed at the same time. + //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or + //wxEVT_COMMAND_RIGHT_CLICK + if (!Enabled || (ActiveButton != (event.GetEventType()-1))) + { + return; + } + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); +#endif + + if(ActiveButton == wxEVT_RIGHT_DOWN) + { +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL); +#else + // old style + InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif + } + else if(ActiveButton == wxEVT_LEFT_DOWN) + { +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL); +#else + // old style + InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif + } + else if(ActiveButton == wxEVT_MIDDLE_DOWN) + { +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL); +#else + // old style + InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif + } + //if the ActiveButton is realeased, then release mouse capture + if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse) + { + ReleaseMouse(); + } + ActiveButton = wxEVT_NULL; +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event) +{ +// Mouse wheel was only added after VTK 4.4 (I think...) +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2) + // new style + //Set vtk event information ... The numebr of wheel rotations is stored in + //the x varible. y varible is zero + SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0, + event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); + if(event.GetWheelRotation() > 0) + { + //Send event to VTK +// EED +// InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL); + } + else + { + //Send event to VTK +// EED +// InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL); + } +#endif + +} + +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::Render() +{ + RenderAllowed = 1; + if (!RenderWhenDisabled) + { + //the user doesn't want us to render when the toplevel frame + //is disabled - first find the top level parent + wxWindow *topParent = wxGetTopLevelParent(this); + if (topParent) + { + //if it exists, check whether it's enabled + //if it's not enabeld, RenderAllowed will be false + RenderAllowed = topParent->IsEnabled(); + } + } + + if (RenderAllowed) + { + if(Handle && (Handle == GetHandleHack()) ) + { + RenderWindow->Render(); + } +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2) + else if(GetHandleHack()) + { + //this means the user has reparented us; let's adapt to the + //new situation by doing the WindowRemap dance + //store the new situation + Handle = GetHandleHack(); + RenderWindow->SetNextWindowId(reinterpret_cast(Handle)); + RenderWindow->WindowRemap(); + RenderWindow->Render(); + } +#endif + } +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue) +{ + //Change value of __RenderWhenDisabled ivar. + //If __RenderWhenDisabled is false (the default), this widget will not + //call Render() on the RenderWindow if the top level frame (i.e. the + //containing frame) has been disabled. + + //This prevents recursive rendering during wxSafeYield() calls. + //wxSafeYield() can be called during the ProgressMethod() callback of + //a VTK object to have progress bars and other GUI elements updated - + //it does this by disabling all windows (disallowing user-input to + //prevent re-entrancy of code) and then handling all outstanding + //GUI events. + + //However, this often triggers an OnPaint() method for wxVTKRWIs, + //resulting in a Render(), resulting in Update() being called whilst + //still in progress. + + RenderWhenDisabled = (bool)newValue; +} +//--------------------------------------------------------------------------- +// +// Set the variable that indicates that we want a stereo capable window +// be created. This method can only be called before a window is realized. +// +void wxVTKRenderWindowInteractor::SetStereo(int capable) +{ + if (Stereo != capable) + { + Stereo = capable; + RenderWindow->StereoCapableWindowOn(); + RenderWindow->SetStereoTypeToCrystalEyes(); + Modified(); + } +} + +//--------------------------------------------------------------------------- +// +// +void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os, indent); +} + + +#if defined(_WIN32) +const char * wxVTKRenderWindowInteractor::GetClassName() const +{ + return "wxVTKRenderWindowInteractor"; +} +#endif //_WIN32 + +} +// LG : EO namespace bbwxvtk +//======================================================================= + diff --git a/packages/wxvtk/src/wxVTKRenderWindowInteractor.h b/packages/wxvtk/src/wxVTKRenderWindowInteractor.h new file mode 100644 index 0000000..7443bce --- /dev/null +++ b/packages/wxvtk/src/wxVTKRenderWindowInteractor.h @@ -0,0 +1,187 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: $RCSfile: wxVTKRenderWindowInteractor.h,v $ + Language: C++ + Date: $Date: 2008/03/03 13:14:28 $ + Version: $Revision: 1.1 $ + + Copyright (c) 1993-2002 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 wxVTKRenderWindowInteractor - class to enable VTK to render to +// and interact with wxWindow. +// .SECTION Description +// wxVTKRenderWindowInteractor provide a VTK widget for wxWindow. This class +// was completely rewrote to have the 'Look & Feel' of the python version: +// wxVTKRenderWindowInteractor.py +// .SECTION Caveats +// - There is a know bug that prevent this class to works for more info see +// WX_USE_X_CAPTURE. This bug only affect wxGTK from 2.3.2 to wxGTK 2.4.0. +// - Furthermore this class is tempated over either wxWindows or wxGLCanvas, +// in wxWindows 2.3.1 and earlier, the wxGLCanvas had scroll bars, you can avoid +// this effect by playing with WX_BASE_CLASS at your risk (you might end up with +// lot of flickering.) +// - This class might not be easily readable as it tried to work with VTK 3.2 +// and 4.x. This class doesn't support reparenting with VTK 4.2 and earlier. +// .SECTION see also +// wxVTKRenderWindowInteractor.py wxVTKRenderWindow.py + +#ifndef _wxVTKRenderWindowInteractor_h_ +#define _wxVTKRenderWindowInteractor_h_ + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +# pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include +#endif + +#include +#include + +// vtk includes +#include "vtkRenderWindowInteractor.h" +#include "vtkRenderWindow.h" + +// Apparently since wxGTK 2.8.0 one can finally use wxWindow (just as in any +// other port): +#if (!wxCHECK_VERSION(2, 8, 0)) +#define USE_WXGLCANVAS +#endif + + +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) +# if wxUSE_GLCANVAS +# include +# else +# error "problem of wxGLCanvas, you need to build wxWidgets with opengl" +# endif //wxUSE_GLCANVAS +#endif //__WXGTK__ + +// Motif version (renamed into wxX11 for wxWindow 2.4 and newer) +#if defined(__WXMOTIF__) +# error This GUI is not supported by wxVTKRenderWindowInteractor for now +#endif + + +// wx forward declarations +class wxPaintEvent; +class wxMouseEvent; +class wxTimerEvent; +class wxKeyEvent; +class wxSizeEvent; + +//======================================================================= +// LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS +namespace bbwxvtk +{ + + +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) +class VTK_RENDERING_EXPORT wxVTKRenderWindowInteractor : public wxGLCanvas, virtual public vtkRenderWindowInteractor +#else +class /*VTK_RENDERING_EXPORT*/ wxVTKRenderWindowInteractor : public wxWindow, virtual public vtkRenderWindowInteractor +#endif //__WXGTK__ +{ + DECLARE_DYNAMIC_CLASS(wxVTKRenderWindowInteractor) + + public: + //constructors + wxVTKRenderWindowInteractor(); + + wxVTKRenderWindowInteractor(wxWindow *parent, + wxWindowID id, + const wxPoint &pos = wxDefaultPosition, + const wxSize &size = wxDefaultSize, + long style = wxWANTS_CHARS | wxNO_FULL_REPAINT_ON_RESIZE, + const wxString &name = wxPanelNameStr); + //vtk ::New() + static wxVTKRenderWindowInteractor * New(); + void PrintSelf(ostream& os, vtkIndent indent); + + //destructor + ~wxVTKRenderWindowInteractor(); + +#if defined(_WIN32) + const char * wxVTKRenderWindowInteractor::GetClassName() const; +#endif //_WIN32 + + + // vtkRenderWindowInteractor overrides + void Initialize(); + void Enable(); + bool Enable(bool enable); + void Disable(); + void Start(); + void UpdateSize(int x, int y); + int CreateTimer(int timertype); + int DestroyTimer(); + void TerminateApp() {}; + + // event handlers + void OnPaint(wxPaintEvent &event); + void OnEraseBackground (wxEraseEvent& event); + void OnMotion(wxMouseEvent &event); + + void OnButtonDown(wxMouseEvent &event); + void OnButtonUp(wxMouseEvent &event); +#if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1) + void OnEnter(wxMouseEvent &event); + void OnLeave(wxMouseEvent &event); + void OnKeyDown(wxKeyEvent &event); + void OnKeyUp(wxKeyEvent &event); +#endif + void OnTimer(wxTimerEvent &event); + void OnSize(wxSizeEvent &event); + void OnMouseWheel(wxMouseEvent& event); + + void Render(); + void SetRenderWhenDisabled(int newValue); + + // Description: + // Prescribe that the window be created in a stereo-capable mode. This + // method must be called before the window is realized. Default if off. + vtkGetMacro(Stereo,int); + vtkBooleanMacro(Stereo,int); + virtual void SetStereo(int capable); + + // Description: + // As CaptureMouse could be a problem sometimes on a window box + // This method allow to set or not the CaptureMouse. + // This method actually will works only if WX_USE_X_CAPTURE was set to 1 + vtkSetMacro(UseCaptureMouse,int); + vtkBooleanMacro(UseCaptureMouse,int); + + protected: + wxTimer timer; + int ActiveButton; + int RenderAllowed; + long GetHandleHack(); + int Stereo; + + private: + long Handle; + bool Created; + int RenderWhenDisabled; + int UseCaptureMouse; + + DECLARE_EVENT_TABLE() +}; + +} +// LG : EO namespace bbwxvtk +//====================================================================== + +#endif //_wxVTKRenderWindowInteractor_h_ -- 2.45.1