]> Creatis software - creaImageIO.git/commitdiff
Implemented calls from/to the interface to several methods.
authorcaballero <caballero>
Mon, 23 Feb 2009 17:07:55 +0000 (17:07 +0000)
committercaballero <caballero>
Mon, 23 Feb 2009 17:07:55 +0000 (17:07 +0000)
appli/TestWxGimmickReaderDialog/main.cxx
src2/creaImageIOGimmickView.h
src2/creaImageIOTreeView.h
src2/creaImageIOWxGimmickFrame.cpp
src2/creaImageIOWxGimmickReaderDialog.cpp
src2/creaImageIOWxGimmickReaderDialog.h
src2/creaImageIOWxGimmickView.cpp
src2/creaImageIOWxGimmickView.h
src2/creaImageIOWxTreeView.cpp
src2/creaImageIOWxTreeView.h

index 541cfa26e4f3f2783ce0bfb2f43c507d1620594c..8149724adc7b2ea418f298b1252b6d21be57f62f 100644 (file)
@@ -29,7 +29,8 @@ bool myApp::OnInit( )
    creaImageIO::SetGimmickDebugMessageLevel(9);
    */
 
-   int image_type = GIMMICK_3D_IMAGE_SELECTION;
+   int min_dim = GIMMICK_2D_IMAGE_SELECTION;
+   int max_dim = GIMMICK_3D_IMAGE_SELECTION;
    int threads = 1;
 
    creaImageIO::WxGimmickReaderDialog w(0,
@@ -37,7 +38,8 @@ bool myApp::OnInit( )
                                        _T("Select image(s)        - Gimmick! (c) CREATIS-LRMN 2008"),
                                        wxDefaultPosition,
                                        wxSize(1200,800),
-                                       image_type,
+                                       min_dim,
+                                       max_dim,
                                        threads);
    w.ShowModal();
    
@@ -55,7 +57,7 @@ bool myApp::OnInit( )
        std::cout << "$$$$ "<<std::endl;
 
        std::vector<vtkImageData*> images;
-       w.GetSelectedImages(images);
+       w.GetSelectedImages(images,3);
        crea::VtkBasicSlicer(images.front());
        images.front()->Delete();
 
index f17fcb48e4cc6a53d6b23a6e987ab2018c2d0b1c..8407a9179cb22008dbcdd940e934862777b0f10d 100644 (file)
@@ -4,6 +4,7 @@
 #include <creaImageIOGimmick.h>
 #include <creaImageIOTreeView.h>
 #include <creaImageIOSystem.h>
+
 //#include <map>
 #include <vtkImageData.h>
 
@@ -48,8 +49,11 @@ namespace creaImageIO
 
       /// Finalize 
       virtual void Finalize();
-      
-      virtual void GetSelectedImages(std::vector<vtkImageData*>& s) {}
+         ///Returns the selected Images and validates to see if they comply with the given parameter(<4D)
+         vtkImageData* GetSelectedImage(int dim);
+      ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
+      virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim) {}
+
       virtual void GetSelectedFiles(std::vector<std::string>& s) {}
 
       /// Create the tree views 
index edee939bfc807f2a4b63695c6fa982a65d560850..fe29f3bddab5635487bcef758a1943289e0c81ab 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <creaImageIOTreeHandler.h>
 #include <creaImageIOSystem.h>
+#include <vtkImageData.h>
 
 namespace creaImageIO
 {
@@ -29,6 +30,16 @@ namespace creaImageIO
          ///Removes selected nodes on given level
          virtual void RemoveSelected( int )
          { GimmickError("INTERNAL ERROR : TreeView::RemoveSelected not overloaded");}
+
+         ///Validates the selected images
+      virtual void ValidateSelectedImages()
+         { GimmickError("INTERNAL ERROR : TreeView::ValidateSelected not overloaded");}
+         ///Returns the selected data as vtkImageData
+         vtkImageData* GetSelectedImage(int dim)
+         { GimmickError("INTERNAL ERROR : TreeView::GetSelectedImage not overloaded");}
+    ///Returns the selected data as a vector of vtkImageData (4D)
+         virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
+         { GimmickError("INTERNAL ERROR : TreeView::GetSelectedImages not overloaded");}
     
     protected:
       TreeHandler* GetTreeHandler() { return mTreeHandler; }
index 3e6b61651adadad8625c447d79f8ec4b1c57411a..a14a7eeeec0004b398358b1bbb369c1118110ddd 100644 (file)
@@ -34,13 +34,15 @@ namespace creaImageIO
       mGimmick = new Gimmick();
       mGimmick->Initialize();
      
-      int image_type = GIMMICK_3D_IMAGE_SELECTION;
+      int min_dim = GIMMICK_2D_IMAGE_SELECTION;
+         int max_dim = GIMMICK_3D_IMAGE_SELECTION;
       mView = new WxGimmickView(mGimmick,
                                this,
                                -1,
                                wxDefaultPosition,
                                size,
-                               image_type,
+                               min_dim,
+                               max_dim,
                                threads);
       mView->Initialize();
     }
