Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r640 - in branches/itanium2: Core/Shm Engine/Display fox


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r640 - in branches/itanium2: Core/Shm Engine/Display fox
  • Date: Fri, 21 Oct 2005 04:50:35 -0600 (MDT)

Author: abe
Date: Fri Oct 21 04:50:34 2005
New Revision: 640

Added:
   branches/itanium2/fox/MediaFusionApp.cc
   branches/itanium2/fox/MediaFusionApp.h
   branches/itanium2/fox/MediaFusionBridge.cc
   branches/itanium2/fox/MediaFusionBridge.h
   branches/itanium2/fox/sc_demo.cc
Modified:
   branches/itanium2/Core/Shm/MFStreamData.cc
   branches/itanium2/Core/Shm/MFStreamData.h
   branches/itanium2/Engine/Display/SHMImageDisplay.cc
   branches/itanium2/Engine/Display/SHMImageDisplay.h
   branches/itanium2/fox/CMakeLists.txt
   branches/itanium2/fox/FMantaImageFrame.cc
   branches/itanium2/fox/FMantaImageFrame.h
   branches/itanium2/fox/FMantaQuakeNav.cc
   branches/itanium2/fox/FMantaWindow.cc
   branches/itanium2/fox/dm_demo.cc
Log:

Note this commit contains a lot of debugging output, I'm just using it to move
some code to a bigger system at sgi. The deskside prism isn't able to run 
manta
and media fusion at the same time very well.

Added code to receive mouse and keyboard commands from a media fusion shm 
segment.

M    fox/FMantaWindow.cc
M    fox/FMantaQuakeNav.cc
M    fox/dm_demo.cc
M    fox/FMantaImageFrame.cc
M    fox/FMantaImageFrame.h
M    fox/CMakeLists.txt
M    Core/Shm/MFStreamData.cc
M    Core/Shm/MFStreamData.h
M    Engine/Display/SHMImageDisplay.cc
M    Engine/Display/SHMImageDisplay.h

Media Fusion bridge polls the shm segment, reads out commands and translates
them into XEvents which are sent to the MediaFusionApp fox gui. Supposedly 
MediaFusionBridge could be coupled with a simple X program like XWindowUI and
would just send it XEvents without the need for extra filtering.

A    fox/MediaFusionBridge.cc
A    fox/MediaFusionBridge.h

MediaFusionApp intercepts XEvents sent by MediaFusionBridge. This is necessary
because Fox will discard events sent to windows which aren't in focus. Since
the media fusion window will never be in focus, this class overrides 
dispatchEvent in FXApp and sends these Events to the target window.

A    fox/MediaFusionApp.cc
A    fox/MediaFusionApp.h

Added separate executable for the super computing demo. This program starts 
up 
renderer with the usual fox interface but using a shm image display and
media fusion bridge to receive media fusion commands.

A    fox/sc_demo.cc

Keyboard events seem pretty solid. Mouse events are not too stable.



Modified: branches/itanium2/Core/Shm/MFStreamData.cc
==============================================================================
--- branches/itanium2/Core/Shm/MFStreamData.cc  (original)
+++ branches/itanium2/Core/Shm/MFStreamData.cc  Fri Oct 21 04:50:34 2005
@@ -50,9 +50,6 @@
 
 #define PERM_FILE ( S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | 
S_IWOTH )
 
-
-
-
 void *MFStreamData::operator new( size_t /*bytes*/, int key_, int flag ) {
 
   int id;
@@ -65,11 +62,13 @@
 
       // Try to create again.
       if ((id = shmget( key_, sizeof(MFStreamData), IPC_CREAT|PERM_FILE )) 
== -1) {
-        throw new ErrnoException( "Cannot create shm: ", errno, __FILE__, 
__LINE__ );
+        perror( "Cannot create shm" );
+        throw ErrnoException( "Cannot create shm: ", errno, __FILE__, 
__LINE__ );
       }
     }
     else {
-      throw new ErrnoException( "Cannot get shm, key invalid: ", errno, 
__FILE__, __LINE__ );
+      perror( "Cannot get shm, key invalid" );
+      throw ErrnoException( "Cannot get shm, key invalid: ", errno, 
__FILE__, __LINE__ );
     }
   }
       
@@ -77,7 +76,8 @@
   void *this_ptr;
 
   if ((long long)(this_ptr = shmat( id, 0, 0 )) == -1) {
-    throw new ErrnoException( "Cannot attach pointer to shm: ", errno, 
__FILE__, __LINE__ );
+    perror( "Cannot attach pointer to shm" );
+    throw ErrnoException( "Cannot attach pointer to shm: ", errno, __FILE__, 
__LINE__ );
   }
 
   // Cast the pointer and set the shmID and key fields.
@@ -111,23 +111,26 @@
 
   // Detach shm
   if (shmdt( stream_data ) == -1) {
-    throw new ErrnoException("Could not detach shm", errno, __FILE__, 
__LINE__);
+    throw ErrnoException("Could not detach shm", errno, __FILE__, __LINE__);
   }
 
   // Remove shm
   if (shmctl( id, IPC_RMID, 0 ) == -1) {
-    throw new ErrnoException("Could not remove shm", errno, __FILE__, 
__LINE__);    
+    throw ErrnoException("Could not remove shm", errno, __FILE__, __LINE__); 
   
   }
 }
 
 MFStreamData::MFStreamData( int xres_, int yres_ ) :
+  
   xres( xres_ ),
   yres( yres_ ),
   zres( 4 ),
   frontBuffer( 0 ),
   backBuffer ( 1 ), 
   semaphore( key, LOCK_OPEN ),
-  counter( 0 )
+
+  counter( 0 ),  // Initialize with zero updates.
+  numSSCMD( 0 )  // Initalize with zero commands.
 {
 
   // Specifify the position/size of the rectangle we are using.
@@ -192,6 +195,22 @@
 
   // If we don't have an RGBA8 Pixel frame buffer do nothing.
 }
+
+void MFStreamData::read_commands( MFSPacket &packet ) {
+
+  // Copy the current commands out of the shm segment.
+  // Nigel: what locking is necessary.
+  int i;
+  for (i=0; i<numSSCMD; ++i) {
+    packet.command[i] = ssCMD[i];
+    packet.data   [i] = ssDATA[i];
+  }
+  packet.size = i;
+
+  // Set the internal counter back to zero.
+  numSSCMD = 0;
+}
+
 
 
 #endif

Modified: branches/itanium2/Core/Shm/MFStreamData.h
==============================================================================
--- branches/itanium2/Core/Shm/MFStreamData.h   (original)
+++ branches/itanium2/Core/Shm/MFStreamData.h   Fri Oct 21 04:50:34 2005
@@ -29,6 +29,9 @@
   DEALINGS IN THE SOFTWARE.
 */
 
+#ifndef MFSTREAMDATA__H
+#define MFSTREAMDATA__H
+
 #include <sys/types.h>
 
 #define STRM_SHM_CREATE 0x1
@@ -97,6 +100,29 @@
 
     
/////////////////////////////////////////////////////////////////////////////
 
+    struct MFSPacket {
+    public:
+      enum {
+        MOUSE_STATE_NONE   = 0x0,
+        MOUSE_STATE_RIGHT  = 0x1,
+        MOUSE_STATE_MIDDLE = 0x2,
+        MOUSE_STATE_LEFT   = 0x4,
+
+        KEYPRESS  = 100, // data is a xevent keysym id (A = 65)
+        DEVPRESS  = 101, // data is a xevent keysym id (F1 = 65470)
+        MOUSE_Y   = 102, // data is the y position of the mouse.
+        MOUSE_X   = 103, // data is the x position of the mouse.
+        MOUSE_BTN = 104, // data is a MOUSE_STATE id (possibled or'ed 
together)
+        MOUSE_MOD = 105  // data is a ... ?
+      };
+      
+      int command[MAX_NUM_SSCMD];
+      int data   [MAX_NUM_SSCMD];
+      int size;
+    };
+    
+    
/////////////////////////////////////////////////////////////////////////////
+
     // Allocates a new Media Fusion Stream Data struct using the specified 
shm key.
     void *operator new( size_t bytes, int key_, int flag );
 
@@ -112,6 +138,9 @@
     // Swap buffers method.
     void swap_buffers();
     void draw_pixels( const Image *image );
+
+    // Read commands from the segment.
+    void read_commands( MFSPacket &command_list );
     
   private:
     // Inaccessible operators.
@@ -125,3 +154,4 @@
 
 
 
+#endif

Modified: branches/itanium2/Engine/Display/SHMImageDisplay.cc
==============================================================================
--- branches/itanium2/Engine/Display/SHMImageDisplay.cc (original)
+++ branches/itanium2/Engine/Display/SHMImageDisplay.cc Fri Oct 21 04:50:34 
2005
@@ -83,9 +83,13 @@
   int xres, yres;
   context.getResolution( stereo, xres, yres );
 
-  // Acquire shm segment.
-  stream_data = new( shm_key, true ) MFStreamData( xres, yres );
+  // Check to see if we need to delete and reallocate the shm segment.
+  if (stream_data != 0)
+    delete stream_data;
 
+  // Allocate a new shm segment.
+  stream_data = new( shm_key, true ) MFStreamData( xres, yres );
+  
 }
 
 
///////////////////////////////////////////////////////////////////////////////

Modified: branches/itanium2/Engine/Display/SHMImageDisplay.h
==============================================================================
--- branches/itanium2/Engine/Display/SHMImageDisplay.h  (original)
+++ branches/itanium2/Engine/Display/SHMImageDisplay.h  Fri Oct 21 04:50:34 
2005
@@ -62,6 +62,7 @@
     // Note that the GLXImage display must be passed a GLX context by the
     // application it is embedded inside of.
     SHMImageDisplay( const vector<string> &args );
+    SHMImageDisplay( int shm_key_ ) : shm_key( shm_key_ ), stream_data( 0 ) 
{ };
     ~SHMImageDisplay();
 
     // RTRT_register creator function.

Modified: branches/itanium2/fox/CMakeLists.txt
==============================================================================
--- branches/itanium2/fox/CMakeLists.txt        (original)
+++ branches/itanium2/fox/CMakeLists.txt        Fri Oct 21 04:50:34 2005
@@ -15,42 +15,36 @@
     LINK_DIRECTORIES   (${HISTX_LIB} )     
   ENDIF(HISTX_PATH)
 
-  ADD_EXECUTABLE(dm_demo dm_demo.cc
-                           FMantaImageFrame.cc
-                           FMantaImageFrame.h
-                           FMantaWidgets.cc
-                           FMantaWidgets.h
-                           FMantaWindow.cc
-                           FMantaWindow.h
-                           FMantaNavigator.h
-                           FMantaQuakeNav.h
-                           FMantaQuakeNav.cc
-                           FMantaUniformNav.h
-                           FMantaUniformNav.cc 
-                           FMantaTrackballNav.h
-                           FMantaTrackballNav.cc 
-                           FMantaRecorder.h
-                           FMantaRecorder.cc
-                           FMantaStereo.h
-                           FMantaStereo.cc
-                           # FMantaTextureChooser.h
-                           # FMantaTextureChooser.cc
-                           # FMantaMaterialChooser.h
-                           # FMantaMaterialChooser.cc
-                           )
-
-
-  TARGET_LINK_LIBRARIES(dm_demo Manta_Engine 
-                                  Manta_UserInterface 
-                                  Manta_Model 
-                                  Manta_Image 
-                                  Manta_Interface 
-                                  Manta_Core 
-                                  SCIRun_Core)
-
-
-
+  # ADD_LIBRARY(FManta
+  SET(FMANTA_STATIC
+    FMantaImageFrame.cc
+    FMantaImageFrame.h
+    FMantaWidgets.cc
+    FMantaWidgets.h
+    FMantaWindow.cc
+    FMantaWindow.h
+    FMantaNavigator.h
+    FMantaQuakeNav.h
+    FMantaQuakeNav.cc
+    FMantaUniformNav.h
+    FMantaUniformNav.cc 
+    FMantaTrackballNav.h
+    FMantaTrackballNav.cc 
+    FMantaRecorder.h
+    FMantaRecorder.cc
+    FMantaStereo.h
+    FMantaStereo.cc
+    # FMantaTextureChooser.h
+    # FMantaTextureChooser.cc
+    # FMantaMaterialChooser.h
+    # FMantaMaterialChooser.cc
+    MediaFusionBridge.h
+    MediaFusionBridge.cc
+    MediaFusionApp.h
+    MediaFusionApp.cc
+    )
 
+  # Determine other libraries to link with
   SET(FOX_X11_LIBRARIES m jpeg png tiff)
 
   # Append Xcursor if it is available.
@@ -68,19 +62,52 @@
                           Xrandr)
   ENDIF(FOUND_XRANDR)
 
-  TARGET_LINK_LIBRARIES(dm_demo ${FOX_STATIC}
-                                ${CMAKE_THREAD_LIBS_INIT}
-                                ${OPENGL_LIBRARIES} 
-                                ${X11_LIBRARIES} 
-                                ${FOX_X11_LIBRARIES})
+  SET(OTHER_FOX_LIBS 
+    Manta_Engine 
+    Manta_UserInterface 
+    Manta_Model 
+    Manta_Image 
+    Manta_Interface 
+    Manta_Core 
+    SCIRun_Core
+
+    ${FOX_STATIC}
+    ${CMAKE_THREAD_LIBS_INIT}
+    ${OPENGL_LIBRARIES} 
+    ${X11_LIBRARIES} 
+    ${FOX_X11_LIBRARIES})
+
   IF(HISTX_PATH)
-    TARGET_LINK_LIBRARIES(dm_demo Manta_histx
-                                    ${HISTX_LINK} )
+    SET(OTHER_FOX_LIBS 
+      ${OTHER_FOX_LIBS}
+      ${HISTX_LINK} 
+      )
   ENDIF(HISTX_PATH)
 
   # Fox seems to insist on using pthreads.
   # IF(CMAKE_USE_SPROC_INIT)
-    TARGET_LINK_LIBRARIES(dm_demo pthread)
+    SET(OTHER_FOX_LIBS
+      ${OTHER_FOX_LIBS}
+      pthread
+      )
   # ENDIF(CMAKE_USE_SPROC_INIT)
 
-ENDIF(FOX_PATH)
\ No newline at end of file
+  # TARGET_LINK_LIBRARIES(FManta 
+  #   ${OTHER_FOX_LIBS})
+
+  ADD_EXECUTABLE(dm_demo dm_demo.cc
+    ${FMANTA_STATIC})
+
+  # Add the dm_demo program
+  TARGET_LINK_LIBRARIES(dm_demo
+    ${OTHER_FOX_LIBS})
+
+  ADD_EXECUTABLE(sc_demo sc_demo.cc
+    ${FMANTA_STATIC})
+
+  TARGET_LINK_LIBRARIES(sc_demo
+    ${OTHER_FOX_LIBS})
+
+ENDIF(FOX_PATH)
+
+

Modified: branches/itanium2/fox/FMantaImageFrame.cc
==============================================================================
--- branches/itanium2/fox/FMantaImageFrame.cc   (original)
+++ branches/itanium2/fox/FMantaImageFrame.cc   Fri Oct 21 04:50:34 2005
@@ -1,6 +1,6 @@
 
 #include <fox/FMantaImageFrame.h>
-
+#include <fox/MediaFusionApp.h>
 
 #include <fxkeys.h>
 
@@ -24,7 +24,19 @@
 
        FXMAPFUNC(SEL_MOUSEWHEEL,          FMantaImageFrame::ID_IMAGE, 
FMantaImageFrame::onMouseWheel ),
        FXMAPFUNC(SEL_MOTION,              FMantaImageFrame::ID_IMAGE, 
FMantaImageFrame::onMouseChange ),
-  FXMAPFUNC(SEL_KEYPRESS,            FMantaImageFrame::ID_IMAGE, 
FMantaImageFrame::onKeyPress )
+  FXMAPFUNC(SEL_KEYPRESS,            FMantaImageFrame::ID_IMAGE, 
FMantaImageFrame::onKeyPress ),
+
+  // Messages from Media Fusion
+       FXMAPFUNC(SEL_LEFTBUTTONRELEASE,   
MediaFusionApp::ID_MEDIA_FUSION_APP, FMantaImageFrame::onMouseChange ),
+       FXMAPFUNC(SEL_LEFTBUTTONPRESS,     
MediaFusionApp::ID_MEDIA_FUSION_APP, FMantaImageFrame::onMouseChange ),
+       FXMAPFUNC(SEL_MIDDLEBUTTONRELEASE, 
MediaFusionApp::ID_MEDIA_FUSION_APP, FMantaImageFrame::onMouseChange ),
+       FXMAPFUNC(SEL_MIDDLEBUTTONPRESS,   
MediaFusionApp::ID_MEDIA_FUSION_APP, FMantaImageFrame::onMouseChange ),
+       FXMAPFUNC(SEL_RIGHTBUTTONRELEASE,  
MediaFusionApp::ID_MEDIA_FUSION_APP, FMantaImageFrame::onMouseChange ),
+       FXMAPFUNC(SEL_RIGHTBUTTONPRESS,    
MediaFusionApp::ID_MEDIA_FUSION_APP, FMantaImageFrame::onMouseChange ),
+
+       FXMAPFUNC(SEL_MOUSEWHEEL,          
MediaFusionApp::ID_MEDIA_FUSION_APP, FMantaImageFrame::onMouseWheel ),
+       FXMAPFUNC(SEL_MOTION,              
MediaFusionApp::ID_MEDIA_FUSION_APP, FMantaImageFrame::onMouseChange ),
+  FXMAPFUNC(SEL_KEYPRESS,            MediaFusionApp::ID_MEDIA_FUSION_APP, 
FMantaImageFrame::onKeyPress ),
 };
 
 
FXIMPLEMENT(FMantaImageFrame,FXGLCanvas,FMantaImageFrameMap,ARRAYNUMBER(FMantaImageFrameMap));
@@ -67,6 +79,8 @@
                return 0;
        }
 
+  // std::cerr << "Mouse change" << std::endl;
+  
        // Check to see if a button is pressed.
        return navigator->onMouseChange( sender, sel, data );
 
@@ -77,7 +91,7 @@
 
        FXEvent *event = (FXEvent *)data;
        
-       std::cout << "Mouse wheel code: " << event->code << std::endl;
+       // std::cout << "Mouse wheel code: " << event->code << std::endl;
        
        return 1;
 }
@@ -85,6 +99,8 @@
 long FMantaImageFrame::onKeyPress   ( FXObject *sender, FXSelector sel, void 
*data ) {
 
        FXEvent *event = (FXEvent *)data;
+
+  // std::cerr << "Key pressed: " << event->text.text() << std::endl;
 
        return navigator->onKeyPress( sender, sel, data );
 }

Modified: branches/itanium2/fox/FMantaImageFrame.h
==============================================================================
--- branches/itanium2/fox/FMantaImageFrame.h    (original)
+++ branches/itanium2/fox/FMantaImageFrame.h    Fri Oct 21 04:50:34 2005
@@ -63,11 +63,9 @@
                int            getMantaChannel  () { return manta_channel;   
};
                
                // Debugging.
-               bool shootOneRay( int pixel_x, int pixel_y, Point 
&result_position, Vector &result_normal );
-
-               
+               bool shootOneRay( int pixel_x, int pixel_y, Point 
&result_position, Vector &result_normal );            
        };
-
+  
 };
 
-#endif
\ No newline at end of file
+#endif

Modified: branches/itanium2/fox/FMantaQuakeNav.cc
==============================================================================
--- branches/itanium2/fox/FMantaQuakeNav.cc     (original)
+++ branches/itanium2/fox/FMantaQuakeNav.cc     Fri Oct 21 04:50:34 2005
@@ -85,12 +85,16 @@
        FXushort sel_type = FXSELTYPE( sel );
        
   if (sel_type == SEL_RIGHTBUTTONPRESS) {
+    std::cerr << "R down" << std::endl;
     right_mouse_down = true;
   }
   else if (sel_type == SEL_RIGHTBUTTONRELEASE) {
+    std::cerr << "R up" << std::endl;    
     right_mouse_down = false;
   }
   else if (sel_type == SEL_MOTION && right_mouse_down) {
+
+    std::cerr << "R motion" << std::endl;
     
     Real delta_x = event->win_x - event->last_x;
     Real delta_y = event->win_y - event->last_y;
@@ -102,13 +106,15 @@
   }
 
   if (sel_type == SEL_LEFTBUTTONPRESS) {
+    std::cerr << "L down" << std::endl;
     left_mouse_down = true;
   }
   else if (sel_type == SEL_LEFTBUTTONRELEASE) {
+    std::cerr << "L up" << std::endl;
     left_mouse_down = false;
   }
   else if (sel_type == SEL_MOTION && left_mouse_down) {
-    
+    std::cerr << "L motion" << std::endl;
     Real delta_x = event->win_x - event->last_x;
     Real delta_y = event->win_y - event->last_y;
     

Modified: branches/itanium2/fox/FMantaWindow.cc
==============================================================================
--- branches/itanium2/fox/FMantaWindow.cc       (original)
+++ branches/itanium2/fox/FMantaWindow.cc       Fri Oct 21 04:50:34 2005
@@ -513,29 +513,55 @@
 
 
 void FMantaWindow::mantaPick( int x, int y ) const {
-       extern TransparentKDTree * __global_transparent_kdtree; 
-       extern KDTree * __global_kdtree;
 
-       if (__global_transparent_kdtree == NULL) {
-               cerr << "don't have a model to pick on\n";
-       }
+       Scene *scene = manta_interface->getScene();
+       Object *root_object = scene->getObject();
+       
+       // Check to see if  the root object is a cutting plane.
+       CuttingPlane *cutting_plane = dynamic_cast< CuttingPlane * >( 
root_object );
+       if (cutting_plane != 0) {
+
+    // If so use the cutting plane's child as the root.
+    root_object = cutting_plane->getObject();
+  }
 
        Point point;
        Vector normal;
+  
+  // Check to see if this object is either a transparent or normal kdtree.
+  if (dynamic_cast<KDTree *>( root_object )) {
+    KDTree * kdtree = dynamic_cast<KDTree *>( root_object );
+    
+    kdtree->enablePicking();
+
+    // Check to see if picking is supported.
+    if (kdtree->isPickingEnabled()) {
+      int result = manta_frame->shootOneRay( x, y, point, normal );
+      if (!result) {
+        kdtree->resetPicking();
+      }
+
+      // Disable picking.
+      kdtree->disablePicking();
+    }
+  }
+  else if (dynamic_cast<KDTree *>( root_object )) {
+    TransparentKDTree *kdtree = dynamic_cast<TransparentKDTree *>( 
root_object );
+
+    kdtree->enablePicking();
+    
+    // Check to see if picking is supported.
+    if (kdtree->isPickingEnabled()) {
+      int result = manta_frame->shootOneRay( x, y, point, normal );
+      if (!result) {
+        kdtree->resetPicking();
+      }
+
+      // Disable picking.
+      kdtree->disablePicking();
+    }
+  }
 
-       // Shoot a ray into the scene.
-       __global_transparent_kdtree->enablePicking();
-       __global_kdtree->enablePicking();
-       if (!__global_kdtree->isPickingEnabled())
-               cerr << "cannot enable picking\n";
-       int result = manta_frame->shootOneRay( x, y, point, normal );
-       if (result) {
-       } else {
-               __global_kdtree->resetPicking();
-               __global_transparent_kdtree->resetPicking();
-       }
-       __global_kdtree->disablePicking();
-       __global_transparent_kdtree->disablePicking();
 };
 
 long FMantaWindow::onNavigator( FXObject *sender, FXSelector key, void *data 
) {

Added: branches/itanium2/fox/MediaFusionApp.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/fox/MediaFusionApp.cc     Fri Oct 21 04:50:34 2005
@@ -0,0 +1,195 @@
+
+
+#include <fox/MediaFusionApp.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <fxkeys.h>
+
+#include <iostream>
+
+using namespace fox_manta;
+
+FXIMPLEMENT(MediaFusionApp,FXApp,0,0);
+
+////////////////////////////////////////////////////////////////////////////////
+// Constructor.
+MediaFusionApp::MediaFusionApp(const FXString& name,const FXString& vendor ) 
:
+  FXApp( name, vendor ),
+  mf_target_id( 0 )
+{ }
+
+////////////////////////////////////////////////////////////////////////////////
+// dispatchEvents
+FXbool MediaFusionApp::dispatchEvent(FXRawEvent& ev) {
+
+  // Determine the target window.
+  FXWindow *window;
+  window = findWindowWithId(ev.xany.window);
+  
+  // Check to see if the window belongs to the applicatoin.
+  if (window) {
+
+    char buf[20];
+    KeySym sym;
+    int n;
+
+    
///////////////////////////////////////////////////////////////////////////
+    // Check to see if the target window of the message happens to be the
+    // media fusion target window and the message came from a XSendEvent.
+    if ((ev.xany.window == mf_target_id) && (ev.xany.send_event == true)) {
+
+      // std::cerr << "Intercepted external event" << std::endl;
+      
+      // This code follows the same functionality in FXApp.cpp except that 
the
+      // various SEL_ id's are replaced by SEL_MF_ id's to distinguish 
internal
+      // and external messages.
+      switch (ev.xany.type) {
+        
+        // Keyboard
+      case KeyPress:
+      case KeyRelease:
+        event.type=SEL_KEYPRESS+ev.xkey.type-KeyPress;
+        event.time=ev.xkey.time;
+        event.win_x=ev.xkey.x;
+        event.win_y=ev.xkey.y;
+        event.root_x=ev.xkey.x_root;
+        event.root_y=ev.xkey.y_root;
+        event.state=ev.xkey.state&~(Button4Mask|Button5Mask);     // Exclude 
wheel buttons
+
+        // Translate to keysym
+        n = XLookupString( &ev.xkey, buf, sizeof(buf), &sym, NULL );
+        event.code=sym;
+
+        // Translate to string on KeyPress
+        if(ev.xkey.type==KeyPress){
+
+          // Replace text string
+          event.text.replace(0,1000,buf,n);
+        }
+
+        // Clear string on KeyRelease
+        else{
+          event.text.clear();
+        }
+
+        // Fix modifier state
+        if(ev.xkey.type==KeyPress){
+          if(sym==KEY_Shift_L) event.state|=SHIFTMASK;
+          if(sym==KEY_Shift_R) event.state|=SHIFTMASK;
+          if(sym==KEY_Control_L) event.state|=CONTROLMASK;
+          if(sym==KEY_Control_R) event.state|=CONTROLMASK;
+          if(sym==KEY_F13) event.state|=METAMASK;     // Key between Ctrl 
and Alt (on most keyboards)
+          if(sym==KEY_Alt_L) event.state|=ALTMASK;
+          if(sym==KEY_Alt_R) event.state|=ALTMASK;    // FIXME do we need 
ALTGR flag instead/in addition?
+        }
+        else{
+          if(sym==KEY_Shift_L) event.state&=~SHIFTMASK;
+          if(sym==KEY_Shift_R) event.state&=~SHIFTMASK;
+          if(sym==KEY_Control_L) event.state&=~CONTROLMASK;
+          if(sym==KEY_Control_R) event.state&=~CONTROLMASK;
+          if(sym==KEY_F13) event.state&=~METAMASK;    // Key between Ctrl 
and Alt (on most keyboards)
+          if(sym==KEY_Alt_L) event.state&=~ALTMASK;
+          if(sym==KEY_Alt_R) event.state&=~ALTMASK;   // FIXME do we need 
ALTGR flag instead/in addition?
+        }
+
+        // Send the FXEvent on to the target window handler.
+        if (window->handle( this, FXSEL(event.type,ID_MEDIA_FUSION_APP), 
&event )) {
+          refresh();
+          return TRUE;
+        }
+
+        break;
+
+      case MotionNotify:
+
+        event.type   = SEL_MOTION;
+        event.time   = ev.xmotion.time;
+        event.win_x  = ev.xmotion.x;
+        event.win_y  = ev.xmotion.y;
+        event.root_x = ev.xmotion.x_root;
+        event.root_y = ev.xmotion.y_root;
+        event.state  = ev.xmotion.state&~(Button4Mask|Button5Mask);        
// Exclude wheel buttons
+        event.code   = 0;
+        
+        if((FXABS(event.root_x-event.rootclick_x)>=6) || 
(FXABS(event.root_y-event.rootclick_y)>=6))
+           event.moved=1;
+
+        if (window->handle( this, FXSEL(event.type,ID_MEDIA_FUSION_APP), 
&event )) {
+          refresh();
+          return TRUE;
+        }
+        
+        event.last_x = event.win_x;
+        event.last_y = event.win_y;
+
+        return TRUE;      
+
+      case ButtonPress:
+      case ButtonRelease:
+
+        event.time=ev.xbutton.time;
+        event.win_x=ev.xbutton.x;
+        event.win_y=ev.xbutton.y;
+        event.root_x=ev.xbutton.x_root;
+        event.root_y=ev.xbutton.y_root;
+        event.state=ev.xbutton.state&~(Button4Mask|Button5Mask);          // 
Exclude wheel buttons
+
+        // Ignore the mouse wheel.
+        event.code=ev.xbutton.button;
+        if(ev.xbutton.type==ButtonPress){                               // 
Mouse button press
+
+          // Check which button is pressed.
+          
if(ev.xbutton.button==Button1){event.type=SEL_LEFTBUTTONPRESS;event.state|=LEFTBUTTONMASK;}
+          
if(ev.xbutton.button==Button2){event.type=SEL_MIDDLEBUTTONPRESS;event.state|=MIDDLEBUTTONMASK;}
+          
if(ev.xbutton.button==Button3){event.type=SEL_RIGHTBUTTONPRESS;event.state|=RIGHTBUTTONMASK;}
+
+          // Check to see if the cursor remained in one position and double 
clicked
+          if(!event.moved && (event.time-event.click_time<400) && 
(event.code==(FXint)event.click_button)) {
+            event.click_count++;
+            event.click_time=event.time;
+          }
+          else{
+            // Reset the click count
+            event.click_count=1;
+            event.click_x=event.win_x;
+            event.click_y=event.win_y;
+            event.rootclick_x=event.root_x;
+            event.rootclick_y=event.root_y;
+            event.click_button=event.code;
+            event.click_time=event.time;
+          }
+          
+          if(!(ev.xbutton.state&(Button1Mask|Button2Mask|Button3Mask)))
+            event.moved=0;
+          
+        }
+
+        else {                                                           // 
Mouse button release
+          
if(ev.xbutton.button==Button1){event.type=SEL_LEFTBUTTONRELEASE;event.state&=~LEFTBUTTONMASK;}
+          
if(ev.xbutton.button==Button2){event.type=SEL_MIDDLEBUTTONRELEASE;event.state&=~MIDDLEBUTTONMASK;}
+          
if(ev.xbutton.button==Button3){event.type=SEL_RIGHTBUTTONRELEASE;event.state&=~RIGHTBUTTONMASK;}
+        }
+
+        // Send the event to the target window
+        if (window->handle( this, FXSEL(event.type,ID_MEDIA_FUSION_APP), 
&event )) {
+          refresh();
+          return TRUE;
+        }
+
+        // Update the last mouse position.
+        event.last_x = event.win_x;
+        event.last_y = event.win_y;
+        
+      };
+    }
+
+    
///////////////////////////////////////////////////////////////////////////
+    // Check to see if the event can be handled by FXApp functionality.
+    else if (FXApp::dispatchEvent( ev )) {
+      return TRUE;
+    }
+  }
+
+  return FALSE;
+}

Added: branches/itanium2/fox/MediaFusionApp.h
==============================================================================
--- (empty file)
+++ branches/itanium2/fox/MediaFusionApp.h      Fri Oct 21 04:50:34 2005
@@ -0,0 +1,74 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2005
+  Silicon Graphics Inc. Mountain View California
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef fox_MEDIAFUSIONAPP__H
+#define fox_MEDIAFUSIONAPP__H
+
+#include <fx.h>
+#include <fx3d.h>
+
+namespace fox_manta {
+
+  using namespace FX;
+  
+  
///////////////////////////////////////////////////////////////////////////////
+  //
+  // This class overrides dispatchEvent in order to intercept XEvents bound 
for
+  // a window whose message handlers contain logic for reacting to Media 
Fusion
+  // commands.
+  //
+  
///////////////////////////////////////////////////////////////////////////////
+  class MediaFusionApp : public FXApp {
+    FXDECLARE(MediaFusionApp);
+  private:
+    // Id of the window to intercept events for.
+    int mf_target_id;
+
+    // Persistant event to update state for as XEvents are received
+    // (for example to handle double clicks)
+    FXEvent event;
+    
+  protected:
+    virtual FXbool dispatchEvent(FXRawEvent& ev);
+  
+  public:
+    enum {
+      ID_MEDIA_FUSION_APP = FXApp::ID_LAST
+    };
+    
+    MediaFusionApp(const FXString& name="Application",const FXString& 
vendor="FoxDefault");
+
+    // This method must be called after the App is constructed since the 
window id
+    // won't be known before.
+    void setTargetId( int mf_target_id_ ) { mf_target_id = mf_target_id_; };
+  };
+
+};
+
+#endif
+

Added: branches/itanium2/fox/MediaFusionBridge.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/fox/MediaFusionBridge.cc  Fri Oct 21 04:50:34 2005
@@ -0,0 +1,337 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2005
+  Silicon Graphics Inc. Mountain View California
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#include <fox/MediaFusionBridge.h>
+
+#include <SCIRun/Core/Thread/Time.h>
+#include <SCIRun/Core/Exceptions/Exception.h>
+
+#include <iostream>
+
+using namespace Manta;
+using namespace SCIRun;
+using namespace fox_manta;
+
+MediaFusionBridge::MediaFusionBridge( Window window_id_, Window root_id_, 
Display *target_display_,
+                                      int shm_key_, double polling_interval_ 
) :
+  this_thread( 0 ),
+  window_id( window_id_ ),
+  root_id( root_id_ ),
+  target_display( target_display_ ),
+  display( 0 ),
+  shm_key( shm_key_ ),
+  stream_data( 0 ),
+  polling_interval( polling_interval_ ),
+
+  // Initialize mouse state to zero.
+  mouse_button( 0 ),
+  mouse_state( 0 )
+{
+
+}
+
+
+MediaFusionBridge::~MediaFusionBridge() {
+
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN 
 R
+///////////////////////////////////////////////////////////////////////////////
+void MediaFusionBridge::run() {
+
+  // Attach to the shm segment.
+  std::cerr << "MediaFusionBridge starting targed window: " << window_id
+            << " root: " << root_id
+            << std::endl;
+
+  try {
+    stream_data = new( shm_key, false ) MFStreamData;
+  }
+  catch (SCIRun::Exception *e) {
+    std::cerr << "Error acquiring shm: " << e->message() << std::endl;
+  }
+  catch (SCIRun::Exception &e) {
+    std::cerr << "Error acquiring shm: " << e.message() << std::endl;
+  }
+  
+  // Connect to the X server.
+  display = XOpenDisplay( 0 );
+
+  // Specify synchronized events.
+  // XSynchronize( display, true );
+  
+  typedef MFStreamData::MFSPacket MFSPacket;
+  MFSPacket packet;
+
+  int result;
+  int mf_button;
+  int prev;
+  int event_type;
+  
+  // Begin polling the shm segment.
+  for (;;) {
+
+    // Read commands from the stream.
+    stream_data->read_commands( packet );
+    
+    // Process the command.
+    for (int i=0;i<packet.size;++i) {
+
+      switch (packet.command[i]) {
+      case MFSPacket::KEYPRESS:
+
+        // Send a key press event.
+        keypress_event( packet.data[i] );
+          
+        break;
+      case MFSPacket::DEVPRESS:
+        std::cerr << "DEVPRESS: " << packet.data[i] << std::endl;
+
+        // Function keys etc.
+        
+        break;
+      case MFSPacket::MOUSE_X:
+        // std::cerr << "MOUSE_X: " << packet.data[i] << std::endl;
+
+        // Update mouse coordinate.
+        mouse_x = packet.data[i];
+
+        // Send a mouse motion event.
+        motion_event();
+
+        break;
+      case MFSPacket::MOUSE_Y:
+        // std::cerr << "MOUSE_Y: " << packet.data[i] << std::endl;
+
+        // Update mouse coordinate.
+        mouse_y = packet.data[i];
+        
+        // Send a mouse motion event.
+        motion_event();
+
+        break;
+      case MFSPacket::MOUSE_BTN:
+        std::cerr << "MOUSE_BTN: " << packet.data[i] << std::endl;
+        
+        mf_button = packet.data[i];
+
+        // Avoid out of range commands.
+        if ((mf_button < 0) || (mf_button > 7))
+          break;
+
+        printf( "Before mouse_state: 0x%x\nCurrent mouse_button: 0x%x\n", 
mouse_state, mouse_button );
+        
+        
///////////////////////////////////////////////////////////////////////
+        // Update the button state.
+        prev       = mouse_state;
+        event_type = ButtonRelease;
+
+        // Determine the new state.
+        if (mf_button == MFSPacket::MOUSE_STATE_NONE) {
+          mouse_state &= (~Button1Mask);
+          mouse_state &= (~Button2Mask);
+          mouse_state &= (~Button3Mask);
+        }
+        else {
+
+          // Check for each button indivdually.
+          if (mf_button & MFSPacket::MOUSE_STATE_LEFT)
+            mouse_state |= (Button1Mask);
+          if (mf_button & MFSPacket::MOUSE_STATE_MIDDLE)
+            mouse_state |= (Button2Mask);
+          if (mf_button & MFSPacket::MOUSE_STATE_RIGHT)
+            mouse_state |= (Button3Mask);          
+        }
+
+        
///////////////////////////////////////////////////////////////////////
+        // Determine which buttons changed the state, send a button event for
+        // each button whose state change.
+
+        // If media fusion has set left button and previously button1 was 
pressed
+        // (or the other way around)
+        if (bool(mf_button & MFSPacket::MOUSE_STATE_LEFT) != bool(prev & 
Button1Mask)) {
+          mouse_button = Button1;
+
+          if (mf_button & MFSPacket::MOUSE_STATE_LEFT)
+            event_type = ButtonPress;
+
+          std::cerr << "Button1 changed " << event_type << std::endl;
+          
+          button_event( event_type );
+        }
+
+        if (bool(mf_button & MFSPacket::MOUSE_STATE_MIDDLE) != bool(prev & 
Button2Mask)) {
+          mouse_button = Button2;
+
+          if (mf_button & MFSPacket::MOUSE_STATE_MIDDLE)
+            event_type = ButtonPress;
+
+          std::cerr << "Button2 changed " << event_type << std::endl;
+          
+          button_event( event_type );
+        }
+
+        if (bool(mf_button & MFSPacket::MOUSE_STATE_RIGHT) != bool(prev & 
Button3Mask)) {
+          mouse_button = Button3;
+
+          if (mf_button & MFSPacket::MOUSE_STATE_RIGHT)
+            event_type = ButtonPress;
+
+          std::cerr << "Button3 changed " << event_type << std::endl;
+          
+          button_event( event_type );
+        }
+
+        // Otherwise nothing changed.
+        
+        // Send mouse update event.
+
+        // button_press_event();
+        printf( "After mouse_state: 0x%x\nCurrent mouse_button: 0x%x\n", 
mouse_state, mouse_button );        
+        break;
+      case MFSPacket::MOUSE_MOD:
+        std::cerr << "MOUSE_MOD: " << packet.data[i] << std::endl;
+        break;
+
+      default:
+        std::cerr << "Unknown MFSPacket command: " << packet.command[i] << 
std::endl;
+      }
+    }
+
+    // Flush any pending events.
+    XFlush( display );
+    
+    // Wait for a specified interval.
+    // SCIRun::Time::waitUntil( 
SCIRun::Time::currentSeconds()+polling_interval );
+  }
+
+  // Disconnect from the x server.
+  XCloseDisplay( display );
+
+}
+
+void MediaFusionBridge::startup() {
+
+  if (this_thread == 0) {
+
+    // Create a thread.
+    this_thread = new Thread( this, "MediaFusionBridge" );
+
+    this_thread->setDaemon( true );
+    this_thread->detach();
+  }
+}
+
+void MediaFusionBridge::keypress_event( int keysym ) {
+
+  XEvent event;
+  KeyCode keycode;
+
+  event.xany.serial      = 0;
+  event.xany.send_event  = 1;
+  event.xany.display     = display;
+  event.xany.window      = window_id;
+
+  // Media fusion delivers a key symbol, however the XEvent expects a key 
code.
+  keycode = XKeysymToKeycode( display, keysym );
+        
+  // std::cerr << "KEYPRESS: sym:" << packet.data[i]
+  //           << " code: " << (int)keycode 
+  //           << std::endl;
+
+  // Create an send a Key press event.
+  event.xany.type        = KeyPress;
+  event.xkey.root        = root_id;
+  event.xkey.subwindow   = 0;
+  event.xkey.time        = CurrentTime;
+  event.xkey.x           = mouse_x;
+  event.xkey.y           = mouse_y;
+  event.xkey.x_root      = mouse_x;
+  event.xkey.y_root      = mouse_y;
+  event.xkey.state       = 0;
+  event.xkey.keycode     = keycode;
+  event.xkey.same_screen = true;
+
+  // Send the event.
+  XSendEvent( display, window_id, True, KeyPressMask,(XEvent *)&event );
+}
+
+void MediaFusionBridge::motion_event() {
+
+  XEvent event;
+  KeyCode keycode;
+
+  event.xany.serial      = 0;
+  event.xany.send_event  = 1;
+  event.xany.display     = display;
+  event.xany.window      = window_id;
+  
+  // Create and send a xmotion event.
+  event.xany.type            = MotionNotify;
+  event.xmotion.root         = root_id;
+  event.xmotion.subwindow    = 0;  
+  event.xmotion.time         = CurrentTime;
+  event.xmotion.x            = mouse_x;
+  event.xmotion.y            = mouse_y;
+  event.xmotion.x_root       = mouse_x;
+  event.xmotion.y_root       = mouse_y;
+  event.xmotion.state        = mouse_state;
+  event.xmotion.is_hint      = 0;
+  event.xmotion.same_screen  = true;
+
+  XSendEvent( display, window_id, True, PointerMotionMask,(XEvent *)&event );
+}
+
+void MediaFusionBridge::button_event( int event_type ) {
+
+  XEvent event;
+  KeyCode keycode;
+
+  event.xany.serial      = 0;
+  event.xany.send_event  = 1;
+  event.xany.display     = display;
+  event.xany.window      = window_id;
+  
+  // Create and send a xbutton event.
+  event.xany.type            = event_type;
+  event.xbutton.root         = root_id;
+  event.xbutton.subwindow    = 0;  
+  event.xbutton.time         = CurrentTime;
+  event.xbutton.x            = mouse_x;
+  event.xbutton.y            = mouse_y;
+  event.xbutton.x_root       = mouse_x;
+  event.xbutton.y_root       = mouse_y;
+  event.xbutton.state        = mouse_state;
+  event.xbutton.button       = mouse_button;
+  event.xbutton.same_screen  = true;
+
+  XSendEvent( display, window_id, True, ButtonPressMask,(XEvent *)&event );  
+}
+
+

Added: branches/itanium2/fox/MediaFusionBridge.h
==============================================================================
--- (empty file)
+++ branches/itanium2/fox/MediaFusionBridge.h   Fri Oct 21 04:50:34 2005
@@ -0,0 +1,91 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2005
+  Silicon Graphics Inc. Mountain View California
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#include <X11/Xlib.h>
+#include <Core/Shm/MFStreamData.h>
+#include <SCIRun/Core/Thread/Thread.h>
+#include <SCIRun/Core/Thread/Runnable.h>
+
+namespace fox_manta {
+
+  using namespace Manta;
+  using namespace SCIRun;
+
+  
/////////////////////////////////////////////////////////////////////////////
+  // This class contains a runnable which will connect to the media fusion 
shm segment and
+  // send XEvents to a specified window and display.
+  
/////////////////////////////////////////////////////////////////////////////
+  class MediaFusionBridge : public SCIRun::Runnable {
+  private:
+    // X11 connection.
+    Window root_id;
+    Window window_id;
+    Display *target_display;
+    Display *display;
+
+    // Shm segment.
+    MFStreamData *stream_data;
+    int shm_key;
+
+    // Thread.
+    Thread *this_thread;
+    double polling_interval;
+
+    // Mouse and keyboard state.
+    int mouse_x, mouse_y;
+    int mouse_state, mouse_button;
+
+    // Helper methods.
+    void keypress_event( int keysym );
+    void motion_event();
+    void button_event( int event_type );
+    
+  public:
+    MediaFusionBridge() :
+      this_thread( 0 ), window_id( 0 ), display( 0 ), stream_data( 0 ), 
polling_interval( 0.1 ) { };
+    MediaFusionBridge( Window window_id_,
+                       Window root_id_,
+                       Display *target_display_,
+                       int shm_key,
+                       double polling_interval_ = 0.1 );
+
+    ~MediaFusionBridge();
+    
+    // Runnable interface.
+    void run();
+
+    // Start up the detached thread.
+    void startup();
+
+    // Start up method which may be called by a oneShotCallback.
+    void startup_callback( int, int ) { startup(); };
+  };
+
+};
+
+

Modified: branches/itanium2/fox/dm_demo.cc
==============================================================================
--- branches/itanium2/fox/dm_demo.cc    (original)
+++ branches/itanium2/fox/dm_demo.cc    Fri Oct 21 04:50:34 2005
@@ -261,17 +261,40 @@
        
        // Create the manta image frame.
        FMantaImageFrame *manta_frame = manta_window.getMantaFrame();
-       
+
        // Create a glx image display.
        GLXImageDisplay glx_image_display( (XVisualInfo 
*)manta_frame->getVisual()->getInfo(),
                                      (Window)       manta_frame->id() );
-       
+
+  std::cout << "X Window id: " << manta_frame->id() << std::endl;
+  
        // Try to load a scene.
        if ((scene_text == 0) || (!manta_interface->readScene( scene_text ))) 
{
                // Create a default scene.
                manta_interface->setScene( createDefaultScene() );
        }
 
+  Object *root_object = manta_interface->getScene()->getObject();
+  
+  // Check to see if the camera should be automatically positioned.
+  if (default_camera == "auto") {
+    
+    // Find the bounds of the model.
+    BBox bounds;
+    root_object->computeBounds( PreprocessContext(), bounds );
+
+    Point lookat = bounds[0] + (bounds[1] - bounds[0]) * 0.5;
+    Point eye = lookat + Vector( 0, bounds.diagonal().length(), 0 );
+    Vector up( 0, 0, 1 );
+
+    ostringstream oss;
+    oss << "pinhole( -eye " << eye << " -lookat " << lookat << " -up " << up 
<< " -fov 60 )";
+
+    default_camera = oss.str();
+
+    std::cerr << "Auto camera: " << default_camera << std::endl;
+  }
+
        // Check to see if a bookmark file was specified.
        if (bookmark_file_name.size() > 0) {
 
@@ -339,7 +362,7 @@
   }
   
        // Check to see if the default scene was a kdtree.
-       Object *root_object = manta_interface->getScene()->getObject();
+       
        
        
/////////////////////////////////////////////////////////////////////////////
        // Create any necessary dialogs now since everything else should be 
initialized.

Added: branches/itanium2/fox/sc_demo.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/fox/sc_demo.cc    Fri Oct 21 04:50:34 2005
@@ -0,0 +1,453 @@
+/*
+ For more information, please see: http://software.sci.utah.edu

+ The MIT License

+ Copyright (c) 2005
+ Silicon Graphics Inc. Mountain View California.

+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:

+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.

+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+ */
+
+#include <Interface/RTRTInterface.h>
+#include <Core/Color/ColorDB.h>
+#include <Core/Util/Args.h>
+#include <Interface/Callback.h>
+#include <Interface/Scene.h>
+#include <Interface/Camera.h>
+#include <Interface/Callback.h>
+
+#include <X11/Xlib.h>
+
+#include <Engine/Display/GLXImageDisplay.h>
+#include <Engine/Display/SHMImageDisplay.h>
+#include <Model/Cameras/PinholeCamera.h>
+
+#include <fox/FMantaWindow.h>
+#include <fox/FMantaUniformNav.h>
+#include <fox/FMantaQuakeNav.h>
+#include <fox/FMantaTrackballNav.h>
+#include <fox/FMantaWidgets.h>
+#include <fox/FMantaStereo.h>
+
+#include <fox/MediaFusionBridge.h>
+
+// #include <histx/SingleSamplerCounter.h>
+
+#include <string>
+#include <stdlib.h>
+#include <fstream>
+
+using namespace FX;
+using namespace fox_manta;
+using namespace Manta;
+using namespace std;
+
+#include <Model/Groups/KDTree.h>
+#include <Model/Groups/TransparentKDTree.h>
+#include <Model/Materials/CopyColorMaterial.h>
+
+#include <fox/MediaFusionApp.h>
+
+using namespace Manta::Kdtree;
+
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+// Digital Mockup Dialog Box.
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+class DmDemoDialog : public FXDialogBox {
+       FXDECLARE(DmDemoDialog)
+private:
+       FXListBox    *render_mode_box;
+       // FXRealSlider *alpha_slider;
+       FMantaRealSlider *alpha_slider;
+
+       FMantaWindow *manta_window;
+       
+       KDTree *kdtree;
+       TransparentKDTree *transparent_kdtree;
+       
+public:
+       enum {
+               ID_RENDER_MODE_SELECT = FXDialogBox::ID_LAST,
+               ID_ALPHA_SLIDER,
+               ID_LAST
+       };
+       DmDemoDialog() {  };
+       DmDemoDialog( FMantaWindow *manta_window_,
+                     KDTree *kdtree_, TransparentKDTree *transparent_kdtree_,
+                                                               const 
FXString &name, FXuint opts=DECOR_ALL,
+                                                   FXint x=50,FXint 
y=50,FXint w=0,FXint h=0,FXint pl=10,
+                                                               FXint 
pr=10,FXint pt=10,FXint pb=10,FXint hs=4,FXint vs=4 );
+       
+       void setKdtrees( KDTree *kdtree_, TransparentKDTree 
*transparent_kdtree_ ) {
+               kdtree = kdtree_; transparent_kdtree = transparent_kdtree_; }
+       
+       void create() { FXDialogBox::create(); show( PLACEMENT_DEFAULT ); };
+       
+       long onRenderModeSelect( FXObject *sender, FXSelector key, void *data 
);
+       long onAlphaSlider     ( FXObject *sender, FXSelector key, void *data 
);
+
+};
+
+FXDEFMAP(DmDemoDialog) DmDemoDialogMap[] = {
+       
//////////////////////////////////////////////////////////////////////////////
+       //        Message_Type ID                                   
Message_Handler
+       FXMAPFUNC(SEL_COMMAND, DmDemoDialog::ID_RENDER_MODE_SELECT,    
DmDemoDialog::onRenderModeSelect ),
+       FXMAPFUNC(SEL_COMMAND, DmDemoDialog::ID_ALPHA_SLIDER,          
DmDemoDialog::onAlphaSlider )
+};     
+
+FXIMPLEMENT(DmDemoDialog,FXDialogBox,DmDemoDialogMap,ARRAYNUMBER(DmDemoDialogMap));
+
+
+DmDemoDialog::DmDemoDialog( FMantaWindow *manta_window_,
+                                                                             
                                  KDTree *kdtree_, TransparentKDTree 
*transparent_kdtree_,
+                                                                             
                                  const FXString &name, FXuint opts,
+                                                                             
                                  FXint x,FXint y,FXint w,FXint h,FXint pl,
+                                                                             
                                  FXint pr,FXint pt,FXint pb,FXint hs,FXint 
vs ) : 
+       manta_window( manta_window_ ),
+       kdtree( kdtree_ ), transparent_kdtree( transparent_kdtree_ ),
+       FXDialogBox ( manta_window_->getApp(), name, opts, x, y, w, h, pl, 
pr, pt, pb, hs, vs ) 
+{
+
+       RTRTInterface *manta_interface = manta_window->getMantaInterface();
+       
+       FXHorizontalFrame *frame = new FXHorizontalFrame( this );
+
+       // Add render mode selection box.
+       render_mode_box = new FXListBox( frame, this, ID_RENDER_MODE_SELECT );
+       render_mode_box->appendItem( "Opaque Surfaces", 0, kdtree );
+       render_mode_box->appendItem( "Transparent Surfaces", 0, 
transparent_kdtree );
+       
+       // Add alpha slider.
+       frame = new FXHorizontalFrame( this, LAYOUT_FILL_X );
+       new FXLabel( frame, "Alpha: " );
+       // alpha_slider = new FXRealSlider( frame, this, ID_ALPHA_SLIDER, 
LAYOUT_FILL_X );
+       
+       alpha_slider = new FMantaRealSlider( frame, 
+                       new FMantaSet<TransparentKDTree,Real>( 
manta_interface, transparent_kdtree, &TransparentKDTree::setAlpha ),
+                       LAYOUT_FILL_X );
+                       
+       alpha_slider->setRange( 0.0, 1.0 );
+       alpha_slider->setValue( transparent_kdtree->getAlpha() );
+       alpha_slider->disable();
+       
+}
+
+long DmDemoDialog::onRenderModeSelect( FXObject *sender, FXSelector key, 
void *data ) {
+
+       // Determine which option selected.
+       int index = render_mode_box->getCurrentItem();
+       Object *new_root = (Object *)render_mode_box->getItemData( index );
+       
+       if (new_root == kdtree) {
+               alpha_slider->disable();
+       }
+       
+       if (new_root == transparent_kdtree) {
+               alpha_slider->enable();
+       }
+       
+       manta_window->setSceneObject( new_root );
+
+       return 1;
+}
+
+long DmDemoDialog::onAlphaSlider     ( FXObject *sender, FXSelector key, 
void *data ) {
+
+       // Set the control speed for interaction.
+       Real alpha = *((double *)data);
+       
+       manta_window->getMantaInterface()->addTransaction("Set Alpha",
+               Callback::create( transparent_kdtree, 
&TransparentKDTree::setAlpha,alpha));
+       
+       return 1;
+
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+
+// XXX to be replaced!
+namespace fox_manta {
+TransparentKDTree *__global_transparent_kdtree = NULL; 
+KDTree *__global_kdtree = NULL; 
+}
+
+Scene* createDefaultScene();
+
+int main( int argc, char *argv[]) {
+
+       // Make sure the necessary environment is setup.
+       if (getenv("THREAD_NO_CATCH_SIGNALS") == 0) {
+               cerr << "ALERT: setenv THREAD_NO_CATCH_SIGNALS 1 to avoid 
instability on exit." << std::endl;
+       };
+       if (getenv("FGL_MACRO_TILE_FB") == 0) {
+               cerr << "ALERT: setenv FGL_MACRO_TILE_FB 1 to improve 
performance over vizserver." << std::endl;
+       }
+
+       // Parse args.
+       int np = 1;
+       char *scene_text = 0;
+       string bookmark_file_name;
+  string default_camera = "pinhole(-eye 3 3 2 -lookat 0 0 0.3 -up 0 0 1 -fov 
60)";
+  bool use_stereo = false;
+  int shm_key = 100;
+
+  
+       // Look for specific args.
+       for (int i=0;i<argc;++i) {
+               string arg = argv[i];
+               if (arg == "-np") {
+                       np = atoi( argv[++i] );
+               }
+               else if (arg == "-scene") {
+                       scene_text = argv[++i];
+               }
+               else if (arg == "-bookmarks") {
+                       bookmark_file_name = argv[++i];
+               }
+    else if (arg == "-stereo") {
+      use_stereo = true;
+    }
+    else if (arg == "-camera") {
+      default_camera = argv[++i];
+    }
+    else if (arg == "-key") {
+      shm_key = atoi( argv[++i] );
+    }
+       }
+       
+       std::cerr << "Using " << np << " workers plus one gui thread." << 
std::endl;
+
+       
/////////////////////////////////////////////////////////////////////////////
+       // Make a fox application object.
+  MediaFusionApp app( "", "Abe Stephens -- SGI" );
+       app.init( argc, argv );
+
+       int width = 512;
+       int height = 512;
+
+       // Add an FMantaWindow.
+       FMantaWindow manta_window( &app, "Open-Source MANTA. Silicon Graphics 
Inc. and SCI Institute, University of Utah", width, height );
+       
+       // Create the application's windows.
+       app.create();
+
+       // Construct Manta.
+       RTRTInterface *manta_interface = createRTRT();
+       
+       manta_interface->setScenePath         (".");
+       manta_interface->changeNumWorkers     ( np );
+       manta_interface->selectImageType      ( "rgba8" );
+       // manta_interface->selectImageType      ( "rgbafloat" );
+       manta_interface->selectLoadBalancer   ( "workqueue" );
+       manta_interface->selectImageTraverser ( "tiled" );
+       // manta_interface->selectPixelSampler   ( "jittersample( 
-numberOfSamples 4 )" );
+       // manta_interface->setPixelSampler      ( new 
Histx_Manta::SingleSamplerCounter );
+       manta_interface->selectPixelSampler   ( "singlesample" );
+       manta_interface->selectRenderer       ( "raytracer" );
+       manta_interface->selectShadowAlgorithm( "hard" );
+       
+       // Camera *camera = new PinholeCamera( Point ( 0.0, 0.0, 0.0 ), Point 
( 0.0, -1.0, 0.0 ), Vector( 0.0, 0.0, 1.0 ), 60 );
+       
+       // Create the manta image frame.
+       FMantaImageFrame *manta_frame = manta_window.getMantaFrame();
+
+  std::cout << "X Window id: " << manta_frame->id() << std::endl;
+
+  // Set the target window id to intercept external events for.
+  app.setTargetId( manta_frame->id() );
+
+  
/////////////////////////////////////////////////////////////////////////////
+  // Create a SHMImageDisplay.
+  SHMImageDisplay image_display( shm_key );
+
+  
/////////////////////////////////////////////////////////////////////////////
+  // Create a user interface event listener for the shm segment.
+  MediaFusionBridge mf_bridge( (Window)manta_frame->id(),
+                               (Window)manta_frame->getRoot()->id(),
+                               (Display *)app.getDisplay(),
+                               shm_key, 0.5 );
+
+  // Have manta start the media fusion bridge after it has setup the 
SHMImageDisplay
+  manta_interface->addOneShotCallback(RTRTInterface::Absolute, 2,
+                Callback::create( &mf_bridge, 
&MediaFusionBridge::startup_callback));
+  
+       // Try to load a scene.
+       if ((scene_text == 0) || (!manta_interface->readScene( scene_text ))) 
{
+               // Create a default scene.
+               manta_interface->setScene( createDefaultScene() );
+       }
+
+       // Check to see if a bookmark file was specified.
+       if (bookmark_file_name.size() > 0) {
+
+               char description[128];
+               char specification[128];
+               ifstream file( bookmark_file_name.c_str() );
+               
+               if (file.is_open()) {
+                       while (!file.eof()) {
+                       
+                               file.getline( description, 128 );
+                               if (string(description).size() > 0) {
+                                       
+                                       file.getline( specification, 128 );
+                                       if (string(specification).size() > 0) 
{
+                                               
manta_window.addCameraBookmark( description, specification );
+                                       }
+                               }
+                       }
+                       
+                       file.close();
+               }
+               else {
+                       std::cerr << "Could not load bookmark file." << 
std::endl;
+               }
+       }
+
+  // Add a camera bookmark for the default camera.
+  manta_window.addCameraBookmark( "Default", default_camera );
+  
+       // Create the camera using the first camera bookmark.
+       Camera *camera = manta_interface->createCamera( 
manta_window.getCameraBookmark( 0 ) );
+  
+       // Create a default quake navigator.
+       FMantaQuakeNav *quake_nav = new FMantaQuakeNav( false );
+       quake_nav->setMantaInterface( manta_interface );
+       manta_window.addNavigatorOption( "Video Game", quake_nav );
+
+       // Create a default quake navigator.
+       FMantaQuakeNav *fly_nav = new FMantaQuakeNav( true );
+       fly_nav->setMantaInterface( manta_interface );
+       manta_window.addNavigatorOption( "Fly", fly_nav );
+
+       // Create a navigator for the image frame.
+       FMantaTrackballNav *trackball_nav = new FMantaTrackballNav();
+       trackball_nav->setMantaInterface( manta_interface );
+       trackball_nav->setMantaFrame( manta_frame );
+       trackball_nav->setMantaChannel( 0 );    
+       manta_window.addNavigatorOption("Trackball", trackball_nav );   
+
+       // Use the quake nav by default.
+       quake_nav->resetToCamera( 
camera->getPosition(),camera->getLookAt(),camera->getUp());
+       manta_window.setNavigator( quake_nav );
+
+       // Create manta channel for the interface.
+       int manta_channel = 0; // !!! See XWindowUI.cc line: 586
+       manta_interface->createChannel( &image_display, camera, use_stereo, 
width, height );
+
+       // Set the manta interface for the application.
+       manta_window.setMantaInterface( manta_interface, manta_channel );
+
+  // Check to see if we should enable the stereo dialog.
+  if (use_stereo) {
+    manta_window.addExtraOptionsDialog( "Stereo", new FMantaStereoDialog( 
&manta_window, "Stereo" ));
+  }
+  
+       // Check to see if the default scene was a kdtree.
+       Object *root_object = manta_interface->getScene()->getObject();
+       
+       
/////////////////////////////////////////////////////////////////////////////
+       // Create any necessary dialogs now since everything else should be 
initialized.
+       KDTree *kdtree = 0;
+       if ((kdtree = dynamic_cast<KDTree *>( root_object ))) {
+               
+               std::cout << "Building transparent tree." << std::endl;
+               
+               // Create a transparent kdtree.
+               TransparentKDTree *transparent_kdtree = 
+                       new TransparentKDTree( kdtree, new 
KDTreeCopyColorMaterial );
+
+               // XXX to be replaced
+               __global_transparent_kdtree = transparent_kdtree;
+               __global_kdtree = kdtree;
+               
+               // Create a new extra options dialog.
+               manta_window.addExtraOptionsDialog( "Transparency",
+      new DmDemoDialog( &manta_window, kdtree, transparent_kdtree, 
"Transparency" ));
+               
+       }
+       
+       
/////////////////////////////////////////////////////////////////////////////
+       // Start up manta.
+       manta_interface->beginRendering(false);
+       
+       // Start fox control loop.
+       return app.run();
+}      
+
+#include <Interface/LightSet.h>
+#include <Model/AmbientLights/ConstantAmbient.h>
+#include <Model/Backgrounds/ConstantBackground.h>
+#include <Model/Lights/PointLight.h>
+#include <Model/Textures/Constant.h>
+#include <Model/Textures/CheckerTexture.h>
+#include <Model/Materials/Phong.h>
+#include <Model/Groups/Group.h>
+#include <Model/Primitives/Parallelogram.h>
+#include <Model/Primitives/Sphere.h>
+#include <Model/TexCoordMappers/UniformMapper.h>
+
+Scene* createDefaultScene()
+{
+  // Create a default scene.  This scene is used for benchmarks, so
+  // please do not change it.  Please create a new scene instead
+  Scene* scene = new Scene();
+  scene->setBackground(new 
ConstantBackground(ColorDB::getNamedColor("SkyBlue3")*0.5));
+  Material* red=new Phong(Color(RGBColor(.6,0,0)),
+                          Color(RGBColor(.6,.6,.6)), 32, 0.4);
+       
+  Material* plane_matl = new Phong(new 
CheckerTexture<Color>(Color(RGBColor(.6,.6,.6)),
+                                                                             
                                                                              
                                                                              
       Color(RGBColor(0,0,0)),
+                                                                             
                                                                              
                                                                              
       Vector(1,0,0),
+                                                                             
                                                                              
                                                                              
       Vector(0,1,0)),
+                                                                             
                                                           new 
Constant<Color>(Color(RGBColor(.6,.6,.6))),
+                                                                             
                                                           32,
+                                                                             
                                                           new 
CheckerTexture<Real>((Real)0.2,
+                                                            (Real)0.5,
+                                                                             
                                                                              
                                                                              
              Vector(1,0,0),
+                                                                             
                                                                              
                                                                              
              Vector(0,1,0)));
+       
+       
+  Group* world = new Group();
+  Primitive* floor = new Parallelogram(plane_matl, Point(-20,-20,0),
+                                                                             
                                                                           
Vector(40,0,0), Vector(0,40,0));
+  // Setup world-space texture coordinates for the checkerboard floor
+  UniformMapper* uniformmap = new UniformMapper();
+  floor->setTexCoordMapper(uniformmap);
+  world->add(floor);
+  world->add(new Sphere(red, Point(0,0,1.2), 1.0));
+  scene->setObject(world);
+       
+  LightSet* lights = new LightSet();
+  lights->add(new PointLight(Point(0,5,8), Color(RGBColor(.6,.1,.1))));
+  lights->add(new PointLight(Point(5,0,8), Color(RGBColor(.1,.6,.1))));
+  lights->add(new PointLight(Point(5,5,2), Color(RGBColor(.2,.2,.2))));
+  lights->setAmbientLight(new ConstantAmbient(Color::black()));
+  scene->setLights(lights);
+  scene->getRenderParameters().maxDepth = 5;
+  return scene;
+}
+
+




  • [MANTA] r640 - in branches/itanium2: Core/Shm Engine/Display fox, abe, 10/21/2005

Archive powered by MHonArc 2.6.16.

Top of page