Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r511 - in branches/AFR/Engine: Control ImageTraversers ImageTraversers/AFR


Chronological Thread 
  • From: abhinav@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r511 - in branches/AFR/Engine: Control ImageTraversers ImageTraversers/AFR
  • Date: Sun, 28 Aug 2005 23:18:08 -0600 (MDT)

Author: abhinav
Date: Sun Aug 28 23:18:06 2005
New Revision: 511

Modified:
   branches/AFR/Engine/Control/AFRPipeline.cc
   branches/AFR/Engine/ImageTraversers/AFImageTraverser.cc
   branches/AFR/Engine/ImageTraversers/AFImageTraverser.h
   branches/AFR/Engine/ImageTraversers/AFR/kdtree.cc
   branches/AFR/Engine/ImageTraversers/AFR/kdtree.h
   branches/AFR/Engine/ImageTraversers/AFR/sample.h
   branches/AFR/Engine/ImageTraversers/AFR/stats.h
   branches/AFR/Engine/ImageTraversers/AFR/tiles.cc
   branches/AFR/Engine/ImageTraversers/AFR/tiles.h
Log:


fixed undersampling and occlusion. Yet to fix the temporalQ time for correct 
tile response.
added the display window for each thread. use 't' to swith between threads, 
'm' to switch display mode and 'b' or 'l' to brighten of darken the display.
set it to only update the tile and its parent the sample belongs to in the 
tree rather than updating entire tree bottom up. Seems to have no loss in 
correctness.

M    Engine/Control/AFRPipeline.cc
M    Engine/ImageTraversers/AFR/kdtree.cc
M    Engine/ImageTraversers/AFR/kdtree.h
M    Engine/ImageTraversers/AFR/stats.h
M    Engine/ImageTraversers/AFR/tiles.cc
M    Engine/ImageTraversers/AFR/tiles.h
M    Engine/ImageTraversers/AFR/sample.h
M    Engine/ImageTraversers/AFImageTraverser.cc
M    Engine/ImageTraversers/AFImageTraverser.h


Modified: branches/AFR/Engine/Control/AFRPipeline.cc
==============================================================================
--- branches/AFR/Engine/Control/AFRPipeline.cc  (original)
+++ branches/AFR/Engine/Control/AFRPipeline.cc  Sun Aug 28 23:18:06 2005
@@ -42,7 +42,8 @@
 #include <Interface/IdleMode.h>
 #include <Interface/Image.h>
 #include <Interface/ImageDisplay.h>
-#include <Interface/ImageTraverser.h>
+#include <Engine/ImageTraversers/AFImageTraverser.h>
+//#include <Interface/ImageTraverser.h>
 #include <Interface/Light.h>
 #include <Interface/LightSet.h>
 #include <Interface/LoadBalancer.h>
@@ -81,13 +82,13 @@
 using SCIRun::InvalidState;
 using SCIRun::InternalError;
 using SCIRun::Thread;
-using SCIRun::Time;
+//using SCIRun::Time;
 using SCIRun::split_string;
 
 #define RENDER_THREAD_STACKSIZE 1024*1024
 
 
-#include <Engine/ImageTraversers/AFImageTraverser.h>
+
 
 RTRTInterface* Manta::Afr::createAFRPipeline() {
        return new AFRPipeline();
@@ -287,13 +288,15 @@
   static bool firstFrame = true;
   static bool wait_for_transactions = false;
   
+
+  Real last_display_time = 0.0;
   Real last_samples = 0.0;
   
        //if(lateComerFlag){
   //  firstFrame = false;
   //  goto skipToRendering;
   //}
-       

        // Begin the outer rendering loop.
        // This updates renderer state and then 
   for(;;){
@@ -406,12 +409,21 @@
                        Image* image = channel->images[displayFrame];
                        
                        if(image && image->isValid()){
-        Real current_samples = currentImageTraverser->getSamplesDone();
-      
-                               DisplayContext myContext(proc, 
workersAnimAndImage);
-                               channel->display->displayImage(myContext, 
image, (current_samples-last_samples) );
+
+                         // Compute the current sampling rate.
+                         Real current_samples = 
currentImageTraverser->getSamplesDone();
+
+                         Real delta_samples = (current_samples-last_samples);
+                         Real delta_time = SCIRun::Time::currentSeconds() - 
last_display_time;
+
+                         Real sampling_rate = delta_samples / delta_time;
+
+                         currentImageTraverser->setSamplingRate( (unsigned 
int)sampling_rate );
+
+                         DisplayContext myContext(proc, workersAnimAndImage);
+                         channel->display->displayImage(myContext, image, 
(current_samples-last_samples) );
         
-        last_samples = current_samples;
+                         last_samples = current_samples;
                        }
       
       // std::cout << "Total samples: " << 
currentImageTraverser->getSamplesDone() << std::endl;
@@ -429,8 +441,8 @@
     /////////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////////
     int inner_iterations = 0;
-               for (double begin_time=Time::currentSeconds();
-         
(Time::currentSeconds()-begin_time)<currentImageTraverser->inner_loop_time;) {
+               for (double begin_time=SCIRun::Time::currentSeconds();
+         
(SCIRun::Time::currentSeconds()-begin_time)<currentImageTraverser->inner_loop_time;)
 {
                
       ++inner_iterations;
     
@@ -466,6 +478,12 @@
                        // Determine how to break out of inner loop. 
!!!!!!!!!!!!!!!!!!!!!!!!!!
                        
                } // End of inner loop.
+               if(proc==0)
+               {
+                 if (currentImageTraverser->debug_window) 
+                       // do the display stuff here
+                       currentImageTraverser->display_stats();
+               }
     
   } // End of outer loop.
 }

Modified: branches/AFR/Engine/ImageTraversers/AFImageTraverser.cc
==============================================================================
--- branches/AFR/Engine/ImageTraversers/AFImageTraverser.cc     (original)
+++ branches/AFR/Engine/ImageTraversers/AFImageTraverser.cc     Sun Aug 28 
23:18:06 2005
@@ -48,8 +48,12 @@
 AFImageTraverser::AFImageTraverser(const vector<string>& args) :
   myRandomNumber( 0 ),
   inner_loop_time( 0.06 ),
-  chunk_size( 256 )
+  chunk_size( 256 ),
+  debug_window( false ),
+  samplingrate( 400000 ),
+  displayClientId( 0 )
 {
+
   for (int i=0;i<args.size();++i) {
     if (args[i] == "-inner") {
       if (!getArg( i, args, inner_loop_time )) {
@@ -61,6 +65,14 @@
         throw IllegalArgument("-chunk <Int>", i, args);
       }
     }
+    if (args[i] == "-samplingrate") {
+      if (!getArg( i, args, samplingrate )) {
+        throw IllegalArgument("-samplingrate <Int>", i, args);
+      }
+    }
+    if (args[i] == "-debug") {
+      debug_window = true;
+    }
   }
 }
 
@@ -71,14 +83,226 @@
   // confirm!
 }
 
