Skip to content

Commit 422aedc

Browse files
committed
Add dialog showing image, with checkbox option
1 parent e8913fe commit 422aedc

File tree

6 files changed

+73
-13
lines changed

6 files changed

+73
-13
lines changed

src/ExampleNets/regression/interfaceWithOspray.srn5

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
</module>
268268
<state>
269269
<stateMap>
270-
<count>18</count>
270+
<count>19</count>
271271
<item_version>0</item_version>
272272
<item>
273273
<first>
@@ -337,7 +337,7 @@
337337
<name>CameraPositionZ</name>
338338
<value>
339339
<which>1</which>
340-
<value>-5.00000000000000000e+000</value>
340+
<value>-2.00000000000000000e+000</value>
341341
</value>
342342
</second>
343343
</item>
@@ -469,7 +469,7 @@
469469
<name>ImageHeight</name>
470470
<value>
471471
<which>0</which>
472-
<value>4000</value>
472+
<value>600</value>
473473
</value>
474474
</second>
475475
</item>
@@ -481,7 +481,19 @@
481481
<name>ImageWidth</name>
482482
<value>
483483
<which>0</which>
484-
<value>6000</value>
484+
<value>800</value>
485+
</value>
486+
</second>
487+
</item>
488+
<item>
489+
<first>
490+
<name>ShowImageInWindow</name>
491+
</first>
492+
<second>
493+
<name>ShowImageInWindow</name>
494+
<value>
495+
<which>3</which>
496+
<value>1</value>
485497
</value>
486498
</second>
487499
</item>

src/Interface/Modules/Visualization/InterfaceWithOspray.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,13 @@
421421
</layout>
422422
</widget>
423423
</item>
424+
<item row="0" column="2">
425+
<widget class="QCheckBox" name="showImageCheckBox_">
426+
<property name="text">
427+
<string>Show Image in new window</string>
428+
</property>
429+
</widget>
430+
</item>
424431
</layout>
425432
</widget>
426433
<resources/>

src/Interface/Modules/Visualization/InterfaceWithOsprayDialog.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
#include <Interface/Modules/Visualization/InterfaceWithOsprayDialog.h>
3030
#include <Modules/Visualization/InterfaceWithOspray.h>
3131
#include <Dataflow/Network/ModuleStateInterface.h>
32+
#include <Core/Algorithms/Base/AlgorithmVariableNames.h>
3233

3334
using namespace SCIRun::Gui;
3435
using namespace SCIRun::Dataflow::Networks;
3536
using namespace SCIRun::Core::Datatypes;
3637
using namespace SCIRun::Modules::Visualization;
38+
using namespace SCIRun::Core::Algorithms;
3739
using namespace SCIRun::Core::Algorithms::Visualization::Parameters;
3840

3941
InterfaceWithOsprayDialog::InterfaceWithOsprayDialog(const std::string& name, ModuleStateHandle state,
@@ -62,6 +64,29 @@ InterfaceWithOsprayDialog::InterfaceWithOsprayDialog(const std::string& name, Mo
6264
addDoubleSpinBoxManager(backgroundColorRDoubleSpinBox_, BackgroundColorR);
6365
addDoubleSpinBoxManager(backgroundColorGDoubleSpinBox_, BackgroundColorG);
6466
addDoubleSpinBoxManager(backgroundColorBDoubleSpinBox_, BackgroundColorB);
67+
addCheckBoxManager(showImageCheckBox_, ShowImageInWindow);
6568

6669
createExecuteInteractivelyToggleAction();
70+
71+
state_->connectSpecificStateChanged(Variables::Filename, [this]() { imageFilenameChanged(); });
72+
connect(this, SIGNAL(imageFilenameChanged()), this, SLOT(showImage()));
6773
}
74+
75+
void InterfaceWithOsprayDialog::showImage()
76+
{
77+
if (state_->getValue(ShowImageInWindow).toBool())
78+
{
79+
auto filename(QString::fromStdString(transient_value_cast<std::string>(state_->getTransientValue(Variables::Filename))));
80+
QImage image(filename);
81+
auto myLabel = new QLabel(parentWidget());
82+
myLabel->setPixmap(QPixmap::fromImage(image));
83+
myLabel->resize(myLabel->pixmap()->size());
84+
85+
auto d = new QDialog;
86+
d->setWindowTitle("Ospray Scene Image");
87+
auto layout = new QHBoxLayout;
88+
layout->addWidget(myLabel);
89+
d->setLayout(layout);
90+
d->show();
91+
}
92+
}

src/Interface/Modules/Visualization/InterfaceWithOsprayDialog.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ class SCISHARE InterfaceWithOsprayDialog : public ModuleDialogGeneric,
4545
InterfaceWithOsprayDialog(const std::string& name,
4646
SCIRun::Dataflow::Networks::ModuleStateHandle state,
4747
QWidget* parent = nullptr);
48-
protected:
49-
private Q_SLOTS:
5048

49+
Q_SIGNALS:
50+
void imageFilenameChanged();
51+
private Q_SLOTS:
52+
void showImage();
5153
};
5254

