Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r381 - in trunk: Engine/Display Image Model/Textures scenes


Chronological Thread 
  • From: aek@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r381 - in trunk: Engine/Display Image Model/Textures scenes
  • Date: Mon, 13 Jun 2005 18:24:41 -0600 (MDT)

Author: aek
Date: Mon Jun 13 18:24:40 2005
New Revision: 381

Added:
   trunk/Image/TGAFile.cc
   trunk/Image/TGAFile.h
   trunk/Model/Textures/ImageTexture.cc
   trunk/Model/Textures/ImageTexture.h
Modified:
   trunk/Engine/Display/FileDisplay.cc
   trunk/Engine/Display/FileDisplay.h
   trunk/Engine/Display/sub.mk
   trunk/Image/CMakeLists.txt
   trunk/Image/sub.mk
   trunk/scenes/primtest.cc
Log:
* Moved support from TGA writing code from FileDisplay to its own module.
* Added 32-bit (alpha) support to TGA writing code
* Added TGA file reader (only 24-bit and 32-bit uncompressed True-color 
currently)
* Added image-based texture mapping. Use "-material image -image
  texture.tga" with primtest to try it.  Defaults to texture.tga in the
  current directory.  Sample available at 
http://www.cs.utah.edu/~aek/manta/texture.tga
  Screenshot at http://www.cs.utah.edu/manta/textures.jpg



Modified: trunk/Engine/Display/FileDisplay.cc
==============================================================================
--- trunk/Engine/Display/FileDisplay.cc (original)
+++ trunk/Engine/Display/FileDisplay.cc Mon Jun 13 18:24:40 2005
@@ -9,6 +9,7 @@
 #include <Image/NullImage.h>
 #include <Image/Pixel.h>
 #include <Image/SimpleImage.h>
+#include <Image/TGAFile.h>
 
 using namespace Manta;
 using namespace std;
@@ -61,92 +62,4 @@
     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");
-  }
 }

Modified: trunk/Engine/Display/FileDisplay.h
==============================================================================
--- trunk/Engine/Display/FileDisplay.h  (original)
+++ trunk/Engine/Display/FileDisplay.h  Mon Jun 13 18:24:40 2005
@@ -19,7 +19,6 @@
                              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:

Modified: trunk/Engine/Display/sub.mk
==============================================================================
--- trunk/Engine/Display/sub.mk (original)
+++ trunk/Engine/Display/sub.mk Mon Jun 13 18:24:40 2005
@@ -6,7 +6,8 @@
 
 SRCS += \
    $(SRCDIR)/NullDisplay.cc \
-   $(SRCDIR)/OpenGLDisplay.cc
+   $(SRCDIR)/OpenGLDisplay.cc \
+   $(SRCDIR)/FileDisplay.cc
 
 PSELIBS := Packages/Manta/Core/Exceptions Packages/Manta/Core/Util \
        Packages/Manta/Image Packages/Manta/Interface Core/Exceptions

Modified: trunk/Image/CMakeLists.txt
==============================================================================
--- trunk/Image/CMakeLists.txt  (original)
+++ trunk/Image/CMakeLists.txt  Mon Jun 13 18:24:40 2005
@@ -1,3 +1,3 @@
 
-ADD_LIBRARY (Manta_Image NullImage.cc)
+ADD_LIBRARY (Manta_Image NullImage.cc TGAFile.cc)
 TARGET_LINK_LIBRARIES(Manta_Image Manta_Interface SCIRun_Core)

