1 /**********
2 *
3 * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
4 * University of Manchester, UK. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 *
9 * . Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * . Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * . Neither the name of the University of Manchester nor the names of its
17 * contributors may be used to endorse or promote products derived from this
18 * software without specific prior written permission.
19 *
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 **********
34 *
35 * Program : TINA
36 * File : $Source: /home/tina/cvs/tina-libs/tina/file/fileEdges_wisp_write.c,v $
37 * Date : $Date: 2003/09/22 16:09:01 $
38 * Version : $Revision: 1.4 $
39 * CVS Id : $Id: fileEdges_wisp_write.c,v 1.4 2003/09/22 16:09:01 tony Exp $
40 *
41 * Author : Legacy TINA
42 *
43 * Notes :
44 *
45 *
46 *********
47 */
48
49 #include "fileEdges_wisp_write.h"
50
51 #if HAVE_CONFIG_H
52 #include <config.h>
53 #endif
54
55 #include <stdio.h>
56 #include <tina/sys/sysDef.h>
57 #include <tina/sys/sysPro.h>
58 #include <tina/math/mathDef.h>
59 #include <tina/math/mathPro.h>
60 #include <tina/geometry/geomPro.h>
61 #include <tina/vision/visDef.h>
62 #include <tina/vision/visPro.h>
63 #include <tina/image/imgPro.h>
64 #include <tina/image/imgDef.h>
65 #include <tina/file/fileUtil_io.h>
66
67 static FILE *stream; /* static data! */
68 static Bool first = true; /* static data! */
69 static float cx, cy; /* static data! */
70 static float ax, ay; /* static data! */
71
72 static void wisp_write_edge(Edgel * edge)
73 {
74 if (first == true)
75 {
76 (void) fprintf(stream, "\nm ");
77 first = false;
78 } else
79 (void) fprintf(stream, "c ");
80
81 (void) fprintf(stream, "%f %f\n", (vec2_x(edge->pos) - cx) * ay, (cy - vec2_y(edge->pos)) * ax);
82 }
83
84 static void wisp_write_poly(Line2 * line)
85 {
86 if (first == true)
87 {
88 (void) fprintf(stream, "\nm %f %f\n", (vec2_x(line->p1) - cx) * ay, (cy - vec2_y(line->p1)) * ax);
89 first = false;
90 }
91 (void) fprintf(stream, "c %f %f\n", (vec2_x(line->p2) - cx) * ay, (cy - vec2_y(line->p2)) * ax);
92 }
93
94 void wisp_write_edge_string(Tstring * s)
95 {
96 first = true;
97 str_apply_func(s, wisp_write_edge, NULL);
98 }
99
100 static void wisp_write_poly_string(Tstring * s)
101 {
102 Tstring *p;
103 double dummy = 0.0;
104
105 first = true;
106
107 /* BUG poly_string requires 2nd argument: double thres. dummy added */
108 p = poly_string(s, dummy);
109 str_apply_func(p, wisp_write_poly, NULL);
110 }
111
112 void wisp_write_edges_stream(Imrect * er, Camera * camera, FILE * stream_out)
113 {
114 float f;
115
116 if (er)
117 {
118 stream = stream_out;
119
120 if (camera == NULL)
121 {
122 f = (float) 1.0;
123 cx = (float) (er->width / 2); /* these two lines may cause a
124 roundoff bug NAT 3/5/95 */
125 cy = (float) (er->height / 2);
126 ax = (float) 1.0;
127 ay = (float) 1.0;
128 } else
129 {
130 f = camera->f / camera->pixel * camera->ax;
131 cx = camera->cx;
132 cy = camera->cy;
133 ax = camera->ax;
134 ay = camera->ay;
135 }
136
137 (void) fprintf(stream, "ICF %f %d\n", f, er->width / 2);
138
139 er_apply_to_all_strings(er, wisp_write_poly_string, NULL);
140 }
141 }
142
143 void wisp_write_edges(char *pathname, Imrect * er, Camera * camera)
144 {
145 if (er)
146 {
147 FILE *stream = fopen_2(pathname, "w");
148
149 if (stream)
150 {
151 wisp_write_edges_stream(er, camera, stream);
152 (void) fclose_2(stream, pathname);
153 }
154 }
155 }
156
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.