ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/cone.c
(Generate patch)

Comparing ray/src/common/cone.c (file contents):
Revision 1.4 by greg, Wed May 22 16:51:12 1991 UTC vs.
Revision 2.5 by greg, Sat Feb 22 02:07:22 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  cone.c - routines for making cones
6 + */
7 +
8 + /* ====================================================================
9 + * The Radiance Software License, Version 1.0
10   *
11 < *     2/12/86
11 > * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 > * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 > *
14 > * Redistribution and use in source and binary forms, with or without
15 > * modification, are permitted provided that the following conditions
16 > * are met:
17 > *
18 > * 1. Redistributions of source code must retain the above copyright
19 > *         notice, this list of conditions and the following disclaimer.
20 > *
21 > * 2. Redistributions in binary form must reproduce the above copyright
22 > *       notice, this list of conditions and the following disclaimer in
23 > *       the documentation and/or other materials provided with the
24 > *       distribution.
25 > *
26 > * 3. The end-user documentation included with the redistribution,
27 > *           if any, must include the following acknowledgment:
28 > *             "This product includes Radiance software
29 > *                 (http://radsite.lbl.gov/)
30 > *                 developed by the Lawrence Berkeley National Laboratory
31 > *               (http://www.lbl.gov/)."
32 > *       Alternately, this acknowledgment may appear in the software itself,
33 > *       if and wherever such third-party acknowledgments normally appear.
34 > *
35 > * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 > *       and "The Regents of the University of California" must
37 > *       not be used to endorse or promote products derived from this
38 > *       software without prior written permission. For written
39 > *       permission, please contact [email protected].
40 > *
41 > * 5. Products derived from this software may not be called "Radiance",
42 > *       nor may "Radiance" appear in their name, without prior written
43 > *       permission of Lawrence Berkeley National Laboratory.
44 > *
45 > * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 > * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 > * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 > * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 > * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 > * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 > * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 > * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 > * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 > * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 > * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 > * SUCH DAMAGE.
57 > * ====================================================================
58 > *
59 > * This software consists of voluntary contributions made by many
60 > * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 > * information on Lawrence Berkeley National Laboratory, please see
62 > * <http://www.lbl.gov/>.
63   */
64  
65   #include  "standard.h"
# Line 48 | Line 100 | getcone(o, getxf)                      /* get cone structure */
100   register OBJREC  *o;
101   int  getxf;
102   {
51        double  fabs(), sqrt();
103          int  sgn0, sgn1;
104          register CONE  *co;
105  
# Line 60 | Line 111 | int  getxf;
111  
112                  co->ca = o->oargs.farg;
113                                                  /* get radii */
114 <                if (o->otype == OBJ_CYLINDER || o->otype == OBJ_TUBE) {
114 >                if (o->otype == OBJ_CYLINDER | o->otype == OBJ_TUBE) {
115                          if (o->oargs.nfargs != 7)
116                                  goto argcerr;
117                          if (co->ca[6] < -FTINY) {
# Line 70 | Line 121 | int  getxf;
121                                  co->ca[6] = -co->ca[6];
122                          } else if (co->ca[6] <= FTINY)
123                                  goto raderr;
124 +                        co->p0 = 0; co->p1 = 3;
125                          co->r0 = co->r1 = 6;
126                  } else {
127                          if (o->oargs.nfargs != 8)
# Line 82 | Line 134 | int  getxf;
134                          else sgn1 = 0;
135                          if (sgn0+sgn1 == 0)
136                                  goto raderr;
137 <                        if (sgn0 < 0 || sgn1 < 0) {
137 >                        if (sgn0 < 0 | sgn1 < 0) {
138                                  objerror(o, o->otype==OBJ_RING?USER:WARNING,
139                                          "negative radii");
140                                  o->otype = o->otype == OBJ_CONE ?
# Line 90 | Line 142 | int  getxf;
142                          }
143                          co->ca[6] = co->ca[6]*sgn0;
144                          co->ca[7] = co->ca[7]*sgn1;
145 <                        co->r0 = 6;
94 <                        co->r1 = 7;
95 <                        if (fabs(co->ca[7] - co->ca[6]) <= FTINY) {
145 >                        if (co->ca[7] - co->ca[6] > FTINY) {
146                                  if (o->otype == OBJ_RING)
147 +                                        co->p0 = co->p1 = 0;
148 +                                else {
149 +                                        co->p0 = 0; co->p1 = 3;
150 +                                }
151 +                                co->r0 = 6; co->r1 = 7;
152 +                        } else if (co->ca[6] - co->ca[7] > FTINY) {
153 +                                if (o->otype == OBJ_RING)
154 +                                        co->p0 = co->p1 = 0;
155 +                                else {
156 +                                        co->p0 = 3; co->p1 = 0;
157 +                                }
158 +                                co->r0 = 7; co->r1 = 6;
159 +                        } else {
160 +                                if (o->otype == OBJ_RING)
161                                          goto raderr;
162                                  o->otype = o->otype == OBJ_CONE ?
163                                                  OBJ_CYLINDER : OBJ_TUBE;
164                                  o->oargs.nfargs = 7;
165 <                                co->r1 = 6;
165 >                                co->p0 = 0; co->p1 = 3;
166 >                                co->r0 = co->r1 = 6;
167                          }
168                  }
169                                                  /* get axis orientation */
170 <                co->p0 = 0;
106 <                if (o->otype == OBJ_RING) {
107 <                        if (co->ca[6] > co->ca[7]) {    /* make r0 smaller */
108 <                                co->r0 = 7;
109 <                                co->r1 = 6;
110 <                        }
111 <                        co->p1 = 0;
170 >                if (o->otype == OBJ_RING)
171                          VCOPY(co->ad, o->oargs.farg+3);
172 <                } else {
173 <                        co->p1 = 3;
174 <                        co->ad[0] = co->ca[3] - co->ca[0];
175 <                        co->ad[1] = co->ca[4] - co->ca[1];
117 <                        co->ad[2] = co->ca[5] - co->ca[2];
172 >                else {
173 >                        co->ad[0] = CO_P1(co)[0] - CO_P0(co)[0];
174 >                        co->ad[1] = CO_P1(co)[1] - CO_P0(co)[1];
175 >                        co->ad[2] = CO_P1(co)[2] - CO_P0(co)[2];
176                  }
177                  co->al = normalize(co->ad);
178                  if (co->al == 0.0)
# Line 122 | Line 180 | int  getxf;
180                                          /* compute axis and side lengths */
181                  if (o->otype == OBJ_RING) {
182                          co->al = 0.0;
183 <                        co->sl = co->ca[co->r1] - co->ca[co->r0];
184 <                } else if (o->otype == OBJ_CONE || o->otype == OBJ_CUP) {
183 >                        co->sl = CO_R1(co) - CO_R0(co);
184 >                } else if (o->otype == OBJ_CONE | o->otype == OBJ_CUP) {
185                          co->sl = co->ca[7] - co->ca[6];
186                          co->sl = sqrt(co->sl*co->sl + co->al*co->al);
187 <                } else { /* OBJ_CYLINDER || OBJ_TUBE */
187 >                } else { /* OBJ_CYLINDER or OBJ_TUBE */
188                          co->sl = co->al;
189                  }
190                  co->tm = NULL;
# Line 143 | Line 201 | raderr:
201   }
202  
203  
204 + void
205   freecone(o)                     /* free memory associated with cone */
206   OBJREC  *o;
207   {
208          register CONE  *co = (CONE *)o->os;
209  
210 +        if (co == NULL)
211 +                return;
212          if (co->tm != NULL)
213 <                free((char *)co->tm);
214 <        free(o->os);
213 >                free((void *)co->tm);
214 >        free((void *)co);
215          o->os = NULL;
216   }
217  
218  
219 + void
220   conexform(co)                   /* get cone transformation matrix */
221   register CONE  *co;
222   {
223 <        double  sqrt(), fabs();
162 <        double  m4[4][4];
223 >        MAT4  m4;
224          register double  d;
225          register int  i;
226  
227 <        co->tm = (double (*)[4])malloc(sizeof(m4));
227 >        co->tm = (FLOAT (*)[4])malloc(sizeof(MAT4));
228          if (co->tm == NULL)
229                  error(SYSTEM, "out of memory in conexform");
230  
# Line 172 | Line 233 | register CONE  *co;
233          if (co->r0 == co->r1)
234                  d = 0.0;
235          else
236 <                d = co->ca[co->r0] / (co->ca[co->r1] - co->ca[co->r0]);
236 >                d = CO_R0(co) / (CO_R1(co) - CO_R0(co));
237          for (i = 0; i < 3; i++)
238 <                co->tm[3][i] = d*(co->ca[co->p1+i] - co->ca[co->p0+i])
239 <                                - co->ca[co->p0+i];
238 >                co->tm[3][i] = d*(CO_P1(co)[i] - CO_P0(co)[i])
239 >                                - CO_P0(co)[i];
240          
241                                  /* rotate to positive z-axis */
242          setident4(m4);
# Line 199 | Line 260 | register CONE  *co;
260          multmat4(co->tm, co->tm, m4);
261  
262                                  /* scale z-axis */
263 <        setident4(m4);
264 <        if (co->p0 != co->p1 && co->r0 != co->r1) {
265 <                d = fabs(co->ca[co->r1] - co->ca[co->r0]);
266 <                m4[2][2] = d/co->al;
263 >        if (co->p0 != co->p1 & co->r0 != co->r1) {
264 >                setident4(m4);
265 >                m4[2][2] = (CO_R1(co) - CO_R0(co)) / co->al;
266 >                multmat4(co->tm, co->tm, m4);
267          }
207        multmat4(co->tm, co->tm, m4);
268   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines