BRL-CAD
pipe.c
Go to the documentation of this file.
1 /* P I P E . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1990-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 libwdb/pipe.c
22  *
23  * Support for particles and pipes. Library for writing geometry
24  * databases from arbitrary procedures.
25  *
26  * Note that routines which are passed point_t or vect_t or mat_t
27  * parameters (which are call-by-address) must be VERY careful to
28  * leave those parameters unmodified (e.g., by scaling), so that the
29  * calling routine is not surprised.
30  *
31  * Return codes of 0 are OK, -1 signal an error.
32  *
33  */
34 
35 
36 #include "common.h"
37 
38 #include <math.h>
39 #include "bio.h"
40 
41 #include "vmath.h"
42 #include "bn.h"
43 #include "rtgeom.h"
44 #include "raytrace.h"
45 #include "wdb.h"
46 
47 
48 int
49 mk_particle(struct rt_wdb *fp, const char *name, fastf_t *vertex, fastf_t *height, double vradius, double hradius)
50 {
51  struct rt_part_internal *part;
52 
53  BU_ALLOC(part, struct rt_part_internal);
54  part->part_magic = RT_PART_INTERNAL_MAGIC;
55  VMOVE(part->part_V, vertex);
56  VMOVE(part->part_H, height);
57  part->part_vrad = vradius;
58  part->part_hrad = hradius;
59  part->part_type = 0; /* sanity, unused */
60 
61  return wdb_export(fp, name, (void *)part, ID_PARTICLE, mk_conv2mm);
62 }
63 
64 
65 int
66 mk_pipe(struct rt_wdb *fp, const char *name, struct bu_list *headp)
67 {
68  struct rt_pipe_internal *pipep;
69 
70  if (rt_pipe_ck(headp)) {
71  bu_log("mk_pipe: BAD PIPE SOLID (%s)\n", name);
72  return 1;
73  }
74 
75  BU_ALLOC(pipep, struct rt_pipe_internal);
76  pipep->pipe_magic = RT_PIPE_INTERNAL_MAGIC;
77  BU_LIST_INIT(&pipep->pipe_segs_head);
78  /* linked list from caller */
79  BU_LIST_APPEND_LIST(&pipep->pipe_segs_head, headp);
80 
81  return wdb_export(fp, name, (void *)pipep, ID_PIPE, mk_conv2mm);
82 }
83 
84 
85 void
86 mk_pipe_free(struct bu_list *headp)
87 {
88  struct wdb_pipept *wp;
89 
90  while (BU_LIST_WHILE(wp, wdb_pipept, headp)) {
91  BU_LIST_DEQUEUE(&wp->l);
92  bu_free((char *)wp, "mk_pipe_free");
93  }
94 }
95 
96 
97 void
99  struct bu_list *headp,
100  const point_t coord,
101  double od,
102  double id,
103  double bendradius)
104 {
105  struct wdb_pipept *newpp;
106 
107  BU_CKMAG(headp, WDB_PIPESEG_MAGIC, "pipe point");
108 
109  BU_ALLOC(newpp, struct wdb_pipept);
110  newpp->l.magic = WDB_PIPESEG_MAGIC;
111  newpp->pp_od = od;
112  newpp->pp_id = id;
113  newpp->pp_bendradius = bendradius;
114  VMOVE(newpp->pp_coord, coord);
115  BU_LIST_INSERT(headp, &newpp->l);
116 }
117 
118 
119 void
120 mk_pipe_init(struct bu_list *headp)
121 {
122  BU_LIST_INIT(headp);
123  headp->magic = WDB_PIPESEG_MAGIC;
124 }
125 
126 
127 /*
128  * Local Variables:
129  * mode: C
130  * tab-width: 8
131  * indent-tabs-mode: t
132  * c-file-style: "stroustrup"
133  * End:
134  * ex: shiftwidth=4 tabstop=8
135  */
int mk_pipe(struct rt_wdb *fp, const char *name, struct bu_list *headp)
Definition: pipe.c:66
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
#define BU_LIST_INSERT(old, new)
Definition: list.h:183
void mk_pipe_init(struct bu_list *headp)
Definition: pipe.c:120
void mk_pipe_free(struct bu_list *headp)
Definition: pipe.c:86
Definition: list.h:118
#define BU_CKMAG(_ptr, _magic, _str)
Definition: magic.h:233
#define ID_PIPE
Pipe (wire) solid.
Definition: raytrace.h:473
Definition: clone.c:90
int rt_pipe_ck(const struct bu_list *headp)
Definition: pipe.c:4278
#define ID_PARTICLE
Particle system solid.
Definition: raytrace.h:474
Header file for the BRL-CAD common definitions.
void mk_add_pipe_pt(struct bu_list *headp, const point_t coord, double od, double id, double bendradius)
Definition: pipe.c:98
int wdb_export(struct rt_wdb *wdbp, const char *name, void *gp, int id, double local2mm)
Definition: wdb.c:265
#define BU_ALLOC(_ptr, _type)
Definition: malloc.h:223
int mk_particle(struct rt_wdb *fp, const char *name, fastf_t *vertex, fastf_t *height, double vradius, double hradius)
Definition: pipe.c:49
double mk_conv2mm
Conversion factor to mm.
Definition: units.c:37
uint32_t magic
Magic # for mem id/check.
Definition: list.h:119
#define BU_LIST_WHILE(p, structure, hp)
Definition: list.h:410
#define BU_LIST_INIT(_hp)
Definition: list.h:148
#define WDB_PIPESEG_MAGIC
Definition: magic.h:214
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
#define BU_LIST_DEQUEUE(cur)
Definition: list.h:209
#define RT_PART_INTERNAL_MAGIC
Definition: magic.h:102
double fastf_t
Definition: defines.h:300
#define BU_LIST_APPEND_LIST(dest_hp, src_hp)
Definition: list.h:281
#define RT_PIPE_INTERNAL_MAGIC
Definition: magic.h:104