Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r469 - in trunk: Engine/Display Engine/ImageTraversers Engine/ImageTraversers/AFR UserInterface


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r469 - in trunk: Engine/Display Engine/ImageTraversers Engine/ImageTraversers/AFR UserInterface
  • Date: Mon, 8 Aug 2005 17:08:33 -0600 (MDT)

Author: bigler
Date: Mon Aug  8 17:08:32 2005
New Revision: 469

Modified:
   trunk/Engine/Display/OpenGLDisplay.cc
   trunk/Engine/Display/XHelper.cc
   trunk/Engine/Display/XHelper.h
   trunk/Engine/ImageTraversers/AFImageTraverser.cc
   trunk/Engine/ImageTraversers/AFImageTraverser.h
   trunk/Engine/ImageTraversers/AFR/evil.h
   trunk/Engine/ImageTraversers/AFR/kdtree.cc
   trunk/Engine/ImageTraversers/AFR/sample.h
   trunk/Engine/ImageTraversers/AFR/tiles.cc
   trunk/UserInterface/XWindowUI.cc
Log:

Engine/Display/OpenGLDisplay.cc
Engine/Display/XHelper.cc
Engine/Display/XHelper.h
Engine/ImageTraversers/AFImageTraverser.cc
UserInterface/XWindowUI.cc

  Added a lock for X displays via XHelper::Xlock.

Engine/ImageTraversers/AFImageTraverser.cc
Engine/ImageTraversers/AFImageTraverser.h
Engine/ImageTraversers/AFR/kdtree.cc
Engine/ImageTraversers/AFR/sample.h
Engine/ImageTraversers/AFR/tiles.cc

  Cleaned up warnings.

Engine/ImageTraversers/AFR/evil.h

  Set default evilness to EVIL_DEAD for all architectures.  This is
  the most benign level of evilness that actually includes something.


Modified: trunk/Engine/Display/OpenGLDisplay.cc
==============================================================================
--- trunk/Engine/Display/OpenGLDisplay.cc       (original)
+++ trunk/Engine/Display/OpenGLDisplay.cc       Mon Aug  8 17:08:32 2005
@@ -94,14 +94,18 @@
 
 void OpenGLDisplay::createWindow(int xres, int yres, XWindow* masterWindow)
 {
+  XHelper::Xlock.lock();
   // Open the display and make sure it has opengl
   dpy = XOpenDisplay(NULL);
-  if(!dpy)
+  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);
@@ -126,6 +130,7 @@
     vi = glXChooseVisual(dpy, screen, &attribList[0]);
     if(!vi){
       // Cannot find anything suitable
+      XHelper::Xlock.unlock();
       throw InternalError("Error selecting OpenGL visual", __FILE__, 
__LINE__);
     }
   }
@@ -179,9 +184,11 @@
   cx = glXCreateContext(dpy, vi, NULL, True);
   XFree(vi);
 
-  if(!glXMakeCurrent(dpy, win, cx))
+  if(!glXMakeCurrent(dpy, win, cx)) {
+    XHelper::Xlock.unlock();
     throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__);
-
+  }
+    
   glClearColor(.05, .1, .2, 0);
   glClear(GL_COLOR_BUFFER_BIT);
   glXSwapBuffers(dpy, win);
@@ -189,14 +196,22 @@
 
   // Get the fonts.  You need to call this with a current GL context.
   fontInfo = XHelper::getX11Font(dpy);
-  if (!fontInfo)
+  if (!fontInfo) {
+    XHelper::Xlock.unlock();
     throw InternalError("getX11Font failed!\n", __FILE__, __LINE__);
+  }
   fontbase = XHelper::getGLFont(fontInfo);
-  if (fontbase == 0)
+  if (fontbase == 0) {
+    XHelper::Xlock.unlock();
     throw InternalError("getGLFont failed!\n", __FILE__, __LINE__);
+  }
 
-  if(!glXMakeCurrent(dpy, None, NULL))
+  if(!glXMakeCurrent(dpy, None, NULL)) {
+    XHelper::Xlock.unlock();
     throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__);
