Revision: 51614
          http://brlcad.svn.sourceforge.net/brlcad/?rev=51614&view=rev
Author:   crdueck
Date:     2012-07-20 01:46:32 +0000 (Fri, 20 Jul 2012)
Log Message:
-----------
seperate poly_area and carc_area calculations in rt_sketch_surf_area

Modified Paths:
--------------
    brlcad/trunk/src/librt/primitives/sketch/sketch_tess.cpp

Modified: brlcad/trunk/src/librt/primitives/sketch/sketch_tess.cpp
===================================================================
--- brlcad/trunk/src/librt/primitives/sketch/sketch_tess.cpp    2012-07-20 
01:45:34 UTC (rev 51613)
+++ brlcad/trunk/src/librt/primitives/sketch/sketch_tess.cpp    2012-07-20 
01:46:32 UTC (rev 51614)
@@ -21,9 +21,8 @@
 /** @{ */
 /** @file primitives/sketch/sketch_tess.c
  *
- * Provide support for tesselation of sketch primitive
- * including approximation of bezier/NURBS curves by
- * circular arcs
+ * An extension of sketch.c for functions using the openNURBS library. Includes
+ * support for approximation of Bezier curves using circular arcs.
  *
  */
 /** @} */
@@ -134,7 +133,7 @@
 HIDDEN void
 approx_bezier(const ON_BezierCurve& bezier, const ON_Arc& biarc, const struct 
bn_tol *tol, std::vector<ON_Arc>& approx)
 {
-    fastf_t t, step = 0.1;
+    fastf_t t, step;
     fastf_t crv, err, max_t, max_err = 0.0;
     ON_BezierCurve head, tail;
     ON_3dPoint test;
@@ -242,16 +241,6 @@
 
 #define SKETCHPT(idx) sketch_ip->verts[(idx)]
 
-HIDDEN inline fastf_t
-carc_area(const struct carc_seg *csg, const struct rt_sketch_internal 
*sketch_ip)
-{
-    fastf_t theta, side_ratio;
-    side_ratio = DIST_PT_PT(SKETCHPT(csg->start), SKETCHPT(csg->end)) / (2.0 * 
csg->radius);
-    theta = asin(side_ratio);
-    return 0.5 * csg->radius * csg->radius * (theta - side_ratio);
-}
-
-
 /**
  * R T _ S K E T C H _ S U R F _ A R E A
  *
@@ -273,21 +262,22 @@
 {
     int j;
     size_t i;
+    fastf_t poly_area = 0, carc_area = 0;
 
+    struct bn_tol tol;
     struct rt_sketch_internal *sketch_ip = (struct rt_sketch_internal 
*)ip->idb_ptr;
     RT_SKETCH_CK_MAGIC(sketch_ip);
     struct rt_curve crv = sketch_ip->curve;
 
-    struct bn_tol tol;
-    tol.magic = BN_TOL_MAGIC;
-    tol.dist = RT_DOT_TOL;
-    tol.dist_sq = RT_DOT_TOL * RT_DOT_TOL;
-
     // a sketch with no curves has no area
     if (UNLIKELY(crv.count == 0)) {
         return;
     }
 
+    tol.magic = BN_TOL_MAGIC;
+    tol.dist = RT_DOT_TOL;
+    tol.dist_sq = RT_DOT_TOL * RT_DOT_TOL;
+
     // iterate through each curve segment in the sketch
     for (i = 0; i < crv.count; i++) {
         const struct line_seg *lsg;
@@ -300,18 +290,21 @@
         case CURVE_LSEG_MAGIC:
             lsg = (struct line_seg *)lng;
             // calculate area for polygon edge
-            *area += 0.5 * V2CROSS(SKETCHPT(lsg->start), SKETCHPT(lsg->end));
+            poly_area += V2CROSS(SKETCHPT(lsg->start), SKETCHPT(lsg->end));
             break;
         case CURVE_CARC_MAGIC:
             csg = (struct carc_seg *)lng;
             if (csg->radius < 0) {
                 // calculate full circle area
-                *area += M_PI * DIST_PT_PT_SQ(SKETCHPT(csg->start), 
SKETCHPT(csg->end));
+                carc_area += M_PI * DIST_PT_PT_SQ(SKETCHPT(csg->start), 
SKETCHPT(csg->end));
             } else {
+                fastf_t theta, side_ratio;
                 // calculate area for polygon edge
-                *area += 0.5 * V2CROSS(SKETCHPT(csg->start), 
SKETCHPT(csg->end));
+                poly_area += V2CROSS(SKETCHPT(csg->start), SKETCHPT(csg->end));
                 // calculate area for circular segment
-                *area += carc_area(csg, sketch_ip);
+                side_ratio = DIST_PT_PT(SKETCHPT(csg->start), 
SKETCHPT(csg->end)) / (2.0 * csg->radius);
+                theta = asin(side_ratio);
+                carc_area += 0.5 * csg->radius * csg->radius * (theta - 
side_ratio);
             }
             break;
         case CURVE_BEZIER_MAGIC: {
@@ -326,9 +319,9 @@
             bezier_to_carcs(ON_BezierCurve(bez_pts), &tol, carcs);
             for (std::vector<ON_Arc>::iterator it = carcs.begin(); it != 
carcs.end(); ++it) {
                 // calculate area for each polygon edge
-                *area += 0.5 * V2CROSS(it->StartPoint(), it->EndPoint());
+                poly_area += V2CROSS(it->StartPoint(), it->EndPoint());
                 // calculate area for each circular segment
-                *area += 0.5 * it->Radius() * it->Radius() * 
(it->AngleRadians() - sin(it->AngleRadians()));
+                carc_area += 0.5 * it->Radius() * it->Radius() * 
(it->AngleRadians() - sin(it->AngleRadians()));
             }
             }
             break;
@@ -337,7 +330,7 @@
             break;
         }
     }
-    *area = fabs(*area);
+    *area = 0.5 * fabs(poly_area) + carc_area;
 }
 
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to