[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mapguide-commits
Subject:    [mapguide-commits] r3271 - trunk/MgDev/Common/Stylization
From:       svn_mapguide () osgeo ! org
Date:       2008-08-12 21:46:55
Message-ID: 20080812214655.8C32DE01078 () lists ! osgeo ! org
[Download RAW message or body]

Author: waltweltonlair
Date: 2008-08-12 17:46:53 -0400 (Tue, 12 Aug 2008)
New Revision: 3271

Modified:
   trunk/MgDev/Common/Stylization/LineBuffer.cpp
   trunk/MgDev/Common/Stylization/LineBuffer.h
Log:
This submission adds functionality to the LineBuffer class to allow LineBuffer clients to
detect the location of tessellated arc segments in the LineBuffer vertex data.  For every
arc segment in the feature data, there will be a pair of integers which indicate the vertex
index of the start and end segments of the tesselated arc.  The following APIs have been
added to LineBuffer:

    inline int arcs_sp_length() const;
    inline int* arcs_sp_array() const;

These methods allow the client to: (1) determine the length of the array of pairs of arc
segment vertex indices and (2) get a pointer to the array.  If the length is 0, there are
no tessellated arc segments in the output array.  Vertex indices refer to vertices in the
m_pts array.


Modified: trunk/MgDev/Common/Stylization/LineBuffer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/LineBuffer.cpp	2008-08-12 20:47:15 UTC (rev 3270)
+++ trunk/MgDev/Common/Stylization/LineBuffer.cpp	2008-08-12 21:46:53 UTC (rev 3271)
@@ -51,6 +51,9 @@
     m_cntrs_len(0),
     m_cur_cntr(-1), //will increment with first MoveTo segment
     m_cur_geom(-1),
+    m_arcs_sp_len(0),
+    m_arcs_sp(NULL),
+    m_cur_arcs_sp(-1),
     m_geom_type(0),
     m_drawingScale(0.0)
 {
@@ -80,6 +83,9 @@
     m_cur_cntr(-1),
     m_cur_geom(-1),
     m_geom_type(0),
+    m_arcs_sp_len(0),
+    m_arcs_sp(NULL),
+    m_cur_arcs_sp(-1),
     m_drawingScale(0.0),
     m_dimensionality(FdoDimensionality_XY),
     m_bIgnoreZ(true),
@@ -98,6 +104,7 @@
     delete[] m_cntrs;
     delete[] m_csp;
     delete[] m_num_geomcntrs;
+    delete[] m_arcs_sp;
 }
 
 
@@ -114,6 +121,8 @@
     m_num_geomcntrs[0] = 0;
     m_drawingScale = 0.0;
 
+    m_cur_arcs_sp = -1;
+
     m_bounds.minx = m_bounds.miny = +DBL_MAX;
     m_bounds.maxx = m_bounds.maxy = -DBL_MAX;
     if (m_bProcessZ)
@@ -179,6 +188,16 @@
     m_cur_geom = src.m_cur_geom;
     memcpy(m_num_geomcntrs, src.m_num_geomcntrs, sizeof(int)*(1+m_cur_geom));
 
+    // arc start points
+    if (m_arcs_sp_len < src.m_arcs_sp_len)
+    {
+        delete[] m_arcs_sp;
+        m_arcs_sp_len = src.m_arcs_sp_len;
+        m_arcs_sp = new int[m_arcs_sp_len];
+    }
+    m_cur_arcs_sp = src.m_cur_arcs_sp;
+    memcpy(m_arcs_sp, src.m_arcs_sp, sizeof(int)*(1+m_cur_arcs_sp));
+
     return *this;
 }
 
@@ -359,6 +378,35 @@
 }
 
 
+void LineBuffer::ResizeArcsSpArray()
+{
+    // double the capacity of the arc start point array
+    if (m_arcs_sp_len == 0)
+        ResizeArcsSpArray(4);
+    else
+        ResizeArcsSpArray(2 * m_arcs_sp_len);
+}
+
+
+void LineBuffer::ResizeArcsSpArray(int n)
+{
+    if (n <= m_arcs_sp_len) // unnecessary at the very least
+        return;
+
+    // new arc start point array
+    int* tempArcsSp = new int[n];
+
+    // copy data
+    if (m_arcs_sp)
+        memcpy(tempArcsSp, m_arcs_sp, sizeof(int)*(1+m_cur_arcs_sp));
+
+    // cleanup
+    delete[] m_arcs_sp;
+    m_arcs_sp = tempArcsSp;
+    m_arcs_sp_len = n;
+}
+
+
 LineBuffer& LineBuffer::operator+=(LineBuffer& other)
 {
     // only if there is something to copy
@@ -368,6 +416,7 @@
     // make sure there is room
     EnsurePoints(other.point_count());
     EnsureContours(other.cntr_count());
+    EnsureArcsSpArray(other.arcs_sp_length());
 
     // copy contours
     memcpy(m_cntrs+m_cur_cntr+1, other.m_cntrs, sizeof(int)*(1+other.m_cur_cntr));
@@ -379,6 +428,12 @@
     // copy point data
     memcpy(m_pts + m_cur_types, other.m_pts, sizeof(double)*(other.point_count() * 3));
 
+    // copy arc start points
+    memcpy(m_arcs_sp+m_cur_arcs_sp+1, other.m_arcs_sp, sizeof(int)*(1+other.m_cur_arcs_sp));
+    for (int i = m_cur_arcs_sp + 1; i < m_cur_arcs_sp + other.m_cur_arcs_sp + 2; ++i)
+        m_arcs_sp[i] += m_cur_types;
+    m_cur_arcs_sp += other.m_cur_arcs_sp + 1;
+
     // copy segment types
     memcpy(m_types + m_cur_types, other.m_types, other.m_cur_types);
     m_cur_types += other.m_cur_types;
@@ -481,8 +536,16 @@
     // Avoid tesselation and draw two line segments
     if (normal.lengthSqrd() < 1.0e-12)
     {
+        // store off arc start point index
+        EnsureArcsSpArray(2);
+        m_arcs_sp[++m_cur_arcs_sp] = m_cur_types - 1;
+
         LineTo(x1, y1, z1);
         LineTo(x2, y2, z2);
+
+        // store off arc end point index (want index of start point of last seg)
+        m_arcs_sp[++m_cur_arcs_sp] = m_cur_types - 2;
+
         return;
     }
     normal.normalize();
@@ -547,8 +610,16 @@
 
         if (areaRatio < 1.0e-10)
         {
+            // store off arc start point index
+            EnsureArcsSpArray(2);
+            m_arcs_sp[++m_cur_arcs_sp] = m_cur_types - 1;
+
             LineTo(x1, y1);
             LineTo(x2, y2);
+
+            // store off arc end point index (want index of start point of last seg)
+            m_arcs_sp[++m_cur_arcs_sp] = m_cur_types - 2;
+
             return;
         }
     }
