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(); }
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(); }