ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/RtraceSimulManager.cpp
(Generate patch)

Comparing ray/src/rt/RtraceSimulManager.cpp (file contents):
Revision 2.6 by greg, Tue Apr 30 23:16:23 2024 UTC vs.
Revision 2.12 by greg, Sat Aug 3 01:54:46 2024 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   */
11  
12   #include <unistd.h>
13 + #include <ctype.h>
14   #include "RtraceSimulManager.h"
15   #include "source.h"
16  
# Line 22 | Line 23 | RadSimulManager::LoadOctree(const char *octn)
23                          return true;
24                  Cleanup();
25          }
26 <        if (!octn)
26 >        if (!octn)              // don't support stdin octree
27                  return false;
28  
29 +        NewHeader(octn);        // load header if we can
30          ray_init((char *)octn);
31          return true;
32   }
33  
34 + // callback function for loading header
35 + static int
36 + add2header(char *str, void *p)
37 + {
38 +        if (isheadid(str))
39 +                return 0;
40 +        if (isformat(str))
41 +                return 0;
42 +
43 +        return (*(RadSimulManager *)p).AddHeader(str);
44 + }
45 +
46 + // Prepare header from previous input (or clear)
47 + // Normally called during octree load
48 + bool
49 + RadSimulManager::NewHeader(const char *fname)
50 + {
51 +        if (header) {
52 +                free(header); header = NULL;
53 +        }
54 +        if (!fname || fname[0] == '!')
55 +                return false;
56 +        FILE    *fp = fopen(fname, "rb");
57 +        bool    ok = (getheader(fp, add2header, this) >= 0);
58 +        fclose(fp);
59 +        return ok;
60 + }
61 +
62 + // Add a string to header (adds newline if none)
63 + bool
64 + RadSimulManager::AddHeader(const char *str)
65 + {
66 +        if (!str) return false;
67 +        int     len = strlen(str);
68 +        if (!len || str[0] == '\n') return false;
69 +        int     olen = 0;
70 +        if (header) {
71 +                olen = strlen(header);
72 +                header = (char *)realloc(header, olen+len+2);
73 +        } else
74 +                header = (char *)malloc(len+2);
75 +        if (!header) return false;
76 +        strcpy(header+olen, str);
77 +        if (str[len-1] != '\n') {
78 +                header[olen+len++] = '\n';
79 +                header[olen+len] = '\0';
80 +        }
81 +        return true;
82 + }
83 +
84 + // helper function to check for white-space and quotations
85 + static int
86 + check_special(const char *s)
87 + {
88 +        int     space_found = 0;
89 +
90 +        while (*s) {
91 +                if ((*s == '"') | (*s == '\''))
92 +                        return *s;      // quotes have priority
93 +                if (isspace(*s))
94 +                        space_found = *s;
95 +                s++;
96 +        }
97 +        return space_found;
98 + }
99 +
100 + // Append program line to header
101 + bool
102 + RadSimulManager::AddHeader(int ac, const char *av[])
103 + {
104 +        if ((ac <= 0) | !av) return false;
105 +        int     len = 0;
106 +        int     n;
107 +        for (n = 0; n < ac; n++) {
108 +                if (!av[n]) return false;
109 +                len += strlen(av[n]) + 3;
110 +        }
111 +        int     hlen = 0;
112 +        if (header) {                   // add to header
113 +                hlen = strlen(header);
114 +                header = (char *)realloc(header, hlen+len+1);
115 +        } else
116 +                header = (char *)malloc(len+1);
117 +        for (n = 0; n < ac; n++) {
118 +                int     c = check_special(av[n]);
119 +                if (c) {                // need to quote argument?
120 +                        if (c == '"') c = '\'';
121 +                        else c = '"';
122 +                        header[hlen++] = c;
123 +                        strcpy(header+hlen, av[n]);
124 +                        hlen += strlen(av[n]);
125 +                        header[hlen++] = c;
126 +                } else {
127 +                        strcpy(header+hlen, av[n]);
128 +                        hlen += strlen(av[n]);
129 +                }
130 +                header[hlen++] = ' ';
131 +        }
132 +        header[hlen-1] = '\n';          // terminate line
133 +        header[hlen] = '\0';
134 +        return true;
135 + }
136 +
137   // How many processors are available?
138   int
139   RadSimulManager::GetNCores()
# Line 99 | Line 204 | int
204   RadSimulManager::Cleanup(bool everything)
205   {
206          if (!ray_pnprocs)
102                ray_pdone(everything);
103        else
207                  ray_done(everything);
208 +        else
209 +                ray_pdone(everything);
210          return 0;
211   }
212  
# Line 117 | Line 222 | RadSimulManager::ThreadsAvailable() const
222   // Global pointer to simulation manager for trace call-back (only one)
223   static const RtraceSimulManager *       ourRTsimMan = NULL;
224  
225 < void    // static call-back
225 > // Call-back for trace output
226 > void
227   RtraceSimulManager::RTracer(RAY *r)
228   {
229          (*ourRTsimMan->traceCall)(r, ourRTsimMan->tcData);
# Line 216 | Line 322 | RtraceSimulManager::EnqueueBundle(const FVECT orig_dir
322                  return -1;
323  
324          if (castonly && !cookedCall)
325 <                error(CONSISTENCY, "EnqueueBundle() called in castonly mode without cookedCall");
325 >                error(INTERNAL, "EnqueueBundle() called in castonly mode without cookedCall");
326  
327          if (!UpdateMode())              // update rendering mode if requested
328                  return -1;
329  
330 +        if (rID0 && curFlags&RTdoFIFO)
331 +                error(INTERNAL, "Ray number assignment unsupported with FIFO");
332 +
333          while (n-- > 0) {               // queue each ray
334                  VCOPY(res.rorg, orig_direc[0]);
335                  VCOPY(res.rdir, orig_direc[1]);
336                  orig_direc += 2;
337                  rayorigin(&res, PRIMARY, NULL, NULL);
338 <                if (rID0) res.rno = rID0++;
230 <                else res.rno = ++lastRayID;
338 >                res.rno = rID0 ? (lastRayID = rID0++) : ++lastRayID;
339                  if (curFlags & RTimmIrrad)
340                          res.revf = rayirrad;
341                  else if (castonly)
342                          res.revf = raycast;
343                  double  d = normalize(res.rdir);
344                  bool    sendRes = (cookedCall != NULL);
345 <                if (d > 0) {            // direction vector is valid?
345 >                if (d > .0) {           // direction vector is valid?
346                          if (curFlags & RTlimDist)
347                                  res.rmax = d;
348 <                        if (curFlags & RTdoFIFO) {
349 <                                ray_fifo_in(&res);
348 >                        if (((curFlags&RTdoFIFO) != 0) & (ray_pnprocs > 0)) {
349 >                                if (ray_fifo_in(&res) < 0)
350 >                                        return -1;
351                                  sendRes = false;
352                          } else
353                                  sendRes &= ProcessRay(&res);
# Line 257 | Line 366 | RtraceSimulManager::EnqueueBundle(const FVECT orig_dir
366   int
367   RtraceSimulManager::FlushQueue()
368   {
369 <        if (curFlags & RTdoFIFO)
370 <                return ray_fifo_flush();
371 <
369 >        if (curFlags & RTdoFIFO) {
370 >                if (ray_pnprocs)
371 >                        return ray_fifo_flush();
372 >                return 0;
373 >        }
374          int     nsent = 0;
375          RAY     res;
376  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines