BRL-CAD
oscale.c
Go to the documentation of this file.
1 /* O S C A L 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/oscale.c
21  *
22  * The oscale command.
23  *
24  */
25 
26 #include "common.h"
27 
28 
29 #include "./ged_private.h"
30 
31 
32 /*
33  * Scale obj about the keypoint by sf.
34  */
35 int
36 ged_oscale(struct ged *gedp, int argc, const char *argv[])
37 {
38  struct directory *dp;
39  struct _ged_trace_data gtd;
40  struct rt_db_internal intern;
41  mat_t smat;
42  mat_t emat;
43  mat_t tmpMat;
44  mat_t invXform;
45  point_t rpp_min;
46  point_t rpp_max;
47  point_t keypoint;
48 
49  /* intentionally double for scan */
50  double sf;
51 
52  static const char *usage = "obj sf [kX kY kZ]";
53 
56  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
57 
58  /* initialize result */
59  bu_vls_trunc(gedp->ged_result_str, 0);
60 
61  /* must be wanting help */
62  if (argc == 1) {
63  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
64  return GED_HELP;
65  }
66 
67  if (argc != 3 && argc != 6) {
68  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
69  return GED_ERROR;
70  }
71 
72  if (sscanf(argv[2], "%lf", &sf) != 1) {
73  bu_vls_printf(gedp->ged_result_str, "%s: bad sf value - %s", argv[0], argv[2]);
74  return GED_ERROR;
75  }
76 
77  if (argc == 3) {
78  if (_ged_get_obj_bounds2(gedp, 1, argv+1, &gtd, rpp_min, rpp_max) == TCL_ERROR)
79  return TCL_ERROR;
80 
81  dp = gtd.gtd_obj[gtd.gtd_objpos-1];
82  if (!(dp->d_flags & RT_DIR_SOLID)) {
83  if (ged_get_obj_bounds(gedp, 1, argv+1, 1, rpp_min, rpp_max) == TCL_ERROR)
84  return TCL_ERROR;
85  }
86 
87  VADD2(keypoint, rpp_min, rpp_max);
88  VSCALE(keypoint, keypoint, 0.5);
89  } else {
90  double scan[3];
91 
92  /* The user has provided the keypoint. */
93  MAT_IDN(gtd.gtd_xform);
94 
95  if (sscanf(argv[3], "%lf", &scan[X]) != 1) {
96  bu_vls_printf(gedp->ged_result_str, "%s: bad kx value - %s", argv[0], argv[3]);
97  return GED_ERROR;
98  }
99 
100  if (sscanf(argv[4], "%lf", &scan[Y]) != 1) {
101  bu_vls_printf(gedp->ged_result_str, "%s: bad ky value - %s", argv[0], argv[4]);
102  return GED_ERROR;
103  }
104 
105  if (sscanf(argv[5], "%lf", &scan[Z]) != 1) {
106  bu_vls_printf(gedp->ged_result_str, "%s: bad kz value - %s", argv[0], argv[5]);
107  return GED_ERROR;
108  }
109 
110  VSCALE(keypoint, scan, gedp->ged_wdbp->dbip->dbi_local2base);
111 
112  if ((dp = db_lookup(gedp->ged_wdbp->dbip, argv[1], LOOKUP_QUIET)) == RT_DIR_NULL) {
113  bu_vls_printf(gedp->ged_result_str, "%s: %s not found", argv[0], argv[1]);
114  return GED_ERROR;
115  }
116  }
117 
118  MAT_IDN(smat);
119  bn_mat_scale_about_pt(smat, keypoint, sf);
120 
121  bn_mat_inv(invXform, gtd.gtd_xform);
122  bn_mat_mul(tmpMat, invXform, smat);
123  bn_mat_mul(emat, tmpMat, gtd.gtd_xform);
124 
125  GED_DB_GET_INTERNAL(gedp, &intern, dp, emat, &rt_uniresource, GED_ERROR);
126  RT_CK_DB_INTERNAL(&intern);
127  GED_DB_PUT_INTERNAL(gedp, dp, &intern, &rt_uniresource, GED_ERROR);
128 
129  return GED_OK;
130 }
131 
132 
133 /*
134  * Local Variables:
135  * tab-width: 8
136  * mode: C
137  * indent-tabs-mode: t
138  * c-file-style: "stroustrup"
139  * End:
140  * ex: shiftwidth=4 tabstop=8
141  */
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 directory * db_lookup(const struct db_i *, const char *name, int noisy)
Definition: db_lookup.c:153
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
int bn_mat_scale_about_pt(mat_t mat, const point_t pt, const double scale)
Definition: mat.c:884
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
#define RT_DIR_SOLID
this name is a solid
Definition: raytrace.h:883
#define LOOKUP_QUIET
Definition: raytrace.h:893
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)
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 RT_DIR_NULL
Definition: raytrace.h:875
#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
int ged_oscale(struct ged *gedp, int argc, const char *argv[])
Definition: oscale.c:36
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