/src/Examples/xman/HCIWindow.cc

https://bitbucket.org/SRIHARIP/xvision-revised · C++ · 108 lines · 83 code · 10 blank · 15 comment · 6 complexity · 29a6dedeef1fcfe673aaead62dce2a7d MD5 · raw file

  1. /* -*-c++-*-
  2. Copyright (C) 2000 Gregory D. Hager and Darius Burschka (JHU
  3. Lab for Computational Interaction with Physical Systems (CIPS))
  4. Permission is granted to any individual or institution to use, copy,
  5. modify, and distribute this software, provided that this complete
  6. copyright and permission notice is maintained, intact, in all copies and
  7. supporting documentation. Authors of papers that describe software
  8. systems using this software package are asked to acknowledge such use by
  9. a brief statement in the paper.
  10. We provide this software "as is" without express or implied warranty.
  11. */
  12. #include "config.h"
  13. #include "HCIWindow.h"
  14. #include "XVBlobs.h"
  15. #define Sqr(a) ((a)*(a))
  16. template class HCIWindow<XV_RGB>;
  17. template <class T>
  18. void HCIWindow<T>::ShowTeach(int x,int y)
  19. {
  20. Drawable win=(back_flag)? back_buffer : window;
  21. if(flip)
  22. XDrawRectangle(dpy,win,gc_window[7],width-x-112,y,112,
  23. 112);
  24. else
  25. XDrawRectangle(dpy,win,gc_window[7],x,y,112,112);
  26. }
  27. template <class T>
  28. void HCIWindow<T>::ShowReg(vector<XVRectangleBlob> &regions,
  29. int x,int y,
  30. float angle)
  31. {
  32. int i;
  33. int cur_len,length;
  34. Drawable win=(back_flag)? back_buffer : window;
  35. XVRectangleBlob *found_reg;
  36. length=-1;
  37. for(vector<XVRectangleBlob>::iterator region=regions.begin();
  38. region!=regions.end();region++)
  39. {
  40. cur_len=Sqr(region->Width())+
  41. Sqr(region->Height());
  42. if(cur_len>length) length=cur_len,found_reg=&*region;
  43. }
  44. if(length>Sqr(60))
  45. {
  46. if(flip)
  47. {
  48. XDrawRectangle(dpy,win,(GC)gc_window[12],
  49. width-found_reg->PosX()-found_reg->Width()-x,
  50. found_reg->PosY()+y,
  51. found_reg->Width(), found_reg->Height());
  52. //XDrawLine(dpy,win,gc_window[12],width-sx,sy,width-ex,ey);
  53. }
  54. else
  55. {
  56. XDrawRectangle(dpy,win,(GC)gc_window[12],
  57. found_reg->PosX()+x,found_reg->PosY()+y,
  58. found_reg->Width(),found_reg->Height());
  59. //XDrawLine(dpy,win,gc_window[12],sx,sy,ex,ey);
  60. }
  61. }
  62. }
  63. template <class T>
  64. void HCIWindow<T>::draw_object(HCIObject *object,int catched)
  65. {
  66. Drawable draw=(back_flag)? back_buffer : window;
  67. switch(object->type)
  68. {
  69. case RECT_OBJECT:
  70. XFillRectangle(dpy,draw,gc_window[object->color+catched],
  71. width-object->posx-object->size1,
  72. object->posy,
  73. object->size1,object->size2);
  74. break;
  75. case CIRC_OBJECT:
  76. XFillArc(dpy,draw,gc_window[object->color+catched],
  77. width-object->posx-object->size1,
  78. object->posy,
  79. object->size1,
  80. object->size2,0,360*64);
  81. break;
  82. default:
  83. break;
  84. }
  85. XDrawRectangle(dpy,draw,gc_window[7],
  86. width-object->posx-3*object->size1/2,
  87. object->posy-object->size2/2,
  88. 2*object->size1, 2*object->size2);
  89. }
  90. template <class T>
  91. HCIWindow<T>::HCIWindow(XVImageRGB<T> &image,int posx,int posy,
  92. char *title,int event_mask,char *display,int num_buf,
  93. int double_buf):
  94. XVWindowX<T>(image,posx,posy,title,event_mask,display,num_buf,double_buf)
  95. {
  96. }