osg model

:: ref_ptr OSG <OSG :: the Node> MyOSGLoadEarth the CreateNode :: () 
{ 
    OSG ref_ptr :: <OSG :: Group> = the _root new new OSG :: Group; 
 
    // definition of the file and read the elevation
     // true elevation file name is : ASTGTM2_N34E110_dem.tif
     // belong to a special tiff format, GeoTIFF
     // when read using osg of gdal plug-in for reading, so after the path added .gdal
     // .gdal extension just add it in here , the real need to modify the file extensions elevation 
    OSG ref_ptr :: <Heightfield OSG ::> :: readHeightFieldFile osgDB HeightMap = ( " G: \\ \\ ASTGTM2_N34E110_dem.tif.gdal ASTER.GDEM.V2-DEM_sn " ); 
 
    / / create a leaf node objects 
    OSG ref_ptr :: <OSG :: Geode> = Geode new new OSG :: Geode; 
 
    IF (HeightMap =!nullptr) 
    { 
        // Since the original data is too large, creating three-dimensional objects will fail, so re-construct an object
         // equivalent data thinning once. Of course, the picture can be directly cut the use of special tools
         // Create a new Heightfield objects, used to copy HeightMap 
        OSG ref_ptr :: <OSG :: Heightfield> = heightMap1 new new OSG :: Heightfield;
         // copy from the original object some familiar over 
        heightMap1-> SetOrigin (heightMap-> getOrigin ()); 
        heightMap1 -> setRotation (heightMap-> getRotation ()); 
        heightMap1 -> setSkirtHeight (heightMap-> getSkirtHeight ());
         // interval XY direction is doubled, 
        heightMap1-> setXInterval (heightMap-> getXInterval () * 2  );
        heightMap1-> setYInterval (heightMap-> getYInterval () * 2 );
         // number of ranks set a new amount to half of the original elevation data of 
        heightMap1-> the allocate (heightMap-> getNumColumns () / 2 , heightMap-> getNumRows () / 2 ); 
 
        // put into actual data values to 
        for (R & lt size_t = 0 ; R & lt <heightMap1-> getNumRows (); ++ R & lt) 
        { 
            for (size_t C = 0 ; C <heightMap1-> getNumColumns (); + + C) 
            { 
                // interval loading data in the XY direction is about 0.0002 (offset latitude and longitude), lattice 3600, the number of stages is too small, the level of elevation values frequently in one thousand, if no coordinate transformation (GPS converted to m), after the results are displayed serious disorders. So here is simple to highly value divided by 50000 (this is in accordance with the tif file to try out different elevation files may vary)
                heightMap1->setHeight(c, r, heightMap->getHeight(c * 2, r * 2)/50000);
            }
        }
 
        //添加到叶子节点中
        geode->addDrawable(new osg::ShapeDrawable(heightMap1));
    }
 
    _root->addChild(geode.get());
    return _root.get();
}

 

Guess you like

Origin www.cnblogs.com/herd/p/11070059.html