Skip to content

Instantly share code, notes, and snippets.

@jumpinjackie
Last active May 31, 2019 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jumpinjackie/69c54ad0174bd7c0c22becae78da6e27 to your computer and use it in GitHub Desktop.
Save jumpinjackie/69c54ad0174bd7c0c22becae78da6e27 to your computer and use it in GitHub Desktop.
SE_Renderer template
#include "MyRenderer.h"
MyRenderer::MyRenderer()
: m_activeLayer(nullptr), m_mapInfo(nullptr), m_layerInfo(nullptr), m_fcInfo(nullptr)
{
}
MyRenderer::~MyRenderer()
{
//Do any member based cleanup
}
//Called by the stylizer when rendering is about to begin on the map
void MyRenderer::StartMap(RS_MapUIInfo * mapInfo, RS_Bounds & extents, double mapScale, double dpi, double metersPerUnit, CSysTransformer * xformToLL)
{
m_mapScale = mapScale;
m_dpi = dpi;
m_metersPerUnit = metersPerUnit;
m_extents = extents;
double metersPerPixel = METERS_PER_INCH / m_dpi;
//Uncomment code below to setup map to screen transforms
/*
// find scale used to convert to pixel coordinates
// need to take aspect ratios into account
double arDisplay = (double)m_width / (double)m_height;
double arMap = m_extents.width() / m_extents.height();
double scale;
if (arDisplay > arMap)
scale = (double)m_height / m_extents.height();
else
scale = (double)m_width / m_extents.width();
m_xform.x0 = scale;
m_xform.x1 = 0.0;
m_xform.x2 = -scale * m_extents.minx;
m_xform.y0 = 0.0;
m_xform.y1 = scale;
m_xform.y2 = -scale * m_extents.miny;
m_ixform.x0 = 1.0 / scale;
m_ixform.x1 = 0.0;
m_ixform.x2 = m_extents.minx;
m_ixform.y0 = 0.0;
m_ixform.y1 = m_ixform.x0;
m_ixform.y2 = m_extents.miny;
*/
// compute drawing scale
// drawing scale is map scale converted to [mapping units] / [pixels]
m_drawingScale = m_mapScale * metersPerPixel / m_metersPerUnit;
}
//Called by the stylizer when rendering is about to begin on the map
void MyRenderer::EndMap()
{
// clear the map info
m_mapInfo = nullptr;
}
//Called by the stylizer when rendering is about to begin on the map for the given layer
void MyRenderer::StartLayer(RS_LayerUIInfo * layerInfo, RS_FeatureClassInfo * classInfo)
{
m_layerInfo = layerInfo;
m_fcInfo = classInfo;
}
//Called by the stylizer when rendering is about to begin on the map for the layer indicated by StartLayer()
void MyRenderer::EndLayer()
{
// clear the layer/feature info
m_layerInfo = nullptr;
m_fcInfo = nullptr;
}
//Called by the stylizer when rendering is about to begin on the map for the given feature
void MyRenderer::StartFeature(RS_FeatureReader * feature, bool initialPass, const RS_String * tooltip, const RS_String * url, const RS_String * theme, double zOffset, double zExtrusion, RS_ElevationType zOffsetType)
{
}
//Entry point for polygon rendering. Perform any pre-rendering operations.
void MyRenderer::ProcessPolygon(LineBuffer * lb, RS_FillStyle & fill)
{
//This will generally result in a call to DrawScreenPolygon() after processing.
}
//Entry point for polyline rendering. Perform any pre-rendering operations.
void MyRenderer::ProcessPolyline(LineBuffer * lb, RS_LineStroke & lsym)
{
//This will generally result in a call to DrawScreenPolyline() after processing.
}
//Entry point for raster/image rendering. Perform any pre-rendering operations.
void MyRenderer::ProcessRaster(unsigned char * data, int length, RS_ImageFormat format, int width, int height, RS_Bounds & extents, TransformMesh * xformMesh)
{
//This will generally result in a call to DrawScreenRaster() after processing.
//
//If your renderer only concerns vector data, this method can be left blank
}
//Entry point for marker rendering. Perform any pre-rendering operations.
void MyRenderer::ProcessMarker(LineBuffer * lb, RS_MarkerDef & mdef, bool allowOverpost, RS_Bounds * bounds)
{
//Depending on the given marker definition, this will generally result in one or more calls to:
//
// - DrawScreenText
// - DrawScreenPolygon
// - DrawScreenPolyline
// - DrawScreenRaster (for image symbols)
}
//Entry point for label group rendering.
void MyRenderer::ProcessLabelGroup(RS_LabelInfo * labels, int nlabels, const RS_String & text, RS_OverpostType type, bool exclude, LineBuffer * path, double scaleLimit)
{
//Most implementations will carry a LabelRenderer member and forward this method call
//to it.
//
//If your renderer does not render labels, this method can be left blank
}
// Inserts the contents of a given DWF input stream into the current
// output W2D. The given coord sys transformation is applied and geometry
// will be clipped to the RS_Bounds context of the DWFRenderer.
void MyRenderer::AddDWFContent(RS_InputStream * in, CSysTransformer * xformer, const RS_String & section, const RS_String & passwd, const RS_String & w2dfilter)
{
// This is data from a DWF drawing layer. If your renderer is not intended to support DWF
// drawing layers/sources, this method can be left blank.
}
//Sets the legacy symbol manager which will be used when fetching (DWF) symbol data
void MyRenderer::SetSymbolManager(RS_SymbolManager * manager)
{
//If your renderer does not render DWF-based image symbols, this method can be left blank
}
RS_MapUIInfo * MyRenderer::GetMapInfo()
{
return m_mapInfo;
}
RS_LayerUIInfo * MyRenderer::GetLayerInfo()
{
return m_layerInfo;
}
RS_FeatureClassInfo * MyRenderer::GetFeatureClassInfo()
{
return m_fcInfo;
}
double MyRenderer::GetMapScale()
{
return m_mapScale;
}
double MyRenderer::GetDrawingScale()
{
return m_drawingScale;
}
double MyRenderer::GetMetersPerUnit()
{
return m_metersPerUnit;
}
double MyRenderer::GetDpi()
{
return m_dpi;
}
RS_Bounds & MyRenderer::GetBounds()
{
return m_extents;
}
bool MyRenderer::RequiresClipping()
{
return false;
}
bool MyRenderer::RequiresLabelClipping()
{
return false;
}
//Return true if this renderer can handle 3D geometries
bool MyRenderer::SupportsZ()
{
return false;
}
//Render out the given polyline using the provided fill style
void MyRenderer::DrawScreenPolyline(LineBuffer * polyline, const SE_Matrix * xform, const SE_LineStroke & lineStroke)
{
}
//Render out the given polygon using the provided fill style
void MyRenderer::DrawScreenPolygon(LineBuffer * polygon, const SE_Matrix * xform, unsigned int fill)
{
}
//Render out the given raster data.
void MyRenderer::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)
{
//If your renderer only concerns vector data, this method can be left blank
}
//Render out the given raster data.
void MyRenderer::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, double alpha)
{
//If your renderer only concerns vector data, this method can be left blank
}
//Render out the given text.
void MyRenderer::DrawScreenText(const RS_TextMetrics & tm, RS_TextDef & tdef, double insx, double insy, RS_F_Point * path, int npts, double param_position)
{
//If your renderer does not render labels, this method can be left blank
}
bool MyRenderer::YPointsUp()
{
return false;
}
void MyRenderer::GetWorldToScreenTransform(SE_Matrix & xform)
{
xform = m_xform;
}
void MyRenderer::WorldToScreenPoint(double & inx, double & iny, double & ox, double & oy)
{
m_xform.transform(inx, iny, ox, oy);
}
void MyRenderer::ScreenToWorldPoint(double & inx, double & iny, double & ox, double & oy)
{
m_ixform.transform(inx, iny, ox, oy);
}
double MyRenderer::GetScreenUnitsPerMillimeterDevice()
{
return m_dpi / MILLIMETERS_PER_INCH;
}
double MyRenderer::GetScreenUnitsPerMillimeterWorld()
{
return m_dpi / MILLIMETERS_PER_INCH / m_mapScale;
}
double MyRenderer::GetScreenUnitsPerPixel()
{
return 1.0;
}
RS_FontEngine * MyRenderer::GetRSFontEngine()
{
return NULL;
}
//Entry point for label rendering.
void MyRenderer::ProcessSELabelGroup(SE_LabelInfo * labels, int nlabels, RS_OverpostType type, bool exclude, LineBuffer * path)
{
//Most implementations will carry a LabelRenderer member and forward this method call
//to it.
//
//If this render does not render labels, this method can be left blank.
}
//If this renderer can render labels, add and track the given exclusion region.
//An exclusion region is a region that should not factor into desired label/symbol placement.
void MyRenderer::AddExclusionRegion(RS_F_Point * fpts, int npts)
{
//Most implementations will carry a LabelRenderer member and forward this method call
//to it.
//
//If this renderer does not render labels. This method can be left blank.
}
#ifndef _MYRENDERER_H_
#define _MYRENDERER_H_
#include "Renderers.h"
#include "SE_Renderer.h"
class MyRenderer : public SE_Renderer
{
public:
RENDERERS_API MyRenderer();
RENDERERS_API virtual ~MyRenderer();
// Inherited via SE_Renderer
RENDERERS_API virtual void StartMap(RS_MapUIInfo * mapInfo, RS_Bounds & extents, double mapScale, double dpi, double metersPerUnit, CSysTransformer * xformToLL);
RENDERERS_API virtual void EndMap();
RENDERERS_API virtual void StartLayer(RS_LayerUIInfo * layerInfo, RS_FeatureClassInfo * classInfo);
RENDERERS_API virtual void EndLayer();
RENDERERS_API virtual void StartFeature(RS_FeatureReader * feature, bool initialPass, const RS_String * tooltip = NULL, const RS_String * url = NULL, const RS_String * theme = NULL, double zOffset = 0.0, double zExtrusion = 0.0, RS_ElevationType zOffsetType = RS_ElevationType_RelativeToGround);
RENDERERS_API virtual void ProcessPolygon(LineBuffer * lb, RS_FillStyle & fill);
RENDERERS_API virtual void ProcessPolyline(LineBuffer * lb, RS_LineStroke & lsym);
RENDERERS_API virtual void ProcessRaster(unsigned char * data, int length, RS_ImageFormat format, int width, int height, RS_Bounds & extents, TransformMesh * xformMesh = NULL);
RENDERERS_API virtual void ProcessMarker(LineBuffer * lb, RS_MarkerDef & mdef, bool allowOverpost, RS_Bounds * bounds = NULL);
RENDERERS_API virtual void ProcessLabelGroup(RS_LabelInfo * labels, int nlabels, const RS_String & text, RS_OverpostType type, bool exclude, LineBuffer * path, double scaleLimit);
RENDERERS_API virtual void AddDWFContent(RS_InputStream * in, CSysTransformer * xformer, const RS_String & section, const RS_String & passwd, const RS_String & w2dfilter);
RENDERERS_API virtual void SetSymbolManager(RS_SymbolManager * manager);
RENDERERS_API virtual RS_MapUIInfo * GetMapInfo();
RENDERERS_API virtual RS_LayerUIInfo * GetLayerInfo();
RENDERERS_API virtual RS_FeatureClassInfo * GetFeatureClassInfo();
RENDERERS_API virtual double GetMapScale();
RENDERERS_API virtual double GetDrawingScale();
RENDERERS_API virtual double GetMetersPerUnit();
RENDERERS_API virtual double GetDpi();
RENDERERS_API virtual RS_Bounds & GetBounds();
RENDERERS_API virtual bool RequiresClipping();
RENDERERS_API virtual bool RequiresLabelClipping();
RENDERERS_API virtual bool SupportsZ();
RENDERERS_API virtual void DrawScreenPolyline(LineBuffer * polyline, const SE_Matrix * xform, const SE_LineStroke & lineStroke);
RENDERERS_API virtual void DrawScreenPolygon(LineBuffer * polygon, const SE_Matrix * xform, unsigned int fill);
RENDERERS_API 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);
RENDERERS_API 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, double alpha);
RENDERERS_API virtual void DrawScreenText(const RS_TextMetrics & tm, RS_TextDef & tdef, double insx, double insy, RS_F_Point * path, int npts, double param_position);
RENDERERS_API virtual bool YPointsUp();
RENDERERS_API virtual void GetWorldToScreenTransform(SE_Matrix & xform);
RENDERERS_API virtual void WorldToScreenPoint(double & inx, double & iny, double & ox, double & oy);
RENDERERS_API virtual void ScreenToWorldPoint(double & inx, double & iny, double & ox, double & oy);
RENDERERS_API virtual double GetScreenUnitsPerMillimeterDevice();
RENDERERS_API virtual double GetScreenUnitsPerMillimeterWorld();
RENDERERS_API virtual double GetScreenUnitsPerPixel();
RENDERERS_API virtual RS_FontEngine * GetRSFontEngine();
RENDERERS_API virtual void ProcessSELabelGroup(SE_LabelInfo * labels, int nlabels, RS_OverpostType type, bool exclude, LineBuffer * path = NULL);
RENDERERS_API virtual void AddExclusionRegion(RS_F_Point * fpts, int npts);
private:
// map/layer/feature info
RS_MapUIInfo* m_mapInfo;
RS_LayerUIInfo* m_layerInfo;
RS_FeatureClassInfo* m_fcInfo;
//Uncomment members below if rendering to a "fixed" screen/surface, which would be the case for
//any image-based renderer
/*
SE_Matrix m_xform;
SE_Matrix m_ixform;
int m_width;
int m_height;
*/
RS_Bounds m_extents;
double m_drawingScale;
double m_metersPerUnit;
double m_dpi;
double m_mapScale;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment