예제 #1
0
// ######################################################################
static int submain(const int argc, char** argv)
{

        MYLOGVERB = LOG_INFO;  // suppress debug messages



// Instantiate a ModelManager:
 ModelManager manager("test get eye position");

 nub::soft_ref<EyeTrackerConfigurator>
   etc(new EyeTrackerConfigurator(manager));
 manager.addSubComponent(etc);

 nub::soft_ref<EventLog> el(new EventLog(manager));
 manager.addSubComponent(el);

 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
 manager.addSubComponent(d);


 manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy");
 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN");

 // Parse command-line:
 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false)
   return(1);


 // hook our various babies up and do post-command-line configs:
 nub::soft_ref<EyeTracker> et = etc->getET();
 et->setEventLog(el);

 // let's get all our ModelComponent instances started:
 manager.start();

 d->setEyeTracker(et);
 d->setEventLog(el);

 el->pushEvent(std::string("===== Trial 1:  ====="));

 //lets time stamp event log and start the eyetracker
 //et->track(true);
 //here we will start testing the get pos

 LINFO("eyescanner started going to start reading stuff");
//  int i=0;

 d->clearScreen();
 d->displayISCANcalib();
 d->waitForKey();

 Image< PixRGB<byte> > displayImage (1920,1080, ZEROS);
 drawCircle(displayImage, Point2D<int>(1920/2,1080/2), 5, PixRGB<byte>(255,0,0));

 SDL_Surface *surf = d->makeBlittableSurface(displayImage, true);
 d->displaySurface(surf, -2);

 CalibrationTransform::Data pts;
 AffineTransform a;
 Image<double> txf;
 Point2D<int> testpoint;
 Point2D<double> testpointCalib,testpointD;

     LINFO("precalib");
     pts = et->getCalibrationSet(d);
     LINFO("postcalib");
     txf = a.computeTransform(pts);
     LINFO("transform is...");
     std::cerr << txf << std::endl;
     testpoint =  et->getEyePos();
     testpointD = Point2D<double>(testpoint);
     LINFO("\n testpoint %d,%d",testpoint.i,testpoint.j);
     testpointCalib = a.getCalibrated(testpointD);
     LINFO("\n testpoint %d,%d, calibrated %f,%f",testpoint.i,testpoint.j,testpointCalib.i,testpointCalib.j);
     d->clearScreen();

   //now for a live demo of real time eyetracking
   char tmp[40];

   //SDL_Surface *surf2;

   while(d->checkForKey() < 0)
   {
     displayImage.clear();
     testpoint =  et->getEyePos();
     testpointD = Point2D<double>(testpoint);
     testpointCalib = a.getCalibrated(testpointD);
     LINFO("\n testpoint %d,%d, calibrated %f,%f",testpoint.i,testpoint.j,testpointCalib.i,testpointCalib.j);
     drawCircle(displayImage, Point2D<int>(testpointCalib), 2, PixRGB<byte>(255,0,0));
     sprintf(tmp,"(%d,%d)",(int)testpointCalib.i,(int)testpointCalib.j);
     writeText(displayImage,Point2D<int>(testpointCalib),tmp,PixRGB<byte>(255,0,0),PixRGB<byte>(0,0,0),SimpleFont::FIXED(8));
     // d->displayImage(displayImage, true, PixRGB<byte>(), -2);
      SDL_Surface *surf2 = d->makeBlittableSurface(displayImage, true);
      d->displaySurface(surf2, -2);
      SDL_FreeSurface(surf2);
//     i++;

   }

//   struct EyeposEvent
//   {
//     uint64;
//     float x, y;
//   };

//    std::vector<EyeposEvent> evs;
//    evs.reserve(100000);

 // stop the eye tracker:
 usleep(50000);
 et->track(false);
 // stop all our ModelComponents
 manager.stop();

 // all done!
 return 0;


}