40 #ifndef _interpolator_h
41 #define _interpolator_h
51 #ifndef SWIG // STD headers are bad for Swig
64 template <
typename InterpolatableType,
typename InterpolatorType>
class TrackStorage;
85 typedef std::vector<InterpolatableType>
Storage;
93 {
return ((End-Begin)*Location)+Begin; }
145 template<
typename TIterator>
148 Whole DataPointCount = std::distance(Begin,End);
149 Whole LineSegmentCount = DataPointCount-1;
151 if(LineSegmentCount<1)
153 if(1==LineSegmentCount)
154 {
return InterpolateMath(*(Begin), *(Begin+1), Location); }
156 Whole UsingLineSegment = Location *
Real(LineSegmentCount);
157 if(UsingLineSegment>=LineSegmentCount)
162 return InterpolateMath(*(Begin+UsingLineSegment),
163 *(Begin+UsingLineSegment+1),
175 template<
typename TIterator>
184 {
return InterpolateMath(*Begin, *(Begin+1), Location); }
186 return GetInterpolatedFromMultiple(Begin, End, Location);
198 if(LinearInterpolaterNode)
204 if( VersionAttr.
SetValue(
"1") && TypeAttr.
SetValue(InterpolatableType::GetSerializableName()) )
208 SerializeError(
"Create XML Attribute Values", GetSerializableName(),
true);
211 SerializeError(
"Create XML Attributes", GetSerializableName(),
true);
214 SerializeError(
"Create XML Serialization Node", GetSerializableName(),
true);
227 if(OneNode.
GetAttribute(
"InterpolatableType").
AsString() == InterpolatableType::GetSerializableName())
245 {
return String(
"LinearInterpolator"); }
260 template <
typename T>
268 typedef std::vector<InterpolatableType>
Storage;
289 template<
typename TIterator>
292 if(Begin==End || Begin+1==End)
298 std::vector<T> SubSection;
299 for(TIterator Iter=Begin; Iter!=End-1; Iter++)
301 return Interpolate(SubSection.begin(),SubSection.end(),Location);
313 if(BezierInterpolaterNode)
319 if( VersionAttr.
SetValue(
"1") && TypeAttr.
SetValue(InterpolatableType::GetSerializableName()) )
323 SerializeError(
"Create XML Attribute Values", GetSerializableName(),
true);
326 SerializeError(
"Create XML Attributes", GetSerializableName(),
true);
329 SerializeError(
"Create XML Serialization Node", GetSerializableName(),
true);
342 if(OneNode.
GetAttribute(
"InterpolatableType").
AsString() == InterpolatableType::GetSerializableName())
360 {
return String(
"BezierInterpolator"); }
374 template <
typename T>
391 template<
typename TIterator>
404 std::vector<T> Points(Begin, End);
405 std::vector<Real> Spacing(Points.size());
408 for(std::vector<Real>::iterator Iter=Spacing.begin();
413 CurrentJump+=JumpSize;
417 return Spliney.interpolate(Location);
433 std::ostream& operator << (std::ostream& stream, const Mezzanine::LinearInterpolator<T>& Lint)
458 std::ostream& operator << (std::ostream& stream, const Mezzanine::BezierInterpolator<T>& Lint)
478 #endif // Include guard
static T GetInterpolatedFromMultiple(TIterator Begin, TIterator End, Real Location)
Handles Interpolation of multiple points.
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
A light-weight handle for manipulating attributes in DOM tree.
CubicSpline< Real, InterpolatableType > Storage
The storage for type for a cubic spline.
A simple functor for interpolating data points in a simple way.
static void ProtoDeSerialize(const XML::Node &OneNode)
This does not create or change the object it deserializes, but it does verify type info...
static T Interpolate(TIterator Begin, TIterator End, Real Location)
Calculates the desired location on a cubic spline.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
All the definitions for datatypes as well as some basic conversion functions are defined here...
std::ostream & Serialize(std::ostream &Stream, const T &Converted, const String &Indent=String(""))
Convert any class that supports serialization or has a serializer to a string of chars in a stream...
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
const Char8 * AsString(const Char8 *def="") const
Attempts to convert the value of the attribute to a String and returns the results.
static void ProtoSerialize(XML::Node &CurrentRoot)
Append a node for with enough information to deserialize to the passed node.
T InterpolatableType
The type this will interpolate.
This implements the exception hiearchy for Mezzanine.
A simple functor for interpolating data points in a simple way.
std::vector< InterpolatableType > Storage
The storage to use with thison tracks.
float Real
A Datatype used to represent a real floating point number.
The interface for serialization.
bool SetValue(const Char8 *rhs)
Set the value of this.
static String GetSerializableName()
get the name of this class for serialization purposes
static T Interpolate(TIterator Begin, TIterator End, Real Location)
Get a value at a given location between two others.
A light-weight handle for manipulating nodes in DOM tree.
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
Thrown when a passed parameter is checked at runtime and not in the expected range.
T InterpolatableType
The type this will interpolate.
static String GetSerializableName()
get the name of this class for serialization purposes
std::istream & DeSerialize(std::istream &Stream, T &Converted)
Deserialize the next xml tag in the stream into a specific in memory class instance.
std::vector< InterpolatableType > Storage
The storage to use with thison tracks.
Thrown when the identity string wasn't valid at all.
static void ProtoSerialize(XML::Node &CurrentRoot)
Append a node for with enough information to deserialize to the passed node.
static T InterpolateMath(T Begin, T End, Real Location)
Get a value at a given location between exactly two others.
static T Interpolate(TIterator Begin, TIterator End, Real Location)
This will interpolates data point with GetInterpolatedFromMultiple or InterpolateMath as required...
static void ProtoDeSerialize(const XML::Node &OneNode)
This does not create or change the object it deserializes, but it does verify type info...
The bulk of the engine components go in this namspace.
double PreciseReal
A Real number that is at least as precise as the Real and could be considerably moreso, perhaps Doubly precise. This type might be poorly aligned but very precise.
A class for interpolating data with arbitrary.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
std::istream & operator>>(std::istream &stream, Mezzanine::LinearInterpolator< T > &Lint)
Used to de-serialize an Mezzanine::LinearInterpolator from a stream.
const Char8 * Name() const
ptrdiff_tGet the name of this Node.
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
std::string String
A datatype used to a series of characters.
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
T InterpolatableType
The type this will interpolate.
If something specifically needs the linear interpolator for T they should use this.