[mapguide-commits] r1239 - trunk/MgDev/Common/Stylization

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Mar 15 12:32:31 EDT 2007


Author: traianstanev
Date: 2007-03-15 12:32:31 -0400 (Thu, 15 Mar 2007)
New Revision: 1239

Modified:
   trunk/MgDev/Common/Stylization/Centroid.cpp
   trunk/MgDev/Common/Stylization/GeometryAdapter.cpp
   trunk/MgDev/Common/Stylization/PolylineAdapter.cpp
   trunk/MgDev/Common/Stylization/SE_LineBuffer.cpp
   trunk/MgDev/Common/Stylization/SE_LineBuffer.h
   trunk/MgDev/Common/Stylization/SE_Renderer.cpp
   trunk/MgDev/Common/Stylization/StylizationEngine.cpp
   trunk/MgDev/Common/Stylization/StylizationEngine.h
Log:
Code cleanup. Feature geometry now passes through the new style engine without being copied into an SE_LineBuffer. It remains in its original LineBuffer and whoever needs to transform it to screen space, does so using the WorldToScreen renderer API call.

Modified: trunk/MgDev/Common/Stylization/Centroid.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/Centroid.cpp	2007-03-15 16:10:12 UTC (rev 1238)
+++ trunk/MgDev/Common/Stylization/Centroid.cpp	2007-03-15 16:32:31 UTC (rev 1239)
@@ -67,11 +67,8 @@
     *cx = x0 + fact*dx;
     *cy = y0 + fact*dy;
 
-    // compute the slope
-    if (dx == 0.0)
-        *slope = (dy < 0.0)? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity();
-    else
-        *slope = dy / dx;
+    // compute the slope (as a rotation)
+    *slope = atan2(dy, dx);
 }
 
 

Modified: trunk/MgDev/Common/Stylization/GeometryAdapter.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/GeometryAdapter.cpp	2007-03-15 16:10:12 UTC (rev 1238)
+++ trunk/MgDev/Common/Stylization/GeometryAdapter.cpp	2007-03-15 16:32:31 UTC (rev 1239)
@@ -638,7 +638,7 @@
 
 
 void GeometryAdapter::AddLabel(double x, double y,
-                               double slope, bool useSlope,
+                               double slope_rad, bool useSlope,
                                MdfModel::Label* label,
                                RS_OverpostType type, bool exclude,
                                Renderer* renderer,
@@ -650,7 +650,7 @@
     ConvertTextDef(text, def);
 
     if (useSlope)
-        def.rotation() = atan(slope) / M_PI180;
+        def.rotation() = slope_rad / M_PI180;
 
     std::wstring txt;
     /*bool const1 =*/ EvalString(text->GetText(), txt);

Modified: trunk/MgDev/Common/Stylization/PolylineAdapter.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/PolylineAdapter.cpp	2007-03-15 16:10:12 UTC (rev 1238)
+++ trunk/MgDev/Common/Stylization/PolylineAdapter.cpp	2007-03-15 16:32:31 UTC (rev 1239)
@@ -129,14 +129,14 @@
     {
         double cx = 0.0;
         double cy = 0.0;
-        double slope = 0.0;
+        double slope_rad = 0.0;
 
         //multi should work for simple polylines too
-        lb->Centroid(LineBuffer::ctLine, &cx, &cy, &slope);
+        lb->Centroid(LineBuffer::ctLine, &cx, &cy, &slope_rad);
 
         if (!_isnan(cx) && !_isnan(cy))
         {
-            AddLabel(cx, cy, slope, true, label, RS_OverpostType_FirstFit, true, renderer, lb);
+            AddLabel(cx, cy, slope_rad, true, label, RS_OverpostType_FirstFit, true, renderer, lb);
         }
     }
 }

Modified: trunk/MgDev/Common/Stylization/SE_LineBuffer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/SE_LineBuffer.cpp	2007-03-15 16:10:12 UTC (rev 1238)
+++ trunk/MgDev/Common/Stylization/SE_LineBuffer.cpp	2007-03-15 16:32:31 UTC (rev 1239)
@@ -747,36 +747,6 @@
     lb->_LineTo(px4, py4);
 }
 
