1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
5 #include "wxContourGUIExample.h"
6 #include "wxContourMainFrame.h"
7 //#include "OutlineModelManager.h"
8 //#include "wxContourEventHandler.h"
10 //#include <creaImageIOWxGimmickDialog.h>
11 #include <creaImageIOWxGimmickReaderDialog.h>
12 #include <creaImageIOSystem.h>
14 #include <creaVtkBasicSlicer.h>
15 //#include "wxContourMainPanel.h"
17 #include "vtkMetaImageReader.h"
19 #include "vtkImageData.h"
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"
31 //#include "interfMainPanel.h"
33 #if defined(MACOSX) // assume this is OSX
34 # include <sys/param.h>
35 # include <mach-o/dyld.h> // _NSGetExecutablePath : must add -framework CoreFoundation to link line
38 # define PATH_MAX MAXPATHLEN
42 #ifndef PATH_MAX // If not defined yet : do it
43 # define PATH_MAX 2048
54 wxContourMainFrame* wxTheApplication::frame = 0;
56 //----------------------------------------------------------------------------------------------------------------
57 // This macro implements the entry point (main function) for the application
58 //----------------------------------------------------------------------------------------------------------------
62 // http://lists.wxwidgets.org/archive/wx-dev/msg30449.html
63 wxString GetExecutablePath()
69 GetModuleFileName(NULL, buf, 511);
70 slash = strrchr(buf, '\\');
75 #elif defined(__LINUX__)
77 res = readlink("/proc/self/exe", buf, 512);
81 slash = strrchr(buf, '/');
90 return wxString(buf, wxConvUTF8 );
94 //=========================================================================
95 // From http://www.fltk.org/newsgroups.php?gfltk.general+v:22083
97 int get_app_path (char *pname, size_t pathsize)
100 /* Oddly, the readlink(2) man page says no NULL is appended. */
101 /* So you have to do it yourself, based on the return value: */
102 pathsize --; /* Preserve a space to add the trailing NULL */
103 long result = readlink("/proc/self/exe", pname, pathsize);
106 pname[result] = 0; /* add the #@!%ing NULL */
108 if ((access(pname, 0) == 0))
109 return 0; /* file exists, return OK */
110 /*else name doesn't seem to exist, return FAIL (falls
116 long result = GetModuleFileName(NULL, pname, pathsize);
119 /* fix up the dir slashes... */
120 int len = strlen(pname);
122 for (idx = 0; idx < len; idx++)
124 if (pname[idx] == '\\') pname[idx] = '/';
127 for (idx = len-1; idx >=0 ; idx--)
129 if (pname[idx] == '/')
136 if ((access(pname, 0) == 0))
137 return 0; /* file exists, return OK */
138 /*else name doesn't seem to exist, return FAIL (falls
144 char *p = getexecname();
147 /* According to the Sun manpages, getexecname will
148 "normally" return an */
149 /* absolute path - BUT might not... AND that IF it is not,
151 /* getcwd() will "usually" be the correct thing... Urgh!
154 /* check pathname is absolute (begins with a / ???) */
155 if (p[0] == '/') /* assume this means we have an
158 strncpy(pname, p, pathsize);
159 if ((access(pname, 0) == 0))
160 return 0; /* file exists, return OK */
162 else /* if not, prepend getcwd() then check if file
165 getcwd(pname, pathsize);
166 long result = strlen(pname);
167 strncat(pname, "/", (pathsize - result));
169 strncat(pname, p, (pathsize - result));
171 if ((access(pname, 0) == 0))
172 return 0; /* file exists, return OK */
173 /*else name doesn't seem to exist, return FAIL
179 #ifdef MACOSX /* assume this is OSX */
181 from http://www.hmug.org/man/3/NSModule.html
183 extern int _NSGetExecutablePath(char *buf, unsigned long
186 _NSGetExecutablePath copies the path of the executable
187 into the buffer and returns 0 if the path was successfully
188 copied in the provided buffer. If the buffer is not large
189 enough, -1 is returned and the expected buffer size is
190 copied in *bufsize. Note that _NSGetExecutablePath will
191 return "a path" to the executable not a "real path" to the
192 executable. That is the path may be a symbolic link and
193 not the real file. And with deep directories the total
194 bufsize needed could be more than MAXPATHLEN.
198 char *given_path = (char*)malloc(MAXPATHLEN * 2);
199 if (!given_path) return status;
201 uint32_t npathsize = MAXPATHLEN * 2;
202 long result = _NSGetExecutablePath(given_path, &npathsize);
204 { /* OK, we got something - now try and resolve the real path...
206 if (realpath(given_path, pname) != NULL)
208 if ((access(pname, 0) == 0))
209 status = 0; /* file exists, return OK */
216 return -1; /* Path Lookup Failed */
218 //=========================================================================
221 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '\\'
223 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '/'
226 //=========================================================================
227 std::string GetExecutablePath()
230 int err = get_app_path(name, PATH_MAX);
233 printf("Could not determine current executable path ? ");
235 // remove the exe name
237 slash = strrchr(name, CREACONTOUR_VALID_FILE_SEPARATOR_CHAR);
245 //=========================================================================
246 //=========================================================================
247 IMPLEMENT_APP( wxTheApplication );
249 wxContourGUIExample :: wxContourGUIExample(const wxString& title, const wxPoint& pos, const wxSize& size)
250 : wxFrame((wxFrame *) NULL, -1, title, pos, size)
256 void wxAppConsole::OnAssert(char const *,int,char const *,char const *)
260 void wxAppConsole::OnAssertFailure(char const *,int,char const *,char const *,char const *)
265 bool wxTheApplication :: OnInit()
267 wxInitAllImageHandlers();
269 int min_image_type = GIMMICK_2D_IMAGE_SELECTION;
270 int max_image_type = GIMMICK_3D_IMAGE_SELECTION;
271 int output_dim = NATIVE;
274 //creaImageIO::WxGimmickDialog w(0,-1,_T("WxGimmickDialog test"),wxDefaultPosition,wxSize(1200,800),max_image_type,threads);
275 creaImageIO::WxGimmickReaderDialog w(0,-1,_T("WxGimmickDialog test"),wxDefaultPosition,wxSize(1200,800),min_image_type,max_image_type,output_dim,threads);
279 //std::string datadir( crea::wx2std(GetExecutablePath()) );
280 std::string datadir( GetExecutablePath() );
283 #ifdef MACOSX /* assume this is OSX */
284 datadir=datadir+"/../../..";
288 std::vector<vtkImageData*> images;
290 if(w.GetReturnCode() == wxID_OK)
292 std::vector<std::string> s;
293 w.GetSelectedFiles(s);
294 std::vector<std::string>::iterator i;
295 for (i=s.begin();i!=s.end();++i)
297 std::cout << *i << std::endl;
299 std::cout << "$$$$ "<<std::endl;
300 //w.GetSelectedImages(images);
301 w.GetSelectedImages(images,output_dim);
303 else if (w.GetReturnCode() == wxID_CANCEL)
305 vtkMetaImageReader *reader = vtkMetaImageReader::New();
306 std::string filename= datadir + "/data/hola.mhd";
307 reader->SetFileName( filename.c_str() );
309 images.push_back(reader->GetOutput());
316 wxFrame* frame1 = new wxFrame(NULL, wxID_ANY, wxT("ROI Application - Evaluation version, 09 Feb 2009 "), wxPoint(400,50), wxSize(800, 600) );
318 //frame = new wxContourMainFrame( frame1, wxID_ANY, wxString(_T("")), wxPoint(50,50), wxSize(800, 600), images );
319 frame = wxContourMainFrame::getInstance(frame1, wxID_ANY, wxString(_T("")), wxPoint(200,50), wxSize(800, 600), images, wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER,datadir );
320 frame1->CreateStatusBar();
322 frame->RefreshInterface();
327 int main(int argc, char* argv[])
329 return WinMain(::GetModuleHandle(NULL), NULL,
330 ::GetCommandLine(), SW_SHOWNORMAL);