Skip to content

Commit 997c35f

Browse files
committed
Can choose image save directory
1 parent 9fd42d5 commit 997c35f

File tree

5 files changed

+137
-75
lines changed

5 files changed

+137
-75
lines changed

src/ExampleNets/regression/ospray1.srn5

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@
346346
</module>
347347
<state>
348348
<stateMap>
349-
<count>26</count>
349+
<count>27</count>
350350
<item_version>0</item_version>
351351
<item>
352352
<first>
@@ -540,6 +540,18 @@
540540
</value>
541541
</second>
542542
</item>
543+
<item>
544+
<first>
545+
<name>Filename</name>
546+
</first>
547+
<second>
548+
<name>Filename</name>
549+
<value>
550+
<which>2</which>
551+
<value>/Users/dan/Dropbox</value>
552+
</value>
553+
</second>
554+
</item>
543555
<item>
544556
<first>
545557
<name>FrameCount</name>

src/Interface/Modules/Visualization/InterfaceWithOspray.ui

Lines changed: 75 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -36,66 +36,13 @@
3636
<string>Image</string>
3737
</attribute>
3838
<layout class="QGridLayout" name="gridLayout_12">
39-
<item row="5" column="0">
40-
<spacer name="verticalSpacer">
41-
<property name="orientation">
42-
<enum>Qt::Vertical</enum>
43-
</property>
44-
<property name="sizeHint" stdset="0">
45-
<size>
46-
<width>20</width>
47-
<height>40</height>
48-
</size>
49-
</property>
50-
</spacer>
51-
</item>
52-
<item row="0" column="0">
53-
<widget class="QGroupBox" name="groupBox_6">
54-
<property name="title">
55-
<string>Image dimensions</string>
56-
</property>
57-
<layout class="QGridLayout" name="gridLayout_6">
58-
<item row="0" column="0">
59-
<widget class="QLabel" name="label">
60-
<property name="text">
61-
<string>Height:</string>
62-
</property>
63-
</widget>
64-
</item>
65-
<item row="0" column="1">
66-
<widget class="QSpinBox" name="imageHeightSpinBox_">
67-
<property name="minimum">
68-
<number>1</number>
69-
</property>
70-
<property name="maximum">
71-
<number>9999</number>
72-
</property>
73-
</widget>
74-
</item>
75-
<item row="1" column="0">
76-
<widget class="QLabel" name="label_2">
77-
<property name="text">
78-
<string>Width:</string>
79-
</property>
80-
</widget>
81-
</item>
82-
<item row="1" column="1">
83-
<widget class="QSpinBox" name="imageWidthSpinBox_">
84-
<property name="minimum">
85-
<number>1</number>
86-
</property>
87-
<property name="maximum">
88-
<number>9999</number>
89-
</property>
90-
</widget>
91-
</item>
92-
</layout>
93-
</widget>
94-
</item>
9539
<item row="2" column="0">
96-
<widget class="QGroupBox" name="groupBox_3">
40+
<widget class="QGroupBox" name="imageSaveGroupBox_">
9741
<property name="title">
98-
<string>Choose file to write</string>
42+
<string>Save image to file</string>
43+
</property>
44+
<property name="checkable">
45+
<bool>false</bool>
9946
</property>
10047
<layout class="QHBoxLayout" name="horizontalLayout">
10148
<item>
@@ -117,7 +64,7 @@
11764
<item>
11865
<widget class="QPushButton" name="saveFileButton_">
11966
<property name="text">
120-
<string>Save...</string>
67+
<string>Choose Location...</string>
12168
</property>
12269
<property name="checkable">
12370
<bool>false</bool>
@@ -153,19 +100,79 @@
153100
</layout>
154101
</widget>
155102
</item>
156-
<item row="3" column="0">
157-
<widget class="QCheckBox" name="showImageCheckBox_">
158-
<property name="text">
159-
<string>Show Image in new window</string>
103+
<item row="0" column="0">
104+
<widget class="QGroupBox" name="groupBox_6">
105+
<property name="title">
106+
<string>Image dimensions</string>
160107
</property>
108+
<layout class="QGridLayout" name="gridLayout_6">
109+
<item row="0" column="0">
110+
<widget class="QLabel" name="label">
111+
<property name="text">
112+
<string>Height:</string>
113+
</property>
114+
</widget>
115+
</item>
116+
<item row="0" column="1">
117+
<widget class="QSpinBox" name="imageHeightSpinBox_">
118+
<property name="minimum">
119+
<number>1</number>
120+
</property>
121+
<property name="maximum">
122+
<number>9999</number>
123+
</property>
124+
</widget>
125+
</item>
126+
<item row="1" column="0">
127+
<widget class="QLabel" name="label_2">
128+
<property name="text">
129+
<string>Width:</string>
130+
</property>
131+
</widget>
132+
</item>
133+
<item row="1" column="1">
134+
<widget class="QSpinBox" name="imageWidthSpinBox_">
135+
<property name="minimum">
136+
<number>1</number>
137+
</property>
138+
<property name="maximum">
139+
<number>9999</number>
140+
</property>
141+
</widget>
142+
</item>
143+
</layout>
161144
</widget>
162145
</item>
163-
<item row="4" column="0">
164-
<widget class="QPushButton" name="closeImageWindowsPushButton_">
165-
<property name="text">
166-
<string>Close image windows</string>
146+
<item row="8" column="0">
147+
<spacer name="verticalSpacer">
148+
<property name="orientation">
149+
<enum>Qt::Vertical</enum>
167150
</property>
168-
</widget>
151+
<property name="sizeHint" stdset="0">
152+
<size>
153+
<width>20</width>
154+
<height>40</height>
155+
</size>
156+
</property>
157+
</spacer>
158+
</item>
159+
<item row="3" column="0">
160+
<layout class="QGridLayout" name="gridLayout_13">
161+
<item row="0" column="0">
162+
<widget class="QCheckBox" name="showImageCheckBox_">
163+
<property name="text">
164+
<string>Show Image in new window</string>
165+
</property>
166+
</widget>
167+
</item>
168+
<item row="0" column="1">
169+
<widget class="QPushButton" name="closeImageWindowsPushButton_">
170+
<property name="text">
171+
<string>Close image windows</string>
172+
</property>
173+
</widget>
174+
</item>
175+
</layout>
169176
</item>
170177
</layout>
171178
</widget>

