Back to index

tetex-bin  3.0
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
ExponentialFunction Class Reference

#include <Function.h>

Inheritance diagram for ExponentialFunction:
Inheritance graph
[legend]
Collaboration diagram for ExponentialFunction:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ExponentialFunction (Object *funcObj, Dict *dict)
virtual ~ExponentialFunction ()
virtual Functioncopy ()
virtual void transform (double *in, double *out)
virtual GBool isOk ()
GBool init (Dict *dict)
int getInputSize ()
int getOutputSize ()

Static Public Member Functions

static Functionparse (Object *funcObj)

Protected Attributes

int m
int n
double domain [funcMaxInputs][2]
double range [funcMaxOutputs][2]
GBool hasRange

Private Member Functions

 ExponentialFunction (ExponentialFunction *func)

Private Attributes

double c0 [funcMaxOutputs]
double c1 [funcMaxOutputs]
double e
GBool ok

Detailed Description

Definition at line 114 of file Function.h.


Constructor & Destructor Documentation

Definition at line 413 of file Function.cc.

                                                                    {
  Object obj1, obj2;
  int i;

  ok = gFalse;

  //----- initialize the generic stuff
  if (!init(dict)) {
    goto err1;
  }
  if (m != 1) {
    error(-1, "Exponential function with more than one input");
    goto err1;
  }

  //----- C0
  if (dict->lookup("C0", &obj1)->isArray()) {
    if (hasRange && obj1.arrayGetLength() != n) {
      error(-1, "Function's C0 array is wrong length");
      goto err2;
    }
    n = obj1.arrayGetLength();
    for (i = 0; i < n; ++i) {
      obj1.arrayGet(i, &obj2);
      if (!obj2.isNum()) {
       error(-1, "Illegal value in function C0 array");
       goto err3;
      }
      c0[i] = obj2.getNum();
      obj2.free();
    }
  } else {
    if (hasRange && n != 1) {
      error(-1, "Function's C0 array is wrong length");
      goto err2;
    }
    n = 1;
    c0[0] = 0;
  }
  obj1.free();

  //----- C1
  if (dict->lookup("C1", &obj1)->isArray()) {
    if (obj1.arrayGetLength() != n) {
      error(-1, "Function's C1 array is wrong length");
      goto err2;
    }
    for (i = 0; i < n; ++i) {
      obj1.arrayGet(i, &obj2);
      if (!obj2.isNum()) {
       error(-1, "Illegal value in function C1 array");
       goto err3;
      }
      c1[i] = obj2.getNum();
      obj2.free();
    }
  } else {
    if (n != 1) {
      error(-1, "Function's C1 array is wrong length");
      goto err2;
    }
    c1[0] = 1;
  }
  obj1.free();

  //----- N (exponent)
  if (!dict->lookup("N", &obj1)->isNum()) {
    error(-1, "Function has missing or invalid N");
    goto err2;
  }
  e = obj1.getNum();
  obj1.free();

  ok = gTrue;
  return;

 err3:
  obj2.free();
 err2:
  obj1.free();
 err1:
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 497 of file Function.cc.

                                          {
}

Definition at line 500 of file Function.cc.

                                                                  {
  memcpy(this, func, sizeof(ExponentialFunction));
}

Here is the call graph for this function:


Member Function Documentation

virtual Function* ExponentialFunction::copy ( ) [inline, virtual]

Implements Function.

Definition at line 119 of file Function.h.

{ return new ExponentialFunction(this); }

Here is the call graph for this function:

int Function::getInputSize ( ) [inline, inherited]

Definition at line 49 of file Function.h.

{ return m; }

Here is the caller graph for this function:

int Function::getOutputSize ( ) [inline, inherited]

Definition at line 50 of file Function.h.

{ return n; }

Here is the caller graph for this function:

GBool Function::init ( Dict dict) [inherited]

Definition at line 81 of file Function.cc.

                               {
  Object obj1, obj2;
  int i;

  //----- Domain
  if (!dict->lookup("Domain", &obj1)->isArray()) {
    error(-1, "Function is missing domain");
    goto err2;
  }
  m = obj1.arrayGetLength() / 2;
  if (m > funcMaxInputs) {
    error(-1, "Functions with more than %d inputs are unsupported",
         funcMaxInputs);
    goto err2;
  }
  for (i = 0; i < m; ++i) {
    obj1.arrayGet(2*i, &obj2);
    if (!obj2.isNum()) {
      error(-1, "Illegal value in function domain array");
      goto err1;
    }
    domain[i][0] = obj2.getNum();
    obj2.free();
    obj1.arrayGet(2*i+1, &obj2);
    if (!obj2.isNum()) {
      error(-1, "Illegal value in function domain array");
      goto err1;
    }
    domain[i][1] = obj2.getNum();
    obj2.free();
  }
  obj1.free();

  //----- Range
  hasRange = gFalse;
  n = 0;
  if (dict->lookup("Range", &obj1)->isArray()) {
    hasRange = gTrue;
    n = obj1.arrayGetLength() / 2;
    if (n > funcMaxOutputs) {
      error(-1, "Functions with more than %d outputs are unsupported",
           funcMaxOutputs);
      goto err2;
    }
    for (i = 0; i < n; ++i) {
      obj1.arrayGet(2*i, &obj2);
      if (!obj2.isNum()) {
       error(-1, "Illegal value in function range array");
       goto err1;
      }
      range[i][0] = obj2.getNum();
      obj2.free();
      obj1.arrayGet(2*i+1, &obj2);
      if (!obj2.isNum()) {
       error(-1, "Illegal value in function range array");
       goto err1;
      }
      range[i][1] = obj2.getNum();
      obj2.free();
    }
  }
  obj1.free();

  return gTrue;

 err1:
  obj2.free();
 err2:
  obj1.free();
  return gFalse;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual GBool ExponentialFunction::isOk ( ) [inline, virtual]

Implements Function.

Definition at line 121 of file Function.h.

{ return ok; }
Function * Function::parse ( Object funcObj) [static, inherited]

Definition at line 36 of file Function.cc.

                                         {
  Function *func;
  Dict *dict;
  int funcType;
  Object obj1;

  if (funcObj->isStream()) {
    dict = funcObj->streamGetDict();
  } else if (funcObj->isDict()) {
    dict = funcObj->getDict();
  } else if (funcObj->isName("Identity")) {
    return new IdentityFunction();
  } else {
    error(-1, "Expected function dictionary or stream");
    return NULL;
  }

  if (!dict->lookup("FunctionType", &obj1)->isInt()) {
    error(-1, "Function type is missing or wrong type");
    obj1.free();
    return NULL;
  }
  funcType = obj1.getInt();
  obj1.free();

  if (funcType == 0) {
    func = new SampledFunction(funcObj, dict);
  } else if (funcType == 2) {
    func = new ExponentialFunction(funcObj, dict);
  } else if (funcType == 3) {
    func = new StitchingFunction(funcObj, dict);
  } else if (funcType == 4) {
    func = new PostScriptFunction(funcObj, dict);
  } else {
    error(-1, "Unimplemented function type (%d)", funcType);
    return NULL;
  }
  if (!func->isOk()) {
    delete func;
    return NULL;
  }

  return func;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ExponentialFunction::transform ( double *  in,
double *  out 
) [virtual]

Implements Function.

Definition at line 504 of file Function.cc.

                                                           {
  double x;
  int i;

  if (in[0] < domain[0][0]) {
    x = domain[0][0];
  } else if (in[0] > domain[0][1]) {
    x = domain[0][1];
  } else {
    x = in[0];
  }
  for (i = 0; i < n; ++i) {
    out[i] = c0[i] + pow(x, e) * (c1[i] - c0[i]);
    if (hasRange) {
      if (out[i] < range[i][0]) {
       out[i] = range[i][0];
      } else if (out[i] > range[i][1]) {
       out[i] = range[i][1];
      }
    }
  }
  return;
}

Member Data Documentation

Definition at line 127 of file Function.h.

Definition at line 128 of file Function.h.

double Function::domain[funcMaxInputs][2] [protected, inherited]

Definition at line 61 of file Function.h.

double ExponentialFunction::e [private]

Definition at line 129 of file Function.h.

GBool Function::hasRange [protected, inherited]

Definition at line 64 of file Function.h.

int Function::m [protected, inherited]

Definition at line 59 of file Function.h.

int Function::n [protected, inherited]

Definition at line 59 of file Function.h.

Definition at line 130 of file Function.h.

double Function::range[funcMaxOutputs][2] [protected, inherited]

Definition at line 63 of file Function.h.


The documentation for this class was generated from the following files: