]> Creatis software - creaContours.git/blob - appli/wxContourGUIExample/wxContourGUIExample.cxx
ddf28af5c096a10da2b457e2815c7406cd525149
[creaContours.git] / appli / wxContourGUIExample / wxContourGUIExample.cxx
1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
4
5
6 #include "wxContourGUIExample.h"
7 #include "wxContourMainFrame.h"
8 //#include "OutlineModelManager.h"
9 //#include "wxContourEventHandler.h"
10
11
12 #include <creaImageIOWxGimmickDialog.h>
13
14 #include <creaVtkBasicSlicer.h>
15 //#include "wxContourMainPanel.h"
16
17 #include "vtkMetaImageReader.h"
18 #include <map>
19 #include "vtkImageData.h"
20
21 #include "wx/artprov.h"
22 #include <wx/filedlg.h>
23 //#include "OutlineModelBuilder.h"
24 //#include "ContourThing.h"
25 //#include "AxeThing.h"
26 //#include "ImageSourceThing.h"
27 //#include "ImageSectionThing.h"
28 //#include "SomeEnvironment.h"
29 //#include "ReaderEnvironment.h"
30
31
32
33
34 //#include "interfMainPanel.h"
35
36
37 wxContourMainFrame* wxTheApplication::frame = 0;
38 //----------------------------------------------------------------------------------------------------------------
39 // This macro implements the entry point (main function) for the application
40 //----------------------------------------------------------------------------------------------------------------
41
42
43 //EED
44 // http://lists.wxwidgets.org/archive/wx-dev/msg30449.html
45 wxString getExecutablePath()
46 {
47     char buf[512];
48     char* slash;
49
50 #if defined(WIN32)
51     GetModuleFileName(NULL, buf, 511);
52     slash = strrchr(buf, '\\');
53     if (slash)
54     {
55         *slash = 0;
56     }
57 #elif defined(__LINUX__)
58     int res;
59     res = readlink("/proc/self/exe", buf, 512);
60     if (res == -1)
61         return _T("");
62     buf[res] = 0;
63     slash = strrchr(buf, '/');
64     if (slash)
65     {
66         *slash = 0;
67     }
68 #else
69     return "";
70 #endif
71
72     return wxString(buf, wxConvUTF8 );
73 }
74
75
76
77
78
79
80 IMPLEMENT_APP( wxTheApplication );
81
82 /*
83 wxContourGUIExample :: wxContourGUIExample(const wxString& title, const wxPoint& pos, const wxSize& size)
84 : wxFrame((wxFrame *) NULL, -1, title, pos, size)
85 {
86         
87 }
88 */
89
90 #ifdef _DEBUG
91 void wxAppConsole::OnAssert(char const *,int,char const *,char const *)
92 {
93 }
94
95 void wxAppConsole::OnAssertFailure(char const *,int,char const *,char const *,char const *)
96 {
97 }
98 #endif
99
100 bool wxTheApplication :: OnInit()
101 {
102
103         wxInitAllImageHandlers();
104
105    int image_type = GIMMICK_3D_IMAGE_SELECTION;
106    int threads = 1;
107
108    creaImageIO::WxGimmickDialog w(0,
109                                   -1,
110                                   _T("WxGimmickDialog test"),
111                                   wxDefaultPosition,
112                                   wxSize(1200,800),
113                                   image_type,
114                                   threads);
115    w.ShowModal();
116    
117    //vtkImageData* selectedimage=NULL;
118    std::vector<vtkImageData*> images;
119         if(w.GetReturnCode() == wxID_OK){
120
121        std::vector<std::string> s;
122        w.GetSelectedFiles(s);
123        std::vector<std::string>::iterator i;
124            for (i=s.begin();i!=s.end();++i){
125                    std::cout << *i << std::endl;
126            }
127                 
128            std::cout << "$$$$ "<<std::endl;
129        w.GetSelectedImages(images);
130            //selectedimage = images[0];
131        //crea::VtkBasicSlicer(images.front());
132        //images.front()->Delete();
133
134         }else if (w.GetReturnCode() == wxID_CANCEL){
135            vtkMetaImageReader *reader = vtkMetaImageReader::New();
136            wxString filename= getExecutablePath()+ wxString( _T("/data/hola.mhd") , wxConvUTF8 );          
137            reader->SetFileName( filename.c_str() );
138            reader->Update();
139            images.push_back(reader->GetOutput());
140         }else{        
141                 return -1;
142         }   
143
144
145         wxFrame* frame1 = new wxFrame(NULL, wxID_ANY, wxT("ROI Application  -    Evaluation version, 09 Feb 2009 "), wxPoint(400,50), wxSize(800, 600) );
146
147         //frame = new wxContourMainFrame( frame1, wxID_ANY, wxString(_T("")), wxPoint(50,50), wxSize(800, 600), images ); 
148         frame = wxContourMainFrame::getInstance(frame1, wxID_ANY, wxString(_T("")), wxPoint(200,50), wxSize(800, 600), images,  wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER,(const char*)( getExecutablePath().mb_str() )  );
149         frame1->CreateStatusBar();
150         frame1->Show(TRUE);
151
152
153         return TRUE;
154 }
155
156 #if(WIN32)
157 int main(int argc, char* argv[])                                        
158   {                                                                     
159     return WinMain(::GetModuleHandle(NULL), NULL,                       
160                    ::GetCommandLine(), SW_SHOWNORMAL);                  
161   }             
162 #else
163 #endif
164