]> Creatis software - creaImageIO.git/blobdiff - src/creaImageIOWxGimmick.cpp
*** empty log message ***
[creaImageIO.git] / src / creaImageIOWxGimmick.cpp
index 2bcc3ab50c53bc08f25fcdfd1ebbae703b725365..63470ba141b56f8d126d92715499c4a1fc90b79d 100644 (file)
@@ -19,7 +19,8 @@
 #include <vtkCamera.h>
 #include <vtkRenderer.h>
 
-#include<wx/filefn.h>
+#include <wx/filefn.h>
+//#include <wx/tipwin.h>
 
 using namespace crea;
 
@@ -62,6 +63,8 @@ namespace creaImageIO
       PopUp_Settings = 501,
       PopUp_About    = 502,
       PopUp_User = WxGimmick::UserMenuFirstId,
+      PopUp_SaveAs = 701,
+      PopUp_AddToFavorites = 702
     };
   //================================================================
 
@@ -209,18 +212,6 @@ namespace creaImageIO
 
 
 
-  //================================================================
-  class WxGimmickSettingsDialog : public wxDialog
-  {
-  public:
-    WxGimmickSettingsDialog(wxWindow *parent);
-    ~WxGimmickSettingsDialog();
-    
-    
-  };
-  //================================================================
-
-
 
 
 
@@ -345,9 +336,15 @@ namespace creaImageIO
     // Image sizer
     wxBoxSizer *isizer = new wxBoxSizer(wxHORIZONTAL  );
     mPanelImage->SetSizer( isizer ); 
-  
+    // Notebook
+    mwxNotebook = new wxNotebook(mSplitter2,
+                                -1,wxDefaultPosition, wxDefaultSize, 0);
+
+
+    
     // Fields view (bottom)
-    mFieldsView = new WxGimmickFieldsView(mSplitter2,-1,
+    mFieldsView = new WxGimmickFieldsView(mwxNotebook,-1,
                                            wxDefaultPosition,
                                            wxDefaultSize,0);
 
@@ -362,16 +359,20 @@ namespace creaImageIO
        GetSettings().BgColour(DicomNode::Series),
        GetSettings().Colour(DicomNode::Image),
        GetSettings().BgColour(DicomNode::Image));
+    mwxNotebook->AddPage( mFieldsView, _T("Dicom fields"));
     
-    
-
+    // Help 
+    mHelp = new WxGimmickHelp(mwxNotebook);
+    mwxNotebook->AddPage( mHelp, _T("Help"));    
+    // Splitting
     int wsize = size.GetWidth();
     int hsize = size.GetHeight();
     int previewhsize = 150;
     int previewwsize = 400;
 
     mSplitter2->SetMinimumPaneSize( previewhsize );
-    mSplitter2->SplitHorizontally( mPanelImage, mFieldsView, 
+    mSplitter2->SplitHorizontally( mPanelImage, mwxNotebook, //mFieldsView, 
                                   hsize - previewhsize);
   
     rsizer->Add( mSplitter2,1,wxGROW  ,0);
@@ -381,7 +382,7 @@ namespace creaImageIO
     rpanel->Layout(); 
   
     // previewer
-    mInteractor = new wxVTKRenderWindowInteractor(mPanelImage,-1);
+       mInteractor = new crea::creawxVTKRenderWindowInteractor(mPanelImage,-1);
     mInteractor->UseCaptureMouseOn();  
   
     mViewer    = vtkImageViewer2::New();
@@ -411,6 +412,16 @@ namespace creaImageIO
 
     ShowImage(mReader.GetImage(""));
 
+    // Show help if no collection
+    if (GetDicomDatabaseList().size()==0)
+      {
+       mwxNotebook->SetSelection(1);
+      } 
+    else
+      {
+       mwxNotebook->SetSelection(0);
+      }
+    //    mJustStarted = true;
   }
   //================================================================
     
@@ -707,8 +718,7 @@ namespace creaImageIO
        mTreeListCtrl->SetItemText(item,std2wx(lab));
       }
     else 
-      {
-       
+      {        
        int c = 0;
        Settings::ColumnListType::iterator col;
        // If Study and Series level are merged and node type is Series
@@ -777,7 +787,7 @@ namespace creaImageIO
 
   //================================================================
   void WxGimmick::UpdateColumnsTitles(wxTreeItemId& item,
-                                                   DicomNode::Type t)
+                                      DicomNode::Type t)
   {
     //    std::cout << "Update columns titles "<<t<<std::endl;
     int c = 0;
@@ -859,6 +869,9 @@ namespace creaImageIO
        boost::filesystem::change_extension(filepath,GetDatabaseExtension());
        if ( boost::filesystem::exists(filepath) )
          {
+                 boost::filesystem::remove(filepath);  
+                         /* 
+                         LG : works on Linux but not Windows :
            if ( ! boost::filesystem::remove(filepath) )
              {
                wxMessageBox(_T("Could not overwrite ")
@@ -866,8 +879,10 @@ namespace creaImageIO
                             _T("Error"),
                             wxOK,this);
                return;
+               
        
              }
+                 */
          }
       }
     
@@ -903,9 +918,11 @@ namespace creaImageIO
          }
       }
 
