Back to index

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

#include <Function.h>

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

List of all members.

Public Member Functions

 StitchingFunction (Object *funcObj, Dict *dict)
virtual ~StitchingFunction ()
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

 StitchingFunction (StitchingFunction *func)

Private Attributes

int k
Function ** funcs
double * bounds
double * encode
GBool ok

Detailed Description

Definition at line 137 of file Function.h.


Constructor & Destructor Documentation

StitchingFunction::StitchingFunction ( Object funcObj,
Dict dict 
)

Definition at line 532 of file Function.cc.

                                                                {
  Object obj1, obj2;
  int i;

  ok = gFalse;
  funcs = NULL;
  bounds = NULL;
  encode = NULL;

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

  //----- Functions
  if (!dict->lookup("Functions", &obj1)->isArray()) {
    error(-1, "Missing 'Functions' entry in stitching function");
    goto err1;
  }
  k = obj1.arrayGetLength();
  funcs = (Function **)gmalloc(k * sizeof(Function *));
  bounds = (double *)gmalloc((k + 1) * sizeof(double));
  encode = (double *)gmalloc(2 * k * sizeof(double));
  for (i = 0; i < k; ++i) {
    funcs[i] = NULL;
  }
  for (i = 0; i < k; ++i) {
    if (!(funcs[i] = Function::parse(obj1.arrayGet(i, &obj2)))) {
      goto err2;
    }
    if (i > 0 && (funcs[i]->getInputSize() != 1 ||
                funcs[i]->getOutputSize() != funcs[0]->getOutputSize())) {
      error(-1, "Incompatible subfunctions in stitching function");
      goto err2;
    }
    obj2.free();
  }
  obj1.free();

  //----- Bounds
  if (!dict->lookup("Bounds", &obj1)->isArray() ||
      obj1.arrayGetLength() != k - 1) {
    error(-1, "Missing or invalid 'Bounds' entry in stitching function");
    goto err1;
  }
  bounds[0] = domain[0][0];
  for (i = 1; i < k; ++i) {
    if (!obj1.arrayGet(i - 1, &obj2)->isNum()) {
      error(-1, "Invalid type in 'Bounds' array in stitching function");
      goto err2;
    }
    bounds[i] = obj2.getNum();
    obj2.free();
  }
  bounds[k] = domain[0][1];
  obj1.free();

  //----- Encode
  if (!dict->lookup("Encode", &obj1)->isArray() ||
      obj1.arrayGetLength() != 2 * k) {
    error(-1, "Missing or invalid 'Encode' entry in stitching function");
    goto err1;
  }
  for (i = 0; i < 2 * k; ++i) {
    if (!obj1.arrayGet(i, &obj2)->isNum()) {
      error(-1, "Invalid type in 'Encode' array in stitching function");
      goto err2;
    }
    encode[i] = obj2.getNum();
    obj2.free();
  }
  obj1.free();

  ok = gTrue;
  return;

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

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 633 of file Function.cc.

                                      {
  int i;

  if (funcs) {
    for (i = 0; i < k; ++i) {
      if (funcs[i]) {
       delete funcs[i];
      }
    }
  }
  gfree(funcs);
  gfree(bounds);
  gfree(encode);
}

Here is the call graph for this function:

Definition at line 618 of file Function.cc.

                                                            {
  int i;

  k = func->k;
  funcs = (Function **)gmalloc(k * sizeof(Function *));
  for (i = 0; i < k; ++i) {
    funcs[i] = func->funcs[i]->copy();
  }
  bounds = (double *)gmalloc((k + 1) * sizeof(double));
  memcpy(bounds, func->bounds, (k + 1) * sizeof(double));
  encode = (double *)gmalloc(2 * k * sizeof(double));
  memcpy(encode, func->encode, 2 * k * sizeof(double));
  ok = gTrue;
}

Here is the call graph for this function:


Member Function Documentation

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

Implements Function.

Definition at line 142 of file Function.h.

{ return new StitchingFunction(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 StitchingFunction::isOk ( ) [inline, virtual]

Implements Function.

Definition at line 144 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 StitchingFunction::transform ( double *  in,
double *  out 
) [virtual]

Implements Function.

Definition at line 648 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 < k - 1; ++i) {
    if (x < bounds[i+1]) {
      break;
    }
  }
  x = encode[2*i] + ((x - bounds[i]) / (bounds[i+1] - bounds[i])) *
                    (encode[2*i+1] - encode[2*i]);
  funcs[i]->transform(&x, out);
}

Here is the call graph for this function:


Member Data Documentation

double* StitchingFunction::bounds [private]

Definition at line 152 of file Function.h.

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

Definition at line 61 of file Function.h.

double* StitchingFunction::encode [private]

Definition at line 153 of file Function.h.

Definition at line 151 of file Function.h.

GBool Function::hasRange [protected, inherited]

Definition at line 64 of file Function.h.

Definition at line 150 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 154 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: