Revision: 54558
          http://brlcad.svn.sourceforge.net/brlcad/?rev=54558&view=rev
Author:   n_reed
Date:     2013-03-07 18:35:23 +0000 (Thu, 07 Mar 2013)
Log Message:
-----------
handle recs specially to reduce calls to cos/sin

Modified Paths:
--------------
    brlcad/trunk/src/librt/primitives/tgc/tgc.c

Modified: brlcad/trunk/src/librt/primitives/tgc/tgc.c
===================================================================
--- brlcad/trunk/src/librt/primitives/tgc/tgc.c 2013-03-07 18:31:42 UTC (rev 
54557)
+++ brlcad/trunk/src/librt/primitives/tgc/tgc.c 2013-03-07 18:35:23 UTC (rev 
54558)
@@ -1814,8 +1814,13 @@
     vect_t axis_b;
 };
 
+
 static void
-draw_lines_between_ellipses(struct bu_list *vhead, struct ellipse ellipse1, 
struct ellipse ellipse2, int num_lines)
+draw_lines_between_rec_ellipses(
+       struct bu_list *vhead,
+       struct ellipse ellipse1,
+       vect_t h,
+       int num_lines)
 {
     int i;
     point_t ellipse1_point, ellipse2_point;
@@ -1824,6 +1829,27 @@
     for (i = 0; i < num_lines; ++i) {
        ellipse_point_at_radian(ellipse1_point, ellipse1.center,
                ellipse1.axis_a, ellipse1.axis_b, i * radian_step);
+       VADD2(ellipse2_point, ellipse1_point, h);
+
+       RT_ADD_VLIST(vhead, ellipse1_point, BN_VLIST_LINE_MOVE);
+       RT_ADD_VLIST(vhead, ellipse2_point, BN_VLIST_LINE_DRAW);
+    }
+}
+
+static void
+draw_lines_between_ellipses(
+       struct bu_list *vhead,
+       struct ellipse ellipse1,
+       struct ellipse ellipse2,
+       int num_lines)
+{
+    int i;
+    point_t ellipse1_point, ellipse2_point;
+    fastf_t radian_step = 2.0 * M_PI / num_lines;
+
+    for (i = 0; i < num_lines; ++i) {
+       ellipse_point_at_radian(ellipse1_point, ellipse1.center,
+               ellipse1.axis_a, ellipse1.axis_b, i * radian_step);
        ellipse_point_at_radian(ellipse2_point, ellipse2.center,
                ellipse2.axis_a, ellipse2.axis_b, i * radian_step);
 
@@ -1905,26 +1931,71 @@
        return 0;
     }
 
+    connecting_lines = tgc_connecting_lines(tip, info);
+
+    if (connecting_lines < 4) {
+       connecting_lines = 4;
+    }
+
     VMOVE(ellipse1.center, tip->v);
     VMOVE(ellipse1.axis_a, tip->a);
     VMOVE(ellipse1.axis_b, tip->b);
-    plot_ellipse(info->vhead, ellipse1.center, ellipse1.axis_a, 
ellipse1.axis_b,
-                points_per_ellipse);
 
     VADD2(ellipse2.center, tip->v, tip->h);
     VMOVE(ellipse2.axis_a, tip->c);
     VMOVE(ellipse2.axis_b, tip->d);
-    plot_ellipse(info->vhead, ellipse2.center, ellipse2.axis_a, 
ellipse2.axis_b,
-                points_per_ellipse);
 
-    connecting_lines = tgc_connecting_lines(tip, info);
+    /* looks like a right elliptical cylinder */
+    if (VNEAR_EQUAL(tip->a, tip->c, info->tol->dist) &&
+       VNEAR_EQUAL(tip->b, tip->d, info->tol->dist))
+    {
+       int i;
+       point_t *pts;
+       fastf_t radian, radian_step;
 
-    if (connecting_lines < 4) {
-       connecting_lines = 4;
+       pts = (point_t *)bu_malloc(sizeof(point_t) * points_per_ellipse,
+               "tgc points");
+
+       radian_step = bn_twopi / points_per_ellipse;
+
+       /* calculate and plot first ellipse */
+       ellipse_point_at_radian(pts[0], tip->v, tip->a, tip->b,
+               radian_step * (points_per_ellipse - 1));
+       RT_ADD_VLIST(info->vhead, pts[0], BN_VLIST_LINE_MOVE);
+
+       radian = 0;
+       for (i = 0; i < points_per_ellipse; ++i) {
+           ellipse_point_at_radian(pts[i], tip->v, tip->a, tip->b, radian);
+           RT_ADD_VLIST(info->vhead, pts[i], BN_VLIST_LINE_DRAW);
+
+           radian += radian_step;
+       }
+
+       /* calculate and plot second ellipse */
+       for (i = 0; i < points_per_ellipse; ++i) {
+           VADD2(pts[i], tip->h, pts[i]);
+       }
+
+       RT_ADD_VLIST(info->vhead, pts[points_per_ellipse - 1], 
BN_VLIST_LINE_MOVE);
+       for (i = 0; i < points_per_ellipse; ++i) {
+           RT_ADD_VLIST(info->vhead, pts[i], BN_VLIST_LINE_DRAW);
+       }
+
+       bu_free(pts, "tgc points");
+
+       draw_lines_between_rec_ellipses(info->vhead, ellipse1, tip->h,
+               connecting_lines);
+    } else {
+       plot_ellipse(info->vhead, ellipse1.center, ellipse1.axis_a, 
ellipse1.axis_b,
+                    points_per_ellipse);
+
+       plot_ellipse(info->vhead, ellipse2.center, ellipse2.axis_a, 
ellipse2.axis_b,
+                    points_per_ellipse);
+
+       draw_lines_between_ellipses(info->vhead, ellipse1, ellipse2,
+               connecting_lines);
     }
 
-    draw_lines_between_ellipses(info->vhead, ellipse1, ellipse2, 
connecting_lines);
-
     return 0;
 }
 

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

Reply via email to