BRL-CAD
otranslate.c
Go to the documentation of this file.
1 /* O T R A N S L A T E . 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/otranslate.c
21  *
22  * The otranslate command.
23  *
24  */
25 
26 #include "common.h"
27 
28 
29 #include "./ged_private.h"
30 
31 
32 int
33 ged_otranslate(struct ged *gedp, int argc, const char *argv[])
34 {
35  struct directory *dp;
36  struct _ged_trace_data gtd;
37  struct rt_db_internal intern;
38  vect_t delta;
39  double scan[3];
40  mat_t dmat;
41  mat_t emat;
42  mat_t tmpMat;
43  mat_t invXform;
44  point_t rpp_min;
45  point_t rpp_max;
46  static const char *usage = "obj dx dy dz";
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 != 5) {
62  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
63  return GED_ERROR;
64  }
65 
66  if (_ged_get_obj_bounds2(gedp, 1, argv+1, &gtd, rpp_min, rpp_max) == GED_ERROR)
67  return GED_ERROR;
68 
69  dp = gtd.gtd_obj[gtd.gtd_objpos-1];
70  if (!(dp->d_flags & RT_DIR_SOLID)) {
71  if (ged_get_obj_bounds(gedp, 1, argv+1, 1, rpp_min, rpp_max) == GED_ERROR)
72  return GED_ERROR;
73  }
74 
75  if (sscanf(argv[2], "%lf", &scan[X]) != 1) {
76  bu_vls_printf(gedp->ged_result_str, "%s: bad x value - %s", argv[0], argv[2]);
77  return GED_ERROR;
78  }
79 
80  if (sscanf(argv[3], "%lf", &scan[Y]) != 1) {
81  bu_vls_printf(gedp->ged_result_str, "%s: bad y value - %s", argv[0], argv[3]);
82  return GED_ERROR;
83  }
84 
85  if (sscanf(argv[4], "%lf", &scan[Z]) != 1) {
86  bu_vls_printf(gedp->ged_result_str, "%s: bad z value - %s", argv[0], argv[4]);
87  return GED_ERROR;
88  }
89 
90  MAT_IDN(dmat);
91  VSCALE(delta, scan, gedp->ged_wdbp->dbip->dbi_local2base);
92  MAT_DELTAS_VEC(dmat, delta);
93 
94  bn_mat_inv(invXform, gtd.gtd_xform);
95  bn_mat_mul(tmpMat, invXform, dmat);
96  bn_mat_mul(emat, tmpMat, gtd.gtd_xform);
97 
98  GED_DB_GET_INTERNAL(gedp, &intern, dp, emat, &rt_uniresource, GED_ERROR);
99  RT_CK_DB_INTERNAL(&intern);
100  GED_DB_PUT_INTERNAL(gedp, dp, &intern, &rt_uniresource, GED_ERROR);
101 
102  return GED_OK;
103 }
104 
105 
106 /*
107  * Local Variables:
108  * tab-width: 8
109  * mode: C
110  * indent-tabs-mode: t
111  * c-file-style: "stroustrup"
112  * End:
113  * ex: shiftwidth=4 tabstop=8
114  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
struct db_i * dbip
Definition: raytrace.h:1266
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
struct rt_wdb * ged_wdbp
Definition: ged.h:340
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
Definition: color.c:49
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 RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
#define RT_DIR_SOLID
this name is a solid
Definition: raytrace.h:883
void bn_mat_inv(mat_t output, const mat_t input)
int ged_get_obj_bounds(struct ged *gedp, int argc, const char *argv[], int use_air, point_t rpp_min, point_t rpp_max)
void bn_mat_mul(mat_t o, const mat_t a, const mat_t b)
int ged_otranslate(struct ged *gedp, int argc, const char *argv[])
Definition: otranslate.c:33
struct bu_vls * ged_result_str
Definition: ged.h:357
mat_t gtd_xform
Definition: ged.h:1917
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 GED_DB_GET_INTERNAL(_gedp, _intern, _dp, _mat, _resource, _flags)
Definition: ged.h:233
Definition: color.c:51
double dbi_local2base
local2mm
Definition: raytrace.h:807
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
int d_flags
flags
Definition: raytrace.h:869
HIDDEN const point_t delta
Definition: sh_prj.c:618
struct directory * gtd_obj[_GED_MAX_LEVELS]
Definition: ged.h:1916
int _ged_get_obj_bounds2(struct ged *gedp, int argc, const char *argv[], struct _ged_trace_data *gtdp, point_t rpp_min, point_t rpp_max)
This version works if the last member of the path is a primitive.
Definition: color.c:50
int gtd_objpos
Definition: ged.h:1918