Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1295 - in trunk: Model/Textures scenes


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1295 - in trunk: Model/Textures scenes
  • Date: Wed, 7 Mar 2007 17:07:20 -0700 (MST)

Author: bigler
Date: Wed Mar  7 17:07:19 2007
New Revision: 1295

Modified:
   trunk/Model/Textures/ImageTexture.cc
   trunk/Model/Textures/ImageTexture.h
   trunk/scenes/objviewer.cc
Log:

Model/Textures/ImageTexture.cc
Model/Textures/ImageTexture.h
scenes/objviewer.cc

  Moved load_image_texture<Color> functionality to
  LoadColorImageTexture in ImageTexture.


Modified: trunk/Model/Textures/ImageTexture.cc
==============================================================================
--- trunk/Model/Textures/ImageTexture.cc        (original)
+++ trunk/Model/Textures/ImageTexture.cc        Wed Mar  7 17:07:19 2007
@@ -32,12 +32,65 @@
 
 #include <Core/Color/Color.h>
 #include <Core/Exceptions/InternalError.h>
+#include <Core/Exceptions/InputError.h>
 #include <Core/Math/MiscMath.h>
 #include <Core/Math/Trig.h>
 
+#include <Image/TGAFile.h>
+#include <Image/NRRDFile.h>
+#include <Image/ImageMagickFile.h>
+
 namespace Manta {
 
   template class ImageTexture<Color>;
+
+  // This will potentially throw a InputError exception if there was a
+  // problem.
+  ImageTexture<Color>* LoadColorImageTexture( const std::string& file_name,
+                                              std::ostream* stream )
+  {
+    if (stream) (*stream) << "Trying to load "<<file_name<<"\n";
+    Image *image = 0;
+
+    // Load the image.
+    // 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 );
+      if (stream) (*stream) << "Read by readNRRD\n";
+    } else if (ImageMagickSupported()) {
+      image = readImageMagick( file_name );
+      if (stream) (*stream) << "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 );
+        if (stream) (*stream) << "Read by readTGA\n";
+      }
+      else if (NRRDSupported()) {
+        // Try reading the image using teem.
+        image = readNRRD( file_name );
+        if (stream) (*stream) << "Read by readNRRD\n";
+      } else {
+        throw InputError("Unsupported image format for image.");
+      }
+    }
+
+    // Create the texture.
+    ImageTexture<Color> *texture = new ImageTexture<Color>( image );
+
+    // Free time image.
+    delete image;
+
+    return texture;
+  
+  }
   
 } // end namespace Manta
 

Modified: trunk/Model/Textures/ImageTexture.h
==============================================================================
--- trunk/Model/Textures/ImageTexture.h (original)
+++ trunk/Model/Textures/ImageTexture.h Wed Mar  7 17:07:19 2007
@@ -63,12 +63,23 @@
 #include <Core/Containers/Array2.h>
 #include <Core/Math/MiscMath.h>
 
+#include <string>
+#include <iosfwd>
+
 namespace Manta {
 
   class RayPacket;
   class RenderContext;
   class Image;
 
+  template<typename ValueType> class ImageTexture;
+
+  // This will potentially throw a InputError exception if there was a
+  // problem.  If stream is non null it will write out chatty stuff to
+  // that.
+  ImageTexture<Color>* LoadColorImageTexture( const std::string& file_name,
+                                              std::ostream* stream = 0 );
+  
   // Whatever type ValueType ends up being, it needs to have
   // ValueType::ScalarType defined.  I'm not sure what to do for
   // things that aren't.  If the occasion arrises such that you need

Modified: trunk/scenes/objviewer.cc
==============================================================================
--- trunk/scenes/objviewer.cc   (original)
+++ trunk/scenes/objviewer.cc   Wed Mar  7 17:07:19 2007
@@ -31,7 +31,6 @@
 
 #include <Core/Geometry/Vector.h>
 #include <Core/Exceptions/IllegalArgument.h>
-#include <Core/Exceptions/InputError.h>
 #include <Core/Util/Args.h>
 
 #include <Interface/Context.h>
@@ -68,10 +67,6 @@
 #include <Model/Textures/NormalTexture.h>
 #include <Model/Cameras/PinholeCamera.h>
 
-#include <Image/TGAFile.h>
-#include <Image/NRRDFile.h>
-#include <Image/ImageMagickFile.h>
-
 #include <sgi_stl_warnings_off.h>
 #include <vector>
 #include <string>
@@ -87,9 +82,6 @@
 static Object *create_single_bvh( GLMmodel *model );
 static void create_materials( GLMmodel *model );
 
-template< typename ValueType >
-static ImageTexture<ValueType> *load_image_texture( const string& file_name 
);
-
 static BBox bounds;
 
 typedef VectorT<float,3> Vectorf;
@@ -277,52 +269,6 @@
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////
 
-// Load a Color texture from a nrrd.
-template<>
-ImageTexture<Color> *load_image_texture<Color>( const string& file_name ) {
-
-  cerr << "Trying to load "<<file_name<<"\n";
-    Image *image = 0;
-
-    // Load the image.
-    // 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 );
-        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.
-    ImageTexture<Color> *texture = new ImageTexture<Color>( image );
-
-    // Free time image.
-    delete image;
-
-    return texture;
-}
-
 // Check to see if the specified file can be loaded, otherwise use the 
specified color.
 Texture<Color> *check_for_texture( const string &path_name, const string 
&file_name, const Color &constant_color, const float* map_scaling ) {
 
@@ -336,7 +282,7 @@
     if (file_name.size()) {
         // Load the image texture.
         try {
-          ImageTexture<Color>* it = load_image_texture<Color>( path_name + 
file_name );
+          ImageTexture<Color>* it = LoadColorImageTexture( path_name + 
file_name , &cerr);
           // The values are assigned to zero in in unintialized state
           if (map_scaling[0] != 0) {
             it->setScale(map_scaling[0], map_scaling[1]);




  • [MANTA] r1295 - in trunk: Model/Textures scenes, bigler, 03/07/2007

Archive powered by MHonArc 2.6.16.

Top of page