All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LayerRenderer.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file LayerRenderer.cpp
22 
23  \brief It renders the objects associated to a Layer.
24  */
25 
26 // TerraLib
27 #include "../../common/STLUtils.h"
28 #include "../../datatype/Enums.h"
29 #include "../../geometry/LineString.h"
30 #include "../../geometry/Point.h"
31 #include "../../maptools/AbstractLayer.h"
32 #include "../../maptools/Canvas.h"
33 #include "../../maptools/CanvasConfigurer.h"
34 #include "../../maptools/MarkRendererManager.h"
35 #include "../../se/Mark.h"
36 #include "../../se/Style.h"
37 #include "../../se/Rule.h"
38 #include "../../se/Utils.h"
39 #include "../core/AbstractGraph.h"
40 #include "../core/Edge.h"
41 #include "../core/Vertex.h"
42 #include "../iterator/BoxIterator.h"
43 #include "../iterator/SequenceIterator.h"
44 #include "Layer.h"
45 #include "LayerRenderer.h"
46 
47 
49 {}
50 
52 {}
53 
55 {
56  // Is our business?
57  te::graph::Layer* l = dynamic_cast<Layer*>(layer);
58  assert(l);
59 
60  // The canvas configurer
61  te::map::CanvasConfigurer cc(canvas);
62 
63  // Gets the associated layer style
64  te::se::Style* style = l->getStyle();
65  if(style == 0)
66  {
67  configDefaultLine(canvas);
68  configDefaultPoint(canvas);
69  }
70  else
71  {
72  if(style->getRules().empty())
73  {
74  throw;
75  }
76  const te::se::Rule* rule = style->getRule(0);
77 
78  const std::vector<te::se::Symbolizer*> symbolizers = rule->getSymbolizers();
79 
80  for(size_t t= 0; t < symbolizers.size(); ++t)
81  {
82  te::se::Symbolizer* symb = symbolizers[t];
83 
84  cc.config(symb);
85  }
86  }
87 
89 
90  //set iterator
92 
93  te::gm::Envelope* box = new te::gm::Envelope(bbox);
94 
96 
97  g->setIterator(it);
98 
99  te::graph::Edge* edge = g->getFirstEdge();
100 
101  int vertexGeomPropIdx = checkVertexGeometryProperty(l);
102  int edgeGeomPropIdx = checkEdgeGeometryProperty(l);
103 
104  while(it->isEdgeIteratorAfterEnd() == false)
105  {
106  if(edge)
107  {
108  //draw vertex from and vertex to
109  te::graph::Vertex* vFrom = g->getVertex(edge->getIdFrom());
110  te::graph::Vertex* vTo = g->getVertex(edge->getIdTo());
111 
112  if(vFrom && vTo)
113  {
114  te::gm::Geometry* geomVFrom = (te::gm::Geometry*)vFrom->getAttributes()[vertexGeomPropIdx];
115  te::gm::Geometry* geomVTo = (te::gm::Geometry*)vTo->getAttributes()[vertexGeomPropIdx];
116 
117  //check if exist a geometry associated a edge... if not draw a simple line
118  if(edgeGeomPropIdx != -1)
119  {
120  te::gm::Geometry* geomEdge = (te::gm::Geometry*)edge->getAttributes()[edgeGeomPropIdx];
121 
122  canvas->draw(geomEdge);
123 
124  if(vFrom->getId() == vTo->getId())
125  {
126  canvas->draw(geomVFrom);
127  }
128  else
129  {
130  canvas->draw(geomVFrom);
131  canvas->draw(geomVTo);
132  }
133  }
134  else
135  {
136  if(vFrom->getId() == vTo->getId())
137  {
138  canvas->draw(geomVFrom);
139  }
140  else
141  {
142  te::gm::Point* pFrom = dynamic_cast<te::gm::Point*>(geomVFrom);
143  te::gm::Point* pTo = dynamic_cast<te::gm::Point*>(geomVTo);
144 
145  if(pFrom && pTo)
146  {
148  line->setPoint(0, pFrom->getX(), pFrom->getY());
149  line->setPoint(1, pTo->getX(), pTo->getY());
150 
151  canvas->draw(line);
152 
153  delete line;
154 
155  }
156 
157  canvas->draw(geomVFrom);
158  canvas->draw(geomVTo);
159  }
160  }
161  }
162  }
163  edge = g->getNextEdge();
164  }
165 
166  g->setIterator(oldIt);
167 
168  delete it;
169 }
170 
172 {
173  int idx = -1;
174 
176 
177  for(int i = 0; i < g->getVertexPropertySize(); ++i)
178  {
180  if(p && p->getType() == te::dt::GEOMETRY_TYPE)
181  {
182  idx = i;
183  break;
184  }
185  }
186 
187  return idx;
188 }
189 
191 {
192  int idx = -1;
193 
195 
196  for(int i = 0; i < g->getEdgePropertySize(); ++i)
197  {
199  if(p && p->getType() == te::dt::GEOMETRY_TYPE)
200  {
201  idx = i;
202  break;
203  }
204  }
205 
206  return idx;
207 }
208 
210 {
216 }
217 
219 {
220  te::se::Mark* mark = te::se::CreateMark("circle", te::se::CreateStroke("#000000", "2"), te::se::CreateFill("#FFFF00", "1.0"));
221  std::size_t size = 12;
224  canvas->setPointPattern(rgba, size, size);
225 
226  te::common::Free(rgba, size);
227  delete mark;
228 }
229 
231 {
232  te::se::Mark* mark = te::se::CreateMark("star", te::se::CreateStroke("#000000", "2"), te::se::CreateFill("#FFFF00", "1.0"));
233  std::size_t size = 12;
236  canvas->setPointPattern(rgba, size, size);
237 
238  te::common::Free(rgba, size);
239  delete mark;
240 }
const std::vector< Rule * > & getRules() const
Definition: Style.cpp:94
TESEEXPORT Fill * CreateFill(const std::string &color, const std::string &opacity)
Creates a fill.
Definition: Utils.cpp:107
Abstract class used to define the main functions of graph struct. All graph implementations must used...
Definition: AbstractGraph.h:56
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
Definition: Edge.h:58
virtual void setPointPattern(te::color::RGBAColor **pattern, int ncols, int nrows)=0
It sets the point pattern.
Rule * getRule(std::size_t i) const
Definition: Style.cpp:105
This is the base class for layers.
Definition: AbstractLayer.h:76
~LayerRenderer()
Destructor.
void setIterator(te::graph::AbstractIterator *i)
Used to associate a iterator to graph.
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
This class defines a commun interface to represents a graph iterator class. The main diferency to ano...
Definition: BoxIterator.h:71
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
Definition: Vertex.h:68
void config(const te::se::Symbolizer *symbolizer)
It configs the canvas based on given symbolizer.
A Layer is a reference to a virtual dataset with/without geometric attributes.
Definition: Layer.h:64
int getIdFrom()
It returns the vertex origin identification.
Definition: Edge.cpp:71
const std::vector< Symbolizer * > & getSymbolizers() const
Definition: Rule.cpp:152
#define TE_SE_DEFAULT_STROKE_BASIC_WIDTH
It specifies the default width used by stroke basic (solid colors).
Definition: Config.h:93
TESEEXPORT Mark * CreateMark(const std::string &wellKnownName, Stroke *stroke, Fill *fill)
Creates a mark.
Definition: Utils.cpp:128
virtual void draw(te::map::AbstractLayer *layer, te::map::Canvas *canvas, const te::gm::Envelope &bbox, int srid)
It draws the layer geographic objects in the given canvas using the informed SRS. ...
It renders the objects associated to a Layer.
int getIdTo()
It returns the vertex destiny identification.
Definition: Edge.cpp:76
#define TE_TRANSPARENT
For an RGBA color this is the value of the alpha-channel for totally transparent. ...
Definition: Config.h:46
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
virtual bool isEdgeIteratorAfterEnd()
Used to check the iterator position.
void configDefaultPoint(te::map::Canvas *canvas)
Configs the canvas with default values for point styles.
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:78
const double & getX() const
It returns the Point x-coordinate value.
Definition: Point.h:136
TESEEXPORT Stroke * CreateStroke(const std::string &color, const std::string &width)
Creates a stroke.
Definition: Utils.cpp:52
A Symbology Enconding visitor that configures a given canvas based on symbolizers elements...
virtual int getVertexPropertySize()=0
Used to verify the number of properties associated to vertex elements.
te::graph::Edge * getNextEdge()
It returns a pointer to the next edge element of a graph.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
This class defines a commun interface to represents a graph iterator class. The main diferency to ano...
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
int getId()
It returns the vertex id.
Definition: Vertex.cpp:69
A point with x and y coordinate values.
Definition: Point.h:50
te::graph::Edge * getFirstEdge()
It returns a pointer to the first edge element of a graph.
virtual te::se::Style * getStyle() const
It returns the Style associated to the layer.
virtual void setPointColor(const te::color::RGBAColor &color)=0
It sets the point drawing color.
int checkEdgeGeometryProperty(te::graph::Layer *l)
Verify if the graph layer has a geometry to define the edges elements.
#define TE_SE_DEFAULT_STROKE_BASIC_COLOR
It specifies the default color used by stroke basic (solid colors).
Definition: Config.h:86
void configDefaultLine(te::map::Canvas *canvas)
Configs the canvas with default values for line styles.
std::vector< te::dt::AbstractData * > & getAttributes()
It returns the vector of attributes associated with this element.
Definition: Vertex.cpp:74
te::graph::AbstractGraph * getGraph() const
It returns the graph associated to the layer.
Definition: Layer.cpp:66
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:65
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
Definition: LineString.cpp:313
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
Definition: Config.h:39
std::vector< te::dt::AbstractData * > & getAttributes()
It returns the vector of attributes associated with this element.
Definition: Edge.cpp:81
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
Definition: STLUtils.h:131
virtual void setLineCapStyle(LineCapStyle style)=0
It sets the line cap style.
virtual void setLineDashStyle(LineDashStyle style)=0
It sets the line dash style.
virtual void setLineJoinStyle(LineJoinStyle style)=0
It sets the line join style.
virtual void draw(const te::gm::Geometry *geom)=0
It draws the geometry on canvas.
virtual te::graph::Vertex * getVertex(int id)=0
It returns the vertex element if it&#39;s exist.
It models a property definition.
Definition: Property.h:59
virtual void setLineColor(const te::color::RGBAColor &color)=0
It sets the pen color used to draw line geometries.
int getType() const
It returns the property data type.
Definition: Property.h:143
void configLoopPoint(te::map::Canvas *canvas)
Configs the canvas with default values for point styles.
const double & getY() const
It returns the Point y-coordinate value.
Definition: Point.h:150
virtual int getEdgePropertySize()=0
Used to verify the number of properties associated to edge elements.
static MarkRendererManager & getInstance()
It returns a reference to the singleton instance.
int checkVertexGeometryProperty(te::graph::Layer *l)
Verify if the graph layer has a geometry to define the vertexs elements.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
virtual te::dt::Property * getEdgeProperty(int idx)=0
Get a edge property given a index.
te::graph::AbstractIterator * getIterator()
Used to get a iterator associated to graph.
virtual void setLineWidth(int w)=0
It sets the line width.
virtual te::dt::Property * getVertexProperty(int idx)=0
Get a vertex property given a index.
A Mark specifies a geometric shape and applies coloring to it.
Definition: Mark.h:84