+  }
+  
+  XHelper::Xlock.unlock();
 }
 
 void OpenGLDisplay::displayImage(const DisplayContext& context,

Modified: trunk/Engine/Display/XHelper.cc
==============================================================================
--- trunk/Engine/Display/XHelper.cc     (original)
+++ trunk/Engine/Display/XHelper.cc     Mon Aug  8 17:08:32 2005
@@ -11,6 +11,8 @@
 using namespace Manta;
 using namespace std;
 
+SCIRun::Mutex XHelper::Xlock("XHelper::Xlock");
+
 XFontStruct* XHelper::getX11Font(Display* dpy,
                                  const char* fontstring) {
   // Should we lock X?

Modified: trunk/Engine/Display/XHelper.h
==============================================================================
--- trunk/Engine/Display/XHelper.h      (original)
+++ trunk/Engine/Display/XHelper.h      Mon Aug  8 17:08:32 2005
@@ -12,6 +12,8 @@
 #include <GL/gl.h>
 #include <X11/Xlib.h>
 
+#include <SCIRun/Core/Thread/Mutex.h>
+
 #ifndef Manta_Engine_XHelper_h
 #define Manta_Engine_XHelper_h
 
@@ -28,6 +30,10 @@
   class XHelper {
   public:
 
+    // Use this to make sure that only one X program is opening
+    // windows at a time.
+    static SCIRun::Mutex Xlock;
+    
     // If there was an error NULL is returned.
     static XFontStruct* getX11Font(Display* dpy,
                                    const char* fontstring=__FONTSTRING__);

Modified: trunk/Engine/ImageTraversers/AFImageTraverser.cc
==============================================================================
--- trunk/Engine/ImageTraversers/AFImageTraverser.cc    (original)
+++ trunk/Engine/ImageTraversers/AFImageTraverser.cc    Mon Aug  8 17:08:32 
2005
@@ -68,14 +68,18 @@
 
 void AFImageTraverser::createStatsWin()
 {
+  XHelper::Xlock.lock();
   // Open the display and make sure it has opengl
   dpy = XOpenDisplay(NULL);
-  if(!dpy)
+  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__);
   }
   
@@ -123,7 +127,7 @@
   
   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;
@@ -134,10 +138,13 @@
 
   windowOpen = true;
 
-  cx = glXCreateContext(dpy, vi, NULL, True);
+  gl_context = glXCreateContext(dpy, vi, NULL, True);
   XFree(vi);
 
-  glXMakeCurrent(dpy, statsWindow.window, cx);
+  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);
@@ -154,8 +161,22 @@
 
   // 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);
-  glXMakeCurrent(dpy, None, NULL);
+  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() {
@@ -180,7 +201,9 @@
       default: sprintf(text, "Random Color Tiles; scale: %d", 
(int)visScale); break;
     };
   
-    glXMakeCurrent(dpy, statsWindow.window, cx);
+    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.displayTiles(tmode, samplingrate, chunkTimeStamp, visScale);
@@ -202,12 +225,8 @@
       switch (e.type) {
       case KeyPress:
         {
-            char buf[100];
-            int rv;
-            KeySym ks;
-
-            rv = XLookupString(&e.xkey, buf, sizeof(buf), &ks, 0);
-            switch (ks) {
+            unsigned long key = XKeycodeToKeysym(dpy, e.xkey.keycode, 0);
+            switch (key) {
                 case XK_m:
                 case XK_M:
                     toggleTileDisplayMode();
@@ -337,7 +356,7 @@
 
 void AFImageTraverser::allocateFragments(const FrameType f)
 {
-  int i, j;
+  int j;
   int x, y;
   Sample s;
   for(j=0; j<chunk_size; j++)
@@ -353,14 +372,13 @@
 void AFImageTraverser::renderCrossHair(const RenderContext& context, int 
myID, 
                                        Image *image, int xres, int yres, 
Sample *s)
 {
-  float xfrac, yfrac, sx, sy;
+  float sx, sy;
   int size = 5;
   int flags = RayPacket::HaveImageCoordinates | RayPacket::ConstantEye;
   sx = s->viewCoord[0];
   sy = s->viewCoord[1];
   //cout << "now rendering xhair" << endl;
   int depth = 0;
-  Point *p;
   RayPacketData raydata;
   RayPacket rays(raydata, size, depth, flags);
   double cx, cy;
@@ -610,7 +628,7 @@
     adjustTiles((float)chunkTimeStamp);
     //cout << "now updaing kdtree" << endl;
     SampleSet *sampleset;
-    int i, j;
+    int i;
     for(i=0; i<num_clients; i++)
     {
         while(!samplesetQ[prevFrameType][i].isEmpty())
@@ -659,7 +677,6 @@
   
   // let us not write temporal samples to image
  
-  float t = (float)chunkTimeStamp;
   //cout << "now placing fragment in temporalQ" << endl;
   for(int i=0; i<fragment_size; i++)
   {

Modified: trunk/Engine/ImageTraversers/AFImageTraverser.h
==============================================================================
--- trunk/Engine/ImageTraversers/AFImageTraverser.h     (original)
+++ trunk/Engine/ImageTraversers/AFImageTraverser.h     Mon Aug  8 17:08:32 
2005
@@ -28,11 +28,11 @@
     virtual void setupFrame(const RenderContext& context);
     virtual void renderImage(const RenderContext& context, Image* image);
     void allocateFragments(const FrameType f);
-    void AFImageTraverser::renderFragment(const RenderContext& context,
-                                      int assignment, Image* image, 
-                                      int xres, int yres);
-    void AFImageTraverser::renderCrossHair(const RenderContext& context, int 
myID, 
-                                       Image *image, int xres, int yres, 
Sample *s);
+    void renderFragment(const RenderContext& context,
+                        int assignment, Image* image, 
+                        int xres, int yres);
+    void renderCrossHair(const RenderContext& context, int myID, 
+                         Image *image, int xres, int yres, Sample *s);
     void masterThread(const RenderContext& context, Image* image);
     void clientThread(const RenderContext& context, Image* image, int 
assignment);
     void adjustTiles(Timestamp currenttime);
@@ -59,7 +59,7 @@
     bool initpass;
     XWindow statsWindow;
     Display* dpy;
-    GLXContext cx;
+    GLXContext gl_context;
   // These contain stuff for font stuff.
     XFontStruct* fontInfo;
     GLuint fontbase;

Modified: trunk/Engine/ImageTraversers/AFR/evil.h
==============================================================================
--- trunk/Engine/ImageTraversers/AFR/evil.h     (original)
+++ trunk/Engine/ImageTraversers/AFR/evil.h     Mon Aug  8 17:08:32 2005
@@ -55,11 +55,7 @@
 
 /* if you're not going to define it yourself you deserve what you get. */
 #ifndef EVIL_LEVEL
-#  ifdef __sgi
-#    define EVIL_LEVEL EVIL_NOT_AT_ALL
-#  else
-#    define EVIL_LEVEL EVIL_DEAD
-#  endif
+#  define EVIL_LEVEL EVIL_DEAD
 #endif
 
 #if EVIL_LEVEL < EVIL_NOT_AT_ALL

Modified: trunk/Engine/ImageTraversers/AFR/kdtree.cc
==============================================================================
--- trunk/Engine/ImageTraversers/AFR/kdtree.cc  (original)
+++ trunk/Engine/ImageTraversers/AFR/kdtree.cc  Mon Aug  8 17:08:32 2005
@@ -43,7 +43,7 @@
        }
        numLevels -= 2;
        cout << "numLevels = " << numLevels << endl;
-       int i, j, k;
+       int i;
        totalNodes = (int)(pow(2.0, numLevels+1));
   cout << "totalNodes = " << totalNodes << endl;
        tile = new Tile[totalNodes]; // allocate memory to our array based 
tree
@@ -103,7 +103,6 @@
 bool KDTree::mergeCut(Timestamp currenttime, int sampling_rate)
 {
        int index = tile[0].getNextTile();
-       int temp;
        // traverse the cut
        while(index!=0)
        {
@@ -592,7 +591,6 @@
 {
        if(displaymode==INDIVIDUAL_SAMPLES) return;
        int tile_to_display, start;
-       int i;
        
        int count = 0;
        tile_to_display = start = pseudostart;

Modified: trunk/Engine/ImageTraversers/AFR/sample.h
==============================================================================
--- trunk/Engine/ImageTraversers/AFR/sample.h   (original)
+++ trunk/Engine/ImageTraversers/AFR/sample.h   Mon Aug  8 17:08:32 2005
@@ -204,18 +204,18 @@
       
       void computeGradients(Timestamp currenttime)
       {
-        float li, ri, bi, ti, ci, tmpi;
+        //        float li, ri, bi, ti, ci, tmpi;
         
         viewX = center.viewCoord[0];
         viewY = center.viewCoord[1];
         viewZ = center.viewCoord[2];
         timestamp = currenttime;
-        li = left.intensity();
-        ri = right.intensity();
-        ti = top.intensity();
-        bi = bottom.intensity();
-        ci = center.intensity();
-        tmpi = temporal.intensity();
+//         li = left.intensity();
+//         ri = right.intensity();
+//         ti = top.intensity();
+//         bi = bottom.intensity();
+//         ci = center.intensity();
+//         tmpi = temporal.intensity();
         
         if(fabsf(center.viewCoord[0]-left.viewCoord[0])>0.001 
                && fabsf(center.viewCoord[0]-right.viewCoord[0])>0.001 )

Modified: trunk/Engine/ImageTraversers/AFR/tiles.cc
==============================================================================
--- trunk/Engine/ImageTraversers/AFR/tiles.cc   (original)
+++ trunk/Engine/ImageTraversers/AFR/tiles.cc   Mon Aug  8 17:08:32 2005
@@ -45,7 +45,6 @@
                       int width, int height, 
                       int samplingrate, float A, float B)
 {
-       int i, j, k;
        left = l;
        right = r;
        bottom = b;
@@ -180,7 +179,6 @@
 void Tile::updateStatsAddSampleSet(SampleSet *newsampleset, Timestamp 
currenttime, float A, float B, 
                           Tile *tree, int sampling_rate, int nTiles)
 {
-       int i, j;
        float wt_new = 1.0;
        float ratio = getWeight(A, B, (currenttime - time_last_updated));
        float temptime = newsampleset->getSampleTimeStamp(TEMPORAL_SAMPLE);
@@ -218,7 +216,6 @@
 void Tile::ageStats(Timestamp currenttime, float A, float B, 
                           Tile *tree, int sampling_rate, int nTiles)
 {
-       int i, j;
        float ratio = getWeight(A, B, (currenttime - time_last_updated));
        intensity.uniformDecrease(ratio);
        sum_tstamps.uniformDecrease(ratio);
@@ -236,7 +233,6 @@
 void Tile::updateStatsAddSample(Sample *newsample, Timestamp currenttime, 
float A, float B, 
                           Tile *tree, int sampling_rate, int nTiles, float 
tgrad, bool occ)
 {
-       int i, j;
        float wt_new = 1.0;
        float ratio = getWeight(A, B, (currenttime - time_last_updated));
        //intensity.uniformDecrease(ratio);
@@ -369,7 +365,7 @@
        TilePrintFormat tpf;
 
        tpf.index = index;
-       float r,g,b,tgrads;
+       float r,g,b;
        r = xGradient.getMean();                
        g = yGradient.getMean();        
        /*if(getOcclusionMeasure(tree, nTiles)>0.05)
@@ -488,7 +484,7 @@
                case ABSOLUTE_GRADIENT:
                        {
                                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-                               float r,g,b,tgrads;
+                               float r,g,b;
                                int p = index/TG_FILTER_WIDTH;
                                while(tree[p].level<meanLevel) p *= 2;
                                b = tree[p].tGradient.getMean();        

Modified: trunk/UserInterface/XWindowUI.cc
==============================================================================
--- trunk/UserInterface/XWindowUI.cc    (original)
+++ trunk/UserInterface/XWindowUI.cc    Mon Aug  8 17:08:32 2005
@@ -12,6 +12,7 @@
 #include <Core/Math/Trig.h>
 #include <Core/Thread/Runnable.h>
 #include <Core/Thread/Thread.h>
+#include <Engine/Display/XHelper.h>
 
 #include <X11/Xutil.h>
 #include <X11/keysym.h>
@@ -239,6 +240,7 @@
 
 void XWindowUI::createWindow(XWindow* window, int channel)
 {
+  XHelper::Xlock.lock();
   int screen=DefaultScreen(dpy);
     
   XSetWindowAttributes atts;
@@ -265,6 +267,8 @@
   XSetWMProperties(dpy, window->window, &tp, &tp, 0, 0, &sh, 0, 0);
   XMapWindow(dpy, window->window);
   
+  XHelper::Xlock.unlock();
+
   // Wait for the window to appear before proceeding
   for(;;){
     XEvent e;




  • [MANTA] r469 - in trunk: Engine/Display Engine/ImageTraversers Engine/ImageTraversers/AFR UserInterface, bigler, 08/08/2005

Archive powered by MHonArc 2.6.16.

Top of page