]> Creatis software - creaContours.git/blob - appli/wxContourGUIExample/wxContourGUIExample.cxx
#2887 creaContours Feature New Normal - Avoid vtk messages window in Windows
[creaContours.git] / appli / wxContourGUIExample / wxContourGUIExample.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 //----------------------------------------------------------------------------------------------------------------
27 // Class definition include
28 //----------------------------------------------------------------------------------------------------------------
29
30 #include "wxContourGUIExample.h"
31 #include "wxContourMainFrame.h"
32 //#include "OutlineModelManager.h"
33 //#include "wxContourEventHandler.h"
34
35 //#include <creaImageIOWxGimmickDialog.h>
36 //#include <creaImageIOWxGimmickReaderDialog.h>
37 #include <creaImageIOWxSimpleDlg.h>
38
39 #include <creaImageIOSystem.h>
40
41 #include <creaVtkBasicSlicer.h>
42 //#include "wxContourMainPanel.h"
43
44 #include "vtkMetaImageReader.h"
45 #include <map>
46 #include "vtkImageData.h"
47
48 #include "wx/artprov.h"
49 #include <wx/filedlg.h>
50
51
52 /* EED EraseMe
53 //#include "OutlineModelBuilder.h"
54 //#include "ContourThing.h"
55 //#include "AxeThing.h"
56 //#include "ImageSourceThing.h"
57 //#include "ImageSectionThing.h"
58 //#include "SomeEnvironment.h"
59 //#include "ReaderEnvironment.h"
60
61 //#include "interfMainPanel.h"
62
63 #if defined(MACOSX) // assume this is OSX
64 # include <sys/param.h>
65 # include <mach-o/dyld.h> // _NSGetExecutablePath : must add -framework CoreFoundation to link line
66 # include <string.h>
67 # ifndef PATH_MAX
68 #  define PATH_MAX MAXPATHLEN
69 # endif
70 #endif // MACOSX
71 */
72
73 #ifndef PATH_MAX // If not defined yet : do it
74 #  define PATH_MAX 2048
75 #endif
76
77 #if defined(WIN32)
78   #include <direct.h>
79 #else
80    #include <dirent.h>
81 #endif
82
83 #include <stdlib.h>
84
85
86
87 wxContourMainFrame* wxTheApplication::frame = 0;
88
89 //----------------------------------------------------------------------------------------------------------------
90 // This macro implements the entry point (main function) for the application
91 //----------------------------------------------------------------------------------------------------------------
92
93
94
95
96
97
98 //=========================================================================
99 //=========================================================================
100 IMPLEMENT_APP( wxTheApplication );
101 /*
102 wxContourGUIExample :: wxContourGUIExample(const wxString& title, const wxPoint& pos, const wxSize& size)
103 : wxFrame((wxFrame *) NULL, -1, title, pos, size)
104 {
105 }
106 */
107
108 #ifdef _DEBUG
109 void wxAppConsole::OnAssert(char const *,int,char const *,char const *)
110 {
111 }
112
113 void wxAppConsole::OnAssertFailure(char const *,int,char const *,char const *,char const *)
114 {
115 }
116 #endif
117
118
119
120 bool wxTheApplication :: OnInit()
121 {
122         vtkOutputWindowCreaContour *outputWindowCreaContour= vtkOutputWindowCreaContour::New();
123         vtkOutputWindow::SetInstance( outputWindowCreaContour );
124         outputWindowCreaContour->Delete();
125
126         wxString infoImage;
127         wxInitAllImageHandlers();
128
129 //EED01Juin2010 int min_image_type = GIMMICK_2D_IMAGE_SELECTION;
130 //EED01Juin2010 int max_image_type = GIMMICK_3D_IMAGE_SELECTION;
131 //EED01Juin2010 int output_dim = NATIVE;
132 //EED01Juin2010 int threads = 1;
133
134
135 //EED 1Juin2010
136       creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
137       w.ShowModal();
138
139         std::vector<vtkImageData*> images;
140 //EED 1Juin2010
141 //      creaImageIO::WxGimmickReaderDialog w(0,
142 //                                                                              -1,
143 //                                                                              "creaContours_Descriptor.dscp",
144 //                                                                              "creatisContours DB",
145 //                                                                              _T("WxGimmickDialog test"),
146 //                                                                              wxDefaultPosition,wxSize(1200,800)
147 //                                                                              ,min_image_type,
148 //                                                                              max_image_type,
149 //                                                                              output_dim,
150 //                                                                              threads);
151 //      w.ShowModal();
152
153
154 //JCP
155         //std::string datadir(  crea::wx2std(GetExecutablePath()) );
156         std::string datadir(  crea::System::GetExecutablePath() );
157 //JCP
158
159             #ifdef LINUX /* assume this is OSX */
160                    datadir=datadir+"/../share/creaContours";
161             #endif // MACOSX
162
163                 #ifdef MACOSX /* assume this is OSX */
164                         datadir=datadir+"/../../../../share/creaContours";
165                 #endif // MACOSX
166
167
168                 if(w.GetReturnCode() == wxID_OK)
169                 {
170                                 std::vector<std::string> s;
171 //EED 01Juin2010                                w.GetSelectedFiles(s);
172
173
174 //EED                   std::vector<std::string>::iterator i;
175 //                              for (i=s.begin();i!=s.end();++i)
176 //                              {
177 //                                      std::cout << *i << std::endl;
178 //                              }
179 //                              std::cout << "$$$$ "<<std::endl;
180                                 //w.GetSelectedImages(images);
181
182 //EED31mai2010                          w.GetSelectedImages(images,output_dim);
183
184
185 //EED 1Juin2010
186 //                              std::vector<creaImageIO::OutStrGimmick> out;
187 //                              std::vector<std::string> attr;
188 ////                            attr.push_back("D0028_0010");
189 ////                            attr.push_back("D0008_0023");
190 ////                            attr.push_back("D0008_1070");
191 //                              w.getSelected(out, attr,true,"");
192 ////                            std::cout<<out.size()<<std::endl;
193 ////                            crea::VtkBasicSlicer(out.front().img);
194 //                              int size=out.size();
195 //                              int ii;
196 //                              for (ii=0;ii<size;ii++)
197 //                              {
198 //                                      images.push_back(out[ii].img);
199 //                              }
200
201 //EED 1Juin2010
202 //                              printf("EED creaContours wxTheApplication :: OnInit  %d\n", w.getImagesSelected().size() );
203                                 images    = w.getImagesSelected();
204                                 infoImage = w.getInfoImage();
205 //                              printf("EED creaContours wxTheApplication :: OnInit  %d\n", images.size() );
206
207                 }
208                 else if (w.GetReturnCode() == wxID_CANCEL)
209                 {
210                                 vtkMetaImageReader *reader = vtkMetaImageReader::New();
211                                 std::string filename= datadir + "/data/hola.mhd";
212                                 infoImage=_T("DEFAULT-Image:")+crea::std2wx(filename);
213                                 reader->SetFileName( filename.c_str() );
214                                 reader->Update();
215                                 images.push_back(reader->GetOutput());
216                         }
217                         else
218                         {
219                                 return -1;
220                         }
221
222
223         wxFrame* frame1 = new wxFrame(NULL, wxID_ANY, wxT("Creatis- ROI Application- Evaluation version,01 Agost 2010 ")+infoImage, wxPoint(400,50), wxSize(800, 600) );
224
225         //frame = new wxContourMainFrame( frame1, wxID_ANY, wxString(_T("")), wxPoint(50,50), wxSize(800, 600), images );
226         frame = wxContourMainFrame::getInstance(frame1, wxID_ANY, wxString(_T("")), wxPoint(200,50), wxSize(800, 600), images,  wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER,datadir );
227         frame1->CreateStatusBar();
228         frame1->Show(TRUE);
229     frame->RefreshInterface();
230         return TRUE;
231 }
232
233 #if(WIN32)
234 int main(int argc, char* argv[])
235   {
236     return WinMain(::GetModuleHandle(NULL), NULL,
237                    ::GetCommandLine(), SW_SHOWNORMAL);
238   }
239 #else
240 #endif
241