Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r628 - in branches/itanium2/Model: AmbientLights Backgrounds Cameras Materials Textures


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r628 - in branches/itanium2/Model: AmbientLights Backgrounds Cameras Materials Textures
  • Date: Fri, 14 Oct 2005 17:09:33 -0600 (MDT)

Author: bigler
Date: Fri Oct 14 17:09:32 2005
New Revision: 628

Modified:
   branches/itanium2/Model/AmbientLights/ArcAmbient.cc
   branches/itanium2/Model/Backgrounds/LinearBackground.cc
   branches/itanium2/Model/Cameras/PinholeCamera.cc
   branches/itanium2/Model/Materials/Lambertian.cc
   branches/itanium2/Model/Materials/LambertianAlt.cc
   branches/itanium2/Model/Materials/MetalMaterial.cc
   branches/itanium2/Model/Textures/CheckerTexture.cc
Log:

Try and use Real or ColorComponent where appropiate.  I found out that
if you do Color<float> * double it won't cast the double to a float to
do the multiplication.  Instead you will promote all the
multiplication operations to double and then store them back to
float.  We should be more careful about this when ColorComponent ==
float and Real == double, or vice versa.  I haven't tracked down all
the cases.  This will involve combing the code..... :-(

Model/AmbientLights/ArcAmbient.cc
Model/Backgrounds/LinearBackground.cc
Model/Cameras/PinholeCamera.cc
Model/Materials/Lambertian.cc
Model/Materials/LambertianAlt.cc
Model/Materials/MetalMaterial.cc
Model/Textures/CheckerTexture.cc


Modified: branches/itanium2/Model/AmbientLights/ArcAmbient.cc
==============================================================================
--- branches/itanium2/Model/AmbientLights/ArcAmbient.cc (original)
+++ branches/itanium2/Model/AmbientLights/ArcAmbient.cc Fri Oct 14 17:09:32 
2005
@@ -1,7 +1,10 @@
 
 #include <Model/AmbientLights/ArcAmbient.h>
 #include <Interface/RayPacket.h>
+#include <Core/Math/Trig.h>
+
 using namespace Manta;
+using namespace SCIRun;
 
 ArcAmbient::ArcAmbient(const Color& cup, const Color& cdown,
                       const Vector& up)
@@ -23,15 +26,19 @@
   rays.computeNormals(context);
   for(int i=0;i<rays.getSize();i++){
     RayPacket::Element& e = rays.get(i);
-    double cosine = Dot(e.normal, up);
-    double sine = sqrt(1-cosine*cosine);
-    double w0, w1;
+    Real cosine = Dot(e.normal, up);
+    Real sine = Sqrt(1-cosine*cosine);
+    // So we want to do the computation for w0 and w1 as type Real,
+    // because that is what all the other computation will be done,
+    // but we would like to cast that to type ColorComponent, because
+    // we will do operations on the color with this value.
+    ColorComponent w0, w1;
     if(cosine > 0){
-      w0= sine/2.;
-      w1= (1. -  w0);
+      w0= sine/2;
+      w1= (1 -  w0);
     } else {
-      w1= sine/2.;
-      w0= (1. -  w1);
+      w1= sine/2;
+      w0= (1 -  w1);
     }
     rays.get(i).ambientLight = cup*w1 + cdown*w0;
   }

Modified: branches/itanium2/Model/Backgrounds/LinearBackground.cc
==============================================================================
--- branches/itanium2/Model/Backgrounds/LinearBackground.cc     (original)
+++ branches/itanium2/Model/Backgrounds/LinearBackground.cc     Fri Oct 14 
17:09:32 2005
@@ -1,6 +1,7 @@
 
 #include <Model/Backgrounds/LinearBackground.h>
 #include <Interface/RayPacket.h>
+#include <MantaTypes.h>
 
 using namespace Manta;
 
@@ -24,7 +25,11 @@
   rays.normalizeDirections();
   for(int i=0;i<rays.getSize();i++){
     RayPacket::Element& e = rays.get(i);
-    double t = 0.5 * (1 + Dot(e.ray.direction(), up));
+    // So we want to do the computation for t as type Real, because
+    // that is what all the other computation will be done, but we
+    // would like to cast that to type ColorComponent, because we will
+    // do operations on the color with this value.
+    ColorComponent t = (Real)0.5 * (1 + Dot(e.ray.direction(), up));
     rays.setResult(i, cup*t+cdown*(1-t));
   }
 }

