/src/Examples/xgest/HCIWindow.cc

https://bitbucket.org/SRIHARIP/xvision-revised · C++ · 130 lines · 107 code · 10 blank · 13 comment · 8 complexity · f0b67ef22cddd9cc28f82b41efe7316e 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. #define Sqr(a) ((a)*(a))
  15. template class HCIWindow<u_char>;
  16. template class HCIWindow<u_short>;
  17. template class HCIWindow<u_long>;
  18. template <class T>
  19. void HCIWindow<T>::ShowTeach(int x,int y)
  20. {
  21. #ifdef HAVE_LIBXDPMS
  22. Drawable win=(back_flag)? back_buffer : window;
  23. #else
  24. Drawable win=window;
  25. #endif
  26. if(flip)
  27. XDrawRectangle(dpy,win,gc_window[7],width-x-SCALE(112),y,SCALE(112),
  28. SCALE(112));
  29. else
  30. XDrawRectangle(dpy,win,gc_window[7],x,y,SCALE(112),SCALE(112));
  31. }
  32. template <class T>
  33. void HCIWindow<T>::ShowReg(Blob * region,int count,int x,int y,
  34. float angle)
  35. {
  36. int i;
  37. int cur_len,length,index;
  38. #ifdef HAVE_LIBXDPMS
  39. Drawable win=(back_flag)? back_buffer : window;
  40. #else
  41. Drawable win=window;
  42. #endif
  43. for(i=0,index=-1,length=0;i<count;i++)
  44. {
  45. if(region[i].valid>0)
  46. {
  47. cur_len=Sqr(region[i].ex-region[i].sx)+
  48. Sqr(region[i].ey-region[i].sy);
  49. if(cur_len>length) length=cur_len,index=i;
  50. }
  51. }
  52. if(index>-1 && length>Sqr(SCALE(60)))
  53. {
  54. int sx,sy,ex,ey;
  55. length=(int)sqrt(length)/2;
  56. ex=sx=x+(region[index].ex+region[index].sx)/2;
  57. ey=sy=y+(region[index].ey+region[index].sy)/2;
  58. sx+=(int)(0.8*length*sin(angle));
  59. sy+=(int)(0.8*length*cos(angle));
  60. ex-=(int)(0.8*length*sin(angle));
  61. ey-=(int)(0.8*length*cos(angle));
  62. if(flip)
  63. {
  64. XDrawRectangle(dpy,win,(GC)gc_window[0],
  65. width-region[index].ex-x,region[index].sy+y,
  66. region[index].ex-region[index].sx,
  67. region[index].ey-region[index].sy);
  68. XDrawLine(dpy,win,gc_window[0],width-sx,sy,width-ex,ey);
  69. }
  70. else
  71. {
  72. XDrawRectangle(dpy,win,(GC)gc_window[0],
  73. region[index].sx+x,region[index].sy+y,
  74. region[index].ex-region[index].sx,
  75. region[index].ey-region[index].sy);
  76. XDrawLine(dpy,win,gc_window[0],sx,sy,ex,ey);
  77. }
  78. }
  79. else
  80. index=-1;
  81. }
  82. template <class T>
  83. void HCIWindow<T>::draw_object(HCIObject *object)
  84. {
  85. #ifdef HAVE_LIBXDPMS
  86. Drawable draw=(back_flag)? back_buffer : window;
  87. #else
  88. Drawable draw=window;
  89. #endif
  90. switch(object->type)
  91. {
  92. case RECT_OBJECT:
  93. XFillRectangle(dpy,draw,gc_window[object->color],
  94. width-object->posx-object->size1,
  95. object->posy,
  96. object->size1,object->size2);
  97. break;
  98. case CIRC_OBJECT:
  99. XFillArc(dpy,draw,gc_window[object->color],
  100. width-object->posx-object->size1,
  101. object->posy,
  102. object->size1,
  103. object->size2,0,360*64);
  104. break;
  105. default:
  106. break;
  107. }
  108. XDrawRectangle(dpy,draw,gc_window[7],
  109. width-object->posx-3*object->size1/2,
  110. object->posy-object->size2/2,
  111. 2*object->size1, 2*object->size2);
  112. }
  113. template <class T>
  114. HCIWindow<T>::HCIWindow(XVImage<T> *image,int posx,int posy,int event_mask,
  115. char *display,int num_buf,int double_buf):
  116. XVWindow(image,posx,posy,event_mask,display,num_buf,double_buf)
  117. {
  118. }