BRL-CAD
eto_brep.cpp
Go to the documentation of this file.
1 /* E L L _ 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 ell_brep.cpp
21  *
22  * Convert a Generalized Ellipsoid 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_eto_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *)
35 {
36  struct rt_eto_internal *eip;
37 
39  eip = (struct rt_eto_internal *)ip->idb_ptr;
40  RT_ETO_CK_MAGIC(eip);
41 
42  point_t p_origin;
43  vect_t v1, v1a, x_dir, y_dir;
44  ON_3dPoint plane_origin;
45  ON_3dVector plane_x_dir, plane_y_dir;
46 
47  double ell_axis_len_1, ell_axis_len_2;
48 
49  // First, find a plane in 3 space with x and y axes
50  // along an axis of the ellipse to be rotated, and its
51  // coordinate origin at the center of the ellipse.
52  //
53  // To identify a point on the eto suitable for use (there
54  // are of course infinitely many such points described by
55  // a circle at radius eto_r from the eto vertex) obtain
56  // a vector at a right angle to the eto normal, unitize it
57  // and scale it.
58 
59  VCROSS(v1, eip->eto_C, eip->eto_N);
60  if (NEAR_ZERO(MAGNITUDE(v1), VUNITIZE_TOL)) {
61  vect_t dir_vect;
62  VSET(dir_vect, 0, 1, 0);
63  VCROSS(v1, dir_vect, eip->eto_N);
64  if (NEAR_ZERO(MAGNITUDE(v1), VUNITIZE_TOL)) {
65  VSET(dir_vect, 1, 0, 0);
66  VCROSS(v1, dir_vect, eip->eto_N);
67  }
68  }
69  point_t temp;
70  VMOVE(temp, v1);
71  VCROSS(v1a, v1, eip->eto_N);
72  VSET(v1, -v1a[0], -v1a[1], -v1a[2]);
73  VUNITIZE( v1 );
74  VSCALE(v1, v1, eip->eto_r);
75  VADD2(v1, v1, eip->eto_V);
76  VMOVE(x_dir, eip->eto_C);
77  VCROSS(y_dir, x_dir, temp);
78  VSET(p_origin, v1[0], v1[1], v1[2]);
79  plane_origin = ON_3dPoint(p_origin);
80  plane_x_dir = ON_3dVector(x_dir);
81  plane_y_dir = ON_3dVector(y_dir);
82 
83  const ON_Plane ell_plane(plane_origin, plane_x_dir, plane_y_dir);
84 
85 
86  // Once the plane has been created, create the ellipse
87  // within the plane.
88  ell_axis_len_1 = MAGNITUDE(eip->eto_C);
89  ell_axis_len_2 = eip->eto_rd;
90  ON_Ellipse ellipse(ell_plane, ell_axis_len_1, ell_axis_len_2);
91 
92 
93  // Generate an ON_Curve from the ellipse and revolve it
94  // around eto_N
95 
96  ON_NurbsCurve ellcurve;
97  ellipse.GetNurbForm(ellcurve);
98  point_t eto_endvertex;
99  VADD2(eto_endvertex, eip->eto_V, eip->eto_N);
100  ON_3dPoint eto_vertex_pt = ON_3dPoint(eip->eto_V);
101  ON_3dPoint eto_endvertex_pt = ON_3dPoint(eto_endvertex);
102  ON_Line revaxis = ON_Line(eto_vertex_pt, eto_endvertex_pt);
103  ON_RevSurface* eto_surf = ON_RevSurface::New();
104  eto_surf->m_curve = &ellcurve;
105  eto_surf->m_axis = revaxis;
106 
107  /* Create brep with one face*/
108  ON_BrepFace *newface = (*b)->NewFace(*eto_surf);
109  (*b)->FlipFace(*newface);
110 // (*b)->Standardize();
111  // (*b)->Compact();
112 }
113 
114 
115 // Local Variables:
116 // tab-width: 8
117 // mode: C++
118 // c-basic-offset: 4
119 // indent-tabs-mode: t
120 // c-file-style: "stroustrup"
121 // End:
122 // ex: shiftwidth=4 tabstop=8
void rt_eto_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *)
Definition: eto_brep.cpp:34
#define VSET(a, b, c, d)
Definition: color.c:53
Header file for the BRL-CAD common definitions.
Definition: tgc.c:1821
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
#define NEAR_ZERO(val, epsilon)
Definition: color.c:55
Support for uniform tolerances.
Definition: tol.h:71
void * idb_ptr
Definition: raytrace.h:195