예제 #1
0
int main()
{
	// Build scene
	SceneList scene;
	
	scene.push_back(new Sphere(Point3(-320,0,50), 200.0f, ColorRGBA(255,0,0,255)));
	scene.push_back(new Sphere(Point3(320, 0, 50), 200.0f, ColorRGBA(0, 0, 255, 255)));
	scene.push_back(new Sphere(Point3(0, 0, -50), 200.0f, ColorRGBA(0, 255, 0, 255)));
	scene.push_back(new Plane(Vector3(0,1,0), Vector3(0, -150, 0), ColorRGBA(255,255,255,255)));
	
	// Render the scene
	RayTraceSettings settings;
	settings.resolutionWidth  = 600;
	settings.resolutionHeight = 480;
	settings.depth = 255;
	settings.clearColor = ColorRGB(50,50,50);
	settings.eyePosition = Point3(0, 0, 600);
	
	RayTracer rayTracer(settings);
	rayTracer.renderScene(scene);
	
	rayTracer.saveToFile("rayTracerTest.tga");

	// Clean up the scene
	std::for_each(scene.begin(), scene.end(), deleteDynamicObject());
	
	return 0;
}
예제 #2
0
bool losExists( const hydroogmap::OgMap &ogMap, double traversabilityThreshhold, const Cell2D &c1, const Cell2D &c2 )
{
    assert( ogMap.cellWithinMap( c1.x(), c1.y() ) );
    assert( ogMap.cellWithinMap( c2.x(), c2.y() ) );
    hydroogmap::OgLosTracer rayTracer( ogMap, (unsigned char)(traversabilityThreshhold*hydroogmap::CELL_OCCUPIED) );
    return rayTracer.isClearCells( c1.x(), c1.y(), c2.x(), c2.y() );
}
예제 #3
0
int main(int argc, char *argv[])
{
    Q_UNUSED(argc);
    Q_UNUSED(argv);

    SceneSettingReader settingsReader(SETTINGS_FILENAME);
    Scene scene(settingsReader);
    RayTracer rayTracer(scene);

    auto image = rayTracer.generateImage();
    image.save(settingsReader.outputFilename());

    return 0;
}
예제 #4
0
파일: main.cpp 프로젝트: Kovath/raytracing
int main(int argc, char** argv) {
	for(int i = 1; i < argc; i++) {
		Timer program_timer, task_timer;
		program_timer.start();
	
		// parse command line inputs and initialize
		cout << "Initializing:\t"; cout.flush();
		task_timer.start();
	
		ifstream render_stream(argv[1]);
		list<Setting> settings = RTInputParser(render_stream).get_settings();
		RayTracer rayTracer(settings);
	
		task_timer.stop();
		cout << task_timer.get_duration_s() << " s" << endl;
	
	
		// create raytracer and RENDER
		cout << "Rendering:\t"; cout.flush();
		task_timer.start();
	
		rayTracer.render();
	
		task_timer.stop();
		cout << task_timer.get_duration_s() << " s" << endl;
	
	
	
		// draw to image
		cout << "Saving:\t\t"; cout.flush();
		task_timer.start();
	
		rayTracer.save();
	
		task_timer.stop();
		cout << task_timer.get_duration_s() << " s" << endl;
	
		program_timer.stop();
		cout << "Total Time:\t" << program_timer.get_duration_s() << " s" << endl;
		cout << endl;
	}
	
	return 0;
}
예제 #5
0
void optimizePath( const hydroogmap::OgMap &ogMap,
                   double                   traversabilityThreshhold,
                   const Cell2DVector      &origPath,
                   Cell2DVector            &optimisedPath )
{
    hydroogmap::OgLosTracer rayTracer( ogMap, (unsigned char)(traversabilityThreshhold*hydroogmap::CELL_OCCUPIED) );

#ifndef NDEBUG
    // Check that the original path is OK.
    if ( origPath.size() >= 2 )
    {
        for ( unsigned int i=1; i < origPath.size(); i++ )
        {
            Cell2D wp1 = origPath[i-1];
            Cell2D wp2 = origPath[i];
            if ( !rayTracer.isClearCells( wp1.x(), wp1.y(), wp2.x(), wp2.y() ) )
            {
                cout<<"TRACE(pathplanutils.cpp): OptimisePath: original path was messed up:" << endl;
                cout<<"TRACE(pathplanutils.cpp): Couldn't get from wp "<<i-1<<" to "<<i<< endl;
                cout<<"TRACE(pathplanutils.cpp):   " << wp1 << " --> " << wp2 << endl;
                cout<<"TRACE(pathplanutils.cpp): entire origPath: " << endl;
                for ( unsigned int j=0; j < origPath.size(); j++ )
                {
                    cout << "  " << j << ": " << origPath[j] << endl;
                }
                assert( false && "optimizePath received dodgy input path!" );
            }
        }
    }
#endif


    assert( origPath.size() > 0 );

    optimisedPath.push_back( origPath[0] );
    if ( origPath.size() >= 2 )
    {

        int priorI  = 0;
        int middleI = 1;

        //
        // In this while loop: middle and post are always contiguous wps from origPath.
        //
        while ( (middleI+1) < (int)(origPath.size()) )
        {
            const Cell2D &prior  = origPath[priorI];
            const Cell2D &middle = origPath[middleI];
            const Cell2D &post   = origPath[middleI+1];

#ifndef NDEBUG
            if ( !rayTracer.isClearCells( prior.x(), prior.y(), middle.x(), middle.y() ) )
            {
                cout << "ERROR(pathplanutils.cpp): Couldn't trace from prior to middle." << endl;
                cout<<"TRACE(pathplanutils.cpp): prior:  " << prior << endl;
                cout<<"TRACE(pathplanutils.cpp): middle: " << middle << endl;
                cout<<"TRACE(pathplanutils.cpp): post:   " << post << endl;
                cout<<"TRACE(pathplanutils.cpp): origPath: " << endl;
                for ( unsigned int j=0; j < origPath.size(); j++ )
                    cout << "  " << j << ": " << origPath[j] << endl;
                assert( false );
            }
#endif

            if ( !rayTracer.isClearCells( prior.x(), prior.y(), post.x(), post.y() ) )
            {
                // There's a direct line from prior to middle, but _not_ from prior to post.
                // Therefore the middle-man is necessary.
                optimisedPath.push_back( middle );
                priorI  = middleI;
            }
            else
            {
                // skip the middle-man
            }
            middleI++;
        }
    }

    // Add the last cell
    optimisedPath.push_back( origPath.back() );

#ifndef NDEBUG
    // Just double-check that the path is OK.
    if ( optimisedPath.size() < 2 ) return;
    for ( unsigned int i=1; i < optimisedPath.size(); i++ )
    {
        Cell2D wp1 = optimisedPath[i-1];
        Cell2D wp2 = optimisedPath[i];
        if ( !rayTracer.isClearCells( wp1.x(), wp1.y(), wp2.x(), wp2.y() ) )
        {
            cout<<"TRACE(pathplanutils.cpp): OptimisePath messed up:" << endl;
            cout<<"TRACE(pathplanutils.cpp): Couldn't get from wp "<<i-1<<" to "<<i<< endl;
            cout<<"TRACE(pathplanutils.cpp):   " << wp1 << " --> " << wp2 << endl;
            cout<<"TRACE(pathplanutils.cpp): entire optimised path: " << endl;
            for ( unsigned int j=0; j < optimisedPath.size(); j++ )
            {
                cout << "  " << j << ": " << optimisedPath[j] << endl;
            }
            cout<<"TRACE(pathplanutils.cpp): origPath: " << endl;
            for ( unsigned int j=0; j < origPath.size(); j++ )
            {
                cout << "  " << j << ": " << origPath[j] << endl;
            }
            assert( false && "optimizePath messed up!" );
        }
    }
#endif
}