~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-libs/tina/file/fileGeom3_wrt.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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/fileGeom3_wrt.c,v $
 37  * Date    :  $Date: 2009/01/26 01:22:19 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: fileGeom3_wrt.c,v 1.5 2009/01/26 01:22:19 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes   :
 44  * 
 45  *
 46  *********
 47 */
 48 
 49 #include "fileGeom3_wrt.h"
 50 
 51 #if HAVE_CONFIG_H
 52   #include <config.h>
 53 #endif
 54 
 55 #include <stdio.h>
 56 #include <tina/sys/sysPro.h>
 57 #include <tina/sys/sysDef.h>
 58 #include <tina/math/mathPro.h>
 59 #include <tina/math/mathDef.h>
 60 #include <tina/vision/visDef.h>
 61 #include <tina/vision/visPro.h>
 62 
 63 
 64 static void point3_fprint(FILE * fp, Point3 * point, int handed)
 65 /* LEFT or RIGHT */
 66 {
 67     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
 68     Vec3    p1 = {Vec3_id};
 69 
 70     p1 = point->p;
 71     p1.el[1] *= handupdate;     /* for compatibility with old tina
 72                                  * system */
 73     (void) fprintf(fp, "P %d 1 ", point->label);
 74     vec3_print(fp, p1);
 75     (void) fprintf(fp, "\n");
 76 }
 77 
 78 static void line3_fprint(FILE * fp, Line3 * line, int handed)
 79 
 80 
 81 /* LEFT or RIGHT */
 82 {
 83     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
 84     Vec3    p1 = {Vec3_id};
 85     Vec3    p2 = {Vec3_id};
 86     Vec3    v = {Vec3_id};
 87 
 88     p1 = line->p1;
 89     p2 = line->p2;
 90     p1.el[1] *= handupdate;     /* for compatibility with old tina
 91                                  * system */
 92     p2.el[1] *= handupdate;
 93     v = line->v;
 94     (void) fprintf(fp, "S %d 1 %f ", line->label, line->length);
 95     vec3_print(fp, p1);
 96     vec3_print(fp, p2);
 97     vec3_print(fp, v);
 98     (void) fprintf(fp, "\n");
 99 }
100 
101 static void conic3_fprint(FILE * fp, Conic3 * con3, int handed)
102 {
103     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
104     Vec3    origin = {Vec3_id};
105     Vec3    ex = {Vec3_id};
106     Vec3    ey = {Vec3_id};
107     Conic  *conic;
108 
109     if (con3->type == ELLIPSE)
110     {
111 
112        origin = con3->origin;
113        ex = con3->ex;
114        ey = con3->ey;
115        origin.el[1] *= handupdate;
116        ex.el[1] *= handupdate;
117        ey.el[1] *= handupdate;
118 
119        conic = con3->conic;
120 
121        (void) fprintf(fp, "E %d ", conic->label);
122        vec3_print(fp, origin);
123        vec3_print(fp, ex);
124        vec3_print(fp, ey);
125        (void) fprintf(fp, "%f %f %f ", conic->theta, conic->alpha, conic->beta);
126        (void) fprintf(fp, "%f %f\n", conic->t1, conic->t2);
127     }
128     else if (con3->type == HYPERBOLA)
129     {
130        origin = con3->origin;
131        ex = con3->ex;
132        ey = con3->ey;
133        origin.el[1] *= handupdate;
134        ex.el[1] *= handupdate;
135        ey.el[1] *= handupdate;
136 
137        conic = con3->conic;
138 
139        (void) fprintf(fp, "H %d ", conic->label);
140        vec3_print(fp, origin);
141        vec3_print(fp, ex);
142        vec3_print(fp, ey);
143        (void) fprintf(fp, "%f %f %f ", conic->theta, conic->alpha, conic->beta);
144        (void) fprintf(fp, "%f %f ", conic->t1, conic->t2);
145        (void) fprintf(fp, "%d\n", conic->branch);
146     }
147 }
148 
149 static void plane_fprint(FILE * fp, Plane * plane, int handed)
150 
151 
152 /* LEFT or RIGHT */
153 {
154     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
155     Vec3    p = {Vec3_id};
156     Vec3    n = {Vec3_id};
157 
158     p = plane->p;
159     n = plane->n;
160     p.el[1] *= handupdate;      /* for compatibility with old tina
161                                  * system */
162     n.el[1] *= handupdate;
163     (void) fprintf(fp, "N %d ", plane->label);
164     vec3_print(fp, p);
165     vec3_print(fp, n);
166     (void) fprintf(fp, "\n");
167 }
168 
169 static FILE *fp_static;         /* static data! */
170 static int handed_static;       /* static data! */
171 
172 static void geom_fprintf(void *geom, int type)
173 {
174     switch (type)
175     {
176     case POINT3:
177         point3_fprint(fp_static, (Point3 *) geom, handed_static);
178         break;
179     case LINE3:
180         line3_fprint(fp_static, (Line3 *) geom, handed_static);
181         break;
182     case CONIC3:
183         conic3_fprint(fp_static, (Conic3 *) geom, handed_static);
184         break;
185     case PLANE:
186         plane_fprint(fp_static, (Plane *) geom, handed_static);
187         break;
188     default:
189         break;
190     }
191 }
192 
193 /* BUGFIX: Julian Briggs 1/11/93. Was: List   *geom3_write_fp(FILE *
194  * fp, List * geom, int handed) */
195 void    geom3_write_fp(FILE * fp, List * geom, int handed       /* LEFT or RIGHT handed
196                            coords */ )
197 {
198     fp_static = fp;
199     handed_static = handed;
200     reclist_list_apply(geom, geom_fprintf, 0, NULL);
201 }
202 
203 void    geom3_write(char *pathname, List * geom, int handed)
204 
205 
206 /* LEFT or RIGHT handed coords */
207 {
208     char    temps[256];
209     FILE   *fp;
210 
211     if ((fp = fopen(pathname, "wt")) == NULL)
212     {
213         (void) string_append(temps, "can not open file ", pathname, 0);
214         error(temps, non_fatal);
215         return;
216     }
217     geom3_write_fp(fp, geom, handed);
218     (void) fclose(fp);
219 }
220 
221 void    line3_write_geom(char *pathname, List * geom, int handed)       /* historical */
222 
223 
224 /* LEFT or RIGHT handed coords */
225 {
226     geom3_write(pathname, geom, handed);
227 }
228 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.