;===================================================================== ; PV-WAVE ARL ; ; PV-Wave Advanced Rendering Library ; 11/90 D. Carr ; ; (c) Copyright Precision Visuals, Inc., 1990 ; Boulder, Colorado, U.S.A. ; ; All Rights Reserved. ; ; This software is confidential information which is proprietary to ; and a trade secret of Precision Visuals, Inc. Use, duplication or ; disclosure is subject to the terms of an appropriate license ; agreement. ; ------------------------------------------------------------------ ; Use, duplication, or disclosure by the Government is subject to ; restrictions set forth in paragraph (b)(3)(B) of the Rights in ; Technical Data and Computer Software clause in DAR 7-104.9(a). ; ; Contractor : Precision Visuals, Inc., Boulder, Colorado, U.S.A. ; ------------------------------------------------------------------- ; ; Program Overview : FUNCTION Grid_4d ; ; Grid_4d takes random 4-D coordinates and returns a gridded ; 3 dimensional array containing intensity values. This gridded ; array is suitable for use with the "Shade_Volume" and "Vol_Rend" ; functions. ; Grid_4d uses a weighted neighborhood averaging technique to ; interpolate missing data values. ; ; SEE ALSO : Grid_2d Grid_4d ; ; MANDATORY INPUTS : ; ; points : A (4, n) array containing random 4-D points to ; be gridded. Normally, points(0, *) contins the ; X values, points(1, *) contains the Y values, ; points(2, *) contains the Z values, and ; points(3, *) contains the intensity values. ; ; grid_x : The X dimension of the grid. The X values are ; scaled to fit this dimension. ; ; grid_y : The Y dimension of the grid. The Y values are ; scaled to fit this dimension. ; ; grid_z : The Z dimension of the grid. The Z values are ; scaled to fit this dimension. ; ; OPTIONAL INPUTS (Keywords) : ; ; order : The order of the weighing function to use for ; neighborhood averaging. The default is 2 . ; Points are weighted by the function : ; w = 1.0 / (dist^order) ; where dist is the distance to the point. ; ;===================================================================== ; FUNCTION Grid_4d, points, grid_x, grid_y, grid_z, order=order sp = Size(points) IF (sp(0) NE 2) THEN BEGIN Print, "Invalid points array." STOP ENDIF IF (sp(1) NE 4) THEN BEGIN Print, "Invalid points array." STOP ENDIF IF (grid_x(0) LT 2) THEN BEGIN Print, "X dimension of grid must be 2 or greater." STOP ENDIF IF (grid_y(0) LT 2) THEN BEGIN Print, "Y dimension of grid must be 2 or greater." STOP ENDIF IF (grid_z(0) LT 2) THEN BEGIN Print, "Z dimension of grid must be 2 or greater." STOP ENDIF p_order = 2.0 IF (N_Elements(order) GT 0) THEN p_order = Float(order(0)) > 0.0 points = Float(points) n_points = sp(2) grid_x = Fix(grid_x(0)) grid_y = Fix(grid_y(0)) grid_z = Fix(grid_z(0)) lox = Min(points(0, *)) hix = Max(points(0, *)) loy = Min(points(1, *)) hiy = Max(points(1, *)) loz = Min(points(2, *)) hiz = Max(points(2, *)) xrange = hix - lox yrange = hiy - loy zrange = hiz - loz IF (((xrange LE 0.0) OR (yrange LE 0.0)) OR (zrange LE 0.0)) THEN BEGIN Print, "Unable to grid points." Print, "All points have the same X, Y, or Z value." STOP ENDIF intens = Fltarr(grid_x, grid_y, grid_z) xinc = xrange / Float(grid_x) yinc = yrange / Float(grid_y) zinc = yrange / Float(grid_z) xs = Fix((points(0, *) - lox) / xinc) < (grid_x - 1) ys = Fix((points(1, *) - loy) / yinc) < (grid_y - 1) zs = Fix((points(2, *) - loz) / zinc) < (grid_z - 1) grid_xm1 = grid_x - 1 grid_ym1 = grid_y - 1 grid_zm1 = grid_z - 1 FOR k=0, grid_zm1 DO BEGIN dz = (Float(zs - k))^2 FOR j=0, grid_ym1 DO BEGIN dy = (Float(ys - j))^2 FOR i=0, grid_xm1 DO BEGIN dx = (Float(xs - i))^2 distances = (dx + dy + dz)^(0.5 * p_order) ind = Where(distances EQ 0.0) IF (ind(0) EQ (-1)) THEN BEGIN intens(i, j, k) = Total(points(3, *) / distances) / Total(1.0 / distances) ENDIF ELSE BEGIN intens(i, j, k) = AVG(points(3, ind)) ENDELSE ENDFOR ENDFOR ENDFOR RETURN, intens END