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"mb_
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
53 wxContourMainFrame* wxTheApplication::frame = 0;
54 //----------------------------------------------------------------------------------------------------------------
55 // This macro implements the entry point (main function) for the application
56 //----------------------------------------------------------------------------------------------------------------
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 );
98 //=========================================================================
99 // From http://www.fltk.org/newsgroups.php?gfltk.general+v:22083
101 int get_app_path (char *pname, size_t pathsize)
104 /* Oddly, the readlink(2) man page says no NULL is appended. */
105 /* So you have to do it yourself, based on the return value: */
106 pathsize --; /* Preserve a space to add the trailing NULL */
107 long result = readlink("/proc/self/exe", pname, pathsize);
110 pname[result] = 0; /* add the #@!%ing NULL */
112 if ((access(pname, 0) == 0))
113 return 0; /* file exists, return OK */
114 /*else name doesn't seem to exist, return FAIL (falls
120 long result = GetModuleFileName(NULL, pname, pathsize);
123 /* fix up the dir slashes... */
124 int len = strlen(pname);
126 for (idx = 0; idx < len; idx++)
128 if (pname[idx] == '\\') pname[idx] = '/';
131 for (idx = len-1; idx >=0 ; idx--)
133 if (pname[idx] == '/')
140 if ((access(pname, 0) == 0))
141 return 0; /* file exists, return OK */
142 /*else name doesn't seem to exist, return FAIL (falls
148 char *p = getexecname();
151 /* According to the Sun manpages, getexecname will
152 "normally" return an */
153 /* absolute path - BUT might not... AND that IF it is not,
155 /* getcwd() will "usually" be the correct thing... Urgh!
158 /* check pathname is absolute (begins with a / ???) */
159 if (p[0] == '/') /* assume this means we have an
162 strncpy(pname, p, pathsize);
163 if ((access(pname, 0) == 0))
164 return 0; /* file exists, return OK */
166 else /* if not, prepend getcwd() then check if file
169 getcwd(pname, pathsize);
170 long result = strlen(pname);
171 strncat(pname, "/", (pathsize - result));
173 strncat(pname, p, (pathsize - result));
175 if ((access(pname, 0) == 0))
176 return 0; /* file exists, return OK */
177 /*else name doesn't seem to exist, return FAIL
183 #ifdef MACOSX /* assume this is OSX */
185 from http://www.hmug.org/man/3/NSModule.html
187 extern int _NSGetExecutablePath(char *buf, unsigned long
190 _NSGetExecutablePath copies the path of the executable
191 into the buffer and returns 0 if the path was successfully
192 copied in the provided buffer. If the buffer is not large
193 enough, -1 is returned and the expected buffer size is
194 copied in *bufsize. Note that _NSGetExecutablePath will
195 return "a path" to the executable not a "real path" to the
196 executable. That is the path may be a symbolic link and
197 not the real file. And with deep directories the total
198 bufsize needed could be more than MAXPATHLEN.
202 char *given_path = (char*)malloc(MAXPATHLEN * 2);
203 if (!given_path) return status;
205 uint32_t npathsize = MAXPATHLEN * 2;
206 long result = _NSGetExecutablePath(given_path, &npathsize);
208 { /* OK, we got something - now try and resolve the real path...
210 if (realpath(given_path, pname) != NULL)
212 if ((access(pname, 0) == 0))
213 status = 0; /* file exists, return OK */
220 return -1; /* Path Lookup Failed */
222 //=========================================================================
225 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '\\'
227 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '/'
231 //=========================================================================
232 std::string GetExecutablePath()
235 int err = get_app_path(name, PATH_MAX);
238 printf("Could not determine current executable path ? ");
241 // remove the exe name
243 slash = strrchr(name, CREACONTOUR_VALID_FILE_SEPARATOR_CHAR);
250 //=========================================================================
260 IMPLEMENT_APP( wxTheApplication );
263 wxContourGUIExample :: wxContourGUIExample(const wxString& title, const wxPoint& pos, const wxSize& size)
264 : wxFrame((wxFrame *) NULL, -1, title, pos, size)
271 void wxAppConsole::OnAssert(char const *,int,char const *,char const *)
275 void wxAppConsole::OnAssertFailure(char const *,int,char const *,char const *,char const *)
280 bool wxTheApplication :: OnInit()
283 wxInitAllImageHandlers();
285 int image_type = GIMMICK_3D_IMAGE_SELECTION;
288 creaImageIO::WxGimmickDialog w(0,
290 _T("WxGimmickDialog test"),
297 std::string datadir( GetExecutablePath() ) ;
299 #ifdef MACOSX /* assume this is OSX */
300 datadir=datadir+"/../../..";
303 //vtkImageData* selectedimage=NULL;
304 std::vector<vtkImageData*> images;
305 if(w.GetReturnCode() == wxID_OK){
307 std::vector<std::string> s;
308 w.GetSelectedFiles(s);
309 std::vector<std::string>::iterator i;
310 for (i=s.begin();i!=s.end();++i){
311 std::cout << *i << std::endl;
314 std::cout << "$$$$ "<<std::endl;
315 w.GetSelectedImages(images);
316 //selectedimage = images[0];
317 //crea::VtkBasicSlicer(images.front());
318 //images.front()->Delete();
320 }else if (w.GetReturnCode() == wxID_CANCEL){
321 vtkMetaImageReader *reader = vtkMetaImageReader::New();
322 std::string filename= datadir + "/data/hola.mhd";
323 reader->SetFileName( filename.c_str() );
325 images.push_back(reader->GetOutput());
331 wxFrame* frame1 = new wxFrame(NULL, wxID_ANY, wxT("ROI Application - Evaluation version, 09 Feb 2009 "), wxPoint(400,50), wxSize(800, 600) );
333 //frame = new wxContourMainFrame( frame1, wxID_ANY, wxString(_T("")), wxPoint(50,50), wxSize(800, 600), images );
334 frame = wxContourMainFrame::getInstance(frame1, wxID_ANY, wxString(_T("")), wxPoint(200,50), wxSize(800, 600), images, wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER,datadir );
335 frame1->CreateStatusBar();
337 frame->RefreshInterface();
342 int main(int argc, char* argv[])
344 return WinMain(::GetModuleHandle(NULL), NULL,
345 ::GetCommandLine(), SW_SHOWNORMAL);