std::shared_ptr<stream_profile_interface> software_sensor::add_video_stream(rs2_video_stream video_stream)
    {
        auto exist = (std::find_if(_profiles.begin(), _profiles.end(), [&](std::shared_ptr<stream_profile_interface> profile)
        {
            if (profile->get_unique_id() == video_stream.uid)
            {
                return true;
            }
            return false;
        } ) != _profiles.end());

        if (exist)
        {
            LOG_WARNING("Stream unique ID already exist!");
            throw rs2::error("Stream unique ID already exist!");
        }

        auto profile = std::make_shared<video_stream_profile>(
            platform::stream_profile{ (uint32_t)video_stream.width, (uint32_t)video_stream.height, (uint32_t)video_stream.fps, 0 });
        profile->set_dims(video_stream.width, video_stream.height);
        profile->set_format(video_stream.fmt);
        profile->set_framerate(video_stream.fps);
        profile->set_stream_index(video_stream.index);
        profile->set_stream_type(video_stream.type);
        profile->set_unique_id(video_stream.uid);
        profile->set_intrinsics([=]() {return video_stream.intrinsics; });
        _profiles.push_back(profile);

        return profile;
    }
Example #2
0
void set_light_tile(struct tile *light, int num, int x, int y)
{
	set_dims(light, x, y, 8, 8, LIGHTS_TEX_X + num*8, LIGHTS_TEX_Y);
	set_type(light, Transparent, NoCollision, 0, NULL);
	light->z = DYN_TILES_OVERLAY_Z;
}
    void  disparity_transform::update_transformation_profile(const rs2::frame& f)
    {
        if(f.get_profile().get() != _source_stream_profile.get())
        {
            _source_stream_profile = f.get_profile();

            // Check if the new frame originated from stereo-based depth sensor
            // and retrieve the stereo baseline parameter that will be used in transformations
            auto snr = ((frame_interface*)f.get())->get_sensor().get();
            librealsense::depth_stereo_sensor* dss;

            // Playback sensor
            if (auto a = As<librealsense::extendable_interface>(snr))
            {
                librealsense::depth_stereo_sensor* ptr;
                if (_stereoscopic_depth = a->extend_to(TypeToExtension<librealsense::depth_stereo_sensor>::value, (void**)&ptr))
                {
                    dss = ptr;
                    _depth_units = dss->get_depth_scale();
                    _stereo_baseline_meter = dss->get_stereo_baseline_mm()*0.001f;
                }
            }
            else // Live sensor
            {
                _stereoscopic_depth = Is<librealsense::depth_stereo_sensor>(snr);
                if (_stereoscopic_depth)
                {
                    dss = As<librealsense::depth_stereo_sensor>(snr);
                    _depth_units = dss->get_depth_scale();
                    _stereo_baseline_meter = dss->get_stereo_baseline_mm()* 0.001f;
                }
            }

            if (_stereoscopic_depth)
            {
                auto vp = _source_stream_profile.as<rs2::video_stream_profile>();
                _focal_lenght_mm    = vp.get_intrinsics().fx;
                const uint8_t fractional_bits = 5;
                const uint8_t fractions = 1 << fractional_bits;
                _d2d_convert_factor = (_stereo_baseline_meter * _focal_lenght_mm * fractions) / _depth_units;
                _width = vp.width();
                _height = vp.height();
                _update_target = true;
            }
        }

        // Adjust the target profile
        if (_update_target)
        {
            auto tgt_format = _transform_to_disparity ? RS2_FORMAT_DISPARITY32 : RS2_FORMAT_Z16;
            _target_stream_profile = _source_stream_profile.clone(RS2_STREAM_DEPTH, 0, tgt_format);
            auto src_vspi = dynamic_cast<video_stream_profile_interface*>(_source_stream_profile.get()->profile);
            auto tgt_vspi = dynamic_cast<video_stream_profile_interface*>(_target_stream_profile.get()->profile);
            rs2_intrinsics src_intrin   = src_vspi->get_intrinsics();

            tgt_vspi->set_intrinsics([src_intrin]() { return src_intrin; });
            tgt_vspi->set_dims(src_intrin.width, src_intrin.height);

            _update_target = false;
        }
    }
Example #4
0
int cgl_read_one_pipe(struct bar *bar, FILE *fp)
{
	int err;
	uint8_t buf[PIPE_HDR_SIZE];
	int16_t buf2[PIPE_NUM_SHORTS];
	size_t nread;

	nread = fread(buf, sizeof(uint8_t), PIPE_HDR_SIZE, fp);
	if (nread < PIPE_HDR_SIZE)
		return -EBADPIPE;
	err = read_short((int16_t*)buf2, PIPE_NUM_SHORTS, fp);
	if (err)
		return -EBADPIPE;
	bar->orientation = (buf[0] >> 0) & 0x01;
	bar->gap_type    = (buf[0] >> 4) & 0x01;
	bar->gap    = buf[2];
	bar->min_s  = buf[6] - 1;
	bar->max_s  = buf[7] - 1;
	bar->freq   = buf[10] & 0x01;
	int width   = buf2[2],
	    height  = buf2[3];
	/* prepare beg, end, fbar and sbar tiles */
	switch (bar->orientation) {
	case Vertical:
		parse_tile_minimal(buf2, bar->beg,
			BAR_BASE_H, BAR_BASE_W, BAR_BEG_TEX_X, BAR_BEG_TEX_Y);
		set_dims(bar->end,
			bar->beg->x, bar->beg->y + height - BAR_BASE_W,
			bar->beg->w, bar->beg->h,
			VBAR_END_TEX_X, VBAR_END_TEX_Y);
		/* fbar and sbar must take the whole space available, so that
		 * cgl_preprocess assigns them to all blocks where they may
		 * appear */
		set_dims(bar->fbar,
			bar->beg->x + (BAR_BASE_H - BAR_THICKNESS)/2,
			bar->beg->y + BAR_BASE_W,
			BAR_THICKNESS, height - 2*BAR_BASE_W,
			VBAR_TEX_X, VBAR_TEX_Y + BAR_TEX_LEN - (height - 2*BAR_BASE_W));
		set_dims(bar->sbar,
			bar->beg->x + (BAR_BASE_H - BAR_THICKNESS)/2,
			bar->beg->y + BAR_BASE_W,
			BAR_THICKNESS, height - 2*BAR_BASE_W,
			VBAR_TEX_X, VBAR_TEX_Y),
		bar->len = height - 2*BAR_BASE_W;
		break;
	case Horizontal:
		parse_tile_minimal(buf2, bar->beg,
				BAR_BASE_W, BAR_BASE_H, BAR_BEG_TEX_X, BAR_BEG_TEX_Y);
		set_dims(bar->end,
			bar->beg->x + width - BAR_BASE_W, bar->beg->y,
			bar->beg->w, bar->beg->h,
			HBAR_END_TEX_X, HBAR_END_TEX_Y);
		/* Same as in case Vertical */
		set_dims(bar->fbar,
			bar->beg->x + BAR_BASE_W,
			bar->beg->y + (BAR_BASE_H - BAR_THICKNESS)/2,
			width - 2*BAR_BASE_W, BAR_THICKNESS,
			HBAR_TEX_X + BAR_TEX_LEN - (width - 2*BAR_BASE_W), HBAR_TEX_Y);
		set_dims(bar->sbar,
			bar->beg->x + BAR_BASE_W,
			bar->beg->y + (BAR_BASE_H - BAR_THICKNESS)/2,
			width - 2*BAR_BASE_W, BAR_THICKNESS,
			HBAR_TEX_X, HBAR_TEX_Y);
		bar->len = width - 2*BAR_BASE_W;
		break;
	}
	bar->btex_x = bar->beg->tex_x;
	bar->etex_x = bar->end->tex_x;
	bar->slen = BAR_MIN_LEN;
	bar->flen = BAR_MIN_LEN;
	bar->beg->collision_test = bar->end->collision_test = Bitmap;
	return 0;
}