18 #define SHIFT_CANVAS_ORIGIN 21 #define STATUSTXTLEN 2048 36 "JPEG Image (*.jpg)\n" 38 "TARGA Image (*.tga)\n" 40 "TIFF Image (*.tif)\n" 70 (FXApp::instance()->getRootWindow());
72 mw->setTitle(title.c_str());
79 (FXApp::instance()->getRootWindow());
89 FXVerticalFrame *canvasFrame;
90 FXVerticalFrame *buttonFrame;
91 FXHorizontalFrame *contents;
93 contents=
new FXHorizontalFrame(
this,LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0);
95 canvasFrame=
new FXVerticalFrame(contents,FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT,0,0,0,0,10,10,10,10);
98 glvisual=
new FXGLVisual(getApp(),VISUAL_DOUBLEBUFFER);
101 glcanvas=
new FXGLCanvas(canvasFrame,glvisual,
this,ID_CANVAS,LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT);
104 buttonFrame=
new FXVerticalFrame(contents,FRAME_SUNKEN|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT,0,0,0,0,10,10,10,10);
106 new FXButton(buttonFrame,
"L&oad Image\tSelect Image to load",
NULL,
this, ID_LOAD,FRAME_THICK|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_LEFT,0,0,0,0,10,10,5,5);
112 new FXButton(buttonFrame,
"Edit &Sensors\tEdit the sensor collection",
NULL,
this,ID_EDSENS,FRAME_THICK|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_LEFT,0,0,0,0,10,10,5,5);
115 new FXButton(buttonFrame,
"E&xit\tQuit ImageApp",
NULL,getApp(),FXApp::ID_QUIT,FRAME_THICK|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_LEFT,0,0,0,0,10,10,5,5);
116 FXStatusBar *sbar =
new FXStatusBar(canvasFrame,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X);
117 m_Statusline = sbar->getStatusLine();
123 filename =
"untitled";
131 m_Brain.toggleUpdateForAll();
132 m_BrainStarted =
false;
137 getApp()->removeTimeout(
this,ID_TIMEOUT);
145 FXMainWindow::create();
147 if(filename!=
"untitled"){
148 setStatusText((FXString(
"trying to load: ")+filename).text());
149 if(!m_Brain.load(filename.text())) {
152 }
else if(!m_Brain.load(
"default.brain"))
154 m_SensorDlg->updateStrings();
157 show(PLACEMENT_SCREEN);
175 if(glcanvas->makeCurrent()){
178 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
179 glDisable(GL_DITHER);
180 glViewport(0,0,glcanvas->getWidth(),glcanvas->getHeight());
181 glcanvas->makeNonCurrent();
196 GLdouble width = glcanvas->getWidth();
197 GLdouble height = glcanvas->getHeight();
201 glcanvas->makeCurrent();
205 glClearColor(0.0,0.0,0.0,1.0);
206 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
208 glMatrixMode(GL_MODELVIEW);
210 glMatrixMode(GL_PROJECTION);
212 if(m_Brain.getData().initialized()) {
213 GLint datwidth = m_Brain.getData().getDim1Size();
214 GLint datheight = m_Brain.getData().getDim2Size();
217 GLfloat xscale = ((float)width)/datwidth;
218 GLfloat yscale = ((float)height)/datheight;
219 m_XYScale = xscale<yscale?xscale:yscale;
220 GLfloat swidth = width/m_XYScale;
221 GLfloat sheight = height/m_XYScale;
225 glEnable(GL_TEXTURE_2D);
226 glColor3f(1.f, 1.f, 1.f);
227 if(m_ScreenImg.getSize()) {
228 if(m_RefreshScreenImg || !m_GLScreenImg) {
229 m_GLScreenImg.setImage(m_ScreenImg);
230 m_RefreshScreenImg =
false;
232 m_GLScreenImg.draw(0,0);
235 m_Brain.getData().draw(0,0);
236 glDisable(GL_TEXTURE_2D);
239 m_Brain.drawAllModels();
242 if(glvisual->isDoubleBuffer()){
243 glcanvas->swapBuffers();
247 glcanvas->makeNonCurrent();
249 if(m_BrainStarted && m_Brain.isDone()) {
251 m_BrainStarted =
false;
258 glcanvas->makeCurrent();
260 glcanvas->makeNonCurrent();
266 if(m_SensorDlg->shown()) m_SensorDlg->hide();
267 else m_SensorDlg->show();
273 FXFileDialog open(
this,
"Load Image (BMP,GIF,TGA)");
275 open.setDirectory(directory);
276 open.setFilename(filename);
279 filename = open.getFilename();
280 directory = open.getDirectory();
281 m_ScreenImg.setSize(0,0);
282 setStatusText((FXString(
"trying to load: ")+filename).text());
283 if(!m_Brain.loadData(filename.text()))
291 FXEvent*
event=(FXEvent*)ptr;
292 if(target && target->handle(
this,MKUINT(message,SEL_KEYPRESS),ptr))
return 1;
294 _x=m_Brain.getData().getDim1Size();
295 _y=m_Brain.getData().getDim2Size();
298 #ifdef SHIFT_CANVAS_ORIGIN 299 mx-=glcanvas->getX();
300 my-=glcanvas->getY();
302 mx=(int)(mx/m_XYScale);
303 my=(int)(my/m_XYScale);
304 if(event->code>=KEY_F5 && event->code<=KEY_F10)
307 int kid =
event->code - KEY_F5;
309 case 0: sido=0;
break;
310 case 1: sido--;
break;
312 case 3: sido++;
break;
314 sido = selectSensor(sido);
317 if( mx < _x && my < _y ) {
318 int what =
event->code;
319 if(what == KEY_F3) m_BrainStarted = !m_BrainStarted;
320 if(m_Brain.triggerTest(mx, my, what))
return 1;
322 return FXMainWindow::onKeyPress(obj,sel,ptr);
327 vuLock glock(m_Brain.getGeomMutex());
330 if((
int)sensors.size()<=sido) sido=0;
331 if(sido<0) sido=sensors.size()-1;
333 for(SensorCollection::iterator s=sensors.begin();
334 s!=sensors.end();s++,sid--) {
342 m_ScreenImg.setSize(0,0);
351 float imax=ss->getMax();
352 float imin=ss->getMin();
357 m_RefreshScreenImg =
true;
362 sprintf(msg,
"Showing sensor [%s] (min=%.4f max=%.4f).",
363 ss->getID().c_str(),imin,imax);
388 FXEvent *
event=(FXEvent*)ptr;
389 FXint _x, _y, mx, my;
391 Point pofs(glcanvas->getX(), glcanvas->getY());
392 _x=m_Brain.getData().getDim1Size();
393 _y=m_Brain.getData().getDim2Size();
400 mx=(int)(mx/m_XYScale);
401 my=(int)(my/m_XYScale);
402 if( mx < _x && my < _y){
403 m_Brain.triggerTest((
int)(mx),
404 (
int)(my),KEY_Control_L);
411 FXEvent *
event=(FXEvent*)ptr;
412 FXint _x, _y, mx, my;
414 Point pofs(glcanvas->getX(), glcanvas->getY());
415 _x=m_Brain.getData().getDim1Size();
416 _y=m_Brain.getData().getDim2Size();
423 mx=(int)(mx/m_XYScale);
424 my=(int)(my/m_XYScale);
425 if( mx < _x && my < _y){
426 m_Brain.triggerTest((
int)(mx),
434 FXEvent *
event=(FXEvent*)ptr;
435 FXint _x, _y, mx, my;
437 Point pofs(glcanvas->getX(), glcanvas->getY());
438 _x=m_Brain.getData().getDim1Size();
439 _y=m_Brain.getData().getDim2Size();
446 mx=(int)(mx/m_XYScale);
447 my=(int)(my/m_XYScale);
448 if( mx < _x && my < _y){
449 m_Brain.triggerTest((
int)(mx),
465 m_Statusline->setNormalText(msg);
467 m_Statusline->setNormalText(m_Statusline->getNormalText()+FXString(msg));
472 if(argc >= 2) filename=argv[1];
473 if(argc >= 3) savefilename=argv[2];
479 int main(
int argc,
char *argv[]){
481 #ifdef REDIRECT_STDOUT 482 ofstream logfile(
"output.log");
483 cout.rdbuf(logfile.rdbuf());
484 cerr.rdbuf(logfile.rdbuf());
487 FXApp application(
"Deformable Model Segmentation",
"FoxText");
490 application.init(argc,argv);
496 glutInit(&argc,argv);
499 application.create();
502 return application.run();
int selectSensor(int sido)
long onTimeout(FXObject *, FXSelector, void *)
FXbool cmdline(int argc, char **argv)
long onMouseMove(FXObject *, FXSelector, void *)
std::shared_ptr< Sensor > sensor_ptr
long onKeyPress(FXObject *, FXSelector, void *ptr)
Image< T > & convertFrom(const Image< S > &rhs)
long onLoadImage(FXObject *, FXSelector, void *)
long onLeftMouseClick(FXObject *, FXSelector, void *)
long onConfigure(FXObject *, FXSelector, void *)
FXIMPLEMENT(SensorDialog, FXDialogBox, SensorDialogMap, ARRAYNUMBER(SensorDialogMap)) SensorDialog
void setStatusText(const char *msg, bool append=false)
long onRightMouseClick(FXObject *, FXSelector, void *)
long onToggleSensorDlg(FXObject *, FXSelector, void *)
long onKeyRelease(FXObject *, FXSelector, void *ptr)
long onCanvasRepaint(FXObject *, FXSelector, void *)
long onCmdOpenGL(FXObject *, FXSelector, void *)
long onExpose(FXObject *, FXSelector, void *)
Image< T > & unsetNAN(double val=0)