BRL-CAD
rpc_brep.cpp
Go to the documentation of this file.
1 /* R P C _ 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 rpc_brep.cpp
21  *
22  * Convert a Right Parabolic Cylinder to b-rep form
23  *
24  */
25 
26 #include "common.h"
27 
28 #include "raytrace.h"
29 #include "rtgeom.h"
30 #include "brep.h"
31 
32 
33 extern "C" void
34 rt_rpc_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *UNUSED(tol))
35 {
36  struct rt_rpc_internal *eip;
37 
39  eip = (struct rt_rpc_internal *)ip->idb_ptr;
40  RT_RPC_CK_MAGIC(eip);
41 
42  point_t p1_origin;
43  ON_3dPoint plane1_origin, plane2_origin;
44  ON_3dVector plane_x_dir, plane_y_dir;
45 
46  // First, find plane in 3 space corresponding to the bottom face
47  // of the RPC.
48 
49  vect_t x_dir, y_dir;
50 
51  VCROSS(x_dir, eip->rpc_H, eip->rpc_B);
52  VUNITIZE(x_dir);
53  VSCALE(x_dir, x_dir, eip->rpc_r);
54  VMOVE(y_dir, eip->rpc_B);
55 
56  VMOVE(p1_origin, eip->rpc_V);
57  plane1_origin = ON_3dPoint(p1_origin);
58  plane_x_dir = ON_3dVector(x_dir);
59  plane_y_dir = ON_3dVector(y_dir);
60  const ON_Plane rpc_bottom_plane = ON_Plane(plane1_origin, plane_x_dir, plane_y_dir);
61 
62  // Next, create a parabolic NURBS curve corresponding to the shape
63  // of the parabola in the two planes.
64  point_t x_rev_dir, ep1, ep2, ep3, tmppt;
65  VREVERSE(x_rev_dir, x_dir);
66 
67  VADD2(ep1, p1_origin, x_rev_dir);
68  VSCALE(tmppt, eip->rpc_B, 2);
69  VADD2(ep2, p1_origin, tmppt);
70  VADD2(ep3, p1_origin, x_dir);
71  ON_3dPoint onp1 = ON_3dPoint(ep1);
72  ON_3dPoint onp3 = ON_3dPoint(ep3);
73 
74 
75  ON_NurbsCurve* parabnurbscurve = ON_NurbsCurve::New(3, false, 3, 3);
76  parabnurbscurve->SetKnot(0, 0);
77  parabnurbscurve->SetKnot(1, 0);
78  parabnurbscurve->SetKnot(2, 1);
79  parabnurbscurve->SetKnot(3, 1);
80  parabnurbscurve->SetCV(0, ON_3dPoint(ep1));
81  parabnurbscurve->SetCV(1, ON_3dPoint(ep2));
82  parabnurbscurve->SetCV(2, ON_3dPoint(ep3));
83 
84  // Also need a straight line from the beginning to the end to
85  // complete the loop.
86 
87  ON_LineCurve* straightedge = new ON_LineCurve(onp3, onp1);
88 
89  // Generate the bottom cap
90  ON_SimpleArray<ON_Curve*> boundary;
91  boundary.Append(ON_Curve::Cast(parabnurbscurve));
92  boundary.Append(ON_Curve::Cast(straightedge));
93 
94  ON_PlaneSurface* bp = new ON_PlaneSurface();
95  bp->m_plane = rpc_bottom_plane;
96  bp->SetDomain(0, -100.0, 100.0);
97  bp->SetDomain(1, -100.0, 100.0);
98  bp->SetExtents(0, bp->Domain(0));
99  bp->SetExtents(1, bp->Domain(1));
100  (*b)->m_S.Append(bp);
101  const int bsi = (*b)->m_S.Count() - 1;
102  ON_BrepFace& bface = (*b)->NewFace(bsi);
103  (*b)->NewPlanarFaceLoop(bface.m_face_index, ON_BrepLoop::outer, boundary, true);
104  const ON_BrepLoop* bloop = (*b)->m_L.Last();
105  bp->SetDomain(0, bloop->m_pbox.m_min.x, bloop->m_pbox.m_max.x);
106  bp->SetDomain(1, bloop->m_pbox.m_min.y, bloop->m_pbox.m_max.y);
107  bp->SetExtents(0, bp->Domain(0));
108  bp->SetExtents(1, bp->Domain(1));
109  (*b)->SetTrimIsoFlags(bface);
110 
111  // Now the side face and top cap - extrude the bottom face and set
112  // the cap flag to true.
113  vect_t vp2;
114  VADD2(vp2, eip->rpc_V, eip->rpc_H);
115  const ON_Curve* extrudepath = new ON_LineCurve(ON_3dPoint(eip->rpc_V), ON_3dPoint(vp2));
116  ON_Brep& brep = *(*b);
117  ON_BrepExtrudeFace(brep, 0, *extrudepath, true);
118  delete extrudepath;
119 
120 }
121 
122 
123 // Local Variables:
124 // tab-width: 8
125 // mode: C++
126 // c-basic-offset: 4
127 // indent-tabs-mode: t
128 // c-file-style: "stroustrup"
129 // End:
130 // ex: shiftwidth=4 tabstop=8
Header file for the BRL-CAD common definitions.
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
unsigned char * bp
Definition: rot.c:56
#define UNUSED(parameter)
Definition: common.h:239
Support for uniform tolerances.
Definition: tol.h:71
void * idb_ptr
Definition: raytrace.h:195
void rt_rpc_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *tol)
Definition: rpc_brep.cpp:34