1 #include "MosaicSceneItem.h"
6 #include <QApplication>
9 #include <QGraphicsItem>
10 #include <QGraphicsSceneContextMenuEvent>
15 #include <QStyleOptionGraphicsItem>
16 #include <QTreeWidgetItem>
18 #include "Directory.h"
19 #include "DisplayProperties.h"
20 #include "FileDialog.h"
21 #include "Histogram.h"
23 #include "ImageList.h"
24 #include "ImagePolygon.h"
26 #include "LineManager.h"
27 #include "MosaicGraphicsView.h"
28 #include "MosaicSceneWidget.h"
29 #include "PolygonTools.h"
31 #include "SerialNumber.h"
32 #include "Statistics.h"
35 #include "TProjection.h"
37 using namespace geos::geom;
48 if (parent->getProjection() == NULL) {
49 std::string msg =
"Parent does not have projection in MosaicWidget";
55 connect(m_image, SIGNAL(destroyed(
QObject *)),
56 this, SLOT(lostCubeDisplay()));
57 connect(m_image, SIGNAL(destroyed(
QObject *)),
58 this, SLOT(deleteLater()));
62 m_cubeDnStretch = NULL;
64 m_showingLabel =
false;
65 m_ignoreCubeDisplayChanged =
false;
75 setAcceptHoverEvents(
true);
87 if(parent->userHasTools()) {
105 scene()->removeItem(
this);
107 while(m_polygons->size()) {
108 delete m_polygons->takeAt(0);
113 QRectF MosaicSceneItem::boundingRect()
const {
116 QGraphicsPolygonItem *polygon;
117 foreach(polygon, *m_polygons) {
118 boundingRect = boundingRect.united(polygon->boundingRect());
121 foreach(polyChild, polygon->childItems()) {
122 if(polyChild->isVisible()) {
123 boundingRect = boundingRect.united(
124 mapFromItem(polyChild, polyChild->boundingRect()).boundingRect());
141 const QStyleOptionGraphicsItem *option,
QWidget *widget) {
149 if (!childItems().count()) {
150 foreach (QGraphicsPolygonItem *polyItem, *m_polygons) {
151 polyItem->paint(painter, option, widget);
160 void MosaicSceneItem::setupFootprint() {
166 tr(
"Cannot display footprints of images which have no footprints. "
174 catch(IException &e) {
175 m_image->deleteLater();
177 IString msg =
"Could not project the footprint from cube [" +
190 prepareGeometryChange();
196 while(m_polygons->size()) {
197 QGraphicsPolygonItem *polyItem = m_polygons->at(0);
199 if (polyItem->scene()) {
200 polyItem->scene()->removeItem(polyItem);
202 m_polygons->removeAll(polyItem);
224 bool useFullChildrenHierarchy = (mp->getNumGeometries() > 1) || m_showingLabel;
226 for (
unsigned int i = 0; i < mp->getNumGeometries(); i++) {
227 const Geometry *geom = mp->getGeometryN(i);
228 CoordinateSequence *pts;
230 pts = geom->getCoordinates();
238 for (
unsigned int j = 0; j < pts->getSize(); j++) {
242 double x = proj->
XCoord();
243 double y = -1 * (proj->
YCoord());
245 polyPoints.push_back(QPointF(x, y));
249 setFlag(QGraphicsItem::ItemIsSelectable,
true);
250 setFlag(QGraphicsItem::ItemIsFocusable,
true);
252 QGraphicsPolygonItem *polyItem = NULL;
254 if (useFullChildrenHierarchy) {
255 polyItem =
new QGraphicsPolygonItem(
this);
258 polyItem =
new QGraphicsPolygonItem;
261 polyItem->setPolygon(QPolygonF(polyPoints));
263 if (m_showingLabel) {
264 QGraphicsSimpleTextItem *label = NULL;
266 label =
new QGraphicsSimpleTextItem(polyItem);
270 label->setFlag(QGraphicsItem::ItemIsMovable);
271 label->setFont(QFont(
"Helvetica", 10));
272 label->setPos(polyItem->polygon().boundingRect().center());
273 label->setFlag(QGraphicsItem::ItemIgnoresTransformations,
true);
275 QRectF boundingRect = polyItem->boundingRect();
276 if(boundingRect.width() < boundingRect.height())
277 label->setRotation(90.0);
280 m_polygons->append(polyItem);
299 double pixelValue = 0;
306 pixelValue = gryBrick[0];
307 if (pixelValue ==
Null) {
310 if (pixelValue < 0) pixelValue = 0;
311 if (pixelValue > 255) pixelValue = 255;
324 const QStyleOptionGraphicsItem *option) {
326 QApplication::setOverrideCursor(Qt::WaitCursor);
329 QGraphicsPolygonItem *polygon;
330 foreach(polygon, *m_polygons) {
331 QPolygonF polyBounding = polygon->polygon();
332 QRectF sceneRect = polyBounding.boundingRect();
333 QPolygon screenPoly = m_scene->getView()->mapFromScene(sceneRect);
334 QRect visibleBox = screenPoly.boundingRect();
336 int bbWidth = (int)visibleBox.width();
337 int bbHeight = (int)visibleBox.height();
339 int bbLeft = visibleBox.left();
340 int bbTop = visibleBox.top();
341 int bbRight = visibleBox.right();
342 int bbBottom = visibleBox.bottom();
344 QImage image(bbWidth, bbHeight, QImage::Format_ARGB32);
346 for (
int y = bbTop; y <= bbBottom; y++) {
347 QRgb *lineData = (QRgb *)image.scanLine(y - bbTop);
349 for (
int x = bbLeft; x <= bbRight; x++) {
350 lineData[x - bbLeft] = qRgba(0, 0, 0, 0);
354 QPointF scenePos = m_scene->getView()->mapToScene(
357 if(polygon->polygon().containsPoint(scenePos, Qt::OddEvenFill)) {
360 m_scene->getProjection()->SetCoordinate(scenePos.x(),
363 double lat = ((
TProjection *)(m_scene->getProjection()))->UniversalLatitude();
364 double lon = ((
TProjection *)(m_scene->getProjection()))->UniversalLongitude();
390 int stretched = (int)stretch->
Map(dn);
392 lineData[x - bbLeft] = qRgba(stretched, stretched,
402 painter->drawImage(polygon->boundingRect(), image);
409 QApplication::restoreOverrideCursor();
413 QColor MosaicSceneItem::color()
const {
424 if (!m_ignoreCubeDisplayChanged) {
425 bool wasBlocking = m_scene->blockSelectionChange(
true);
427 m_scene->blockSelectionChange(wasBlocking);
429 if (m_showingLabel !=
455 switch (event->type()) {
456 case QEvent::GraphicsSceneContextMenu:
457 scenePos = ((QGraphicsSceneContextMenuEvent *)event)->scenePos();
459 case QEvent::GraphicsSceneHoverEnter:
460 case QEvent::GraphicsSceneHoverMove:
461 case QEvent::GraphicsSceneHoverLeave:
462 scenePos = ((QGraphicsSceneHoverEvent *)event)->scenePos();
464 case QEvent::GraphicsSceneMouseMove:
465 case QEvent::GraphicsSceneMousePress:
466 case QEvent::GraphicsSceneMouseRelease:
467 case QEvent::GraphicsSceneMouseDoubleClick:
468 scenePos = ((QGraphicsSceneMouseEvent *)event)->scenePos();
474 bool ourEvent =
true;
475 if(!scenePos.isNull()) {
480 return QGraphicsObject::sceneEvent(event);
498 QGraphicsPolygonItem * polygon;
499 foreach(polygon, *m_polygons) {
500 if(polygon->contains(p)) {
517 QGraphicsPolygonItem * polygon;
519 m_ignoreCubeDisplayChanged =
true;
525 selected = isSelected();
528 foreach(polygon, *m_polygons) {
529 selected = selected || (polygon->scene() && polygon->isSelected());
535 if(selected != isSelected()) {
536 bool wasBlocking = m_scene->blockSelectionChange(
true);
537 setSelected(selected);
538 m_scene->blockSelectionChange(wasBlocking);
541 foreach(polygon, *m_polygons) {
542 if(polygon->isSelected() != selected) {
543 polygon->setSelected(selected);
547 m_ignoreCubeDisplayChanged =
false;
557 QGraphicsSceneContextMenuEvent *event) {
563 title->setEnabled(
false);
569 Directory *directory = m_scene->directory();
575 displayActs.append(NULL);
580 foreach(displayAct, displayActs) {
581 if (displayAct == NULL) {
585 menu.addAction(displayAct);
590 QAction *removeAction = menu.addAction(
"Close Cube");
592 if (QApplication::applicationName() ==
"qmos") {
593 connect(removeAction, SIGNAL(triggered()),
594 m_image, SLOT(deleteLater()));
597 connect(removeAction, SIGNAL(triggered()), SLOT(
onCloseCube()));
600 menu.exec(event->screenPos());
606 void MosaicSceneItem::lostCubeDisplay() {
615 emit mosaicCubeClosed(m_image);
625 if (childItems().count()) {
626 setFlag(QGraphicsItem::ItemIsSelectable,
false);
629 setFlag(QGraphicsItem::ItemIsSelectable, m_scene->cubesSelectable());
635 foreach(QAbstractGraphicsShapeItem *polygon, *m_polygons) {
638 polygon->setBrush(color());
641 polygon->setBrush(Qt::NoBrush);
645 QColor opaqueColor(color());
646 opaqueColor.setAlpha(255);
649 QPen pen(opaqueColor);
650 pen.setCosmetic(
true);
651 polygon->setPen(pen);
654 polygon->setPen(Qt::NoPen);
657 polygon->setFlag(QGraphicsItem::ItemIsSelectable,
658 m_scene->cubesSelectable());
662 polyChild->setVisible(
665 polyChild->setFlag(QGraphicsItem::ItemIsSelectable,
666 m_scene->cubesSelectable());
670 if(polyChild->type() == 9) {
671 QGraphicsSimpleTextItem * text =
672 (QGraphicsSimpleTextItem *)polyChild;
673 text->setBrush(opaqueColor);
679 emit changed(regionsChanged);
692 if (m_cubeDnStretch != NULL || !m_image)
return m_cubeDnStretch;
705 for(
int i = 0; i < skip; i++)
709 m_cubeDnStretch =
new Stretch();
714 m_cubeDnStretch->
SetLis(0.0);
715 m_cubeDnStretch->
SetLrs(0.0);
716 m_cubeDnStretch->
SetHis(255.0);
717 m_cubeDnStretch->
SetHrs(255.0);
718 m_cubeDnStretch->SetMinimum(0.0);
719 m_cubeDnStretch->SetMaximum(255.0);
721 return m_cubeDnStretch;