home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / lic / part06 < prev    next >
Encoding:
Text File  |  1993-11-09  |  60.1 KB  |  1,896 lines

  1. Newsgroups: comp.sources.misc
  2. From: casey@gauss.llnl.gov (Casey Leedom)
  3. Subject: v40i120:  lic - LLNL Line Integral Convolution, v1.3, Part06/09
  4. Message-ID: <1993Nov9.171011.26848@sparky.sterling.com>
  5. X-Md4-Signature: 665e9ec0afab99cc8a6c2b1b030d439d
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Tue, 9 Nov 1993 17:10:11 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: casey@gauss.llnl.gov (Casey Leedom)
  12. Posting-number: Volume 40, Issue 120
  13. Archive-name: lic/part06
  14. Environment: UNIX
  15. Supersedes: lic: Volume 38, Issue 104
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # Contents:  lic.1.3/avs/LIC.txt lic.1.3/include/lic.h
  22. #   lic.1.3/liblic/ComputeImage.c lic.1.3/liblic/Convolve2D.c
  23. #   lic.1.3/liblic/Convolve3D.c lic.1.3/test/BasketWeave.c
  24. # Wrapped by kent@sparky on Tue Nov  9 10:09:40 1993
  25. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  26. echo If this archive is complete, you will see the following message:
  27. echo '          "shar: End of archive 6 (of 9)."'
  28. if test -f 'lic.1.3/avs/LIC.txt' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'lic.1.3/avs/LIC.txt'\"
  30. else
  31.   echo shar: Extracting \"'lic.1.3/avs/LIC.txt'\" \(9112 characters\)
  32.   sed "s/^X//" >'lic.1.3/avs/LIC.txt' <<'END_OF_FILE'
  33. XAVS Modules                                            LIC
  34. XLawrence Livermore National Laboratory
  35. X
  36. XNAME
  37. X     LIC - 2D Line Integral Convolution (LIC) vector field imager
  38. X
  39. XSUMMARY
  40. X     Name       LIC
  41. X
  42. X     Type       mapper
  43. X
  44. X     Inputs       field 2D 2-vector float (vector field)
  45. X               field 2D 4-vector byte (image)
  46. X
  47. X     Outputs       field 2D 4-vector 2-space byte (filtered image)
  48. X
  49. X     Parameters       
  50. X    Name                   Type         Default        Min      Max
  51. X    ---------------------------------------------------------------------
  52. X    Filter type               choice    Box        N/A       N/A
  53. X    Normalization type        choice    Variable        N/A       N/A
  54. X    Length                    integer    10              0         1000
  55. X    Frequency                    real     3.0             0.1       100.0
  56. X    Variable length filtering  toggle    off        off      on
  57. X    Variable speed filtering   toggle    off        off       on
  58. X    Animate                    toggle       off             off       on
  59. X    Red               integer      -1              -1        255
  60. X    Green               integer      -1              -1        255
  61. X    Blue               integer      -1              -1        255
  62. X    Alpha               integer      -1              -1        255
  63. X    Threads               integer      1               0         1000
  64. X
  65. X
  66. XDESCRIPTION
  67. X     This module one-dimensionally filters the input image along local
  68. X     stream lines defined by the input vector field. The resulting
  69. X     output image appears as though it was painted using a coarse
  70. X     brush. Many options exist for modifying the behavior of the
  71. X     algorithm and thus controlling the appearance of the output image
  72. X     (see below).  Particularly noteworthy is the ripple filter option
  73. X     used in conjunction with the animate option. One can use these
  74. X     two options to animate a sequence, visualizing the flow of the
  75. X     vector field for a single time step.
  76. X
  77. X     An arbitrary RGBA image can be used as input, however white or
  78. X     band limited noise produce the most effective scientific
  79. X     visualizations.  The input image and vector field need not be the
  80. X     same size. If the input image is smaller the input vector field
  81. X     then the image is replicated and truncated to match the vector
  82. X     field dimensions. Best results occur when contrast stretching the
  83. X     output (see example 1).
  84. X
  85. X     The algorithm details and descriptions are presented in the
  86. X     SIGGRAPH '93 paper ``Imaging Vector Fields Using Line Integral
  87. X     Convolution'' by Brian Cabral and Casey Leedom.
  88. X
  89. XINPUTS
  90. X     Input field - a 2-D 2-vector float field
  91. X    A classic 2-space 2-vector field. Note that many 3-D slicing tools
  92. X    produce 2-dimensional 3-vector fields and will require using the
  93. X    extract vector module to remove one of the 3-vector components.
  94. X
  95. X     Input texture - a 2-D 4-vector byte RGBA image
  96. X    An arbitrary RGBA image.
  97. X
  98. XPARAMETERS
  99. X
  100. X     Filter type
  101. X    Choice: Box, Ripple, Ramp or Select
  102. X    Default: Box
  103. X
  104. X    The Box filter is the default filter. The Ripple filter can be
  105. X    used for animating vector field flow for a single time step.
  106. X    The Ramp filter can be used for motion blurring and special
  107. X    effects.  The Select filter selects an approximately one pixel
  108. X    wide window near the end of the locally advected streamline.
  109. X    This can be used to produce a warp of the input texture.
  110. X
  111. X     Normalization type
  112. X    Choice: Fixed or Variable
  113. X    Default: Variable
  114. X
  115. X    Fixed normalization uses a constant value to normalize the
  116. X    output pixel intensity. This type of normalization causes
  117. X    field singularities to appear darkener.  If the vector field
  118. X    flows out of or into an edge this edge is also attenuated.
  119. X    Variable normalization normalizes the output pixel so that the
  120. X    entire image appears uniform in brightness (assuming uniform
  121. X    brightness in the input image) irrespective of any vector
  122. X    field singularities.
  123. X
  124. X     Length
  125. X    Integer
  126. X    Default: 10
  127. X
  128. X    This parameter controls the amount of blurring or the length
  129. X    of the line integral convolution. The number is given in unit
  130. X    pixels. Note that the run time of the algorithm is
  131. X    proportional to this parameter.
  132. X
  133. X     Frequency
  134. X    (only available for filter type "ripple")
  135. X    Real
  136. X    Default: 3.0
  137. X
  138. X    This parameter is only used in conjunction with the ripple
  139. X    filter.  It specifies the number cycles of the ripple filter
  140. X    over the length of the filter.  This governs the relative
  141. X    feature size of apparent motion when used with the animate
  142. X    option. Smaller values for frequency produce bigger features.
  143. X    However, low frequency values produce animations which appear
  144. X    to come in to and out of apparent focus (i.e.  the filter
  145. X    has poor frequency response).  High frequencies have better
  146. X    frequency response, but smaller apparent features.  Finally,
  147. X    the frequency response problem can also be dealt with by
  148. X    increasing the length of the filter, but this may introduce
  149. X    more blurring than desired.  There's no free lunch.
  150. X
  151. X     Variable length filtering
  152. X    Toggle
  153. X    Default: off
  154. X
  155. X    Enabling variable length filtering.  The filter length for each
  156. X    vector v will vary from 0 to Length based on the vector's
  157. X    magnitude.  This magnitude scaling is performed by finding the
  158. X    maximum magnitude vector in the input vector field, max_v, and
  159. X    then using a filter length equal to Length * ||v|| / ||max_v||.
  160. X    The filter will be dilated to match the length of the convolution.
  161. X    This prevents any visual artifacts which might occur because of
  162. X    abrupt filter truncation if the filter were not dilated.
  163. X
  164. X     Variable speed filtering
  165. X    (only available for filter type "ripple")
  166. X    Toggle
  167. X    Default: off
  168. X
  169. X    This option is used in conjunction with the ripple filter in
  170. X    animation mode. When enabled the LIC algorithm will vary
  171. X    apparent motion flow as a function of the vector field
  172. X    magnitude so that high magnitude portions of the vector field
  173. X    move faster than low magnitude parts.  This is accomplished by
  174. X    scaling the ripple filter frequency inversely by vector
  175. X    magnitudes.
  176. X
  177. X     Animate
  178. X    (only available for filter type "ripple")
  179. X    Toggle
  180. X    Default: off
  181. X
  182. X    Enabling the animate option will cause this module to produce
  183. X    LIC_ANIMATION_FRAMES animated frames showing vector field flow
  184. X    for a single time step.  The phase of the ripple filter will
  185. X    be different for each frame, varying from 0 to 2*Pi.
  186. X    LIC_ANIMATION_FRAMES is currently hardwired to 10.
  187. X
  188. X     Red, Green, Blue and Alpha
  189. X    Integer
  190. X    Default: -1
  191. X
  192. X    These RGBA values instruct the module on how to color pixels which
  193. X    map onto zero length vectors. A value of -1 instructs the
  194. X    algorithm to use the underlying texture pixel value for the given
  195. X    color channel.
  196. X
  197. X     Threads
  198. X    Integer
  199. X    Default: 1
  200. X
  201. X    Specifies the number of parallel threads to use when computing the
  202. X    output image.  If 0, the maximum number of CPUs available for
  203. X    parallel processing on the current system will be used.  Note that
  204. X    parallel processing support is not available on all systems.  If a
  205. X    value other than 1 is specified on a system which does not support
  206. X    parallel processing, a warning will be issued and the calculation
  207. X    will proceed single threaded.
  208. X
  209. XOUTPUTS
  210. X     Output image - 2D 4-vector 2-space byte field RGBA image
  211. X    The module generates the usual RGBA AVS image which can be
  212. X        displayed or otherwise manipulated.
  213. X
  214. XEXAMPLE    1
  215. X    The first example illustrates the use of the LIC module
  216. X    to visualize a 2-D vector field. Note the use of the contrast
  217. X        stretching module to produce a crisper image. Good contrast values
  218. X        are 50 and 200 for the input minimum and maximum values
  219. X        respectively.
  220. X
  221. X    READ FIELD      GENERATE NOISE
  222. X             |            |
  223. X             +----------+ |
  224. X                        | |
  225. X                        LIC
  226. X                         |
  227. X                         |
  228. X                      CONTRAST
  229. X                         |
  230. X                 +-------+------+
  231. X                 |              |
  232. X          DISPLAY IMAGE     WRITE IMAGE
  233. X
  234. XEXAMPLE    2
  235. X    This second example is the same as first except it produces a
  236. X        single time step flow animation. Note that the ripple function and
  237. X        animation options must be enabled on the LIC algorithm the number
  238. X        of frames is equal to the length of the LIC filter. The image
  239. X        viewer will allow you to view and save the animation sequence.
  240. X
  241. X    READ FIELD      GENERATE NOISE
  242. X             |            |
  243. X             +----------+ |
  244. X                        | |
  245. X                        LIC
  246. X                         |
  247. X                         |
  248. X                      CONTRAST
  249. X                         |
  250. X                    IMAGE VIEWER
  251. X       
  252. XFEATURES/BUGS
  253. X     Asynchronous button display
  254. X        When this module is invoked and the flow executive is disabled the
  255. X        animate, period, and variable speed buttons will not become visible
  256. X        upon selection of the ripple filter. In all other cases these latter
  257. X        buttons become visible upon selection of the ripple filter and become
  258. X        invisible upon selection of another filter.
  259. X
  260. XRELATED MODULES
  261. X     Generate noise
  262. X
  263. XAUTHOR
  264. X     Brian Cabral, Casey Leedom
  265. X     Lawrence Livermore National Laboratory
  266. X
  267. X     Copyright (c) 1993 The Regents of the University of California.
  268. X     All rights reserved.
  269. X
  270. X
  271. XAVS Modules                                            LIC
  272. XLawrence Livermore National Laboratory
  273. END_OF_FILE
  274.   if test 9112 -ne `wc -c <'lic.1.3/avs/LIC.txt'`; then
  275.     echo shar: \"'lic.1.3/avs/LIC.txt'\" unpacked with wrong size!
  276.   fi
  277.   # end of 'lic.1.3/avs/LIC.txt'
  278. fi
  279. if test -f 'lic.1.3/include/lic.h' -a "${1}" != "-c" ; then 
  280.   echo shar: Will not clobber existing file \"'lic.1.3/include/lic.h'\"
  281. else
  282.   echo shar: Extracting \"'lic.1.3/include/lic.h'\" \(9521 characters\)
  283.   sed "s/^X//" >'lic.1.3/include/lic.h' <<'END_OF_FILE'
  284. X/*
  285. X * $Header: /usr/local/src/lic/include/RCS/lic.h,v 1.18 1993/11/04 03:42:02 casey Exp $
  286. X */
  287. X
  288. X/*
  289. X * Copyright (c) 1993 The Regents of the University of California.
  290. X * All rights reserved.
  291. X *
  292. X * Redistribution and use in source and binary forms, with or without
  293. X * modification, are permitted provided that the following conditions
  294. X * are met:
  295. X * 1. Redistributions of source code must retain the above copyright
  296. X *    notice, this list of conditions and the following disclaimer.
  297. X * 2. Redistributions in binary form must reproduce the above copyright
  298. X *    notice, this list of conditions and the following disclaimer in the
  299. X *    documentation and/or other materials provided with the distribution.
  300. X * 3. All advertising materials mentioning features or use of this software
  301. X *    must display the following acknowledgement:
  302. X *    This product includes software developed by the University of
  303. X *    California, Lawrence Livermore National Laboratory and its
  304. X *    contributors.
  305. X * 4. Neither the name of the University nor the names of its contributors
  306. X *    may be used to endorse or promote products derived from this software
  307. X *    without specific prior written permission.
  308. X *
  309. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  310. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  311. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  312. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  313. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  314. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  315. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  316. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  317. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  318. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  319. X * SUCH DAMAGE.
  320. X */
  321. X
  322. X#ifndef _LIC_H_
  323. X#define    _LIC_H_
  324. X
  325. X
  326. X/*
  327. X * Public user interface to Line Integral Convolution (LIC) library.
  328. X *
  329. X * For a thorough explaination of vector field imaging algorithms used in
  330. X * this library see: "Imaging Vector Fields Using Line Integral Convolution"
  331. X * by Brian Cabral and Casey Leedom in the SIGGRAPH '93 proceedings.
  332. X */
  333. X#define LIC_VERSION    "1.3/PL0"
  334. X
  335. X
  336. X/*
  337. X * Handy booleans.
  338. X */
  339. X#ifndef TRUE
  340. X#   define TRUE        1
  341. X#endif
  342. X
  343. X#ifndef FALSE
  344. X#   define FALSE     0
  345. X#endif
  346. X
  347. X
  348. X/*
  349. X * Integral tabel length and the number of different speeds we keep.
  350. X */
  351. X#define LIC_INTEGRAL_LEN    2048
  352. X#define LIC_INTEGRAL_SPEEDS    20
  353. X
  354. X
  355. X/*
  356. X * Convolution integration direction for LIC_Convolve routines.
  357. X */
  358. X#define LIC_FOREWARD     1
  359. X#define LIC_BACKWARD    -1
  360. X
  361. X
  362. X/*
  363. X * Normalization types.  The Line Integral Convolution process integrates
  364. X * a set of pixels on a parametric curve in an input image multiplied by
  365. X * a filter kernel.  Unless this integral is normalized by the integral of
  366. X * the filter kernel (the area under the filter kernel), output pixels will
  367. X * often be overly bright (and quite probably clamped to maximum pixel
  368. X * values).  With VARIABLE normalization the convolution integral is
  369. X * normalized by the integral of the filter kernel actually used in the LIC.
  370. X * With FIXED normalization the convolution integral is normalized by the
  371. X * full integral of the filter kernel.  This will have an effect when a
  372. X * LIC is prematurely terminated by a singularity.  With FIXED normalization
  373. X * these truncated LICs will have their brightness lowered by the larger
  374. X * normalization factor.
  375. X */
  376. X#define LIC_VARIABLE    0
  377. X#define LIC_FIXED    1
  378. X
  379. X
  380. X/*
  381. X * Image and vector field data types used by the LIC algorithm.
  382. X */
  383. Xtypedef struct LIC_Image_
  384. X{
  385. X    unsigned char     *data;        /* image pixel data */
  386. X    int                   Xres;        /* size of image in x, y and z */
  387. X    int                   Yres;
  388. X    int                   Zres;
  389. X    int                   Rank;        /* size of pixels in bytes */
  390. X} LIC_Image;
  391. X
  392. Xtypedef struct LIC_VectorField_
  393. X{
  394. X    float              *data;        /* original vector field data */
  395. X    int                   Xres;        /* size of field in x, y and z */
  396. X    int                   Yres;
  397. X    int                   Zres;
  398. X    int                   Rank;        /* size of field elements in floats */
  399. X} LIC_VectorField;
  400. X
  401. X
  402. X/*
  403. X * LIC instance structure.
  404. X */
  405. Xtypedef struct LIC_
  406. X{
  407. X    /*
  408. X     * User supplied arguments.  Most are supplied by the LIC_Create
  409. X     * constructor.  Phase is supplied by LIC_ChangePhase for use in
  410. X     * computing LICs with varying phase for animation purposes.
  411. X     */
  412. X    LIC_Image       InputImage;        /* input image */
  413. X    LIC_VectorField InputField;        /* input vector field */
  414. X    LIC_VectorField NormalField;    /* (normalized version of field) */
  415. X    LIC_Image       OutputImage;    /* output image (possibly allocated */
  416. X                    /*   by Create) */
  417. X    int                FreeOutput;        /* (free OutputImage on Destroy) */
  418. X    double        (*Filter)(struct LIC_ *, double, double, int);
  419. X                    /* function called to provide filter */
  420. X                    /*   kernel integrals */
  421. X    int                NormalizationType;    /* normalization type */
  422. X    int                Normalized;
  423. X    double          Length;        /* half length of filter kernel */
  424. X    double          Phase;        /* phase of filter */
  425. X    double          Frequency;        /* frequency of filter */
  426. X    int                VariableLength;    /* do variable length LIC */
  427. X    int                VariableSpeed;    /* do variable speed (phase) LIC */
  428. X    int             DefaultAlpha;    /* default pixel value for zero */
  429. X    int             DefaultRed;        /*   magnitude vectors */
  430. X    int             DefaultGreen;
  431. X    int             DefaultBlue;
  432. X    void          (*UpdateUser)(double);
  433. X                    /* function called to report percent */
  434. X                    /*   of LIC completed */
  435. X    void          (*ReportError)(const char *);
  436. X                    /* function called to report errors */
  437. X    unsigned int    NumThreads;        /* number of parallel threads to */
  438. X                    /*   spawn in LIC_ComputeImage ... */
  439. X
  440. X    /*
  441. X     * Convolution filter integral tables.  Cumulative filter kernel integral
  442. X     * values are computed at LIC_INTEGRAL_LEN points from 0 to Length.
  443. X     * Integral tables are constructed for both the positive and negative
  444. X     * haves of the filter kernel (-Length .. Length).
  445. X     *
  446. X     * Additionally, LIC_INTEGRAL_SPEEDS versions of these tables are
  447. X     * constructed for use in variable ``speed'' LIC computation.
  448. X     * The scaled magnitude of the vector being imaged is used to index
  449. X     * into one of the speed variation tables.
  450. X     */
  451. X    int                NeedIntegration;    /* need to build integral tables */
  452. X    double          NegIntegralTable[LIC_INTEGRAL_SPEEDS][LIC_INTEGRAL_LEN];
  453. X    double          PosIntegralTable[LIC_INTEGRAL_SPEEDS][LIC_INTEGRAL_LEN];
  454. X    double          MaxLength;        /* maximum vector magnitude in */
  455. X                    /*   input vector field */
  456. X
  457. X    /*
  458. X     * Bookkeeping ...
  459. X     */
  460. X    double          TotalLength;    /* total length of LICs traversed */
  461. X    int                TotalLoopCount;    /* total loop cells visited */
  462. X} LIC;
  463. X
  464. X
  465. X/*
  466. X * Filter function types.
  467. X */
  468. Xtypedef double
  469. X    (*LIC_Filter)(LIC *This, double a, double b, int speed);
  470. X
  471. X
  472. X/*
  473. X * User interface to the LIC library.
  474. X */
  475. X#ifdef __cplusplus
  476. Xextern "C" {
  477. X#endif
  478. X
  479. XLIC *
  480. XLIC_Create(unsigned char *InputImage,
  481. X       int              iiXres,
  482. X       int              iiYres,
  483. X       int              iiZres,
  484. X       float         *InputField,
  485. X       int              ifXres,
  486. X       int              ifYres,
  487. X       int              ifZres,
  488. X       unsigned char *OutputImage,
  489. X       LIC_Filter     Filter,
  490. X       int              NormalizationType,
  491. X       int              Normalized,
  492. X       double         Length,
  493. X       double         Frequency,
  494. X       int              VariableLength,
  495. X       int              VariableSpeed,
  496. X       int            DefaultRed,
  497. X       int            DefaultGreen,
  498. X       int            DefaultBlue,
  499. X       int            DefaultAlpha,
  500. X       void        (*UpdateUser)(double),
  501. X       void        (*ReportError)(const char *));
  502. X
  503. Xvoid        LIC_Destroy(LIC *This);
  504. X
  505. Xvoid        LIC_ChangeLength    (LIC *This, double length);
  506. Xvoid        LIC_ChangePhase     (LIC *This, double phase);
  507. Xvoid        LIC_ChangeFrequency (LIC *This, double frequency);
  508. Xvoid        LIC_ChangeFilter    (LIC *This, LIC_Filter filter);
  509. Xvoid        LIC_ChangeNumThreads(LIC *This, int threads);
  510. X
  511. Xdouble      LIC_Box   (LIC *This, double a, double b, int speed);
  512. Xdouble      LIC_Ripple(LIC *This, double a, double b, int speed);
  513. Xdouble      LIC_Ramp  (LIC *This, double a, double b, int speed);
  514. Xdouble      LIC_Select(LIC *This, double a, double b, int speed);
  515. X
  516. Xvoid        LIC_BuildIntegralTables(LIC *This);
  517. Xvoid        LIC_ComputeImage(LIC *This);
  518. X
  519. Xvoid
  520. XLIC_Convolve2D(LIC      *This,
  521. X           int       i,
  522. X           int       j,
  523. X           int       direction,
  524. X           double   *rIntegral,
  525. X           double   *gIntegral,
  526. X           double   *bIntegral,
  527. X           double   *aIntegral,
  528. X           double   *KernelArea);
  529. X
  530. Xvoid
  531. XLIC_Convolve3D(LIC      *This,
  532. X           int       i,
  533. X           int       j,
  534. X           int       k,
  535. X           int       direction,
  536. X           double   *rIntegral,
  537. X           double   *gIntegral,
  538. X           double   *bIntegral,
  539. X           double   *aIntegral,
  540. X           double   *KernelArea);
  541. X
  542. X#define LIC_InputImage(T)    (T)->InputImage->data
  543. X#define LIC_InputField(T)    (T)->InputField->data
  544. X#define LIC_OutputImage(T)    (T)->OutputImage->data
  545. X#define LIC_Length(T)        (T)->Length
  546. X#define LIC_Phase(T)        (T)->Phase
  547. X#define LIC_Frequency(T)    (T)->Frequency
  548. X#define    LIC_NumThreads(T)    (T)->NumThreads
  549. X
  550. Xint         LIC_ConfiguredPixelSize(void);
  551. Xconst char *LIC_ConfiguredPixelType(void);
  552. X
  553. X#ifdef __cplusplus
  554. X}
  555. X#endif
  556. X
  557. X
  558. X#endif /* _LIC_H_ */
  559. END_OF_FILE
  560.   if test 9521 -ne `wc -c <'lic.1.3/include/lic.h'`; then
  561.     echo shar: \"'lic.1.3/include/lic.h'\" unpacked with wrong size!
  562.   fi
  563.   # end of 'lic.1.3/include/lic.h'
  564. fi
  565. if test -f 'lic.1.3/liblic/ComputeImage.c' -a "${1}" != "-c" ; then 
  566.   echo shar: Will not clobber existing file \"'lic.1.3/liblic/ComputeImage.c'\"
  567. else
  568.   echo shar: Extracting \"'lic.1.3/liblic/ComputeImage.c'\" \(11062 characters\)
  569.   sed "s/^X//" >'lic.1.3/liblic/ComputeImage.c' <<'END_OF_FILE'
  570. X/*
  571. X * $Header: /usr/local/src/lic/liblic/RCS/ComputeImage.c,v 1.15 1993/11/05 00:14:44 casey Exp $
  572. X */
  573. X
  574. X/*
  575. X * Copyright (c) 1993 The Regents of the University of California.
  576. X * All rights reserved.
  577. X *
  578. X * Redistribution and use in source and binary forms, with or without
  579. X * modification, are permitted provided that the following conditions
  580. X * are met:
  581. X * 1. Redistributions of source code must retain the above copyright
  582. X *    notice, this list of conditions and the following disclaimer.
  583. X * 2. Redistributions in binary form must reproduce the above copyright
  584. X *    notice, this list of conditions and the following disclaimer in the
  585. X *    documentation and/or other materials provided with the distribution.
  586. X * 3. All advertising materials mentioning features or use of this software
  587. X *    must display the following acknowledgement:
  588. X *    This product includes software developed by the University of
  589. X *    California, Lawrence Livermore National Laboratory and its
  590. X *    contributors.
  591. X * 4. Neither the name of the University nor the names of its contributors
  592. X *    may be used to endorse or promote products derived from this software
  593. X *    without specific prior written permission.
  594. X *
  595. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  596. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  597. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  598. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  599. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  600. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  601. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  602. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  603. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  604. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  605. X * SUCH DAMAGE.
  606. X */
  607. X
  608. X#ifndef lint
  609. X    static char rcsid[] = "$Header: /usr/local/src/lic/liblic/RCS/ComputeImage.c,v 1.15 1993/11/05 00:14:44 casey Exp $";
  610. X    static char copyright[] =
  611. X    "Copyright (c) 1993 The Regents of the University of California.\n"
  612. X    "All rights reserved.\n";
  613. X#endif
  614. X
  615. X
  616. X#include "liblic.h"
  617. X
  618. X
  619. X/*
  620. X *    Perform Line Integral Convolution (LIC) on a LIC instance.
  621. X *    ==========================================================
  622. X */
  623. X
  624. X
  625. X#ifdef DEBUG
  626. XFILE *ps;
  627. X#endif
  628. X
  629. X
  630. X/*
  631. X *    Local routines
  632. X *    ==============
  633. X */
  634. Xstatic void ComputeStripe(LIC *This, int parallel, int y_lo, int y_hi);
  635. X
  636. X
  637. X/*
  638. X *    Code to implement ComputeImage(...) API.
  639. X *    ========================================
  640. X *
  641. X * Includes a generic single threaded implementation and various platform
  642. X * specific multithreaded implementations.
  643. X */
  644. X
  645. X
  646. X#if (!defined(PARALLEL))
  647. X    void
  648. X    LIC_ComputeImage(LIC *This)
  649. X    /*
  650. X     * Compute LIC for each vector in input vector field.
  651. X     *
  652. X     * Generic, non-parallel version.  Just call ComputeStripe to compute
  653. X     * LICs for entire field and indicate this *isn't* a stripe out of a
  654. X     * parallel set of threads.
  655. X     */
  656. X    {
  657. X    if (LIC_NumThreads(This) > 1 && This->ReportError)
  658. X        This->ReportError("LIC_ComputeImage: no parallel support,"
  659. X                  " executing single threaded");
  660. X    ComputeStripe(This, FALSE, 0, This->InputField.Yres);
  661. X    }
  662. X#endif /* PARALLEL */
  663. X
  664. X
  665. X#if (defined(HAS_M_FORK))
  666. X    /*
  667. X     * This is known to work under SGI IRIX 4.0.5.  The SGI m_fork()
  668. X     * primitives are based on the Sequent Computer Systems parallel
  669. X     * programming primitives, thus there is some chance that this may
  670. X     * also work on a Sequent ...
  671. X     */
  672. X
  673. X#   include <ulocks.h>
  674. X#   include <task.h>
  675. X
  676. X    static void mstripe(LIC *This);
  677. X
  678. X    void
  679. X    LIC_ComputeImage(LIC *This)
  680. X    /*
  681. X     * Compute LIC for each vector in input vector field.
  682. X     *
  683. X     * Basic algorithm is to use m_fork to split the task among
  684. X     * numprocs threads.  Each thread will process a stripe of
  685. X     * rows.
  686. X     *
  687. X     * If their are fewer rows than threads (as reported by
  688. X     * m_get_numprocs()), then we limit the number of threads to
  689. X     * the number of rows.  We should really automatically slice
  690. X     * the field more intelligently to take full advantage of the
  691. X     * number of processors available -- perhaps via vertical
  692. X     * stripes or tiles or even bricks (cuboids) for
  693. X     * three-dimensional fields -- but this is really just a quick
  694. X     * hack and True Intelligence is not our aim ... :-)
  695. X     *
  696. X     * Note also that it would really be nice if we could mark all
  697. X     * of the InputImage and NormalField as read-only in order to
  698. X     * prevent cache snoopers from flushing caches when multiple
  699. X     * threads access the same input cells.  Unfortunately can't
  700. X     * see a way of doing this.  lic(1) automatically does this
  701. X     * for us if HAS_MMAP is defined -- but only if the vector
  702. X     * field is already normalized ...
  703. X     */
  704. X    {
  705. X    if (This->NumThreads == 1 || This->InputField.Yres == 1)
  706. X        ComputeStripe(This, FALSE, 0, This->InputField.Yres);
  707. X    else
  708. X    {
  709. X        int numprocs,  onumprocs;
  710. X
  711. X        numprocs = onumprocs = m_get_numprocs();
  712. X
  713. X        /* pay attention to any user parallelization limits */
  714. X        if (This->NumThreads > 0 && numprocs > This->NumThreads)
  715. X        numprocs = This->NumThreads;
  716. X
  717. X        /* don't fork more threads than we have rows */
  718. X        if (numprocs > This->InputField.Yres)
  719. X        numprocs = This->InputField.Yres;
  720. X
  721. X        /* restrict the number of threads to execute ... */
  722. X        if (numprocs != onumprocs)
  723. X        m_set_procs(numprocs);
  724. X
  725. X        if (m_fork(mstripe, This) >= 0)
  726. X        m_kill_procs();
  727. X        else
  728. X        {
  729. X        if (This->ReportError)
  730. X            This->ReportError("LIC_ComputeImage: m_fork failed,"
  731. X                      " executing single threaded");
  732. X        ComputeStripe(This, FALSE, 0, This->InputField.Yres);
  733. X        }
  734. X
  735. X        /* restore previous default number of parallel threads ... */
  736. X        if (numprocs > onumprocs)
  737. X        m_set_procs(onumprocs);
  738. X    }
  739. X    }
  740. X
  741. X
  742. X    static void
  743. X    mstripe(LIC *This)
  744. X    /*
  745. X     * mstripe is called by m_fork to distribute LIC calculations among
  746. X     * numprocs threads.
  747. X     */
  748. X    {
  749. X    int numprocs = m_get_numprocs();
  750. X    int myid = m_get_myid();
  751. X    int stripesize = (This->InputField.Yres + numprocs-1) / numprocs;
  752. X    int y_lo = myid * stripesize;
  753. X    int y_hi = y_lo + stripesize;
  754. X    if (y_hi > This->InputField.Yres)
  755. X        y_hi = This->InputField.Yres;
  756. X    ComputeStripe(This, TRUE, y_lo, y_hi);
  757. X    }
  758. X#   endif /* HAS_M_FORK */
  759. X
  760. X
  761. X/*
  762. X *    Main code for top-level LIC computation.
  763. X *    ========================================
  764. X */
  765. X
  766. X
  767. Xstatic void
  768. XComputeStripe(LIC *This, int parallel, int y_lo, int y_hi)
  769. X    /*
  770. X     * Compute LIC for the row stripe [y_lo, y_hi).  The flag "parallel" tells
  771. X     * us if we've been invoked as a parallel thread and, thus, need to use
  772. X     * special code to estimate how far along the whole job is ...
  773. X     */
  774. X{
  775. X    int    i, j, k;
  776. X    double nrows    = (This->InputField.Yres * This->InputField.Zres);
  777. X    int    nrows_10 = (This->InputField.Yres * This->InputField.Zres)/10;
  778. X    int    rowcount = 0;
  779. X
  780. X#   if (defined(DEBUG))
  781. X    ps = fopen("tmp.ps", "r+");
  782. X    if (ps == NULL)
  783. X    {
  784. X        perror("tmp.ps");
  785. X        exit(1);
  786. X    }
  787. X#   endif
  788. X
  789. X    /*
  790. X     * Loop over the vector field rendering a pixel per field vector.
  791. X     */
  792. X    for (k = 0; k < This->InputField.Zres; k++)
  793. X    {
  794. X    for (j = y_lo; j < y_hi; j++)
  795. X    {
  796. X        /* Update status every 10% rows */
  797. X        if (This->UpdateUser)
  798. X        {
  799. X        int count;
  800. X
  801. X#        if (defined(PARALLEL))
  802. X            if (parallel)
  803. X            {
  804. X#            if (defined(HAS_M_FORK))
  805. X                count = m_next();
  806. X#            endif
  807. X            }
  808. X            else
  809. X            count = rowcount++;
  810. X#        else
  811. X            count = rowcount++;
  812. X#        endif
  813. X
  814. X        if ((count % nrows_10) == 0)
  815. X            This->UpdateUser(100.0 * count / nrows);
  816. X        }
  817. X
  818. X        for (i = 0; i < This->InputField.Xres; i++)
  819. X        {
  820. X        double ForewardKernelArea, BackwardKernelArea;
  821. X        double rForewardIntegral, gForewardIntegral,
  822. X               bForewardIntegral, aForewardIntegral;
  823. X        double rBackwardIntegral, gBackwardIntegral,
  824. X               bBackwardIntegral, aBackwardIntegral;
  825. X
  826. X        if (This->InputField.Zres == 1)
  827. X        {
  828. X            LIC_Convolve2D(This, i, j, LIC_FOREWARD,
  829. X                   &rForewardIntegral, &gForewardIntegral,
  830. X                   &bForewardIntegral, &aForewardIntegral,
  831. X                   &ForewardKernelArea);
  832. X            LIC_Convolve2D(This, i, j, LIC_BACKWARD,
  833. X                   &rBackwardIntegral, &gBackwardIntegral,
  834. X                   &bBackwardIntegral, &aBackwardIntegral,
  835. X                   &BackwardKernelArea);
  836. X        }
  837. X        else
  838. X        {
  839. X            LIC_Convolve3D(This, i, j, k, LIC_FOREWARD,
  840. X                   &rForewardIntegral, &gForewardIntegral,
  841. X                   &bForewardIntegral, &aForewardIntegral,
  842. X                   &ForewardKernelArea);
  843. X            LIC_Convolve3D(This, i, j, k, LIC_BACKWARD,
  844. X                   &rBackwardIntegral, &gBackwardIntegral,
  845. X                   &bBackwardIntegral, &aBackwardIntegral,
  846. X                   &BackwardKernelArea);
  847. X        }
  848. X
  849. X#        if (PixelSize >= 3)
  850. X        {
  851. X            double red, green, blue;
  852. X
  853. X            red   = (rForewardIntegral + rBackwardIntegral)
  854. X            / (ForewardKernelArea + BackwardKernelArea);
  855. X            green = (gForewardIntegral + gBackwardIntegral)
  856. X            / (ForewardKernelArea + BackwardKernelArea);
  857. X            blue  = (bForewardIntegral + bBackwardIntegral)
  858. X            / (ForewardKernelArea + BackwardKernelArea);
  859. X
  860. X            /* k is 0 for 2D case ... */
  861. X            RED  (INDEX_3D(This->OutputImage, i, j, k)) = CLAMP(red);
  862. X            GREEN(INDEX_3D(This->OutputImage, i, j, k)) = CLAMP(green);
  863. X            BLUE (INDEX_3D(This->OutputImage, i, j, k)) = CLAMP(blue);
  864. X        }
  865. X#        endif
  866. X#        if (PixelSize == 4 || PixelSize == 1)
  867. X        {
  868. X            double alpha;
  869. X
  870. X            alpha = (aForewardIntegral + aBackwardIntegral)
  871. X            / (ForewardKernelArea + BackwardKernelArea);
  872. X
  873. X            ALPHA(INDEX_3D(This->OutputImage, i, j, k)) = CLAMP(alpha);
  874. X        }
  875. X#        endif
  876. X
  877. X#        if (defined(DEBUG))
  878. X            if (ThisPixel)
  879. X            {
  880. X            int a, b;
  881. X
  882. X            fprintf(ps,  "stroke\n");
  883. X            fprintf(ps,  "} def\n");
  884. X            fprintf(ps,  "25 25 scale\n");
  885. X            fprintf(ps,  "0.01 setlinewidth\n");
  886. X            fprintf(ps,  "11 11 translate\n");
  887. X            fprintf(ps,  "verticals\nhorizontals\n");
  888. X            fprintf(ps,  "0.02 setlinewidth\n");
  889. X            fprintf(ps,  "0.5 -0.5 translate\n");
  890. X
  891. X            for (a = i - 10; a < i + 10; a++)
  892. X            {
  893. X                for (b = j - 10; b < j + 10; b++)
  894. X                {
  895. X                fprintf(ps,  "%f %f %d %d arrow\n",
  896. X                    INDEX_2D(This->NormalField, a, b)[1],
  897. X                    INDEX_2D(This->NormalField, a, b)[0],
  898. X                    a-i, b-j);
  899. X                }
  900. X            }
  901. X            fprintf(ps,  "streamlines\n");
  902. X            fprintf(ps,  "grestore\n");
  903. X            fprintf(ps,  "showpage\n");
  904. X            fclose(ps);
  905. X            }
  906. X#        endif
  907. X        }
  908. X    }
  909. X    }
  910. X}
  911. X
  912. X
  913. X/*
  914. X *    LIC_ChangeNumThreads ...
  915. X *    ========================
  916. X */
  917. X
  918. X
  919. Xvoid
  920. XLIC_ChangeNumThreads(LIC *This, int threads)
  921. X    /*
  922. X     * Change the number of parallel threads to use by LIC_ComputeImage.
  923. X     *
  924. X     * We put this here rather than in liblic/Modify.c since it only affects
  925. X     * LIC_ComputeImage and lowers the number of files that are affected by
  926. X     * the PARALLEL define ...
  927. X     */
  928. X{
  929. X    if (threads < 0)
  930. X    {
  931. X    threads = 1;
  932. X    if (This->ReportError)
  933. X        This->ReportError("LIC_ChangeNumThreads: threads must be greater"
  934. X                  " than or equal to 0 -- using 1");
  935. X    }
  936. X#   if (!defined(PARALLEL))
  937. X    if (threads != 1)
  938. X    {
  939. X        threads = 1;
  940. X        if (This->ReportError)
  941. X        This->ReportError("LIC_ChangeNumThreads: no parallel"
  942. X                  " processing support available"
  943. X                  " -- using threads=1");
  944. X    }
  945. X#   endif
  946. X    This->NumThreads = threads;
  947. X}
  948. END_OF_FILE
  949.   if test 11062 -ne `wc -c <'lic.1.3/liblic/ComputeImage.c'`; then
  950.     echo shar: \"'lic.1.3/liblic/ComputeImage.c'\" unpacked with wrong size!
  951.   fi
  952.   # end of 'lic.1.3/liblic/ComputeImage.c'
  953. fi
  954. if test -f 'lic.1.3/liblic/Convolve2D.c' -a "${1}" != "-c" ; then 
  955.   echo shar: Will not clobber existing file \"'lic.1.3/liblic/Convolve2D.c'\"
  956. else
  957.   echo shar: Extracting \"'lic.1.3/liblic/Convolve2D.c'\" \(9921 characters\)
  958.   sed "s/^X//" >'lic.1.3/liblic/Convolve2D.c' <<'END_OF_FILE'
  959. X/*
  960. X * $Header: /usr/local/src/lic/liblic/RCS/Convolve2D.c,v 1.8 1993/10/26 18:26:58 casey Exp $
  961. X */
  962. X
  963. X/*
  964. X * Copyright (c) 1993 The Regents of the University of California.
  965. X * All rights reserved.
  966. X *
  967. X * Redistribution and use in source and binary forms, with or without
  968. X * modification, are permitted provided that the following conditions
  969. X * are met:
  970. X * 1. Redistributions of source code must retain the above copyright
  971. X *    notice, this list of conditions and the following disclaimer.
  972. X * 2. Redistributions in binary form must reproduce the above copyright
  973. X *    notice, this list of conditions and the following disclaimer in the
  974. X *    documentation and/or other materials provided with the distribution.
  975. X * 3. All advertising materials mentioning features or use of this software
  976. X *    must display the following acknowledgement:
  977. X *    This product includes software developed by the University of
  978. X *    California, Lawrence Livermore National Laboratory and its
  979. X *    contributors.
  980. X * 4. Neither the name of the University nor the names of its contributors
  981. X *    may be used to endorse or promote products derived from this software
  982. X *    without specific prior written permission.
  983. X *
  984. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  985. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  986. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  987. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  988. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  989. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  990. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  991. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  992. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  993. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  994. X * SUCH DAMAGE.
  995. X */
  996. X
  997. X#ifndef lint
  998. X    static char rcsid[] = "$Header: /usr/local/src/lic/liblic/RCS/Convolve2D.c,v 1.8 1993/10/26 18:26:58 casey Exp $";
  999. X    static char copyright[] =
  1000. X    "Copyright (c) 1993 The Regents of the University of California.\n"
  1001. X    "All rights reserved.\n";
  1002. X#endif
  1003. X
  1004. X
  1005. X#include "liblic.h"
  1006. X
  1007. X
  1008. X/*
  1009. X *    Two-dimensional Line Integral Convolution.
  1010. X *    ============================================
  1011. X */
  1012. X
  1013. X
  1014. X#ifdef DEBUG
  1015. Xextern FILE *ps;
  1016. X#endif
  1017. X
  1018. X
  1019. Xvoid
  1020. XLIC_Convolve2D(LIC      *This,
  1021. X           int       i,
  1022. X           int       j,
  1023. X           int       direction,
  1024. X           double   *rIntegral,
  1025. X           double   *gIntegral,
  1026. X           double   *bIntegral,
  1027. X           double   *aIntegral,
  1028. X           double   *KernelArea)
  1029. X    /*
  1030. X     * Perform Line Integral Convolution on a two-dimensional vector field.
  1031. X     */
  1032. X{
  1033. X    REGISTER double L;            /* pos/neg length of kernel */
  1034. X    REGISTER double s, sp;        /* parametric distance along kernel */
  1035. X    double          wp;            /* integral corresponding to sp */
  1036. X    double          rSum, gSum,        /* integrated pixel values */
  1037. X            bSum, aSum;
  1038. X    int             speed;        /* integral table speed index */
  1039. X    double         *itab, is;        /* integral table and index scale */
  1040. X    int             LoopCount;        /* main loop iteration count */
  1041. X
  1042. X    sp = 0.0;
  1043. X
  1044. X    rSum = 0.0;
  1045. X    gSum = 0.0;
  1046. X    bSum = 0.0;
  1047. X    aSum = 0.0;
  1048. X
  1049. X    /*
  1050. X     * Establish length, L, of convolution and which ``speed'' version of the
  1051. X     * filter kernel to use.  The default L is the value set by the user.
  1052. X     * For VariableLength convolutions, L is scaled by the magnitude of the
  1053. X     * vector.  The default speed is to use the maximum ``speed'' version of
  1054. X     * the filter kernel.  For VariableSpeed convolutions, speed is scaled
  1055. X     * by the magnitude of the vector.
  1056. X     */
  1057. X    L = LIC_Length(This);
  1058. X    speed = LIC_INTEGRAL_SPEEDS - 1;
  1059. X    if (This->VariableLength || This->VariableSpeed)
  1060. X    {
  1061. X    REGISTER double fx, fy, norm;
  1062. X
  1063. X    fx = INDEX_2D(This->InputField, i, j)[0];
  1064. X    fy = INDEX_2D(This->InputField, i, j)[1];
  1065. X    norm = sqrt(fx*fx + fy*fy) / This->MaxLength;
  1066. X
  1067. X    if (This->VariableLength)
  1068. X        L *= norm;
  1069. X    if (This->VariableSpeed)
  1070. X        speed *= norm;
  1071. X    }
  1072. X
  1073. X    /*
  1074. X     * Establish filter kernel integral table to use based on direction and
  1075. X     * speed.  Also determine index scaling for values of s, 0 <= s <= L,
  1076. X     * into the table.  Note that the scaling is performed relative to L,
  1077. X     * not LIC_Length(This).  Scaling relative to L means that the filter
  1078. X     * is effectively dilated to match the convolution length even when
  1079. X     * performing VariableLength convolution.
  1080. X     */
  1081. X    if (This->NeedIntegration)
  1082. X    LIC_BuildIntegralTables(This);
  1083. X    if (direction == LIC_FOREWARD)
  1084. X    itab = &This->PosIntegralTable[speed][0];
  1085. X    else
  1086. X    itab = &This->NegIntegralTable[speed][0];
  1087. X    is = (double)(LIC_INTEGRAL_LEN - 1) / L;
  1088. X
  1089. X    LoopCount = 0;
  1090. X
  1091. X#   ifdef DEBUG
  1092. X    if (ThisPixel)
  1093. X        fprintf(ps, "0.0 0.0 moveto\n");
  1094. X#   endif
  1095. X
  1096. X    /*
  1097. X     * Only perform LIC if L is greater than zero.  Zero lengths
  1098. X     * can result from bad user input or magnitude based lengths.
  1099. X     */
  1100. X    if (L > 0)
  1101. X    {
  1102. X    REGISTER int    fi, fj;        /* vector field index */
  1103. X    REGISTER double x, y;        /* current cartesian location in the */
  1104. X                    /*   vector field */
  1105. X
  1106. X    fi = i;
  1107. X    fj = j;
  1108. X
  1109. X    x =  i + 0.5;
  1110. X    y = This->NormalField.Yres - j - 0.5;
  1111. X
  1112. X    wp = 0.0;
  1113. X
  1114. X    /* Loop until we reach the end of the line integral */
  1115. X    do
  1116. X    {
  1117. X        REGISTER double t;        /* distance to nearest cell edge */
  1118. X        REGISTER double fx, fy;    /* vector field values */
  1119. X
  1120. X        /*
  1121. X         * Grab the current cell vector.
  1122. X         */
  1123. X
  1124. X        /* Get the field value for this cell */
  1125. X        fx = INDEX_2D(This->NormalField, fi, fj)[0];
  1126. X        fy = INDEX_2D(This->NormalField, fi, fj)[1];
  1127. X
  1128. X        /* Bail out if the vector field goes to zero */
  1129. X        if (fx == 0.0 && fy == 0.0)
  1130. X        break;
  1131. X
  1132. X        if (direction == LIC_BACKWARD)
  1133. X        {
  1134. X        fx = -fx;
  1135. X        fy = -fy;
  1136. X        }
  1137. X
  1138. X        /*
  1139. X         * Compute the intersection with the next cell along the line
  1140. X         * of the vector field.
  1141. X         */
  1142. X        {
  1143. X        REGISTER double tt;
  1144. X#        define TT(v) \
  1145. X        { \
  1146. X            tt = (v); \
  1147. X            if (tt < t) \
  1148. X            t = tt; \
  1149. X        }
  1150. X
  1151. X        if (fx < -SIN_PARALLEL)
  1152. X            t = (FLOOR(x) - x) / fx;        /* left edge */
  1153. X        else if (fx > SIN_PARALLEL)
  1154. X            t = (CEIL(x) - x) / fx;        /* right edge */
  1155. X        else
  1156. X            t = HUGE_VAL;
  1157. X
  1158. X        if (fy < -SIN_PARALLEL)
  1159. X            TT((FLOOR(y) - y) / fy)        /* bottom edge */
  1160. X        else if (fy > SIN_PARALLEL)
  1161. X            TT((CEIL(y) - y) / fy)        /* top edge */
  1162. X
  1163. X#        undef TT
  1164. X        }
  1165. X
  1166. X        /* s and sp represent a monotonically moving convolution window */
  1167. X        s  = sp;
  1168. X        sp = sp + t;
  1169. X        t += ROUND_OFF;
  1170. X
  1171. X        /* Make sure we don't exceed the kernel width */
  1172. X        if (sp > L)
  1173. X        {
  1174. X        sp = L;
  1175. X        t  =  sp - s;
  1176. X        }
  1177. X
  1178. X#        ifdef DEBUG
  1179. X        if (ThisPixel)
  1180. X            fprintf(ps, "%f %f rlineto\n", fx*t, fy*t);
  1181. X#        endif
  1182. X
  1183. X        /*
  1184. X         * Grab the input pixel corresponding to the current cell and
  1185. X         * integrate its value over the convolution kernel from s to sp.
  1186. X         */
  1187. X        {
  1188. X#        if (PixelSize >= 3)
  1189. X            double rV, gV, bV;
  1190. X#        endif
  1191. X#        if (PixelSize == 4 || PixelSize == 1)
  1192. X            double aV;
  1193. X#        endif
  1194. X        {
  1195. X            REGISTER int ii, ij;
  1196. X
  1197. X            /* toriodally wrap input image coordinates */
  1198. X            ii = fi;
  1199. X            ij = fj;
  1200. X            WRAP(ii, This->InputImage.Xres);
  1201. X            WRAP(ij, This->InputImage.Yres);
  1202. X
  1203. X            /* Get the input image value for this cell */
  1204. X#            if (PixelSize >= 3)
  1205. X            rV = RED  (INDEX_2D(This->InputImage, ii, ij));
  1206. X            gV = GREEN(INDEX_2D(This->InputImage, ii, ij));
  1207. X            bV = BLUE (INDEX_2D(This->InputImage, ii, ij));
  1208. X#            endif
  1209. X#            if (PixelSize == 4 || PixelSize == 1)
  1210. X            aV = ALPHA(INDEX_2D(This->InputImage, ii, ij));
  1211. X#            endif
  1212. X        }
  1213. X
  1214. X        /* integrate over the convolution kernel between s and sp */
  1215. X        {
  1216. X            double          wt;
  1217. X            REGISTER double dw;
  1218. X
  1219. X            wt = itab[(int)(sp * is)];
  1220. X            dw = wt - wp;
  1221. X            wp = wt;
  1222. X
  1223. X#            if (PixelSize >= 3)
  1224. X            rSum  += (rV * dw);
  1225. X            gSum  += (gV * dw);
  1226. X            bSum  += (bV * dw);
  1227. X#            endif
  1228. X#            if (PixelSize == 4 || PixelSize == 1)
  1229. X            aSum  += (aV * dw);
  1230. X#            endif
  1231. X        }
  1232. X        }
  1233. X
  1234. X        /*
  1235. X         * March to the next cell.
  1236. X         */
  1237. X
  1238. X        LoopCount++;
  1239. X
  1240. X        /* Compute the cell we just stepped into */
  1241. X        x = x + fx*t;
  1242. X        y = y + fy*t;
  1243. X
  1244. X        /* break out of the loop if we step out of the field */
  1245. X        if (x < 0.0 || y < 0.0)
  1246. X            break;
  1247. X
  1248. X        fi = IFLOOR(x);
  1249. X        fj = This->NormalField.Yres - ICEIL(y);
  1250. X
  1251. X        /* Break out of the loop if we step out of the field */
  1252. X        if (   fi >= This->NormalField.Xres
  1253. X        || fj < 0)
  1254. X        break;
  1255. X
  1256. X        /*
  1257. X         * Loop until we reach the end or we think we've fallen into
  1258. X         * a singularity.
  1259. X         */
  1260. X    } while (sp < L && LoopCount <= 3*L);
  1261. X    }
  1262. X
  1263. X    if (LoopCount > 0 && L > 0)
  1264. X    {
  1265. X    *rIntegral = rSum;
  1266. X    *gIntegral = gSum;
  1267. X    *bIntegral = bSum;
  1268. X    *aIntegral = aSum;
  1269. X
  1270. X    /* Compute an integration normalization factor as function of sp */
  1271. X    *KernelArea = (This->NormalizationType == LIC_VARIABLE)
  1272. X        ? wp
  1273. X        : itab[LIC_INTEGRAL_LEN - 1];
  1274. X    }
  1275. X    else
  1276. X    {
  1277. X#    if (PixelSize >= 3)
  1278. X        *rIntegral = (This->DefaultRed == -1)
  1279. X        ? RED  (INDEX_2D(This->InputImage, i, j))
  1280. X        : (double)This->DefaultRed;
  1281. X        *gIntegral = (This->DefaultGreen == -1)
  1282. X        ? GREEN(INDEX_2D(This->InputImage, i, j))
  1283. X        : (double)This->DefaultGreen;
  1284. X        *bIntegral = (This->DefaultBlue == -1)
  1285. X        ? BLUE (INDEX_2D(This->InputImage, i, j))
  1286. X        : (double)This->DefaultBlue;
  1287. X#    else
  1288. X        *rIntegral = 0.0;
  1289. X        *gIntegral = 0.0;
  1290. X        *bIntegral = 0.0;
  1291. X#    endif
  1292. X#    if (PixelSize == 4 || PixelSize == 1)
  1293. X        *aIntegral = (This->DefaultAlpha == -1)
  1294. X        ? ALPHA(INDEX_2D(This->InputImage, i, j))
  1295. X        : (double)This->DefaultAlpha;
  1296. X#    else
  1297. X        *aIntegral = 0.0;
  1298. X#    endif
  1299. X
  1300. X    *KernelArea = 1;
  1301. X    }
  1302. X
  1303. X    /*
  1304. X     * Random bookkeeping for performance monitoring.
  1305. X     */
  1306. X#   if (defined(PARALLEL))
  1307. X    /*
  1308. X     * It isn't really worth the performance hit to do a critical
  1309. X     * section locking per pixel just to keep track of a few
  1310. X     * performance metrics that probably won't be used ...
  1311. X     */
  1312. X#   else
  1313. X    This->TotalLoopCount += LoopCount;
  1314. X    This->TotalLength    += sp;
  1315. X#   endif
  1316. X}
  1317. END_OF_FILE
  1318.   if test 9921 -ne `wc -c <'lic.1.3/liblic/Convolve2D.c'`; then
  1319.     echo shar: \"'lic.1.3/liblic/Convolve2D.c'\" unpacked with wrong size!
  1320.   fi
  1321.   # end of 'lic.1.3/liblic/Convolve2D.c'
  1322. fi
  1323. if test -f 'lic.1.3/liblic/Convolve3D.c' -a "${1}" != "-c" ; then 
  1324.   echo shar: Will not clobber existing file \"'lic.1.3/liblic/Convolve3D.c'\"
  1325. else
  1326.   echo shar: Extracting \"'lic.1.3/liblic/Convolve3D.c'\" \(10234 characters\)
  1327.   sed "s/^X//" >'lic.1.3/liblic/Convolve3D.c' <<'END_OF_FILE'
  1328. X/*
  1329. X * $Header: /usr/local/src/lic/liblic/RCS/Convolve3D.c,v 1.7 1993/10/26 18:26:58 casey Exp $
  1330. X */
  1331. X
  1332. X/*
  1333. X * Copyright (c) 1993 The Regents of the University of California.
  1334. X * All rights reserved.
  1335. X *
  1336. X * Redistribution and use in source and binary forms, with or without
  1337. X * modification, are permitted provided that the following conditions
  1338. X * are met:
  1339. X * 1. Redistributions of source code must retain the above copyright
  1340. X *    notice, this list of conditions and the following disclaimer.
  1341. X * 2. Redistributions in binary form must reproduce the above copyright
  1342. X *    notice, this list of conditions and the following disclaimer in the
  1343. X *    documentation and/or other materials provided with the distribution.
  1344. X * 3. All advertising materials mentioning features or use of this software
  1345. X *    must display the following acknowledgement:
  1346. X *    This product includes software developed by the University of
  1347. X *    California, Lawrence Livermore National Laboratory and its
  1348. X *    contributors.
  1349. X * 4. Neither the name of the University nor the names of its contributors
  1350. X *    may be used to endorse or promote products derived from this software
  1351. X *    without specific prior written permission.
  1352. X *
  1353. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  1354. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1355. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1356. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  1357. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  1358. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  1359. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  1360. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  1361. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  1362. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  1363. X * SUCH DAMAGE.
  1364. X */
  1365. X
  1366. X#ifndef lint
  1367. X    static char rcsid[] = "$Header: /usr/local/src/lic/liblic/RCS/Convolve3D.c,v 1.7 1993/10/26 18:26:58 casey Exp $";
  1368. X    static char copyright[] =
  1369. X    "Copyright (c) 1993 The Regents of the University of California.\n"
  1370. X    "All rights reserved.\n";
  1371. X#endif
  1372. X
  1373. X
  1374. X#include "liblic.h"
  1375. X
  1376. X
  1377. X/*
  1378. X *    Three-dimensional Line Integral Convolution.
  1379. X *    ============================================
  1380. X */
  1381. X
  1382. X
  1383. Xvoid
  1384. XLIC_Convolve3D(LIC      *This,
  1385. X           int       i,
  1386. X           int       j,
  1387. X           int       k,
  1388. X           int       direction,
  1389. X           double   *rIntegral,
  1390. X           double   *gIntegral,
  1391. X           double   *bIntegral,
  1392. X           double   *aIntegral,
  1393. X           double   *KernelArea)
  1394. X    /*
  1395. X     * Perform Line Integral Convolution on a three-dimensional vector field.
  1396. X     */
  1397. X{
  1398. X    REGISTER double L;            /* pos/neg length of kernel */
  1399. X    REGISTER double s, sp;        /* parametric distance along kernel */
  1400. X    double          wp;            /* integral corresponding to sp */
  1401. X    double          rSum, gSum,        /* integrated pixel values */
  1402. X            bSum, aSum;
  1403. X    int             speed;        /* integral table speed index */
  1404. X    double         *itab, is;        /* integral table and index scale */
  1405. X    int             LoopCount;        /* main loop iteration count */
  1406. X
  1407. X    sp = 0.0;
  1408. X
  1409. X    rSum = 0.0;
  1410. X    gSum = 0.0;
  1411. X    bSum = 0.0;
  1412. X    aSum = 0.0;
  1413. X
  1414. X    /*
  1415. X     * Establish length, L, of convolution and which ``speed'' version of the
  1416. X     * filter kernel to use.  The default L is the value set by the user.
  1417. X     * For VariableLength convolutions, L is scaled by the magnitude of the
  1418. X     * vector.  The default speed is to use the maximum ``speed'' version of
  1419. X     * the filter kernel.  For VariableSpeed convolutions, speed is scaled
  1420. X     * by the magnitude of the vector.
  1421. X     */
  1422. X    L = LIC_Length(This);
  1423. X    speed = LIC_INTEGRAL_SPEEDS - 1;
  1424. X    if (This->VariableLength || This->VariableSpeed)
  1425. X    {
  1426. X    REGISTER double fx, fy, fz, norm;
  1427. X
  1428. X    fx = INDEX_3D(This->InputField, i, j, k)[0];
  1429. X    fy = INDEX_3D(This->InputField, i, j, k)[1];
  1430. X    fz = INDEX_3D(This->InputField, i, j, k)[2];
  1431. X    norm = sqrt(fx*fx + fy*fy + fz*fz) / This->MaxLength;
  1432. X
  1433. X    if (This->VariableLength)
  1434. X        L *= norm;
  1435. X    if (This->VariableSpeed)
  1436. X        speed *= norm;
  1437. X    }
  1438. X
  1439. X    /*
  1440. X     * Establish filter kernel integral table to use based on direction and
  1441. X     * speed.  Also determine index scaling for values of s, 0 <= s <= L,
  1442. X     * into the table.  Note that the scaling is performed relative to L,
  1443. X     * not LIC_Length(This).  Scaling relative to L means that the filter
  1444. X     * is effectively dilated to match the convolution length even when
  1445. X     * performing VariableLength convolution.
  1446. X     */
  1447. X    if (This->NeedIntegration)
  1448. X    LIC_BuildIntegralTables(This);
  1449. X    if (direction == LIC_FOREWARD)
  1450. X    itab = &This->PosIntegralTable[speed][0];
  1451. X    else
  1452. X    itab = &This->NegIntegralTable[speed][0];
  1453. X    is = (double)(LIC_INTEGRAL_LEN - 1) / L;
  1454. X
  1455. X    LoopCount = 0;
  1456. X
  1457. X    /*
  1458. X     * Only perform LIC if L is greater than zero.  Zero lengths
  1459. X     * can result from bad user input or magnitude based lengths.
  1460. X     */
  1461. X    if (L > 0)
  1462. X    {
  1463. X    REGISTER int    fi, fj, fk;    /* vector field indices */
  1464. X    REGISTER double x, y, z;    /* current cartesian location in the */
  1465. X                    /*   vector field */
  1466. X
  1467. X    fi = i;
  1468. X    fj = j;
  1469. X    fk = k;
  1470. X
  1471. X    x = i + 0.5;
  1472. X    y = This->NormalField.Yres - j - 0.5;
  1473. X    z = k + 0.5;
  1474. X
  1475. X    wp = 0.0;
  1476. X
  1477. X    /* Loop until we reach the end of the line integral */
  1478. X    do
  1479. X    {
  1480. X        REGISTER double t;        /* distance to nearest cell face */
  1481. X        REGISTER double fx, fy, fz;    /* vector field values */
  1482. X
  1483. X        /*
  1484. X         * Grab the current cell vector.
  1485. X         */
  1486. X
  1487. X        /* Get the field value in This pixel */
  1488. X        fx = INDEX_3D(This->NormalField, fi, fj, fk)[0];
  1489. X        fy = INDEX_3D(This->NormalField, fi, fj, fk)[1];
  1490. X        fz = INDEX_3D(This->NormalField, fi, fj, fk)[2];
  1491. X
  1492. X        /* bail out if the vector field goes to zero */
  1493. X        if (fx == 0.0 && fy == 0.0 && fz == 0.0)
  1494. X        break;
  1495. X
  1496. X        if (direction == LIC_BACKWARD)
  1497. X        {
  1498. X        fx = -fx;
  1499. X        fy = -fy;
  1500. X        fz = -fz;
  1501. X        }
  1502. X
  1503. X        /*
  1504. X         * Compute the intersection with the next cell along the line
  1505. X         * of the vector field.
  1506. X         */
  1507. X        {
  1508. X        REGISTER double tt;
  1509. X#        define TT(v) \
  1510. X        { \
  1511. X            tt = (v); \
  1512. X            if (tt < t) \
  1513. X            t = tt; \
  1514. X        }
  1515. X
  1516. X        if (fx < -SIN_PARALLEL)
  1517. X            t = (FLOOR(x) - x) / fx;        /* left face */
  1518. X        else if (fx > SIN_PARALLEL)
  1519. X            t = (CEIL(x) - x) / fx;        /* right face */
  1520. X        else
  1521. X            t = HUGE_VAL;
  1522. X
  1523. X        if (fy < -SIN_PARALLEL)
  1524. X            TT((FLOOR(y) - y) / fy)        /* bottom face */
  1525. X        else if (fy > SIN_PARALLEL)
  1526. X            TT((CEIL(y) - y) / fy)        /* top face */
  1527. X
  1528. X        if (fz < -SIN_PARALLEL)
  1529. X            TT((FLOOR(z) - z) / fz)        /* front face */
  1530. X        else if (fz > SIN_PARALLEL)
  1531. X            TT((CEIL(z) - z) / fz)        /* back face */
  1532. X
  1533. X#        undef TT
  1534. X        }
  1535. X
  1536. X        /* s and sp represent a monotonically moving convolution window */
  1537. X        s  = sp;
  1538. X        sp = sp + t;
  1539. X        t += ROUND_OFF;
  1540. X
  1541. X        /* Make sure we don't exceed the kernel width */
  1542. X        if (sp > L)
  1543. X        {
  1544. X        sp = L;
  1545. X        t  =  sp - s;
  1546. X        }
  1547. X
  1548. X        /*
  1549. X         * Grab the input pixel corresponding to the current cell and
  1550. X         * integrate its value over the convolution kernel from s to sp.
  1551. X         */
  1552. X        {
  1553. X#        if (PixelSize >= 3)
  1554. X            double rV, gV, bV;
  1555. X#        endif
  1556. X#        if (PixelSize == 4 || PixelSize == 1)
  1557. X            double aV;
  1558. X#        endif
  1559. X        {
  1560. X            REGISTER int ii, ij, ik;
  1561. X
  1562. X            /* toriodally wrap input image coordinates */
  1563. X            ii = fi;
  1564. X            ij = fj;
  1565. X            ik = fk;
  1566. X            WRAP(ii, This->InputImage.Xres);
  1567. X            WRAP(ij, This->InputImage.Yres);
  1568. X            WRAP(ik, This->InputImage.Zres);
  1569. X
  1570. X            /* Get the input image value for this cell */
  1571. X#            if (PixelSize >= 3)
  1572. X            rV = RED  (INDEX_3D(This->InputImage, ii, ij, ik));
  1573. X            gV = GREEN(INDEX_3D(This->InputImage, ii, ij, ik));
  1574. X            bV = BLUE (INDEX_3D(This->InputImage, ii, ij, ik));
  1575. X#            endif
  1576. X#            if (PixelSize == 4 || PixelSize == 1)
  1577. X            aV = ALPHA(INDEX_3D(This->InputImage, ii, ij, ik));
  1578. X#            endif
  1579. X        }
  1580. X
  1581. X        /* integrate over the convolution kernel between s and sp */
  1582. X        {
  1583. X            double          wt;
  1584. X            REGISTER double dw;
  1585. X
  1586. X            wt = itab[(int)(sp * is)];
  1587. X            dw = wt - wp;
  1588. X            wp = wt;
  1589. X
  1590. X#            if (PixelSize >= 3)
  1591. X            rSum  += (rV * dw);
  1592. X            gSum  += (gV * dw);
  1593. X            bSum  += (bV * dw);
  1594. X#            endif
  1595. X#            if (PixelSize == 4 || PixelSize == 1)
  1596. X            aSum  += (aV * dw);
  1597. X#            endif
  1598. X        }
  1599. X        }
  1600. X
  1601. X        /*
  1602. X         * March to the next cell.
  1603. X         */
  1604. X
  1605. X        LoopCount++;
  1606. X
  1607. X        /* Compute the cell we just stepped into */
  1608. X        x = x + fx*t;
  1609. X        y = y + fy*t;
  1610. X        z = z + fz*t;
  1611. X
  1612. X        /* break out of the loop if we step out of the field */
  1613. X        if (x < 0.0 || y < 0.0 || z < 0.0)
  1614. X            break;
  1615. X
  1616. X        fi = IFLOOR(x);
  1617. X        fj = This->NormalField.Yres - ICEIL(y);
  1618. X        fk = IFLOOR(z);
  1619. X
  1620. X        /* break out of the loop if we step out of the field */
  1621. X        if (   fi >= This->NormalField.Xres
  1622. X        || fj < 0
  1623. X        || fk >= This->NormalField.Zres)
  1624. X        break;
  1625. X
  1626. X        /*
  1627. X         * Loop until we reach the end or we think we've fallen into
  1628. X         * a singularity.
  1629. X         */
  1630. X    } while (sp < L && LoopCount <= 3*L);
  1631. X    }
  1632. X
  1633. X    if (LoopCount > 0 && L > 0)
  1634. X    {
  1635. X    *rIntegral = rSum;
  1636. X    *gIntegral = gSum;
  1637. X    *bIntegral = bSum;
  1638. X    *aIntegral = aSum;
  1639. X
  1640. X    /* Compute an integration normalization factor as function of sp */
  1641. X    *KernelArea = (This->NormalizationType == LIC_VARIABLE)
  1642. X        ? wp
  1643. X        : itab[LIC_INTEGRAL_LEN - 1];
  1644. X    }
  1645. X    else
  1646. X    {
  1647. X#    if (PixelSize >= 3)
  1648. X        *rIntegral = (This->DefaultRed == -1)
  1649. X        ? RED  (INDEX_3D(This->InputImage, i, j, k))
  1650. X        : (double)This->DefaultRed;
  1651. X        *gIntegral = (This->DefaultGreen == -1)
  1652. X        ? GREEN(INDEX_3D(This->InputImage, i, j, k))
  1653. X        : (double)This->DefaultGreen;
  1654. X        *bIntegral = (This->DefaultBlue == -1)
  1655. X        ? BLUE (INDEX_3D(This->InputImage, i, j, k))
  1656. X        : (double)This->DefaultBlue;
  1657. X#    else
  1658. X        *rIntegral = 0.0;
  1659. X        *gIntegral = 0.0;
  1660. X        *bIntegral = 0.0;
  1661. X#    endif
  1662. X#    if (PixelSize == 4 || PixelSize == 1)
  1663. X        *aIntegral = (This->DefaultAlpha == -1)
  1664. X        ? ALPHA(INDEX_3D(This->InputImage, i, j, k))
  1665. X        : (double)This->DefaultAlpha;
  1666. X#    else
  1667. X        *aIntegral = 0.0;
  1668. X#    endif
  1669. X
  1670. X    *KernelArea = 1;
  1671. X    }
  1672. X
  1673. X    /*
  1674. X     * Random bookkeeping for performance monitoring.
  1675. X     */
  1676. X#   if (defined(PARALLEL))
  1677. X    /*
  1678. X     * It isn't really worth the performance hit to do a critical
  1679. X     * section locking per pixel just to keep track of a few
  1680. X     * performance metrics that probably won't be used ...
  1681. X     */
  1682. X#   else
  1683. X    This->TotalLoopCount += LoopCount;
  1684. X    This->TotalLength    += sp;
  1685. X#   endif
  1686. X}
  1687. END_OF_FILE
  1688.   if test 10234 -ne `wc -c <'lic.1.3/liblic/Convolve3D.c'`; then
  1689.     echo shar: \"'lic.1.3/liblic/Convolve3D.c'\" unpacked with wrong size!
  1690.   fi
  1691.   # end of 'lic.1.3/liblic/Convolve3D.c'
  1692. fi
  1693. if test -f 'lic.1.3/test/BasketWeave.c' -a "${1}" != "-c" ; then 
  1694.   echo shar: Will not clobber existing file \"'lic.1.3/test/BasketWeave.c'\"
  1695. else
  1696.   echo shar: Extracting \"'lic.1.3/test/BasketWeave.c'\" \(5417 characters\)
  1697.   sed "s/^X//" >'lic.1.3/test/BasketWeave.c' <<'END_OF_FILE'
  1698. X/*
  1699. X * $Header: /usr/local/src/lic/test/RCS/BasketWeave.c,v 1.6 1993/11/04 02:24:20 casey Exp $
  1700. X */
  1701. X
  1702. X/*
  1703. X * Copyright (c) 1993 The Regents of the University of California.
  1704. X * All rights reserved.
  1705. X *
  1706. X * Redistribution and use in source and binary forms, with or without
  1707. X * modification, are permitted provided that the following conditions
  1708. X * are met:
  1709. X * 1. Redistributions of source code must retain the above copyright
  1710. X *    notice, this list of conditions and the following disclaimer.
  1711. X * 2. Redistributions in binary form must reproduce the above copyright
  1712. X *    notice, this list of conditions and the following disclaimer in the
  1713. X *    documentation and/or other materials provided with the distribution.
  1714. X * 3. All advertising materials mentioning features or use of this software
  1715. X *    must display the following acknowledgement:
  1716. X *    This product includes software developed by the University of
  1717. X *    California, Lawrence Livermore National Laboratory and its
  1718. X *    contributors.
  1719. X * 4. Neither the name of the University nor the names of its contributors
  1720. X *    may be used to endorse or promote products derived from this software
  1721. X *    without specific prior written permission.
  1722. X *
  1723. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  1724. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1725. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1726. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  1727. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  1728. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  1729. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  1730. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  1731. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  1732. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  1733. X * SUCH DAMAGE.
  1734. X */
  1735. X
  1736. X#ifndef lint
  1737. X    static char rcsid[] = "$Header: /usr/local/src/lic/test/RCS/BasketWeave.c,v 1.6 1993/11/04 02:24:20 casey Exp $";
  1738. X    static char copyright[] =
  1739. X    "Copyright (c) 1993 The Regents of the University of California.\n"
  1740. X    "All rights reserved.\n";
  1741. X#endif
  1742. X
  1743. X
  1744. X#include <stdlib.h>
  1745. X#include <unistd.h>
  1746. X#include <errno.h>
  1747. X#include <fcntl.h>
  1748. X#include <string.h>
  1749. X#include <stdio.h>
  1750. X
  1751. X
  1752. X/*
  1753. X * Create a two-dimensional floating point vector field with horizontal and
  1754. X * vertical vectors alternating in a checkerboard fashion.  Each checker
  1755. X * will be surrounded by a border of zero vectors.  When rendered with
  1756. X * Line Integral Convolution and white noise as input, this will generate
  1757. X * a basket weave texture.
  1758. X */
  1759. X
  1760. X
  1761. X#ifdef NEED_STRERROR
  1762. X    /*
  1763. X     * strerror is supposed to be defined in <string.h> and supplied in the
  1764. X     * standard C library according to the ANSI C X3.159-1989 specification,
  1765. X     * but Sun OS 4.1.1 fails to define or supply it ...  Unfortunately the
  1766. X     * only way we can control this is with an externally supplied define.
  1767. X     */
  1768. X    extern int      errno;        /* system error number */
  1769. X    extern char     *sys_errlist[];    /* system error messages */
  1770. X    extern int      sys_nerr;        /* number of entries in sys_errlist */
  1771. X
  1772. X    char *
  1773. X    strerror(int err)
  1774. X    {
  1775. X    if (err < 0 || err >= sys_nerr) {
  1776. X        static char msg[100];
  1777. X
  1778. X        sprintf(msg, "system error number %d", err);
  1779. X        return(msg);
  1780. X    }
  1781. X    return(sys_errlist[err]);
  1782. X    }
  1783. X#endif
  1784. X
  1785. X
  1786. X#define HORIZONTAL   0            /* must == !VERTICAL */
  1787. X#define VERTICAL     1            /* must == !HORIZONTAL */
  1788. X
  1789. X
  1790. Xmain(int argc, char *argv[])
  1791. X{
  1792. X    char          *myname;
  1793. X    char          *file;
  1794. X    int            Xres, Yres, Xchecks, Ychecks;
  1795. X    int            Xchecker, Ychecker;
  1796. X    register int   Orientation;
  1797. X    float         *VectorField;
  1798. X    register float fx, fy;
  1799. X    register int   i, j;
  1800. X    int            fd, cc;
  1801. X
  1802. X    myname = argv[0];
  1803. X    if (argc != 6)
  1804. X    {
  1805. X    (void)fprintf(stderr, "usage: %s file-name x-res y-res x-checks"
  1806. X              " y-checks\n", myname);
  1807. X    exit(EXIT_FAILURE);
  1808. X    }
  1809. X
  1810. X    /* grab arguments */
  1811. X    file    = argv[1];
  1812. X    Xres    = atoi(argv[2]);
  1813. X    Yres    = atoi(argv[3]);
  1814. X    Xchecks = atoi(argv[4]);
  1815. X    Ychecks = atoi(argv[5]);
  1816. X
  1817. X    Xchecker = Xres / Xchecks;
  1818. X    Ychecker = Yres / Ychecks;
  1819. X
  1820. X    VectorField = (float *)malloc(sizeof(float)*Yres*Xres*2);
  1821. X    if (VectorField == NULL)
  1822. X    {
  1823. X    (void)fprintf(stderr, "%s: insufficient memory for creating the basket"
  1824. X              " weave\n", myname);
  1825. X    exit(EXIT_FAILURE);
  1826. X    }
  1827. X
  1828. X    Orientation = HORIZONTAL;
  1829. X    for (j = 0; j < Yres; j++)
  1830. X    {
  1831. X    if ((j % Ychecker) == 0)
  1832. X        Orientation = !Orientation;
  1833. X
  1834. X    for (i = 0; i < Xres; i++)
  1835. X    {
  1836. X        if ((i % Xchecker) == 0)
  1837. X        Orientation = !Orientation;
  1838. X
  1839. X        if ((i % Xchecker) == 0  || (j % Ychecker) == 0)
  1840. X        {
  1841. X        fx = 0;
  1842. X        fy = 0;
  1843. X        }
  1844. X        else
  1845. X        {
  1846. X        fx = Orientation;
  1847. X        fy = !Orientation;
  1848. X        }
  1849. X        VectorField[2*(j*Xres + i) + 0] = fx;
  1850. X        VectorField[2*(j*Xres + i) + 1] = fy;
  1851. X    }
  1852. X    }
  1853. X
  1854. X    fd = open(file, O_CREAT|O_TRUNC|O_WRONLY, 0666);
  1855. X    if (fd < 0)
  1856. X    {
  1857. X    (void)fprintf(stderr, "%s: unable to open %s: %s\n", myname, file,
  1858. X              strerror(errno));
  1859. X    exit(EXIT_FAILURE);
  1860. X    }
  1861. X
  1862. X    cc = write(fd, VectorField, 2*sizeof(float)*Xres*Yres);
  1863. X    if (cc != 2*sizeof(float)*Xres*Yres)
  1864. X    {
  1865. X    (void)fprintf(stderr, "%s: write returned short: %s\n", myname,
  1866. X              strerror(errno));
  1867. X    (void)close(fd);
  1868. X    exit(EXIT_FAILURE);
  1869. X    }
  1870. X    (void)close(fd);
  1871. X    exit(EXIT_SUCCESS);
  1872. X}
  1873. END_OF_FILE
  1874.   if test 5417 -ne `wc -c <'lic.1.3/test/BasketWeave.c'`; then
  1875.     echo shar: \"'lic.1.3/test/BasketWeave.c'\" unpacked with wrong size!
  1876.   fi
  1877.   # end of 'lic.1.3/test/BasketWeave.c'
  1878. fi
  1879. echo shar: End of archive 6 \(of 9\).
  1880. cp /dev/null ark6isdone
  1881. MISSING=""
  1882. for I in 1 2 3 4 5 6 7 8 9 ; do
  1883.     if test ! -f ark${I}isdone ; then
  1884.     MISSING="${MISSING} ${I}"
  1885.     fi
  1886. done
  1887. if test "${MISSING}" = "" ; then
  1888.     echo You have unpacked all 9 archives.
  1889.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1890. else
  1891.     echo You still must unpack the following archives:
  1892.     echo "        " ${MISSING}
  1893. fi
  1894. exit 0
  1895. exit 0 # Just in case...
  1896.