Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1007 - in trunk: Engine/Display Model/Groups SwigInterface UserInterface


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1007 - in trunk: Engine/Display Model/Groups SwigInterface UserInterface
  • Date: Thu, 13 Apr 2006 13:51:52 -0600 (MDT)

Author: bigler
Date: Thu Apr 13 13:51:51 2006
New Revision: 1007

Added:
   trunk/Engine/Display/SyncDisplay.cc
   trunk/Engine/Display/SyncDisplay.h
   trunk/UserInterface/SyncFrameAutomator.cc
   trunk/UserInterface/SyncFrameAutomator.h
Modified:
   trunk/Engine/Display/CMakeLists.txt
   trunk/Model/Groups/KDTree2.cc
   trunk/SwigInterface/manta.i
   trunk/SwigInterface/runmanta.py
   trunk/UserInterface/CMakeLists.txt
Log:

Engine/Display/CMakeLists.txt

  Added SyncDisplay.{cc,h}

Engine/Display/SyncDisplay.cc
Engine/Display/SyncDisplay.h

  New ImageDisplay that is designed to allow synchronization with an
  external entity.

Model/Groups/KDTree2.cc

  Only call rays.hit after looping over the triangle list.

  Changed some size_t's to unsigned int that weren't changed as
  needed.

SwigInterface/manta.i

  Added ImageDisplay, SyncDisplay, OpenGLDisplay

SwigInterface/runmanta.py

  Run with the SyncImage version of the ImageDisplay.

UserInterface/CMakeLists.txt

  Added SyncFrameAutomator.{cc,h}

  Alphabetized the files.
  
UserInterface/SyncFrameAutomator.cc
UserInterface/SyncFrameAutomator.h

  AutomatorUI that works in conjunction with the SyncDisplay.


Modified: trunk/Engine/Display/CMakeLists.txt
==============================================================================
--- trunk/Engine/Display/CMakeLists.txt (original)
+++ trunk/Engine/Display/CMakeLists.txt Thu Apr 13 13:51:51 2006
@@ -10,6 +10,8 @@
      Display/NullDisplay.h
      Display/OpenGLDisplay.cc
      Display/OpenGLDisplay.h
+     Display/SyncDisplay.cc
+     Display/SyncDisplay.h
 )
 
 

Added: trunk/Engine/Display/SyncDisplay.cc
==============================================================================
--- (empty file)
+++ trunk/Engine/Display/SyncDisplay.cc Thu Apr 13 13:51:51 2006
@@ -0,0 +1,117 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2005-2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  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 <Engine/Display/SyncDisplay.h>
+#include <Interface/ImageDisplay.h>
+#include <Interface/Context.h>
+#include <Core/Thread/Semaphore.h>
+
+#include <sgi_stl_warnings_off.h>
+#include <iostream>
+#include <sgi_stl_warnings_on.h>
+
+#include <Core/Thread/Mutex.h>
+SCIRun::Mutex sync_lock("SyncDisplay io lock");
+
+using namespace Manta;
+using namespace std;
+
+SyncDisplay::SyncDisplay(const vector<string>& args)
+  : child_display(NULL),
+    self_created_child(false),
+    current_context(NULL),
+    current_image(NULL),
+    _frameready("SyncDisplay::_frameready", 1),
+    _framedone("SyncDisplay::_framedone", 1)
+{
+  _frameready.down();
+  _framedone.down();
+
+  // Possibly add a factory call to make child_display from args.
+}
+
+SyncDisplay::~SyncDisplay()
+{
+  if (self_created_child) {
+    delete child_display;
+  }
+}
+
+void
+SyncDisplay::setupDisplayChannel(SetupContext& context)
+{
+  if (child_display) child_display->setupDisplayChannel(context);
+}
+
+void
+SyncDisplay::displayImage(const DisplayContext& context,
+                          const Image* image)
+{
+  if(context.proc != 0)
+    return;
+  current_context = &(context);
+  current_image = image;
+  //  sync_lock.lock(); cerr << "di::_frameready.up() .. \n"; 
sync_lock.unlock();
+  _frameready.up();
+  //  sync_lock.lock(); cerr << "di::_frameready.up() .. done\n"; 
sync_lock.unlock();
+  //  sync_lock.lock(); cerr << "di::_framedone.down() .. \n"; 
sync_lock.unlock();
+  _framedone.down();
+  //  sync_lock.lock(); cerr << "di::_framedone.down() .. done\n"; 
sync_lock.unlock();
+}
+
+void
+SyncDisplay::setChild(ImageDisplay* child_in)
+{
+  if (self_created_child) {
+    // destroy the old child
+    delete child_display;
+    self_created_child = false;
+  }
+  child_display = child_in;
+}
+
+bool
+SyncDisplay::frameReady()
+{
+  return _frameready.tryDown();
+}
+
+void
+SyncDisplay::renderFrame()
+{
+  // _frameready should already be locked at this point by the
+  // frameReady call.
+  child_display->displayImage(*current_context, current_image);
+}
+
+void
+SyncDisplay::doneRendering() {
+  //  sync_lock.lock(); cerr << "dr::_framedone.up() .. \n"; 
sync_lock.unlock();
+  _framedone.up();
+  //  sync_lock.lock(); cerr << "dr::_framedone.up() .. done\n"; 
sync_lock.unlock();
+}

