libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo es el conjunto de objetos y funciones, que permiten ejecutar las operaciones básicas de la plataforma Moldeo, y que compone su núcleo.
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Amigas 'defines' Grupos Páginas
moFilterManager.cpp
Ir a la documentación de este archivo.
1 /*******************************************************************************
2 
3  moFilterManager.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28 
29 *******************************************************************************/
30 
31 #include "moFilterManager.h"
32 
33 #include "moArray.h"
34 #ifdef USE_TUIO
35 moDefineDynamicArray( moTuioCursorArray )
36 moDefineDynamicArray( moTuioObjectArray )
37 #endif
38 moDefineDynamicArray( moTrackerFeatureArray )
39 moDefineDynamicArray( moTrackerInstanceRecords );
40 
41 
43  m_Variance = moVector2f(0,0);
44  m_SpeedVariance = moVector2f(0,0);
45  m_AccelerationVariance = moVector2f(0,0);
46 
47  m_BoundingRectangle = moVector4f(0,0,0,0);
48  m_BoundingRectangleAngle = 0.0;
49  m_BlobCandidates = 0;
50 
51  m_AbsoluteSpeedAverage = 0;
52  m_AbsoluteAccelerationAverage = 0;
53  m_AbsoluteTorqueAverage = 0;
54 
55  m_Barycenter = moVector2f(0,0);
56  m_BarycenterMotion = moVector2f(0,0);
57  m_BarycenterAcceleration = moVector2f(0,0);
58 
59 
60  m_Max = moVector2f(0,0);
61  m_Min = moVector2f(0,0);
62 
63  m_nFeatures = 0;
64  m_SurfaceCovered = 0;
65  m_Tick = -1;
66  m_ValidFeatures = 0;
67  m_DeltaValidFeatures = 0;
68 }
69 
71 
72  m_Variance = src.m_Variance;
75 
79 
83 
87 
88 
89  m_Max = src.m_Max;
90  m_Min = src.m_Min;
91 
94  m_Tick = src.m_Tick;
97  return(*this);
98 }
99 
101  m_MaxTime = 60000;
102  m_Granularity = 33;
104 }
105 
107 
108 }
109 
110 void
111 moTrackerSystemHistory::StartRecording( long maxtime, long granularity ) {
112 
113  if ( !m_Timer.Started() ) {
114  m_Timer.Start();
115 
117  m_MaxTime = maxtime;
118 
120  m_Granularity = granularity;
121 
122  m_nRecorded = 0;
123 
125 
126  m_History.Empty();
127 
128  moTrackerInstanceRecord dummyRec;
129 
130  m_History.Init( (int)(m_RecordFactor)+1, dummyRec );
131 
132  MODebug2->Message("Tracker History Started with" + IntToStr(m_History.Count()) + " records in max " + IntToStr(m_MaxTime) + " ms." );
133 
134  } else {
135  m_Timer.Continue();
136  }
137 
138 }
139 
140 void
142  m_Timer.Continue();
143  MODebug2->Message("Tracker History Resumed");
144 }
145 
147  return m_nRecorded;
148 }
149 
150 
151 void
152 moTrackerSystemHistory::Record( moTrackerInstanceRecord& p_InstanceRecord, long p_Tick ) {
153 
154  double rec_pos = 0;
155  MOulong rec_posl = 0;
156 
157  if (m_Timer.Started()) {
158 
159 
160  if ( p_Tick>=0 && p_InstanceRecord.m_Tick<0) p_InstanceRecord.m_Tick = p_Tick;
161  else if ( p_Tick == -1 ) {
162  p_InstanceRecord.m_Tick = m_Timer.Duration();
163  }
164 
165  if ( m_History.Count()==0 ) {
166 
167  m_History.Add( p_InstanceRecord );
168  //MODebug2->Message("Tracker History Record Added at the end.");
169  } else {
170 
171  rec_pos = (double) ( p_InstanceRecord.m_Tick / m_Granularity );
172 
173  rec_posl = (MOulong)rec_pos;
174 
175  if ( rec_posl < m_History.Count() ) {
176  m_History.Set( rec_posl, p_InstanceRecord );
177  m_nRecorded = rec_posl+1;
178  //MODebug2->Message("Tracker History Record Added at "+IntToStr(rec_posl));
179  }
180 
181  }
182  }
183 }
184 
186 
188 
189 }
190 
192 void
194  m_Timer.Pause();
195  MODebug2->Message("Tracker History Recording Paused.");
196 }
197 
198 void
200  m_Timer.Stop();
201  MODebug2->Message("Tracker History Recording Stopped.");
202 }
203 
204 void
206  m_Timer.Stop();
207  m_History.Empty();
208  MODebug2->Message("Tracker History Recording Reset.");
209 }
210 
211 bool
213  MODebug2->Message("moTrackerSystemHistory::SaveToFile > not implemented! argument: " + filename);
214  return false;
215 }
216 
217 bool
219  MODebug2->Message("moTrackerSystemHistory::SaveToXML > not implemented! argument: " + filename);
220  return false;
221 }
222 
225  return m_History[index];
226 }
227 
228 #ifdef USE_TUIO
229 
230 moTUIOSystemData::moTUIOSystemData() {
231 
232  currentFrameTime = TuioTime::getSessionTime().getSeconds();
233  currentFrame = sessionID = maxCursorID = -1;
234  verbose = updateObject = updateCursor = false;
235  lastObjectUpdate = lastCursorUpdate = currentFrameTime.getSeconds();
236 
237  periodic_update = false;
238  full_update = false;
239 }
240 
241 moTUIOSystemData::~moTUIOSystemData() {
242 
243 
244 }
245 
246 TuioObject* moTUIOSystemData::addTuioObject(int f_id, float x, float y, float a) {
247  sessionID++;
248  TuioObject *tobj = new TuioObject(currentFrameTime, sessionID, f_id, x, y, a);
249  objectList.push_back(tobj);
250  updateObject = true;
251 
252  if (verbose)
253  std::cout << "add obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle() << std::endl;
254 
255  return tobj;
256 }
257 
258 void moTUIOSystemData::addExternalTuioObject(TuioObject *tobj) {
259  if (tobj==NULL) return;
260  objectList.push_back(tobj);
261  updateObject = true;
262 
263  if (verbose)
264  std::cout << "add obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle() << std::endl;
265 }
266 
267 void moTUIOSystemData::updateTuioObject(TuioObject *tobj, float x, float y, float a) {
268  if (tobj==NULL) return;
269  if (tobj->getTuioTime()==currentFrameTime) return;
270  tobj->update(currentFrameTime,x,y,a);
271  updateObject = true;
272 
273  if (verbose && tobj->isMoving())
274  std::cout << "set obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle()
275  << " " << tobj->getXSpeed() << " " << tobj->getYSpeed() << " " << tobj->getRotationSpeed() << " " << tobj->getMotionAccel() << " " << tobj->getRotationAccel() << std::endl;
276 }
277 
278 void moTUIOSystemData::updateExternalTuioObject(TuioObject *tobj) {
279  if (tobj==NULL) return;
280  updateObject = true;
281  if (verbose && tobj->isMoving())
282  std::cout << "set obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle()
283  << " " << tobj->getXSpeed() << " " << tobj->getYSpeed() << " " << tobj->getRotationSpeed() << " " << tobj->getMotionAccel() << " " << tobj->getRotationAccel() << std::endl;
284 }
285 
286 void moTUIOSystemData::removeTuioObject(TuioObject *tobj) {
287  if (tobj==NULL) return;
288  objectList.remove(tobj);
289  delete tobj;
290  updateObject = true;
291 
292  if (verbose)
293  std::cout << "del obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ")" << std::endl;
294 }
295 
296 void moTUIOSystemData::removeExternalTuioObject(TuioObject *tobj) {
297  if (tobj==NULL) return;
298  objectList.remove(tobj);
299  updateObject = true;
300 
301  if (verbose)
302  std::cout << "del obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ")" << std::endl;
303 }
304 
305 TuioCursor* moTUIOSystemData::addTuioCursor(float x, float y) {
306  sessionID++;
307 
308  int cursorID = (int)cursorList.size();
309  if (((int)(cursorList.size())<=maxCursorID) && ((int)(freeCursorList.size())>0)) {
310  std::list<TuioCursor*>::iterator closestCursor = freeCursorList.begin();
311 
312  for(std::list<TuioCursor*>::iterator iter = freeCursorList.begin();iter!= freeCursorList.end(); iter++) {
313  if((*iter)->getDistance(x,y)<(*closestCursor)->getDistance(x,y)) closestCursor = iter;
314  }
315 
316  TuioCursor *freeCursor = (*closestCursor);
317  cursorID = (*closestCursor)->getCursorID();
318  freeCursorList.erase(closestCursor);
319  delete freeCursor;
320  } else maxCursorID = cursorID;
321 
322  TuioCursor *tcur = new TuioCursor(currentFrameTime, sessionID, cursorID, x, y);
323  cursorList.push_back(tcur);
324  updateCursor = true;
325 
326  if (verbose)
327  std::cout << "add cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY() << std::endl;
328 
329  return tcur;
330 }
331 
332 void moTUIOSystemData::addExternalTuioCursor(TuioCursor *tcur) {
333  if (tcur==NULL) return;
334  cursorList.push_back(tcur);
335  updateCursor = true;
336 
337  if (verbose)
338  std::cout << "add cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY() << std::endl;
339 }
340 
341 void moTUIOSystemData::updateTuioCursor(TuioCursor *tcur,float x, float y) {
342  if (tcur==NULL) return;
343  if (tcur->getTuioTime()==currentFrameTime) return;
344  tcur->update(currentFrameTime,x,y);
345  updateCursor = true;
346 
347  if (verbose && tcur->isMoving())
348  std::cout << "set cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY()
349  << " " << tcur->getXSpeed() << " " << tcur->getYSpeed() << " " << tcur->getMotionAccel() << " " << std::endl;
350 }
351 
352 void moTUIOSystemData::updateExternalTuioCursor(TuioCursor *tcur) {
353  if (tcur==NULL) return;
354  updateCursor = true;
355  if (verbose && tcur->isMoving())
356  std::cout << "set cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY()
357  << " " << tcur->getXSpeed() << " " << tcur->getYSpeed() << " " << tcur->getMotionAccel() << " " << std::endl;
358 }
359 
360 void moTUIOSystemData::removeTuioCursor(TuioCursor *tcur) {
361  if (tcur==NULL) return;
362  cursorList.remove(tcur);
363  tcur->remove(currentFrameTime);
364  updateCursor = true;
365 
366  if (verbose)
367  std::cout << "del cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ")" << std::endl;
368 
369  if (tcur->getCursorID()==maxCursorID) {
370  maxCursorID = -1;
371  delete tcur;
372 
373  if (cursorList.size()>0) {
374  std::list<TuioCursor*>::iterator clist;
375  for (clist=cursorList.begin(); clist != cursorList.end(); clist++) {
376  int cursorID = (*clist)->getCursorID();
377  if (cursorID>maxCursorID) maxCursorID=cursorID;
378  }
379 
380  freeCursorBuffer.clear();
381  for (std::list<TuioCursor*>::iterator flist=freeCursorList.begin(); flist != freeCursorList.end(); flist++) {
382  TuioCursor *freeCursor = (*flist);
383  if (freeCursor->getCursorID()>maxCursorID) delete freeCursor;
384  else freeCursorBuffer.push_back(freeCursor);
385  }
386  freeCursorList = freeCursorBuffer;
387 
388  } else {
389  for (std::list<TuioCursor*>::iterator flist=freeCursorList.begin(); flist != freeCursorList.end(); flist++) {
390  TuioCursor *freeCursor = (*flist);
391  delete freeCursor;
392  }
393  freeCursorList.clear();
394  }
395  } else if (tcur->getCursorID()<maxCursorID) {
396  freeCursorList.push_back(tcur);
397  }
398 }
399 
400 void moTUIOSystemData::removeExternalTuioCursor(TuioCursor *tcur) {
401  if (tcur==NULL) return;
402  cursorList.remove(tcur);
403  updateCursor = true;
404 
405  if (verbose)
406  std::cout << "del cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ")" << std::endl;
407 }
408 
409 long moTUIOSystemData::getSessionID() {
410  sessionID++;
411  return sessionID;
412 }
413 
414 long moTUIOSystemData::getFrameID() {
415  return currentFrame;
416 }
417 
418 TuioTime moTUIOSystemData::getFrameTime() {
419  return currentFrameTime;
420 }
421 
422 void moTUIOSystemData::initFrame(TuioTime ttime) {
423  currentFrameTime = ttime;
424  currentFrame++;
425 }
426 
427 void moTUIOSystemData::commitFrame() {
428 /*
429  if(updateCursor) {
430  startCursorBundle();
431  for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) {
432 
433  // start a new packet if we exceed the packet capacity
434 
435  if ((oscPacket->Capacity()-oscPacket->Size())<CUR_MESSAGE_SIZE) {
436  sendCursorBundle(currentFrame);
437  startCursorBundle();
438  }
439 
440 
441  TuioCursor *tcur = (*tuioCursor);
442  if ((full_update) || (tcur->getTuioTime()==currentFrameTime)) addCursorMessage(tcur);
443  }
444  //sendCursorBundle(currentFrame);
445  } else if ((!periodic_update) && (lastCursorUpdate<currentFrameTime.getSeconds())) {
446  lastCursorUpdate = currentFrameTime.getSeconds();
447  startCursorBundle();
448  sendCursorBundle(currentFrame);
449  }
450  updateCursor = false;
451 
452  if(updateObject) {
453  startObjectBundle();
454  for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++) {
455 
456  // start a new packet if we exceed the packet capacity
457  if ((oscPacket->Capacity()-oscPacket->Size())<OBJ_MESSAGE_SIZE) {
458  sendObjectBundle(currentFrame);
459  startObjectBundle();
460  }
461 
462  TuioObject *tobj = (*tuioObject);
463  if ((full_update) || (tobj->getTuioTime()==currentFrameTime)) addObjectMessage(tobj);
464  }
465  sendObjectBundle(currentFrame);
466  } else if ((!periodic_update) && (lastObjectUpdate<currentFrameTime.getSeconds())) {
467  lastObjectUpdate = currentFrameTime.getSeconds();
468  startObjectBundle();
469  sendObjectBundle(currentFrame);
470  }
471  */
472  updateCursor = false;
473  updateObject = false;
474 }
475 
476 
477 TuioObject* moTUIOSystemData::getTuioObject(long s_id) {
478  for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++)
479  if((*iter)->getSessionID()==s_id) return (*iter);
480 
481  return NULL;
482 }
483 
484 TuioCursor* moTUIOSystemData::getTuioCursor(long s_id) {
485  for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++)
486  if((*iter)->getSessionID()==s_id) return (*iter);
487 
488  return NULL;
489 }
490 
491 TuioObject* moTUIOSystemData::getClosestTuioObject(float xp, float yp) {
492 
493  TuioObject *closestObject = NULL;
494  float closestDistance = 1.0f;
495 
496  for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++) {
497  float distance = (*iter)->getDistance(xp,yp);
498  if(distance<closestDistance) {
499  closestObject = (*iter);
500  closestDistance = distance;
501  }
502  }
503 
504  return closestObject;
505 }
506 
507 TuioCursor* moTUIOSystemData::getClosestTuioCursor(float xp, float yp) {
508 
509  TuioCursor *closestCursor = NULL;
510  float closestDistance = 1.0f;
511 
512  for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++) {
513  float distance = (*iter)->getDistance(xp,yp);
514  if(distance<closestDistance) {
515  closestCursor = (*iter);
516  closestDistance = distance;
517  }
518  }
519 
520  return closestCursor;
521 }
522 
523 std::list<TuioObject*> moTUIOSystemData::getTuioObjects() {
524  return objectList;
525 }
526 
527 std::list<TuioCursor*> moTUIOSystemData::getTuioCursors() {
528  return cursorList;
529 }
530 
531 std::list<TuioObject*> moTUIOSystemData::getUntouchedObjects() {
532 
533  std::list<TuioObject*> untouched;
534  for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++) {
535  TuioObject *tobj = (*tuioObject);
536  if (tobj->getTuioTime()!=currentFrameTime) untouched.push_back(tobj);
537  }
538  return untouched;
539 }
540 
541 void moTUIOSystemData::stopUntouchedMovingObjects() {
542 
543  std::list<TuioObject*> untouched;
544  for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++) {
545 
546  TuioObject *tobj = (*tuioObject);
547  if ((tobj->getTuioTime()!=currentFrameTime) && (tobj->isMoving())) {
548  tobj->stop(currentFrameTime);
549  updateObject = true;
550  /*if (verbose)
551  std::cout << "set obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle()
552  << " " << tobj->getXSpeed() << " " << tobj->getYSpeed() << " " << tobj->getRotationSpeed() << " " << tobj->getMotionAccel() << " " << tobj->getRotationAccel() << std::endl;
553  */
554  }
555  }
556 }
557 
558 void moTUIOSystemData::removeUntouchedStoppedObjects() {
559 
560  std::list<TuioObject*>::iterator tuioObject = objectList.begin();
561  while (tuioObject!=objectList.end()) {
562  TuioObject *tobj = (*tuioObject);
563  if ((tobj->getTuioTime()!=currentFrameTime) && (!tobj->isMoving())) {
564  removeTuioObject(tobj);
565  tuioObject = objectList.begin();
566  } else tuioObject++;
567  }
568 }
569 
570 
571 std::list<TuioCursor*> moTUIOSystemData::getUntouchedCursors() {
572 
573  std::list<TuioCursor*> untouched;
574  for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) {
575  TuioCursor *tcur = (*tuioCursor);
576  if (tcur->getTuioTime()!=currentFrameTime) untouched.push_back(tcur);
577  }
578  return untouched;
579 }
580 
581 void moTUIOSystemData::stopUntouchedMovingCursors() {
582 
583  std::list<TuioCursor*> untouched;
584  for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) {
585  TuioCursor *tcur = (*tuioCursor);
586  if ((tcur->getTuioTime()!=currentFrameTime) && (tcur->isMoving())) {
587  tcur->stop(currentFrameTime);
588  updateCursor = true;
589  /*
590  if (verbose)
591  std::cout << "set cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY()
592  << " " << tcur->getXSpeed() << " " << tcur->getYSpeed()<< " " << tcur->getMotionAccel() << " " << std::endl;
593  */
594  }
595  }
596 }
597 
598 void moTUIOSystemData::removeUntouchedStoppedCursors() {
599 
600  if (cursorList.size()==0) return;
601  std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin();
602  while (tuioCursor!=cursorList.end()) {
603  TuioCursor *tcur = (*tuioCursor);
604  if ((tcur->getTuioTime()!=currentFrameTime) && (!tcur->isMoving())) {
605  removeTuioCursor(tcur);
606  tuioCursor = cursorList.begin();
607  } else tuioCursor++;
608  }
609 }
610 
611 #endif
612 
613 
614 
615 
616 
617 
618 
620  m_ZoneW = 4;
621  m_ZoneH = 4;
622  m_ZoneCW = 12;
623  m_ZoneCH = 3;
624 
625  _zonewf = (float)(m_ZoneW) - 0.000001;
626  _zonehf = (float)(m_ZoneH) - 0.000001;
627  _zonecwf = (float)(m_ZoneCW) - 0.000001;
628  _zonechf = (float)(m_ZoneCH) - 0.000001;
631  m_PositionMatrix = new int [m_Zones];
632  m_MotionMatrix = new int [m_Zones];
633  m_AccelerationMatrix = new int [m_Zones];
635  m_CircularMotionMatrix = new int [m_ZonesC];
636  m_Features.Init( 0, NULL );
638 
639  m_Distancias = NULL;
640  m_Pares = NULL;
641  nPares = 0;
642  ResetMatrix();
643 }
644 
646  m_ZoneW = ZoneW;
647  m_ZoneH = ZoneH;
648  m_ZoneCW = ZoneW;
649  m_ZoneCH = ZoneH;
650 
651  _zonewf = (float)(m_ZoneW) - 0.000001;
652  _zonehf = (float)(m_ZoneH) - 0.000001;
653  _zonecwf = (float)(m_ZoneCW) - 0.000001;
654  _zonechf = (float)(m_ZoneCH) - 0.000001;
657  m_PositionMatrix = new int [m_Zones];
658  m_MotionMatrix = new int [m_Zones];
659  m_AccelerationMatrix = new int [m_Zones];
661  m_CircularMotionMatrix = new int [m_ZonesC];
662  m_Features.Init( 0, NULL );
664 
665  m_Distancias = NULL;
666  m_Pares = NULL;
667  nPares = 0;
668 
669  ResetMatrix();
670 
671 }
672 
673 moTrackerSystemData::moTrackerSystemData( int ZoneW, int ZoneH, int ZoneCW, int ZoneCH ) {
674  m_ZoneW = ZoneW;
675  m_ZoneH = ZoneH;
676  m_ZoneCW = ZoneCW;
677  m_ZoneCH = ZoneCH;
678 
679  _zonewf = (float)(m_ZoneW) - 0.000001;
680  _zonehf = (float)(m_ZoneH) - 0.000001;
681  _zonecwf = (float)(m_ZoneCW) - 0.000001;
682  _zonechf = (float)(m_ZoneCH) - 0.000001;
685  m_PositionMatrix = new int [m_Zones];
686  m_MotionMatrix = new int [m_Zones];
687  m_AccelerationMatrix = new int [m_Zones];
689  m_CircularMotionMatrix = new int [m_ZonesC];
690  m_Features.Init( 0, NULL );
692 
693  m_Distancias = NULL;
694  m_Pares = NULL;
695  nPares = 0;
696 
697  ResetMatrix();
698 
699 }
700 
702 
703  if (m_PositionMatrix) {
704  delete [] m_PositionMatrix;
705  m_PositionMatrix = NULL;
706  }
707 
708  if (m_MotionMatrix) {
709  delete [] m_MotionMatrix;
710  m_MotionMatrix = NULL;
711  }
712 
714  delete [] m_CircularMotionMatrix;
715  m_CircularMotionMatrix = NULL;
716  }
717 
719  delete [] m_CircularPositionMatrix;
721  }
722 }
723 
724 void moTrackerSystemData::SetMax( float x, float y ) {
726 }
727 
728 void moTrackerSystemData::SetMin( float x, float y ) {
730 }
731 
733  return m_ActualRecord.m_Max;
734 }
735 
737  return m_ActualRecord.m_Min;
738 }
739 
741  return m_Features.Count();
742 }
743 
745  return m_Features.GetRef(i);
746 }
747 
748 moTrackerFeatureArray& moTrackerSystemData::GetFeatures() {
749  return m_Features;
750 }
751 
754 }
755 
758 }
759 
762 }
763 
765  return m_ActualRecord.m_Variance;
766 }
767 
770 }
771 
774 }
775 
778 }
779 
782 }
783 
786 }
787 
789  for(int i=0; i<m_Zones;i++) {
790  m_PositionMatrix[i] = 0;
791  m_MotionMatrix[i] = 0;
792  m_AccelerationMatrix[i] = 0;
793  }
794 
795  for(int i=0; i<m_Zones;i++) {
798  }
799 }
800 
803 int moTrackerSystemData::PositionToZone( float x, float y ) {
804  float i = floor( x * (float) _zonewf );
805  float j = floor( y * (float) _zonehf );
806 
807  int pos = (int)i + ((int)j)*m_ZoneW ;
808 
809  return ( pos );
810 }
811 
815  int j = zone / m_ZoneW;
816  int i = zone - j*m_ZoneW;
817  return moVector2f( (1.0/ (2.0*float(m_ZoneW))) + (float)i / (float) m_ZoneW, (1.0/(2.0*float(m_ZoneH))) + (float)j / (float) m_ZoneH);
818 }
819 
821 int moTrackerSystemData::PositionToZoneC( float x, float y ) {
822 
823  moVector2f PosRePos;
824  float Teta;
825  float Radius;
826  float MaxRadius;
827  moVector2f MaxCuad;
828 
830 
831  if ( PosRePos.X() > 0 && PosRePos.Y() >= 0 ) {
832  Teta = atan( PosRePos.Y() / PosRePos.X() );
833  } else if ( PosRePos.X() > 0 && PosRePos.Y() < 0 ) {
834  Teta = atan( PosRePos.Y() / PosRePos.X() ) + moMathf::TWO_PI;
835  } else if( PosRePos.X() < 0 ) {
836  Teta = atan( PosRePos.Y() / PosRePos.X() ) + moMathf::PI;
837  } else if (PosRePos.X() == 0 && PosRePos.Y() > 0) {
838  Teta = moMathf::PI / 2.0;
839  } else if (PosRePos.X() == 0 && PosRePos.Y() < 0) {
840  Teta = 3.0 * moMathf::PI / 2.0;
841  }
842 
843  Radius = PosRePos.Length();
844 
845  MaxCuad = ( m_ActualRecord.m_Max - m_ActualRecord.m_Min ) ;
846  MaxRadius = fabs( MaxCuad.Length() / 2.0);
847  ( MaxRadius > 0 ) ? MaxRadius = MaxRadius : MaxRadius = 1.5;
848 
849  float i = floor( (Teta / moMathf::TWO_PI ) * (float) _zonecwf );
850  float j = floor( ( Radius / MaxRadius ) * (float) _zonechf );
851 
852  return ( (int)i + ((int)j)*m_ZoneCW );
853 }
854 
857 
858  moVector2f PosRePos;
859  float Teta;
860  float Radius;
861  float MaxRadius;
862  moVector2f MaxCuad;
863 
864  int j = zone / m_ZoneCW;
865  int i = zone - j*m_ZoneCW;
866 
868 
869  MaxCuad = ( m_ActualRecord.m_Max - m_ActualRecord.m_Min ) ;
870  MaxRadius = fabs( MaxCuad.Length() / 2.0 );
871  ( MaxRadius > 0 ) ? MaxRadius = MaxRadius : MaxRadius = 1.5;
872 
873  Teta = ( moMathf::TWO_PI * i ) / _zonecwf - moMathf::TWO_PI / (_zonecwf*2);
874  Radius = ( MaxRadius * (j+1) ) / _zonechf;
875 
876  float x,y;
877 
878  x = Radius * cos ( Teta ) + PosRePos.X();
879  y = Radius * sin ( Teta ) + PosRePos.Y();
880 
881  return moVector2f( x, y);
882 }
883 
884 
885 
886 
887 
888 /*
889 moVector2f& pos
890 */
892 
893 void moTrackerSystemData::SetPositionMatrix( float x, float y, int nfeatures ) {
894  int pos = PositionToZone(x,y);
895  if ( pos >=0 && pos <m_Zones ) {
896  m_PositionMatrix[pos]+=nfeatures;
897  }
898 }
899 
901  int posi = PositionToZone(pos.X(),pos.Y());
902  if ( posi >=0 && posi <m_Zones ) {
903  m_PositionMatrix[posi]+=nfeatures;
904  }
905 }
906 
907 
908 int moTrackerSystemData::GetPositionMatrix( float x, float y ) {
909  int pos = PositionToZone(x,y);
910  if ( pos >=0 && pos <m_Zones ) return m_PositionMatrix[pos];
911  return 0;
912 }
913 
915  int posi = PositionToZone(pos.X(),pos.Y());
916  if ( posi >=0 && posi <m_Zones ) return m_PositionMatrix[posi];
917  return 0;
918 }
919 
920 
922 
923 
924 
925 void moTrackerSystemData::SetMotionMatrix( float x, float y, int nfeatures ) {
926  int pos = PositionToZone(x,y);
927  if ( pos >=0 && pos <m_Zones ) m_MotionMatrix[pos]+=nfeatures;
928 }
929 
930 int moTrackerSystemData::GetMotionMatrix( float x, float y ) {
931  int pos = PositionToZone(x,y);
932  if ( pos >=0 && pos <m_Zones ) return m_MotionMatrix[pos];
933  return 0;
934 }
935 
937  int posi = PositionToZone(pos.X(),pos.Y());
938  if ( posi >=0 && posi <m_Zones ) m_MotionMatrix[posi]+=nfeatures;
939 }
940 
942  int posi = PositionToZone(pos.X(),pos.Y());
943  if ( posi >=0 && posi <m_Zones ) return m_MotionMatrix[posi];
944  return 0;
945 }
946 
947 
948 
950 
951 void moTrackerSystemData::SetAccelerationMatrix( float x, float y, int nfeatures ) {
952  int pos = PositionToZone(x,y);
953  if ( pos >=0 && pos <m_Zones ) m_AccelerationMatrix[pos]+=nfeatures;
954 }
955 
957  int pos = PositionToZone(x,y);
958  if ( pos >=0 && pos <m_Zones ) return m_AccelerationMatrix[pos];
959  return 0;
960 }
961 
963  int posi = PositionToZone(pos.X(),pos.Y());
964  if ( posi >=0 && posi <m_Zones ) m_AccelerationMatrix[posi]+=nfeatures;
965 }
966 
968  int posi = PositionToZone(pos.X(),pos.Y());
969  if ( posi >=0 && posi <m_Zones ) return m_AccelerationMatrix[posi];
970  return 0;
971 }
972 
973 
975 
976 
977 
978 void moTrackerSystemData::SetPositionMatrixC( float x, float y, int nfeatures ) {
979  int pos = PositionToZoneC(x,y);
980  if ( pos >=0 && pos <m_ZonesC ) m_CircularPositionMatrix[pos]+=nfeatures;
981 }
982 
984  int pos = PositionToZoneC(x,y);
985  if ( pos >=0 && pos <m_ZonesC ) return m_CircularPositionMatrix[pos];
986  return 0;
987 }
988 
990  int posi = PositionToZoneC(pos.X(),pos.Y());
991  if ( posi >=0 && posi <m_ZonesC ) return m_CircularPositionMatrix[posi];
992  return 0;
993 }
994 
996  if ( zone >=0 && zone <m_ZonesC ) return m_CircularPositionMatrix[zone];
997  return 0;
998 }
999 
1000 
1001 void moTrackerSystemData::SetMotionMatrixC( float x, float y, int nfeatures ) {
1002  int pos = PositionToZoneC(x,y);
1003  if ( pos >=0 && pos <m_ZonesC ) m_CircularMotionMatrix[pos]+=nfeatures;
1004 }
1005 
1006 int moTrackerSystemData::GetMotionMatrixC( float x, float y ) {
1007  int pos = PositionToZoneC(x,y);
1008  if ( pos >=0 && pos <m_ZonesC ) return m_CircularMotionMatrix[pos];
1009  return 0;
1010 }
1011 
1013  int posi = PositionToZoneC(pos.X(),pos.Y());
1014  if ( posi >=0 && posi <m_ZonesC ) return m_CircularMotionMatrix[posi];
1015  return 0;
1016 }
1018  if ( zone >=0 && zone <m_ZonesC ) return m_CircularMotionMatrix[zone];
1019  return 0;
1020 }
1021 
1022 
1023 
1024 
1025 /*************************
1026 
1027 *
1028  DRAW FEATURES
1029 
1030  values are supposed to be between 0.0 and 1.0
1031  normalized values means:
1032  0.0,0.0 = > pixel ( 0, 0 )
1033  1.0,1.0 = > pixel ( width, height )
1034 
1035 *
1036 
1037 ****************************/
1038 
1039 #include "moDebugManager.h"
1040 
1041 void moTrackerSystemData::DrawFeatures( float w, float h, float offsetx, float offsety ) {
1042 
1043  float x=0.0,y=0.0;
1044  float d = 1.0;
1045 
1046  //m_pResourceManager->GetGuiMan()->DisplayInfoWindow( m_DisplayX , m_DisplayY, m_DisplayW, m_DisplayH, pInfo );
1047 
1048  glColor4f( 1.0, 0.0, 0.0, 1.0 );
1049 
1050 #ifndef OPENGLESV2
1051  glDisable( GL_TEXTURE_2D );
1052  glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
1053  //glEnable( GL_BLEND );
1054  //glBlendFunc (GL_SRC_ALPHA, GL_ONE);
1055  glLineWidth((GLfloat)2.0);
1056  glBegin(GL_QUADS);
1057  glVertex2f((x - 0.5*d)*w, (y - 0.5*d)*h);
1058  glVertex2f((x - 0.5*d)*w, (y + 0.5*d)*h);
1059  glVertex2f((x + 0.5*d)*w, (y + 0.5*d)*h);
1060  glVertex2f((x + 0.5*d)*w, (y - 0.5*d)*h);
1061  glEnd();
1062 
1063  glLineWidth((GLfloat)1.0);
1064  glBegin(GL_LINES);
1065 
1066  glVertex2f( x*w, (y - 0.1*d)*h);
1067  glVertex2f( x*w, (y + 0.1*d)*h);
1068 
1069  //flecha (puntita arriba en el eje Y)
1070  glVertex2f( x*w, (y + 0.1*d)*h);
1071  glVertex2f( (x-0.0008*d)*w, (y + 0.1*d - 0.0008*d)*h);
1072 
1073  glVertex2f((x - 0.1*d)*w, y*d*h);
1074  glVertex2f((x + 0.1*d)*w, y*d*h);
1075 
1076  //flecha (puntita )
1077  glVertex2f((x + 0.1*d)*w, y*d*h);
1078  glVertex2f((x + 0.1*d - 0.0008*d)*w, (y+0.0008)*h);
1079 
1080 
1081  glEnd();
1082 
1083 #endif // OPENGLESV2
1084 
1085  if (GetFeaturesCount()>0) {
1086 
1087  for (int f = 0; f < GetFeaturesCount(); f++)
1088  {
1089 
1090  moTrackerFeature* pF = GetFeature(f);
1091 
1093  if (pF && pF->val>=MO_TRACKER_TRACKED) {
1094  //if (pF) {
1095 
1096  x = (pF->x) - offsetx;
1097  y = (pF->y) - offsety;
1098  float tr_x = (pF->tr_x) - offsetx;
1099  float tr_y = (pF->tr_y) - offsety;
1103  int v = pF->val;
1105 
1106  //MODebug2->Log(moText(" x:")+FloatToStr(pF->x) + moText(" y:")+FloatToStr(pF->y) );
1107 
1108  glBindTexture(GL_TEXTURE_2D,0);
1109  glColor4f(1.0, 0.0, 0.0, 0.15);
1110 
1111  if (v >= MO_TRACKER_TRACKED) glColor4f(0.0, 1.0, 0.0, 1.0);
1112  else if (v == MO_TRACKER_NOT_FOUND) glColor4f(1.0, 0.0, 1.0, 1.0);
1113  else if (v == MO_TRACKER_SMALL_DET) glColor4f(1.0, 0.0, 1.0, 1.0);
1114  else if (v == MO_TRACKER_MAX_ITERATIONS) glColor4f(1.0, 0.0, 1.0, 1.0);
1115  else if (v == MO_TRACKER_OOB) glColor4f(1.0, 0.0, 1.0, 1.0);
1116  else if (v == MO_TRACKER_LARGE_RESIDUE) glColor4f(1.0, 0.0, 1.0, 1.0);
1117 
1118  if ( pF->val>=MO_TRACKER_TRACKED ) {
1119 
1120  if (f==0) {
1121  d = 3.0;
1122  glColor4f(1.0, 0.0, 0.0, 1.0);
1123  }
1124 #ifndef OPENGLESV2
1125  glBegin(GL_QUADS);
1126  glVertex2f((x - 0.008*d)*w, (y - 0.008*d)*h);
1127  glVertex2f((x - 0.008*d)*w, (y + 0.008*d)*h);
1128  glVertex2f((x + 0.008*d)*w, (y + 0.008*d)*h);
1129  glVertex2f((x + 0.008*d)*w, (y - 0.008*d)*h);
1130  glEnd();
1131 #endif
1132 
1133 
1134  glColor4f(1.0, 1.0, 1.0, 1.0);
1135  if (f==0) {
1136  glColor4f(1.0, 0.0, 0.0, 1.0);
1137  }
1138  glBindTexture(GL_TEXTURE_2D,0);
1139  glDisable(GL_TEXTURE_2D);
1140  glLineWidth((GLfloat)1.2);
1141 #ifndef OPENGLESV2
1142 
1143  glBegin(GL_LINES);
1144  glVertex2f( x*w, y*h);
1145  glVertex2f( tr_x*w, tr_y*h);
1146  glEnd();
1147 #endif
1148 
1149  /*if ( vel > 0.001 ) {
1150  glDisable(GL_TEXTURE_2D);
1151  glColor4f(0.0, 0.0, 1.0, 1.0);
1152  //glPointSize((GLfloat)10);
1153  glLineWidth((GLfloat)10.0);
1154  glBegin(GL_LINES);
1155  glVertex2f( x*w, y*h);
1156  glVertex2f( x*w+v_x*w, y*h+v_y*h);
1157  glEnd();
1158  }*/
1159 
1160 
1161  }
1162 
1163 
1164  }
1165 
1166 
1167  /***********************************************************************************
1168  ** UPLAS - JUNTANDO VECINOS
1169  ***********************************************************************************/
1170 /*
1171  float p1x,p1y;
1172  float p2x,p2y;
1173  int k1, k2;
1174  int Uplas[GetFeaturesCount()];
1176  for( int g = 0; g < nPares; g++ ) {
1177  k1 = m_Pares[g][0];
1178  k2 = m_Pares[g][1];
1179  Uplas[k1]++;
1180  Uplas[k2]++;
1181 
1182  p1x = GetFeature(k1)->x - offsetx;
1183  p1y = GetFeature(k1)->y - offsety;
1184 
1185  p2x = GetFeature(k2)->x - offsetx;
1186  p2y = GetFeature(k2)->y - offsety;
1187 
1188 
1189  glColor4f(1.0, 1.0, 1.0, 0.1);
1190  glDisable(GL_TEXTURE_2D);
1191  glLineWidth((GLfloat)1.0);
1192  glBegin(GL_LINES);
1193  glVertex2f( p1x*w, p1y*h);
1194  glVertex2f( p2x*w, p2y*h);
1195  glEnd();
1196 
1197  }
1198 
1199  int myuplas[3];
1200  for( int u=0; u<GetFeaturesCount(); u++) {
1201  if( Uplas[u]>=2) {
1202 
1203  p1x = GetFeature(u)->x - offsetx;
1204  p1y = GetFeature(u)->y - offsety;
1205 
1208  if (Uplas[u]==3) {
1209  int o = 0;
1210  moVector2f aver(p1x,p1y);
1211  for( int pp=0; pp<nPares; pp++) {
1212  k1 = m_Pares[pp][0];
1213  k2 = m_Pares[pp][1];
1214  if (k1==u) myuplas[o++] = k2;
1215  if (k2==u) myuplas[o++] = k1;
1216  }
1217  for(int pp=0;pp<3;pp++) {
1218  aver+= moVector2f( GetFeature(myuplas[pp])->x - offsetx,
1219  GetFeature(myuplas[pp])->y - offsety );
1220  }
1221  aver/=4;
1222  moVector2f aver2;
1223  for(int pp=0;pp<3;pp++) {
1224  aver2 = aver - moVector2f( GetFeature(myuplas[pp])->x - offsetx,
1225  GetFeature(myuplas[pp])->y - offsety );
1226  }
1227 
1228  glColor4f(1.0, 1.0, 0.0, 0.1);
1229  glBegin(GL_QUADS);
1230  glVertex2f((aver.X() - 0.02)*w, (aver.Y() - 0.02)*h);
1231  glVertex2f((aver.X() - 0.02)*w, (aver.Y() + 0.02)*h);
1232  glVertex2f((aver.X() + 0.02)*w, (aver.Y()+ 0.02)*h);
1233  glVertex2f((aver.X() + 0.02)*w, (aver.Y() - 0.02)*h);
1234  glEnd();
1235  }
1236  }
1237  }
1238 
1239 */
1240  /***********************************************************************************
1241  ** VARIANCE - BARYCENTER - ETC
1242  ***********************************************************************************/
1243 
1245 #ifndef OPENGLESV2
1246  glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
1247 #endif
1248  moVector2f m_TrackerBarycenter = moVector2f( GetBarycenter().X() - offsetx,
1249  GetBarycenter().Y() - offsety );
1250  moVector2f m_TrackerMin = moVector2f( GetMin().X() - offsetx,
1251  GetMin().Y() - offsety );
1252  moVector2f m_TrackerMax = moVector2f( GetMax().X() - offsetx,
1253  GetMax().Y() - offsety );
1254 
1255 
1256  glBindTexture(GL_TEXTURE_2D,0);
1257  glDisable(GL_TEXTURE_2D);
1258  glColor4f(1.0, 1.0, 0.0, 1.0); //yellow
1259 
1260  //GL_MAX_TEXTURE_UNITS_ARB
1261  //GL_TEXTURE0_ARB
1262 #ifndef OPENGLESV2
1263  glBegin(GL_QUADS);
1264  //glColor4f(0.7, 1.0, 0.5, 0.2);
1265  glVertex2f((m_TrackerBarycenter.X() - 0.02)*w, (m_TrackerBarycenter.Y() - 0.02)*h);
1266  //glColor4f(0.7, 1.0, 0.5, 0.2);
1267  glVertex2f((m_TrackerBarycenter.X() - 0.02)*w, (m_TrackerBarycenter.Y() + 0.02)*h);
1268  //glColor4f(0.7, 1.0, 0.5, 0.2);
1269  glVertex2f((m_TrackerBarycenter.X() + 0.02)*w, (m_TrackerBarycenter.Y() + 0.02)*h);
1270  //glColor4f(0.7, 1.0, 0.5, 0.2);
1271  glVertex2f((m_TrackerBarycenter.X() + 0.02)*w, (m_TrackerBarycenter.Y() - 0.02)*h);
1272  glEnd();
1273 #endif
1274  moVector2f m_TrackerVariance = moVector2f( GetVariance().X(),
1275  GetVariance().Y());
1276 
1278  glColor4f(0.0, 1.0, 0.0, 1.0);
1279  glLineWidth((GLfloat)1.0);
1280 #ifndef OPENGLESV2
1281  glBegin(GL_QUADS);
1282  //glColor4f(0.7, 1.0, 0.5, 0.5);
1283  glVertex2f( m_TrackerMin.X()*w, m_TrackerMax.Y()*h);
1284  glVertex2f( m_TrackerMax.X()*w, m_TrackerMax.Y()*h);
1285  glVertex2f( m_TrackerMax.X()*w, m_TrackerMin.Y()*h);
1286  glVertex2f( m_TrackerMin.X()*w, m_TrackerMin.Y()*h);
1287  glEnd();
1288 #endif
1289 
1291  glColor4f(0.0, 1.0, 1.0, 1.0);
1292  glLineWidth((GLfloat)1.5);
1293 #ifndef OPENGLESV2
1294  glBegin(GL_QUADS);
1295  glVertex2f( m_TrackerBarycenter.X()*w - m_TrackerVariance.X()*w*5, m_TrackerBarycenter.Y()*h-m_TrackerVariance.Y()*h*5);
1296  glVertex2f( m_TrackerBarycenter.X()*w + m_TrackerVariance.X()*w*5, m_TrackerBarycenter.Y()*h-m_TrackerVariance.Y()*h*5);
1297  glVertex2f( m_TrackerBarycenter.X()*w + m_TrackerVariance.X()*w*5, m_TrackerBarycenter.Y()*h+m_TrackerVariance.Y()*h*5);
1298  glVertex2f( m_TrackerBarycenter.X()*w - m_TrackerVariance.X()*w*5, m_TrackerBarycenter.Y()*h+m_TrackerVariance.Y()*h*5);
1299  glEnd();
1300 #endif
1301  /*
1302  moDebugManager::Push(moText("varianza: vx:")+FloatToStr(m_TrackerVariance.X()*w*10)
1303  +moText(" vy")+FloatToStr(m_TrackerVariance.Y()*h*10) );
1304 */
1305 
1306  /***********************************************************************************
1307  ** ZONES
1308  ***********************************************************************************/
1309 
1310  glEnable( GL_BLEND );
1311  glDisable(GL_TEXTURE_2D);
1312  glBlendFunc (GL_SRC_ALPHA, GL_ONE);
1313 
1314 
1315  moText matrix;
1316  int npz,nmz;
1317  int n = GetValidFeatures();
1318  int z;
1319  float off_w, off_h, off_w_m, off_h_m;
1320  off_w = off_h = 1.0 / 8.0;
1321 
1322  if ( m_ZoneW > 0 ) {
1323  off_w = 1.0 / ( (float)(m_ZoneW)*2.0 );
1324  }
1325  if ( m_ZoneH > 0 ) {
1326  off_h = 1.0 / ( float(m_ZoneH)*2.0 );
1327  }
1328  off_w_m = off_w - off_w/8.0;
1329  off_h_m = off_h - off_h/8.0;
1330 
1333  for(z=0; z<m_Zones; z++) {
1334 
1335  moVector2f poscuad = ZoneToPosition(z);
1336 
1337  npz = GetPositionMatrix( poscuad );
1338  nmz = GetMotionMatrix( poscuad );
1339 
1340  //matrix = matrix + moText(" ")+IntToStr(npz);
1341  poscuad = moVector2f( poscuad.X()-offsetx, poscuad.Y()-offsety);
1342  if ( npz > 0 ) {
1343 #ifndef OPENGLESV2
1344  glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
1345 #endif
1346  //glColor4f( 0.5+0.5*(float)z/(m_Zones-1), 0.5+0.5*(float)z/(m_Zones-1), 0.0, 0.25);
1347  glColor4f(0.5, 0.5, 0.0, 0.002);
1348 #ifndef OPENGLESV2
1349  glBegin(GL_QUADS);
1350  glVertex2f((poscuad.X() - off_w)*w, (poscuad.Y() - off_h)*h);
1351  glVertex2f((poscuad.X() - off_w)*w, (poscuad.Y() + off_h)*h);
1352  glVertex2f((poscuad.X() + off_w)*w, (poscuad.Y() + off_h)*h);
1353  glVertex2f((poscuad.X() + off_w)*w, (poscuad.Y() - off_h)*h);
1354  glEnd();
1355 #endif
1356  }
1357  if ( nmz > 0 ) {
1358 
1360 #ifndef OPENGLESV2
1361  glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
1362 #endif
1363  //glColor4f( 0.0, 0.0, 0.5+0.5*(float)z/(m_Zones-1), 0.25);
1364  glColor4f(0.0, 0.0, 0.5, 0.02);
1365 #ifndef OPENGLESV2
1366  glBegin(GL_QUADS);
1367  glVertex2f((poscuad.X() - off_w_m)*w, (poscuad.Y() - off_h_m)*h);
1368  glVertex2f((poscuad.X() - off_w_m)*w, (poscuad.Y() + off_h_m)*h);
1369  glVertex2f((poscuad.X() + off_w_m)*w, (poscuad.Y() + off_h_m)*h);
1370  glVertex2f((poscuad.X() + off_w_m)*w, (poscuad.Y() - off_h_m)*h);
1371  glEnd();
1372 #endif
1373 
1374  }
1375  }
1376 
1378 #ifndef OPENGLESV2
1379  glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
1380 #endif
1381  if (n>0)
1382  for(int cc=0; cc < m_ZonesC; cc++) {
1383 
1384  moVector2f poscuadC = ZoneToPositionC(cc);
1385  moVector2f p2,p3,p4;
1386  if (((cc+1)%m_ZoneCW)==0) { p2 = ZoneToPositionC( cc - m_ZoneCW -1); }
1387  else { p2 = ZoneToPositionC( cc + 1 ); }
1388 
1389  if (cc<12) {
1390  p3 = GetBarycenter();
1391  p4 = GetBarycenter();
1392  }
1393  else {
1394  if (((cc+1)%m_ZoneCW)==0) { p3 = ZoneToPositionC( cc - m_ZoneCW -1 - m_ZoneCW); }
1395  else { p3 = ZoneToPositionC( cc + 1 - m_ZoneCW); }
1396  p4 = ZoneToPositionC( cc - m_ZoneCW );
1397 
1398  }
1399 
1400  npz = GetPositionMatrixC( cc );
1401  nmz = GetMotionMatrixC( cc );
1402 
1403  //matrix = matrix + moText(" ")+IntToStr(npz);
1404  poscuadC = moVector2f( poscuadC.X()-offsetx, poscuadC.Y()-offsety);
1405  p2 = moVector2f( p2.X()-offsetx, p2.Y()-offsety );
1406  p3 = moVector2f( p3.X()-offsetx, p3.Y()-offsety );
1407  p4 = moVector2f( p4.X()-offsetx, p4.Y()-offsety );
1408  if ( npz == 0 ) {
1409  glColor4f( 0.3+0.2*(float)cc/(m_ZonesC-1), 0.3+0.2*(float)cc/(m_ZonesC-1), 0.2, 0.0015);
1410 #ifndef OPENGLESV2
1411  glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
1412 #endif
1413  } else {
1414  glColor4f( 0.7+0.3*(float)cc/(m_ZonesC-1), 0.0, 0.0, 0.0025);
1415 #ifndef OPENGLESV2
1416  glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
1417 #endif
1418  }
1419 
1420 
1421  //moVector2f p3 = m_pTrackerData->ZoneToPositionC( cc + 1 + 12 );
1422  //moVector2f p4 = m_pTrackerData->ZoneToPositionC( cc + 12 );
1423 #ifndef OPENGLESV2
1424  glBegin(GL_QUADS);
1425  glVertex2f( poscuadC.X()*w, poscuadC.Y()*h);
1426  glVertex2f( p2.X()*w, p2.Y()*h);
1427  glVertex2f( p3.X()*w, p3.Y()*h);
1428  glVertex2f( p4.X()*w, p4.Y()*h);
1429  //glVertex2f( p3.X()*w, p3.Y()*h);
1430  //glVertex2f( p4.X()*w, p4.Y()*h);
1431  glEnd();
1432 #endif
1433 
1434  //}
1435  if ( nmz > 0 ) {
1436  glColor4f( 0.0, 0.0, 0.5+0.5*(float)cc/(m_ZonesC-1), 0.0025);
1437 
1438  }
1439  }
1440 
1441  //MODebug2->Push(moText("N:")+(moText)IntToStr(m_pTrackerData->GetValidFeatures())+moText("matrix: vx:")+(moText)matrix);
1442 
1443  }
1444 
1445  }
1446 
1447  #ifndef OPENGLESV2
1448  glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
1449  #endif
1450 
1451 }
1452 
1458 {
1459  x = -1; y = -1; valid = false;
1460  track.Empty();
1461  is_object = false;
1462  is_parent = false;
1463  is_cursor = false;
1464  stime = 0;
1465  sframe = 0;
1466  utime = 0;
1467  uframe = 0;
1468  Parent = NULL;
1469 }
1470 
1471 
1473 {
1474 }
1475 
1476 
1478 
1479  x = src.x;
1480  y = src.y;
1481 
1482  normx = src.normx;
1483  normy = src.normy;
1484 
1485  tr_x = src.tr_x;
1486  tr_y = src.tr_y;
1487 
1488  v_x = src.v_x;
1489  v_y = src.v_y;
1490  vp_x = src.vp_x;
1491  vp_y = src.vp_y;
1492  a_x = src.a_x;
1493  a_y = src.a_y;
1494  ap_x = src.ap_x;
1495  ap_y = src.ap_y;
1496  t_x = src.t_x;
1497  t_y = src.t_y;
1498 
1499  val = src.val;
1500  valid = src.valid;
1501 
1502  track = src.track;
1503 
1505  Parent = src.Parent;
1506 
1507  is_object = src.is_object;
1508  is_parent = src.is_parent;
1509  is_cursor = src.is_cursor;
1510  stime = src.stime;
1511  sframe = src.sframe;
1512  utime = src.utime;
1513  uframe = src.uframe;
1514  return (*this);
1515 }
1516 
1522 {
1523  printf("Pos:\t%10.5f,%10.5f\t(%7.2f,%7.2f)\n",normx,normy,x,y);
1524 }
1525 
1531 {
1532  MOuint n = track.Count();
1533 
1534  if (n==0)
1535  printf("(%7.2f,%7.2f)\n", x, y);
1536  else
1537  printf("(%7.2f,%7.2f) -> (%7.2f,%7.2f)\n", track[n-1]->X(), track[n-1]->Y(), x, y);
1538 }
1539 
1540 
1541 
1546 int moTrackerFeature::updatePos(float kltConvergeThreshold, float kltSSDthresh, int kltborder, float delta, float res, float d1, float d2, float w, float h)
1547 {
1548 
1549  kltConvergeThreshold = 0.0;
1550  delta = 0.0;
1551 
1552  double delx, dely;
1553  bool discardFlag;
1554 
1555  if (res > kltSSDthresh)
1556  discardFlag = true;
1557  else if (d1 < 0.0 && d2 < 0.0)
1558  discardFlag = true;
1559  else
1560  {
1561  moVector2f * pt = new moVector2f(x,y);
1562  track.Add(pt);
1563 
1564  delx = normx - d1;
1565  dely = normy - d2;
1566  normx = normx - delx;
1567  normy = normy - dely;
1568  x = normx * w;
1569  y = normy * h;
1570 
1571  if ( (x < kltborder) || (x > (w - kltborder)) || (y < kltborder) || (y > (h - kltborder)) )
1572  discardFlag = true;
1573  else
1574  discardFlag = false;
1575  }
1576 
1577  if (discardFlag)
1578  {
1579 
1580  //for (int j=0;j<track.size();j++)
1581  // delete track[j];
1582  track.Empty();
1583  valid = false;
1584  return -1;
1585  }
1586  else
1587  return 1;
1588 }
1589 
1590 
1591 //===========================================
1592 //
1593 // moFilter
1594 //
1595 //===========================================
1596 
1597 
1598 
1599 
1600 //===========================================
1601 //
1602 // moFilterManager
1603 //
1604 //===========================================
1605 
1607 
1610 
1611  SetName("filtermanager");
1612  SetLabelName("filtermanager");
1613 
1614 }
1615 
1617 
1618 }
1619 
1621  return true;
1622 }
1623 
1624 
1626  return true;
1627 }
1628 
void StartRecording(long maxtime=60000, long granularity=30)
Empieza a grabar.
moDefineDynamicArray(moTrackerFeatureArray) moDefineDynamicArray(moTrackerInstanceRecords)
virtual void DrawFeatures(float w, float h, float offsetx, float offsety)
virtual MOboolean Finish()
long m_Tick
operador de copia, y seteo de timers
void printTracks()
Imprime el valor de los valores trazados por este punto.
#define MOulong
Definition: moTypes.h:392
moVector2fpArray track
list of feature positions in the past frames. Forms the feature tracks in video.
void SetName(const moText &p_name)
virtual void SetPositionMatrixC(float x, float y, int nfeatures)
POSITION CIRCULAR.
double m_AbsoluteAccelerationAverage
cantidad de movimiento
moVector4< MOfloat > moVector4f
virtual moVector2f GetMin()
virtual void Start()
Inicia el temporizador.
Definition: moTimer.cpp:196
virtual long Duration()
Devuelve el valor del reloj del temporizador.
Definition: moTimer.cpp:211
#define MO_TRACKER_LARGE_RESIDUE
int val
Other states for valid feature point.
moTrackerInstanceRecord & operator=(const moTrackerInstanceRecord &src)
float v_y
Speed in the actual frame.
virtual int GetMotionMatrixC(float x, float y)
virtual moVector2f GetSpeedVariance()
#define MOboolean
Definition: moTypes.h:385
virtual int GetValidFeatures()
long uframe
once recognized
function a
Definition: jquery.js:41
virtual moTrackerFeature * GetFeature(int i)
virtual moVector2f GetBarycenter()
virtual void SetPositionMatrix(float x, float y, int nfeatures)
POSITION.
int m_ValidFeatures
0 nada, 1 todo...
function x(bx)
Definition: jquery.js:30
f
Definition: jquery.js:71
float ap_y
Acceleration in the previous frame.
virtual moVector2f GetBarycenterAcceleration()
void SetResourceType(moResourceType p_restype)
virtual void SetAccelerationMatrix(float x, float y, int nfeatures)
ACCELERATION.
virtual int GetMotionMatrix(float x, float y)
#define MO_TRACKER_SMALL_DET
float vp_y
Speed in the previous frame.
virtual ~moFilterManager()
virtual int GetFeaturesCount()
virtual ~moTrackerFeature()
Destructor.
moVector2< MOfloat > moVector2f
Definition: moMathVector.h:423
bool is_object
once recognized
float tr_y
Feature position in the previous frame.
bool SaveToXML(moText filename)
moTrackerInstanceRecord m_ActualRecord
clase de para manejar textos
Definition: moText.h:75
float y
Location.
moTrackerFeature()
Constructor.
void Stop()
Detiene el temporizador.
Definition: moTimer.h:219
Dispositivo de entrada/salida, típicamente, interfaces humanas de IO y datos ( teclado, mouse, tableta, tcp, udp, serial )
Definition: moTypes.h:532
bool is_cursor
once recognized
moTypes MOint moText moParamIndex moParamReference int iRow int int i int i
Definition: all_f.js:18
virtual moVector2f ZoneToPosition(int zone)
Transforma el indice de zona al vector posicion.
long utime
once recognized
virtual void SetMax(float x, float y)
#define MO_TRACKER_NOT_FOUND
#define MO_TRACKER_TRACKED
int * m_MotionMatrix
4 x 4 zones
long sframe
once recognized
virtual MOboolean Init()
long stime
once recognized
int * m_CircularMotionMatrix
12 semitones, 3 levels
virtual void ResetMatrix()
Real X() const
Definition: moMathVector.h:77
Real Y() const
Definition: moMathVector.h:79
void Pause()
Congela o pausa el temporizador.
Definition: moTimer.h:231
moTrackerFeature & operator=(const moTrackerFeature &src)
virtual void SetMotionMatrix(float x, float y, int nfeatures)
MOTION.
moTrackerInstanceRecords m_History
virtual int PositionToZoneC(float x, float y)
Transforma el vector de posicion (0..1) a coordenadas polares luego al indice de zona de la matriz...
#define MO_TRACKER_MAX_ITERATIONS
void print()
Imprime los detalles de este punto.
const MOlong PI
Definition: moMath.cpp:44
virtual moVector2f GetAccelerationVariance()
void SetLabelName(const moText &p_labelname)
void Continue()
Prosigue el temporizador.
Definition: moTimer.h:239
bool is_parent
once recognized
bool valid
True for a valid feature point.
moTrackerFeatureArray FeaturesCaptured
virtual int GetDeltaValidFeatures()
The Y component of space.
Definition: moOGLFT.h:78
static moDebug * MODebug2
Clase de impresión de errores para depuración.
Definition: moAbstract.h:225
function d
Definition: jquery.js:41
moTrackerFeature * Parent
bool SaveToFile(moText filename)
void Record(moTrackerInstanceRecord &p_InstanceRecord, long p_Tick=-1)
virtual void SetMin(float x, float y)
double m_SurfaceCovered
separa formas de fondo
moTypes h
Definition: all_0.js:5
The X component of space.
Definition: moOGLFT.h:77
virtual moVector2f GetBarycenterMotion()
virtual int GetAccelerationMatrix(float x, float y)
float t_y
Torque in the actual frame.
moTrackerSystemHistory m_History
moTrackerInstanceRecord & Get(int index)
int * m_AccelerationMatrix
4 x 4 zones
double m_BoundingRectangleAngle
cantidad de fuerzas
void PauseRecording()
Util cuando no hay señales interesantes...
virtual moVector2f GetVariance()
virtual int GetPositionMatrix(float x, float y)
const MOlong TWO_PI
Definition: moMath.cpp:45
#define MOuint
Definition: moTypes.h:387
LIBMOLDEO_API moText0 IntToStr(int a)
Definition: moText.cpp:1070
bool Started() const
Devuelve el estado del temporizador.
Definition: moTimer.h:248
virtual moTrackerFeatureArray & GetFeatures()
#define MO_TRACKER_OOB
double m_AbsoluteTorqueAverage
cantidad de cambios de velocidad
virtual void SetMotionMatrixC(float x, float y, int nfeatures)
Real Length() const
Definition: moMathVector.h:170
float normy
Normalized Feature Coordinates [ 0 - 1 ].
Característica de seguimiento ( sensado )
void Message(moText p_text)
Anuncia un mensaje al usuario además de guardarlo en el log de texto.
Definition: moAbstract.cpp:114
virtual int GetPositionMatrixC(float x, float y)
virtual moVector2f GetMax()
moTrackerFeatureArray m_Features
void SetType(moMoldeoObjectType p_type)
virtual moVector4f GetBoundingRectangle()
int updatePos(float kltConvergeThreshold, float kltSSDthresh, int kltborder, float delta, float res, float d1, float d2, float w, float h)
Update Feature Positions.
Matrix de características.
moVector2f m_BarycenterAcceleration
virtual int PositionToZone(float x, float y)
Transforma el vector de posicion (0..1) al indice de zona de la matriz cuadrada.
int * m_CircularPositionMatrix
4 x 4 zones
virtual moVector2f ZoneToPositionC(int zone)
Transforma el indice de zona al vector posicion circular!
float a_y
Acceleration in the actual frame.