BRL-CAD
m2v_point.c
Go to the documentation of this file.
1 /* M 2 V _ P O I N T . 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/m2v_point.c
21  *
22  * The m2v_point command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 #include <ctype.h>
30 
31 #include "./ged_private.h"
32 
33 
34 int
35 ged_m2v_point(struct ged *gedp, int argc, const char *argv[])
36 {
37  point_t model;
38  point_t view;
39  double scan[3];
40  static const char *usage = "x y z";
41 
44  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
45 
46  /* initialize result */
47  bu_vls_trunc(gedp->ged_result_str, 0);
48 
49  /* must be wanting help */
50  if (argc == 1) {
51  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
52  return GED_HELP;
53  }
54 
55  if (argc != 2 && argc != 4) {
56  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
57  return GED_ERROR;
58  }
59 
60  if (argc == 2) {
61  if (bn_decode_vect(model, argv[1]) != 3) {
62  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
63  return GED_ERROR;
64  }
65  } else {
66  if (sscanf(argv[1], "%lf", &scan[X]) != 1) {
67  bu_vls_printf(gedp->ged_result_str, "ged_m2v_point: bad X value - %s\n", argv[1]);
68  return GED_ERROR;
69  }
70 
71  if (sscanf(argv[2], "%lf", &scan[Y]) != 1) {
72  bu_vls_printf(gedp->ged_result_str, "ged_m2v_point: bad Y value - %s\n", argv[2]);
73  return GED_ERROR;
74  }
75 
76  if (sscanf(argv[3], "%lf", &scan[Z]) != 1) {
77  bu_vls_printf(gedp->ged_result_str, "ged_m2v_point: bad Z value - %s\n", argv[3]);
78  return GED_ERROR;
79  }
80 
81  /* convert from double to fastf_t */
82  VMOVE(model, scan);
83  }
84 
85  /* Convert the incoming model point to a view point */
86  MAT4X3PNT(view, gedp->ged_gvp->gv_model2view, model);
87  bn_encode_vect(gedp->ged_result_str, view);
88 
89  return GED_OK;
90 }
91 
92 
93 /*
94  * Local Variables:
95  * tab-width: 8
96  * mode: C
97  * indent-tabs-mode: t
98  * c-file-style: "stroustrup"
99  * End:
100  * ex: shiftwidth=4 tabstop=8
101  */
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
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
struct bview * ged_gvp
Definition: ged.h:361
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
int bn_decode_vect(vect_t v, const char *str)
struct bu_vls * ged_result_str
Definition: ged.h:357
mat_t gv_model2view
Definition: bview.h:222
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
int ged_m2v_point(struct ged *gedp, int argc, const char *argv[])
Definition: m2v_point.c:35
Definition: color.c:50