Changeset 54

Show
Ignore:
Timestamp:
04/23/07 17:09:02 (2 years ago)
Author:
astraw
Message:

commit heightfield patch from Stou Sandalski

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pyosg/osg/Shape3.cpp

    r45 r54  
    1313#include <boost/python/return_value_policy.hpp> 
    1414#include <boost/python/copy_const_reference.hpp> 
     15#include <boost/python/numeric.hpp> 
     16#include <boost/python/tuple.hpp> 
    1517 
     18#include <iostream> 
    1619#include <osg/Shape> 
    1720 
     
    2225 
    2326namespace PyOSG { 
     27 
     28void osgHeightField_setData(osg::HeightField * self, numeric::array& data) 
     29{ 
     30    object shape = data.getshape(); 
     31    int rows = extract<int>(shape[0]); 
     32    int cols = extract<int>(shape[1]); 
     33 
     34    if((rows == 0) || (cols == 0)) 
     35    { 
     36 
     37        PyErr_SetString(PyExc_ValueError, "Invalid array dimensions"); 
     38        throw_error_already_set(); 
     39        return; 
     40    } 
     41 
     42    // Switch this to R,C maybe? 
     43    self->allocate(cols,rows); 
     44 
     45    float value = 0.0f; 
     46 
     47    for(int r = 0; r < rows; ++r) 
     48    { 
     49        for(int c = 0; c < cols; ++c) 
     50        { 
     51           value = extract<float>(data[make_tuple(r,c)]); 
     52           self->setHeight(c, r, value); 
     53        } 
     54    } 
     55} 
     56 
    2457void init_Shape3() 
    2558{ 
     
    80113        &osg::HeightField::getHeight); 
    81114 
     115 
     116    hfield.def("setHeightData", &osgHeightField_setData); 
     117    
     118 
    82119    hfield.def("getVertex", &osg::HeightField::getVertex); 
    83120    hfield.def("getNormal", &osg::HeightField::getNormal);