123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- #include "Example.h"
- using namespace OBJREC;
- using namespace std;
- using namespace NICE;
- Example::Example()
- {
- weight = 0.0;
- height = 0;
- width = 0;
- x = 0;
- y = 0;
- vec = NULL;
- svec = NULL;
- position = 0;
- }
- Example::~Example ()
- {
- }
- Example::Example ( CachedExample *_ce )
- {
- _ce->getImageSize ( width, height );
- if ( width % 2 == 0 )
- width--;
- if ( height % 2 == 0 )
- height--;
- x = width/2;
- y = height/2;
- ce = _ce;
- vec = NULL;
- svec = NULL;
- weight = 1.0;
- position = 0;
- }
- Example::Example ( CachedExample *_ce,
- int _x,
- int _y,
- double _weight )
- {
- ce = _ce;
- x = _x;
- y = _y;
- width = 0;
- height = 0;
- vec = NULL;
- svec = NULL;
- weight = _weight;
- position = 0;
- }
- Example::Example ( CachedExample *_ce,
- int _x,
- int _y,
- int _width,
- int _height,
- double _weight )
- {
- ce = _ce;
- x = _x;
- y = _y;
- width = _width;
- height = _height;
- assert ( (width > 0) && (height > 0) );
- vec = NULL;
- svec = NULL;
- weight = _weight;
- position = 0;
- }
- Example::Example ( NICE::Vector *_vec,
- double _weight )
- {
- x = y = 0;
- width = height = 0;
- ce = NULL;
- vec = _vec;
- svec = NULL;
- weight = _weight;
- position = 0;
- }
- void Example::clean ()
- {
- if ( ce != NULL )
- {
- delete ce;
- ce = NULL;
- }
- if ( vec != NULL )
- {
- delete vec;
- vec = NULL;
- }
-
- if ( svec != NULL )
- {
- delete svec;
- svec = NULL;
- }
- }
- Example::Example ( const Example &ex)
- {
- copy(ex);
- }
- void Example::copy ( const Example &ex)
- {
- vec = ex.vec;
- svec = ex.svec;
- weight = ex.weight;
- position = ex.position;
- width = ex.width;
- height = ex.height;
- x = ex.x;
- y = ex.y;
- ce = ex.ce;
- scale = ex.scale;
- }
- void Example::restore (istream & is, int format)
- {
- is >> weight;
- is >> x;
- is >> y;
- is >> width;
- is >> height;
- is >> position;
- int tmp;
- is >> tmp;
- if(tmp == 1)
- {
- svec = new SparseVector();
- svec->restore(is);
- }
- else
- svec = NULL;
- is >> tmp;
- if(tmp >= 0 )
- {
- vec = new Vector(tmp);
- for(int i = 0; i < tmp; i++)
- {
- is >> vec[i];
- }
- }
- else
- vec = NULL;
- }
- void Example::store (ostream & os, int format) const
- {
- os << weight << " " << x << " " << y << " " << width << " " << height << " " << position << endl;
- if(svec == NULL)
- os << 0 << endl;
- else
- {
- os << 1 << endl;
- svec->store(os);
- }
-
- if(vec == NULL)
- os << -1 << endl;
- else
- {
- os << vec->size() << endl;
- for(int i = 0; i < (int)vec->size(); i++)
- {
- os << vec[i] << " ";
- }
- }
- }
- void Examples::clean ()
- {
- for ( iterator i = begin(); i != end(); i++ )
- {
- Example & example = i->second;
- example.clean();
- }
- clear();
- }
|