BRL-CAD
draw_calc.cpp
Go to the documentation of this file.
1 /* D R A W _ C A L C . C P P
2  * BRL-CAD
3  *
4  * Copyright (c) 2013-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 draw_calc.cpp
21  *
22  * Utility functions for miscellaneous draw calculations.
23  *
24  */
25 
26 #include "common.h"
27 #include "brep.h"
28 #include "raytrace.h"
29 #include "rtgeom.h"
30 
32 
33 static fastf_t
34 brep_avg_curve_bbox_diagonal_len(ON_Brep *brep)
35 {
36  fastf_t avg_curve_len = 0.0;
37  int i, num_curves = 0;
38 
39  for (i = 0; i < brep->m_E.Count(); ++i) {
40  ON_BrepEdge &e = brep->m_E[i];
41  const ON_Curve *crv = e.EdgeCurveOf();
42 
43  if (!crv->IsLinear()) {
44  ++num_curves;
45 
46  ON_BoundingBox bbox;
47  if (crv->GetTightBoundingBox(bbox)) {
48  avg_curve_len += bbox.Diagonal().Length();
49  } else {
50  ON_3dVector linear_approx =
51  crv->PointAtEnd() - crv->PointAtStart();
52  avg_curve_len += linear_approx.Length();
53  }
54  }
55  }
56  avg_curve_len /= num_curves;
57 
58  return avg_curve_len;
59 }
60 
61 fastf_t
62 brep_est_avg_curve_len(struct rt_brep_internal *bi)
63 {
64  return brep_avg_curve_bbox_diagonal_len(bi->brep) * 2.0;
65 }
66 
68 
69 // Local Variables:
70 // tab-width: 8
71 // mode: C++
72 // c-basic-offset: 4
73 // indent-tabs-mode: t
74 // c-file-style: "stroustrup"
75 // End:
76 // ex: shiftwidth=4 tabstop=8
Header file for the BRL-CAD common definitions.
#define __BEGIN_DECLS
Definition: common.h:73
#define __END_DECLS
Definition: common.h:74
double fastf_t
Definition: defines.h:300
fastf_t brep_est_avg_curve_len(struct rt_brep_internal *bi)
Definition: draw_calc.cpp:62