BRL-CAD
extrude_brep.cpp
Go to the documentation of this file.
1 /* E X T R U D E _ B R E P . C P P
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 extrude_brep.cpp
21  *
22  * Convert an Extruded Sketch to b-rep form
23  *
24  */
25 
26 #include "common.h"
27 
28 #include "raytrace.h"
29 #include "rtgeom.h"
30 #include "nmg.h"
31 #include "brep.h"
32 
33 extern "C" {
34  extern void rt_sketch_brep(ON_Brep **bi, struct rt_db_internal *ip, const struct bn_tol *tol);
35 }
36 
37 
38 extern "C" void
39 rt_extrude_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *tol)
40 {
41  struct rt_db_internal *tmp_internal;
42  struct rt_extrude_internal *eip;
43 
44  BU_ALLOC(tmp_internal, struct rt_db_internal);
45  RT_DB_INTERNAL_INIT(tmp_internal);
46 
47  eip = (struct rt_extrude_internal *)ip->idb_ptr;
48  RT_EXTRUDE_CK_MAGIC(eip);
49 
50  // Create a sketch whose shape is according to eip->skt,
51  // and position is according to eip->V, eip->u_vec and eip->v_vec.
52  // Then convert the sketch to BREP.
53  struct rt_sketch_internal sketch;
54  sketch = *(eip->skt);
55  VMOVE(sketch.V, eip->V);
56  VMOVE(sketch.u_vec, eip->u_vec);
57  VMOVE(sketch.v_vec, eip->v_vec);
58  tmp_internal->idb_ptr = (void *)(&sketch);
59  rt_sketch_brep(b, tmp_internal, tol);
60 
61  // Create the extrude path and make the extrude primitive.
62  vect_t endpoint;
63  VADD2(endpoint, eip->V, eip->h);
64  const ON_Curve* extrudepath = new ON_LineCurve(ON_3dPoint(eip->V), ON_3dPoint(endpoint));
65  ON_Brep& brep = *(*b);
66  ON_BrepExtrudeFace(brep, 0, *extrudepath, true);
67  bu_free(tmp_internal, "free temporary rt_db_internal");
68  delete extrudepath;
69 }
70 
71 
72 // Local Variables:
73 // tab-width: 8
74 // mode: C++
75 // c-basic-offset: 4
76 // indent-tabs-mode: t
77 // c-file-style: "stroustrup"
78 // End:
79 // ex: shiftwidth=4 tabstop=8
void rt_extrude_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *tol)
Header file for the BRL-CAD common definitions.
void rt_sketch_brep(ON_Brep **bi, struct rt_db_internal *ip, const struct bn_tol *tol)
#define BU_ALLOC(_ptr, _type)
Definition: malloc.h:223
#define RT_DB_INTERNAL_INIT(_p)
Definition: raytrace.h:199
Support for uniform tolerances.
Definition: tol.h:71
void * idb_ptr
Definition: raytrace.h:195
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328