12#include <QApplication>
21#include <QStackedWidget>
26#include "MdiCubeViewport.h"
27#include "RubberBandTool.h"
28#include "SpecialPixel.h"
61 action->setIcon(QPixmap(
toolIconDir() +
"/color_line.png"));
62 action->setToolTip(
"Image Edit (E)");
63 action->setShortcut(Qt::Key_E);
66 "<b>Function:</b> Edit active viewport \
67 <p><b>Shortcut:</b> E</p> ";
68 action->setWhatsThis(text);
86 container->setObjectName(
"EditToolActiveToolBarWidget");
98 "<b>Function:</b> The shape in the image that will be replaced with \
99 a new value. If Horizontal line is chosen, clicking anywhere on the \
100 image will cause all samples on that line of the cube to be replaced \
101 with the replacement value. If Vertical Line is chosen, a v ...";
117 "<b>Function:</b> The value which will be used to replace image data. ";
127 "<b>Function:</b> This is the dn used to replace image data";
136 "<b>Function:</b> Undo last edit operation";
146 "<b>Function:</b> Redo last undo operation";
157 "<b>Function:</b> Save any changes made, these changes are finalized";
168 "<b>Function:</b> Save any changes made to the file specified, these changes are finalized";
174 QHBoxLayout *layout =
new QHBoxLayout;
175 layout->setMargin(0);
183 layout->addStretch(1);
184 container->setLayout(layout);
186m_container = container;
265 if (vp == NULL)
return;
267 if (vp->cube()->isReadOnly()) {
269 QString fileName = vp->cube()->fileName();
273 vp->cube()->reopen(
"rw");
276 vp->cube()->open(fileName,
"r");
277 QMessageBox::information((
QWidget *)parent(),
"Error",
"Cannot open cube read/write");
282 QMessageBox::information((
QWidget *)parent(),
283 "Error",
"Cannot edit in color mode");
287 int issamp, isline, iesamp, ieline;
288 double ssamp, sline, esamp, eline;
289 QList<QPoint *> *linePts = NULL;
294 if (!rubberBandTool()->isValid())
return;
297 if ((r.width() < 1) || (r.height() < 1))
return;
299 vp->viewportToCube(r.left(), r.top(), ssamp, sline);
300 vp->viewportToCube(r.right(), r.bottom(), esamp, eline);
302 issamp = (int)(ssamp + 0.5);
303 isline = (int)(sline + 0.5);
304 iesamp = (int)(esamp + 0.5);
305 ieline = (int)(eline + 0.5);
308 if (issamp < 0) issamp = 0;
309 if (iesamp < 0) iesamp = 0;
310 if (isline < 0) isline = 0;
311 if (ieline < 0) ieline = 0;
313 if (issamp > vp->cubeSamples()) issamp = vp->cubeSamples();
314 if (iesamp > vp->cubeSamples()) iesamp = vp->cubeSamples();
315 if (isline > vp->cubeLines()) isline = vp->cubeLines();
316 if (ieline > vp->cubeLines()) ieline = vp->cubeLines();
319 if (issamp > iesamp || isline > ieline) {
320 QMessageBox::information((
QWidget *)parent(),
321 "Error",
"Rectangle is out of bounds");
328 if (!rubberBandTool()->isValid())
return;
329 vp->viewportToCube(rubberBandTool()->vertices()[0].rx(), rubberBandTool()->vertices()[0].ry(),
331 vp->viewportToCube(rubberBandTool()->vertices()[1].rx(), rubberBandTool()->vertices()[1].ry(),
334 QLine l((
int)ssamp, (
int)sline, (
int)esamp, (
int)eline);
339 if (linePts->empty()) {
340 QMessageBox::information((
QWidget *)parent(),
341 "Error",
"No points in edit line");
346 issamp = std::min(linePts->front()->x(), linePts->back()->x());
347 isline = std::min(linePts->front()->y(), linePts->back()->y());
348 iesamp = std::max(linePts->front()->x(), linePts->back()->x());
349 ieline = std::max(linePts->front()->y(), linePts->back()->y());
357 writeToCube(iesamp, issamp, ieline, isline, linePts);
358 if (linePts)
delete linePts;
362 connect(newViewport, SIGNAL(saveChanges(
CubeViewport *)),
364 connect(newViewport, SIGNAL(discardChanges(
CubeViewport *)),
366 connect(newViewport, SIGNAL(destroyed(
QObject *)),
399 if (vp == NULL)
return;
405 if (vp->cube()->isReadOnly()) {
408 QString fileName = vp->cube()->fileName();
413 vp->cube()->reopen(
"rw");
416 vp->cube()->open(fileName,
"r");
417 QMessageBox::information((
QWidget *)parent(),
"Error",
"Cannot open cube read/write");
422 QMessageBox::information((
QWidget *)parent(),
423 "Error",
"Cannot edit in color mode");
427 int issamp, isline, iesamp, ieline;
432 if (m == Qt::RightButton &&
435 vp->viewportToCube(p.x(), p.y(), ssamp, sline);
436 issamp = (int)(ssamp + 0.5);
437 isline = (int)(sline + 0.5);
439 vp->cube()->pixelType());
440 pntBrick->SetBasePosition(issamp, isline, vp->grayBand());
441 vp->cube()->read(*pntBrick);
442 p_dn = (*pntBrick)[0];
451 vp->viewportToCube(p.x(), p.y(), ssamp, sline);
452 if ((ssamp < 0.5) || (sline < 0.5) ||
453 (ssamp > vp->cubeSamples() + 0.5) || (sline > vp->cubeLines() + 0.5)) {
454 QApplication::beep();
457 issamp = (int)(ssamp + 0.5);
458 isline = (int)(sline + 0.5);
463 iesamp = vp->cube()->sampleCount();
467 ieline = vp->cube()->lineCount();
490 int nsamps = iesamp - issamp + 1;
491 int nlines = ieline - isline + 1;
493 brick =
new Brick(nsamps, nlines, 1, vp->cube()->pixelType());
494 brick->SetBasePosition(issamp, isline, vp->grayBand());
495 vp->cube()->read(*brick);
505 s =
new QStack<Brick *>;
513 while(!temp->isEmpty()) {
521 brick =
new Brick(nsamps, nlines, 1, vp->cube()->pixelType());
522 brick->SetBasePosition(issamp, isline, vp->grayBand());
523 vp->cube()->read(*brick);
527 for(
int i = 0; linePts && i < (int)linePts->size(); i++) {
528 QPoint *pt = (*linePts)[i];
531 int brickIndex = (il - isline) * nsamps + (is - issamp);
532 (*brick)[brickIndex] = (double)
p_dn;
536 for(
int i = 0; i < brick->size(); i++)(*brick)[i] = (double)
p_dn;
543 vp->cube()->write(*brick);
544 vp->cubeChanged(
true);
548 QRect r(brick->Sample(), brick->Line(),
549 brick->SampleDimension(), brick->LineDimension());
550 vp->cubeContentsChanged(r);
558 QMessageBox::information((
QWidget *)parent(),
"Error",
"Not enough memory to complete this operation.");
569 Brick *redoBrick = NULL;
572 if (vp == NULL)
return;
576 QApplication::beep();
581 if (vp->cube()->isReadOnly()) {
582 QMessageBox::information((
QWidget *)parent(),
"Error",
"Cube is Read Only");
588 Brick *brick = s->top();
591 redoBrick =
new Brick(brick->SampleDimension(), brick->LineDimension(), 1, vp->cube()->pixelType());
592 redoBrick->SetBasePosition(brick->Sample(), brick->Line(), vp->grayBand());
593 vp->cube()->read(*(redoBrick));
595 QStack<Brick *> *redo;
600 redo =
new QStack<Brick *>;
602 redo->push(redoBrick);
606 vp->cube()->write(*(brick));
609 QRect r(brick->Sample(), brick->Line(),
610 brick->SampleDimension(), brick->LineDimension());
611 vp->cubeContentsChanged(r);
617 vp->cubeChanged(
true);
632 QMessageBox::information((
QWidget *)parent(),
"Error",
"Not enough memory to complete this operation.");
648 if (vp->cube()->isReadOnly()) {
649 QMessageBox::information((
QWidget *)parent(),
"Error",
"Cube is Read Only");
653 QStack<Brick *> *undo;
654 QStack<Brick *> *redo;
666 for(
int i = undo->count() - 1; i >= marker; i--) {
667 Brick *brick = undo->at(i);
669 vp->cube()->write(*(brick));
674 marker = marker - undo->count();
682 for(
int i = redo->count() - 1; i >= redo->count() - marker; i--) {
683 Brick *brick = redo->at(i);
686 vp->cube()->write(*(brick));
693 QMessageBox::information((
QWidget *)parent(),
"Error",
694 "Not enough memory to complete this operation.");
704 Brick *undoBrick = NULL;
707 if (vp == NULL)
return;
711 QApplication::beep();
716 if (vp->cube()->isReadOnly()) {
717 QMessageBox::information((
QWidget *)parent(),
"Error",
"Cube is Read Only");
722 Brick *brick = s->top();
725 undoBrick =
new Brick(brick->SampleDimension(),
726 brick->LineDimension(), 1,
727 vp->cube()->pixelType());
728 undoBrick->SetBasePosition(brick->Sample(), brick->Line(), vp->grayBand());
729 vp->cube()->read(*(undoBrick));
731 QStack<Brick *> *undo;
736 undo =
new QStack<Brick *>;
738 undo->push(undoBrick);
742 vp->cube()->write(*(brick));
745 QRect r(brick->Sample(), brick->Line(),
746 brick->SampleDimension(), brick->LineDimension());
747 vp->cubeContentsChanged(r);
751 vp->cubeChanged(
true);
767 QMessageBox::information((
QWidget *)parent(),
"Error",
"Not enough memory to complete this operation.");
793 vp->cubeChanged(
false);
811 while(!temp->isEmpty()) {
818 while(!temp->isEmpty()) {
844 if (vp == NULL)
return new QList<QPoint *>();
847 int x, y, xinc, yinc;
851 QList<QPoint *> *points =
new QList<QPoint *>;
853 int sx = line.p1().x();
854 int ex = line.p2().x();
855 int sy = line.p1().y();
856 int ey = line.p2().y();
876 slope = (double)(ex - sx) / (double)(ey - sy);
878 for(i = 0; i < ysize; i++) {
879 x = (int)(slope * (
double)(y - sy) + (
double) sx + 0.5);
882 if (x >= 0 && y >= 0 && x <= vp->cubeSamples() && y <= vp->cubeLines()) {
883 QPoint *pt =
new QPoint;
886 points->push_back(pt);
891 else if (xsize == 1) {
893 if (sx >= 0 && sy >= 0 && sx <= vp->cubeSamples() && sy <= vp->cubeLines()) {
894 QPoint *pt =
new QPoint;
897 points->push_back(pt);
901 slope = (double)(ey - sy) / (double)(ex - sx);
903 for(i = 0; i < xsize; i++) {
904 y = (int)(slope * (
double)(x - sx) + (
double) sy + 0.5);
907 if (x >= 0 && y >= 0 && x <= vp->cubeSamples() && y <= vp->cubeLines()) {
908 QPoint *pt =
new QPoint;
911 points->push_back(pt);
929 rubberBandTool()->
enable(RubberBandTool::LineMode);
932 else if (index == 4) {
933 rubberBandTool()->
enable(RubberBandTool::RectangleMode);
Buffer for containing a three dimensional section of an image.
Widget to display Isis cubes for qt apps.
Cube display widget for certain Isis MDI applications.
This is free and unencumbered software released into the public domain.
const double His
Value for an Isis High Instrument Saturation pixel.
const double Hrs
Value for an Isis High Representation Saturation pixel.
const double Null
Value for an Isis Null pixel.
const double Lrs
Value for an Isis Low Representation Saturation pixel.
const double Lis
Value for an Isis Low Instrument Saturation pixel.