Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r358 - in trunk: Engine/Control Engine/Display Image


Chronological Thread 
  • From: aek@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r358 - in trunk: Engine/Control Engine/Display Image
  • Date: Mon, 30 May 2005 18:13:34 -0600 (MDT)

Author: aek
Date: Mon May 30 18:13:34 2005
New Revision: 358

Added:
   trunk/Engine/Display/FileDisplay.cc
   trunk/Engine/Display/FileDisplay.h
Modified:
   trunk/Engine/Control/RTRT_register.cc
   trunk/Engine/Display/CMakeLists.txt
   trunk/Image/Pixel.h
Log:
* Added new display type: FileDisplay.  Currently outputs a numbered
  sequence of TGA images.  Used with a video encoder like MEncoder, this
  can create high-quality video files.

* Fixed a typo in Image/Pixel.h -- one of the conversions mixed up blue and
  green values.



Modified: trunk/Engine/Control/RTRT_register.cc
==============================================================================
--- trunk/Engine/Control/RTRT_register.cc       (original)
+++ trunk/Engine/Control/RTRT_register.cc       Mon May 30 18:13:34 2005
@@ -1,6 +1,7 @@
 #include <Interface/RTRTInterface.h>
 #include <Engine/Display/NullDisplay.h>
 #include <Engine/Display/OpenGLDisplay.h>
+#include <Engine/Display/FileDisplay.h>
 #include <Engine/IdleModes/ZoomIdleMode.h>
 #include <Engine/ImageTraversers/NullImageTraverser.h>
 #include <Engine/ImageTraversers/TiledImageTraverser.h>
@@ -43,6 +44,7 @@
     // Register display components
     rtrt->registerComponent("null", &NullDisplay::create);
     rtrt->registerComponent("opengl", &OpenGLDisplay::create);
+    rtrt->registerComponent("file", &FileDisplay::create);
 
     // Register image traversers
     rtrt->registerComponent("null", &NullImageTraverser::create);

Modified: trunk/Engine/Display/CMakeLists.txt
==============================================================================
--- trunk/Engine/Display/CMakeLists.txt (original)
+++ trunk/Engine/Display/CMakeLists.txt Mon May 30 18:13:34 2005
@@ -2,5 +2,6 @@
 SET (Manta_Display_SRCS
      Display/NullDisplay.cc
      Display/OpenGLDisplay.cc
+     Display/FileDisplay.cc
      Display/XHelper.cc
      )