index a6053faec50a798c1b6fa8534a0b52639bdc6599..2bf166168c26db24dc3fc102043e84c04d713b05 100644 (file)
@@ -9,7 +9,8 @@ namespace creaImageIO
                                               wxString title,
                                               const wxPoint& pos,
                                               const wxSize& size,
-                                              int image_type,
+                                              int min_dim,
+                                                  int max_dim,
                                               int threads)
  :   wxDialog( parent, 
                  id, 
@@ -41,7 +42,8 @@ namespace creaImageIO
                                TVID,
                                wxDefaultPosition,
                                size,
-                               image_type,
+                               min_dim,
+                               max_dim,
                                threads);
       mView->Initialize();
     }
@@ -80,11 +82,13 @@ namespace creaImageIO
        delete mGimmick;
       }
   }
-  
+
+
   
   //================================================================
   BEGIN_EVENT_TABLE(WxGimmickReaderDialog, wxDialog)
-    END_EVENT_TABLE()
+        
+  END_EVENT_TABLE()
   //================================================================
 
 
index 1bf53de07799e83e87dc989cd5539ec173184a95..9526d374e428c154acc08f203113161dfc07a8a4 100644 (file)
@@ -22,7 +22,8 @@ namespace creaImageIO
                          wxString title,
                          const wxPoint& pos, 
                          const wxSize& size,
-                         int image_type = GIMMICK_3D_IMAGE_SELECTION,
+                         int image_min_type = GIMMICK_2D_IMAGE_SELECTION,
+                         int image_max_type = GIMMICK_3D_IMAGE_SELECTION,
                          int threads = 0);
     
     Gimmick* GetGimmick() { return mGimmick; }
@@ -31,14 +32,23 @@ namespace creaImageIO
 
     ~WxGimmickReaderDialog();
 
-    void GetSelectedImages(std::vector<vtkImageData*>& s)
-    { mView->GetSelectedImages(s); }
+
+       //===============================================================================================
+       //Image Selection
+       //===============================================================================================
+    vtkImageData* GetSelectedImage(int dim) 
+       { return mView->GetSelectedImage(dim); }
+    void GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
+    { mView->GetSelectedImages(s, dim); }
+
+
     void GetSelectedFiles(std::vector<std::string>& s) 
     { mView->GetSelectedFiles(s); }
     
     void OnSelChanged(EventType& event);
     void OnContextualMenu(EventType& event);
     void OnMenuTest(wxCommandEvent& event);
+       //    void OnValid(wxCommandEvent& event);
     //    void OnButtonOk(wxCommandEvent& event);
     //    void OnButtonCancel(wxCommandEvent& event);
 
index 064accc941394e18dd560df5372ed44f2ec34447..edcc6843d54b17fb39b4f0aa38cb087c088e4bcc 100644 (file)
@@ -61,7 +61,8 @@ namespace creaImageIO
                               wxWindow *parent, 
                               const wxWindowID id,
                               const wxPoint& pos, const wxSize& size,
-                              int image_type,
+                              int min_dim,
+                                  int max_dim,
                               int number_of_threads)
     : wxPanel(parent,id,pos,size),
       GimmickView(gimmick),
@@ -190,8 +191,21 @@ namespace creaImageIO
 
   }
   //======================================================================
+  /// Returns the selected Images so that they comply with the given parameter(<4D)
+  vtkImageData* WxGimmickView::GetSelectedImage(int dim)
+  {
+         return NULL;
+  }
 
