summaryrefslogtreecommitdiff
path: root/gpr/source/lib/dng_sdk/dng_1d_function.h
blob: aee59cad79975cb7da8137cbd87411fcc9a6f24c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*****************************************************************************/
// Copyright 2006 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE:  Adobe permits you to use, modify, and distribute this file in
// accordance with the terms of the Adobe license agreement accompanying it.
/*****************************************************************************/

/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_1d_function.h#1 $ */ 
/* $DateTime: 2012/05/30 13:28:51 $ */
/* $Change: 832332 $ */
/* $Author: tknoll $ */

/** \file
 * Classes for a 1D floating-point to floating-point function abstraction.
 */

/*****************************************************************************/

#ifndef __dng_1d_function__
#define __dng_1d_function__

/*****************************************************************************/

#include "dng_classes.h"
#include "dng_types.h"

/*****************************************************************************/

/// \brief A 1D floating-point function.
///
/// The domain (input) is always from 0.0 to 1.0, while the range (output) can be an arbitrary interval.

class dng_1d_function
	{
	
	public:
	
		virtual ~dng_1d_function ();

		/// Returns true if this function is the map x -> y such that x == y for all x . That is if Evaluate(x) == x for all x.

		virtual bool IsIdentity () const;

		/// Return the mapping for value x.
		/// This method must be implemented by a derived class of dng_1d_function and the derived class determines the
		/// lookup method and function used.
		/// \param x A value between 0.0 and 1.0 (inclusive).
		/// \retval Mapped value for x

		virtual real64 Evaluate (real64 x) const = 0;

		/// Return the reverse mapped value for y.
		/// This method can be implemented by derived classes. The default implementation uses Newton's method to solve
		/// for x such that Evaluate(x) == y.
		/// \param y A value to reverse map. Should be within the range of the function implemented by this dng_1d_function .
		/// \retval A value x such that Evaluate(x) == y (to very close approximation).

		virtual real64 EvaluateInverse (real64 y) const;
	
	};

/*****************************************************************************/

/// An identity (x -> y such that x == y for all x) mapping function.

class dng_1d_identity: public dng_1d_function
	{
	
	public:
		/// Always returns true for this class.

		virtual bool IsIdentity () const;
	
		/// Always returns x for this class.

		virtual real64 Evaluate (real64 x) const;
		
		/// Always returns y for this class.

		virtual real64 EvaluateInverse (real64 y) const;

		/// This class is a singleton, and is entirely threadsafe. Use this method to get an instance of the class.

		static const dng_1d_function & Get ();
	
	};

/*****************************************************************************/

/// A dng_1d_function that represents the composition (curry) of two other dng_1d_functions.

class dng_1d_concatenate: public dng_1d_function
	{
	
	protected:
	
		const dng_1d_function &fFunction1;
		
		const dng_1d_function &fFunction2;
	
	public:
	
		/// Create a dng_1d_function which computes y = function2.Evaluate(function1.Evaluate(x)).
		/// Compose function1 and function2 to compute y = function2.Evaluate(function1.Evaluate(x)). The range of function1.Evaluate must be a subset of 0.0 to 1.0 inclusive,
		/// otherwise the result of function1(x) will be pinned (clipped) to 0.0 if <0.0 and to 1.0 if > 1.0 .
		/// \param function1 Inner function of composition.
		/// \param function2 Outer function of composition.

		dng_1d_concatenate (const dng_1d_function &function1,
							const dng_1d_function &function2);
	
		/// Only true if both function1 and function2 have IsIdentity equal to true.

		virtual bool IsIdentity () const;
	
		/// Return the composed mapping for value x.
		/// \param x A value between 0.0 and 1.0 (inclusive).
		/// \retval function2.Evaluate(function1.Evaluate(x)).

		virtual real64 Evaluate (real64 x) const;
	
		/// Return the reverse mapped value for y.
		/// Be careful using this method with compositions where the inner function does not have a range 0.0 to 1.0 . (Or better yet, do not use such functions.)
		/// \param y A value to reverse map. Should be within the range of function2.Evaluate.
		/// \retval A value x such that function2.Evaluate(function1.Evaluate(x)) == y (to very close approximation).

		virtual real64 EvaluateInverse (real64 y) const;
	
	};

/*****************************************************************************/

/// A dng_1d_function that represents the inverse of another dng_1d_function.

class dng_1d_inverse: public dng_1d_function
	{
	
	protected:
	
		const dng_1d_function &fFunction;
	
	public:
	
		dng_1d_inverse (const dng_1d_function &f);
	
		virtual bool IsIdentity () const;
	
		virtual real64 Evaluate (real64 x) const;
	
		virtual real64 EvaluateInverse (real64 y) const;
	
	};

/*****************************************************************************/

#endif
	
/*****************************************************************************/