src/Interface/Modules/Visualization/InterfaceWithOsprayDialog.cc

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,27 @@ InterfaceWithOsprayDialog::InterfaceWithOsprayDialog(const std::string& name, Mo
7575
addCheckBoxManager(automaticViewCheckBox_, AutoCameraView);
7676
connect(automaticViewCheckBox_, SIGNAL(stateChanged(int)), this, SLOT(updateViewWidgets(int)));
7777

78+
connect(saveFileButton_, SIGNAL(clicked()), this, SLOT(saveFile()));
79+
connect(fileNameLineEdit_, SIGNAL(editingFinished()), this, SLOT(pushFileNameToState()));
80+
connect(fileNameLineEdit_, SIGNAL(returnPressed()), this, SLOT(pushFileNameToState()));
81+
7882
createExecuteInteractivelyToggleAction();
7983

8084
state_->connectSpecificStateChanged(Variables::Filename, [this]() { imageFilenameChanged(); });
8185
connect(this, SIGNAL(imageFilenameChanged()), this, SLOT(showImage()));
8286
WidgetStyleMixin::tabStyle(tabWidget);
87+
88+
connect(closeImageWindowsPushButton_, SIGNAL(clicked()), this, SLOT(closeImageWindows()));
89+
}
90+
91+
void InterfaceWithOsprayDialog::closeImageWindows()
92+
{
93+
for (auto& child : children())
94+
{
95+
auto dialog = qobject_cast<QDialog*>(child);
96+
if (dialog)
97+
dialog->close();
98+
}
8399
}
84100

85101
void InterfaceWithOsprayDialog::showImage()
@@ -93,7 +109,7 @@ void InterfaceWithOsprayDialog::showImage()
93109
myLabel->resize(myLabel->pixmap()->size());
94110

