POV-Ray : Newsgroups : povray.advanced-users : Problem concerning the use of array indices inside functions : Problem concerning the use of array indices inside functions Server Time
29 Jul 2024 00:34:17 EDT (-0400)
  Problem concerning the use of array indices inside functions  
From: Jaap Frank
Date: 2 May 2003 08:13:44
Message: <3eb260f8$1@news.povray.org>
Hallo,

I have a problem concerning the use of array indices inside
a function.
Let me explain what I'm trying to do and what the problem is:

I have a 3D-grid with density values in a 3D-array called
Cube and must use this as density inside a media statement.
Beside a interpolation between these grid points,
ultimately POV-ray needs something like

   #declare F_DensPoint = function(x,y,z)
   { Cube[int((x-X0)/StepX)]
         [int((y-Y0)/StepY)]
         [int((z-Z0)/StepZ)] }

   (X0,Y0,Z0 is the origin of the density grid and
    StepX, StepY and StepZ are the grid distances)

to get values from the 3D-array.
If you use this function you get the error massage:
'Float expected but vector or color expression found'

This has clearly something to do with the array indices
control of the parser, because

  #declare F_Ix = function(x,y,z)
  { int((x-X0)/StepX) }

does NOT give an error message and returns a float and not a
vector.
I thought I found a workaround with

  #declare F_Ix = function(x,y,z){ int((x - X0)/StepX) }
  #declare F_Iy = function(x,y,z){ int((y - Y0)/StepY) }
  #declare F_Iz = function(x,y,z){ int((z - Z0)/StepZ) }

  #declare F_Cube =
  function(x,y,z,NX,NY,NZ) { Cube[NX][NY][NZ] }
  #declare F_DensPoint = function(x,y,z)
  { F_Cube(x,y,z, F_Ix(x,y,z), F_Iy(x,y,z), F_Iz(x,y,z)) }

but this gives the error message

'Expected 'numeric expression', undeclared identifier 'NX'
found instead'.

*#@!@^& .. the parser doesn't accept function parameters
as array indices!

I've tried several other possibilities, but that doesn't
work because you have to pass over x,y,z somewhere and the
parser stops when it finds this vector. You can use
functions as indices, but they may not contain x,y,z in the
parameter section and that is essential to find the correct
indices in the array.

My question is:
  Is there a way to circumvent this problem
  or if not
  is it possible to raise one of the blockages of the parser.

I've been working for months to develop interpolation
functions with matrices and they work perfectly, but now I
stumble over a not expected problem that blocks everything.

...help please...

Jaap Frank


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.