示例#1
0
void TextSpan::DrawContentsInRegions(const Regions& rgns, const Point& offset) const
{
	size_t charsPrinted = 0;
	Regions::const_iterator rit = rgns.begin();
	for (; rit != rgns.end(); ++rit) {
		Region drawRect = *rit;
		drawRect.x += offset.x;
		drawRect.y += offset.y;
		const Font* printFont = font;
		Palette* printPalette = palette;
		TextContainer* container = dynamic_cast<TextContainer*>(parent);
		if (printFont == NULL && container) {
			printFont = container->TextFont();
		}
		if (printPalette == NULL && container) {
			printPalette = container->TextPalette();
		}
		assert(printFont && printPalette);
#if (DEBUG_TEXT)
		// FIXME: this shouldnt happen, but it does (BG2 belt03 unidentified).
		// for now only assert when DEBUG_TEXT is set
		// the situation is benign and nothing even looks wrong because all that this means is that there was more space allocated than was actually needed
		assert(charsPrinted < text.length());
		core->GetVideoDriver()->DrawRect(drawRect, ColorRed, true);
#endif
		charsPrinted += printFont->Print(drawRect, text.substr(charsPrinted), printPalette, IE_FONT_ALIGN_LEFT);
#if (DEBUG_TEXT)
		core->GetVideoDriver()->DrawRect(drawRect, ColorWhite, false);
#endif
	}
}
void RegionFileLoader::LoadDataFromFile(std::ifstream &file)
{
    if (file.fail())
    {
        std::cerr << "Error <RegionFileLoader::LoadDataFromFile> File is unreadable" <<  std::endl;
        return;
    }

    Double_t sa;
    std::string aline;
    std::stringstream ss;
    while(1)
    {
        std::getline(file,aline);
        if ( FileIsNotOkay(file) )
            break;
        else if ( LineShouldBeSkipped(aline) )
            continue;
        else if ( BeginningOfRegions(aline) )
        {
//            std::cout << aline << std::endl;
            Regions regions = ReadRegions(file);
            if (regions.size()>0)
                fTheRegions.push_back(regions);
        }
    }

    file.close();

}
示例#3
0
Regions Content::LayoutForPointInRegion(Point p, const Region& rgn) const
{
	Region layoutRgn = Region(rgn.Origin() + p, frame.Dimensions());

	Regions rgns;
	rgns.push_back(layoutRgn);
	return rgns;
}
示例#4
0
Regions ContentContainer::LayoutForPointInRegion(Point p, const Region&) const
{
	Region layoutRgn(p, ContentFrame());
	parentOffset = p;

	Regions rgns;
	rgns.push_back(layoutRgn);
	return rgns;
}
示例#5
0
bool borderVAny( const Regions& rs, mfxU32 i,mfxU32 j )
{
	bool ret = false;
	Regions::const_iterator it = rs.begin();
	while(!ret && it != rs.end() )
		ret = (it++)->onBorderV(i,j);

	return ret;
}
Regions RegionFileLoader::ReadRegions(std::ifstream& f)
{
    Regions regions;
    std::vector<Double_t> vec;
    Char_t next_char;
    std::stringstream ss;
    Double_t sa;

    std::string aline;
    while (1)
    {
        f >> std::ws;
        next_char = f.peek();
        // check to see if the next is a number,
        // if so, this function is done break
        if ( ! IsNumber(next_char) )
        {
            break;
        }

        std::getline(f,aline);
        ss.clear(); ss.str("");
        vec.clear();

        ss << aline;
        ss >> sa;
        while(!ss.fail())
        {
            vec.push_back(sa);
            ss >> sa;
        }

//        std::cout << vec.size() << std::endl;
        if (vec.size() == 8)
        {
            Region region;
            region.grid_xlow = vec[0];
            region.cntr_xlow = vec[1];

            region.grid_xhigh = vec[2];
            region.cntr_xhigh = vec[3];

            region.grid_ylow = vec[4];
            region.cntr_ylow = vec[5];

            region.grid_yhigh = vec[6];
            region.cntr_yhigh = vec[7];

//            std::cout << "filling current region" << std::endl;
            regions.push_back(region);
        }
    }

    return regions;
}
示例#7
0
std::pair<bool, std::string> insideAny( const Regions& rs, mfxU32 i,mfxU32 j )
{
	std::pair<bool, std::string> ret = std::make_pair( false, std::string("") );
	Regions::const_iterator it = rs.begin();
	while(!ret.first && it != rs.end() )
	{
		if( it->inside(i,j) )
			ret = std::make_pair( true, it->m_name );
		++it;
	}
	return ret;
}
示例#8
0
void ContentContainer::DrawContentsInRegions(const Regions& rgns, const Point& offset) const
{
	// layout shouldn't be empty unless there is no content anyway...
	if (layout.empty()) return;

	// should only have 1 region
	const Region& rgn = rgns.front();

	// TODO: intersect with the screen clip so we can bail out even earlier

	const Point& drawOrigin = rgn.Origin();
	Point drawPoint = drawOrigin;
	ContentLayout::const_iterator it = layout.begin();

#if (DEBUG_TEXT)
	Region dr(parentOffset + offset, contentBounds);
	core->GetVideoDriver()->DrawRect(dr, ColorRed, true);
	core->GetVideoDriver()->DrawRect(dr, ColorWhite, false);
	dr = Region(parentOffset + offset, ContentFrame());
	core->GetVideoDriver()->DrawRect(dr, ColorGreen, true);
	core->GetVideoDriver()->DrawRect(dr, ColorWhite, false);
#endif

	for (; it != layout.end(); ++it) {
		const Layout& l = *it;
		assert(drawPoint.x <= drawOrigin.x + frame.w);
		l.content->DrawContentsInRegions(l.regions, offset + parentOffset);
	}
}
Double_t RegionIntegratorMultiDim::RegionIntegral(const ROOT::Math::IMultiGenFunction &f, const Regions &reg)
{
    Double_t result = 0;
    Double_t xlow[2], xhigh[2];
    for (UInt_t i=0; i<reg.size(); i++)
    {
        if (fUseCenters == true)
        {
            xlow[0] = reg[i].cntr_xlow;
            xlow[1] = reg[i].cntr_ylow;

            xhigh[0] = reg[i].cntr_xhigh;
            xhigh[1] = reg[i].cntr_yhigh;
        }
        else
        {
            xlow[0] = reg[i].grid_xlow;
            xlow[1] = reg[i].grid_ylow;

            xhigh[0] = reg[i].grid_xhigh;
            xhigh[1] = reg[i].grid_yhigh;
        }

        result += Integral(f, xlow, xhigh);
    }

    return result;
}
示例#10
0
void ImageSpan::DrawContentsInRegions(const Regions& rgns, const Point& offset) const
{
	// we only care about the first region... (should only be 1 anyway)
	Region r = rgns.front();
	r.x += offset.x;
	r.y += offset.y;
	core->GetVideoDriver()->BlitSprite(image, r.x, r.y, true, &r);
}
示例#11
0
  void onPageChange()
  {
    int pageIndex = m_tab.getActivePage();

    switch (pageIndex) {
      // Region A
      case 0:
	m_regions.setRegion(m_regionA, false);
	break;
      // Region B
      case 1:
	m_regions.setRegion(m_regionB, false, true);
	break;
      // A | B
      case 2:
	m_region = m_regionA | m_regionB;
	m_regions.setRegion(m_region, true);
	break;
      // A & B
      case 3: 
	m_region = m_regionA & m_regionB;
	m_regions.setRegion(m_region, true);
	break;
      // A - B
      case 4: 
	m_region = m_regionA - m_regionB;
	m_regions.setRegion(m_region, true);
	break;
      // B - A
      case 5: 
	m_region = m_regionB - m_regionA;
	m_regions.setRegion(m_region, true);
	break;
      // A ^ B
      case 6:
	m_region = m_regionA ^ m_regionB;
	m_regions.setRegion(m_region, true);
	break;
    }
  }
