[mapguide-commits] r1180 - trunk/MgDev/Common/Stylization
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Thu Mar 8 14:26:43 EST 2007
Author: jasonnogar
Date: 2007-03-08 14:26:42 -0500 (Thu, 08 Mar 2007)
New Revision: 1180
Modified:
trunk/MgDev/Common/Stylization/GDRenderer.cpp
trunk/MgDev/Common/Stylization/GDRenderer.h
trunk/MgDev/Common/Stylization/LabelRenderer.cpp
trunk/MgDev/Common/Stylization/LabelRenderer.h
trunk/MgDev/Common/Stylization/LabelRendererBase.h
trunk/MgDev/Common/Stylization/LabelRendererLocal.cpp
trunk/MgDev/Common/Stylization/LabelRendererLocal.h
trunk/MgDev/Common/Stylization/RS_FontEngine.cpp
trunk/MgDev/Common/Stylization/SE_Bounds.cpp
trunk/MgDev/Common/Stylization/SE_Bounds.h
trunk/MgDev/Common/Stylization/SE_LineBuffer.cpp
trunk/MgDev/Common/Stylization/SE_LineBuffer.h
trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.cpp
trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.h
trunk/MgDev/Common/Stylization/SE_Renderer.cpp
trunk/MgDev/Common/Stylization/SE_Renderer.h
trunk/MgDev/Common/Stylization/StylizationEngine.cpp
trunk/MgDev/Common/Stylization/StylizationEngine.h
Log:
Symbology:
Change the internal storage of SE_LineBuffer to LineBuffers(per transformed instance of the geometry).
Fix bug where the bounds of symbols resized by a ResizeBox were not updated.
Fixed the Transform method of SE_Bounds.
Modified: trunk/MgDev/Common/Stylization/GDRenderer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/GDRenderer.cpp 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/GDRenderer.cpp 2007-03-08 19:26:42 UTC (rev 1180)
@@ -2145,7 +2145,7 @@
//copied from WritePolylines, except it doesn't do to screen trasnform -- we should refactor.
-void GDRenderer::DrawScreenPolyline(SE_Geometry& geom, unsigned int color, double weightpx)
+void GDRenderer::DrawScreenPolyline(LineBuffer* srclb, unsigned int color, double weightpx)
{
RS_Color c((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF, (color >> 24) & 0xFF);
@@ -2166,12 +2166,12 @@
//draw the lines
int index = 0;
- for (int i=0; i<geom.n_cntrs; i++)
+ for (int i=0; i<srclb->cntr_count(); i++)
{
- int cntr_size = geom.contours[i];
+ int cntr_size = srclb->cntrs()[i];
//convert to integer coords
- _TransferPoints(geom.points + index, cntr_size);
+ _TransferPoints(srclb->points() + index, cntr_size);
if (cntr_size > 1)
{
@@ -2196,11 +2196,11 @@
}
-void GDRenderer::DrawScreenPolygon(SE_Geometry& geom, unsigned int color)
+void GDRenderer::DrawScreenPolygon(LineBuffer* polygon, unsigned int color)
{
RS_Color c((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF, (color >> 24) & 0xFF);
- if (geom.n_pts == 0)
+ if (polygon->point_count() == 0)
return;
if (c.alpha() != 0)
@@ -2218,10 +2218,10 @@
}
*/
- _TransferPoints(geom.points, geom.n_pts);
+ _TransferPoints(polygon->points(), polygon->point_count());
//call the new rasterizer
- m_polyrasterizer->FillPolygon((Point*)m_wtPointBuffer, geom.n_pts, geom.contours, geom.n_cntrs,
+ m_polyrasterizer->FillPolygon((Point*)m_wtPointBuffer, polygon->point_count(), polygon->cntrs(), polygon->cntr_count(),
(fillpat) ? gdTiled : gdc, (gdImagePtr)m_imout);
/*
@@ -2285,7 +2285,7 @@
int nlabels,
RS_OverpostType type,
bool exclude,
- SE_Geometry* path)
+ LineBuffer* path)
{
//pass labels to the label renderer here
Modified: trunk/MgDev/Common/Stylization/GDRenderer.h
===================================================================
--- trunk/MgDev/Common/Stylization/GDRenderer.h 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/GDRenderer.h 2007-03-08 19:26:42 UTC (rev 1180)
@@ -149,8 +149,8 @@
////////////////////////////////////////////////
// SE_Renderer
//
- virtual void DrawScreenPolyline(SE_Geometry& geom, unsigned int color, double weight); // px
- virtual void DrawScreenPolygon(SE_Geometry& geom, unsigned int fill);
+ virtual void DrawScreenPolyline(LineBuffer* geom, unsigned int color, double weight); // px
+ virtual void DrawScreenPolygon(LineBuffer* geom, unsigned int fill);
virtual void DrawScreenRaster(unsigned char* data, int length, RS_ImageFormat format, int native_width, int native_height,
double x, double y, double w, double h, double angledeg);
virtual void DrawScreenText(const RS_String& txt, RS_TextDef& tdef, double insx, double insy, double* path, int npts, double param_position);
@@ -170,7 +170,7 @@
int nlabels,
RS_OverpostType type,
bool exclude,
- SE_Geometry* path = NULL);
+ LineBuffer* path = NULL);
virtual void DrawString(const RS_String& s,
int x,
Modified: trunk/MgDev/Common/Stylization/LabelRenderer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/LabelRenderer.cpp 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/LabelRenderer.cpp 2007-03-08 19:26:42 UTC (rev 1180)
@@ -197,7 +197,7 @@
int nlabels,
RS_OverpostType type,
bool exclude,
- SE_Geometry* path)
+ LineBuffer* path)
{
BeginOverpostGroup(type, true, exclude);
Modified: trunk/MgDev/Common/Stylization/LabelRenderer.h
===================================================================
--- trunk/MgDev/Common/Stylization/LabelRenderer.h 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/LabelRenderer.h 2007-03-08 19:26:42 UTC (rev 1180)
@@ -105,7 +105,7 @@
int nlabels,
RS_OverpostType type,
bool exclude,
- SE_Geometry* path);
+ LineBuffer* path);
virtual void BlastLabels();
Modified: trunk/MgDev/Common/Stylization/LabelRendererBase.h
===================================================================
--- trunk/MgDev/Common/Stylization/LabelRendererBase.h 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/LabelRendererBase.h 2007-03-08 19:26:42 UTC (rev 1180)
@@ -54,7 +54,7 @@
int nlabels,
RS_OverpostType type,
bool exclude,
- SE_Geometry* path) = 0;
+ LineBuffer* path) = 0;
virtual void BlastLabels() = 0;
Modified: trunk/MgDev/Common/Stylization/LabelRendererLocal.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/LabelRendererLocal.cpp 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/LabelRendererLocal.cpp 2007-03-08 19:26:42 UTC (rev 1180)
@@ -308,7 +308,7 @@
int nlabels,
RS_OverpostType type,
bool exclude,
- SE_Geometry* path)
+ LineBuffer* path)
{
}
Modified: trunk/MgDev/Common/Stylization/LabelRendererLocal.h
===================================================================
--- trunk/MgDev/Common/Stylization/LabelRendererLocal.h 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/LabelRendererLocal.h 2007-03-08 19:26:42 UTC (rev 1180)
@@ -111,7 +111,7 @@
int nlabels,
RS_OverpostType type,
bool exclude,
- SE_Geometry* path);
+ LineBuffer* path);
virtual void BlastLabels();
Modified: trunk/MgDev/Common/Stylization/RS_FontEngine.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/RS_FontEngine.cpp 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/RS_FontEngine.cpp 2007-03-08 19:26:42 UTC (rev 1180)
@@ -519,20 +519,14 @@
}
// draw a filled rectangle
- SE_Geometry geom;
- double points[10] = {fpts[0].x, fpts[0].y,
- fpts[1].x, fpts[1].y,
- fpts[2].x, fpts[2].y,
- fpts[3].x, fpts[3].y,
- fpts[0].x, fpts[0].y};
- int contours[1] = {5};
- geom.points = points;
- geom.n_pts = 5;
- geom.contours = contours;
- geom.n_cntrs = 1;
- geom.geom_type = (int)FdoGeometryType_Polygon;
+ LineBuffer lb(5);
+ lb.MoveTo(fpts[0].x, fpts[0].y);
+ lb.LineTo(fpts[1].x, fpts[1].y);
+ lb.LineTo(fpts[2].x, fpts[2].y);
+ lb.LineTo(fpts[3].x, fpts[3].y);
+ lb.Close();
- m_serenderer->DrawScreenPolygon(geom, tdef.bgcolor().argb());
+ m_serenderer->DrawScreenPolygon(&lb, tdef.bgcolor().argb());
}
for (size_t k=0; k<tm.line_pos.size(); ++k)
@@ -584,16 +578,11 @@
double y1 = y0 - textwidth * sin_a;
// draw the thick line
- SE_Geometry geom;
- double points[4] = {x0, y0, x1, y1};
- int contours[1] = {2};
- geom.points = points;
- geom.n_pts = 2;
- geom.contours = contours;
- geom.n_cntrs = 1;
- geom.geom_type = (int)FdoGeometryType_LineString;
+ LineBuffer lb(2);
+ lb.MoveTo(x0, y0);
+ lb.LineTo(x1, y1);
- m_serenderer->DrawScreenPolyline(geom, tdef.color().argb(), line_width);
+ m_serenderer->DrawScreenPolyline(&lb, tdef.color().argb(), line_width);
}
}
}
@@ -676,16 +665,11 @@
ey = tm.char_pos[i+1].y + cos(tm.char_pos[i+1].anglerad) * line_pos;
}
- SE_Geometry geom;
- double points[4] = {sx, sy, ex, ey};
- int contours[1] = {2};
- geom.points = points;
- geom.n_pts = 2;
- geom.contours = contours;
- geom.n_cntrs = 1;
- geom.geom_type = (int)FdoGeometryType_LineString;
+ LineBuffer lb(2);
+ lb.MoveTo(sx, sy);
+ lb.LineTo(ex, ey);
- m_serenderer->DrawScreenPolyline(geom, tdef.color().argb(), line_width);
+ m_serenderer->DrawScreenPolyline(&lb, tdef.color().argb(), line_width);
last_x = ex;
last_y = ey;
Modified: trunk/MgDev/Common/Stylization/SE_Bounds.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/SE_Bounds.cpp 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/SE_Bounds.cpp 2007-03-08 19:26:42 UTC (rev 1180)
@@ -20,6 +20,18 @@
#include "SE_ConvexHull.h"
#include <float.h>
+inline void AddToBounds(double x, double y, double* min, double* max)
+{
+ if (min[0] > x)
+ min[0] = x;
+ if (max[0] < x)
+ max[0] = x;
+ if (min[1] > y)
+ min[1] = y;
+ if (max[1] < y)
+ max[1] = y;
+}
+
SE_Bounds::SE_Bounds()
{
}
@@ -35,27 +47,47 @@
hull[2*size] = x;
hull[2*size+1] = y;
- if (min[0] > x)
- min[0] = x;
- if (max[0] < x)
- max[0] = x;
- if (min[1] > y)
- min[1] = y;
- if (max[1] < y)
- max[1] = y;
-
+ AddToBounds(x,y, min, max);
+
size++;
}
-void SE_Bounds::Transform(SE_Matrix& xform)
+void SE_Bounds::Transform(const SE_Matrix& xform)
{
double *last = hull + 2*size;
double *cur = hull;
+ min[0] = min[1] = DBL_MAX;
+ max[0] = max[1] = -DBL_MAX;
while (cur < last)
- xform.transform(*cur++, *cur++);
+ {
+ xform.transform(cur[0], cur[1]);
+ AddToBounds(cur[0], cur[1], min, max);
+ cur += 2;
+ }
}
+/* NOTE: This method is intentionally unchecked, the caller must ensure that the
+ * destination SE_Bounds is large enough, that the source is valid, etc. */
+void SE_Bounds::Transform(const SE_Matrix& xform, SE_Bounds* src)
+{
+ double *last = src->hull + 2*src->size;
+ double *cur = src->hull;
+ double *dst = hull;
+ min[0] = min[1] = DBL_MAX;
+ max[0] = max[1] = -DBL_MAX;
+ size = src->size;
+ pivot = src->pivot;
+
+ while (cur < last)
+ {
+ xform.transform(cur[0], cur[1], dst[0], dst[1]);
+ AddToBounds(dst[0], dst[1], min, max);
+ cur += 2;
+ dst += 2;
+ }
+}
+
struct SimplePoint
{
double x;
Modified: trunk/MgDev/Common/Stylization/SE_Bounds.h
===================================================================
--- trunk/MgDev/Common/Stylization/SE_Bounds.h 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/SE_Bounds.h 2007-03-08 19:26:42 UTC (rev 1180)
@@ -41,7 +41,8 @@
double max[2];
STYLIZATION_API void Add(double x, double y);
- STYLIZATION_API void Transform(SE_Matrix& xform);
+ STYLIZATION_API void Transform(const SE_Matrix& xform);
+ STYLIZATION_API void Transform(const SE_Matrix& xform, SE_Bounds* src);
STYLIZATION_API void Contained(double minx, double miny, double maxx, double maxy, double &growx, double &growy);
STYLIZATION_API void Free();
STYLIZATION_API SE_Bounds* Clone();
Modified: trunk/MgDev/Common/Stylization/SE_LineBuffer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/SE_LineBuffer.cpp 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/SE_LineBuffer.cpp 2007-03-08 19:26:42 UTC (rev 1180)
@@ -29,26 +29,146 @@
if ((m_npts + (points)) > m_max_pts) \
ResizeBuffer((void**)&m_pts, sizeof(double), (points), m_npts, m_max_pts);
-#define ENSURE_XF_POINT_BUFFER(points) \
- if ((m_xf_npts + (points)) > m_max_xf_pts) \
- ResizeBuffer((void**)&m_xf_pts, 2*sizeof(double), (points), m_xf_npts, m_max_xf_pts);
+#define ENSURE_SEG_BUFFER(points) \
+ if ((m_nsegs + (points)) > m_max_segs) \
+ ResizeBuffer((void**)&m_segs, sizeof(SE_LB_SegType), (points), m_nsegs, m_max_segs);
-#define ENSURE_INST_POINT_BUFFER(points) \
- if ((m_inst_npts + (points)) > m_max_inst_pts) \
- ResizeBuffer((void**)&m_inst_pts, 2*sizeof(double), (points), m_inst_npts, m_max_inst_pts);
+class SE_LineStorage : public LineBuffer
+{
+public:
+ SE_INLINE SE_LineStorage(int size);
+ SE_INLINE void EnsurePoints(int n);
+ SE_INLINE void EnsureContours(int n);
+ SE_INLINE void _MoveTo(double x, double y);
+ SE_INLINE void _LineTo(double x, double y);
+ SE_INLINE void SetBounds(double minx, double miny, double maxx, double maxy);
+ SE_INLINE void SetBounds(SE_Bounds* bounds);
+ void SetToTransform(const SE_Matrix& xform, LineBuffer* src);
+};
-#define ENSURE_XF_CNTR_BUFFER(points) \
- if ((m_xf_ncntrs + (points)) > m_max_xf_cntrs) \
- ResizeBuffer((void**)&m_xf_cntrs, sizeof(int), (points), m_xf_ncntrs, m_max_xf_cntrs);
+SE_LineStorage::SE_LineStorage(int size) :
+ LineBuffer(size)
+{
+}
-#define ENSURE_INST_CNTR_BUFFER(points) \
- if ((m_inst_ncntrs + (points)) > m_max_inst_cntrs) \
- ResizeBuffer((void**)&m_inst_cntrs, sizeof(int), (points), m_inst_ncntrs, m_max_inst_cntrs);
+void SE_LineStorage::_MoveTo(double x, double y)
+{
+ m_types[m_cur_types++] = (unsigned char)stMoveTo;
+ m_pts[m_cur_pts++] = x;
+ m_pts[m_cur_pts++] = y;
-#define ENSURE_SEG_BUFFER(points) \
- if ((m_nsegs + (points)) > m_max_segs) \
- ResizeBuffer((void**)&m_segs, sizeof(SE_LB_SegType), (points), m_nsegs, m_max_segs);
+ m_last_x = x;
+ m_last_y = y;
+ m_cntrs[++m_cur_cntr] = 1; //increment to next contour and count the point
+}
+
+
+void SE_LineStorage::_LineTo(double x, double y)
+{
+ m_types[m_cur_types++] = (unsigned char)stLineTo;
+ m_pts[m_cur_pts++] = x;
+ m_pts[m_cur_pts++] = y;
+
+ m_cntrs[m_cur_cntr]++;
+}
+
+void SE_LineStorage::EnsurePoints(int n)
+{
+ if (m_cur_pts + 2*n >= m_pts_len)
+ {
+ int len = 2*m_pts_len;
+ if (len - m_pts_len < 2*n)
+ len += 2*n;
+
+ double* tempPts = new double[len];
+ memcpy(tempPts, m_pts, sizeof(double)*m_pts_len);
+ delete[] m_pts;
+ m_pts = tempPts;
+ m_pts_len = len;
+
+ len /= 2;
+ unsigned char* tempTypes = new unsigned char[len];
+ memcpy(tempTypes, m_types, sizeof(unsigned char) * m_types_len);
+ delete[] m_types;
+ m_types = tempTypes;
+ m_types_len = len;
+ }
+}
+
+void SE_LineStorage::EnsureContours(int n)
+{
+ if (m_cur_cntr + 2 + n > m_cntrs_len)
+ {
+ int len = 2*m_cntrs_len;
+ if (len - m_pts_len < n)
+ len += n;
+
+ int* tempCntrs = new int[len];
+ memcpy(tempCntrs, m_cntrs, sizeof(int)*m_cntrs_len);
+ delete[] m_cntrs;
+ m_cntrs = tempCntrs;
+ m_cntrs_len = len;
+ }
+}
+
+void SE_LineStorage::SetBounds(double minx, double miny, double maxx, double maxy)
+{
+ m_bounds.minx = minx;
+ m_bounds.miny = miny;
+ m_bounds.maxx = maxx;
+ m_bounds.maxy = maxy;
+}
+
+void SE_LineStorage::SetBounds(SE_Bounds* bounds)
+{
+ m_bounds.minx = bounds->min[0];
+ m_bounds.miny = bounds->min[1];
+ m_bounds.maxx = bounds->max[0];
+ m_bounds.maxy = bounds->max[1];
+}
+
+void SE_LineStorage::SetToTransform(const SE_Matrix& xform, LineBuffer* lb)
+{
+ EnsurePoints(lb->point_count());
+ EnsureContours(lb->cntr_count());
+
+ int n_cntrs = lb->cntr_count();
+ int* contours = lb->cntrs();
+ double* src = lb->points();
+ double* dst = m_pts;
+
+ for (int i = 0; i < n_cntrs; i++)
+ {
+ double sx, sy, *tx, *ty;
+ double* last = src + 2*contours[i];
+ sx = *src++;
+ sy = *src++;
+ xform.transform(sx, sy, m_last_x, m_last_y);
+ *dst++ = m_last_x;
+ *dst++ = m_last_y;
+
+ while (src < last)
+ {
+ sx = *src++;
+ sy = *src++;
+ tx = dst++;
+ ty = dst++;
+ xform.transform(sx, sy, *tx, *ty);
+ }
+ }
+
+ memcpy(m_types, lb->types(), lb->point_count());
+ memcpy(m_cntrs, lb->cntrs(), sizeof(int)*lb->cntr_count());
+
+ m_cur_types = lb->point_count();
+ m_cur_pts = m_cur_types*2;
+ m_cur_cntr = lb->cntr_count() - 1;
+
+ m_geom_type = lb->geom_type();
+ xform.transform(m_last_x, m_last_y);
+}
+
inline void SineCosineMax(double sAng, double sSine, double sCosine, double eAng, double eSine, double eCosine, double &maxSine, double &maxCosine)
{
int quadrants = ((int)(sAng*2.0/M_PI) << 2) | (int)(eAng*2.0/M_PI);
@@ -142,6 +262,8 @@
SE_Bounds* SE_LineBuffer::ComputeConvexHull(double* pnts, int* cntrs, int ncntrs, double weight)
{
+ if (ncntrs == 0)
+ return NULL;
// Monotone Chain Convex Hull Algorithm (Andrew, 1979)
m_ch_ptbuf.clear();
@@ -196,6 +318,8 @@
std::set<std::pair<double,double>, PointLess>::iterator end = m_ch_ptbuf.end();
std::set<std::pair<double,double>, PointLess>::iterator iter = m_ch_ptbuf.begin();
+ if (m_ch_ptbuf.size() < 2)
+ return NULL;
return AndrewHull<std::set<std::pair<double,double>, PointLess>::iterator, PointUtil>
(iter, --end, (int)m_ch_ptbuf.size(), m_pool);
}
@@ -203,38 +327,27 @@
SE_LineBuffer::SE_LineBuffer(int size) :
m_npts(0),
m_nsegs(0),
- m_xf_ncntrs(0),
- m_inst_ncntrs(0),
- m_xf_npts(0),
- m_inst_npts(0),
- m_max_xf_pts(size),
- m_max_inst_pts(size),
- m_max_xf_cntrs(size),
- m_max_inst_cntrs(size),
m_max_pts(2*size),
m_max_segs(size),
m_xf_tol(-1.0),
m_xf_weight(-1.0),
m_src_lb(NULL),
m_xf_bounds(NULL),
- m_inst_bounds(NULL)
+ m_inst_bounds(NULL),
+ m_compute_bounds(true)
{
m_pts = new double[size*2];
- m_xf_pts = new double[size*2];
- m_inst_pts = new double[size*2];
- m_xf_cntrs = new int[size];
- m_inst_cntrs = new int[size];
m_segs = new SE_LB_SegType[size];
+ m_xf_buf = new SE_LineStorage(size);
+ m_inst_buf = new SE_LineStorage(size);
}
SE_LineBuffer::~SE_LineBuffer()
{
delete[] m_pts;
- delete[] m_xf_pts;
- delete[] m_inst_pts;
- delete[] m_xf_cntrs;
- delete[] m_inst_cntrs;
delete[] m_segs;
+ delete m_xf_buf;
+ delete m_inst_buf;
}
void SE_LineBuffer::MoveTo(double x, double y)
@@ -334,25 +447,28 @@
void SE_LineBuffer::Reset()
{
- m_npts = m_xf_npts = m_xf_ncntrs = m_nsegs = m_inst_npts = m_inst_ncntrs = 0;
+ m_compute_bounds = true;
+ m_npts = m_nsegs = 0;
if (m_xf_bounds)
{
- m_pool->FreeBounds(m_xf_bounds);
+ m_xf_bounds->Free();
m_xf_bounds = NULL;
}
if (m_inst_bounds)
{
- m_pool->FreeBounds(m_inst_bounds);
+ m_inst_bounds->Free();
m_inst_bounds = NULL;
}
m_src_lb = NULL;
m_xf_tol = m_xf_weight = -1.0;
m_xf.setIdentity();
+ m_xf_buf->Reset();
+ m_inst_buf->Reset();
}
void SE_LineBuffer::ResizeBuffer(void** buffer, int unitsize, int mininc, int cur_pts, int& max_pts)
{
- int max_newpts = (int)(max_pts*GROWTH_FACTOR) + 1;
+ int max_newpts = (int)(GROWTH_FACTOR*max_pts) + 1;
if (max_newpts - max_pts < mininc)
max_newpts += mininc;
@@ -363,45 +479,44 @@
max_pts = max_newpts;
}
-void SE_LineBuffer::Transform(const SE_Matrix& xform, double weight, double tolerance)
+LineBuffer* SE_LineBuffer::Transform(const SE_Matrix& xform, double weight, double tolerance)
{
if (m_xf == xform && m_xf_tol == tolerance && m_xf_weight == weight)
- return;
+ return m_xf_buf;
if (m_xf_bounds)
{
- m_pool->FreeBounds(m_xf_bounds);
+ m_xf_bounds->Free();
m_xf_bounds = NULL;
}
if (m_src_lb)
- {
- SetToTransform(m_src_lb, xform);
- return;
- }
+ return Transform(m_src_lb, xform, weight);
m_xf = xform;
m_xf_tol = tolerance;
m_xf_weight = weight;
+ m_xf_buf->Reset();
SE_LB_SegType* endseg = m_segs + m_nsegs;
SE_LB_SegType* curseg = m_segs;
int src_idx = 0;
- int dst_idx = 0;
+ double x, y;
while(curseg != endseg)
{
switch(*curseg++)
{
case SegType_MoveTo:
- ENSURE_XF_CNTR_BUFFER(1);
- m_xf_cntrs[m_xf_ncntrs++] = 0;
+ m_xf_buf->EnsureContours(1);
+ xform.transform(m_pts[src_idx], m_pts[src_idx+1], x, y);
+ m_xf_buf->_MoveTo(x,y);
+ src_idx += 2;
+ break;
case SegType_LineTo:
- ENSURE_XF_POINT_BUFFER(1);
- xform.transform(m_pts[src_idx], m_pts[src_idx+1], m_xf_pts[dst_idx], m_xf_pts[dst_idx+1]);
+ m_xf_buf->EnsurePoints(1);
+ xform.transform(m_pts[src_idx], m_pts[src_idx+1], x, y);
+ m_xf_buf->_LineTo(x,y);
src_idx += 2;
- dst_idx += 2;
- m_xf_cntrs[m_xf_ncntrs-1]++;
- m_xf_npts++;
break;
case SegType_EllipticalArc:
{
@@ -464,9 +579,7 @@
mx *= rx;
my *= ry;
int steps = (int)((aspan/tolerance)*sqrt(mx*mx + my*my)) + 1;
- ENSURE_XF_POINT_BUFFER(steps + 1);
- m_xf_cntrs[m_xf_ncntrs-1] += steps + 1;
- m_xf_npts += steps + 1;
+ m_xf_buf->EnsurePoints(steps + 1);
if (rot != 0.0)
{
@@ -488,54 +601,62 @@
c2x += cx;
c2y += cy;
- TessellateCubicTo(m_xf_pts + dst_idx, c1x, c1y, c2x, c2y, ex + cx, ey + cy, steps);
- dst_idx += 2*steps + 2;
+ TessellateCubicTo(m_xf_buf, c1x, c1y, c2x, c2y, ex + cx, ey + cy, steps);
}
break;
}
}
}
+
+ if (m_compute_bounds)
+ m_xf_bounds = ComputeConvexHull(m_xf_buf->points(), m_xf_buf->cntrs(), m_xf_buf->cntr_count(), m_xf_weight);
+ if (m_xf_bounds)
+ m_xf_buf->SetBounds(m_xf_bounds);
+
+ return m_xf_buf;
}
-void SE_LineBuffer::InstanceTransform(const SE_Matrix& xform, SE_Geometry& geom, SE_Bounds** bounds)
+LineBuffer* SE_LineBuffer::Transform(LineBuffer* lb, const SE_Matrix& xform, double weight)
{
- m_inst_npts = 0;
- m_inst_ncntrs = 0;
- ENSURE_INST_POINT_BUFFER(m_xf_npts);
- //ENSURE_INST_CNTR_BUFFER(m_inst_ncntrs); For this transform, the same number of points
- double* src = m_xf_pts;
- double* dst = m_inst_pts;
- double* last = m_xf_pts + m_xf_npts*2;
- while (src < last)
+ m_src_lb = lb;
+ m_xf = xform;
+ m_xf_tol = 0.0;
+ m_xf_weight = weight;
+
+ if (m_xf_bounds)
{
- double sx = *src++;
- double sy = *src++;
- double* ix = dst++;
- double* iy = dst++;
- xform.transform(sx, sy, *ix, *iy);
+ m_xf_bounds->Free();
+ m_xf_bounds = NULL;
}
- m_inst_npts = m_xf_npts;
- geom.points = m_inst_pts;
- geom.n_pts = m_inst_npts;
- geom.contours = m_xf_cntrs;
- geom.n_cntrs = m_xf_ncntrs;
- geom.geom_type = xf_geom_type();
+ m_xf_buf->SetToTransform(xform, lb);
+ if (m_compute_bounds)
+ m_xf_bounds = ComputeConvexHull(m_xf_buf->points(), m_xf_buf->cntrs(), m_xf_buf->cntr_count(), m_xf_weight);
+ if (m_xf_bounds)
+ m_xf_buf->SetBounds(m_xf_bounds);
- if (bounds)
+ return m_xf_buf;
+}
+
+LineBuffer* SE_LineBuffer::TransformInstance(const SE_Matrix& xform)
+{
+ m_inst_buf->SetToTransform(xform, m_xf_buf);
+
+ if (m_inst_bounds)
{
- SE_Bounds* srcbounds = xf_bounds();
- SE_Bounds* dstbounds = *bounds;
- dstbounds = m_pool->NewBounds(srcbounds->size);
- for(int i = 0; i < srcbounds->size; i++)
- xform.transform(srcbounds->hull[2*i], srcbounds->hull[2*i+1], dstbounds->hull[2*i], dstbounds->hull[2*i+1]);
- dstbounds->size = srcbounds->size;
- dstbounds->max[0] = srcbounds->max[0];
- dstbounds->max[1] = srcbounds->max[1];
- dstbounds->min[0] = srcbounds->min[0];
- dstbounds->min[1] = srcbounds->min[1];
+ m_inst_bounds->Free();
+ m_inst_bounds = NULL;
}
+
+ if (m_xf_bounds && m_compute_bounds)
+ {
+ m_inst_bounds = m_pool->NewBounds(m_xf_bounds->size);
+ m_inst_bounds->Transform(xform, m_xf_bounds);
+ m_inst_buf->SetBounds(m_inst_bounds);
+ }
+
+ return m_inst_buf;
}
bool SE_LineBuffer::Empty()
@@ -546,9 +667,15 @@
return m_npts == 0;
}
-void SE_LineBuffer::TessellateCubicTo(double* pts, double px2, double py2, double px3, double py3, double px4, double py4, int steps)
+void SE_LineBuffer::Free()
{
+ m_pool->FreeLineBuffer(this);
+}
+
+void SE_LineBuffer::TessellateCubicTo(SE_LineStorage* lb, double px2, double py2, double px3, double py3, double px4, double py4, int steps)
+{
//get the start point
+ double* pts = lb->points() + 2*lb->point_count();
double px1 = pts[-2];
double py1 = pts[-1];
@@ -589,28 +716,18 @@
ddfy += dddfy;
ddfx += dddfx;
- *pts++ = fx;
- *pts++ = fy;
+ lb->_LineTo(fx, fy);
}
- *pts++ = px4;
- *pts++ = py4;
+ lb->_LineTo(px4, py4);
}
-SE_Bounds* SE_LineBuffer::xf_bounds()
+void SE_LineBuffer::LongestEdge(LineBuffer* lb, double& x0, double& y0, double& x1, double& y1)
{
- if (m_xf_bounds == NULL)
- m_xf_bounds = ComputeConvexHull(m_xf_pts, m_xf_cntrs, m_xf_ncntrs, m_xf_weight);
+ int* contours = lb->cntrs();
+ int* cntr_end = contours + lb->cntr_count();
+ double* points = lb->points();
- return m_xf_bounds;
-}
-
-void SE_LineBuffer::xf_longest_edge(double& x0, double& y0, double& x1, double& y1)
-{
- int* cntr_end = m_xf_cntrs + m_xf_ncntrs;
- int* contours = m_xf_cntrs;
- double* points = m_xf_pts;
-
while(contours < cntr_end)
{
double* pnt_end = points + 2*(*contours++);
@@ -635,45 +752,6 @@
}
}
-int SE_LineBuffer::xf_geom_type()
-{
- if (m_src_lb)
- return m_src_lb->geom_type();
- return -1;
-}
-
-void SE_LineBuffer::Centroid(LineBuffer::GeomOperationType type, double* x, double * y, double * slope)
-{
- if (m_src_lb)
- {
- double dx = 1.0;
- m_src_lb->Centroid(type, x, y, slope);
- m_xf.transform(*x, *y);
- m_xf.transformVector(*slope, dx);
- *slope /= dx;
- }
-}
-
-void SE_LineBuffer::SetToTransform(LineBuffer* lb, const SE_Matrix& xform)
-{
- m_src_lb = lb;
- m_xf = xform;
- m_xf_tol = 0.0;
- m_xf_weight = 0.0;
-
- ENSURE_XF_POINT_BUFFER(lb->point_count());
- ENSURE_XF_CNTR_BUFFER(lb->cntr_count());
-
- m_xf_ncntrs = lb->cntr_count();
- memcpy(m_xf_cntrs, lb->cntrs(), sizeof(int)*m_xf_ncntrs);
-
- m_xf_npts = lb->point_count();
- double *srcpts = lb->points();
-
- for (int i = 0; i < 2*m_xf_npts; i += 2)
- xform.transform(srcpts[i], srcpts[i+1], m_xf_pts[i], m_xf_pts[i+1]);
-}
-
SE_LineBufferPool::~SE_LineBufferPool()
{
while (!m_lb_pool.empty())
Modified: trunk/MgDev/Common/Stylization/SE_LineBuffer.h
===================================================================
--- trunk/MgDev/Common/Stylization/SE_LineBuffer.h 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/SE_LineBuffer.h 2007-03-08 19:26:42 UTC (rev 1180)
@@ -24,6 +24,7 @@
struct SE_Bounds;
class SE_LineBufferPool;
+class SE_LineStorage;
struct PointLess : std::binary_function<std::pair<double, double>&, std::pair<double, double>&, bool>
{
@@ -37,36 +38,6 @@
//---------------------------------------------
//---------------------------------------------
-struct SE_Geometry
-{
- SE_INLINE SE_Geometry() :
- points(NULL),
- n_pts(0),
- contours(NULL),
- n_cntrs(0),
- geom_type(0)
- {
- }
-
- SE_INLINE SE_Geometry(LineBuffer* srclb)
- {
- points = srclb->points();
- n_pts = srclb->point_count();
- contours = srclb->cntrs();
- n_cntrs = srclb->cntr_count();
- geom_type = srclb->geom_type();
- }
-
- double* points;
- int n_pts;
- int* contours;
- int n_cntrs;
- int geom_type;
-};
-
-//---------------------------------------------
-//---------------------------------------------
-
class SE_LineBuffer
{
friend class SE_LineBufferPool;
@@ -82,66 +53,58 @@
SegType_EllipticalArc
};
- STYLIZATION_API void SetToTransform(LineBuffer* lb, const SE_Matrix& xform);
-
STYLIZATION_API void MoveTo(double x, double y);
STYLIZATION_API void LineTo(double x, double y);
STYLIZATION_API void EllipticalArcTo(double cx, double cy, double rx, double ry, double sAng, double eAng, double rotation);
STYLIZATION_API void Close();
- STYLIZATION_API void Transform(const SE_Matrix& xform, double weight = 0.0, double tolerance = .25);
- STYLIZATION_API void InstanceTransform(const SE_Matrix& xform, SE_Geometry& geom, SE_Bounds** bounds);
STYLIZATION_API bool Empty();
+ STYLIZATION_API void Free();
- STYLIZATION_API SE_Bounds* xf_bounds();
- STYLIZATION_API void xf_longest_edge(double& x0, double& y0, double& x1, double& y1);
- STYLIZATION_API void Centroid(LineBuffer::GeomOperationType type, double* x, double * y, double * slope);
- STYLIZATION_API int xf_geom_type();
- SE_INLINE double* xf_points() { return m_xf_pts; }
- SE_INLINE int xf_point_cnt() { return m_xf_npts; }
- SE_INLINE int* xf_cntrs() { return m_xf_cntrs; }
- SE_INLINE int xf_cntr_cnt() { return m_xf_ncntrs; }
+ STYLIZATION_API LineBuffer* Transform(const SE_Matrix& xform, double weight = 0.0, double tolerance = .25);
+ STYLIZATION_API LineBuffer* Transform(LineBuffer* srclb, const SE_Matrix& xform, double weight = 0.0);
+ STYLIZATION_API LineBuffer* TransformInstance(const SE_Matrix& xform);
+ STYLIZATION_API SE_INLINE bool& compute_bounds() { return m_compute_bounds; }
+ STYLIZATION_API SE_INLINE LineBuffer* xf_buffer() { return (LineBuffer*)m_xf_buf; }
+ STYLIZATION_API SE_INLINE LineBuffer* inst_buffer() { return (LineBuffer*)m_inst_buf; }
+ 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);
+
private:
void Reset();
void ResizeBuffer(void** buffer, int unitsize, int mininc, int cur_pts, int& max_pts);
- void TessellateCubicTo(double* pts, double px2, double py2, double px3, double py3, double px4, double py4, int steps);
+ void TessellateCubicTo(SE_LineStorage* pts, double px2, double py2, double px3, double py3, double px4, double py4, int steps);
SE_Bounds* ComputeConvexHull(double* pnts, int* cntrs, int ncntrs, double weight);
SE_LineBufferPool* m_pool;
LineBuffer* m_src_lb;
double* m_pts;
- double* m_xf_pts;
- double* m_inst_pts;
- int* m_xf_cntrs;
- int* m_inst_cntrs;
SE_LB_SegType* m_segs;
+ int m_npts;
+ int m_nsegs;
+ int m_max_pts;
+ int m_max_segs;
- /* TODO: maintaining this buffer for every instance is wasteful */
- std::set<std::pair<double, double>, PointLess> m_ch_ptbuf;
+ double m_start[2];
+ double m_last[2];
+
+ bool m_compute_bounds;
SE_Matrix m_xf;
- SE_Bounds* m_xf_bounds;
- SE_Bounds* m_inst_bounds;
double m_xf_tol;
double m_xf_weight;
+ SE_Bounds* m_xf_bounds;
+ SE_LineStorage* m_xf_buf;
- double m_start[2];
- double m_last[2];
- int m_npts;
- int m_xf_npts;
- int m_inst_npts;
- int m_xf_ncntrs;
- int m_inst_ncntrs;
- int m_nsegs;
+ SE_Bounds* m_inst_bounds;
+ SE_LineStorage* m_inst_buf;
- int m_max_xf_cntrs;
- int m_max_inst_cntrs;
- int m_max_pts;
- int m_max_xf_pts;
- int m_max_inst_pts;
- int m_max_segs;
+ /* TODO: write a stack based allocator for this, or replace it */
+ std::set<std::pair<double, double>, PointLess> m_ch_ptbuf;
};
//---------------------------------------------
Modified: trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.cpp 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.cpp 2007-03-08 19:26:42 UTC (rev 1180)
@@ -74,12 +74,12 @@
}
void SE_PositioningAlgorithms::EightBall(SE_Renderer* renderer,
- SE_LineBuffer* geometry,
- SE_Matrix& xform,
- SE_Style* style,
- SE_RenderStyle* rstyle,
- double mm2px
- )
+ LineBuffer* geometry,
+ SE_Matrix& xform,
+ SE_Style* style,
+ SE_RenderStyle* rstyle,
+ double mm2px
+ )
{
//this placement algorithm implements the MapGuide dynamic point labeling algorithm
//which means 8 candidate labels generated for each symbol
@@ -281,7 +281,7 @@
void SE_PositioningAlgorithms::MultipleHighwaysShields(SE_Renderer* renderer,
- SE_LineBuffer* geometry,
+ LineBuffer* geometry,
SE_Matrix& xform,
SE_Style* style,
SE_RenderStyle* rstyle,
Modified: trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.h
===================================================================
--- trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.h 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.h 2007-03-08 19:26:42 UTC (rev 1180)
@@ -11,7 +11,7 @@
public:
static void EightBall(SE_Renderer* renderer,
- SE_LineBuffer* geometry,
+ LineBuffer* geometry,
SE_Matrix& xform,
SE_Style* style,
SE_RenderStyle* rstyle,
@@ -20,12 +20,12 @@
static void MultipleHighwaysShields(SE_Renderer* renderer,
- SE_LineBuffer* geometry,
- SE_Matrix& xform,
- SE_Style* style,
- SE_RenderStyle* rstyle,
- double mm2px
- );
+ LineBuffer* geometry,
+ SE_Matrix& xform,
+ SE_Style* style,
+ SE_RenderStyle* rstyle,
+ double mm2px
+ );
private:
Modified: trunk/MgDev/Common/Stylization/SE_Renderer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/SE_Renderer.cpp 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/SE_Renderer.cpp 2007-03-08 19:26:42 UTC (rev 1180)
@@ -28,56 +28,43 @@
m_lbp = pool;
}
-void SE_Renderer::ProcessPoint(SE_LineBuffer* geometry, SE_RenderPointStyle* style)
+void SE_Renderer::ProcessPoint(LineBuffer* geometry, SE_RenderPointStyle* style)
{
SE_Matrix xform;
- SE_Geometry geom;
- geom.n_pts = 1;
- geom.n_cntrs = 0;
- geom.geom_type = geometry->xf_geom_type();
-
/* Render the points */
- for (int i = 0; i < geometry->xf_point_cnt(); i++)
+ for (int i = 0; i < geometry->point_count(); i++)
{
xform.setIdentity();
- xform.translate(geometry->xf_points()[2*i], geometry->xf_points()[2*i+1]);
- double pt[2] = {geometry->xf_points()[2*i], geometry->xf_points()[2*i+1]};
- geom.points = pt;
-
+ xform.translate(geometry->points()[2*i], geometry->points()[2*i+1]);
double angle = 0;//TODO: angle needs to be added to the RenderPointStyle
if (style->drawLast)
- AddLabel(&geom, style, xform, angle);
+ AddLabel(geometry, style, xform, 0);
else
{
DrawSymbol(style->symbol, xform, angle);
+ double angle = 0;
if (style->addToExclusionRegions)
AddExclusionRegion(style, xform, angle);
}
}
}
-void SE_Renderer::ProcessLine(SE_LineBuffer* geometry, SE_RenderLineStyle* style)
+void SE_Renderer::ProcessLine(LineBuffer* geometry, SE_RenderLineStyle* style)
{
SE_Matrix symxf;
- SE_Geometry geom;
- geom.points = geometry->xf_points();
- geom.n_pts = geometry->xf_point_cnt();
- geom.contours = geometry->xf_cntrs();
- geom.n_cntrs = geometry->xf_cntr_cnt();
- geom.geom_type = geometry->xf_geom_type();
-
+
int ptindex = 0;
//convert increment to pixels
double increment = style->repeat; //TODO: is this already scaled by the mm to pixel scale?
- for (int j=0; j<geom.n_cntrs; j++)
+ for (int j=0; j<geometry->cntr_count(); j++)
{
//current polyline
- int ptcount = geom.contours[j];
- double* pts = geom.points + 2*ptindex;
+ int ptcount = geometry->cntrs()[j];
+ double* pts = geometry->points() + 2*ptindex;
//pixel position along the current segment
//of the polyline
@@ -125,7 +112,7 @@
while (drawpos < len)
{
if (style->drawLast)
- AddLabel(&geom, style, symxf, symrot);
+ AddLabel(geometry, style, symxf, symrot);
else
{
DrawSymbol(style->symbol, symxf, symrot);
@@ -147,7 +134,7 @@
}
}
-void SE_Renderer::ProcessArea(SE_LineBuffer* /*geometry*/, SE_RenderAreaStyle* /*style*/)
+void SE_Renderer::ProcessArea(LineBuffer* /*geometry*/, SE_RenderAreaStyle* /*style*/)
{
}
@@ -161,8 +148,7 @@
{
SE_RenderPolyline* pl = (SE_RenderPolyline*)primitive;
- SE_Geometry geometry;
- pl->geometry->InstanceTransform(posxform, geometry, NULL);
+ LineBuffer* geometry = pl->geometry->TransformInstance(posxform);
if (primitive->type == SE_PolygonPrimitive)
DrawScreenPolygon( geometry, ((SE_RenderPolygon*)primitive)->fill );
@@ -202,7 +188,7 @@
}
-void SE_Renderer::AddLabel(SE_Geometry* geom, SE_RenderStyle* style, SE_Matrix& xform, double angle)
+void SE_Renderer::AddLabel(LineBuffer* geom, SE_RenderStyle* style, SE_Matrix& xform, double angle)
{
SE_LabelInfo info(xform.x2, xform.y2, 0.0, 0.0, RS_Units_Device, angle, style);
Modified: trunk/MgDev/Common/Stylization/SE_Renderer.h
===================================================================
--- trunk/MgDev/Common/Stylization/SE_Renderer.h 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/SE_Renderer.h 2007-03-08 19:26:42 UTC (rev 1180)
@@ -27,14 +27,14 @@
public:
void SetLineBufferPool(SE_LineBufferPool* pool);
/* SE_RenderSymbol, under associated xform, is in screen space, and geometry is in screen space */
- virtual void ProcessPoint(SE_LineBuffer* geometry, SE_RenderPointStyle* style);
- virtual void ProcessLine(SE_LineBuffer* geometry, SE_RenderLineStyle* style);
- virtual void ProcessArea(SE_LineBuffer* geometry, SE_RenderAreaStyle* style);
+ virtual void ProcessPoint(LineBuffer* geometry, SE_RenderPointStyle* style);
+ virtual void ProcessLine(LineBuffer* geometry, SE_RenderLineStyle* style);
+ virtual void ProcessArea(LineBuffer* geometry, SE_RenderAreaStyle* style);
virtual void DrawSymbol(SE_RenderSymbol& symbol, const SE_Matrix& xform, double anglerad);
- virtual void DrawScreenPolyline(SE_Geometry& polyline, unsigned int color, double weight) = 0; // px
- virtual void DrawScreenPolygon(SE_Geometry& polygon, unsigned int fill) = 0;
+ virtual void DrawScreenPolyline(LineBuffer* polyline, unsigned int color, double weight) = 0; // px
+ virtual void DrawScreenPolygon(LineBuffer* polygon, unsigned int fill) = 0;
virtual void DrawScreenRaster(unsigned char* data, int length, RS_ImageFormat format, int native_width, int native_height,
double x, double y, double w, double h, double angledeg) = 0;
virtual void DrawScreenText(const RS_String& txt, RS_TextDef& tdef, double insx, double insy, double* path, int npts, double param_position) = 0;
@@ -54,7 +54,7 @@
int nlabels,
RS_OverpostType type,
bool exclude,
- SE_Geometry* path = NULL) = 0;
+ LineBuffer* path = NULL) = 0;
virtual void AddExclusionRegion(RS_F_Point* fpts, int npts) = 0;
@@ -62,7 +62,7 @@
const RS_F_Point* GetLastExclusionRegion() { return m_lastExclusionRegion; }
private:
- void AddLabel(SE_Geometry* geom, SE_RenderStyle* style, SE_Matrix& xform, double angle);
+ void AddLabel(LineBuffer* geom, SE_RenderStyle* style, SE_Matrix& xform, double angle);
void AddExclusionRegion(SE_RenderStyle* rstyle, SE_Matrix& xform, double angle);
Modified: trunk/MgDev/Common/Stylization/StylizationEngine.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/StylizationEngine.cpp 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/StylizationEngine.cpp 2007-03-08 19:26:42 UTC (rev 1180)
@@ -120,9 +120,10 @@
/* TODO: Obey the indices--Get rid of the indices alltogther--single pass! */
SE_LineBuffer* xformGeom = m_pool->NewLineBuffer(geometry->point_count());
+ xformGeom->compute_bounds() = false;
+
+ xformGeom->Transform(geometry, m_w2s);
- xformGeom->SetToTransform(geometry, m_w2s);
-
for (std::vector<SE_Symbolization*>::const_iterator iter = symbolization->begin(); iter != symbolization->end(); iter++)
{
SE_Symbolization* sym = *iter;
@@ -170,20 +171,20 @@
if (!sym->positioningAlgorithm.empty() && sym->positioningAlgorithm != L"Default")
{
- LayoutCustomLabel(sym->positioningAlgorithm, xformGeom, tmpxform, style, rstyle, mm2px);
+ LayoutCustomLabel(sym->positioningAlgorithm, xformGeom->xf_buffer(), tmpxform, style, rstyle, mm2px);
}
else
{
switch(style->type)
{
case SE_PointStyleType:
- m_renderer->ProcessPoint(xformGeom, (SE_RenderPointStyle*)rstyle);
+ m_renderer->ProcessPoint(xformGeom->xf_buffer(), (SE_RenderPointStyle*)rstyle);
break;
case SE_LineStyleType:
- m_renderer->ProcessLine(xformGeom, (SE_RenderLineStyle*)rstyle);
+ m_renderer->ProcessLine(xformGeom->xf_buffer(), (SE_RenderLineStyle*)rstyle);
break;
case SE_AreaStyleType:
- m_renderer->ProcessArea(xformGeom, (SE_RenderAreaStyle*)rstyle);
+ m_renderer->ProcessArea(xformGeom->xf_buffer(), (SE_RenderAreaStyle*)rstyle);
break;
}
}
@@ -205,7 +206,7 @@
LineBuffer::GeomOperationType type;
- switch(geometry->xf_geom_type())
+ switch(geometry->xf_buffer()->geom_type())
{
case FdoGeometryType_LineString:
case FdoGeometryType_MultiLineString:
@@ -230,7 +231,7 @@
if (type == LineBuffer::ctLine || type == LineBuffer::ctArea)
{
double x0, x1, y0, y1;
- geometry->xf_longest_edge(x0, y0, x1, y1);
+ geometry->LongestEdge(geometry->xf_buffer(), x0, y0, x1, y1);
rotation = atan2(y1 - y0, x1 - x0); //TODO: this is probably affected by which way y goes in the renderer (yUp or yDown)
if (rotation < 0)
rotation += 2*M_PI;
@@ -319,9 +320,15 @@
SE_RenderPolyline* rp = (SE_RenderPolyline*)rsym;
rp->weight = p->weight.evaluate(m_exec)*mm2px;
rp->geometry = p->geometry;
- rp->geometry->Transform(xform, rp->weight);
- rp->bounds = p->geometry->xf_bounds();
rp->color = p->color.evaluate(m_exec);
+ /* Defer transformation */
+ if (sym->resize != GraphicElement::AdjustToResizeBox)
+ {
+ rp->geometry->Transform(xform, rp->weight);
+ rp->bounds = p->geometry->xf_bounds();
+ }
+ else
+ rp->bounds = NULL;
}
break;
case SE_TextPrimitive:
@@ -449,15 +456,20 @@
if (rsym)
{
- if (renderStyle->bounds)
+ rsym->resize = sym->resize == GraphicElement::AdjustToResizeBox;
+
+ if (!rsym->resize)
{
- SE_Bounds* bounds = renderStyle->bounds;
- renderStyle->bounds = bounds->Union(rsym->bounds);
- bounds->Free();
+ if (renderStyle->bounds)
+ {
+ SE_Bounds* bounds = renderStyle->bounds;
+ renderStyle->bounds = bounds->Union(rsym->bounds);
+ bounds->Free();
+ }
+ else
+ renderStyle->bounds = rsym->bounds->Clone();
}
- else
- renderStyle->bounds = rsym->bounds->Clone();
- rsym->resize = sym->resize == GraphicElement::AdjustToResizeBox;
+
renderStyle->symbol.push_back(rsym);
if (style->useBox && sym->resize == GraphicElement::AddToResizeBox)
@@ -482,54 +494,62 @@
growy = growx;
}
- if (growx != 0 || growy != 0)
+ SE_Matrix totalxf(xform);
+ SE_Matrix growxf;
+ growxf.translate(-dx, -dy);
+ growxf.scale(1.0 + growx, 1.0 + growy);
+ growxf.translate(dx, dy);
+ totalxf.premultiply(growxf);
+
+ for (SE_RenderSymbol::iterator rs = renderStyle->symbol.begin(); rs != renderStyle->symbol.end(); rs++)
{
- SE_Matrix totalxf(xform);
- SE_Matrix growxf;
- growxf.translate(-dx, -dy);
- growxf.scale(1.0 + growx, 1.0 + growy);
- growxf.translate(dx, dy);
- totalxf.premultiply(growxf);
-
- for (SE_RenderSymbol::iterator rs = renderStyle->symbol.begin(); rs != renderStyle->symbol.end(); rs++)
+ SE_RenderPrimitive* rsym = *rs;
+ if (rsym->resize)
{
- SE_RenderPrimitive* rsym = *rs;
- if (rsym->resize)
+ switch(rsym->type)
{
- switch(rsym->type)
+ case SE_PolygonPrimitive:
+ case SE_PolylinePrimitive:
{
- case SE_PolygonPrimitive:
- case SE_PolylinePrimitive:
- {
- SE_RenderPolyline* rp = (SE_RenderPolyline*)rsym;
- rp->geometry->Transform(totalxf, rp->weight);
- rp->bounds = rp->geometry->xf_bounds();
- break;
- }
- case SE_TextPrimitive:
- {
- SE_RenderText* rt = (SE_RenderText*)rsym;
- growxf.transform(rt->position[0], rt->position[1]);
- rt->tdef.font().height() *= growxf.y1;
- break;
- }
- case SE_RasterPrimitive:
- {
- SE_RenderRaster* rr = (SE_RenderRaster*)rsym;
- growxf.transform(rr->position[0], rr->position[1]);
- rr->extent[0] *= growxf.x0;
- rr->extent[1] *= growxf.y1;
- break;
- }
+ SE_RenderPolyline* rp = (SE_RenderPolyline*)rsym;
+ rp->geometry->Transform(totalxf, rp->weight);
+ rp->bounds = rp->geometry->xf_bounds();
+ break;
}
+ case SE_TextPrimitive:
+ {
+ SE_RenderText* rt = (SE_RenderText*)rsym;
+ growxf.transform(rt->position[0], rt->position[1]);
+ rt->tdef.font().height() *= growxf.y1;
+ rt->bounds->Transform(growxf);
+ break;
+ }
+ case SE_RasterPrimitive:
+ {
+ SE_RenderRaster* rr = (SE_RenderRaster*)rsym;
+ growxf.transform(rr->position[0], rr->position[1]);
+ rr->extent[0] *= growxf.x0;
+ rr->extent[1] *= growxf.y1;
+ rr->bounds->Transform(growxf);
+ break;
+ }
}
+
+ if (renderStyle->bounds)
+ {
+ SE_Bounds* bounds = renderStyle->bounds;
+ renderStyle->bounds = bounds->Union(rsym->bounds);
+ bounds->Free();
+ }
+ else
+ renderStyle->bounds = rsym->bounds->Clone();
}
}
}
}
-void StylizationEngine::LayoutCustomLabel(const std::wstring& positioningAlgo, SE_LineBuffer* geometry, SE_Matrix& xform, SE_Style* style, SE_RenderStyle* rstyle, double mm2px)
+void StylizationEngine::LayoutCustomLabel(const std::wstring& positioningAlgo, LineBuffer* geometry, SE_Matrix& xform, SE_Style* style, SE_RenderStyle* rstyle, double mm2px)
{
//here we decide which one to call based on the name of the positioning algorithm
if (positioningAlgo == L"EightSurrounding")
Modified: trunk/MgDev/Common/Stylization/StylizationEngine.h
===================================================================
--- trunk/MgDev/Common/Stylization/StylizationEngine.h 2007-03-08 18:09:45 UTC (rev 1179)
+++ trunk/MgDev/Common/Stylization/StylizationEngine.h 2007-03-08 19:26:42 UTC (rev 1180)
@@ -59,7 +59,7 @@
SE_RenderAreaStyle* EvaluateAreaStyle(SE_Matrix& xform, SE_AreaStyle* style);
SE_RenderLineStyle* EvaluateLineStyle(SE_Matrix& xform, SE_LineStyle* style);
- void LayoutCustomLabel(const std::wstring& positioningAlgo, SE_LineBuffer* geometry, SE_Matrix& xform, SE_Style* style, SE_RenderStyle* rstyle, double mm2px);
+ void LayoutCustomLabel(const std::wstring& positioningAlgo, LineBuffer* geometry, SE_Matrix& xform, SE_Style* style, SE_RenderStyle* rstyle, double mm2px);
void EvaluateSymbols(SE_Matrix& xform, SE_Style* style, SE_RenderStyle* renderStyle, double mm2px);
SE_Renderer* m_renderer;
RS_FilterExecutor* m_exec;
More information about the mapguide-commits
mailing list