Changeset 11287

Show
Ignore:
Timestamp:
03/25/10 12:11:35 (3 years ago)
Author:
robert
Message:

Introduced the use of linear interpolation of evelvations when sampling

Location:
OpenSceneGraph/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgTerrain/Layer

    r9618 r11287  
    192192        } 
    193193 
     194        inline bool getInterpolatedValidValue(double ndc_x, double ndc_y, float& value) 
     195        { 
     196            unsigned int i,j; 
     197            double ir, jr; 
     198            computeIndices(ndc_x, ndc_y, i, j, ir, jr); 
     199            value = 0.0f; 
     200            double div = 0.0f; 
     201            float v,r; 
     202 
     203            r = (1.0f-ir)*(1.0f-jr); 
     204            if (r>0.0 && getValidValue(i,j,v)) 
     205            { 
     206                value += v*r; 
     207                div += r; 
     208            } 
     209 
     210            r = (ir)*(1.0f-jr); 
     211            if (r>0.0 && getValidValue(i+1,j,v)) 
     212            { 
     213                value += v*r; 
     214                div += r; 
     215            } 
     216 
     217            r = (ir)*(jr); 
     218            if (r>0.0 && getValidValue(i+1,j+1,v)) 
     219            { 
     220                value += v*r; 
     221                div += r; 
     222            } 
     223 
     224            r = (1.0f-ir)*(jr); 
     225            if (r>0.0 && getValidValue(i,j+1,v)) 
     226            { 
     227                value += v*r; 
     228                div += r; 
     229            } 
     230 
     231            if (div != 0.0) 
     232            { 
     233                value /= div; 
     234                return true; 
     235            } 
     236 
     237            value = 0.0; 
     238            return false; 
     239        } 
     240 
    194241        /** increment the modified count."*/ 
    195242        virtual void dirty() {}; 
  • OpenSceneGraph/trunk/src/osgTerrain/GeometryTechnique.cpp

    r11259 r11287  
    311311                Locator* locator = colorLayer->getLocator(); 
    312312                if (!locator) 
    313                 {             
     313                { 
    314314                    osgTerrain::SwitchLayer* switchLayer = dynamic_cast<osgTerrain::SwitchLayer*>(colorLayer); 
    315315                    if (switchLayer) 
     
    322322                        } 
    323323                    } 
    324                 }             
    325              
     324                } 
     325 
    326326                TexCoordLocatorPair& tclp = layerToTexCoordMap[colorLayer]; 
    327327                tclp.first = new osg::Vec2Array; 
     
    356356            unsigned int iv = j*numColumns + i; 
    357357            osg::Vec3d ndc( ((double)i)/(double)(numColumns-1), ((double)j)/(double)(numRows-1), 0.0); 
    358       
     358 
    359359            bool validValue = true; 
    360       
    361              
    362             unsigned int i_equiv = i_sampleFactor==1.0 ? i : (unsigned int) (double(i)*i_sampleFactor); 
    363             unsigned int j_equiv = i_sampleFactor==1.0 ? j : (unsigned int) (double(j)*j_sampleFactor); 
    364              
    365360            if (elevationLayer) 
    366361            { 
    367362                float value = 0.0f; 
    368                 validValue = elevationLayer->getValidValue(i_equiv,j_equiv, value); 
    369                 // OSG_INFO<<"i="<<i<<" j="<<j<<" z="<<value<<std::endl; 
     363                if (sampleRatio==1.0) validValue = elevationLayer->getValidValue(i,j,value); 
     364                else validValue = elevationLayer->getInterpolatedValidValue(ndc.x(), ndc.y(), value); 
    370365                ndc.z() = value*scaleHeight; 
    371366            } 
    372              
     367 
    373368            if (validValue) 
    374369            { 
    375370                indices[iv] = vertices->size(); 
    376              
     371 
    377372                osg::Vec3d model; 
    378373                masterLocator->convertLocalToModel(ndc, model); 
     
    417412        } 
    418413    } 
    419      
     414 
    420415    // populate primitive sets 
    421416//    bool optimizeOrientations = elevations!=0;