-
+  //======================================================================
+  /// Returns the selected Images so that they comply with the given parameter(4D)
+  void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
+  {
+       
+               //GetTreeViewMap()["Local database"]->GetImageData()
+               //return NULL   ;
+       
+  }
 
   //=================================================
   void WxGimmickView::CreateIconList()
index c2790c721c9fda3f5c4943f9da5c18f14824646d..1da272979ddbaa4a793ddddc2245a3a6789ede38 100644 (file)
@@ -30,11 +30,19 @@ namespace creaImageIO
                    wxWindow *parent, 
                    const wxWindowID id,
                    const wxPoint& pos, const wxSize& size,
-                   int image_type = GIMMICK_3D_IMAGE_SELECTION,
+                   int min_dim = GIMMICK_2D_IMAGE_SELECTION,
+                       int max_dim = GIMMICK_3D_IMAGE_SELECTION,
                    int number_of_threads = 0);
       /// Virtual destructor
       virtual ~WxGimmickView();
 
+         /// Returns the selected Images so that they comply with the given parameter(<4D)
+         ///(overloaded from GimmickView)
+         vtkImageData* GetSelectedImage(int dim);
+      /// Returns the selected Images so that they comply with the given parameter(4D)
+      //(overloaded from GimmickView)
+         void GetSelectedImages(std::vector<vtkImageData*>& s, int dim);
+
     protected:
       /// Creates the tool bar
       void CreateToolBar(); 
@@ -43,6 +51,7 @@ namespace creaImageIO
       /// (overloaded from GimmickView)
       void CreateTreeView( TreeHandler* );
 
+
     private:
       /// The ToolBar and the tools
       wxToolBar*         mToolBar;
index 2a58cd393a9598dfb4af7b88fd5112efe2dd4e79..1b3d20d7d0ff829db0b92e30b4ae12ab1aca9add 100644 (file)
@@ -1,7 +1,16 @@
 #include <creaImageIOWxTreeView.h>
 #include <creaImageIOSystem.h>
 #include <wx/splitter.h>
-
+int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData))
+{
+    // inverse the order
+    if (item1 < item2)
+        return -1;
+    if (item1 > item2)
+        return 1;
+
+    return 0;
+}
 namespace creaImageIO
 {
   //=====================================================================
@@ -321,12 +330,251 @@ namespace creaImageIO
                        " Level "<<level+1
                        <<std::endl);
     if (level<mLevelList.size()-1) UpdateLevel( level + 2 ); 
