Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1294 - in trunk: CMake Image Model/Readers/glm SwigInterface scenes


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1294 - in trunk: CMake Image Model/Readers/glm SwigInterface scenes
  • Date: Wed, 7 Mar 2007 10:36:21 -0700 (MST)

Author: bigler
Date: Wed Mar  7 10:36:19 2007
New Revision: 1294

Added:
   trunk/CMake/FindImageMagick++.cmake
   trunk/Image/ImageMagickFile-stub.cc
   trunk/Image/ImageMagickFile.cc
   trunk/Image/ImageMagickFile.h
Modified:
   trunk/Image/CMakeLists.txt
   trunk/Image/NRRDFile-stub.cc
   trunk/Image/NRRDFile.cc
   trunk/Image/NRRDFile.h
   trunk/Model/Readers/glm/glm.cc
   trunk/SwigInterface/wxManta.py
   trunk/scenes/objviewer.cc
Log:

CMake/FindImageMagick++.cmake

  New cmake file for finding ImageMagick++.

Image/CMakeLists.txt
Image/ImageMagickFile-stub.cc
Image/ImageMagickFile.cc
Image/ImageMagickFile.h

  Add stuff for using ImageMagick++ to read and write images.

  writeImageMagick is currently unimplemented.
  
Image/NRRDFile-stub.cc
Image/NRRDFile.cc
Image/NRRDFile.h

  Added NRRDSupported function that returns true or false depending on
  if NRRD support has been built.

Model/Readers/glm/glm.cc

  When trying to parse some new OBJ files, there were some some image
  maps used for bump mapping or opacity maps.  We don't support those,
  so we need to be more graceful and ignore them to prevent crashes.

SwigInterface/wxManta.py

  Changed name of menu item for light editing dialog.

scenes/objviewer.cc

  Added support for reading textures with readImageMagick.

  I changed the logic of which readers are used, so that I think it
  will do the right thing with respect different installations.


Added: trunk/CMake/FindImageMagick++.cmake
==============================================================================
--- (empty file)
+++ trunk/CMake/FindImageMagick++.cmake Wed Mar  7 10:36:19 2007
@@ -0,0 +1,21 @@
+# The following are set after configuration is done:
+#
+#  ImageMagickPP_FOUND          - True or false depending on if we have
+#                                 all the right pieces around.
+#  ImageMagickPP_LIB            - Name of library.  Set to
+#                                 ImageMagickPP_LIB-NOTFOUND if not found.
+#  ImageMagickPP_H              - Location of the main include file.  This is
+#                                 an extra test to make sure that we actually
+#                                 have the development packages around.
+
+FIND_LIBRARY(ImageMagickPP_LIB "Magick++" "/usr/local/lib" "/usr/lib" )
+
+FIND_FILE(ImageMagickPP_H "Magick++.h" "/usr/local/include" "/usr/include" )
+
+MARK_AS_ADVANCED(ImageMagickPP_LIB ImageMagickPP_H)
+
+IF(ImageMagickPP_H AND ImageMagickPP_LIB)
+  SET(ImageMagickPP_FOUND TRUE)
+ELSE(ImageMagickPP_H AND ImageMagickPP_LIB)
+  SET(ImageMagickPP_FOUND FALSE)
+ENDIF(ImageMagickPP_H AND ImageMagickPP_LIB)

Modified: trunk/Image/CMakeLists.txt
==============================================================================
--- trunk/Image/CMakeLists.txt  (original)
+++ trunk/Image/CMakeLists.txt  Wed Mar  7 10:36:19 2007
@@ -24,6 +24,15 @@
 
 ENDIF(FOUND_TEEM_LIB)
 
