/
MainWindow.cc
150 lines (122 loc) · 4.79 KB
/
MainWindow.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// __BEGIN_LICENSE__
// Copyright (c) 2006-2012, United States Government as represented by the
// Administrator of the National Aeronautics and Space Administration. All
// rights reserved.
//
// The NASA Vision Workbench is licensed under the Apache License,
// Version 2.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// __END_LICENSE__
/// \file vwv_MainWindow.cc
///
/// The Vision Workbench image viewer main window class.
///
#include <QtGui>
#include <vw/config.h>
#include <vw/gui/MainWindow.h>
#include <vw/gui/GlPreviewWidget.h>
using namespace vw::gui;
#include <vw/Image/MaskViews.h>
#include <vw/FileIO/DiskImageView.h>
#include <vw/FileIO/DiskImageResource.h>
#include <vw/Image/Statistics.h>
#include <vw/Image/PixelMask.h>
#include <sstream>
namespace po = boost::program_options;
MainWindow::MainWindow(std::string input_filename,
float nodata_value,
int transaction_id,
bool /*do_normalize*/,
po::variables_map const& vm) :
m_filename(input_filename), m_nodata_value(nodata_value), m_vm(vm) {
// Set up the basic layout of the window and its menus
create_actions();
create_menus();
create_status_bar();
// Set the window title and add tabs
std::string window_title = "Vision Workbench Viewer : " + m_filename;
this->setWindowTitle(window_title.c_str());
// Set up OpenGL context parameters
QGLFormat gl_frmt = QGLFormat::defaultFormat();
gl_frmt.setSampleBuffers(true);
gl_frmt.setDoubleBuffer(true);
gl_frmt.setSwapInterval(1);
// Set up GlPreviewWidget
m_preview_widget = new GlPreviewWidget(this, input_filename, gl_frmt, transaction_id);
setCentralWidget(m_preview_widget);
// // Set the nodata value
// vw::DiskImageResource *rsrc = vw::DiskImageResource::open(input_filename);
// if (m_vm.count("nodata-value")) {
// std::cout << "\t--> User specified nodata value: " << m_nodata_value << ".\n";
// m_preview_widget->set_nodata_value(m_nodata_value);
// } else if ( rsrc->has_nodata_value() ) {
// m_nodata_value = rsrc->nodata_value();
// std::cout << "\t--> Extracted nodata value from file: " << m_nodata_value << ".\n";
// m_preview_widget->set_nodata_value(m_nodata_value);
// }
// delete rsrc;
// if (do_normalize) {
// m_preview_widget->normalize();
// }
// Maximize the main window
this->showMaximized();
}
//********************************************************************
// MAIN WINDOW SETUP
//********************************************************************
void MainWindow::create_actions() {
// The About Box
about_action = new QAction(tr("About VWV"), this);
about_action->setStatusTip(tr("Show the Vision Workbench Viewere about box."));
connect(about_action, SIGNAL(triggered()), this, SLOT(about()));
// Exit or Quit
exit_action = new QAction(tr("E&xit"), this);
exit_action->setShortcut(tr("Ctrl+Q"));
exit_action->setStatusTip(tr("Exit the application"));
connect(exit_action, SIGNAL(triggered()), this, SLOT(close()));
}
void MainWindow::create_menus() {
// File Menu
file_menu = menuBar()->addMenu(tr("&File"));
file_menu->addAction(exit_action);
// Edit Menu
edit_menu = menuBar()->addMenu(tr("&Edit"));
// Help menu
menuBar()->addSeparator();
help_menu = menuBar()->addMenu(tr("&Help"));
help_menu->addAction(about_action);
}
void MainWindow::create_status_bar() {
status_label = new QLabel("");
status_label->setAlignment(Qt::AlignHCenter);
statusBar()->addWidget(status_label);
// WARNING: Memory leak as currently written. Fix this somewhow...
// GuiProgressCallback *clbk = new GuiProgressCallback(this, "Updating: ");
// statusBar()->addWidget(clbk->widget());
}
void MainWindow::update_status_bar(std::string const& s) {
status_label->setText(QString(s.c_str()));
}
void MainWindow::about() {
std::ostringstream about_text;
about_text << "<h3>Vision Workbench Image Viewer (vwv)</h3>"
<< "<p>Version " << VW_PACKAGE_VERSION << "</p>"
<< "<p>Copyright © 2008 NASA Ames Research Center</p>";
QMessageBox::about(this, tr("About Vision Workbench Viewer"),
tr(about_text.str().c_str()));
}
void MainWindow::keyPressEvent(QKeyEvent *event) {
std::ostringstream s;
switch (event->key()) {
case Qt::Key_Escape: // Quit
close();
break;
}
}