+       if (level==mLevelList.size()-1) ValidateSelectedImages ();
+
+  }
+  //================================================================
+
+//================================================================
+  void WxTreeView::OnColClick(wxListEvent& event)
+  { 
+         /*
+       //Obtain the column name and the level that needs to be organized
+       int colNum=event.m_col;
+    GimmickMessage(1,
+                       " Column " <<event.m_col
+                       <<std::endl);
+
+       
+    wxObject* ctrl = event.GetEventObject(); 
+       unsigned int level = 0;
+    for (level = 0; level<mLevelList.size(); ++level)
+      {
+       if ( GetCtrl(level) == ctrl ) break;
+      }
+
+         wxBusyCursor busy;
+    std::vector<tree::Node*> sel=GetSelected(level+1);
+
+       tree::Node* nodes[20];
+
+         int l = level - 1;
+    // to speed up inserting we hide the control temporarily
+    GetCtrl(level)->Hide();
+    GetCtrl(level)->DeleteAllItems();
+    
+    std::vector<tree::Node*>::iterator i;
+       int num=0;
+    for (i=sel.begin(); i!=sel.end(); ++i)
+      {
+       
+               //Adds columns
+               GetTreeHandler()->LoadChildren(*i,1);
+               tree::Node::ChildrenListType::reverse_iterator j;
+               
+               for (j = (*i)->GetChildrenList().rbegin(); 
+                       j!= (*i)->GetChildrenList().rend(); 
+                       ++j)
+                       {
+                               nodes[num]=*j;
+                               num++;
+                       }
+      }
+       
+         //Sorting elements
+         int k, m; 
+         tree::Node* index;
+         
+       
+       for (k=1; k<num; ++k)
+       {
+               index = nodes[k];
+               m = k;
+               GimmickMessage(1,
+                       "Comparison Key 1: "
+                           <<(nodes[m-1])->GetAttribute(mLevelList[level].key[colNum-1])
+                               <<"Comparison Key 2: "<<(index)->GetAttribute(mLevelList[level].key[colNum-1])
+                           <<std::endl);
+               while ((m > 0) && ((nodes[m-1])->GetAttribute(mLevelList[level].key[colNum-1]) > 
+                                                  (index)->GetAttribute(mLevelList[level].key[colNum-1])))
+               {
+               nodes[m] = nodes[m-1];
+               m = m - 1;
+               }
+               nodes[m] = index;
+       }
+
+       for (m=0; m<num; ++m)
+       {
+               tree::Node* node=nodes[m];
+           wxListItem item;
+           item.SetMask(wxLIST_MASK_STATE | 
+                        wxLIST_MASK_TEXT |
+                        //                      wxLIST_MASK_IMAGE |
+                        wxLIST_MASK_DATA |
+                        //                      wxLIST_MASK_WIDTH |
+                        wxLIST_MASK_FORMAT
+                        );
+
+           long id = GetCtrl(level)->InsertItem(item);
+               int n;
+               if ((node)->GetChildrenLoaded()) 
+               {
+                       n=(node)->GetChildrenList().size();
+               }
+               else
+               {
+                       n= GetTreeHandler()->GetNumberOfChildren(node);
+               }
+               std::ostringstream oss;
+               
+               oss << n;
+               std::string s(oss.str());
 
+               GetCtrl(level)->SetItem(id,0, crea::std2wx(s));
+               GetCtrl(level)->SetColumnWidth(0, wxLIST_AUTOSIZE );
+               
+         for (int k=1; k<GetCtrl(level)->GetColumnCount(); k++)
+             {
+               std::string val = (node)->GetAttribute(mLevelList[level].key[k-1]);
+               if (val.size()==0) val = "?";
+               GetCtrl(level)->SetItem(id,k, crea::std2wx(val));
+               GetCtrl(level)->SetColumnWidth(k, wxLIST_AUTOSIZE );
+               
+             }
+           
+         }
+
+    
+    GetCtrl(level)->Show();
+*/
+  }
+  //================================================================
+
+  void WxTreeView::ValidateSelectedImages()
+  {
+         GimmickMessage(1,
+                       "Hello World Validate"
+                           <<std::endl);
+         /*
+       MyEvent event( MyCommandEvent, 0 );
+       wxString bar( wxT("This is a Foo_DoFirstThing event") );
+       event.SetText( bar );
+       wxPostEvent( this, event );
+       */
+       
   }
+
   //================================================================
 
 
