int scanForEdge(int first,int last){ //direction parameters for edge tracking //moves to first edge location int i; scanRegion(first,last); direction=(rsigns[nstep-1]-rsigns[0])/2; //is it getting brighter or darker? if(last<first) direction*=-1; i=0; while(direction*(threshold-readings[i])>0) i++; return(first+i*step); }
int scanForLine(int first,int last){ //looks for transition //assumes line is brighter int i; int rmax,imax; scanRegion(first,last); rmax=-10000; for(i=0;i<nstep;i++){ if(readings[i]>rmax) { imax=i; rmax=readings[i]; } } threshold=(rmax+avgM)/2; //adjustment for thin line (average of peak can be depressed) return(first+imax*step);//returns location of max }
void stroke_autofill_learn(const TVectorImageP &imgToLearn, TStroke *stroke) { if (!imgToLearn || !stroke || stroke->getControlPointCount() == 0) return; TVectorImage appImg; TStroke *appStroke = new TStroke(*stroke); appImg.addStroke(appStroke); appImg.findRegions(); double pbx, pby; double totalArea = 0; pbx = pby = 0; if (!regionsReference.isEmpty()) regionsReference.clear(); int i, j, index = 0; for (i = 0; i < (int)imgToLearn->getRegionCount(); i++) { TRegion *currentRegion = imgToLearn->getRegion(i); for (j = 0; j < (int)appImg.getRegionCount(); j++) { TRegion *region = appImg.getRegion(j); if (contains(region, currentRegion)) { scanRegion(currentRegion, index, regionsReference, region->getBBox()); index++; int k, subRegionCount = currentRegion->getSubregionCount(); for (k = 0; k < subRegionCount; k++) { TRegion *subRegion = currentRegion->getSubregion(k); if (contains(region, subRegion)) scanSubRegion(subRegion, index, regionsReference, region->getBBox()); } } } } QMap<int, Region>::Iterator it; for (it = regionsReference.begin(); it != regionsReference.end(); it++) { pbx += it.value().m_barycentre.x; pby += it.value().m_barycentre.y; totalArea += it.value().m_area; } if (totalArea > 0) referenceB = TPointD(pbx / totalArea, pby / totalArea); else referenceB = TPointD(0.0, 0.0); }
bool do_card_ptr(jbyte* card_ptr, int worker_i) { // Construct the region representing the card. HeapWord* start = _ct_bs->addr_for(card_ptr); // And find the region containing it. HeapRegion* r = _g1->heap_region_containing(start); assert(r != NULL, "unexpected null"); // Scan oops in the card looking for references into the collection set HeapWord* end = _ct_bs->addr_for(card_ptr + 1); MemRegion scanRegion(start, end); UpdateRSetImmediate update_rs_cl(_g1->g1_rem_set()); FilterIntoCSClosure update_rs_cset_oop_cl(NULL, _g1, &update_rs_cl); FilterOutOfRegionClosure filter_then_update_rs_cset_oop_cl(r, &update_rs_cset_oop_cl); // We can pass false as the "filter_young" parameter here as: // * we should be in a STW pause, // * the DCQS to which this closure is applied is used to hold // references that point into the collection set from the prior // RSet updating, // * the post-write barrier shouldn't be logging updates to young // regions (but there is a situation where this can happen - see // the comment in G1RemSet::concurrentRefineOneCard below - // that should not be applicable here), and // * during actual RSet updating, the filtering of cards in young // regions in HeapRegion::oops_on_card_seq_iterate_careful is // employed. // As a result, when this closure is applied to "refs into cset" // DCQS, we shouldn't see any cards in young regions. update_rs_cl.set_region(r); HeapWord* stop_point = r->oops_on_card_seq_iterate_careful(scanRegion, &filter_then_update_rs_cset_oop_cl, false /* filter_young */); // Since this is performed in the event of an evacuation failure, we // we shouldn't see a non-null stop point assert(stop_point == NULL, "saw an unallocated region"); return true; }
void rect_autofill_learn(const TVectorImageP &imgToLearn, const TRectD &rect) { if (rect.getLx() * rect.getLy() < MIN_SIZE) return; double pbx, pby; double totalArea = 0; pbx = pby = 0; if (!regionsReference.isEmpty()) regionsReference.clear(); int i, index = 0, regionCount = imgToLearn->getRegionCount(); for (i = 0; i < regionCount; i++) { TRegion *region = imgToLearn->getRegion(i); if (rect.contains(region->getBBox())) { scanRegion(region, index, regionsReference, rect); index++; } int j, subRegionCount = region->getSubregionCount(); for (j = 0; j < subRegionCount; j++) { TRegion *subRegion = region->getSubregion(j); if (rect.contains(subRegion->getBBox())) scanSubRegion(subRegion, index, regionsReference, rect); } } QMap<int, Region>::Iterator it; for (it = regionsReference.begin(); it != regionsReference.end(); it++) { pbx += it.value().m_barycentre.x; pby += it.value().m_barycentre.y; totalArea += it.value().m_area; } if (totalArea > 0) referenceB = TPointD(pbx / totalArea, pby / totalArea); else referenceB = TPointD(0.0, 0.0); }
bool stroke_autofill_apply(const TVectorImageP &imgToApply, TStroke *stroke, bool selective) { if (!imgToApply || !stroke || stroke->getControlPointCount() == 0) return false; TVectorImage appImg; TStroke *appStroke = new TStroke(*stroke); appImg.addStroke(appStroke); appImg.findRegions(); if (regionsReference.size() <= 0) return false; double pbx, pby; double totalArea = 0; pbx = pby = 0.0; if (!regionsWork.isEmpty()) regionsWork.clear(); int i, j, index = 0; for (i = 0; i < (int)imgToApply->getRegionCount(); i++) { TRegion *currentRegion = imgToApply->getRegion(i); for (j = 0; j < (int)appImg.getRegionCount(); j++) { TRegion *region = appImg.getRegion(j); if (contains(region, currentRegion)) { scanRegion(currentRegion, index, regionsWork, region->getBBox()); index++; int k, subRegionCount = currentRegion->getSubregionCount(); for (k = 0; k < subRegionCount; k++) { TRegion *subRegion = currentRegion->getSubregion(k); if (contains(region, subRegion)) scanSubRegion(subRegion, index, regionsWork, region->getBBox()); } } } } if (regionsWork.size() <= 0) return false; QMap<int, Region>::Iterator it; for (it = regionsWork.begin(); it != regionsWork.end(); it++) { pbx += it.value().m_barycentre.x; pby += it.value().m_barycentre.y; totalArea += it.value().m_area; } workB = TPointD(pbx / totalArea, pby / totalArea); std::vector<MatchingProbs> probVector; RegionDataList::Iterator refIt, workIt; for (refIt = regionsReference.begin(); refIt != regionsReference.end(); refIt++) for (workIt = regionsWork.begin(); workIt != regionsWork.end(); workIt++) assignProbs(probVector, refIt.value(), workIt.value(), refIt.key(), workIt.key()); bool filledRegions = false; for (refIt = regionsReference.begin(); refIt != regionsReference.end(); refIt++) { int to = 0, from = 0; int valore = 0; do valore = match(probVector, from, to); while ((regionsWork[to].m_match != -1 || regionsReference[from].m_match != -1) && valore > 0); if (valore > AMB_TRESH) { regionsWork[to].m_match = from; regionsReference[from].m_match = to; regionsWork[to].m_styleId = regionsReference[from].m_styleId; TRegion *reg = regionsWork[to].m_region; if (reg && (!selective || selective && reg->getStyle() == 0)) { reg->setStyle(regionsWork[to].m_styleId); filledRegions = true; } } } return filledRegions; }
bool rect_autofill_apply(const TVectorImageP &imgToApply, const TRectD &rect, bool selective) { if (rect.getLx() * rect.getLy() < MIN_SIZE) return false; if (regionsReference.size() <= 0) return false; double pbx, pby; double totalArea = 0; pbx = pby = 0.0; if (!regionsWork.isEmpty()) regionsWork.clear(); int i, index = 0, regionCount = imgToApply->getRegionCount(); for (i = 0; i < regionCount; i++) { TRegion *region = imgToApply->getRegion(i); TRectD bbox = region->getBBox(); if (rect.contains(bbox)) { scanRegion(region, index, regionsWork, rect); index++; } int j, subRegionCount = region->getSubregionCount(); for (j = 0; j < subRegionCount; j++) { TRegion *subRegion = region->getSubregion(j); if (rect.contains(subRegion->getBBox())) scanSubRegion(subRegion, index, regionsWork, rect); } } if (regionsWork.size() <= 0) return false; QMap<int, Region>::Iterator it; for (it = regionsWork.begin(); it != regionsWork.end(); it++) { pbx += it.value().m_barycentre.x; pby += it.value().m_barycentre.y; totalArea += it.value().m_area; } workB = TPointD(pbx / totalArea, pby / totalArea); std::vector<MatchingProbs> probVector; RegionDataList::Iterator refIt, workIt; for (refIt = regionsReference.begin(); refIt != regionsReference.end(); refIt++) for (workIt = regionsWork.begin(); workIt != regionsWork.end(); workIt++) assignProbs(probVector, refIt.value(), workIt.value(), refIt.key(), workIt.key()); bool filledRegions = false; for (refIt = regionsReference.begin(); refIt != regionsReference.end(); refIt++) { int to = 0, from = 0; int valore = 0; do valore = match(probVector, from, to); while ((regionsWork[to].m_match != -1 || regionsReference[from].m_match != -1) && valore > 0); if (valore > AMB_TRESH) { regionsWork[to].m_match = from; regionsReference[from].m_match = to; regionsWork[to].m_styleId = regionsReference[from].m_styleId; TRegion *reg = regionsWork[to].m_region; if (reg && (!selective || selective && reg->getStyle() == 0)) { reg->setStyle(regionsWork[to].m_styleId); filledRegions = true; } } } return filledRegions; }