BRL-CAD
mirror.c
Go to the documentation of this file.
1 /* M I R R O R . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2007-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 /** @file primitives/mirror.c
21  *
22  * Routine(s) to mirror objects.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <string.h>
29 #include "bio.h"
30 
31 #include "rtgeom.h"
32 #include "raytrace.h"
33 #include "wdb.h"
34 #include "bn.h"
35 
36 #include "vmath.h"
37 #include "nurb.h"
38 
39 
40 /* FIXME: temporary until all mirror functions are migrated and the
41  * functab is utilized.
42  */
43 #define RT_DECLARE_MIRROR(name) extern int rt_##name##_mirror(struct rt_db_internal *ip, const plane_t plane)
44 
49 RT_DECLARE_MIRROR(half);
50 RT_DECLARE_MIRROR(grip);
52 RT_DECLARE_MIRROR(poly);
53 RT_DECLARE_MIRROR(bspline);
54 RT_DECLARE_MIRROR(arbn);
55 RT_DECLARE_MIRROR(pipe);
56 RT_DECLARE_MIRROR(particle);
67 RT_DECLARE_MIRROR(superell);
68 RT_DECLARE_MIRROR(comb);
70 RT_DECLARE_MIRROR(nurb);
71 
72 
73 /*
74  FIXME: missing mirror implementations
75 
76  RT_DECLARE_MIRROR(brep);
77  RT_DECLARE_MIRROR(cline);
78  RT_DECLARE_MIRROR(ehy);
79  RT_DECLARE_MIRROR(extrude);
80  RT_DECLARE_MIRROR(hf);
81  RT_DECLARE_MIRROR(metaball);
82  RT_DECLARE_MIRROR(pnts);
83  RT_DECLARE_MIRROR(rec);
84  RT_DECLARE_MIRROR(revolve);
85  RT_DECLARE_MIRROR(sketch);
86  RT_DECLARE_MIRROR(submodel);
87 */
88 
89 
90 /**
91  * Mirror an object about some axis at a specified point on the axis.
92  * It is the caller's responsibility to retain and free the internal.
93  *
94  * Returns the modified internal object or NULL on error.
95  **/
96 struct rt_db_internal *
97 rt_mirror(struct db_i *dbip,
98  struct rt_db_internal *ip,
99  point_t mirror_pt,
100  vect_t mirror_dir,
101  struct resource *resp)
102 {
103  int id;
104  int err;
105  static fastf_t tol_dist_sq = 0.0005 * 0.0005;
106  plane_t plane;
107 
108  RT_CK_DBI(dbip);
109  RT_CK_DB_INTERNAL(ip);
110 
111  if (!NEAR_EQUAL(MAGSQ(mirror_dir), 1.0, tol_dist_sq)) {
112  bu_log("ERROR: mirror direction is invalid\n");
113  return NULL;
114  }
115 
116  if (!resp) {
117  resp=&rt_uniresource;
118  }
119 
120  /* not the best, but consistent until v6 */
121  id = ip->idb_type;
122 
123  /* set up the plane direction */
124  VUNITIZE(mirror_dir);
125  VMOVE(plane, mirror_dir);
126 
127  /* determine the plane offset */
128  plane[W] = VDOT(mirror_pt, mirror_dir);
129 
130  switch (id) {
131  case ID_TOR: {
132  err = rt_tor_mirror(ip, plane);
133  return err ? NULL : ip;
134  }
135  case ID_TGC:
136  case ID_REC: {
137  err = rt_tgc_mirror(ip, plane);
138  return err ? NULL : ip;
139  }
140  case ID_ELL:
141  case ID_SPH: {
142  err = rt_ell_mirror(ip, plane);
143  return err ? NULL : ip;
144  }
145  case ID_ARB8: {
146  err = rt_arb_mirror(ip, plane);
147  return err ? NULL : ip;
148  }
149  case ID_HALF: {
150  err = rt_half_mirror(ip, plane);
151  return err ? NULL : ip;
152  }
153  case ID_GRIP: {
154  err = rt_grip_mirror(ip, plane);
155  return err ? NULL : ip;
156  }
157  case ID_JOINT: {
158  err = rt_joint_mirror(ip, plane);
159  return err ? NULL : ip;
160  }
161  case ID_POLY: {
162  err = rt_poly_mirror(ip, plane);
163  return err ? NULL : ip;
164  }
165  case ID_BSPLINE: {
166  err = rt_nurb_mirror(ip, plane);
167  return err ? NULL : ip;
168  }
169  case ID_ARBN: {
170  err = rt_arbn_mirror(ip, plane);
171  return err ? NULL : ip;
172  }
173  case ID_PIPE: {
174  err = rt_pipe_mirror(ip, plane);
175  return err ? NULL : ip;
176  }
177  case ID_PARTICLE: {
178  err = rt_particle_mirror(ip, plane);
179  return err ? NULL : ip;
180  }
181  case ID_RPC: {
182  err = rt_rpc_mirror(ip, plane);
183  return err ? NULL : ip;
184  }
185  case ID_RHC: {
186  err = rt_rhc_mirror(ip, plane);
187  return err ? NULL : ip;
188  }
189  case ID_EPA: {
190  err = rt_epa_mirror(ip, plane);
191  return err ? NULL : ip;
192  }
193  case ID_ETO: {
194  err = rt_eto_mirror(ip, plane);
195  return err ? NULL : ip;
196  }
197  case ID_HYP: {
198  err = rt_hyp_mirror(ip, plane);
199  return err ? NULL : ip;
200  }
201  case ID_NMG: {
202  err = rt_nmg_mirror(ip, plane);
203  return err ? NULL : ip;
204  }
205  case ID_ARS: {
206  err = rt_ars_mirror(ip, plane);
207  return err ? NULL : ip;
208  }
209  case ID_EBM: {
210  err = rt_ebm_mirror(ip, plane);
211  return err ? NULL : ip;
212  }
213  case ID_DSP: {
214  err = rt_dsp_mirror(ip, plane);
215  return err ? NULL : ip;
216  }
217  case ID_VOL: {
218  err = rt_vol_mirror(ip, plane);
219  return err ? NULL : ip;
220  }
221  case ID_SUPERELL: {
222  err = rt_superell_mirror(ip, plane);
223  return err ? NULL : ip;
224  }
225  case ID_COMBINATION: {
226  err = rt_comb_mirror(ip, plane);
227  return err ? NULL : ip;
228  }
229  case ID_BOT: {
230  err = rt_bot_mirror(ip, plane);
231  return err ? NULL : ip;
232  }
233  default: {
234  bu_log("Unknown or unsupported object type (id==%d)\n", id);
235  }
236  }
237 
238  /* sanity in case object is unknown */
239  return NULL;
240 }
241 
242 
243 /*
244  * Local Variables:
245  * mode: C
246  * tab-width: 8
247  * indent-tabs-mode: t
248  * c-file-style: "stroustrup"
249  * End:
250  * ex: shiftwidth=4 tabstop=8
251  */
Definition: joint.h:118
int rt_nurb_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: raytrace.h:800
#define ID_ARS
ARS.
Definition: raytrace.h:463
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
int rt_half_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: half_mirror.c:37
int rt_joint_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: joint_mirror.c:37
int rt_epa_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: epa_mirror.c:37
#define ID_PIPE
Pipe (wire) solid.
Definition: raytrace.h:473
#define RT_DECLARE_MIRROR(name)
Definition: mirror.c:43
int rt_hyp_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: hyp_mirror.c:37
#define ID_ARB8
Generalized ARB. V + 7 vectors.
Definition: raytrace.h:462
#define ID_GRIP
Pseudo Solid Grip.
Definition: raytrace.h:480
#define ID_JOINT
Pseudo Solid/Region Joint.
Definition: raytrace.h:481
#define ID_BOT
Bag o' triangles.
Definition: raytrace.h:488
#define ID_PARTICLE
Particle system solid.
Definition: raytrace.h:474
Header file for the BRL-CAD common definitions.
#define ID_TOR
Toroid.
Definition: raytrace.h:459
#define ID_BSPLINE
B-spline object.
Definition: raytrace.h:467
#define ID_COMBINATION
Combination Record.
Definition: raytrace.h:499
int rt_eto_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: eto_mirror.c:37
#define ID_VOL
3-D Volume
Definition: raytrace.h:471
int rt_tor_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: tor_mirror.c:37
#define ID_DSP
Displacement map.
Definition: raytrace.h:483
struct resource rt_uniresource
default. Defined in librt/globals.c
Definition: globals.c:41
int rt_nmg_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: nmg_mirror.c:37
#define ID_HYP
Hyperboloid of one sheet.
Definition: raytrace.h:510
#define ID_EBM
Extruded bitmap solid.
Definition: raytrace.h:470
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
struct rt_db_internal * rt_mirror(struct db_i *dbip, struct rt_db_internal *ip, point_t mirror_pt, vect_t mirror_dir, struct resource *resp)
Definition: mirror.c:97
int rt_arbn_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: arbn_mirror.c:37
#define ID_NMG
n-Manifold Geometry solid
Definition: raytrace.h:469
int rt_arb_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: arb8_mirror.c:37
int rt_ell_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: ell_mirror.c:37
int rt_rpc_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: rpc_mirror.c:37
int rt_ars_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: ars_mirror.c:40
int rt_ebm_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: ebm_mirror.c:37
#define ID_SPH
Sphere.
Definition: raytrace.h:468
#define ID_HALF
Half-space.
Definition: raytrace.h:464
#define ID_REC
Right Elliptical Cylinder [TGC special].
Definition: raytrace.h:465
#define ID_RHC
Right Hyperbolic Cylinder.
Definition: raytrace.h:476
#define ID_ARBN
ARB with N faces.
Definition: raytrace.h:472
#define ID_EPA
Elliptical Paraboloid.
Definition: raytrace.h:477
#define RT_CK_DBI(_p)
Definition: raytrace.h:829
int rt_pipe_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: pipe_mirror.c:38
int rt_poly_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: poly_mirror.c:37
#define ID_SUPERELL
Superquadratic ellipsoid.
Definition: raytrace.h:507
#define ID_POLY
Polygonal faceted object.
Definition: raytrace.h:466
int rt_vol_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: vol_mirror.c:37
int rt_tgc_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: tgc_mirror.c:37
int rt_bot_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: bot_mirror.c:37
int rt_particle_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: part_mirror.c:37
int rt_comb_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: comb_mirror.c:37
#define ID_RPC
Right Parabolic Cylinder.
Definition: raytrace.h:475
#define ID_TGC
Generalized Truncated General Cone.
Definition: raytrace.h:460
#define ID_ETO
Elliptical Torus.
Definition: raytrace.h:479
double fastf_t
Definition: defines.h:300
#define ID_ELL
Ellipsoid.
Definition: raytrace.h:461
int rt_grip_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: grip_mirror.c:37
int rt_superell_mirror(struct rt_db_internal *ip, register const plane_t plane)
int rt_rhc_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: rhc_mirror.c:37
int rt_dsp_mirror(struct rt_db_internal *ip, register const plane_t plane)
Definition: dsp_mirror.c:37