FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
LinearIpol.hpp
1#ifndef __IPOL_LINEAR_HPP
2#define __IPOL_LINEAR_HPP
3
4//#include <iostream>
5#include "IpolDelimiter.hpp"
6#include <assert.h>
7
8namespace Fiber
9{
10//using namespace std;
11
23template <class T>
25{
26static T zero()
27 {
28 return T({0});
29 }
30};
31
38template <class T, bool Vectorial = false>
40{
41public:
43 typedef T value_type;
44
45 template <class Storage1D, class Limiter>
46static T interpolate(const Storage1D&Data, double t, index_t size, const Limiter&L)
47 {
48 assert(size > 0);
49#ifdef DEBUG_LINEAR_IPOL
50 cout << "LinearIpol @ "<< t << " of " << size << endl;
51 printf("LinearIpol():%lg of %d\n", t, int(size) );
52#endif
53 if (t<=0 ) return L.limit(Data[ 0 ] );
54 if (t+1>=size ) return L.limit(Data[size-1]);
55
56 index_t i = index_t(t);
57 t = t - floor(t);
58
59 if (t==0.0)
60 return L.limit(Data[i]);
61
62#ifdef DEBUG_LINEAR_IPOL
63 cout << " LinearIpol: [" << i << "]=" << Data[i] << ", [" << i+1 << "]="<<Data[i+1]<<" @ " << t << endl;
64 printf("LinearIpol(%d,%d)@%lg\n",i,i+1, t);
65#endif
66
67 return L.limit(Data[i]) * (1-t) + L.limit(Data[i+1]) * t;
68 }
69
70 template <class Storage1D, class Limiter>
71static T derivative(const Storage1D&Data, double t, index_t size, const Limiter&L)
72 {
73// assert(size > 1);
74
75// need to think about return value here, since T might not always have a constructor with 0 value
76// maybe need a type trait here
79
80 index_t i = index_t(t);
81// printf("LinearIpol Derivative(%d,%d)@%lg\n",i,i+1, t);
82 return L.limit(Data[i+1]) - L.limit(Data[i]);
83 }
84};
85
86
92template <class T>
94{
95public:
97 typedef T value_type;
98
99 template <class Storage1D, class Limiter>
100static T interpolate(const Storage1D&Data, double t, index_t size, const Limiter&L)
101 {
102 assert(size > 0);
103
104 if (t<=0 ) return L.limit(Data[ 0 ] );
105 if (t+1>=size ) return L.limit(Data[size-1]);
106
107 index_t i = index_t(t);
108 t = t - floor(t);
109
110 if (t==0.0)
111 return L.limit(Data[i]);
112
113 return L.limit(Data[i]) + (L.limit(Data[i+1]) - L.limit(Data[i])) * t;
114 }
115
116 template <class Storage1D, class Limiter>
117static T derivative(const Storage1D&Data, double t, index_t size, const Limiter&L)
118 {
119// assert(size > 1);
120
121 //if (t<0 ) return T(0);
122 //if (t>=size-1 ) return T(0);
123
124 index_t i = index_t(t);
125 // printf("LinearIpol Derivative(%d,%d)@%lg\n",i,i+1, t);
126 return L.limit(Data[i+1]) - L.limit(Data[i]);
127 }
128};
129
130} /* namespace Fiber */
131
132#endif /* __IPOL_LINEAR_HPP */
constexpr __enable_if_is_duration< _ToDur > floor(const duration< _Rep, _Period > &__d)
valarray< size_t > size() const
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
ostream cout
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
T value_type
Export the type argument.
Definition LinearIpol.hpp:97
Linear interpolation.
Definition LinearIpol.hpp:40
T value_type
Export the type argument.
Definition LinearIpol.hpp:43
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
Helper class (type trait) for class LinerIpol, which for a given type T provides a static member func...
Definition LinearIpol.hpp:25