Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

SUMA_trackball.c File Reference

#include "SUMA_suma.h"

Go to the source code of this file.


Defines

#define TRACKBALLSIZE   (1)
#define RENORMCOUNT   97

Functions

float tb_project_to_sphere (float, float, float)
void normalize_quat (float[4])
void vzero (float *v)
void vset (float *v, float x, float y, float z)
void vsub (const float *src1, const float *src2, float *dst)
void vcopy (const float *v1, float *v2)
void vcross (const float *v1, const float *v2, float *cross)
float vlength (const float *v)
void vscale (float *v, float div)
void vnormal (float *v)
float vdot (const float *v1, const float *v2)
void vadd (const float *src1, const float *src2, float *dst)
void trackball (float q[4], float p1x, float p1y, float p2x, float p2y)
void trackball_Phi (float q[4], float p1x, float p1y, float p2x, float p2y, float phi)
void axis_to_quat (float a[3], float phi, float q[4])
void add_quats (float q1[4], float q2[4], float dest[4])
void SUMA_build_rotmatrix (GLfloat m[4][4], float q[4])

Variables

SUMA_CommonFieldsSUMAg_CF

Define Documentation

#define RENORMCOUNT   97
 

Definition at line 207 of file SUMA_trackball.c.

Referenced by add_quats().

#define TRACKBALLSIZE   (1)
 

Definition at line 16 of file SUMA_trackball.c.

Referenced by trackball(), and trackball_Phi().


Function Documentation

void add_quats float    q1[4],
float    q2[4],
float    dest[4]
 

Definition at line 210 of file SUMA_trackball.c.

References normalize_quat(), RENORMCOUNT, vadd(), vcopy(), vcross(), vdot(), and vscale().

00211 {
00212   static int count = 0;
00213   float t1[4], t2[4], t3[4];
00214   float tf[4];
00215 
00216   vcopy(q1, t1);
00217   vscale(t1, q2[3]);
00218 
00219   vcopy(q2, t2);
00220   vscale(t2, q1[3]);
00221 
00222   vcross(q2, q1, t3);
00223   vadd(t1, t2, tf);
00224   vadd(t3, tf, tf);
00225   tf[3] = q1[3] * q2[3] - vdot(q1, q2);
00226 
00227   dest[0] = tf[0];
00228   dest[1] = tf[1];
00229   dest[2] = tf[2];
00230   dest[3] = tf[3];
00231 
00232   if (++count > RENORMCOUNT) {
00233     count = 0;
00234     normalize_quat(dest);
00235   }
00236 }

void axis_to_quat float    a[3],
float    phi,
float    q[4]
 

Definition at line 174 of file SUMA_trackball.c.

References a, q, vcopy(), vnormal(), and vscale().

Referenced by SUMA_input(), trackball(), and trackball_Phi().

00175 {
00176   vnormal(a);
00177   vcopy(a, q);
00178   vscale(q, sin(phi / 2.0));
00179   q[3] = cos(phi / 2.0);
00180 }

void normalize_quat float   [4] [static]
 

Definition at line 242 of file SUMA_trackball.c.

References i, and q.

Referenced by add_quats().

00243 {
00244   int i;
00245   float mag;
00246 
00247   mag = (q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]);
00248   for (i = 0; i < 4; i++)
00249     q[i] /= mag;
00250 }

void SUMA_build_rotmatrix GLfloat    m[4][4],
float    q[4]
 

Definition at line 254 of file SUMA_trackball.c.

References LocalHead, q, SUMA_Boolean, SUMA_ENTRY, and SUMA_RETURNe.

