int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener); TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); //Print key command info std::cout << "\n\nKEY COMMANDS:" << std::endl; std::cout << "space Play/Pause the animation" << std::endl; std::cout << "G Show/Hide the grid" << std::endl; std::cout << "A Show/Hide the axes" << std::endl; std::cout << "B Show/Hide the bind pose skeleton" << std::endl; std::cout << "SHIFT-B Show/Hide the bind pose mesh" << std::endl; std::cout << "P Show/Hide the current pose skeleton" << std::endl; std::cout << "SHIFT-P Show/Hide the current pose mesh" << std::endl; std::cout << "CTRL-Q Exit\n\n" << std::endl; //Setup axes LineChunkPtr AxesLineChunk = LineChunk::create(); beginEditCP(AxesLineChunk); AxesLineChunk->setWidth(0.0f); AxesLineChunk->setSmooth(true); endEditCP(AxesLineChunk); //Axes material ChunkMaterialPtr AxesMaterial = ChunkMaterial::create(); beginEditCP(AxesMaterial, ChunkMaterial::ChunksFieldMask); AxesMaterial->addChunk(AxesLineChunk); endEditCP(AxesMaterial, ChunkMaterial::ChunksFieldMask); //Grid material ChunkMaterialPtr gridMaterial = ChunkMaterial::create(); beginEditCP(gridMaterial, ChunkMaterial::ChunksFieldMask); gridMaterial->addChunk(AxesLineChunk); endEditCP(gridMaterial, ChunkMaterial::ChunksFieldMask); //Axes should render as lines GeoPTypesPtr axesType = GeoPTypesUI8::create(); beginEditCP(axesType, GeoPTypesUI8::GeoPropDataFieldMask); { axesType->addValue(GL_LINES); } endEditCP (axesType, GeoPTypesUI8::GeoPropDataFieldMask); //Grid type GeoPTypesPtr gridType = GeoPTypesUI8::create(); beginEditCP(gridType, GeoPTypesUI8::GeoPropDataFieldMask); { gridType->addValue(GL_LINES); } endEditCP (gridType, GeoPTypesUI8::GeoPropDataFieldMask); //Axes lens GeoPLengthsPtr axesLens = GeoPLengthsUI32::create(); beginEditCP(axesLens, GeoPLengthsUI32::GeoPropDataFieldMask); { axesLens->addValue(6); } endEditCP (axesLens, GeoPLengthsUI32::GeoPropDataFieldMask); //Grid lens GeoPLengthsPtr gridLens = GeoPLengthsUI32::create(); beginEditCP(gridLens, GeoPLengthsUI32::GeoPropDataFieldMask); { gridLens->addValue(84); } endEditCP (gridLens, GeoPLengthsUI32::GeoPropDataFieldMask); //Axes points GeoPositions3fPtr axesPnts = GeoPositions3f::create(); beginEditCP(axesPnts, GeoPositions3f::GeoPropDataFieldMask); { // X-Axis axesPnts->addValue(Pnt3f(0, 0, 0)); axesPnts->addValue(Pnt3f(15, 0, 0)); // Y-Axis axesPnts->addValue(Pnt3f(0, 0, 0)); axesPnts->addValue(Pnt3f(0, 15, 0)); // Z-Axis axesPnts->addValue(Pnt3f(0, 0, 0)); axesPnts->addValue(Pnt3f(0, 0, 15)); } endEditCP (axesPnts, GeoPositions3f::GeoPropDataFieldMask); //Grid points GeoPositions3fPtr gridPnts = GeoPositions3f::create(); beginEditCP(gridPnts, GeoPositions3f::GeoPropDataFieldMask); { float height = 0; gridPnts->addValue(Pnt3f(-10, height, 0)); if(height == 0) gridPnts->addValue(Pnt3f(0, height, 0)); else gridPnts->addValue(Pnt3f(10, height, 0)); gridPnts->addValue(Pnt3f(-10, height, 1)); gridPnts->addValue(Pnt3f(10, height, 1)); gridPnts->addValue(Pnt3f(-10, height, 2)); gridPnts->addValue(Pnt3f(10, height, 2)); gridPnts->addValue(Pnt3f(-10, height, 3)); gridPnts->addValue(Pnt3f(10, height, 3)); gridPnts->addValue(Pnt3f(-10, height, 4)); gridPnts->addValue(Pnt3f(10, height, 4)); gridPnts->addValue(Pnt3f(-10, height, 5)); gridPnts->addValue(Pnt3f(10, height, 5)); gridPnts->addValue(Pnt3f(-10, height, 6)); gridPnts->addValue(Pnt3f(10, height, 6)); gridPnts->addValue(Pnt3f(-10, height, 7)); gridPnts->addValue(Pnt3f(10, height, 7)); gridPnts->addValue(Pnt3f(-10, height, 8)); gridPnts->addValue(Pnt3f(10, height, 8)); gridPnts->addValue(Pnt3f(-10, height, 9)); gridPnts->addValue(Pnt3f(10, height, 9)); gridPnts->addValue(Pnt3f(-10, height, 10)); gridPnts->addValue(Pnt3f(10, height, 10)); gridPnts->addValue(Pnt3f(-10, height, -1)); gridPnts->addValue(Pnt3f(10, height, -1)); gridPnts->addValue(Pnt3f(-10, height, -2)); gridPnts->addValue(Pnt3f(10, height, -2)); gridPnts->addValue(Pnt3f(-10, height, -3)); gridPnts->addValue(Pnt3f(10, height, -3)); gridPnts->addValue(Pnt3f(-10, height, -4)); gridPnts->addValue(Pnt3f(10, height, -4)); gridPnts->addValue(Pnt3f(-10, height, -5)); gridPnts->addValue(Pnt3f(10, height, -5)); gridPnts->addValue(Pnt3f(-10, height, -6)); gridPnts->addValue(Pnt3f(10, height, -6)); gridPnts->addValue(Pnt3f(-10, height, -7)); gridPnts->addValue(Pnt3f(10, height, -7)); gridPnts->addValue(Pnt3f(-10, height, -8)); gridPnts->addValue(Pnt3f(10, height, -8)); gridPnts->addValue(Pnt3f(-10, height, -9)); gridPnts->addValue(Pnt3f(10, height, -9)); gridPnts->addValue(Pnt3f(-10, height, -10)); gridPnts->addValue(Pnt3f(10, height, -10)); gridPnts->addValue(Pnt3f(0, height, -10)); if(height == 0) gridPnts->addValue(Pnt3f(0, height, 0)); else gridPnts->addValue(Pnt3f(0, height, 10)); gridPnts->addValue(Pnt3f(1, height, -10)); gridPnts->addValue(Pnt3f(1, height, 10)); gridPnts->addValue(Pnt3f(2, height, -10)); gridPnts->addValue(Pnt3f(2, height, 10)); gridPnts->addValue(Pnt3f(3, height, -10)); gridPnts->addValue(Pnt3f(3, height, 10)); gridPnts->addValue(Pnt3f(4, height, -10)); gridPnts->addValue(Pnt3f(4, height, 10)); gridPnts->addValue(Pnt3f(5, height, -10)); gridPnts->addValue(Pnt3f(5, height, 10)); gridPnts->addValue(Pnt3f(6, height, -10)); gridPnts->addValue(Pnt3f(6, height, 10)); gridPnts->addValue(Pnt3f(7, height, -10)); gridPnts->addValue(Pnt3f(7, height, 10)); gridPnts->addValue(Pnt3f(8, height, -10)); gridPnts->addValue(Pnt3f(8, height, 10)); gridPnts->addValue(Pnt3f(9, height, -10)); gridPnts->addValue(Pnt3f(9, height, 10)); gridPnts->addValue(Pnt3f(10, height, -10)); gridPnts->addValue(Pnt3f(10, height, 10)); gridPnts->addValue(Pnt3f(-1, height, -10)); gridPnts->addValue(Pnt3f(-1, height, 10)); gridPnts->addValue(Pnt3f(-2, height, -10)); gridPnts->addValue(Pnt3f(-2, height, 10)); gridPnts->addValue(Pnt3f(-3, height, -10)); gridPnts->addValue(Pnt3f(-3, height, 10)); gridPnts->addValue(Pnt3f(-4, height, -10)); gridPnts->addValue(Pnt3f(-4, height, 10)); gridPnts->addValue(Pnt3f(-5, height, -10)); gridPnts->addValue(Pnt3f(-5, height, 10)); gridPnts->addValue(Pnt3f(-6, height, -10)); gridPnts->addValue(Pnt3f(-6, height, 10)); gridPnts->addValue(Pnt3f(-7, height, -10)); gridPnts->addValue(Pnt3f(-7, height, 10)); gridPnts->addValue(Pnt3f(-8, height, -10)); gridPnts->addValue(Pnt3f(-8, height, 10)); gridPnts->addValue(Pnt3f(-9, height, -10)); gridPnts->addValue(Pnt3f(-9, height, 10)); gridPnts->addValue(Pnt3f(-10, height, -10)); gridPnts->addValue(Pnt3f(-10, height, 10)); } endEditCP (gridPnts, GeoPositions3f::GeoPropDataFieldMask); //Axes normals GeoNormals3fPtr axesNorms = GeoNormals3f::create(); beginEditCP(axesNorms, GeoNormals3f::GeoPropDataFieldMask); axesNorms->addValue(Vec3f( 0.0,0.0,1.0)); axesNorms->addValue(Vec3f( 0.0,0.0,1.0)); axesNorms->addValue(Vec3f( 0.0,0.0,1.0)); axesNorms->addValue(Vec3f( 0.0,0.0,1.0)); axesNorms->addValue(Vec3f( 1.0,0.0,0.0)); axesNorms->addValue(Vec3f( 1.0,0.0,0.0)); endEditCP(axesNorms, GeoNormals3f::GeoPropDataFieldMask); //Grid normals GeoNormals3fPtr gridNorms = GeoNormals3f::create(); beginEditCP(gridNorms, GeoNormals3f::GeoPropDataFieldMask); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); endEditCP(gridNorms, GeoNormals3f::GeoPropDataFieldMask); //Axes colors GeoColors3fPtr axesColors = GeoColors3f::create(); beginEditCP(axesColors, GeoColors3f::GeoPropDataFieldMask); //X-Axis = Red axesColors->addValue(Color3f( 1.0,0.0,0.0)); axesColors->addValue(Color3f( 1.0,0.0,0.0)); //Y-Axis = Green axesColors->addValue(Color3f( 0.0,1.0,0.0)); axesColors->addValue(Color3f( 0.0,1.0,0.0)); //Z-Axis = Blue axesColors->addValue(Color3f( 0.0,0.0,1.0)); axesColors->addValue(Color3f( 0.0,0.0,1.0)); endEditCP(axesColors, GeoColors3f::GeoPropDataFieldMask); //Grid gridColors GeoColors3fPtr gridColors = GeoColors3f::create(); beginEditCP(gridColors, GeoColors3f::GeoPropDataFieldMask); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); endEditCP(gridColors, GeoColors3f::GeoPropDataFieldMask); //Create axes geometry GeometryPtr axesGeo = Geometry::create(); beginEditCP(axesGeo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask); { axesGeo->setTypes (axesType); axesGeo->setLengths (axesLens); axesGeo->setPositions(axesPnts); axesGeo->setNormals(axesNorms); axesGeo->setColors(axesColors); // assign a material to the geometry to make it visible. The details // of materials are defined later. axesGeo->setMaterial(AxesMaterial); } endEditCP (axesGeo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask ); //Create grid geometry GeometryPtr gridGeo = Geometry::create(); beginEditCP(gridGeo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask); { gridGeo->setTypes (gridType); gridGeo->setLengths (gridLens); gridGeo->setPositions(gridPnts); gridGeo->setNormals(gridNorms); gridGeo->setColors(gridColors); // assign a material to the geometry to make it visible. The details // of materials are defined later. gridGeo->setMaterial(AxesMaterial); } endEditCP (gridGeo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask ); //Create unbound geometry Node Axes = osg::Node::create(); beginEditCP(Axes, Node::CoreFieldMask); Axes->setCore(axesGeo); endEditCP(Axes, Node::CoreFieldMask); //Create unbound geometry Node Grid = osg::Node::create(); beginEditCP(Grid, Node::CoreFieldMask); Grid->setCore(gridGeo); endEditCP(Grid, Node::CoreFieldMask); //Import scene from an XML file ChunkMaterialPtr ExampleMaterial; std::vector<SkeletonPtr> SkeletonPtrs; std::vector<SkeletonBlendedGeometryPtr> SkeletonBlendedGeometryPtrs; std::vector<GeometryPtr> GeometryPtrs; FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(Path("./Data/21SceneFromMaya.xml")); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { if( (*Itor)->getType() == (ChunkMaterial::getClassType())) { //Set ExampleMaterial to the ChunkMaterial we just read in ExampleMaterial = (ChunkMaterial::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Skeleton::getClassType())) { //Add the skeleton we just read in to SkeletonPtrs SkeletonPtrs.push_back(Skeleton::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType())) { //Add the SkeletonBlendedGeometry we just read in to SkeletonBlendedGeometryPtrs SkeletonBlendedGeometryPtrs.push_back(SkeletonBlendedGeometry::Ptr::dcast(*Itor)); } if( (*Itor)->getType().isDerivedFrom(SkeletonAnimation::getClassType())) { //Set TheSkeletonAnimation to the Animation we just read in TheSkeletonAnimation = (Animation::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Geometry::getClassType())) { //Add the Geometry we just read in to GeometryPtrs GeometryPtrs.push_back(Geometry::Ptr::dcast(*Itor)); } } //Create unbound geometry Node (to show the mesh in its bind pose) for (int i(0); i < GeometryPtrs.size(); ++i) { NodePtr UnboundGeometry = Node::create(); beginEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); UnboundGeometry->setCore(GeometryPtrs[i]); UnboundGeometry->setTravMask(0); endEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); UnboundGeometries.push_back(UnboundGeometry); } //Create skeleton nodes for (int i(0); i < SkeletonPtrs.size(); ++i) { //SkeletonDrawer SkeletonDrawablePtr ExampleSkeletonDrawable = osg::SkeletonDrawable::create(); beginEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask); ExampleSkeletonDrawable->setSkeleton(SkeletonPtrs[i]); ExampleSkeletonDrawable->setMaterial(AxesMaterial); ExampleSkeletonDrawable->setDrawPose(true); //By default we draw the current skeleton ExampleSkeletonDrawable->setPoseColor(Color4f(1.0, 0.0, 1.0, 1.0)); //Set color of current skeleton ExampleSkeletonDrawable->setDrawBindPose(false); //By default we don't draw the bind pose skeleton ExampleSkeletonDrawable->setBindPoseColor(Color4f(1.0, 1.0, 0.0, 1.0)); //Set color of bind pose skeleton endEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask); //Skeleton Node NodePtr SkeletonNode = osg::Node::create(); beginEditCP(SkeletonNode, Node::CoreFieldMask); SkeletonNode->setCore(ExampleSkeletonDrawable); endEditCP(SkeletonNode, Node::CoreFieldMask); SkeletonNodes.push_back(SkeletonNode); } //Create skeleton blended geometry nodes for (int i(0); i < SkeletonBlendedGeometryPtrs.size(); ++i) { NodePtr MeshNode = osg::Node::create(); beginEditCP(MeshNode, Node::CoreFieldMask); MeshNode->setCore(SkeletonBlendedGeometryPtrs[i]); endEditCP(MeshNode, Node::CoreFieldMask); MeshNodes.push_back(MeshNode); } //Create Animation Advancer TheAnimationAdvancer = osg::ElapsedTimeAnimationAdvancer::create(); osg::beginEditCP(TheAnimationAdvancer); osg::ElapsedTimeAnimationAdvancer::Ptr::dcast(TheAnimationAdvancer)->setStartTime( 0.0 ); osg::beginEditCP(TheAnimationAdvancer); //Add nodes to scene NodePtr scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(Axes); scene->addChild(Grid); //Add all imported skeletons to scene for (int i(0); i < SkeletonNodes.size(); ++i) { scene->addChild(SkeletonNodes[i]); } //Add all imported geometries to scene for (int i(0); i < UnboundGeometries.size(); ++i) { scene->addChild(UnboundGeometries[i]); } //Add all imported SkeletonBlendedGeometries to scene for (int i(0); i < MeshNodes.size(); ++i) { scene->addChild(MeshNodes[i]); } endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); mgr->setRoot(scene); //By default the animation is not paused animationPaused = false; // Show the whole Scene mgr->showAll(); TheAnimationAdvancer->start(); //Show window Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "21LoadXMLSceneFromMaya"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
NodePtr createScenegraph(){ // the scene must be created here for (int x = 0; x < N; x++) for (int z = 0; z < N; z++) wMesh[x][z] = 0; // GeoPTypes will define the types of primitives to be used GeoPTypesPtr type = GeoPTypesUI8::create(); beginEditCP(type, GeoPTypesUI8::GeoPropDataFieldMask); // we want to use quads ONLY type->addValue(GL_QUADS); endEditCP(type, GeoPTypesUI8::GeoPropDataFieldMask); // GeoPLength will define the number of vertices of // the used primitives GeoPLengthsPtr length = GeoPLengthsUI32::create(); beginEditCP(length, GeoPLengthsUI32::GeoPropDataFieldMask); // the length of our quads is four ;-) length->addValue((N-1)*(N-1)*4); endEditCP(length, GeoPLengthsUI32::GeoPropDataFieldMask); // GeoPositions3f stores the positions of all vertices used in // this specific geometry core GeoPositions3fPtr pos = GeoPositions3f::create(); beginEditCP(pos, GeoPositions3f::GeoPropDataFieldMask); // here they all come for (int x = 0; x < N; x++) for (int z = 0; z < N; z++) pos->addValue(Pnt3f(x, wMesh[x][z], z)); endEditCP(pos, GeoPositions3f::GeoPropDataFieldMask); //GeoColors3f stores all color values that will be used GeoColors3fPtr colors = GeoColors3f::create(); beginEditCP(colors, GeoColors3f::GeoPropDataFieldMask); for (int x = 0; x < N; x++) for (int z = 0; z < N; z++) colors->addValue(Color3f(0,0,1)); endEditCP(colors, GeoColors3f::GeoPropDataFieldMask); GeoNormals3fPtr norms = GeoNormals3f::create(); beginEditCP(norms, GeoNormals3f::GeoPropDataFieldMask); for (int x = 0; x < N; x++) for (int z = 0; z < N; z++) // As initially all heights are set to zero thus yielding a plane, // we set all normals to (0,1,0) parallel to the y-axis norms->addValue(Vec3f(0,1,0)); endEditCP(norms, GeoNormals3f::GeoPropDataFieldMask); SimpleMaterialPtr mat = SimpleMaterial::create(); beginEditCP(mat); mat->setDiffuse(Color3f(0,0,1)); endEditCP(mat); // GeoIndicesUI32 points to all relevant data used by the // provided primitives GeoIndicesUI32Ptr indices = GeoIndicesUI32::create(); beginEditCP(indices, GeoIndicesUI32::GeoPropDataFieldMask); for (int x = 0; x < N-1; x++) for (int z = 0; z < N-1; z++){ // points to four vertices that will // define a single quad indices->addValue(z*N+x); indices->addValue((z+1)*N+x); indices->addValue((z+1)*N+x+1); indices->addValue(z*N+x+1); } endEditCP(indices, GeoIndicesUI32::GeoPropDataFieldMask); GeometryPtr geo = Geometry::create(); beginEditCP(geo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::IndicesFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask | Geometry::DlistCacheFieldMask ); geo->setTypes(type); geo->setLengths(length); geo->setIndices(indices); geo->setPositions(pos); geo->setNormals(norms); geo->setMaterial(mat); //geo->setColors(colors); geo->setDlistCache(false); endEditCP(geo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::IndicesFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask | Geometry::DlistCacheFieldMask ); PointLightPtr pLight = PointLight::create(); NodePtr root = Node::create(); NodePtr water = Node::create(); NodePtr pLightTransformNode = Node::create(); TransformPtr pLightTransform = Transform::create(); NodePtr pLightNode = Node::create(); beginEditCP(pLightNode); pLightNode->setCore(Group::create()); endEditCP(pLightNode); Matrix m; m.setIdentity(); m.setTranslate(50,25,50); beginEditCP(pLightTransform); pLightTransform->setMatrix(m); endEditCP(pLightTransform); //we add a little spehere that will represent the light source GeometryPtr sphere = makeSphereGeo(2,2); SimpleMaterialPtr sm = SimpleMaterial::create(); beginEditCP(sm, SimpleMaterial::DiffuseFieldMask | SimpleMaterial::LitFieldMask); { sm->setLit(false); sm->setDiffuse(Color3f(1,1,1)); } endEditCP (sm, SimpleMaterial::DiffuseFieldMask | SimpleMaterial::LitFieldMask); beginEditCP(sphere, Geometry::MaterialFieldMask); { sphere->setMaterial(sm); } endEditCP (sphere, Geometry::MaterialFieldMask); NodePtr sphereNode = Node::create(); beginEditCP(sphereNode); sphereNode->setCore(sphere); endEditCP(sphereNode); beginEditCP(pLightTransformNode); pLightTransformNode->setCore(pLightTransform); pLightTransformNode->addChild(pLightNode); pLightTransformNode->addChild(sphereNode); endEditCP(pLightTransformNode); beginEditCP(pLight); pLight->setPosition(Pnt3f(0,0,0)); //Attenuation parameters pLight->setConstantAttenuation(1); pLight->setLinearAttenuation(0); pLight->setQuadraticAttenuation(0); //color information pLight->setDiffuse(Color4f(1,1,1,1)); pLight->setAmbient(Color4f(0.2,0.2,0.2,1)); pLight->setSpecular(Color4f(1,1,1,1)); //set the beacon pLight->setBeacon(pLightNode); endEditCP (pLight); beginEditCP(water); water->setCore(geo); endEditCP(water); beginEditCP(root); root->setCore(pLight); root->addChild(water); root->addChild(pLightTransformNode); endEditCP(root); return root; }
NodePtr createScenegraph(){ // the scene must be created here for (int x = 0; x < N; x++) for (int z = 0; z < N; z++) wMesh[x][z] = 0; // GeoPTypes will define the types of primitives to be used GeoPTypesPtr type = GeoPTypesUI8::create(); beginEditCP(type, GeoPTypesUI8::GeoPropDataFieldMask); // we want to use quads ONLY type->addValue(GL_QUADS); endEditCP(type, GeoPTypesUI8::GeoPropDataFieldMask); // GeoPLength will define the number of vertices of // the used primitives GeoPLengthsPtr length = GeoPLengthsUI32::create(); beginEditCP(length, GeoPLengthsUI32::GeoPropDataFieldMask); // the length of our quads is four ;-) length->addValue((N-1)*(N-1)*4); endEditCP(length, GeoPLengthsUI32::GeoPropDataFieldMask); // GeoPositions3f stores the positions of all vertices used in // this specific geometry core GeoPositions3fPtr pos = GeoPositions3f::create(); beginEditCP(pos, GeoPositions3f::GeoPropDataFieldMask); // here they all come for (int x = 0; x < N; x++) for (int z = 0; z < N; z++) pos->addValue(Pnt3f(x, wMesh[x][z], z)); endEditCP(pos, GeoPositions3f::GeoPropDataFieldMask); //GeoColors3f stores all color values that will be used GeoColors3fPtr colors = GeoColors3f::create(); beginEditCP(colors, GeoColors3f::GeoPropDataFieldMask); for (int x = 0; x < N; x++) for (int z = 0; z < N; z++) colors->addValue(Color3f(0,0,1)); endEditCP(colors, GeoColors3f::GeoPropDataFieldMask); GeoNormals3fPtr norms = GeoNormals3f::create(); beginEditCP(norms, GeoNormals3f::GeoPropDataFieldMask); for (int x = 0; x < N; x++) for (int z = 0; z < N; z++) // As initially all heights are set to zero thus yielding a plane, // we set all normals to (0,1,0) parallel to the y-axis norms->addValue(Vec3f(0,1,0)); endEditCP(norms, GeoNormals3f::GeoPropDataFieldMask); SimpleMaterialPtr mat = SimpleMaterial::create(); // GeoIndicesUI32 points to all relevant data used by the // provided primitives GeoIndicesUI32Ptr indices = GeoIndicesUI32::create(); beginEditCP(indices, GeoIndicesUI32::GeoPropDataFieldMask); for (int x = 0; x < N-1; x++) for (int z = 0; z < N-1; z++){ // points to four vertices that will // define a single quad indices->addValue(z*N+x); indices->addValue((z+1)*N+x); indices->addValue((z+1)*N+x+1); indices->addValue(z*N+x+1); } endEditCP(indices, GeoIndicesUI32::GeoPropDataFieldMask); GeometryPtr geo = Geometry::create(); beginEditCP(geo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::IndicesFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask ); geo->setTypes(type); geo->setLengths(length); geo->setIndices(indices); geo->setPositions(pos); geo->setNormals(norms); geo->setMaterial(mat); geo->setColors(colors); endEditCP(geo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::IndicesFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask ); NodePtr root = Node::create(); beginEditCP(root); root->setCore(geo); endEditCP(root); return root; }
bool vtkOsgConverter::WriteAnActor() { vtkMapper* actorMapper = _actor->GetMapper(); // see if the actor has a mapper. it could be an assembly if (actorMapper == NULL) return false; // dont export when not visible if (_actor->GetVisibility() == 0) return false; vtkDataObject* inputDO = actorMapper->GetInputDataObject(0, 0); if (inputDO == NULL) return false; // Get PolyData. Convert if necessary becasue we only want polydata vtkSmartPointer<vtkPolyData> pd; if(inputDO->IsA("vtkCompositeDataSet")) { vtkCompositeDataGeometryFilter* gf = vtkCompositeDataGeometryFilter::New(); gf->SetInput(inputDO); gf->Update(); pd = gf->GetOutput(); gf->Delete(); } else if(inputDO->GetDataObjectType() != VTK_POLY_DATA) { vtkGeometryFilter* gf = vtkGeometryFilter::New(); gf->SetInput(inputDO); gf->Update(); pd = gf->GetOutput(); gf->Delete(); } else pd = static_cast<vtkPolyData*>(inputDO); // Get the color range from actors lookup table double range[2]; vtkLookupTable* actorLut = static_cast<vtkLookupTable*>(actorMapper->GetLookupTable()); actorLut->GetTableRange(range); // Copy mapper to a new one vtkPolyDataMapper* pm = vtkPolyDataMapper::New(); // Convert cell data to point data // NOTE: Comment this out to export a mesh if (actorMapper->GetScalarMode() == VTK_SCALAR_MODE_USE_CELL_DATA || actorMapper->GetScalarMode() == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA) { vtkCellDataToPointData* cellDataToPointData = vtkCellDataToPointData::New(); cellDataToPointData->PassCellDataOff(); cellDataToPointData->SetInput(pd); cellDataToPointData->Update(); pd = cellDataToPointData->GetPolyDataOutput(); cellDataToPointData->Delete(); pm->SetScalarMode(VTK_SCALAR_MODE_USE_POINT_DATA); } else pm->SetScalarMode(actorMapper->GetScalarMode()); pm->SetInput(pd); pm->SetScalarVisibility(actorMapper->GetScalarVisibility()); vtkLookupTable* lut = NULL; // ParaView OpenSG Exporter if (dynamic_cast<vtkDiscretizableColorTransferFunction*>(actorMapper->GetLookupTable())) lut = actorLut; // Clone the lut in OGS because otherwise the original lut gets destroyed else { lut = vtkLookupTable::New(); lut->DeepCopy(actorLut); lut->Build(); } pm->SetLookupTable(lut); pm->SetScalarRange(range); pm->Update(); if(pm->GetScalarMode() == VTK_SCALAR_MODE_USE_POINT_FIELD_DATA || pm->GetScalarMode() == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA ) { if(actorMapper->GetArrayAccessMode() == VTK_GET_ARRAY_BY_ID ) pm->ColorByArrayComponent(actorMapper->GetArrayId(), actorMapper->GetArrayComponent()); else pm->ColorByArrayComponent(actorMapper->GetArrayName(), actorMapper->GetArrayComponent()); } vtkPointData* pntData = pd->GetPointData(); bool hasTexCoords = false; vtkUnsignedCharArray* vtkColors = pm->MapScalars(1.0); // ARRAY SIZES vtkIdType m_iNumPoints = pd->GetNumberOfPoints(); if (m_iNumPoints == 0) return false; vtkIdType m_iNumGLPoints = pd->GetVerts()->GetNumberOfCells(); vtkIdType m_iNumGLLineStrips = pd->GetLines()->GetNumberOfCells(); vtkIdType m_iNumGLPolygons = pd->GetPolys()->GetNumberOfCells(); vtkIdType m_iNumGLTriStrips = pd->GetStrips()->GetNumberOfCells(); vtkIdType m_iNumGLPrimitives = m_iNumGLPoints + m_iNumGLLineStrips + m_iNumGLPolygons + m_iNumGLTriStrips; bool lit = !(m_iNumGLPolygons == 0 && m_iNumGLTriStrips == 0); if (_verbose) { std::cout << "Array sizes:" << std::endl; std::cout << " number of vertices: " << m_iNumPoints << std::endl; std::cout << " number of GL_POINTS: " << m_iNumGLPoints << std::endl; std::cout << " number of GL_LINE_STRIPS: " << m_iNumGLLineStrips << std::endl; std::cout << " number of GL_POLYGON's: " << m_iNumGLPolygons << std::endl; std::cout << " number of GL_TRIANGLE_STRIPS: " << m_iNumGLTriStrips << std::endl; std::cout << " number of primitives: " << m_iNumGLPrimitives << std::endl; } // NORMALS vtkDataArray* vtkNormals = NULL; int m_iNormalType = NOT_GIVEN; if (_actor->GetProperty()->GetInterpolation() == VTK_FLAT) { vtkNormals = pd->GetCellData()->GetNormals(); if (vtkNormals != NULL) m_iNormalType = PER_CELL; } else { vtkNormals = pntData->GetNormals(); if (vtkNormals != NULL) m_iNormalType = PER_VERTEX; } if (_verbose) { std::cout << "Normals:" << std::endl; if (m_iNormalType != NOT_GIVEN) { std::cout << " number of normals: " << vtkNormals->GetNumberOfTuples() << std::endl; std::cout << " normals are given: "; std::cout << ((m_iNormalType == PER_VERTEX) ? "per vertex" : "per cell") << std::endl; } else std::cout << " no normals are given" << std::endl; } // COLORS int m_iColorType = NOT_GIVEN; if(pm->GetScalarVisibility()) { int iScalarMode = pm->GetScalarMode(); if(vtkColors == NULL) { m_iColorType = NOT_GIVEN; std::cout << "WARNING: MapScalars(1.0) did not return array!" << std::endl; } else if(iScalarMode == VTK_SCALAR_MODE_USE_CELL_DATA) m_iColorType = PER_CELL; else if(iScalarMode == VTK_SCALAR_MODE_USE_POINT_DATA) m_iColorType = PER_VERTEX; else if(iScalarMode == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA) { std::cout << "WARNING TO BE REMOVED: Can not process colours with scalar mode using cell field data!" << std::endl; m_iColorType = PER_CELL; } else if(iScalarMode == VTK_SCALAR_MODE_USE_POINT_FIELD_DATA) { std::cout << "WARNING TO BE REMOVED: Can not process colours with scalar mode using point field data!" << std::endl; m_iColorType = PER_VERTEX; } else if(iScalarMode == VTK_SCALAR_MODE_DEFAULT) { //Bummer, we do not know what it is. may be we can make a guess int numColors = vtkColors->GetNumberOfTuples(); if (numColors == 0) { m_iColorType = NOT_GIVEN; std::cout << "WARNING: No colors found!" << std::endl; } else if (numColors == m_iNumPoints) m_iColorType = PER_VERTEX; else if (numColors == m_iNumGLPrimitives) m_iColorType = PER_CELL; else { m_iColorType = NOT_GIVEN; std::cout << "WARNING: Number of colors do not match number of points / cells!" << std::endl; } } } if (_verbose) { std::cout << "Colors:" << std::endl; if (m_iColorType != NOT_GIVEN) { std::cout << " number of colors: " << vtkColors->GetNumberOfTuples() << std::endl; std::cout << " colors are given: " << ((m_iColorType == PER_VERTEX) ? "per vertex" : "per cell") << std::endl; } else std::cout << " no colors are given" << std::endl; } // TEXCOORDS vtkDataArray* vtkTexCoords = pntData->GetTCoords(); if (_verbose) { std::cout << "Tex-coords:" << std::endl; if (vtkTexCoords) { std::cout << " Number of tex-coords: " << vtkTexCoords->GetNumberOfTuples() << std::endl; hasTexCoords = true; } else std::cout << " No tex-coords where given" << std::endl; } // TRANSFORMATION double scaling[3]; double translation[3]; // double rotation[3]; _actor->GetPosition(translation); _actor->GetScale(scaling); //_actor->GetRotation(rotation[0], rotation[1], rotation[2]); if (_verbose) std::cout << "set scaling: " << scaling[0] << " " << scaling[1] << " " << scaling[2] << std::endl; osg::Matrix m; m.setIdentity(); m.setTranslate(translation[0], translation[1], translation[2]); m.setScale(scaling[0], scaling[1], scaling[2]); // TODO QUATERNION m.setRotate(rotation[0], rotation[1], rotation[2]) beginEditCP(_osgTransform); _osgTransform->setMatrix(m); endEditCP(_osgTransform); //pm->Update(); // Get the converted OpenSG node NodePtr osgGeomNode = Node::create(); GeometryPtr osgGeometry = Geometry::create(); beginEditCP(osgGeomNode); osgGeomNode->setCore(osgGeometry); endEditCP(osgGeomNode); bool osgConversionSuccess = false; GeoPTypesPtr osgTypes = GeoPTypesUI8::create(); GeoPLengthsPtr osgLengths = GeoPLengthsUI32::create(); GeoIndicesUI32Ptr osgIndices = GeoIndicesUI32::create(); GeoPositions3fPtr osgPoints = GeoPositions3f::create(); GeoNormals3fPtr osgNormals = GeoNormals3f::create(); GeoColors3fPtr osgColors = GeoColors3f::create(); GeoTexCoords2dPtr osgTexCoords = GeoTexCoords2d::create(); //Rendering with OpenSG simple indexed geometry if (((m_iNormalType == PER_VERTEX) || (m_iNormalType == NOT_GIVEN)) && ((m_iColorType == PER_VERTEX) || (m_iColorType == NOT_GIVEN))) { if (_verbose) std::cout << "Start ProcessGeometryNormalsAndColorsPerVertex()" << std::endl; //getting the vertices: beginEditCP(osgPoints); { for (int i = 0; i < m_iNumPoints; i++) { double* aVertex = pd->GetPoint(i); osgPoints->addValue(Vec3f(aVertex[0], aVertex[1], aVertex[2])); } } endEditCP(osgPoints); //possibly getting the normals if (m_iNormalType == PER_VERTEX) { vtkIdType iNumNormals = vtkNormals->GetNumberOfTuples(); beginEditCP(osgNormals); { double* aNormal; for (int i = 0; i < iNumNormals; i++) { aNormal = vtkNormals->GetTuple(i); osgNormals->addValue(Vec3f(aNormal[0], aNormal[1], aNormal[2])); } } endEditCP(osgNormals); if (iNumNormals != m_iNumPoints) { std::cout << "WARNING: CVtkActorToOpenSG::ProcessGeometryNormalsAndColorsPerVertex() number of normals" << std::endl; std::cout << "should equal the number of vertices (points)!" << std::endl << std::endl; } } //possibly getting the colors if (m_iColorType == PER_VERTEX) { vtkIdType iNumColors = vtkColors->GetNumberOfTuples(); beginEditCP(osgColors); { unsigned char aColor[4]; for (int i = 0; i < iNumColors; i++) { vtkColors->GetTupleValue(i, aColor); float r = ((float) aColor[0]) / 255.0f; float g = ((float) aColor[1]) / 255.0f; float b = ((float) aColor[2]) / 255.0f; osgColors->addValue(Color3f(r, g, b)); } } endEditCP(osgColors); if (iNumColors != m_iNumPoints) { std::cout << "WARNING: CVtkActorToOpenSG::ProcessGeometryNormalsAndColorsPerVertex() number of colors" << std::endl; std::cout << "should equal the number of vertices (points)!" << std::endl << std::endl; } } //possibly getting the texture coordinates. These are alwary per vertex if (vtkTexCoords != NULL) { int numTuples = vtkTexCoords->GetNumberOfTuples(); for (int i = 0; i < numTuples; i++) { double texCoords[3]; vtkTexCoords->GetTuple(i, texCoords); osgTexCoords->addValue(Vec2f(texCoords[0], texCoords[1])); } } //getting the cells beginEditCP(osgTypes); beginEditCP(osgLengths); beginEditCP(osgIndices); { vtkCellArray* pCells; vtkIdType npts, * pts; int prim; prim = 0; pCells = pd->GetVerts(); if (pCells->GetNumberOfCells() > 0) for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) { osgLengths->addValue(npts); osgTypes->addValue(GL_POINTS); for (int i = 0; i < npts; i++) osgIndices->addValue(pts[i]); } prim = 0; pCells = pd->GetLines(); if (pCells->GetNumberOfCells() > 0) for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) { osgLengths->addValue(npts); osgTypes->addValue(GL_LINE_STRIP); for (int i = 0; i < npts; i++) osgIndices->addValue(pts[i]); } prim = 0; pCells = pd->GetPolys(); if (pCells->GetNumberOfCells() > 0) for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) { osgLengths->addValue(npts); osgTypes->addValue(GL_POLYGON); for (int i = 0; i < npts; i++) osgIndices->addValue(pts[i]); } prim = 0; pCells = pd->GetStrips(); if (pCells->GetNumberOfCells() > 0) for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) { osgLengths->addValue(npts); osgTypes->addValue(GL_TRIANGLE_STRIP); for (int i = 0; i < npts; i++) osgIndices->addValue(pts[i]); } } endEditCP(osgIndices); endEditCP(osgLengths); endEditCP(osgTypes); ChunkMaterialPtr material = CreateMaterial(lit, hasTexCoords); beginEditCP(osgGeometry); { osgGeometry->setPositions(osgPoints); osgGeometry->setTypes(osgTypes); osgGeometry->setLengths(osgLengths); osgGeometry->setIndices(osgIndices); osgGeometry->setMaterial(material); if (m_iNormalType == PER_VERTEX) osgGeometry->setNormals(osgNormals); if (m_iColorType == PER_VERTEX) osgGeometry->setColors(osgColors); if (osgTexCoords->getSize() > 0) osgGeometry->setTexCoords(osgTexCoords); } endEditCP(osgGeometry); osgConversionSuccess = true; if (_verbose) std::cout << " End ProcessGeometryNormalsAndColorsPerVertex()" << std::endl; } else { //Rendering with OpenSG non indexed geometry by copying a lot of attribute data if (_verbose) std::cout << "Start ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type)" << std::endl; int gl_primitive_type = -1; if(m_iNumGLPolygons > 0) { if(m_iNumGLPolygons != m_iNumGLPrimitives) std::cout << "WARNING: vtkActor contains different kind of primitives" << std::endl; gl_primitive_type = GL_POLYGON; //osgConversionSuccess = this->ProcessGeometryNonIndexedCopyAttributes(GL_POLYGON, pd, osgGeometry); } else if(m_iNumGLLineStrips > 0) { if (m_iNumGLLineStrips != m_iNumGLPrimitives) std::cout << "WARNING: vtkActor contains different kind of primitives" << std::endl; gl_primitive_type = GL_LINE_STRIP; //osgConversionSuccess = this->ProcessGeometryNonIndexedCopyAttributes(GL_LINE_STRIP, pd osgGeometry); } else if(m_iNumGLTriStrips > 0) { if (m_iNumGLTriStrips != m_iNumGLPrimitives) std::cout << "WARNING: vtkActor contains different kind of primitives" << std::endl; gl_primitive_type = GL_TRIANGLE_STRIP; //osgConversionSuccess = this->ProcessGeometryNonIndexedCopyAttributes(GL_TRIANGLE_STRIP, pd osgGeometry); } else if (m_iNumGLPoints > 0) { if (m_iNumGLPoints != m_iNumGLPrimitives) std::cout << "WARNING: vtkActor contains different kind of primitives" << std::endl; gl_primitive_type = GL_POINTS; //osgConversionSuccess = this->ProcessGeometryNonIndexedCopyAttributes(GL_POINTS, pd osgGeometry); } if(gl_primitive_type != -1) { vtkCellArray* pCells; if (gl_primitive_type == GL_POINTS) pCells = pd->GetVerts(); else if (gl_primitive_type == GL_LINE_STRIP) pCells = pd->GetLines(); else if (gl_primitive_type == GL_POLYGON) pCells = pd->GetPolys(); else if (gl_primitive_type == GL_TRIANGLE_STRIP) pCells = pd->GetStrips(); else { std::cout << "CVtkActorToOpenSG::ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type)" << std::endl << " was called with non implemented gl_primitive_type!" << std::endl; } beginEditCP(osgTypes); beginEditCP(osgLengths); beginEditCP(osgPoints); beginEditCP(osgColors); beginEditCP(osgNormals); { int prim = 0; if (pCells->GetNumberOfCells() > 0) { vtkIdType npts, * pts; for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) { osgLengths->addValue(npts); osgTypes->addValue(GL_POLYGON); for (int i = 0; i < npts; i++) { double* aVertex; double* aNormal; unsigned char aColor[4]; aVertex = pd->GetPoint(pts[i]); osgPoints->addValue(Vec3f(aVertex[0], aVertex[1], aVertex[2])); if (m_iNormalType == PER_VERTEX) { aNormal = vtkNormals->GetTuple(pts[i]); osgNormals->addValue(Vec3f(aNormal[0], aNormal[1], aNormal[2])); } else if (m_iNormalType == PER_CELL) { aNormal = vtkNormals->GetTuple(prim); osgNormals->addValue(Vec3f(aNormal[0], aNormal[1], aNormal[2])); } if (m_iColorType == PER_VERTEX) { vtkColors->GetTupleValue(pts[i], aColor); float r = ((float) aColor[0]) / 255.0f; float g = ((float) aColor[1]) / 255.0f; float b = ((float) aColor[2]) / 255.0f; osgColors->addValue(Color3f(r, g, b)); } else if (m_iColorType == PER_CELL) { vtkColors->GetTupleValue(prim, aColor); float r = ((float) aColor[0]) / 255.0f; float g = ((float) aColor[1]) / 255.0f; float b = ((float) aColor[2]) / 255.0f; osgColors->addValue(Color3f(r, g, b)); } } } } } endEditCP(osgTypes); endEditCP(osgLengths); endEditCP(osgPoints); endEditCP(osgColors); endEditCP(osgNormals); //possibly getting the texture coordinates. These are always per vertex vtkPoints* points = pd->GetPoints(); if ((vtkTexCoords != NULL) && (points != NULL)) { int numPoints = points->GetNumberOfPoints(); int numTexCoords = vtkTexCoords->GetNumberOfTuples(); if (numPoints == numTexCoords) { beginEditCP(osgTexCoords); { int numTuples = vtkTexCoords->GetNumberOfTuples(); for (int i = 0; i < numTuples; i++) { double texCoords[3]; vtkTexCoords->GetTuple(i, texCoords); osgTexCoords->addValue(Vec2f(texCoords[0], texCoords[1])); } } endEditCP(osgTexCoords); } } ChunkMaterialPtr material = CreateMaterial(lit, hasTexCoords); //GeometryPtr geo = Geometry::create(); beginEditCP(osgGeometry); { osgGeometry->setPositions(osgPoints); osgGeometry->setTypes(osgTypes); osgGeometry->setLengths(osgLengths); osgGeometry->setMaterial(material); if (m_iNormalType != NOT_GIVEN) osgGeometry->setNormals(osgNormals); if (m_iColorType != NOT_GIVEN) osgGeometry->setColors(osgColors); if (osgTexCoords->getSize() > 0) osgGeometry->setTexCoords(osgTexCoords); //geo->setMaterial(getDefaultMaterial()); } endEditCP(osgGeometry); osgConversionSuccess = true; } if (_verbose) std::cout << " End ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type)" << std::endl; } if(!osgConversionSuccess) { std::cout << "OpenSG converter was not able to convert this actor." << std::endl; return false; } if(m_iNormalType == NOT_GIVEN) { //GeometryPtr newGeometryPtr = GeometryPtr::dcast(newNodePtr->getCore()); if((osgGeometry != NullFC) && (m_iColorType == PER_VERTEX)) { std::cout << "WARNING: Normals are missing in the vtk layer, calculating normals per vertex!" << std::endl; calcVertexNormals(osgGeometry); } else if ((osgGeometry != NullFC) && (m_iColorType == PER_CELL)) { std::cout << "WARNING: Normals are missing in the vtk layer, calculating normals per face!" << std::endl; calcFaceNormals(osgGeometry); } else if (osgGeometry != NullFC) { std::cout << "WARNING: Normals are missing in the vtk layer, calculating normals per vertex!" << std::endl; calcVertexNormals(osgGeometry); } } std::cout << "Conversion finished." << std::endl; // Add node to root beginEditCP(_osgRoot); _osgRoot->addChild(osgGeomNode); endEditCP(_osgRoot); pm->Delete(); return true; }
int main(int argc, char *argv[]) { osgLogP->setLogLevel(LOG_NOTICE); osgInit(argc, argv); int winid = setupGLUT(&argc, argv); // create a GLUT window GLUTWindowPtr gwin = GLUTWindow::create(); gwin->setId(winid); gwin->init(); osgLogP->setLogLevel(LOG_DEBUG); // build the test scene NodePtr pRoot = Node ::create(); GroupPtr pRootCore = Group::create(); NodePtr pRayGeo = Node ::create(); NodePtr pScene = buildGraph(); GroupPtr pSceneCore = Group::create(); Time tStart; Time tStop; Time tDFTotal = 0.0; Time tDFSTotal = 0.0; Time tPTotal = 0.0; Time tOTotal = 0.0; StatCollector statP; StatCollector statDF; StatCollector statDFS; beginEditCP(pRoot, Node::CoreFieldId | Node::ChildrenFieldId); pRoot->setCore (pRootCore ); pRoot->addChild(pScene ); pRoot->addChild(pRayGeo ); endEditCP (pRoot, Node::CoreFieldId | Node::ChildrenFieldId); createRays(uiNumRays, testRays); // build the geometry to visualize the rays pPoints = GeoPositions3f::create(); beginEditCP(pPoints); pPoints->addValue(Pnt3f(0.0, 0.0, 0.0)); pPoints->addValue(Pnt3f(0.0, 0.0, 0.0)); pPoints->addValue(Pnt3f(0.0, 0.0, 0.0)); pPoints->addValue(Pnt3f(0.0, 0.0, 0.0)); pPoints->addValue(Pnt3f(0.0, 0.0, 0.0)); endEditCP (pPoints); GeoIndicesUI32Ptr pIndices = GeoIndicesUI32::create(); beginEditCP(pIndices); pIndices->addValue(0); pIndices->addValue(1); pIndices->addValue(2); pIndices->addValue(3); pIndices->addValue(4); endEditCP (pIndices); GeoPLengthsPtr pLengths = GeoPLengthsUI32::create(); beginEditCP(pLengths); pLengths->addValue(2); pLengths->addValue(3); endEditCP (pLengths); GeoPTypesPtr pTypes = GeoPTypesUI8::create(); beginEditCP(pTypes); pTypes->addValue(GL_LINES ); pTypes->addValue(GL_TRIANGLES); endEditCP (pTypes); GeoColors3fPtr pColors = GeoColors3f::create(); beginEditCP(pColors); pColors->addValue(Color3f(1.0, 1.0, 1.0)); pColors->addValue(Color3f(1.0, 0.0, 0.0)); pColors->addValue(Color3f(1.0, 0.0, 0.0)); pColors->addValue(Color3f(1.0, 0.0, 0.0)); pColors->addValue(Color3f(1.0, 0.0, 0.0)); endEditCP (pColors); SimpleMaterialPtr pMaterial = SimpleMaterial::create(); beginEditCP(pMaterial); pMaterial->setLit(false); endEditCP (pMaterial); GeometryPtr pRayGeoCore = Geometry::create(); beginEditCP(pRayGeoCore); pRayGeoCore->setPositions(pPoints ); pRayGeoCore->setIndices (pIndices ); pRayGeoCore->setLengths (pLengths ); pRayGeoCore->setTypes (pTypes ); pRayGeoCore->setColors (pColors ); pRayGeoCore->setMaterial (pMaterial); endEditCP (pRayGeoCore); beginEditCP(pRayGeo, Node::CoreFieldId); pRayGeo->setCore(pRayGeoCore); endEditCP (pRayGeo, Node::CoreFieldId); IntersectActor::regDefaultClassEnter( osgTypedFunctionFunctor2CPtr< NewActionTypes::ResultE, NodeCorePtr, ActorBase::FunctorArgumentType & >(enterDefault)); NewActionBase *pDFAction = DepthFirstAction ::create(); NewActionBase *pDFSAction = DepthFirstStateAction::create(); NewActionBase *pPAction = PriorityAction ::create(); IntersectActor *pIActorDF = IntersectActor ::create(); IntersectActor *pIActorDFS = IntersectActor ::create(); IntersectActor *pIActorP = IntersectActor ::create(); pDFAction ->setStatistics(&statDF ); pDFSAction->setStatistics(&statDFS); pPAction ->setStatistics(&statP ); // IntersectActor with DFS-Action does not need leave calls pIActorDFS->setLeaveNodeFlag(false); pDFAction ->addActor(pIActorDF ); pDFSAction->addActor(pIActorDFS); pPAction ->addActor(pIActorP ); // create old action IntersectAction *pIntAction = IntersectAction ::create(); // make sure bv are up to date pScene->updateVolume(); SINFO << "-=< Intersect >=-" << endLog; std::vector<Line>::iterator itRays = testRays.begin(); std::vector<Line>::iterator endRays = testRays.end (); for(; itRays != endRays; ++itRays) { // DepthFirst tStart = getSystemTime(); pIActorDF->setRay (*itRays); pIActorDF->setMaxDistance(10000.0); pIActorDF->reset ( ); pDFAction->apply(pScene); tStop = getSystemTime(); tDFTotal += (tStop - tStart); if(pIActorDF->getHit() == true) { IntersectResult result; result._hit = true; result._pObj = pIActorDF->getHitObject (); result._tri = pIActorDF->getHitTriangleIndex(); result._dist = pIActorDF->getHitDistance (); result._time = (tStop - tStart); resultsDF.push_back(result); } else { IntersectResult result; result._hit = false; result._pObj = NullFC; result._tri = -1; result._dist = 0.0; result._time = (tStop - tStart); resultsDF.push_back(result); } std::string strStatDF; statDF.putToString(strStatDF); //SINFO << "stat DF: " << strStatDF << endLog; // Depth First State tStart = getSystemTime(); pIActorDFS->setRay (*itRays); pIActorDFS->setMaxDistance(10000.0); pIActorDFS->reset ( ); pDFSAction->apply(pScene); tStop = getSystemTime(); tDFSTotal += (tStop - tStart); if(pIActorDFS->getHit() == true) { IntersectResult result; result._hit = true; result._pObj = pIActorDFS->getHitObject (); result._tri = pIActorDFS->getHitTriangleIndex(); result._dist = pIActorDFS->getHitDistance (); result._time = (tStop - tStart); resultsDFS.push_back(result); } else { IntersectResult result; result._hit = false; result._pObj = NullFC; result._tri = -1; result._dist = 0.0; result._time = (tStop - tStart); resultsDFS.push_back(result); } std::string strStatDFS; statDFS.putToString(strStatDFS); //SINFO << "stat DFS: " << strStatDFS << endLog; // Priority tStart = getSystemTime(); pIActorP->setRay (*itRays); pIActorP->setMaxDistance(10000.0); pIActorP->reset ( ); pPAction->apply(pScene); tStop = getSystemTime(); tPTotal += (tStop - tStart); if(pIActorP->getHit() == true) { IntersectResult result; result._hit = true; result._pObj = pIActorP->getHitObject (); result._tri = pIActorP->getHitTriangleIndex(); result._dist = pIActorP->getHitDistance (); result._time = (tStop - tStart); resultsP.push_back(result); } else { IntersectResult result; result._hit = false; result._pObj = NullFC; result._tri = -1; result._dist = 0.0; result._time = (tStop - tStart); resultsP.push_back(result); } std::string strStatP; statP.putToString(strStatP); //SINFO << "stat P: " << strStatP << endLog; // Old tStart = getSystemTime(); pIntAction->setLine(*itRays, 100000); pIntAction->apply (pScene ); tStop = getSystemTime(); tOTotal += (tStop - tStart); if(pIntAction->didHit() == true) { IntersectResult result; result._hit = true; result._pObj = pIntAction->getHitObject (); result._tri = pIntAction->getHitTriangle(); result._dist = pIntAction->getHitT (); result._time = (tStop - tStart); resultsO.push_back(result); } else { IntersectResult result; result._hit = false; result._pObj = NullFC; result._tri = -1; result._dist = 0.0; result._time = (tStop - tStart); resultsO.push_back(result); } } UInt32 DFwins = 0; UInt32 DFwinsHit = 0; UInt32 DFwinsMiss = 0; UInt32 DFSwins = 0; UInt32 DFSwinsHit = 0; UInt32 DFSwinsMiss = 0; UInt32 Pwins = 0; UInt32 PwinsHit = 0; UInt32 PwinsMiss = 0; UInt32 Owins = 0; UInt32 OwinsHit = 0; UInt32 OwinsMiss = 0; UInt32 failCount = 0; UInt32 passCount = 0; UInt32 hitCount = 0; UInt32 missCount = 0; for(UInt32 i = 0; i < uiNumRays; ++i) { bool DFfastest = ((resultsDF [i]._time <= resultsDFS[i]._time) && (resultsDF [i]._time <= resultsP [i]._time) && (resultsDF [i]._time <= resultsO [i]._time) ); bool DFSfastest = ((resultsDFS[i]._time <= resultsDF [i]._time) && (resultsDFS[i]._time <= resultsP [i]._time) && (resultsDFS[i]._time <= resultsO [i]._time) ); bool Pfastest = ((resultsP [i]._time <= resultsDF [i]._time) && (resultsP [i]._time <= resultsDFS[i]._time) && (resultsP [i]._time <= resultsO [i]._time) ); bool Ofastest = ((resultsO [i]._time <= resultsDF [i]._time) && (resultsO [i]._time <= resultsDFS[i]._time) && (resultsO [i]._time <= resultsP [i]._time) ); if((resultsDF [i]._hit == resultsDFS[i]._hit) && (resultsDFS[i]._hit == resultsP [i]._hit) && (resultsP [i]._hit == resultsO [i]._hit) ) { if((osgabs(resultsDF [i]._dist - resultsDFS[i]._dist) >= 0.001) || (osgabs(resultsDFS[i]._dist - resultsP [i]._dist) >= 0.001) || (osgabs(resultsP [i]._dist - resultsO [i]._dist) >= 0.001) || (osgabs(resultsO [i]._dist - resultsDF [i]._dist) >= 0.001) ) { ++failCount; SINFO << "FAIL: df: " << resultsDF [i]._dist << " dfs: " << resultsDFS[i]._dist << " p: " << resultsP [i]._dist << " o: " << resultsO [i]._dist << endLog; SINFO << "FAIL: df: " << resultsDF [i]._tri << " dfs: " << resultsDFS[i]._tri << " p: " << resultsP [i]._tri << " o: " << resultsO [i]._tri << endLog; } else { ++passCount; } if(resultsDF[i]._hit == true) { ++hitCount; DFwinsHit = DFfastest ? DFwinsHit + 1 : DFwinsHit; DFSwinsHit = DFSfastest ? DFSwinsHit + 1 : DFSwinsHit; PwinsHit = Pfastest ? PwinsHit + 1 : PwinsHit; OwinsHit = Ofastest ? OwinsHit + 1 : OwinsHit; } else { ++missCount; DFwinsMiss = DFfastest ? DFwinsMiss + 1 : DFwinsMiss; DFSwinsMiss = DFSfastest ? DFSwinsMiss + 1 : DFSwinsMiss; PwinsMiss = Pfastest ? PwinsMiss + 1 : PwinsMiss; OwinsMiss = Ofastest ? OwinsMiss + 1 : OwinsMiss; } DFwins = DFfastest ? DFwins + 1 : DFwins; DFSwins = DFSfastest ? DFSwins + 1 : DFSwins; Pwins = Pfastest ? Pwins + 1 : Pwins; Owins = Ofastest ? Owins + 1 : Owins; } else { ++failCount; } //SINFO << i << " \t" << (DFfastest ? "D ->" : " ") << " hit: " << resultsDF [i]._hit << " time: " << resultsDF [i]._time << endLog; //SINFO << " \t" << (DFSfastest ? "S ->" : " ") << " hit: " << resultsDFS[i]._hit << " time: " << resultsDFS[i]._time << endLog; //SINFO << " \t" << (Pfastest ? "P ->" : " ") << " hit: " << resultsP [i]._hit << " time: " << resultsP [i]._time << endLog; //SINFO << " \t" << (Ofastest ? "O ->" : " ") << " hit: " << resultsO [i]._hit << " time: " << resultsO [i]._time << endLog; } SINFO << " df total: " << tDFTotal << (tDFTotal < tDFSTotal && tDFTotal < tPTotal && tDFTotal < tOTotal ? " *" : " ") << " wins: " << DFwins << " (" << (static_cast<Real32>(DFwins) / static_cast<Real32>(passCount)) * 100.0 << "%)\t" << " wins on hit: " << DFwinsHit << " (" << (static_cast<Real32>(DFwinsHit) / static_cast<Real32>(hitCount )) * 100.0 << "%)\t" << " wins on miss: " << DFwinsMiss << " (" << (static_cast<Real32>(DFwinsMiss) / static_cast<Real32>(missCount)) * 100.0 << "%)" << endLog; SINFO << " dfs total: " << tDFSTotal << (tDFSTotal < tDFTotal && tDFSTotal < tPTotal && tDFSTotal < tOTotal ? " *" : " ") << " wins: " << DFSwins << " (" << (static_cast<Real32>(DFSwins) / static_cast<Real32>(passCount)) * 100.0 << "%)\t" << " wins on hit: " << DFSwinsHit << " (" << (static_cast<Real32>(DFSwinsHit) / static_cast<Real32>(hitCount )) * 100.0 << "%)\t" << " wins on miss: " << DFSwinsMiss << " (" << (static_cast<Real32>(DFSwinsMiss) / static_cast<Real32>(missCount)) * 100.0 << "%)" << endLog; SINFO << " p total: " << tPTotal << (tPTotal < tDFTotal && tPTotal < tDFSTotal && tPTotal < tOTotal ? " *" : " ") << " wins: " << Pwins << " (" << (static_cast<Real32>(Pwins) / static_cast<Real32>(passCount)) * 100.0 << "%)\t" << " wins on hit: " << PwinsHit << " (" << (static_cast<Real32>(PwinsHit) / static_cast<Real32>(hitCount )) * 100.0 << "%)\t" << " wins on miss: " << PwinsMiss << " (" << (static_cast<Real32>(PwinsMiss) / static_cast<Real32>(missCount)) * 100.0 << "%)" << endLog; SINFO << " o total: " << tOTotal << (tOTotal < tDFTotal && tOTotal < tDFSTotal && tOTotal < tPTotal ? " *" : " ") << " wins: " << Owins << " (" << (static_cast<Real32>(Owins) / static_cast<Real32>(passCount)) * 100.0 << "%)\t" << " wins on hit: " << OwinsHit << " (" << (static_cast<Real32>(OwinsHit) / static_cast<Real32>(hitCount )) * 100.0 << "%)\t" << " wins on miss: " << OwinsMiss << " (" << (static_cast<Real32>(OwinsMiss) / static_cast<Real32>(missCount)) * 100.0 << "%)" << endLog; SINFO << "pass: "******" fail: " << failCount << " hit: " << hitCount << " miss: " << missCount << endLog; osgLogP->setLogLevel(LOG_NOTICE); #if 0 // create the SimpleSceneManager helper mgr = new SimpleSceneManager; // tell the manager what to manage mgr->setWindow(gwin ); mgr->setRoot (pRoot); // show the whole scene mgr->showAll(); // GLUT main loop glutMainLoop(); #endif return 0; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // GLUT init int winid = setupGLUT(&argc, argv); // the connection between GLUT and OpenSG GLUTWindowPtr gwin= GLUTWindow::create(); gwin->setId(winid); gwin->init(); // create the scene /* Geometry data in OpenSG is stored in several separate vectors. These vectors are not a direct part of the Geometry Core but rather split up into multiple separate classes. These classes, the GeoProperties, contain a single field containg their values, which can be accessed directly, see the docs for GeoProperty for the whole interface. */ /* The first part: the primtive types. These are taken from OpenGL, any values that can be passed to glBegin(); are legal. Different types can be freely mixed. All properties have only one field, which has the same name for every property, thus the mask is also called the same for each property. */ GeoPTypesPtr type = GeoPTypesUI8::create(); beginEditCP(type, GeoPTypesUI8::GeoPropDataFieldMask); { type->addValue(GL_POLYGON ); type->addValue(GL_TRIANGLES); type->addValue(GL_QUADS ); } endEditCP (type, GeoPTypesUI8::GeoPropDataFieldMask); /* The second part: the primtive lengths. These define the number of vertices to be passed to OpenGL for each primitive. Thus there have to be at least as many entries as in the types property. */ GeoPLengthsPtr lens = GeoPLengthsUI32::create(); beginEditCP(lens, GeoPLengthsUI32::GeoPropDataFieldMask); { lens->addValue(4); lens->addValue(6); lens->addValue(8); } endEditCP (lens, GeoPLengthsUI32::GeoPropDataFieldMask); /* The third part: the vertex positions. OpenSG uses different types for vectors and points. Points (e.g. Pnt3f) are just positions in space, they have a limited set of operations they can handle. Vectors (e.g. Vec3f) are the more general kind. */ GeoPositions3fPtr pnts = GeoPositions3f::create(); beginEditCP(pnts, GeoPositions3f::GeoPropDataFieldMask); { // the 4 points of the polygon pnts->addValue(Pnt3f(-1, -1, -1)); pnts->addValue(Pnt3f(-1, -1, 1)); pnts->addValue(Pnt3f( 1, -1, 1)); pnts->addValue(Pnt3f( 1, -1, -1)); // the 6 points of the two triangles pnts->addValue(Pnt3f( 1, 0, -1)); pnts->addValue(Pnt3f(-1, 0, -1)); pnts->addValue(Pnt3f( 0, 1, -1)); pnts->addValue(Pnt3f(-1, 0, 1)); pnts->addValue(Pnt3f( 1, 0, 1)); pnts->addValue(Pnt3f( 0, 1, 1)); // the 8 points of the two quads pnts->addValue(Pnt3f(-1, -1, 1)); pnts->addValue(Pnt3f( 1, -1, 1)); pnts->addValue(Pnt3f( 1, 0, 1)); pnts->addValue(Pnt3f(-1, 0, 1)); pnts->addValue(Pnt3f( 1, -1, -1)); pnts->addValue(Pnt3f(-1, -1, -1)); pnts->addValue(Pnt3f(-1, 0, -1)); pnts->addValue(Pnt3f( 1, 0, -1)); } endEditCP (pnts, GeoPositions3f::GeoPropDataFieldMask); /* Put it all together into a Geometry NodeCore. */ geo=Geometry::create(); beginEditCP(geo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::MaterialFieldMask ); { geo->setTypes (type); geo->setLengths (lens); geo->setPositions(pnts); // assign a material to the geometry to make it visible. The details // of materials are defined later. geo->setMaterial(getDefaultUnlitMaterial()); } endEditCP (geo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::MaterialFieldMask ); // put the geometry core into a node NodePtr n = Node::create(); beginEditCP(n, Node::CoreFieldMask); { n->setCore(geo); } endEditCP (n, Node::CoreFieldMask); // add a transformation to make it move NodePtr scene = Node::create(); trans = Transform::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask ); { scene->setCore(trans); scene->addChild(n); } endEditCP (scene, Node::CoreFieldMask | Node::ChildrenFieldMask ); // create the SimpleSceneManager helper mgr = new SimpleSceneManager; // tell the manager what to manage mgr->setWindow(gwin ); mgr->setRoot (scene); // show the whole scene mgr->showAll(); // GLUT main loop glutMainLoop(); return 0; }
int main (int argc, char **argv) { osgInit(argc, argv); FieldContainerPtr pProto = Geometry::getClassType().getPrototype(); GeometryPtr pGeoProto = GeometryPtr::dcast(pProto); if(pGeoProto != NullFC) { pGeoProto->setDlistCache(false); } // init GLUT glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("OpenSG"); glutKeyboardFunc(key); // glutReshapeFunc(resize); glutDisplayFunc(display); // glutMouseFunc(mouse); // glutMotionFunc(motion); glutIdleFunc(display); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 60, 1, 0.1, 10 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt( 3, 3, 3, 0, 0, 0, 0, 0, 1 ); glDepthFunc( GL_LEQUAL ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glLineWidth( 3 ); #if 0 // for testing only: register Node type functions IntersectAction::registerEnterDefault(Group::getStaticType(), osgFunctionFunctor2(groupEnter)); IntersectAction::registerEnterDefault(Geometry::getStaticType(), osgFunctionFunctor2(geometryEnter)); IntersectAction::registerEnterDefault(Transform::getStaticType(), osgFunctionFunctor2(transformEnter)); IntersectAction::registerLeaveDefault(Transform::getStaticType(), osgFunctionFunctor2(transformLeave)); #endif // create test scene SimpleMaterialPtr white = SimpleMaterial::create(); SimpleMaterialPtr red = SimpleMaterial::create(); white->setEmission( Color3f( 1,1,1 ) ); red->setEmission( Color3f( 1,0,0 ) ); // g1->(g2->g3->p1,t1->p2) GeometryPtr g; NodePtr p1 = makePlane( 2,2,2,2 ); g = GeometryPtr::dcast(p1->getCore()); g->setMaterial( white ); p1->updateVolume(); NodePtr p2 = makePlane( 2,2,2,2 ); g = GeometryPtr::dcast(p2->getCore()); g->setMaterial( white ); p2->updateVolume(); NodePtr g4 = Node::create(); TransformPtr t1 = Transform::create(); beginEditCP(t1); t1->editMatrix().setRotate( Quaternion( Vec3f(1,0,0), 30 ) ); endEditCP(t1); beginEditCP(g4); g4->setCore( t1 ); g4->addChild( p2 ); g4->updateVolume(); endEditCP(g4); NodePtr g3 = Node::create(); GroupPtr g3c = Group::create(); beginEditCP(g3); g3->setCore( g3c ); g3->addChild( p1 ); g3->updateVolume(); endEditCP(g3); NodePtr g2 = Node::create(); GroupPtr g2c = Group::create(); beginEditCP(g2); g2->setCore( g2c ); g2->addChild( g3 ); g2->updateVolume(); endEditCP(g2); iroot = Node::create(); GroupPtr g1c = Group::create(); beginEditCP(iroot); iroot->setCore( g1c ); iroot->addChild( g2 ); iroot->addChild( g4 ); iroot->updateVolume(); endEditCP(iroot); // make the root and test objects points = GeoPositions3f::create(); beginEditCP(points); points->addValue( Pnt3f(0,0,0) ); points->addValue( Pnt3f(0,0,0) ); points->addValue( Pnt3f(0,0,0) ); points->addValue( Pnt3f(0,0,0) ); points->addValue( Pnt3f(0,0,0) ); endEditCP(points); GeoIndicesUI32Ptr index = GeoIndicesUI32::create(); beginEditCP(index); index->addValue( 0 ); index->addValue( 1 ); index->addValue( 2 ); index->addValue( 3 ); index->addValue( 4 ); endEditCP(index); GeoPLengthsPtr lens = GeoPLengthsUI32::create(); beginEditCP(lens); lens->addValue( 2 ); lens->addValue( 3 ); endEditCP(lens); GeoPTypesPtr type = GeoPTypesUI8::create(); beginEditCP(type); type->addValue( GL_LINES ); type->addValue( GL_TRIANGLES ); endEditCP(type); GeometryPtr testgeocore = Geometry::create(); beginEditCP(testgeocore); testgeocore->setPositions( points ); testgeocore->setIndices( index ); testgeocore->setLengths( lens ); testgeocore->setTypes( type ); testgeocore->setMaterial( red ); endEditCP( testgeocore ); NodePtr testgeo = Node::create(); beginEditCP(testgeo); testgeo->setCore( testgeocore ); endEditCP( testgeo ); root = Node::create(); GroupPtr rootc = Group::create(); beginEditCP(root); root->setCore( rootc ); root->addChild( iroot ); root->addChild( testgeo ); endEditCP( root ); dact = DrawAction::create(); dact->setFrustumCulling(false); glutMainLoop(); return 0; }