Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r702 - in branches/itanium2: . Core/Color Engine/Display Image Interface Model/Textures


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r702 - in branches/itanium2: . Core/Color Engine/Display Image Interface Model/Textures
  • Date: Tue, 8 Nov 2005 13:36:39 -0700 (MST)

Author: bigler
Date: Tue Nov  8 13:36:38 2005
New Revision: 702

Added:
   branches/itanium2/Model/Textures/ImageTexture.cc
   branches/itanium2/Model/Textures/ImageTexture.h
Modified:
   branches/itanium2/CMakeLists.txt
   branches/itanium2/Core/Color/ColorSpace.h
   branches/itanium2/Engine/Display/GLXImageDisplay.h
   branches/itanium2/Image/NullImage.cc
   branches/itanium2/Image/NullImage.h
   branches/itanium2/Image/Pixel.h
   branches/itanium2/Image/SimpleImage.h
   branches/itanium2/Image/TGAFile.cc
   branches/itanium2/Interface/Image.h
   branches/itanium2/Model/Textures/CMakeLists.txt
Log:

CMakeLists.txt

  Uncommented out ADD_CXX_FLAGS macro.  This requires you to use CMake
  > 2.0.

  If forcing the pthread libraries on IRIX, you need to add -lpthread.

  Force -DSCI_NOPERSISTENT flag to be added to CXX_FLAGS.

  Set the PASSED_FIRST_CONFIGURE variable.  Not sure why this wasn't
  happening before.  Everytime you configured it would set all the
  variables to their defaults.  This was fixed in the trunk, but not
  here.

Core/Color/ColorSpace.h

  Added ScalarType typedef to match that of Points and Vectors.

Engine/Display/GLXImageDisplay.h

  To ISO standard you need to declare a return type of the function.
  I'm not sure why this function is here, because it isn't implemented
  and no one references it.

Image/NullImage.cc
Image/NullImage.h
Image/SimpleImage.h
Interface/Image.h

  Added get method.

Image/Pixel.h

  Added convertToRGBColor method.

Image/TGAFile.cc

  Fix off by one error for up side down images.

Model/Textures/CMakeLists.txt

  Added ImageTexture class.
  
Model/Textures/ImageTexture.cc
Model/Textures/ImageTexture.h

  New ImageTexture class used for 2D texturing.  The constructor takes
  an Image class and makes a copy of it while converting it to type
  Color.  No sense in converting everytime you want to do lookups.

  Some basic texturing parameters are supported.  Bilinear and nearest
  neighbor interpolation methods can be selected after construction.
  You can also select to wrap boundaries or clamp them.  With bilinear
  interpolation with wrapped boundaries will interpolate across the
  edges.


Modified: branches/itanium2/CMakeLists.txt
==============================================================================
--- branches/itanium2/CMakeLists.txt    (original)
+++ branches/itanium2/CMakeLists.txt    Tue Nov  8 13:36:38 2005
@@ -13,26 +13,25 @@
 INCLUDE (${CMAKE_ROOT}/Modules/FindThreads.cmake)
 INCLUDE (${CMAKE_ROOT}/Modules/FindX11.cmake)
 
