IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 6, 2006, 3:53:24 PM (20 years ago)
Author:
drobbin
Message:

Edited psSphereOps to use dynamically allocated psSphereRot's everywhere.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astro/psSphereOps.c

    r6309 r6534  
    88 *  @author Dave Robbins, MHPCC
    99 *
    10  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2006-02-02 23:19:58 $
     10 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2006-03-07 01:53:24 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3939}
    4040
     41static psSphereRot* sphereRotAlloc(void)
     42{
     43    psSphereRot *sphereRot = (psSphereRot* ) psAlloc(sizeof(psSphereRot));
     44    psMemSetDeallocator(sphereRot, (psFreeFunc)sphereRotFree);
     45    return (sphereRot);
     46}
     47
    4148psSphereRot* psSphereRotAlloc(double alphaP,
    4249                              double deltaP,
    4350                              double phiP)
    4451{
    45     psSphereRot r,s,t;
     52    psSphereRot *r = sphereRotAlloc();
     53    psSphereRot *s = sphereRotAlloc();
     54    psSphereRot *t = sphereRotAlloc();
     55
    4656    //The following represents: r =a rotation about the z-axis by alphaP, s =a rotation about
    4757    // the y-axis by deltaP, and t =a rotation about the z-axis by phiP.
    48     r.q0=0;
    49     r.q1=0;
    50     r.q2=sin(alphaP/2.0);
    51     r.q3=cos(alphaP/2.0);
    52 
    53     s.q0=0;
    54     s.q1=sin(deltaP/2.0);
    55     s.q2=0;
    56     s.q3=cos(deltaP/2.0);
    57 
    58     t.q0=0;
    59     t.q1=0;
    60     t.q2=sin(phiP/2.0);
    61     t.q3=cos(phiP/2.0);
     58    r->q0=0;
     59    r->q1=0;
     60    r->q2=sin(alphaP/2.0);
     61    r->q3=cos(alphaP/2.0);
     62
     63    s->q0=0;
     64    s->q1=sin(deltaP/2.0);
     65    s->q2=0;
     66    s->q3=cos(deltaP/2.0);
     67
     68    t->q0=0;
     69    t->q1=0;
     70    t->q2=sin(phiP/2.0);
     71    t->q3=cos(phiP/2.0);
    6272
    6373    // calculate t*s*r.
    64     psSphereRot* temp = psSphereRotCombine(NULL,&t,&s);
    65     psSphereRot* result = psSphereRotCombine(NULL, temp, &r);
     74    psSphereRot* temp = psSphereRotCombine(NULL,t,s);
     75    psSphereRot* result = psSphereRotCombine(NULL, temp, r);
    6676    psFree(temp);
    67 
     77    psFree(r);
     78    psFree(s);
     79    psFree(t);
    6880    return result;
    6981}
     
    8395{
    8496    //allocate space for a new sphere rotation and set deallocator
    85     psSphereRot* rot = (psSphereRot*)psAlloc(sizeof(psSphereRot));
    86     psMemSetDeallocator(rot, (psFreeFunc)sphereRotFree);
     97    psSphereRot* rot = sphereRotAlloc();
    8798
    8899    //The magnitude of a rotation quaternion should = 1 so we normalize here in case the
     
    108119    //if output sphere rotation is NULL, allocate a new sphere rotation to return
    109120    if (out == NULL) {
    110         out = (psSphereRot* ) psAlloc(sizeof(psSphereRot));
    111         psMemSetDeallocator(out, (psFreeFunc)sphereRotFree);
     121        out = sphereRotAlloc();
    112122    }
    113123    //Since q3 is the magnitude and q0,q1,q2 are direction, the conjugate rotation
     
    173183    //If output rotation is NULL, allocate a new psSphereRot to return
    174184    if (out == NULL) {
    175         out = (psSphereRot* ) psAlloc(sizeof(psSphereRot));
    176         psMemSetDeallocator(out, (psFreeFunc)sphereRotFree);
     185        out = sphereRotAlloc();
    177186    }
    178187
Note: See TracChangeset for help on using the changeset viewer.