5355
}

src/Modules/Visualization/InterfaceWithOspray.cc

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ DEALINGS IN THE SOFTWARE.
3131
#include <Core/Datatypes/Legacy/Field/VField.h>
3232
#include <Core/Datatypes/ColorMap.h>
3333
#include <Core/Datatypes/Legacy/Field/Field.h>
34+
#include <Core/Datatypes/Legacy/Field/FieldInformation.h>
3435
#include <Core/Datatypes/Legacy/Field/VMesh.h>
3536
#include <Core/Datatypes/Mesh/VirtualMeshFacade.h>
37+
#include <Core/Algorithms/Base/AlgorithmVariableNames.h>
38+
3639
#include <boost/date_time/posix_time/posix_time.hpp>
3740

3841
#include <ospray/ospray.h>
@@ -63,6 +66,7 @@ ALGORITHM_PARAMETER_DEF(Visualization, BackgroundColorR);
6366
ALGORITHM_PARAMETER_DEF(Visualization, BackgroundColorG);
6467
ALGORITHM_PARAMETER_DEF(Visualization, BackgroundColorB);
6568
ALGORITHM_PARAMETER_DEF(Visualization, FrameCount);
69+
ALGORITHM_PARAMETER_DEF(Visualization, ShowImageInWindow);
6670

6771
MODULE_INFO_DEF(InterfaceWithOspray, Visualization, SCIRun)
6872

@@ -87,6 +91,7 @@ void InterfaceWithOspray::setStateDefaults()
8791
state->setValue(Parameters::BackgroundColorG, 0.0);
8892
state->setValue(Parameters::BackgroundColorB, 0.0);
8993
state->setValue(Parameters::FrameCount, 10);
94+
state->setValue(Parameters::ShowImageInWindow, true);
9095
}
9196

9297
namespace detail
@@ -225,15 +230,17 @@ namespace detail
225230
{
226231
FILE *file = fopen(fileName, "wb");
227232
fprintf(file, "P6\n%i %i\n255\n", size.x, size.y);
228-
unsigned char *out = (unsigned char *)alloca(3 * size.x);
229-
for (int y = 0; y < size.y; y++) {
233+
std::vector<unsigned char> out(3 * size.x);
234+
for (int y = 0; y < size.y; y++)
235+
{
230236
const unsigned char *in = (const unsigned char *)&pixel[(size.y - 1 - y)*size.x];
231-
for (int x = 0; x < size.x; x++) {
237+
for (int x = 0; x < size.x; x++)
238+
{
232239
out[3 * x + 0] = in[4 * x + 0];
233240
out[3 * x + 1] = in[4 * x + 1];
234241
out[3 * x + 2] = in[4 * x + 2];
235242
}
236-
fwrite(out, 3 * size.x, sizeof(char), file);
243+
fwrite(&out[0], 3 * size.x, sizeof(char), file);
237244
}
238245
fprintf(file, "\n");
239246
fclose(file);
@@ -256,10 +263,16 @@ void InterfaceWithOspray::execute()
256263

257264
if (needToExecute())
258265
{
259-
260-
auto isoString = boost::posix_time::to_iso_string(boost::posix_time::microsec_clock::universal_time());
266+
FieldInformation info(field);
267+
268+
if (!info.is_trisurfmesh())
269+
THROW_INVALID_ARGUMENT("Module currently only works with trisurfs.");
261270

262-
impl_->writeImage(field, "scirunOsprayOutput_" + isoString + ".ppm", get_state(), colorMap);
271+
auto isoString = boost::posix_time::to_iso_string(boost::posix_time::microsec_clock::universal_time());
272+
auto filename = "scirunOsprayOutput_" + isoString + ".ppm";
273+
remark("Saving output to " + filename);
274+
impl_->writeImage(field, filename, get_state(), colorMap);
275+
get_state()->setTransientValue(Variables::Filename, filename);
263276

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

src/Modules/Visualization/InterfaceWithOspray.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace SCIRun {
6464
ALGORITHM_PARAMETER_DECL(BackgroundColorG);
6565
ALGORITHM_PARAMETER_DECL(BackgroundColorB);
6666
ALGORITHM_PARAMETER_DECL(FrameCount);
67+
ALGORITHM_PARAMETER_DECL(ShowImageInWindow);
6768
}
6869
}
6970
}

0 commit comments

Comments
 (0)