examples/qt/rastervisual/ReadPixelTool.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 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 ReadPixel.cpp
22 
23  \brief An example of MapDisplay Tool. The only purpose of this tool is to show how you can implement a new tool. Do not consider it as a final application.
24 */
25 
26 // Example
27 #include "ReadPixelTool.h"
28 
29 // TerraLib
30 #include <terralib/raster.h>
33 #include <terralib/se.h>
34 #include <terralib/geometry.h>
36 //#include <terralib/maptools/RasterLayer.h> // * Under revision *
41 #include <terralib/se/Utils.h>
42 
43 
44 // Qt
45 #include <QMouseEvent>
46 #include <QToolTip>
47 
48 // STL
49 #include <cassert>
50 
51 ReadPixelTool::ReadPixelTool(te::qt::widgets::MapDisplay* display, /*te::map::RasterLayer* layer,*/ QObject* parent)
52  : te::qt::widgets::AbstractTool(display, parent)
53 {
54  // * Under revision *
55  //assert(layer);
56  //m_layer = dynamic_cast<te::map::RasterLayer*>(layer);
57  //assert(m_layer);
58 }
59 
61 {
62 }
63 
65 {
66  if(e->button() != Qt::LeftButton)
67  return false;
68 
69  // Converts clicked point to world coordinates
70 #if QT_VERSION >= 0x050000
71  QPointF qpoint = m_display->transform(e->localPos());
72 #else
73  QPointF qpoint = m_display->transform(e->posF());
74 #endif
75 
76  // * Under revision *
77  //te::se::RasterSymbolizer* rs = (te::se::RasterSymbolizer*)m_layer->getRasterSymbolizer()->clone();
79 
80  // * Under revision *
81  //te::rst::Raster* raster = m_layer->getRaster();
82  te::rst::Raster* raster = 0;
83 
84  //create the raster transform
85  te::map::RasterTransform rt(raster, 0);
86 
87  double rMin, rMax;
88 
91  const std::complex<double>* cmin = rsMin->at(0).m_minVal;
92  const std::complex<double>* cmax = rsMax->at(0).m_maxVal;
93  rMin = cmin->real();
94  rMax = cmax->real();
95 
96  rt.setLinearTransfParameters(0, 255, rMin, rMax);
97 
98  //configure the raster transformation using the raster symbolizer
100 
101  rtc.configure();
102 
103  te::gm::Coord2D coord = raster->getGrid()->geoToGrid(qpoint.x(), qpoint.y());
104 
105  int x = te::rst::Round(coord.x);
106  int y = te::rst::Round(coord.y);
107 
108  if((x >=0 && x < (int)raster->getNumberOfColumns()) && (y >=0 && y < (int)raster->getNumberOfRows()))
109  {
110  QString information("<h2>Read Pixel</h2><ul>");
111 
112  information += "<h3>Location</h3>";
113 
114  QString column, line, xCoord, yCoord;
115  column.setNum(x);
116  line.setNum(y);
117  xCoord.setNum(qpoint.x());
118  yCoord.setNum(qpoint.y());
119 
120  information += "<li><b>" + QString("Line ") + ":</b> " + line + "</li>";
121  information += "<li><b>" + QString("Column ") + ":</b> " + column + "</li>";
122  information += "<li><b>" + QString("Coord X ") + ":</b> " + xCoord + "</li>";
123  information += "<li><b>" + QString("Coord Y ") + ":</b> " + yCoord + "</li>";
124 
125  information += "<h3>Original Values</h3>";
126 
127  for(size_t t = 0; t < raster->getNumberOfBands(); ++t )
128  {
129  double val;
130  raster->getValue(x, y, val, t);
131 
132  QString band, value;
133  band.setNum(t);
134  value.setNum(val);
135 
136  information += "<li><b>" + QString("Value for band ") + band + ":</b> " + value + "</li>";
137 
138  }
139 
140  te::color::RGBAColor color = rt.apply(x, y);
141 
142  information += "<h3>Transformed Values</h3>";
143 
144  QString red, green, blue, alpha;
145  red.setNum(color.getRed());
146  green.setNum(color.getGreen());
147  blue.setNum(color.getBlue());
148  alpha.setNum(color.getAlpha());
149 
150  QString rBand, gBand, bBand;
154 
155  information += "<li><b>" + QString("Red Channel: </b>") + rBand + "<b> - Value:</b> " + red + "</li>";
156  information += "<li><b>" + QString("Green Channel: </b>") + gBand + "<b> - Value:</b> " + green + "</li>";
157  information += "<li><b>" + QString("Blue Channel: </b>") + bBand + "<b> - Value:</b> " + blue + "</li>";
158  information += "<li><b>" + QString("Alpha Channel value") + ":</b> " + alpha + "</li>";
159 
160 
161  information += "<h3>Symbolizer</h3>";
162 
163  QString type;
164 
166  {
167  type = "RGB Composition";
168  }
170  {
171  type = "Gray Composition";
172  }
173  else
174  {
175  type = "Unknown Composition";
176  }
177 
178  QString opacity = te::se::GetString(rs->getOpacity()).c_str();
179  QString gain = te::se::GetString(rs->getGain()).c_str();
180  QString offset = te::se::GetString(rs->getOffset()).c_str();
181 
182  information += "<li><b>" + QString("Color Composition ") + ":</b> " + type + "</li>";
183  information += "<li><b>" + QString("Opacity Value ") + ":</b> " + opacity + "</li>";
184  information += "<li><b>" + QString("Gain Value ") + ":</b> " + gain + "</li>";
185  information += "<li><b>" + QString("Offset Value ") + ":</b> " + offset + "</li>";
186 
187  if(rs->getChannelSelection()->getRedChannel() &&
189  {
190  QString c;
192 
193  information += "<li><b>" + QString("Red Contrast") + ":</b> " + c + "</li>";
194  }
195 
196  if(rs->getChannelSelection()->getGreenChannel() &&
198  {
199  QString c;
201 
202  information += "<li><b>" + QString("Green Contraste") + ":</b> " + c + "</li>";
203  }
204 
205  if(rs->getChannelSelection()->getBlueChannel() &&
207  {
208  QString c;
210 
211  information += "<li><b>" + QString("Blue Contraste") + ":</b> " + c + "</li>";
212  }
213 
214  if(rs->getChannelSelection()->getGrayChannel() &&
216  {
217  QString c;
219 
220  information += "<li><b>" + QString("Gray Contraste") + ":</b> " + c + "</li>";
221  }
222 
223  information += "</ul>";
224 
225  // Show attributes
226  QToolTip::showText(QCursor::pos(), information, m_display, m_display->rect());
227  }
228 
229  return true;
230 }
A canvas built on top of Qt.
unsigned int band
ReadPixelTool(te::qt::widgets::MapDisplay *display, QObject *parent=0)
A Raster Transform is a class that defines functions to transform a styled raster.
double y
y-coordinate.
Definition: Coord2D.h:114
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:307
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
Utility functions for Symbology Enconding module.
double x
x-coordinate.
Definition: Coord2D.h:113
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
A singleton for keeping raster summaries (most statistics).
ParameterValue * getOffset() const
void configure()
Configure Transformation.
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:317
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:312
te::se::ChannelSelection * getChannelSelection() const
This file contains include headers for TerraLib Symbology Encoding module.
SelectedChannel * getRedChannel() const
A widget to control the display of a set of layers.
A Qt4 widget to control the display of a set of layers.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
SelectedChannel * getBlueChannel() const
void geoToGrid(const double &x, const double &y, double &col, double &row) const
Get the grid point associated to a spatial location.
void setLinearTransfParameters(double vmin, double vmax, double rmin, double rmax)
Set parameters of linear transformation.
unsigned int line
ParameterValue * getGain() const
virtual QPointF transform(const QPointF &p)
Transforms the given point, in screen coordinates, to a point in world coordinates.
static RasterSummaryManager & getInstance()
It returns a reference to the singleton instance.
An abstract class for raster data strucutures.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
ParameterValue * getOpacity() const
URI C++ Library.
Definition: Attributes.h:37
RasterSummary is just a typedef of a boost::ptr_vector.
TERASTEREXPORT int Round(double val)
Round a double value to a integer value.
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
Definition: RGBAColor.h:322
ColorCompositionType getColorCompositionType() const
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
Definition: RasterSummary.h:44
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
Grid * getGrid()
It returns the raster grid.
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the attribute value of a band of a cell.
void apply(double icol, double ilin, double ocol, double olin)
SelectedChannel * getGreenChannel() const
ContrastEnhancement * getContrastEnhancement() const
A Raster Transform configurer generates a Raster Transform given a RasterSymbolzier.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
A Raster Transform configurer generates a Raster Transform given a RasterSymbolzier.
MapDisplay * m_display
The map display associated with the tool.
Definition: AbstractTool.h:171
A Raster Transform is a class that defines functions to transform a styled raster.
This file contains include headers for the Vector Geometry model of TerraLib.
Calculate the min value.
SelectedChannel * getGrayChannel() const
Calculate the max value.
std::map< RGBChannels, short > & getRGBMap()
TESEEXPORT std::string GetString(const te::se::ParameterValue *param)
It gets the parameter value as a string.
This file contains several utility functions for dealing with STL containers.