-
-# #################################################################
-# ###   ADD_CXX_FLAGS(flags)                                    ###
-# ### flags will be added to CMAKE_CXX_FLAGS, but only once     ###
-# ### This only works for CMake 2.0 and above.                  ###
-# #################################################################
-# MACRO(FORCE_ADD_CXX_FLAGS)
-#   FOREACH(arg ${ARGN})
-#     SET(TMP ${arg}) #elsewise the Seperate command doesn't work)
-#     SEPARATE_ARGUMENTS(TMP)
-#     FOREACH(option ${TMP})
-#       STRING(REGEX REPLACE " ${option}" "" CMAKE_CXX_FLAGS
-# "${CMAKE_CXX_FLAGS}")
-#       STRING(REGEX REPLACE "${option}" "" CMAKE_CXX_FLAGS
-# "${CMAKE_CXX_FLAGS}")
-#       SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${option}" CACHE STRING
-# "common C++ build flags" FORCE)
-#     ENDFOREACH(option ${TMP})  
-#   ENDFOREACH(arg ${ARGN})
-# ENDMACRO(FORCE_ADD_CXX_FLAGS)
+#################################################################
+###   ADD_CXX_FLAGS(flags)                                    ###
+### flags will be added to CMAKE_CXX_FLAGS, but only once     ###
+### This only works for CMake 2.0 and above.                  ###
+#################################################################
+MACRO(FORCE_ADD_CXX_FLAGS)
+  FOREACH(arg ${ARGN})
+    SET(TMP ${arg}) #elsewise the Seperate command doesn't work)
+    SEPARATE_ARGUMENTS(TMP)
+    FOREACH(option ${TMP})
+      STRING(REGEX REPLACE " ${option}" "" CMAKE_CXX_FLAGS
+        "${CMAKE_CXX_FLAGS}")
+      STRING(REGEX REPLACE "${option}" "" CMAKE_CXX_FLAGS
+        "${CMAKE_CXX_FLAGS}")
+      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${option}" CACHE STRING
+        "common C++ build flags" FORCE)
+    ENDFOREACH(option ${TMP})
+  ENDFOREACH(arg ${ARGN})
+ENDMACRO(FORCE_ADD_CXX_FLAGS)
 
 # This MACRO is designed to set variables to default values only on
 # the first configure.  Subsequent configures will produce no ops.
@@ -80,7 +79,7 @@
   #  MESSAGE("Forcing Irix Threads")
   SET(CMAKE_USE_SPROC_INIT 0)
   SET(CMAKE_USE_PTHREADS_INIT 1)
-  SET(CMAKE_THREAD_LIBS_INIT -lfetchop)
+  SET(CMAKE_THREAD_LIBS_INIT -lpthread -lfetchop)
 
   # Check for CC compiler and add -LANG:std to it
   IF(CMAKE_CXX_COMPILER MATCHES "CC")
@@ -104,6 +103,13 @@
 ENDIF (APPLE)
 
 
+##################################################################
+## No more setting CXX_FLAGS beyond this point.  Only appending.
+
+## We need SCI_NOPERSISTENT to be defined
+FORCE_ADD_CXX_FLAGS("-DSCI_NOPERSISTENT")
+
+
 
 IF (OPENGL_INCLUDE_PATH)
   INCLUDE_DIRECTORIES (${OPENGL_INCLUDE_PATH})
@@ -146,6 +152,11 @@
 IF(BUILD_FOX)
   SUBDIRS(fox)
 ENDIF(BUILD_FOX)
+
+# Now that everything is done indicate that we have finished
+# configuring at least once.
+
+SET(PASSED_FIRST_CONFIGURE ON CACHE INTERNAL "Already Configured once?")
 
 
 

Modified: branches/itanium2/Core/Color/ColorSpace.h
==============================================================================
--- branches/itanium2/Core/Color/ColorSpace.h   (original)
+++ branches/itanium2/Core/Color/ColorSpace.h   Tue Nov  8 13:36:38 2005
@@ -11,6 +11,7 @@
   class ColorSpace {
   public:
     typedef typename Traits::ComponentType ComponentType;
+    typedef typename Traits::ComponentType ScalarType;
     enum { NumComponents = Traits::NumComponents};
 
     ColorSpace() { }

Modified: branches/itanium2/Engine/Display/GLXImageDisplay.h
==============================================================================
--- branches/itanium2/Engine/Display/GLXImageDisplay.h  (original)
+++ branches/itanium2/Engine/Display/GLXImageDisplay.h  Tue Nov  8 13:36:38 
2005
@@ -24,8 +24,8 @@
     bool use_stereo;   // Setup parameter used when creating the visual
                int manta_channel; // The last channel number to call 
setupDisplayChannel.
 
-    static createVisual( bool stereo_ );
-    
+    static void createVisual( bool stereo_ );
+
        public:
                // Note that the GLXImage display must be passed a GLX 
context by the
                // application it is embedded inside of.

Modified: branches/itanium2/Image/NullImage.cc
==============================================================================
--- branches/itanium2/Image/NullImage.cc        (original)
+++ branches/itanium2/Image/NullImage.cc        Tue Nov  8 13:36:38 2005
@@ -45,3 +45,8 @@
   // Do nothing
 }
 