+  vtkImageData* WxTreeView::GetSelectedImage(int dim)
+  {
+         /*
+               wxArrayTreeItemIds id;
+    // TO DO : TEST THAT STYLE IS MULTIPLE 
+    unsigned int nb = mTreeListCtrl->GetSelections(id);
+    f.clear();
+
+    // Collect the brute vector of Image nodes
+    std::vector<DicomNode*> im;
+    for (unsigned int i=0; i<nb; ++i)
+      {
+       TreeItemData *data = 
+         (TreeItemData *)mTreeListCtrl->GetItemData(id[i]);
+       if ((data) && (data->IsDicomNode()))
+         {
+           if (data->GetDicomNode()->GetType()==DicomNode::Image)
+             {
+               im.push_back ( data->GetDicomNode() );
 
+             }
+           else if (data->GetDicomNode()->GetType()==DicomNode::Series)
+             {
+               DicomNode::ChildrenListType::iterator j;
+               for (j =data->GetDicomNode()->GetChildrenList().begin();
+                    j!=data->GetDicomNode()->GetChildrenList().end();
+                    j++) 
+                 {
+                   im.push_back ( *j );
+                 }
+             }
+         }
+      }
+    // Create the output data
+    if (im.size()==1) 
+      {
+       // Only one image : give it
+       vtkImageData* out = vtkImageData::New();
+       out->ShallowCopy(mReader.GetImage(im.front()->ImageGetFullFileName()));
+       f.push_back( out );
+      }
+    else if (im.size()>1)
+      {
+       vtkImageData* first = mReader.GetImage( im.front()->ImageGetFullFileName() );
+       if (first->GetDataDimension()==2) 
+         {     
+           // n2D to 3D
+           vtkImageData* out = vtkImageData::New();
+           out->CopyStructure(first);  
+           out->SetScalarType(first->GetScalarType());
+           int ext[6];
+           first->GetExtent(ext);
+           ext[5] = im.size();
+           out->SetExtent(ext);
+           // LG : TODO : Z Spacing  ?
+           
+           out->AllocateScalars();
+           
+           //first->Print(std::cout);
+           //      out->Print(std::cout);
+           
+           int dim[3];
+           first->GetDimensions(dim);
+           unsigned long imsize = 
+             ( (unsigned long)first->GetScalarPointer(0,1,0)
+               - (unsigned long)first->GetScalarPointer(0,0,0))
+             *dim[1];
+
+           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);
+
+               slice++;
+             }
+           f.push_back(out);
+         }
+       else 
+         {
+           // n3D
+           std::vector<DicomNode*>::iterator it;
+           for (it=im.begin(); it!=im.end(); ++it) 
+             {
+               vtkImageData* out = vtkImageData::New();
+               out->ShallowCopy(mReader.GetImage((*it)->ImageGetFullFileName()));
+               f.push_back(out);
+             }
+         }
+      }
+         */
+       return NULL;
+  }
+
+  void WxTreeView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
+  {
+
+  }
   BEGIN_EVENT_TABLE(WxTreeView, wxPanel)
   /*
     EVT_SIZE(MyFrame::OnSize)
@@ -384,8 +632,10 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
     EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
     EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused)
 
-    EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick)
     EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick)
+       */
+    EVT_LIST_COL_CLICK(-1, WxTreeView::OnColClick)
+       /*
     EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnColBeginDrag)
     EVT_LIST_COL_DRAGGING(LIST_CTRL, MyListCtrl::OnColDragging)
     EVT_LIST_COL_END_DRAG(LIST_CTRL, MyListCtrl::OnColEndDrag)
index e0e46d77708432450f386539d438456476d59e1e..6ffc1f52173df045143d4ea55c93130ba355169c 100644 (file)
@@ -34,9 +34,12 @@ namespace creaImageIO
          ///Removes selected nodes on given level
          virtual void RemoveSelected( int );
 
-      /// Callback for selection change
+         /// Callback for selection change
       void OnSelected(wxListEvent& event);
 
+         /// Callback for selection change
+      void OnColClick(wxListEvent& event);
+
 
     private:
       /// The struct holding the data for one level
@@ -44,7 +47,7 @@ namespace creaImageIO
       /// such as the vector of attribute keys corresponding to the columns
       struct LevelType
       {
-       // The
+       // The List Control
        wxListCtrl* wxCtrl;
        wxSplitterWindow* wxSplitter;
        std::vector<std::string> key;
@@ -56,10 +59,14 @@ namespace creaImageIO
       wxListCtrl* GetCtrl(int l) { return mLevelList[l].wxCtrl; }
       /// return the wxSplitter of one level
       wxSplitterWindow* GetSplitter(int l) { return mLevelList[l].wxSplitter; }
-
+         /// Gets the user selected data from the level passed as a parameter
       std::vector<tree::Node*> GetSelected(int level);
-  
-  
+         ///Validates the selected images
+      void ValidateSelectedImages();
+         ///Returns the selected data as vtkImageData
+         vtkImageData* GetSelectedImage(int dim);  
+         ///Returns the selected data as vtkImageData
+         void GetSelectedImages(std::vector<vtkImageData*>& s, int dim);  
        
       // Updates the view of a level given the selected items of upper level
       // Recursive method
@@ -72,8 +79,27 @@ namespace creaImageIO
     //=====================================================================
   
 } // EO namespace creaImageIO
-
-
+/*
+class MyEvent: public wxCommandEvent
+{
+public:
+       MyEvent( wxEventType commandType = MyCommandEvent, int id = 0 )
+       :  wxCommandEvent(commandType, id) { }
+       // You *must* copy here the data to be transported
+       MyEvent( const MyEvent &event )
+       :  wxCommandEvent(event) { this->SetText( event.GetText() ); }
+       // Required for sending with wxPostEvent()
+       wxEvent* Clone() const { return new MyEvent(*this); }
+       wxString GetText() const { return m_Text; }
+       void SetText( const wxString& text ) { m_Text = text; }
+private:
+       wxString m_Text;
+};
+*/
 #endif // USE_WIDGETS
 // EOF
 #endif