Added: trunk/Image/TGAFile.cc
==============================================================================
--- (empty file)
+++ trunk/Image/TGAFile.cc      Mon Jun 13 18:24:40 2005
@@ -0,0 +1,204 @@
+
+#include <fstream>
+#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 std;
+using SCIRun::IllegalValue;
+using SCIRun::InternalError;
+
+namespace Manta
+{
+
+  static inline void writeShort(
+    ofstream &out,
+    int const value )
+  {
+    out.put( value & 0xFF );
+    out.put( ( value >> 8 ) & 0xFF );
+  }
+
+  static inline void writeLong(
+    ofstream &out,
+    int const value )
+  {
+    out.put( value & 0xFF );
+    out.put( ( value >> 8 ) & 0xFF );
+    out.put( ( value >> 16 ) & 0xFF );
+    out.put( ( value >> 24 ) & 0xFF );
+  }
+
+  void writeTGA(
+    Image const *image,
+    string const &filename,
+    int const eye )
+  {
+    ofstream out( filename.c_str(), ios::out | ios::binary );
+    if ( !out )
+      throw InternalError( "Couldn't open TGA file for writing: " + filename 
);
+    out.put( 0 );                 // ID length: 0
+    out.put( 0 );                 // Color map type: None
+    out.put( 2 );                 // Image type: uncompressed, true-color 
image
+    writeShort( out, 0 );         // Color map first entry index
+    writeShort( out, 0 );         // Color map length
+    out.put( 0 );                 // Color map entry size
+    writeShort( out, 0 );         // X-origin of image (left)
+    writeShort( out, 0 );         // Y-origin of image (bottom)
+    bool stereo;
+    int xres, yres;
+    image->getResolution( stereo, xres, yres );
+    writeShort( out, xres );      // Image width
+    writeShort( out, yres );      // Image height
+    if ( typeid( *image ) == typeid( SimpleImage< RGBA8Pixel > ) ) {
+      out.put( 32 );              // Pixel depth: 32bpp
+      out.put( 8 );               // Image descriptor: 8 bits of alpha, 
bottom-left origin
+      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 );
+          out.put( buffer->a );
+          ++buffer;
+        }
+    } else if ( typeid( *image ) == typeid( SimpleImage< RGB8Pixel > ) ) {
+      out.put( 24 );              // Pixel depth: 24bpp
+      out.put( 0 );               // Image descriptor: 0 bits of alpha, 
bottom-left origin
+      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 > ) 
) {
+      out.put( 32 );              // Pixel depth: 32bpp
+      out.put( 8 );               // Image descriptor: 8 bits of alpha, 
bottom-left origin
+      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 ) );
+          float a = buffer->a;
+          a = a < 0.0f ? 0.0f : a;
+          a = a > 1.0f ? 1.0f : a;
+          out.put( static_cast< unsigned char >( a * 255.0f ) );
+          ++buffer;
+        }
+    } else if ( typeid( *image ) == typeid( SimpleImage< RGBfloatPixel > ) ) 
{
+      out.put( 24 );              // Pixel depth: 24bpp
+      out.put( 0 );               // Image descriptor: 0 bits of alpha, 
bottom-left origin
+      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 writeTGA()" );
+    }
+  }
+
+  static inline int readShort(
+    ifstream &in )
+  {
+    int byte_1 = in.get();
+    int byte_2 = in.get();
+    return byte_1 | ( byte_2 << 8 );
+  }
+
+  static inline int readLong(
+    ifstream &in )
+  {
+    int byte_1 = in.get();
+    int byte_2 = in.get();
+    int byte_3 = in.get();
+    int byte_4 = in.get();
+    return byte_1 | ( byte_2 << 8 ) | ( byte_2 << 16 ) | ( byte_2 << 24 );
+  }
+
+  Image *readTGA(
+    string const &filename )
+  {
+    ifstream in( filename.c_str(), ios::in | ios::binary );
+    if ( !in )
+      throw InternalError( "Couldn't open TGA file for reading: " + filename 
);
+    int id_length = in.get();
+    int color_map_type = in.get();
+    if ( color_map_type != 0 )
+      throw InternalError( "Color map TGA files currently unsupported" );
+    int image_type = in.get();
+    if ( image_type != 2 )
+      throw InternalError( "Only uncompressed true-color TGA files currently 
supported" );
+    int color_map_first_entry_index = readShort( in );
+    int color_map_length = readShort( in );
+    int color_map_entry_size = in.get();
+    int x_origin = readShort( in );
+    int y_origin = readShort( in );
+    int width = readShort( in );
+    int height = readShort( in );
+    int pixel_depth = in.get();
+    int image_descriptor = in.get();
+    in.ignore( id_length );
+    if ( pixel_depth == 24 && ( image_descriptor & 15 ) == 0 ) {
+      SimpleImage< RGB8Pixel > *si = new SimpleImage< RGB8Pixel >( false, 
width, height );
+      RGB8Pixel *buffer = const_cast< RGB8Pixel * >( si->getRaw( 0 ) );
+      for ( int y = 0; y < height; ++y )
+        for ( int x = 0; x < width; ++x ) {
+          RGB8Pixel *offset = ( buffer +
+                                ( image_descriptor & 32 ? height - y : y ) * 
width +
+                                ( image_descriptor & 16 ? width - x : x ) );
+          offset->b = in.get();
+          offset->g = in.get();
+          offset->r = in.get();
+        }
+      return si;
+    } else if ( pixel_depth == 32 && ( image_descriptor & 15 ) == 8 ) {
+      SimpleImage< RGBA8Pixel > *si = new SimpleImage< RGBA8Pixel >( false, 
width, height );
+      RGBA8Pixel *buffer = const_cast< RGBA8Pixel * >( si->getRaw( 0 ) );
+      for ( int y = 0; y < height; ++y )
+        for ( int x = 0; x < width; ++x ) {
+          RGBA8Pixel *offset = ( buffer +
+                                 ( image_descriptor & 32 ? height - y : y ) 
* width +
+                                 ( image_descriptor & 16 ? width - x : x ) );
+          offset->b = in.get();
+          offset->g = in.get();
+          offset->r = in.get();
+          offset->a = in.get();
+        }
+      return si;
+    }
+    throw InternalError( "Unhandled pixel depth and alpha for TGA files" );
+  }
+
+}