+
+void AFImageTraverser::createStatsWin()
+{
+  XHelper::Xlock.lock();
+  // Open the display and make sure it has opengl
+  dpy = XOpenDisplay(NULL);
+  if(!dpy) {
+    XHelper::Xlock.unlock();
+    throw InternalError("Error opening display", __FILE__, __LINE__);
+  }
+  int error, event;
+  if ( !glXQueryExtension( dpy, &error, &event) ) {
+    XCloseDisplay(dpy);
+    dpy=0;
+    XHelper::Xlock.unlock();
+    throw InternalError("GL extension NOT available!\n", __FILE__, __LINE__);
+  }
+  
+  int screen=DefaultScreen(dpy);
+    
+  // Form the criteria for the 
+  vector<int> attribList;
+  attribList.push_back(GLX_RGBA);
+  attribList.push_back(GLX_RED_SIZE); attribList.push_back(1);
+  attribList.push_back(GLX_GREEN_SIZE); attribList.push_back(1);
+  attribList.push_back(GLX_BLUE_SIZE); attribList.push_back(1);
+  attribList.push_back(GLX_ALPHA_SIZE); attribList.push_back(0);
+  attribList.push_back(GLX_DEPTH_SIZE); attribList.push_back(0);
+  attribList.push_back(GLX_DOUBLEBUFFER); // This must be the last one
+  attribList.push_back(None);
+
+  XVisualInfo* vi = glXChooseVisual(dpy, screen, &attribList[0]);
+  if(!vi){
+    // We failed to choose a visual.  Try again without the double-buffer 
flag
+    attribList.pop_back();
+    attribList.pop_back();
+    attribList.push_back(None);
+    vi = glXChooseVisual(dpy, screen, &attribList[0]);
+  }
+
+  Colormap cmap = XCreateColormap(dpy, RootWindow(dpy, screen),
+                                 vi->visual, AllocNone);
+
+  XSetWindowAttributes atts;
+  int flags=CWColormap|CWEventMask|CWBackPixmap|CWBorderPixel;
+  atts.background_pixmap = None;
+  atts.border_pixmap = None;
+  atts.border_pixel = 0;
+  atts.colormap=cmap;
+  
atts.event_mask=StructureNotifyMask|ExposureMask|KeyPressMask|KeyReleaseMask;
+  Window parent = RootWindow(dpy, screen);
+  statsWindow.window=XCreateWindow(dpy, parent, 600, 0, DISPLAY_WIDTH, 
DISPLAY_HEIGHT, 0, vi->depth,
+                   InputOutput, vi->visual, flags, &atts);
+
+  XTextProperty tp;
+  char* name = "AFR Debug";
+  XStringListToTextProperty(&name, 1, &tp);
+  XSizeHints sh;
+  sh.flags = USPosition|USSize;
+  
+  XSetWMProperties(dpy, statsWindow.window, &tp, &tp, 0, 0, &sh, 0, 0);
+  XMapWindow(dpy, statsWindow.window);
+
+  // Wait for the window to appear before proceeding
+  for(;;){
+    XEvent e;
+    XNextEvent(dpy, &e);
+    if(e.type == MapNotify)
+      break;
+  }
+
+  windowOpen = true;
+
+  gl_context = glXCreateContext(dpy, vi, NULL, True);
+  XFree(vi);
+
+  if(!glXMakeCurrent(dpy, statsWindow.window, gl_context)) {
+    XHelper::Xlock.unlock();
+    throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__);
+  }
+  
+  glViewport(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
+  glMatrixMode(GL_PROJECTION);
+  glLoadIdentity();
+  gluOrtho2D(0, DISPLAY_WIDTH, 0, DISPLAY_HEIGHT);
+  glMatrixMode(GL_MODELVIEW);
+  glLoadIdentity();
+  
+  glClearColor(.05, .1, .2, 0);
+  glClear(GL_COLOR_BUFFER_BIT);
+  
+  glXSwapBuffers(dpy, statsWindow.window);
+  glFinish();
+
+  // Get the fonts.  You need to call this with a current GL context.
+  fontInfo = XHelper::getX11Font(dpy);
+  if (!fontInfo) {
+    XHelper::Xlock.unlock();
+    throw InternalError("getX11Font failed!\n", __FILE__, __LINE__);
+  }
+  fontbase = XHelper::getGLFont(fontInfo);
+  if (fontbase == 0) {
+    XHelper::Xlock.unlock();
+    throw InternalError("getGLFont failed!\n", __FILE__, __LINE__);
+  }
+
+  if(!glXMakeCurrent(dpy, None, NULL)) {
+    XHelper::Xlock.unlock();
+    throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__);
+  }
+  
+  XHelper::Xlock.unlock();
+}
+
+void AFImageTraverser::display_stats() {
+  static int fcount = 0;
+     // Display textual information on the screen:
+    char text[200];
+    
+    switch(tmode)
+    {
+      case SOLID: sprintf(text, "Client: %d: Random Color Tiles (x %d)", 
displayClientId, (int)visScale); break;
+      case BOUNDARY: sprintf(text, "Client: %d: Tiles colored by size (x 
%d)", displayClientId, (int)visScale); break;
+      case DERIVATIVE: sprintf(text, "Client: %d: Derivative (x %d)", 
displayClientId, (int)visScale); break;
+      case OCCLUSION: sprintf(text, "Client: %d: Occlusion; (x %d)", 
displayClientId, (int)visScale); break;
+      case ABSOLUTE_GRADIENT: sprintf(text, "Client: %d: ABS Gradients (x 
%d)", displayClientId, (int)visScale); break;
+      case RELATIVE_GRADIENT: sprintf(text, "Client: %d: REL Gradients (x 
%d)", displayClientId, (int)visScale); break;
+      case SAMPLING_DENSITY: sprintf(text, "Client: %d: Sample density (x 
%d)", displayClientId, (int)visScale); break;
+      case UNDERSAMPLING: sprintf(text, "Client: %d: Undersampling (x %d)", 
displayClientId, (int)visScale); break;
+      case AVERAGE_AGE: sprintf(text, "Client: %d: Average Age (x %d)", 
displayClientId, (int)visScale); break;
+      case JITTERING: sprintf(text, "Client: %d: Jittering (x %d)", 
displayClientId, (int)visScale); break;
+      default: sprintf(text, "Client: %d: Random Color Tiles (x %d)", 
displayClientId, (int)visScale); break;
+    };
+  
+    if(!glXMakeCurrent(dpy, statsWindow.window, gl_context))
+      throw InternalError("AFImageTraverser::glXMakeCurrent failed!\n",
+                          __FILE__, __LINE__);
+    glClearColor(.05, .1, .2, 0);
+    glClear(GL_COLOR_BUFFER_BIT);
+    kdtree[displayClientId].displayTiles(tmode, 
chunkTimeStamp[displayClientId], visScale);
+    // Figure out how wide the string is
+    int width = XHelper::calc_width(fontInfo, text);
+    // Now we want to draw a gray box beneth the font using blending. :)
+    glEnable(GL_BLEND);
+    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
+    glColor4f(0.5,0.5,0.5,0.5);
+    glRecti(8,3-fontInfo->descent-2,25+width,fontInfo->ascent+3);
+    glDisable(GL_BLEND);
+    XHelper::printString(fontbase, 10, 3, text, RGBColor(1,1,1));
+    glXSwapBuffers(dpy, statsWindow.window);
+    glFinish();
+    // Suck up X events to keep opengl happy
+    while (XPending(dpy)) {
+      XEvent e;
+      XNextEvent(dpy, &e);
+      switch (e.type) {
+      case KeyPress:
+        {
+            unsigned long key = XKeycodeToKeysym(dpy, e.xkey.keycode, 0);
+            switch (key) {
+                case XK_m:
+                case XK_M:
+                    toggleTileDisplayMode();
+                    break;
+                case XK_b:
+                case XK_B:
+                    visScale++;
+                    break;
+                case XK_l:
+                case XK_L:
+                    if (visScale>0) visScale--;
+                    break;
+                               case XK_t:
+                               case XK_T:
+                                       displayClientId++;
+                                       if(displayClientId>=num_clients) 
+                                               displayClientId = 0;
+                                       break;
+            }
+        }
+      };
+    }
+  
+}
+
+void AFImageTraverser::toggleTileDisplayMode()
+{
+       switch(tmode)
+               {
+                       case SOLID: tmode = BOUNDARY; break;
+                       case BOUNDARY: tmode = DERIVATIVE; break;
+                       case DERIVATIVE: tmode = OCCLUSION; break;
+                       case OCCLUSION: tmode = ABSOLUTE_GRADIENT; break;
+                       case ABSOLUTE_GRADIENT: tmode=RELATIVE_GRADIENT; 
break;
+                       case RELATIVE_GRADIENT: tmode=SAMPLING_DENSITY; break;
+                       case SAMPLING_DENSITY: tmode = AVERAGE_AGE; break;
+                       case AVERAGE_AGE: tmode = UNDERSAMPLING; break;
+                       case UNDERSAMPLING: tmode = JITTERING; break;
+                       case JITTERING: tmode = SOLID; break;   
+                       default: tmode = SOLID; break;
+               };                      
+}
+
 void AFImageTraverser::setupBegin(SetupContext& context, int numChannels) {
 
   context.loadBalancer->setupBegin(context, numChannels);
+
+  if (debug_window) {
+    context.setMultipleGLWindows();
+    statsWindow.xres = DISPLAY_WIDTH; statsWindow.yres = DISPLAY_HEIGHT;
+    createStatsWin();
+  }
 }
 
 void AFImageTraverser::setupDisplayChannel(SetupContext& context) {
 
        // Specify that the rendering pipeline should use only one image 
buffer.
+  if (debug_window)
+    context.setMultipleGLWindows();
+
   context.constrainPipelineDepth(1,1); // single buffer mode is set here
        
   bool stereo; // get whether it is stereo, (shoot two rays for left
@@ -86,8 +310,7 @@
   int i;
   int xres,yres;
   num_clients = context.numProcs;
-  samplingrate = 400000; // let us for now assume something realistic
-  
+  cout << "samplingrate = " << samplingrate << endl;
   // Samples done.
 #ifdef __ia64__
   samples_done = (SamplesDone *)memalign( 128, 
sizeof(SamplesDone)*num_clients );
@@ -123,9 +346,8 @@
     
     initpass[i] = false;
     chunkTimeStamp[i] = 0.0;
-    kdtree[i].setAB(xres, yres, samplingrate);
+    kdtree[i].setAB(xres, yres);
     int numlevels = kdtree[i].init(xres, yres, samplingrate);  // initialize 
the tree
-    kdtree[i].setTileCut(numlevels/2, 0, samplingrate);        
   
     // set a mean number of tiles, i.e. cut at middle of tree
     kdtree[i].resetPseudoRandomSeed();
@@ -143,6 +365,7 @@
 void AFImageTraverser::renderCrossHair(const RenderContext& context, int 
myID, 
                                        Image *image, int xres, int yres, 
Sample *s)
 {
+
   float sx, sy;
   int size = 5;
   int flags = RayPacket::HaveImageCoordinates | RayPacket::ConstantEye;
@@ -160,7 +383,7 @@
   ss.set(TEMPORAL_SAMPLE, sx, sy, s->t, 
          s->worldCoord[0], s->worldCoord[1], s->worldCoord[2],
          s->c[0], s->c[1], s->c[2]);
-         
+  ss.tileindex = kdtree[context.proc].getTileforXY(sx, sy);
   float t = (float)chunkTimeStamp[context.proc];
   Color color[5];
 
@@ -210,8 +433,9 @@
     RGBColor tempcol = color[i].convertRGB();
     Point p = re.hitPosition;
     
-    ss.set( (CrosshairSampleLoc)i, sx, sy, t, p.x(), p.y(), 
p.z(),tempcol.r(), tempcol.g(), tempcol.b() ); 
-    image->set( (int)sx, (int)sy, color[i] );
+    ss.set( i, sx, sy, t, p.x(), p.y(), p.z(),tempcol.r(), tempcol.g(), 
tempcol.b() ); 
+    
+    image->set( (int)sx+offset[i][0], (int)sy+offset[i][1], color[i] );
   }
   
   //cout << "computing gradients" << endl;
@@ -257,9 +481,10 @@
     // Copy samples from the sampleQ into the fragment.
     for(int i=0;i<size;i++) {
       int cx, cy;
-      kdtree[myID].getRandomSample(cx, cy, myRandomNumber[myID]);
+      int tindex = kdtree[myID].getRandomSample(cx, cy, 
myRandomNumber[myID]);
       newSample[i].viewCoord[0] = cx;
       newSample[i].viewCoord[1] = cy;
+      newSample[i].tileindex = tindex;
       
       // normalized
       double px, py;
@@ -310,7 +535,8 @@
       image->set((int)(newSample[i].viewCoord[0]), 
(int)(newSample[i].viewCoord[1]), color[i]);
       
       // add sample to the corresponding kdtree
-      kdtree[myID].updateStatsAddSample(&newSample[i], 
(float)chunkTimeStamp[myID], samplingrate, 0.0, false);
+      kdtree[myID].updateStatsAddSample(&newSample[i], 
(float)chunkTimeStamp[myID], 0.0, false, samplingrate);
+      //kdtree[myID].ageStats(&newSample[i], (float)chunkTimeStamp[myID]);
       
       // add this sample into the temporalQ
       temporalQ[myID].qInsert(&newSample[i]);
@@ -330,17 +556,21 @@
   int xres, yres;
   image->getResolution(stereo, xres, yres);
   
-  chunkTimeStamp[context.proc] = 
(float)samples_done[context.proc].value/(float)samplingrate;//Time::currentSeconds();
+  chunkTimeStamp[context.proc] = (float)SCIRun::Time::currentSeconds();
+  //cout << "time (thread = " << context.proc << " ) is now " << 
chunkTimeStamp[context.proc] << endl; 
   // return during intialization here 
   if(!initpass[context.proc])
   {
-    if(samples_done[context.proc].value >= xres*yres)  
initpass[context.proc] = true;
+    if(samples_done[context.proc].value >= (xres*yres)) {
+      initpass[context.proc] = true;
+    }
   }
   else 
   {
     // adjust tiles based on current status
     adjustTiles(context.proc, (float)chunkTimeStamp[context.proc]);
   }
+  
 }
 
 
///////////////////////////////////////////////////////////////////////////////
@@ -359,6 +589,7 @@
   
   
   if(initpass[myID]) {
+
     // initialization is done so we can reproject one chunk worth
     int i;
     Sample *sp;
@@ -411,7 +642,7 @@
     {
       while(kdtree[id].number_of_tiles()>required_tiles)  
       {
-        kdtree[id].merge(kdtree[id].getminErrorParentTile(), currenttime, 
samplingrate); 
+        kdtree[id].merge(kdtree[id].getminErrorParentTile(), currenttime); 
       }
       while(kdtree[id].number_of_tiles()<required_tiles) 
       { 
@@ -431,7 +662,7 @@
     do
     {
       count++;
-      num_tiles_merged = 
kdtree[id].merge(kdtree[id].getminErrorParentTile(), currenttime, 
samplingrate); 
+      num_tiles_merged = 
kdtree[id].merge(kdtree[id].getminErrorParentTile(), currenttime); 
       for(i=0; i<num_tiles_merged && count<MAX_MERGE_SPLIT_LIMIT; i++)
       {
         count++;

Modified: branches/AFR/Engine/ImageTraversers/AFImageTraverser.h
==============================================================================
--- branches/AFR/Engine/ImageTraversers/AFImageTraverser.h      (original)
+++ branches/AFR/Engine/ImageTraversers/AFImageTraverser.h      Sun Aug 28 
23:18:06 2005
@@ -11,6 +11,10 @@
 #include <Engine/ImageTraversers/AFR/kdtree.h>
 #include <Engine/ImageTraversers/AFR/CQ.h>
 #include <Engine/ImageTraversers/AFR/sample.h>
+#include <Interface/XWindow.h>
+//#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#include <GL/glx.h>
 
 #ifdef __ia64__
 #include <malloc.h>
@@ -48,7 +52,13 @@
                        
                        // Update kdtree-cut.
                        void adjustTiles(int id, Timestamp currenttime);
-                       
+                       void createStatsWin();
+                       void display_stats();
+                       void toggleTileDisplayMode();
+                       inline int setSamplingRate(unsigned int srate)
+                        {
+                         samplingrate = (unsigned 
int)((float)srate/(float)num_clients);
+                       }
                        static ImageTraverser* create(const vector<string>& 
args);
                        
                private:
@@ -66,7 +76,21 @@
                        
                        // Random number generator array??
                        MT_RNG *myRandomNumber;
-                       
+                       // display stuff
+                       bool debug_window;
+                       XWindow statsWindow;
+            Display* dpy;
+            GLXContext gl_context;
+                       int displayClientId;
+                       int displayCount;
+                       // These contain stuff for font stuff.
+                       XFontStruct* fontInfo;
+                       GLuint fontbase;
+                       bool windowOpen;
+                       bool madeCurrent;
+                       TileDisplayMode tmode;
+                       float visScale;
+
                        // ??????????????
                        int num_clients;
                        int chunk_size;

Modified: branches/AFR/Engine/ImageTraversers/AFR/kdtree.cc
==============================================================================
--- branches/AFR/Engine/ImageTraversers/AFR/kdtree.cc   (original)
+++ branches/AFR/Engine/ImageTraversers/AFR/kdtree.cc   Sun Aug 28 23:18:06 
2005
@@ -8,7 +8,7 @@
 
 #include <Engine/ImageTraversers/AFR/kdtree.h>
 #include <assert.h>
-
+#define ONLY_NODE_UPDATE
 using namespace Manta;
 using namespace Manta::Afr;
 KDTree::KDTree()
@@ -18,19 +18,15 @@
 }
 
 // initialize a kdtree with width x height leaf nodes
-void KDTree::setAB(int width, int height, int samplingrate)
+void KDTree::setAB(int width, int height)
 {
        A = 1.0;
        // B is calculated such that the oldest sample after 2/3rd sec  
weight >=0.1
        //B = -1.0*log(0.1)/(2.0/3.0);
        B = -1.0*log(0.01)/(2.0/3.0);
-
-       //cout << "in kdtree init: sampling rate = " << samplingrate << endl;
-       //cout << "A = " << A << ", B = " << B << endl;
-       //getchar();
 }
 
-int KDTree::init(int width, int height, int samplingrate)
+int KDTree::init(int width, int height, unsigned int samplingrate)
 {
        myRandomNumber.seed_rng(1234); // just to begin give a simple seed
        numLevels = 0;
@@ -57,7 +53,7 @@
        {
                Tile::leafMapping[i] = (int*)malloc((height/2)*sizeof(int));
        }
-       buildtree(0, 1, 0, 0, width, height, samplingrate);
+       buildtree(0, 1, 0, 0, width, height);
        for(i=width*height/4; i<width*height/2; i++)
        {
                //printf("mapping: %d,%d = %d\n",tile[i].getLeft()/2, 
tile[i].getBottom()/2, i);
@@ -65,29 +61,37 @@
        }
        //exit(1);
        Tile::meanLevel = (numLevels/2)+1;
-       //cout << "meanLevel = " << Tile::meanLevel << endl;
+       Tile::max_tile_area = 1;
+       for(i=0; i<Tile::meanLevel; i++)
+               Tile::max_tile_area *= 2;
+
+       minTiles = Tile::max_tile_area;
+       maxTiles = minTiles*16;
+       setTileCut(Tile::meanLevel, 0, samplingrate);
+       
+       cout << "meanLevel = " << Tile::meanLevel << endl;
+       cout << "max_tile_area = " << Tile::max_tile_area << endl;
        return numLevels;
 }
 
-void KDTree::buildtree(int level, int index, int left, int bottom, int 
right, int top, 
-                                          int samplingrate)
+void KDTree::buildtree(int level, int index, int left, int bottom, int 
right, int top)
 {
-       tile[index].initialize(left, bottom, right, top, level, index, 
rootwidth, rootheight, samplingrate, A, B);
+       tile[index].initialize(left, bottom, right, top, level, index, 
rootwidth, rootheight, A, B);
        if(level==numLevels) return;
        if(level%2==0)  // even levels, split along x axis
        {
-               buildtree(level+1, index*2, left, bottom, left + 
(right-left)/2, top, samplingrate);    // build left subtree
-               buildtree(level+1, index*2+1, left + (right-left)/2, bottom, 
right, top, samplingrate); // build right subtree
+               buildtree(level+1, index*2, left, bottom, left + 
(right-left)/2, top);  // build left subtree
+               buildtree(level+1, index*2+1, left + (right-left)/2, bottom, 
right, top);       // build right subtree
        }
        else    // odd levels, split along y axis
        {
-               buildtree(level+1, index*2, left, bottom, right, bottom + 
(top-bottom)/2, samplingrate);        // build left subtree
-               buildtree(level+1, index*2+1, left, bottom + (top-bottom)/2, 
right, top, samplingrate); // build right subtree
+               buildtree(level+1, index*2, left, bottom, right, bottom + 
(top-bottom)/2);      // build left subtree
+               buildtree(level+1, index*2+1, left, bottom + (top-bottom)/2, 
right, top);       // build right subtree
        }
 }
 
 // split all tiles at the cut i.e. take the cut a level down
-bool KDTree::splitCut(Timestamp currenttime, int sampling_rate)
+bool KDTree::splitCut(Timestamp currenttime, unsigned int samplingrate)
 {
        int index = tile[0].getNextTile();
        int temp;
@@ -95,20 +99,20 @@
        while(index!=0)
        {
                temp = tile[index].getNextTile(); 
-               split(index, currenttime, sampling_rate); //split
+               split(index, currenttime, samplingrate); //split
                index = temp;
        }
        return true;
 }
 
 // merge all tiles at the cut i.e. take the cut a level up
-bool KDTree::mergeCut(Timestamp currenttime, int sampling_rate)
+bool KDTree::mergeCut(Timestamp currenttime)
 {
        int index = tile[0].getNextTile();
        // traverse the cut
        while(index!=0)
        {
-               if (merge(index, currenttime, sampling_rate))   // merge
+               if (merge(index, currenttime))  // merge
                        index = tile[index/2].getNextTile(); // get the next 
tile on updated cut
                else
                        index = tile[index].getNextTile();
@@ -118,7 +122,7 @@
 // set a level of tree as a set of valid tiles
 // this is useful for initializing with a set of 
 // uniform tiles
-bool KDTree::setTileCut(int level, Timestamp currenttime, int sampling_rate)
+bool KDTree::setTileCut(int level, Timestamp currenttime, unsigned int 
samplingrate)
 {
        
        // no need to recurse
@@ -153,7 +157,7 @@
        numTiles = 1;
        pseudostart = 1;
        for(i=0; i<level; i++)
-               splitCut(currenttime, sampling_rate);
+               splitCut(currenttime, samplingrate);
        
        return true;
 }
@@ -175,7 +179,7 @@
 }
 
 // split a tile in O(log n)
-bool KDTree::split(int index, Timestamp currenttime, int sampling_rate)
+bool KDTree::split(int index, Timestamp currenttime, unsigned int 
samplingrate)
 {
        //cout << "inside split" << endl;
        assert(index<totalNodes);
@@ -194,13 +198,19 @@
        // set the left child as valid tile
        tile[index*2].setValidTile();
        tile[index*2].setTimeLastDerivativeSet(currenttime);
-       tile[index*2].updateCommon(currenttime, tile, numTiles, 
sampling_rate);
+#ifdef ONLY_NODE_UPDATE
+       tile[index*2].copystats(tile[index]);
+#endif
+       tile[index*2].updateCommon(currenttime, tile, numTiles, samplingrate);
        // insert right child in the random list; we do it first because we 
do not want it to be valid yet
        insertRandom(index*2+1);
        // set the right child as valid tile
        tile[index*2+1].setValidTile();
        tile[index*2+1].setTimeLastDerivativeSet(currenttime);
-       tile[index*2+1].updateCommon(currenttime, tile, numTiles, 
sampling_rate);
+#ifdef ONLY_NODE_UPDATE
+       tile[index*2+1].copystats(tile[index]);
+#endif
+       tile[index*2+1].updateCommon(currenttime, tile, numTiles, 
samplingrate);
        numTiles+=2; // update valid tile counter
        
        // connect the two children
@@ -233,7 +243,7 @@
 // merge a tile, what this does is that
 // it sets the parent of the tile to be merged as a valid tile
 // dissolving the entire subtree of the parent
-int KDTree::merge(int index, Timestamp currenttime, int sampling_rate)
+int KDTree::merge(int index, Timestamp currenttime)
 {
        //<TODO> adding updating to tile stats and min/max variances
        // this may not be necessary for merges, if we maintain an updated 
thing
@@ -258,7 +268,6 @@
        // set parent as a valid tile
        tile[index].setValidTile();
        tile[index].setTimeLastDerivativeSet(currenttime);
-       //tile[index].updateCommon(currenttime, tile[1], numTiles, 
sampling_rate);
        // increment valid tile counter
        numTiles++;
        
@@ -434,7 +443,8 @@
 // update min/max up the tree in O(log n)
 void KDTree::updateMinMax(int index)
 {
-       while(index>1)
+       //while(tile[index].getLevel()>=Tile::meanLevel)
+       while(index>0)
        {
                index = index/2;        // get the parent
                tile[index].updateMinMax(tile);
@@ -451,75 +461,71 @@
        return retval;
 }
 
-void KDTree::updateStatsAddSampleSet(SampleSet *newsampleset, Timestamp 
currenttime, int sampling_rate)
+void KDTree::updateStatsAddSampleSet(SampleSet *newsampleset, Timestamp 
currenttime, unsigned int samplingrate)
 {
        /*
        do the following:
        check the queue in deepbuffer, if full delete the last element and 
delete its contribution from tile
        add the new element 
        */
+#ifndef ONLY_NODE_UPDATE
        int x, y;
-
-  // Determine which leaf this sample maps to.
+       
        x = (int)newsampleset->viewX;
        y = (int)newsampleset->viewY;
        int index = Tile::leafMapping[x/2][y/2];
        if(!tile[index].checkBounds(x,y)) return;
-       int vtileindex;
-
-  
//////////////////////////////////////////////////////////////////////////////
-  // Update stats up the kdtree to the root.
-       while(index>0)
+       int vtileindex=-1;
+       while(tile[index].getLevel()>0)//=Tile::meanLevel-1)
        {
-               tile[index].updateStatsAddSampleSet(newsampleset, 
currenttime, A, B, tile, sampling_rate, numTiles);
+               tile[index].updateStatsAddSampleSet(newsampleset, 
currenttime, A, B, tile, numTiles, samplingrate);
                if(tile[index].isValid()) vtileindex = index;
                index/=2;
        }
-
-  
-       updateMinMax(vtileindex);
-}
-
-void KDTree::ageStats(Sample *newsample, Timestamp currenttime, int 
sampling_rate)
-
-{
-       int x, y;
-       
-       x = (int)newsample->viewCoord[0];
-       y = (int)newsample->viewCoord[1];
-       int index = Tile::leafMapping[x/2][y/2];
-       if(!tile[index].checkBounds(x,y)) return;
-       int vtileindex;
-       while(index>0)
-       {
-               tile[index].ageStats(currenttime, A, B, tile, sampling_rate, 
numTiles);
-               if(tile[index].isValid()) vtileindex = index;
-               index/=2;
+       if(vtileindex==-1)
+       { 
+          cout << "error: split/merge do not constrain tile sizes 
appropriately" << endl;
        }
-       updateMinMax(vtileindex);
+       else
+         updateMinMax(vtileindex);
+#else
+       tile[newsampleset->tileindex].updateStatsAddSampleSet(newsampleset, 
currenttime, A, B, tile, numTiles, samplingrate);
+       tile[newsampleset->tileindex/2].updateStatsAddSampleSet(newsampleset, 
currenttime, A, B, tile, numTiles, samplingrate);
+       updateMinMax(newsampleset->tileindex);
+#endif
 }
 
-void KDTree::updateStatsAddSample(Sample *newsample, Timestamp currenttime, 
int sampling_rate, 
-                                  float tgrad, bool occ)
+void KDTree::updateStatsAddSample(Sample *newsample, Timestamp currenttime, 
+                                  float tgrad, bool occ, unsigned int 
samplingrate)
 {
        int x, y;
-       
+#ifndef ONLY_NODE_UPDATE
        x = (int)newsample->viewCoord[0];
        y = (int)newsample->viewCoord[1];
        int index = Tile::leafMapping[x/2][y/2];
        if(!tile[index].checkBounds(x,y)) return;
-       int vtileindex;
-       while(index>0)
+       int vtileindex=-1;
+       while(tile[index].getLevel()>0)//=Tile::meanLevel-1)
        {
-               tile[index].updateStatsAddSample(newsample, currenttime, A, 
B, tile, sampling_rate, 
-                                                numTiles, tgrad, occ);
+               tile[index].updateStatsAddSample(newsample, currenttime, A, 
B, tile, 
+                                                numTiles, tgrad, occ, 
samplingrate);
                if(tile[index].isValid()) vtileindex = index;
                index/=2;
        }
-       updateMinMax(vtileindex);
+       if(vtileindex==-1)
+       { 
+          cout << "error: split/merge do not constrain tile sizes 
appropriately" << endl;
+       }
+       else
+         updateMinMax(vtileindex);
+#else
+       tile[newsample->tileindex].updateStatsAddSample(newsample, 
currenttime, A, B, tile, numTiles, tgrad, occ, samplingrate);
+       tile[newsample->tileindex/2].updateStatsAddSample(newsample, 
currenttime, A, B, tile, numTiles, tgrad, occ, samplingrate);
+       updateMinMax(newsample->tileindex);
+#endif
 }
 
-int KDTree::printTiles_to_file(FILE *fp, Timestamp currenttime, float 
samplingrate)
+int KDTree::printTiles_to_file(FILE *fp, Timestamp currenttime)
 {
        int tile_to_print;
        int count = 0;
@@ -528,38 +534,12 @@
        {
                count++;
 
-               tile[tile_to_print].print_to_file(fp, tile, numTiles, 
currenttime, samplingrate);
+               tile[tile_to_print].print_to_file(fp, tile, numTiles, 
currenttime);
                tile_to_print = tile[tile_to_print].getNextTile();
        }
        return count;
 }
 
-void KDTree::bruteforceMinMax(int &min, int &max, float &min_error, float 
&max_error, Timestamp currenttime, int samplingrate)
-{
-       int currenttile;
-       currenttile = tile[0].getNextTile();
-       min = currenttile/2;
-       max = currenttile;
-       max_error = -9999.0;
-       min_error = 9999.0;
-       while(currenttile!=0)
-       {
-               if(tile[currenttile].getLevel()>Tile::meanLevel && min_error 
> tile[currenttile/2].getTotalError())
-               {
-                       tile[currenttile/2].setTotalError(tile, currenttime, 
numTiles, samplingrate);
-                       min_error = tile[currenttile/2].getTotalError();
-                       min = currenttile/2;
-               }
-               if(tile[currenttile].getLevel()<numLevels-1 && max_error < 
tile[currenttile].getTotalError())
-               {
-                       tile[currenttile].setTotalError(tile, currenttime, 
numTiles, samplingrate);
-                       max_error = tile[currenttile].getTotalError();
-                       max = currenttile;
-               }
-               currenttile = tile[currenttile].getNextTile();
-       }
-}
-
 int KDTree::getTileforXY(float x, float y)
 {
        int index = 1;
@@ -595,7 +575,7 @@
 }
 
 
-void KDTree::displayTiles(TileDisplayMode displaymode, int sampling_rate, 
Timestamp currenttime, float visScale)
+void KDTree::displayTiles(TileDisplayMode displaymode, Timestamp 
currenttime, float visScale)
 {
        if(displaymode==INDIVIDUAL_SAMPLES) return;
        int tile_to_display, start;
@@ -607,7 +587,7 @@
                if(tile_to_display!=0) 
                {
                        count++;
-                       tile[tile_to_display].display(displaymode, numTiles, 
tile, sampling_rate, currenttime, A, B, visScale);
+                       tile[tile_to_display].display(displaymode, numTiles, 
tile, currenttime, A, B, visScale);
                }
                tile_to_display = tile[tile_to_display].getNextRandomTile();
        }

Modified: branches/AFR/Engine/ImageTraversers/AFR/kdtree.h
==============================================================================
--- branches/AFR/Engine/ImageTraversers/AFR/kdtree.h    (original)
+++ branches/AFR/Engine/ImageTraversers/AFR/kdtree.h    Sun Aug 28 23:18:06 
2005
@@ -34,7 +34,7 @@
   class KDTree
   {
     private:
-      int totalNodes, numLevels, numTiles, pseudostart;
+      int totalNodes, numLevels, numTiles, pseudostart, minTiles, maxTiles;
       int rootwidth, rootheight;
       int **samples, **reprojSamples;
       Tile *tile;
@@ -43,20 +43,17 @@
   
     public:
       KDTree();
-      void setAB(int width, int height, int samplingrate);
-      int init(int width, int height, int samplingrate);       // initialize 
the tree for max width x height tiles
-      void buildtree(int level, int index, int left, int bottom, int right, 
int top, 
-               int samplingrate); // recusive routine to build tree
-      bool setTileCut(int level, Timestamp currenttime, 
-                        int sampling_rate);    // set a particular level as 
cut in the tree
+      void setAB(int width, int height);
+      int init(int width, int height, unsigned int samplingrate);      // 
initialize the tree for max width x height tiles
+      void buildtree(int level, int index, int left, int bottom, int right, 
int top);  
+      bool setTileCut(int level, Timestamp currenttime, unsigned int 
samplingrate);
       bool isLeftChild(int index);     // is the tile labeled index left 
child of its parent
       bool isRightChild(int index);    // is the tile labeled index right 
child of its parent
-      bool split(int index, Timestamp currenttime, int sampling_rate); // 
split the tile labeled index to its children
-      int merge(int index, Timestamp currenttime, int sampling_rate);  // 
merge the tile labeled index and all its siblings to the parent tile
-      bool splitCut(Timestamp currenttime, int sampling_rate); // split all 
tiles; move the cut a level down
-      bool mergeCut(Timestamp currenttime, int sampling_rate); // merge all 
tiles; move the cut a level up
+      bool split(int index, Timestamp currenttime, unsigned int 
samplingrate); // split the tile labeled index to its children
+      int merge(int index, Timestamp currenttime);     // merge the tile 
labeled index and all its siblings to the parent tile
+      bool splitCut(Timestamp currenttime, unsigned int samplingrate); // 
split all tiles; move the cut a level down
+      bool mergeCut(Timestamp currenttime);    // merge all tiles; move the 
cut a level up
       int getmaxErrorTile();   // get the max var tile
-      void bruteforceMinMax(int &min, int &max, float &min_error, float 
&max_error, Timestamp currenttime, int samplingrate); // seach for min/max by 
brute force linear search; included for debugging
       int getminErrorParentTile();     // get the min var tile
       inline double getmaxError() { return tile[1].maxError(); }       // 
get the maximum variance value
       inline double getminError() { return tile[1].minError(); } // get the 
minimum variance value
@@ -70,7 +67,6 @@
       void insertRandom(int index);    // insert tile in the random list
       void deleteRandom(int index);    // delete tile from the random list
       void updateMinMax(int index);    // update the min/max when some tile 
changes
-      void ageStats(Sample *newsample, Timestamp currenttime, int 
sampling_rate);
       int getPseudoRandomTile();       // get a pseudo random tile
       void resetPseudoRandomSeed() { pseudostart = getRandomTile(); } // 
update seed for pseudo random tile
       inline float xGrad() { return tile[1].xGrad(); }
@@ -84,7 +80,7 @@
       inline bool isValidTile(int index) { return tile[index].isValid(); }
       int getTileforXY(float x, float y);
       inline double getTotalError(int index) { return  
tile[index].getTotalError(); }
-      int printTiles_to_file(FILE *fp, Timestamp currenttime, float 
samplingrate);
+      int printTiles_to_file(FILE *fp, Timestamp currenttime);
       inline bool isInside(int index, float x, float y)
       {
         return tile[index].isInside(x,y);
@@ -100,9 +96,9 @@
         return tile[index].getOcclusionMeasure(tile, numTiles);
       }
       int isUsampledOrOccluded(float x, float y, Timestamp currenttime);
-      void updateStatsAddSampleSet(SampleSet *newsampleset, Timestamp 
currenttime, int sampling_rate);
-                 void updateStatsAddSample(Sample *newsample, Timestamp 
currenttime, int sampling_rate, float tgrad, bool occ);
-                 void displayTiles(TileDisplayMode displaymode, int 
sampling_rate, Timestamp currenttime, float visScale);     
+      void updateStatsAddSampleSet(SampleSet *newsampleset, Timestamp 
currenttime, unsigned int samplingrate);
+      void updateStatsAddSample(Sample *newsample, Timestamp currenttime, 
float tgrad, bool occ, unsigned int samplingrate);
+      void displayTiles(TileDisplayMode displaymode, Timestamp currenttime, 
float visScale);   
   };
  } // end namespace Afr
 } // emd namespace Manta

Modified: branches/AFR/Engine/ImageTraversers/AFR/sample.h
==============================================================================
--- branches/AFR/Engine/ImageTraversers/AFR/sample.h    (original)
+++ branches/AFR/Engine/ImageTraversers/AFR/sample.h    Sun Aug 28 23:18:06 
2005
@@ -49,6 +49,7 @@
                        
       /** time at which the sample was generated (in milliseconds) */
                        float worldCoord[3]; // the 3d location of the sample
+                       int tileindex; // index of tile to which the sample 
belongs
                        Timestamp t; // timestamp of the sample.        
                                 
                        Sample()
@@ -102,6 +103,7 @@
                                        worldCoord[i] = value.worldCoord[i];
                                }
                                t = value.t;
+                               tileindex = value.tileindex;
                        }
                
                        void print_to_file(FILE *fp)
@@ -170,13 +172,12 @@
                class SampleSet {
                        public:
                                
-        // Sample left, right, bottom, top, center, temporal;
         Sample sample[6];
         
                                float tgrad, xgrad, ygrad;
                                Timestamp timestamp;
                                float viewX, viewY, viewZ; 
-                                               
+                               int tileindex;                  
         // Constructor.
                                SampleSet() { reset(); }
                                
@@ -192,7 +193,7 @@
           }
                                }
                                
-                               void set(CrosshairSampleLoc sloc, const float 
x, const float y, const Timestamp tstamp, 
+                               void set(int sloc, const float x, const float 
y, const Timestamp tstamp, 
                                                                         
const float wx, const float wy, const float wz,
                                                                         
const float r, const float g, const float b)
                                {
@@ -232,8 +233,8 @@
                                                xgrad = 
(sample[CENTER_SAMPLE].getRGBDistance(sample[LEFT_SAMPLE].c) + 
sample[CENTER_SAMPLE].getRGBDistance(sample[RIGHT_SAMPLE].c))/2.0f;
                                        }
                                        
-                                       
if(fabsf(sample[CENTER_SAMPLE].viewCoord[0]-sample[TOP_SAMPLE].viewCoord[1])>0.001
 && 
-             
fabsf(sample[CENTER_SAMPLE].viewCoord[0]-sample[BOTTOM_SAMPLE].viewCoord[1])>0.001
 )
+                                       
if(fabsf(sample[CENTER_SAMPLE].viewCoord[1]-sample[TOP_SAMPLE].viewCoord[1])>0.001
 && 
+             
fabsf(sample[CENTER_SAMPLE].viewCoord[1]-sample[BOTTOM_SAMPLE].viewCoord[1])>0.001
 )
                                        {
                                                //ygrad = 
fabsf(ci-bi)/fabsf(center.viewCoord[1]-top.viewCoord[1]) 
                                                //       + 
fabsf(ci-ti)/fabsf(center.viewCoord[1]-bottom.viewCoord[1]);
@@ -256,7 +257,7 @@
                                        else
                                        {
                                                //tgrad = fabsf(ci-tmpi);
-                                               tgrad = 
sample[CENTER_SAMPLE].getRGBDistance(sample[BOTTOM_SAMPLE].c);
+                                               tgrad = 
sample[CENTER_SAMPLE].getRGBDistance(sample[TEMPORAL_SAMPLE].c);
                                        }                       
                                        
                                        //<TODO> set occlusion status here
@@ -285,7 +286,15 @@
                                
                                float      getIntensity(CrosshairSampleLoc 
sloc) { return sample[sloc].intensity(); }
                                Timestamp  
getSampleTimeStamp(CrosshairSampleLoc sloc) { return sample[sloc].t; } 
-                               bool isOccluded() { return false; }
+                               inline bool isOccluded() { 
+                                 const static float epsilon = 0.001;
+                                 
if(fabsf(sample[TEMPORAL_SAMPLE].worldCoord[0]-sample[CENTER_SAMPLE].worldCoord[0])>
 epsilon 
+                                    || 
fabsf(sample[TEMPORAL_SAMPLE].worldCoord[1]-sample[CENTER_SAMPLE].worldCoord[1])>
 epsilon 
+                                    || 
fabsf(sample[TEMPORAL_SAMPLE].worldCoord[2]-sample[CENTER_SAMPLE].worldCoord[2])>
 epsilon )
+                                    return true;
+                                  else
+                                    return false;
+                               }
         
                };
        } // end namespace Afr

Modified: branches/AFR/Engine/ImageTraversers/AFR/stats.h
==============================================================================
--- branches/AFR/Engine/ImageTraversers/AFR/stats.h     (original)
+++ branches/AFR/Engine/ImageTraversers/AFR/stats.h     Sun Aug 28 23:18:06 
2005
@@ -7,7 +7,6 @@
   {
     private:
       Stats(const Stats&);
-      Stats& operator=(const Stats&);
       int n;
       float sigma_wi, sigma_xi_wi, sigma_xi_wi_sqr;
     public:

Modified: branches/AFR/Engine/ImageTraversers/AFR/tiles.cc
==============================================================================
--- branches/AFR/Engine/ImageTraversers/AFR/tiles.cc    (original)
+++ branches/AFR/Engine/ImageTraversers/AFR/tiles.cc    Sun Aug 28 23:18:06 
2005
@@ -46,7 +46,7 @@
 void Tile::initialize(int l, int b, int r, int t, 
                            int currlevel, int address, 
                       int width, int height, 
-                      int samplingrate, float A, float B)
+                      float A, float B)
 {
        left = l;
        right = r;
@@ -122,37 +122,35 @@
        }
 }
 
-void Tile::setError(Tile *tree, int nTiles, int sampling_rate, Timestamp 
currenttime)
+void Tile::setError(Tile *tree, int nTiles, Timestamp currenttime, unsigned 
int samplingrate)
 {
        // now we add some monitoring factor so that variance 0 does not mean 
a single tile
        
        float verror = intensity.getVariance()+AMBIENT_ERROR;
-       float uerror = (currenttime - sum_tstamps.getMean())*0.33/0.1651225 - 
1.0;
+       unsigned int numPixels = (tree[1].right - tree[1].left)*(tree[1].top 
- tree[1].bottom);
+       float meanGlobalAge = 0.5*(float)numPixels/(float)samplingrate;
+       float uerror = (currenttime - 
sum_tstamps.getMean())*0.33/meanGlobalAge - 1.0;
        if(uerror>1.0) uerror = 1.0;
        if(uerror<0.0) uerror = 0.0;
-  
-  // 
        float oerror = getOcclusionMeasure(tree, nTiles);
-       
-  
-  if(oerror>1.0) oerror = 1.0;
-       error = (0.25*(uerror) + 2.0*(verror) +0.25*(oerror))*num_pixels ;
+       if(oerror>1.0) oerror = 1.0;
+       error = (verror+0.25*uerror)*num_pixels;//(0.25*(uerror) + 
2.0*(verror) +0.25*(oerror))*num_pixels ;
 }
 
-void Tile::setTotalError(Tile *tree, Timestamp currenttime, int nTiles, int 
sampling_rate)
+void Tile::setTotalError(Tile *tree, Timestamp currenttime, int nTiles, 
unsigned int samplingrate)
 {
        // update the mean & variance
-       setError(tree, nTiles, sampling_rate, currenttime);
+       setError(tree, nTiles, currenttime, samplingrate);
        // well what about the derivative
        setDerivative(currenttime);
        total_error = KOEFF*(error) + (1.0-KOEFF)*derivative;
        time_last_updated = currenttime;
 }
 
-void Tile::updateCommon(Timestamp currenttime, Tile *tree, int nTiles, int 
sampling_rate)
+void Tile::updateCommon(Timestamp currenttime, Tile *tree, int nTiles, 
unsigned int samplingrate)
 {
        // set the total error
-       setTotalError(tree, currenttime, nTiles, sampling_rate);
+       setTotalError(tree, currenttime, nTiles, samplingrate);
        if(num_pixels<=MIN_VALID_TILE_AREA) min_size_violation = true;
        else min_size_violation = false;
        max_error = min_error = total_error; // check if we need variance here
@@ -160,48 +158,19 @@
        if(min_size_violation) max_error = 0;
 }
 
-void Tile::setStatsFromChildren(Timestamp currenttime, float A, float B, 
-                          Tile *tree, int sampling_rate, int nTiles, bool 
validreached)
-{
-       Tile *leftChild, *rightChild;
-       leftChild = &tree[index*2];
-       rightChild = &tree[index*2+1];
-       float ratioL = getWeight(A, B, (currenttime - 
leftChild->time_last_updated));
-       float ratioR = getWeight(A, B, (currenttime - 
rightChild->time_last_updated));
-
-       intensity.sum(leftChild->intensity, rightChild->intensity, ratioL, 
ratioR);
-       xGradient.sum(leftChild->xGradient, rightChild->xGradient, ratioL, 
ratioR);
-       yGradient.sum(leftChild->yGradient, rightChild->yGradient, ratioL, 
ratioR);
-       tGradient.sum(leftChild->tGradient, rightChild->tGradient, ratioL, 
ratioR);
-       sum_tstamps.sum(leftChild->sum_tstamps, rightChild->sum_tstamps, 
ratioL, ratioR);
-       occlusion.sum(leftChild->occlusion, rightChild->occlusion, ratioL, 
ratioR);
-       if(isValid()) updateCommon(currenttime, tree, nTiles, sampling_rate);
-       else setTotalError(tree, currenttime, nTiles, sampling_rate);
-       
-       if(validreached) updateMinMax(tree);
-}
-
-
-
 void Tile::updateStatsAddSampleSet(SampleSet *newsampleset, Timestamp 
currenttime, float A, float B, 
-                          Tile *tree, int sampling_rate, int nTiles)
+                          Tile *tree, int nTiles, unsigned int samplingrate)
 {
        float wt_new = 1.0;
        float ratio = getWeight(A, B, (currenttime - time_last_updated));
        float temptime = newsampleset->getSampleTimeStamp(TEMPORAL_SAMPLE);
        float stime = newsampleset->timestamp;
-  
-  
        intensity.addElement(newsampleset->getIntensity(CENTER_SAMPLE), 
wt_new, ratio);
        intensity.addElement(newsampleset->getIntensity(TOP_SAMPLE), wt_new, 
1.0);
        intensity.addElement(newsampleset->getIntensity(BOTTOM_SAMPLE), 
wt_new, 1.0);
        intensity.addElement(newsampleset->getIntensity(LEFT_SAMPLE), wt_new, 
1.0);
        intensity.addElement(newsampleset->getIntensity(RIGHT_SAMPLE), 
wt_new, 1.0);
        
-  intensity.addElement(newsampleset->getIntensity(TEMPORAL_SAMPLE), 
-                       getWeight(A, B, (currenttime - temptime)), 
-                            1.0);
-       
        xGradient.addElement(newsampleset->xgrad, wt_new, ratio);
        yGradient.addElement(newsampleset->ygrad, wt_new, ratio);
        
@@ -210,42 +179,22 @@
        sum_tstamps.addElement(stime, wt_new, 1.0);
        sum_tstamps.addElement(stime, wt_new, 1.0);
        sum_tstamps.addElement(stime, wt_new, 1.0);
-       sum_tstamps.addElement(temptime, wt_new, 1.0);
        
        float occ = (newsampleset->isOccluded())? 1.0 : 0.0;
-       //occlusion.addElement(occ, wt_new, getWeight(A, 4.0*B, (currenttime 
- time_last_updated)));
        float denom = 1.0 - occlusion.getMean();
        if(denom<0.1) denom = 0.1;
        
        float tgradRatio = ratio;//getWeight(A, B/denom, (currenttime - 
