Commit 892dfe81 authored by schultezub's avatar schultezub
Browse files

improved thread-safety for ImageData

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@457 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent d07ea26d
......@@ -50,13 +50,15 @@ namespace campvis {
ImageData* ImageData::clone() const {
ImageData* toReturn = new ImageData(_dimensionality, _size, _numChannels);
toReturn->_mappingInformation = _mappingInformation;
toReturn->_representations.assign(_representations.begin(), _representations.end());
tbb::concurrent_vector<const AbstractImageRepresentation*>::const_iterator start = _representations.begin();
tbb::concurrent_vector<const AbstractImageRepresentation*>::const_iterator end = _representations.end();
toReturn->_representations.assign(start, end);
return toReturn;
}
size_t ImageData::getLocalMemoryFootprint() const {
size_t toReturn = sizeof(*this) + _representations.size() * sizeof(AbstractImageRepresentation*);
for (std::vector<const AbstractImageRepresentation*>::iterator it = _representations.begin(); it != _representations.end(); ++it)
for (tbb::concurrent_vector<const AbstractImageRepresentation*>::const_iterator it = _representations.begin(); it != _representations.end(); ++it)
toReturn += (*it)->getLocalMemoryFootprint();
return toReturn;
......@@ -64,7 +66,7 @@ namespace campvis {
size_t ImageData::getVideoMemoryFootprint() const {
size_t toReturn = 0;
for (std::vector<const AbstractImageRepresentation*>::iterator it = _representations.begin(); it != _representations.end(); ++it)
for (tbb::concurrent_vector<const AbstractImageRepresentation*>::const_iterator it = _representations.begin(); it != _representations.end(); ++it)
toReturn += (*it)->getVideoMemoryFootprint();
return toReturn;
......@@ -121,7 +123,7 @@ namespace campvis {
toReturn->_mappingInformation = ImageMappingInformation(newSize, _mappingInformation.getOffset(), _mappingInformation.getVoxelSize(), _mappingInformation.getRealWorldMapping());
// create sub-image of every image representation
for (std::vector<const AbstractImageRepresentation*>::iterator it = _representations.begin(); it != _representations.end(); ++it) {
for (tbb::concurrent_vector<const AbstractImageRepresentation*>::const_iterator it = _representations.begin(); it != _representations.end(); ++it) {
AbstractImageRepresentation* si = (*it)->getSubImage(toReturn, llf, urb);
toReturn->addRepresentation(si);
}
......@@ -145,7 +147,7 @@ namespace campvis {
}
void ImageData::clearRepresentations() {
for (std::vector<const AbstractImageRepresentation*>::iterator it = _representations.begin(); it != _representations.end(); ++it)
for (tbb::concurrent_vector<const AbstractImageRepresentation*>::iterator it = _representations.begin(); it != _representations.end(); ++it)
delete *it;
_representations.clear();
}
......
......@@ -30,13 +30,14 @@
#ifndef IMAGEDATA_H__
#define IMAGEDATA_H__
#include "tbb/concurrent_vector.h"
#include "tgt/bounds.h"
#include "tgt/logmanager.h"
#include "tgt/vector.h"
#include "core/datastructures/abstractdata.h"
#include "core/datastructures/abstractimagerepresentation.h"
#include "core/datastructures/imagemappinginformation.h"
//
#include <vector>
......@@ -194,17 +195,17 @@ namespace campvis {
/**
* Clears all representations from the vector and frees the memory.
* \note Make sure to call this method only when nobody else holds pointers to the
* representations as they will be invalidated.
* representations as they will be invalidated. This method is \b not thread-safe!
*/
void clearRepresentations();
/// List of all representations of this image. Mutable to allow lazy instantiation of new representations.
mutable std::vector<const AbstractImageRepresentation*> _representations;
mutable tbb::concurrent_vector<const AbstractImageRepresentation*> _representations;
size_t _dimensionality; ///< Dimensionality of this image
tgt::svec3 _size; ///< Size of this image (number of elements per dimension)
size_t _numChannels; ///< Number of channels per element
size_t _numElements; ///< number of elements (= tgt::hmul(size))
const size_t _dimensionality; ///< Dimensionality of this image
const tgt::svec3 _size; ///< Size of this image (number of elements per dimension)
const size_t _numChannels; ///< Number of channels per element
const size_t _numElements; ///< number of elements (= tgt::hmul(size))
ImageMappingInformation _mappingInformation; ///< Mapping information of this image
static const std::string loggerCat_;
......@@ -216,7 +217,7 @@ namespace campvis {
template<typename T>
const T* campvis::ImageData::getRepresentation(bool performConversion /*= true*/) const {
// look, whether we already have a suitable representation
for (std::vector<const AbstractImageRepresentation*>::iterator it = _representations.begin(); it != _representations.end(); ++it) {
for (tbb::concurrent_vector<const AbstractImageRepresentation*>::const_iterator it = _representations.begin(); it != _representations.end(); ++it) {
if (const T* tester = dynamic_cast<const T*>(*it))
return tester;
//if (typeid(T) == typeid(**it)) {
......@@ -226,7 +227,7 @@ namespace campvis {
if (performConversion) {
// no representation found, create a new one
for (std::vector<const AbstractImageRepresentation*>::iterator it = _representations.begin(); it != _representations.end(); ++it) {
for (tbb::concurrent_vector<const AbstractImageRepresentation*>::const_iterator it = _representations.begin(); it != _representations.end(); ++it) {
const T* tester = T::tryConvertFrom(*it);
if (tester != 0) {
return tester;
......
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