Ejemplo n.º 1
0
int main( int argc, char** argv )
{
    kvs::glut::Application app( argc, argv );
    kvs::glut::Screen screen( &app );
    screen.background()->setColor( kvs::RGBColor( 255, 255, 255 ) );
    screen.show();

    kvs::Vector3ui resolution( 32, 32, 32 );
    kvs::StructuredVolumeObject* object1 = new kvs::HydrogenVolumeData( resolution );
    kvs::glew::StochasticUniformGridEngine* engine1 = new kvs::glew::StochasticUniformGridEngine();
    engine1->setShader( kvs::Shader::BlinnPhong( 0.3, 0.5, 0.8, 100 ) );
    kvs::ColorMap cmap1( kvs::RGBFormulae::Hot( 256 ) );
    kvs::OpacityMap omap1( 256 );
    omap1.setRange( object1->minValue(), object1->maxValue() );
    omap1.addPoint( object1->minValue(), 0 );
    omap1.addPoint( object1->maxValue(), 0.8 );
    omap1.create();
    kvs::TransferFunction tfunc1( cmap1, omap1 );
    engine1->setTransferFunction( tfunc1 );

    kvs::StructuredVolumeObject* volume = new kvs::TornadoVolumeData( resolution );
    kvs::StructuredVolumeObject* object2 = new kvs::StructuredVectorToScalar( volume );
    kvs::glew::StochasticUniformGridEngine* engine2 = new kvs::glew::StochasticUniformGridEngine();
    engine2->setShader( kvs::Shader::BlinnPhong( 0.8, 0.2, 0.8, 50 ) );
    kvs::ColorMap cmap2( kvs::RGBFormulae::PM3D( 256 ) );
    kvs::OpacityMap omap2( 256 );
    omap2.setRange( object2->minValue(), object2->maxValue() );
    omap2.addPoint( object2->minValue(), 0 );
    omap2.addPoint( object2->maxValue(), 0.3 );
    omap2.create();
    kvs::TransferFunction tfunc2( cmap2, omap2 );
    engine2->setTransferFunction( tfunc2 );
    delete volume;

    kvs::ObjectManager* object_manager = screen.objectManager();
    kvs::RendererManager* renderer_manager = screen.rendererManager();
    kvs::IDManager* id_manager = screen.IDManager();
    kvs::glew::StochasticRenderingCompositor compositor( object_manager, renderer_manager, id_manager );
    compositor.setRepetitionLevel( 50 );
    compositor.enableLODControl( 1 );
    compositor.registerObject( object1, engine1 );
    compositor.registerObject( object2, engine2 );

    return app.run();
}
Ejemplo n.º 2
0
int main( int argc, char** argv )
{
    kvs::glut::Application app( argc, argv );
    kvs::glut::Screen screen( &app );
    screen.show();
    screen.light()->setModelTwoSide( true );
    screen.setBackgroundColor( kvs::RGBColor( 255, 255, 255 ));
    
//    RenderingTime time_fps;
//    kvs::glut::Timer* glut_timer = new kvs::glut::Timer( 1000 );
//    screen.addTimerEvent( &time_fps, glut_timer );
    
    KeyPressEvent key;
    screen.addKeyPressEvent( &key );
    
    // object 1
    kvs::StructuredVolumeObject* object1 = new kvs::StructuredVolumeImporter( argv[1]);
    float min = object1->minValue();
    float max = object1->maxValue() / 8.0;
    std::cout << "min value: " << min << std::endl;
    std::cout << "max value: " << max << std::endl;
    float* pvalues = (float*)object1->values().pointer();
    for ( size_t i = 0; i < object1->nnodes(); i++) {
        if( pvalues[i] < min ) pvalues[i] = min;
        if( pvalues[i] > max ) pvalues[i] = max;
    }
    object1->updateMinMaxValues();
    std::cout << object1->minValue() << std::endl;
    std::cout << object1->maxValue() << std::endl;
    
    kvs::glew::StochasticUniformGridEngine* engine1 = new kvs::glew::StochasticUniformGridEngine();
    engine1->setShader( kvs::Shader::BlinnPhong( 0.8, 0.2, 0.8, 100 ) );
    engine1->disableShading();
    kvs::TransferFunction tfunc1( 256 );
    kvs::OpacityMap omap1( 256 );
    omap1.setRange( object1->minValue(), object1->maxValue() );
    omap1.addPoint( object1->minValue(), 0 );
    omap1.addPoint( ( object1->maxValue() - object1->minValue() ) * 0.9 + object1->minValue(), 0.04 );
    omap1.addPoint( object1->maxValue(), 0 );
    omap1.create();
    kvs::OpacityMap omap2( omap1.table() );
    
    tfunc1.setOpacityMap( omap2 );
    tfunc1.write( "tfunc10.kvsml" );
//    tfunc1.setColorMap( kvs::RGBFormulae::GreenRedViolet( 256 ));
    engine1->setTransferFunction( tfunc1 );
    
//    // object 2
//    kvs::StructuredVolumeObject* object2 = new kvs::StructuredVolumeImporter( argv[3] );
//    kvs::glew::StochasticUniformGridEngine* engine2 = new kvs::glew::StochasticUniformGridEngine();
//    engine2->setShader( kvs::Shader::BlinnPhong( 0.8, 0.2, 0.8, 50 ) );
//    kvs::TransferFunction tfunc2( argv[4] );
//    engine2->setTransferFunction( tfunc2 );
    
    // isosurface
    kvs::StructuredVolumeObject* volume = new kvs::StructuredVolumeImporter( argv[2] );
    kvs::PolygonObject::NormalType n = kvs::PolygonObject::VertexNormal;
    bool d = false;
    kvs::TransferFunction t( 256 );
    kvs::PolygonObject* object2 = new kvs::Isosurface( volume, 0.1, n, d, t );
    object2->setOpacity( 100 );
//    object2->setColor( kvs::TransferFunction( 256 ).colorMap()[ int ( 256 * 0.1 )]);
    float grey = 0.4;
    object2->setColor( kvs::RGBColor( grey * 255, grey * 255, 0.6 * 255 ));
//    WritePolygon( object2, "pressure10.kvsml" );
    kvs::glew::StochasticPolygonEngine* engine2 = new kvs::glew::StochasticPolygonEngine();
    engine2->setShader( kvs::Shader::BlinnPhong( 0.8, 0.2, 0.8, 100 ) );
    
    kvs::ObjectManager* object_manager = screen.objectManager();
    kvs::RendererManager* renderer_manager = screen.rendererManager();
    kvs::IDManager* id_manager = screen.IDManager();
    kvs::glew::StochasticRenderingCompositor compositor( object_manager, renderer_manager, id_manager );
    compositor.setRepetitionLevel( 30 );
    compositor.enableLODControl( 1 );
    compositor.registerObject( object1, engine1 );
    compositor.registerObject( object2, engine2 );
    compositor.disableLODControl();
    
//    glut_timer->start( 10 );

    return app.run();
}
Ejemplo n.º 3
0
void testTextInput() {
    printf("TextInput\n");

    {
        // Parse floats
 		TextInput ti(TextInput::FROM_STRING, "1.2f");
        testAssert(ti.readNumber() == 1.2);
        testAssert(! ti.hasMore());
    }
    {
        // Parse floats
 		TextInput ti(TextInput::FROM_STRING, ".1");
        testAssert(ti.readNumber() == 0.1);
    }
    {
 		TextInput ti(TextInput::FROM_STRING, "..1");
        testAssert(ti.readSymbol() == "..");
        testAssert(ti.readNumber() == 1);
    }

    {
 		TextInput ti(TextInput::FROM_STRING, "0x1");
        testAssert(ti.readNumber() == 1);
    }

    {
        // Quoted string with escapes.  The actual expression we are parsing looks like:
        // "\\"
 		TextInput ti(TextInput::FROM_STRING, "\"\\\\\"");
        Token t;

		ti.readString("\\");

        t = ti.read();
        testAssert(t.type() == Token::END);
        testAssert(! ti.hasMore());
	}

    {
        // Quoted string without escapes: read as two backslashes
        // (the test itself has to escape the backslashes, just to write them).
        // The actual expression we are parsing is:
        // "\"
        TextInput::Settings opt;
        Token t;

        opt.escapeSequencesInStrings = false;
 		TextInput ti(TextInput::FROM_STRING, "\"\\\"", opt);
		ti.readString("\\");

        t = ti.read();
        testAssert(t.type() == Token::END);
        testAssert(! ti.hasMore());
	}

	{
 		TextInput ti(TextInput::FROM_STRING, "a \'foo\' bar");
        Token t;

		ti.readSymbol("a");

		t = ti.read();
		testAssert(t.extendedType() == Token::SINGLE_QUOTED_TYPE);
		testAssert(t.string() == "foo");
		ti.readSymbol("bar");

        t = ti.read();
        testAssert(t.type() == Token::END);
        testAssert(! ti.hasMore());
	}

    {
        TextInput ti(TextInput::FROM_STRING, "2.x");
        Token t;

        testAssert(ti.readNumber() == 2);
        ti.readSymbol("x");

        t = ti.read();
        testAssert(t.type() == Token::END);
        testAssert(! ti.hasMore());
    }
    {
        TextInput ti(TextInput::FROM_STRING, "1.E7");
        Token t;

        testAssert(ti.readNumber() == 1.E7);

        t = ti.read();
        testAssert(t.type() == Token::END);
        testAssert(! ti.hasMore());
    }

    {
        TextInput ti(TextInput::FROM_STRING, "\\123");
        Token t;
        t = ti.read();
        testAssert(t.type() == Token::SYMBOL);
        testAssert(t.string() == "\\");
        t = ti.read();
        testAssert(t.type() == Token::NUMBER);
        testAssert(t.number() == 123);

        t = ti.read();
        testAssert(t.type() == Token::END);
        testAssert(! ti.hasMore());
    }

    {
        TextInput::Settings options;
        options.otherCommentCharacter = '#';

        TextInput ti(TextInput::FROM_STRING, "1#23\nA\\#2", options);
        Token t;
        t = ti.read();
        testAssert(t.type() == Token::NUMBER);
        testAssert(t.number() == 1);

        // skip the comment
        t = ti.read();
        testAssert(t.type() == Token::SYMBOL);
        testAssert(t.string() == "A");

        // Read escaped comment character
        t = ti.read();
        testAssert(t.type() == Token::SYMBOL);
        testAssert(t.string() == "#");

        t = ti.read();
        testAssert(t.type() == Token::NUMBER);
        testAssert(t.number() == 2);

        t = ti.read();
        testAssert(t.type() == Token::END);
        testAssert(! ti.hasMore());
    }

    {
        TextInput ti(TextInput::FROM_STRING, "0xFEED");

        Token t;
   
        t = ti.peek();
        testAssert(t.type() == Token::NUMBER);
        double n = ti.readNumber();
        (void)n;
        testAssert((int)n == 0xFEED);

        t = ti.read();
        testAssert(t.type() == Token::END);
        testAssert(! ti.hasMore());
    }

    {
        TextInput::Settings opt;
        opt.cppLineComments = false;
        TextInput ti(TextInput::FROM_STRING, 
                     "if/*comment*/(x->y==-1e6){cout<<\"hello world\"}; // foo\nbar",
                     opt);

        Token a = ti.read();
        Token b = ti.read();
        Token c = ti.read();
        Token d = ti.read();
        Token e = ti.read();
        Token f = ti.read();
        double g = ti.readNumber();
        (void)g;
        Token h = ti.read();
        Token i = ti.read();
        Token j = ti.read();
        Token k = ti.read();
        Token L = ti.read();
        Token m = ti.read();
        Token n = ti.read();
        Token p = ti.read();
        Token q = ti.read();
        Token r = ti.read();
        Token s = ti.read();
        Token t = ti.read();

        testAssert(a.type() == Token::SYMBOL);
        testAssert(a.string() == "if");

        testAssert(b.type() == Token::SYMBOL);
        testAssert(b.string() == "(");

        testAssert(c.type() == Token::SYMBOL);
        testAssert(c.string() == "x");

        testAssert(d.type() == Token::SYMBOL);
        testAssert(d.string() == "->");

        testAssert(e.type() == Token::SYMBOL);
        testAssert(e.string() == "y");

        testAssert(f.type() == Token::SYMBOL);
        testAssert(f.string() == "==");

        testAssert(g == -1e6);

        testAssert(h.type() == Token::SYMBOL);
        testAssert(h.string() == ")");

        testAssert(i.type() == Token::SYMBOL);
        testAssert(i.string() == "{");

        testAssert(j.type() == Token::SYMBOL);
        testAssert(j.string() == "cout");

        testAssert(k.type() == Token::SYMBOL);
        testAssert(k.string() == "<<");

        testAssert(L.type() == Token::STRING);
        testAssert(L.string() == "hello world");

        testAssert(m.type() == Token::SYMBOL);
        testAssert(m.string() == "}");

        testAssert(n.type() == Token::SYMBOL);
        testAssert(n.string() == ";");

        testAssert(p.type() == Token::SYMBOL);
        testAssert(p.string() == "/");

        testAssert(q.type() == Token::SYMBOL);
        testAssert(q.string() == "/");

        testAssert(r.type() == Token::SYMBOL);
        testAssert(r.string() == "foo");

        testAssert(s.type() == Token::SYMBOL);
        testAssert(s.string() == "bar");

        testAssert(t.type() == Token::END);
    }
    
    {
        TextInput ti(TextInput::FROM_STRING, "-1 +1 2.6");

        Token t;
   
        t = ti.peek();
        testAssert(t.type() == Token::NUMBER);
        double n = ti.readNumber();
        testAssert(n == -1);

        t = ti.peek();
        testAssert(t.type() == Token::NUMBER);
        n = ti.readNumber();
        testAssert(n == 1);

        t = ti.peek();
        testAssert(t.type() == Token::NUMBER);
        n = ti.readNumber();
        testAssert(n == 2.6);
    }

    {
        TextInput ti(TextInput::FROM_STRING, "- 1 ---.51");

        Token t;
   
        t = ti.peek();
        testAssert(t.type() == Token::SYMBOL);
        ti.readSymbol("-");

        t = ti.peek();
        testAssert(t.type() == Token::NUMBER);
        double n = ti.readNumber();
        testAssert(n == 1);

        t = ti.peek();
        testAssert(t.type() == Token::SYMBOL);
        ti.readSymbol("--");

        t = ti.peek();
        testAssert(t.type() == Token::NUMBER);
        n = ti.readNumber();
        testAssert(n == -.51);
    }


    {
        G3D::TextInput::Settings ti_opts;
        const String str = "'";
        ti_opts.singleQuotedStrings = false;

        G3D::TextInput ti(G3D::TextInput::FROM_STRING, str, ti_opts);

        G3D::Token t = ti.read();

        /*
        printf("t.string       = %s\n", t.string().c_str());
        printf("t.type         = %d\n", t.type());
        printf("t.extendedType = %d\n", t.extendedType());

        printf("\n");
        printf("SYMBOL         = %d\n", G3D::Token::SYMBOL);
        printf("END            = %d\n", G3D::Token::END);

        printf("\n");
        printf("SYMBOL_TYPE    = %d\n", G3D::Token::SYMBOL_TYPE);
        printf("END_TYPE       = %d\n", G3D::Token::END_TYPE);
        */

        testAssertM(t.type() == G3D::Token::SYMBOL, "");
        testAssertM(t.extendedType() == G3D::Token::SYMBOL_TYPE, "");
    }
    
    tfunc1();
    tfunc2();
    
    tCommentTokens();
    tNewlineTokens();
}