Added: trunk/Engine/Display/FileDisplay.cc
==============================================================================
--- (empty file)
+++ trunk/Engine/Display/FileDisplay.cc Mon May 30 18:13:34 2005
@@ -0,0 +1,152 @@
+
+#include <fstream>
+#include <sstream>
+#include <iomanip>
+#include <Engine/Display/FileDisplay.h>
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Exceptions/InternalError.h>
+#include <Core/Util/NotFinished.h>
+#include <Image/NullImage.h>
+#include <Image/Pixel.h>
+#include <Image/SimpleImage.h>
+
+using namespace Manta;
+using namespace std;
+using SCIRun::IllegalValue;
+using SCIRun::InternalError;
+
+ImageDisplay *FileDisplay::create(
+  const vector< string > &args )
+{
+  return new FileDisplay(args);
+}
+
+FileDisplay::FileDisplay(
+  const vector<string> &args )
+{
+  if( args.size() != 1 )
+    throw IllegalArgument( "FileDisplay", 0, args );
+  baseName = args[ 0 ];
+  currentFrame = 0;
+}
+
+FileDisplay::~FileDisplay()
+{
+}
+
+void FileDisplay::setupDisplayChannel(
+  SetupContext & )
+{
+}
+
+void FileDisplay::displayImage(
+  const DisplayContext &context,
+  const Image *image )
+{
+  bool stereo;
+  int xres, yres;
+  image->getResolution( stereo, xres, yres );
+  if ( stereo ) {
+    stringstream lss, rss;
+    lss << baseName << "_left_" << setfill( '0' ) << setw( 5 ) << 
currentFrame << ".tga";
+    rss << baseName << "_right_" << setfill( '0' ) << setw( 5 ) << 
currentFrame << ".tga";
+    string left = lss.str();
+    string right = rss.str();
+    writeTGA( image, left, 0 );
+    writeTGA( image, right, 1 );
+  } else {
+    stringstream ss;
+    ss << baseName << "_" << setfill( '0' ) << setw( 5 ) << currentFrame << 
".tga";
+    string name = ss.str();
+    writeTGA( image, name, 0 );
+  }
+  ++currentFrame;
+}
+
+// TODO: TGA supports 32 bpp images with an alpha channel.  Make RGBA
+// images write out the alpha.
+void FileDisplay::writeTGA(
+  const Image *image,
+  string &filename,
+  int eye )
+{
+  ofstream out( filename.c_str(), std::ios::out | std::ios::binary );
+  if ( !out )
+    throw InternalError( "Couldn't open TGA file for writing: " + filename );
+  char const header_part_1[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+  out.write( header_part_1, 12 );
+  bool stereo;
+  int xres, yres;
+  image->getResolution( stereo, xres, yres );
+  out.put( xres & 0xFF );
+  out.put( xres >> 8 );
+  out.put( yres & 0xFF );
+  out.put( yres >> 8 );
+  char const header_part_2[] = { 24, 0 };
+  out.write( header_part_2, 2 );
+  if ( typeid( *image ) == typeid( SimpleImage< RGBA8Pixel > ) ) {
+    const SimpleImage< RGBA8Pixel > *si = dynamic_cast< const SimpleImage< 
RGBA8Pixel > * >( image );
+    RGBA8Pixel const *buffer = si->getRaw( eye );
+    for ( int y = 0; y < yres; ++y )
+      for ( int x = 0; x < xres; ++x )
+      {
+        out.put( buffer->b );
+        out.put( buffer->g );
+        out.put( buffer->r );
+        ++buffer;
+      }
+  } else if ( typeid( *image ) == typeid( SimpleImage< RGB8Pixel > ) ) {
+    const SimpleImage< RGB8Pixel > *si = dynamic_cast< const SimpleImage< 
RGB8Pixel > * >( image );
+    RGB8Pixel const *buffer = si->getRaw( eye );
+    for ( int y = 0; y < yres; ++y )
+      for ( int x = 0; x < xres; ++x )
+      {
+        out.put( buffer->b );
+        out.put( buffer->g );
+        out.put( buffer->r );
+        ++buffer;
+      }
+  } else if ( typeid( *image ) == typeid( SimpleImage< RGBAfloatPixel > ) ) {
+    const SimpleImage< RGBAfloatPixel > *si = dynamic_cast< const 
SimpleImage< RGBAfloatPixel > * >( image );
+    RGBAfloatPixel const *buffer = si->getRaw( eye );
+    for ( int y = 0; y < yres; ++y )
+      for ( int x = 0; x < xres; ++x )
+      {
+        float b = buffer->b;
+        b = b < 0.0f ? 0.0f : b;
+        b = b > 1.0f ? 1.0f : b;
+        out.put( static_cast< unsigned char >( b * 255.0f ) );
+        float g = buffer->g;
+        g = g < 0.0f ? 0.0f : g;
+        g = g > 1.0f ? 1.0f : g;
+        out.put( static_cast< unsigned char >( g * 255.0f ) );
+        float r = buffer->r;
+        r = r < 0.0f ? 0.0f : r;
+        r = r > 1.0f ? 1.0f : r;
+        out.put( static_cast< unsigned char >( r * 255.0f ) );
+        ++buffer;
+      }
+  } else if ( typeid( *image ) == typeid( SimpleImage< RGBfloatPixel > ) ) {
+    const SimpleImage< RGBfloatPixel > *si = dynamic_cast< const 
SimpleImage< RGBfloatPixel > * >( image );
+    RGBfloatPixel const *buffer = si->getRaw( eye );
+    for ( int y = 0; y < yres; ++y )
+      for ( int x = 0; x < xres; ++x )
+      {
+        float b = buffer->b;
+        b = b < 0.0f ? 0.0f : b;
+        b = b > 1.0f ? 1.0f : b;
+        out.put( static_cast< unsigned char >( b * 255.0f ) );
+        float g = buffer->g;
+        g = g < 0.0f ? 0.0f : g;
+        g = g > 1.0f ? 1.0f : g;
+        out.put( static_cast< unsigned char >( g * 255.0f ) );
+        float r = buffer->r;
+        r = r < 0.0f ? 0.0f : r;
+        r = r > 1.0f ? 1.0f : r;
+        out.put( static_cast< unsigned char >( r * 255.0f ) );
+        ++buffer;
+      }
+  } else {
+    throw InternalError( "Unknown image type in FileDisplay");
+  }
+}

Added: trunk/Engine/Display/FileDisplay.h
==============================================================================
--- (empty file)
+++ trunk/Engine/Display/FileDisplay.h  Mon May 30 18:13:34 2005
@@ -0,0 +1,31 @@
+
+#ifndef Manta_Engine_FileDisplay_h
+#define Manta_Engine_FileDisplay_h
+
+#include <Interface/ImageDisplay.h>
+#include <sgi_stl_warnings_off.h>
+#include <string>
+#include <vector>
+#include <sgi_stl_warnings_on.h>
+
+namespace Manta {
+  using namespace std;
+  class FileDisplay : public ImageDisplay {
+  public:
+    FileDisplay(const vector<string>& args);
+    virtual ~FileDisplay();
+    virtual void setupDisplayChannel(SetupContext&);
+    virtual void displayImage(const DisplayContext& context,
+                             const Image* image);
+    static ImageDisplay* create(const vector<string>& args);
+  protected:
+    virtual void writeTGA( const Image *image, string &filename, int eye );
+    string baseName;
+    int currentFrame;
+  private:
+    FileDisplay(const FileDisplay&);
+    FileDisplay& operator=(const FileDisplay&);
+  };
+}
+
+#endif

Modified: trunk/Image/Pixel.h
==============================================================================
--- trunk/Image/Pixel.h (original)
+++ trunk/Image/Pixel.h Mon May 30 18:13:34 2005
@@ -60,7 +60,7 @@
     p.g = (unsigned char)(g*255.f);
     float b = c.b();
     b = b<0.f?0.f:b;
-    b = b>1.f?1.f:g;
+    b = b>1.f?1.f:b;
     p.b = (unsigned char)(b*255.f);
 #if SLOWER_VERSION
     float r = c.r() < 0.f?0.f: c.r() > 1.f? 1.f : c.r();




  • [MANTA] r358 - in trunk: Engine/Control Engine/Display Image, aek, 05/30/2005

Archive powered by MHonArc 2.6.16.

Top of page