BRL-CAD
get_autoview.c
Go to the documentation of this file.
1 /* G E T _ A U T O V I E W . 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/get_autoview.c
21  *
22  * The get_autoview command.
23  *
24  */
25 
26 #include "bu/getopt.h"
27 #include "ged.h"
28 
29 
30 #include "./ged_private.h"
31 
32 /*
33  * Get the view size and center such that all displayed solids would be in view
34  *
35  * Usage:
36  * get_autoview
37  *
38  */
39 int
40 ged_get_autoview(struct ged *gedp, int argc, const char *argv[])
41 {
42  int is_empty = 1;
43  vect_t min, max;
44  vect_t center;
45  vect_t radial;
46  fastf_t size;
47  int pflag = 0;
48  int c;
49 
52  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
53 
54  /* initialize result */
55  bu_vls_trunc(gedp->ged_result_str, 0);
56 
57  /* must be wanting help */
58  if (argc != 1) {
59  bu_vls_printf(gedp->ged_result_str, "Usage: %s", argv[0]);
60  return GED_HELP;
61  }
62 
63  /* Parse options. */
64  bu_optind = 1;
65  while ((c = bu_getopt(argc, (char * const *)argv, "p")) != -1) {
66  switch (c) {
67  case 'p':
68  pflag = 1;
69  break;
70  default: {
71  bu_vls_printf(gedp->ged_result_str, "Usage: %s", argv[0]);
72  return GED_ERROR;
73  }
74  }
75  }
76  argc -= bu_optind;
77  argv += bu_optind;
78 
79  is_empty = dl_bounding_sph(gedp->ged_gdp->gd_headDisplay, &min, &max, pflag);
80 
81  if (is_empty) {
82  /* Nothing is in view */
83  VSETALL(center, 0.0);
84  VSETALL(radial, 1000.0); /* 1 meter */
85  } else {
86  VADD2SCALE(center, max, min, 0.5);
87  VSUB2(radial, max, center);
88  }
89 
90  if (VNEAR_ZERO(radial, SQRT_SMALL_FASTF))
91  VSETALL(radial, 1.0);
92 
93  VSCALE(center, center, gedp->ged_wdbp->dbip->dbi_base2local);
94  VSCALE(radial, radial, gedp->ged_wdbp->dbip->dbi_base2local * 2.0);
95  size = radial[X];
96  V_MAX(size, radial[Y]);
97  V_MAX(size, radial[Z]);
98  bu_vls_printf(gedp->ged_result_str, "center {%g %g %g} size %g", V3ARGS(center), size);
99 
100  return GED_OK;
101 }
102 
103 
104 /*
105  * Local Variables:
106  * tab-width: 8
107  * mode: C
108  * indent-tabs-mode: t
109  * c-file-style: "stroustrup"
110  * End:
111  * ex: shiftwidth=4 tabstop=8
112  */
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
struct db_i * dbip
Definition: raytrace.h:1266
#define VSETALL(a, s)
Definition: color.c:54
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
int bu_optind
Definition: globals.c:89
int bu_getopt(int nargc, char *const nargv[], const char *ostr)
Definition: getopt.c:43
struct bu_list * gd_headDisplay
head of display list
Definition: ged.h:307
#define GED_ERROR
Definition: ged.h:61
Definition: color.c:49
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
#define V3ARGS(a)
Definition: color.c:56
#define SQRT_SMALL_FASTF
Definition: defines.h:346
#define GED_CHECK_DRAWABLE(_gedp, _flags)
Definition: ged.h:129
int dl_bounding_sph(struct bu_list *hdlp, vect_t *min, vect_t *max, int pflag)
Definition: display_list.c:157
struct bu_vls * ged_result_str
Definition: ged.h:357
double dbi_base2local
unit conversion factors
Definition: raytrace.h:808
struct ged_drawable * ged_gdp
Definition: ged.h:360
int ged_get_autoview(struct ged *gedp, int argc, const char *argv[])
Definition: get_autoview.c:40
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
Definition: color.c:51
double fastf_t
Definition: defines.h:300
Definition: color.c:50