1 #include "MosaicSceneItem.h"
6 #include <QApplication>
9 #include <QGraphicsItem>
10 #include <QGraphicsSceneContextMenuEvent>
15 #include <QStyleOptionGraphicsItem>
16 #include <QTreeWidgetItem>
19 #include "DisplayProperties.h"
20 #include "FileDialog.h"
23 #include "ImageList.h"
27 #include "MosaicGraphicsView.h"
28 #include "MosaicSceneWidget.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");
591 connect(removeAction, SIGNAL(triggered()),
592 m_image, SLOT(deleteLater()));
594 menu.exec(event->screenPos());
600 void MosaicSceneItem::lostCubeDisplay() {
611 if (childItems().count()) {
612 setFlag(QGraphicsItem::ItemIsSelectable,
false);
615 setFlag(QGraphicsItem::ItemIsSelectable, m_scene->cubesSelectable());
621 foreach(QAbstractGraphicsShapeItem *polygon, *m_polygons) {
624 polygon->setBrush(color());
627 polygon->setBrush(Qt::NoBrush);
631 QColor opaqueColor(color());
632 opaqueColor.setAlpha(255);
635 QPen pen(opaqueColor);
636 pen.setCosmetic(
true);
637 polygon->setPen(pen);
640 polygon->setPen(Qt::NoPen);
643 polygon->setFlag(QGraphicsItem::ItemIsSelectable,
644 m_scene->cubesSelectable());
648 polyChild->setVisible(
651 polyChild->setFlag(QGraphicsItem::ItemIsSelectable,
652 m_scene->cubesSelectable());
656 if(polyChild->type() == 9) {
657 QGraphicsSimpleTextItem * text =
658 (QGraphicsSimpleTextItem *)polyChild;
659 text->setBrush(opaqueColor);
665 emit changed(regionsChanged);
678 if (m_cubeDnStretch != NULL || !m_image)
return m_cubeDnStretch;
689 stats.
AddData(mgr.DoubleBuffer(), mgr.size());
691 for(
int i = 0; i < skip; i++)
695 m_cubeDnStretch =
new Stretch();
700 m_cubeDnStretch->
SetLis(0.0);
701 m_cubeDnStretch->
SetLrs(0.0);
702 m_cubeDnStretch->
SetHis(255.0);
703 m_cubeDnStretch->
SetHrs(255.0);
704 m_cubeDnStretch->SetMinimum(0.0);
705 m_cubeDnStretch->SetMaximum(255.0);
707 return m_cubeDnStretch;
QVariant getValue(int property) const
Get a property's associated data.
double WorldX() const
This returns the world X coordinate provided SetGround, SetCoordinate, SetUniversalGround, or SetWorld returned with success.
True if the cube should show a fill area if possible (bool)
Internalizes a list of images and allows for operations on the entire list.
const double Null
Value for an Isis Null pixel.
void updateSelection(bool)
Update the selected state.
void reproject()
Called anytime the user reprojects the cube.
The main project for cnetsuite.
geos::geom::MultiPolygon * m_180mp
This item's multipolygon in the -180/180 longitude domain.
QList< QAction * > supportedActions(DataType data)
Returns a list of supported actions for a WorkOrder.
PixelType pixelType() const
Isis::Camera * Camera() const
Return the camera associated with the ground map (NULL implies none)
geos::geom::MultiPolygon * m_mp
This item's multipolygon in the 0/360 longitude domain.
double Map(const double value) const
Maps an input value to an output value based on the stretch pairs and/or special pixel mappings...
Base class for Map TProjections.
double BestMaximum(const double percent=99.5) const
This method returns the better of the absolute maximum or the Chebyshev maximum.
void drawImage(QPainter *painter, const QStyleOptionGraphicsItem *option)
This method reads in and draws the image associated with this item.
void SetLis(const double value)
Sets the mapping for LIS pixels.
bool InCube()
This returns true if the current Sample() or Line() value is outside of the cube (meaning the point m...
Buffer for containing a three dimensional section of an image.
double XCoord() const
This returns the projection X provided SetGround, SetCoordinate, SetUniversalGround, or SetWorld returned with success.
void SetBasePosition(const int start_sample, const int start_line, const int start_band)
This method is used to set the base position of the shape buffer.
True if the cube should be outlined (bool)
void setSelected(bool)
Change the selected state associated with this cube.
void read(Blob &blob) const
This method will read data from the specified Blob object.
Project * project() const
Gets the Project for this directory.
True if the cube should show DN values if possible (bool)
bool begin()
Moves the shape buffer to the first position.
True if the cube should show its display name (bool)
Buffer manager, for moving through a cube in lines.
This class is used to accumulate statistics on double arrays.
QList< QAction * > supportedActions(Project *project=NULL)
Gets a list of pre-connected actions that have to do with display.
void AddPair(const double input, const double output)
Adds a stretch pair to the list of pairs.
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
The user right clicked on us (or otherwise requested a context menu).
This is the GUI communication mechanism for cubes.
void SetHrs(const double value)
Sets the mapping for HRS pixels.
QString displayName() const
Returns the display name.
void SetLrs(const double value)
Sets the mapping for LRS pixels.
#define _FILEINFO_
Macro for the filename and line number.
void print() const
Prints a string representation of this exception to stderr.
void SetHis(const double value)
Sets the mapping for HIS pixels.
double Sample()
Returns the current sample number.
A type of error that could only have occurred due to a mistake on the user's part (e...
virtual bool SetGround(const double lat, const double lon)
This method is used to set the latitude/longitude (assumed to be of the correct LatitudeType, LongitudeDirection, and LongitudeDomain.
A type of error that cannot be classified as any of the other error types.
bool IsSpecial(const double d)
Returns if the input pixel is special.
This represents a cube in a project-based GUI interface.
ImageDisplayProperties * displayProperties()
Get the display (GUI) properties (information) associated with this image.
bool contains(const QPointF &) const
Test if we contain the point.
void append(Image *const &value)
Appends an image to the image list.
bool Has180Domain() const
This indicates if the longitude domain is -180 to 180 (as opposed to 0 to 360).
Property
This is a list of properties and actions that are possible.
double YCoord() const
This returns the projection Y provided SetGround, SetCoordinate, SetUniversalGround, or SetWorld returned with success.
Data ignored. Tells if the cube supports the zoomFit action.
Data ignored. Tells if the cube supports the "move*" actions.
void addSupport(int property)
Call this with every property you support, otherwise they will not communicate properly between widge...
double Line()
Returns the current line number.
geos::geom::MultiPolygon * footprint()
Get the footprint of this image (if available).
bool SetUniversalGround(double lat, double lon)
Returns whether the lat/lon position was set successfully in the camera model or projection.
virtual bool sceneEvent(QEvent *event)
This filters out events that happen within our polygons.
Cube * cube()
Get the Cube pointer associated with this display property.
The selection state of this cube (bool)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Re-paints the item.
Stretch * getStretch()
This gets a Stretch object that will work for the cubeDisplay converting from DN to screen pixel...
~MosaicSceneItem()
Mosaic Item destructor.
The color of the cube, default randomized (QColor)
double getPixelValue(int sample, int line)
Returns the pixel value at the given sample/line.
Isis::Projection * Projection() const
Return the projection associated with the ground map (NULL implies none)
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
double BestMinimum(const double percent=99.5) const
This method returns the better of the absolute minimum or the Chebyshev minimum.
void SetNull(const double value)
Sets the mapping for NULL pixels.
void updateChildren()
This applies the displayProperties and selectability.
void cubeDisplayChanged()
Someone changed something in the cube display properties, re-read the whole thing.
double WorldY() const
This returns the world Y coordinate provided SetGround, SetCoordinate, SetUniversalGround, or SetWorld returned with success.