Modified: branches/itanium2/Model/Cameras/PinholeCamera.cc
==============================================================================
--- branches/itanium2/Model/Cameras/PinholeCamera.cc    (original)
+++ branches/itanium2/Model/Cameras/PinholeCamera.cc    Fri Oct 14 17:09:32 
2005
@@ -14,6 +14,7 @@
 using namespace Manta;
 using namespace std;
 using SCIRun::Clamp;
+using SCIRun::Abs;
 
 PinholeCamera::PinholeCamera(const vector<string>& args)
 {
@@ -97,7 +98,7 @@
     uvn[2][i] = n[i];
 
   v=Cross(direction, up);
-  if(v.length2() == 0.0){
+  if(v.length2() == 0){
     std::cerr << __FILE__ << " line: " << __LINE__ << " Ambiguous up 
direciton...\n";
   }
   v.normalize();
@@ -132,7 +133,7 @@
       Vector raydir(v*e.imageX+u*e.imageY+direction);
       raydir.normalize();
       e.ray.set(stereo_eye[e.whichEye], raydir);
-      e.importance = 1.0;
+      e.importance = 1;
     }
     rays.setFlag(RayPacket::NormalizedDirections);
 
@@ -144,7 +145,7 @@
       Vector raydir(v*e.imageX+u*e.imageY+direction);
 
       e.ray.set(stereo_eye[e.whichEye], raydir);
-      e.importance = 1.0;
+      e.importance = 1;
     }
 
 
@@ -155,9 +156,9 @@
 {
   Real fov_min = 0;
   Real fov_max = 180;
-  hfov = RtoD(2*atan(scale*tan(DtoR(hfov/2))));
+  hfov = RtoD(2*Atan(scale*Tan(DtoR(hfov/2))));
   hfov = Clamp(hfov, fov_min, fov_max);
-  vfov = RtoD(2*atan(scale*tan(DtoR(vfov/2))));
+  vfov = RtoD(2*Atan(scale*Tan(DtoR(vfov/2))));
   vfov = Clamp(vfov, fov_min, fov_max);
   setup();
 }
@@ -211,15 +212,15 @@
 
 void PinholeCamera::autoview(Real new_fov)
 {
-  BBox bbox(Point(-1,-1,0.2), Point(1,1,2.2));
+  BBox bbox(Point(-1,-1,(Real)0.2), Point(1,1,(Real)2.2));
   //  Real ratio = tan(DtoR(vfov/2))/tan(DtoR(hfov/2));
   hfov = new_fov;
-  vfov = RtoD(2*atan(tan(DtoR(hfov/2))));
+  vfov = RtoD(2*Atan(Tan(DtoR(hfov/2))));
   Vector diag(bbox.diagonal());
   Real w=diag.length();
   Vector lookdir(eye-lookat);
   lookdir.normalize();
-  Real scale = 1/(2*tan(DtoR(hfov/2)));
+  Real scale = 1/(2*Tan(DtoR(hfov/2)));
   Real length = w*scale;
   lookat = bbox.center();
   eye = lookat+lookdir*length;
@@ -243,10 +244,10 @@
   // and is visible to camera, else it is not
   // It is not a sufficient condition though, the x and y coordinates should 
lie within the
   // width and height of the image, so returned coordinates are in the 
normalized space [-1,1]
-  if(fabs(p2.z())<0.0001) // check for inconsistencies
+  if(Abs(p2.z()) < (Real)0.0001) // check for inconsistencies
     return Point(0,0,0);
   else
-    return Point((p2.x()*nearZ/p2.z())/(width/2.0),
-                 (p2.y()*nearZ/p2.z())/(height/2.0),
+    return Point((p2.x()*nearZ/p2.z())/(width/2),
+                 (p2.y()*nearZ/p2.z())/(height/2),
                   p2.z()/nearZ);
 }

Modified: branches/itanium2/Model/Materials/Lambertian.cc
==============================================================================
--- branches/itanium2/Model/Materials/Lambertian.cc     (original)
+++ branches/itanium2/Model/Materials/Lambertian.cc     Fri Oct 14 17:09:32 
2005
@@ -48,16 +48,16 @@
     int end = context.shadowAlgorithm->computeShadows(context, activeLights,
                                                      rays, start, 
shadowRays);
       for(int i=start;i<end;i++){
-       RayPacket::Element& e = rays.get(i);
-       Color totalLight(e.ambientLight);
-       for(int j=e.shadowBegin;j<e.shadowEnd;j++){
-         RayPacket::Element& s = shadowRays.get(j);
-         if(!s.hitInfo.wasHit()){
-           double cos_theta = Dot(s.ray.direction(), e.normal);
-           totalLight += s.light*cos_theta;
-         }
-       }
-       rays.setResult(i, colors[i]*totalLight);
+        RayPacket::Element& e = rays.get(i);
+        Color totalLight(e.ambientLight);
+        for(int j=e.shadowBegin;j<e.shadowEnd;j++){
+          RayPacket::Element& s = shadowRays.get(j);
+          if(!s.hitInfo.wasHit()){
+            ColorComponent cos_theta = Dot(s.ray.direction(), e.normal);
+            totalLight += s.light*cos_theta;
+          }
+        }
+        rays.setResult(i, colors[i]*totalLight);
       }
     start = end;
   } while(start < rays.getSize());

