home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / macraysh.sit / Code / Source / stats.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-28  |  3.4 KB  |  128 lines

  1. /*
  2.  * stats.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: stats.c,v 4.0 91/07/17 14:47:41 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    stats.c,v $
  19.  * Revision 4.0  91/07/17  14:47:41  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include <ctype.h>
  24. #include "rayshade.h"
  25. #include "options.h"
  26. #include "stats.h"
  27.  
  28. RSStats Stats;            /* Statistical information */
  29. Geom *GeomRep = NULL;    /* Linked list of object representatives */
  30.  
  31. static void PrintGeomStats();
  32.  
  33. void
  34. StatsPrint()
  35. {
  36.     extern void PrintMemoryStats();
  37.     unsigned long TotalRays;
  38.  
  39.     ShadowStats(&Stats.ShadowRays, &Stats.ShadowHits,
  40.             &Stats.CacheHits, &Stats.CacheMisses);
  41.     IntersectStats(&Stats.BVTests);
  42.     
  43.     TotalRays = Stats.EyeRays + Stats.ShadowRays + Stats.ReflectRays
  44.              + Stats.RefractRays;
  45.     Stats.ShadowHits += Stats.CacheHits;
  46.     Stats.HitRays += Stats.ShadowHits;
  47.     printf("Eye rays:\t\t\t%lu\n", Stats.EyeRays);
  48.     printf("Shadow rays:\t\t\t%lu\n",Stats.ShadowRays);
  49.     printf("Reflected rays:\t\t\t%lu\n",Stats.ReflectRays);
  50.     printf("Refracted rays:\t\t\t%lu\n",Stats.RefractRays);
  51.     printf("Total rays:\t\t\t%lu\n", TotalRays);
  52.     if (TotalRays != 0)
  53.         printf("Intersecting rays:\t\t%lu (%3.3f%%)\n",
  54.             Stats.HitRays,
  55.             100. * (float)Stats.HitRays / (float)TotalRays);
  56.     if (Stats.ShadowRays != 0) {
  57.         if (Options.cache)
  58.             printf("Shadow cache hits:\t\t%lu (%lu misses)\n",
  59.                 Stats.CacheHits, Stats.CacheMisses);
  60.         printf("Total shadow hits:\t\t%lu (%3.3f%%)\n",
  61.             Stats.ShadowHits, 100.*(float)Stats.ShadowHits /
  62.             (float)Stats.ShadowRays);
  63.     }
  64.     printf("Supersampled pixels:\t\t%lu\n",Stats.SuperSampled);
  65.     printf("B.V. intersection tests:\t%lu\n",Stats.BVTests);
  66.     PrintGeomStats();
  67.  
  68.     printf("Total CPU time (sec):\t\t");
  69.     printf("%2.2f (%2.2fu + %2.2fs)\n",Stats.Utime+Stats.Stime, Stats.Utime, Stats.Stime);
  70.     if (TotalRays != 0.)
  71.         printf("Seconds / ray:\t\t\t%4.4f\n",(Stats.Utime + Stats.Stime) / (Float)TotalRays);
  72.     if (Stats.HitRays != 0.)
  73.         printf("Seconds / intersecting ray:\t%4.4f\n",(Stats.Utime + Stats.Stime)/(Float)Stats.HitRays);
  74.     PrintMemoryStats();
  75. }
  76.  
  77. static void
  78. PrintGeomStats()
  79. {
  80.     Geom *otmp;
  81.     unsigned long tests, hits, totaltests, totalhits;
  82.     char *name;
  83.     extern void GeomStats();
  84.  
  85.     totaltests = totalhits = 0;
  86.  
  87.     for (otmp = GeomRep; otmp; otmp = otmp->next) {
  88.         GeomStats(otmp, &tests, &hits);
  89.         if (tests <= 0)
  90.             continue;
  91.         name = GeomName(otmp);
  92.         printf("%c%s intersection tests:\t%lu (%lu hit, %f%%)\n",
  93.                 toupper((int)name[0]), &name[1], tests, hits,
  94.                 100.*(float)hits/(float)tests);
  95.         if (!IsAggregate(otmp)) {
  96.             totaltests += tests;
  97.             totalhits += hits;
  98.         }
  99.     }
  100.     printf("Total prim. intersection tests:\t%lu",
  101.         totaltests);
  102.     if (totaltests == 0)
  103.         printf("\n");
  104.     else
  105.         printf(" (%lu hit, %f%%)\n", totalhits,
  106.             100.*(float)totalhits/(float)totaltests);
  107. }
  108.  
  109. void
  110. StatsAddRep(obj)
  111. Geom *obj;
  112. {
  113.     Geom *otmp;
  114.  
  115.     for (otmp = GeomRep; otmp; otmp = otmp->next) {
  116.         if (otmp->methods->stats == obj->methods->stats)
  117.             return;
  118.     }
  119.  
  120.     /*
  121.      * Stats method didn't match anything found so far.  Add
  122.      * a copy of obj to head of GeomRep list.
  123.      */
  124.     otmp = GeomCopy(obj);
  125.     otmp->next = GeomRep;
  126.     GeomRep = otmp;
  127. }
  128.