Added: trunk/Engine/Display/SyncDisplay.h
==============================================================================
--- (empty file)
+++ trunk/Engine/Display/SyncDisplay.h  Thu Apr 13 13:51:51 2006
@@ -0,0 +1,97 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2005-2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  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 Manta_Engine_SyncDisplay_h
+#define Manta_Engine_SyncDisplay_h
+
+#include <Interface/ImageDisplay.h>
+#include <Core/Thread/Semaphore.h>
+
+#include <sgi_stl_warnings_off.h>
+#include <string>
+#include <vector>
+#include <sgi_stl_warnings_on.h>
+
+/*
+  The code that wants to render should have something that looks like this:
+
+  for(;;) {
+    if (syncd->frameReady()) {
+      syncd->renderFrame();
+      syncd->doneRendering();
+    }
+  }
+
+  If you don't want to render the frame you must still call
+  doneRendering to relsease the lock on the frame resources.
+  
+    if (syncd->frameReady()) {
+      if (really_want_to_render)
+        syncd->renderFrame();
+      syncd->doneRendering();
+    }
+*/
+
+namespace Manta {
+  class SetupContext;
+  class DisplayContext;
+  class ImageDisplay;
+  class Image;
+
+  using namespace std;
+
+  class SyncDisplay: public ImageDisplay {
+  public:
+    SyncDisplay(const vector<string>& args);
+    virtual ~SyncDisplay();
+    virtual void setupDisplayChannel(SetupContext&);
+    virtual void displayImage(const DisplayContext& context,
+                             const Image* image);
+
+    void setChild(ImageDisplay* child_in);
+    bool frameReady();
+    void renderFrame();
+    void doneRendering();
+  private:
+    SyncDisplay(const SyncDisplay&);
+    SyncDisplay& operator=(const SyncDisplay&);
+
+    // This is what will actually do the displaying
+    ImageDisplay* child_display;
+    // Whether this class created the child or not
+    bool self_created_child;
+    // Temporaries to be passed to the child's displayImage
+    DisplayContext const* current_context;
+    Image const* current_image;
+
+    SCIRun::Semaphore _frameready;
+    SCIRun::Semaphore _framedone;
+  };
+}
+
+#endif

Modified: trunk/Model/Groups/KDTree2.cc
==============================================================================
--- trunk/Model/Groups/KDTree2.cc       (original)
+++ trunk/Model/Groups/KDTree2.cc       Thu Apr 13 13:51:51 2006
@@ -279,6 +279,7 @@
     // now, have a leaf
     if (node->listLen > 0) {
       int hit_tri = -1;
+      float minT = data->minT[which];
 //       fprintf(stderr, "node(%u): listBegin = %u, listLen = %u\n",
 //               (rootNode-node)/sizeof(Node), node->listBegin, 
node->listLen);
       for (int tri_index=node->listBegin;
@@ -308,7 +309,7 @@
 
         const float f = f0 * nd;
         // plane test
-        if ( f < T_EPSILON || f > data->minT[which] )
+        if ( f < T_EPSILON || f > minT )
           continue;
 
         const float hu = org_ku + f*dir_ku;
@@ -323,16 +324,22 @@
         if ( mue < 0.f || mue + lambda > 1.f )
           continue;
 
-        if (rays.hit(which, f, getMaterial(), this, getTexCoordMapper())) {
-//           if (tri_index > 11)
-//             fprintf(stderr, "hit_tri = %d, tri_index = %d\n", hit_tri, 
tri_index);
+        if (f < minT) {
           hit_tri = tri_indices[tri_index];
+          minT = f;
         }
+//         if (rays.hit(which, f, getMaterial(), this, getTexCoordMapper())) 
{
+// //           if (tri_index > 11)
+// //             fprintf(stderr, "hit_tri = %d, tri_index = %d\n", hit_tri, 
tri_index);
+//           hit_tri = tri_indices[tri_index];
+//         }
       }
       if (hit_tri >= 0) {
-        ScratchData sd;
-        sd.tri_index = hit_tri;
-        rays.scratchpad<ScratchData>(which) = sd;
+        if (rays.hit(which, minT, getMaterial(), this, getTexCoordMapper())) 
{
+          ScratchData sd;
+          sd.tri_index = hit_tri;
+          rays.scratchpad<ScratchData>(which) = sd;
+        }
       }
       if (data->minT[which] < far) return;
     }
