Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

vp_global.h

Go to the documentation of this file.
00001 /*
00002  * vp_global.h
00003  *
00004  * Non-exported global declarations for VolPack.
00005  *
00006  * Copyright (c) 1994 The Board of Trustees of The Leland Stanford
00007  * Junior University.  All rights reserved.
00008  *
00009  * Permission to use, copy, modify and distribute this software and its
00010  * documentation for any purpose is hereby granted without fee, provided
00011  * that the above copyright notice and this permission notice appear in
00012  * all copies of this software and that you do not sell the software.
00013  * Commercial licensing is available by contacting the author.
00014  * 
00015  * THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
00016  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
00017  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00018  *
00019  * Author:
00020  *    Phil Lacroute
00021  *    Computer Systems Laboratory
00022  *    Electrical Engineering Dept.
00023  *    Stanford University
00024  */
00025 
00026 /*
00027  * $Date: 2003/04/30 16:08:35 $
00028  * $Revision: 1.2 $
00029  */
00030 
00031 /*******************************************************************
00032  * Include files.                                                  *
00033  *******************************************************************/
00034 
00035 #include "config.h"
00036 #include "volpack.h"
00037 
00038 #include <stdio.h>
00039 #include <stdlib.h>   /* replaces malloc.h - 30 Apr 2003 */
00040 #include <math.h>
00041 extern double rint ANSI_ARGS((double x)); /* missing from Ultrix math.h */
00042 
00043 #ifdef ANSI_C
00044 #include <stdarg.h>
00045 #else
00046 #include <varargs.h>
00047 #endif
00048 
00049 #if STDC_HEADERS || HAVE_STRING_H
00050 #include <string.h>
00051 /* An ANSI string.h and pre-ANSI memory.h might conflict.  */
00052 #if !STDC_HEADERS && HAVE_MEMORY_H
00053 #include <memory.h>
00054 #endif /* not STDC_HEADERS and HAVE_MEMORY_H */
00055 #define index strchr
00056 #define rindex strrchr
00057 #define bcopy(s, d, n) memcpy ((d), (s), (n))
00058 #define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
00059 #define bzero(s, n) memset ((s), 0, (n))
00060 #else /* not STDC_HEADERS and not HAVE_STRING_H */
00061 #include <strings.h>
00062 /* memory.h and strings.h conflict on some systems.  */
00063 #endif /* not STDC_HEADERS and not HAVE_STRING_H */
00064 
00065 #ifdef HAVE_LORES_TIMER
00066 /* use the low-resolution interval timer system call to collect timings */
00067 #   define USE_TIMER
00068 #   include <sys/time.h>
00069 #   define DECLARE_TIME(t)      struct timeval t
00070 #   define GET_TIME(vpc, t)     gettimeofday(&t)
00071 #   define STORE_TIME(vpc, code, t0, t1)        \
00072     vpc->timer_ticks[code] += ((t1).tv_usec < (t0).tv_usec) ? \
00073         (((t1).tv_sec - (t0).tv_sec)*1000000 - ((t0).tv_usec - (t1).tv_usec)):\
00074         (((t1).tv_sec - (t0).tv_sec)*1000000 + ((t1).tv_usec - (t0).tv_usec));
00075 #endif
00076 
00077 #ifdef HAVE_HIRES_TIMER
00078 /* use the high-resolution memory-mapped timer to collect timings 
00079    (available only on certain SGI architectures) */
00080 #   define USE_TIMER
00081 #   include <fcntl.h>
00082 #   include <sys/mman.h>
00083 #   include <sys/syssgi.h>
00084 #   include <sys/immu.h>
00085 #   define DECLARE_TIME(t)      unsigned t
00086 #   define GET_TIME(vpc, t)     t = *vpc->timer_addr
00087 #   define STORE_TIME(vpc, code, t0, t1)        \
00088     vpc->timer_ticks[code] += ((t1) < (t0)) ? \
00089         ((0xFFFFFFFF - (t0)) + (t1)) : ((t1) - (t0));
00090 #   define DECLARE_HIRES_TIME(t)        DECLARE_TIME(t)
00091 #   define GET_HIRES_TIME(vpc, t)       GET_TIME(vpc, t)
00092 #   define STORE_HIRES_TIME(vpc, code, t0, t1)  STORE_TIME(vpc, code, t0, t1)
00093 #   define COPY_HIRES_TIME(t0, t1)      t0 = t1
00094 #else
00095 #   define DECLARE_HIRES_TIME(t)
00096 #   define GET_HIRES_TIME(vpc, t)
00097 #   define STORE_HIRES_TIME(vpc, code, t0, t1)
00098 #   define COPY_HIRES_TIME(t0, t1)
00099 #endif
00100 
00101 #ifndef USE_TIMER
00102 #   define DECLARE_TIME(t)
00103 #   define GET_TIME(vpc, t)
00104 #   define STORE_TIME(vpc, code, t0, t1)
00105 #endif
00106 
00107 /*******************************************************************
00108  * Constants.                                                      *
00109  *******************************************************************/
00110 
00111 /* rendering algorithms */
00112 #define USE_RLEVOLUME   10      /* use classified, run-length encoded volume */
00113 #define USE_RAWVOLUME   11      /* use raw volume (with octree if present) */
00114 
00115 /* shading modes */
00116 #define CALLBACK_SHADER 20
00117 #define LOOKUP_SHADER   21
00118 
00119 /* surfaces */
00120 #define EXT_SURFACE     0
00121 #define INT_SURFACE     1
00122 
00123 /* material property indexes */
00124 #define MATL_AMB_R      0               /* ambient red coefficient */
00125 #define MATL_DIFF_R     1               /* diffuse red coefficient */
00126 #define MATL_SPEC_R     2               /* specular red coefficient */
00127 #define MATL_AMB_G      3               /* ambient green coefficient */
00128 #define MATL_DIFF_G     4               /* diffuse green coefficient */
00129 #define MATL_SPEC_G     5               /* specular green coefficient */
00130 #define MATL_AMB_B      6               /* ambient blue coefficient */
00131 #define MATL_DIFF_B     7               /* diffuse blue coefficient */
00132 #define MATL_SPEC_B     8               /* specular blue coefficient */
00133 #define MATL_SHINY      9               /* specular exponent */
00134 #define NUM_MATL_PROPS  10
00135 
00136 /* default material properties */
00137 #define DEFAULT_AMBIENT         (0.1*255.0)
00138 #define DEFAULT_DIFFUSE         (0.4*255.0)
00139 #define DEFAULT_SPECULAR        (0.5*255.0)
00140 #define DEFAULT_SHINYNESS       10.0
00141 
00142 /* default depth cueing parameters */
00143 #define DEFAULT_DC_QUANTIZATION (1./255.) /* quantization */
00144 
00145 /* size of lookup table for filter kernel used in the 2D warp */
00146 #define WARP_WEIGHT_INDEX_BITS  6
00147 #define WARP_WEIGHT_ENTRIES     (1 << WARP_WEIGHT_INDEX_BITS)
00148 
00149 /* constants for MinMaxOctree and fast classification */
00150 #define VP_MAX_OCTREE_LEVELS    16      /* maximum number of levels in octree;
00151                                            each side of volume can be at most
00152                                            (2^VP_MAX_OCTREE_LEVELS)*
00153                                            base_node_size */
00154 
00155 #define MM_K_BIT        4               /* bits in child_octant field of */
00156 #define MM_J_BIT        2               /* MMOctreeLevel */
00157 #define MM_I_BIT        1
00158 
00159 #define MM_EMPTY        0               /* node is transparent */
00160 #define MM_FULL         1               /* node is non-transparent */
00161 #define MM_PARTFULL     2               /* node is neither transparent
00162                                            nor opaque and is not a leaf */
00163 
00164 #define INDEX_RUN_IS_ZERO 0x7000        /* bit to indicate a run in an
00165                                            index volume is a zero run */
00166 
00167 /*******************************************************************
00168  * Macros.                                                         *
00169  *******************************************************************/
00170 
00171 #ifndef NULL           /* added by RWCox */
00172 #define NULL 0
00173 #endif
00174 
00175 #define MAX(a,b)        (((a)<(b)) ? (b) : (a))
00176 #define MIN(a,b)        (((a)>(b)) ? (b) : (a))
00177 
00178 /* Alloc: allocate memory */
00179 #define Alloc(context, ptr, type, size, use)                            \
00180 {                                                                       \
00181     (ptr) = (type)malloc((unsigned)(size));                             \
00182     if ((ptr) == NULL)                                                  \
00183         VPBug("out of memory");                                         \
00184     if ((context)->log_alloc_func != NULL)                              \
00185         (context)->log_alloc_func((ptr),(size),(use),                   \
00186                    __LINE__,__FILE__,(context)->client_data);           \
00187 }
00188 
00189 /* Dealloc: free memory */
00190 #define Dealloc(context, ptr)                                           \
00191 {                                                                       \
00192     if ((context)->log_free_func != NULL)                               \
00193         (context)->log_free_func(ptr, (context)->client_data);          \
00194     free((void *)ptr);                                                  \
00195 }
00196 
00197 /* Debug: print debugging information */
00198 #ifdef DEBUG
00199 #define Debug(x)        VPDebug x
00200 #else
00201 #define Debug(x)
00202 #endif
00203 
00204 /* assertions */
00205 #ifdef ASSERTIONS
00206 #define ASSERT(expr)                                                    \
00207     if (!(expr))                                                        \
00208         VPBug("assertion failed on line %d of file %s",                 \
00209               __LINE__, __FILE__)
00210 #else
00211 #define ASSERT(expr)
00212 #endif
00213 
00214 /* ReportStatus: call a callback to give a progress report */
00215 #define ReportStatus(context, frac)                                     \
00216     if ((context)->status_func != NULL)                                 \
00217         (context)->status_func(frac, (context)->client_data)
00218 
00219 /* macros for accessing the fields of a voxel */
00220 #define ByteField(voxel, offset)   (*((unsigned char *)(voxel) + (offset)))
00221 #define ShortField(voxel, offset)  (*((unsigned short *)((char *)(voxel)+\
00222                                       (offset))))
00223 #define IntField(voxel, offset)    (*((unsigned *)((char *)(voxel)+(offset))))
00224 #define VoxelField(voxel, offset, size)                         \
00225     (((size) == 1) ? ByteField(voxel, offset) :                 \
00226      ((size) == 2) ? ShortField(voxel, offset) :                \
00227                      IntField(voxel, offset))
00228 
00229 /*******************************************************************
00230  * Type definitions.                                               *
00231  *******************************************************************/
00232 
00233 /* ScanOffset: offsets to beginning of a run-length encoded voxel scanline */
00234 typedef struct {                /* ScanOffset */
00235     int first_len;              /*   byte offset to first run length */
00236     int first_data;             /*   byte offset to first voxel data */
00237 } ScanOffset;
00238 
00239 #ifdef INDEX_VOLUME
00240 /* VoxelLocation: pointer to the run containing a voxel and the position
00241    of the voxel in the run */
00242 typedef struct {                /* VoxelLocation */
00243     unsigned char run_count;    /*   number of voxels in run starting from
00244                                      this voxel (run_count = run_len for
00245                                      first voxel in run, run_count = 1 for
00246                                      last voxel in run) */
00247     unsigned char len_offset;   /*   offset in bytes from first run length
00248                                      for scanline to run length for voxel */
00249     short data_offset;          /*   offset in bytes from first voxel data
00250                                      for scanline to data for voxel, or -1
00251                                      if voxel has no data (zero run) */
00252 } VoxelLocation;
00253 #endif /* INDEX_VOLUME */
00254 
00255 /* RLEVoxels: a run-length encoding of a classified volume for one of the
00256               three principal viewing axes */
00257 typedef struct {                /* RLEVoxels */
00258     int ilen, jlen, klen;       /*   size of each dimension */
00259     int run_count;              /*   number of runs */
00260     unsigned char *run_lengths; /*   length of each run */
00261     int data_count;             /*   number of entries in data */
00262     void *data;                 /*   data */
00263     int scan_offsets_per_slice; /*   number of entries in scan_offsets for
00264                                      each slice of voxel data */
00265     ScanOffset *scan_offsets;   /*   array of offsets to scanlines */
00266     int mmapped;                /*   true if pointers point to memory-mapped
00267                                      data */
00268 #ifdef INDEX_VOLUME
00269     VoxelLocation *voxel_index; /*   index for experimental ERT code */
00270 #endif
00271 } RLEVoxels;
00272 
00273 /* RunData: statistics about the runs in a scanline of voxels */
00274 typedef struct {                /* RunData */
00275     short run_length;           /*   length of current run */
00276     short next_index;           /*   index of next voxel in current scanline */
00277     union {
00278         struct {                /*   data for pass 1 (ClassifyRawScanline) */
00279             short run_count;    /*   number of runs in scanline */
00280             short non_zero_count; /* number of nontransparent voxels in
00281                                      scanline */
00282         } p1;
00283         struct {                /*   data for pass 2 (RepackClassifiedVolume)*/
00284             unsigned data_offset; /* byte offset for storage for voxel */
00285             unsigned length_offset; /* byte offset for storage for runlength */
00286         } p2;
00287     } p;
00288 } RunData;
00289 
00290 /* GBuffer: growable buffer (a singly-linked list of buffers) */
00291 #define GBUFFER_SIZE    1024    /* number of bytes per list element
00292                                    (to optimize memory performance, size
00293                                    should be small enough so that at
00294                                    least two buffers fit in the cache) */
00295 
00296 typedef struct _gbuffer {       /* GBuffer */
00297     int bytes_left;             /*   size of unallocated space */
00298     char *data_ptr;             /*   pointer to next available byte */
00299     struct _gbuffer *next;      /*   next buffer in list */
00300     char data[GBUFFER_SIZE];    /*   data */
00301 } GBuffer;
00302 
00303 /* ConstructionBuffer: buffer for storing data while constructing a
00304                        classified volume */
00305 typedef struct {                /* ConstructionBuffer */
00306     RunData *rundata_y;         /*   statistics for y-axis runs (2D array)
00307                                      index: x*zlen + z */
00308     RunData *rundata_z;         /*   statistics for z-axis runs (2D array)
00309                                      index: y*xlen + x */
00310     GBuffer *data_buf_head;     /*   first buffer for storing voxels */
00311     GBuffer *data_buf_tail;     /*   last buffer in list */
00312     GBuffer *lengths_buf_head;  /*   first buffer for storing run lengths */
00313     GBuffer *lengths_buf_tail;  /*   last buffer in list */
00314     int non_zero_count;         /*   number of nonzero voxels in data bufs */
00315     int x_run_count;            /*   number of z-axis runs seen so far */
00316     unsigned char octree_runs[VP_MAX_VOLUME_DIM];
00317                                 /*   estimated run lengths from octree */
00318     int octree_scans_left;      /*   number of scanlines until octree_runs
00319                                      must be recomputed */
00320     int next_z;                 /*   z coordinate of next scanline */
00321     int next_y;                 /*   y coordinate of next scanline */
00322 } ConstructionBuffer;
00323 
00324 /* MinMaxOctree: min-max octree representation of the volume for
00325    fast classification */
00326 typedef struct {                /* MinMaxOctree */
00327     int levels;                 /*   number of levels in octree
00328                                      level 0 = root = lowest detail
00329                                      level levels-1 = base = finest detail */
00330     int root_node_size;         /*   voxels/side for root level */
00331     int base_node_size;         /*   voxels/side for base level */
00332     int range_bytes_per_node;   /*   bytes/node for min/max data */
00333     int base_bytes_per_node;    /*   bytes/node for base level
00334                                      (min/max data + status) */
00335     int nonbase_bytes_per_node; /*   bytes/node for non-base level
00336                                      (min/max data + status + ptr to child) */
00337     int node_offset[VP_MAX_FIELDS]; /* offset to min/max data for each
00338                                        parameter in a node; min comes first */
00339     int status_offset;          /*   offset to status field */
00340     int child_offset;           /*   offset to child field */
00341     void *root;                 /*   storage for the octree, and a pointer
00342                                      to the root node */
00343     int octree_bytes;           /*   bytes of storage for the octree */
00344 
00345     /*
00346      * Layout of an octree node:
00347      *
00348      * Nodes at level 0 (root) through levels-2 are nonbase_bytes_per_node
00349      * bytes long.  This space is divided into a number of fields as follows:
00350      *
00351      *    minimum value for parameter 0 of the classification function
00352      *    maximum value for parameter 0
00353      *    minimum value for parameter 1
00354      *    maximum value for parameter 1
00355      *    .
00356      *    .
00357      *    .
00358      *    minimum value for parameter num_clsfy_params-1
00359      *    maximum value for parameter num_clsfy_params-1
00360      *    status field
00361      *    child field
00362      *
00363      * The min/max fields are the same size as the corresponding
00364      * classification parameters (one or two bytes; four bytes not allowed).
00365      * Node_offset[] gives offsets to the min field for each parameter.
00366      *
00367      * The status field is a one byte field which is filled in during
00368      * classification of the volume (VPClassifyOctree).  The possible
00369      * values are MM_EMPTY (node is transparent), MM_FULL (node has
00370      * no transparent children), or MM_PARTFULL.  Status_offset
00371      * gives the offset to this field from the beginning of the node.
00372      *
00373      * The child field is a one word field which gives the number of
00374      * bytes from the root of the octree to the first child node of
00375      * this node.  The remaining 7 children follow right after the
00376      * first child.  Child_offset gives the offset to this field
00377      * from the beginning of the node.
00378      *
00379      * There may be additional bytes of padding in between fields
00380      * to satisfy alignment restrictions.  This could make the code
00381      * non-portable on machines with bizarre requirements.
00382      *
00383      * Nodes at level levels-1 are base_bytes_per_node long and contain
00384      * the same fields except there is no child field.
00385      *
00386      * NOTE: As you can probably tell, I'm simulating a C structure here.
00387      * Unfortunately I can't use a real structure because I don't know the
00388      * number of fields in advance: it depends on the number and
00389      * size of the classification parameters.
00390      */
00391 } MinMaxOctree;
00392 
00393 /* MMOctreeLevel: data associated with one level of the min-max octree during
00394  *     a depth first traversal; this data is used to compute which octree
00395  *     nodes intersect the current scanline of interest */
00396 typedef struct {                /* MMOctreeLevel */
00397     int level_size;             /*   voxels/side for a node at this level */
00398     int child_octant;           /*   octant number of first child to visit
00399                                      when a scanline intersects a node at
00400                                      this level */
00401     int child_offset1;          /*   offset (in bytes) of first child to
00402                                      visit relative to child 0 */
00403     int child_offset2;          /*   offset (in bytes) of second child to
00404                                      visit relative to child 0 */
00405     void *child2;               /*   points to 2nd child if first is
00406                                      begin visit; NULL otherwise */
00407 } MMOctreeLevel;
00408 
00409 /* GrayIntPixel: grayscale intermediate image pixel */
00410 typedef struct {                /* GrayIntPixel */
00411     float clrflt;               /*   color */
00412     float opcflt;               /*   opacity */
00413     short lnk;                  /*   early-ray termination link */
00414     unsigned char zratio;       /*   integer part of opacity correction
00415                                        exponent (perspective only) */
00416     unsigned char zfrac;        /*   fractional part of opacity correction
00417                                        exponent (perspective only) */
00418 } GrayIntPixel;
00419 
00420 /* RGBIntPixel: RGB intermediate image pixel */
00421 typedef struct {                /* RGBIntPixel */
00422     float rclrflt;              /*   color (red channel) */
00423     float gclrflt;              /*   color (green channel) */
00424     float bclrflt;              /*   color (blue channel) */
00425     float opcflt;               /*   opacity */
00426     short lnk;                  /*   early-ray termination link */
00427     unsigned char zratio;       /*   integer part of opacity correction
00428                                        exponent (perspective only) */
00429     unsigned char zfrac;        /*   fractional part of opacity correction
00430                                        exponent (perspective only) */
00431 } RGBIntPixel;
00432 
00433 /* Trapezoid: a trapezoidal region of the output image (used to record
00434  *            intersection of the intermediate and final images) */
00435 typedef struct {
00436     /* all coordinates are in the coordinate system of the final image */
00437     int miny;           /* first scanline of the final image which
00438                            overlaps the trapezoid */
00439     int maxy;           /* last scanline of the final image which
00440                            overlaps the trapezoid */
00441     double x_top_lft;   /* left edge of the trapezoid at y = miny */
00442     double x_top_rgt;   /* right edge of the trapezoid at y = miny */
00443     double x_incr_lft;  /* increment to add to x_top_lft to get the
00444                            left edge of the trapezoid at the next y */
00445     double x_incr_rgt;  /* increment to add to x_top_rgt to get the
00446                            right edge of the trapezoid at the next y */
00447 } Trapezoid;
00448 
00449 /* vpContext: rendering context */
00450 struct _vp_context {                    /* vpContext */
00451 
00452     /* *** USER-SPECIFIED PARAMETERS *** */
00453 
00454     /* raw volume data layout */
00455     int xlen, ylen, zlen;               /* voxels in each dimension */
00456     short raw_bytes_per_voxel;          /* size of raw voxel in bytes */
00457     short num_voxel_fields;             /* number of fields in the voxel */
00458     short num_shade_fields;             /* # of voxel fields for shading */
00459     short field_size[VP_MAX_FIELDS];    /* size of each field in bytes */
00460     short field_offset[VP_MAX_FIELDS];  /* byte offset for each field */
00461     int field_max[VP_MAX_FIELDS];       /* maximum value of each field */
00462     void *raw_voxels;                   /* voxel data */
00463     int raw_voxels_size;                /* size of raw_voxels in bytes */
00464     int xstride, ystride, zstride;      /* byte stride for each dimension */
00465 
00466     /* classification specification */
00467     double min_opacity;                 /* low opacity threshold (0.0-1.0) */
00468     int num_clsfy_params;               /* # of params for classification */
00469     int param_field[VP_MAX_FIELDS];     /* voxel field # for each param */
00470     float *clsfy_table[VP_MAX_FIELDS];  /* lookup table for each parameter */
00471     int clsfy_table_size[VP_MAX_FIELDS]; /* size of each table in bytes */
00472 
00473     /* shading specification */
00474     int color_channels;                 /* number of color channels */
00475     int shading_mode;                   /* type of shader to use */
00476     float *shade_color_table;           /* lookup table for LOOKUP_SHADER */
00477     int shade_color_table_size;         /* size of shade table in bytes */
00478     float *shade_weight_table;          /* lookup table for LOOKUP_SHADER */
00479     int shade_weight_table_size;        /* size of weight table in bytes */
00480     short num_materials;                /* # of material types in tables */
00481     short color_field;                  /* voxel field # for color index */
00482     short weight_field;                 /* field # for weight index */
00483 
00484     /* material properties for each material and surface side */
00485     double matl_props[VP_MAX_MATERIAL][2][NUM_MATL_PROPS]; /* 0.0-255.0 */
00486 
00487     /* lighting properties */
00488     short light_enable[VP_MAX_LIGHTS];  /* enable each light */
00489     vpVector4 light_vector[VP_MAX_LIGHTS]; /* normalized light direction
00490                                               vectors (in eye coordinates) */
00491     vpVector3 light_color[VP_MAX_LIGHTS];  /* light colors (0.0-1.0) */
00492     int light_both_sides;               /* use two-sided lighting */
00493     int reverse_surface_sides;          /* reverse interior and exterior */
00494 
00495     /* depth cueing parameters */
00496     short dc_enable;                    /* true to enable depth cueing */
00497     double dc_front_factor;             /* front depth cueing factor */
00498     double dc_density;                  /* fog density for depth cueing */
00499     int dc_table_len_hint;              /* hint for dc_table_len */
00500     double dc_quantization;             /* minimum resolvable depth */
00501 
00502     /* view specification */
00503     vpMatrix4 transforms[3];            /* transformation matrices (VP_MODEL,
00504                                            VP_VIEW and VP_PROJECT) */
00505     short current_matrix;               /* current matrix */
00506     int concat_left;                    /* if true, concatenate matrices
00507                                            on left instead of on right */
00508     int axis_override;                  /* if not equal to VP_NO_AXIS then
00509                                            this is an axis number (e.g.
00510                                            VP_X_AXIS) that overrides the
00511                                            computed value of best_view_axis */
00512 
00513     /* result image */
00514     void *image;                        /* memory for image */
00515     int image_width;                    /* image dimensions */
00516     int image_height;
00517     short image_bytes_per_scan;         /* size of scanline (with padding) */
00518     int pixel_type;                     /* format for pixels (e.g. VP_RGB) */
00519 
00520     /* rendering parameters */
00521     double max_opacity;                 /* high opacity threshold */
00522     short int_image_width_hint;         /* hint for size of int. image */
00523     short int_image_height_hint;
00524     short clamp_shade_table;            /* clamp shade table entries */
00525 
00526     /* min-max octree parameters */
00527     int param_maxrange[VP_MAX_FIELDS];  /* max. range of values allowed in an
00528                                            mm_octree node w/o subdividing it */
00529 
00530     /* preclassified volume parameters */
00531     short rle_bytes_per_voxel;          /* bytes per voxel in RLEVoxels */
00532     int skip_rle_x;                     /* if true, don't compute rle_x */
00533     int skip_rle_y;                     /* if true, don't compute rle_y */
00534     int skip_rle_z;                     /* if true, don't compute rle_z */
00535 
00536     /* parameters for rendering shadows */
00537     short enable_shadows;               /* if true, enable shadows */
00538     short shadow_light_num;             /* light source id (VP_LIGHT#) for
00539                                            the light producing the shadows */
00540     short shadow_width_hint;            /* hint for width of shadow buffer */
00541     short shadow_height_hint;           /* hint for height of shadow buffer */
00542     float *shadow_color_table;          /* lookup table for LOOKUP_SHADER */
00543     int shadow_color_table_size;        /* size of shade table in bytes */
00544     int shadow_bias;                    /* shadow bias distance */
00545 
00546     /* *** USER-SPECIFIED PARAMETERS THAT ARE NOT STORED IN CONTEXT FILE *** */
00547 
00548     /* dummy variable marking the boundary between state variables stored
00549        in volpack context files and those that are not; the value
00550        of this variable is never used or set */
00551     int end_of_parameters;
00552 
00553     /* callback functions */
00554     void (*shade_func)();               /* shade a voxel */
00555     int (*write_func) ANSI_ARGS((int, void *, unsigned)); /* write to file */
00556     int (*read_func) ANSI_ARGS((int, void *, unsigned));  /* read from file */
00557     void *(*mmap_func) ANSI_ARGS((int, unsigned, void *));/* memory map file */
00558     void (*log_alloc_func) ANSI_ARGS((void *,int,char *,int,char *,void *));
00559                                         /* log memory allocation */
00560     void (*log_free_func) ANSI_ARGS((void *, void *));
00561                                         /* log memory deallocation */
00562     void (*status_func) ANSI_ARGS((double, void *)); /* give progress report */
00563 
00564     /* client data */
00565     void *client_data;                  /* hook for client data structure */
00566 
00567     /* resampling filter for vpResample */
00568     int filter_num_taps;                /* number of filter taps */
00569     int filter_num_phases;              /* number of filter phases */
00570     float *filter_weights;              /* table of filter weights
00571                                            (weights[num_phases][num_taps]) */
00572 
00573     /* *** INTERNAL DATA STRUCTURES *** */
00574 
00575     /* data structures for fast classification */
00576     MinMaxOctree *mm_octree;            /* min-max octree version of volume */
00577     unsigned *sum_table;                /* summed area table */
00578     int sum_table_size;                 /* size of summed area table (bytes) */
00579 
00580     /* classified, run-length encoded volume data */
00581     RLEVoxels *rle_x;                   /* RLE data for X viewing axis */
00582     RLEVoxels *rle_y;                   /* RLE data for Y viewing axis */
00583     RLEVoxels *rle_z;                   /* RLE data for Z viewing axis */
00584     ConstructionBuffer *cbuf;           /* buffer for constructing volume */
00585 
00586     /* factored viewing parameters */
00587     short factored_view_ready;          /* true if factored view is current */
00588     short affine_view;                  /* true for affine transformation */
00589     short best_view_axis;               /* principal viewing axis */
00590     short reverse_slice_order;          /* compositing direction */
00591     short intermediate_width;           /* size of intermediate image */
00592     short intermediate_height;
00593     double shear_i;                     /* shear coefficients */
00594     double shear_j;
00595     double trans_i;                     /* translation coefficients */
00596     double trans_j;
00597     vpMatrix3 warp_2d;                  /* final 2D transformation */
00598     double depth_000;                   /* depth of first voxel in volume */
00599     double depth_di;                    /* change in depth per unit i */
00600     double depth_dj;                    /* change in depth per unit j */
00601     double depth_dk;                    /* change in depth per unit k */
00602 
00603     /* work buffers for rendering */
00604     short max_intermediate_width;       /* size of intermediate image buffer */
00605     short max_intermediate_height;
00606     short max_scan_length;              /* size of scanline buffers */
00607     short intermediate_color_channels;  /* color channels in int. image */
00608     short pad_int_to_maxwidth;          /* pad intermediate image scanlines */
00609     union {                             /* intermediate image (2D array) */
00610         GrayIntPixel *gray_intim;
00611         RGBIntPixel *rgb_intim;
00612     } int_image;
00613 
00614     /* parameters and data structures for shadows */
00615     double shadow_shear_i;              /* shear coeffs for light vector */
00616     double shadow_shear_j;
00617     double shadow_trans_i;              /* trans. coeffs for light vector */
00618     double shadow_trans_j;
00619     short shadow_width;                 /* size of image in shadow buffer */
00620     short shadow_height;
00621     short max_shadow_width;             /* size of shadow buffer */
00622     short max_shadow_height;
00623     short pad_shadow_to_maxwidth;       /* pad shadow buffer scanlines */
00624     GrayIntPixel *shadow_buffer;        /* 2D shadow buffer */
00625 
00626     /* depth cueing */
00627     float *dc_table;                    /* depth cueing lookup table */
00628     int dc_table_len;                   /* number of entries in dc_table */
00629 
00630     /* opacity correction */
00631     float affine_opac_correct[VP_OPACITY_MAX+1];
00632                                         /* maps opacity (0-255) to opacity
00633                                            corrected for view (0.0-1.0) */
00634     float shadow_opac_correct[VP_OPACITY_MAX+1];
00635                                         /* opacity correction for shadow
00636                                            buffer calculation */
00637 
00638     /* debugging info */
00639     vpResult error_code;                /* result code from first invalid
00640                                            command since last call to
00641                                            vpGetError() */
00642 #ifdef DEBUG
00643     short debug_enable[VPDEBUG_COUNT];  /* flags to enable messages */
00644     int trace_u, trace_v;               /* intermediate image pixel to trace */
00645     int trace_shadow_k;                 /* slice of interest for tracing
00646                                            shadow opacity values */
00647 #endif
00648 
00649 #ifdef USE_TIMER
00650     unsigned timer_ticks[VPTIMER_COUNT];/* timer values in ticks */
00651     double timer_usec_per_tick;         /* microseconds per tick */
00652 #ifdef HAVE_HIRES_TIMER
00653     volatile unsigned *timer_addr;      /* address of the timer */
00654     unsigned dummy_timer;               /* dummy location */
00655 #endif
00656 #endif
00657 
00658 };
00659 
00660 /*******************************************************************
00661  * Function prototypes.                                            *
00662  *******************************************************************/
00663 
00664 /* vp_context.c */
00665 
00666 /* vp_check.c */
00667 extern vpResult             VPCheckVoxelFields ANSI_ARGS((vpContext *vpc));
00668 extern vpResult             VPCheckRawVolume ANSI_ARGS((vpContext *vpc));
00669 extern vpResult             VPCheckClassifiedVolume ANSI_ARGS((
00670                                 vpContext *vpc, int axis));
00671 extern vpResult             VPCheckClassifier ANSI_ARGS((vpContext *vpc));
00672 extern vpResult             VPCheckShader ANSI_ARGS((vpContext *vpc));
00673 extern vpResult             VPCheckImage ANSI_ARGS((vpContext *vpc));
00674 extern vpResult             VPCheckShadows ANSI_ARGS((vpContext *vpc));
00675 extern vpResult             VPSetError ANSI_ARGS((vpContext *vpc,
00676                                 vpResult code));
00677 
00678 /* vp_extract.c */
00679 extern vpResult             VPClassifyBlock ANSI_ARGS((vpContext *vpc,
00680                                 int correct, int x0, int y0, int z0,
00681                                 int x1, int y1, int z1, float *opc,
00682                                 int dst_xstride, int dst_ystride,
00683                                 int dst_zstride));
00684 extern float                VPClassifyVoxel ANSI_ARGS((vpContext *vpc,
00685                                 void *voxel));
00686 extern vpResult             VPShadeBlock ANSI_ARGS((vpContext *vpc,
00687                                 int x0, int y0, int z0, int x1, int y1, int z1,
00688                                 float *shd, int dst_xstride, int dst_ystride,
00689                                 int dst_zstride));
00690 extern void                 VPQuantize ANSI_ARGS((float *src, int xlen,
00691                                 int ylen, int zlen, double scale, int maxvalue,
00692                                 unsigned char *dst, int dst_xstride,
00693                                 int dst_ystride, int dst_zstride));
00694 
00695 /* vp_linalg.c */
00696 extern void                 VPLoadTranslation ANSI_ARGS((vpMatrix4 m,
00697                                 double tx, double ty, double tz));
00698 extern void                 VPLoadRotation ANSI_ARGS((vpMatrix4 m,
00699                                 int axis, double degrees));
00700 extern void                 VPLoadScale ANSI_ARGS((vpMatrix4 m,
00701                                 double sx, double sy, double sz));
00702 
00703 /* vp_view.c */
00704 extern vpResult             VPFactorView ANSI_ARGS((vpContext *vpc));
00705 extern void                 VPComputeViewTransform ANSI_ARGS((vpContext *vpc,
00706                                 vpMatrix4 vm));
00707 extern void                 VPResizeRenderBuffers ANSI_ARGS((vpContext *vpc,
00708                                 int max_width, int max_height, int max_scan));
00709 extern void                 VPResizeDepthCueTable ANSI_ARGS((vpContext *vpc,
00710                                 int entries, int copy));
00711 extern void                 VPComputeDepthCueTable ANSI_ARGS((vpContext *vpc,
00712                                 int first, int last));
00713 extern float                VPSliceDepthCueRatio ANSI_ARGS((vpContext *vpc));
00714 extern void                 VPDepthCueIntImage ANSI_ARGS((vpContext *vpc,
00715                                 int slicenum));
00716 extern void                 VPResizeShadowBuffer ANSI_ARGS((vpContext *vpc,
00717                                 int max_width, int max_height));
00718 
00719 /* vp_util.c */
00720 extern void                 VPBug ANSI_ARGS((char *fmt, ...));
00721 #ifdef DEBUG
00722 extern void                 VPDebug ANSI_ARGS((vpContext *vpc, int debug_code,
00723                                 char *fmt, ...));
00724 #endif /* DEBUG */
00725 
00726 /* vp_rle.c */
00727 extern RLEVoxels *          VPCreateRLEVoxels ANSI_ARGS((vpContext *vpc,
00728                                 int ilen, int jlen, int klen, int data_count,
00729                                 int run_count, int rle_bytes_per_voxel));
00730 extern void                 VPDestroyRLEVoxels ANSI_ARGS((vpContext *vpc,
00731                                 RLEVoxels *rle_voxels));
00732 #ifdef INDEX_VOLUME
00733 extern vpResult             VPComputeRLEScanOffsets ANSI_ARGS((
00734                                 vpContext *vpc));
00735 #endif
00736 #ifdef DEBUG
00737 extern void                 VPCheckScanOffsets ANSI_ARGS((
00738                                 RLEVoxels *rle_voxels,
00739                                 int rle_bytes_per_voxel));
00740 extern void                 VPValidateClassifiedVolume ANSI_ARGS((
00741                                 vpContext *vpc));
00742 extern void                 VPDumpView ANSI_ARGS((vpContext *vpc));
00743 extern void                 VPDumpClassifier ANSI_ARGS((vpContext *vpc));
00744 #endif
00745 
00746 
00747 /* vp_renderA.c */
00748 extern void                 VPRenderAffine ANSI_ARGS((vpContext *vpc,
00749                                 int algorithm, void (*composite_func)()));
00750 
00751 /* vp_octree.c */
00752 extern void                 VPComputeSummedAreaTable ANSI_ARGS((
00753                                 vpContext *vpc));
00754 extern void                 VPClassifyOctree ANSI_ARGS((vpContext *vpc));
00755 extern void                 VPInitOctreeLevelStack ANSI_ARGS((vpContext *vpc,
00756                                MMOctreeLevel level_stack[VP_MAX_OCTREE_LEVELS],
00757                                int axis, int k));
00758 extern int                  VPComputeScanRuns ANSI_ARGS((vpContext *vpc,
00759                                MMOctreeLevel level_stack[VP_MAX_OCTREE_LEVELS],
00760                                unsigned char *run_lengths, int axis,
00761                                int j, int icount));
00762 extern int                  VPCheckRuns ANSI_ARGS((vpContext *vpc,
00763                                 unsigned char *run_lengths, int axis,
00764                                 int k, int j));
00765 extern void                 VPTestMinMaxOctree ANSI_ARGS((vpContext *vpc));
00766 
00767 /* vp_warp.c */
00768 extern void                 VPComputeWarpTables ANSI_ARGS((void));
00769 extern void                 VPAffineImageOverlap ANSI_ARGS((int in_width,
00770                                 int in_height, int out_width, int out_height,
00771                                 vpMatrix3 warp_matrix, double filter_width,
00772                                 Trapezoid full_overlap[9],
00773                                 Trapezoid part_overlap[9]));
 

Powered by Plone

This site conforms to the following standards: