25 #include <QMouseEvent> 46 IndependentCubeViewport::IndependentCubeViewport(Cube * cube,
47 CubeDataThread * cdt,
QWidget * parent) :
48 CubeViewport(cube, cdt, parent)
50 panningPrevPoint = NULL;
54 panningPrevPoint =
new QPoint;
55 bandingPoint1 =
new QPoint;
56 bandingPoint2 =
new QPoint;
62 viewport()->setMouseTracking(
true);
66 IndependentCubeViewport::~IndependentCubeViewport()
70 delete panningPrevPoint;
71 panningPrevPoint = NULL;
93 QMouseEvent *m = (QMouseEvent *) e;
94 QPoint currentPosition(m->pos());
95 Qt::MouseButton b = (Qt::MouseButton)(m->button() + m->modifiers());
105 case QEvent::MouseMove:
108 emit synchronize(
this);
110 handleMouseMove(currentPosition);
119 case QEvent::MouseButtonPress:
121 handleMousePress(currentPosition, b);
124 case QEvent::MouseButtonRelease:
126 handleMouseRelease(currentPosition);
127 emit synchronize(
this);
138 return QAbstractScrollArea::eventFilter(o, e);
148 QPainter painter(viewport());
149 painter.drawPixmap(0, 0, p_pixmap);
153 QPen pen(QColor(255, 0, 0));
154 pen.setStyle(Qt::SolidLine);
156 painter.drawRect(bandingRect());
165 Stretch globalStretch = grayStretch();
167 stretchGray(globalStretch);
171 void IndependentCubeViewport::showEvent(QShowEvent * event)
173 QAbstractScrollArea::show();
176 restretch(grayBuffer());
180 void IndependentCubeViewport::resetKnownGlobal()
183 p_globalStretches->clear();
184 for (
int i = 0; i < cubeBands(); i++)
185 p_globalStretches->append(NULL);
188 grayBuffer()->addStretchAction();
192 void IndependentCubeViewport::cubeDataChanged(
int cubeId,
200 data->
Band() == grayBand() &&
204 Stretch *& globalStretch = (*p_globalStretches)[data->
Band() - 1];
208 delete globalStretch;
209 globalStretch = NULL;
213 Stretch newGlobal = grayStretch();
214 newGlobal.ClearPairs();
218 if (stats.ValidPixels() > 1 &&
219 fabs(stats.Minimum() - stats.Maximum()) > DBL_EPSILON)
221 Histogram hist(stats.BestMinimum(), stats.BestMaximum(), 65536);
224 if (fabs(hist.Percent(0.5) - hist.Percent(99.5)) > DBL_EPSILON)
226 newGlobal.AddPair(hist.Percent(0.5), 0.0);
227 newGlobal.AddPair(hist.Percent(99.5), 255.0);
231 if (newGlobal.Pairs() == 0)
233 newGlobal.AddPair(-DBL_MAX, 0.0);
234 newGlobal.AddPair(DBL_MAX, 255.0);
237 globalStretch =
new Stretch(newGlobal);
240 stretchGray(newGlobal);
247 void IndependentCubeViewport::handleMouseMove(QPoint p)
251 QPoint diff = *panningPrevPoint - p;
252 *panningPrevPoint = p;
253 scrollBy(diff.x(), diff.y());
260 viewport()->repaint();
268 void IndependentCubeViewport::handleMousePress(QPoint p, Qt::MouseButton b)
270 bool ctrlPressed = ((b & Qt::ControlModifier) == Qt::ControlModifier);
271 bool shiftPressed = ((b & Qt::ShiftModifier) == Qt::ShiftModifier);
272 bool ctrlShiftPressed = ctrlPressed && shiftPressed;
273 leftClick = ((b & Qt::LeftButton) == Qt::LeftButton);
277 if (ctrlPressed && !shiftPressed)
284 if (ctrlShiftPressed)
287 *panningPrevPoint = p;
298 void IndependentCubeViewport::handleMouseRelease(QPoint p)
321 stretchKnownGlobal();
328 void IndependentCubeViewport::handleSynchronization(
329 IndependentCubeViewport * other)
334 int deltaWidth = other->viewport()->width() - viewport()->width();
335 int deltaHeight = other->viewport()->height() - viewport()->height();
337 double offsetXToCenter = deltaWidth / 2.0 + viewport()->width() / 2.0;
338 double offsetYToCenter = deltaHeight / 2.0 + viewport()->height() / 2.0;
340 double offsetSampsToCenter = offsetXToCenter / other->scale();
341 double offsetLinesToCenter = offsetYToCenter / other->scale();
343 double otherSS, otherSL;
344 other->viewportToCube(0, 0, otherSS, otherSL);
346 double thisCenterSamp = otherSS + offsetSampsToCenter;
347 double thisCenterLine = otherSL + offsetLinesToCenter;
349 if (scale() == other->scale())
350 center(thisCenterSamp, thisCenterLine);
352 setScale(other->scale(), thisCenterSamp, thisCenterLine);
356 QRect IndependentCubeViewport::bandingRect()
359 rect.setTop(qMin(bandingPoint1->y(), bandingPoint2->y()));
360 rect.setLeft(qMin(bandingPoint1->x(), bandingPoint2->x()));
361 rect.setBottom(qMax(bandingPoint1->y(), bandingPoint2->y()));
362 rect.setRight(qMax(bandingPoint1->x(), bandingPoint2->x()));
368 void IndependentCubeViewport::stretch()
370 QRect rect(bandingRect());
371 if (rect.width() == 0 || rect.height() == 0)
376 newStretch = grayStretch();
379 stretchGray(newStretch);
382 void IndependentCubeViewport::track(
const QPoint & p)
384 if (grayBuffer()->working())
386 emit cantTrack(
"busy",
this);
391 viewportToCube(p.x(), p.y(), sample, line);
401 if (sample >= 0.5 && sample <= cubeSamples() + 0.5 &&
402 line >= 0.5 && line <= cubeLines() + 0.5 &&
403 trackBuffer(grayBuffer(), p, dn))
405 bool camSucceeds = camera() && camera()->SetImage(sample, line);
406 bool projSucceeds = !camSucceeds && projection() &&
407 projection()->SetWorld(sample, line);
411 if (projSucceeds) projType = projection()->projectionType();
413 if (camSucceeds || projSucceeds)
420 lat = camera()->UniversalLatitude();
421 lon = camera()->UniversalLongitude();
427 TProjection *tproj = (TProjection *) projection();
428 lat = tproj->Latitude();
429 lon = tproj->Longitude();
432 RingPlaneProjection *rproj = (RingPlaneProjection *) projection();
433 lat = rproj->RingRadius();
434 lon = rproj->RingLongitude();
438 emit trackingChanged(sample, line, lat, lon, dn,
this);
442 emit trackingChanged(sample, line, dn,
this);
447 emit cantTrack(
"n/a",
this);
452 bool IndependentCubeViewport::trackBuffer(ViewportBuffer * buffer,
453 const QPoint & p,
double & dn)
455 const QRect rect(buffer->bufferXYRect());
456 bool success = rect.contains(p,
true);
459 const int bufX = p.x() - rect.left();
460 const int bufY = p.y() - rect.top();
461 dn = buffer->getLine(bufY)[bufX];
468 void IndependentCubeViewport::zoom()
476 QRect rect = bandingRect();
484 if (rect.topLeft() == rect.bottomRight())
489 factor = 1.0 / factor;
491 scale = this->scale() * factor;
495 if ((rect.width() < 5) || (rect.height() < 5))
497 viewport()->repaint();
501 x += rect.width() / 2;
502 y += rect.height() / 2;
503 double xscale = (double) viewport()->width() / (double) rect.width();
504 double yscale = (double) viewport()->height() / (double) rect.height();
505 scale = xscale < yscale ? xscale : yscale;
510 scale *= this->scale();
514 setScale(scale, x, y);
double * DoubleBuffer() const
Returns the value of the shape buffer.
Reads and stores visible DN values.
int Band(const int index=0) const
Returns the band position associated with a shape buffer index.
void paintEvent(QPaintEvent *e)
Repaint the viewport.
void restretch(ViewportBuffer *)
This is called by internal viewport buffers when a stretch action should be performed.
Buffer for containing a three dimensional section of an image.
Namespace for the standard library.
int LineDimension() const
Returns the number of lines in the shape buffer.
int size() const
Returns the total number of pixels in the shape buffer.
bool eventFilter(QObject *o, QEvent *e)
Event filter to watch for mouse events on viewport.
int Sample(const int index=0) const
Returns the sample position associated with a shape buffer index.
void CopyPairs(const Stretch &other)
Copies the stretch pairs from another Stretch object, but maintains special pixel values...
int BandDimension() const
Returns the number of bands in the shape buffer.
int Line(const int index=0) const
Returns the line position associated with a shape buffer index.
int SampleDimension() const
Returns the number of samples in the shape buffer.
virtual void cubeDataChanged(int cubeId, const Isis::Brick *)
This method updates the internal viewport buffer based on changes in cube DN values.
Namespace for ISIS/Bullet specific routines.
virtual void paintEvent(QPaintEvent *e)
Repaint the viewport.
ProjectionType
This enum defines the subclasses of Projection supported in Isis.
void showEvent(QShowEvent *)
This method is called to initially show the viewport.
These projections are used to map triaxial and irregular-shaped bodies.