]> Creatis software - creaContours.git/blob - appli/wxContourGUIExample/wxContourGUIExample.cxx
no message
[creaContours.git] / appli / wxContourGUIExample / wxContourGUIExample.cxx
1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
4
5 #include "wxContourGUIExample.h"
6 #include "wxContourMainFrame.h"
7 //#include "OutlineModelManager.h"
8 //#include "wxContourEventHandler.h"
9
10 //#include <creaImageIOWxGimmickDialog.h>
11 #include <creaImageIOWxGimmickReaderDialog.h>
12 #include <creaImageIOSystem.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
24
25 /* EED EraseMe
26 //#include "OutlineModelBuilder.h"
27 //#include "ContourThing.h"
28 //#include "AxeThing.h"
29 //#include "ImageSourceThing.h"
30 //#include "ImageSectionThing.h"
31 //#include "SomeEnvironment.h"
32 //#include "ReaderEnvironment.h"
33
34 //#include "interfMainPanel.h"
35
36 #if defined(MACOSX) // assume this is OSX 
37 # include <sys/param.h>
38 # include <mach-o/dyld.h> // _NSGetExecutablePath : must add -framework CoreFoundation to link line 
39 # include <string.h>
40 # ifndef PATH_MAX
41 #  define PATH_MAX MAXPATHLEN
42 # endif
43 #endif // MACOSX
44 */
45  
46 #ifndef PATH_MAX // If not defined yet : do it 
47 #  define PATH_MAX 2048
48 #endif
49
50 #if defined(WIN32)
51   #include <direct.h>
52 #else
53    #include <dirent.h>  
54 #endif
55
56 #include <stdlib.h>
57
58 wxContourMainFrame* wxTheApplication::frame = 0;
59
60 //----------------------------------------------------------------------------------------------------------------
61 // This macro implements the entry point (main function) for the application
62 //----------------------------------------------------------------------------------------------------------------
63
64
65
66
67 #if defined(_WIN32)
68 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '\\'
69 #else
70 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '/'
71 #endif
72
73 //=========================================================================
74 std::string GetExecutablePath()
75 {
76     char name[PATH_MAX];
77         //EED    int err = get_app_path(name, PATH_MAX);
78         int err = crea::System::GetAppPath(name,PATH_MAX);
79     if (err) 
80         {
81                 printf("Could not determine current executable path ?  ");  
82         }    
83     // remove the exe name
84     char *slash;                
85     slash = strrchr(name, CREACONTOUR_VALID_FILE_SEPARATOR_CHAR);
86     if (slash)
87         {
88                 *slash = 0;
89         }
90     return name;
91 }
92
93 //=========================================================================
94 //=========================================================================
95 IMPLEMENT_APP( wxTheApplication );
96 /*
97 wxContourGUIExample :: wxContourGUIExample(const wxString& title, const wxPoint& pos, const wxSize& size)
98 : wxFrame((wxFrame *) NULL, -1, title, pos, size)
99 {
100 }
101 */
102
103 #ifdef _DEBUG
104 void wxAppConsole::OnAssert(char const *,int,char const *,char const *)
105 {
106 }
107
108 void wxAppConsole::OnAssertFailure(char const *,int,char const *,char const *,char const *)
109 {
110 }
111 #endif
112
113 bool wxTheApplication :: OnInit()
114 {
115         wxInitAllImageHandlers();
116
117         int min_image_type = GIMMICK_2D_IMAGE_SELECTION;
118         int max_image_type = GIMMICK_3D_IMAGE_SELECTION;
119         int output_dim = NATIVE;
120         int threads = 1;
121
122         std::vector<vtkImageData*> images;
123         printf("EED wxContourGUIExample:OnInit 1\n");
124         creaImageIO::WxGimmickReaderDialog w(0,
125                                                                                 -1,
126                                                                                 "creaContours_Descriptor.dscp",
127                                                                                 "creatisContours DB", 
128                                                                                 _T("WxGimmickDialog test"),
129                                                                                 wxDefaultPosition,wxSize(1200,800)
130                                                                                 ,min_image_type,
131                                                                                 max_image_type,
132                                                                                 output_dim,
133                                                                                 threads);
134   
135         w.ShowModal();
136         printf("EED wxContourGUIExample:OnInit 2\n");
137
138
139 //JCP
140         //std::string datadir(  crea::wx2std(GetExecutablePath()) );    
141         std::string datadir(  GetExecutablePath() );
142 //JCP
143         
144                 #ifdef MACOSX /* assume this is OSX */
145                         datadir=datadir+"/../../..";
146                 #endif // MACOSX        
147                 
148                 
149                         if(w.GetReturnCode() == wxID_OK)
150                         {
151                                 std::vector<std::string> s;
152                                 w.GetSelectedFiles(s);
153                                 std::vector<std::string>::iterator i;
154                                 for (i=s.begin();i!=s.end();++i)
155                                 {
156                                         std::cout << *i << std::endl;
157                                 }
158                                 std::cout << "$$$$ "<<std::endl;
159                                 //w.GetSelectedImages(images);
160                                 w.GetSelectedImages(images,output_dim);
161                         }
162                         else if (w.GetReturnCode() == wxID_CANCEL)
163                         {
164                                 vtkMetaImageReader *reader = vtkMetaImageReader::New();
165                                 std::string filename= datadir + "/data/hola.mhd";          
166                                 reader->SetFileName( filename.c_str() );
167                                 reader->Update();
168                                 images.push_back(reader->GetOutput());
169                         }
170                         else
171                         {        
172                                 return -1;
173                         }   
174
175
176         wxFrame* frame1 = new wxFrame(NULL, wxID_ANY, wxT("ROI Application  -    Evaluation version, 09 Feb 2009 "), wxPoint(400,50), wxSize(800, 600) );
177
178         //frame = new wxContourMainFrame( frame1, wxID_ANY, wxString(_T("")), wxPoint(50,50), wxSize(800, 600), images ); 
179         frame = wxContourMainFrame::getInstance(frame1, wxID_ANY, wxString(_T("")), wxPoint(200,50), wxSize(800, 600), images,  wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER,datadir );
180         frame1->CreateStatusBar();
181         frame1->Show(TRUE);
182     frame->RefreshInterface();
183         return TRUE;
184 }
185
186 #if(WIN32)
187 int main(int argc, char* argv[])                                        
188   {                                                                     
189     return WinMain(::GetModuleHandle(NULL), NULL,                       
190                    ::GetCommandLine(), SW_SHOWNORMAL);                  
191   }             
192 #else
193 #endif
194