Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Function.h

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

Generated on Wed Nov 3 12:58:56 2004 for Lemur Toolkit by doxygen1.2.18