void* SkMetaData::set(const char name[], const void* data, size_t dataSize, Type type, int count) { SkASSERT(name); SkASSERT(dataSize); SkASSERT(count > 0); (void)this->remove(name, type); size_t len = strlen(name); Rec* rec = Rec::Alloc(sizeof(Rec) + dataSize * count + len + 1); #ifndef SK_DEBUG rec->fType = SkToU8(type); #else rec->fType = type; #endif rec->fDataLen = SkToU8(dataSize); rec->fDataCount = SkToU16(count); if (data) memcpy(rec->data(), data, dataSize * count); memcpy(rec->name(), name, len + 1); if (kPtr_Type == type) { PtrPair* pair = (PtrPair*)rec->data(); if (pair->fProc && pair->fPtr) { pair->fPtr = pair->fProc(pair->fPtr, true); } } rec->fNext = fRec; fRec = rec; return rec->data(); }
void SkResourceCache::purgeAsNeeded(bool forcePurge) { size_t byteLimit; int countLimit; if (fDiscardableFactory) { countLimit = SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT; byteLimit = SK_MaxU32; // no limit based on bytes } else { countLimit = SK_MaxS32; // no limit based on count byteLimit = fTotalByteLimit; } Rec* rec = fTail; while (rec) { if (!forcePurge && fTotalBytesUsed < byteLimit && fCount < countLimit) { break; } Rec* prev = rec->fPrev; if (rec->canBePurged()) { this->remove(rec); } rec = prev; } }
PlayScene::PlayScene(){ //creat a scene QGraphicsScene *scene = new QGraphicsScene(); scene->setSceneRect(0,0,1024,768); scene->setBackgroundBrush(QBrush(QImage("D:/img/img/bg.png"))); //add a view QGraphicsView *view = new QGraphicsView(scene); view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setFixedSize(1024,768); //add Rec Rec *rec = new Rec(); rec->setFlag(QGraphicsItem::ItemIsFocusable); rec->setFocus(); scene->addItem(rec); BlueHit *bluehit = new BlueHit(); scene->addItem(bluehit); bluehit->setPos(80,190); //QTimer *timer = new QTimer(); //QObject::connect(timer,SIGNAL(timeout()),bluehit,SLOT(create())); Drum *drum = new Drum(); scene->addItem(drum); drum->setPos(1000,250); //show the view view->show(); }
void SkResourceCache::purgeSharedID(uint64_t sharedID) { if (0 == sharedID) { return; } #ifdef SK_TRACK_PURGE_SHAREDID_HITRATE gPurgeCallCounter += 1; bool found = false; #endif // go backwards, just like purgeAsNeeded, just to make the code similar. // could iterate either direction and still be correct. Rec* rec = fTail; while (rec) { Rec* prev = rec->fPrev; if (rec->getKey().getSharedID() == sharedID) { // SkDebugf("purgeSharedID id=%llx rec=%p\n", sharedID, rec); this->remove(rec); #ifdef SK_TRACK_PURGE_SHAREDID_HITRATE found = true; #endif } rec = prev; } #ifdef SK_TRACK_PURGE_SHAREDID_HITRATE if (found) { gPurgeHitCounter += 1; } SkDebugf("PurgeShared calls=%d hits=%d rate=%g\n", gPurgeCallCounter, gPurgeHitCounter, gPurgeHitCounter * 100.0 / gPurgeCallCounter); #endif }
bool SkMetaData::remove(const char name[], Type type) { Rec* rec = fRec; Rec* prev = nullptr; while (rec) { Rec* next = rec->fNext; if (rec->fType == type && !strcmp(rec->name(), name)) { if (prev) { prev->fNext = next; } else { fRec = next; } if (kPtr_Type == type) { PtrPair* pair = (PtrPair*)rec->data(); if (pair->fProc && pair->fPtr) { (void)pair->fProc(pair->fPtr, false); } } Rec::Free(rec); return true; } prev = rec; rec = next; } return false; }
vector<Rec> EngineRec::generateRec(vector<int> IDS){ /* * tworzy tabelę, którą później zwróci */ vector<Rec> result; /* * pętla od 0 do ilości elementów w tabeli IDS * obiekt tymczasowy typu Rec */ Rec tmp; /* * rozpoczyna liczenie czasu */ Timer count_time; count_time.start(); for (int i=0;i<IDS.size();i++) { /* * wypełnia zawartość obiektu tmp (ID i note), a następnie dodaje ten obiekt do wektora obiektów Rec */ tmp.setID(IDS[i]); tmp.setNote(Rand(1, 10)); result.push_back(tmp); } /* * zakończono liczenie czasu */ count_time.stop(); cout << "EngineRec::generateRec() czas: " << count_time.getElapsedTimeInMicroSec() << " qs \n"; /* * zwraca wypełniony wektor obiektów Rec */ return result; }
void SkResourceCache::add(Rec* rec, void* payload) { this->checkMessages(); SkASSERT(rec); // See if we already have this key (racy inserts, etc.) if (Rec** preexisting = fHash->find(rec->getKey())) { Rec* prev = *preexisting; if (prev->canBePurged()) { // if it can be purged, the install may fail, so we have to remove it this->remove(prev); } else { // if it cannot be purged, we reuse it and delete the new one prev->postAddInstall(payload); delete rec; return; } } this->addToHead(rec); fHash->set(rec); rec->postAddInstall(payload); if (gDumpCacheTransactions) { SkString bytesStr, totalStr; make_size_str(rec->bytesUsed(), &bytesStr); make_size_str(fTotalBytesUsed, &totalStr); SkDebugf("RC: add %5s %12p key %08x -- total %5s, count %d\n", bytesStr.c_str(), rec, rec->getHash(), totalStr.c_str(), fCount); } // since the new rec may push us over-budget, we perform a purge check now this->purgeAsNeeded(); }
void* SkMetaData::set(const char name[], const void* data, size_t dataSize, Type type, int count) { SkASSERT(name); SkASSERT(dataSize); SkASSERT(count > 0); (void)this->remove(name, type); size_t len = strlen(name); Rec* rec = Rec::Alloc(sizeof(Rec) + dataSize * count + len + 1); #ifndef SK_DEBUG rec->fType = SkToU8(type); #else rec->fType = type; #endif rec->fDataLen = SkToU8(dataSize); rec->fDataCount = SkToU16(count); if (data) memcpy(rec->data(), data, dataSize * count); memcpy(rec->name(), name, len + 1); #ifdef SK_DEBUG rec->fName = rec->name(); switch (type) { case kS32_Type: rec->fData.fS32 = *(const int32_t*)rec->data(); break; case kScalar_Type: rec->fData.fScalar = *(const SkScalar*)rec->data(); break; case kString_Type: rec->fData.fString = (const char*)rec->data(); break; case kPtr_Type: rec->fData.fPtr = *(void**)rec->data(); break; case kBool_Type: rec->fData.fBool = *(const bool*)rec->data(); break; default: SkASSERT(!"bad type"); break; } #endif rec->fNext = fRec; fRec = rec; return rec->data(); }
int main(){ Rec rec; Tri tri; rec.setWidth(10); rec.setHeight(20); cout << "The area is of rec: " << rec.getArea() << endl; tri.setWidth(10); tri.setHeight(20); cout << "The area is tri: " << tri.getArea() << endl; return 0; }
static void Timer_int() { if( Dev::TimerIntClear() ) { if( RoundInc(Sec_cnt,SecCnt) ) { Time_sec++; Time_clock.update(Dev::TimerClock()); } if( RoundInc(MSec_cnt,MSecCnt) ) { if( (Time_msec&511)<256 ) Dev::LightOn(1u<<3); else Dev::LightOff(1u<<3); Time_msec++; } if( RoundInc(Tick_cnt,TickCnt) ) { Task::Internal::Tick_int(); } } }
void SkMetaData::reset() { Rec* rec = fRec; while (rec) { if (kPtr_Type == rec->fType) { PtrPair* pair = (PtrPair*)rec->data(); if (pair->fProc && pair->fPtr) { pair->fPtr = pair->fProc(pair->fPtr, false); } } Rec* next = rec->fNext; Rec::Free(rec); rec = next; } fRec = nullptr; }
void extend(Rec &rec) { ulen len=random.select(rec.mem.len,rec.mem.len+rec.mem.len/2); if( rec.extend(heap,len) ) stat.count(OpExtendDone); stat.count(OpExtend); }
void shrink(Rec &rec) { ulen len=random.select(0,rec.mem.len); rec.shrink(heap,len); stat.count(OpShrink); }
Rec CombineRec(const Rec &rc1, const Rec &rc2) { if (!rc1.is_valid()) return rc2; if (!rc2.is_valid()) return rc1; Rec ret; for (int i = 0; i < DIMENSION; i++) { ret.bound[i] = std::min(rc1.bound[i], rc2.bound[i]); } for (int i = DIMENSION; i < 2 * DIMENSION; i++) { ret.bound[i] = std::max(rc1.bound[i], rc2.bound[i]); } return ret; }
virtual void run (Arg) { Rec::Mutator target; Rec& subject = target; DiffApplicator<Rec::Mutator> application(target); // Part I : apply diff to populate application.consume(populationDiff()); CHECK (!isnil (subject)); // nonempty -- content has been added CHECK ("X" == subject.getType()); // type was set to "X" CHECK (1 == subject.get("α").data.get<int>()); // has gotten our int attribute "α" CHECK (2L == subject.get("β").data.get<int64_t>()); // ... the long attribute "β" CHECK (3.45 == subject.get("γ").data.get<double>()); // ... and double attribute "γ" auto scope = subject.scope(); // look into the scope contents... CHECK ( *scope == CHILD_A); // there is CHILD_A CHECK (*++scope == CHILD_T); // followed by a copy of CHILD_T CHECK (*++scope == CHILD_T); // and another copy of CHILD_T CHECK (*++scope == MakeRec().appendChild(CHILD_B) // and there is a nested Record .appendChild(CHILD_A) // with CHILD_B .genNode(SUB_NODE.idi.getSym())); // and CHILD_A CHECK (isnil(++scope)); // thats all -- no more children // Part II : apply the second diff application.consume(mutationDiff()); CHECK (join (subject.keys()) == "α, β, γ"); // the attributes weren't altered scope = subject.scope(); // but the scope was reordered CHECK ( *scope == CHILD_T); // CHILD_T CHECK (*++scope == CHILD_A); // CHILD_A Rec nested = (++scope)->data.get<Rec>(); // and our nested Record, which too has been altered: CHECK (nested.get("γ").data.get<double>() == 3.45); // it carries now an attribute "δ", which is again CHECK (nested.get("δ") == MakeRec().appendChild(CHILD_A) // a nested Record with three children CHILD_A .appendChild(CHILD_A) // .appendChild(CHILD_A) // .genNode("δ")); // auto subScope = nested.scope(); // and within the nested sub-scope we find CHECK ( *subScope == CHILD_A); // CHILD_A CHECK (*++subScope == MakeRec().type("Y") // a yet-again nested sub-Record of type "Y" .set("β", int64_t(2)) // with just an attribute "β" == 2L .genNode(CHILD_NODE.idi.getSym())); // (and an empty child scope) CHECK (*++subScope == CHILD_T); // followed by another copy of CHILD_T CHECK (isnil (++subScope)); // CHECK (isnil (++scope)); // and nothing beyond that. }
void SkClipStack::clipDevRect(const SkRect& rect, SkRegion::Op op) { Rec* rec = (Rec*)fDeque.back(); if (rec && rec->canBeIntersected(fSaveCount, op)) { switch (rec->fState) { case Rec::kEmpty_State: return; case Rec::kRect_State: if (!rec->fRect.intersect(rect)) { rec->fState = Rec::kEmpty_State; } return; case Rec::kPath_State: if (!SkRect::Intersects(rec->fPath.getBounds(), rect)) { rec->fState = Rec::kEmpty_State; return; } break; } } new (fDeque.push_back()) Rec(fSaveCount, rect, op); }
bool SkMetaData::remove(const char name[], Type type) { Rec* rec = fRec; Rec* prev = NULL; while (rec) { Rec* next = rec->fNext; if (rec->fType == type && !strcmp(rec->name(), name)) { if (prev) prev->fNext = next; else fRec = next; Rec::Free(rec); return true; } prev = rec; rec = next; } return false; }
void SkResourceCache::purgeSharedID(uint64_t sharedID) { if (0 == sharedID) { return; } #ifdef SK_TRACK_PURGE_SHAREDID_HITRATE gPurgeCallCounter += 1; bool found = false; #endif // go backwards, just like purgeAsNeeded, just to make the code similar. // could iterate either direction and still be correct. Rec* rec = fTail; while (rec) { Rec* prev = rec->fPrev; if (rec->getKey().getSharedID() == sharedID) { // even though the "src" is now dead, caches could still be in-flight, so // we have to check if it can be removed. if (rec->canBePurged()) { this->remove(rec); } #ifdef SK_TRACK_PURGE_SHAREDID_HITRATE found = true; #endif } rec = prev; } #ifdef SK_TRACK_PURGE_SHAREDID_HITRATE if (found) { gPurgeHitCounter += 1; } SkDebugf("PurgeShared calls=%d hits=%d rate=%g\n", gPurgeCallCounter, gPurgeHitCounter, gPurgeHitCounter * 100.0 / gPurgeCallCounter); #endif }
double RecArea(const Rec &mbr) { if (!mbr.is_valid()) return 0; static const double xpi = vratio(DIMENSION); double ret = 0; double sumr = 0; for (int i = 0; i < DIMENSION; i++) { double len = (mbr.bound[i + DIMENSION] - mbr.bound[i]) / 2; sumr += len * len; } double radius = sqrt(sumr); ret = pow(radius, DIMENSION) * xpi; return ret; }
void SkDeferredCanvas::emit(const Rec& rec) { switch (rec.fType) { case kSave_Type: fCanvas->save(); this->INHERITED::willSave(); break; case kClipRect_Type: fCanvas->clipRect(rec.fData.fBounds); this->INHERITED::onClipRect(rec.fData.fBounds, SkRegion::kIntersect_Op, kHard_ClipEdgeStyle); break; case kTrans_Type: case kScaleTrans_Type: { SkMatrix mat; rec.getConcat(&mat); fCanvas->concat(mat); this->INHERITED::didConcat(mat); } break; } }
void init() { mbr.init(); child = 0; }
//============================================================================= // Main execution //============================================================================= StatusCode B2DMuNu::execute() { if (msgLevel(MSG::DEBUG)) debug() << "==> Execute" << endmsg; StatusCode sc = StatusCode::SUCCESS; //### Extract Run number and Event number ###// const LHCb::ODIN* odin = get<LHCb::ODIN>(LHCb::ODINLocation::Default); const unsigned int runNum = odin->runNumber(), evNum = odin->eventNumber(); debug() << "Run number is " << runNum << " and Event ID is " << evNum << " at time " << odin->eventTime() << endmsg; //odin->gpsTime() << endmsg; counter("EventID")++; debug() << "### Processing event number " << counter("EventID").nEntries() << " in job ###" << endmsg; setFilterPassed(true); // Mandatory. Set to true if event is accepted. //### Only run on MC data if requested ###// if (m_runMC==1) { //### Test MC data to see if event warrants reconstruction (Require B0/B- OR B0~/B+ both decaying to muons) ###// m_passEvent = 0; debug() << "Performing Analysis on MC data" << endmsg; sc = loopOnMC(); if (!sc) return sc; } if (m_passEvent==1) { debug() << "### Event number " << counter("EventID").nEntries() << " accepted for analysis buddy ###" << endmsg; counter("EventPasses")++; debug() << "Extracting daughters..." << endmsg; LHCb::Particle::ConstVector daughters = this->i_particles(); if (daughters.size()!=0) { debug() << "### There are " << daughters.size() << " possible Muons in this event (EventID " << counter("EventID").nEntries() << ") ###" << endmsg; counter("MuonsPresent")++; //### Extract muon hits and muon misid if requested ###// if (m_muHits) { const std::string& strExtra = "Extra"; Extra* extra = new Extra(strExtra, m_local); Tuple fakeTuple = nTuple("fakeMuonTuple"); sc = extra->fakeMuon(daughters, fakeTuple); Tuple hitTuple = nTuple("muonHitTuple"); sc = extra->muonChamberHits(hitTuple); delete extra; if (!sc) return sc; } //### Test - Call loopOnRec ###// const std::string& strRec = "Rec"; Rec* rec = new Rec(strRec, m_local); Tuple recAllTuple=nTuple("recAllTuple"), hitDistTuple=nTuple("muHitDistTuple"), motherTuple=nTuple("motherTuple"), candTuple=nTuple("candidateTuple"); const LHCb::RecVertex::Range prims = this->primaryVertices(); LHCb::Particle::Vector mothers = rec->loopOnRec(daughters, prims, m_motherID, recAllTuple, hitDistTuple, motherTuple, candTuple, m_runMC); delete rec; if (!sc) return sc; } else debug() << "### There are no possible muons in the event!! ###" << endmsg; debug() << "### Finishing analysis for Event number " << counter("EventID").nEntries() << " ###" << endmsg; } else { debug() << "Event rejected" << endmsg; counter("EventFails")++; } debug() << "Event fully analysed." << endmsg; return StatusCode::SUCCESS; }
float calculoDistancia(Rec<T> p_ini, Rec<T> p_fin) { if (p_ini.isPoint() && p_fin.isPoint()) { return (sqrt( pow((p_fin.p1.first - p_ini.p1.first),2) + pow((p_fin.p1.second - p_ini.p1.second),2) )); } }
void check(Rec &rec) { rec.check(heap); }
void match::domatch(std::vector<SamePoint>& resultData) { const int nBlockSize = 512; int scale = 1; int nx1, ny1, nx2, ny2, nband1, nband2; uchar *pBuf = NULL; m_pImage->Open(_bstr_t(m_szPathNameL), modeRead); m_pImage->GetCols(&nx1); m_pImage->GetRows(&ny1); m_pImage->GetBandNum(&nband1); m_pImage->Close(); m_pImage->Open(_bstr_t(m_szPathNameR), modeRead); m_pImage->GetCols(&nx2); m_pImage->GetRows(&ny2); m_pImage->GetBandNum(&nband2); m_pImage->Close(); int mincr = /*max(max(max(nx1, ny1), nx2),ny2)*/(nx1+nx2+ny1+ny2)/4; while(mincr/scale >1024) { scale *= 2; } int nxsize1 = nx1/scale; int nysize1 = ny1/scale; int nxsize2 = nx2/scale; int nysize2 = ny2/scale; m_pImage->Open(_bstr_t(m_szPathNameL), modeRead); pBuf = new uchar[nxsize1*nysize1*nband1]; m_pImage->ReadImg(0, 0, nx1, ny1, pBuf, nxsize1, nysize1, nband1, 0, 0, nxsize1, nysize1, -1, 0); m_pImage->Close(); m_pImage->CreateImg(_bstr_t("templ.tif"), modeCreate, nxsize1, nysize1, Pixel_Byte, nband1, BIL, 0, 0, 1); m_pImage->WriteImg(0, 0, nxsize1, nysize1, pBuf, nxsize1, nysize1, nband1, 0, 0, nxsize1, nysize1, -1, 0); m_pImage->Close(); delete [] pBuf; m_pImage->Open(_bstr_t(m_szPathNameR), modeRead); pBuf = new uchar[nxsize2*nysize2*nband2]; m_pImage->ReadImg(0, 0, nx2, ny2, pBuf, nxsize2, nysize2, nband2, 0, 0, nxsize2, nysize2, -1, 0); m_pImage->Close(); m_pImage->CreateImg(_bstr_t("tempr.tif"), modeCreate, nxsize2, nysize2, Pixel_Byte, nband2, BIL, 0, 0, 1); m_pImage->WriteImg(0, 0, nxsize2, nysize2, pBuf, nxsize2, nysize2, nband2, 0, 0, nxsize2, nysize2, -1, 0); m_pImage->Close(); delete []pBuf; pBuf = NULL; sl.fetchFeatures("templ.tif"); sr.fetchFeatures("tempr.tif"); /*sl.fetchFeatures(m_szPathNameL); sr.fetchFeatures(m_szPathNameR);*/ Keypoint** nbrs; kd_node* kd_root; int nsize = sl.m_listKeyPoint.size(); int nsize2 = sr.m_listKeyPoint.size(); Keypoint* feat1 = (Keypoint*)malloc(nsize*sizeof(Keypoint)); std::list<Keypoint>::iterator temIte = sl.m_listKeyPoint.begin(); int i = 0; while(temIte != sl.m_listKeyPoint.end()) { feat1[i] = *temIte; ++i; ++temIte; } sl.m_listKeyPoint.clear(); Keypoint* feat2 = (Keypoint*)malloc(nsize2*sizeof(Keypoint)); temIte = sr.m_listKeyPoint.begin(); i = 0; while(temIte != sr.m_listKeyPoint.end()) { feat2[i] = *temIte; ++i; ++temIte; } sr.m_listKeyPoint.clear(); kd_root = kdtree_build(feat2, nsize2); int k = 0; double d0, d1; Keypoint* feat; int matchnum = 0; std::vector<SamePoint> sp; for (i = 0; i < nsize; ++i) { feat = feat1+i; k = kdtree_bbf_knn(kd_root, feat, 2, &nbrs, KDTREE_BBF_MAX_NN_CHKS); if (k == 2) { d0 = descr_dist_sq(feat, nbrs[0]); d1 = descr_dist_sq(feat, nbrs[1]); if (d0 < d1*NN_SQ_DIST_RATIO_THR) { sp.push_back(SamePoint(feat->dx, feat->dy, nbrs[0]->dx, nbrs[0]->dy)); ++matchnum; } } free(nbrs); } kdtree_release(kd_root); free(feat1); free(feat2); feat1 = NULL; feat2 = NULL; std::vector<double> matParameters; MatParamEstimator mpEstimator(5); int numForEstimate = 3; mpEstimator.leastSquaresEstimate(sp, matParameters); double usedData = Ransac<SamePoint, double>::compute(matParameters, &mpEstimator, sp, numForEstimate, resultData); sp.swap(std::vector<SamePoint>()); resultData.swap(std::vector<SamePoint>()); Pt lLeftTop(0, 0); Pt lRightBottom(nx1, ny1); double a = matParameters[0]; double b = matParameters[1]; double c = matParameters[2]*scale; double d = matParameters[3]; double e = matParameters[4]; double f = matParameters[5]*scale; std::list<Block> listDataBlock; for (int y = 0; y < ny1;) { if (y+nBlockSize < ny1) { for (int x = 0; x < nx1;) { if (x+nBlockSize < nx1) { Rec rect(a*x+b*y+c, a*(x+nBlockSize)+b*y+c, d*x+e*y+f, d*x+e*(y+nBlockSize)+f); if (rect.Intersects(Rec(0, nx2, 0, ny2))) { listDataBlock.push_back(Block(NULL, x, y, nBlockSize, nBlockSize)); } x += nBlockSize; } else { Rec rect(a*x+b*y+c, a*nx1+b*y+c, d*x+e*y+f, d*x+e*(y+nBlockSize)+f); if (rect.Intersects(Rec(0, nx2, 0, ny2))) { listDataBlock.push_back(Block(NULL, x, y, nx1-x, nBlockSize)); } x = nx1; } } y += nBlockSize; } else { for (int x = 0; x < nx1;) { if (x+nBlockSize < nx1) { Rec rect(a*x+b*y+c, a*(x+nBlockSize)+b*y+c, d*x+e*y+f, d*x+e*ny1+f); if (rect.Intersects(Rec(0, nx2, 0, ny2))) { listDataBlock.push_back(Block(NULL, x, y, nBlockSize, ny1-y)); } x += nBlockSize; } else { Rec rect(a*x+b*y+c, a*nx1+b*y+c, d*x+e*y+f, d*x+e*ny1+f); if (rect.Intersects(Rec(0, nx2, 0, ny2))) { listDataBlock.push_back(Block(NULL, x, y, nx1-x, ny1-y)); } x = nx1; } } y = ny1; } } int nBlockNumx = (nx2+nBlockSize-1)/nBlockSize; int nBlockNumy = (ny2+nBlockSize-1)/nBlockSize; int nBlockNum = nBlockNumx*nBlockNumy; std::vector<RBTree> vecKDTree(nBlockNum); std::list<Block>::iterator blockIte = listDataBlock.begin(); m_pImage->Open(_bstr_t(m_szPathNameL), modeRead); m_pImage2->Open(_bstr_t(m_szPathNameR), modeRead); int countblock = 0; std::list<SamePoint> listSP; std::vector<Keypoint> feature; std::vector<Keypoint> feature2; while(blockIte != listDataBlock.end()) { pBuf = new uchar[blockIte->nXSize*blockIte->nYSize*nband1]; m_pImage->ReadImg(blockIte->nXOrigin, blockIte->nYOrigin, blockIte->nXOrigin+blockIte->nXSize, blockIte->nYOrigin+blockIte->nYSize, pBuf, blockIte->nXSize, blockIte->nYSize, nband1, 0, 0, blockIte->nXSize, blockIte->nYSize, -1, 0); pixel_t* p = new pixel_t[blockIte->nXSize*blockIte->nYSize]; for (int y = 0; y < blockIte->nYSize; ++y) { for (int x = 0, m = 0; x < blockIte->nXSize*nband1; x += nband1, ++m) { double sum = 0; for (int n = 0; n < nband1; ++n) { sum += pBuf[y*blockIte->nXSize*nband1+x+n]; } p[y*blockIte->nXSize+m] = sum/(nband1*225.0); } } delete []pBuf; pBuf = NULL; sift(p, feature, blockIte->nXSize, blockIte->nYSize); p = NULL; std::vector<Keypoint>::iterator feaIte = feature.begin(); int count = 0; while(feaIte != feature.end()) { std::cout<<countblock<<"/"<<listDataBlock.size()<<":"<<count<<"/"<<feature.size()<<":"<<listSP.size()<<std::endl; ++count; feaIte->dx += blockIte->nXOrigin; feaIte->dy += blockIte->nYOrigin; int calx = int(feaIte->dx*a+feaIte->dy*b+c); int caly = int(feaIte->dx*d+feaIte->dy*e+f); int idx = calx/nBlockSize; int idy = caly/nBlockSize; if (idx >= nBlockNumx || idy >= nBlockNumy) { ++feaIte; continue; } int nBlockIndex = idy*nBlockNumx+idx; if (vecKDTree[nBlockIndex].num != 0 && vecKDTree[nBlockIndex].num < 50) { ++feaIte; continue; } if (vecKDTree[nBlockIndex].node == NULL) { int xo = idx*nBlockSize; int yo = idy*nBlockSize; int xsize = nBlockSize; int ysize = nBlockSize; if (idx == nBlockNumx-1) { xsize = nx2%nBlockSize; if (xsize == 0) { xsize = nBlockSize; } } if (idy == nBlockNumy-1) { ysize = ny2%nBlockSize; if (ysize == 0) { ysize = nBlockSize; } } pBuf = new uchar[xsize*ysize*nband2]; m_pImage2->ReadImg(xo, yo, xo+xsize, yo+ysize, pBuf, xsize, ysize, nband2, 0, 0, xsize, ysize, -1, 0); p = new pixel_t[xsize*ysize]; for(int y = 0; y < ysize; ++y) { for (int x = 0, m = 0; x < xsize*nband2; x += nband2, ++m) { double sum = 0; for (int n = 0; n < nband2; ++n) { sum += pBuf[y*xsize*nband2+x+n]; } p[y*xsize+m] = sum/(nband2*255.0); } } delete []pBuf; pBuf = NULL; sift(p, feature2, xsize, ysize); p = NULL; int nf2 = feature2.size(); vecKDTree[nBlockIndex].num = nf2; if (nf2 < 50) { ++feaIte; continue; } feat2 = (Keypoint*)malloc(nf2*sizeof(Keypoint)); std::vector<Keypoint>::iterator kIte2 = feature2.begin(); i = 0; while(kIte2 != feature2.end()) { kIte2->dx += xo; kIte2->dy += yo; feat2[i] = *kIte2; ++i; ++kIte2; } feature2.swap(std::vector<Keypoint>()); kd_root = kdtree_build(feat2, nf2); vecKDTree[nBlockIndex].node = kd_root; vecKDTree[nBlockIndex].feature = feat2; } k = kdtree_bbf_knn(vecKDTree[nBlockIndex].node, &(*feaIte), 2, &nbrs, KDTREE_BBF_MAX_NN_CHKS); if (k == 2) { d0 = descr_dist_sq(&(*feaIte), nbrs[0]); d1 = descr_dist_sq(&(*feaIte), nbrs[1]); if (d0 < d1*NN_SQ_DIST_RATIO_THR) { listSP.push_back(SamePoint(feaIte->dx, feaIte->dy, nbrs[0]->dx, nbrs[0]->dy)); } } free(nbrs); ++feaIte; } feature.swap(std::vector<Keypoint>()); std::vector<RBTree>::iterator kdIte = vecKDTree.begin(); while(kdIte != vecKDTree.end()) { if (kdIte->node != NULL) { free(kdIte->node); kdIte->node = NULL; free(kdIte->feature); kdIte->feature = NULL; } ++kdIte; } ++countblock; ++blockIte; } m_pImage->Close(); m_pImage2->Close(); std::vector<SamePoint> vecsp(std::make_move_iterator(std::begin(listSP)), std::make_move_iterator(std::end(listSP))); listSP.clear(); sp.swap(vecsp); mpEstimator.leastSquaresEstimate(sp, matParameters); if (sp.size() < 500) { usedData = Ransac<SamePoint, double>::compute(matParameters, &mpEstimator, sp, numForEstimate, resultData); } else { usedData = Ransac<SamePoint, double>::compute(matParameters, &mpEstimator, sp, numForEstimate, 0.5, 0.8, resultData); } std::cout<<usedData<<":"<<resultData.size()<<std::endl; sp.swap(std::vector<SamePoint>()); resultData.swap(std::vector<SamePoint>()); a = matParameters[0]; b = matParameters[1]; c = matParameters[2]; d = matParameters[3]; e = matParameters[4]; f = matParameters[5]; //mosaic Pt calrLeftTop; Pt calrRightBottom; calrLeftTop.x = lLeftTop.x*a+lLeftTop.y*b+c; calrLeftTop.y = lLeftTop.x*d+lLeftTop.y*e+f; calrRightBottom.x = lRightBottom.x*a+lRightBottom.y*b+c; calrRightBottom.y = lRightBottom.x*d+lRightBottom.y*e+f; Rec calRight(calrLeftTop.x, calrRightBottom.x, calrLeftTop.y, calrRightBottom.y); calRight.extend(); Rec Right(0, nx2, 0, ny2); Rec resultRec = Right.Union(calRight); Rec resultRectR = calRight.Intersected(Right); resultRectR.extend(); Pt callLeftTop; Pt callRightBottom; callLeftTop.y = (d/a*resultRectR.left-resultRectR.top+f-c*d/a)/(b*d/a-e); callLeftTop.x = (resultRectR.left-b*callLeftTop.y-c)/a; callRightBottom.y = (d/a*resultRectR.right-resultRectR.bottom+f-c*d/a)/(b*d/a-e); callRightBottom.x = (resultRectR.right-b*callRightBottom.y-c)/a; Rec resultRectL(callLeftTop.x, callRightBottom.x, callLeftTop.y, callRightBottom.y); resultRectL.extend(); m_pImage->CreateImg(_bstr_t("result.tif"), modeCreate, (int)resultRec.Width(), (int)resultRec.Height(), Pixel_Byte, nband1, BIL, 0, 0, 1); IImage* pImage = NULL; IImage* pImage2 = NULL; ::CoCreateInstance(CLSID_ImageDriver, NULL, CLSCTX_ALL, IID_IImage, (void**)&pImage); ::CoCreateInstance(CLSID_ImageDriver, NULL, CLSCTX_ALL, IID_IImage, (void**)&pImage2); pImage->Open(_bstr_t(m_szPathNameR), modeRead); pBuf = new uchar[nx2*nBlockSize*nband2]; for (int i = 0; i < ny2;) { if (i + nBlockSize < ny2) { pImage->ReadImg(0, i, nx2, i+nBlockSize, pBuf, nx2, nBlockSize, nband2, 0, 0, nx2, nBlockSize, -1, 0); m_pImage->WriteImg(int(0-resultRec.left), int(i-resultRec.top), int(nx2-resultRec.left), int(i+nBlockSize-resultRec.top), pBuf, nx2, nBlockSize, nband2, 0, 0, nx2, nBlockSize, -1, 0); i += nBlockSize; } else { pImage->ReadImg(0, i, nx2, ny2, pBuf, nx2, nBlockSize, nband2, 0, 0, nx2, ny2-i, -1, 0); m_pImage->WriteImg(int(0-resultRec.left), int(i-resultRec.top), int(nx2-resultRec.left), int(ny2-resultRec.top), pBuf, nx2, nBlockSize, nband2, 0, 0, nx2, ny2-i, -1, 0); i = ny2; } } pImage->Close(); delete []pBuf; pImage->Open(_bstr_t(m_szPathNameL), modeRead); pBuf = new uchar[nx1*nBlockSize*nband1]; for (int i = 0; i < calRight.Height();) { if (i+nBlockSize < calRight.Height()) { pImage->ReadImg(0, i, nx1, i+nBlockSize, pBuf, nx1, nBlockSize, nband1, 0, 0, nx1, nBlockSize, -1, 0); m_pImage->WriteImg(int(calRight.left-resultRec.left), int(calRight.top+i-resultRec.top), int(calRight.right-resultRec.left), int(calRight.top+i+nBlockSize-resultRec.top), pBuf, nx1, nBlockSize, nband1, 0, 0, nx1, nBlockSize, -1, 0); i += nBlockSize; } else { pImage->ReadImg(0, i, nx1, ny1, pBuf, nx1, nBlockSize, nband1, 0, 0, nx1, ny1-i, -1, 0); m_pImage->WriteImg(int(calRight.left-resultRec.left), int(calRight.top+i-resultRec.top), int(calRight.right-resultRec.left), int(calRight.bottom-resultRec.top), pBuf, nx1, nBlockSize, nband1, 0, 0, nx1, ny1-i, -1, 0); i = (int)calRight.Height(); } } pImage->Close(); delete []pBuf; pBuf = NULL; m_pImage->Close(); pImage->Open(_bstr_t(m_szPathNameL), modeRead); pImage2->Open(_bstr_t(m_szPathNameR), modeRead); m_pImage->Open(_bstr_t("result.tif"), modeReadWrite); pBuf = new uchar[nband1*(int)resultRectR.Width()*(int)resultRectR.Height()]; m_pImage->ReadImg(int(resultRectR.left-resultRec.left), int(resultRectR.top-resultRec.top), int(resultRectR.right-resultRec.left), int(resultRectR.bottom-resultRec.top), pBuf, (int)resultRectR.Width(), (int)resultRectR.Height(), nband1, 0, 0, (int)resultRectR.Width(), (int)resultRectR.Height(), -1, 0); uchar* pBufl = new uchar[nband1*(int)resultRectL.Width()*(int)resultRectL.Height()]; pImage->ReadImg((int)resultRectL.left, (int)resultRectL.top, (int)resultRectL.right, (int)resultRectL.bottom, pBufl, (int)resultRectL.Width(), (int) resultRectL.Height(), nband1, 0, 0, (int)resultRectL.Width(), (int)resultRectL.Height(), -1, 0); uchar* pBufr = new uchar[nband2*(int)resultRectR.Width()*(int)resultRectR.Height()]; pImage2->ReadImg((int)resultRectR.left, (int)resultRectR.top, (int)resultRectR.right, (int)resultRectR.bottom, pBufr, (int)resultRectR.Width(), (int)resultRectR.Height(), nband2, 0, 0, (int)resultRectR.Width(), (int)resultRectR.Height(), -1, 0); double lx, ly; for (int y = 0; y < (int)resultRectR.Height(); ++y) { for (int x = 0; x < (int)resultRectR.Width()*nband1; x += nband1) { ly = (d/a*(x+resultRectR.left)-(y+resultRectR.top)+f-c*d/a)/(b*d/a-e); lx = ((x+resultRectR.left)-b*ly-c)/a; if (ly < resultRectL.top || lx < resultRectL.left) { continue; } if (pBufl[(int)(ly-resultRectL.top)*(int)resultRectL.Width()*nband1+(int)(lx-resultRectL.left)] < 20 && pBufl[(int)(ly-resultRectL.top)*(int)resultRectL.Width()*nband1+(int)(lx-resultRectL.left)+1] < 20 && pBufl[(int)(ly-resultRectL.top)*(int)resultRectL.Width()*nband1+(int)(lx-resultRectL.left)+2] < 20) { for (int n = 0; n < nband2; ++n) { pBuf[y*(int)resultRectR.Width()*nband1+x+n] = pBufr[y*(int)resultRectR.Width()*nband2+x+n]; } } else if (pBufr[y*(int)resultRectR.Width()*nband1+x] < 20 && pBufr[y*(int)resultRectR.Width()*nband1+x+1]<20 && pBufr[y*(int)resultRectR.Width()*nband1+x+2]<20) { for (int n = 0; n < nband1; ++n) { pBuf[y*(int)resultRectR.Width()*nband1+x+n] = pBufl[(int)(ly-resultRectL.top)*(int)resultRectL.Width()*nband1+(int)(lx-resultRectL.left)+n]; } } else { for (int n = 0; n < nband1; ++n) { pBuf[y*(int)resultRectR.Width()*nband1+x+n] = (pBufl[(int)(ly-resultRectL.top)*(int)resultRectL.Width()*nband1+(int)(lx-resultRectL.left)+n] + pBufr[y*(int)resultRectR.Width()*nband2+x+n])/2; } } } } delete []pBufl; pBufl = NULL; delete []pBufr; pBufr = NULL; m_pImage->WriteImg(int(resultRectR.left-resultRec.left), int(resultRectR.top-resultRec.top), int(resultRectR.right-resultRec.left), int(resultRectR.bottom-resultRec.top), pBuf, (int)resultRectR.Width(), (int)resultRectR.Height(), nband1, 0, 0, (int)resultRectR.Width(), (int)resultRectR.Height(), -1, 0); delete []pBuf; pBuf = NULL; m_pImage->Close(); }
LargePhylip::LargePhylip(const char* filename) : m_fm(filename, boost::interprocess::read_only), m_fileSize(0), m_buf(0), m_nTaxa(0), m_seqLen(0), m_maxNameLen(0) { //m_fd = open( filename, O_RDONLY ); { std::ifstream ist(filename); ist.seekg(0, std::ios::end); m_fileSize = ist.tellg(); } // printf( "size: %zd\n", m_fileSize ); map(); off_t ptr = 0; bool haveHeader = false; std::vector<Rec>::iterator currec; // When all you have is a hammer, everything looks like a nail while ( ptr < m_fileSize ) { off_t spos = ptr; // FIXME: this assumes left to right execution of the expression! while ( ptr < m_fileSize && m_buf[ptr] != '\n' ) { ptr++; } // ptr currently points to the newline (or the first position past the EOF). // in the non-EOF case this is one position before the current mbuf.position() // u1_t *line = &m_buf[spos]; size_t lineLen = ptr - spos; // advance ptr past newline (=beginning of next line) ptr++; if ( !haveHeader ) { Rec rec; // printf( "ll: %d %d %d\n", lineLen, spos, ptr ); interpret( spos, lineLen, rec ); std::string name = rec.getName(m_buf); std::string data = rec.getData(m_buf); // printf( "header: %s %s\n", name.c_str(), data.c_str() ); haveHeader = true; m_nTaxa = atoi( name.c_str() ); m_seqLen = atoi( data.c_str() ); m_recs.resize( m_nTaxa ); currec = m_recs.begin(); } else { if ( lineLen > 0 ) { interpret(spos, lineLen, *currec ); std::string n = (*currec).getName(m_buf); size_t idx = currec - m_recs.begin(); if ( m_nameMap.find( n ) != m_nameMap.end() ) { std::stringstream out; out << idx; n = out.str(); } m_nameMap[n] = idx; m_maxNameLen = std::max( m_maxNameLen, int(n.length()) ); ++currec; } } } assert( currec == m_recs.end() ); // print(); }
static ClockTimeType GetClockTime() noexcept { Dev::IntLock lock; return Time_clock.update(Dev::TimerClock()); }