Пример #1
0
void obj_loader::load_material(string material_filename)
{
    ifstream in(material_filename.c_str(), ios::in);
    if (!in) { cerr << "Cannot open " << material_filename << endl; exit(1); }

    string line;
    material curr_mater;

    while (getline(in, line)) {

        if (line.substr(0,6) == "newmtl")
        {
            curr_mater.name = line.substr(7); // first set name
        }
        else if (line.substr(0,3) == "Kd ")   // diffuse
        {
            line =  line.substr(3); // first set name

            istringstream iis(line);

            iis >> curr_mater.diffuse[0];
            iis >> curr_mater.diffuse[1];
            iis >> curr_mater.diffuse[2];

            //sscanf(line.c_str(), "%f %f %f\r", curr_mater.rgb.x, curr_mater.rgb.y, curr_mater.rgb.z);
            mats.push_back(curr_mater);
        }
        else if (line.substr(0,3) == "Ka ")   // diffuse
Пример #2
0
void nonMaximaSuppression(const Mat& src, const int sz, Mat& dst, const Mat mask) {

    // initialise the block mask and destination
    const int M = src.rows;
    const int N = src.cols;
    const bool masked = !mask.empty();
    Mat block = 255*Mat_<uint8_t>::ones(Size(2*sz+1,2*sz+1));
    dst = Mat_<uint8_t>::zeros(src.size());

    // iterate over image blocks
    for (int m = 0; m < M; m+=sz+1) {
            for (int n = 0; n < N; n+=sz+1) {
                    Point  ijmax;
                    double vcmax, vnmax;

                    // get the maximal candidate within the block
                    Range ic(m, min(m+sz+1,M));
                    Range jc(n, min(n+sz+1,N));
                    minMaxLoc(src(ic,jc), NULL, &vcmax, NULL, &ijmax, masked ? mask(ic,jc) : noArray());
                    Point cc = ijmax + Point(jc.start,ic.start);

                    // search the neighbours centered around the candidate for the true maxima
                    Range in(max(cc.y-sz,0), min(cc.y+sz+1,M));
                    Range jn(max(cc.x-sz,0), min(cc.x+sz+1,N));

                    // mask out the block whose maxima we already know
                    Mat_<uint8_t> blockmask;
                    block(Range(0,in.size()), Range(0,jn.size())).copyTo(blockmask);
                    Range iis(ic.start-in.start, min(ic.start-in.start+sz+1, in.size()));
                    Range jis(jc.start-jn.start, min(jc.start-jn.start+sz+1, jn.size()));
                    blockmask(iis, jis) = Mat_<uint8_t>::zeros(Size(jis.size(),iis.size()));

                    minMaxLoc(src(in,jn), NULL, &vnmax, NULL, &ijmax, masked ? mask(in,jn).mul(blockmask) : blockmask);
                    Point cn = ijmax + Point(jn.start, in.start);

                    // if the block centre is also the neighbour centre, then it's a local maxima
                    if (vcmax > vnmax) {
                            dst.at<uint8_t>(cc.y, cc.x) = src.at<uint8_t>(cc.y, cc.x);
                    }

            }
    }
}
Пример #3
0
void yaml_iarchive_t::init( std::istream& is)
{
	RAMEN_ASSERT( is.good());

	version_ = 0;
	header_read_ = false;

	if( 1)
		parser_.Load( is);
	else
	{
		is.seekg( 0, std::ios_base::end);
		std::size_t length = is.tellg();
		std::string buffer;
		buffer.reserve( length);
		is.read( &buffer[0], length);
		std::stringstream iis( buffer, std::ios_base::in);
		parser_.Load( iis);
	}

	parser_.GetNextDocument( doc_);	
	root_.reset( new yaml_node_t( this, &doc_, version_));
}