cElHomographie cElHomographie::RansacInitH(const ElPackHomologue & aPack,int aNbRansac,int aNbMaxPts) { if ((aPack.size()<10) || (aNbMaxPts<4)) return cElHomographie(aPack,false); cRandNParmiQ aRand(aNbMaxPts,aPack.size()); std::vector<ElCplePtsHomologues> aVCH; for (ElPackHomologue::tCstIter itH=aPack.begin() ; itH!=aPack.end() ; itH++) { if (aRand.GetNext()) { aVCH.push_back(itH->ToCple()); } } double anEcMin = 1e30; cElHomographie aHMin = cElHomographie::Id(); while (aNbRansac) { int aK1 = NRrandom3(aVCH.size()); int aK2 = NRrandom3(aVCH.size()); int aK3 = NRrandom3(aVCH.size()); int aK4 = NRrandom3(aVCH.size()); if ( (aK1!=aK2) && (aK1!=aK3) && (aK1!=aK4) && (aK2!=aK3) && (aK2!=aK4) && (aK3!=aK4) ) { aNbRansac--; ElPackHomologue aP4; aP4.Cple_Add(aVCH[aK1]); aP4.Cple_Add(aVCH[aK2]); aP4.Cple_Add(aVCH[aK3]); aP4.Cple_Add(aVCH[aK4]); cElHomographie aSol = cElHomographie(aP4,true); double anEcart = 0; for (int aKP=0 ; aKP<int(aVCH.size()) ; aKP++) { anEcart += euclid(aSol.Direct(aVCH[aKP].P1()),aVCH[aKP].P2()); } anEcart /= aVCH.size(); if (anEcart<anEcMin) { anEcMin = anEcart; aHMin = aSol; } } } std::cout << "ECART H " << anEcMin << "\n"; return aHMin; }
ElMatrix<REAL> GlobMepRelCocentrique(double & anEcartMin,const ElPackHomologue & aPack, int aNbRansac,int aNbMaxPts) { aNbMaxPts = ElMin(aNbMaxPts,aPack.size()); std::vector<Pt3dr> aVDir1; std::vector<Pt3dr> aVDir2; cRandNParmiQ aRand(aNbMaxPts,aPack.size()); for (ElPackHomologue::tCstIter itH=aPack.begin() ; itH!=aPack.end() ; itH++) { if (aRand.GetNext()) { aVDir1.push_back(vunit(PZ1(itH->P1()))); aVDir2.push_back(vunit(PZ1(itH->P2()))); } } ElMatrix<REAL> aRes(3,3); anEcartMin = 1e60; while (aNbRansac) { int aKA = NRrandom3(aVDir1.size()); int aKB = NRrandom3(aVDir2.size()); if (aKA!=aKB) { aNbRansac--; ElMatrix<REAL> aMat = ComplemRotation(aVDir1[aKA],aVDir1[aKB],aVDir2[aKA],aVDir2[aKB]); double anEc = SomEcartDist(aMat,aVDir1,aVDir2); if (anEc<anEcartMin) { anEcartMin = anEc; aRes = aMat; } } } return aRes; }
void ReadPixSanityTest::checkRGBA(ReadPixSanityResult& r, Window& w) { DrawingSurfaceConfig& config = *r.config; RandomBitsDouble rRand(config.r, 1066); RandomBitsDouble gRand(config.g, 1492); RandomBitsDouble bRand(config.b, 1776); RandomBitsDouble aRand((config.a? config.a: 1), 1789); int thresh = 1; r.passRGBA = true; r.errRGBA = 0.0; for (int i = 0; i < 100 && r.passRGBA; ++i) { // Generate a random color and use it to clear the color buffer: float expected[4]; expected[0] = rRand.next(); expected[1] = gRand.next(); expected[2] = bRand.next(); expected[3] = aRand.next(); glClearColor(expected[0],expected[1],expected[2],expected[3]); glClear(GL_COLOR_BUFFER_BIT); // If the color buffer doesn't have an alpha channel, then // the spec requires the readback value to be 1.0: if (!config.a) expected[3] = 1.0; // Read the buffer: GLfloat buf[READPIX_SANITY_WIN_SIZE][READPIX_SANITY_WIN_SIZE][4]; glReadPixels(0, 0, READPIX_SANITY_WIN_SIZE, READPIX_SANITY_WIN_SIZE, GL_RGBA, GL_FLOAT, buf); // Now compute the error for each pixel, and record the // worst one we find: for (int y = 0; y < READPIX_SANITY_WIN_SIZE; ++y) for (int x = 0; x < READPIX_SANITY_WIN_SIZE; ++x) { GLfloat dr = abs(buf[y][x][0] - expected[0]); GLfloat dg = abs(buf[y][x][1] - expected[1]); GLfloat db = abs(buf[y][x][2] - expected[2]); GLfloat da = abs(buf[y][x][3] - expected[3]); double err = max(ErrorBits(dr, config.r), max(ErrorBits(dg, config.g), max(ErrorBits(db, config.b), ErrorBits(da, config.a? config.a: thresh+1)))); // The "thresh+1" fudge above is // needed to force the error to // be greater than the threshold // in the case where there is no // alpha channel. Without it the // error would be just equal to // the threshold, and the test // would spuriously pass. if (err > r.errRGBA) { r.xRGBA = x; r.yRGBA = y; r.errRGBA = err; for (int j = 0; j < 4; ++j) { r.expectedRGBA[j] = expected[j]; r.actualRGBA[j] = buf[y][x][j]; } } } if (r.errRGBA > thresh) r.passRGBA = false; w.swap(); } } // ReadPixSanityTest::checkRGBA