Commit d9ae79b6 authored by schultezub's avatar schultezub

replaced DataHandle pointers by simple DataHandle instances - managing...

replaced DataHandle pointers by simple DataHandle instances - managing pointers to smart pointers is cumbersome and prone to errors...

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@318 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 192d5803
......@@ -87,13 +87,6 @@ namespace TUMVis {
_dataContainer->s_dataAdded.disconnect(this);
}
{
tbb::mutex::scoped_lock lock(_localMutex);
for (std::map<std::string, const DataHandle*>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
delete it->second;
}
}
GLJobProc.deregisterContext(this);
ShdrMgr.dispose(_paintShader);
delete _quad;
......@@ -106,10 +99,6 @@ namespace TUMVis {
{
tbb::mutex::scoped_lock lock(_localMutex);
_dataContainer = dataContainer;
for (std::map<std::string, const DataHandle*>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
delete it->second;
}
_handles = _dataContainer->getHandlesCopy();
}
......@@ -124,20 +113,19 @@ namespace TUMVis {
return QSize(640, 480);
}
void DataContainerInspectorCanvas::onDataContainerDataAdded(const std::string& name, const DataHandle* dh) {
void DataContainerInspectorCanvas::onDataContainerDataAdded(const std::string& name, const DataHandle& dh) {
{
tbb::mutex::scoped_lock lock(_localMutex);
// check whether DataHandle is already existing
std::map<std::string, const DataHandle*>::iterator lb = _handles.lower_bound(name);
std::map<std::string, DataHandle>::iterator lb = _handles.lower_bound(name);
if (lb == _handles.end() || lb->first != name) {
// not existant -> insert
_handles.insert(std::make_pair(name, new DataHandle(*dh)));
_handles.insert(std::make_pair(name, dh));
}
else {
// existant -> replace
delete lb->second;
lb->second = new DataHandle(*dh);
lb->second = dh;
}
}
......@@ -148,12 +136,12 @@ namespace TUMVis {
tbb::mutex::scoped_lock lock(_localMutex);
std::vector<const tgt::Texture*> textures;
for (std::map<std::string, const DataHandle*>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
if (const ImageDataGL* imgGL = dynamic_cast<const ImageDataGL*>(it->second->getData())) {
for (std::map<std::string, DataHandle>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
if (const ImageDataGL* imgGL = dynamic_cast<const ImageDataGL*>(it->second.getData())) {
if (imgGL->getDimensionality() == 2)
textures.push_back(imgGL->getTexture());
}
else if (const ImageDataRenderTarget* imgRT = dynamic_cast<const ImageDataRenderTarget*>(it->second->getData())) {
else if (const ImageDataRenderTarget* imgRT = dynamic_cast<const ImageDataRenderTarget*>(it->second.getData())) {
if (imgRT->getDimensionality() == 2) {
for (size_t i = 0; i < imgRT->getNumColorTextures(); ++i)
textures.push_back(imgRT->getColorTexture(i));
......
......@@ -106,7 +106,7 @@ namespace TUMVis {
* \param name Name of the added data.
* \param dh DataHandle to the newly added data.
*/
void onDataContainerDataAdded(const std::string& name, const DataHandle* dh);
void onDataContainerDataAdded(const std::string& name, const DataHandle& dh);
/**
* To be called when the canvas is invalidated, issues new paint job.
......@@ -117,8 +117,8 @@ namespace TUMVis {
void createQuad(float width, float height);
DataContainer* _dataContainer; ///< The DataContainer this widget is inspecting
std::map<std::string, const DataHandle*> _handles; ///< Local copy of the DataHandles to inspect
DataContainer* _dataContainer; ///< The DataContainer this widget is inspecting
std::map<std::string, DataHandle> _handles; ///< Local copy of the DataHandles to inspect
tbb::mutex _localMutex;
tgt::Shader* _paintShader;
......
......@@ -69,9 +69,9 @@ namespace TUMVis {
}
}
void DataContainerInspectorWidget::onDataContainerDataAdded(const std::string& key, const DataHandle* dh) {
void DataContainerInspectorWidget::onDataContainerDataAdded(const std::string& key, const DataHandle& dh) {
// copy DataHandle because signal will be handled by a different thread an indefinite amount of time later:
emit dataContainerChanged(QString::fromStdString(key), new DataHandle(*dh));
emit dataContainerChanged(QString::fromStdString(key), dh);
}
QSize DataContainerInspectorWidget::sizeHint() const {
......
......@@ -78,7 +78,7 @@ namespace TUMVis {
/**
* Slot called when _dataContainer has changed and emitted the s_dataAdded signal.
*/
void onDataContainerDataAdded(const std::string&, const DataHandle*);
void onDataContainerDataAdded(const std::string&, const DataHandle&);
/**
* Size hint for the default window size
......@@ -87,7 +87,7 @@ namespace TUMVis {
QSize sizeHint() const;
signals:
void dataContainerChanged(const QString&, const DataHandle*);
void dataContainerChanged(const QString&, const DataHandle&);
private slots:
/**
......
......@@ -46,13 +46,12 @@ namespace TUMVis {
// ================================================================================================
DataHandleTreeItem::DataHandleTreeItem(const DataHandle* dataHandle, const std::string& name, TreeItem* parent)
DataHandleTreeItem::DataHandleTreeItem(const DataHandle& dataHandle, const std::string& name, TreeItem* parent)
: TreeItem(parent)
, _dataHandle(dataHandle)
, _name(name)
{
tgtAssert(_dataHandle != 0, "DataHandle must not be 0.");
tgtAssert(_dataHandle->getData() != 0, "WTF - DataHandle with empty data?");
tgtAssert(_dataHandle.getData() != 0, "WTF - DataHandle with empty data?");
}
QVariant DataHandleTreeItem::getData(int column, int role) const {
......@@ -61,7 +60,7 @@ namespace TUMVis {
if (column == COLUMN_NAME)
return QVariant(QString::fromStdString(_name));
else if (column == COLUMN_TYPE) {
const AbstractData* data = _dataHandle->getData();
const AbstractData* data = _dataHandle.getData();
tgtAssert(data != 0, "WTF - DataHandle with empty data?");
if (const ImageDataDisk* tester = dynamic_cast<const ImageDataDisk*>(data)) {
return QVariant(QString("ImageData on disk"));
......@@ -80,18 +79,16 @@ namespace TUMVis {
return QVariant();
case Qt::UserRole:
// const cast ist ugly, same as GUI programming...
return qVariantFromValue(const_cast<void*>(static_cast<const void*>(_dataHandle)));
return qVariantFromValue(const_cast<void*>(static_cast<const void*>(&_dataHandle)));
default:
return QVariant();
}
}
DataHandleTreeItem::~DataHandleTreeItem() {
delete _dataHandle;
}
void DataHandleTreeItem::setDataHandle(const DataHandle* dataHandle) {
delete _dataHandle;
void DataHandleTreeItem::setDataHandle(const DataHandle& dataHandle) {
_dataHandle = dataHandle;
}
......@@ -197,15 +194,15 @@ namespace TUMVis {
delete _rootItem;
_rootItem = new DataContainerTreeRootItem();
std::vector< std::pair< std::string, const DataHandle*> > handlesCopy = dataContainer->getDataHandlesCopy();
for (std::vector< std::pair< std::string, const DataHandle*> >::iterator it = handlesCopy.begin(); it != handlesCopy.end(); ++it) {
std::vector< std::pair< std::string, DataHandle> > handlesCopy = dataContainer->getDataHandlesCopy();
for (std::vector< std::pair< std::string, DataHandle> >::iterator it = handlesCopy.begin(); it != handlesCopy.end(); ++it) {
DataHandleTreeItem* dhti = new DataHandleTreeItem(it->second, it->first, _rootItem);
_itemMap.insert(std::make_pair(QString::fromStdString(it->first), dhti));
}
}
void DataContainerTreeModel::onDataContainerChanged(const QString& key, const DataHandle* dh) {
tgtAssert(dh->getData() != 0, "WTF - DataHandle with empty data?");
void DataContainerTreeModel::onDataContainerChanged(const QString& key, const DataHandle& dh) {
tgtAssert(dh.getData() != 0, "WTF - DataHandle with empty data?");
std::map<QString, DataHandleTreeItem*>::const_iterator it = _itemMap.lower_bound(key);
if (it == _itemMap.end() || it->first != key) {
......
......@@ -36,10 +36,10 @@
#include <map>
#include "application/tools/treeitem.h"
#include "core/datastructures/datahandle.h"
namespace TUMVis {
class DataContainer;
class DataHandle;
// = TreeModel items ==============================================================================
......@@ -66,7 +66,7 @@ namespace TUMVis {
* \param name Name of the DataHandle
* \param parent Parent TreeItem
*/
DataHandleTreeItem(const DataHandle* dataHandle, const std::string& name, TreeItem* parent);
DataHandleTreeItem(const DataHandle& dataHandle, const std::string& name, TreeItem* parent);
/**
* Destructor, deletes the DataHandle
......@@ -81,11 +81,11 @@ namespace TUMVis {
* \note DataHandleTreeItem takes ownership of this pointer.
* \param dataHandle The DataHandle to wrap around, DataHandleTreeItem takes ownership of this pointer!
*/
void setDataHandle(const DataHandle* dataHandle);
void setDataHandle(const DataHandle& dataHandle);
private:
const DataHandle* _dataHandle; ///< Base DataHandle
std::string _name; ///< Name of that DataHandle
DataHandle _dataHandle; ///< Base DataHandle
std::string _name; ///< Name of that DataHandle
};
// = TreeModel ====================================================================================
......@@ -126,7 +126,7 @@ namespace TUMVis {
* \param key Name of the DataHandle
* \param dh The added DataHandle
*/
void onDataContainerChanged(const QString& key, const DataHandle* dh);
void onDataContainerChanged(const QString& key, const DataHandle& dh);
private:
TreeItem* _rootItem;
......
......@@ -77,7 +77,6 @@ namespace TUMVis {
if (_texture != 0)
LWARNING("Called AbstractTransferFunction dtor without proper deinitialization - you just wasted resources!");
delete _intensityHistogram;
delete _imageHandle;
}
void AbstractTransferFunction::deinit() {
......@@ -130,18 +129,12 @@ namespace TUMVis {
return _texture;
}
const DataHandle* AbstractTransferFunction::getImageHandle() const {
DataHandle AbstractTransferFunction::getImageHandle() const {
return _imageHandle;
}
void AbstractTransferFunction::setImageHandle(const DataHandle* imageHandle) {
delete _imageHandle;
if (imageHandle == 0)
_imageHandle = 0;
else
_imageHandle = new DataHandle(*imageHandle);
void AbstractTransferFunction::setImageHandle(const DataHandle& imageHandle) {
_imageHandle = imageHandle;
_dirtyHistogram = true;
}
......@@ -149,8 +142,8 @@ namespace TUMVis {
delete _intensityHistogram;
_intensityHistogram = 0;
if (_imageHandle != 0) {
const ImageDataLocal* idl = dynamic_cast<const ImageDataLocal*>(_imageHandle->getData());
if (_imageHandle.getData() != 0) {
const ImageDataLocal* idl = dynamic_cast<const ImageDataLocal*>(_imageHandle.getData());
if (idl != 0) {
float mins = _intensityDomain.x;
float maxs = _intensityDomain.y;
......
......@@ -122,14 +122,14 @@ namespace TUMVis {
* Returns a DataHandle to the image for this transfer function, may be 0.
* \return _imageHandle, may be 0!
*/
const DataHandle* getImageHandle() const;
DataHandle getImageHandle() const;
/**
* Sets the DataHandle for this transfer function, may be 0.
* \note This method makes a copy of \a imageHandle, hence does not take ownership.
* \param imageHandle The new DataHandle for this transfer function, may be 0, will be copied.
* \param imageHandle The new DataHandle for this transfer function
*/
void setImageHandle(const DataHandle* imageHandle);
void setImageHandle(const DataHandle& imageHandle);
/**
* Returns the intensity histogram
......@@ -158,7 +158,7 @@ namespace TUMVis {
tgt::Texture* _texture; ///< OpenGL lookup texture storing the TF
tbb::atomic<bool> _dirtyTexture; ///< Flag whether the OpenGL texture has to be updated
const DataHandle* _imageHandle; ///< DataHandle to the image for this transfer function. May be 0.
DataHandle _imageHandle; ///< DataHandle to the image for this transfer function. May be 0.
mutable IntensityHistogramType* _intensityHistogram; ///< Intensity histogram of the intensity in _imageHandle for the current _intensityDomain
mutable tbb::atomic<bool> _dirtyHistogram; ///< Flag whether the intensity histogram has to be updated.
......
......@@ -39,27 +39,21 @@ namespace TUMVis {
}
DataContainer::~DataContainer() {
// remove ownership op all owned DataHandles
for (std::map<std::string, const DataHandle*>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
delete it->second;
}
_handles.clear();
}
const DataHandle* DataContainer::addData(const std::string& name, AbstractData* data) {
DataHandle DataContainer::addData(const std::string& name, AbstractData* data) {
tgtAssert(data != 0, "The Data must not be 0.");
DataHandle* dh = new DataHandle(data);
DataHandle dh(data);
addDataHandle(name, dh);
return dh;
}
void DataContainer::addDataHandle(const std::string& name, const DataHandle* dh) {
tgtAssert(dh != 0, "DataHandle must not be 0.");
void DataContainer::addDataHandle(const std::string& name, const DataHandle& dh) {
{
tbb::spin_mutex::scoped_lock lock(_localMutex);
std::map<std::string, const DataHandle*>::iterator it = _handles.lower_bound(name);
std::map<std::string, DataHandle>::iterator it = _handles.lower_bound(name);
if (it != _handles.end() && it->first == name) {
delete it->second;
it->second = dh;
}
else {
......@@ -75,47 +69,38 @@ namespace TUMVis {
return (_handles.find(name) != _handles.end());
}
const DataHandle* DataContainer::getData(const std::string& name) const {
DataHandle DataContainer::getData(const std::string& name) const {
tbb::spin_mutex::scoped_lock lock(_localMutex);
std::map<std::string, const DataHandle*>::const_iterator it = _handles.find(name);
std::map<std::string, DataHandle>::const_iterator it = _handles.find(name);
if (it == _handles.end())
return 0;
return DataHandle(0);
else
return new DataHandle(*it->second);
return it->second;
}
void DataContainer::removeData(const std::string& name) {
tbb::spin_mutex::scoped_lock lock(_localMutex);
std::map<std::string, const DataHandle*>::const_iterator it = _handles.find(name);
std::map<std::string, DataHandle>::const_iterator it = _handles.find(name);
if (it != _handles.end()) {
delete it->second;
_handles.erase(it);
}
}
std::vector< std::pair< std::string, const DataHandle*> > DataContainer::getDataHandlesCopy() const {
std::vector< std::pair< std::string, const DataHandle*> > toReturn;
std::vector< std::pair< std::string, DataHandle> > DataContainer::getDataHandlesCopy() const {
std::vector< std::pair< std::string, DataHandle> > toReturn;
toReturn.reserve(_handles.size());
tbb::spin_mutex::scoped_lock lock(_localMutex);
for (std::map<std::string, const DataHandle*>::const_iterator it = _handles.begin(); it != _handles.end(); ++it) {
toReturn.push_back(std::make_pair(it->first, new DataHandle(*(it->second))));
for (std::map<std::string, DataHandle>::const_iterator it = _handles.begin(); it != _handles.end(); ++it) {
toReturn.push_back(std::make_pair(it->first, it->second));
}
return toReturn;
}
std::map<std::string, const DataHandle*> DataContainer::getHandlesCopy() const {
std::map<std::string, const DataHandle*> toReturn;
std::map<std::string, const DataHandle*>::const_iterator hint = toReturn.begin();
// copy map while also deep copying the DataHandles
std::map<std::string, DataHandle> DataContainer::getHandlesCopy() const {
tbb::spin_mutex::scoped_lock lock(_localMutex);
for (std::map<std::string, const DataHandle*>::const_iterator it = _handles.begin(); it != _handles.end(); ++it) {
hint = toReturn.insert(hint, std::make_pair(it->first, new DataHandle(*(it->second))));
}
return toReturn;
return _handles;
}
}
\ No newline at end of file
......@@ -77,17 +77,8 @@ namespace TUMVis {
: dh(dc.getData(name))
, data(0)
{
if (dh != 0 && dh->getData() != 0) {
data = dynamic_cast<const T*>(dh->getData());
}
};
/**
* Destructor, deletes the internal DataHandle.
*/
~ScopedTypedData() {
if (dh) {
delete dh;
if (dh.getData() != 0) {
data = dynamic_cast<const T*>(dh.getData());
}
};
......@@ -111,7 +102,7 @@ namespace TUMVis {
* Gets the DataHandle.
* \return dh
*/
const DataHandle* getDataHandle() const {
const DataHandle& getDataHandle() const {
return dh;
}
......@@ -121,8 +112,8 @@ namespace TUMVis {
/// Not assignable
ScopedTypedData& operator=(const ScopedTypedData& rhs);
const DataHandle* dh; ///< DataHandle, may be 0
const T* data; ///< strongly-typed pointer to data, may be 0
DataHandle dh; ///< DataHandle
const T* data; ///< strongly-typed pointer to data, may be 0
};
......@@ -146,7 +137,7 @@ namespace TUMVis {
* \param data DataHandle to add.
* \return The DataHandle which was created for \a data.
*/
const DataHandle* addData(const std::string& name, AbstractData* data);
DataHandle addData(const std::string& name, AbstractData* data);
/**
* Adds the given DataHandle \a data, accessible by the key \name, to this DataContainer.
......@@ -155,7 +146,7 @@ namespace TUMVis {
* \param name Key for accessing the DataHandle within this DataContainer
* \param data DataHandle to add.
*/
void addDataHandle(const std::string& name, const DataHandle* dh);
void addDataHandle(const std::string& name, const DataHandle& dh);
/**
* Checks whether this DataContainer contains a DataHandle with the given name.
......@@ -172,7 +163,7 @@ namespace TUMVis {
* \param name Key of the DataHandle to search for
* \return The stored DataHandle with the given name, 0 if no such DataHandle exists.
*/
const DataHandle* getData(const std::string& name) const;
DataHandle getData(const std::string& name) const;
/**
* Removes the DataHandle with the given name from this container.
......@@ -187,7 +178,7 @@ namespace TUMVis {
* copies and locks the whole DataContainer during execution.
* \return A list of pairs (name, DataHandle). The caller has to take ownership of the passed pointers!
*/
std::vector< std::pair< std::string, const DataHandle*> > getDataHandlesCopy() const;
std::vector< std::pair< std::string, DataHandle> > getDataHandlesCopy() const;
/**
* Returns a copy of the current map of DataHandles.
......@@ -195,19 +186,19 @@ namespace TUMVis {
* copies and locks the whole DataContainer during execution.
* \return A copy of the current handles map. The caller has to take ownership of the passed pointers!
*/
std::map<std::string, const DataHandle*> getHandlesCopy() const;
std::map<std::string, DataHandle> getHandlesCopy() const;
/**
* Signal emitted when data has been added to this DataContainer (this includes also data being replaced).
* First parameter is the name of the added data, second parameter contains a DataHandle to the new data.
*/
sigslot::signal2<const std::string&, const DataHandle*> s_dataAdded;
sigslot::signal2<const std::string&, const DataHandle&> s_dataAdded;
/// Signal emitted when list of DataHandles has changed.
sigslot::signal0<> s_changed;
private:
std::map<std::string, const DataHandle*> _handles;
std::map<std::string, DataHandle> _handles;
mutable tbb::spin_mutex _localMutex;
static const std::string loggerCat_;
......
......@@ -70,14 +70,6 @@ namespace TUMVis {
return _data;
}
AbstractData* DataHandle::getData() {
if (_data->isShared())
_data = _data->clone();
_data->markUnsharable();
return _data;
}
void DataHandle::init() {
if (_data == 0)
return;
......
......@@ -83,13 +83,6 @@ namespace TUMVis {
*/
const AbstractData* getData() const;
/**
* Grants access to the managed AbstractData instance.
* \note If the data is referenced by more than one object, this implies a copy of the data!
* \return A modifyable version of the held data.
*/
AbstractData* getData();
/**
* Gets the timestamp when this data has been created.
* \return _timestamp
......
......@@ -82,7 +82,7 @@ namespace TUMVis {
return _renderTargetSize.getValue();
}
void VisualizationPipeline::onDataContainerDataAdded(const std::string& name, const DataHandle* dh) {
void VisualizationPipeline::onDataContainerDataAdded(const std::string& name, const DataHandle& dh) {
if (name == _renderTargetID.getValue()) {
s_renderTargetChanged();
}
......
......@@ -129,7 +129,7 @@ namespace TUMVis {
* \param name Name of the added data.
* \param dh DataHandle to the newly added data.
*/
void onDataContainerDataAdded(const std::string& name, const DataHandle* dh);
void onDataContainerDataAdded(const std::string& name, const DataHandle& dh);
/**
* Slot getting called when one of the observed properties changed and notifies its observers.
......
......@@ -162,7 +162,7 @@ namespace TUMVis {
if (img != 0) {
ImageDataLocal* local = ImageDataConverter::tryConvert<ImageDataLocal>(img);
if (local != 0) {
const DataHandle* dh = _data.addData("clr.input", local);
DataHandle dh = _data.addData("clr.input", local);
_dvrNormal._transferFunction.getTF()->setImageHandle(dh);
}
{
......
......@@ -121,10 +121,10 @@ namespace TUMVis {
_clProgram->build();
}
if (img.getDataHandle()->getTimestamp() != _volumeTimestamp) {
if (img.getDataHandle().getTimestamp() != _volumeTimestamp) {
WeaklyTypedPointer wtp = img->getWeaklyTypedPointer();
_imgVolume = new kisscl::Image(_clContext, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, img->getSize(), wtp.getClChannelOrder(), wtp.getClChannelType(), wtp._pointer);
_volumeTimestamp = img.getDataHandle()->getTimestamp();
_volumeTimestamp = img.getDataHandle().getTimestamp();
}
// upload TF
......
......@@ -63,7 +63,7 @@ namespace TUMVis {
if (img != 0) {
if (img->getDimensionality() == 3) {
if (img.getDataHandle()->getTimestamp() != _sourceTimestamp) {
if (img.getDataHandle().getTimestamp() != _sourceTimestamp) {
_clipX.setMaxValue(tgt::ivec2(img->getSize().x, img->getSize().x));
_clipY.setMaxValue(tgt::ivec2(img->getSize().y, img->getSize().y));
_clipZ.setMaxValue(tgt::ivec2(img->getSize().z, img->getSize().z));
......@@ -71,7 +71,7 @@ namespace TUMVis {
_clipX.setValue(tgt::ivec2(0, img->getSize().x));
_clipY.setValue(tgt::ivec2(0, img->getSize().y));
_clipZ.setValue(tgt::ivec2(0, img->getSize().z));
_sourceTimestamp = img.getDataHandle()->getTimestamp();
_sourceTimestamp = img.getDataHandle().getTimestamp();
}
tgt::Bounds volumeExtent = img->getWorldBounds(tgt::svec3(_clipX.getValue().x, _clipY.getValue().x, _clipZ.getValue().x), tgt::svec3(_clipX.getValue().y, _clipY.getValue().y, _clipZ.getValue().y));
tgt::vec3 numSlices = tgt::vec3(img->getSize());
......
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