home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / inventorTemplates1.1.2 / InventorSplineClass.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.0 KB  |  116 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdlib.h>
  18. #include "InventorSplineClass.h"
  19.  
  20.  
  21. InvSplineClass::InvSplineClass(SoMFVec4f *all)
  22. {
  23.     double *t, *tx, *ty, *tz;
  24.     int n = all->getNum();
  25.     const SoMFVec4f &allto = (*all);
  26.  
  27.     t = (double *) malloc(n * sizeof(double));
  28.     tx = (double *) malloc(n * sizeof(double));
  29.     ty = (double *) malloc(n * sizeof(double));
  30.     tz = (double *) malloc(n * sizeof(double));
  31.  
  32.     float tval, xval, yval, zval;
  33.     SbVec4f blah;
  34.     for (int i = 0; i < n; i++) {
  35.     blah = (allto[i]);
  36.     blah.getValue(tval, xval, yval, zval);
  37.     t[i] = (double) tval;
  38.     tx[i] = (double) xval;
  39.     ty[i] = (double) yval;
  40.     tz[i] = (double) zval;
  41.     }
  42.     x = new SplineClass(n, t, tx);
  43.     y = new SplineClass(n, t, ty);
  44.     z = new SplineClass(n, t, tz);
  45.  
  46.     free(t);
  47.     free(tx);
  48.     free(ty);
  49.     free(tz);
  50. }
  51.  
  52. InvSplineClass::InvSplineClass(SoMFVec2f *tax, SoMFVec2f *tay, SoMFVec2f *taz)
  53. {
  54.     double *tx, *ty, *tz, *ttx, *tty, *ttz;
  55.     int nx = tax->getNum();
  56.     int ny = tay->getNum();
  57.     int nz = taz->getNum();
  58.     const SoMFVec2f &ttax = (*tax);
  59.     const SoMFVec2f &ttay = (*tay);
  60.     const SoMFVec2f &ttaz = (*taz);
  61.  
  62.     tx = (double *) malloc(nx * sizeof(double));
  63.     ty = (double *) malloc(ny * sizeof(double));
  64.     tz = (double *) malloc(nz * sizeof(double));
  65.     ttx = (double *) malloc(nx * sizeof(double));
  66.     tty = (double *) malloc(ny * sizeof(double));
  67.     ttz = (double *) malloc(nz * sizeof(double));
  68.  
  69.  
  70.     float xval, yval, zval, txval, tyval, tzval;
  71.     SbVec2f xvec, yvec, zvec;
  72.     for (int i = 0; i < nx; i++) {
  73.     xvec = ttax[i];
  74.     xvec.getValue(txval, xval);
  75.     tx[i] = (double) xval;
  76.     ttx[i] = (double) txval;
  77.     }
  78.  
  79.     for (i = 0; i < ny; i++) {
  80.     yvec = ttay[i];
  81.     yvec.getValue(tyval, yval);
  82.     ty[i] = (double) yval;
  83.     tty[i] = (double) tyval;
  84.     }
  85.  
  86.     for (i = 0; i < nz; i++) {
  87.     zvec = ttaz[i];
  88.     zvec.getValue(tzval, zval);
  89.     tz[i] = (double) zval;
  90.     ttz[i] = (double) tzval;
  91.     }
  92.  
  93.     x = new SplineClass(nx, ttx, tx);
  94.     y = new SplineClass(ny, tty, ty);
  95.     z = new SplineClass(nz, ttz, tz);
  96.  
  97.     free(tx);
  98.     free(ty);
  99.     free(tz);
  100.     free(ttx);
  101.     free(tty);
  102.     free(ttz);
  103. }
  104.  
  105.  
  106. SbVec3f InvSplineClass::evaluate(double t) {
  107.     SbVec3f result;
  108.  
  109.     result.setValue(x->evaluate(t), y->evaluate(t), z->evaluate(t));
  110.     return result;
  111. }
  112.  
  113. InvSplineClass::~InvSplineClass()
  114. {
  115. }
  116.