@@ -370,7 +377,7 @@
 
 // Returns 0 on success
 int
-KDTree2::reserveTriangles(size_t num_tris_in) {
+KDTree2::reserveTriangles(unsigned int num_tris_in) {
   triangles = static_cast<Triangle*>(malloc(num_tris_in*sizeof(Triangle)));
   if (triangles) {
     num_tris = num_tris_in;
@@ -382,7 +389,7 @@
         
 // Returns 0 on success
 int
-KDTree2::reserveTriangleIndices(size_t num_tri_indices_in) {
+KDTree2::reserveTriangleIndices(unsigned int num_tri_indices_in) {
   tri_indices =
     static_cast<unsigned int*>(malloc(num_tri_indices_in*sizeof(Triangle)));
   if (tri_indices) {

Modified: trunk/SwigInterface/manta.i
==============================================================================
--- trunk/SwigInterface/manta.i (original)
+++ trunk/SwigInterface/manta.i Thu Apr 13 13:51:51 2006
@@ -67,6 +67,8 @@
 
 namespace std {
   %template(vectorStr) vector<string>;
+
+  
 };
 
 %include <Interface/UserInterface.h>
@@ -170,6 +172,33 @@
   };
   
 }
+
+///////////////////////////////////////////////////////
+// ImageDisplay
+%{
+#include <Interface/ImageDisplay.h>
+#include <Engine/Display/SyncDisplay.h>
+#include <Engine/Display/OpenGLDisplay.h>
+%}
+
+%include <Interface/ImageDisplay.h>
+%include <Engine/Display/SyncDisplay.h>
+%include <Engine/Display/OpenGLDisplay.h>
+
+///////////////////////////////////////////////////////
+// UI
+%{
+#include <Interface/UserInterface.h>
+#include <UserInterface/AutomatorUI.h>
+#include <UserInterface/SyncFrameAutomator.h>
+%}
+
+%include <Interface/UserInterface.h>
+%include <UserInterface/AutomatorUI.h>
+%include <UserInterface/SyncFrameAutomator.h>
+
+///////////////////////////////////////////////////////
+//
 
 %{
 #include <Core/Geometry/Ray.h>

Modified: trunk/SwigInterface/runmanta.py
==============================================================================
--- trunk/SwigInterface/runmanta.py     (original)
+++ trunk/SwigInterface/runmanta.py     Thu Apr 13 13:51:51 2006
@@ -106,7 +106,14 @@
 def addXInterface(engine, camera, xres, yres):
     xinterface = engine.createUserInterface("X")
     xinterface.startup()
-    engine.createChannel("opengl", camera, False, xres, yres)
+    args = vectorStr()
+    ogl_display = manta_new(OpenGLDisplay(args))
+    sync_display = manta_new(SyncDisplay(args))
+    sync_display.setChild(ogl_display)
+    sync_automator = manta_new(SyncFrameAutomator(engine, sync_display))
+    sync_automator.startup()
+    engine.createChannel(sync_display, camera, False, xres, yres)
+#    engine.createChannel("opengl", camera, False, xres, yres)
 
 def addNullInterface(engine, camera, xres, yres):
     ui = engine.createUserInterface("null")

Modified: trunk/UserInterface/CMakeLists.txt
==============================================================================
--- trunk/UserInterface/CMakeLists.txt  (original)
+++ trunk/UserInterface/CMakeLists.txt  Thu Apr 13 13:51:51 2006
@@ -1,15 +1,18 @@
 
 ADD_LIBRARY (Manta_UserInterface
-            PromptUI.h 
-            PromptUI.cc
-            XWindowUI.h 
-            XWindowUI.cc
-            NullUI.h
-            AutomatorUI.h
-            AutomatorUI.cc
-            CameraPathAutomator.h
-            CameraPathAutomator.cc
-            )
+  AutomatorUI.h
+  AutomatorUI.cc
+  CameraPathAutomator.h
+  CameraPathAutomator.cc
+  NullUI.h
+  PromptUI.h
+  PromptUI.cc
+  SyncFrameAutomator.cc
+  SyncFrameAutomator.h
+  XWindowUI.h
+  XWindowUI.cc
+  )
+
 TARGET_LINK_LIBRARIES(Manta_UserInterface Manta_Interface
                       Manta_Core_XUtils Manta_Core)
 TARGET_LINK_LIBRARIES(Manta_UserInterface ${OPENGL_LIBRARIES} 
${X11_LIBRARIES})

Added: trunk/UserInterface/SyncFrameAutomator.cc
==============================================================================
--- (empty file)
+++ trunk/UserInterface/SyncFrameAutomator.cc   Thu Apr 13 13:51:51 2006
@@ -0,0 +1,86 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2005
+  Scientific Computing and Imaging Institue, University of Utah
+
+  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 <UserInterface/SyncFrameAutomator.h>
+
+#include <sgi_stl_warnings_off.h>
+#include <iostream>
+#include <sgi_stl_warnings_on.h>
+
+#include <unistd.h>
+
+#include <Core/Thread/Mutex.h>
+extern SCIRun::Mutex sync_lock;
+
+using namespace Manta;
+using namespace std;
+
+SyncFrameAutomator::SyncFrameAutomator( MantaInterface* manta_interface_,
+                                        SyncDisplay* syncd)
+  : AutomatorUI(manta_interface_),
+    syncd(syncd)
+{
+}
+
+SyncFrameAutomator::~SyncFrameAutomator()
+{
+}
+
+// Create method called by RTRT_register.
+UserInterface*
+SyncFrameAutomator::create( const vector<string>& args,
+                            MantaInterface* manta_interface_ )
+{
+#if 0
+  // Create the SyncDisplay
+  SyncDisplay* syncd = new Syncd(args);
+  // Create the ImageDisplay
+  ImageDisplay* id = NULL; // ??(args);
+  return new SyncFrameAutomator(manta_interface_, syncd);
+#else
+  return NULL;
+#endif
+}
+
+// Implementation of the interpolator.
+void
+SyncFrameAutomator::run_automator()
+{
+  cerr << "SyncFrameAutomator::run_automator(): start\n";
+  for(;;) {
+    if (syncd->frameReady()) {
+      syncd->renderFrame();
+      syncd->doneRendering();
+    } else {
+      // Wait for a little bit
+      usleep(10);
+    }
+  }
+  cerr << "SyncFrameAutomator::run_automator(): end\n";
+}
+

Added: trunk/UserInterface/SyncFrameAutomator.h
==============================================================================
--- (empty file)
+++ trunk/UserInterface/SyncFrameAutomator.h    Thu Apr 13 13:51:51 2006
@@ -0,0 +1,63 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2005
+  Scientific Computing and Imaging Institue, University of Utah
+
+  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 Manta_UserInterface_SyncFrameAutomator_h
+#define Manta_UserInterface_SyncFrameAutomator_h
+
+#include <UserInterface/AutomatorUI.h>
+#include <Engine/Display/SyncDisplay.h>
+
+#include <sgi_stl_warnings_off.h>
+#include <string>
+#include <vector>
+#include <sgi_stl_warnings_on.h>
+
+namespace Manta {
+
+  using std::string;
+  using std::vector;
+
+  class SyncFrameAutomator : public AutomatorUI {
+  private:
+    SyncDisplay* syncd;
+  public:
+    SyncFrameAutomator( MantaInterface* manta_interface_,
+                        SyncDisplay* syncd);
+    virtual ~SyncFrameAutomator();
+
+    // Create method called by RTRT_register.
+    static UserInterface* create( const vector<string>& args,
+                                  MantaInterface* manta_interface_ );
+
+    // Implementation of the interpolator.
+    virtual void run_automator();
+
+  };
+} // end namespace Manta
+
+#endif // ifndef Manta_UserInterface_SyncFrameAutomator_h




  • [MANTA] r1007 - in trunk: Engine/Display Model/Groups SwigInterface UserInterface, bigler, 04/13/2006

Archive powered by MHonArc 2.6.16.

Top of page