示例#12
0
Regions TextSpan::LayoutForPointInRegion(Point layoutPoint, const Region& rgn) const
{
	Regions layoutRegions;
	const Point& drawOrigin = rgn.Origin();
	const Font* layoutFont = LayoutFont();
	assert(layoutFont);

	if (frame.Dimensions().IsZero()) {
		// this means we get to wrap :)
		// calculate each line and print line by line
		int lineheight = layoutFont->LineHeight;
		Regions lineExclusions;
		Region lineRgn(layoutPoint + drawOrigin, Size(rgn.w, lineheight));
		lineRgn.y -= lineheight;
		Region lineSegment;

#define LINE_REMAINDER lineRgn.w - lineSegment.x;
		const Region* excluded = NULL;
		size_t numPrinted = 0;
		bool newline = true;
		do {
			if (newline || lineSegment.x + lineSegment.w >= lineRgn.x + lineRgn.w) {
				// start next line
				newline = false;
				lineRgn.x = drawOrigin.x;
				lineRgn.y += lineheight;
				lineRgn.w = rgn.w;
				layoutPoint = lineRgn.Origin();

				lineSegment = lineRgn;
			}
			do {
				// process all overlaping exclusion zones until we trim down to the leftmost non conflicting region.
				// check for intersections with other content
				excluded = parent->ContentRegionForRect(lineSegment);
				if (!excluded) {
					// now check if we already used this region ourselves
					std::vector<Region>::const_iterator it;
					for (it = lineExclusions.begin(); it != lineExclusions.end(); ++it) {
						if (lineSegment.IntersectsRegion(*it)) {
							excluded = &*it;
							break;
						}
					}
				} // no else!
				if (excluded) {
					Region intersect = excluded->Intersect(lineSegment);
					if (intersect.x > lineSegment.x) { // to the right, simply shrink the width
						lineSegment.w = intersect.x - lineSegment.x;
					} else { // overlaps our start point, jump to the right of intersect
						int x = lineSegment.x;
						lineSegment.x = intersect.x + intersect.w;
						// must shrink to compensate for moving x
						lineSegment.w -= lineSegment.x - x;
					}

					// its possible that the resulting segment is 0 in width
					if (lineSegment.w <= 0) {
						lineSegment.x = intersect.x + intersect.w;
						lineSegment.w = LINE_REMAINDER;
						lineExclusions.push_back(lineSegment);
						newline = true;
						goto newline;
					}
				}
			} while (excluded);

			{ // protected scope for goto
				assert(lineSegment.h == lineheight);
				size_t numOnLine = 0;
				// must limit our operation to this single line.
				size_t nextLine = text.find_first_of(L'\n', numPrinted);
				if (nextLine == numPrinted) {
					// this is a new line, we dont have to actually size that
					// simply occupy the entire area and advance.
					lineSegment.w = LINE_REMAINDER;
					numOnLine = 1;
					newline = true;
				} else {
					size_t subLen = nextLine;
					if (nextLine != String::npos) {
						subLen = nextLine - numPrinted + 1; // +1 for the \n
					}
					const String& substr = text.substr(numPrinted, subLen);
					Font::StringSizeMetrics metrics = {lineSegment.Dimensions(), 0, lineSegment.w == lineRgn.w};
					Size printSize = layoutFont->StringSize(substr, &metrics);
					numOnLine = metrics.numChars;
					assert(numOnLine || !metrics.forceBreak);

					bool noFit = !metrics.forceBreak && numOnLine == 0;
					bool lineFilled = lineSegment.x + lineSegment.w == lineRgn.w;
					bool moreChars = numPrinted + numOnLine < text.length();
					if (subLen != String::npos || noFit || (lineFilled && moreChars)) {
						// optimization for when the segment is the entire line (and we have more text)
						// saves looping again for the known to be useless segment
						newline = true;
						lineSegment.w = LINE_REMAINDER;
					} else {
						assert(printSize.w);
						lineSegment.w = printSize.w;
					}
				}
				numPrinted += numOnLine;
			}
			assert(!lineSegment.Dimensions().IsEmpty());
			lineExclusions.push_back(lineSegment);

		newline:
			if (newline || numPrinted == text.length()) {
				// must claim the lineExclusions as part of the layout
				// just because we didnt fit doesnt mean somethng else wont...
				Region lineLayout = Region::RegionEnclosingRegions(lineExclusions);
				assert(lineLayout.h % lineheight == 0);
				layoutRegions.push_back(lineLayout);
				lineExclusions.clear();
			}
			// FIXME: infinite loop possibility.
		} while (numPrinted < text.length());
#undef LINE_REMAINDER
		assert(numPrinted == text.length());
	} else {
		// we are limited to drawing within our frame :(

		// FIXME: we ought to be able to set an alignment for "blocks" of text
		// probably the way to do this is have alignment on the container
		// then maybe another Draw method that takes an alignment argument?

		Region drawRegion = LayoutInFrameAtPoint(layoutPoint, rgn);
		assert(drawRegion.h && drawRegion.w);
		layoutRegions.push_back(drawRegion);
	}
	return layoutRegions;
}
示例#13
0
void cairo_regions(cairo_t *cr, Regions const &p) {
    srand(0); 
    for(Regions::const_iterator j = p.begin(); j != p.end(); ++j)
        cairo_region(cr, *j);
}
	void callback( const sensor_msgs::ImageConstPtr& dep, const CameraInfoConstPtr& cam_info)
	{
		ros::Time begin = ros::Time::now();
		//  Debug info
		std::cerr << "Recieved frame..." << std::endl;
		std::cerr << "Cam info: fx:" << cam_info->K[0] << " fy:" << cam_info->K[4] << " cx:" << cam_info->K[2] <<" cy:" << cam_info->K[5] << std::endl;
		std::cerr << "Depth image h:" << dep->height << " w:" << dep->width << " e:" << dep->encoding << " " << dep->step << endl;
		std::cerr << "=========================================================" << endl;

		//get image from message
		cv_bridge::CvImagePtr image = cv_bridge::toCvCopy(dep);
		cv::Mat depth = image->image;
		double min, max;
		Mat xxx = Mat(depth.size(), CV_32FC1);
		minMaxLoc(depth, &min, &max);
		depth.convertTo(xxx, CV_32F, 1.0/(max-min), -min);


		Mat depth2;

		for (int i = 0; i < depth.rows; ++i)
			for (int j = 0; j < depth.cols; ++j)
			{
				if (depth.at<unsigned short>(i, j) > maxDepth)
					depth.at<unsigned short>(i, j) = 0;
			}

		Regions reg;

		if (typeRegions == REGIONS_DEPTH)
		{
			reg.watershedRegions(depth, cam_info, WatershedType::DepthDiff, 1, 2, 20);
		}
		if (typeRegions == REGIONS_NORMAL)
		{
			reg.watershedRegions(depth, cam_info, WatershedType::NormalDiff);
			reg.computeStatistics(0.3);
			minMaxLoc(reg.m_stddeviation, &min, &max);
			reg.m_stddeviation.convertTo(depth, CV_16U, 255.0/(max-min), -min);
			image->image = depth;
			deviation_image.publish(image->toImageMsg());
		}
		if (typeRegions == REGIONS_COMBINED)
		{
			reg.watershedRegions(depth, cam_info, WatershedType::Combined);
			reg.computeStatistics(0.3);
			minMaxLoc(reg.m_stddeviation, &min, &max);
			reg.m_stddeviation.convertTo(depth, CV_16U, 255.0/(max-min), -min);
			minMaxLoc(reg.m_regionMatrix, &min, &max);

			image->image = depth;
			deviation_image.publish(image->toImageMsg());
		}
		if (typeRegions == REGIONS_PREDICTOR)
		{
			reg.watershedRegions(depth, cam_info, WatershedType::PredictorDiff);
		}
		if (typeRegions == REGIONS_TILE)
		{
			reg.independentTileRegions(depth, cam_info);
			reg.computeStatistics(0.3);
			minMaxLoc(reg.m_stddeviation, &min, &max);
			reg.m_stddeviation.convertTo(depth, CV_16U, 255.0/(max-min), -min);

			image->image = depth;
			deviation_image.publish(image->toImageMsg());
		}



		minMaxLoc(reg.m_regionMatrix, &min, &max);
		reg.m_regionMatrix.convertTo(depth, CV_16U, 255.0/(max-min), -min);

		image->image = depth;
		region_image.publish(image->toImageMsg());

		ros::Time end = ros::Time::now();
		std::cout << "Computation time: " << (end - begin).toNSec()/1000000.0 << "ms" << std::endl;
	}