wxReadingPriorityPanel.cpp

Go to the documentation of this file.
00001 
00002 // Name:        Test_ReadingPriorityFrm.cpp
00003 // Purpose:     
00004 // Author:      
00005 // Modified by: 
00006 // Created:     
00007 // RCS-ID:      
00008 // Copyright:   (C)2003 
00009 // Licence:     wxWindows
00011 
00012 // ----------------------------------------------------------------------------
00013 // headers
00014 // ----------------------------------------------------------------------------
00015 #include "wx/wxprec.h"
00016 #include <wx/thread.h>
00017 
00018 
00019 #ifndef WX_PRECOMP
00020         #include "wx/wx.h"
00021 #endif
00022 
00023 #include "wxReadingPriorityPanel.h"
00024 
00025 
00026 // ----------------------------------------------------------------------------
00027 // ----------------------------------------------------------------------------
00028 // ----------------------------------------------------------------------------
00029 PriorityLoop::PriorityLoop(){
00030         _vecIdImage                     =       NULL;
00031         _loadingSerie           =       false;
00032         _forceReadRegion        =       false;
00033         _i_forceReadReagion =   -1;
00034         _needToChange       =   false;
00035         _deltaImg                       =       0;
00036 }
00037 // ----------------------------------------------------------------------------
00038 PriorityLoop::~PriorityLoop(){
00039         if (_vecIdImage!=NULL) {
00040                 free(_vecIdImage);
00041         }
00042 }
00043 // ----------------------------------------------------------------------------
00044 void PriorityLoop::StopLoop(){
00045         _loadingSerie = false;
00046 }
00047 // ----------------------------------------------------------------------------
00048 bool PriorityLoop::IsLoop(){
00049         return _loadingSerie;
00050 }
00051 // ----------------------------------------------------------------------------
00052 void PriorityLoop::ForceEndLoopRegion(){
00053         _forceReadRegion=true;
00054 }
00055 
00056 // ----------------------------------------------------------------------------
00057 void PriorityLoop::InitLoop(){
00058         _loadingSerie = true;
00059         NeedToChange();
00060         Create_Empty_Vector();
00061         InitConfiguration();
00062         _counterReading = 0;
00063 }
00064 
00065 // ----------------------------------------------------------------------------
00066 void PriorityLoop::Iteration(){
00067 
00068         NeedToChange();
00069 
00070         if (_forceReadRegion==false){
00071                 int ii,i=Get_i_image();
00072                 for (ii=i-_deltaImg;ii<=i+_deltaImg;ii++){
00073                         if (_Action_i( ii )==true){
00074                                 _counterReading++;
00075                         }
00076                 }
00077         } else {
00078                 _loadingSerie=_ForceEndLoopRegion();
00079         }
00080 
00081         if (_counterReading==_maxImages){
00082                 _loadingSerie=false;
00083         }
00084 
00085 }
00086 
00087 // ----------------------------------------------------------------------------
00088 bool PriorityLoop::_ForceEndLoopRegion (){
00089         bool ok=true;
00090         if (_i_forceReadReagion==-1){
00091                 _i_forceReadReagion=_start;
00092         }
00093         _Action_i( _i_forceReadReagion );
00094         _i_forceReadReagion++;
00095         if (_i_forceReadReagion>_end){
00096                 ok=false;
00097         }
00098         return ok;
00099 }
00100 // ----------------------------------------------------------------------------
00101 void PriorityLoop::Create_Empty_Vector(){
00102         if (_vecIdImage!=NULL) {
00103                 free(_vecIdImage);
00104         }
00105         _vecIdImage =  (bool*)malloc(sizeof(bool)*(_maxImages+1) );
00106         int i;
00107         for (i=0; i<=_maxImages;i++){
00108                 _vecIdImage[i]=false;
00109         }       
00110 
00111 }
00112 
00113 // ----------------------------------------------------------------------------
00114 void PriorityLoop::SetStartEndActualMax(int start,int end, int actual, int deltaImg,int maxImages){
00115         _tstart         = start;
00116         _tend           = end;
00117         _tactual        = actual;
00118         _tdeltaImg      = deltaImg;
00119         _tmaxImages     = maxImages;
00120         _needToChange = true;
00121 }
00122 // ----------------------------------------------------------------------------
00123 void PriorityLoop::NeedToChange(){
00124         if (_needToChange==true){
00125                 _needToChange   = false;
00126                 _start                  = _tstart;
00127                 _end                    = _tend;
00128                 _actual                 = _tactual;
00129                 _deltaImg               = _tdeltaImg;
00130                 _maxImages              = _tmaxImages;
00131                 InitConfiguration();
00132         }
00133 }
00134 
00135 // ----------------------------------------------------------------------------
00136 void PriorityLoop::InitConfiguration(){
00137         _forceReadRegion=false;
00138         int i;
00139         for (i=0;i<PriorityLoadImage_MAX_P;i++){
00140                 _dg[i]=false;
00141                 _counterActual[i]=0;
00142         }
00143         _priorityType=0;
00144         _priority=9;
00145 }
00146 
00147 // ----------------------------------------------------------------------------
00148 bool PriorityLoop::_Action_i( int i ){
00149         bool ok=false;
00150         if (i!=-1) {
00151                 if ((i>=0) && (i<_maxImages)){
00152                         if (_vecIdImage[i]==false ) {
00153                                 Action_i(i);
00154                                 _vecIdImage[i]=true;
00155                                 ok=true;
00156                         }
00157                 }
00158         }
00159         return ok;
00160 }
00161 
00162 // ----------------------------------------------------------------------------
00163 void PriorityLoop::Action_i( int i ){
00164 }
00165 
00166 // ----------------------------------------------------------------------------
00167 int PriorityLoop::Get_i_image(){
00168         int p=4;
00169 
00170         int i=-1;
00171         while ((i==-1) || (p==4) ){
00172                 if (_priorityType==0){
00173                         if ((_priority<=9) && (_priority>=5))   { p=0; }
00174                         if ((_priority<=4) && (_priority>=2))   { p=1; }
00175                         if ((_priority<=1) && (_priority>=0))   { p=2; }
00176                 }
00177                 if (_priorityType==1){
00178                         if ((_priority<=9) && (_priority>=4))   { p=1; }
00179                         if ((_priority<=3) && (_priority>=2))   { p=2; }
00180                         if ((_priority<=1) && (_priority>=0))   { p=3; }
00181                 }
00182                 if (_priorityType==2){
00183                         if ((_priority<=9) && (_priority>=3))   { p=2; }
00184                         if ((_priority<=2) && (_priority>=0))   { p=3; }
00185                 }
00186                 if (_priorityType==3){
00187                         if ((_priority<=9) && (_priority>=0))   { p=3; }
00188                 }
00189                 if (_priorityType==4){
00190                         p=4;
00191                 }
00192                 _priority--;
00193                 if (_priority==-1) {_priority=9;}
00194 
00195                 if (p==0) { i=Geti(p,5,_start,_actual           ,_actual                ,_end);                 }
00196                 if (p==1) { i=Geti(p,1,_start,_actual           ,_actual                ,_end);                 }
00197                 if (p==2) { i=Geti(p,5,0         ,_start                ,_end                   ,_maxImages);   }
00198                 if (p==3) { i=Geti(p,1,0         ,_start                ,_end                   ,_maxImages);   }
00199                 if (p==4) { i=Geti(p,1,0         ,_maxImages    ,_maxImages             ,_maxImages);   }
00200 
00201                 if ((_priorityType==0) && (p==0) && (i==-1)) { _priorityType++; _priority=9; }
00202                 if ((_priorityType==1) && (p==1) && (i==-1)) { _priorityType++; _priority=9; }
00203                 if ((_priorityType==2) && (p==2) && (i==-1)) { _priorityType++; _priority=9; }
00204                 if ((_priorityType==3) && (p==3) && (i==-1)) { _priorityType++; _priority=9; }
00205         }
00206         return i;
00207 }
00208 
00209 // ----------------------------------------------------------------------------
00210 
00211 int PriorityLoop::Geti(int id,int step,int start,int actualg,int actuald,int end){
00212         int tempig=0;
00213         int tempid=0;
00214         int i=-2;
00215         while (i==-2){
00216                 if (_dg[id]==true) { _counterActual[id] = _counterActual[id]+step; }
00217                 tempig=actualg - _counterActual[id];
00218                 tempid=actuald + _counterActual[id];
00219                 if (_dg[id]==true){
00220                         if (tempig>=start) { 
00221                                 if (_vecIdImage[tempig]==false ) {
00222                                         i=tempig;
00223                                 }
00224                         }
00225                 }
00226                 if (_dg[id]==false){
00227                         if (tempid<=end) { 
00228                                 if (_vecIdImage[tempid]==false ) {
00229                                         i=tempid;
00230                                 }
00231                         }
00232                 }
00233                 if ((tempig<start) && (tempid>end)){
00234                         i=-1;
00235                 }
00236                 _dg[id]=!_dg[id];
00237         }
00238         return i;
00239 }
00240 // ----------------------------------------------------------------------------
00241 void PriorityLoop::WaitUntil_i_isDone(int i){
00242         WaitUntil_segment_isDone(i-_deltaImg,i+_deltaImg,false);
00243 }
00244 // ----------------------------------------------------------------------------
00245 void PriorityLoop::WaitUntil_segment_isDone(int start, int end,bool forceEndLoopRegion){
00246         if (forceEndLoopRegion==true) { ForceEndLoopRegion(); }
00247         if (_loadingSerie==true){
00248                 int s=start,e=end;
00249                 if (s<0){
00250                         s=0;
00251                 }
00252                 if (e>_maxImages-1){
00253                         e=_maxImages-1;
00254                 }
00255                 bool ok=false;
00256                 while (ok==false){
00257                         int i;
00258                         ok=true;
00259                         for (i=s;i<=e;i++){
00260                                 ok = ok && _vecIdImage[i];
00261                         }
00262                         if (ok==false) { 
00263                                 RefreshForce();
00264                                 wxThread::Sleep(100); 
00265                         }
00266                 }
00267         }
00268 }
00269 
00270 // ----------------------------------------------------------------------------
00271 // ----------------------------------------------------------------------------
00272 // ----------------------------------------------------------------------------
00273 
00274 // ----------------------------------------------------------------------------
00275 PriorityLoadImageBar::PriorityLoadImageBar(marFilesBase *marfilesbase, BarLoading *bar){
00276         _marfilesbase=marfilesbase;
00277         _bar=bar;
00278 }
00279 // ----------------------------------------------------------------------------
00280 PriorityLoadImageBar::~PriorityLoadImageBar(){
00281 }
00282 // ----------------------------------------------------------------------------
00283 void PriorityLoadImageBar::Action_i(int i){
00284 
00285         if (_bar!=NULL){
00286 
00287 // EED 09 Oct 2007 
00288                 _bar->SetI(i);
00289 
00290                 #if defined(WIN32)
00291 //                      _bar->Refresh(false);
00292                         //_bar->Paint();
00293 //                      Sleep(1);
00294                 #else
00295 //                      _bar->Refresh(false);
00296 //                      _bar->Update();
00297 //                      _bar->Paint();
00298 //                      usleep(1000);
00299                 #endif
00300         }
00301 
00302 
00303         if (_marfilesbase!=NULL){
00304                 _marfilesbase->loadImage(i);
00305                 vtkImageData *imagedata = _marfilesbase->getVolume()->castVtk();
00306                 imagedata->Update();
00307         }
00308 }
00309 // ----------------------------------------------------------------------------
00310 void PriorityLoadImageBar::RefreshForce(){
00311         _bar->RefreshForce();
00312 }
00313 
00314 // ----------------------------------------------------------------------------
00315 // ----------------------------------------------------------------------------
00316 // ----------------------------------------------------------------------------
00317 
00318 IMPLEMENT_CLASS(BarLoading, wxPanel)
00319 BEGIN_EVENT_TABLE(BarLoading, wxPanel)
00320          EVT_PAINT(BarLoading::OnPaint)
00321 END_EVENT_TABLE()
00322 
00323 static wxMutex *s_mutexProtectingTheGlobalData=NULL;
00324 
00325 
00326 // ----------------------------------------------------------------------------
00327 BarLoading::BarLoading(wxWindow *parent, int w, int h) 
00328  :wxPanel(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
00329 {
00330         _w=w;
00331         _h=h;
00332         SetSize(_w,_h);
00333         SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
00334         _bitmap = new wxBitmap(_w,_h);
00335         _flag_bitmap=true;
00336         _flag2_bitmap=true;
00337 
00338         if (s_mutexProtectingTheGlobalData!=NULL)
00339         {
00340                 delete s_mutexProtectingTheGlobalData;
00341                 s_mutexProtectingTheGlobalData=NULL;
00342         }
00343         s_mutexProtectingTheGlobalData = new wxMutex();
00344         Reset();
00345 }
00346 
00347 // ----------------------------------------------------------------------------
00348 BarLoading::~BarLoading()
00349 {
00350 }
00351 // ----------------------------------------------------------------------------
00352 void BarLoading::SetI(int i)
00353 {
00354 
00355 s_mutexProtectingTheGlobalData->Lock();
00356 
00357         _flag_bitmap=false;
00358 
00359         while (_flag2_bitmap==false){
00360                 //sleep force
00361 #if defined(WIN32)
00362                 Sleep(1);
00363 #else
00364 //              usleep(1000);
00365 #endif
00366         }
00367 
00368 /*
00369         wxMemoryDC temp_dc;
00370         temp_dc.SelectObject( *_bitmap );
00371         int x = (_w*i)/_sizeData;
00372         int d = (_w/_sizeData)+1;
00373         temp_dc.SetBrush(wxBrush( wxColour(0,0,255),wxSOLID  ));
00374         temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID  ));
00375         temp_dc.DrawRectangle(x,0,d,_h);
00376 */
00377 
00378        lstInt.push_back(i);
00379 
00380 s_mutexProtectingTheGlobalData->Unlock();
00381         _flag_bitmap=true;
00382 
00383 }
00384 // ----------------------------------------------------------------------------
00385 void BarLoading::RefreshForce()
00386 {
00387 //      Refresh();
00388 //      Update();
00389 }
00390 // ----------------------------------------------------------------------------
00391 void BarLoading::SetSizeData(int sizeData)
00392 {
00393    _sizeData=sizeData;
00394 }
00395 // ----------------------------------------------------------------------------
00396 void BarLoading::Reset()
00397 {
00398         if (_flag_bitmap==true){
00399                 wxMemoryDC temp_dc;
00400                 temp_dc.SelectObject( *_bitmap );
00401                 temp_dc.SetBrush(wxBrush( wxColour(255,0,0),wxSOLID  ));
00402                 temp_dc.SetPen(wxPen( wxColour(255,0,0),1,wxSOLID  ));
00403                 temp_dc.DrawRectangle(0,0,_w,_h);
00404                 lstInt.clear();
00405         }
00406 }
00407 
00408 
00409 // ----------------------------------------------------------------------------
00410 void BarLoading::Paint( )
00411 {
00412   _flag2_bitmap=false;
00413   wxMutexLocker lock(*s_mutexProtectingTheGlobalData);
00414 
00415 
00416         if (_flag_bitmap==true){
00417                 wxMemoryDC temp_dc;
00418                 temp_dc.SelectObject( *_bitmap );
00419         
00420         int i,ii,size=lstInt.size();
00421         for (ii=0;ii<size; ii++)
00422         {
00423                 i=lstInt[ii];
00424                 int x = (_w*i)/_sizeData;
00425                 int d = (_w/_sizeData)+1;
00426                 temp_dc.SetBrush(wxBrush( wxColour(0,0,255),wxSOLID  ));
00427                 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID  ));
00428                 temp_dc.DrawRectangle(x,0,d,_h);
00429         }
00430         lstInt.clear();
00431 
00432 
00433 
00434 
00435                 wxPaintDC dc( this );
00436                 dc.Blit(0,0, _w, _h, &temp_dc, 0, 0);
00437         }
00438         _flag2_bitmap=true;//SIL//POR QUE TANTAS VECES LO MISMO??????
00439         _flag2_bitmap=true;
00440         _flag2_bitmap=true;
00441         _flag2_bitmap=true;
00442         _flag2_bitmap=true;
00443         _flag2_bitmap=true;
00444 
00445 
00446 }
00447 
00448 
00449 // ----------------------------------------------------------------------------
00450 void BarLoading::OnPaint( wxPaintEvent &WXUNUSED(event) )
00451 {
00452         Paint();
00453 }
00454 
00455 
00456 // ----------------------------------------------------------------------------
00457 // ----------------------------------------------------------------------------
00458 // ----------------------------------------------------------------------------
00459 // ----------------------------------------------------------------------------
00460 /* EED Borrame
00461 IMPLEMENT_CLASS(BarRange, wxPanel)
00462 BEGIN_EVENT_TABLE(BarRange, wxPanel)
00463          EVT_PAINT(BarRange::OnPaint)
00464 END_EVENT_TABLE()
00465 
00466 
00467 BarRange::BarRange(wxWindow *parent, int w, int h)
00468  :wxPanel(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
00469 {
00470         _w=w;
00471         _h=h;
00472         SetSize(_w,_h);
00473         SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
00474         _bitmap = new wxBitmap(_w,_h);
00475 
00476         _start = 0;
00477         _max   = 100;
00478         _end   = _max;
00479 }
00480 // ----------------------------------------------------------------------------
00481 BarRange::~BarRange()
00482 {
00483 }
00484 // ----------------------------------------------------------------------------
00485 void BarRange::SetStart(int i)
00486 {
00487         _start=i;
00488 }
00489 // ----------------------------------------------------------------------------
00490 void BarRange::SetActual(int i)
00491 {
00492         _actual=i;
00493 }
00494 // ----------------------------------------------------------------------------
00495 void BarRange::SetEnd(int i)
00496 {
00497         _end=i;
00498 }
00499 // ----------------------------------------------------------------------------
00500 void BarRange::SetMax(int i)
00501 {
00502         _max=i;
00503 }
00504 // ----------------------------------------------------------------------------
00505 void BarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
00506 {
00507 
00508         RefreshView();
00509 
00510     wxMemoryDC temp_dc;
00511         temp_dc.SelectObject( *_bitmap );
00512         wxPaintDC dc( this );
00513         dc.Blit(0,0, _w, _h, &temp_dc, 0, 0);
00514 
00515 }
00516 // ----------------------------------------------------------------------------
00517 
00518 void BarRange::RefreshView()
00519 {
00520         wxPoint points[3];
00521 
00522         int px1=(_w*_start)/_max;
00523         int px2=(_w*_end)/_max;
00524         int px3=(_w*_actual)/_max;
00525 
00526         wxMemoryDC temp_dc;
00527         temp_dc.SelectObject( *_bitmap );
00528 
00529         // Background
00530         wxColour colourParent =  GetParent()->GetBackgroundColour();
00531         temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID  ));
00532         temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID  ));
00533         temp_dc.DrawRectangle(0,0,_w,_h);
00534 
00535         // Yellow line
00536         temp_dc.SetBrush(wxBrush( wxColour(255,0,255),wxSOLID  ));
00537         temp_dc.SetPen(wxPen( wxColour(255,0,255),1,wxSOLID  ));
00538         temp_dc.DrawRectangle( px1 , 0 , px2-px1 , _h );
00539 
00540         // 2 Start End ( triangles )
00541         temp_dc.SetBrush(wxBrush( wxColour(0,0,255),wxSOLID  ));
00542         temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID  ));
00543         points[0].x=0;
00544         points[0].y=0;
00545         points[1].x=-3;
00546         points[1].y=_h;
00547         points[2].x=3;
00548         points[2].y=_h;
00549         temp_dc.DrawPolygon(3,points,px1,0);
00550         temp_dc.DrawPolygon(3,points,px2,0);
00551 
00552         // Actual ( black triangles )
00553         // 2 Start End ( yellow triangles )
00554         temp_dc.SetBrush(wxBrush( wxColour(255,255,0),wxSOLID  ));
00555         temp_dc.SetPen(wxPen( wxColour(255,255,0),1,wxSOLID  ));
00556         points[0].x = -3;
00557         points[0].y = 0;
00558         points[1].x = 3;
00559         points[1].y = 0;
00560         points[2].x = 0;
00561         points[2].y = _h;
00562         temp_dc.DrawPolygon(3,points,px3,0);
00563 
00564 }
00565 // ----------------------------------------------------------------------------
00566 void BarRange::RefreshForce()
00567 {
00568         Refresh();
00569         Update();
00570 }
00571 // ----------------------------------------------------------------------------
00572 */
00573 
00574 // ----------------------------------------------------------------------------
00575 // ----------------------------------------------------------------------------
00576 // ----------------------------------------------------------------------------
00577 
00578 
00579 
00580 /*
00581 PriorityBar::PriorityBar(BarLoading *bar){
00582         _bar = bar;
00583 }
00584 // ----------------------------------------------------------------------------
00585 PriorityBar::~PriorityBar(){
00586 }
00587 // ----------------------------------------------------------------------------
00588 void PriorityBar::Action_i(int i){
00589         _bar->SetI(i);
00590         _bar->Refresh();
00591         wxThread::Sleep(100); 
00592 }
00593 // ----------------------------------------------------------------------------
00594 void PriorityBar::RefreshForce(){
00595         _bar->RefreshForce();
00596 }
00597 */
00598 
00599 // ----------------------------------------------------------------------------
00600 // ----------------------------------------------------------------------------
00601 // ----------------------------------------------------------------------------
00602 
00603 // ----------------------------------------------------------------------------
00604 AdminThreadEED::AdminThreadEED()
00605 : m_condAllDone(m_mutexAllDone){
00606 
00607          // the mutex associated with a condition must be initially locked, it will
00608     // only be unlocked when we call Wait()
00609     m_mutexAllDone.Lock();
00610     m_waitingUntilAllDone = FALSE;
00611 
00612 }
00613 // ----------------------------------------------------------------------------
00614 AdminThreadEED::~AdminThreadEED(){
00615         // the mutex must be unlocked before being destroyed
00616     m_mutexAllDone.Unlock();
00617 }
00618 
00619 // ----------------------------------------------------------------------------
00620 // ----------------------------------------------------------------------------
00621 // ----------------------------------------------------------------------------
00622 
00623 // ----------------------------------------------------------------------------
00624 MyThread::MyThread(PriorityLoop *priorityLoop,AdminThreadEED *adminThreadEED){
00625    _priorityLoop        =       priorityLoop;
00626    _adminThreadEED      =       adminThreadEED;
00627 
00628 }
00629 
00630 // ----------------------------------------------------------------------------
00631 void MyThread::OnExit(){
00632     _priorityLoop->StopLoop();
00633     wxCriticalSectionLocker locker(_adminThreadEED->m_critsect);
00634     wxArrayThread& threads = _adminThreadEED->m_threads;
00635     threads.Remove(this);
00636 
00637     if ( threads.IsEmpty() )    {
00638         if ( _adminThreadEED->m_waitingUntilAllDone ){
00639             _adminThreadEED->m_waitingUntilAllDone = FALSE;
00640             wxMutexLocker lock(_adminThreadEED->m_mutexAllDone);
00641             _adminThreadEED->m_condAllDone.Signal();
00642         }
00643     }
00644 }
00645 // ----------------------------------------------------------------------------
00646 
00647 void *MyThread::Entry(){
00648         _priorityLoop->InitLoop();
00649         while ( _priorityLoop->IsLoop()==true ){
00650         if ( TestDestroy() ){
00651             break;
00652                 }
00653                 _priorityLoop->Iteration();
00654     }
00655     return NULL;
00656 }
00657 
00658 
00659 
00660 // ----------------------------------------------------------------------------
00661 // ----------------------------------------------------------------------------
00662 // ----------------------------------------------------------------------------
00663 
00664 
00665 // ----------------------------------------------------------------------------
00666 LoadRangeImage::LoadRangeImage(wxWindow *parent,marFilesBase *marfilesbase ) 
00667 : wxPanel(parent, -1)
00668 {
00669         _marfilesbase           = marfilesbase;
00670         
00671     wxPanel *panel              = new wxPanel(this, -1);
00672         int wx=550;
00673         _bar                            = new BarLoading(panel,wx-10,15);
00674         //SIL//_barRange                        = new BarRange(panel,wx-10,5);
00675         //SIL//
00676         _sl_barRange_ROI        = new mBarRange(panel,wx-10 ,70);
00677         _sl_barRange_ROI-> SetOrientation(true);
00678         _sl_barRange_ROI -> setVisibleLabels ( true );
00679         _sl_barRange_ROI -> setActiveStateTo ( true );  
00680         _sl_barRange_ROI -> setDeviceBlitStart (2,2);
00681         _sl_barRange_ROI -> setDeviceEndMargin(0);
00682         _sl_barRange_ROI -> SetTrianglesHalfWidth(5);
00683 
00684         
00685         parent->SetBackgroundColour(wxColour(255,255,255 )) ;
00686         panel->SetBackgroundColour(parent-> GetBackgroundColour());
00687 
00688 /*
00689         parent->SetBackgroundColour(wxColour(255,0,0 )) ;
00690         panel->SetBackgroundColour(wxColour(0,255,0 )) ;*/
00691         /*
00692         panel->SetBackgroundColour(wxColour(0,0,0 ));
00693         parent->SetBackgroundColour(wxColour(255,0,0 ));
00694         (parent->GetParent())->SetBackgroundColour(wxColour(0,255,0 )) ;
00695         ((parent->GetParent())->GetParent())->SetBackgroundColour(wxColour(0,0,255 )) ;*/
00696         
00697 
00698         _sl_barRange_ROI-> setBackgroundColor( parent-> GetBackgroundColour()/*wxColour(255,255,255 )*/);
00699         reseteableActual =true;
00700 
00701 
00702 /*_//SIL//
00703         _sldActual                      = new wxSlider(panel,-1,0,0,10000,wxDefaultPosition,wxSize(wx-10,20),wxSL_HORIZONTAL);
00704         
00705         _btnStart                       = new wxButton(panel,-1,_T("Start:"),wxDefaultPosition, wxSize(70,20) );
00706         _btnEnd                         = new wxButton(panel,-1,_T("End:"),wxDefaultPosition, wxSize(70,20) );
00707         _textActual                     = new wxStaticText(panel,-1,_T("Actual: 0000000000"));*/
00708         _textActual                     = new wxStaticText(panel,-1,_T("  "));
00709 
00710 //EEDxx2.4
00711 //      _sldActual      ->SetSize(wx-10,20);
00712 //      _btnStart       ->SetSize(70,20);
00713 //      _btnEnd         ->SetSize(70,20);
00714 
00715         //SIL//_sizer1a = new wxFlexGridSizer(1);
00716         //SIL//_sizer1a->Add(_btnStart                                          );
00717         //SIL//_sizer1a->Add(_textActual ,wxALIGN_CENTER,0      );
00718         //SIL//_sizer1a->Add(_btnEnd                                            );
00719 
00720 //      _btnStart       ->Show(true);
00721 //      _btnEnd         ->Show(true);
00722 
00723         //SIL//_sizer1a->Show(_btnStart, false);
00724         //SIL//_sizer1a->Show(_btnEnd, false);
00725 
00726 
00727 //      _sizer1a = new wxFlexGridSizer(1);
00728 //      _sizer1a->Add(_textActual ,wxALIGN_CENTER,0     );
00729 
00730         wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
00731 //      sizer1->AddGrowableRow(1);
00732 //      wxBoxSizer *sizer1 =  new wxBoxSizer(wxVERTICAL );
00733         //SIL//sizer1->Add(_sldActual);
00734         sizer1->Add(_bar);
00735         //SIL//sizer1->Add(_barRange);
00736         //SIL//
00737         sizer1->Add(_sl_barRange_ROI,1,wxEXPAND,0);
00738 
00739         wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
00740 //      sizer -> AddGrowableRow(1);//SIL//
00741 //      sizer->Add(_sizer1a, 1, wxALL , 5 );
00742         sizer->Add(_textActual);
00743         sizer->Add(sizer1,1,wxEXPAND,0);
00744 
00745 
00746 
00747         /*wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
00748         sizer->Add(_bar, 0, wxEXPAND);  
00749         sizer->Add(_sl_barRange_ROI, 0, wxEXPAND);*/
00750 
00751 
00752 /*//SIL//
00753         Connect(_btnStart->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED      , (wxObjectEventFunction) (wxCommandEventFunction) &LoadRangeImage::OnBtnStart          );
00754         Connect(_btnEnd->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) (wxCommandEventFunction) &LoadRangeImage::OnBtnEnd                    );
00755 */
00756         //Connect(_sldActual->GetId() , wxEVT_COMMAND_SLIDER_UPDATED    , (wxObjectEventFunction) (wxEventFunction) (wxScrollEventFunction) &LoadRangeImage::OnSliceActual      );
00757         //SIL//
00758         Connect(_sl_barRange_ROI->GetId(),wxEVT_TSBAR,(wxObjectEventFunction) (wxCommandEventFunction) &LoadRangeImage::OnBarrange );
00759         Connect(_sl_barRange_ROI->GetId(),wxEVT_TSBAR_START,(wxObjectEventFunction) (wxCommandEventFunction)  &LoadRangeImage::OnStartChange_BarRange );
00760         Connect(_sl_barRange_ROI->GetId(),wxEVT_TSBAR_END,(wxObjectEventFunction) (wxCommandEventFunction)  &LoadRangeImage::OnEndChange_BarRange );
00761         Connect(_sl_barRange_ROI->GetId(),wxEVT_TSBAR_ACTUAL,(wxObjectEventFunction) (wxCommandEventFunction)  &LoadRangeImage::OnActualChange_BarRange );
00762         Connect(_sl_barRange_ROI->GetId(),wxEVT_TSBAR_MOVED,(wxObjectEventFunction) (wxCommandEventFunction)  &LoadRangeImage::OnBarMoved_BarRange );
00763         Connect(_sl_barRange_ROI->GetId(),wxEVT_SELECTION_END,(wxObjectEventFunction) (wxCommandEventFunction)  &LoadRangeImage::OnSelectionEnd_BarRange );
00764 
00765         // EED
00766         _timer=NULL;
00767 #if defined(WIN32)
00768         //...
00769 #else
00770     _timer = new wxTimer(this);
00771         _timer->Start(100);
00772     Connect( _timer->GetId(), wxEVT_TIMER , (wxObjectEventFunction) (wxTimerEventFunction)  &LoadRangeImage::OnTimer );
00773 #endif
00774 
00775 
00776         panel->SetSizer(sizer);
00777         panel->SetAutoLayout( TRUE );
00778 
00779         this->SetSize(wx,75);
00780         panel->SetSize(wx,75);
00781 
00782         _mythread                       = NULL;
00783         _priorityLoadImageBar           = new PriorityLoadImageBar(_marfilesbase,_bar);
00784         _adminThreadEED                 = new AdminThreadEED();
00785 }
00786 // ----------------------------------------------------------------------------
00787 LoadRangeImage::~LoadRangeImage()
00788 {
00789         if (_timer!=NULL){
00790                 _timer->Stop();
00791                 delete _timer;
00792         }
00793         _Stop();
00794 }
00795 
00796 // ----------------------------------------------------------------------------
00797 void LoadRangeImage::ResetLoadRegion()
00798 {
00799         int s,e,a;
00800         s=_startSlice;
00801         e=_endSlice;
00802         //SIL//a=_sldActual->GetValue();
00803         //a=_sl_barRange_ROI->GetActual();
00804         a = _toShowSlice;
00805         if ((a<s) || (a>e))
00806         {
00807                 s=0;
00808                 e=_maxZ;
00809         } 
00810         _priorityLoadImageBar->SetStartEndActualMax(s,e,a,0,_maxZ);
00811 }
00812 
00813 // ----------------------------------------------------------------------------
00814 void LoadRangeImage::Start(  )
00815 {
00816 
00817     vtkImageData *vol = _marfilesbase->getVolume( )->castVtk();
00818         int dim[3];
00819         vol->GetDimensions(dim);
00820         _maxZ=dim[2]-1;
00821 
00822         _startSlice     =       0;
00823         _endSlice       =       _maxZ;
00824 
00825         this->SetStartSlice(_startSlice);
00826         this->SetEndSlice(_endSlice);
00827 
00828 
00829         _bar ->                 SetSizeData(_maxZ);
00830 //SIL// Para quitar luego als siguientes dos lineas
00831         /*_sldActual -> SetRange(0, _maxZ);
00832         _sldActual ->   SetValue( _maxZ/2 );*/
00833 
00834         //SIL//
00835         _sl_barRange_ROI -> setRepresentedValues (0,_maxZ);
00836         _sl_barRange_ROI -> SetActual(_maxZ/2);
00837         _sl_barRange_ROI -> RefreshForce();     
00838 
00839 
00840         SetStartSlice( 0 );
00841         SetEndSlice( _maxZ );
00842         _toShowSlice = _sl_barRange_ROI->GetActual();
00843         RefreshSlice();
00844 
00845 //EEDx44
00846         _marfilesbase->ResetLstFileNotReaded();
00847 
00848         _Start();
00849 }
00850 // ----------------------------------------------------------------------------
00851 void LoadRangeImage::_Start()
00852 {
00853 
00854         ResetLoadRegion();
00855         _mythread = new MyThread (_priorityLoadImageBar,_adminThreadEED);
00856         _mythread->Create();
00857         wxCriticalSectionLocker enter(_adminThreadEED->m_critsect);
00858         _adminThreadEED->m_threads.Add(_mythread);
00859         if ( _mythread->Run() != wxTHREAD_NO_ERROR ){
00860                 wxLogError(wxT("Can't start thread!"));
00861         }
00862 }
00863 // ----------------------------------------------------------------------------
00864 void LoadRangeImage::_Stop(  )
00865 {
00866 
00867     _adminThreadEED->m_critsect.Enter();
00868     // stop the last thread
00869     if ( _adminThreadEED->m_threads.IsEmpty() ){
00870         //wxLogError(wxT("No thread to stop!"));
00871        _adminThreadEED->m_critsect.Leave();
00872     } else {
00873         wxThread *_mythread = _adminThreadEED->m_threads.Last();
00874         // it's important to leave critical section before calling Delete()
00875         // because delete will (implicitly) call OnExit() which also tries
00876         // to enter the same crit section - would dead lock.
00877         _adminThreadEED->m_critsect.Leave();
00878         _mythread->Delete();
00879     }
00880 
00881 }
00882 
00883 // ----------------------------------------------------------------------------
00884 /*
00885 void LoadRangeImage::OnBtnRestart( wxCommandEvent& event ){
00886         _priorityLoadImageBar->WaitUntil_segment_isDone( _sldStart->GetValue(),_sldEnd->GetValue() );
00887 
00888         OnBtnStop(event);
00889         _bar->Reset();
00890         _bar->Refresh();
00891 }
00892 */
00893 // ----------------------------------------------------------------------------
00894 void LoadRangeImage::OnSliceActual(wxScrollEvent& event)
00895 {
00896         //SIL// metodo para quitar
00897         _toShowSlice = _sl_barRange_ROI->GetActual();
00898         ResetLoadRegion();
00899         RefreshSlice();
00900 }
00901 
00902 // ----------------------------------------------------------------------------
00903 
00904 void LoadRangeImage::OnBtnStart( wxCommandEvent &  event )
00905 {
00906         //SIL// metodo para quitar
00907         /*SetStartSlice( _sldActual->GetValue() );
00908         ResetLoadRegion();
00909         RefreshSlice();*/
00910 }
00911 
00912 // ----------------------------------------------------------------------------
00913 void LoadRangeImage::OnBtnEnd( wxCommandEvent &  event )
00914 {
00915         //SIL// metodo para quitar
00916         /*SetEndSlice( _sldActual->GetValue() );
00917         ResetLoadRegion();
00918         RefreshSlice();*/
00919 }
00920 // ----------------------------------------------------------------------------
00921 void LoadRangeImage::SetStartEnd( int start, int end )
00922 {
00923         SetStartSlice( start );
00924         SetEndSlice( end );
00925         ResetLoadRegion();
00926         RefreshSlice();
00927 }
00928 
00929 // ----------------------------------------------------------------------------
00930 void LoadRangeImage::Reset( )
00931 {
00932         int delta= (int) (_maxZ*0.1);
00933         SetStartSlice( 0 + delta );
00934         SetEndSlice( _maxZ - delta );
00935 
00936 //EEDxx2.4
00937 //      _btnStart       ->Show(true);
00938 //      _btnEnd         ->Show(true);
00939 
00940         //SIL//_sizer1a->Show(_btnStart, true );
00941         //SIL//_sizer1a->Show(_btnEnd   , true );
00942 //    _sizer1a->Layout();       
00943         RefreshSlice();
00944 }
00945 
00946 // ----------------------------------------------------------------------------
00947 void LoadRangeImage::SetStartSlice(int value)
00948 {
00949         if (value<_endSlice){
00950                 _startSlice     = value;
00951                 /*wxString txt;
00952                 txt.Printf(_T("%d"),_startSlice);
00953                 _textActual->SetLabel(txt);*/
00954                 
00955                 //SIL// para quitar las siguientes 4 lineas
00956                 /*
00957                 _btnStart->SetLabel(_T("Start:  ")+txt);
00958                 _barRange->SetMax(_maxZ);
00959                 _barRange->SetStart(_startSlice);
00960                 _barRange->RefreshForce();*/
00961 
00962                 //SIL//
00963                 _sl_barRange_ROI->SetMax(_maxZ);
00964                 _sl_barRange_ROI->SetStart(_startSlice);
00965                 _sl_barRange_ROI->RefreshForce(); 
00966         }
00967 }
00968 // ----------------------------------------------------------------------------
00969 void LoadRangeImage::SetEndSlice(int value)
00970 {
00971         if (value>_startSlice){
00972                 _endSlice       = value;
00973                 /*wxString txt;
00974                 txt.Printf(_T("%d"),_endSlice);
00975                 _textActual->SetLabel(txt);*/
00976                 //SIL//_btnEnd->SetLabel(_T("End:  ")+txt);
00977                 _sl_barRange_ROI->SetEnd(_endSlice);
00978                 _sl_barRange_ROI->RefreshForce(); 
00979 
00980         }
00981 }
00982 
00983 // ----------------------------------------------------------------------------
00984 void LoadRangeImage::RefreshSlice()
00985 {
00986 //SIL// _priorityLoadImageBar->WaitUntil_i_isDone( _sldActual->GetValue() );
00987         _priorityLoadImageBar->WaitUntil_i_isDone( _toShowSlice );
00988 
00989         wxCommandEvent newevent(wxEVT_COMMAND_MENU_SELECTED,12122);
00990         this->GetParent()->ProcessEvent(newevent);
00991 /* //SIL//
00992         wxString text;  
00993         //SIL//text.Printf(_T("Actual: %d "), _sldActual->GetValue() );
00994         text.Printf(_T("Start: %d\n Actual: %d\n End: %d"), _sl_barRange_ROI->GetStart(),_sl_barRange_ROI->GetActual(),_sl_barRange_ROI->GetEnd() );
00995         _textActual->SetLabel(text);*/
00996         
00997         //SIL// Para borrar las lineas de barrange
00998         /*_barRange->SetMax(_maxZ);
00999         _barRange->SetActual( _sldActual->GetValue() );
01000         _barRange->SetStart(_startSlice);
01001         _barRange->SetEnd(_endSlice);
01002         _barRange->RefreshForce();*/
01003 
01004         //SIL//
01005         // EED
01006 //      _sl_barRange_ROI->SetMax(_maxZ);
01007         //_sl_barRange_ROI->SetActual(  _sldActual->GetValue() );
01008 //      _sl_barRange_ROI->SetStart(_startSlice);
01009 //      _sl_barRange_ROI->SetEnd(_endSlice);
01010         _sl_barRange_ROI->RefreshForce();
01011 
01012 //EED 28 Fev 2008
01013 //      _bar->Refresh();
01014 //      _bar->Update();
01015 
01016    Refresh(false);
01017 //      _imageViewerWidget->SetZSlice( _sldActual->GetValue()  );
01018 //      _imageViewerWidget->Render();
01019 }
01020 // ----------------------------------------------------------------------------
01021 void LoadRangeImage::CallBackOnMouseWheel( wxMouseEvent& event )
01022 {
01023         /* //SIL ImageViewer no existe//int actual = _imageViewerWidget->GetZSlice();
01024         if (actual<_sl_barRange_ROI->GetActual()) {
01025                 actual = _sl_barRange_ROI->GetActual();
01026         }
01027         if (actual>_sl_barRange_ROI->GetEnd()) {
01028                 actual = _sl_barRange_ROI->GetEnd();
01029         }
01030         _sl_barRange_ROI->SetActual( actual );
01031         ResetLoadRegion();
01032         RefreshSlice();
01033 */
01034         /*int actual = _imageViewerWidget->GetZSlice();
01035         if (actual<_sldStart->GetValue()) {
01036                 actual = _sldStart->GetValue();
01037         }
01038         if (actual>_sldEnd->GetValue()) {
01039                 actual = _sldEnd->GetValue();
01040         }
01041         _sldActual->SetValue( actual );
01042         ResetLoadRegion();
01043         RefreshSlice();*/
01044 
01045 }
01046 // ----------------------------------------------------------------------------
01047 void LoadRangeImage::ForceToFinisReadActiveImages()
01048 {
01049         int s=_startSlice;
01050         int e=_endSlice;
01051 
01052         _priorityLoadImageBar->WaitUntil_segment_isDone(s,e,true);
01053 
01054 
01055 //EEDx44
01056         std::string msgLstFile( _marfilesbase->GetMsgLstFile() );
01057         if ( msgLstFile!="")
01058         {
01059                 wxDialog *dialog = new wxDialog( this , -1, wxString(_T("The following files doesn't exist:")), wxDefaultPosition, wxSize(550,300),  wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );                        
01060                 wxTextCtrl *textCtrl = new wxTextCtrl(dialog, -1, wxString (msgLstFile.c_str(), wxConvUTF8) ,wxDefaultPosition , wxSize(100,100) , wxTE_MULTILINE | wxTE_READONLY );
01061                 textCtrl->SetSelection(0,0);
01062                 wxBoxSizer *sizer       = new wxBoxSizer(wxVERTICAL  );
01063                 sizer->Add( textCtrl , 1, wxALL|wxEXPAND, 0);
01064                 dialog->SetAutoLayout(true);
01065                 dialog->SetSizer( sizer );      // use the sizer for layout
01066                 dialog->Layout(); 
01067 //EEDxx2.4
01068 //              dialog->FitInside();
01069                 dialog->ShowModal();
01070         }
01071 
01072 
01073 
01074 
01075 }
01076 // ----------------------------------------------------------------------------
01077 void LoadRangeImage::GetROI( int extent[6] )
01078 {
01079         extent[4]=_startSlice;
01080         extent[5]=_endSlice;
01081 }
01082 // ----------------------------------------------------------------------------
01083 void LoadRangeImage::SetActualSlice( int actual )
01084 {
01085 
01086         if ( actual > _endSlice ){
01087                 actual=_endSlice;
01088         }
01089         if ( actual < _startSlice ){
01090                 actual = _startSlice;
01091         }
01092 
01093         //SIL//_sldActual->SetValue( actual  );//SIL// para quitar esta linea
01094         //SIL//
01095         _sl_barRange_ROI->SetActual( actual);//de pronto no se necesita aca
01096         _toShowSlice=actual;
01097 
01098         ResetLoadRegion();
01099         RefreshSlice();
01100 }
01101 // ----------------------------------------------------------------------------
01102 int LoadRangeImage::GetActualSlice( )
01103 {
01104         return _toShowSlice;/*_sl_barRange_ROI->GetActual()*/; 
01105 }
01106 // ----------------------------------------------------------------------------
01107 
01108 void  LoadRangeImage::ResetActualSlice( )
01109 {
01110         if( reseteableActual )
01111                 _toShowSlice = _sl_barRange_ROI->GetActual();
01112 }
01113 
01114 //------------------------------------------------------------------------
01115 // Events captured form the barrange used configuring the ROI
01116 //------------------------------------------------------------------------
01117 void  LoadRangeImage::OnBarrange(wxCommandEvent& event)
01118 {
01119         
01120 }
01121 void  LoadRangeImage::OnActualChange_BarRange(wxCommandEvent& event)
01122 {
01123         //reseteableActual =true;
01124         _toShowSlice = _sl_barRange_ROI->GetActual();
01125         ResetLoadRegion();
01126         RefreshSlice(); 
01127 }
01128 void  LoadRangeImage::OnStartChange_BarRange(wxCommandEvent& event)
01129 {       
01130         reseteableActual =false;
01131         _toShowSlice = _sl_barRange_ROI->GetStart();
01132         SetStartSlice( _sl_barRange_ROI->GetStart() );
01133         ResetLoadRegion();
01134         RefreshSlice();
01135 }
01136 
01137 void  LoadRangeImage::OnEndChange_BarRange(wxCommandEvent& event)
01138 {
01139         reseteableActual =false;
01140         _toShowSlice = _sl_barRange_ROI->GetEnd();
01141         SetEndSlice( _sl_barRange_ROI->GetEnd() );
01142         ResetLoadRegion();
01143         RefreshSlice();
01144 }
01145 void  LoadRangeImage:: OnBarMoved_BarRange (wxCommandEvent& event)
01146 {
01147         SetEndSlice( _sl_barRange_ROI->GetEnd() );
01148         SetStartSlice( _sl_barRange_ROI->GetStart() );
01149         ResetLoadRegion();
01150         RefreshSlice();
01151 
01152 }
01153 void  LoadRangeImage:: OnSelectionEnd_BarRange (wxCommandEvent& event)
01154 {
01155         reseteableActual = true;
01156 }
01157 
01158 // ---  Timer ------
01159 void LoadRangeImage:: OnTimer(wxTimerEvent& event)
01160 {
01161 //  EED  used in linux  (see constructor)
01162         _bar->Refresh(false);
01163         _bar->Update();
01164         RefreshSlice();
01165 }
01166 
01167 
01168 // ----------------------------------------------------------------------------
01169 // ----------------------------------------------------------------------------
01170 // ----------------------------------------------------------------------------
01171 
01172 

Generated on Wed Jul 29 16:35:28 2009 for creaMaracasVisu_lib by  doxygen 1.5.3