00255 {
00256         static char FuncName[]={"SUMA_build_rotmatrix"};
00257         SUMA_Boolean LocalHead = NOPE;
00258         
00259         SUMA_ENTRY;
00260         m[0][0] = 1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2]);
00261         m[0][1] = 2.0 * (q[0] * q[1] - q[2] * q[3]);
00262         m[0][2] = 2.0 * (q[2] * q[0] + q[1] * q[3]);
00263         m[0][3] = 0.0;
00264 
00265         m[1][0] = 2.0 * (q[0] * q[1] + q[2] * q[3]);
00266         m[1][1] = 1.0 - 2.0 * (q[2] * q[2] + q[0] * q[0]);
00267         m[1][2] = 2.0 * (q[1] * q[2] - q[0] * q[3]);
00268         m[1][3] = 0.0;
00269 
00270         m[2][0] = 2.0 * (q[2] * q[0] - q[1] * q[3]);
00271         m[2][1] = 2.0 * (q[1] * q[2] + q[0] * q[3]);
00272         m[2][2] = 1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0]);
00273         m[2][3] = 0.0;
00274 
00275         m[3][0] = 0.0;
00276         m[3][1] = 0.0;
00277         m[3][2] = 0.0;
00278         m[3][3] = 1.0;
00279         
00280         SUMA_RETURNe;
00281 }

float tb_project_to_sphere float   ,
float   ,
float   
[static]
 

Definition at line 186 of file SUMA_trackball.c.

References r.

Referenced by trackball(), and trackball_Phi().

00187 {
00188   float d, t, z;
00189 
00190   d = sqrt(x * x + y * y);
00191   if (d < r * 0.70710678118654752440) {  /* Inside sphere. */
00192     z = sqrt(r * r - d * d);
00193   } else {              /* On hyperbola. */
00194     t = r / 1.41421356237309504880;
00195     z = t * t / d;
00196   }
00197   return z;
00198 }

void trackball float    q[4],
float    p1x,
float    p1y,
float    p2x,
float    p2y
 

functions defined in SUMA_trackball.c

Definition at line 99 of file SUMA_trackball.c.

References a, axis_to_quat(), q, tb_project_to_sphere(), TRACKBALLSIZE, vcross(), vlength(), vset(), vsub(), and vzero().

Referenced by SUMA_input().

00100 {
00101   float a[3];           /* Axis of rotation. */
00102   float phi;            /* How much to rotate about axis. */
00103   float p1[3], p2[3], d[3];
00104   float t;
00105 
00106   if (p1x == p2x && p1y == p2y) {
00107     /* Zero rotation */
00108     vzero(q);
00109     q[3] = 1.0;
00110     return;
00111   }
00112   /* First, figure out z-coordinates for projection of P1 and
00113      P2 to deformed sphere. */
00114   vset(p1, p1x, p1y, tb_project_to_sphere(TRACKBALLSIZE, p1x, p1y));
00115   vset(p2, p2x, p2y, tb_project_to_sphere(TRACKBALLSIZE, p2x, p2y));
00116 
00117   /* Now, we want the cross product of P1 and P2. */
00118   vcross(p2, p1, a);
00119   /* Figure out how much to rotate around that axis. */
00120   vsub(p1, p2, d);
00121   t = vlength(d) / (2.0 * TRACKBALLSIZE);
00122 
00123   /* Avoid problems with out-of-control values. */
00124   if (t > 1.0)
00125     t = 1.0;
00126   if (t < -1.0)
00127     t = -1.0;
00128   phi = 2.0 * asin(t);
00129   axis_to_quat(a, phi, q);
00130 }

void trackball_Phi float    q[4],
float    p1x,
float    p1y,
float    p2x,
float    p2y,
float    phi
 

A modification/hack of trackball function to control the rotation angle directement

Definition at line 136 of file SUMA_trackball.c.

References a, axis_to_quat(), q, tb_project_to_sphere(), TRACKBALLSIZE, vcross(), vlength(), vset(), vsub(), and vzero().

Referenced by SUMA_input().