@@ -608,6 +679,10 @@
     if (extent == 0.0)
         return;
 
+    // store off arc start point index
+    EnsureArcsSpArray(2);
+    m_arcs_sp[++m_cur_arcs_sp] = m_cur_types - 1;
+
     double extentA = fabs(extent);
     if (extentA > PI2)
     {
@@ -657,6 +732,9 @@
 
         TesselateCubicTo(c0x, c0y, c1x, c1y, c2x, c2y, c3x, c3y);
     }
+
+    // store off arc end point index (want index of start point of last seg)
+    m_arcs_sp[++m_cur_arcs_sp] = m_cur_types - 2;
 }
 
 

Modified: trunk/MgDev/Common/Stylization/LineBuffer.h
===================================================================
--- trunk/MgDev/Common/Stylization/LineBuffer.h	2008-08-12 20:47:15 UTC (rev 3270)
+++ trunk/MgDev/Common/Stylization/LineBuffer.h	2008-08-12 21:46:53 UTC (rev 3271)
@@ -60,6 +60,11 @@
 // Point Data:     {0,0,0},{1,1,0},{2,2,0},{3,3,0},{4,4,0},{5,5,0}
 // Contour Data:   {2, 2, 1}
 // Geometry Data:  {2, 1}
+//
+// If there are arc segments in the geometry that were tessellated,
+// then the m_arcs_sp array contains one pair for each tessellated
+// arc segment.  The pair contains the vertex indices (into the
+// m_pts array) of the start and end segments of the tesselated arc.
 class LineBuffer
 {
 public:
@@ -146,8 +151,11 @@
     inline const RS_Bounds& bounds() const;
     inline void EnsurePoints(int n);
     inline void EnsureContours(int n);
+    inline void EnsureArcsSpArray(int n);
     inline int contour_start_point(int contour) const;
     inline int contour_end_point(int contour) const;
+    inline int arcs_sp_length() const;
+    inline int* arcs_sp_array() const;
     inline void get_point(int n, double&x, double&y, double& z) const;
     inline void get_point(int n, double&x, double&y) const;
     inline double& x_coord(int n) const;
@@ -192,10 +200,14 @@
     bool m_bProcessZ;
     FdoDimensionality m_dimensionality;
     double m_drawingScale;
+    int m_arcs_sp_len;          // length of m_arcs_sp array
+    int m_cur_arcs_sp;          // current index into m_arcs_sp
+    int* m_arcs_sp;             // arc start points array
 
     void Resize();
     void ResizeContours();
     void ResizeNumGeomContours(int size);
+    void ResizeArcsSpArray();
 
     void AddToBounds(double x, double y, double z = 0.0);
 
@@ -228,6 +240,7 @@
 
     void ResizePoints(int n);    // new size of array # of points
     void ResizeContours(int n);
+    void ResizeArcsSpArray(int n);
 };
 
 
@@ -340,6 +353,16 @@
 }
 
 
+void LineBuffer::EnsureArcsSpArray(int n)
+{
+    // need to have space for n additional arcs start points
+    int needed = m_cur_arcs_sp + n + 1;
+    // existing array not large enough
+    if (needed > m_arcs_sp_len)
+        ResizeArcsSpArray(2 * needed);
+}
+
+
 void LineBuffer::append_segment(SegType type, const double& x, const double& y, const double& z)
 {
     m_pts[m_cur_types][0] = x;
@@ -384,6 +407,18 @@
 }
 
 
+int LineBuffer::arcs_sp_length() const
+{
+    return m_cur_arcs_sp + 1;
+}
+
+
+int* LineBuffer::arcs_sp_array() const
+{
+    return m_arcs_sp;
+}
+
+
 void LineBuffer::get_point(int n, double&x, double&y, double& z) const
 {
     x = m_pts[n][0];

_______________________________________________
mapguide-commits mailing list
mapguide-commits@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-commits

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic