Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r1807 - in trunk: CMake Image Model/Textures scenes


Chronological Thread 
  • From: kmorley@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r1807 - in trunk: CMake Image Model/Textures scenes
  • Date: Sat, 3 Nov 2007 10:40:52 -0600 (MDT)

Author: kmorley
Date: Sat Nov  3 10:40:49 2007
New Revision: 1807

Added:
   trunk/CMake/FindOpenEXR.cmake
   trunk/Image/EXRFile-stub.cc
   trunk/Image/EXRFile.cc
   trunk/Image/EXRFile.h
Modified:
   trunk/Image/CMakeLists.txt
   trunk/Model/Textures/ImageTexture.cc
   trunk/scenes/CMakeLists.txt
Log:
Initial support for EXR

Added: trunk/CMake/FindOpenEXR.cmake
==============================================================================
--- (empty file)
+++ trunk/CMake/FindOpenEXR.cmake       Sat Nov  3 10:40:49 2007
@@ -0,0 +1,41 @@
+# The following are set after configuration is done:
+#
+#  OpenEXR_FOUND          - True or false depending on if we have all the 
right
+#                           pieces around.
+#  OpenEXR_LIB            - Name of library.  Set to OpenEXR_LIB-NOTFOUND if 
+#                           not found.
+#  OpenEXR_H              - Location of the main include file.  This is an 
+#                           extra test to make sure that we actually have 
the 
+#                           development packages around.
+
+SET( system_path "/usr/local" "/usr" )
+IF ( APPLE )
+  SET( system_path ${system_path} "/opt/local" )
+ENDIF ( APPLE )
+
+# Append the appropiate lib and include
+SET( library_path "" )
+SET( include_path "" )
+FOREACH( path ${system_path} )
+  SET( library_path ${library_path} "${path}/lib" )
+  SET( include_path ${include_path} "${path}/include" )
+ENDFOREACH( path )
+
+FIND_LIBRARY( OpenEXR_LIB "IlmImf" ${library_path} )
+FIND_LIBRARY( OpenEXR_Half_LIB "Half" ${library_path} )
+FIND_LIBRARY( OpenEXR_Math_LIB "Imath" ${library_path} )
+
+FIND_FILE( OpenEXR_H "OpenEXR/ImfIO.h" ${include_path} )
+
+MARK_AS_ADVANCED( OpenEXR_LIB OpenEXR_Half_LIB OpenEXR_Math_LIB OpenEXR_H )
+
+IF( OpenEXR_H AND OpenEXR_LIB)
+  SET(OpenEXR_FOUND TRUE)
+  GET_FILENAME_COMPONENT(OpenEXR_Include_Dir ${OpenEXR_H}
+                         PATH)
+  GET_FILENAME_COMPONENT(OpenEXR_Lib_Dir ${OpenEXR_LIB}
+                         PATH)
+ELSE(OpenEXR_H AND OpenEXR_LIB)
+  SET(OpenEXR_FOUND FALSE)
+ENDIF(OpenEXR_H AND OpenEXR_LIB)
+

Modified: trunk/Image/CMakeLists.txt
==============================================================================
--- trunk/Image/CMakeLists.txt  (original)
+++ trunk/Image/CMakeLists.txt  Sat Nov  3 10:40:49 2007
@@ -27,6 +27,24 @@
   SET (ImageMagick_SRC ImageMagickFile.h ImageMagickFile-stub.cc)
 ENDIF(ImageMagickPP_FOUND)
 
+
+###############################################################################
+# Locate OpenEXR
+INCLUDE (${CMAKE_SOURCE_DIR}/CMake/FindOpenEXR.cmake)
+
+IF (OpenEXR_FOUND)
+  # Add the EXR files
+  SET (EXR_SRC EXRFile.h EXRFile.cc)
+  INCLUDE_DIRECTORIES(${OpenEXR_Include_Dir})
+  GET_SOURCE_FILE_PROPERTY(prop EXRFile.cc COMPILE_FLAGS)
+#  SET_SOURCE_FILES_PROPERTIES(EXRFile.cc
+#                              PROPERTIES INCLUDE_DIRECTORIES 
${OpenEXR_Include_Dir})
+ELSE(OpenEXR_FOUND)
+  SET (EXR_SRC EXRFile.h EXRFile-stub.cc)
+ENDIF(OpenEXR_FOUND)
+
+
+
 
###############################################################################
 # Create the library
 ADD_LIBRARY (Manta_Image 
@@ -46,6 +64,7 @@
              TGAFile.cc
              ${NRRD_IMAGE_SRC}
              ${ImageMagick_SRC}
+             ${EXR_SRC}
              )
 
 TARGET_LINK_LIBRARIES(Manta_Image
@@ -58,7 +77,12 @@
 IF (ImageMagickPP_FOUND)
   TARGET_LINK_LIBRARIES(Manta_Image ${ImageMagickPP_LIB})
 ENDIF(ImageMagickPP_FOUND)
-
+                    
+IF (OpenEXR_FOUND)
+  TARGET_LINK_LIBRARIES(Manta_Image ${OpenEXR_LIB} ${OpenEXR_Half_LIB} 
${OpenEXR_Math_LIB}  )
+ENDIF(OpenEXR_FOUND)
+                    
 IF(FOUND_TEEM)
   TARGET_LINK_LIBRARIES(Manta_Image ${TEEM_LIBRARY})
 ENDIF(FOUND_TEEM)
+

Added: trunk/Image/EXRFile-stub.cc
==============================================================================
--- (empty file)
+++ trunk/Image/EXRFile-stub.cc Sat Nov  3 10:40:49 2007
@@ -0,0 +1,77 @@
+
+/*
+  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.
+*/
+
+// This file provides some stubs, so that others that call these
+// functions will be able to link even though the Teem stuff isn't
+// being built.
+
+#include <Image/EXRFile.h>
+#include <Image/SimpleImage.h>
+
+#include <Core/Exceptions/InputError.h>
+#include <Core/Exceptions/OutputError.h>
+
+#include <fstream> 
+
+
+extern"C"  
+bool isEXRImage( std::string const &filename )
+{   
+  std::ifstream file(filename.c_str(), std::ios_base::binary); 
+    
+  char b[4];
+  file.read (b, sizeof (b)); 
+
+  return !!file && b[0] == 0x76 && b[1] == 0x2f && b[2] == 0x31 && b[3] == 
0x01;
+}
+
+
+extern "C" void writeEXR( Manta::Image const *image, 
+    std::string const &file_name, int which ) 
+{
+  throw SCIRun OutputError( "EXR writing not supported by this build.  
Perhaps \
+      you need to add the path to the Teem libraries.");
+}
+
+
+extern "C" Manta::Image *readEXR( const std::string &file_name ) 
+{
+  throw SCIRun::InputError( "EXR reading not supported by this build.  
Perhaps \
+      you need to add the path to the Teem libraries.");
+
+  return NULL;
+}
+
+
+extern "C" bool EXRSupported() 
+{
+  return false;
+}
+
+

Added: trunk/Image/EXRFile.cc
==============================================================================
--- (empty file)
+++ trunk/Image/EXRFile.cc      Sat Nov  3 10:40:49 2007
@@ -0,0 +1,207 @@
+
+/*
+  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 <Image/EXRFile.h>
+#include <Image/Pixel.h>
+#include <Image/SimpleImage.h>
+
+#include <Core/Exceptions/UnknownPixel.h>
+#include <Core/Exceptions/InputError.h>
+#include <Core/Exceptions/OutputError.h>
+
+#include <OpenEXR/half.h>
+#include <OpenEXR/ImfInputFile.h>
+#include <OpenEXR/ImfRgba.h>
+#include <OpenEXR/ImfRgbaFile.h>
+#include <OpenEXR/ImfChannelList.h>
+#include <OpenEXR/ImfArray.h>
+#include <OpenEXR/ImfRGBA.h>
+#include <OpenEXR/ImfFrameBuffer.h>
+#include <OpenEXR/ImathBox.h>
+
+#include <fstream>
+#include <iostream>
+using namespace Manta;
+
+extern "C" 
+bool isEXRImage( std::string const &filename )
+{
+  std::ifstream file(filename.c_str(), std::ios_base::binary); 
+
+  char b[4]; 
+  file.read (b, sizeof (b)); 
+
+  return !!file && b[0] == 0x76 && b[1] == 0x2f && b[2] == 0x31 && b[3] == 
0x01;
+}
+
+
+extern "C" 
+void writeEXR( Image const *image, std::string const &file_name, 
+    int which ) 
+{
+}
+
+
+extern "C" 
+Image* readEXR( const std::string &filename ) 
+{
+#if 0
+
+  Imf::InputFile file( filename.c_str() );
+
+  Imath::Box2i dw = file.header().dataWindow(); 
+  long width  = dw.max.x - dw.min.x + 1; 
+  long height = dw.max.y - dw.min.y + 1; 
+
+  std::cerr << " width : " << width << " height: " << height << std::endl;
+
+  Imf::Array2D<half> r_pixels( height, width );
+  Imf::Array2D<half> g_pixels( height, width );
+  Imf::Array2D<half> b_pixels( height, width );
+  Imf::Array2D<half> a_pixels( height, width );
+  std::string red_name, green_name, blue_name, alpha_name;
+
+  Imf::FrameBuffer frame_buffer; 
+
+  const Imf::ChannelList &channels = file.header().channels(); 
+  for ( Imf::ChannelList::ConstIterator iter = channels.begin(); 
+      iter != channels.end(); ++iter ) 
+  { 
+    std::string name            = iter.name();  
+    const Imf::Channel& channel = iter.channel(); 
+
+    
+    std::cerr << "    channel found: '" << name << "'" << std::endl;
+
+    Imf::Array2D<half>* array;
+    if      ( name == "R" || name == "r" || name == "Red" || 
+              name == "RED" || name == "red" ) {
+      array = &r_pixels;
+      red_name = name;
+    }
+    else if ( name == "G"   || name == "g"   || name == "Green" || 
+              name == "GREEN" || name == "green" ) {
+      array = &g_pixels;
+      green_name = name;
+    }
+    else if ( name == "B" || name == "b" || name == "Blue" || 
+              name == "BLUE" || name == "blue" ) {
+      array = &b_pixels;
+      blue_name = name;
+    }
+    else if ( name == "A" || name == "a" || name == "Alpha" || 
+              name == "ALPHA" || name == "alpha" ) {
+      array = &a_pixels;
+      alpha_name = name;
+    } else {
+      std::cerr << __FILE__ << ":" << __FUNCTION__ << " Unknown channel type 
'"
+                << name << "' ... ignoring" << std::endl;
+      continue;
+    }
+    frame_buffer.insert( name.c_str(), 
+        Imf::Slice(
+          channel.type,                                        // type
+          (char*)(&(*array[0][0]) - dw.min.x - dw.min.y * width), // base 
+          sizeof (*array[0][0]) * 1,                           // xStride 
+          sizeof (*array[0][0]) * width,                       // yStride 
+          channel.xSampling,                                   // x sampling
+          channel.ySampling,                                   // y sampling 
+          0.0 ) );                                             // fillValue 
+    
+  }
+
+  file.setFrameBuffer( frame_buffer ); 
+  file.readPixels( dw.min.y, dw.max.y ); 
+  
+  SimpleImage<RGBA8Pixel>* image = new SimpleImage<RGBA8Pixel>( false, 
width, 
+      height );
+
+  for ( int i = 0; i < width; ++i ) {
+    for ( int j = 0; j < height; ++j ) {
+    
+      std::cerr << r_pixels[i][j] << " " 
+                << g_pixels[i][j] << " " 
+                << b_pixels[i][j] << std::endl;
+      
+      RGBA8Pixel pixel;
+      RGBColor color( r_pixels[i][j], g_pixels[i][j], b_pixels[i][j] );
+
+      convertToPixel( pixel, color );
+      image->set( pixel, i, j, 0 ); 
+    }
+  }
+  return image;
+#else
+                                        
+     
+  Imf::RgbaInputFile file( filename.c_str() ); 
+
+  Imath::Box2i dw = file.dataWindow(); 
+  int width  = dw.max.x - dw.min.x + 1; 
+  int height = dw.max.y - dw.min.y + 1; 
+  Imf::Array2D<Imf::Rgba> pixels( height, width ); 
+
+  file.setFrameBuffer (&pixels[0][0] - dw.min.x - dw.min.y * width, 1, 
width); 
+  file.readPixels (dw.min.y, dw.max.y); 
+
+  SimpleImage<RGBA8Pixel>* image = new SimpleImage<RGBA8Pixel>( false, 
width, 
+      height );
+  for ( int i = 0; i < width; ++i ) {
+    for ( int j = 0; j < height; ++j ) {
+    
+      RGBA8Pixel pixel;
+     
+      float r = pixels[height-1-j][i].r;
+      float g = pixels[height-1-j][i].g;
+      float b = pixels[height-1-j][i].b;
+      RGBColor color( r, g, b ); 
+
+      //std::cerr << float( pixels[i][j].r ) << " " 
+      //          << float( pixels[i][j].g ) << " " 
+      //          << float( pixels[i][j].b ) << std::endl;
+
+      convertToPixel( pixel, color );
+      image->set( pixel, i, j, 0 ); 
+    }
+  }
+
+  return image;
+
+#endif
+}
+
+
+extern "C" 
+bool EXRSupported() 
+{
+  return true;
+}
+
+

Added: trunk/Image/EXRFile.h
==============================================================================
--- (empty file)
+++ trunk/Image/EXRFile.h       Sat Nov  3 10:40:49 2007
@@ -0,0 +1,51 @@
+
+/*
+  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_Image_EXRFile_h
+#define Manta_Image_EXRFile_h
+
+#include <string>
+
+namespace Manta {
+
+  class Image;
+
+  extern "C" bool isEXRImage( std::string const &filename );
+
+  extern "C" void writeEXR ( Image const *image, std::string const 
&filename, 
+      int which = 0 );
+
+  extern "C" Image *readEXR( const std::string &filename );
+
+  // Returns true if this reader is supported
+  extern "C" bool EXRSupported();
+
+}
+
+#endif

Modified: trunk/Model/Textures/ImageTexture.cc
==============================================================================
--- trunk/Model/Textures/ImageTexture.cc        (original)
+++ trunk/Model/Textures/ImageTexture.cc        Sat Nov  3 10:40:49 2007
@@ -40,6 +40,7 @@
 #include <Image/NRRDFile.h>
 #include <Image/RGBEFile.h>
 #include <Image/TGAFile.h>
+#include <Image/EXRFile.h>
 
 namespace Manta {
 
@@ -61,6 +62,7 @@
     bool isRGBE = ( (file_name.rfind(".hdr") == (file_name.size() - 4) ||
                      file_name.rfind(".pic") == (file_name.size() - 4) ||
                      file_name.rfind(".rgbe") == (file_name.size() - 5)));
+   
 
     if (isNrrd) {
       // Check to see if it is a nrrd before trying to read with
@@ -71,6 +73,8 @@
     } else if (isRGBE) {
       image = readRGBE(file_name);
       if (stream) (*stream) << "Read by readRGBE\n";
+    } else if ( isEXRImage( file_name ) && EXRSupported() ) {
+          image = readEXR( file_name );
     } else if (ImageMagickSupported()) {
       image = readImageMagick( file_name );
       if (stream) (*stream) << "Read by readImageMagick\n";

Modified: trunk/scenes/CMakeLists.txt
==============================================================================
--- trunk/scenes/CMakeLists.txt (original)
+++ trunk/scenes/CMakeLists.txt Sat Nov  3 10:40:49 2007
@@ -54,6 +54,13 @@
    TARGET_LINK_LIBRARIES(scene_fence ${MANTA_SCENE_LINK})
 ENDIF(SCENE_FENCE)
 
+# hdri lit scene 
+SET(SCENE_HDRI TRUE CACHE BOOL "HDRI test")
+IF(SCENE_HDRI)
+   ADD_LIBRARY(scene_hdri hdritest.cc)
+   TARGET_LINK_LIBRARIES(scene_hdri ${MANTA_SCENE_LINK})
+ENDIF(SCENE_HDRI)
+
 IF(FOUND_TEEM AND MANTA_SSE)
 SET(SCENE_VOLUMETEST 0 CACHE BOOL "volume test")
 IF(SCENE_VOLUMETEST)




  • [Manta] r1807 - in trunk: CMake Image Model/Textures scenes, kmorley, 11/03/2007

Archive powered by MHonArc 2.6.16.

Top of page