time_last_updated));
        tGradient.addElement(newsampleset->tgrad, wt_new, tgradRatio);
        occlusion.addElement(occ, wt_new, tgradRatio);
-       updateCommon(currenttime, tree, nTiles, sampling_rate);
-}
-
-void Tile::ageStats(Timestamp currenttime, float A, float B, 
-                          Tile *tree, int sampling_rate, int nTiles)
-{
-       float ratio = getWeight(A, B, (currenttime - time_last_updated));
-       intensity.uniformDecrease(ratio);
-       sum_tstamps.uniformDecrease(ratio);
-       xGradient.uniformDecrease(ratio);
-       yGradient.uniformDecrease(ratio);
-       //occlusion.uniformDecrease(getWeight(A, 4.0*B, (currenttime - 
time_last_updated)));
-       float denom = 1.0 - occlusion.getMean();
-       if(denom<0.1) denom = 0.1;
-       float tgradRatio = getWeight(A, B/denom, (currenttime - 
time_last_updated));
-       tGradient.uniformDecrease(tgradRatio);
-       occlusion.uniformDecrease(tgradRatio);
-       updateCommon(currenttime, tree, nTiles, sampling_rate);
+       updateCommon(currenttime, tree, nTiles, samplingrate);
 }
 
 void Tile::updateStatsAddSample(Sample *newsample, Timestamp currenttime, 
float A, float B, 
-                          Tile *tree, int sampling_rate, int nTiles, float 
tgrad, bool occ)
+                          Tile *tree, int nTiles, float tgrad, bool occ, 
unsigned int samplingrate)
 {
        float wt_new = 1.0;
        float ratio = getWeight(A, B, (currenttime - time_last_updated));
-       //intensity.uniformDecrease(ratio);
        intensity.addElement(newsample->intensity(), wt_new, ratio);
        sum_tstamps.uniformDecrease(ratio);
        xGradient.uniformDecrease(ratio);
@@ -255,13 +204,11 @@
        if(denom<0.1) denom = 0.1;
        float tgradRatio = ratio;//getWeight(A, B/denom, (currenttime - 
time_last_updated));
        tGradient.addElement(tgrad, wt_new, tgradRatio);
