Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit 4af18b59 authored by schultezub's avatar schultezub
Browse files

* added ImageDataRAM

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@169 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent e97cf77e
......@@ -16,13 +16,13 @@ namespace TUMVis {
}
ImageData* ImageDataDisk::getSubImage(const tgt::svec3& llf, const tgt::svec3& urb) const {
tgtAssert(tgt::hand(tgt::lessThan(llf, urb)), "Coordinates in LLF must be componentwise smaller than the ones in URB!");
ImageDataDisk* ImageDataDisk::getSubImage(const tgt::svec3& llf, const tgt::svec3& urb) const {
tgtAssert(tgt::hand(tgt::lessThan(llf, urb)), "Coordinates in LLF must be component-wise smaller than the ones in URB!");
tgt::svec3 newSize = urb - llf;
if (newSize == _size) {
// nothing has changed, just provide a copy:
return static_cast<ImageData*>(clone());
return clone();
}
size_t newOffset = _offset + WeaklyTypedPointer::numBytes(_type) * llf.x;
......@@ -175,7 +175,7 @@ namespace TUMVis {
return tgt::svec3(0, size.x, size.x * size.y);
}
AbstractData* ImageDataDisk::clone() const {
ImageDataDisk* ImageDataDisk::clone() const {
return new ImageDataDisk(_url, _dimensionality, _size, _type, _offset, _endianess, _stride);
}
}
\ No newline at end of file
......@@ -50,12 +50,12 @@ namespace TUMVis {
/**
* \see AbstractData::clone()
**/
virtual AbstractData* clone() const;
virtual ImageDataDisk* clone() const;
/**
* \see ImageData::getSubImage
*/
virtual ImageData* getSubImage(const tgt::svec3& llf, const tgt::svec3& urb) const;
virtual ImageDataDisk* getSubImage(const tgt::svec3& llf, const tgt::svec3& urb) const;
/**
......@@ -84,6 +84,7 @@ namespace TUMVis {
**/
tgt::svec3 _stride;
static const std::string loggerCat_;
};
}
......
#include "imagedataram.h"
#include <cstring>
namespace TUMVis {
const std::string ImageDataRAM::loggerCat_ = "TUMVis.core.datastructures.ImageDataRAM";
ImageDataRAM::ImageDataRAM(size_t dimensionality, const tgt::svec3& size, WeaklyTypedPointer data)
: ImageData(dimensionality, size)
, _data(data)
{
}
ImageDataRAM::~ImageDataRAM() {
delete _data._pointer;
}
ImageDataRAM* ImageDataRAM::clone() const {
size_t numBytes = tgt::hmul(_size) * _data.numBytes();
char* newData = new char[numBytes];
memcpy(newData, _data._pointer, numBytes);
return new ImageDataRAM(_dimensionality, _size, WeaklyTypedPointer(_data._pointerType, static_cast<void*>(newData)));
}
ImageDataRAM* ImageDataRAM::getSubImage(const tgt::svec3& llf, const tgt::svec3& urb) const {
tgtAssert(tgt::hand(tgt::lessThan(llf, urb)), "Coordinates in LLF must be component-wise smaller than the ones in URB!");
tgt::svec3 newSize = urb - llf;
if (newSize == _size) {
// nothing has changed, just provide a copy:
return clone();
}
size_t numBytesPerElement = _data.numBytes();
size_t numBytesTotal = tgt::hmul(newSize) * numBytesPerElement;
char* newData = new char[numBytesTotal];
// slice image data into new array
size_t index = 0;
for (size_t z = llf.z; z < urb.z; ++z) {
for (size_t y = llf.y; y < urb.y; ++y) {
size_t offset = llf.x + (y * _size.x) + (z * _size.y * _size.x);
memcpy(newData + (index * numBytesPerElement), static_cast<char*>(_data._pointer) + (offset * numBytesPerElement), newSize.x * numBytesPerElement);
index += newSize.x;
}
}
return new ImageDataRAM(_dimensionality, newSize, WeaklyTypedPointer(_data._pointerType, static_cast<void*>(newData)));
}
WeaklyTypedPointer& ImageDataRAM::getImageData() {
return _data;
}
const WeaklyTypedPointer& ImageDataRAM::getImageData() const {
return _data;
}
}
\ No newline at end of file
#ifndef IMAGEDATARAM_H__
#define IMAGEDATARAM_H__
#include "tgt/vector.h"
#include "core/datastructures/imagedata.h"
#include "core/tools/endianhelper.h"
#include "core/tools/typetraits.h"
#include "core/tools/weaklytypedpointer.h"
#include <fstream>
#include <string>
namespace TUMVis {
/**
* Subclass of ImageData storing the image data in the local memory.
*
* \todo implement padding
*/
class ImageDataRAM : public ImageData {
public:
/**
* Creates a new ImageData disk representation.
*
* \param dimensionality Dimensionality of data
* \param size Size of this image (number of elements per dimension)
* \param data WeaklyTypedPointer to the image data
*/
ImageDataRAM(
size_t dimensionality,
const tgt::svec3& size,
WeaklyTypedPointer data
);
/**
* Destructor
*/
virtual ~ImageDataRAM();
/**
* \see AbstractData::clone()
**/
virtual ImageDataRAM* clone() const;
/**
* \see ImageData::getSubImage
*/
virtual ImageDataRAM* getSubImage(const tgt::svec3& llf, const tgt::svec3& urb) const;
/**
* Returns the WeaklyTypedPointer to the image data.
* \return Pointer to the image data.
*/
WeaklyTypedPointer& getImageData();
/**
* Returns the WeaklyTypedPointer to the image data.
* \return Pointer to the image data.
*/
const WeaklyTypedPointer& getImageData() const;
private:
WeaklyTypedPointer _data; ///< pointer to image data
static const std::string loggerCat_;
};
}
#endif // IMAGEDATARAM_H__
......@@ -73,6 +73,14 @@ namespace TUMVis {
{
};
/**
* Returns the number of bytes occupied by one element of the type of this pointer.
* \returns The number of bytes occupied by one element of the type of this pointer.
*/
size_t numBytes() const {
return WeaklyTypedPointer::numBytes(_pointerType);
}
PointerType _pointerType; ///< Base data type of the pointer
void* _pointer; ///< Pointer to the data
};
......
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