1 /**********
2 *
3 * This file is part of the TINA Open Source Image Analysis Environment
4 * henceforth known as TINA
5 *
6 * TINA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation.
9 *
10 * TINA is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with TINA; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 **********
20 *
21 * Program : TINA
22 * File : $Source: /home/tina/cvs/tina-libs/tina/geometry/geomCurve_conic.c,v $
23 * Date : $Date: 2005/01/09 17:49:25 $
24 * Version : $Revision: 1.2 $
25 * CVS Id : $Id: geomCurve_conic.c,v 1.2 2005/01/09 17:49:25 paul Exp $
26 *
27 * Author : Legacy TINA
28 *
29 * Notes :
30 *
31 *********
32 */
33
34 #include "geomCurve_conic.h"
35
36 #if HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39
40 #include <math.h>
41 #include <string.h>
42 #include <tina/sys/sysDef.h>
43 #include <tina/sys/sysPro.h>
44 #include <tina/math/mathDef.h>
45 #include <tina/math/mathPro.h>
46 #include <tina/geometry/geomDef.h>
47 #include <tina/geometry/geom_CurveDef.h>
48 #ifdef _PCC
49 #include <memory.h>
50 #endif
51
52 Conic *conic_alloc(unsigned int type)
53 {
54 Conic *conic = ts_ralloc(Conic);
55
56 conic->type = type;
57 conic->label = new_label();
58 conic->props = NULL;
59 return (conic);
60 }
61
62 Conic *conic_make(int type, Vec2 center, double theta, double alpha, double beta, double t1, double t2, int branch)
63 {
64 Conic *conic = ts_ralloc(Conic);
65 Mat3 rot = {Mat3_id};
66 Mat3 con = {Mat3_id};
67 double cx, cy, a, b, c, s;
68
69 conic->type = type;
70 conic->label = new_label();
71 conic->center = center;
72 conic->theta = theta;
73 conic->alpha = alpha;
74 conic->beta = beta;
75 conic->t1 = t1;
76 conic->t2 = t2;
77 conic->branch = branch;
78
79 cx = vec2_x(center);
80 cy = vec2_y(center);
81 a = 1.0 / (alpha * alpha);
82 b = 1.0 / (beta * beta);
83 if (type == HYPERBOLA)
84 b = -b;
85
86 /** conic in own frame **/
87 con = mat3(a, 0.0, 0.0,
88 0.0, b, 0.0,
89 0.0, 0.0, -1.0);
90
91 /** homogeneous transform to image frame **/
92 c = cos(theta);
93 s = sin(theta);
94 rot = mat3(c, s, cx,
95 s, -c, cy,
96 0.0, 0.0, 1.0);
97
98 /** homogeneous transform from image frame **/
99 rot = mat3_inverse(rot);
100
101 /** conic in image frame **/
102 con = mat3_prod(con, rot);
103 con = mat3_prod(mat3_transpose(rot), con);
104
105 conic->a = mat3_xx(con);
106 conic->b = mat3_xy(con);
107 conic->c = mat3_yy(con);
108 conic->d = mat3_xz(con);
109 conic->e = mat3_yz(con);
110 conic->f = mat3_zz(con);
111
112 return (conic);
113 }
114
115 Conic *conic_copy(Conic * conic)
116 {
117 Conic *copy;
118 List *proplist_copy();
119
120 if (conic == NULL)
121 return (NULL);
122
123 copy = ts_ralloc(Conic);
124 (void) memcpy((char *) copy, (char *) conic, sizeof(Conic));
125 copy->props = proplist_copy(conic->props);
126 return (copy);
127 }
128
129 /* ARGSUSED quieten lint */
130 void *conic_prop_get(Conic * conic, int type, int prop)
131 {
132 if (conic == NULL)
133 return (NULL);
134
135 return (prop_get(conic->props, prop));
136 }
137
138
139 void conic_free(Conic * conic)
140 {
141 if (conic == NULL)
142 return;
143
144 proplist_freelist(conic->props);
145 rfree((void *) conic);
146 }
147
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.