BRL-CAD
grid2model_lu.c
Go to the documentation of this file.
1 /* G R I D 2 M O D E L _ L U . 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/grid2model_lu.c
21  *
22  * The grid2model_lu command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <string.h>
31 
32 #include "./ged_private.h"
33 
34 
35 int
36 ged_grid2model_lu(struct ged *gedp, int argc, const char *argv[])
37 {
38  fastf_t f;
39  point_t view_pt;
40  point_t model_pt;
41  point_t mo_view_pt; /* model origin in view space */
42  point_t diff;
43  double scan[3];
44  static const char *usage = "u v";
45 
48  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
49 
50  /* initialize result */
51  bu_vls_trunc(gedp->ged_result_str, 0);
52 
53  if (argc != 3)
54  goto bad;
55 
56  if (sscanf(argv[1], "%lf", &scan[X]) != 1 ||
57  sscanf(argv[2], "%lf", &scan[Y]) != 1)
58  goto bad;
59  scan[Z] = 0.0;
60 
61  f = 1.0 / (gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local);
62  VSCALE(diff, scan, f);
63  VSETALL(model_pt, 0.0);
64  MAT4X3PNT(mo_view_pt, gedp->ged_gvp->gv_model2view, model_pt);
65  VADD2(view_pt, mo_view_pt, diff);
66  MAT4X3PNT(model_pt, gedp->ged_gvp->gv_view2model, view_pt);
67  VSCALE(model_pt, model_pt, gedp->ged_wdbp->dbip->dbi_base2local);
68  bn_encode_vect(gedp->ged_result_str, model_pt);
69 
70  return GED_OK;
71 
72 bad:
73  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
74  return GED_ERROR;
75 }
76 
77 
78 /*
79  * Local Variables:
80  * tab-width: 8
81  * mode: C
82  * indent-tabs-mode: t
83  * c-file-style: "stroustrup"
84  * End:
85  * ex: shiftwidth=4 tabstop=8
86  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
void bn_encode_vect(struct bu_vls *vp, const vect_t v)
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
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
struct bview * ged_gvp
Definition: ged.h:361
mat_t gv_view2model
Definition: bview.h:224
Definition: color.c:49
#define GED_CHECK_VIEW(_gedp, _flags)
Definition: ged.h:140
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
fastf_t gv_scale
Definition: bview.h:211
struct bu_vls * ged_result_str
Definition: ged.h:357
double dbi_base2local
unit conversion factors
Definition: raytrace.h:808
mat_t gv_model2view
Definition: bview.h:222
int ged_grid2model_lu(struct ged *gedp, int argc, const char *argv[])
Definition: grid2model_lu.c:36
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
Definition: color.c:51
double fastf_t
Definition: defines.h:300
Definition: color.c:50