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>
12 #include <creaVtkBasicSlicer.h>
13 //#include "wxContourMainPanel.h"
15 #include "vtkMetaImageReader.h"
17 #include "vtkImageData.h"
19 #include "wx/artprov.h"
20 #include <wx/filedlg.h>
21 //#include "OutlineModelBuilder.h"
22 //#include "ContourThing.h"
23 //#include "AxeThing.h"
24 //#include "ImageSourceThing.h"
25 //#include "ImageSectionThing.h"
26 //#include "SomeEnvironment.h"
27 //#include "ReaderEnvironment.h"
29 //#include "interfMainPanel.h"
31 #if defined(MACOSX) // assume this is OSX
32 # include <sys/param.h>
33 # include <mach-o/dyld.h> // _NSGetExecutablePath : must add -framework CoreFoundation to link line
36 # define PATH_MAX MAXPATHLEN
40 #ifndef PATH_MAX // If not defined yet : do it
41 # define PATH_MAX 2048
52 wxContourMainFrame* wxTheApplication::frame = 0;
54 //----------------------------------------------------------------------------------------------------------------
55 // This macro implements the entry point (main function) for the application
56 //----------------------------------------------------------------------------------------------------------------
60 // http://lists.wxwidgets.org/archive/wx-dev/msg30449.html
61 wxString GetExecutablePath()
67 GetModuleFileName(NULL, buf, 511);
68 slash = strrchr(buf, '\\');
73 #elif defined(__LINUX__)
75 res = readlink("/proc/self/exe", buf, 512);
79 slash = strrchr(buf, '/');
88 return wxString(buf, wxConvUTF8 );
92 //=========================================================================
93 // From http://www.fltk.org/newsgroups.php?gfltk.general+v:22083
95 int get_app_path (char *pname, size_t pathsize)
98 /* Oddly, the readlink(2) man page says no NULL is appended. */
99 /* So you have to do it yourself, based on the return value: */
100 pathsize --; /* Preserve a space to add the trailing NULL */
101 long result = readlink("/proc/self/exe", pname, pathsize);
104 pname[result] = 0; /* add the #@!%ing NULL */
106 if ((access(pname, 0) == 0))
107 return 0; /* file exists, return OK */
108 /*else name doesn't seem to exist, return FAIL (falls
114 long result = GetModuleFileName(NULL, pname, pathsize);
117 /* fix up the dir slashes... */
118 int len = strlen(pname);
120 for (idx = 0; idx < len; idx++)
122 if (pname[idx] == '\\') pname[idx] = '/';
125 for (idx = len-1; idx >=0 ; idx--)
127 if (pname[idx] == '/')
134 if ((access(pname, 0) == 0))
135 return 0; /* file exists, return OK */
136 /*else name doesn't seem to exist, return FAIL (falls
142 char *p = getexecname();
145 /* According to the Sun manpages, getexecname will
146 "normally" return an */
147 /* absolute path - BUT might not... AND that IF it is not,
149 /* getcwd() will "usually" be the correct thing... Urgh!
152 /* check pathname is absolute (begins with a / ???) */
153 if (p[0] == '/') /* assume this means we have an
156 strncpy(pname, p, pathsize);
157 if ((access(pname, 0) == 0))
158 return 0; /* file exists, return OK */
160 else /* if not, prepend getcwd() then check if file
163 getcwd(pname, pathsize);
164 long result = strlen(pname);
165 strncat(pname, "/", (pathsize - result));
167 strncat(pname, p, (pathsize - result));
169 if ((access(pname, 0) == 0))
170 return 0; /* file exists, return OK */
171 /*else name doesn't seem to exist, return FAIL
177 #ifdef MACOSX /* assume this is OSX */
179 from http://www.hmug.org/man/3/NSModule.html
181 extern int _NSGetExecutablePath(char *buf, unsigned long
184 _NSGetExecutablePath copies the path of the executable
185 into the buffer and returns 0 if the path was successfully
186 copied in the provided buffer. If the buffer is not large
187 enough, -1 is returned and the expected buffer size is
188 copied in *bufsize. Note that _NSGetExecutablePath will
189 return "a path" to the executable not a "real path" to the
190 executable. That is the path may be a symbolic link and
191 not the real file. And with deep directories the total
192 bufsize needed could be more than MAXPATHLEN.
196 char *given_path = (char*)malloc(MAXPATHLEN * 2);
197 if (!given_path) return status;
199 uint32_t npathsize = MAXPATHLEN * 2;
200 long result = _NSGetExecutablePath(given_path, &npathsize);
202 { /* OK, we got something - now try and resolve the real path...
204 if (realpath(given_path, pname) != NULL)
206 if ((access(pname, 0) == 0))
207 status = 0; /* file exists, return OK */
214 return -1; /* Path Lookup Failed */
216 //=========================================================================
219 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '\\'
221 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '/'
224 //=========================================================================
225 std::string GetExecutablePath()
228 int err = get_app_path(name, PATH_MAX);
231 printf("Could not determine current executable path ? ");
234 // remove the exe name
236 slash = strrchr(name, CREACONTOUR_VALID_FILE_SEPARATOR_CHAR);
244 //=========================================================================
245 //=========================================================================
246 IMPLEMENT_APP( wxTheApplication );
248 wxContourGUIExample :: wxContourGUIExample(const wxString& title, const wxPoint& pos, const wxSize& size)
249 : wxFrame((wxFrame *) NULL, -1, title, pos, size)
255 void wxAppConsole::OnAssert(char const *,int,char const *,char const *)
259 void wxAppConsole::OnAssertFailure(char const *,int,char const *,char const *,char const *)
264 bool wxTheApplication :: OnInit()
266 wxInitAllImageHandlers();
268 int image_type = GIMMICK_3D_IMAGE_SELECTION;
271 creaImageIO::WxGimmickDialog w(0,
273 _T("WxGimmickDialog test"),
280 std::string datadir( GetExecutablePath() ) ;
282 #ifdef MACOSX /* assume this is OSX */
283 datadir=datadir+"/../../..";
286 //vtkImageData* selectedimage=NULL;
287 std::vector<vtkImageData*> images;
288 if(w.GetReturnCode() == wxID_OK){
290 std::vector<std::string> s;
291 w.GetSelectedFiles(s);
292 std::vector<std::string>::iterator i;
293 for (i=s.begin();i!=s.end();++i){
294 std::cout << *i << std::endl;
297 std::cout << "$$$$ "<<std::endl;
298 w.GetSelectedImages(images);
299 //selectedimage = images[0];
300 //crea::VtkBasicSlicer(images.front());
301 //images.front()->Delete();
303 }else if (w.GetReturnCode() == wxID_CANCEL){
304 vtkMetaImageReader *reader = vtkMetaImageReader::New();
305 std::string filename= datadir + "/data/hola.mhd";
306 reader->SetFileName( filename.c_str() );
308 images.push_back(reader->GetOutput());
313 wxFrame* frame1 = new wxFrame(NULL, wxID_ANY, wxT("ROI Application - Evaluation version, 09 Feb 2009 "), wxPoint(400,50), wxSize(800, 600) );
315 //frame = new wxContourMainFrame( frame1, wxID_ANY, wxString(_T("")), wxPoint(50,50), wxSize(800, 600), images );
316 frame = wxContourMainFrame::getInstance(frame1, wxID_ANY, wxString(_T("")), wxPoint(200,50), wxSize(800, 600), images, wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER,datadir );
317 frame1->CreateStatusBar();
319 frame->RefreshInterface();
324 int main(int argc, char* argv[])
326 return WinMain(::GetModuleHandle(NULL), NULL,
327 ::GetCommandLine(), SW_SHOWNORMAL);