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

Commit 5c930d64 authored by schultezub's avatar schultezub

* added visibility flag and corresponding signal for properties

* added InvalidationLevel::INVALID_PROPERTIES level
* added HasPropertyCollection::updateProperties() method being triggerd upon INVALID_PROPERTIES invalidation

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@423 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 9d75cf0d
......@@ -48,16 +48,12 @@ namespace campvis {
}
PropertyCollectionWidget::~PropertyCollectionWidget() {
qDeleteAll(_widgetList);
clearWidgetMap();
}
void PropertyCollectionWidget::updatePropCollection(HasPropertyCollection* propertyCollection) {
// remove and delete all widgets of the previous PropertyCollection
for (QList<QWidget*>::iterator it = _widgetList.begin(); it != _widgetList.end(); ++it) {
_layout->removeWidget(*it);
}
qDeleteAll(_widgetList);
_widgetList.clear();
clearWidgetMap();
// create widgets for the new PropertyCollection
for (std::vector<AbstractProperty*>::const_iterator it = propertyCollection->getProperties().begin(); it != propertyCollection->getProperties().end(); ++it) {
......@@ -65,8 +61,10 @@ namespace campvis {
if (propWidget == 0)
propWidget = new QPushButton(QString::fromStdString((*it)->getTitle()));
_widgetList.push_back(propWidget);
_widgetMap.insert(std::make_pair(*it, propWidget));
_layout->addWidget(propWidget);
propWidget->setVisible((*it)->isVisible());
(*it)->s_visibilityChanged.connect(this, &PropertyCollectionWidget::onPropertyVisibilityChanged);
}
}
......@@ -76,4 +74,21 @@ namespace campvis {
setLayout(_layout);
}
void PropertyCollectionWidget::clearWidgetMap() {
for (std::map<AbstractProperty*, QWidget*>::iterator it = _widgetMap.begin(); it != _widgetMap.end(); ++it) {
it->first->s_visibilityChanged.disconnect(this);
_layout->removeWidget(it->second);
delete it->second;
}
_widgetMap.clear();
}
void PropertyCollectionWidget::onPropertyVisibilityChanged(const AbstractProperty* prop) {
// const_cast does not harm anything.
std::map<AbstractProperty*, QWidget*>::iterator item = _widgetMap.find(const_cast<AbstractProperty*>(prop));
if (item != _widgetMap.end())
item->second->setVisible(item->first->isVisible());
}
}
\ No newline at end of file
......@@ -30,18 +30,21 @@
#ifndef PROPERTYCOLLECTIONWIDGET_H__
#define PROPERTYCOLLECTIONWIDGET_H__
#include "sigslot/sigslot.h"
#include <QList>
#include <QVBoxLayout>
#include <QWidget>
#include <map>
namespace campvis {
class AbstractProperty;
class HasPropertyCollection;
/**
* Main Window for the CAMPVis application.
* Wraps a nice Qt GUI around the TumVisApplication instance given during creation.
*/
class PropertyCollectionWidget : public QWidget {
class PropertyCollectionWidget : public QWidget, public sigslot::has_slots<> {
Q_OBJECT;
public:
......@@ -63,6 +66,11 @@ namespace campvis {
*/
void updatePropCollection(HasPropertyCollection* propertyCollection);
/**
* Slot to be called when one of the propertie's visibility has changed.
* \param prop Property that emitted the signal
*/
void onPropertyVisibilityChanged(const AbstractProperty* prop);
private:
/**
......@@ -70,9 +78,15 @@ namespace campvis {
*/
void setupWidget();
/**
* Clears the _widgetMap and destroys all widgets inside.
*/
void clearWidgetMap();
HasPropertyCollection* _propCollection; ///< The HasPropertyCollection instance this widget is currently working on.
QVBoxLayout* _layout;
QList<QWidget*> _widgetList;
std::map<AbstractProperty*, QWidget*> _widgetMap;
//QList<QWidget*> _widgetList;
};
}
......
......@@ -77,7 +77,8 @@ namespace campvis {
}
void AbstractPipeline::onPropertyChanged(const AbstractProperty* prop) {
_invalidationLevel.setLevel(InvalidationLevel::INVALID_RESULT);
HasPropertyCollection::onPropertyChanged(prop);
_invalidationLevel.setLevel(InvalidationLevel::INVALID_RESULT);
s_PipelineInvalidated();
}
......@@ -134,4 +135,6 @@ namespace campvis {
tgtAssert(processor != 0, "Processor must not be 0.")
_processors.push_back(processor);
}
}
......@@ -75,6 +75,7 @@ namespace campvis {
}
void AbstractProcessor::onPropertyChanged(const AbstractProperty* prop) {
HasPropertyCollection::onPropertyChanged(prop);
applyInvalidationLevel(prop->getInvalidationLevel());
}
......@@ -86,4 +87,5 @@ namespace campvis {
_enabled = enabled;
}
}
......@@ -38,6 +38,7 @@ namespace campvis {
, _title(title)
, _invalidationLevel(il)
{
_isVisible = true;
_inUse = false;
}
......@@ -94,4 +95,13 @@ namespace campvis {
}
bool AbstractProperty::isVisible() const {
return _isVisible;
}
void AbstractProperty::setVisible(bool isVisible) {
_isVisible = isVisible;
s_visibilityChanged(this);
}
}
......@@ -98,6 +98,17 @@ namespace campvis {
*/
void setInvalidationLevel(const InvalidationLevel& il);
/**
* Returns whether this proberty shall be visible in the GUI.
* \return _isVisible
*/
bool isVisible() const;
/**
* Sets whether this property shall be visible in the GUI.
* \param isVisible new visibility flag
*/
void setVisible(bool isVisible);
/**
* Adds the given property \a prop to the set of shared properties.
......@@ -139,12 +150,16 @@ namespace campvis {
/// Signal emitted, when the property changes.
sigslot::signal1<const AbstractProperty*> s_changed;
/// Signal emitted, when the visibility of this property changed
sigslot::signal1<const AbstractProperty*> s_visibilityChanged;
protected:
// DO NOT REMOVE THE CONSTNESS OF _name. PropertyCollection relies on it!
const std::string _name; ///< Property name (unchangable on purpose!)
std::string _title; ///< Property title (e.g. used for GUI)
InvalidationLevel _invalidationLevel; ///< Invalidation level that this property triggers
tbb::atomic<bool> _isVisible; ///< Flag whether this property shall be visible in the GUI
tbb::atomic<bool> _inUse; ///< flag whether property is currently in use and values are written to back buffer
tbb::spin_mutex _localMutex; ///< Mutex used when altering local members
......
......@@ -115,4 +115,13 @@ namespace campvis {
}
}
void HasPropertyCollection::onPropertyChanged(const AbstractProperty* prop) {
if (prop->getInvalidationLevel().isInvalidProperties())
updateProperties();
}
void HasPropertyCollection::updateProperties() {
}
}
\ No newline at end of file
......@@ -114,9 +114,15 @@ namespace campvis {
* Slot getting called when one of the observed properties changed and notifies its observers.
* \param prop Property that emitted the signal
*/
virtual void onPropertyChanged(const AbstractProperty* prop) = 0;
virtual void onPropertyChanged(const AbstractProperty* prop);
protected:
/**
* Gets called, when one of the properties invalidates with an INVALID_PROPERTIES level.
* \note You may overload this method as needed.
*/
virtual void updateProperties();
/**
* Searches _properties for a property named \a name.
* \param name Property name to search for.
......
......@@ -47,6 +47,7 @@ namespace campvis {
INVALID_RESULT = 1 << 0,
INVALID_SHADER = 1 << 1,
INVALID_FILE = 1 << 2,
INVALID_PROPERTIES = 1 << 3
};
/**
......@@ -81,6 +82,10 @@ namespace campvis {
return (_level & static_cast<int>(INVALID_SHADER)) != 0;
}
bool isInvalidProperties() const {
return (_level & static_cast<int>(INVALID_PROPERTIES)) != 0;
}
void setValid() {
_level = static_cast<int>(VALID);
......
......@@ -193,7 +193,7 @@ namespace campvis {
: AbstractProcessor()
, p_sourceImageID("InputVolume", "Input Volume ID", "volume", DataNameProperty::READ)
, p_targetImageID("OutputGradients", "Output Gradient Volume ID", "gradients", DataNameProperty::WRITE)
, p_filterMode("FilterMode", "Filter Mode", filterModes, 5)
, p_filterMode("FilterMode", "Filter Mode", filterModes, 5, InvalidationLevel::INVALID_RESULT | InvalidationLevel::INVALID_PROPERTIES)
, p_kernelSize("KernelSize", "Kernel Size", 3, 3, 15)
, p_sigma("Sigma", "Sigma", 1.f, .1f, 10.f)
, p_numberOfSteps("NumberOfSteps", "Number of Steps", 5, 1, 15)
......@@ -263,4 +263,35 @@ namespace campvis {
_invalidationLevel.setValid();
}
void ItkImageFilter::updateProperties() {
if (p_filterMode.getOptionValue() == "median") {
p_kernelSize.setVisible(true);
p_sigma.setVisible(false);
p_numberOfSteps.setVisible(false);
p_timeStep.setVisible(false);
p_conductance.setVisible(false);
}
else if (p_filterMode.getOptionValue() == "gauss") {
p_kernelSize.setVisible(false);
p_sigma.setVisible(true);
p_numberOfSteps.setVisible(false);
p_timeStep.setVisible(false);
p_conductance.setVisible(false);
}
else if (p_filterMode.getOptionValue() == "sobel") {
p_kernelSize.setVisible(false);
p_sigma.setVisible(false);
p_numberOfSteps.setVisible(false);
p_timeStep.setVisible(false);
p_conductance.setVisible(false);
}
else if (p_filterMode.getOptionValue() == "gradientDiffusion" || p_filterMode.getOptionValue() == "curvatureDiffusion") {
p_kernelSize.setVisible(false);
p_sigma.setVisible(false);
p_numberOfSteps.setVisible(true);
p_timeStep.setVisible(true);
p_conductance.setVisible(true);
}
}
}
......@@ -74,6 +74,8 @@ namespace campvis {
FloatProperty p_conductance;
protected:
/// \see AbstractProcessor::updateProperties
virtual void updateProperties();
static const std::string loggerCat_;
};
......
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