SomeFusion
10-05-2009 13:01:57
Hi,
I'm currently trying to convert this code from C++ to Python:
viewtopic.php?t=6370
This is the code I have till now:
The problem is here when I try to create the brushes.
brushReturn = ET.Brush(ctypes.pointer(vecReturnBuffer), iWidth, iHeight)
brushHeights = ET.Brush(ctypes.pointer(vecHeightBuffer), iWidth, iHeight)
ctypes.pointer(vecReturnBuffer) won't give me the correct type which the Brush constructor expects. This is the error I get.
[attachment=0]error.png[/attachment]
This is propably more a python question than a python-ogre question but I don't think its a horribly wrong place to ask here
.
How do I get the correct results from cpython? The other method would be an std::vector of floats, but I don't think this type is wrapped.
Thanks!
I'm currently trying to convert this code from C++ to Python:
viewtopic.php?t=6370
This is the code I have till now:
def averageFilter(self, x, z, brush, intensity):
#When you're doing a loop possibly thousands of times, it's worth setting these
#aside rather than calling a function every iteration.
iWidth = brush.getWidth()
iHeight = brush.getHeight()
storageclass = ctypes.c_float * (iWidth * iHeight)
vecReturnBuffer = storageclass()
vecHeightBuffer = storageclass()
ptr = ctypes.pointer(vecReturnBuffer)
brushReturn = ET.Brush(ctypes.pointer(vecReturnBuffer), iWidth, iHeight)
brushHeights = ET.Brush(ctypes.pointer(vecHeightBuffer), iWidth, iHeight)
self.terrainManager.getHeights(x, z, brushHeights)
fSumHeights = 0.0
iNumHeights = iWidth * iHeight
# Find the sum of all the heights within the sample
i = 0
j = 0
while i < iWidth:
while j < iHeight:
fSumHeights += brushHeights.at(i, j)
j += 1
i += 1
#Find the average height within the sample
fAvgHeight = fSumHeights / iNumHeights
i = 0
j = 0
while i < iWidth:
while j < iHeight:
fHeight = brushHeights.at(i, j)
fDelta = fHeight - fAvgHeight
fShapeMask = shape.at(i, j)
fDelta = fDelta * fShapeMask * fIntensity
val = brushReturn.at(i, j)
val = fHeight - fDelta
j += 1
i += 1
The problem is here when I try to create the brushes.
brushReturn = ET.Brush(ctypes.pointer(vecReturnBuffer), iWidth, iHeight)
brushHeights = ET.Brush(ctypes.pointer(vecHeightBuffer), iWidth, iHeight)
ctypes.pointer(vecReturnBuffer) won't give me the correct type which the Brush constructor expects. This is the error I get.
[attachment=0]error.png[/attachment]
This is propably more a python question than a python-ogre question but I don't think its a horribly wrong place to ask here

How do I get the correct results from cpython? The other method would be an std::vector of floats, but I don't think this type is wrapped.
Thanks!