BRL-CAD
arb.c
Go to the documentation of this file.
1 /* A R B . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-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 libged/arb.c
21  *
22  * The arb command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <string.h>
31 
32 #include "rtgeom.h"
33 
34 #include "./ged_private.h"
35 
36 
37 int
38 ged_arb(struct ged *gedp, int argc, const char *argv[])
39 {
40  struct directory *dp;
41  struct rt_db_internal internal;
42  struct rt_arb_internal *arb;
43  int i, j;
44  double rota, fb_a;
45  vect_t norm1, norm2, norm3;
46  static const char *usage = "name rot fb";
47 
50  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
51 
52  /* initialize result */
53  bu_vls_trunc(gedp->ged_result_str, 0);
54 
55  /* must be wanting help */
56  if (argc == 1) {
57  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
58  return GED_HELP;
59  }
60 
61  if (argc != 4) {
62  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
63  return GED_ERROR;
64  }
65 
66  GED_CHECK_EXISTS(gedp, argv[1], LOOKUP_QUIET, GED_ERROR);
67 
68  /* get rotation angle */
69  if (sscanf(argv[2], "%lf", &rota) != 1) {
70  bu_vls_printf(gedp->ged_result_str, "%s: bad rotation angle - %s", argv[0], argv[2]);
71  return GED_ERROR;
72  }
73 
74  /* get fallback angle */
75  if (sscanf(argv[3], "%lf", &fb_a) != 1) {
76  bu_vls_printf(gedp->ged_result_str, "%s: bad fallback angle - %s", argv[0], argv[3]);
77  return GED_ERROR;
78  }
79 
80  rota *= DEG2RAD;
81  fb_a *= DEG2RAD;
82 
83  BU_ALLOC(arb, struct rt_arb_internal);
84  RT_DB_INTERNAL_INIT(&internal);
85  internal.idb_major_type = DB5_MAJORTYPE_BRLCAD;
86  internal.idb_type = ID_ARB8;
87  internal.idb_meth = &OBJ[ID_ARB8];
88  internal.idb_ptr = (void *)arb;
90 
91  /* FIXME: we should be creating the arb at the center of the
92  * screen. Extract bounding box code from both autoview.c and
93  * get_autoview.c into a general bounding rpp function, and use
94  * accordingly. Should combin autoview.c with get_autoview.c
95  * (perhaps as a flag).
96  */
97  VSET(arb->pt[0], 0.0, 0.0, 0.0);
98 
99  /* calculate normal vector defined by rot, fb_a */
100  norm1[0] = cos(fb_a) * cos(rota);
101  norm1[1] = cos(fb_a) * sin(rota);
102  norm1[2] = sin(fb_a);
103 
104  /* find two perpendicular vectors which are perpendicular to norm */
105  j = 0;
106  for (i = 0; i < 3; i++) {
107  if (fabs(norm1[i]) < fabs(norm1[j]))
108  j = i;
109  }
110  VSET(norm2, 0.0, 0.0, 0.0);
111  norm2[j] = 1.0;
112  VCROSS(norm3, norm2, norm1);
113  VCROSS(norm2, norm3, norm1);
114 
115  /* create new rpp 20x20x2 */
116  /* the 20x20 faces are in rot, fb plane */
117  VUNITIZE(norm2);
118  VUNITIZE(norm3);
119  VJOIN1(arb->pt[1], arb->pt[0], 508.0, norm2);
120  VJOIN1(arb->pt[3], arb->pt[0], -508.0, norm3);
121  VJOIN2(arb->pt[2], arb->pt[0], 508.0, norm2, -508.0, norm3);
122  for (i = 0; i < 4; i++)
123  VJOIN1(arb->pt[i+4], arb->pt[i], -50.8, norm1);
124 
125  GED_DB_DIRADD(gedp, dp, argv[1], RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, (void *)&internal.idb_type, GED_ERROR);
126  GED_DB_PUT_INTERNAL(gedp, dp, &internal, &rt_uniresource, GED_ERROR);
127 
128  return GED_OK;
129 }
130 
131 
132 /*
133  * Local Variables:
134  * tab-width: 8
135  * mode: C
136  * indent-tabs-mode: t
137  * c-file-style: "stroustrup"
138  * End:
139  * ex: shiftwidth=4 tabstop=8
140  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_DB_DIRADD(_gedp, _dp, _name, _laddr, _len, _dirflags, _ptr, _flags)
Definition: ged.h:213
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
#define ID_ARB8
Generalized ARB. V + 7 vectors.
Definition: raytrace.h:462
#define VSET(a, b, c, d)
Definition: color.c:53
void bu_vls_trunc(struct bu_vls *vp, int len)
Definition: vls.c:198
#define GED_CHECK_ARGC_GT_0(_gedp, _argc, _flags)
Definition: ged.h:202
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
#define GED_DB_PUT_INTERNAL(_gedp, _dp, _intern, _resource, _flags)
Definition: ged.h:243
struct resource rt_uniresource
default. Defined in librt/globals.c
Definition: globals.c:41
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
#define BU_ALLOC(_ptr, _type)
Definition: malloc.h:223
#define RT_DIR_SOLID
this name is a solid
Definition: raytrace.h:883
#define RT_DB_INTERNAL_INIT(_p)
Definition: raytrace.h:199
#define LOOKUP_QUIET
Definition: raytrace.h:893
#define RT_DIR_PHONY_ADDR
Special marker for d_addr field.
Definition: raytrace.h:879
#define GED_CHECK_EXISTS(_gedp, _name, _noisy, _flags)
Definition: ged.h:171
struct bu_vls * ged_result_str
Definition: ged.h:357
const struct rt_functab OBJ[]
Definition: table.c:159
int ged_arb(struct ged *gedp, int argc, const char *argv[])
Definition: arb.c:38
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define GED_HELP
Definition: ged.h:62
#define idb_type
Definition: raytrace.h:198
uint32_t magic
Definition: raytrace.h:2042
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
#define RT_ARB_INTERNAL_MAGIC
Definition: magic.h:82