+void NullImage::get(Fragment&) const
+{
+  // Do nothing
+}
+

Modified: branches/itanium2/Image/NullImage.h
==============================================================================
--- branches/itanium2/Image/NullImage.h (original)
+++ branches/itanium2/Image/NullImage.h Tue Nov  8 13:36:38 2005
@@ -15,6 +15,7 @@
     NullImage(bool stereo, int xres, int yres);
     virtual ~NullImage();
     virtual void set(const Fragment&);
+    virtual void get(Fragment&) const;
     virtual bool isValid() const;
     virtual void setValid(bool to);
     virtual void getResolution(bool& stereo, int& xres, int& yres) const;

Modified: branches/itanium2/Image/Pixel.h
==============================================================================
--- branches/itanium2/Image/Pixel.h     (original)
+++ branches/itanium2/Image/Pixel.h     Tue Nov  8 13:36:38 2005
@@ -42,6 +42,13 @@
     p.a = 255;
   }
 
+  inline void convertToRGBColor(RGBColor& c, const RGBA8Pixel& p) {
+    ColorComponent norm = (ColorComponent)1/255;
+    c.setR(p.r*norm);
+    c.setG(p.g*norm);
+    c.setB(p.b*norm);
+  }
+
   class RGB8Pixel {
   public:
     unsigned char r;
@@ -77,6 +84,13 @@
 #endif
   }
 
+  inline void convertToRGBColor(RGBColor& c, const RGB8Pixel& p) {
+    ColorComponent norm = (ColorComponent)1/255;
+    c.setR(p.r*norm);
+    c.setG(p.g*norm);
+    c.setB(p.b*norm);
+  }
+
   class RGBfloatPixel {
   public:
     float r;
@@ -90,6 +104,12 @@
     p.b = c.b();
   }
 
+  inline void convertToRGBColor(RGBColor& c, const RGBfloatPixel& p) {
+    c.setR(p.r);
+    c.setG(p.g);
+    c.setB(p.b);
+  }
+
   class RGBAfloatPixel {
   public:
     float r;
@@ -103,6 +123,12 @@
     p.g = c.g();
     p.b = c.b();
     p.a = 1;
+  }
+
+  inline void convertToRGBColor(RGBColor& c, const RGBAfloatPixel& p) {
+    c.setR(p.r);
+    c.setG(p.g);
+    c.setB(p.b);
   }
 }
 

Modified: branches/itanium2/Image/SimpleImage.h
==============================================================================
--- branches/itanium2/Image/SimpleImage.h       (original)
+++ branches/itanium2/Image/SimpleImage.h       Tue Nov  8 13:36:38 2005
@@ -18,6 +18,7 @@
     SimpleImage(bool stereo, int xres, int yres);
     virtual ~SimpleImage();
     virtual void set(const Fragment&);
+    virtual void get(Fragment&) const;
     virtual bool isValid() const;
     virtual void setValid(bool to);
     virtual void getResolution(bool& stereo, int& xres, int& yres) const;
@@ -114,6 +115,30 @@
       for(int i=0;i<fragment.getSize();i++){
        const Fragment::Element& f = fragment.get(i);
        convertToPixel(eyeStart[f.which_eye][f.y][f.x], f.color.convertRGB());
+      }
+    }
+  }
+
+  template<class Pixel>
+  void SimpleImage<Pixel>::get(Fragment& fragment) const
+  {
+    if(fragment.getFlags() & (Fragment::ConsecutiveX|Fragment::ConstantEye) 
+       == (Fragment::ConsecutiveX|Fragment::ConstantEye)){
+      int nf = fragment.getSize();
+      Pixel* pix = 
eyeStart[fragment.get(0).which_eye][fragment.get(0).y]+fragment.get(0).x;
+      for(int i=0;i<nf;i++) {
+        RGBColor color;
+        convertToRGBColor(color, *pix++);
+        // Convert from RGBColor to Color
+        fragment.setColor(i, Color(color));
+      }
+    } else {
+      for(int i=0;i<fragment.getSize();i++){
+        const Fragment::Element& f = fragment.get(i);
+        RGBColor color;
+        convertToRGBColor(color, eyeStart[f.which_eye][f.y][f.x]);
+        // Convert from RGBColor to Color
+        fragment.setColor(i, Color(color));
       }
     }
   }

Modified: branches/itanium2/Image/TGAFile.cc
==============================================================================
--- branches/itanium2/Image/TGAFile.cc  (original)
+++ branches/itanium2/Image/TGAFile.cc  Tue Nov  8 13:36:38 2005
@@ -182,8 +182,8 @@
       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 ) );
+                                ( image_descriptor & 32 ? height-1 - y : y ) 
* width +
+                                ( image_descriptor & 16 ? width-1 - x : x ) 
);
           offset->b = static_cast<unsigned char>(in.get());
           offset->g = static_cast<unsigned char>(in.get());
           offset->r = static_cast<unsigned char>(in.get());
@@ -195,8 +195,8 @@
       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 ) );
+                                 ( image_descriptor & 32 ? height-1 - y : y 
) * width +
+                                 ( image_descriptor & 16 ? width-1 - x : x ) 
);
           offset->b = static_cast<unsigned char>(in.get());
           offset->g = static_cast<unsigned char>(in.get());
           offset->r = static_cast<unsigned char>(in.get());

Modified: branches/itanium2/Interface/Image.h
==============================================================================
--- branches/itanium2/Interface/Image.h (original)
+++ branches/itanium2/Interface/Image.h Tue Nov  8 13:36:38 2005
@@ -13,6 +13,7 @@
     virtual bool isValid() const = 0;
     virtual void setValid(bool to) = 0;
     virtual void set(const Fragment&) = 0;
+    virtual void get(Fragment&) const = 0;
   private:
     Image(const Image&);
     Image& operator=(const Image&);

Modified: branches/itanium2/Model/Textures/CMakeLists.txt
==============================================================================
--- branches/itanium2/Model/Textures/CMakeLists.txt     (original)
+++ branches/itanium2/Model/Textures/CMakeLists.txt     Tue Nov  8 13:36:38 
2005
@@ -5,6 +5,8 @@
      Textures/CheckerTexture.h
 #     Textures/Constant.cc
      Textures/Constant.h
+#     Textures/ImageTexture.cc
+     Textures/ImageTexture.h
 #     Textures/MarbleTexture.cc
      Textures/MarbleTexture.h
 #     Textures/OakTexture.cc
@@ -12,6 +14,7 @@
 #     Textures/TriVerTexture.cc
      Textures/TriVerTexture.h
 #     Textures/WoodTexture.cc
-     Textures/WoodTexture.h )
+     Textures/WoodTexture.h
+     )
 
 