Added: trunk/Image/TGAFile.h
==============================================================================
--- (empty file)
+++ trunk/Image/TGAFile.h       Mon Jun 13 18:24:40 2005
@@ -0,0 +1,16 @@
+
+#ifndef Manta_Engine_TGAFile_h
+#define Manta_Engine_TGAFile_h
+
+#include <string>
+
+namespace Manta {
+
+    class Image;
+
+    void writeTGA( Image const *image, std::string const &filename, int 
const eye );
+    Image *readTGA( std::string const &filename );
+
+}
+
+#endif

Modified: trunk/Image/sub.mk
==============================================================================
--- trunk/Image/sub.mk  (original)
+++ trunk/Image/sub.mk  Mon Jun 13 18:24:40 2005
@@ -6,7 +6,8 @@
 
 SRCS += \
    $(SRCDIR)/NullImage.cc \
-   $(SRCDIR)/SimpleImage_templates.cc
+   $(SRCDIR)/SimpleImage_templates.cc \
+   $(SRCDIR)/TGAFile.cc
 
 PSELIBS := Packages/Manta/Interface Core/Exceptions
 LIBS := 

Added: trunk/Model/Textures/ImageTexture.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/ImageTexture.cc        Mon Jun 13 18:24:40 2005
@@ -0,0 +1,89 @@
+
+#include <Model/Textures/ImageTexture.h>
+#include <Interface/RayPacket.h>
+#include <Core/Geometry/PointVector.h>
+#include <Core/Math/Noise.h>
+#include <Core/Math/MiscMath.h>
+#include <Core/Exceptions/InternalError.h>
+#include <Image/NullImage.h>
+#include <Image/Pixel.h>
+#include <Image/SimpleImage.h>
+
+namespace Manta {
+
+  ImageTexture::ImageTexture(
+      Image *img,
+      double x_scale,
+      double y_scale )
+      : img( img ),
+        x_scale( x_scale ),
+        y_scale( y_scale )
+  {
+  }
+
+  ImageTexture::~ImageTexture()
+  {
+      delete img;
+  }
+
+  void ImageTexture::mapValues(
+    RenderContext const &context,
+    RayPacket &rays,
+    Color results[] ) const
+  {
+    bool stereo;
+    int xres, yres;
+    img->getResolution( stereo, xres, yres );
+    rays.computeTextureCoordinates3( context );
+    if ( typeid( *img ) == typeid( SimpleImage< RGB8Pixel > ) ) {
+      const SimpleImage< RGB8Pixel > *si = dynamic_cast< const SimpleImage< 
RGB8Pixel > * >( img );
+      RGB8Pixel const *buffer = si->getRaw( 0 );
+      for( int i = 0; i < rays.getSize(); i++ ) {
+        RayPacket::Element &e = rays.get( i );
+        double x = SCIRun::Fraction( e.texCoords.x() * x_scale ) * xres;
+        double y = SCIRun::Fraction( e.texCoords.y() * y_scale ) * yres;
+        int left = static_cast< int >( x );
+        int bottom = static_cast< int >( y );
+        int right = ( left + 1 ) == xres ? 0 : left + 1;
+        int top = ( bottom + 1 ) == yres ? 0 : bottom + 1;
+        RGB8Pixel const *upper_left = buffer + top * xres + left;
+        Color upper_left_color = Color( RGB( upper_left->r / 255.0, 
upper_left->g / 255.0, upper_left->b / 255.0 ) );
+        RGB8Pixel const *upper_right = buffer + top * xres + right;
+        Color upper_right_color = Color( RGB( upper_right->r / 255.0, 
upper_right->g / 255.0, upper_right->b / 255.0 ) );
+        RGB8Pixel const *lower_left = buffer + bottom * xres + left;
+        Color lower_left_color = Color( RGB( lower_left->r / 255.0, 
lower_left->g / 255.0, lower_left->b / 255.0 ) );
+        RGB8Pixel const *lower_right = buffer + bottom * xres + right;
+        Color lower_right_color = Color( RGB( lower_right->r / 255.0, 
lower_right->g / 255.0, lower_right->b / 255.0 ) );
+        results[ i ] = SCIRun::Interpolate( SCIRun::Interpolate( 
lower_left_color, lower_right_color, x - left ),
+                                            SCIRun::Interpolate( 
upper_left_color, upper_right_color, x - left ),
+                                            y - bottom );
+      }
+    } else if ( typeid( *img ) == typeid( SimpleImage< RGBA8Pixel > ) ) {
+      const SimpleImage< RGBA8Pixel > *si = dynamic_cast< const SimpleImage< 
RGBA8Pixel > * >( img );
+      RGBA8Pixel const *buffer = si->getRaw( 0 );
+      for( int i = 0; i < rays.getSize(); i++ ) {
+        RayPacket::Element &e = rays.get( i );
+        double x = SCIRun::Fraction( e.texCoords.x() * x_scale ) * xres;
+        double y = SCIRun::Fraction( e.texCoords.y() * y_scale ) * yres;
+        int left = static_cast< int >( x );
+        int bottom = static_cast< int >( y );
+        int right = ( left + 1 ) == xres ? 0 : left + 1;
+        int top = ( bottom + 1 ) == yres ? 0 : bottom + 1;
+        RGBA8Pixel const *upper_left = buffer + top * xres + left;
+        Color upper_left_color = Color( RGB( upper_left->r / 255.0, 
upper_left->g / 255.0, upper_left->b / 255.0 ) );
+        RGBA8Pixel const *upper_right = buffer + top * xres + right;
+        Color upper_right_color = Color( RGB( upper_right->r / 255.0, 
upper_right->g / 255.0, upper_right->b / 255.0 ) );
+        RGBA8Pixel const *lower_left = buffer + bottom * xres + left;
+        Color lower_left_color = Color( RGB( lower_left->r / 255.0, 
lower_left->g / 255.0, lower_left->b / 255.0 ) );
+        RGBA8Pixel const *lower_right = buffer + bottom * xres + right;
+        Color lower_right_color = Color( RGB( lower_right->r / 255.0, 
lower_right->g / 255.0, lower_right->b / 255.0 ) );
+        results[ i ] = SCIRun::Interpolate( SCIRun::Interpolate( 
lower_left_color, lower_right_color, x - left ),
+                                            SCIRun::Interpolate( 
upper_left_color, upper_right_color, x - left ),
+                                            y - bottom );
+      }
+    } else {
+      throw SCIRun::InternalError( "Unknown image type in ImageTexture" );
+    }
+  }
+
+}