-       
-  if(occ) 
+       if(occ) 
                occlusion.addElement(1.0, wt_new, tgradRatio);
        else
                occlusion.addElement(0.0, wt_new, tgradRatio);
-       
-  updateCommon(currenttime, tree, nTiles, sampling_rate);
+       updateCommon(currenttime, tree, nTiles, samplingrate);
 }
 
 void Tile::updateMinMax(Tile *tree)
@@ -371,7 +318,7 @@
        }
 }
 
-void Tile::print_to_file(FILE *fp, Tile *tree, int nTiles, Timestamp 
currenttime, float samplingrate)
+void Tile::print_to_file(FILE *fp, Tile *tree, int nTiles, Timestamp 
currenttime)
 {
        // we have to output in binart, so make  a struct and use fwrite
        TilePrintFormat tpf;
@@ -408,7 +355,8 @@
        tpf.yGrad = g;
        tpf.tGrad = b;
 
-       tpf.oldest_sample_timestamp = currenttime - 
getNumSamples()*((float)nTiles/(float)samplingrate);
+       // find the current sampling rate for this call
+       // tpf.oldest_sample_timestamp = currenttime - 
getNumSamples()*((float)nTiles/(float)samplingrate);
        fwrite(&tpf, sizeof(tpf), 1, fp);
 }
 
