The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mainutil.h

Go to the documentation of this file.
00001 #ifndef __MAINUTIL__H__
00002 #define __MAINUTIL__H__
00003 
00004 #include <utility>
00005 #include <list>
00006 #include <map>
00007 #include <cmath>
00008 
00009 // ================================================================================================
00010 
00011 struct ROISequence {
00012         int numframes;
00013         float beginx, endx, beginy, endy, begins, ends, curx, cury, curs, incrx, incry, incrs;
00014 
00015         ROISequence(float _bx, float _ex, float _by, float _ey, float _bs, float _es, int _n) {
00016                 beginx = _bx;   endx = _ex;
00017                 beginy = _by; endy = _ey;
00018                 begins = _bs; ends = _es;
00019                 numframes = _n;
00020                 curx = _bx; cury = _by; curs = _bs;
00021                 incrx = fabs(endx-beginx)/numframes;
00022                 incry = fabs(endy-beginy)/numframes;
00023                 incrs = fabs(ends-begins)/numframes;
00024         }
00025         
00026         inline void getnext (float &x, float &y, float &s) {
00027                         x = (beginx < endx) ? curx += incrx : curx -= incrx;
00028                         y = (beginy < endy) ? cury += incry : cury -= incry;
00029                         s = (begins < ends) ? curs += incrs : curs -= incrs;
00030         }
00031 };
00032 
00033 // ================================================================================================
00034 
00035 struct Timeline {
00036         int numframes, curframe;
00037         typedef multimap< pair<int, int>, ROISequence> EntryMap;
00038         EntryMap entries;
00039 
00040         Timeline() : numframes(0), curframe(0) {}
00041 
00042         void addEntry(int timept, float bx, float ex, float by, float ey, float bs, float es, int nf) {
00043                 numframes = (numframes>timept+nf) ? numframes : timept + nf;
00044                 entries.insert(EntryMap::value_type(make_pair<int, int>(timept, timept+nf), ROISequence(bx, ex, by, ey, bs, es, nf)));
00045         }
00046 
00047         void getROISequences(int timept, list<ROISequence *> &seq) {
00048                 seq.clear();
00049                 for (EntryMap::iterator pos = entries.begin(); pos != entries.end(); ++pos) {
00050                         pair<int, int> timerange = pos->first;
00051                         ROISequence &ROIs = pos->second;
00052 
00053                         if (timept >= timerange.first && timept < timerange.second)
00054                                 seq.push_back(&ROIs);
00055                 }
00056         }
00057 };
00058 
00059 // ================================================================================================
00060 
00061 /* draw number from normal random distribution */
00062 inline double normal(const double &mean, const double &std)
00063 { 
00064   static const double pii=3.1415927;
00065   static const double r_max=RAND_MAX+1;
00066   return std*sqrt(-2*log((rand()+1)/r_max))*sin(2*pii*rand()/r_max)+mean;
00067 } 
00068 
00069 // ================================================================================================
00070 
00071 inline void drawBack(TIntegral<double> &likratimage, float mean, float var) {
00072         for (int y = 0; y < likratimage.getImHeight(); y++) {
00073                 for (int x = 0; x < likratimage.getImWidth(); x++)
00074                         likratimage.setImPixel(x, y, normal(mean, var));
00075         }
00076 }
00077 
00078 // ================================================================================================
00079 
00080 inline void drawROI(TIntegral<double> &likratimage, TBox<float> &roi, float mean, float var) {
00081         for (int y=roi.y; y < roi.y+roi.size; y++) {
00082                 for (int x=roi.x; x < roi.x+roi.size; x++) {
00083                         if (x > likratimage.getImWidth()-1 || 
00084                                         y > likratimage.getImHeight()-1 ||
00085                                         x < 0 || y < 0)
00086                                 continue;
00087                         likratimage.setImPixel(x, y, normal(mean, var));        
00088                 }
00089         }
00090 }
00091 
00092 // ================================================================================================
00093 
00094 
00095 #endif __MAINUTIL__H__

Generated on Mon Nov 8 17:07:41 2004 for MPT by  doxygen 1.3.9.1