1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
6 #include "wxContourGUIExample.h"
7 #include "wxContourMainFrame.h"
8 //#include "OutlineModelManager.h"
9 //#include "wxContourEventHandler.h"
12 #include <creaImageIOWxGimmickDialog.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"
34 //#include "interfMainPanel.h"
37 #if defined(MACOSX) // assume this is OSX
38 # include <sys/param.h>
39 # include <mach-o/dyld.h> // _NSGetExecutablePath : must add -framework CoreFoundation to link line
42 # define PATH_MAX MAXPATHLEN
46 #ifndef PATH_MAX // If not defined yet : do it
47 # define PATH_MAX 2048
59 wxContourMainFrame* wxTheApplication::frame = 0;
60 //----------------------------------------------------------------------------------------------------------------
61 // This macro implements the entry point (main function) for the application
62 //----------------------------------------------------------------------------------------------------------------
67 // http://lists.wxwidgets.org/archive/wx-dev/msg30449.html
68 wxString GetExecutablePath()
74 GetModuleFileName(NULL, buf, 511);
75 slash = strrchr(buf, '\\');
80 #elif defined(__LINUX__)
82 res = readlink("/proc/self/exe", buf, 512);
86 slash = strrchr(buf, '/');
95 return wxString(buf, wxConvUTF8 );
99 //=========================================================================
100 // From http://www.fltk.org/newsgroups.php?gfltk.general+v:22083
102 int get_app_path (char *pname, size_t pathsize)
105 /* Oddly, the readlink(2) man page says no NULL is appended. */
106 /* So you have to do it yourself, based on the return value: */
107 pathsize --; /* Preserve a space to add the trailing NULL */
108 long result = readlink("/proc/self/exe", pname, pathsize);
111 pname[result] = 0; /* add the #@!%ing NULL */
113 if ((access(pname, 0) == 0))
114 return 0; /* file exists, return OK */
115 /*else name doesn't seem to exist, return FAIL (falls
121 long result = GetModuleFileName(NULL, pname, pathsize);
124 /* fix up the dir slashes... */
125 int len = strlen(pname);
127 for (idx = 0; idx < len; idx++)
129 if (pname[idx] == '\\') pname[idx] = '/';
132 for (idx = len-1; idx >=0 ; idx--)
134 if (pname[idx] == '/')
141 if ((access(pname, 0) == 0))
142 return 0; /* file exists, return OK */
143 /*else name doesn't seem to exist, return FAIL (falls
149 char *p = getexecname();
152 /* According to the Sun manpages, getexecname will
153 "normally" return an */
154 /* absolute path - BUT might not... AND that IF it is not,
156 /* getcwd() will "usually" be the correct thing... Urgh!
159 /* check pathname is absolute (begins with a / ???) */
160 if (p[0] == '/') /* assume this means we have an
163 strncpy(pname, p, pathsize);
164 if ((access(pname, 0) == 0))
165 return 0; /* file exists, return OK */
167 else /* if not, prepend getcwd() then check if file
170 getcwd(pname, pathsize);
171 long result = strlen(pname);
172 strncat(pname, "/", (pathsize - result));
174 strncat(pname, p, (pathsize - result));
176 if ((access(pname, 0) == 0))
177 return 0; /* file exists, return OK */
178 /*else name doesn't seem to exist, return FAIL
184 #ifdef MACOSX /* assume this is OSX */
186 from http://www.hmug.org/man/3/NSModule.html
188 extern int _NSGetExecutablePath(char *buf, unsigned long
191 _NSGetExecutablePath copies the path of the executable
192 into the buffer and returns 0 if the path was successfully
193 copied in the provided buffer. If the buffer is not large
194 enough, -1 is returned and the expected buffer size is
195 copied in *bufsize. Note that _NSGetExecutablePath will
196 return "a path" to the executable not a "real path" to the
197 executable. That is the path may be a symbolic link and
198 not the real file. And with deep directories the total
199 bufsize needed could be more than MAXPATHLEN.
203 char *given_path = (char*)malloc(MAXPATHLEN * 2);
204 if (!given_path) return status;
206 uint32_t npathsize = MAXPATHLEN * 2;
207 long result = _NSGetExecutablePath(given_path, &npathsize);
209 { /* OK, we got something - now try and resolve the real path...
211 if (realpath(given_path, pname) != NULL)
213 if ((access(pname, 0) == 0))
214 status = 0; /* file exists, return OK */
221 return -1; /* Path Lookup Failed */
223 //=========================================================================
226 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '\\'
228 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '/'
232 //=========================================================================
233 std::string GetExecutablePath()
236 int err = get_app_path(name, PATH_MAX);
239 printf("Could not determine current executable path ? ");
242 // remove the exe name
244 slash = strrchr(name, CREACONTOUR_VALID_FILE_SEPARATOR_CHAR);
251 //=========================================================================
261 IMPLEMENT_APP( wxTheApplication );
264 wxContourGUIExample :: wxContourGUIExample(const wxString& title, const wxPoint& pos, const wxSize& size)
265 : wxFrame((wxFrame *) NULL, -1, title, pos, size)
272 void wxAppConsole::OnAssert(char const *,int,char const *,char const *)
276 void wxAppConsole::OnAssertFailure(char const *,int,char const *,char const *,char const *)
281 bool wxTheApplication :: OnInit()
288 wxInitAllImageHandlers();
290 int image_type = GIMMICK_3D_IMAGE_SELECTION;
293 creaImageIO::WxGimmickDialog w(0,
295 _T("WxGimmickDialog test"),
302 std::string datadir( GetExecutablePath() ) ;
304 #ifdef MACOSX /* assume this is OSX */
305 datadir=datadir+"/../../..";
308 //vtkImageData* selectedimage=NULL;
309 std::vector<vtkImageData*> images;
310 if(w.GetReturnCode() == wxID_OK){
312 std::vector<std::string> s;
313 w.GetSelectedFiles(s);
314 std::vector<std::string>::iterator i;
315 for (i=s.begin();i!=s.end();++i){
316 std::cout << *i << std::endl;
319 std::cout << "$$$$ "<<std::endl;
320 w.GetSelectedImages(images);
321 //selectedimage = images[0];
322 //crea::VtkBasicSlicer(images.front());
323 //images.front()->Delete();
325 }else if (w.GetReturnCode() == wxID_CANCEL){
326 vtkMetaImageReader *reader = vtkMetaImageReader::New();
327 std::string filename= datadir + "/data/hola.mhd";
328 reader->SetFileName( filename.c_str() );
330 images.push_back(reader->GetOutput());
336 wxFrame* frame1 = new wxFrame(NULL, wxID_ANY, wxT("ROI Application - Evaluation version, 09 Feb 2009 "), wxPoint(400,50), wxSize(800, 600) );
338 //frame = new wxContourMainFrame( frame1, wxID_ANY, wxString(_T("")), wxPoint(50,50), wxSize(800, 600), images );
339 frame = wxContourMainFrame::getInstance(frame1, wxID_ANY, wxString(_T("")), wxPoint(200,50), wxSize(800, 600), images, wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER,datadir );
340 frame1->CreateStatusBar();
342 frame->RefreshInterface();
347 int main(int argc, char* argv[])
349 return WinMain(::GetModuleHandle(NULL), NULL,
350 ::GetCommandLine(), SW_SHOWNORMAL);