creaImageIO_lib
creaImageIO::WxViewer Class Reference

#include <creaImageIOWxViewer.h>

Inheritance diagram for creaImageIO::WxViewer:
Collaboration diagram for creaImageIO::WxViewer:

Public Member Functions

 WxViewer ()
 Ctors. More...
 
 WxViewer (wxWindow *parent, const wxWindowID id, wxString title, const wxPoint &pos, const wxSize &size)
 
virtual ~WxViewer ()
 Dtor. More...
 
void ShowNextImage ()
 Shows the next image in the image vector. More...
 
void StartPlayer ()
 Starts the image player. More...
 
void StopPlayer ()
 Stops the image player. More...
 
bool RefreshIfNecessary ()
 Refreshes the interface if the current image shown has changed. More...
 
void SetImageVector (std::vector< boost::shared_ptr< ImagePointerHolder > > &pointers)
 Sets a new image vector to be read. More...
 
void SetValue ()
 Set value of slider control. More...
 

Private Member Functions

void OnCineLoop (wxCommandEvent &Event)
 Event to resume or start cine loop. More...
 
void OnSlide (wxCommandEvent &Event)
 Event to change displayed frames with slide control. More...
 
void ShowImage (vtkImageData *im)
 Shows the image passed as parameter. More...
 

Private Attributes

vtkImageViewer2 * mViewer
 Previewer. More...
 
wxSlider * mslide
 Slider. More...
 
wxCheckBox * mcheck
 CheckBox to cine loop. More...
 
crea::creawxVTKRenderWindowInteractor * mInteractor
 Associated wxvtk interactor. More...
 
int mx1
 Current extent. More...
 
int mx2
 
int my1
 
int my2
 
int mz1
 
int mz2
 
double mspx
 Current spacing. More...
 
double mspy
 
double mspz
 
int mCurrent
 Current image shown. More...
 
WxViewerPlayermPlayer
 The threaded movie player. More...
 
wxMutex mMutex
 The mutex. More...
 
bool mNeedRefresh
 Boolean that declares if the player needs to be refreshed. More...
 
vtkImageData * mLastImageShown
 Last image shown. More...
 
std::vector< boost::shared_ptr
< ImagePointerHolder > > 
imagePointers
 The vectors of images to be shown. More...
 
wxFlexGridSizer * mflexSizer
 Sizers to preview images. More...
 
wxBoxSizer * mtopSizer
 

Detailed Description

Definition at line 52 of file creaImageIOWxViewer.h.

Constructor & Destructor Documentation

creaImageIO::WxViewer::WxViewer ( )

Ctors.

creaImageIO::WxViewer::WxViewer ( wxWindow *  parent,
const wxWindowID  id,
wxString  title,
const wxPoint &  pos,
const wxSize &  size 
)

Definition at line 70 of file creaImageIOWxViewer.cpp.

References GimmickDebugMessage, mcheck, mCurrent, mflexSizer, mInteractor, mLastImageShown, mMutex, mNeedRefresh, mPlayer, mslide, mtopSizer, mViewer, OnCineLoop(), and OnSlide().

75  : wxPanel( parent,
76  id,
77  pos,
78  size)
79  {
80  wxMutexLocker lock(mMutex);
81  GimmickDebugMessage(6,"WxViewer::WxViewer"
82  <<std::endl);
83 
84  mNeedRefresh = false;
85  mLastImageShown = NULL;
86 
87  // previewer
88  mInteractor = new crea::creawxVTKRenderWindowInteractor(this,-1);
89  mInteractor->UseCaptureMouseOn();
90 
91  mViewer = vtkImageViewer2::New();
92  mViewer->SetupInteractor ( mInteractor );
93 
94  mCurrent = 0;
95  mPlayer = 0;
96 
97  // Grid to place checkbox and slider
98  mflexSizer = new wxFlexGridSizer(1,2,1,1);
99  //Slider
100  mslide = new wxSlider(this,-1,0,0,1, wxDefaultPosition, wxSize(400,40), wxSL_HORIZONTAL | wxSL_LABELS);
101  Connect( mslide->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WxViewer::OnSlide );
102  //CheckBox
103  mcheck = new wxCheckBox(this,5123,crea::std2wx("Cine Loop"));
104  Connect( mcheck->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &WxViewer::OnCineLoop );
105  mcheck->SetValue(false);
106  mflexSizer->Add(mcheck,0, wxFIXED_MINSIZE);
107  mflexSizer-> Add( mslide,1,wxALIGN_CENTER | wxFIXED_MINSIZE );
108 
109  // Sizer for Previewer and GridSizer
110  mtopSizer = new wxBoxSizer(wxVERTICAL);
111  mtopSizer->Add(mflexSizer,0);
112  mtopSizer-> Add( mInteractor ,1,wxGROW,0);
113  SetSizer(mtopSizer,true);
114 
115  Update();
116  Layout();
117  }

Here is the call graph for this function:

creaImageIO::WxViewer::~WxViewer ( )
virtual

Dtor.

Destructor.

Definition at line 122 of file creaImageIOWxViewer.cpp.

References GimmickDebugMessage, mInteractor, mMutex, and mPlayer.

123  {
124  wxMutexLocker lock(mMutex);
125  GimmickDebugMessage(6,"WxViewer::~WxViewer"
126  <<std::endl);
127  // TO DO : desallocate cleanly
128  if(mPlayer)
129  {
130  mPlayer->Pause();
131  mPlayer->Delete();
132  mPlayer = 0;
133  }
134  delete mInteractor;
135  //delete mslide;
136  //delete mflexSizer;
137  }

Member Function Documentation

void creaImageIO::WxViewer::OnCineLoop ( wxCommandEvent &  Event)
private

Event to resume or start cine loop.

Definition at line 326 of file creaImageIOWxViewer.cpp.

References mcheck, mPlayer, and StartPlayer().

Referenced by WxViewer().

327  {
328  if(!mcheck->IsChecked())
329  {
330  mPlayer->Pause();
331  mPlayer->Delete();
332  mPlayer = 0;
333  }
334  StartPlayer();
335  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::WxViewer::OnSlide ( wxCommandEvent &  Event)
private

Event to change displayed frames with slide control.

Definition at line 341 of file creaImageIOWxViewer.cpp.

References mCurrent, mslide, and StartPlayer().

Referenced by WxViewer().

342  {
343  mCurrent = mslide->GetValue() -1;
344  StartPlayer();
345  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool creaImageIO::WxViewer::RefreshIfNecessary ( )

Refreshes the interface if the current image shown has changed.

Definition at line 280 of file creaImageIOWxViewer.cpp.

References GimmickDebugMessage, mInteractor, and mNeedRefresh.

Referenced by creaImageIO::WxGimmickView::ClearSelection(), and creaImageIO::WxGimmickView::UpdateWindowUI().

281  {
282  if (mNeedRefresh)
283  {
284  GimmickDebugMessage(10,"WxViewer : Refreshing"<<std::endl);
285 
286  mInteractor->Render();
287  mNeedRefresh = false;
288  return true;
289  }
290  return false;
291  }

Here is the caller graph for this function:

void creaImageIO::WxViewer::SetImageVector ( std::vector< boost::shared_ptr< ImagePointerHolder > > &  pointers)

Sets a new image vector to be read.

Definition at line 141 of file creaImageIOWxViewer.cpp.

References GimmickDebugMessage, imagePointers, mMutex, mslide, and StartPlayer().

Referenced by creaImageIO::WxGimmickView::ClearSelection(), creaImageIO::WxGimmickView::ReadImageThreaded(), and creaImageIO::WxGimmickView::WxGimmickView().

142  {
143  wxMutexLocker lock(mMutex);
144  GimmickDebugMessage(6,"WxViewer::SetImageVector"<<std::endl);
145  imagePointers=pointers;
146 
147  mslide->SetMax((int)pointers.size());
148  mslide->SetMin(1);
149  // Refresh don't work, TO MODIFY
150  mslide->Refresh();
151  mslide->ClearTicks();
152  mslide->Hide();
153  mslide->Show();
154  StartPlayer();
155  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::WxViewer::SetValue ( )

Set value of slider control.

Definition at line 350 of file creaImageIOWxViewer.cpp.

References mCurrent, and mslide.

Referenced by creaImageIO::WxViewerPlayer::Entry().

351  {
352  mslide->SetValue(mCurrent);
353  }

Here is the caller graph for this function:

void creaImageIO::WxViewer::ShowImage ( vtkImageData *  im)
private

Shows the image passed as parameter.

Definition at line 204 of file creaImageIOWxViewer.cpp.

References GimmickDebugMessage, mspx, mspy, mspz, mViewer, mx1, mx2, my1, my2, mz1, and mz2.

Referenced by ShowNextImage().

205  {
206  GimmickDebugMessage(6,"WxViewer::ShowImage"
207  <<std::endl);
208  if (im==0) return;
209 
210  mViewer->SetInput(im);
211 
212  mViewer->SetSlice( 0 );
213 
214  int x1,x2,y1,y2,z1,z2;
215  double spx,spy,spz;
216  im->Update();
217 
218 //std::cout << "in WxViewer::ShowImage PrintSelf() =";
219 //im->PrintSelf(std::cout, vtkIndent(2));
220 
221  im->GetSpacing(spx,spy,spz);
222  //im->GetExtent (x1,x2,y1,y2,z1,z2); // JPR
223  im->GetWholeExtent (x1,x2,y1,y2,z1,z2);
224 /*
225 std::cout << "in WxViewer::ShowImage GetWholeExtent ext =";
226  std::cout << " [x1]=" << x1;
227  std::cout << " [x2]=" << x2;
228  std::cout << " [y1]=" << y1;
229  std::cout << " [y2]=" << y2;
230  std::cout << " [z1]=" << z1;
231  std::cout << " [z2]=" << z2;
232 std::cout << std::endl;
233 */
234  if ((x1!=mx1) ||
235  (x2!=mx2) ||
236  (y1!=my1) ||
237  (y2!=my2) ||
238  (z1!=mz1) ||
239  (z2!=mz2) ||
240  (spx!=mspx) ||
241  (spy!=mspy) ||
242  (spz!=mspz)
243  )
244  {
245  mx1 = x1;
246  mx2 = x2;
247  my1 = y1;
248  my2 = y2;
249  mz1 = z1;
250  mz2 = z2;
251  mspx = spx;
252  mspy = spy;
253  mspz = spz;
254 
255  double *range = im->GetScalarRange();
256  mViewer->SetColorWindow(range[1] - range[0]);
257  mViewer->SetColorLevel(0.5 * (range[1] + range[0]));
258 
259  mViewer->GetRenderer()->ResetCamera();
260 
261  //EED 21 mars 2012 FLIP problem ..PLOP..
262  vtkCamera *camera =mViewer->GetRenderer()->GetActiveCamera();
263  camera->SetViewUp ( 0 , -1 , 0 );
264  camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000);
265  camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
266  camera->SetParallelScale( (x2-x1)/3.0 );
267 
268 
269  double bounds[6];
270 
271  mViewer->GetRenderer()->ComputeVisiblePropBounds(bounds);
272 
273  mViewer->GetRenderer()->ResetCameraClippingRange(bounds);
274  mViewer->GetRenderer()->SetBackground(0.1,0.1,0.2);
275  }
276  }

Here is the caller graph for this function:

void creaImageIO::WxViewer::ShowNextImage ( )

Shows the next image in the image vector.

Definition at line 159 of file creaImageIOWxViewer.cpp.

References GimmickMessage, imagePointers, mCurrent, mLastImageShown, mMutex, mNeedRefresh, and ShowImage().

Referenced by creaImageIO::WxViewerPlayer::Entry(), and StartPlayer().

160  {
161 
162 
163  mMutex.Unlock();
164  wxMutexLocker lock(mMutex);
165 
166  GimmickMessage(2,"WxViewer::ShowNextImage() "
167  <<mCurrent+1<<"/"
168  <<imagePointers.size()<<std::endl);
169 
170  if(imagePointers.size()>0)
171  {
172  if (mCurrent<imagePointers.size())
173  {
174  boost::shared_ptr<ImagePointerHolder> iph = imagePointers[mCurrent];
175  //ImagePointerHolder* iph= imagePointers[mCurrent];
176  vtkImageData* currIm=iph->Get();
177  ShowImage(currIm);
178  if ( currIm != mLastImageShown )
179  {
180  mNeedRefresh = true;
181  mLastImageShown = currIm;
182  }
183  mCurrent++;
184  }
185  else
186  {
187  mCurrent = 0;
188  //ImagePointerHolder* iph=imagePointers[mCurrent];
189  boost::shared_ptr<ImagePointerHolder> iph = imagePointers[mCurrent];
190  vtkImageData* currIm=iph->Get();
191  ShowImage(currIm);
192  if ( currIm != mLastImageShown )
193  {
194  mNeedRefresh = true;
195  mLastImageShown = currIm;
196  }
197  mCurrent++;
198  }
199  }
200  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::WxViewer::StartPlayer ( )

Starts the image player.

Definition at line 306 of file creaImageIOWxViewer.cpp.

References mcheck, mPlayer, and ShowNextImage().

Referenced by creaImageIO::WxGimmickView::OnAddDir(), creaImageIO::WxGimmickView::OnAddFiles(), OnCineLoop(), creaImageIO::WxGimmickView::OnDriveMount(), OnSlide(), creaImageIO::WxGimmickView::OnTools(), SetImageVector(), and creaImageIO::WxGimmickView::WxGimmickView().

307  {
308  if(mcheck->IsChecked())
309  {
310  // wxMutexLocker lock(mMutex);
311  if (mPlayer != 0) return;
312  mPlayer = new WxViewerPlayer(this);
313  mPlayer->Create();
314  mPlayer->Run();
315  }
316  else
317  {
318  ShowNextImage();
319  }
320  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::WxViewer::StopPlayer ( )

Stops the image player.

Definition at line 295 of file creaImageIOWxViewer.cpp.

References mMutex, and mPlayer.

Referenced by creaImageIO::WxGimmickView::OnAddDir(), creaImageIO::WxGimmickView::OnAddFiles(), creaImageIO::WxGimmickView::OnDriveMount(), creaImageIO::WxGimmickView::OnTools(), creaImageIO::WxGimmickView::StopPlayer(), and creaImageIO::WxGimmickView::~WxGimmickView().

296  {
297  wxMutexLocker lock(mMutex);
298  if (mPlayer==0 ) return;
299  mPlayer->Delete();
300  mPlayer=0;
301  mMutex.Unlock();
302  }

Here is the caller graph for this function:

Member Data Documentation

std::vector< boost::shared_ptr<ImagePointerHolder> > creaImageIO::WxViewer::imagePointers
private

The vectors of images to be shown.

Definition at line 117 of file creaImageIOWxViewer.h.

Referenced by SetImageVector(), and ShowNextImage().

wxCheckBox* creaImageIO::WxViewer::mcheck
private

CheckBox to cine loop.

Definition at line 97 of file creaImageIOWxViewer.h.

Referenced by OnCineLoop(), StartPlayer(), and WxViewer().

int creaImageIO::WxViewer::mCurrent
private

Current image shown.

Definition at line 107 of file creaImageIOWxViewer.h.

Referenced by OnSlide(), SetValue(), ShowNextImage(), and WxViewer().

wxFlexGridSizer* creaImageIO::WxViewer::mflexSizer
private

Sizers to preview images.

Definition at line 120 of file creaImageIOWxViewer.h.

Referenced by WxViewer().

crea::creawxVTKRenderWindowInteractor* creaImageIO::WxViewer::mInteractor
private

Associated wxvtk interactor.

Definition at line 100 of file creaImageIOWxViewer.h.

Referenced by RefreshIfNecessary(), WxViewer(), and ~WxViewer().

vtkImageData* creaImageIO::WxViewer::mLastImageShown
private

Last image shown.

Definition at line 115 of file creaImageIOWxViewer.h.

Referenced by ShowNextImage(), and WxViewer().

wxMutex creaImageIO::WxViewer::mMutex
private

The mutex.

Definition at line 111 of file creaImageIOWxViewer.h.

Referenced by SetImageVector(), ShowNextImage(), StopPlayer(), WxViewer(), and ~WxViewer().

bool creaImageIO::WxViewer::mNeedRefresh
private

Boolean that declares if the player needs to be refreshed.

Definition at line 113 of file creaImageIOWxViewer.h.

Referenced by RefreshIfNecessary(), ShowNextImage(), and WxViewer().

WxViewerPlayer* creaImageIO::WxViewer::mPlayer
private

The threaded movie player.

Definition at line 109 of file creaImageIOWxViewer.h.

Referenced by OnCineLoop(), StartPlayer(), StopPlayer(), WxViewer(), and ~WxViewer().

wxSlider* creaImageIO::WxViewer::mslide
private

Slider.

Definition at line 94 of file creaImageIOWxViewer.h.

Referenced by OnSlide(), SetImageVector(), SetValue(), and WxViewer().

double creaImageIO::WxViewer::mspx
private

Current spacing.

Definition at line 105 of file creaImageIOWxViewer.h.

Referenced by ShowImage().

double creaImageIO::WxViewer::mspy
private

Definition at line 105 of file creaImageIOWxViewer.h.

Referenced by ShowImage().

double creaImageIO::WxViewer::mspz
private

Definition at line 105 of file creaImageIOWxViewer.h.

Referenced by ShowImage().

wxBoxSizer* creaImageIO::WxViewer::mtopSizer
private

Definition at line 121 of file creaImageIOWxViewer.h.

Referenced by WxViewer().

vtkImageViewer2* creaImageIO::WxViewer::mViewer
private

Previewer.

Definition at line 91 of file creaImageIOWxViewer.h.

Referenced by ShowImage(), and WxViewer().

int creaImageIO::WxViewer::mx1
private

Current extent.

Definition at line 103 of file creaImageIOWxViewer.h.

Referenced by ShowImage().

int creaImageIO::WxViewer::mx2
private

Definition at line 103 of file creaImageIOWxViewer.h.

Referenced by ShowImage().

int creaImageIO::WxViewer::my1
private

Definition at line 103 of file creaImageIOWxViewer.h.

Referenced by ShowImage().

int creaImageIO::WxViewer::my2
private

Definition at line 103 of file creaImageIOWxViewer.h.

Referenced by ShowImage().

int creaImageIO::WxViewer::mz1
private

Definition at line 103 of file creaImageIOWxViewer.h.

Referenced by ShowImage().

int creaImageIO::WxViewer::mz2
private

Definition at line 103 of file creaImageIOWxViewer.h.

Referenced by ShowImage().


The documentation for this class was generated from the following files: