Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit e90692d8 authored by schultezub's avatar schultezub
Browse files

#5: Making constructors of ImageRepresentationXYZ protected - new image...

#5: Making constructors of ImageRepresentationXYZ protected - new image representations are to be created via ImageRepresentationXYZ::create().
    This makes much more sense, since the pointer of the newly create image representation is owned by the parent ImageData instead of the caller.

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@443 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent bf0a6d1b
...@@ -37,7 +37,6 @@ namespace campvis { ...@@ -37,7 +37,6 @@ namespace campvis {
: _parent(parent) : _parent(parent)
{ {
tgtAssert(parent != 0, "Parent ImageData must not be 0!"); tgtAssert(parent != 0, "Parent ImageData must not be 0!");
parent->addRepresentation(this);
} }
AbstractImageRepresentation::~AbstractImageRepresentation() { AbstractImageRepresentation::~AbstractImageRepresentation() {
...@@ -59,5 +58,9 @@ namespace campvis { ...@@ -59,5 +58,9 @@ namespace campvis {
return _parent->getNumElements(); return _parent->getNumElements();
} }
void AbstractImageRepresentation::addToParent() const {
const_cast<ImageData*>(_parent)->addRepresentation(this);
}
} }
\ No newline at end of file
...@@ -111,6 +111,15 @@ namespace campvis { ...@@ -111,6 +111,15 @@ namespace campvis {
virtual AbstractImageRepresentation* getSubImage(ImageData* parent, const tgt::svec3& llf, const tgt::svec3& urb) const = 0; virtual AbstractImageRepresentation* getSubImage(ImageData* parent, const tgt::svec3& llf, const tgt::svec3& urb) const = 0;
protected: protected:
/**
* Adds this image representations to the parent image data.
*/
void addToParent() const;
/// Not copy-constructable
AbstractImageRepresentation(const AbstractImageRepresentation& rhs);
/// Not assignable
AbstractImageRepresentation& operator=(const AbstractImageRepresentation& rhs);
const ImageData* _parent; ///< Image this representation represents, must not be 0. const ImageData* _parent; ///< Image this representation represents, must not be 0.
......
...@@ -138,14 +138,18 @@ namespace campvis { ...@@ -138,14 +138,18 @@ namespace campvis {
const ImageData* data; ///< strongly-typed pointer to data, may be 0 const ImageData* data; ///< strongly-typed pointer to data, may be 0
const GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>* representation; ///< strongly-typed pointer to the image representation, may be 0 const GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>* representation; ///< strongly-typed pointer to the image representation, may be 0
}; };
/** /**
* Creates a new strongly typed ImageData object storing the image in the local memory. * Creates a new GenericImageRepresentationLocal with the given parameters and automatically
* * adds it to \a parent which will take ownerwhip.
* \param parent Image this representation represents, must not be 0. *
* \note You do \b not own the returned pointer.
*
* \param parent Image this representation represents, must not be 0, will take ownership of the returned pointer.
* \param data Pointer to the image data, must not be 0, GenericImageRepresentationLocal takes ownership of this pointer! * \param data Pointer to the image data, must not be 0, GenericImageRepresentationLocal takes ownership of this pointer!
* \return A pointer to the newly created ImageRepresentationDisk, you do \b not own this pointer!
*/ */
GenericImageRepresentationLocal(ImageData* parent, ElementType* data); static GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>* create(ImageData* parent, ElementType* data);
/** /**
* Destructor * Destructor
...@@ -156,9 +160,9 @@ namespace campvis { ...@@ -156,9 +160,9 @@ namespace campvis {
/** /**
* Performs a conversion of \a source to an ImageRepresentationLocal if feasible. * Performs a conversion of \a source to an ImageRepresentationLocal if feasible.
* Returns 0 if conversion was not successful or source representation type is not compatible. * Returns 0 if conversion was not successful or source representation type is not compatible.
* \note The caller has to take ownership of the returned pointer if not 0. * \note The callee, respectively the callee's parent, has the ownership of the returned pointer.
* \param source Source image representation for conversion. * \param source Source image representation for conversion.
* \return A pointer to a local representation of \a source or 0 on failure. The caller has to take ownership. * \return A pointer to a local representation of \a source or 0 on failure. The caller does \b not have ownership.
*/ */
static GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>* tryConvertFrom(const AbstractImageRepresentation* source); static GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>* tryConvertFrom(const AbstractImageRepresentation* source);
...@@ -260,6 +264,13 @@ namespace campvis { ...@@ -260,6 +264,13 @@ namespace campvis {
ElementType getElementLinear(const tgt::vec3 position) const; ElementType getElementLinear(const tgt::vec3 position) const;
protected: protected:
/**
* Creates a new strongly typed ImageData object storing the image in the local memory.
*
* \param parent Image this representation represents, must not be 0.
* \param data Pointer to the image data, must not be 0, GenericImageRepresentationLocal takes ownership of this pointer!
*/
GenericImageRepresentationLocal(ImageData* parent, ElementType* data);
ElementType* _data; ElementType* _data;
...@@ -267,6 +278,13 @@ namespace campvis { ...@@ -267,6 +278,13 @@ namespace campvis {
// = Template implementation ====================================================================== // = Template implementation ======================================================================
template<typename BASETYPE, size_t NUMCHANNELS>
campvis::GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>* campvis::GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>::create(ImageData* parent, ElementType* data) {
ThisType* toReturn = new ThisType(parent, data);
toReturn->addToParent();
return toReturn;
}
template<typename BASETYPE, size_t NUMCHANNELS> template<typename BASETYPE, size_t NUMCHANNELS>
campvis::GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>::GenericImageRepresentationLocal(ImageData* parent, ElementType* data) campvis::GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>::GenericImageRepresentationLocal(ImageData* parent, ElementType* data)
: ImageRepresentationLocal(parent, TypeTraits<BASETYPE, NUMCHANNELS>::weaklyTypedPointerBaseType) : ImageRepresentationLocal(parent, TypeTraits<BASETYPE, NUMCHANNELS>::weaklyTypedPointerBaseType)
...@@ -296,7 +314,7 @@ namespace campvis { ...@@ -296,7 +314,7 @@ namespace campvis {
ElementType* newData = new ElementType[numElements]; ElementType* newData = new ElementType[numElements];
memcpy(newData, _data, numElements * sizeof(ElementType)); memcpy(newData, _data, numElements * sizeof(ElementType));
return new ThisType(newParent, newData); return ThisType::create(newParent, newData);
} }
template<typename BASETYPE, size_t NUMCHANNELS> template<typename BASETYPE, size_t NUMCHANNELS>
......
...@@ -123,6 +123,7 @@ namespace campvis { ...@@ -123,6 +123,7 @@ namespace campvis {
// create sub-image of every image representation // create sub-image of every image representation
for (std::vector<const AbstractImageRepresentation*>::iterator it = _representations.begin(); it != _representations.end(); ++it) { for (std::vector<const AbstractImageRepresentation*>::iterator it = _representations.begin(); it != _representations.end(); ++it) {
AbstractImageRepresentation* si = (*it)->getSubImage(toReturn, llf, urb); AbstractImageRepresentation* si = (*it)->getSubImage(toReturn, llf, urb);
toReturn->addRepresentation(si);
} }
return toReturn; return toReturn;
......
...@@ -35,6 +35,12 @@ ...@@ -35,6 +35,12 @@
namespace campvis { namespace campvis {
const std::string ImageRepresentationDisk::loggerCat_ = "CAMPVis.core.datastructures.ImageRepresentationDisk"; const std::string ImageRepresentationDisk::loggerCat_ = "CAMPVis.core.datastructures.ImageRepresentationDisk";
ImageRepresentationDisk* ImageRepresentationDisk::create(ImageData* parent, const std::string& url, WeaklyTypedPointer::BaseType type, size_t offset /*= 0*/, EndianHelper::Endianness endianness /*= EndianHelper::LITTLE_ENDIAN*/, const tgt::svec3& stride /*= tgt::svec3::zero */) {
ImageRepresentationDisk* toReturn = new ImageRepresentationDisk(parent, url, type, offset, endianness, stride);
toReturn->addToParent();
return toReturn;
}
ImageRepresentationDisk::ImageRepresentationDisk(ImageData* parent, const std::string& url, WeaklyTypedPointer::BaseType type, size_t offset /*= 0*/, EndianHelper::Endianness endianness /*= EndianHelper::LITTLE_ENDIAN*/, const tgt::svec3& stride /*= tgt::svec2::zero */) ImageRepresentationDisk::ImageRepresentationDisk(ImageData* parent, const std::string& url, WeaklyTypedPointer::BaseType type, size_t offset /*= 0*/, EndianHelper::Endianness endianness /*= EndianHelper::LITTLE_ENDIAN*/, const tgt::svec3& stride /*= tgt::svec2::zero */)
: GenericAbstractImageRepresentation<ImageRepresentationDisk>(parent) : GenericAbstractImageRepresentation<ImageRepresentationDisk>(parent)
, _url(url) , _url(url)
...@@ -195,7 +201,7 @@ namespace campvis { ...@@ -195,7 +201,7 @@ namespace campvis {
} }
ImageRepresentationDisk* ImageRepresentationDisk::clone(ImageData* newParent) const { ImageRepresentationDisk* ImageRepresentationDisk::clone(ImageData* newParent) const {
return new ImageRepresentationDisk(newParent, _url, _type, _offset, _endianess, _stride); return ImageRepresentationDisk::create(newParent, _url, _type, _offset, _endianess, _stride);
} }
size_t ImageRepresentationDisk::getLocalMemoryFootprint() const { size_t ImageRepresentationDisk::getLocalMemoryFootprint() const {
......
...@@ -45,16 +45,20 @@ namespace campvis { ...@@ -45,16 +45,20 @@ namespace campvis {
class ImageRepresentationDisk : public GenericAbstractImageRepresentation<ImageRepresentationDisk> { class ImageRepresentationDisk : public GenericAbstractImageRepresentation<ImageRepresentationDisk> {
public: public:
/** /**
* Creates a new ImageData disk representation. * Creates a new ImageRepresentationDisk with the given parameters and automatically
* adds it to \a parent which will take ownerwhip.
* *
* \param parent Image this representation represents, must not be 0. * \note You do \b not own the returned pointer.
* \param url Path to file with raw data *
* \param type Base type of data * \param parent Image this representation represents, must not be 0, will take ownership of the returned pointer.
* \param offset Offset of first data element in file (in bytes) * \param url Path to file with raw data
* \param endianness Endianess of data * \param type Base type of data
* \param stride Number of _elemments_ _between_ adjacent elements for each dimension (\see ImageRepresentationDisk::_stride). * \param offset Offset of first data element in file (in bytes)
* \param endianness Endianess of data
* \param stride Number of _elements_ _between_ adjacent elements for each dimension (\see ImageRepresentationDisk::_stride).
* \return A pointer to the newly created ImageRepresentationDisk, you do \b not own this pointer!
*/ */
ImageRepresentationDisk( static ImageRepresentationDisk* create(
ImageData* parent, ImageData* parent,
const std::string& url, const std::string& url,
WeaklyTypedPointer::BaseType type, WeaklyTypedPointer::BaseType type,
...@@ -63,6 +67,7 @@ namespace campvis { ...@@ -63,6 +67,7 @@ namespace campvis {
const tgt::svec3& stride = tgt::svec3::zero const tgt::svec3& stride = tgt::svec3::zero
); );
/** /**
* Destructor * Destructor
*/ */
...@@ -71,9 +76,9 @@ namespace campvis { ...@@ -71,9 +76,9 @@ namespace campvis {
/** /**
* Performs a conversion of \a source to an ImageRepresentationLocal if feasible. * Performs a conversion of \a source to an ImageRepresentationLocal if feasible.
* Returns 0 if conversion was not successful or source representation type is not compatible. * Returns 0 if conversion was not successful or source representation type is not compatible.
* \note The caller has to take ownership of the returned pointer if not 0. * \note The callee, respectively the callee's parent, has the ownership of the returned pointer.
* \param source Source image representation for conversion. * \param source Source image representation for conversion.
* \return A pointer to a local representation of \a source or 0 on failure. The caller has to take ownership. * \return A pointer to a local representation of \a source or 0 on failure. The caller does \b not have ownership.
*/ */
static ImageRepresentationDisk* tryConvertFrom(const AbstractImageRepresentation* source); static ImageRepresentationDisk* tryConvertFrom(const AbstractImageRepresentation* source);
...@@ -104,7 +109,28 @@ namespace campvis { ...@@ -104,7 +109,28 @@ namespace campvis {
*/ */
WeaklyTypedPointer::BaseType getBaseType() const; WeaklyTypedPointer::BaseType getBaseType() const;
private: protected:
/**
* Creates a new ImageData disk representation.
* \note The Constructor is protected since image representations are not supposed to be
* created via the new operator - use ImageRepresentationDisk::create() instead.
*
* \param parent Image this representation represents, must not be 0.
* \param url Path to file with raw data
* \param type Base type of data
* \param offset Offset of first data element in file (in bytes)
* \param endianness Endianess of data
* \param stride Number of _elements_ _between_ adjacent elements for each dimension (\see ImageRepresentationDisk::_stride).
*/
ImageRepresentationDisk(
ImageData* parent,
const std::string& url,
WeaklyTypedPointer::BaseType type,
size_t offset = 0,
EndianHelper::Endianness endianness = EndianHelper::LITTLE_ENDIAN,
const tgt::svec3& stride = tgt::svec3::zero
);
/** /**
* Calculates the canonical stride for the given image size. * Calculates the canonical stride for the given image size.
* \param size Image size (number of elements per dimension). * \param size Image size (number of elements per dimension).
......
...@@ -45,6 +45,18 @@ namespace campvis { ...@@ -45,6 +45,18 @@ namespace campvis {
const std::string ImageRepresentationGL::loggerCat_ = "CAMPVis.core.datastructures.ImageRepresentationGL"; const std::string ImageRepresentationGL::loggerCat_ = "CAMPVis.core.datastructures.ImageRepresentationGL";
ImageRepresentationGL* ImageRepresentationGL::create(ImageData* parent, tgt::Texture* texture) {
ImageRepresentationGL* toReturn = new ImageRepresentationGL(parent, texture);
toReturn->addToParent();
return toReturn;
}
ImageRepresentationGL* ImageRepresentationGL::create(ImageData* parent, const WeaklyTypedPointer& wtp) {
ImageRepresentationGL* toReturn = new ImageRepresentationGL(parent, wtp);
toReturn->addToParent();
return toReturn;
}
ImageRepresentationGL::ImageRepresentationGL(ImageData* parent, tgt::Texture* texture) ImageRepresentationGL::ImageRepresentationGL(ImageData* parent, tgt::Texture* texture)
: GenericAbstractImageRepresentation<ImageRepresentationGL>(parent) : GenericAbstractImageRepresentation<ImageRepresentationGL>(parent)
, _texture(texture) , _texture(texture)
...@@ -69,17 +81,17 @@ namespace campvis { ...@@ -69,17 +81,17 @@ namespace campvis {
// test source image type via dynamic cast // test source image type via dynamic cast
if (const ImageRepresentationDisk* tester = dynamic_cast<const ImageRepresentationDisk*>(source)) { if (const ImageRepresentationDisk* tester = dynamic_cast<const ImageRepresentationDisk*>(source)) {
WeaklyTypedPointer wtp = tester->getImageData(); WeaklyTypedPointer wtp = tester->getImageData();
ImageRepresentationGL* toReturn = new ImageRepresentationGL(const_cast<ImageData*>(tester->getParent()), wtp); ImageRepresentationGL* toReturn = ImageRepresentationGL::create(const_cast<ImageData*>(tester->getParent()), wtp);
delete wtp._pointer; delete wtp._pointer;
return toReturn; return toReturn;
} }
else if (const ImageRepresentationLocal* tester = dynamic_cast<const ImageRepresentationLocal*>(source)) { else if (const ImageRepresentationLocal* tester = dynamic_cast<const ImageRepresentationLocal*>(source)) {
ImageRepresentationGL* toReturn = new ImageRepresentationGL(const_cast<ImageData*>(tester->getParent()), tester->getWeaklyTypedPointer()); ImageRepresentationGL* toReturn = ImageRepresentationGL::create(const_cast<ImageData*>(tester->getParent()), tester->getWeaklyTypedPointer());
return toReturn; return toReturn;
} }
#ifdef CAMPVIS_HAS_MODULE_ITK #ifdef CAMPVIS_HAS_MODULE_ITK
else if (const AbstractImageRepresentationItk* tester = dynamic_cast<const AbstractImageRepresentationItk*>(source)) { else if (const AbstractImageRepresentationItk* tester = dynamic_cast<const AbstractImageRepresentationItk*>(source)) {
ImageRepresentationGL* toReturn = new ImageRepresentationGL(const_cast<ImageData*>(tester->getParent()), tester->getWeaklyTypedPointer()); ImageRepresentationGL* toReturn = ImageRepresentationGL::create(const_cast<ImageData*>(tester->getParent()), tester->getWeaklyTypedPointer());
return toReturn; return toReturn;
} }
#endif #endif
...@@ -90,7 +102,7 @@ namespace campvis { ...@@ -90,7 +102,7 @@ namespace campvis {
ImageRepresentationGL* ImageRepresentationGL::clone(ImageData* newParent) const { ImageRepresentationGL* ImageRepresentationGL::clone(ImageData* newParent) const {
GLubyte* data = _texture->downloadTextureToBuffer(); GLubyte* data = _texture->downloadTextureToBuffer();
WeaklyTypedPointer wtp(WeaklyTypedPointer::baseType(_texture->getDataType()), WeaklyTypedPointer::numChannels(_texture->getFormat()), data); WeaklyTypedPointer wtp(WeaklyTypedPointer::baseType(_texture->getDataType()), WeaklyTypedPointer::numChannels(_texture->getFormat()), data);
ImageRepresentationGL* toReturn = new ImageRepresentationGL(newParent, wtp); ImageRepresentationGL* toReturn = ImageRepresentationGL::create(newParent, wtp);
delete data; delete data;
return toReturn; return toReturn;
} }
......
...@@ -49,33 +49,29 @@ namespace campvis { ...@@ -49,33 +49,29 @@ namespace campvis {
*/ */
class ImageRepresentationGL : public GenericAbstractImageRepresentation<ImageRepresentationGL> { class ImageRepresentationGL : public GenericAbstractImageRepresentation<ImageRepresentationGL> {
public: public:
/** /**
* Creates a new ImageRepresentationGL representation from a tgt::Texture. * Creates a new ImageRepresentationGL representation from a tgt::Texture and automatically
* adds it to \a parent which will take ownerwhip.
*
* \note You do \b not own the returned pointer.
* *
* \param parent Image this representation represents, must not be 0. * \param parent Image this representation represents, must not be 0, will take ownership of the returned pointer.
* \param texture OpenGL texture to use, must not be 0, ImageRepresentationGL will take ownership of this texture. * \param texture OpenGL texture to use, must not be 0, ImageRepresentationGL will take ownership of this texture.
* \return A pointer to the newly created ImageRepresentationGL, you do \b not own this pointer!
*/ */
ImageRepresentationGL(ImageData* parent, tgt::Texture* texture); static ImageRepresentationGL* create(ImageData* parent, tgt::Texture* texture);
/** /**
* Creates a new ImageRepresentationGL representation. * Creates a new ImageRepresentationGL representation from a tgt::Texture and automatically
* adds it to \a parent which will take ownerwhip.
* *
* \param parent Image this representation represents, must not be 0. * \note You do \b not own the returned pointer.
*
* \param parent Image this representation represents, must not be 0, will take ownership of the returned pointer.
* \param wtp WeaklyTypedPointer to the image data, must not be 0, ImageRepresentationGL does \b not take ownership of that pointer. * \param wtp WeaklyTypedPointer to the image data, must not be 0, ImageRepresentationGL does \b not take ownership of that pointer.
* \return A pointer to the newly created ImageRepresentationGL, you do \b not own this pointer!
*/ */
ImageRepresentationGL(ImageData* parent, const WeaklyTypedPointer& wtp); static ImageRepresentationGL* create(ImageData* parent, const WeaklyTypedPointer& wtp);
/**
* Creates a new ImageRepresentationGL representation from GenericImageRepresentationLocal.
*
* \param parent Image this representation represents, must not be 0.
* \param data Pointer to the GenericImageRepresentationLocal instance, must not be 0
* \tparam BASETYPE Base type of image data
* \tparam NUMCHANNELS Number of channels per element
*/
template<typename BASETYPE, size_t NUMCHANNELS>
ImageRepresentationGL(ImageData* parent, const GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>* data);
/** /**
* Destructor * Destructor
...@@ -86,9 +82,9 @@ namespace campvis { ...@@ -86,9 +82,9 @@ namespace campvis {
/** /**
* Performs a conversion of \a source to an ImageRepresentationLocal if feasible. * Performs a conversion of \a source to an ImageRepresentationLocal if feasible.
* Returns 0 if conversion was not successful or source representation type is not compatible. * Returns 0 if conversion was not successful or source representation type is not compatible.
* \note The caller has to take ownership of the returned pointer if not 0. * \note The callee, respectively the callee's parent, has the ownership of the returned pointer.
* \param source Source image representation for conversion. * \param source Source image representation for conversion.
* \return A pointer to a local representation of \a source or 0 on failure. The caller has to take ownership. * \return A pointer to a local representation of \a source or 0 on failure. The caller does \b not have ownership.
*/ */
static ImageRepresentationGL* tryConvertFrom(const AbstractImageRepresentation* source); static ImageRepresentationGL* tryConvertFrom(const AbstractImageRepresentation* source);
...@@ -139,6 +135,33 @@ namespace campvis { ...@@ -139,6 +135,33 @@ namespace campvis {
protected: protected:
/**
* Creates a new ImageRepresentationGL representation from a tgt::Texture.
*
* \param parent Image this representation represents, must not be 0.
* \param texture OpenGL texture to use, must not be 0, ImageRepresentationGL will take ownership of this texture.
*/
ImageRepresentationGL(ImageData* parent, tgt::Texture* texture);
/**
* Creates a new ImageRepresentationGL representation.
*
* \param parent Image this representation represents, must not be 0.
* \param wtp WeaklyTypedPointer to the image data, must not be 0, ImageRepresentationGL does \b not take ownership of that pointer.
*/
ImageRepresentationGL(ImageData* parent, const WeaklyTypedPointer& wtp);
/**
* Creates a new ImageRepresentationGL representation from GenericImageRepresentationLocal.
*
* \param parent Image this representation represents, must not be 0.
* \param data Pointer to the GenericImageRepresentationLocal instance, must not be 0
* \tparam BASETYPE Base type of image data
* \tparam NUMCHANNELS Number of channels per element
*/
template<typename BASETYPE, size_t NUMCHANNELS>
ImageRepresentationGL(ImageData* parent, const GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>* data);
/** /**
* Creates the OpenGL texture from the given pointer \a wtp. * Creates the OpenGL texture from the given pointer \a wtp.
* \param wtp WeaklyTypedPointer with source image data * \param wtp WeaklyTypedPointer with source image data
......
...@@ -140,7 +140,7 @@ namespace campvis { ...@@ -140,7 +140,7 @@ namespace campvis {
\ \
PixelType* pixelDataCopy = new PixelType[tgt::hmul(size)]; \ PixelType* pixelDataCopy = new PixelType[tgt::hmul(size)]; \
memcpy(pixelDataCopy, pixelData, tgt::hmul(size) * TypeTraits<basetype, 1>::elementSize); \ memcpy(pixelDataCopy, pixelData, tgt::hmul(size) * TypeTraits<basetype, 1>::elementSize); \
return new GenericImageRepresentationLocal<PixelType, 1>(const_cast<ImageData*>(source->getParent()), pixelDataCopy); \ return GenericImageRepresentationLocal<PixelType, 1>::create(const_cast<ImageData*>(source->getParent()), pixelDataCopy); \
} }
#define DISPATCH_ITK_TO_GENERIC_LOCAL_CONVERSION_ND(numchannels, dimensionality) \ #define DISPATCH_ITK_TO_GENERIC_LOCAL_CONVERSION_ND(numchannels, dimensionality) \
...@@ -201,7 +201,7 @@ namespace campvis { ...@@ -201,7 +201,7 @@ namespace campvis {
WeaklyTypedPointer wtp = source->getImageData(); WeaklyTypedPointer wtp = source->getImageData();
#define CONVERT_DISK_TO_GENERIC_LOCAL(baseType,numChannels) \ #define CONVERT_DISK_TO_GENERIC_LOCAL(baseType,numChannels) \
return new GenericImageRepresentationLocal<baseType, numChannels>( \ return GenericImageRepresentationLocal<baseType, numChannels>::create( \
const_cast<ImageData*>(source->getParent()), \ const_cast<ImageData*>(source->getParent()), \
reinterpret_cast< TypeTraits<baseType, numChannels>::ElementType*>(wtp._pointer)); reinterpret_cast< TypeTraits<baseType, numChannels>::ElementType*>(wtp._pointer));
......
...@@ -49,15 +49,6 @@ namespace campvis { ...@@ -49,15 +49,6 @@ namespace campvis {
public: public:
typedef ConcurrentGenericHistogramND<float, 1> IntensityHistogramType; typedef ConcurrentGenericHistogramND<float, 1> IntensityHistogramType;
/**
* Creates a new ImageData representation in local memory.
*
* \param dimensionality Dimensionality of data
* \param size Size of this image (number of elements per dimension)
* \param baseType Base type of the image data.
*/
ImageRepresentationLocal(ImageData* parent, WeaklyTypedPointer::BaseType baseType);
/** /**
* Destructor * Destructor
*/ */
...@@ -66,9 +57,9 @@ namespace campvis { ...@@ -66,9 +57,9 @@ namespace campvis {
/** /**
* Performs a conversion of \a source to an ImageRepresentationLocal if feasible. * Performs a conversion of \a source to an ImageRepresentationLocal if feasible.
* Returns 0 if conversion was not successful or source representation type is not compatible. * Returns 0 if conversion was not successful or source representation type is not compatible.
* \note The caller has to take ownership of the returned pointer if not 0. * \note The callee, respectively the callee's parent, has the ownership of the returned pointer.
* \param source Source image representation for conversion. * \param source Source image representation for conversion.
* \return A pointer to a local representation of \a source or 0 on failure. The caller has to take ownership. * \return A pointer to a local representation of \a source or 0 on failure. The caller does \b not have ownership.
*/ */
static ImageRepresentationLocal* tryConvertFrom(const AbstractImageRepresentation* source); static ImageRepresentationLocal* tryConvertFrom(const AbstractImageRepresentation* source);
...@@ -190,6 +181,15 @@ namespace campvis { ...@@ -190,6 +181,15 @@ namespace campvis {
const IntensityHistogramType& getIntensityHistogram() const; const IntensityHistogramType& getIntensityHistogram() const;
protected: protected:
/**
* Creates a new ImageData representation in local memory.
*
* \param dimensionality Dimensionality of data
* \param size Size of this image (number of elements per dimension)
* \param baseType Base type of the image data.
*/
ImageRepresentationLocal(ImageData* parent, WeaklyTypedPointer::BaseType baseType);
/** /**
* Computes the normalized intensity range. * Computes the normalized intensity range.
*/ */
......
...@@ -42,9 +42,16 @@ namespace campvis { ...@@ -42,9 +42,16 @@ namespace campvis {
const std::string ImageRepresentationRenderTarget::loggerCat_ = "CAMPVis.core.datastructures.ImageRepresentationRenderTarget"; const std::string ImageRepresentationRenderTarget::loggerCat_ = "CAMPVis.core.datastructures.ImageRepresentationRenderTarget";
ImageRepresentationRenderTarget* ImageRepresentationRenderTarget::create(ImageData* parent, GLint internalFormatColor /*= GL_RGBA8*/, GLint internalFormatDepth /*= GL_DEPTH_COMPONENT24*/) {
ImageRepresentationRenderTarget* toReturn = new ImageRepresentationRenderTarget(parent, internalFormatColor, internalFormatDepth);
toReturn->addToParent();
return toReturn;
}
std::pair<ImageData*, ImageRepresentationRenderTarget*> ImageRepresentationRenderTarget::createWithImageData(const tgt::svec2& size, GLint internalFormatColor /*= GL_RGBA8*/, GLint internalFormatDepth /*= GL_DEPTH_COMPONENT24*/) { std::pair<ImageData*, ImageRepresentationRenderTarget*> ImageRepresentationRenderTarget::createWithImageData(const tgt::svec2& size, GLint internalFormatColor /*= GL_RGBA8*/, GLint internalFormatDepth /*= GL_DEPTH_COMPONENT24*/) {
ImageData* id = new ImageData(2, tgt::svec3(size, 1), 4); ImageData* id = new ImageData(2, tgt::svec3(size, 1), 4);
ImageRepresentationRenderTarget* toReturn = new ImageRepresentationRenderTarget(id, internalFormatColor, internalFormatDepth); ImageRepresentationRenderTarget* toReturn = new ImageRepresentationRenderTarget(id, internalFormatColor, internalFormatDepth);
toReturn->addToParent();
return std::make_pair(id, toReturn); return std::make_pair(id, toReturn);
} }
......
...@@ -60,6 +60,19 @@ namespace campvis { ...@@ -60,6 +60,19 @@ namespace campvis {
*/