Added: branches/itanium2/Model/Textures/ImageTexture.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/Model/Textures/ImageTexture.cc    Tue Nov  8 13:36:38 
2005
@@ -0,0 +1,150 @@
+/*
+  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 <Model/Textures/ImageTexture.h>
+#include <Interface/RayPacket.h>
+#include <Interface/Image.h>
+
+#include <Core/Exceptions/InternalError.h>
+
+#include <Core/Geometry/PointVector.h>
+#include <Core/Math/MiscMath.h>
+#include <Core/Math/Trig.h>
+
+namespace Manta {
+  template< class ValueType >
+  ImageTexture< ValueType >::ImageTexture(const Image* image):
+    scale(VectorT< ScalarType, 2 >(1,1)),
+    interpolation_method(NearestNeighbor),
+    u_edge(Wrap), v_edge(Wrap)
+  {
+    bool stereo;
+    int xres, yres;
+    image->getResolution(stereo, xres, yres);
+    if (stereo) {
+      throw SCIRun::InternalError( "ImageTexture doesn't support stereo 
currently", __FILE__, __LINE__);
+    }
+    texture.resize(xres, yres);
+
+    // Now copy over the data
+    for(int y = 0; y < yres; y++) {
+      for(int x = 0; x < xres; x+=Fragment::MaxFragmentSize) {
+        int end = x + Fragment::MaxFragmentSize;
+        if (end > xres) end = xres;
+        Fragment fragment(0, x, end, y);
+        image->get(fragment);
+        for(int i = 0; i < fragment.getSize(); i++) {
+          texture(x+i, y) = fragment.get(i).color;
+        }
+      }
+    }
+  }
+
+  template< class ValueType >
+  void ImageTexture< ValueType >::mapValues(RenderContext const &context,
+                                            RayPacket &rays,
+                                            ValueType results[] ) const
+  {
+    rays.computeTextureCoordinates2( context );
+    PointT<ScalarType, 2> tex_coords[RayPacket::MaxSize];
+
+    // Grab the texture coordinates
+    for( int i = 0; i < rays.getSize(); ++i ) {
+      RayPacket::Element &e = rays.get( i );
+      tex_coords[i] = PointT<ScalarType, 2>(e.texCoords.x(), 
e.texCoords.y());
+      tex_coords[i].multiplyBy(scale);
+    }
+
+    int xres = texture.dim1();
+    int yres = texture.dim2();
+
+    // Grab the textures and do the interpolation as needed
+    switch (interpolation_method) {
+    case Bilinear:
+      {
+        for( int i = 0; i < rays.getSize(); ++i) {
+          ScalarType x = tex_coords[i].x();
+          ScalarType y = tex_coords[i].y();
+          int x_low, y_low, x_high, y_high;
+          ScalarType x_weight_high, y_weight_high;
+
+          BL_edge_behavior(x, u_edge, xres, x_low, x_high, x_weight_high);
+          BL_edge_behavior(y, v_edge, yres, y_low, y_high, y_weight_high);
+
+          // Do the interpolation
+          Color a, b;
+          a = ( texture(x_low,  y_low )*(1-x_weight_high) +
+                texture(x_high, y_low )*   x_weight_high);
+          b = ( texture(x_low,  y_high)*(1-x_weight_high) +
+                texture(x_high, y_high)*   x_weight_high);
+          results[i] = a*(1-y_weight_high) + b*y_weight_high;
+        }
+      }
+      break;
+    case NearestNeighbor:
+      {
+        for( int i = 0; i < rays.getSize(); ++i) {
+          int tx = NN_edge_behavior(static_cast<int>(tex_coords[i].x()*xres),
+                                    u_edge, texture.dim1());
+          int ty = NN_edge_behavior(static_cast<int>(tex_coords[i].y()*yres),
+                                    v_edge, texture.dim2());
+          results[i] = texture(tx, ty);
+        }
+      }
+      break;
+    }
+  } // end mapValues
+
+  template< class ValueType >
+  void ImageTexture< ValueType >::setEdgeBehavior(int new_behavior,
+                                                  int& edge) {
+    switch (new_behavior) {
+    case Wrap:
+    case Clamp:
+      edge = new_behavior;
+      break;
+    default:
+      throw SCIRun::InternalError( "ImageTexture::setEdgeBehavior doesn't 
support this edge behavior", __FILE__, __LINE__);
+      break;
+    }
+  }
+
+  template< class ValueType >
+  void ImageTexture< ValueType >::setInterpolationMethod(int new_method) {
+    switch (new_method) {
+    case NearestNeighbor:
+    case Bilinear:
+      interpolation_method = new_method;
+      break;
+    default:
+      throw SCIRun::InternalError( "ImageTexture::setInterpolationMethod 
doesn't support this interpolation method", __FILE__, __LINE__);
+      break;
+    }
+  }
+  
+} // end namespace Manta

Added: branches/itanium2/Model/Textures/ImageTexture.h
==============================================================================
--- (empty file)
+++ branches/itanium2/Model/Textures/ImageTexture.h     Tue Nov  8 13:36:38 
2005
@@ -0,0 +1,167 @@
+/*
+  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_Model_ImageTexture_h
+#define Manta_Model_ImageTexture_h
+
+#include <Interface/Texture.h>
+#include <Core/Geometry/PointVector.h>
+
+#include <Core/Containers/Array2.h>
+#include <Core/Math/MiscMath.h>
+
+namespace Manta {
+
+  class RayPacket;
+  class RenderContext;
+  class Image;
+
+  template< typename ValueType >
+  class ImageTexture : public Texture< ValueType > {
+  public:
+    ImageTexture(const Image* image);
+    virtual ~ImageTexture() {}
+
+    virtual void mapValues(RenderContext const &context,
+                           RayPacket &rays,
+                           ValueType results[] ) const;
+
+    template<class T>
+    void setScale(const VectorT<T, 2>& scale_in) {
+      // We don't know if T will match ValueType::ScalarType, so we
+      // need to copy the components over one at a time to do the
+      // implicit cast.
+      scale[0] = scale_in[0];
+      scale[1] = scale_in[1];
+    }
+
+    enum {
+      NearestNeighbor,
+      Bilinear
+    };
+
+    enum {
+      Wrap,
+      Clamp
+    };
+
+    void setUEdgeBehavior(int new_behavior) {
+      setEdgeBehavior(new_behavior, u_edge);
+    }
+    void setVEdgeBehavior(int new_behavior) {
+      setEdgeBehavior(new_behavior, v_edge);
+    }
+
+    void setInterpolationMethod(int new_method);
+
+  private:
+    typedef typename ValueType::ScalarType ScalarType;
+
+    inline void BL_edge_behavior(ScalarType val, int behavior, int size,
+                                 int& low, int& high,
+                                 ScalarType& weight_high) const {
+      switch (behavior) {
+      case Wrap:
+        // When we wrap [0,1] maps to [0, 1, ..., size-1, 0].  This is
+        // so we interpolate from texture[size-1] to texture[0].
+        val *= size;
+        low = static_cast<int>(val);
+        weight_high = val - low;
+        // If val is negative then we need to look right (negative)
+        // for the high interpolant.
+        if (val >= 0) {
+          high = low + 1;
+        } else {
+          high = low - 1;
+          // Here we get our negative index from [0..-size-1].  Add
+          // size back in and you get the right shift.  You need to
+          // make sure you do the %size afterwards, though.  This will
+          // catch the case where low%size + size == size.
+          low  =  low%size + size;
+          high = high%size + size;
+          // If val was negative then weight_high will also be
+          // negative.  We don't need a negative number for
+          // interpolation.
+          weight_high = -weight_high;
+        }
+        low  %= size;
+        high %= size;
+        break;
+      case Clamp:
+        if (val < 0) {
+          low = 0;
+          high = 0;
+          weight_high = 0;
+        } else {
+          val *= size-1;
+          low = static_cast<int>(val);
+          if (low > size-2) {
+            low = size-2;
+            weight_high = 0;
+          } else {
+            weight_high = val - low;
+          }
+          high = low + 1;
+        }
+        break;
+      }
+    }
+    inline int NN_edge_behavior(int val, int behavior, int size) const {
+      int result;
+      switch (behavior) {
+      case Wrap:
+        result = val % size;
+        break;
+      case Clamp:
+        result = SCIRun::Clamp(val, 0, size-1);
+        break;
+      }
+      return result;
+    }
+
+    void setEdgeBehavior(int new_behavior, int& edge);
+
+  private:
+    // We make a copy of the data
+    SCIRun::Array2<ValueType> texture;
+    // You can scale the normal [(0,0)..(1,1)] texture coordinates,
+    VectorT< ScalarType, 2 > scale;
+    // Linear, nearest neighbor?
+    int interpolation_method;
+    // Edge behavior
+    int u_edge, v_edge;
+  };
+
+} // end namespace Manta
+
+#ifdef __GNUG__
+// This should instead be a configure variable...
+#include <Model/Textures/ImageTexture.cc>
+#endif
+
+#endif // Manta_Model_ImageTexture_h




  • [MANTA] r702 - in branches/itanium2: . Core/Color Engine/Display Image Interface Model/Textures, bigler, 11/08/2005

Archive powered by MHonArc 2.6.16.

Top of page