Added: trunk/Model/Textures/ImageTexture.h
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/ImageTexture.h Mon Jun 13 18:24:40 2005
@@ -0,0 +1,45 @@
+
+#ifndef Manta_Model_ImageTexture_h
+#define Manta_Model_ImageTexture_h
+
+#include <Interface/Texture.h>
+#include <Core/Color/RGBColor.h>
+#include <MantaTypes.h>
+
+namespace Manta {
+  class RayPacket;
+  class RenderContext;
+  class Image;
+  class ImageTexture : public Texture< Color > {
+    public:
+    /**
+     * Note that this material will destroy the image that it's given when
+     * destroyed itself.
+     */
+    ImageTexture(
+      Image *img,
+      double x_scale,
+      double y_scale );
+    virtual ~ImageTexture();
+    virtual void mapValues(
+      RenderContext const &context,
+      RayPacket &rays,
+      Color results[] ) const;
+    private:
+    ImageTexture(
+      ImageTexture const & );
+    ImageTexture& operator=(
+      ImageTexture const & );
+
+    Image *img;
+    double x_scale;
+    double y_scale;
+  };
+}
+
+#ifdef __GNUG__
+// This should instead be a configure variable...
+#include <Model/Textures/ImageTexture.cc>
+#endif
+
+#endif