+# Locate ImageMagick++
+INCLUDE (${CMAKE_SOURCE_DIR}/CMake/FindImageMagick++.cmake)
+
+IF (ImageMagickPP_FOUND)
+  # Add the ImageMagick files
+  SET (ImageMagick_SRC ImageMagickFile.h ImageMagickFile.cc)
+ELSE(ImageMagickPP_FOUND)
+  SET (ImageMagick_SRC ImageMagickFile.h ImageMagickFile-stub.cc)
+ENDIF(ImageMagickPP_FOUND)
 
 ADD_LIBRARY (Manta_Image 
              NullImage.cc
@@ -39,6 +48,7 @@
              TGAFile.h
              TGAFile.cc
              ${NRRD_IMAGE_SRC}
+             ${ImageMagick_SRC}
              )
 
 TARGET_LINK_LIBRARIES(Manta_Image
@@ -46,3 +56,10 @@
                       Manta_Core
                       SCIRun_Core 
                       ${NRRD_IMAGE_LIB})
+
+IF (ImageMagickPP_FOUND)
+  # Add the ImageMagick libraries
+  TARGET_LINK_LIBRARIES(Manta_Image ${ImageMagickPP_LIB})
+ENDIF(ImageMagickPP_FOUND)
+
+                    
\ No newline at end of file

