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