1 /*=========================================================================
4 Module: $RCSfile: bbwxvtkViewer3D.cxx,v $
6 Date: $Date: 2010/03/07 13:18:43 $
7 Version: $Revision: 1.20 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
24 #ifdef _USE_WXWIDGETS_
27 #include "bbwxvtkViewer3D.h"
28 #include "bbwxvtkPackage.h"
30 #include "vtkCamera.h"
36 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wxvtk,Viewer3D);
38 //-------------------------------------------------------------------------
39 Viewer3DWidget::Viewer3DWidget(Viewer3D* box, wxWindow *parent, bool stereo)
41 wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
44 wxPanel *panel = this;
46 wxvtkrenderwindowinteractor = new wxVTKRenderWindowInteractor(panel,-1);
47 wxvtkrenderwindowinteractor->UseCaptureMouseOn();
49 renderer = vtkRenderer::New();
50 renderwindow = vtkRenderWindow::New();
52 renderwindow->AddRenderer(renderer);
55 renderwindow->SetStereoCapableWindow(1);
56 //renderwindow->SetStereoTypeToCrystalEyes();
57 renderwindow->SetStereoTypeToRedBlue();
58 renderwindow->SetStereoRender(1);
61 wxvtkrenderwindowinteractor->SetRenderWindow(renderwindow);
63 interactorstyle = vtkInteractorStyleTrackballCamera ::New();
64 interactorstyle->SetInteractor ( wxvtkrenderwindowinteractor );
65 wxvtkrenderwindowinteractor->SetInteractorStyle( interactorstyle );
67 int x1=0,x2=200,y1=0,y2=200,z1=0,z2=200;
68 double spx=1,spy=1,spz=1;
69 vtkCamera *camera = renderer->GetActiveCamera();
70 camera->SetViewUp ( spx*0, -spy*1, spz*0);
71 camera->SetPosition( spx*(x1+x2)/2, spy*(y1+y2)/2, -spz*10000000);
72 camera->SetFocalPoint ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*0);
73 // camera->SetParallelScale( spx*(x2-x1)/2.0 );
74 renderer->ResetCamera(x1,x2,y1,y2,z1,z2);
76 renderer->SetBackground(0.1, 0.1, 0.2);
78 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
79 sizer->Add( wxvtkrenderwindowinteractor , 1, wxEXPAND, 0);
80 panel->SetSizer(sizer);
81 panel->SetAutoLayout(true);
85 //-------------------------------------------------------------------------
87 //-------------------------------------------------------------------------
88 Viewer3DWidget::~Viewer3DWidget()
90 mBox->DisableObservers();
91 mBox->bbSetOutputWidget(NULL);
92 renderwindow->Delete();
94 interactorstyle->Delete();
95 delete wxvtkrenderwindowinteractor;
97 //-------------------------------------------------------------------------
99 //-------------------------------------------------------------------------
100 void Viewer3DWidget::Update()
102 // wxvtkrenderwindowinteractor->Update();
103 wxvtkrenderwindowinteractor->Render();
104 renderer->ResetCameraClippingRange();
106 //-------------------------------------------------------------------------
108 //-------------------------------------------------------------------------
109 vtkRenderer *Viewer3DWidget::GetRenderer()
113 //-------------------------------------------------------------------------
115 //-------------------------------------------------------------------------
116 wxVTKRenderWindowInteractor * Viewer3DWidget::GetInteractor()
118 return wxvtkrenderwindowinteractor;
120 //-------------------------------------------------------------------------
122 void Viewer3DWidget::Refresh(bool eraseBackground , const wxRect* rect )
124 // wxPanel::Refresh(false,rect);
129 //--------------------------------------------------------------------------
130 //-------------------------------------------------------------------------
131 //--------------------------------------------------------------------------
132 //--------------------------------------------------------------------------
135 BBTK_BLACK_BOX_IMPLEMENTATION(Viewer3D,bbtk::WxBlackBox);
138 //-----------------------------------------------------------------
139 void Viewer3D::bbUserSetDefaultValues()
147 bbSetInputObs1(NULL);
148 bbSetInputObs2(NULL);
149 bbSetInputObs3(NULL);
150 bbSetInputObs4(NULL);
151 bbSetInputObs5(NULL);
152 bbSetInputStereo(false);
153 bbSetOutputRenderer( NULL );
154 bbSetOutputInteractor( NULL );
155 bbSetOutputWidget(NULL);
158 //-----------------------------------------------------------------
159 void Viewer3D::bbUserInitializeProcessing()
163 //-----------------------------------------------------------------
164 void Viewer3D::bbUserFinalizeProcessing()
169 void Viewer3D::DisableObservers()
171 Viewer3DWidget* w = (Viewer3DWidget*)bbGetOutputWidget();
174 vtkRenderWindowInteractor *interactor = w->GetInteractor();
175 if (interactor!=NULL)
177 if (bbGetInputObs1()!=NULL)
179 if (bbGetInputObs1()->GetInteractor()!=NULL)
180 bbGetInputObs1()->EnabledOff();
182 if (bbGetInputObs2()!=NULL)
184 if (bbGetInputObs2()->GetInteractor()!=NULL)
185 //bbGetInputObs2()->SetInteractor(NULL);
186 bbGetInputObs2()->EnabledOff();
188 if (bbGetInputObs3()!=NULL)
190 if (bbGetInputObs3()->GetInteractor()!=NULL)
191 //bbGetInputObs3()->SetInteractor(NULL);
192 bbGetInputObs3()->EnabledOff();
194 if (bbGetInputObs4()!=NULL)
196 if (bbGetInputObs4()->GetInteractor()!=NULL)
197 //bbGetInputObs4()->SetInteractor(NULL);
198 bbGetInputObs4()->EnabledOff();
200 if (bbGetInputObs5()!=NULL)
202 if (bbGetInputObs5()->GetInteractor()!=NULL)
203 //bbGetInputObs5()->SetInteractor(NULL);
204 bbGetInputObs5()->EnabledOff();
210 //--------------------------------------------------------------------------
211 void Viewer3D::Process()
214 if (!bbIsShown()) return;
216 // Viewer3DWidget* w = (Viewer3DWidget*)bbGetOutputWidget();
217 // if (w) w->Update();
221 Viewer3DWidget* w = (Viewer3DWidget*)bbGetOutputWidget();
222 if ((firsttime==true) && (w!=NULL)){
225 vtkRenderWindowInteractor *interactor = w->GetInteractor();
226 if (interactor!=NULL)
229 if (bbGetInputObs1()!=NULL)
231 bbGetInputObs1()->SetInteractor(interactor);
232 bbGetInputObs1()->EnabledOn();
234 if (bbGetInputObs2()!=NULL)
236 bbGetInputObs2()->SetInteractor(interactor);
237 bbGetInputObs2()->EnabledOn();
239 if (bbGetInputObs3()!=NULL)
241 bbGetInputObs3()->SetInteractor(interactor);
242 bbGetInputObs3()->EnabledOn();
244 if (bbGetInputObs4()!=NULL)
246 bbGetInputObs4()->SetInteractor(interactor);
247 bbGetInputObs4()->EnabledOn();
249 if (bbGetInputObs5()!=NULL)
251 bbGetInputObs5()->SetInteractor(interactor);
252 bbGetInputObs5()->EnabledOn();
254 bbSetOutputInteractor( w->GetInteractor() );
257 vtkRenderer *renderer = w->GetRenderer();
260 bbSetOutputRenderer( renderer );
262 /*if (bbGetInputIn1()!=NULL) {renderer->AddActor( bbGetInputIn1() ); }
263 if (bbGetInputIn2()!=NULL) {renderer->AddActor( bbGetInputIn2() ); }
264 if (bbGetInputIn3()!=NULL) {renderer->AddActor( bbGetInputIn3() ); }
265 if (bbGetInputIn4()!=NULL) {renderer->AddActor( bbGetInputIn4() ); }
266 if (bbGetInputIn5()!=NULL) {renderer->AddActor( bbGetInputIn5() ); }
267 renderer->ResetCamera();
269 renderer->ComputeVisiblePropBounds(bounds);
270 renderer->ResetCameraClippingRange(bounds);*/
277 if(bbGetOutputRenderer()!=NULL){
278 vtkRenderer *renderer = w->GetRenderer();
279 if (bbGetInputIn1()!=NULL) {renderer->AddActor( bbGetInputIn1() ); }
280 if (bbGetInputIn2()!=NULL) {renderer->AddActor( bbGetInputIn2() ); }
281 if (bbGetInputIn3()!=NULL) {renderer->AddActor( bbGetInputIn3() ); }
282 if (bbGetInputIn4()!=NULL) {renderer->AddActor( bbGetInputIn4() ); }
283 if (bbGetInputIn5()!=NULL) {renderer->AddActor( bbGetInputIn5() ); }
284 renderer->ResetCamera();
286 renderer->ComputeVisiblePropBounds(bounds);
287 renderer->ResetCameraClippingRange(bounds);
291 if (w!=NULL) w->Update();
297 * \brief Create Widget .
301 void Viewer3D::CreateWidget(wxWindow* parent)
304 bbtkDebugMessageInc("Core",9,"Viewer3D::CreateWidget()"<<std::endl);
306 Viewer3DWidget* w = new Viewer3DWidget(this,
313 bbSetOutputWidget(w);
315 bbtkDebugDecTab("Core",9);
319 // This callback is necessary to get actual processing of the view
320 // when window is shown
321 void Viewer3D::OnShowWidget()
324 // Viewer3DWidget* w = (Viewer3DWidget*)bbGetOutputWidget();
325 // if (w) w->Update();