Modified: trunk/scenes/primtest.cc
==============================================================================
--- trunk/scenes/primtest.cc    (original)
+++ trunk/scenes/primtest.cc    Mon Jun 13 18:24:40 2005
@@ -1,4 +1,6 @@
 
+#include <Model/Textures/ImageTexture.h>
+#include <Image/TGAFile.h>
 #include <Core/Exceptions/IllegalArgument.h>
 #include <Core/Util/Args.h>
 #include <Interface/LightSet.h>
@@ -57,6 +59,7 @@
   string material = "redphong";
   string arraytype = "spin";
   string modelName = 
"/usr/sci/data/Geometry/Stanford_Sculptures/bun_zipper_res4.ply";
+  string imageName = "texture.tga";
   bool set_primtype = false;
   bool bgpoly = true;
   int argc = static_cast<int>(args.size());
@@ -80,6 +83,9 @@
     } else if(arg == "-model"){
       if(!getStringArg(i, args, modelName))
         throw IllegalArgument("scene primtest -model", i, args);
+    } else if(arg == "-image"){
+      if(!getStringArg(i, args, imageName))
+        throw IllegalArgument("scene primtest -image", i, args);
     } else {
       if(arg[0] == '-' || set_primtype) {
         cerr << "Valid options for scene primtest:\n";
@@ -151,6 +157,12 @@
              new OakTexture<Color>(
                Color(RGB(0.15,0.077,0.028)), Color(RGB(0.5,0.2,0.067)),
                64.0, 0.5, 200.0, 0.02, 1.0, 0.3, 0.4, 1.0, 2.0, 1.0, 0.4 ) );
+    mapr = new UniformMapper();
+  }
+  else if(material == "image")
+  {
+    Image *img = readTGA( imageName );
+    matl = new Lambertian( new ImageTexture( img, 1.0, 1.0 ) );
     mapr = new UniformMapper();
   }
   else




  • [MANTA] r381 - in trunk: Engine/Display Image Model/Textures scenes, aek, 06/13/2005

Archive powered by MHonArc 2.6.16.

Top of page