@@ -448,7 +396,7 @@
 
 
 void Tile::display(TileDisplayMode displaymode, int nTiles, Tile *tree, 
-                                  int sampling_rate, Timestamp currenttime, 
float A, float B, float visScale)
+                                  Timestamp currenttime, float A, float B, 
float visScale)
 {
   float gvisScale;
   gvisScale = 0.33;
@@ -469,12 +417,6 @@
                                glColor3f(1.0, 1.0, 0.0);
                        }
                        break;
-               case UNDERSAMPLING:
-                       {
-                               float dcol=0.0;
-                               glColor3f(dcol*0.5, dcol*0.8, dcol*0.4);
-                       }
-                       break;
                case DERIVATIVE:
                        {
                                float dcol=0.0;
@@ -482,12 +424,12 @@
                                glColor3f(dcol*0.8, dcol*0.8, dcol*0.4);
                        }
                        break;
+               case UNDERSAMPLING:
                case AVERAGE_AGE:
                        {
                                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-                               float dcol=1.0;// = (currenttime - 
sum_tstamps.getMean())*0.33/0.1651225 - 1.0;
-                               //if(dcol<0.0) dcol = 0.0;
-                               dcol *= 
visScale*getAverageAgeMeasure(tree[1], currenttime, gvisScale);
+                               float dcol= (currenttime - 
sum_tstamps.getMean())*0.33/0.1651225 - 1.0;
+                               dcol *= visScale;
                                glColor3f(0.6*dcol, 0.3*dcol, 0.9*dcol);
                        }
                        break;

