Commit 5d00488d authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Merge branch '3dMISegment-flat-rebased' into 'development'

3d mi segment flat rebased

See merge request !89
parents 2a2ff2b5 ff14d163
......@@ -53,6 +53,7 @@ SET(CampvisApplicationToBeMocced
gui/properties/datanamepropertywidget.h
gui/properties/intpropertywidget.h
gui/properties/floatpropertywidget.h
gui/properties/colorpropertywidget.h
gui/properties/geometry1dtransferfunctioneditor.h
gui/properties/geometry2dtransferfunctioneditor.h
gui/properties/metapropertywidget.h
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// 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.
//
// ================================================================================================
#include "colorpropertywidget.h"
#include "core/properties/colorproperty.h"
namespace campvis {
ColorPropertyWidget::ColorPropertyWidget(ColorProperty* property, DataContainer* dataContainer, QWidget* parent /*= 0*/)
: AbstractPropertyWidget(property, false, dataContainer, parent)
//, _lblColorPicker(0)
, _colorPicker(0)
{
//_lblColorPicker = new QLabel("Change color: ", this);
_colorPicker = new ColorPickerWidget(QtColorTools::toQColor(property->getValue()), this);
addWidget(_colorPicker);
//connect(_colorPicker, SIGNAL(valueChanged(tgt::vec4)), this, SLOT(onColorChanged(tgt::vec4)));
connect(_colorPicker, SIGNAL(colorChanged(const QColor&)), this, SLOT(onColorChanged(const QColor&)));
}
ColorPropertyWidget::~ColorPropertyWidget() {
}
void ColorPropertyWidget::updateWidgetFromProperty() {
_colorPicker->blockSignals(true);
const tgt::vec4 val = static_cast<ColorProperty*>(_property)->getValue();
_colorPicker->setColor(QtColorTools::toQColor(tgt::vec4(val.x *255, val.y*255, val.z*255, val.w*255)));
_colorPicker->blockSignals(false);
}
void ColorPropertyWidget::onColorChanged(const QColor& value) {
++_ignorePropertyUpdates;
ColorProperty* prop = static_cast<ColorProperty*>(_property);
tgt::vec4 val = QtColorTools::toTgtColor(_colorPicker->color());
prop->setValue(tgt::vec4(val.x/val.w, val.y/val.w, val.z/val.w, 1));
--_ignorePropertyUpdates;
}
void ColorPropertyWidget::onPropertyMinMaxChanged(const AbstractProperty* property) {
if (_ignorePropertyUpdates == 0)
emit s_propertyChanged(property);
}
}
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// 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.
//
// ================================================================================================
#ifndef COLORPROPERTYWIDGET_H__
#define COLORPROPERTYWIDGET_H__
#include "application/gui/adjusterwidgets/doubleadjusterwidget.h"
#include "application/gui/properties/abstractpropertywidget.h"
#include "application/gui/properties/propertywidgetfactory.h"
#include "core/properties/floatingpointproperty.h"
#include "core/properties/colorproperty.h"
#include "application/gui/qtcolortools.h"
namespace campvis {
/**
* Widget for a ColorProperty
*/
class ColorPropertyWidget : public AbstractPropertyWidget {
Q_OBJECT
public:
/**
* Creates a new FloatPropertyWidget for the property \a property.
* \param property The property the widget shall handle
* \param dataContainer DataContainer to use (optional), defaults to nullptr.
* \param parent Parent Qt widget
*/
ColorPropertyWidget(ColorProperty* property, DataContainer* dataContainer, QWidget* parent = 0);
/**
* Destructor
*/
virtual ~ColorPropertyWidget();
protected:
/**
* Gets called when the property has changed, so that widget can update its state.
*/
virtual void updateWidgetFromProperty();
private slots:
/// Slot getting called when the adjuster's value changes
void onColorChanged(const QColor&);
private:
/// Slot getting called when the property's min or max value has changed, so that the widget can be updated.
virtual void onPropertyMinMaxChanged(const AbstractProperty* property);
//QLabel *_lblColorPicker;
ColorPickerWidget * _colorPicker; ///< color picker widget allowing to change color
};
// ================================================================================================
// explicitly instantiate template, so that it gets registered also over DLL boundaries.
template class PropertyWidgetRegistrar<ColorPropertyWidget, ColorProperty>;
}
#endif // COLORPROPERTYWIDGET_H__
// WARNING: This file is automatically generated by CMake, do not modify!
// Include Converter Headers:
#include "datastructures/imagerepresentationconversioncore.h"
......@@ -51,9 +51,9 @@ namespace campvis {
class CAMPVIS_CORE_API VisualizationProcessor : public AbstractProcessor {
public:
/**
* Utility struct to encapuslate off-screen rendering with this processor using FBOs.
* Utility struct to encapsulate off-screen rendering with this processor using FBOs.
* This guard essentially activates the VisualizationProcessor's FBO and sets the OpenGL
* viewport size. Upon destruction it detaches all texutres and deactivates the FBO again.
* viewport size. Upon destruction it detaches all textures and deactivates the FBO again.
*/
struct CAMPVIS_CORE_API FramebufferActivationGuard {
public:
......
#include "core/properties/colorproperty.h"
namespace campvis {
}
#ifndef COLORPROPERTY_H__
#define COLORPROPERTY_H__
# include "core/properties/floatingpointproperty.h"
namespace campvis {
template <typename T>
class _ColorProperty : public FloatingPointProperty<T> {
public:
/**
* Creates a new FloatingPointProperty.
* \param name Property name
* \param title Property title (e.g. used for GUI)
* \param value Initial value of the property
* \param minValue Minimum value for this property
* \param maxValue Maximum value for this property
* \param stepValue Step value for this property
* \param decimals Number of significant decimal places
*/
_ColorProperty(
const std::string& name,
const std::string& title,
const T& value,
const T& minValue,
const T& maxValue,
const T& stepValue = T(0.01f));
static const std::string loggerCat_;
};
template<typename T>
const std::string campvis::_ColorProperty<T>::loggerCat_ = "CAMPVis.core.properties.ColorProperty";
typedef _ColorProperty<tgt::vec4> ColorProperty;
template<typename T>
_ColorProperty<T>::_ColorProperty(
const std::string& name,
const std::string& title,
const T& value,
const T& minValue,
const T& maxValue,
const T& stepValue)
: Vec4Property(name, title, value, minValue, maxValue, stepValue)
{
}
}
#endif // COLORPROPERTY_H__
......@@ -36,6 +36,12 @@ namespace campvis {
MetaProperty::~MetaProperty() {
}
void MetaProperty::deinit() {
for (size_t i = 0; i < _properties.size(); ++i) {
removeProperty(*_properties[i]);
}
}
void MetaProperty::onPropertyChanged(const AbstractProperty* prop) {
s_changed.emitSignal(this);
}
......
......@@ -53,6 +53,8 @@ namespace campvis {
**/
virtual ~MetaProperty();
/// \see AbstractProperty::deinit
virtual void deinit();
/// \see HasPropertyCollection::onPropertyChanged
virtual void onPropertyChanged(const AbstractProperty* prop);
......
......@@ -68,7 +68,7 @@ namespace campvis {
, _title(title)
, _value(value)
{};
std::string _id;
std::string _title;
T _value;
......@@ -161,6 +161,41 @@ namespace campvis {
* \param option Option to set.
*/
void selectByOption(T option);
/**
* Add a new Option
* \param option New option to add
* returns Number of items
*/
size_t addOption(GenericOption<T> option);
/**
* Update current option
* \param copy Data to copy from
* returns Number of items
*/
size_t updateCurrent(GenericOption<T> copy);
size_t updateCurrent(T& copy);
/**
* Remove current copy, except the last one
* returns Number of items
*/
size_t removeCurrent();
/**
* Returns a non-const reference of current option's value
* \param index Position to
* \note With great power comes great responsibility
* returns Number of items
*/
T& getOptionReference(int index = -1);
/**
* Get Option count
* returns Number of items
*/
size_t getOptionCount();
protected:
std::vector< GenericOption<T> > _options;
......@@ -223,7 +258,7 @@ namespace campvis {
template<typename T>
void campvis::GenericOptionProperty<T>::selectByIndex(int index) {
tgtAssert(index > 0 && index < _options.size(), "Index out of bounds.");
tgtAssert(index >= 0 && index < static_cast<int>(_options.size()), "Index out of bounds.");
setValue(index);
}
......@@ -238,6 +273,48 @@ namespace campvis {
LERROR("Could not find specified option.");
}
template<typename T>
size_t campvis::GenericOptionProperty<T>::addOption(GenericOption<T> option) {
this->_options.push_back(option);
setMaxValue(static_cast<int>(this->_options.size()) - 1);
return this->_options.size();
}
template<typename T>
size_t campvis::GenericOptionProperty<T>::removeCurrent() {
size_t index = getValue();
if (index == 0) return 0;
if (index <= this->_options.size()-1)
this->_options.erase(this->_options.begin() + index);
selectByIndex((index <= this->_options.size() - 1) ? static_cast<int>(index) : static_cast<int>(this->_options.size() - 1));
return (index <= this->_options.size() - 1) ? index : this->_options.size() - 1;
}
template<typename T>
size_t campvis::GenericOptionProperty<T>::updateCurrent(GenericOption<T> copy) {
GenericOption<T>* it = &this->_options[getValue()];
it->_id = copy._id;
it->_title = copy._title;
it->_value = copy._value;
return this->_options.size();
}
template<typename T>
size_t campvis::GenericOptionProperty<T>::updateCurrent(T& copy) {
GenericOption<T>* it = &this->_options[getValue()];
it->_value = copy;
return this->_options.size();
}
template<typename T>
T& campvis::GenericOptionProperty<T>::getOptionReference(int index) {
return (index == -1) ? _options[_value]._value : _options[index]._value;
}
template<typename T>
size_t campvis::GenericOptionProperty<T>::getOptionCount() {
return _options.size();
}
}
#endif // OPTIONPROPERTY_H__
......@@ -66,6 +66,17 @@ namespace campvis {
void setDisplayType(DisplayType val) { _displayType = val; }
/**
* Overloads == operator.
* \param rhs Object to compare with.
**/
bool operator==(StringProperty& rhs) {
return this->getValue() == rhs.getValue()
&& this->getName() == rhs.getName()
&& this->getTitle() == rhs.getTitle();
}
protected:
DisplayType _displayType;
......
......@@ -27,6 +27,7 @@
#include <IL/il.h>
#include <cstring>
#include <vector>
#include "tgt/logmanager.h"
#include "tgt/filesystem.h"
......@@ -40,30 +41,40 @@
#include "core/datastructures/genericimagerepresentationlocal.h"
#include "core/tools/quadrenderer.h"
#include "core/tools/stringutils.h"
#include "core/tools/mapping.h"
namespace campvis {
const std::string DevilImageReader::loggerCat_ = "CAMPVis.modules.io.DevilImageReader";
GenericOption<std::string> importOptions[3] = {
GenericOption<std::string> importOptions[4] = {
GenericOption<std::string>("rt", "Render Target"),
GenericOption<std::string>("texture", "OpenGL Texture"),
GenericOption<std::string>("localIntensity", "Local Intensity Image")
GenericOption<std::string>("localIntensity", "Local Intensity Image"),
GenericOption<std::string>("localIntensity3", "Local Intensity Image RGB")
};
DevilImageReader::DevilImageReader(IVec2Property* viewportSizeProp)
: VisualizationProcessor(viewportSizeProp)
, p_url("url", "Image URL", "", StringProperty::OPEN_FILENAME)
, p_targetImageID("targetImageName", "Target Image ID", "DevilImageReader.output", DataNameProperty::WRITE)
, p_importType("ImportType", "Import Type", importOptions, 3)
, p_importType("ImportType", "Import Type", importOptions, 4)
, p_importSimilar("ImportSimilar", "Import All Similar Files", false)
, _shader(nullptr)
, _devilTextureReader(nullptr)
{
this->_ext.push_back(".jpg");
this->_ext.push_back(".png");
this->_ext.push_back(".tif");
this->p_targetImageID.setValue("DevilImageReader.output");
addProperty(p_url);
addProperty(p_targetImageID);
addProperty(p_importType);
addProperty(p_importSimilar);
_devilTextureReader = new tgt::TextureReaderDevil();
p_importType.selectById("localIntensity3");
}
DevilImageReader::~DevilImageReader() {
......@@ -83,10 +94,23 @@ namespace campvis {
}
void DevilImageReader::updateResult(DataContainer& data) {
std::string url = this->p_url.getValue();
std::string base = "", numstr = "", ext = "";
size_t _Pos = url.rfind('_');
size_t dotPos = url.rfind('.');
if (dotPos > _Pos && dotPos != std::string::npos && _Pos != std::string::npos ) {
numstr = url.substr(_Pos+1, dotPos);
base = url.substr(0, _Pos+1);
ext = url.substr(dotPos);
}
int suffix = StringUtils::fromString<int>(numstr);
std::cout << "\nfileName Suffix: "<<suffix <<" count: "<<dotPos-_Pos <<std::endl;
tgt::Texture* tex = _devilTextureReader->loadTexture(p_url.getValue(), tgt::Texture::LINEAR, false, true, true, false);
if (tex != 0) {
if (p_importType.getOptionValue() == "rt") {
ImageData id (2, tex->getDimensions(), tex->getNumChannels());
ImageData id (3, tex->getDimensions(), tex->getNumChannels());
ImageRepresentationGL* image = ImageRepresentationGL::create(&id, tex);
FramebufferActivationGuard fag(this);
......@@ -112,7 +136,7 @@ namespace campvis {
data.addData(p_targetImageID.getValue(), new RenderData(_fbo));
}
else if (p_importType.getOptionValue() == "texture") {
ImageData* id = new ImageData(2, tex->getDimensions(), tex->getNumChannels());
ImageData* id = new ImageData(3, tex->getDimensions(), tex->getNumChannels());
ImageRepresentationGL::create(id, tex);
data.addData(p_targetImageID.getValue(), id);
}
......@@ -121,7 +145,7 @@ namespace campvis {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
tex->downloadTexture();
size_t numElements = tgt::hmul(tex->getDimensions());
ImageData* id = new ImageData(2, tex->getDimensions(), 1);
ImageData* id = new ImageData(3, tex->getDimensions(), 1);
// TODO: use macro magic to switch through the different data types and number of channels
if (tex->getDataType() == GL_UNSIGNED_BYTE && tex->getNumChannels() == 3) {
......@@ -136,6 +160,48 @@ namespace campvis {
delete tex;
data.addData(p_targetImageID.getValue(), id);
}
else if (p_importType.getOptionValue() == "localIntensity3") {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
tex->downloadTexture();
size_t numElements = tgt::hmul(tex->getDimensions());
tgt::ivec3 temp = tex->getDimensions();
int zee = 0;
std::vector<tgt::Vector3<uint8_t> > vdata;
while (nullptr != tex) {
if (tex->getDataType() == GL_UNSIGNED_BYTE && tex->getNumChannels() == 3) {
tgt::Vector3<uint8_t>* data = reinterpret_cast<tgt::Vector3<uint8_t>*>(tex->getPixelData());
for (size_t i = 0; i < numElements*1; ++i) {
for(int k = 0; k < temp.z; k++){
vdata.push_back(data[i % numElements]);
}
}
zee+=1;
}
delete tex;
if (this->p_importSimilar.getValue() == true) {
numstr = StringUtils::toString(++suffix, dotPos-_Pos-1, '0');
std::cout << base+numstr+ext;
tex = _devilTextureReader->loadTexture(base+numstr+ext, tgt::Texture::LINEAR, false, true, true, false);
if(nullptr != tex)
tex->downloadTexture();
}
else {
break;
}
}
temp.z = zee;
ImageData* id = new ImageData(3, temp, 3);
tgt::Vector3<uint8_t>* data3d = new tgt::Vector3<uint8_t>[temp.x * temp.y * temp.z];
memcpy(data3d, &vdata.front(), temp.x*temp.y*temp.z *3);
GenericImageRepresentationLocal<uint8_t, 3>::create(id, data3d);
id->setMappingInformation(ImageMappingInformation(id->getSize(), id->getMappingInformation().getOffset(), id->getMappingInformation().getVoxelSize() * tgt::vec3(1, 1, 1) ));
data.addData(p_targetImageID.getValue(), id);
}
}
else {
LDEBUG("Could not load image.");
......
......@@ -33,6 +33,8 @@
#include "core/properties/optionproperty.h"
#include "core/properties/stringproperty.h"
#include "modules/io/processors/abstractimagereader.h"
namespace tgt {
class Shader;
class TextureReaderDevil;
......@@ -45,7 +47,7 @@ namespace campvis {
*
* \note Full list of supported formats: http://openil.sourceforge.net/features.php
*/
class DevilImageReader : public VisualizationProcessor {
class DevilImageReader : public AbstractImageReader, public VisualizationProcessor {
public:
/**
* Constructs a new DevilImageReader Processor
......@@ -73,9 +75,8 @@ namespace campvis {
/// \see AbstractProcessor::getProcessorState()
virtual ProcessorState getProcessorState() const { return AbstractProcessor::EXPERIMENTAL; };
StringProperty p_url; ///< URL for file to read
DataNameProperty p_targetImageID; ///< image ID for read image
GenericOptionProperty<std::string> p_importType;
BoolProperty p_importSimilar;
protected:
/// \see AbstractProcessor::updateResult
......
......@@ -42,7 +42,7 @@ namespace campvis {
* of files into ImageRepresentationDisk representation
*
*/
class AbstractImageReader : public AbstractProcessor {
class AbstractImageReader {
public:
/**
* Constructs a new AbstractImageReader Processor
......
......@@ -37,7 +37,7 @@ namespace campvis {
* Reads a CSVD to read multiple CSV image files into the pipeline.
* This YANF (yet another neat format) is proudly provided by Christian Schulte zu Berge.
*/
class CsvdImageReader : public AbstractImageReader {
class CsvdImageReader : public AbstractImageReader, public AbstractProcessor {
public:
/**
* Constructs a new CsvdImageReader Processor
......
......@@ -34,7 +34,7 @@
namespace campvis {
const std::string GenericImageReader::loggerCat_ = "CAMPVis.modules.io.MhdImageReader";
const std::string GenericImageReader::loggerCat_ = "CAMPVis.modules.io.GenericImageReader";
GenericImageReader::GenericImageReader()
: AbstractProcessor()
......@@ -48,6 +48,7 @@ namespace campvis {
this->addReader(new MhdImageReader());
this->addReader(new RawImageReader());
this->addReader(new VtkImageReader());