Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

vlipolator_trilinear.h

Go to the documentation of this file.
00001 // $Id: vlipolator_trilinear.h,v 1.2 2003/08/13 17:20:38 sarang Exp $
00002 //
00003 // OpenVL - A Library for working with volumetric datasets.
00004 //          http://openvl.sf.net
00005 //
00006 // Copyright (C) 2003  Sarang Lakare <sarang#users.sf.net>
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems to openvl-devel@lists.sf.net or
00024 // at the OpenVL website.
00025 //
00026 
00027 #ifndef _vlInterpolatorTriLinear_h
00028 #define _vlInterpolatorTriLinear_h
00029 
00030 #include <iostream>
00031 #include "vloffset.h"
00032 #include "vlinterpolator.h"
00033 
00034 /*    Trilinear interpolation: x,y,z are the three weights for  */
00035 /*    the x, y, and z directions, and a,b,c,d,e,f,g, and h are  */
00036 /*    the 8 vertices (values) to interpolate between.           */
00037 /*    (x, y, and z are the distances from point a along the x,  */
00038 /*    y, and z axis respectively. )                             */
00039 /*                                                              */
00040 /*                                                              */
00041 /*                         g----------------h                   */
00042 /*            Y           /|               /|                   */
00043 /*                       / |              / |                   */
00044 /*                      /  |             /  |                   */
00045 /*            |        c----------------d   |                   */
00046 /*            |        |   |            |   |                   */
00047 /*            |        |   |            |   |                   */
00048 /*            |        |   |            |   |                   */
00049 /*            |      Z |   |            |   |                   */
00050 /*            |        |   e------------|---f                   */
00051 /*            |     /  |  /             |  /                    */
00052 /*            |    /   | /              | /                     */
00053 /*            |   /    |/               |/                      */
00054 /*            |  /     a----------------b                       */
00055 /*            | /                                               */
00056 /*            |/                                                */
00057 /*            o------------------  X                            */
00058 /*                                                              */
00059 /*                                                              */
00060 
00061 #define vlTriLinear(x,y,z,a,b,c,d,e,f,g,h)                 \
00062        ((((a)*(1.0 - (z))               +               \
00063           (e)*(z))*(1.0 - (y))          +               \
00064          ((c)*(1.0 - (z))               +               \
00065           (g)*(z))*(y))*(1.0-(x))       +               \
00066         (((b)*(1.0 - (z))               +               \
00067           (f)*(z))*(1.0 - (y))          +               \
00068          ((d)*(1.0 - (z))               +               \
00069           (h)*(z))*(y))*(x))
00070 
00071 
00072 
00073 template <typename DataType, vlLayoutType Layout>
00074 class vlInterpolatorTriLinear : public vlInterpolator<DataType, Layout>
00075 {
00076 public:
00077   vlInterpolationType type() { return vlInterpolation::TriLinear; };
00078 
00079   std::string name() { return ("TriLinear"); };
00080 
00082   vlLayoutType layout() { return Layout; };
00083 
00084   DataType getValueAt(vlVolIterConst<DataType, Layout> & iter, const vlPoint3f & position, bool check=true)
00085   {
00086     vlPoint3ui oldPos = iter.pos();
00087     vlPoint3ui pos((int)position.x(), (int)position.y(), (int)position.z());
00088     iter.moveTo(pos);
00089 
00090     DataType a,b,c,d,e,f,g,h;
00091     a = iter.get();
00092     b = iter.getRelativeX(1);
00093     c = iter.getRelativeY(1);
00094     d = iter.getRelative(vlOffset(vlTriple<int16>(1,1,0)));
00095     e = iter.getRelativeZ(1);
00096     f = iter.getRelative(vlOffset(vlTriple<int16>(1,0,1)));
00097     g = iter.getRelative(vlOffset(vlTriple<int16>(0,1,1)));
00098     h = iter.getRelative(vlOffset(vlTriple<int16>(1,1,1)));
00099 
00100 //    std::cout << "abcd.. " << a << "," << b << "," << c << "," << d << ","
00101 //                           << e << "," << f << "," << g << "," << h << std::endl;
00102     float x,y,z;
00103     x = position.x() - (int)position.x();
00104     y = position.y() - (int)position.y();
00105     z = position.z() - (int)position.z();
00106 
00107 //    std::cout << "xyz.. " << x << "," << y << "," << z << std::endl;
00108         
00109     DataType value = vlTriLinear(x,y,z,a,b,c,d,e,f,g,h);
00110     
00111     iter.moveTo(oldPos);    
00112     return (value);
00113   };
00114   
00116   DataType getValueAtOffset(vlVolIterConst<DataType, Layout> & iter, const vlPoint3f & offset, bool check=true)
00117   {
00118     int16 ofX = (offset.x() < 0.0)?-1:1;
00119     int16 ofY = (offset.y() < 0.0)?-1:1;
00120     int16 ofZ = (offset.z() < 0.0)?-1:1;
00121 
00122     
00123     DataType a,b,c,d,e,f,g,h;
00124     a = iter.get();
00125     b = iter.getRelativeX(ofX);
00126     c = iter.getRelativeY(ofY);
00127     d = iter.getRelative(vlOffset(vlTriple<int16>(ofX,ofY,0)));
00128     e = iter.getRelativeZ(ofZ);
00129     f = iter.getRelative(vlOffset(vlTriple<int16>(ofX,0,ofZ)));
00130     g = iter.getRelative(vlOffset(vlTriple<int16>(0,ofY,ofZ)));
00131     h = iter.getRelative(vlOffset(vlTriple<int16>(ofX,ofY,ofZ)));
00132 
00133 //    std::cout << "abcd.. " << a << "," << b << "," << c << "," << d << ","
00134 //                           << e << "," << f << "," << g << "," << h << std::endl;
00135     
00136     DataType temp;
00137     float x,y,z;
00138     x = offset.x() - (int)offset.x();
00139     y = offset.y() - (int)offset.y();
00140     z = offset.z() - (int)offset.z();
00141 
00142 //    std::cout << "xyz.. " << x << "," << y << "," << z << std::endl;
00143 
00144 //    std::cout << "About to start swapping.. " << std::endl;
00145     
00146     // Perform swaps so that "a" represents the base voxel and offsets are all +ve
00147     if(ofX < 0) {
00148 //      std::cout << "Swapping x" << std::endl;
00149       temp = b;
00150       b = a;
00151       a = temp;
00152 
00153       temp = d;
00154       d = c;
00155       c = temp;
00156 
00157       temp = f;
00158       f = e;
00159       e = temp;
00160 
00161       temp = h;
00162       h = g;
00163       g = temp;
00164 
00165       x = x+1.0;
00166     }
00167 
00168     if(ofY < 0) {
00169 //      std::cout << "Swapping y" << std::endl;      
00170       temp = c;
00171       c = a;
00172       a = temp;
00173 
00174       temp = d;
00175       d = b;
00176       b = temp;
00177 
00178       temp = g;
00179       g = e;
00180       e = temp;
00181 
00182       temp = h;
00183       h = f;
00184       f = temp;
00185 
00186       y = y+1.0;
00187     }
00188 
00189     if(ofZ < 0) {
00190 //      std::cout << "Swapping z" << std::endl;      
00191       temp = e;
00192       e = a;
00193       a = temp;
00194 
00195       temp = f;
00196       f = b;
00197       b = temp;
00198 
00199       temp = g;
00200       g = c;
00201       c = temp;
00202 
00203       temp = h;
00204       h = d;
00205       d = temp;
00206 
00207       z = z+1.0;                                                
00208     }
00209 
00210 //    std::cout << "abcd.. " << a << "," << b << "," << c << "," << d << ","
00211 //                           << e << "," << f << "," << g << "," << h << std::endl;
00212 
00213 //    std::cout << "xyz.. " << x << "," << y << "," << z << std::endl;
00214         
00215     DataType value = vlTriLinear(x,y,z,a,b,c,d,e,f,g,h);
00216 
00217     return (value);
00218   };           
00219 };
00220 
00221 #endif // _vlInterpolatorTriLinear_h

Generated on Fri Mar 18 11:33:13 2005 for OpenVL by doxygen 1.3.3