Modified: branches/AFR/Engine/ImageTraversers/AFR/tiles.h
==============================================================================
--- branches/AFR/Engine/ImageTraversers/AFR/tiles.h     (original)
+++ branches/AFR/Engine/ImageTraversers/AFR/tiles.h     Sun Aug 28 23:18:06 
2005
@@ -14,7 +14,7 @@
 #include <Core/Math/MT_RNG.h>
 #define JITTER_THRESHOLD 0.005
 #define MIN_GRAD 0.01
-#define MIN_VALID_TILE_AREA 4
+#define MIN_VALID_TILE_AREA 16
 #define DISPLAY_WIDTH 512
 #define DISPLAY_HEIGHT 512
 
@@ -77,11 +77,21 @@
        public:
                static int **leafMapping, meanLevel, max_tile_area;
                Tile();
-               void print( int nTiles, Tile *tree, int sampling_rate, 
Timestamp currenttime);
+               inline void copystats(Tile &t)
+               {
+                 xGradient = t.xGradient;
+                 yGradient = t.yGradient;
+                 tGradient = t.tGradient;
+
+                 intensity = t.intensity;
+                 sum_tstamps = t.sum_tstamps;
+                 occlusion = t.occlusion;
+               }
+               void print( int nTiles, Tile *tree, Timestamp currenttime);
                void initialize(int l, int b, int r, int t, 
                                                int currlevel, int address, 
                                                int width, int height,  
-                                               int samplingrate, float A, 
float B);
+                                               float A, float B);
                inline void setNextTile(int index) { next = index; }
                inline void setPrevTile(int index) { prev = index; }
                inline void setNextRandomTile(int index) { nextrandom = 
index; }
@@ -109,7 +119,7 @@
                inline int getNextRandomTile() { return nextrandom; }
                inline int getPrevRandomTile() { return prevrandom; }
                inline float getNumSamples() { return 
xGradient.getSumWeights(); }
-               int getLevel() { return level; }
+               inline int getLevel() { return level; }
                inline double maxError() { return max_error; }
                inline double minError() { return min_error; }
                void getNextSample(int &x, int &y, MT_RNG &myRandomNumber);
