Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Function.h

Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // Function.h
00004 //
00005 // Copyright 2001-2002 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef FUNCTION_H
00010 #define FUNCTION_H
00011 
00012 #ifdef __GNUC__
00013 #pragma interface
00014 #endif
00015 
00016 #include "gtypes.h"
00017 #include "Object.h"
00018 
00019 class Dict;
00020 class Stream;
00021 struct PSObject;
00022 class PSStack;
00023 
00024 //------------------------------------------------------------------------
00025 // Function
00026 //------------------------------------------------------------------------
00027 
00028 #define funcMaxInputs  8
00029 #define funcMaxOutputs 8
00030 
00031 class Function {
00032 public:
00033 
00034   Function();
00035 
00036   virtual ~Function();
00037 
00038   // Construct a function.  Returns NULL if unsuccessful.
00039   static Function *parse(Object *funcObj);
00040 
00041   // Initialize the entries common to all function types.
00042   GBool init(Dict *dict);
00043 
00044   virtual Function *copy() = 0;
00045 
00046   // Return size of input and output tuples.
00047   int getInputSize() { return m; }
00048   int getOutputSize() { return n; }
00049 
00050   // Transform an input tuple into an output tuple.
00051   virtual void transform(fouble *in, fouble *out) = 0;
00052 
00053   virtual GBool isOk() = 0;
00054 
00055 protected:
00056 
00057   int m, n;                     // size of input and output tuples
00058   fouble                        // min and max values for function domain
00059     domain[funcMaxInputs][2];
00060   fouble                        // min and max values for function range
00061     range[funcMaxOutputs][2];
00062   GBool hasRange;               // set if range is defined
00063 };
00064 
00065 //------------------------------------------------------------------------
00066 // IdentityFunction
00067 //------------------------------------------------------------------------
00068 
00069 class IdentityFunction: public Function {
00070 public:
00071 
00072   IdentityFunction();
00073   virtual ~IdentityFunction();
00074   virtual Function *copy() { return new IdentityFunction(); }
00075   virtual void transform(fouble *in, fouble *out);
00076   virtual GBool isOk() { return gTrue; }
00077 
00078 private:
00079 };
00080 
00081 //------------------------------------------------------------------------
00082 // SampledFunction
00083 //------------------------------------------------------------------------
00084 
00085 class SampledFunction: public Function {
00086 public:
00087 
00088   SampledFunction(Object *funcObj, Dict *dict);
00089   virtual ~SampledFunction();
00090   virtual Function *copy() { return new SampledFunction(this); }
00091   virtual void transform(fouble *in, fouble *out);
00092   virtual GBool isOk() { return ok; }
00093 
00094 private:
00095 
00096   SampledFunction(SampledFunction *func);
00097 
00098   int                           // number of samples for each domain element
00099     sampleSize[funcMaxInputs];
00100   fouble                        // min and max values for domain encoder
00101     encode[funcMaxInputs][2];
00102   fouble                        // min and max values for range decoder
00103     decode[funcMaxOutputs][2];
00104   fouble *samples;              // the samples
00105   GBool ok;
00106 };
00107 
00108 //------------------------------------------------------------------------
00109 // ExponentialFunction
00110 //------------------------------------------------------------------------
00111 
00112 class ExponentialFunction: public Function {
00113 public:
00114 
00115   ExponentialFunction(Object *funcObj, Dict *dict);
00116   virtual ~ExponentialFunction();
00117   virtual Function *copy() { return new ExponentialFunction(this); }
00118   virtual void transform(fouble *in, fouble *out);
00119   virtual GBool isOk() { return ok; }
00120 
00121 private:
00122 
00123   ExponentialFunction(ExponentialFunction *func);
00124 
00125   fouble c0[funcMaxOutputs];
00126   fouble c1[funcMaxOutputs];
00127   fouble e;
00128   GBool ok;
00129 };
00130 
00131 //------------------------------------------------------------------------
00132 // StitchingFunction
00133 //------------------------------------------------------------------------
00134 
00135 class StitchingFunction: public Function {
00136 public:
00137 
00138   StitchingFunction(Object *funcObj, Dict *dict);
00139   virtual ~StitchingFunction();
00140   virtual Function *copy() { return new StitchingFunction(this); }
00141   virtual void transform(fouble *in, fouble *out);
00142   virtual GBool isOk() { return ok; }
00143 
00144 private:
00145 
00146   StitchingFunction(StitchingFunction *func);
00147 
00148   int k;
00149   Function **funcs;
00150   fouble *bounds;
00151   fouble *encode;
00152   GBool ok;
00153 };
00154 
00155 //------------------------------------------------------------------------
00156 // PostScriptFunction
00157 //------------------------------------------------------------------------
00158 
00159 class PostScriptFunction: public Function {
00160 public:
00161 
00162   PostScriptFunction(Object *funcObj, Dict *dict);
00163   virtual ~PostScriptFunction();
00164   virtual Function *copy() { return new PostScriptFunction(this); }
00165   virtual void transform(fouble *in, fouble *out);
00166   virtual GBool isOk() { return ok; }
00167 
00168 private:
00169 
00170   PostScriptFunction(PostScriptFunction *func);
00171   GBool parseCode(Stream *str, int *codePtr);
00172   GString *getToken(Stream *str);
00173   void resizeCode(int newSize);
00174   void exec(PSStack *stack, int codePtr);
00175 
00176   PSObject *code;
00177   int codeSize;
00178   GBool ok;
00179 };
00180 
00181 #endif

Generated on Sat Nov 5 16:18:13 2005 for OPIE by  doxygen 1.4.2