Revision: 54579
http://brlcad.svn.sourceforge.net/brlcad/?rev=54579&view=rev
Author: n_reed
Date: 2013-03-08 19:32:06 +0000 (Fri, 08 Mar 2013)
Log Message:
-----------
pull view calculations into separate functions
Modified Paths:
--------------
brlcad/trunk/src/libged/draw.c
Modified: brlcad/trunk/src/libged/draw.c
===================================================================
--- brlcad/trunk/src/libged/draw.c 2013-03-08 19:25:12 UTC (rev 54578)
+++ brlcad/trunk/src/libged/draw.c 2013-03-08 19:32:06 UTC (rev 54579)
@@ -545,6 +545,96 @@
return curtree;
}
+static fastf_t
+view_avg_size(struct ged_view *gvp)
+{
+ fastf_t view_aspect, x_size, y_size;
+
+ view_aspect = (fastf_t)gvp->gv_x_samples / gvp->gv_y_samples;
+ x_size = gvp->gv_size;
+ y_size = x_size / view_aspect;
+
+ return (x_size + y_size) / 2.0;
+}
+
+static fastf_t
+view_avg_sample_spacing(struct ged_view *gvp)
+{
+ fastf_t avg_view_size, avg_view_samples;
+
+ avg_view_size = view_avg_size(gvp);
+ avg_view_samples = (gvp->gv_x_samples + gvp->gv_y_samples) / 2.0;
+
+ return avg_view_size / avg_view_samples;
+}
+
+static fastf_t
+solid_point_spacing(struct ged_view *gvp, struct solid *sp)
+{
+ fastf_t radius, avg_view_size, avg_sample_spacing;
+ point_t p1, p2;
+
+ avg_view_size = view_avg_size(gvp);
+ avg_sample_spacing = view_avg_sample_spacing(gvp);
+
+ /* Now, for the sake of simplicity we're going to make
+ * several assumptions:
+ * - our samples represent a grid of square pixels
+ * - we're plotting an implicit solid
+ * - the solid's bounding box is a cube
+ * - a circle with a diameter half the width of the
+ * bounding box is a good proxy for the kind of curves
+ * that will be plotted
+ * - sp->s_size is the bbox diagonal and only a slight
+ * overestimate of the width of the bounding box
+ */
+ radius = sp->s_size / 4.0;
+ if (avg_view_size < sp->s_size) {
+ /* If the solid is larger than the view, it is
+ * probably only partly visible and likely isn't the
+ * primary focus of the user. We'll cap the point
+ * spacing and avoid wasting effort.
+ */
+ radius = avg_view_size / 4.0;
+ }
+
+ /* We imagine our representative circular curve lying in
+ * the XY plane centered at the origin.
+ *
+ * Suppose we're viewing the circle head on, and that the
+ * apex of the curve (0, radius) lies just inside the
+ * top edge of a pixel. Here we place a plotted point p1.
+ *
+ * As we continue clockwise around the circle we pass
+ * through neighboring pixels in the same row, until we
+ * vertically drop a distance equal to the pixel spacing,
+ * in which case we just barely enter a pixel in the next
+ * row. Here we place a plotted point p2 (y = radius -
+ * avg_sample_spacing).
+ *
+ * In theory the line segment between p1 and p2 passes
+ * through all the same pixels that the actual curve does,
+ * and thus produces the exact same rasterization as if
+ * the curve between p1 and p2 was approximated with an
+ * infinite number of line segments.
+ *
+ * We assume that the distance between p1 and p2 is the
+ * maximum point sampling distance we can use for the
+ * curve which will give a perfect rasterization, i.e.
+ * the same rasterization as if we chose a point distance
+ * of 0.
+ */
+ p1[Z] = p2[Z] = 0.0;
+
+ p1[X] = 0.0;
+ p1[Y] = radius;
+
+ p2[Y] = radius - (avg_sample_spacing);
+ p2[X] = sqrt(radius * radius - p2[Y] * p2[Y]);
+
+ return DIST_PT_PT(p1, p2);
+}
+
/**
* G E D _ W I R E F R A M E _ L E A F
*
@@ -597,85 +687,15 @@
gvp = dgcdp->gedp->ged_gvp;
if (gvp && gvp->gv_adaptive_plot && ip->idb_meth->ft_adaptive_plot) {
struct rt_view_info info;
- fastf_t view_aspect, x_size, y_size;
- fastf_t avg_view_size, avg_view_samples, avg_sample_spacing;
info.vhead = &vhead;
info.tol = tsp->ts_tol;
- view_aspect = (fastf_t)gvp->gv_x_samples / gvp->gv_y_samples;
- x_size = gvp->gv_size;
- y_size = x_size / view_aspect;
-
- avg_view_size = (x_size + y_size) / 2.0;
- avg_view_samples = (gvp->gv_x_samples + gvp->gv_y_samples) / 2.0;
- avg_sample_spacing = avg_view_size / avg_view_samples;
-
if (ip->idb_minor_type == ID_BOT) {
- /* for bots, use sample spacing as point spacing */
- info.point_spacing = avg_sample_spacing;
+ info.point_spacing = view_avg_sample_spacing(gvp);
} else {
- fastf_t radius;
- point_t p1, p2;
-
- /* Now, for the sake of simplicity we're going to make
- * several assumptions:
- * - our samples represent a grid of square pixels
- * - we're plotting an implicit solid
- * - the solid's bounding box is a cube
- * - a circle with a diameter half the width of the
- * bounding box is a good proxy for the kind of curves
- * that will be plotted
- * - sp->s_size is the bbox diagonal and only a slight
- * overestimate of the width of the bounding box
- */
- radius = sp->s_size / 4.0;
- if (avg_view_size < sp->s_size) {
- /* If the solid is larger than the view, it is
- * probably only partly visible and likely isn't the
- * primary focus of the user. We'll cap the point
- * spacing and avoid wasting effort.
- */
- radius = avg_view_size / 4.0;
- }
-
- /* We imagine our representative circular curve lying in
- * the XY plane centered at the origin.
- *
- * Suppose we're viewing the circle head on, and that the
- * apex of the curve (0, radius) lies just inside the
- * top edge of a pixel. Here we place a plotted point p1.
- *
- * As we continue clockwise around the circle we pass
- * through neighboring pixels in the same row, until we
- * vertically drop a distance equal to the pixel spacing,
- * in which case we just barely enter a pixel in the next
- * row. Here we place a plotted point p2 (y = radius -
- * avg_sample_spacing).
- *
- * In theory the line segment between p1 and p2 passes
- * through all the same pixels that the actual curve does,
- * and thus produces the exact same rasterization as if
- * the curve between p1 and p2 was approximated with an
- * infinite number of line segments.
- *
- * We assume that the distance between p1 and p2 is the
- * maximum point sampling distance we can use for the
- * curve which will give a perfect rasterization, i.e.
- * the same rasterization as if we chose a point distance
- * of 0.
- */
- p1[Z] = p2[Z] = 0.0;
-
- p1[X] = 0.0;
- p1[Y] = radius;
-
- p2[Y] = radius - (avg_sample_spacing);
- p2[X] = sqrt(radius * radius - p2[Y] * p2[Y]);
-
- info.point_spacing = DIST_PT_PT(p1, p2);
+ info.point_spacing = solid_point_spacing(gvp, sp);
}
-
info.curve_spacing = sp->s_size / 2.0;
plot_status = ip->idb_meth->ft_adaptive_plot(ip, &info);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits