39 "JPEG Image",
"*.jpg",
41 "TARGA Image",
"*.tga",
43 "TIFF Image",
"*.tif",
63 FXString savefilename;
78 FXStatusLine *m_Statusline;
85 long onCanvasRepaint(FXObject*,FXSelector,
void*);
86 long onLeftMouseClick(FXObject*,FXSelector,
void*);
87 long onRightMouseClick(FXObject*,FXSelector,
void*);
88 long onKeyPress(FXObject*,FXSelector,
void* ptr);
89 long onKeyRelease(FXObject*,FXSelector,
void* ptr);
90 long onCmdRestore(FXObject*,FXSelector,
void*);
91 long onLoadImage(FXObject*,FXSelector,
void*);
92 long onMouseDown(FXObject*,FXSelector,
void*);
93 long onMouseUp(FXObject*,FXSelector,
void*);
94 long onMouseMove(FXObject*,FXSelector,
void*);
95 long onExpose(FXObject*,FXSelector,
void*);
96 long onConfigure(FXObject*,FXSelector,
void*);
97 long onCmdOpenGL(FXObject*,FXSelector,
void*);
101 void changeSpecies(
const Species &s);
108 ID_CANVAS=FXMainWindow::ID_LAST,
121 virtual void create();
124 FXbool cmdline(
int argc,
char ** argv);
157 (FXApp::instance()->getMainWindow());
167 (FXApp::instance()->getMainWindow());
176 FXVerticalFrame *canvasFrame;
177 FXVerticalFrame *buttonFrame;
178 FXHorizontalFrame *contents;
180 contents=
new FXHorizontalFrame(
this,LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0);
182 canvasFrame=
new FXVerticalFrame(contents,FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT,0,0,0,0,10,10,10,10);
185 glvisual=
new FXGLVisual(getApp(),VISUAL_DOUBLEBUFFER);
188 glcanvas=
new FXGLCanvas(canvasFrame,glvisual,
this,
ID_CANVAS,LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT);
191 buttonFrame=
new FXVerticalFrame(contents,FRAME_SUNKEN|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT,0,0,0,0,10,10,10,10);
193 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);
200 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);
201 FXStatusbar *sbar =
new FXStatusbar(canvasFrame,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X);
202 m_Statusline = sbar->getStatusline();
205 picture=
new FXBMPImage(getApp(),
"test.rgb",IMAGE_SHMI|IMAGE_SHMP,850,600);
208 font=
new FXFont(getApp(),
"times",36,FONTWEIGHT_BOLD);
213 filename =
"untitled";
236 FXMainWindow::create();
254 if(!m_Selector.
load(
"kinds.list"))
260 if(filename!=
"untitled"){
261 setStatusText((FXString(
"trying to load: ")+filename).text());
262 if(!m_DB.
load(filename.text())) {
267 cout <<
"dir: " << directory.text() << endl;
272 show(PLACEMENT_SCREEN);
280 cerr <<
"onCanvasRepaint: ..."<<endl;
282 FXDCWindow dc(glcanvas);
285 dc.setForeground(FXRGB(0,255,0));
286 dc.drawLine(10,10,100,100);
293 if(glcanvas->makeCurrent()){
294 glViewport(0,0,glcanvas->getWidth(),glcanvas->getHeight());
295 glcanvas->makeNonCurrent();
310 GLdouble width = glcanvas->getWidth();
311 GLdouble height = glcanvas->getHeight();
315 glcanvas->makeCurrent();
317 glViewport(0,0,glcanvas->getWidth(),glcanvas->getHeight());
319 glClearColor(0.0,0.0,0.0,1.0);
320 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
322 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
323 glEnable(GL_LINE_SMOOTH);
324 glDisable(GL_DITHER);
326 glMatrixMode(GL_MODELVIEW);
328 glMatrixMode(GL_PROJECTION);
333 glPixelStorei(GL_UNPACK_ROW_LENGTH, datwidth);
334 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
335 GLfloat xscale = ((float)width)/datwidth;
336 GLfloat yscale = ((float)height)/datheight;
337 m_XYScale = xscale<yscale?xscale:yscale;
338 GLfloat swidth = width/m_XYScale;
339 GLfloat sheight = height/m_XYScale;
346 m_Data.
draw(0,datheight,m_XYScale,m_XYScale);
350 if(glvisual->isDoubleBuffer()){
351 glcanvas->swapBuffers();
355 glcanvas->makeNonCurrent();
362 glcanvas->makeCurrent();
364 glcanvas->makeNonCurrent();
371 FXFileDialog open(
this,
"Load Database (DAT)");
373 open.setDirectory(directory);
374 open.setFilename(filename);
377 filename = open.getFilename();
378 directory = open.getDirectory();
380 setStatusText((FXString(
"trying to load: ")+filename).text());
381 if(!m_DB.
load(filename.text())) {
395 if(!m_Data.
load((directory+
"\\"+m_CSpecies[
"image"].c_str()).text()))
397 cout <<
"Error loading image " 398 << (directory+
"\\"+m_CSpecies[
"image"].c_str()).text() << endl;
400 string msg =
"species_id: ";
405 msg += m_CSpecies[
"species_id"] +
" image: " + m_CSpecies[
"image"]
407 +
" scale (pixels per mm): "+number;
409 setTitle(m_CSpecies[
"name"].c_str());
416 FXEvent*
event=(FXEvent*)ptr;
417 if(target && target->handle(
this,MKUINT(message,SEL_KEYPRESS),ptr))
return 1;
424 mx-=glcanvas->getX();
425 my-=glcanvas->getY();
427 mx=(int)(mx/m_XYScale);
428 my=(int)(my/m_XYScale);
430 switch(event->code) {
450 if(!walkdir) walkdir=1;
464 case KEY_F1:
case KEY_F2:
case KEY_F3:
case KEY_F4:
case KEY_F5:
465 case KEY_F6:
case KEY_F7:
case KEY_F8:
case KEY_F9:
467 static const int nct[9] = {1,2,3,4,5,10,30,50,100};
468 int nc = nct[
event->code-KEY_F1];
469 cout <<
"computing " << nc <<
" nearest colours." << endl;
485 for(i=0; i<size; i++)
498 cout <<
"computing chrominance." << endl;
504 vector<float> c(m_Data.
getMValue(i,height-j-1));
508 float g = (c[0]+c[1]+c[2])/3.0f;
509 float R = fabs(g-c[1])+
abs(g-c[2]);
510 float G = fabs(g-c[2])+
abs(g-c[0]);
511 float B = fabs(g-c[0])+
abs(g-c[1]);
512 #elif defined(SATURATION) 514 v = max(c[0],max(c[1],c[2]));
515 m = min(c[0],min(c[1],c[2]));
518 G = R = B = (v>0)?255*(v-m)/v : 0;
530 ofstream os((m_DB.
getDirectory()+
"//species-db.dat").c_str());
584 cout <<
"unit is now " << m_Unit <<
" mm" << endl;
588 cout <<
"unit is now " << m_Unit <<
" mm" << endl;
591 return FXMainWindow::onKeyPress(obj,sel,ptr);
615 FXEvent *
event=(FXEvent*)ptr;
616 FXint _x, _y, mx, my;
618 Point pofs(glcanvas->getX(), glcanvas->getY());
624 mx-=glcanvas->getX();
625 my-=glcanvas->getY();
627 mx=(int)(mx/m_XYScale);
628 my=(int)(my/m_XYScale);
629 if( mx < _x && my < _y){
630 cout <<
"doing nothing at " << mx <<
" " << my << endl;
637 FXEvent *
event=(FXEvent*)ptr;
638 FXint _x, _y, mx, my;
640 Point pofs(glcanvas->getX(), glcanvas->getY());
646 mx-=glcanvas->getX();
647 my-=glcanvas->getY();
649 mx=(int)(mx/m_XYScale);
650 my=(int)(my/m_XYScale);
651 if( mx < _x && my < _y){
652 cout <<
"doing nothing at " << mx <<
" " << my << endl;
653 static int lastclick = -1;
655 m_DB[m_CSpecies.
id][
"scale"] = (FXString().format(
"%i",
int(
abs(lastclick-mx)/m_Unit))).text();
656 cout << m_DB[m_CSpecies.
id] <<
" for " << m_Unit <<
" mm" << endl;
658 }
else lastclick = mx;
666 m_Statusline->setNormalText(msg);
668 m_Statusline->setNormalText(m_Statusline->getNormalText()+FXString(msg));
673 if(argc >= 2) filename=argv[1];
674 if(argc >= 3) savefilename=argv[2];
680 int main(
int argc,
char *argv[]){
683 FXApp application(
"Deformable Model Segmentation",
"FoxText");
686 application.init(argc,argv);
693 application.create();
696 return application.run();
void iterateClassification(dword maxit=10)
FXbool cmdline(int argc, char **argv)
vector< CElement< D > > m_Classes
bool nextSelector(int walkdir=1, bool wrap=true, dword mincount=1)
const std::string & getDirectory() const
virtual std::vector< float > getMValue(int x, int y) const
get multi-channel value
void changeSpecies(const Species &s)
long onKeyPress(FXObject *, FXSelector, void *ptr)
long onLoadImage(FXObject *, FXSelector, void *)
bool load(const char *filename, dword ppmm=0)
long onLeftMouseClick(FXObject *, FXSelector, void *)
long onConfigure(FXObject *, FXSelector, void *)
bool setTitle(const char *title)
bool load(const char *filename)
FXIMPLEMENT(SensorDialog, FXDialogBox, SensorDialogMap, ARRAYNUMBER(SensorDialogMap)) SensorDialog
bool load(const char *filename)
DMatrix< T > & abs(DMatrix< T > &mat)
void setStatusText(const char *msg, bool append=false)
long onRightMouseClick(FXObject *, FXSelector, void *)
const ByteImage & getImage() const
long onKeyRelease(FXObject *, FXSelector, void *ptr)
int main(int argc, char *argv[])
void draw(float x=0, float y=0, float sx=1.0f, float sy=1.0f) const
long onCanvasRepaint(FXObject *, FXSelector, void *)
long onCmdOpenGL(FXObject *, FXSelector, void *)
void setSize(int nx, int ny)
vector< CElement< D > > m_Elements
std::string getFlagString() const
FXDEFMAP(ImageWindow) ImageWindowMap[]
bool nextSelection(int dir=1, bool wrap=true)
Species & getCurSpecies()
Returns a handle to the currently selected species in the data base.
const FXchar * patterns[]
bool setStatusText(const char *stext)
long onExpose(FXObject *, FXSelector, void *)