-void SE_LineBuffer::LongestEdge(LineBuffer* lb, double& x0, double& y0, double& x1, double& y1)
-{
-    int* contours = lb->cntrs();
-    int* cntr_end = contours + lb->cntr_count();
-    double* points = lb->points();
-
-    while(contours < cntr_end)
-    {
-        double* pnt_end = points + 2*(*contours++);
-        double maxlensq = -1.0, lastx, lasty;
-        lastx = x0 = x1 = *points++;
-        lasty = y0 = y1 = *points++;
-
-        while (points < pnt_end)
-        {
-            double x = *points++;
-            double y = *points++;
-            double lensq = (x - lastx)*(x - lastx) + (y - lasty)*(y - lasty);
-            if (lensq > maxlensq)
-            {
-                maxlensq = lensq;
-                x0 = lastx; y0 = lasty;
-                x1 = x; y1 = y;
-            }
-            lastx = x;
-            lasty = y;
-        }
-    }
-}
-
 SE_LineBuffer* SE_LineBuffer::Clone()
 {
     SE_LineBuffer* clone = m_pool->NewLineBuffer(m_npts);

Modified: trunk/MgDev/Common/Stylization/SE_LineBuffer.h
===================================================================
--- trunk/MgDev/Common/Stylization/SE_LineBuffer.h	2007-03-15 16:10:12 UTC (rev 1238)
+++ trunk/MgDev/Common/Stylization/SE_LineBuffer.h	2007-03-15 16:32:31 UTC (rev 1239)
@@ -71,8 +71,6 @@
     STYLIZATION_API SE_INLINE SE_Bounds* xf_bounds() { return m_xf_bounds; }
     STYLIZATION_API SE_INLINE SE_Bounds* inst_bounds() { return m_inst_bounds; }
 
-    STYLIZATION_API static void LongestEdge(LineBuffer* lb, double& x0, double& y0, double& x1, double& y1);
-
     STYLIZATION_API SE_LineBuffer* Clone();
 
 private:

Modified: trunk/MgDev/Common/Stylization/SE_Renderer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/SE_Renderer.cpp	2007-03-15 16:10:12 UTC (rev 1238)
+++ trunk/MgDev/Common/Stylization/SE_Renderer.cpp	2007-03-15 16:32:31 UTC (rev 1239)
@@ -185,8 +185,14 @@
     /* Render the points */
     for (int i = 0; i < geometry->point_count(); i++)
     {
+        double x = geometry->points()[2*i];
+        double y= geometry->points()[2*i+1];
+
+        //transform to screen space -- geometry is in [the original] mapping space
+        WorldToScreenPoint(x, y, x, y);
+        
         xform.setIdentity();
-        xform.translate(geometry->points()[2*i], geometry->points()[2*i+1]);
+        xform.translate(x, y);
         double angle = 0;//TODO: angle needs to be added to the RenderPointStyle
         if (style->drawLast)
             AddLabel(geometry, style, xform, 0);
@@ -263,10 +269,15 @@
 
             //current line segment
             double* seg = pts + cur_seg * 2;
+            double seg_screen[4];
+
+            //transform segment from mapping to screen space
+            WorldToScreenPoint(seg[0], seg[1], seg_screen[0], seg_screen[1]);
+            WorldToScreenPoint(seg[2], seg[3], seg_screen[2], seg_screen[3]);
             
             //get length
-            double dx = seg[2] - seg[0];
-            double dy = seg[3] - seg[1];
+            double dx = seg_screen[2] - seg_screen[0];
+            double dy = seg_screen[3] - seg_screen[1];
             double len = sqrt(dx*dx + dy*dy);
 
             //check if completely skipping current segment since it is smaller than
@@ -281,8 +292,8 @@
                 double dy_incr = sin(slope);
 
                 double symrot = fromAngle? style->angle : slope;
-                double tx = seg[0] + dx_incr * drawpos;
-                double ty = seg[1] + dy_incr * drawpos;
+                double tx = seg_screen[0] + dx_incr * drawpos;
+                double ty = seg_screen[1] + dy_incr * drawpos;
 
                 symxf.rotate(symrot);
                 symxf.translate(tx, ty);

Modified: trunk/MgDev/Common/Stylization/StylizationEngine.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/StylizationEngine.cpp	2007-03-15 16:10:12 UTC (rev 1238)
+++ trunk/MgDev/Common/Stylization/StylizationEngine.cpp	2007-03-15 16:32:31 UTC (rev 1239)
@@ -145,11 +145,6 @@
 
     /* TODO: Obey the indices--Get rid of the indices altogther--single pass! */
     
-    SE_LineBuffer* xformGeom = m_pool->NewLineBuffer(geometry->point_count());
-    xformGeom->compute_bounds() = false;
-
-    xformGeom->Transform(geometry, w2s);
-
     for (std::vector<SE_Symbolization*>::const_iterator iter = symbolization->begin(); iter != symbolization->end(); iter++)
     {
         SE_Symbolization* sym = *iter;
@@ -176,7 +171,7 @@
             {
                 case SE_PointStyleType:
                     //this call may modify xform to apply the necessary rotation 
-                    rstyle = EvaluatePointStyle(xformGeom, tmpxform, (SE_PointStyle*)style, mm2px);
+                    rstyle = EvaluatePointStyle(geometry, tmpxform, (SE_PointStyle*)style, mm2px);
                     break;
                 case SE_LineStyleType:
                     rstyle = EvaluateLineStyle(tmpxform, (SE_LineStyle*)style);
@@ -204,13 +199,13 @@
                 switch(style->type)
                 {
                 case SE_PointStyleType:
-                    m_renderer->ProcessPoint(xformGeom->xf_buffer(), (SE_RenderPointStyle*)rstyle);
+                    m_renderer->ProcessPoint(geometry, (SE_RenderPointStyle*)rstyle);
                     break;
                 case SE_LineStyleType:
-                    m_renderer->ProcessLine(xformGeom->xf_buffer(), (SE_RenderLineStyle*)rstyle);
+                    m_renderer->ProcessLine(geometry, (SE_RenderLineStyle*)rstyle);
                     break;
                 case SE_AreaStyleType:
-                    m_renderer->ProcessArea(xformGeom->xf_buffer(), (SE_RenderAreaStyle*)rstyle);
+                    m_renderer->ProcessArea(geometry, (SE_RenderAreaStyle*)rstyle);
                     break;
                 }
             }
@@ -220,15 +215,14 @@
             delete rstyle;
         }
     }
-    m_pool->FreeLineBuffer(xformGeom);
 }
 
