msSys.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*******************************************************
  2. Mean Shift Analysis Library
  3. =============================================
  4. The mean shift library is a collection of routines
  5. that use the mean shift algorithm. Using this algorithm,
  6. the necessary output will be generated needed
  7. to analyze a given input set of data.
  8. Mean Shift System:
  9. ==================
  10. The Mean Shift System class provides a mechanism for the
  11. mean shift library classes to prompt progress and to
  12. time its computations. When porting the mean shift library
  13. to an application the methods of this class may be changed
  14. such that the output of the mean shift class prompts
  15. will be given to whatever hardware or software device that
  16. is desired.
  17. The definition for the mean shift system class is provided
  18. below. Its prototype is provided in "msSys.cc".
  19. The theory is described in the papers:
  20. D. Comaniciu, P. Meer: Mean Shift: A robust approach toward feature
  21. space analysis.
  22. C. Christoudias, B. Georgescu, P. Meer: Synergism in low level vision.
  23. and they are is available at:
  24. http://www.caip.rutgers.edu/riul/research/papers/
  25. Implemented by Chris M. Christoudias, Bogdan Georgescu
  26. ********************************************************/
  27. //include the msSystem class prototype
  28. #include "msSys.h"
  29. //include needed system libraries
  30. #include <time.h>
  31. #include <stdio.h>
  32. #include <stdarg.h>
  33. #include <stdlib.h>
  34. /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
  35. /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
  36. /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ PUBLIC METHODS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
  37. /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
  38. /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
  39. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  40. /*** Class Constructor and Destructor ***/
  41. /*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
  42. /*******************************************************/
  43. /*Class Constructor */
  44. /*******************************************************/
  45. /*Constructs a mean shift system object. */
  46. /*******************************************************/
  47. /*Post: */
  48. /* - an msSystem object has been properly init- */
  49. /* ialized. */
  50. /*******************************************************/
  51. msSystem::msSystem( void )
  52. {
  53. //initialize currentTime
  54. currentTime = clock();
  55. //done.
  56. }
  57. /*******************************************************/
  58. /*Class Destructor */
  59. /*******************************************************/
  60. /*Destroys a mean shift system object. */
  61. /*******************************************************/
  62. /*Post: */
  63. /* - an msSystem object has been properly dest- */
  64. /* royed. */
  65. /*******************************************************/
  66. msSystem::~msSystem( void )
  67. {
  68. /* do nothing */
  69. }
  70. /*/\/\/\/\/\/\/\/\/\*/
  71. /*** System Timer ***/
  72. /*\/\/\/\/\/\/\/\/\/*/
  73. /*******************************************************/
  74. /*Start Timer */
  75. /*******************************************************/
  76. /*Sets the mean shift system time to the current */
  77. /*system time. */
  78. /*******************************************************/
  79. /*Post: */
  80. /* - the mean shift system time has been set to */
  81. /* the current system time. */
  82. /*******************************************************/
  83. void msSystem::StartTimer( void )
  84. {
  85. //set msSystem time to system time
  86. currentTime = clock();
  87. //done.
  88. return;
  89. }
  90. /*******************************************************/
  91. /*Elapsed Time */
  92. /*******************************************************/
  93. /*Returns the amount of time in seconds since the */
  94. /*mean shift system time was last set. */
  95. /*******************************************************/
  96. /*Post: */
  97. /* - the amount of time in seconds since the mean */
  98. /* shift system time was last set is returned. */
  99. /*******************************************************/
  100. double msSystem::ElapsedTime( void )
  101. {
  102. //return the amount of time elapsed in seconds
  103. //since the msSystem time was last set...
  104. return ((double) (clock() - currentTime))/(CLOCKS_PER_SEC);
  105. }
  106. /*/\/\/\/\/\/\/\/\/\/\*/
  107. /*** System Output ***/
  108. /*\/\/\/\/\/\/\/\/\/\/*/
  109. /*******************************************************/
  110. /*Prompt */
  111. /*******************************************************/
  112. /*Output a text message to the user. */
  113. /*******************************************************/
  114. /*Pre: */
  115. /* - PromptStr is a string containing delimeters */
  116. /* that is to be output to the user. */
  117. /* - a variable set of arguments is also passed */
  118. /* to this method that are used to replace */
  119. /* the delimeters contained by PromptStr */
  120. /*Post: */
  121. /* - the delimeters of PromptStr have been */
  122. /* replaced accordingly using the variable */
  123. /* set of arguments and the resulting string */
  124. /* has been output to the user. */
  125. /*******************************************************/
  126. //extern void bgLogVar(const char *, va_list);
  127. void msSystem::Prompt(const char *PromptStr, ...)
  128. {
  129. //obtain argument list using ANSI standard...
  130. va_list argList;
  131. va_start(argList, PromptStr);
  132. //print the output string to stderr using
  133. //vfprintf
  134. //bgLogVar(PromptStr, argList);
  135. va_end(argList);
  136. //done.
  137. return;
  138. }
  139. /*******************************************************/
  140. /*Progress */
  141. /*******************************************************/
  142. /*The progress of a specific algorithm of the mean */
  143. /*shift library is output to the user. */
  144. /*******************************************************/
  145. /*Pre: */
  146. /* - percentComplete indicates the percentage */
  147. /* of the algorithm that has executed and is */
  148. /* a floating point number from zero to one */
  149. /*Post: */
  150. /* - the percentComplete has been noted by the */
  151. /* interface (possibly to update a progress */
  152. /* bar). */
  153. /* - if the thread executing the mean shift code */
  154. /* must halt execution msSYS_HALT is returned, */
  155. /* msSYS_OK is returned otherwise */
  156. /*******************************************************/
  157. ///////////////////////////////////////////////////////////////////
  158. //NOTE: This implementation is specific to EDISON. In order
  159. // for one to port the mean shift class to another project
  160. // or program one must re-implement this method.
  161. ///////////////////////////////////////////////////////////////////
  162. //is set by the GUI when the user presses the Cancel button
  163. //on the wxWindows progress modal window; this flag indicates
  164. //to the mean shift library that it is to halt execution.
  165. //This parameter is used and checked in the method
  166. //BgMdiSegmentChild::OnSegment.
  167. //extern bool stop_flag;
  168. bool stop_flag;
  169. //is updated in the msSystem::Progress method and indicates to
  170. //the wxWindows progress modal window the percent complete, such
  171. //that it may update its progress bar accordingly; This parameter
  172. //is used and checked in the method BgMdiSegmentChild::OnSegment.
  173. //extern int percentDone;
  174. int percentDone;
  175. ErrorLevel msSystem::Progress(float percentComplete)
  176. {
  177. percentDone = (int)(percentComplete*100);
  178. //check stop flag and return appropriate system state
  179. ErrorLevel myState = EL_OKAY;
  180. if(stop_flag) myState = EL_HALT;
  181. //done.
  182. return myState;
  183. }
  184. /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
  185. /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
  186. /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ END OF CLASS DEFINITION @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
  187. /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
  188. /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/