FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
CatmullSplineIpol.hpp
1
2//
3// $Id: CatmullSplineIpol.hpp,v 1.1 2006/07/07 14:10:53 werner Exp $
4//
5// $Log: CatmullSplineIpol.hpp,v $
6// Revision 1.1 2006/07/07 14:10:53 werner
7// Intermediate state: multidimensional interpolation with on-demand
8// fractional loading appears to work, but still problem with vectorfield
9// interpolation.
10//
11// Revision 1.5 2004/07/09 20:15:26 werner
12// Added local alignment capability when interpolating vector fields and
13// option to compute the interpolated derivative.
14//
15// Revision 1.4 2004/07/04 17:24:03 werner
16// Recursive multidimensional Interpolation interface implemented.
17//
18// Revision 1.3 2004/06/18 23:29:46 werner
19// Intermediate version that supports the recursive interpolation scheme.
20// Need to beautify the interface, fix some indexing bug, and make it to
21// work with the ViewPtr.
22//
23// Revision 1.2 2004/06/15 22:45:31 werner
24// Enhanced the fixed array member functions.
25// Using better name for interpolation template parameters.
26//
27// Revision 1.1 2004/06/14 22:42:00 werner
28// Moved interpolation files from light++ to VecAl and Multindex from Fiber to VecAl.
29//
30// Revision 1.1 2002/07/11 16:11:52 werner
31// Support for generic spline interpolation and camera paths added.
32//
33// Created 2002/07/11 17:28:21 bzfbenge
34// Initial version
35//
37#ifndef __CATMULLROMSPLINE_HPP
38#define __CATMULLROMSPLINE_HPP "Created 11.07.2002 17:28:21 by bzfbenge"
39
40#include "IpolDelimiter.hpp"
41#include <assert.h>
42
43namespace Fiber
44{
45
51template <class T>
53{
54
55double MatrixTerm(int i, double t, double t2, double t3)
56{
57static const double Matrix [4][4] =
58 { { -1.0, 3.0, -3.0, 1.0 },
59 { 2.0, -5.0, 4.0, -1.0 },
60 { -1.0, 0, 1.0, 0 },
61 { 0, 2.0, 0, 0 } };
62
63 return Matrix[0][3-i] * t3 +
64 Matrix[1][3-i] * t2 +
65 Matrix[2][3-i] * t +
66 Matrix[3][3-i];
67}
68
69double dMatrixTerm(int i, double t, double t2)
70{
71static const double Matrix [4][4] =
72 { { -1.0, 3.0, -3.0, 1.0 },
73 { 2.0, -5.0, 4.0, -1.0 },
74 { -1.0, 0, 1.0, 0 },
75 { 0, 2.0, 0, 0 } };
76
77 return Matrix[0][3-i] * 3*t2 +
78 Matrix[1][3-i] * 2*t +
79 Matrix[2][3-i];
80}
81
82public:
83
84template <class Storage1D, class Limiter>
85static T interpolate(const Storage1D&Data, double t, index_t size, const Limiter&L)
86{
87 /* there is something to do */
88 // TODO: Check for Samplings.size() < 2 !
89 assert(size > 2);
90
91int lastPoint = size - 1; // point numbering starts with 0
92
93/*
94 CatmullRomSpline cannot interpolate the first and the last point,
95 so LinearInterpolation is used there
96
97 (mn) using the first/last point twice would also help and so
98 no LinearInterpolation is needed
99*/
100 if ( t>=0 && t<1 )
101 {
102 T InterPol = Data[1] - Data[0];
103 return Data[0] + t * InterPol;
104 }
105
106 if ( t>lastPoint-1 && t <= lastPoint )
107 {
108 T InterPol = Data[ lastPoint ] - Data[ lastPoint - 1 ];
109 return Data[ lastPoint - 1 ] + ( t - ( lastPoint - 1 ) ) * InterPol;
110 }
111
112index_t index = index_t(t) + 2;
113 t = t - floor(t);
114
115T sum;
116
117double t2 = t*t,
118 t3 = t2*t;
119
120static const double Matrix [4][4] =
121 { { -1.0, 3.0, -3.0, 1.0 },
122 { 2.0, -5.0, 4.0, -1.0 },
123 { -1.0, 0, 1.0, 0 },
124 { 0, 2.0, 0, 0 } };
125
126 for(int i=0; i<4; i++)
127 {
128 double MatrixTerm = Matrix[0][3-i] * t3 +
129 Matrix[1][3-i] * t2 +
130 Matrix[2][3-i] * t +
131 Matrix[3][3-i];
132
133 if (i==0)
134 sum = MatrixTerm * Data[ index-i ];
135 else
136 sum += MatrixTerm * Data[ index-i ];
137 }
138
139 return sum * 0.5;
140}
141}; // class CatMullRomSpline
142
143} /* namespace VecAl */
144
145#endif /* __CATMULLROMSPLINE_HPP */
constexpr __enable_if_is_duration< _ToDur > floor(const duration< _Rep, _Period > &__d)
_Tp sum() const
valarray< size_t > size() const
Catmull-Rom cubic spline interpolation.
Definition CatmullSplineIpol.hpp:53
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
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