CImage:CoordOf
The CoordOf method returns a lua table containing the 1-based pixel coordinates of a linear position in the data array. The first pixel in the data array is at position 1, corresponding to pixel coordinates {1,1,...}. Also see the inverse method, Pos.
Syntax
tCoord[] = CImage:CoordOf( nPos ) where |
nPos is the linear position in the data array. The first element is at position 1.
tCoord[] is a Lua array containing the 1-based coordinates of the linear position.
The following script creates a 3-D image and then returns the coordinates of a linear offset into the image array.
|
-- create a CImage of 100 x 200 x 50 pixels |
|
-- specify the position |
|
-- result: x,y,z = 10,20,40 |
In the next example, suppose the image dimensions are not immediately known. The following script returns the coordinate for each dimension of the data array. Note that the number of array axes could be determined directly by using the Axes method.
|
-- specify the offset |
|
-- use #t to get the number of table elements |
|
-- result: x[1] = 10 x[2] = 20 x[3] = 40 |
|
|
Another way to do the same thing is to use the ipairs operator to iterate over the coordinate table:
|
-- specify the offset |
|
-- use #t to get the number of table elements |
|
-- result: x[1] = 10 x[2] = 20 x[3] = 40 |
|
|