SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CatmullRomSpline.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2010 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9  License for the specific language governing rights and limitations under
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 
30 
31 ///
32 ///@class CatmullRomSpline
33 ///
34 ///@author
35 /// Steven G. Parker
36 /// Department of Computer Science
37 /// University of Utah
38 ///
39 ///@date March 1994
40 ///
41 
42 #ifndef SCI_Math_CatmullRomSpline_h
43 #define SCI_Math_CatmullRomSpline_h
44 
45 #include <Core/Containers/Array1.h>
46 
47 namespace SCIRun {
48 
49 
50 template<class T>
52 {
53 public:
55  CatmullRomSpline( const Array1<T>& );
56  CatmullRomSpline( const int );
58 
59  void setData( const Array1<T>& );
60  void add( const T& );
61  void insertData( const int, const T& );
62  void removeData( const int );
63 
64  void clear();
65 
66  T operator()( double ) const; // 0-1
67  T& operator[]( const int );
68 
69 private:
70 
71  Array1<T> d;
72 
73 };
74 
75 } // End namespace SCIRun
76 
77 ////////////////////////////////////////////////////////////
78 // Start of included CatmullRomSpline.cc
79 
80 #include <Core/Util/Assert.h>
81 
82 namespace SCIRun {
83 
84 template<class T>
86  d(0)
87 {
88 }
89 
90 template<class T>
92  d(data)
93 {
94 }
95 
96 template<class T>
98  d(n)
99 {
100 }
101 
102 template<class T>
104  d(s.d)
105 {
106 }
107 
108 template<class T>
109 void
111 {
112  d = data;
113 }
114 
115 template<class T>
116 void
118 {
119  d.remove_all();
120 }
121 
122 template<class T>
123 void
125 {
126  d.add(obj);
127 }
128 
129 template<class T>
130 void
131 CatmullRomSpline<T>::insertData( const int idx, const T& obj )
132 {
133  d.insert(idx, obj);
134 }
135 
136 template<class T>
137 void
139 {
140  d.remove(idx);
141 }
142 
143 template<class T>
144 T
146 {
147  int idx = (int)x;
148  double t = x - idx;
149 
150  double t2 = t * t;
151  double t3 = t2 * t;
152 
153  int size = d.size();
154 
155  int idx1 = (idx-1+size) % size;
156  int idx2 = (idx +size) % size;
157  int idx3 = (idx+1+size) % size;
158  int idx4 = (idx+2+size) % size;
159 
160  T p0 = d[ idx1 ];
161  T p1 = d[ idx2 ];
162  T p2 = d[ idx3 ];
163  T p3 = d[ idx4 ];
164 
165  T result = ( (p0*-1 + p1*3 + p2*-3 + p3 ) * (t3 * 0.5)+
166  (p0*2 + p1*-5 + p2*4 + p3*-1) * (t2 * 0.5)+
167  (p0*-1 + p2 ) * (t * 0.5)+
168  ( p1 ) );
169 
170  return result;
171 }
172 
173 template<class T>
174 T&
176 {
177  return d[idx];
178 }
179 
180 } // End namespace SCIRun
181 
182 
183 #endif /* SCI_Math_CatmullRomSpline_h */
Interface to dynamic 1D array class.
void add(const T &)
Definition: CatmullRomSpline.h:124
void removeData(const int)
Definition: CatmullRomSpline.h:138
void setData(const Array1< T > &)
Definition: CatmullRomSpline.h:110
dictionary data
Definition: eabLatVolData.py:11
T & operator[](const int)
Definition: CatmullRomSpline.h:175
T operator()(double) const
Definition: CatmullRomSpline.h:145
int n
Definition: eab.py:9
Definition: Array1.h:51
void insertData(const int, const T &)
Definition: CatmullRomSpline.h:131
Definition: CatmullRomSpline.h:51
void clear()
Definition: CatmullRomSpline.h:117
CatmullRomSpline()
Definition: CatmullRomSpline.h:85
int size
Definition: eabLatVolData.py:2