void TestGPURayCaster::testSetImages() { vtkImageDataPtr data = vtkImageData::New(); cx::ImagePtr image1(new cx::Image("i1", data)); cx::ImagePtr image2(new cx::Image("i2", data)); cx::ImagePtr image3(new cx::Image("i3", data)); cx::ImagePtr image4(new cx::Image("i4", data)); cx::ImagePtr image5(new cx::Image("i5", data)); std::vector<cx::ImagePtr> images; uint64_t mTime = mRep->mActor->GetMTime(); images.push_back(image1); CPPUNIT_ASSERT_EQUAL((size_t)0, mRep->getImages().size()); mRep->setImages(images); CPPUNIT_ASSERT_EQUAL((size_t)1, mRep->getImages().size()); CPPUNIT_ASSERT_EQUAL(QString("i1"), mRep->getImages()[0]->getUid()); CPPUNIT_ASSERT(mRep->mActor->GetMTime() > mTime); mTime = mRep->mActor->GetMTime(); mRep->setImages(images); uint64_t mNewTime = mRep->mActor->GetMTime(); CPPUNIT_ASSERT_EQUAL(mTime, mNewTime); images.push_back(image2); images.push_back(image3); images.push_back(image4); images.push_back(image5); mRep->setImages(images); CPPUNIT_ASSERT_EQUAL((size_t)4, mRep->getImages().size()); CPPUNIT_ASSERT_EQUAL(QString("i1"), mRep->getImages()[0]->getUid()); CPPUNIT_ASSERT_EQUAL(QString("i2"), mRep->getImages()[1]->getUid()); CPPUNIT_ASSERT_EQUAL(QString("i3"), mRep->getImages()[2]->getUid()); CPPUNIT_ASSERT_EQUAL(QString("i4"), mRep->getImages()[3]->getUid()); }
void TerrainWeightEditor::DecomposeImageToCanvases(const QImage& image) { QLabel *canvas1 = editor_widget_->findChild<QLabel *>("canvas_1"); QLabel *canvas2 = editor_widget_->findChild<QLabel *>("canvas_2"); QLabel *canvas3 = editor_widget_->findChild<QLabel *>("canvas_3"); QLabel *canvas4 = editor_widget_->findChild<QLabel *>("canvas_4"); assert(canvas1 && canvas2 && canvas3 && canvas4); int width = image.width(); int height = image.height(); QImage::Format format = image.format(); QImage image1(width,height,format); QImage image2(width,height,format); QImage image3(width,height,format); QImage image4(width,height,format); for(int i=0;i<width;i++) { for(int j=0; j<height;j++) { QRgb color = image.pixel(i,j); int alpha = qAlpha(color); int red = qRed(color); int green = qGreen(color); int blue = qBlue(color); image1.setPixel(i,j, QColor(red,red,red).rgba()); image2.setPixel(i,j, QColor(green,green,green).rgba()); image3.setPixel(i,j, QColor(blue,blue,blue).rgba()); image4.setPixel(i,j, QColor(alpha,alpha,alpha).rgba()); } } canvas1->setPixmap(QPixmap::fromImage(image1)); canvas2->setPixmap(QPixmap::fromImage(image2)); canvas3->setPixmap(QPixmap::fromImage(image3)); canvas4->setPixmap(QPixmap::fromImage(image4)); }
void WindowTexture::generateWindowTexture() //randomly generate windows texture for buildings { CBitmap image0("building/texture/1.bmp"); glBindTexture(GL_TEXTURE_2D, m_nTextureId[0]); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image0.GetWidth(),image0.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,image0.GetBits()); //load data into texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //specify texture coordinate treatment glEnable(GL_TEXTURE_2D); CBitmap image1("building/texture/2.bmp"); glBindTexture(GL_TEXTURE_2D, m_nTextureId[1]); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image1.GetWidth(),image1.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,image1.GetBits()); //load data into texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //specify texture coordinate treatment glEnable(GL_TEXTURE_2D); CBitmap image2("building/texture/3.bmp"); glBindTexture(GL_TEXTURE_2D, m_nTextureId[2]); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image2.GetWidth(),image2.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,image2.GetBits()); //load data into texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //specify texture coordinate treatment glEnable(GL_TEXTURE_2D); CBitmap image3("building/texture/4.bmp"); glBindTexture(GL_TEXTURE_2D, m_nTextureId[3]); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image3.GetWidth(),image3.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,image3.GetBits()); //load data into texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //specify texture coordinate treatment glEnable(GL_TEXTURE_2D); CBitmap image4("building/texture/5.bmp"); glBindTexture(GL_TEXTURE_2D, m_nTextureId[4]); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image4.GetWidth(),image4.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,image4.GetBits()); //load data into texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //specify texture coordinate treatment glEnable(GL_TEXTURE_2D); CBitmap image100("building/texture/mailbox_asdf.bmp"); glBindTexture(GL_TEXTURE_2D, m_nTextureId[numTex]); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image100.GetWidth(),image100.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,image100.GetBits()); //load data into texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //specify texture coordinate treatment glEnable(GL_TEXTURE_2D); textureBounded = true; }
/* * Constructs a Smilies which is a child of 'parent', with the * name 'name' and widget flags set to 'f' */ Smilies::Smilies( QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ) { QPixmap image0( SmallIcon("face_smile") ); QPixmap image1( SmallIcon("face_angel") ); QPixmap image2( SmallIcon("face_embarrassed") ); QPixmap image3( SmallIcon("face_yell") ); QPixmap image4( SmallIcon("face_wink") ); QPixmap image5( SmallIcon("face_glasses") ); QPixmap image6( SmallIcon("face_moneymouth") ); QPixmap image7( SmallIcon("face_crossedlips") ); QPixmap image8( SmallIcon("face_sad") ); QPixmap image9( SmallIcon("face_scream") ); QPixmap image10( SmallIcon("face_cry") ); QPixmap image11( SmallIcon("face_burp") ); QPixmap image12( SmallIcon("face_kiss") ); QPixmap image13( SmallIcon("face_think") ); QPixmap image14( SmallIcon("face_tongue") ); QPixmap image15( SmallIcon("face_luke") ); QPixmap image16( SmallIcon("face_bigsmile") ); QPixmap image17( SmallIcon("face_oneeye") ); if ( !name ) setName( "Smilies" ); resize( 124, 139 ); setCaption( tr( "kaim-smiles" ) ); SmiliesLayout = new QGridLayout( this ); SmiliesLayout->setSpacing( 0 ); SmiliesLayout->setMargin( 0 ); smile = new QToolButton( this, "smile" ); smile->setText( tr( " " ) ); smile->setPixmap( image0 ); SmiliesLayout->addWidget( smile, 0, 0 ); angel = new QToolButton( this, "angel" ); angel->setText( tr( " " ) ); angel->setPixmap( image1 ); SmiliesLayout->addWidget( angel, 2, 3 ); embarrassed = new QToolButton( this, "embarrassed" ); embarrassed->setText( tr( " " ) ); embarrassed->setPixmap( image2 ); SmiliesLayout->addWidget( embarrassed, 2, 2 ); yell = new QToolButton( this, "yell" ); yell->setText( tr( " " ) ); yell->setPixmap( image3 ); SmiliesLayout->addWidget( yell, 1, 2 ); wink = new QToolButton( this, "wink" ); wink->setText( tr( " " ) ); wink->setPixmap( image4 ); SmiliesLayout->addWidget( wink, 0, 3 ); glasses = new QToolButton( this, "glasses" ); glasses->setText( tr( " " ) ); glasses->setPixmap( image5 ); SmiliesLayout->addWidget( glasses, 2, 0 ); moneymouth = new QToolButton( this, "moneymouth" ); moneymouth->setText( tr( " " ) ); moneymouth->setPixmap( image6 ); SmiliesLayout->addWidget( moneymouth, 3, 3 ); crossedlips = new QToolButton( this, "crossedlips" ); crossedlips->setText( tr( " " ) ); crossedlips->setPixmap( image7 ); SmiliesLayout->addWidget( crossedlips, 3, 2 ); sad = new QToolButton( this, "sad" ); sad->setText( tr( " " ) ); sad->setPixmap( image8 ); SmiliesLayout->addWidget( sad, 0, 2 ); scream = new QToolButton( this, "scream" ); scream->setText( tr( " " ) ); scream->setPixmap( image9 ); SmiliesLayout->addWidget( scream, 1, 1 ); cry = new QToolButton( this, "cry" ); cry->setText( tr( " " ) ); cry->setPixmap( image10 ); SmiliesLayout->addWidget( cry, 3, 1 ); burp = new QToolButton( this, "burp" ); burp->setText( tr( " " ) ); burp->setPixmap( image11 ); SmiliesLayout->addWidget( burp, 2, 1 ); kiss = new QToolButton( this, "kiss" ); kiss->setText( tr( " " ) ); kiss->setPixmap( image12 ); SmiliesLayout->addWidget( kiss, 1, 3 ); think = new QToolButton( this, "think" ); think->setText( tr( " " ) ); think->setPixmap( image13 ); SmiliesLayout->addWidget( think, 3, 0 ); tongue = new QToolButton( this, "tongue" ); tongue->setText( tr( " " ) ); tongue->setPixmap( image14 ); SmiliesLayout->addWidget( tongue, 1, 0 ); luke = new QToolButton( this, "luke" ); luke->setText( tr( " " ) ); luke->setPixmap( image15 ); SmiliesLayout->addWidget( luke, 4, 2 ); bigsmile = new QToolButton( this, "bigsmile" ); bigsmile->setText( tr( " " ) ); bigsmile->setPixmap( image16 ); SmiliesLayout->addWidget( bigsmile, 0, 1 ); oneeye = new QToolButton( this, "oneeye" ); oneeye->setText( tr( " " ) ); oneeye->setPixmap( image17 ); SmiliesLayout->addWidget( oneeye, 4, 1 ); QObject::connect( smile, SIGNAL(clicked()), SLOT(smileClicked()) ); QObject::connect( angel, SIGNAL(clicked()), SLOT(angelClicked()) ); QObject::connect( embarrassed, SIGNAL(clicked()), SLOT(embarrassedClicked()) ); QObject::connect( yell, SIGNAL(clicked()), SLOT(yellClicked()) ); QObject::connect( wink, SIGNAL(clicked()), SLOT(winkClicked()) ); QObject::connect( glasses, SIGNAL(clicked()), SLOT(glassesClicked()) ); QObject::connect( moneymouth, SIGNAL(clicked()), SLOT(moneymouthClicked()) ); QObject::connect( crossedlips, SIGNAL(clicked()), SLOT(crossedlipsClicked()) ); QObject::connect( sad, SIGNAL(clicked()), SLOT(sadClicked()) ); QObject::connect( scream, SIGNAL(clicked()), SLOT(screamClicked()) ); QObject::connect( cry, SIGNAL(clicked()), SLOT(cryClicked()) ); QObject::connect( burp, SIGNAL(clicked()), SLOT(burpClicked()) ); QObject::connect( kiss, SIGNAL(clicked()), SLOT(kissClicked()) ); QObject::connect( think, SIGNAL(clicked()), SLOT(thinkClicked()) ); QObject::connect( tongue, SIGNAL(clicked()), SLOT(tongueClicked()) ); QObject::connect( luke, SIGNAL(clicked()), SLOT(lukeClicked()) ); QObject::connect( bigsmile, SIGNAL(clicked()), SLOT(bigsmileClicked()) ); QObject::connect( oneeye, SIGNAL(clicked()), SLOT(oneeyeClicked()) ); }
int main(int, char *[]) { double testrad = 5.5, testx = 127.25, testy = 127.75; //< Actual location of spot double seedrad = 6, seedx = 120, seedy = 118; //< Start location for tracking int avgcount; //< How many samples to average over double pixacc; //< Pixel accuracy desired double err, minerr, maxerr, sumerr; double raderr, minraderr, maxraderr, sumraderr; double biasx, biasy; printf("Generating default test image with radius %lg disk at %lg, %lg\n", testrad, testx, testy); disc_image image(0,255, 0,255, 127, 5, testx, testy, testrad, 250); printf("-----------------------------------------------------------------\n"); printf("Generating default spot tracker\n"); disk_spot_tracker tracker(seedrad); printf("Looking for best fit within the image\n"); tracker.locate_good_fit_in_image(image, 0, seedx, seedy); printf("Optimization, starting at found location %lg, %lg, rad %lg\n", seedx, seedy, seedrad); int i; double x,y, rad, fit; tracker.take_single_optimization_step(image, 0, x,y, seedx, seedy); for (i = 0; i < 5; i++) { tracker.take_single_optimization_step(image, 0, x, y, true, true, true); rad = tracker.get_radius(); fit = tracker.get_fitness(); printf("Next step: X = %8.3lg, Y = %8.3lg, rad = %8.3lg, fit = %12.5lg\n", x,y,rad, fit); } printf("Chasing around a slightly noisy spot using full optimization\n"); testrad = 5.5, testx = 127.25, testy = 127.75; //< Actual location of spot seedrad = 6, seedx = 120, seedy = 118; //< Start location for tracking avgcount = 50; minerr = 1000; maxerr = 0; sumerr = 0; minraderr = 1000; maxraderr = 0; sumraderr = 0; biasx = 0; biasy = 0; for (i = 0; i < avgcount; i++) { testrad += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * 1; if (testrad < 3) { testrad = 3; } testx += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2); testy += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2); { disc_image image2(0,255, 0,255, 127, 5, testx, testy, testrad, 250); tracker.optimize(image2, 0, x, y); rad = tracker.get_radius(); fit = tracker.get_fitness(); err = sqrt( (x-testx)*(x-testx) + (y-testy)*(y-testy) ); if (err < minerr) { minerr = err; } if (err > maxerr) { maxerr = err; } sumerr += err; raderr = fabs(rad-testrad); if (raderr < minraderr) { minraderr = raderr; } if (raderr > maxraderr) { maxraderr = raderr; } sumraderr += raderr; biasx += x - testx; biasy += y - testy; if (i == 0) { printf("First opt: real coords (%g,%g), found coords (%g,%g)\n", testx,testy, x,y); } } } printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); printf("Rad err: min=%g, max=%g, mean=%g\n", minraderr, maxraderr, sumraderr/avgcount); testrad = 5.5; pixacc = 0.05; avgcount = 50; x = 120.5; y = 120; printf("Chasing around a slightly noisy disk of known radius %g to %g pixel\n", testrad, pixacc); compute_disk_chase_statistics(tracker, testrad, pixacc, avgcount, minerr, maxerr, sumerr, biasx, biasy, x,y); printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); x = 120.5; y = 120; printf("Chasing around a slightly noisy cone of known radius %g to %g pixel\n", testrad, pixacc); compute_cone_chase_statistics(tracker, testrad, pixacc, avgcount, minerr, maxerr, sumerr, biasx, biasy, x,y); printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); pixacc = 0.05; testrad = 5.5; tracker.set_pixel_accuracy(pixacc); printf("Timing how long it takes to optimize pos to %g pixels from a nearby position on average\n", pixacc); avgcount = 1000; struct timeval start, end; tracker.optimize(image, 0, x,y); // Get back to the correct starting location gettimeofday(&start, NULL); for (i = 0; i < avgcount; i++) { tracker.optimize_xy(image, 0, x, y, x + ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2), y + ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2)); } gettimeofday(&end, NULL); printf(" Time: %lg seconds per optimization\n", duration(end, start)/avgcount); printf("-----------------------------------------------------------------\n"); printf("Generating interpolating spot tracker\n"); disk_spot_tracker_interp interptracker(seedrad); printf("Looking for best fit within the image\n"); interptracker.locate_good_fit_in_image(image, 0, seedx, seedy); printf("Optimization, starting at found location %lg, %lg, rad %lg\n", seedx, seedy, seedrad); interptracker.take_single_optimization_step(image, 0, x,y, seedx, seedy); for (i = 0; i < 5; i++) { interptracker.take_single_optimization_step(image, 0, x, y, true, true, true); rad = interptracker.get_radius(); fit = interptracker.get_fitness(); printf("Next step: X = %8.3lg, Y = %8.3lg, rad = %8.3lg, fit = %12.5lg\n", x,y,rad, fit); } printf("Chasing around a slightly noisy spot using full optimization\n"); testrad = 5.5, testx = 127.25, testy = 127.75; //< Actual location of spot seedrad = 6, seedx = 120, seedy = 118; //< Start location for tracking avgcount = 50; minerr = 1000; maxerr = 0; sumerr = 0; minraderr = 1000; maxraderr = 0; sumraderr = 0; biasx = 0; biasy = 0; for (i = 0; i < avgcount; i++) { testrad += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * 1; if (testrad < 3) { testrad = 3; } testx += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2); testy += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2); { disc_image image2(0,255, 0,255, 127, 5, testx, testy, testrad, 250); interptracker.optimize(image2, 0, x, y); rad = interptracker.get_radius(); fit = interptracker.get_fitness(); err = sqrt( (x-testx)*(x-testx) + (y-testy)*(y-testy) ); if (err < minerr) { minerr = err; } if (err > maxerr) { maxerr = err; } sumerr += err; raderr = fabs(rad-testrad); if (raderr < minraderr) { minraderr = raderr; } if (raderr > maxraderr) { maxraderr = raderr; } sumraderr += raderr; biasx += x - testx; biasy += y - testy; if (i == 0) { printf("First opt: real coords (%g,%g), found coords (%g,%g)\n", testx,testy, x,y); } } } printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); printf("Rad err: min=%g, max=%g, mean=%g\n", minraderr, maxraderr, sumraderr/avgcount); testrad = 5.5; pixacc = 0.05; avgcount = 50; x = 120.5; y = 120; printf("Chasing around a slightly noisy disk of known radius %g to %g pixel\n", testrad, pixacc); compute_disk_chase_statistics(interptracker, testrad, pixacc, avgcount, minerr, maxerr, sumerr, biasx,biasy, x,y); printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); x = 120.5; y = 120; printf("Chasing around a slightly noisy cone of known radius %g to %g pixel\n", testrad, pixacc); compute_cone_chase_statistics(interptracker, testrad, pixacc, avgcount, minerr, maxerr, sumerr, biasx,biasy, x,y); printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); testrad = 5.5; pixacc = 0.05; x = 120.5; y = 120; disc_image image3(0,255,0,255,127,0,x,y,testrad, 250); printf("Optimizing a slightly noisy disk of known radius %g at %g,%g\n", testrad, x,y); interptracker.optimize_xy(image3, 0, x, y, floor(x), ceil(y)); printf(" Found a spot of radius %g at %g,%g\n", interptracker.get_radius(), interptracker.get_x(), interptracker.get_y()); pixacc = 0.05; testrad = 5.5; interptracker.set_pixel_accuracy(pixacc); printf("Timing how long it takes to optimize pos to %g pixels from a nearby position on average\n", pixacc); avgcount = 100; interptracker.optimize(image, 0, x,y); // Get back to the correct starting location gettimeofday(&start, NULL); for (i = 0; i < avgcount; i++) { interptracker.optimize_xy(image, 0, x, y, x + ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2), y + ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2)); } gettimeofday(&end, NULL); printf(" Time: %lg seconds per optimization\n", duration(end, start)/avgcount); printf("-----------------------------------------------------------------\n"); printf("Generating interpolating cone spot tracker\n"); cone_spot_tracker_interp conetracker(seedrad); printf("Looking for best fit within the image\n"); conetracker.locate_good_fit_in_image(image, 0, seedx, seedy); printf("Optimization, starting at found location %lg, %lg, rad %lg\n", seedx, seedy, seedrad); conetracker.take_single_optimization_step(image, 0, x,y, seedx, seedy); for (i = 0; i < 5; i++) { conetracker.take_single_optimization_step(image, 0, x, y, true, true, true); rad = conetracker.get_radius(); fit = conetracker.get_fitness(); printf("Next step: X = %8.3lg, Y = %8.3lg, rad = %8.3lg, fit = %12.5lg\n", x,y,rad, fit); } printf("Chasing around a slightly noisy spot using full optimization\n"); testrad = 5.5, testx = 127.25, testy = 127.75; //< Actual location of spot seedrad = 6, seedx = 120, seedy = 118; //< Start location for tracking avgcount = 50; minerr = 1000; maxerr = 0; sumerr = 0; minraderr = 1000; maxraderr = 0; sumraderr = 0; biasx = 0; biasy = 0; for (i = 0; i < avgcount; i++) { testrad += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * 1; if (testrad < 3) { testrad = 3; } testx += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2); testy += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2); { disc_image image2(0,255, 0,255, 127, 5, testx, testy, testrad, 250); conetracker.optimize(image2, 0, x, y); rad = conetracker.get_radius(); fit = conetracker.get_fitness(); err = sqrt( (x-testx)*(x-testx) + (y-testy)*(y-testy) ); if (err < minerr) { minerr = err; } if (err > maxerr) { maxerr = err; } sumerr += err; raderr = fabs(rad-testrad); if (raderr < minraderr) { minraderr = raderr; } if (raderr > maxraderr) { maxraderr = raderr; } sumraderr += raderr; biasx += x - testx; biasy += y - testy; if (i == 0) { printf("First opt: real coords (%g,%g), found coords (%g,%g)\n", testx,testy, x,y); } } } printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); printf("Rad err: min=%g, max=%g, mean=%g\n", minraderr, maxraderr, sumraderr/avgcount); testrad = 5.5; pixacc = 0.05; avgcount = 50; x = 120.5; y = 120; printf("Chasing around a slightly noisy disk of known radius %g to %g pixel\n", testrad, pixacc); // Make the radius slightly larger than the radius of the spot. compute_disk_chase_statistics(conetracker, 1.3*testrad, pixacc, avgcount, minerr, maxerr, sumerr, biasx,biasy, x,y); printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); x = 120.5; y = 120; printf("Chasing around a slightly noisy cone of known radius %g to %g pixel\n", testrad, pixacc); // Make the radius slightly larger than the radius of the spot. compute_cone_chase_statistics(conetracker, 1.3*testrad, pixacc, avgcount, minerr, maxerr, sumerr, biasx,biasy, x,y); printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); testrad = 5.5; pixacc = 0.05; x = 120.5; y = 120; disc_image image4(0,255,0,255,127,0,x,y,testrad, 250); printf("Optimizing a slightly noisy disk of known radius %g at %g,%g\n", testrad, x,y); conetracker.optimize_xy(image4, 0, x, y, floor(x), ceil(y)); printf(" Found a spot of radius %g at %g,%g\n", conetracker.get_radius(), conetracker.get_x(), conetracker.get_y()); pixacc = 0.05; testrad = 5.5; conetracker.set_pixel_accuracy(pixacc); printf("Timing how long it takes to optimize pos to %g pixels from a nearby position on average\n", pixacc); avgcount = 100; conetracker.optimize(image, 0, x,y); // Get back to the correct starting location gettimeofday(&start, NULL); for (i = 0; i < avgcount; i++) { conetracker.optimize_xy(image, 0, x, y, x + ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2), y + ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2)); } gettimeofday(&end, NULL); printf(" Time: %lg seconds per optimization\n", duration(end, start)/avgcount); printf("-----------------------------------------------------------------\n"); printf("Generating interpolating symmetric spot tracker\n"); symmetric_spot_tracker_interp symmetrictracker(seedrad); printf("Looking for best fit within the image\n"); symmetrictracker.locate_good_fit_in_image(image, 0, seedx, seedy); printf("Optimization, starting at found location %lg, %lg, rad %lg\n", seedx, seedy, seedrad); symmetrictracker.take_single_optimization_step(image, 0, x,y, seedx, seedy); for (i = 0; i < 5; i++) { symmetrictracker.take_single_optimization_step(image, 0, x, y, true, true, true); rad = symmetrictracker.get_radius(); fit = symmetrictracker.get_fitness(); printf("Next step: X = %8.3lg, Y = %8.3lg, rad = %8.3lg, fit = %12.5lg\n", x,y,rad, fit); } printf("Chasing around a slightly noisy spot using full optimization\n"); testrad = 5.5, testx = 127.25, testy = 127.75; //< Actual location of spot seedrad = 6, seedx = 120, seedy = 118; //< Start location for tracking avgcount = 50; minerr = 1000; maxerr = 0; sumerr = 0; minraderr = 1000; maxraderr = 0; sumraderr = 0; biasx = 0; biasy = 0; for (i = 0; i < avgcount; i++) { testrad += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * 1; if (testrad < 3) { testrad = 3; } testx += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2); testy += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2); { disc_image image2(0,255, 0,255, 127, 5, testx, testy, testrad, 250); symmetrictracker.optimize(image2, 0, x, y); rad = symmetrictracker.get_radius(); fit = symmetrictracker.get_fitness(); err = sqrt( (x-testx)*(x-testx) + (y-testy)*(y-testy) ); if (err < minerr) { minerr = err; } if (err > maxerr) { maxerr = err; } sumerr += err; raderr = fabs(rad-testrad); if (raderr < minraderr) { minraderr = raderr; } if (raderr > maxraderr) { maxraderr = raderr; } sumraderr += raderr; biasx += x - testx; biasy += y - testy; if (i == 0) { printf("First opt: real coords (%g,%g), found coords (%g,%g)\n", testx,testy, x,y); } } } printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); printf("Rad err: min=%g, max=%g, mean=%g\n", minraderr, maxraderr, sumraderr/avgcount); testrad = 5.5; pixacc = 0.01; avgcount = 50; x = 120.5; y = 120; printf("Chasing around a slightly noisy disk of known radius %g to %g pixel\n", testrad, pixacc); // Make the radius slightly larger than the radius of the spot. compute_disk_chase_statistics(symmetrictracker, 1.3*testrad, pixacc, avgcount, minerr, maxerr, sumerr, biasx,biasy, x,y); printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); x = 120.5; y = 120; printf("Chasing around a slightly noisy cone of known radius %g to %g pixel\n", testrad, pixacc); // Make the radius slightly larger than the radius of the spot. compute_disk_chase_statistics(symmetrictracker, 1.3*testrad, pixacc, avgcount, minerr, maxerr, sumerr, biasx,biasy, x,y); printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); testrad = 5.5; pixacc = 0.05; x = 120.5; y = 120; disc_image image5(0,255,0,255,127,0,x,y,testrad, 250); printf("Optimizing a slightly noisy disk of known radius %g at %g,%g\n", testrad, x,y); symmetrictracker.optimize_xy(image5, 0, x, y, floor(x), ceil(y)); printf(" Found a spot of radius %g at %g,%g\n", symmetrictracker.get_radius(), symmetrictracker.get_x(), symmetrictracker.get_y()); pixacc = 0.05; testrad = 5.5; symmetrictracker.set_pixel_accuracy(pixacc); printf("Timing how long it takes to optimize pos to %g pixels from a nearby position on average\n", pixacc); avgcount = 100; symmetrictracker.optimize(image, 0, x,y); // Get back to the correct starting location gettimeofday(&start, NULL); for (i = 0; i < avgcount; i++) { symmetrictracker.optimize_xy(image, 0, x, y, x + ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2), y + ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2)); } gettimeofday(&end, NULL); printf(" Time: %lg seconds per optimization\n", duration(end, start)/avgcount); printf("-----------------------------------------------------------------\n"); printf("Generating Gaussian spot tracker\n"); testrad = 5.5, testx = 127.25, testy = 127.75; //< Actual location of spot seedrad = 6, seedx = 120, seedy = 118; //< Start location for tracking Gaussian_spot_tracker Gaussiantracker(seedrad, false, 0.25, 0.25, 1.0, 127, 11689); printf("Looking for best fit within the image\n"); Gaussiantracker.locate_good_fit_in_image(image, 0, seedx, seedy); printf("Optimization, starting at found location %lg, %lg, rad %lg\n", seedx, seedy, seedrad); Gaussiantracker.take_single_optimization_step(image, 0, x,y, seedx, seedy); for (i = 0; i < 5; i++) { Gaussiantracker.take_single_optimization_step(image, 0, x, y, true, true, true); rad = Gaussiantracker.get_radius(); fit = Gaussiantracker.get_fitness(); printf("Next step: X = %8.3lg, Y = %8.3lg, rad = %8.3lg, fit = %12.5lg\n", x,y,rad, fit); } printf("Chasing around a slightly noisy spot using full optimization\n"); avgcount = 50; minerr = 1000; maxerr = 0; sumerr = 0; minraderr = 1000; maxraderr = 0; sumraderr = 0; biasx = 0; biasy = 0; for (i = 0; i < avgcount; i++) { testrad += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * 1; if (testrad < 3) { testrad = 3; } testx += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2); testy += ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2); { disc_image image2(0,255, 0,255, 127, 5, testx, testy, testrad, 250); Gaussiantracker.optimize(image2, 0, x, y); rad = Gaussiantracker.get_radius(); fit = Gaussiantracker.get_fitness(); err = sqrt( (x-testx)*(x-testx) + (y-testy)*(y-testy) ); if (err < minerr) { minerr = err; } if (err > maxerr) { maxerr = err; } sumerr += err; raderr = fabs(rad-testrad); if (raderr < minraderr) { minraderr = raderr; } if (raderr > maxraderr) { maxraderr = raderr; } sumraderr += raderr; biasx += x - testx; biasy += y - testy; if (i == 0) { printf("First opt: real coords (%g,%g), found coords (%g,%g)\n", testx,testy, x,y); } } } printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); // XXX Radius error meaningless here because radius not optimized. //printf("Rad err: min=%g, max=%g, mean=%g\n", minraderr, maxraderr, sumraderr/avgcount); testrad = 5.5; pixacc = 0.01; avgcount = 50; x = 120.5; y = 120; printf("Chasing around a slightly noisy disk of known radius %g to %g pixel\n", testrad, pixacc); // Make the radius slightly larger than the radius of the spot. compute_disk_chase_statistics(Gaussiantracker, 1.3*testrad, pixacc, avgcount, minerr, maxerr, sumerr, biasx,biasy, x,y); printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); x = 120.5; y = 120; printf("Chasing around a slightly noisy cone of known radius %g to %g pixel\n", testrad, pixacc); // Make the radius slightly larger than the radius of the spot. compute_disk_chase_statistics(Gaussiantracker, 1.3*testrad, pixacc, avgcount, minerr, maxerr, sumerr, biasx,biasy, x,y); printf("Pos err: min=%g, max=%g, mean=%g, xbias = %g, ybias = %g\n", minerr, maxerr, sumerr/avgcount, biasx/avgcount, biasy/avgcount); testrad = 5.5; pixacc = 0.05; x = 120.5; y = 120; disc_image image6(0,255,0,255,127,0,x,y,testrad, 250); printf("Optimizing a slightly noisy disk of known radius %g at %g,%g\n", testrad, x,y); Gaussiantracker.optimize(image6, 0, x, y, floor(x), ceil(y)); printf(" Found a spot of radius %g at %g,%g\n", Gaussiantracker.get_radius(), Gaussiantracker.get_x(), Gaussiantracker.get_y()); pixacc = 0.05; testrad = 5.5; Gaussiantracker.set_pixel_accuracy(pixacc); printf("Timing how long it takes to optimize pos to %g pixels from a nearby position on average\n", pixacc); avgcount = 10; Gaussiantracker.optimize(image, 0, x,y); // Get back to the correct starting location gettimeofday(&start, NULL); for (i = 0; i < avgcount; i++) { Gaussiantracker.optimize_xy(image, 0, x, y, x + ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2), y + ( (rand()/(double)(RAND_MAX)) - 0.5) * 2 * (testrad/2)); } gettimeofday(&end, NULL); printf(" Time: %lg seconds per optimization\n", duration(end, start)/avgcount); //----------------------------------------------------------------------------------------------- // Testing the Z-tracking classes. printf("-----------------------------------------------------------------\n"); // Construct a PSF kernel by making a number of disc images and sticking them into it. disc_image *discs[10]; PSF_File *psf = new PSF_File("deleteme.tif", 25, false); for (i = 0; i < 10; i++) { discs[i] = new disc_image(0,128, 0,128, 0, 0.0, 64,64, i+10, 255, 4); psf->append_line(*discs[i], 64, 64); } delete psf; // Test the best-fit-finding code radial_average_tracker_Z Ztrack("deleteme.tif"); double z = 0.0; Ztrack.locate_best_fit_in_depth(*discs[5], 0, 64, 64, z); printf("Z best fit should be 5, found at %lf\n", z); // Test the optimization code Ztrack.optimize(*discs[7], 0, 64, 64, z); printf("Z optimum should be 7, found at %lf\n", z); // Test on a novel image disc_image test_disc(0,128, 0,128, 0, 0.0, 64,64, 5.5+10, 255, 4); Ztrack.optimize(test_disc, 0, 64, 64, z); printf("Z optimum should be 5.5, found at %lf\n", z); // Delete the PSF file unlink("deleteme.tif"); return 0; }