BRL-CAD
epa_brep.cpp
Go to the documentation of this file.
1 /* E P A _ 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 epa_brep.cpp
21  *
22  * Convert an Elliptical Paraboloid 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_epa_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *)
35 {
36  struct rt_epa_internal *eip;
37 
39  eip = (struct rt_epa_internal *)ip->idb_ptr;
40  RT_EPA_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 of the EPA.
47 
48  vect_t x_dir, y_dir;
49 
50  VMOVE(x_dir, eip->epa_Au);
51  VCROSS(y_dir, eip->epa_Au, eip->epa_H);
52  VUNITIZE(y_dir);
53 
54  VMOVE(p1_origin, eip->epa_V);
55  plane1_origin = ON_3dPoint(p1_origin);
56  plane_x_dir = ON_3dVector(x_dir);
57  plane_y_dir = ON_3dVector(y_dir);
58  const ON_Plane epa_bottom_plane = ON_Plane(plane1_origin, plane_x_dir, plane_y_dir);
59 
60  // Next, create an ellipse in the plane corresponding to the edge of the epa.
61 
62  ON_Ellipse ellipse1 = ON_Ellipse(epa_bottom_plane, eip->epa_r1, eip->epa_r2);
63  ON_NurbsCurve ellcurve1;
64  ellipse1.GetNurbForm(ellcurve1);
65  ellcurve1.SetDomain(0.0, 1.0);
66 
67  // Generate the bottom cap
68  ON_SimpleArray<ON_Curve*> boundary;
69  boundary.Append(ON_Curve::Cast(&ellcurve1));
70  ON_PlaneSurface* bp = new ON_PlaneSurface();
71  bp->m_plane = epa_bottom_plane;
72  bp->SetDomain(0, -100.0, 100.0);
73  bp->SetDomain(1, -100.0, 100.0);
74  bp->SetExtents(0, bp->Domain(0));
75  bp->SetExtents(1, bp->Domain(1));
76  (*b)->m_S.Append(bp);
77  const int bsi = (*b)->m_S.Count() - 1;
78  ON_BrepFace& bface = (*b)->NewFace(bsi);
79  (*b)->NewPlanarFaceLoop(bface.m_face_index, ON_BrepLoop::outer, boundary, true);
80  const ON_BrepLoop* bloop = (*b)->m_L.Last();
81  bp->SetDomain(0, bloop->m_pbox.m_min.x, bloop->m_pbox.m_max.x);
82  bp->SetDomain(1, bloop->m_pbox.m_min.y, bloop->m_pbox.m_max.y);
83  bp->SetExtents(0, bp->Domain(0));
84  bp->SetExtents(1, bp->Domain(1));
85  (*b)->SetTrimIsoFlags(bface);
86 
87  // Now, the hard part. Need an elliptical parabolic NURBS surface
88 
89  ON_NurbsSurface* epacurvedsurf = ON_NurbsSurface::New(3, true, 3, 3, 9, 3);
90  epacurvedsurf->SetKnot(0, 0, 0);
91  epacurvedsurf->SetKnot(0, 1, 0);
92  epacurvedsurf->SetKnot(0, 2, 1.571);
93  epacurvedsurf->SetKnot(0, 3, 1.571);
94  epacurvedsurf->SetKnot(0, 4, 3.142);
95  epacurvedsurf->SetKnot(0, 5, 3.142);
96  epacurvedsurf->SetKnot(0, 6, 4.713);
97  epacurvedsurf->SetKnot(0, 7, 4.713);
98  epacurvedsurf->SetKnot(0, 8, 6.284);
99  epacurvedsurf->SetKnot(0, 9, 6.284);
100  epacurvedsurf->SetKnot(1, 0, 0);
101  epacurvedsurf->SetKnot(1, 1, 0);
102  epacurvedsurf->SetKnot(1, 2, eip->epa_r1*2);
103  epacurvedsurf->SetKnot(1, 3, eip->epa_r1*2);
104 
105  double h = MAGNITUDE(eip->epa_H);
106  double r1 = eip->epa_r1;
107  double r2 = eip->epa_r2;
108 
109  ON_4dPoint pt01 = ON_4dPoint(0, 0, h, 1);
110  epacurvedsurf->SetCV(0, 0, pt01);
111  ON_4dPoint pt02 = ON_4dPoint(0, r2/2, h, 1);
112  epacurvedsurf->SetCV(0, 1, pt02);
113  ON_4dPoint pt03 = ON_4dPoint(0, r2, 0, 1);
114  epacurvedsurf->SetCV(0, 2, pt03);
115 
116  ON_4dPoint pt04 = ON_4dPoint(0, 0, h/sqrt(2.), 1/sqrt(2.));
117  epacurvedsurf->SetCV(1, 0, pt04);
118  ON_4dPoint pt05 = ON_4dPoint(r1/2/sqrt(2.), r2/2/sqrt(2.), h/sqrt(2.), 1/sqrt(2.));
119  epacurvedsurf->SetCV(1, 1, pt05);
120  ON_4dPoint pt06 = ON_4dPoint(r1/sqrt(2.), r2/sqrt(2.), 0, 1/sqrt(2.));
121  epacurvedsurf->SetCV(1, 2, pt06);
122 
123  ON_4dPoint pt07 = ON_4dPoint(0, 0, h, 1);
124  epacurvedsurf->SetCV(2, 0, pt07);
125  ON_4dPoint pt08 = ON_4dPoint(r1/2, 0, h, 1);
126  epacurvedsurf->SetCV(2, 1, pt08);
127  ON_4dPoint pt09 = ON_4dPoint(r1, 0, 0, 1);
128  epacurvedsurf->SetCV(2, 2, pt09);
129 
130  ON_4dPoint pt10 = ON_4dPoint(0, 0, h/sqrt(2.), 1/sqrt(2.));
131  epacurvedsurf->SetCV(3, 0, pt10);
132  ON_4dPoint pt11 = ON_4dPoint(r1/2/sqrt(2.), -r2/2/sqrt(2.), h/sqrt(2.), 1/sqrt(2.));
133  epacurvedsurf->SetCV(3, 1, pt11);
134  ON_4dPoint pt12 = ON_4dPoint(r1/sqrt(2.), -r2/sqrt(2.), 0, 1/sqrt(2.));
135  epacurvedsurf->SetCV(3, 2, pt12);
136 
137  ON_4dPoint pt13 = ON_4dPoint(0, 0, h, 1);
138  epacurvedsurf->SetCV(4, 0, pt13);
139  ON_4dPoint pt14 = ON_4dPoint(0, -r2/2, h, 1);
140  epacurvedsurf->SetCV(4, 1, pt14);
141  ON_4dPoint pt15 = ON_4dPoint(0, -r2, 0, 1);
142  epacurvedsurf->SetCV(4, 2, pt15);
143 
144  ON_4dPoint pt16 = ON_4dPoint(0, 0, h/sqrt(2.), 1/sqrt(2.));
145  epacurvedsurf->SetCV(5, 0, pt16);
146  ON_4dPoint pt17 = ON_4dPoint(-r1/2/sqrt(2.), -r2/2/sqrt(2.), h/sqrt(2.), 1/sqrt(2.));
147  epacurvedsurf->SetCV(5, 1, pt17);
148  ON_4dPoint pt18 = ON_4dPoint(-r1/sqrt(2.), -r2/sqrt(2.), 0, 1/sqrt(2.));
149  epacurvedsurf->SetCV(5, 2, pt18);
150 
151  ON_4dPoint pt19 = ON_4dPoint(0, 0, h, 1);
152  epacurvedsurf->SetCV(6, 0, pt19);
153  ON_4dPoint pt20 = ON_4dPoint(-r1/2, 0, h, 1);
154  epacurvedsurf->SetCV(6, 1, pt20);
155  ON_4dPoint pt21 = ON_4dPoint(-r1, 0, 0, 1);
156  epacurvedsurf->SetCV(6, 2, pt21);
157 
158  ON_4dPoint pt22 = ON_4dPoint(0, 0, h/sqrt(2.), 1/sqrt(2.));
159  epacurvedsurf->SetCV(7, 0, pt22);
160  ON_4dPoint pt23 = ON_4dPoint(-r1/2/sqrt(2.), r2/2/sqrt(2.), h/sqrt(2.), 1/sqrt(2.));
161  epacurvedsurf->SetCV(7, 1, pt23);
162  ON_4dPoint pt24 = ON_4dPoint(-r1/sqrt(2.), r2/sqrt(2.), 0, 1/sqrt(2.));
163  epacurvedsurf->SetCV(7, 2, pt24);
164 
165  ON_4dPoint pt25 = ON_4dPoint(0, 0, h, 1);
166  epacurvedsurf->SetCV(8, 0, pt25);
167  ON_4dPoint pt26 = ON_4dPoint(0, r2/2, h, 1);
168  epacurvedsurf->SetCV(8, 1, pt26);
169  ON_4dPoint pt27 = ON_4dPoint(0, r2, 0, 1);
170  epacurvedsurf->SetCV(8, 2, pt27);
171 
172  (*b)->m_S.Append(epacurvedsurf);
173  int surfindex = (*b)->m_S.Count();
174  (*b)->NewFace(surfindex - 1);
175  int faceindex = (*b)->m_F.Count();
176  (*b)->NewOuterLoop(faceindex-1);
177 }
178 
179 
180 // Local Variables:
181 // tab-width: 8
182 // mode: C++
183 // c-basic-offset: 4
184 // indent-tabs-mode: t
185 // c-file-style: "stroustrup"
186 // End:
187 // 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
Support for uniform tolerances.
Definition: tol.h:71
void rt_epa_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *)
Definition: epa_brep.cpp:34
void * idb_ptr
Definition: raytrace.h:195