00137 {
00138   float a[3];           /* Axis of rotation. */
00139   float p1[3], p2[3], d[3];
00140   float t;
00141 
00142   if (p1x == p2x && p1y == p2y) {
00143     /* Zero rotation */
00144     vzero(q);
00145     q[3] = 1.0;
00146     return;
00147   }
00148   /* First, figure out z-coordinates for projection of P1 and
00149      P2 to deformed sphere. */
00150   vset(p1, p1x, p1y, tb_project_to_sphere(TRACKBALLSIZE, p1x, p1y));
00151   vset(p2, p2x, p2y, tb_project_to_sphere(TRACKBALLSIZE, p2x, p2y));
00152 
00153   /* Now, we want the cross product of P1 and P2. */
00154   vcross(p2, p1, a);
00155   /* Figure out how much to rotate around that axis. */
00156   vsub(p1, p2, d);
00157   t = vlength(d) / (2.0 * TRACKBALLSIZE);
00158 
00159   /* Avoid problems with out-of-control values. */
00160   if (t > 1.0) {
00161       t = 1.0;
00162       phi = 2.0 * asin(t);
00163   }
00164   if (t < -1.0) {
00165       t = -1.0;
00166       phi = 2.0 * asin(t);
00167   }
00168   
00169   axis_to_quat(a, phi, q);
00170 }

void vadd const float *    src1,
const float *    src2,
float *    dst
 

Definition at line 91 of file SUMA_trackball.c.

Referenced by add_quats().

00092 {
00093   dst[0] = src1[0] + src2[0];
00094   dst[1] = src1[1] + src2[1];
00095   dst[2] = src1[2] + src2[2];
00096 }

void vcopy const float *    v1,
float *    v2
 

Definition at line 46 of file SUMA_trackball.c.

References i, and v1.

Referenced by add_quats(), axis_to_quat(), and vcross().

00047 {
00048   register int i;
00049   for (i = 0; i < 3; i++)
00050     v2[i] = v1[i];
00051 }

void vcross const float *    v1,
const float *    v2,
float *    cross
 

Definition at line 54 of file SUMA_trackball.c.

References v1, and vcopy().

Referenced by add_quats(), trackball(), and trackball_Phi().

00055 {
00056   float temp[3];
00057 
00058   temp[0] = (v1[1] * v2[2]) - (v1[2] * v2[1]);
00059   temp[1] = (v1[2] * v2[0]) - (v1[0] * v2[2]);
00060   temp[2] = (v1[0] * v2[1]) - (v1[1] * v2[0]);
00061   vcopy(temp, cross);
00062 }

float vdot const float *    v1,
const float *    v2
 

Definition at line 85 of file SUMA_trackball.c.

References v1.

Referenced by add_quats().

00086 {
00087   return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
00088 }

float vlength const float *    v
 

Definition at line 65 of file SUMA_trackball.c.

References v.

Referenced by trackball(), trackball_Phi(), and vnormal().

00066 {
00067   return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
00068 }

void vnormal float *    v
 

Definition at line 79 of file SUMA_trackball.c.

References v, vlength(), and vscale().

Referenced by axis_to_quat().

00080 {
00081   vscale(v, 1.0 / vlength(v));
00082 }

void vscale float *    v,
float    div
 

Definition at line 71 of file SUMA_trackball.c.

References v.

Referenced by add_quats(), axis_to_quat(), and vnormal().

00072 {
00073   v[0] *= div;
00074   v[1] *= div;
00075   v[2] *= div;
00076 }

void vset float *    v,
float    x,
float    y,
float    z
 

Definition at line 30 of file SUMA_trackball.c.

References v.

Referenced by trackball(), and trackball_Phi().

00031 {
00032   v[0] = x;
00033   v[1] = y;
00034   v[2] = z;
00035 }

void vsub const float *    src1,
const float *    src2,
float *    dst
 

Definition at line 38 of file SUMA_trackball.c.

Referenced by trackball(), and trackball_Phi().

00039 {
00040   dst[0] = src1[0] - src2[0];
00041   dst[1] = src1[1] - src2[1];
00042   dst[2] = src1[2] - src2[2];
00043 }

void vzero float *    v
 

Definition at line 22 of file SUMA_trackball.c.

References v.

Referenced by trackball(), and trackball_Phi().

00023 {
00024   v[0] = 0.0;
00025   v[1] = 0.0;
00026   v[2] = 0.0;
00027 }

Variable Documentation

SUMA_CommonFields* SUMAg_CF  
 

Global pointer to structure containing info common to all viewers

Definition at line 3 of file SUMA_trackball.c.

 

Powered by Plone

This site conforms to the following standards: