Revision: 41059
http://brlcad.svn.sourceforge.net/brlcad/?rev=41059&view=rev
Author: brlcad
Date: 2010-10-18 21:16:50 +0000 (Mon, 18 Oct 2010)
Log Message:
-----------
break out the functions from cattrack.c that are used by anim_track.c into a
private header file so that the function signatures can be declared in one
place. move and doxygenify the function comments, reordering the
implementations to avoid the need for forward decls and calling out the HIDDEN
ones that are just internal to the implementation.
Modified Paths:
--------------
brlcad/trunk/src/anim/Makefile.am
brlcad/trunk/src/anim/anim_track.c
brlcad/trunk/src/anim/cattrack.c
Added Paths:
-----------
brlcad/trunk/src/anim/cattrack.h
Modified: brlcad/trunk/src/anim/Makefile.am
===================================================================
--- brlcad/trunk/src/anim/Makefile.am 2010-10-18 20:34:55 UTC (rev 41058)
+++ brlcad/trunk/src/anim/Makefile.am 2010-10-18 21:16:50 UTC (rev 41059)
@@ -17,6 +17,7 @@
chan_permute
AM_CPPFLAGS = ${TCL_CPPFLAGS}
+# AM_CFLAGS = ${STRICT_FLAGS}
anim_cascade_SOURCES = anim_cascade.c
anim_cascade_LDADD = ${BN}
@@ -63,6 +64,8 @@
chan_permute_SOURCES = chan_permute.c
chan_permute_LDADD = ${BU}
+noinst_HEADERS = cattrack.h
+
man_MANS = \
anim_script.1 \
anim_sort.1 \
Modified: brlcad/trunk/src/anim/anim_track.c
===================================================================
--- brlcad/trunk/src/anim/anim_track.c 2010-10-18 20:34:55 UTC (rev 41058)
+++ brlcad/trunk/src/anim/anim_track.c 2010-10-18 21:16:50 UTC (rev 41059)
@@ -36,7 +36,9 @@
#include "anim.h"
#include "vmath.h"
+#include "./cattrack.h"
+
#define OPT_STR "sycuvb:d:f:i:r:p:w:g:m:l:a"
#define GIVEN 0
@@ -263,8 +265,6 @@
fastf_t phi, costheta, arc_angle;
fastf_t linearlen, hyperlen;
vect_t difference;
- int getcurve(fastf_t *pa, fastf_t *pb, fastf_t *pc, fastf_t *pth0, fastf_t
*pth1, fastf_t delta_s, fastf_t *p_zero, fastf_t *p_one, fastf_t r_zero,
fastf_t r_one);
- fastf_t hyper_get_s(fastf_t a, fastf_t c, fastf_t x);
/* first loop - get inter axle slopes and start/end angles */
for (i=0;i<NW;i++) {
@@ -375,7 +375,6 @@
{
int i;
vect_t temp;
- fastf_t hyper_get_x(fastf_t a, fastf_t c, fastf_t s, int d, int x, int
cos_ang), hyper_get_z(fastf_t a, fastf_t b, fastf_t c, fastf_t x),
hyper_get_ang(fastf_t a, fastf_t c, fastf_t x);
while (dist >= tracklen) /*periodicize*/
dist -= tracklen;
Modified: brlcad/trunk/src/anim/cattrack.c
===================================================================
--- brlcad/trunk/src/anim/cattrack.c 2010-10-18 20:34:55 UTC (rev 41058)
+++ brlcad/trunk/src/anim/cattrack.c 2010-10-18 21:16:50 UTC (rev 41059)
@@ -49,12 +49,9 @@
#define G_TOL 1.0e-12
#define F_TOL 1.0e-12
-/* HYPER_GET_X - get x value of a point which is a given distance along
- * caternary curve.
- * x(s) = arcsinh(a*s-sinh(a*c))/a + c
- * Left to calling routine to avoid dividing by zero.
- */
-fastf_t hyper_get_x(fastf_t a, fastf_t c, fastf_t s, int d, int x, int cos_ang)
+
+fastf_t
+hyper_get_x(fastf_t a, fastf_t c, fastf_t s, int d, int x, int cos_ang)
/* curve parameters */
/* arclength value */
{
@@ -66,21 +63,16 @@
return asinh_arg/a + c;
}
-/* HYPER_GET_S - calculate the arclength parameter of a caternary
- * curve corresponding to the given value of x.
- * s(x) = (sinh(a(x-c))+sinh(ac))/a
- * Left to calling routime to avoid dividing by zero.
- */
-fastf_t hyper_get_s(fastf_t a, fastf_t c, fastf_t x)
+
+fastf_t
+hyper_get_s(fastf_t a, fastf_t c, fastf_t x)
{
return((sinh(a*(x-c))+sinh(a*c))/a);
}
-/* HYPER_GET_Z - calculate point on the caternary curve:
- * z(x) = cosh(a*(x-c))/a + b
- * Left to calling routine to avoid dividing by zero.
- */
-fastf_t hyper_get_z(fastf_t a, fastf_t b, fastf_t c, fastf_t x)
+
+fastf_t
+hyper_get_z(fastf_t a, fastf_t b, fastf_t c, fastf_t x)
{
fastf_t z;
@@ -92,11 +84,9 @@
return z;
}
-/* HYPER_GET_ANG - calculate angle corresponding to the slope of
- * caternary curve.
- * z'(x) = sinh(a*(x-c))
- */
-fastf_t hyper_get_ang(fastf_t a, fastf_t c, fastf_t x)
+
+fastf_t
+hyper_get_ang(fastf_t a, fastf_t c, fastf_t x)
{
fastf_t slope;
@@ -104,24 +94,107 @@
return atan2(slope, 1.0);
}
-/* GET_CURVE - Find the constants a, b, and c such that the curve
- * z = cosh(a*(x-c))/a + b
- * is tangent to circles of radii r0 and r1 located at
- * (x0, z0) and (x1, z1) and such that the curve has
- * arclength delta_s between circles. Also find the angle where
- * the curve touches each circle. When called successively,
- * It uses the values of a, b, and c from the last call as a start.
+
+/* find Newtonian adjustment for 'a', assuming 'c' fixed*/
+HIDDEN fastf_t
+eff(fastf_t a, fastf_t c, fastf_t x0, fastf_t x1, fastf_t delta_s)
+{
+ double f, fprime;
+ double arg0, arg1, sarg0, sarg1;
+
+ arg0 = a*(x0-c);
+ arg1 = a*(x1-c);
+
+ sarg0 = sinh(arg0);
+ sarg1 = sinh(arg1);
+
+ f = a*(sarg1-sarg0 - a*delta_s);
+ fprime = sarg0 - sarg1 - arg0*cosh(arg0) + arg1*cosh(arg1);
+
+ if (fabs(fprime) > VDIVIDE_TOL)
+ return f/fprime;
+ else if ((a*a) > VDIVIDE_TOL)
+ return(f/(a*a));
+ else if (fabs(a) > VDIVIDE_TOL)
+ return f/a;
+ else
+ return f;
+}
+
+
+/* find Newtonian adjustment for c, assuming 'a' fixed*/
+HIDDEN fastf_t
+gee(fastf_t a, fastf_t c, fastf_t x0, fastf_t x1, fastf_t delta_z)
+{
+ double g, gprime, arg0, arg1;
+
+ arg0 = a*(x0-c);
+ arg1 = a*(x1-c);
+
+ g = cosh(arg1)-cosh(arg0) - a*delta_z;
+ gprime = a*(sinh(arg0) - sinh(arg1));
+
+ if (fabs(gprime) > VDIVIDE_TOL)
+ return g/gprime;
+ else if (fabs(a) > VDIVIDE_TOL)
+ return g/a;
+ else
+ return g;
+}
+
+
+/* INGETCURVE - find constants a, b, and c, such that the curve
+ * z = cosh(a*(x-c))/a + b
+ * passes through (x0, z0) and (x1, z1) and has arclength delta_s
+ * Appropriate first guesses for a, b, and c should be given.
*/
-int getcurve(fastf_t *pa, fastf_t *pb, fastf_t *pc, fastf_t *pth0, fastf_t
*pth1, fastf_t delta_s, fastf_t *p_zero, fastf_t *p_one, fastf_t r_zero,
fastf_t r_one)
- /* curve parameters */
- /* angle where curve contacts circle0, circle1 */
- /* desired arclength */
- /* radii of circle0 and circle1 */
- /* center of circle0 and circle1 */
+HIDDEN int
+ingetcurve(fastf_t *pa, fastf_t *pb, fastf_t *pc, fastf_t delta_s, fastf_t
*p_zero, fastf_t *p_one)
{
+ int status, i, j, k;
+ fastf_t adjust;
+ status = MAX_REACHED;
+ i=0;
+ while (i++<MAX_OUT_ITS) {
+ for (j=0;j<MAX_ITS;j++) {
+ adjust = eff(*pa, *pc, p_zero[X], p_one[X], delta_s);
+ if ((*pa-adjust)<=0.0) {
+ *pa *= 0.5;
+ }
+ else {
+ *pa -= adjust;
+ }
+ if (adjust<F_TOL) {
+ break;
+ }
+ }
+
+ for (k=0;k<MAX_ITS;k++) {
+ adjust = gee(*pa, *pc, p_zero[X], p_one[X], (p_one[Z]-p_zero[Z]));
+ *pc -= adjust;
+ if (adjust<G_TOL) {
+ break;
+ }
+ }
+
+ if ((j==0)&&(k==0)) {
+ status = SOLVED;
+ break;
+ }
+ }
+ *pb = p_zero[Z] - cosh( (*pa)*(p_zero[X]-(*pc)) )/(*pa);
+
+ return status;
+
+}
+
+
+int
+getcurve(fastf_t *pa, fastf_t *pb, fastf_t *pc, fastf_t *pth0, fastf_t *pth1,
fastf_t delta_s, fastf_t *p_zero, fastf_t *p_one, fastf_t r_zero, fastf_t r_one)
+{
+
int status, i, solved;
- int ingetcurve(fastf_t *pa, fastf_t *pb, fastf_t *pc, fastf_t delta_s,
fastf_t *p_zero, fastf_t *p_one);
fastf_t theta_one, theta_zero, new_theta_zero, new_theta_one;
fastf_t avg_theta_zero, avg_theta_one, arc_dist;
fastf_t tang_ang, costheta;
@@ -130,7 +203,9 @@
static fastf_t last_a, last_c, last_theta_one, last_theta_zero;
static int called_before = 0;
- /*first calculate angle at which tangent line would contact circles*/
+ /* first calculate angle at which tangent line would contact
+ * circles.
+ */
VSUB2(diff, p_one, p_zero);
tang_ang = atan2(diff[Z], diff[X]);
costheta = (r_zero-r_one)/MAGNITUDE(diff);
@@ -198,97 +273,7 @@
}
-/* INGETCURVE - find constants a, b, and c, such that the curve
- * z = cosh(a*(x-c))/a + b
- * passes through (x0, z0) and (x1, z1) and has arclength delta_s
- * Appropriate first guesses for a, b, and c should be given.
- */
-int ingetcurve(fastf_t *pa, fastf_t *pb, fastf_t *pc, fastf_t delta_s, fastf_t
*p_zero, fastf_t *p_one)
-{
- int status, i, j, k;
- fastf_t adjust;
- fastf_t eff(fastf_t a, fastf_t c, fastf_t x0, fastf_t x1, fastf_t
delta_s), gee(fastf_t a, fastf_t c, fastf_t x0, fastf_t x1, fastf_t delta_z);
- status = MAX_REACHED;
- i=0;
- while (i++<MAX_OUT_ITS) {
- for (j=0;j<MAX_ITS;j++) {
- adjust = eff(*pa, *pc, p_zero[X], p_one[X], delta_s);
- if ((*pa-adjust)<=0.0) {
- *pa *= 0.5;
- }
- else {
- *pa -= adjust;
- }
- if (adjust<F_TOL) {
- break;
- }
- }
-
- for (k=0;k<MAX_ITS;k++) {
- adjust = gee(*pa, *pc, p_zero[X], p_one[X], (p_one[Z]-p_zero[Z]));
- *pc -= adjust;
- if (adjust<G_TOL) {
- break;
- }
- }
-
- if ((j==0)&&(k==0)) {
- status = SOLVED;
- break;
- }
- }
- *pb = p_zero[Z] - cosh( (*pa)*(p_zero[X]-(*pc)) )/(*pa);
-
- return status;
-
-}
-
-/* find Newtonian adjustment for 'a', assuming 'c' fixed*/
-fastf_t eff(fastf_t a, fastf_t c, fastf_t x0, fastf_t x1, fastf_t delta_s)
-{
- double f, fprime;
- double arg0, arg1, sarg0, sarg1;
-
- arg0 = a*(x0-c);
- arg1 = a*(x1-c);
-
- sarg0 = sinh(arg0);
- sarg1 = sinh(arg1);
-
- f = a*(sarg1-sarg0 - a*delta_s);
- fprime = sarg0 - sarg1 - arg0*cosh(arg0) + arg1*cosh(arg1);
-
- if (fabs(fprime) > VDIVIDE_TOL)
- return f/fprime;
- else if ((a*a) > VDIVIDE_TOL)
- return(f/(a*a));
- else if (fabs(a) > VDIVIDE_TOL)
- return f/a;
- else
- return f;
-}
-
-/* find Newtonian adjustment for c, assuming 'a' fixed*/
-fastf_t gee(fastf_t a, fastf_t c, fastf_t x0, fastf_t x1, fastf_t delta_z)
-{
- double g, gprime, arg0, arg1;
-
- arg0 = a*(x0-c);
- arg1 = a*(x1-c);
-
- g = cosh(arg1)-cosh(arg0) - a*delta_z;
- gprime = a*(sinh(arg0) - sinh(arg1));
-
- if (fabs(gprime) > VDIVIDE_TOL)
- return g/gprime;
- else if (fabs(a) > VDIVIDE_TOL)
- return g/a;
- else
- return g;
-}
-
-
/*
* Local Variables:
* mode: C
Added: brlcad/trunk/src/anim/cattrack.h
===================================================================
--- brlcad/trunk/src/anim/cattrack.h (rev 0)
+++ brlcad/trunk/src/anim/cattrack.h 2010-10-18 21:16:50 UTC (rev 41059)
@@ -0,0 +1,94 @@
+/* C A T T R A C K . H
+ * BRL-CAD
+ *
+ * Copyright (c) 2010 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file cattrack.h
+ *
+ * private functions used by anim_track
+ *
+ */
+
+#include "common.h"
+
+#include "bu.h"
+
+
+/**
+ * get x value of a point which is a given distance along caternary
+ * curve: x(s) = arcsinh(a*s-sinh(a*c))/a + c
+ *
+ * Left to calling routine to avoid dividing by zero.
+ */
+fastf_t hyper_get_x(fastf_t a, fastf_t c, fastf_t s, int d, int x, int
cos_ang);
+
+
+/**
+ * calculate the arclength parameter of a caternary curve
+ * corresponding to the given value of x.
+ *
+ * s(x) = (sinh(a(x-c))+sinh(ac))/a
+ *
+ * Left to calling routime to avoid dividing by zero.
+ */
+fastf_t hyper_get_s(fastf_t a, fastf_t c, fastf_t x);
+
+
+/**
+ * calculate point on the caternary curve: z(x) = cosh(a*(x-c))/a + b
+ * Left to calling routine to avoid dividing by zero.
+ */
+fastf_t hyper_get_z(fastf_t a, fastf_t b, fastf_t c, fastf_t x);
+
+
+/**
+ * calculate angle corresponding to the slope of caternary curve:
+ * z'(x) = sinh(a*(x-c))
+ */
+fastf_t hyper_get_ang(fastf_t a, fastf_t c, fastf_t x);
+
+
+/**
+ * Find the constants a, b, and c such that the curve
+ *
+ * z = cosh(a*(x-c))/a + b
+ *
+ * is tangent to circles of radii r0 and r1 located at (x0, z0) and
+ * (x1, z1) and such that the curve has arclength delta_s between
+ * circles. Also find the angle where the curve touches each
+ * circle. When called successively, It uses the values of a, b, and c
+ * from the last call as a start.
+ *
+ * pa, pb, pc: curve parameters
+ * pth0, pth1: angle where curve contacts circle0, circle1
+ * delta_s: desired arclength
+ * p_zero, p_one: center of circle0 and circle1
+ * r_zero, r_one: radii of circle0 and circle1
+ *
+ */
+int getcurve(fastf_t *pa, fastf_t *pb, fastf_t *pc, fastf_t *pth0, fastf_t
*pth1, fastf_t delta_s, fastf_t *p_zero, fastf_t *p_one, fastf_t r_zero,
fastf_t r_one);
+
+
+/*
+ * Local Variables:
+ * tab-width: 8
+ * mode: C
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/trunk/src/anim/cattrack.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits