BRL-CAD
nmg_fix_normals.c
Go to the documentation of this file.
1 /* N M G _ F I X _ N O R M A L S . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2009-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 
21 /** @file libged/nmg_fix_normals.c
22  *
23  * The nmg_fix_normals command.
24  *
25  */
26 
27 #include "common.h"
28 
29 #include <string.h>
30 
31 #include "bu/cmd.h"
32 #include "rtgeom.h"
33 
34 #include "./ged_private.h"
35 
36 
37 int
38 ged_nmg_fix_normals(struct ged *gedp, int argc, const char *argv[])
39 {
40  struct directory *dp;
41  struct rt_db_internal nmg_intern;
42  struct model *m;
43  struct nmgregion *r;
44  struct shell *s;
45  const char *nmg_name;
46  struct bn_tol tol;
47 
48  static const char *usage = "nmg_prim";
49 
52  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
53 
54  /* in theory, we should probably allow the user to override this. */
55  tol.magic = BN_TOL_MAGIC;
56  tol.dist = 0.01;
57  tol.dist_sq = tol.dist * tol.dist;
58  tol.perp = 0.001;
59  tol.para = 0.999;
60 
61  if (argc != 2) {
62  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
63  return GED_HELP;
64  }
65 
66  /* attempt to resolve and verify before we jump in */
67  nmg_name = argv[1];
68 
69  if ((dp=db_lookup(gedp->ged_wdbp->dbip, nmg_name, LOOKUP_QUIET)) == RT_DIR_NULL) {
70  bu_vls_printf(gedp->ged_result_str, "%s does not exist\n", nmg_name);
71  return GED_ERROR;
72  }
73 
74  if (rt_db_get_internal(&nmg_intern, dp, gedp->ged_wdbp->dbip, bn_mat_identity, &rt_uniresource) < 0) {
75  bu_vls_printf(gedp->ged_result_str, "rt_db_get_internal() error\n");
76  return GED_ERROR;
77  }
78 
79  if (nmg_intern.idb_type != ID_NMG) {
80  bu_vls_printf(gedp->ged_result_str, "%s is not an NMG solid\n", nmg_name);
81  rt_db_free_internal(&nmg_intern);
82  return GED_ERROR;
83  }
84 
85  m = (struct model *)nmg_intern.idb_ptr;
86  NMG_CK_MODEL(m);
87 
88  /* hum, here we go */
89  for (BU_LIST_FOR(r, nmgregion, &m->r_hd))
90  for (BU_LIST_FOR(s, shell, &r->s_hd))
91  nmg_fix_normals(s, &tol);
92 
93  return GED_OK;
94 }
95 
96 
97 /*
98  * Local Variables:
99  * tab-width: 8
100  * mode: C
101  * indent-tabs-mode: t
102  * c-file-style: "stroustrup"
103  * End:
104  * ex: shiftwidth=4 tabstop=8
105  */
void nmg_fix_normals(struct shell *s_orig, const struct bn_tol *tol)
Definition: nmg_misc.c:3505
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
#define BU_LIST_FOR(p, structure, hp)
Definition: list.h:365
int rt_db_get_internal(struct rt_db_internal *ip, const struct directory *dp, const struct db_i *dbip, const mat_t mat, struct resource *resp)
Definition: dir.c:76
double dist
>= 0
Definition: tol.h:73
Definition: ged.h:338
const mat_t bn_mat_identity
Matrix and vector functionality.
Definition: mat.c:46
struct db_i * dbip
Definition: raytrace.h:1266
if lu s
Definition: nmg_mod.c:3860
#define GED_CHECK_ARGC_GT_0(_gedp, _argc, _flags)
Definition: ged.h:202
double dist_sq
dist * dist
Definition: tol.h:74
struct directory * db_lookup(const struct db_i *, const char *name, int noisy)
Definition: db_lookup.c:153
#define BN_TOL_MAGIC
Definition: magic.h:74
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 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 LOOKUP_QUIET
Definition: raytrace.h:893
#define ID_NMG
n-Manifold Geometry solid
Definition: raytrace.h:469
Support for uniform tolerances.
Definition: tol.h:71
struct bu_vls * ged_result_str
Definition: ged.h:357
double perp
nearly 0
Definition: tol.h:75
void * idb_ptr
Definition: raytrace.h:195
uint32_t magic
Definition: tol.h:72
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
int ged_nmg_fix_normals(struct ged *gedp, int argc, const char *argv[])
#define GED_HELP
Definition: ged.h:62
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
double para
nearly 1
Definition: tol.h:76
void rt_db_free_internal(struct rt_db_internal *ip)
Definition: dir.c:216