+    if (GetDicomDatabaseList().size()==0) mFieldsView->UpdateFields(db);
     GetDicomDatabaseList().push_back(db);
     UpdateDicomDatabaseView(db);
 
+
   }
   //================================================================
 
@@ -915,10 +932,13 @@ namespace creaImageIO
   {
     wxBusyCursor busy;
     //    std::cout << "WxGimmick : Reading config"<<std::endl;
+    LoadOrCreateFavoritesDatabase();
 
-    //    std::cout << "==> Loading collections from '"<<mDatabaseListFile
+    //    std::cout <<     
+    creaMessage("Gimmick!",1,"Gimmick! : ==> Loading collections from '"<<mDatabaseListFile<<"'"<<std::endl);
     //       <<"'"<<std::endl;
 
+
     std::ifstream s;
     s.open(mDatabaseListFile.c_str());
     if (s.good())
@@ -953,7 +973,7 @@ namespace creaImageIO
              }
            else 
              {
-               //          std::cout << "    ... ERROR !"<<std::endl;
+               creaMessage("Gimmick!",1,"           ==> ERROR opening collection '"<<tokens[0]<<"'"<<std::endl);
                delete db;
              }
          }
@@ -961,7 +981,7 @@ namespace creaImageIO
        }
        else 
        {
-               std::cout << "ERROR opening "<<mDatabaseListFile<<std::endl;
+         creaMessage("Gimmick!",1,"           ==> File does not exist. It will be created on exit (if you already ran Gimmick! and exited normally, this is not normal. Send a bug report).");
        }
 
        
@@ -1007,6 +1027,13 @@ namespace creaImageIO
   }
   //================================================================
 
+  //================================================================
+  void WxGimmick::LoadOrCreateFavoritesDatabase()
+  {
+    // TODO
+  }
+  //================================================================
+
   /*
   //================================================================
   void  WxGimmick::OnClose(wxCloseEvent& event)
@@ -1086,7 +1113,6 @@ namespace creaImageIO
   //================================================================
   void WxGimmick::OnItemExpanded(wxTreeEvent& event)                   
   {
-
     //    std::cout << "* Expanded *"<<std::endl;
     //  }
 
@@ -1236,7 +1262,6 @@ namespace creaImageIO
   
   void WxGimmick::OnItemRightClick(wxTreeEvent& event)
   {
-
     wxTreeItemId itemId = event.GetItem();
     if (itemId.IsOk())
       {
@@ -1247,8 +1272,6 @@ namespace creaImageIO
     event.Skip();
   }
   //=====================================================================
-  
-
 
   //=====================================================================
   void WxGimmick::ShowMenu(wxTreeItemId id, const wxPoint& pt)
@@ -1293,8 +1316,9 @@ namespace creaImageIO
          }
        if (data->IsDicomNode())
          {
-           /*
+           
            //      LG : BUGGY
+           /*
            std::string str("&Remove ");
            str += data->GetDicomNode()->GetTypeName();
            menu.Append(PopUp_Remove, std2wx(str));
@@ -1348,13 +1372,11 @@ namespace creaImageIO
       }
     GetEventHandler()->ProcessEvent(ev);
     //
-  
+
     if (menu.GetMenuItemCount()>0) menu.AppendSeparator();
     menu.Append(PopUp_Settings, wxT("&Settings..."));
     menu.Append(PopUp_About, wxT("&About..."));
   
-
-  
     /*
       wxMenu* newmenu = new wxMenu;
       wxMenu* openmenu = new wxMenu;
@@ -1414,9 +1436,6 @@ namespace creaImageIO
       }
       }
     */
-
-
  
     PopupMenu(&menu, pt);
 #endif // wxUSE_MENUS
@@ -1429,7 +1448,7 @@ namespace creaImageIO
   // Pop up menu callbacks
   void  WxGimmick::OnPopUpAbout(wxCommandEvent& event)
   {
-    wxMessageBox( _T("Give me my medical images quick ! \n\n  (c) CREATIS-LRMN 2008\n"),
+    wxMessageBox( _T("Give me my medical images quick ! \n\n  (c) CREATIS-LRMN 2008\n      laurent.guigues@creatis.insa-lyon.fr"),
                  _T("Gimmick!"),
                  wxOK | wxICON_INFORMATION, this);
   }
@@ -1439,7 +1458,7 @@ namespace creaImageIO
   void  WxGimmick::OnPopUpSettings(wxCommandEvent& event)
   {
     WxGimmickSettingsDialog* s = 
-      new WxGimmickSettingsDialog(this);
+      new WxGimmickSettingsDialog(this,&mSettings);
     s->ShowModal();
     delete s;
   }
@@ -1453,7 +1472,6 @@ namespace creaImageIO
   }
   //=====================================================================
   
