26 #include <QApplication>
29 #include <QHBoxLayout>
33 #include <QMessageBox>
35 #include <QStackedWidget>
36 #include <QToolButton>
41 #include "RubberBandTool.h"
75 action->setIcon(QPixmap(
toolIconDir() +
"/color_line.png"));
76 action->setToolTip(
"Image Edit (E)");
77 action->setShortcut(Qt::Key_E);
80 "<b>Function:</b> Edit active viewport \
81 <p><b>Shortcut:</b> E</p> ";
82 action->setWhatsThis(text);
100 container->setObjectName(
"EditToolActiveToolBarWidget");
112 "<b>Function:</b> The shape in the image that will be replaced with \
113 a new value. If Horizontal line is chosen, clicking anywhere on the \
114 image will cause all samples on that line of the cube to be replaced \
115 with the replacement value. If Vertical Line is chosen, a v ...";
131 "<b>Function:</b> The value which will be used to replace image data. ";
141 "<b>Function:</b> This is the dn used to replace image data";
150 "<b>Function:</b> Undo last edit operation";
160 "<b>Function:</b> Redo last undo operation";
171 "<b>Function:</b> Save any changes made, these changes are finalized";
182 "<b>Function:</b> Save any changes made to the file specified, these changes are finalized";
188 QHBoxLayout *layout =
new QHBoxLayout;
189 layout->setMargin(0);
197 layout->addStretch(1);
198 container->setLayout(layout);
200 m_container = container;
279 if (vp == NULL)
return;
288 QMessageBox::information((
QWidget *)parent(),
"Error",
"Cannot open cube read/write");
293 QMessageBox::information((
QWidget *)parent(),
294 "Error",
"Cannot edit in color mode");
298 int issamp, isline, iesamp, ieline;
299 double ssamp, sline, esamp, eline;
305 if (!rubberBandTool()->
isValid())
return;
308 if ((r.width() < 1) || (r.height() < 1))
return;
313 issamp = (int)(ssamp + 0.5);
314 isline = (int)(sline + 0.5);
315 iesamp = (int)(esamp + 0.5);
316 ieline = (int)(eline + 0.5);
319 if (issamp < 0) issamp = 0;
320 if (iesamp < 0) iesamp = 0;
321 if (isline < 0) isline = 0;
322 if (ieline < 0) ieline = 0;
330 if (issamp > iesamp || isline > ieline) {
331 QMessageBox::information((
QWidget *)parent(),
332 "Error",
"Rectangle is out of bounds");
339 if (!rubberBandTool()->
isValid())
return;
340 vp->
viewportToCube(rubberBandTool()->vertices()[0].rx(), rubberBandTool()->vertices()[0].ry(),
342 vp->
viewportToCube(rubberBandTool()->vertices()[1].rx(), rubberBandTool()->vertices()[1].ry(),
345 QLine l((
int)ssamp, (
int)sline, (
int)esamp, (
int)eline);
350 if (linePts->empty()) {
351 QMessageBox::information((
QWidget *)parent(),
352 "Error",
"No points in edit line");
357 issamp = std::min(linePts->front()->x(), linePts->back()->x());
358 isline = std::min(linePts->front()->y(), linePts->back()->y());
359 iesamp = std::max(linePts->front()->x(), linePts->back()->x());
360 ieline = std::max(linePts->front()->y(), linePts->back()->y());
368 writeToCube(iesamp, issamp, ieline, isline, linePts);
369 if (linePts)
delete linePts;
373 connect(newViewport, SIGNAL(saveChanges(
CubeViewport *)),
375 connect(newViewport, SIGNAL(discardChanges(
CubeViewport *)),
377 connect(newViewport, SIGNAL(destroyed(
QObject *)),
406 if (vp == NULL)
return;
419 QMessageBox::information((
QWidget *)parent(),
"Error",
"Cannot open cube read/write");
424 QMessageBox::information((
QWidget *)parent(),
425 "Error",
"Cannot edit in color mode");
429 int issamp, isline, iesamp, ieline;
434 if (m == Qt::RightButton &&
438 issamp = (int)(ssamp + 0.5);
439 isline = (int)(sline + 0.5);
444 p_dn = (*pntBrick)[0];
454 if ((ssamp < 0.5) || (sline < 0.5) ||
456 QApplication::beep();
459 issamp = (int)(ssamp + 0.5);
460 isline = (int)(sline + 0.5);
492 int nsamps = iesamp - issamp + 1;
493 int nlines = ieline - isline + 1;
515 while(!temp->isEmpty()) {
529 for(
int i = 0; linePts && i < (int)linePts->size(); i++) {
530 QPoint *pt = (*linePts)[i];
533 int brickIndex = (il - isline) * nsamps + (is - issamp);
534 (*brick)[brickIndex] = (double)
p_dn;
538 for(
int i = 0; i < brick->
size(); i++)(*brick)[i] = (double)
p_dn;
560 QMessageBox::information((
QWidget *)parent(),
"Error",
"Not enough memory to complete this operation.");
571 Brick *redoBrick = NULL;
574 if (vp == NULL)
return;
578 QApplication::beep();
584 QMessageBox::information((
QWidget *)parent(),
"Error",
"Cube is Read Only");
590 Brick *brick = s->top();
604 redo->push(redoBrick);
634 QMessageBox::information((
QWidget *)parent(),
"Error",
"Not enough memory to complete this operation.");
651 QMessageBox::information((
QWidget *)parent(),
"Error",
"Cube is Read Only");
668 for(
int i = undo->count() - 1; i >= marker; i--) {
669 Brick *brick = undo->at(i);
676 marker = marker - undo->count();
684 for(
int i = redo->count() - 1; i >= redo->count() - marker; i--) {
685 Brick *brick = redo->at(i);
695 QMessageBox::information((
QWidget *)parent(),
"Error",
696 "Not enough memory to complete this operation.");
706 Brick *undoBrick = NULL;
709 if (vp == NULL)
return;
713 QApplication::beep();
719 QMessageBox::information((
QWidget *)parent(),
"Error",
"Cube is Read Only");
724 Brick *brick = s->top();
740 undo->push(undoBrick);
769 QMessageBox::information((
QWidget *)parent(),
"Error",
"Not enough memory to complete this operation.");
813 while(!temp->isEmpty()) {
820 while(!temp->isEmpty()) {
849 int x, y, xinc, yinc;
855 int sx = line.p1().x();
856 int ex = line.p2().x();
857 int sy = line.p1().y();
858 int ey = line.p2().y();
878 slope = (double)(ex - sx) / (double)(ey - sy);
880 for(i = 0; i < ysize; i++) {
881 x = (int)(slope * (
double)(y - sy) + (
double) sx + 0.5);
884 if (x >= 0 && y >= 0 && x <= vp->cubeSamples() && y <= vp->
cubeLines()) {
885 QPoint *pt =
new QPoint;
888 points->push_back(pt);
893 else if (xsize == 1) {
895 if (sx >= 0 && sy >= 0 && sx <= vp->cubeSamples() && sy <= vp->cubeLines()) {
896 QPoint *pt =
new QPoint;
899 points->push_back(pt);
903 slope = (double)(ey - sy) / (double)(ex - sx);
905 for(i = 0; i < xsize; i++) {
906 y = (int)(slope * (
double)(x - sx) + (
double) sy + 0.5);
909 if (x >= 0 && y >= 0 && x <= vp->cubeSamples() && y <= vp->
cubeLines()) {
910 QPoint *pt =
new QPoint;
913 points->push_back(pt);
931 rubberBandTool()->
enable(RubberBandTool::LineMode);
934 else if (index == 4) {
935 rubberBandTool()->
enable(RubberBandTool::RectangleMode);
Cube display widget for certain Isis MDI applications.
int Line(const int index=0) const
Returns the line position associated with a shape buffer index.
const double Null
Value for an Isis Null pixel.
int LineDimension() const
Returns the number of lines in the shape buffer.
PixelType pixelType() const
bool isColor() const
Is the viewport shown in 3-band color.
int cubeSamples() const
Return the number of samples in the cube.
Buffer for containing a three dimensional section of an image.
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.
void cubeContentsChanged(QRect rect)
Cube changed, repaint given area.
Widget to display Isis cubes for qt apps.
void read(Blob &blob) const
This method will read data from the specified Blob object.
int Sample(const int index=0) const
Returns the sample position associated with a shape buffer index.
const double Lis
Value for an Isis Low Instrument Saturation pixel.
void reopen(QString access="r")
This method will reopen an isis sube for reading or reading/writing.
Cube * cube() const
Return the cube associated with viewport.
int grayBand() const
Return the gray band currently viewed.
void viewportToCube(int x, int y, double &sample, double &line) const
Convert a viewport x/y to a cube sample/line (may be outside the cube)
bool isReadOnly() const
Test if the opened cube is read-only, that is write operations will fail if this is true...
void cubeChanged(bool changed)
This method is called when the cube has changed or changes have been finalized.
int size() const
Returns the total number of pixels in the shape buffer.
void write(Blob &blob)
This method will write a blob of data (e.g.
void setCaption()
Change the caption on the viewport title bar.
const double Lrs
Value for an Isis Low Representation Saturation pixel.
int cubeLines() const
Return the number of lines in the cube.
int SampleDimension() const
Returns the number of samples in the shape buffer.
const double His
Value for an Isis High Instrument Saturation pixel.
const double Hrs
Value for an Isis High Representation Saturation pixel.