void VecFile::write(int aXSource, int aYSource, int aXTarget, int aYTarget, int aXCenter, int aYCenter, int aThickness, QGEcolor aColor, QGEoutline anOutline) { Q_UNUSED(aColor); isOpenW(); fstream_ << s_vec_prim_arc_ // primitive code << ' ' << toVecOutline(anOutline) // continuous|dashed << ' ' << aXCenter // xcenter << ' ' << aYCenter // ycenter << ' ' << qgDist(aXCenter, aYCenter, aXSource, aYSource) // radius << ' ' << qgAngleDegrees(Point(aXCenter,aYCenter), Point(aXSource,aYSource)) // source angle << ' ' << qgAngleDegrees(Point(aXCenter,aYCenter), Point(aXTarget,aYTarget)) // target angle << ' ' << aThickness // width << std::endl; }
DesShapeContext::DesShapeContext(const std::list< GenPoint<int> >& aPtList, double aRhoMax, int aRhoBinCnt, int aThetaBinCnt) : rhoMax_ (aRhoMax), rhoMaxLog_ (log(aRhoMax + 1.)), rhoBinCnt_ (aRhoBinCnt), thetaBinCnt_ (aThetaBinCnt) { // Number of given points int ptCnt = (int) aPtList.size(); // Number of bin points int binCnt = aRhoBinCnt * aThetaBinCnt; // ALLOCATE MEMORY SPACE FOR POINTS // -------------------------------- points_.reserve(ptCnt); // ALLOCATE AND SHAPE CONTEXTS // --------------------------- pShapeContexts_.reserve(ptCnt); for (int pdx = 0 ; pdx < ptCnt ; ++pdx) { // Allocate Shape Context... int* currShapeContext = new int[binCnt]; pShapeContexts_.push_back(currShapeContext); // ...and initialize it to zero qgMemSet0(currShapeContext, binCnt); } // ACCESS TO BINS // -------------- double rhoSamplingRate = rhoMaxLog_ / (double) rhoBinCnt_; double thetaSamplingRate = Math::QG_2PI / (double) thetaBinCnt_; ////////////////////////////////////////////////////////////////////////////// std::cout << std::endl << "- Nb points = " << ptCnt << std::endl << "- Taille vecteur points = " << points_.size() << std::endl << "- Taille vecteur Shape Contexts = " << pShapeContexts_.size() << std::endl << "- Nb bins pour rho = " << aRhoBinCnt << std::endl << "- Nb bins pour theta = " << aThetaBinCnt << std::endl << "- Rho max = " << rhoMax_ << std::endl << "- log(rho_max+1) = " << rhoMaxLog_ << std::endl << "- Rho sampling rate = " << rhoSamplingRate << std::endl << "- Theta sampling rate = " << thetaSamplingRate << " = " << qgRadiansToDegrees(thetaSamplingRate) << " degrees" << std::endl << std::endl; ////////////////////////////////////////////////////////////////////////////// // LOOP ON POINTS // -------------- // Let P be the current point // pIt: pointer to P // pdx: index of P in the data structures of the descriptor std::list<Point>::const_iterator pIt = aPtList.begin(); for (int pdx = 0; pdx < ptCnt; ++pdx, ++pIt) { // Save current point points_.push_back(*pIt); int pX = (*pIt).x(); int pY = (*pIt).y(); ////////////////////////////////////////////////////////////////////////////// std::cout << "pdx = " << pdx << " x=" << pX << " y=" << pY << std::endl; ////////////////////////////////////////////////////////////////////////////// // _______________________________________________________________ // // Do not compute again rho's & theta's computed in previous steps // _______________________________________________________________ // // * let pdx be the index of point P // * let qdx be the index of point Q, different from P // * let V(P,Q) stand for rho(P,Q) or theta(P,Q) // // V(P,Q) can be deduced from V(Q,P): // - rho(P,Q) == rho(Q,P) // - theta(P,Q) == (theta(Q,P) + PI) % 2PI // // * When qdx > pdx, both V(P,Q) and V(Q,P) // are computed and registered in adequate bins // * Thus, when qdx < pdx, V(P,Q) has already been // computed and registered: there is nothing to do... // _______________________________________________________________ // qIt: pointer to point Q, different from current point P // qdx: index of Q in the data structures of the descriptor std::list< GenPoint<int> >::const_iterator qIt = pIt; ++qIt; for (int qdx = pdx + 1; qdx < ptCnt ; ++qdx, ++qIt) { int qX = (*qIt).x(); int qY = (*qIt).y(); ////////////////////////////////////////////////////////////////////////////// std::cout << " qdx = " << qdx << " x=" << qX << " y=" << qY << std::endl; ////////////////////////////////////////////////////////////////////////////// // Offset (in the Shape Context table) corresponding // to bin number given by log(rho(P,Q)) int rhoOffset = thetaBinCnt_ * (int) (log(qgDist(pX, pY, qX, qY)) / rhoSamplingRate); // Theta(P,Q) double theta = qgAngle(pX, pY, qX, qY); // Register position of Q relatively to P ++(pShapeContexts_[pdx][rhoOffset + (int) (theta / thetaSamplingRate)]); ////////////////////////////////////////////////////////////////////////////// std::cout << " rho=" << qgDist(pX, pY, qX, qY) << " log(rho)= " << log(qgDist(pX, pY, qX, qY)) << " index=" << (int) (log(qgDist(pX, pY, qX, qY)) / rhoSamplingRate) << " offset=" << rhoOffset << std::endl << " theta_1=" << qgRadiansToDegrees(theta) << " index_1=" << (int) (theta / thetaSamplingRate) << std::endl; ////////////////////////////////////////////////////////////////////////////// // Theta(Q,P) if (theta > Math::QG_PI) { theta -= Math::QG_PI; } else { theta += Math::QG_PI; } // Register position of P relatively to Q ++(pShapeContexts_[qdx][rhoOffset + (int) (theta / thetaSamplingRate)]); ////////////////////////////////////////////////////////////////////////////// std::cout << " theta_2=" << qgRadiansToDegrees(theta) << " index_2=" << (int) (theta / thetaSamplingRate) << std::endl; ////////////////////////////////////////////////////////////////////////////// } // END for qdx } // END for pdx }
RWTree* RWSegmentVector::buildTree(std::vector<Point>& myChain, int fidx, int lidx, double minDeviation) { RWTree* myNode = new RWTree(fidx, lidx); // Find maximum deviation double maxDeviation = 0.0; int whereToCut = fidx; if (myChain[fidx] == myChain[lidx]) // Closed curves { Point p = myChain[fidx]; for (int i = fidx + 1 ; i < lidx ; ++i) { double d = qgDist(p, myChain[i]); if (d > maxDeviation) { whereToCut = i; maxDeviation = d; } } // If loop too small or max deviation equal to zero, forget it if ((lidx - fidx + 1) < 4 || maxDeviation < minDeviation) { delete myNode; return 0; } else // Otherwise, create a very large significance { myNode->setSignificance(RWSEGMENTVECTOR_VERY_LARGE_SIGNIFICANCE); myNode->setLeftChild(buildTree(myChain, fidx, whereToCut, minDeviation)); myNode->setRightChild(buildTree(myChain, whereToCut, lidx, minDeviation)); searchBestApproximation (myNode); return myNode; } } else // Open curves { for (int i = fidx + 1 ; i < lidx ; ++i) { double d = qgDist(myChain[i], myChain[fidx], myChain[lidx]); if (d > maxDeviation) { whereToCut = i; maxDeviation = d; } } // If loop too small or max deviation equal to zero, keep as such if ((lidx - fidx + 1) < 4 || maxDeviation < minDeviation) { myNode->setSignificance(maxDeviation / qgDist(myChain[fidx], myChain[lidx])); return myNode; } else // Otherwise, recursive call { myNode->setSignificance(maxDeviation / qgDist(myChain[fidx], myChain[lidx])); myNode->setLeftChild(buildTree(myChain, fidx, whereToCut, minDeviation)); myNode->setRightChild(buildTree(myChain, whereToCut, lidx, minDeviation)); searchBestApproximation (myNode); return myNode; } } }