Modified: branches/itanium2/Model/Materials/LambertianAlt.cc
==============================================================================
--- branches/itanium2/Model/Materials/LambertianAlt.cc  (original)
+++ branches/itanium2/Model/Materials/LambertianAlt.cc  Fri Oct 14 17:09:32 
2005
@@ -38,9 +38,8 @@
                Color  &triangle_color = 
e.hitInfo.scratchpad<Kdtree::KDTree::ScratchPadInfo>().payload;
                Vector &normal         = 
e.hitInfo.scratchpad<Kdtree::KDTree::ScratchPadInfo>().normal;
 
-    Real scale = Abs(Dot( normal, e.ray.direction() ));
-    scale *= 0.75;
-    scale += 0.25;
+    ColorComponent scale = (ColorComponent)Dot( normal, e.ray.direction() );
+    scale = Abs(scale)*(ColorComponent)0.75 + (ColorComponent)0.25;
     
                Color result = (triangle_color * scale);
                

Modified: branches/itanium2/Model/Materials/MetalMaterial.cc
==============================================================================
--- branches/itanium2/Model/Materials/MetalMaterial.cc  (original)
+++ branches/itanium2/Model/Materials/MetalMaterial.cc  Fri Oct 14 17:09:32 
2005
@@ -64,7 +64,11 @@
        Real k = 1 - cosine;
        k*=k*k*k*k;
 
-        Color R = specular[i] * (1-k) + Color::white()*k;
+       // Doing the explicit cast to ColorComponent here, so that we
+       // don't do things like multiply all the colors by a double,
+       // thus promoting those expressions when we don't need to.
+       ColorComponent kc = (ColorComponent)k;
+       Color R = specular[i] * (1-kc) + Color::white()*kc;
 
         *e.color = R * (*r.color);
     }

Modified: branches/itanium2/Model/Textures/CheckerTexture.cc
==============================================================================
--- branches/itanium2/Model/Textures/CheckerTexture.cc  (original)
+++ branches/itanium2/Model/Textures/CheckerTexture.cc  Fri Oct 14 17:09:32 
2005
@@ -34,12 +34,12 @@
       rays.computeTextureCoordinates2(context);
     for(int i=0;i<rays.getSize();i++){
       RayPacket::Element& e = rays.get(i);
-      double vv1 = Dot(e.texCoords, v1);
-      double vv2 = Dot(e.texCoords, v2);
+      Real vv1 = Dot(e.texCoords, v1);
+      Real vv2 = Dot(e.texCoords, v2);
       if(vv1<0)
-       vv1=-vv1+1;
+        vv1=-vv1+1;
       if(vv2<0)
-       vv2=-vv2+1;
+        vv2=-vv2+1;
       int i1 = (int)vv1;
       int i2 = (int)vv2;
       int which = (i1+i2)%2;




  • [MANTA] r628 - in branches/itanium2/Model: AmbientLights Backgrounds Cameras Materials Textures, bigler, 10/14/2005

Archive powered by MHonArc 2.6.16.

Top of page