-
  
   //=====================================================================
   void  WxGimmick::OnPopUpOpenCollection(wxCommandEvent& event)
@@ -1483,22 +1501,21 @@ namespace creaImageIO
   void  WxGimmick::OnPopUpDeleteCollection(wxCommandEvent& event)
   {
     if (wxMessageBox(_T("This will physically delete the collection's file on disk and cannot be reverted. Proceed ?"),_T("Confirm"),wxYES_NO,this)==wxNO) return;
-    
+  
     wxBusyCursor busy;
 
-   
     //   std::cout << "OnPopUpClose"<<std::endl;
     //  wxTreeItemId id = event.GetId();
     TreeItemData *data = (TreeItemData *)mTreeListCtrl->GetItemData(mItemOfMenu);
     DicomDatabase* r = data->GetDicomNode()->GetDicomDatabase();
-
     wxRemoveFile(std2wx(r->GetFileName()));
     //   std::cout << "OnPopUpClose '"<<r->GetName()<<"'"<<std::endl;
     DeleteDicomDatabase(mItemOfMenu,r);
-    
   }
   //=====================================================================
-  
+
   void DisplayUpdateSummary( DicomDatabase::UpdateSummary& summary,
                             wxWindow* parent )
   {
@@ -1521,18 +1538,18 @@ namespace creaImageIO
            summary.update_database_time,
            (int)(summary.update_database_time*100./summary.total_time),
            summary.total_time );
-    
+
     mess << times;
-    
     wxMessageBox(std2wx(mess.str()),_T("Update summary"),wxOK,parent);
   }
-  
-  
+
+
   //=====================================================================
   void  WxGimmick::OnPopUpAddFile(wxCommandEvent& event)
   {
     long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
-    std::string wc("*.*");
+    std::string wc("*");
     wxFileDialog* FD = new wxFileDialog( 0, 
                                         _T("Select file"),
                                         mCurrentDirectory,
@@ -1540,7 +1557,7 @@ namespace creaImageIO
                                         std2wx(wc),
                                         style,
                                         wxDefaultPosition);
-    
+
     if (FD->ShowModal()==wxID_OK)
       {
        wxBusyCursor busy;
@@ -1844,7 +1861,7 @@ namespace creaImageIO
            return false;
          }
       }
-    std::cout << "Selecting : "<<node->ImageGetFullFileName() << std::endl;
+    //    std::cout << "Selecting : "<<node->ImageGetFullFileName() << std::endl;
     return true;
   }
   //================================================================
@@ -1974,7 +1991,7 @@ namespace creaImageIO
              }
            sib = GetTreeListCtrl()->GetNextSibling(sib);
          }
-       prio = maxprio + 1000;
+       prio = maxprio + 999;
        sib = GetTreeListCtrl()->GetPrevSibling(item);
        while (sib.IsOk())
          {
@@ -2017,13 +2034,17 @@ namespace creaImageIO
   void WxGimmick::ShowImage(vtkImageData* im)
   {
     //  wxBusyCursor busy;
+    mViewer->SetInput( im );
+    mViewer->SetSlice( 0 );
     
+
     int x1,x2,y1,y2,z1,z2;
     double spx,spy,spz;
+    im->Update();
     im->GetSpacing(spx,spy,spz);
     im->GetExtent (x1,x2,y1,y2,z1,z2);
-    
     /*
+    std::cout << "-----------------------------"<<std::endl;
       std::cout << x1 << "-"<<x2<<std::endl; 
       std::cout << y1 << "-"<<y2<<std::endl; 
       std::cout << z1 << "-"<<z2<<std::endl; 
@@ -2051,19 +2072,39 @@ namespace creaImageIO
        mspy = spy;
        mspz = spz;
        
+       double *range = im->GetScalarRange();
+        mViewer->SetColorWindow(range[1] - range[0]);
+        mViewer->SetColorLevel(0.5 * (range[1] + range[0]));
+
+        mViewer->GetRenderer()->ResetCamera();
+       double bounds[6];
+
+
+        mViewer->GetRenderer()->ComputeVisiblePropBounds(bounds);
+
+        /*
+       std::cout <<"bounds : "<<bounds[0]<<","
+<<bounds[1]<<","
+<<bounds[2]<<","
+<<bounds[3]<<","
+<<bounds[4]<<","
+                 <<bounds[5]<<std::endl;
+        */
+        mViewer->GetRenderer()->ResetCameraClippingRange(bounds);
+       /*
        vtkCamera *camera = mViewer->GetRenderer()->GetActiveCamera();
        
        camera->SetViewUp ( spx*0, -spy*1, spz*0);
-       camera->SetPosition( spx*(x1+x2)/2, spy*(y1+y2)/2, -spz*10000000); 
+       camera->SetPosition( spx*(x1+x2)/2, spy*(y1+y2)/2, spz*10000000); 
        camera->SetFocalPoint   ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*0); 
        
        camera->ComputeViewPlaneNormal();
        camera->SetParallelScale(  spx*(x2-x1)/2.0 );
        
+       camera->Roll ( 180 );
+       */
       }
     
-    mViewer->SetInput( im );
-    mViewer->SetSlice( 0 );
     mInteractor->Render();
   } 
   //================================================================
