Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 427729d0 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Cleaned up GenericImageReader and fixed some bugs.

parent fc26d1ca
......@@ -24,6 +24,8 @@
#include "datacontainerfileloaderwidget.h"
#include <QScrollBar>
namespace campvis {
const std::string DataContainerFileLoaderWidget::loggerCat_ = "CAMPVis.application.DataContainerFileLoaderWidget";
......@@ -36,21 +38,20 @@ namespace campvis {
, _fileName("fileName", "Image URL", "")
, _propCollectionWidget(0)
{
this->_parent = parentDataInspector;
this->_dataContainer = this->_parent->getDataContainer();
this->_imgReader = new GenericImageReader();
this->_imgReader->setVisibibility(".mhd", true);
_parent = parentDataInspector;
_dataContainer = _parent->getDataContainer();
_imgReader = new GenericImageReader();
setupGUI();
}
DataContainerFileLoaderWidget::~DataContainerFileLoaderWidget() {
if (this->_dataContainer != 0) {
this->_dataContainer->s_dataAdded.disconnect(this);
if (_dataContainer != 0) {
_dataContainer->s_dataAdded.disconnect(this);
}
}
void DataContainerFileLoaderWidget::setDataContainer(DataContainer* dataContainer) {
this->_dataContainer = dataContainer;
_dataContainer = dataContainer;
}
QSize DataContainerFileLoaderWidget::sizeHint() const {
......@@ -61,33 +62,39 @@ namespace campvis {
void DataContainerFileLoaderWidget::setupGUI() {
setWindowTitle(tr("Browse File"));
this->_layout = new QGridLayout();
this->_layout->setSpacing(2);
_layout = new QGridLayout();
_layout->setSpacing(2);
setLayout(_layout);
this->_pipelinePropertiesScrollArea = new QScrollArea(this);
this->_pipelinePropertiesScrollArea->setWidgetResizable(true);
this->_pipelinePropertiesScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->_pipelinePropertiesScrollArea->setFrameStyle(QScrollArea::NoFrame);
_pipelinePropertiesScrollArea = new QScrollArea(this);
_pipelinePropertiesScrollArea->setWidgetResizable(true);
_pipelinePropertiesScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_pipelinePropertiesScrollArea->setFrameStyle(QScrollArea::NoFrame);
this->installEventFilter(this);
this->_propCollectionWidget = new PropertyCollectionWidget(this->_pipelinePropertiesScrollArea);
this->_layout->addWidget(this->_propCollectionWidget, 0, 0, 1, 2);
this->_propCollectionWidget->updatePropCollection(this->_imgReader, this->_dataContainer);
_propCollectionWidget = new PropertyCollectionWidget(_pipelinePropertiesScrollArea);
_propCollectionWidget->installEventFilter(this);
_pipelinePropertiesScrollArea->setWidget(_propCollectionWidget);
_propCollectionWidget->updatePropCollection(_imgReader, _dataContainer);
_layout->addWidget(_pipelinePropertiesScrollArea, 0, 0, 1, 2);
this->_btnLoadFile = new QPushButton(tr("Load"), this);
this->_layout->addWidget(this->_btnLoadFile, 1, 0, 1, 1);
this->_btnCancel = new QPushButton(tr("Cancel"), this);
this->_layout->addWidget(this->_btnCancel, 1, 1, 1, 1);
_btnLoadFile = new QPushButton(tr("Load"), this);
_layout->addWidget(_btnLoadFile, 1, 0, 1, 1);
_btnCancel = new QPushButton(tr("Cancel"), this);
_layout->addWidget(_btnCancel, 1, 1, 1, 1);
qRegisterMetaType<QtDataHandle>("QtDataHandle");
connect(
this->_btnCancel, SIGNAL(clicked()),
this, SLOT(onBtnCancelClicked()));
connect(
this->_btnLoadFile, SIGNAL(clicked()),
this, SLOT(onBtnLoadFileClicked()));
connect(_btnCancel, SIGNAL(clicked()), this, SLOT(onBtnCancelClicked()));
connect( _btnLoadFile, SIGNAL(clicked()), this, SLOT(onBtnLoadFileClicked()));
}
bool DataContainerFileLoaderWidget::eventFilter(QObject* watched, QEvent* event) {
if (watched == _propCollectionWidget && event->type() == QEvent::Resize) {
_pipelinePropertiesScrollArea->setMinimumWidth(_propCollectionWidget->minimumSizeHint().width() +
_pipelinePropertiesScrollArea->verticalScrollBar()->width());
}
return false;
}
void DataContainerFileLoaderWidget::init() {
......@@ -95,19 +102,19 @@ namespace campvis {
void DataContainerFileLoaderWidget::deinit() {
delete _imgReader;
this->_imgReader = nullptr;
_imgReader = nullptr;
}
void DataContainerFileLoaderWidget::onBtnCancelClicked() {
delete _imgReader;
this->_imgReader = nullptr;
this->close();
_imgReader = nullptr;
close();
}
void DataContainerFileLoaderWidget::onBtnLoadFileClicked() {
this->_imgReader->process(*_dataContainer);
this->_parent->setDataContainer(_dataContainer);
this->close();
_imgReader->process(*_dataContainer);
_parent->setDataContainer(_dataContainer);
close();
}
}
......@@ -94,6 +94,14 @@ namespace campvis {
*/
void setupGUI();
/**
* Listens to resize events on _pipelinePropertiesWidget and resizes _pipelinePropertiesScrollArea accordingly
* \param watched the object that caused the event
* \param event the event to be filtered
*/
bool eventFilter(QObject* watched, QEvent* event);
protected:
DataContainer* _dataContainer; ///< The DataContainer this widget is inspecting
......
......@@ -59,10 +59,10 @@ namespace campvis {
, p_importSimilar("ImportSimilar", "Import All Similar Files", false)
, _shader(nullptr)
{
this->_ext.push_back(".bmp");
this->_ext.push_back(".jpg");
this->_ext.push_back(".png");
this->_ext.push_back(".tif");
this->_ext.push_back("bmp");
this->_ext.push_back("jpg");
this->_ext.push_back("png");
this->_ext.push_back("tif");
this->p_targetImageID.setValue("DevilImageReader.output");
addProperty(p_url);
......
......@@ -36,7 +36,7 @@ namespace campvis {
}
bool AbstractImageReader::acceptsExtension(const std::string& extension) const {
for (std::vector<std::string>::const_iterator it = this->_ext.begin(); it != this->_ext.end(); ++it) {
for (auto it = this->_ext.begin(); it != this->_ext.end(); ++it) {
if (*it == extension) {
return true;
}
......
......@@ -43,7 +43,7 @@ namespace campvis {
, p_imageOffset("ImageOffset", "Image Offset in mm", cgt::vec3(0.f), cgt::vec3(-10000.f), cgt::vec3(10000.f), cgt::vec3(0.1f))
, p_voxelSize("VoxelSize", "Voxel Size in mm", cgt::vec3(1.f), cgt::vec3(-100.f), cgt::vec3(100.f), cgt::vec3(0.1f))
{
this->_ext.push_back(".csv");
this->_ext.push_back("csv");
this->p_targetImageID.setValue("CsvdImageReader.output");
addProperty(p_url);
......
......@@ -40,34 +40,45 @@
#include "modules/io/processors/vtkimagereader.h"
namespace campvis {
namespace {
struct checkExtension {
checkExtension(const std::string& str) : _str(str) {}
bool operator()(const std::pair<AbstractImageReader*, MetaProperty*>& v) const {
return v.first->acceptsExtension(this->_str);
}
private:
std::string _str;
};
}
const std::string GenericImageReader::loggerCat_ = "CAMPVis.modules.io.GenericImageReader";
GenericImageReader::GenericImageReader()
: AbstractProcessor()
, p_url("Url", "Image URL", "", StringProperty::OPEN_FILENAME)
, p_targetImageID("TargetImageName", "Target Image ID", "AbstractImageReader.output", DataNameProperty::WRITE)
, _currentlyVisible(nullptr)
{
addProperty(p_url);
addProperty(p_targetImageID);
p_url.s_changed.connect(this, &GenericImageReader::onUrlPropertyChanged);
this->addReader(new CsvdImageReader());
this->addReader(new LtfImageReader());
this->addReader(new MhdImageReader());
this->addReader(new NiftiImageReader());
this->addReader(new RawImageReader());
this->addReader(new VtkImageReader());
addReader(new CsvdImageReader());
addReader(new LtfImageReader());
addReader(new MhdImageReader());
addReader(new NiftiImageReader());
addReader(new RawImageReader());
addReader(new VtkImageReader());
#ifdef CAMPVIS_HAS_MODULE_DEVIL
this->addReader(new DevilImageReader());
addReader(new DevilImageReader());
#endif
this->_ext = "";
this->_currentlyVisible = nullptr;
}
GenericImageReader::~GenericImageReader() {
for(std::map<AbstractImageReader*, MetaProperty*>::iterator it = this->_readers.begin(); it != this->_readers.end(); ++it) {
for (auto it = _readers.begin(); it != _readers.end(); ++it) {
delete it->second;
delete it->first;
}
......@@ -78,7 +89,7 @@ namespace campvis {
}
void GenericImageReader::deinit() {
for(std::map<AbstractImageReader*, MetaProperty*>::iterator it = this->_readers.begin(); it != this->_readers.end(); ++it) {
for(std::map<AbstractImageReader*, MetaProperty*>::iterator it = _readers.begin(); it != _readers.end(); ++it) {
// deinit MetaProperty first!
if (nullptr != it->second) {
it->second->deinit();
......@@ -91,33 +102,28 @@ namespace campvis {
}
void GenericImageReader::updateResult(DataContainer& data) {
std::map<AbstractImageReader*, MetaProperty*>::iterator it = std::find_if(this->_readers.begin(), this->_readers.end(), checkExt(this->_ext));
if(it != this->_readers.end()) {
if (this->_currentlyVisible != it->second) {
if(nullptr != this->_currentlyVisible) {
this->_currentlyVisible->setVisible(false);
}
(it->second)->setVisible(true);
this->_currentlyVisible = it->second;
}
const std::string extension = cgt::FileSystem::fileExtension(p_url.getValue());
auto it = findReader(extension);
if (it != this->_readers.end()) {
it->first->process(data);
}
}
void GenericImageReader::setVisibibility(const std::string& extention, bool visibility) {
std::string _ext = extention;
std::map<AbstractImageReader*, MetaProperty*>::iterator it = std::find_if(this->_readers.begin(), this->_readers.end(), checkExt(_ext));
if(it != this->_readers.end()) {
if(nullptr != this->_currentlyVisible) {
this->_currentlyVisible->setVisible(!visibility);
}
(it->second)->setVisible(visibility);
void GenericImageReader::updateVisibility(const std::string& extension) {
if (_currentlyVisible != nullptr) {
_currentlyVisible->setVisible(false);
_currentlyVisible = nullptr;
}
auto it = findReader(extension);
if (it != this->_readers.end()) {
it->second->setVisible(true);
this->_currentlyVisible = it->second;
//(it->first)->process(data);
}
}
int GenericImageReader::addReader(AbstractImageReader* reader) {
void GenericImageReader::addReader(AbstractImageReader* reader) {
MetaProperty* meta = new MetaProperty(reader->getName() + "MetaProp", reader->getName());
meta->addPropertyCollection(*reader);
meta->setVisible(false);
......@@ -128,28 +134,21 @@ namespace campvis {
p_targetImageID.addSharedProperty(&reader->p_targetImageID);
reader->p_targetImageID.setVisible(false);
this->_readers.insert(std::pair<AbstractImageReader*, MetaProperty*>(reader, meta));
return 0;
_readers.insert(std::pair<AbstractImageReader*, MetaProperty*>(reader, meta));
}
void GenericImageReader::onUrlPropertyChanged(const AbstractProperty* prop) {
// first set visibility of old extension to false
setVisibibility(_ext, false);
// now update extension
const std::string& url = this->p_url.getValue();
size_t extPos = url.rfind('.');
if (extPos != std::string::npos) {
this->_ext = url.substr(extPos);
}
// set visibility of new extension's properties to true
setVisibibility(_ext, true);
std::string extension = cgt::FileSystem::fileExtension(p_url.getValue());
updateVisibility(extension);
}
void GenericImageReader::adjustToNewExtension() {
std::map<AbstractImageReader*, MetaProperty*>::const_iterator GenericImageReader::findReader(const std::string& extension) const {
auto it = std::find_if(_readers.begin(), _readers.end(), checkExtension(extension));
if (it == _readers.end())
it = std::find_if(_readers.begin(), _readers.end(), checkExtension("raw"));
return it;
}
}
\ No newline at end of file
......@@ -72,7 +72,7 @@ namespace campvis {
/// \see AbstractProcessor::getProcessorState()
virtual ProcessorState getProcessorState() const { return AbstractProcessor::TESTING; };
void setVisibibility(const std::string& extention, bool visibility);
void updateVisibility(const std::string& extension);
StringProperty p_url; ///< URL for file to read
DataNameProperty p_targetImageID; ///< image ID for read image
......@@ -86,10 +86,7 @@ namespace campvis {
private:
void onUrlPropertyChanged(const AbstractProperty* prop);
void adjustToNewExtension();
std::map<AbstractImageReader*, MetaProperty*> _readers;
std::string _ext;
MetaProperty* _currentlyVisible;
/**
......@@ -99,19 +96,18 @@ namespace campvis {
*
* /param reader pointer to the reader to be added
*/
int addReader(AbstractImageReader* reader);
};
void addReader(AbstractImageReader* reader);
/**
* Returns an iterator to the corresponding reader-property pair that can read a file with
* the given extension. If there is no matching reader found, the RawImageReader is returned.
* \param extension Extension to look for.
* \return An iterator to the corresponding reader-property pair.
*/
std::map<AbstractImageReader*, MetaProperty*>::const_iterator findReader(const std::string& extension) const;
struct checkExt {
checkExt( std::string str ) : _str(str) {}
bool operator()( const std::pair<AbstractImageReader*, MetaProperty*>& v ) const {
return v.first->acceptsExtension(this->_str);
}
private:
std::string _str;
};
}
#endif // GENERICIMAGEREADER_H__
......@@ -53,7 +53,7 @@ namespace campvis {
, p_imageOffset("ImageOffset", "Image Offset in mm", cgt::vec3(0.f), cgt::vec3(-10000.f), cgt::vec3(10000.f), cgt::vec3(0.1f))
, p_voxelSize("VoxelSize", "Voxel Size in mm", cgt::vec3(1.f), cgt::vec3(-100.f), cgt::vec3(100.f), cgt::vec3(0.1f))
{
this->_ext.push_back(".ltf");
this->_ext.push_back("ltf");
this->p_targetImageID.setValue("LtfImageReader.output");
addProperty(p_url);
......
......@@ -44,7 +44,7 @@ namespace campvis {
, p_imageOffset("ImageOffset", "Image Offset in mm", cgt::vec3(0.f), cgt::vec3(-10000.f), cgt::vec3(10000.f), cgt::vec3(0.1f))
, p_voxelSize("VoxelSize", "Voxel Size in mm", cgt::vec3(1.f), cgt::vec3(-100.f), cgt::vec3(100.f), cgt::vec3(0.1f))
{
this->_ext.push_back(".mhd");
this->_ext.push_back("mhd");
this->p_targetImageID.setValue("MhdImageReader.output");
addProperty(p_url);
addProperty(p_targetImageID);
......
......@@ -362,8 +362,8 @@ namespace campvis {
, p_imageOffset("ImageOffset", "Image Offset in mm", cgt::vec3(0.f), cgt::vec3(-10000.f), cgt::vec3(10000.f), cgt::vec3(0.1f))
, p_voxelSize("VoxelSize", "Voxel Size in mm", cgt::vec3(1.f), cgt::vec3(-100.f), cgt::vec3(100.f), cgt::vec3(0.1f))
{
this->_ext.push_back(".hdr");
this->_ext.push_back(".nii");
this->_ext.push_back("hdr");
this->_ext.push_back("nii");
this->p_targetImageID.setValue("NiftiImageReader.output");
addProperty(p_url);
addProperty(p_targetImageID);
......
......@@ -58,7 +58,7 @@ namespace campvis {
, p_imageOffset("ImageOffset", "Image Offset in mm", cgt::vec3(0.f), cgt::vec3(-10000.f), cgt::vec3(10000.f), cgt::vec3(0.1f))
, p_voxelSize("VoxelSize", "Voxel Size in mm", cgt::vec3(1.f), cgt::vec3(-100.f), cgt::vec3(100.f), cgt::vec3(0.1f))
{
this->_ext.push_back(".raw");
this->_ext.push_back("raw");
this->p_targetImageID.setValue("RawImageReader.output");
addProperty(p_url);
......
......@@ -48,7 +48,7 @@ namespace campvis {
, p_imageOffset("ImageOffset", "Image Offset in mm", cgt::vec3(0.f), cgt::vec3(-10000.f), cgt::vec3(10000.f), cgt::vec3(0.1f))
, p_voxelSize("VoxelSize", "Voxel Size in mm", cgt::vec3(1.f), cgt::vec3(-100.f), cgt::vec3(100.f), cgt::vec3(0.1f))
{
this->_ext.push_back(".vtk");
this->_ext.push_back("vtk");
this->p_targetImageID.setValue("VtkImageReader.output");
addProperty(p_url);
......
......@@ -36,18 +36,15 @@ namespace campvis {
AdvDVRVis::AdvDVRVis(DataContainer* dc)
: AutoEvaluationPipeline(dc)
, _tcp(&_canvasSize)
, _lsp()
, _imageReader()
, _vr(&_canvasSize, new AdvOptimizedRaycaster(&_canvasSize))
, _ve(&_canvasSize, new SliceExtractor(nullptr), new AdvOptimizedRaycaster(nullptr))
{
_tcp.addLqModeProcessor(&_vr);
addEventListenerToBack(&_tcp);
addEventListenerToBack(&_ve);
addProcessor(&_tcp);
addProcessor(&_lsp);
addProcessor(&_imageReader);
addProcessor(&_vr);
addProcessor(&_ve);
}
AdvDVRVis::~AdvDVRVis() {
......@@ -57,20 +54,19 @@ namespace campvis {
void AdvDVRVis::init() {
AutoEvaluationPipeline::init();
_vr.p_outputImage.setValue("combine");
_ve.p_outputImage.setValue("combine");
_renderTargetID.setValue("combine");
_imageReader.p_url.setValue(ShdrMgr.completePath("/modules/vis/sampledata/smallHeart.mhd"));
_imageReader.p_targetImageID.setValue("reader.output");
_imageReader.p_targetImageID.addSharedProperty(&_vr.p_inputVolume);
_imageReader.p_targetImageID.addSharedProperty(&_tcp.p_image);
_imageReader.p_targetImageID.addSharedProperty(&_ve.p_inputVolume);
Geometry1DTransferFunction* dvrTF = new Geometry1DTransferFunction(128, cgt::vec2(0.f, .05f));
dvrTF->addGeometry(TFGeometry1D::createQuad(cgt::vec2(.12f, .15f), cgt::col4(85, 0, 0, 128), cgt::col4(255, 0, 0, 128)));
dvrTF->addGeometry(TFGeometry1D::createQuad(cgt::vec2(.19f, .28f), cgt::col4(89, 89, 89, 155), cgt::col4(89, 89, 89, 155)));
dvrTF->addGeometry(TFGeometry1D::createQuad(cgt::vec2(.41f, .51f), cgt::col4(170, 170, 128, 64), cgt::col4(192, 192, 128, 64)));
static_cast<TransferFunctionProperty*>(_vr.getNestedProperty("RaycasterProps::TransferFunction"))->replaceTF(dvrTF);
static_cast<FloatProperty*>(_vr.getNestedProperty("RaycasterProps::SamplingRate"))->setValue(4.f);
static_cast<TransferFunctionProperty*>(_ve.getNestedProperty("VolumeRendererProperties::RaycasterProps::TransferFunction"))->replaceTF(dvrTF);
static_cast<FloatProperty*>(_ve.getNestedProperty("VolumeRendererProperties::RaycasterProps::SamplingRate"))->setValue(4.f);
}
}
\ No newline at end of file
......@@ -31,9 +31,8 @@
#include "modules/modulesapi.h"
#include "modules/pipelinefactory.h"
#include "modules/base/processors/lightsourceprovider.h"
#include "modules/base/processors/trackballcameraprovider.h"
#include "modules/io/processors/mhdimagereader.h"
#include "modules/vis/processors/volumerenderer.h"
#include "modules/io/processors/genericimagereader.h"
#include "modules/vis/processors/volumeexplorer.h"
namespace campvis {
class CAMPVIS_MODULES_API AdvDVRVis : public AutoEvaluationPipeline {
......@@ -57,10 +56,9 @@ namespace campvis {
protected:
TrackballCameraProvider _tcp;
LightSourceProvider _lsp;
MhdImageReader _imageReader;
VolumeRenderer _vr;
GenericImageReader _imageReader;
VolumeExplorer _ve;
};
// Instantiate template to register the pipelines.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment