1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
5 #include "wxContourGUIExample.h"
6 #include "wxContourMainFrame.h"
7 //#include "OutlineModelManager.h"
8 //#include "wxContourEventHandler.h"
11 #include <creaImageIOWxGimmickDialog.h>
13 #include <creaVtkBasicSlicer.h>
14 //#include "wxContourMainPanel.h"
16 #include "vtkMetaImageReader.h"
18 #include "vtkImageData.h"
20 #include "wx/artprov.h"
21 #include <wx/filedlg.h>
22 //#include "OutlineModelBuilder.h"
23 //#include "ContourThing.h"
24 //#include "AxeThing.h"
25 //#include "ImageSourceThing.h"
26 //#include "ImageSectionThing.h"
27 //#include "SomeEnvironment.h"
28 //#include "ReaderEnvironment.h"
30 //#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
55 wxContourMainFrame* wxTheApplication::frame = 0;
56 //----------------------------------------------------------------------------------------------------------------
57 // This macro implements the entry point (main function) for the application
58 //----------------------------------------------------------------------------------------------------------------
63 // http://lists.wxwidgets.org/archive/wx-dev/msg30449.html
64 wxString GetExecutablePath()
70 GetModuleFileName(NULL, buf, 511);
71 slash = strrchr(buf, '\\');
76 #elif defined(__LINUX__)
78 res = readlink("/proc/self/exe", buf, 512);
82 slash = strrchr(buf, '/');
91 return wxString(buf, wxConvUTF8 );
95 //=========================================================================
96 // From http://www.fltk.org/newsgroups.php?gfltk.general+v:22083
98 int get_app_path (char *pname, size_t pathsize)
101 /* Oddly, the readlink(2) man page says no NULL is appended. */
102 /* So you have to do it yourself, based on the return value: */
103 pathsize --; /* Preserve a space to add the trailing NULL */
104 long result = readlink("/proc/self/exe", pname, pathsize);
107 pname[result] = 0; /* add the #@!%ing NULL */
109 if ((access(pname, 0) == 0))
110 return 0; /* file exists, return OK */
111 /*else name doesn't seem to exist, return FAIL (falls
117 long result = GetModuleFileName(NULL, pname, pathsize);
120 /* fix up the dir slashes... */
121 int len = strlen(pname);
123 for (idx = 0; idx < len; idx++)
125 if (pname[idx] == '\\') pname[idx] = '/';
128 for (idx = len-1; idx >=0 ; idx--)
130 if (pname[idx] == '/')
137 if ((access(pname, 0) == 0))
138 return 0; /* file exists, return OK */
139 /*else name doesn't seem to exist, return FAIL (falls
145 char *p = getexecname();
148 /* According to the Sun manpages, getexecname will
149 "normally" return an */
150 /* absolute path - BUT might not... AND that IF it is not,
152 /* getcwd() will "usually" be the correct thing... Urgh!
155 /* check pathname is absolute (begins with a / ???) */
156 if (p[0] == '/') /* assume this means we have an
159 strncpy(pname, p, pathsize);
160 if ((access(pname, 0) == 0))
161 return 0; /* file exists, return OK */
163 else /* if not, prepend getcwd() then check if file
166 getcwd(pname, pathsize);
167 long result = strlen(pname);
168 strncat(pname, "/", (pathsize - result));
170 strncat(pname, p, (pathsize - result));
172 if ((access(pname, 0) == 0))
173 return 0; /* file exists, return OK */
174 /*else name doesn't seem to exist, return FAIL
180 #ifdef MACOSX /* assume this is OSX */
182 from http://www.hmug.org/man/3/NSModule.html
184 extern int _NSGetExecutablePath(char *buf, unsigned long
187 _NSGetExecutablePath copies the path of the executable
188 into the buffer and returns 0 if the path was successfully
189 copied in the provided buffer. If the buffer is not large
190 enough, -1 is returned and the expected buffer size is
191 copied in *bufsize. Note that _NSGetExecutablePath will
192 return "a path" to the executable not a "real path" to the
193 executable. That is the path may be a symbolic link and
194 not the real file. And with deep directories the total
195 bufsize needed could be more than MAXPATHLEN.
199 char *given_path = (char*)malloc(MAXPATHLEN * 2);
200 if (!given_path) return status;
202 uint32_t npathsize = MAXPATHLEN * 2;
203 long result = _NSGetExecutablePath(given_path, &npathsize);
205 { /* OK, we got something - now try and resolve the real path...
207 if (realpath(given_path, pname) != NULL)
209 if ((access(pname, 0) == 0))
210 status = 0; /* file exists, return OK */
217 return -1; /* Path Lookup Failed */
219 //=========================================================================
222 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '\\'
224 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '/'
228 //=========================================================================
229 std::string GetExecutablePath()
232 int err = get_app_path(name, PATH_MAX);
235 printf("Could not determine current executable path ? ");
238 // remove the exe name
240 slash = strrchr(name, CREACONTOUR_VALID_FILE_SEPARATOR_CHAR);
247 //=========================================================================
257 IMPLEMENT_APP( wxTheApplication );
260 wxContourGUIExample :: wxContourGUIExample(const wxString& title, const wxPoint& pos, const wxSize& size)
261 : wxFrame((wxFrame *) NULL, -1, title, pos, size)
268 void wxAppConsole::OnAssert(char const *,int,char const *,char const *)
272 void wxAppConsole::OnAssertFailure(char const *,int,char const *,char const *,char const *)
277 bool wxTheApplication :: OnInit()
284 wxInitAllImageHandlers();
286 int image_type = GIMMICK_3D_IMAGE_SELECTION;
289 creaImageIO::WxGimmickDialog w(0,
291 _T("WxGimmickDialog test"),
298 std::string datadir( GetExecutablePath() ) ;
300 #ifdef MACOSX /* assume this is OSX */
301 datadir=datadir+"/../../..";
304 //vtkImageData* selectedimage=NULL;
305 std::vector<vtkImageData*> images;
306 if(w.GetReturnCode() == wxID_OK){
308 std::vector<std::string> s;
309 w.GetSelectedFiles(s);
310 std::vector<std::string>::iterator i;
311 for (i=s.begin();i!=s.end();++i){
312 std::cout << *i << std::endl;
315 std::cout << "$$$$ "<<std::endl;
316 w.GetSelectedImages(images);
317 //selectedimage = images[0];
318 //crea::VtkBasicSlicer(images.front());
319 //images.front()->Delete();
321 }else if (w.GetReturnCode() == wxID_CANCEL){
322 vtkMetaImageReader *reader = vtkMetaImageReader::New();
323 std::string filename= datadir + "/data/hola.mhd";
324 reader->SetFileName( filename.c_str() );
326 images.push_back(reader->GetOutput());
332 wxFrame* frame1 = new wxFrame(NULL, wxID_ANY, wxT("ROI Application - Evaluation version, 09 Feb 2009 "), wxPoint(400,50), wxSize(800, 600) );
334 //frame = new wxContourMainFrame( frame1, wxID_ANY, wxString(_T("")), wxPoint(50,50), wxSize(800, 600), images );
335 frame = wxContourMainFrame::getInstance(frame1, wxID_ANY, wxString(_T("")), wxPoint(200,50), wxSize(800, 600), images, wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER,datadir );
336 frame1->CreateStatusBar();
338 frame->RefreshInterface();
343 int main(int argc, char* argv[])
345 return WinMain(::GetModuleHandle(NULL), NULL,
346 ::GetCommandLine(), SW_SHOWNORMAL);