@@ -122,15 +132,11 @@
                                return true;
                        return false;
                }
-               void setStatsFromChildren(Timestamp currenttime, float A, 
float B, 
-                          Tile *tree, int sampling_rate, int nTiles, bool 
validreached);
-               void updateCommon(Timestamp currenttime, Tile *tree, int 
nTiles, int sampling_rate);
-               void ageStats(Timestamp currenttime, float A, float B, 
-                                       Tile *tree, int sampling_rate, int 
nTiles);
+               void updateCommon(Timestamp currenttime, Tile *tree, int 
nTiles, unsigned int samplingrate);
                void updateStatsAddSampleSet(SampleSet *newsampleset, 
Timestamp currenttime, float A, float B, 
-                                       Tile *tree, int sampling_rate, int 
nTiles);
+                                       Tile *tree, int nTiles, unsigned int 
samplingrate);
                void updateStatsAddSample(Sample *newsample, Timestamp 
currenttime, float A, float B, 
-                          Tile *tree, int sampling_rate, int nTiles, float 
tgrad, bool occ);
+                          Tile *tree, int nTiles, float tgrad, bool occ, 
unsigned int samplingrate);
                void updateMinMax(Tile *tree);
                inline float xGrad() { return xGradient.getMean(); }
                inline float yGrad() { return yGradient.getMean(); }