@@ -2144,6 +2185,14 @@ namespace creaImageIO
   void  WxGimmick::OnInternalIdle()
   {
     ProcessImageEvents();
+    /*
+    if (mJustStarted)
+      {
+
+       mJustStarted = false;
+       }
+    */
+    //
   }
   //================================================================
  
@@ -2237,14 +2286,22 @@ namespace creaImageIO
          {     
            // n2D to 3D
            vtkImageData* out = vtkImageData::New();
-           out->CopyStructure(first);
+           out->CopyStructure(first);  
+           out->SetScalarType(first->GetScalarType());
            int ext[6];
            first->GetExtent(ext);
            ext[5] = im.size();
            out->SetExtent(ext);
+           // LG : TODO : Z Spacing  ?
+           //
+           // ==> to get an accurate ZSpacing from a Dicom set of files
+           // ==> you need a gdcm::SerieHelper
+           //  JPR
            
            out->AllocateScalars();
-           out->Print(std::cout);
+           
+           //first->Print(std::cout);
+           //      out->Print(std::cout);
            
            int dim[3];
            first->GetDimensions(dim);
@@ -2252,17 +2309,36 @@ namespace creaImageIO
              ( (unsigned long)first->GetScalarPointer(0,1,0)
                - (unsigned long)first->GetScalarPointer(0,0,0))
              *dim[1];
-           std::cout << "imsize="<<imsize<<std::endl;
 
            int slice = 0;
            std::vector<DicomNode*>::iterator it;
            for (it=im.begin(); it!=im.end(); ++it) 
              {
+               //std::cout << "copying slice "<<slice <<std::endl;
                vtkImageData* cur = mReader.GetImage( (*it)->ImageGetFullFileName() );
                
                void* src = cur->GetScalarPointer(0,0,0);
                void* dst = out->GetScalarPointer(0,0,slice);
+               //              std::cout << "src="<<src<<std::endl;
+               //              std::cout << "dst="<<dst<<std::endl;
+               //              std::cout << "siz="<<imsize<<std::endl;
                memcpy(dst,src,imsize);
+
+               /*
+               // verif
+               int ii,jj;
+               for (ii=1;ii<4;ii++) {
+                 for (jj=1;jj<4;jj++) {
+                   int x = (int)(ii*dim[0] / 4);
+                   int y = (int)(jj*dim[1] / 4);
+                   std::cout << cur->GetScalarComponentAsFloat(x,y,0,0)
+                             << " vs "
+                             << out->GetScalarComponentAsFloat(x,y,slice,0)
+                             << std::endl;
+                 }
+               }
+               */
+
                slice++;
              }
            f.push_back(out);
@@ -2726,10 +2802,19 @@ namespace creaImageIO
     }
 
 
-
-
-
-
+    //====================================================================
+    void WxGimmick::ShowHelp()
+    {
+      /*
+      if (mHelpWindow==0)
+       {
+         mHelpWindow = new WxGimmickHelpWindow(this);
+       }
+      mHelpWindow->CenterOnParent();
+      mHelpWindow->ShowModal();
+      */
+    }
+    //====================================================================
 
 
 
@@ -2911,38 +2996,7 @@ namespace creaImageIO
 
 
 
-             //================================================================
-             //================================================================
-             //================================================================
-             //================================================================
-
-             //================================================================
-             WxGimmickSettingsDialog::WxGimmickSettingsDialog(wxWindow *parent)
-             : 
-             wxDialog( parent, 
-                       -1, 
-                       _T("Settings"),
-                       wxDefaultPosition,
-                       wxSize(400,400),
-                       wxRESIZE_BORDER | 
-                       wxSYSTEM_MENU  |
-                       wxCLOSE_BOX |
-                       wxMAXIMIZE_BOX | 
-                       wxMINIMIZE_BOX | 
-                       wxCAPTION  
-                       )
-             {
-             } 
-             //================================================================
-    
-             //================================================================
-             WxGimmickSettingsDialog::~WxGimmickSettingsDialog()
-               {
-               }
-             //================================================================
-
-    
-
+