Assignments
Assignments
interpolation.todo.inl
Go to the documentation of this file.
1/*
2Copyright (c) 2019, Michael Kazhdan
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without modification,
6are permitted provided that the following conditions are met:
7
8Redistributions of source code must retain the above copyright notice, this list of
9conditions and the following disclaimer. Redistributions in binary form must reproduce
10the above copyright notice, this list of conditions and the following disclaimer
11in the documentation and/or other materials provided with the distribution.
12
13Neither the name of the Johns Hopkins University nor the names of its contributors
14may be used to endorse or promote products derived from this software without specific
15prior written permission.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
19OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26DAMAGE.
27*/
28
29#include <math.h>
30#include <Util/exceptions.h>
31
32namespace Util
33{
35 // Interpolation //
37 template< typename SampleType >
38 SampleType Interpolation::Sample( const std::vector< SampleType > &samples , double t , int interpolationType )
39 {
40 switch( interpolationType )
41 {
42 case NEAREST:
43 {
44 t *= samples.size();
45 int it1 = (int)floor(t);
46 int it2 = ( it1 + 1 ) % samples.size();
47 t -= it1;
48 if( t<0.5 ) return samples[it1];
49 else return samples[it2];
50 break;
51 }
52 case LINEAR:
54 // Perform linear interpolation here //
56 WARN_ONCE( "method undefined" );
57 return samples[0];
58 break;
59 case CATMULL_ROM:
61 // Perform Catmull-Rom interpolation here //
63 WARN_ONCE( "method undefined" );
64 return samples[0];
65 break;
68 // Perform uniform cubic b-spline interpolation here //
70 WARN_ONCE( "method undefined" );
71 return samples[0];
72 break;
73 default:
74 ERROR_OUT( "unrecognized interpolation type" );
75 return samples[0];
76 }
77 }
78}
@ NEAREST
Definition interpolation.h:43
@ LINEAR
Definition interpolation.h:44
@ UNIFORM_CUBIC_B_SPLINE
Definition interpolation.h:46
@ CATMULL_ROM
Definition interpolation.h:45
static SampleType Sample(const std::vector< SampleType > &samples, double t, int interpolationType)
Definition interpolation.todo.inl:38
#define WARN_ONCE(...)
Definition exceptions.h:148
#define ERROR_OUT(...)
Definition exceptions.h:154
Definition algebra.h:7