All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PixmapItem.cpp
Go to the documentation of this file.
1 // TerraLib
2 #include "PixmapItem.h"
3 #include "AnimationScene.h"
4 #include "Animation.h"
5 #include "../canvas/MapDisplay.h"
6 #include "../canvas/Canvas.h"
7 
8 // Qt
9 #include <QtCore/QPropertyAnimation>
10 #include <QtGui/QPainter>
11 #include <QtCore/QVector>
12 
14  : te::qt::widgets::AnimationItem("", 0)
15 {
16 }
17 
18 te::qt::widgets::PixmapItem::PixmapItem(const QString& title, const QString& file, te::qt::widgets::MapDisplay* display)
19  : te::qt::widgets::AnimationItem(title, display)
20 {
21  setMatrix();
22 
23  m_dir = QDir(file);
24 
25  QFileInfo fi(file);
26  m_baseFile = fi.completeBaseName();
27  m_suffix = fi.suffix();
28 
29  if(m_suffix.isEmpty())
30  m_suffix = ".bin";
31 
32  for(size_t i = 0; i < 256; ++i)
33  m_lut[i] = QColor(i, i, i, 255);
34 }
35 
37 {
38 }
39 
40 void te::qt::widgets::PixmapItem::setImagePosition(const QPointF& p, const QRectF& dr)
41 {
42  QString f = m_files[0];
43  QString file = m_dir.path() + "/" + f;
44  QImage ima(file);
45 
46  te::gm::Envelope env = m_display->getExtent();
47  QRectF ar(env.m_llx, env.m_lly, env.getWidth(), env.getHeight());
48  double fat = ar.width() / dr.width();
49 
50  QRectF r(0, 0, ((double)ima.rect().width()/4.)/fat, ((double)ima.rect().height()/4.)/fat);
51  m_imaRect = m_matrix.inverted().mapRect(r);
52  m_imaRect.moveCenter(p);
53 }
54 
56 {
58  m_animationFiles.clear();
59 
60  te::dt::TimeInstant iTime = m_animation->m_temporalAnimationExtent.getInitialTimeInstant();
61  te::dt::TimeInstant fTime = m_animation->m_temporalAnimationExtent.getFinalTimeInstant();
62 
63  size_t ini = 0;
64  size_t size = m_time.size();
65  size_t fim = size;
66  for(size_t i = 0; i < size; ++i)
67  {
68  if(m_time[i] == iTime || m_time[i] > iTime)
69  {
70  ini = i;
71  break;
72  }
73  }
74  for(size_t i = size-1; i >= 0; --i)
75  {
76  if(m_time[i] == fTime || m_time[i] < fTime)
77  {
78  fim = i;
79  break;
80  }
81  }
82  size = fim - ini + 1;
83  size_t tfim = ini + size;
84 
85  for(size_t i = ini; i < tfim; ++i)
86  {
87  QString f = m_files[i];
88  m_animationFiles.push_back(f);
89  }
90 
91  if(m_SRID != m_display->getSRID())
92  {
93  te::gm::Envelope env(m_imaRect.left(), m_imaRect.top(), m_imaRect.right(), m_imaRect.bottom());
94  env.transform(m_SRID, m_display->getSRID());
95  m_imaRect = QRectF(env.m_llx, env.m_lly, env.getWidth(), env.getHeight());
96  }
97 }
98 
99 void te::qt::widgets::PixmapItem::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
100 {
101  unsigned int curTime = m_animation->currentTime();
102  if(m_curTimeDuration == curTime)
103  return;
104 
105  drawForward(curTime);
106 }
107 
108 void te::qt::widgets::PixmapItem::drawForward(const unsigned int& curTime)
109 {
110  m_pos = pos(); // image position
111  m_curTimeDuration = curTime;
112  calculateCurrentFile(curTime);
113  m_display->update();
114 }
115 
116 void te::qt::widgets::PixmapItem::erase(const unsigned int& curTime)
117 {
118  drawForward(curTime);
119 }
120 
122 {
123  calculateCurrentFile(m_curTimeDuration);
124  m_display->update();
125 }
126 
127 void te::qt::widgets::PixmapItem::calculateCurrentFile(const unsigned int& curTime)
128 {
129  double nt = (double)curTime / (double)m_duration;
130  int ind = m_animation->getAnimationDataIndex(nt);
131  QString f = m_animationFiles[ind];
132  m_currentImageFile = m_dir.path() + "/" + f;
133  m_curTimeDuration = curTime;
134 }
135 
137 {
138  QRect r = m_matrix.mapRect(m_imaRect).toRect();
139  return r;
140 }
141 
142 void te::qt::widgets::PixmapItem::setLUT(const std::vector<std::pair<int, QColor> >& tab)
143 {
144  size_t i = 0;
145  std::vector<std::pair<int, QColor> >::const_iterator it = tab.begin();
146  size_t v = (*it).first;
147  QColor c = (*it).second;
148  while(i <= 255)
149  {
150  while(i <= v)
151  m_lut[i++] = c;
152 
153  ++it;
154  if(it == tab.end())
155  break;
156 
157  v = (*it).first;
158  c = (*it).second;
159  }
160 
161  while(i <= 255)
162  m_lut[i++] = c;
163 
164 }
165 
166 //void te::qt::widgets::PixmapItem::reproject()
167 //{
168 //}
virtual void createAnimationDataInDisplayProjection()
Create Animation Item making reprojection if necessary.
void erase(const unsigned int &curTime)
Draw current pixmap item. curTime The animation current time.
Definition: PixmapItem.cpp:116
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *)
Paint a pixmap item.
Definition: PixmapItem.cpp:99
PixmapItem()
Empty Constructor.
Definition: PixmapItem.cpp:13
QDir m_dir
The image data directory.
Definition: PixmapItem.h:136
void createAnimationDataInDisplayProjection()
Create images making reprojection if necessary.
Definition: PixmapItem.cpp:55
void setLUT(const std::vector< std::pair< int, QColor > > &tab)
Sets the LUT. tab The LUT information.
Definition: PixmapItem.cpp:142
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
A widget to control the display of a set of layers.
Definition: MapDisplay.h:66
void setMatrix()
It sets the internal matrix.
A class to represent time instant.
Definition: TimeInstant.h:55
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
This file defines a class for a Animation Scene.
void setImagePosition(const QPointF &p, const QRectF &dr)
Definition: PixmapItem.cpp:40
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
void draw()
Draw the current pixmap item.
Definition: PixmapItem.cpp:121
This file defines a class for a Trajectory Animation.
std::map< uchar, QColor > m_lut
LUT.
Definition: PixmapItem.h:146
void drawForward(const unsigned int &curTime)
Draw current pixmap item. curTime The animation current time.
Definition: PixmapItem.cpp:108
QRect getRect()
It gets image rect in device coordinate.
Definition: PixmapItem.cpp:136
This file defines a class for a Pixmap Item.
This class is a dialog for the Pixmap Item.
Definition: AnimationItem.h:57
void calculateCurrentFile(const unsigned int &curTime)
Calculate current file.
Definition: PixmapItem.cpp:127
QString m_suffix
File suffix.
Definition: PixmapItem.h:144
QString m_baseFile
Base file name.
Definition: PixmapItem.h:143
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
Definition: Envelope.cpp:92
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
virtual ~PixmapItem()
Destructor It destructs a Pixmap Item.
Definition: PixmapItem.cpp:36