FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
CubicIpol.hpp
1
2//
3// $Id: CubicIpol.hpp,v 1.3 2007/02/22 19:55:34 werner Exp $
4//
5// $Log: CubicIpol.hpp,v $
6// Revision 1.3 2007/02/22 19:55:34 werner
7// adjusted fixed array interface
8//
9// Revision 1.2 2006/07/30 20:43:42 werner
10// Partial Derivative of multidimensional arrays enabled.
11//
12// Revision 1.1 2006/07/07 14:10:53 werner
13// Intermediate state: multidimensional interpolation with on-demand
14// fractional loading appears to work, but still problem with vectorfield
15// interpolation.
16//
17// Revision 1.9 2004/08/17 16:59:52 werner
18// Towards compilation with gcc 3.3.3
19//
20// Revision 1.8 2004/08/12 16:08:45 werner
21// Various improvements for implementing the tangential space
22//
23// Revision 1.7 2004/07/14 15:45:14 werner
24// Outsourcing of quadratic matrices into its own header file.
25// Added great gaus decomposition from Marcus Weber that allows
26// multiple right-hand sides.
27//
28// Revision 1.6 2004/07/12 10:29:24 werner
29// Computing Lower Christoffels in demo application.
30//
31// Revision 1.5 2004/07/09 20:15:26 werner
32// Added local alignment capability when interpolating vector fields and
33// option to compute the interpolated derivative.
34//
35// Revision 1.4 2004/07/04 17:24:03 werner
36// Recursive multidimensional Interpolation interface implemented.
37//
38// Revision 1.3 2004/06/18 23:29:46 werner
39// Intermediate version that supports the recursive interpolation scheme.
40// Need to beautify the interface, fix some indexing bug, and make it to
41// work with the ViewPtr.
42//
43// Revision 1.2 2004/06/15 22:45:31 werner
44// Enhanced the fixed array member functions.
45// Using better name for interpolation template parameters.
46//
47// Revision 1.1 2004/06/14 22:42:00 werner
48// Moved interpolation files from light++ to VecAl and Multindex from Fiber to VecAl.
49//
51#ifndef __IPOL_CUBIC_HPP
52#define __IPOL_CUBIC_HPP "Created 11.06.2004 22:28:21 by bzfbenge"
53
54#include "Index.hpp"
55#include <eagle/vecmath.hpp>
56#include <assert.h>
57
58namespace Fiber
59{
60
68template <class T>
70{
71public:
73 typedef T value_type;
74
75 template <class Storage1D, class Limiter>
76static T interpolate(const Storage1D&Data, double t, index_t size, const Limiter&L)
77 {
78 // TODO: Check for Samplings.size() < 2 !
79 assert(size > 2);
80
81 // printf("CubicIpol[%lg]\n", t);
82
83 if (t<0 ) return L.limit(Data[0] );
84 if (t>=size ) return L.limit(Data[size-1]);
85
86 const double derivation_factor = 2;
87
88 index_t i = index_t(t);
89 double x = t - floor(t);
90 double x2 = x*x,
91 x3 = x2*x,
92
93 // Hermite'sche Polynome
94 h00 = 2*x3 - 3*x2 + 1,
95// h10 = 1 - h00,
96 h01 = x3 - 2*x2 + x,
97 h11 = x3 - x2;
98
99 // Boundary conditions.
100 index_t i_1 = i-1, i1 = i+1, i2 = i+2;
101 if (i_1<0 || i_1>=size) i_1 = 0;
102 if (i < 0 ) i = 0;
103 if (i >=size) i = size-1;
104 if (i1<0) i1 = 0;
105 if (i2<0) i2 = 0;
106 if (i1>=size) i1 = size-1;
107 if (i2>=size) i2 = size-1;
108
109 // printf("CubicIpol[%d,%d,%d,%d]\n", i_1, i, i1, i2);
110
111/*
112 // Estimate the Derivatives at A and B
113 T d0 = ( Data[i+1] - Data[i-1] ) * (1./derivation_factor);
114 d1 = ( Data[i+2] - Data[i ] ) * (1./derivation_factor);
115
116 // < linear term > < cubic term >
117 return Data[i]*h00 + Data[i+1]*h10 + d0 * h01 + d1 * h11;
118
119 Reordering to reduce the number of data array evaluations yields:
120*/
121
122// ( (L.limit( Data[i ] ))*(h00 - (1./derivation_factor) * h11 )
123// + (L.limit( Data[i1 ] ))*(h10 + (1./derivation_factor) * h01 )
124// - (L.limit( Data[i_1] ))* (1./derivation_factor) * h01
125// + (L.limit( Data[i2 ] ))* (1./derivation_factor) * h11 );
126
127// this version also works for Eagle::PhysicalSpace::point
128 return T( L.limit(Data[i1])
129 + (L.limit(Data[i])-L.limit(Data[i1]))*h00
130 + (L.limit(Data[i1])-L.limit(Data[i_1]))*h01*(1./derivation_factor)
131 + (L.limit(Data[i2])-L.limit(Data[i]))*h11*(1./derivation_factor));
132 }
133
134 template <class Storage1D, class Limiter>
135static T derivative(const Storage1D&Data, double t, index_t size, const Limiter&L)
136 {
137 index_t i = index_t(t);
138 double x = t - floor(t),
139 x2 = x*x,
140
141 // Ableitungen der Hermite'schen Polynome
142 h00 = 6*x*(x - 1) ,
143 h10 = - h00,
144 h01 = 3*x2 - 4*x + 1,
145 h11 = 3*x2 - 2*x;
146
147 // printf("Deriv CubicIpol[%lg] ->", t);
148
149 const double derivation_factor = 2;
150
151 // Boundary conditions.
152 index_t i_1 = i-1, i1 = i+1, i2 = i+2;
153 if (i_1<0 || i_1>=size) i_1 = 0;
154 if (i < 0 ) i = 0;
155 if (i >=size) i = size-1;
156 if (i1<0) i1 = 0;
157 if (i2<0) i2 = 0;
158 if (i1>=size) i1 = size-1;
159 if (i2>=size) i2 = size-1;
160
161 // printf("Indices: [%d,%d,%d,%d]", i_1, i, i1, i2);
162 // printf("Values: [%lg %lg %lg %lg]\n", Data[i_1], Data[i], Data[i1], Data[i2]);
163
164 T Di_1 = L.limit(Data[i_1]),
165 Di = L.limit(Data[i ]),
166 Di1 = L.limit(Data[i1]),
167 Di2 = L.limit(Data[i2]);
168
169 // printf("SValues: [%lg %lg %lg %lg] %s\n",
170 // double(Di_1), double(Di), double(Di1), double(Di2), typeid(Data).name() );
171
172 // Estimate the Derivatives at A and B
173 T d0 = ( Di1 - Di_1 ) * (1./derivation_factor),
174 d1 = ( Di2 - Di ) * (1./derivation_factor);
175
176 return Di*h00 + Di1*h10 + d0 * h01 + d1 * h11;
177 }
178};
179
180} /* namespace VecAl */
181
182#endif /* __IPOL_CUBIC_HPP */
constexpr __enable_if_is_duration< _ToDur > floor(const duration< _Rep, _Period > &__d)
valarray< size_t > size() const
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
Cubic interpolation using Hermite polynoms.
Definition CubicIpol.hpp:70
T value_type
Export the type argument.
Definition CubicIpol.hpp:73
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
IndexTypeConfig< sizeof(void *)>::index_t index_t
Define the index type as according to the size of a pointer, i.e.
Definition Index.hpp:22