95111
auto d = new QDialog(this);
96-
d->setWindowTitle("Ospray Scene Image");
112+
d->setWindowTitle("Ospray Scene Image: " + filename);
97113
auto layout = new QHBoxLayout;
98114
layout->addWidget(myLabel);
99115
d->setLayout(layout);
@@ -105,3 +121,23 @@ void InterfaceWithOsprayDialog::updateViewWidgets(int state)
105121
{
106122
manualViewGroupBox_->setEnabled(state == 0);
107123
}
124+
125+
void InterfaceWithOsprayDialog::pullSpecial()
126+
{
127+
fileNameLineEdit_->setText(QString::fromStdString(state_->getValue(Variables::Filename).toString()));
128+
}
129+
130+
void InterfaceWithOsprayDialog::pushFileNameToState()
131+
{
132+
state_->setValue(Variables::Filename, fileNameLineEdit_->text().trimmed().toStdString());
133+
}
134+
135+
void InterfaceWithOsprayDialog::saveFile()
136+
{
137+
auto dir = QFileDialog::getExistingDirectory(this, "Choose Directory to save images", ".");
138+
if (dir.length() > 0)
139+
{
140+
fileNameLineEdit_->setText(dir);
141+
pushFileNameToState();
142+
}
143+
}

src/Interface/Modules/Visualization/InterfaceWithOsprayDialog.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,31 @@
3131

3232
#include "Interface/Modules/Visualization/ui_InterfaceWithOspray.h"
3333
#include <Interface/Modules/Base/ModuleDialogGeneric.h>
34+
#include <Interface/Modules/Base/RemembersFileDialogDirectory.h>
3435
#include <Interface/Modules/Visualization/share.h>
3536

3637
namespace SCIRun {
3738
namespace Gui {
3839

3940
class SCISHARE InterfaceWithOsprayDialog : public ModuleDialogGeneric,
40-
public Ui::InterfaceWithOspray
41+
public Ui::InterfaceWithOspray, public RemembersFileDialogDirectory
4142
{
4243
Q_OBJECT
4344

4445
public:
4546
InterfaceWithOsprayDialog(const std::string& name,
4647
SCIRun::Dataflow::Networks::ModuleStateHandle state,
4748
QWidget* parent = nullptr);
48-
49+
protected:
50+
virtual void pullSpecial() override;
4951
Q_SIGNALS:
5052
void imageFilenameChanged();
5153
private Q_SLOTS:
5254
void showImage();
5355
void updateViewWidgets(int state);
56+
void pushFileNameToState();
57+
void saveFile();
58+
void closeImageWindows();
5459
};
5560

5661
}

src/Modules/Visualization/InterfaceWithOspray.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ void InterfaceWithOspray::setStateDefaults()
108108
state->setValue(Parameters::LightVisible, false);
109109
state->setValue(Parameters::LightType, std::string("none"));
110110
state->setValue(Parameters::AutoCameraView, true);
111+
state->setValue(Variables::Filename, std::string(""));
111112
}
112113

113114
namespace detail
@@ -382,10 +383,11 @@ void InterfaceWithOspray::execute()
382383

383384
auto isoString = boost::posix_time::to_iso_string(boost::posix_time::microsec_clock::universal_time());
384385
auto filename = "scirunOsprayOutput_" + isoString + ".ppm";
385-
ospray.writeImage(filename);
386-
remark("Saving output to " + filename);
386+
auto filePath = get_state()->getValue(Variables::Filename).toString() / boost::filesystem::path(filename);
387+
ospray.writeImage(filePath.string());
388+
remark("Saving output to " + filePath.string());
387389

388-
get_state()->setTransientValue(Variables::Filename, filename);
390+
get_state()->setTransientValue(Variables::Filename, filePath.string());
389391

390392
//auto geom = builder_->buildGeometryObject(field, colorMap, *this, this);
391393
//sendOutput(SceneGraph, geom);

0 commit comments

Comments
 (0)