Added: trunk/Image/ImageMagickFile-stub.cc
==============================================================================
--- (empty file)
+++ trunk/Image/ImageMagickFile-stub.cc Wed Mar  7 10:36:19 2007
@@ -0,0 +1,56 @@
+
+/*
+  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.
+
+#include <Image/ImageMagickFile.h>
+#include <Image/SimpleImage.h>
+
+#include <Core/Exceptions/InputError.h>
+#include <Core/Exceptions/OutputError.h>
+
+using namespace Manta;
+using namespace SCIRun;
+
+extern "C" void writeImageMagick( Image const *image, std::string const 
&file_name, int which ) {
+  throw OutputError( "ImageMagick writing not supported by this build.  
Perhaps you need to add the path to the ImageMagick++ libraries.");
+}
+
+extern "C" Image *readImageMagick( const std::string &file_name ) {
+
+  throw InputError( "ImageMagick writing not supported by this build.  
Perhaps you need to add the path to the ImageMagick++ libraries.");
+  return NULL;
+}
+
+// Returns true if this reader is supported
+extern "C" bool ImageMagickSupported()
+{
+  return false;
+}

Added: trunk/Image/ImageMagickFile.cc
==============================================================================
--- (empty file)
+++ trunk/Image/ImageMagickFile.cc      Wed Mar  7 10:36:19 2007
@@ -0,0 +1,134 @@
+
+/*
+  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/ImageMagickFile.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 <Magick++.h>
+
+using namespace Manta;
+using namespace SCIRun;
+
+using MagickLib::Quantum;
+using MagickLib::MagickRealType;
+
+extern "C" void writeImageMagick( Image const *image,
+                                  std::string const &file_name,
+                                  int which )
+{
+  Magick::Image magick_image;
+
+  // Copy image data over
+  throw OutputError( "writeImageMagick currently not implemented");
+//   magick_image.read(image->width, image->height, pixel_type,
+//                     storage_type, image
+  
+  try {
+    // Read a file into image object
+    magick_image.write( file_name );
+  } catch ( Magick::Exception& error_ ) {
+    throw OutputError( "writeImageMagick::Error writing file:" + 
string(error_.what()) );
+  }
+    
+}
+
+extern "C" Image *readImageMagick( const std::string &file_name )
+{
+  Magick::Image magick_image;
+
+  try {
+    // Read a file into image object
+    magick_image.read( file_name );
+  } catch ( Magick::Exception& error_ ) {
+    throw InputError( "readImageMagick::Error reading file:" + 
string(error_.what()) );
+  }
+
+  Magick::Geometry size = magick_image.size();
+  int width = size.width();
+  int height = size.height();
+  
+  // Copy image data over
+  if (magick_image.matte()) {
+    // RGBA pixels
+    SimpleImage<RGBA8Pixel>* si = new SimpleImage<RGBA8Pixel>( false, width, 
height );
+    for ( int y = 0; y < height; ++y )
+      for ( int x = 0; x < width; ++x ) {
+        RGBA8Pixel pixel;
+        Magick::Color color = magick_image.pixelColor(x,y);
+        if (QuantumDepth == 8) {
+          pixel.r = color.redQuantum();
+          pixel.g = color.greenQuantum();
+          pixel.b = color.blueQuantum();
+          pixel.a = color.alphaQuantum();
+        } else {
+          // Pixels need to be rescaled
+          MagickRealType scale = (MagickRealType)(255)/QuantumRange;
+          pixel.r = static_cast<unsigned char>(color.redQuantum()*scale);
+          pixel.g = static_cast<unsigned char>(color.greenQuantum()*scale);
+          pixel.b = static_cast<unsigned char>(color.blueQuantum()*scale);
+          pixel.a = static_cast<unsigned char>(color.alphaQuantum()*scale);
+        }
+        si->set(pixel, x, (height-1-y), 0);
+      }
+    return si;
+  } else {
+    // RGB Pixels
+    SimpleImage<RGB8Pixel>* si = new SimpleImage<RGB8Pixel>( false, width, 
height );
+    for ( int y = 0; y < height; ++y )
+      for ( int x = 0; x < width; ++x ) {
+        RGB8Pixel pixel;
+        Magick::Color color = magick_image.pixelColor(x,y);
+        if (QuantumDepth == 8) {
+          pixel.r = color.redQuantum();
+          pixel.g = color.greenQuantum();
+          pixel.b = color.blueQuantum();
+        } else {
+          // Pixels need to be rescaled
+          MagickRealType scale = (MagickRealType)(255)/QuantumRange;
+          pixel.r = static_cast<unsigned char>(color.redQuantum()*scale);
+          pixel.g = static_cast<unsigned char>(color.greenQuantum()*scale);
+          pixel.b = static_cast<unsigned char>(color.blueQuantum()*scale);
+        }
+        si->set(pixel, x, (height-1-y), 0);
+      }
+    return si;
+  }
+}
+
+// Returns true if this reader is supported
+extern "C" bool ImageMagickSupported()
+{
+  return true;
+}

Added: trunk/Image/ImageMagickFile.h
==============================================================================
--- (empty file)
+++ trunk/Image/ImageMagickFile.h       Wed Mar  7 10:36:19 2007
@@ -0,0 +1,47 @@
+#ifndef Manta_Image_ImageMagickFile_h
+#define Manta_Image_ImageMagickFile_h
+
+
+/*
+  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 <string>
+
+namespace Manta {
+
+  class Image;
+
+  extern "C" void writeImageMagick ( Image const *image, std::string const 
&filename, int which = 0 );
+  extern "C" Image *readImageMagick( const std::string &filename );
+
+  // Returns true if this reader is supported
+  extern "C" bool ImageMagickSupported();
+
+}
+
+#endif // #ifndef Manta_Image_ImageMagickFile_h

Modified: trunk/Image/NRRDFile-stub.cc
==============================================================================
--- trunk/Image/NRRDFile-stub.cc        (original)
+++ trunk/Image/NRRDFile-stub.cc        Wed Mar  7 10:36:19 2007
@@ -50,3 +50,6 @@
   return NULL;
 }
 
+extern "C" bool NRRDSupported() {
+  return false;
+}

Modified: trunk/Image/NRRDFile.cc
==============================================================================
--- trunk/Image/NRRDFile.cc     (original)
+++ trunk/Image/NRRDFile.cc     Wed Mar  7 10:36:19 2007
@@ -192,3 +192,6 @@
   }
 }
 
+extern "C" bool NRRDSupported() {
+  return true;
+}

Modified: trunk/Image/NRRDFile.h
==============================================================================
--- trunk/Image/NRRDFile.h      (original)
+++ trunk/Image/NRRDFile.h      Wed Mar  7 10:36:19 2007
@@ -39,6 +39,9 @@
   extern "C" void writeNRRD ( Image const *image, std::string const 
&filename, int which = 0 );
   extern "C" Image *readNRRD( const std::string &filename );
 
+  // Returns true if this reader is supported
+  extern "C" bool NRRDSupported();
+
 }
 
 #endif

Modified: trunk/Model/Readers/glm/glm.cc
==============================================================================
--- trunk/Model/Readers/glm/glm.cc      (original)
+++ trunk/Model/Readers/glm/glm.cc      Wed Mar  7 10:36:19 2007
@@ -402,6 +402,11 @@
           } else if (strcmp(buf,"map_Ks")==0) {
             map_name = model->materials[nummaterials].specular_map;
             scaling = model->materials[nummaterials].ambient_map_scaling;
+          } else {
+            // We don't know what kind of map it is, so ignore it
+            fprintf(stderr, "Unknown map: \"%s\" found at %s(%d)\n", buf,
+                    __FILE__, __LINE__);
+            break;
           }
           
           char string_litteral[128];

Modified: trunk/SwigInterface/wxManta.py
==============================================================================
--- trunk/SwigInterface/wxManta.py      (original)
+++ trunk/SwigInterface/wxManta.py      Wed Mar  7 10:36:19 2007
@@ -307,7 +307,7 @@
         light_dialog_id = wx.NewId()
         self.dialog_map[light_dialog_id] = LightFrame
         self.Bind(wx.EVT_MENU, self.OnShowDialog,
-                  manta_menu.Append(light_dialog_id, "Modify Lights"))
+                  manta_menu.Append(light_dialog_id, "Edit Lights"))
         self.menuBar.Append(manta_menu, "&Manta")
 
         file_menu = wx.Menu()

Modified: trunk/scenes/objviewer.cc
==============================================================================
--- trunk/scenes/objviewer.cc   (original)
+++ trunk/scenes/objviewer.cc   Wed Mar  7 10:36:19 2007
@@ -31,6 +31,7 @@
 
 #include <Core/Geometry/Vector.h>
 #include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Exceptions/InputError.h>
 #include <Core/Util/Args.h>
 
 #include <Interface/Context.h>
@@ -69,6 +70,7 @@
 
 #include <Image/TGAFile.h>
 #include <Image/NRRDFile.h>
+#include <Image/ImageMagickFile.h>
 
 #include <sgi_stl_warnings_off.h>
 #include <vector>
@@ -279,16 +281,37 @@
 template<>
 ImageTexture<Color> *load_image_texture<Color>( const string& file_name ) {
 
+  cerr << "Trying to load "<<file_name<<"\n";
     Image *image = 0;
 
     // Load the image.
-    if (file_name.rfind(".tga") == (file_name.size()-4)) {
+    // Try and see if it is a nrrd
+    bool isNrrd = ( (file_name.rfind(".nrrd") == (file_name.size()-5)) ||
+                    (file_name.rfind(".nhdr") == (file_name.size()-5))
+                    );
+    if (isNrrd) {
+      // Check to see if it is a nrrd before trying to read with
+      // something else.  ImageMagick will choke on nrrds and throw an
+      // exception.
+      image = readNRRD( file_name );
+      cerr << "Read by readNRRD\n";
+    } else if (ImageMagickSupported()) {
+      image = readImageMagick( file_name );
+      cerr << "Read by readImageMagick\n";
+    } else {
+      // Try our hard coded image readers
+      if (file_name.rfind(".tga") == (file_name.size()-4)) {
         // Try to read a tga file.
         image = readTGA( file_name );
-    }
-    else {
+        cerr << "Read by readTGA\n";
+      }
+      else if (NRRDSupported()) {
         // Try reading the image using teem.
         image = readNRRD( file_name );
+        cerr << "Read by readNRRD\n";
+      } else {
+        throw InputError("Unsupported image format for image.");
+      }
     }
 
     // Create the texture.




  • [MANTA] r1294 - in trunk: CMake Image Model/Readers/glm SwigInterface scenes, bigler, 03/07/2007

Archive powered by MHonArc 2.6.16.

Top of page