00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _vlInterpolatorTriLinear_h
00028 #define _vlInterpolatorTriLinear_h
00029
00030 #include <iostream>
00031 #include "vloffset.h"
00032 #include "vlinterpolator.h"
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
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
00101
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
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
00134
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
00143
00144
00145
00146
00147 if(ofX < 0) {
00148
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
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
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
00211
00212
00213
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