BRL-CAD
db_flip.c
Go to the documentation of this file.
1 /* D B _ F L I P . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1995-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup librt */
21 /** @{ */
22 /** @file librt/db_flip.c
23  *
24  * v4 geometry database serialization routines.
25  *
26  */
27 /** @} */
28 
29 #include "common.h"
30 
31 #include "vmath.h"
32 #include "db.h"
33 
34 
35 typedef union {
36  float f;
37  unsigned char c[4];
38 } val;
39 
40 typedef union {
41  short s;
42  unsigned char c[2];
43 } sval;
44 
45 
46 short
47 flip_short(short s)
48 {
49  sval v, v2;
50  v2.s = s;
51  v.c[0] = v2.c[1];
52  v.c[1] = v2.c[0];
53  return v.s;
54 }
55 
56 
57 fastf_t
58 flip_dbfloat(dbfloat_t d)
59 {
60  fastf_t f;
61  val v, v2;
62  v2.f = d;
63  v.c[0] = v2.c[3];
64  v.c[1] = v2.c[2];
65  v.c[2] = v2.c[1];
66  v.c[3] = v2.c[0];
67  f = v.f;
68  return f;
69 }
70 
71 
72 /* private */
73 void
74 flip_fastf_float(fastf_t *ff, const dbfloat_t *fp, int n, int flip)
75 {
76  if (!flip) {
77  while (n--) {
78  *ff++ = *fp++;
79  *ff++ = *fp++;
80  *ff++ = *fp++;
81  ff += ELEMENTS_PER_VECT-3;
82  }
83  } else {
84  while (n--) {
85  *ff++ = flip_dbfloat(fp[0]);
86  *ff++ = flip_dbfloat(fp[1]);
87  *ff++ = flip_dbfloat(fp[2]);
88  fp += 3;
89  }
90  }
91 }
92 
93 
94 /**
95  * Convert TO fastf_t FROM 3xfloats (for database)
96  *
97  * DEPRECATED.
98  */
99 void
100 rt_fastf_float(fastf_t *ff, const dbfloat_t *fp, int n, int flip)
101 {
102  flip_fastf_float(ff, fp, n, flip);
103 }
104 
105 
106 void
107 flip_mat_dbmat(fastf_t *ff, const dbfloat_t *dbp, int flip)
108 {
109  if (!flip) {
110  *ff++ = *dbp++;
111  *ff++ = *dbp++;
112  *ff++ = *dbp++;
113  *ff++ = *dbp++;
114 
115  *ff++ = *dbp++;
116  *ff++ = *dbp++;
117  *ff++ = *dbp++;
118  *ff++ = *dbp++;
119 
120  *ff++ = *dbp++;
121  *ff++ = *dbp++;
122  *ff++ = *dbp++;
123  *ff++ = *dbp++;
124 
125  *ff++ = *dbp++;
126  *ff++ = *dbp++;
127  *ff++ = *dbp++;
128  *ff++ = *dbp++;
129  } else {
130  *ff++ = flip_dbfloat(dbp[0]);
131  *ff++ = flip_dbfloat(dbp[1]);
132  *ff++ = flip_dbfloat(dbp[2]);
133  *ff++ = flip_dbfloat(dbp[3]);
134 
135  *ff++ = flip_dbfloat(dbp[4]);
136  *ff++ = flip_dbfloat(dbp[5]);
137  *ff++ = flip_dbfloat(dbp[6]);
138  *ff++ = flip_dbfloat(dbp[7]);
139 
140  *ff++ = flip_dbfloat(dbp[8]);
141  *ff++ = flip_dbfloat(dbp[9]);
142  *ff++ = flip_dbfloat(dbp[10]);
143  *ff++ = flip_dbfloat(dbp[11]);
144 
145  *ff++ = flip_dbfloat(dbp[12]);
146  *ff++ = flip_dbfloat(dbp[13]);
147  *ff++ = flip_dbfloat(dbp[14]);
148  *ff++ = flip_dbfloat(dbp[15]);
149  }
150 }
151 
152 
153 /**
154  * Convert TO fastf_t matrix FROM dbfloats (for database)
155  *
156  * DEPRECATED.
157  */
158 void
159 rt_mat_dbmat(fastf_t *ff, const dbfloat_t *dbp, int flip)
160 {
161  flip_mat_dbmat(ff, dbp, flip);
162 }
163 
164 
165 void
166 flip_dbmat_mat(dbfloat_t *dbp, const fastf_t *ff)
167 {
168  *dbp++ = (dbfloat_t) *ff++;
169  *dbp++ = (dbfloat_t) *ff++;
170  *dbp++ = (dbfloat_t) *ff++;
171  *dbp++ = (dbfloat_t) *ff++;
172 
173  *dbp++ = (dbfloat_t) *ff++;
174  *dbp++ = (dbfloat_t) *ff++;
175  *dbp++ = (dbfloat_t) *ff++;
176  *dbp++ = (dbfloat_t) *ff++;
177 
178  *dbp++ = (dbfloat_t) *ff++;
179  *dbp++ = (dbfloat_t) *ff++;
180  *dbp++ = (dbfloat_t) *ff++;
181  *dbp++ = (dbfloat_t) *ff++;
182 
183  *dbp++ = (dbfloat_t) *ff++;
184  *dbp++ = (dbfloat_t) *ff++;
185  *dbp++ = (dbfloat_t) *ff++;
186  *dbp++ = (dbfloat_t) *ff++;
187 }
188 
189 
190 /**
191  * Convert FROM fastf_t matrix TO dbfloats (for updating database)
192  *
193  * DEPRECATED.
194  */
195 void
196 rt_dbmat_mat(dbfloat_t *dbp, const fastf_t *ff)
197 {
198  flip_dbmat_mat(dbp, ff);
199 }
200 
201 
202 /*
203  * Local Variables:
204  * mode: C
205  * tab-width: 8
206  * indent-tabs-mode: t
207  * c-file-style: "stroustrup"
208  * End:
209  * ex: shiftwidth=4 tabstop=8
210  */
Definition: db_flip.c:35
void rt_dbmat_mat(dbfloat_t *dbp, const fastf_t *ff)
Definition: db_flip.c:196
if lu s
Definition: nmg_mod.c:3860
unsigned char c[4]
Definition: db_flip.c:37
Header file for the BRL-CAD common definitions.
void flip_dbmat_mat(dbfloat_t *dbp, const fastf_t *ff)
Definition: db_flip.c:166
Definition: db_flip.c:40
void flip_fastf_float(fastf_t *ff, const dbfloat_t *fp, int n, int flip)
Definition: db_flip.c:74
void flip_mat_dbmat(fastf_t *ff, const dbfloat_t *dbp, int flip)
Definition: db_flip.c:107
void rt_mat_dbmat(fastf_t *ff, const dbfloat_t *dbp, int flip)
Definition: db_flip.c:159
fastf_t flip_dbfloat(dbfloat_t d)
Definition: db_flip.c:58
float f
Definition: db_flip.c:36
short s
Definition: db_flip.c:41
short flip_short(short s)
Definition: db_flip.c:47
unsigned char c[2]
Definition: db_flip.c:42
void rt_fastf_float(fastf_t *ff, const dbfloat_t *fp, int n, int flip)
Definition: db_flip.c:100
double fastf_t
Definition: defines.h:300