1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 /////////////////////////////////////////////////////////////////////////////
27 // Name: Test_ReadingPriorityFrm.cpp
35 /////////////////////////////////////////////////////////////////////////////
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
40 #include "wx/wxprec.h"
41 #include <wx/thread.h>
48 #include "wxReadingPriorityPanel.h"
51 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
54 PriorityLoop::PriorityLoop(){
56 _loadingSerie = false;
57 _forceReadRegion = false;
58 _i_forceReadReagion = -1;
59 _needToChange = false;
62 // ----------------------------------------------------------------------------
63 PriorityLoop::~PriorityLoop(){
64 if (_vecIdImage!=NULL) {
68 // ----------------------------------------------------------------------------
69 void PriorityLoop::StopLoop(){
70 _loadingSerie = false;
72 // ----------------------------------------------------------------------------
73 bool PriorityLoop::IsLoop(){
76 // ----------------------------------------------------------------------------
77 void PriorityLoop::ForceEndLoopRegion(){
78 _forceReadRegion=true;
81 // ----------------------------------------------------------------------------
82 void PriorityLoop::InitLoop(){
85 Create_Empty_Vector();
90 // ----------------------------------------------------------------------------
91 void PriorityLoop::Iteration(){
95 if (_forceReadRegion==false){
96 int ii,i=Get_i_image();
97 for (ii=i-_deltaImg;ii<=i+_deltaImg;ii++){
98 if (_Action_i( ii )==true){
103 _loadingSerie=_ForceEndLoopRegion();
106 if (_counterReading==_maxImages){
112 // ----------------------------------------------------------------------------
113 bool PriorityLoop::_ForceEndLoopRegion (){
115 if (_i_forceReadReagion==-1){
116 _i_forceReadReagion=_start;
118 _Action_i( _i_forceReadReagion );
119 _i_forceReadReagion++;
120 if (_i_forceReadReagion>_end){
125 // ----------------------------------------------------------------------------
126 void PriorityLoop::Create_Empty_Vector(){
127 if (_vecIdImage!=NULL) {
130 _vecIdImage = (bool*)malloc(sizeof(bool)*(_maxImages+1) );
132 for (i=0; i<=_maxImages;i++){
133 _vecIdImage[i]=false;
138 // ----------------------------------------------------------------------------
139 void PriorityLoop::SetStartEndActualMax(int start,int end, int actual, int deltaImg,int maxImages){
143 _tdeltaImg = deltaImg;
144 _tmaxImages = maxImages;
145 _needToChange = true;
147 // ----------------------------------------------------------------------------
148 void PriorityLoop::NeedToChange(){
149 if (_needToChange==true){
150 _needToChange = false;
154 _deltaImg = _tdeltaImg;
155 _maxImages = _tmaxImages;
160 // ----------------------------------------------------------------------------
161 void PriorityLoop::InitConfiguration(){
162 _forceReadRegion=false;
164 for (i=0;i<PriorityLoadImage_MAX_P;i++){
172 // ----------------------------------------------------------------------------
173 bool PriorityLoop::_Action_i( int i ){
176 if ((i>=0) && (i<_maxImages)){
177 if (_vecIdImage[i]==false ) {
187 // ----------------------------------------------------------------------------
188 void PriorityLoop::Action_i( int i ){
191 // ----------------------------------------------------------------------------
192 int PriorityLoop::Get_i_image(){
196 while ((i==-1) || (p==4) ){
197 if (_priorityType==0){
198 if ((_priority<=9) && (_priority>=5)) { p=0; }
199 if ((_priority<=4) && (_priority>=2)) { p=1; }
200 if ((_priority<=1) && (_priority>=0)) { p=2; }
202 if (_priorityType==1){
203 if ((_priority<=9) && (_priority>=4)) { p=1; }
204 if ((_priority<=3) && (_priority>=2)) { p=2; }
205 if ((_priority<=1) && (_priority>=0)) { p=3; }
207 if (_priorityType==2){
208 if ((_priority<=9) && (_priority>=3)) { p=2; }
209 if ((_priority<=2) && (_priority>=0)) { p=3; }
211 if (_priorityType==3){
212 if ((_priority<=9) && (_priority>=0)) { p=3; }
214 if (_priorityType==4){
218 if (_priority==-1) {_priority=9;}
220 if (p==0) { i=Geti(p,5,_start,_actual ,_actual ,_end); }
221 if (p==1) { i=Geti(p,1,_start,_actual ,_actual ,_end); }
222 if (p==2) { i=Geti(p,5,0 ,_start ,_end ,_maxImages); }
223 if (p==3) { i=Geti(p,1,0 ,_start ,_end ,_maxImages); }
224 if (p==4) { i=Geti(p,1,0 ,_maxImages ,_maxImages ,_maxImages); }
226 if ((_priorityType==0) && (p==0) && (i==-1)) { _priorityType++; _priority=9; }
227 if ((_priorityType==1) && (p==1) && (i==-1)) { _priorityType++; _priority=9; }
228 if ((_priorityType==2) && (p==2) && (i==-1)) { _priorityType++; _priority=9; }
229 if ((_priorityType==3) && (p==3) && (i==-1)) { _priorityType++; _priority=9; }
234 // ----------------------------------------------------------------------------
236 int PriorityLoop::Geti(int id,int step,int start,int actualg,int actuald,int end){
241 if (_dg[id]==true) { _counterActual[id] = _counterActual[id]+step; }
242 tempig=actualg - _counterActual[id];
243 tempid=actuald + _counterActual[id];
246 if (_vecIdImage[tempig]==false ) {
253 if (_vecIdImage[tempid]==false ) {
258 if ((tempig<start) && (tempid>end)){
265 // ----------------------------------------------------------------------------
266 void PriorityLoop::WaitUntil_i_isDone(int i){
267 WaitUntil_segment_isDone(i-_deltaImg,i+_deltaImg,false);
269 // ----------------------------------------------------------------------------
270 void PriorityLoop::WaitUntil_segment_isDone(int start, int end,bool forceEndLoopRegion){
271 if (forceEndLoopRegion==true) { ForceEndLoopRegion(); }
272 if (_loadingSerie==true){
285 ok = ok && _vecIdImage[i];
289 wxThread::Sleep(100);
295 // ----------------------------------------------------------------------------
296 // ----------------------------------------------------------------------------
297 // ----------------------------------------------------------------------------
299 // ----------------------------------------------------------------------------
300 PriorityLoadImageBar::PriorityLoadImageBar(marFilesBase *marfilesbase, BarLoading *bar){
301 _marfilesbase=marfilesbase;
304 // ----------------------------------------------------------------------------
305 PriorityLoadImageBar::~PriorityLoadImageBar(){
307 // ----------------------------------------------------------------------------
308 void PriorityLoadImageBar::Action_i(int i){
316 // _bar->Refresh(false);
320 // _bar->Refresh(false);
328 if (_marfilesbase!=NULL){
329 _marfilesbase->loadImage(i);
330 vtkImageData *imagedata = _marfilesbase->getVolume()->castVtk();
334 // ----------------------------------------------------------------------------
335 void PriorityLoadImageBar::RefreshForce(){
336 _bar->RefreshForce();
339 // ----------------------------------------------------------------------------
340 // ----------------------------------------------------------------------------
341 // ----------------------------------------------------------------------------
343 IMPLEMENT_CLASS(BarLoading, wxPanel)
344 BEGIN_EVENT_TABLE(BarLoading, wxPanel)
345 EVT_PAINT(BarLoading::OnPaint)
348 static wxMutex *s_mutexProtectingTheGlobalData=NULL;
351 // ----------------------------------------------------------------------------
352 BarLoading::BarLoading(wxWindow *parent, int w, int h)
353 :wxPanel(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
358 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
359 _bitmap = new wxBitmap(_w,_h);
363 if (s_mutexProtectingTheGlobalData!=NULL)
365 delete s_mutexProtectingTheGlobalData;
366 s_mutexProtectingTheGlobalData=NULL;
368 s_mutexProtectingTheGlobalData = new wxMutex();
372 // ----------------------------------------------------------------------------
373 BarLoading::~BarLoading()
376 // ----------------------------------------------------------------------------
377 void BarLoading::SetI(int i)
380 s_mutexProtectingTheGlobalData->Lock();
384 while (_flag2_bitmap==false){
395 temp_dc.SelectObject( *_bitmap );
396 int x = (_w*i)/_sizeData;
397 int d = (_w/_sizeData)+1;
398 temp_dc.SetBrush(wxBrush( wxColour(0,0,255),wxSOLID ));
399 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
400 temp_dc.DrawRectangle(x,0,d,_h);
405 s_mutexProtectingTheGlobalData->Unlock();
409 // ----------------------------------------------------------------------------
410 void BarLoading::RefreshForce()
415 // ----------------------------------------------------------------------------
416 void BarLoading::SetSizeData(int sizeData)
420 // ----------------------------------------------------------------------------
421 void BarLoading::Reset()
423 if (_flag_bitmap==true){
425 temp_dc.SelectObject( *_bitmap );
426 temp_dc.SetBrush(wxBrush( wxColour(255,0,0),wxSOLID ));
427 temp_dc.SetPen(wxPen( wxColour(255,0,0),1,wxSOLID ));
428 temp_dc.DrawRectangle(0,0,_w,_h);
434 // ----------------------------------------------------------------------------
435 void BarLoading::Paint( )
438 wxMutexLocker lock(*s_mutexProtectingTheGlobalData);
441 if (_flag_bitmap==true){
443 temp_dc.SelectObject( *_bitmap );
445 int i,ii,size=lstInt.size();
446 for (ii=0;ii<size; ii++)
449 int x = (_w*i)/_sizeData;
450 int d = (_w/_sizeData)+1;
451 temp_dc.SetBrush(wxBrush( wxColour(0,0,255),wxSOLID ));
452 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
453 temp_dc.DrawRectangle(x,0,d,_h);
460 wxPaintDC dc( this );
461 dc.Blit(0,0, _w, _h, &temp_dc, 0, 0);
463 _flag2_bitmap=true;//SIL//POR QUE TANTAS VECES LO MISMO??????
474 // ----------------------------------------------------------------------------
475 void BarLoading::OnPaint( wxPaintEvent &WXUNUSED(event) )
481 // ----------------------------------------------------------------------------
482 // ----------------------------------------------------------------------------
483 // ----------------------------------------------------------------------------
484 // ----------------------------------------------------------------------------
486 IMPLEMENT_CLASS(BarRange, wxPanel)
487 BEGIN_EVENT_TABLE(BarRange, wxPanel)
488 EVT_PAINT(BarRange::OnPaint)
492 BarRange::BarRange(wxWindow *parent, int w, int h)
493 :wxPanel(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
498 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
499 _bitmap = new wxBitmap(_w,_h);
505 // ----------------------------------------------------------------------------
506 BarRange::~BarRange()
509 // ----------------------------------------------------------------------------
510 void BarRange::SetStart(int i)
514 // ----------------------------------------------------------------------------
515 void BarRange::SetActual(int i)
519 // ----------------------------------------------------------------------------
520 void BarRange::SetEnd(int i)
524 // ----------------------------------------------------------------------------
525 void BarRange::SetMax(int i)
529 // ----------------------------------------------------------------------------
530 void BarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
536 temp_dc.SelectObject( *_bitmap );
537 wxPaintDC dc( this );
538 dc.Blit(0,0, _w, _h, &temp_dc, 0, 0);
541 // ----------------------------------------------------------------------------
543 void BarRange::RefreshView()
547 int px1=(_w*_start)/_max;
548 int px2=(_w*_end)/_max;
549 int px3=(_w*_actual)/_max;
552 temp_dc.SelectObject( *_bitmap );
555 wxColour colourParent = GetParent()->GetBackgroundColour();
556 temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID ));
557 temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID ));
558 temp_dc.DrawRectangle(0,0,_w,_h);
561 temp_dc.SetBrush(wxBrush( wxColour(255,0,255),wxSOLID ));
562 temp_dc.SetPen(wxPen( wxColour(255,0,255),1,wxSOLID ));
563 temp_dc.DrawRectangle( px1 , 0 , px2-px1 , _h );
565 // 2 Start End ( triangles )
566 temp_dc.SetBrush(wxBrush( wxColour(0,0,255),wxSOLID ));
567 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
574 temp_dc.DrawPolygon(3,points,px1,0);
575 temp_dc.DrawPolygon(3,points,px2,0);
577 // Actual ( black triangles )
578 // 2 Start End ( yellow triangles )
579 temp_dc.SetBrush(wxBrush( wxColour(255,255,0),wxSOLID ));
580 temp_dc.SetPen(wxPen( wxColour(255,255,0),1,wxSOLID ));
587 temp_dc.DrawPolygon(3,points,px3,0);
590 // ----------------------------------------------------------------------------
591 void BarRange::RefreshForce()
596 // ----------------------------------------------------------------------------
599 // ----------------------------------------------------------------------------
600 // ----------------------------------------------------------------------------
601 // ----------------------------------------------------------------------------
606 PriorityBar::PriorityBar(BarLoading *bar){
609 // ----------------------------------------------------------------------------
610 PriorityBar::~PriorityBar(){
612 // ----------------------------------------------------------------------------
613 void PriorityBar::Action_i(int i){
616 wxThread::Sleep(100);
618 // ----------------------------------------------------------------------------
619 void PriorityBar::RefreshForce(){
620 _bar->RefreshForce();
624 // ----------------------------------------------------------------------------
625 // ----------------------------------------------------------------------------
626 // ----------------------------------------------------------------------------
628 // ----------------------------------------------------------------------------
629 AdminThreadEED::AdminThreadEED()
630 : m_condAllDone(m_mutexAllDone){
632 // the mutex associated with a condition must be initially locked, it will
633 // only be unlocked when we call Wait()
634 m_mutexAllDone.Lock();
635 m_waitingUntilAllDone = FALSE;
638 // ----------------------------------------------------------------------------
639 AdminThreadEED::~AdminThreadEED(){
640 // the mutex must be unlocked before being destroyed
641 m_mutexAllDone.Unlock();
644 // ----------------------------------------------------------------------------
645 // ----------------------------------------------------------------------------
646 // ----------------------------------------------------------------------------
648 // ----------------------------------------------------------------------------
649 MyThread::MyThread(PriorityLoop *priorityLoop,AdminThreadEED *adminThreadEED){
650 _priorityLoop = priorityLoop;
651 _adminThreadEED = adminThreadEED;
655 // ----------------------------------------------------------------------------
656 void MyThread::OnExit(){
657 _priorityLoop->StopLoop();
658 wxCriticalSectionLocker locker(_adminThreadEED->m_critsect);
659 wxArrayThread& threads = _adminThreadEED->m_threads;
660 threads.Remove(this);
662 if ( threads.IsEmpty() ) {
663 if ( _adminThreadEED->m_waitingUntilAllDone ){
664 _adminThreadEED->m_waitingUntilAllDone = FALSE;
665 wxMutexLocker lock(_adminThreadEED->m_mutexAllDone);
666 _adminThreadEED->m_condAllDone.Signal();
670 // ----------------------------------------------------------------------------
672 void *MyThread::Entry(){
673 _priorityLoop->InitLoop();
674 while ( _priorityLoop->IsLoop()==true ){
675 if ( TestDestroy() ){
678 _priorityLoop->Iteration();
685 // ----------------------------------------------------------------------------
686 // ----------------------------------------------------------------------------
687 // ----------------------------------------------------------------------------
690 // ----------------------------------------------------------------------------
691 LoadRangeImage::LoadRangeImage(wxWindow *parent,marFilesBase *marfilesbase )
692 : wxPanel(parent, -1)
694 _marfilesbase = marfilesbase;
696 wxPanel *panel = new wxPanel(this, -1);
698 _bar = new BarLoading(panel,wx-10,15);
699 //SIL//_barRange = new BarRange(panel,wx-10,5);
701 _sl_barRange_ROI = new mBarRange(panel,wx-10 ,70);
702 _sl_barRange_ROI-> SetOrientation(true);
703 _sl_barRange_ROI -> setVisibleLabels ( true );
704 _sl_barRange_ROI -> setActiveStateTo ( true );
705 _sl_barRange_ROI -> setDeviceBlitStart (2,2);
706 _sl_barRange_ROI -> setDeviceEndMargin(0);
707 _sl_barRange_ROI -> SetTrianglesHalfWidth(5);
710 parent->SetBackgroundColour(wxColour(255,255,255 )) ;
711 panel->SetBackgroundColour(parent-> GetBackgroundColour());
714 parent->SetBackgroundColour(wxColour(255,0,0 )) ;
715 panel->SetBackgroundColour(wxColour(0,255,0 )) ;*/
717 panel->SetBackgroundColour(wxColour(0,0,0 ));
718 parent->SetBackgroundColour(wxColour(255,0,0 ));
719 (parent->GetParent())->SetBackgroundColour(wxColour(0,255,0 )) ;
720 ((parent->GetParent())->GetParent())->SetBackgroundColour(wxColour(0,0,255 )) ;*/
723 _sl_barRange_ROI-> setBackgroundColor( parent-> GetBackgroundColour()/*wxColour(255,255,255 )*/);
724 reseteableActual =true;
728 _sldActual = new wxSlider(panel,-1,0,0,10000,wxDefaultPosition,wxSize(wx-10,20),wxSL_HORIZONTAL);
730 _btnStart = new wxButton(panel,-1,_T("Start:"),wxDefaultPosition, wxSize(70,20) );
731 _btnEnd = new wxButton(panel,-1,_T("End:"),wxDefaultPosition, wxSize(70,20) );
732 _textActual = new wxStaticText(panel,-1,_T("Actual: 0000000000"));*/
733 _textActual = new wxStaticText(panel,-1,_T(" "));
736 // _sldActual ->SetSize(wx-10,20);
737 // _btnStart ->SetSize(70,20);
738 // _btnEnd ->SetSize(70,20);
740 //SIL//_sizer1a = new wxFlexGridSizer(1);
741 //SIL//_sizer1a->Add(_btnStart );
742 //SIL//_sizer1a->Add(_textActual ,wxALIGN_CENTER,0 );
743 //SIL//_sizer1a->Add(_btnEnd );
745 // _btnStart ->Show(true);
746 // _btnEnd ->Show(true);
748 //SIL//_sizer1a->Show(_btnStart, false);
749 //SIL//_sizer1a->Show(_btnEnd, false);
752 // _sizer1a = new wxFlexGridSizer(1);
753 // _sizer1a->Add(_textActual ,wxALIGN_CENTER,0 );
755 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
756 // sizer1->AddGrowableRow(1);
757 // wxBoxSizer *sizer1 = new wxBoxSizer(wxVERTICAL );
758 //SIL//sizer1->Add(_sldActual);
760 //SIL//sizer1->Add(_barRange);
762 sizer1->Add(_sl_barRange_ROI,1,wxEXPAND,0);
764 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
765 // sizer -> AddGrowableRow(1);//SIL//
766 // sizer->Add(_sizer1a, 1, wxALL , 5 );
767 sizer->Add(_textActual);
768 sizer->Add(sizer1,1,wxEXPAND,0);
772 /*wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
773 sizer->Add(_bar, 0, wxEXPAND);
774 sizer->Add(_sl_barRange_ROI, 0, wxEXPAND);*/
778 Connect(_btnStart->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) (wxCommandEventFunction) &LoadRangeImage::OnBtnStart );
779 Connect(_btnEnd->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) (wxCommandEventFunction) &LoadRangeImage::OnBtnEnd );
781 //Connect(_sldActual->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) (wxEventFunction) (wxScrollEventFunction) &LoadRangeImage::OnSliceActual );
783 Connect(_sl_barRange_ROI->GetId(),wxEVT_TSBAR,(wxObjectEventFunction) (wxCommandEventFunction) &LoadRangeImage::OnBarrange );
784 Connect(_sl_barRange_ROI->GetId(),wxEVT_TSBAR_START,(wxObjectEventFunction) (wxCommandEventFunction) &LoadRangeImage::OnStartChange_BarRange );
785 Connect(_sl_barRange_ROI->GetId(),wxEVT_TSBAR_END,(wxObjectEventFunction) (wxCommandEventFunction) &LoadRangeImage::OnEndChange_BarRange );
786 Connect(_sl_barRange_ROI->GetId(),wxEVT_TSBAR_ACTUAL,(wxObjectEventFunction) (wxCommandEventFunction) &LoadRangeImage::OnActualChange_BarRange );
787 Connect(_sl_barRange_ROI->GetId(),wxEVT_TSBAR_MOVED,(wxObjectEventFunction) (wxCommandEventFunction) &LoadRangeImage::OnBarMoved_BarRange );
788 Connect(_sl_barRange_ROI->GetId(),wxEVT_SELECTION_END,(wxObjectEventFunction) (wxCommandEventFunction) &LoadRangeImage::OnSelectionEnd_BarRange );
795 _timer = new wxTimer(this);
797 Connect( _timer->GetId(), wxEVT_TIMER , (wxObjectEventFunction) (wxTimerEventFunction) &LoadRangeImage::OnTimer );
801 panel->SetSizer(sizer);
802 panel->SetAutoLayout( TRUE );
804 this->SetSize(wx,75);
805 panel->SetSize(wx,75);
808 _priorityLoadImageBar = new PriorityLoadImageBar(_marfilesbase,_bar);
809 _adminThreadEED = new AdminThreadEED();
811 // ----------------------------------------------------------------------------
812 LoadRangeImage::~LoadRangeImage()
821 // ----------------------------------------------------------------------------
822 void LoadRangeImage::ResetLoadRegion()
827 //SIL//a=_sldActual->GetValue();
828 //a=_sl_barRange_ROI->GetActual();
835 _priorityLoadImageBar->SetStartEndActualMax(s,e,a,0,_maxZ);
838 // ----------------------------------------------------------------------------
839 void LoadRangeImage::Start( )
842 vtkImageData *vol = _marfilesbase->getVolume( )->castVtk();
844 vol->GetDimensions(dim);
850 this->SetStartSlice(_startSlice);
851 this->SetEndSlice(_endSlice);
854 _bar -> SetSizeData(_maxZ);
855 //SIL// Para quitar luego als siguientes dos lineas
856 /*_sldActual -> SetRange(0, _maxZ);
857 _sldActual -> SetValue( _maxZ/2 );*/
860 _sl_barRange_ROI -> setRepresentedValues (0,_maxZ);
861 _sl_barRange_ROI -> SetActual(_maxZ/2);
862 _sl_barRange_ROI -> RefreshForce();
866 SetEndSlice( _maxZ );
867 _toShowSlice = _sl_barRange_ROI->GetActual();
871 _marfilesbase->ResetLstFileNotReaded();
875 // ----------------------------------------------------------------------------
876 void LoadRangeImage::_Start()
880 _mythread = new MyThread (_priorityLoadImageBar,_adminThreadEED);
882 wxCriticalSectionLocker enter(_adminThreadEED->m_critsect);
883 _adminThreadEED->m_threads.Add(_mythread);
884 if ( _mythread->Run() != wxTHREAD_NO_ERROR ){
885 wxLogError(wxT("Can't start thread!"));
888 // ----------------------------------------------------------------------------
889 void LoadRangeImage::_Stop( )
892 _adminThreadEED->m_critsect.Enter();
893 // stop the last thread
894 if ( _adminThreadEED->m_threads.IsEmpty() ){
895 //wxLogError(wxT("No thread to stop!"));
896 _adminThreadEED->m_critsect.Leave();
898 wxThread *_mythread = _adminThreadEED->m_threads.Last();
899 // it's important to leave critical section before calling Delete()
900 // because delete will (implicitly) call OnExit() which also tries
901 // to enter the same crit section - would dead lock.
902 _adminThreadEED->m_critsect.Leave();
908 // ----------------------------------------------------------------------------
910 void LoadRangeImage::OnBtnRestart( wxCommandEvent& event ){
911 _priorityLoadImageBar->WaitUntil_segment_isDone( _sldStart->GetValue(),_sldEnd->GetValue() );
918 // ----------------------------------------------------------------------------
919 void LoadRangeImage::OnSliceActual(wxScrollEvent& event)
921 //SIL// metodo para quitar
922 _toShowSlice = _sl_barRange_ROI->GetActual();
927 // ----------------------------------------------------------------------------
929 void LoadRangeImage::OnBtnStart( wxCommandEvent & event )
931 //SIL// metodo para quitar
932 /*SetStartSlice( _sldActual->GetValue() );
937 // ----------------------------------------------------------------------------
938 void LoadRangeImage::OnBtnEnd( wxCommandEvent & event )
940 //SIL// metodo para quitar
941 /*SetEndSlice( _sldActual->GetValue() );
945 // ----------------------------------------------------------------------------
946 void LoadRangeImage::SetStartEnd( int start, int end )
948 SetStartSlice( start );
954 // ----------------------------------------------------------------------------
955 void LoadRangeImage::Reset( )
957 int delta= (int) (_maxZ*0.1);
958 SetStartSlice( 0 + delta );
959 SetEndSlice( _maxZ - delta );
962 // _btnStart ->Show(true);
963 // _btnEnd ->Show(true);
965 //SIL//_sizer1a->Show(_btnStart, true );
966 //SIL//_sizer1a->Show(_btnEnd , true );
967 // _sizer1a->Layout();
971 // ----------------------------------------------------------------------------
972 void LoadRangeImage::SetStartSlice(int value)
974 if (value<_endSlice){
977 txt.Printf(_T("%d"),_startSlice);
978 _textActual->SetLabel(txt);*/
980 //SIL// para quitar las siguientes 4 lineas
982 _btnStart->SetLabel(_T("Start: ")+txt);
983 _barRange->SetMax(_maxZ);
984 _barRange->SetStart(_startSlice);
985 _barRange->RefreshForce();*/
988 _sl_barRange_ROI->SetMax(_maxZ);
989 _sl_barRange_ROI->SetStart(_startSlice);
990 _sl_barRange_ROI->RefreshForce();
993 // ----------------------------------------------------------------------------
994 void LoadRangeImage::SetEndSlice(int value)
996 if (value>_startSlice){
999 txt.Printf(_T("%d"),_endSlice);
1000 _textActual->SetLabel(txt);*/
1001 //SIL//_btnEnd->SetLabel(_T("End: ")+txt);
1002 _sl_barRange_ROI->SetEnd(_endSlice);
1003 _sl_barRange_ROI->RefreshForce();
1008 // ----------------------------------------------------------------------------
1009 void LoadRangeImage::RefreshSlice()
1011 //SIL// _priorityLoadImageBar->WaitUntil_i_isDone( _sldActual->GetValue() );
1012 _priorityLoadImageBar->WaitUntil_i_isDone( _toShowSlice );
1014 wxCommandEvent newevent(wxEVT_COMMAND_MENU_SELECTED,12122);
1015 this->GetParent()->ProcessEvent(newevent);
1018 //SIL//text.Printf(_T("Actual: %d "), _sldActual->GetValue() );
1019 text.Printf(_T("Start: %d\n Actual: %d\n End: %d"), _sl_barRange_ROI->GetStart(),_sl_barRange_ROI->GetActual(),_sl_barRange_ROI->GetEnd() );
1020 _textActual->SetLabel(text);*/
1022 //SIL// Para borrar las lineas de barrange
1023 /*_barRange->SetMax(_maxZ);
1024 _barRange->SetActual( _sldActual->GetValue() );
1025 _barRange->SetStart(_startSlice);
1026 _barRange->SetEnd(_endSlice);
1027 _barRange->RefreshForce();*/
1031 // _sl_barRange_ROI->SetMax(_maxZ);
1032 //_sl_barRange_ROI->SetActual( _sldActual->GetValue() );
1033 // _sl_barRange_ROI->SetStart(_startSlice);
1034 // _sl_barRange_ROI->SetEnd(_endSlice);
1035 _sl_barRange_ROI->RefreshForce();
1042 // _imageViewerWidget->SetZSlice( _sldActual->GetValue() );
1043 // _imageViewerWidget->Render();
1045 // ----------------------------------------------------------------------------
1046 void LoadRangeImage::CallBackOnMouseWheel( wxMouseEvent& event )
1048 /* //SIL ImageViewer no existe//int actual = _imageViewerWidget->GetZSlice();
1049 if (actual<_sl_barRange_ROI->GetActual()) {
1050 actual = _sl_barRange_ROI->GetActual();
1052 if (actual>_sl_barRange_ROI->GetEnd()) {
1053 actual = _sl_barRange_ROI->GetEnd();
1055 _sl_barRange_ROI->SetActual( actual );
1059 /*int actual = _imageViewerWidget->GetZSlice();
1060 if (actual<_sldStart->GetValue()) {
1061 actual = _sldStart->GetValue();
1063 if (actual>_sldEnd->GetValue()) {
1064 actual = _sldEnd->GetValue();
1066 _sldActual->SetValue( actual );
1071 // ----------------------------------------------------------------------------
1072 void LoadRangeImage::ForceToFinisReadActiveImages()
1077 _priorityLoadImageBar->WaitUntil_segment_isDone(s,e,true);
1081 std::string msgLstFile( _marfilesbase->GetMsgLstFile() );
1082 if ( msgLstFile!="")
1084 wxDialog *dialog = new wxDialog( this , -1, wxString(_T("The following files doesn't exist:")), wxDefaultPosition, wxSize(550,300), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
1085 wxTextCtrl *textCtrl = new wxTextCtrl(dialog, -1, wxString (msgLstFile.c_str(), wxConvUTF8) ,wxDefaultPosition , wxSize(100,100) , wxTE_MULTILINE | wxTE_READONLY );
1086 textCtrl->SetSelection(0,0);
1087 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
1088 sizer->Add( textCtrl , 1, wxALL|wxEXPAND, 0);
1089 dialog->SetAutoLayout(true);
1090 dialog->SetSizer( sizer ); // use the sizer for layout
1093 // dialog->FitInside();
1094 dialog->ShowModal();
1101 // ----------------------------------------------------------------------------
1102 void LoadRangeImage::GetROI( int extent[6] )
1104 extent[4]=_startSlice;
1105 extent[5]=_endSlice;
1107 // ----------------------------------------------------------------------------
1108 void LoadRangeImage::SetActualSlice( int actual )
1111 if ( actual > _endSlice ){
1114 if ( actual < _startSlice ){
1115 actual = _startSlice;
1118 //SIL//_sldActual->SetValue( actual );//SIL// para quitar esta linea
1120 _sl_barRange_ROI->SetActual( actual);//de pronto no se necesita aca
1121 _toShowSlice=actual;
1126 // ----------------------------------------------------------------------------
1127 int LoadRangeImage::GetActualSlice( )
1129 return _toShowSlice;/*_sl_barRange_ROI->GetActual()*/;
1131 // ----------------------------------------------------------------------------
1133 void LoadRangeImage::ResetActualSlice( )
1135 if( reseteableActual )
1136 _toShowSlice = _sl_barRange_ROI->GetActual();
1139 //------------------------------------------------------------------------
1140 // Events captured form the barrange used configuring the ROI
1141 //------------------------------------------------------------------------
1142 void LoadRangeImage::OnBarrange(wxCommandEvent& event)
1146 void LoadRangeImage::OnActualChange_BarRange(wxCommandEvent& event)
1148 //reseteableActual =true;
1149 _toShowSlice = _sl_barRange_ROI->GetActual();
1153 void LoadRangeImage::OnStartChange_BarRange(wxCommandEvent& event)
1155 reseteableActual =false;
1156 _toShowSlice = _sl_barRange_ROI->GetStart();
1157 SetStartSlice( _sl_barRange_ROI->GetStart() );
1162 void LoadRangeImage::OnEndChange_BarRange(wxCommandEvent& event)
1164 reseteableActual =false;
1165 _toShowSlice = _sl_barRange_ROI->GetEnd();
1166 SetEndSlice( _sl_barRange_ROI->GetEnd() );
1170 void LoadRangeImage:: OnBarMoved_BarRange (wxCommandEvent& event)
1172 SetEndSlice( _sl_barRange_ROI->GetEnd() );
1173 SetStartSlice( _sl_barRange_ROI->GetStart() );
1178 void LoadRangeImage:: OnSelectionEnd_BarRange (wxCommandEvent& event)
1180 reseteableActual = true;
1184 void LoadRangeImage:: OnTimer(wxTimerEvent& event)
1186 // EED used in linux (see constructor)
1187 _bar->Refresh(false);
1193 // ----------------------------------------------------------------------------
1194 // ----------------------------------------------------------------------------
1195 // ----------------------------------------------------------------------------