-SE_RenderPointStyle* StylizationEngine::EvaluatePointStyle(SE_LineBuffer* geometry, SE_Matrix& xform, SE_PointStyle* style, double mm2px)
+SE_RenderPointStyle* StylizationEngine::EvaluatePointStyle(LineBuffer* geometry, SE_Matrix& xform, SE_PointStyle* style, double mm2px)
 {
     SE_RenderPointStyle* render = new SE_RenderPointStyle();
 
     LineBuffer::GeomOperationType type;
-    switch(geometry->xf_buffer()->geom_type())
+    switch(geometry->geom_type())
     {
     case FdoGeometryType_LineString:
     case FdoGeometryType_MultiLineString:
@@ -253,9 +247,15 @@
     {
         if (type == LineBuffer::ctLine || type == LineBuffer::ctArea)
         {
-            double x0, x1, y0, y1;
-            geometry->LongestEdge(geometry->xf_buffer(), x0, y0, x1, y1);
-            angle = atan2(y1 - y0, x1 - x0);
+            double x0, y0;
+            double slope_rad = 0.0;
+            geometry->Centroid(LineBuffer::ctLine, &x0, &y0, &slope_rad);
+
+            angle = slope_rad; 
+
+            //TODO: do we really need to invert this in case of y-down?
+            if (xform.y1 < 0)
+                angle = -angle;
         }
     }
     else

Modified: trunk/MgDev/Common/Stylization/StylizationEngine.h
===================================================================
--- trunk/MgDev/Common/Stylization/StylizationEngine.h	2007-03-15 16:10:12 UTC (rev 1238)
+++ trunk/MgDev/Common/Stylization/StylizationEngine.h	2007-03-15 16:32:31 UTC (rev 1239)
@@ -61,7 +61,7 @@
     void ParseStringExpression(const MdfString& mdf_string, SE_String& se_string);
 
 private:
-    SE_RenderPointStyle* EvaluatePointStyle(SE_LineBuffer* geometry, SE_Matrix& xform, SE_PointStyle* style, double mm2px);
+    SE_RenderPointStyle* EvaluatePointStyle(LineBuffer* geometry, SE_Matrix& xform, SE_PointStyle* style, double mm2px);
     SE_RenderAreaStyle* EvaluateAreaStyle(SE_Matrix& xform, SE_AreaStyle* style);
     SE_RenderLineStyle* EvaluateLineStyle(SE_Matrix& xform, SE_LineStyle* style);
 



More information about the mapguide-commits mailing list