int HostRender::run_noninteractive(RaytracingContext& context,
                                   PixelFuncRaw const& render_pixel, int kill_timeout_seconds)
{
    Image      frame_buffer(context.params.image_width, context.params.image_height);
    ThreadPool thread_pool(context.params.num_threads);
    std::vector<glm::ivec2> tile_idx;

    Timer timer;
    timer.start();
    context.scene->refresh_scene(context.params);
    launch(&frame_buffer, thread_pool, &context, &tile_idx, render_pixel);

    if (kill_timeout_seconds > 0)
    {
        if (thread_pool.kill_at_timeout(kill_timeout_seconds))
        {
            cg_assert(!bool("Process ran into timeout - is there an infinite "
                            "loop?"));
        }
    }
    else
    {
        thread_pool.wait();
    }
    thread_pool.poll_exceptions();
    timer.stop();
    std::cout << "Rendering time: " << timer.getElapsedTimeInMilliSec() << "ms" << std::endl;
    frame_buffer.saveTGA(context.params.output_file_name.c_str(), 2.2f);

    return 0;
}
Exemple #2
0
void ieee802frame154_dump( TiFrame * frame )
{
    static TiIEEE802Frame154Descriptor m_desc;
    TiIEEE802Frame154Descriptor * desc;

	if (frame_length(frame) > 0)
	{   
		dbc_putchar( '>' );
	 	dbc_n8toa( frame_length(frame) );

		/*
        desc = ieee802frame154_open( &m_desc );
        if (ieee802frame154_parse(desc, frame_startptr(frame), frame_length(frame)))
        {
            // if the frame received is parsed successfully, then output it to the
            // computer through debugging channel

            //ieee802frame154_sequence( desc );
		    //ieee802frame154_panto( desc );
		    //ieee802frame154_shortaddrto( desc );
		    //ieee802frame154_panfrom( desc );
		    //ieee802frame154_shortaddrfrom( desc );

            // todo: you can output more
            // reference frame_dump() in rtl_frame.c

            dbc_n8toa( ieee802frame154_sequence(desc) );
			dbc_putchar( ':' );
			dbc_write( frame_startptr(frame), frame_length(frame) );
		}
		else{
	        // if the frame received is parsed failed, then output the error frame
            // to the computer through debugging channel

	        dbc_putchar( 'X' );
			dbc_putchar( ':' );
			dbc_write( frame_startptr(frame), frame_length(frame) );
		}
		*/
		
		//dbc_write( frame_startptr(frame), frame_length(frame) );
		dbc_write( frame_buffer(frame), frame_buffercapacity(frame) );
        //dbc_mem( frame_startptr(rxbuf), frame_length(rxbuf) );
		//dbc_write( frame_startptr(frame), frame_capacity(frame) );
		dbc_putchar( '\n' );
	}
}
int HostRender::run_interactive(RaytracingContext& context, PixelFuncRaw const& render_pixel,
                                std::function<void()> const& render_overlay)
{
    Image      frame_buffer(context.params.image_width, context.params.image_height);
    ThreadPool thread_pool(context.params.num_threads);
    std::vector<glm::ivec2> tile_idx;

    if (!GUI::init_host(context.params))
    {
        return 1;
    }

    if(context.scene)
        context.scene->set_active_camera();

    // Launch first render.
    launch(&frame_buffer, thread_pool, &context, &tile_idx, render_pixel);

    auto time_last_frame = std::chrono::high_resolution_clock::now();

    RaytracingParameters oldParams = context.params;
    while (GUI::keep_running())
    {
        GUI::poll_events();
        thread_pool.poll_exceptions();

        // Restart rendering if parameters have changed.
        auto cam = Camera::get_active();
        if ((cam && cam->requires_restart())
                || context.params.change_requires_restart(oldParams))
        {
            thread_pool.terminate();
            if (oldParams.scene != context.params.scene) {
                // reload scene
                switch (context.params.scene) {
                case RaytracingParameters::CORNELL_BOX:
                    context.scene = context.scenes["cornell_box"];
                    break;
                case RaytracingParameters::SPHERE_PORTRAIT:
                    context.scene = context.scenes["sphere_portrait"];
                    break;
                default:
                    cg_assert(!"should not happen");
                }
                cg_assert(context.scene);
                context.scene->set_active_camera();
            }
            context.scene->refresh_scene(context.params);
            oldParams = context.params;
            launch(&frame_buffer, thread_pool, &context, &tile_idx, render_pixel);
        }

        // Update the texture displayed online in regular intervals so that
        // we don't waste many cycles uploading all the time.
        auto const now = std::chrono::high_resolution_clock::now();
        float const mspf = 1000.f / static_cast<float>(context.params.fps);
        if (std::chrono::duration_cast<std::chrono::milliseconds>(now-time_last_frame).count() > mspf)
        {
            GUI::display_host(frame_buffer, render_overlay);
        }
    }

    GUI::cleanup();

    return 0;
}
Exemple #4
0
void
DPXCodec::compress(const FrameBuffer &frame)
{
	const PixelType pixel_type = (_depth == DPX_8 ? MoxFiles::UINT8 : MoxFiles::UINT16);
	const size_t bytes_per_subpixel = PixelSize(pixel_type);
	const int num_channels = (_channels == DPX_RGBA ? 4 : 3);
	
	const Box2i dataW = dataWindow();
	
	const int width = (dataW.max.x - dataW.min.x + 1);
	const int height = (dataW.max.y - dataW.min.y + 1);
	
	const size_t bytes_per_pixel = bytes_per_subpixel * num_channels;
	const size_t rowbytes = bytes_per_pixel * width;
	const size_t buffer_size = rowbytes * height;
	
	
	DataChunk data(buffer_size);
	
	FrameBuffer frame_buffer(dataW);
		
	char *origin = (char *)data.Data;
	
	frame_buffer.insert("R", Slice(pixel_type, origin + (bytes_per_subpixel * 0), bytes_per_pixel, rowbytes));
	frame_buffer.insert("G", Slice(pixel_type, origin + (bytes_per_subpixel * 1), bytes_per_pixel, rowbytes));
	frame_buffer.insert("B", Slice(pixel_type, origin + (bytes_per_subpixel * 2), bytes_per_pixel, rowbytes));
	
	if(_channels == DPX_RGBA)
		frame_buffer.insert("A", Slice(pixel_type, origin + (bytes_per_subpixel * 3), bytes_per_pixel, rowbytes));
	
	
	frame_buffer.copyFromFrame(frame);
	
	
	MemoryFile file(buffer_size);
	
	DPXCodec_OutStream ostream(file);
	
	dpx::Writer dpx;
	
	dpx.SetOutStream(&ostream);
	
	dpx.SetFileInfo("MOX",	// fileName
					NULL,			// creation time (set by libdpx)
					"DPXcodec, part of MOX", // creator
					NULL,			// project
					NULL,			// copyright
					~0,				// encryption key (0xffffffff means no encryption)
					false);			// don't swap byte order
	
	dpx.SetImageInfo(width, height);
	
	dpx.header.SetAspectRatio(0, _pixelAspectRatio.Numerator);
	dpx.header.SetAspectRatio(1, _pixelAspectRatio.Denominator);
	
	dpx.header.SetFrameRate((dpx::R32)_frameRate.Numerator / (dpx::R32)_frameRate.Denominator);
	
	//dpx.header.SetInterlace(info->field_label->type == FIEL_Type_FRAME_RENDERED ? 0 : 1);
	
	const unsigned int bit_depth = (_depth == DPX_8 ? 8 :
									_depth == DPX_10 ? 10 :
									_depth == DPX_12 ? 12 :
									_depth == DPX_16 ? 16 :
									10);
	
	const dpx::Descriptor dpx_desc = (_channels == DPX_RGBA ? dpx::kRGBA : dpx::kRGB);
	const dpx::Packing packing = ((bit_depth == 8 || bit_depth == 16) ? dpx::kPacked : dpx::kFilledMethodA);
	
	const dpx::Characteristic transfer = dpx::kLogarithmic;
	const dpx::Characteristic colorimetric = dpx::kLogarithmic;
	
	dpx.SetElement(0, dpx_desc, bit_depth, transfer, colorimetric, packing);
	
	
	const bool wrote_header = dpx.WriteHeader();
	
	if(!wrote_header)
		throw MoxMxf::ArgExc("Error writing header");
	

	const dpx::DataSize size = (pixel_type == MoxFiles::UINT16 ? dpx::kWord : dpx::kByte);
	
	const bool wrote_element = dpx.WriteElement(0, data.Data, size);
	
	if(!wrote_element)
		throw MoxMxf::ArgExc("Error writing image");
	
	
	const bool wrote_finish = dpx.Finish();
	
	if(!wrote_finish)
		throw MoxMxf::ArgExc("Error writing finish");
	
	
	storeData( file.getDataChunk() );
}