@@ -154,8 +160,8 @@
                        y = ((float)bottom+(float)top)/2.0;
                }       
                void setDerivative(Timestamp currenttime);
-               void setError(Tile *tree, int nTiles, int sampling_rate, 
Timestamp currenttime);
-               void setTotalError(Tile *tree, Timestamp currenttime, int 
nTiles, int sampling_rate);
+               void setError(Tile *tree, int nTiles, Timestamp currenttime, 
unsigned int samplingrate);
+               void setTotalError(Tile *tree, Timestamp currenttime, int 
nTiles, unsigned int samplingrate);
                inline void setTimeLastDerivativeSet(Timestamp currenttime)
                {
                        time_last_derivative_set = currenttime;
@@ -169,7 +175,7 @@
                {
                        return (num_pixels==1);
                }
-               void print_to_file(FILE *fp, Tile *tree, int nTiles, 
Timestamp currenttime, float samplingrate);
+               void print_to_file(FILE *fp, Tile *tree, int nTiles, 
Timestamp currenttime);
                inline bool isZeroGrad()
                {
                        return (xGradient.getMean()<MIN_GRAD && 
yGradient.getMean()<MIN_GRAD && tGradient.getMean()<MIN_GRAD);
@@ -178,7 +184,7 @@
                float getOcclusionMeasure(Tile *tree, int nTiles);
                bool checkBounds(int x, int y);
     void display(TileDisplayMode displaymode, int nTiles, Tile *tree, 
-                                  int sampling_rate, Timestamp currenttime, 
float A, float B, float visScale);
+                                  Timestamp currenttime, float A, float B, 
float visScale);
                
 };
 




  • [MANTA] r511 - in branches/AFR/Engine: Control ImageTraversers ImageTraversers/AFR, abhinav, 08/28/2005

Archive powered by MHonArc 2.6.16.

Top of page