2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
28 #include <creaImageIOWxViewer.h>
31 #include <vtkCamera.h>
32 #include <vtkRenderer.h>
33 #include <vtkImageData.h>
34 #include <creaMessageManager.h>
44 //=====================================================================
46 //=====================================================================
47 class WxViewerPlayer: public wxThread
50 WxViewerPlayer(WxViewer* v) :
62 //=====================================================================
68 //=====================================================================
70 WxViewer::WxViewer(wxWindow *parent,
80 wxMutexLocker lock(mMutex);
81 GimmickDebugMessage(6,"WxViewer::WxViewer" <<std::endl);
84 mLastImageShown = NULL;
87 mInteractor = new crea::wxVTKRenderWindowInteractor(this,-1);
88 mInteractor->UseCaptureMouseOn();
90 mViewer = vtkImageViewer2::New();
91 mViewer->SetupInteractor ( mInteractor );
96 // Grid to place checkbox and slider
97 mflexSizer = new wxFlexGridSizer(1,2,1,1);
99 mslide = new wxSlider(this,-1,0,0,1, wxDefaultPosition, wxSize(400,40), wxSL_HORIZONTAL | wxSL_LABELS);
100 Connect( mslide->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WxViewer::OnSlide );
102 mcheck = new wxCheckBox(this,5123,crea::std2wx("Cine Loop"));
103 Connect( mcheck->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &WxViewer::OnCineLoop );
104 mcheck->SetValue(false);
105 mflexSizer->Add(mcheck,0, wxFIXED_MINSIZE);
106 mflexSizer-> Add( mslide,1,wxALIGN_CENTER | wxFIXED_MINSIZE );
108 // Sizer for Previewer and GridSizer
109 mtopSizer = new wxBoxSizer(wxVERTICAL);
110 mtopSizer->Add(mflexSizer,0);
111 mtopSizer-> Add( mInteractor ,1,wxGROW,0);
112 SetSizer(mtopSizer,true);
117 //=====================================================================
119 //=====================================================================
121 WxViewer::~WxViewer()
123 wxMutexLocker lock(mMutex);
124 GimmickDebugMessage(6,"WxViewer::~WxViewer"<<std::endl);
125 // TO DO : desallocate cleanly
136 //=====================================================================
138 //================================================================
139 void WxViewer::SetImageVector(std::vector<boost::shared_ptr<ImagePointerHolder> >& pointers)
141 wxMutexLocker lock(mMutex);
142 GimmickDebugMessage(6,"WxViewer::SetImageVector"<<std::endl);
143 imagePointers=pointers;
145 mslide->SetMax((int)pointers.size());
147 // Refresh don't work, TO MODIFY
149 mslide->ClearTicks();
155 //================================================================
157 void WxViewer::ShowNextImage()
160 wxMutexLocker lock(mMutex);
162 GimmickMessage(2,"WxViewer::ShowNextImage() "
164 <<imagePointers.size()<<std::endl);
166 if(imagePointers.size()>0)
168 if (mCurrent<imagePointers.size())
170 boost::shared_ptr<ImagePointerHolder> iph = imagePointers[mCurrent];
171 //ImagePointerHolder* iph= imagePointers[mCurrent];
172 vtkImageData* currIm=iph->Get();
174 if ( currIm != mLastImageShown )
177 mLastImageShown = currIm;
182 //ImagePointerHolder* iph=imagePointers[mCurrent];
183 boost::shared_ptr<ImagePointerHolder> iph = imagePointers[mCurrent];
184 vtkImageData* currIm=iph->Get();
186 if ( currIm != mLastImageShown )
189 mLastImageShown = currIm;
193 } // if imagePointers
195 //================================================================
197 //=====================================================================
198 void WxViewer::ShowImage(vtkImageData* im)
200 GimmickDebugMessage(6,"WxViewer::ShowImage"
204 //EED 2017-01-01 Migration VTK7
205 #if VTK_MAJOR_VERSION <= 5
206 mViewer->SetInput(im);
208 mViewer->SetInputData(im);
211 mViewer->SetSlice( 0 );
213 int x1,x2,y1,y2,z1,z2;
215 //EED 2017-01-01 Migration VTK7
216 #if VTK_MAJOR_VERSION <= 5
223 //std::cout << "in WxViewer::ShowImage PrintSelf() =";
224 //im->PrintSelf(std::cout, vtkIndent(2));
226 im->GetSpacing(spx,spy,spz);
227 //im->GetExtent (x1,x2,y1,y2,z1,z2); // JPR
230 //EED 2017-01-01 Migration VTK7
231 #if VTK_MAJOR_VERSION <= 5
232 im->GetWholeExtent (x1,x2,y1,y2,z1,z2);
234 im->GetExtent (x1,x2,y1,y2,z1,z2);
239 std::cout << "in WxViewer::ShowImage GetWholeExtent ext =";
240 std::cout << " [x1]=" << x1;
241 std::cout << " [x2]=" << x2;
242 std::cout << " [y1]=" << y1;
243 std::cout << " [y2]=" << y2;
244 std::cout << " [z1]=" << z1;
245 std::cout << " [z2]=" << z2;
246 std::cout << std::endl;
269 double *range = im->GetScalarRange();
270 mViewer->SetColorWindow(range[1] - range[0]);
271 mViewer->SetColorLevel(0.5 * (range[1] + range[0]));
273 mViewer->GetRenderer()->ResetCamera();
275 //EED 21 mars 2012 FLIP problem ..PLOP..
276 vtkCamera *camera =mViewer->GetRenderer()->GetActiveCamera();
277 camera->SetViewUp ( 0 , -1 , 0 );
278 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000);
279 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
280 camera->SetParallelScale( (x2-x1)/3.0 );
285 mViewer->GetRenderer()->ComputeVisiblePropBounds(bounds);
287 mViewer->GetRenderer()->ResetCameraClippingRange(bounds);
288 mViewer->GetRenderer()->SetBackground(0.1,0.1,0.2);
291 //================================================================
293 //================================================================
294 bool WxViewer::RefreshIfNecessary()
298 GimmickDebugMessage(10,"WxViewer : Refreshing"<<std::endl);
299 mInteractor->Render();
300 mNeedRefresh = false;
305 //================================================================
307 //==================================================
308 void WxViewer::StopPlayer()
310 wxMutexLocker lock(mMutex);
311 if (mPlayer==NULL ) return;
316 //================================================================
318 //==================================================
319 void WxViewer::StartPlayer()
321 if(mcheck->IsChecked())
323 // wxMutexLocker lock(mMutex);
324 if (mPlayer != NULL) return;
325 mPlayer = new WxViewerPlayer(this);
333 //================================================================
335 //==================================================
337 void WxViewer::OnCineLoop(wxCommandEvent &Event)
339 if(!mcheck->IsChecked())
348 //================================================================
350 //==================================================
352 void WxViewer::OnSlide(wxCommandEvent &Event)
354 mCurrent = mslide->GetValue() -1;
357 //================================================================
359 //==================================================
361 void WxViewer::SetValue()
363 mslide->SetValue(mCurrent);
366 // BEGIN_EVENT_TABLE(WxGimmickFrame, wxDialog)
368 //================================================================
370 //========================================================================
371 //========================================================================
372 //========================================================================
373 //========================================================================
374 //========================================================================
375 //========================================================================
376 //========================================================================
377 //========================================================================
379 void* WxViewerPlayer::Entry()
382 GimmickDebugMessage(6,"WxViewerPlayer::Entry()"<<std::endl);
384 while(!TestDestroy())
387 mWxViewer->ShowNextImage();
388 mWxViewer->SetValue();
391 endwait = clock () + 0.2 * CLOCKS_PER_SEC ;
392 while (clock() < endwait ) {}
398 //=====================================================================
400 //=====================================================================
401 void WxViewerPlayer::OnExit()
403 GimmickDebugMessage(6,"WxViewerPlayer::OnExit() "<<std::endl);
407 } // EO namespace creaImageIO