Commit 3aa094f7 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Added flag to read multichannel images stored side-by-side on disk

parent df8c3e9f
......@@ -35,19 +35,20 @@
namespace campvis {
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);
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 */, bool multichannelSideBySide /*= false*/) {
ImageRepresentationDisk* toReturn = new ImageRepresentationDisk(parent, url, type, offset, endianness, stride, multichannelSideBySide);
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 */, bool multichannelSideBySide /*= false*/)
: GenericAbstractImageRepresentation<ImageRepresentationDisk>(parent)
, _url(url)
, _offset(offset)
, _type(type)
, _endianess(endianness)
, _stride(stride)
, _multichannelSideBySide(multichannelSideBySide)
{
}
......@@ -186,6 +187,21 @@ namespace campvis {
}
}
if (_multichannelSideBySide && _parent->getNumChannels() > 1) {
// there is no simple in-place solution, so we copy everything around...
char* reordered = new char[numBytes];
size_t numBytesPerChannel = numBytesPerElement / _parent->getNumChannels();
for (size_t i = 0; i < numElements; ++i) {
for (size_t j = 0; j < _parent->getNumChannels(); ++j) {
size_t fromOffset = (i + j*numElements) * numBytesPerChannel;
size_t toOffset = (j + i*_parent->getNumChannels()) * numBytesPerChannel;
memcpy(reordered + toOffset, data + fromOffset, numBytesPerChannel);
}
}
std::swap(data, reordered);
delete [] reordered;
}
return WeaklyTypedPointer(_type, _parent->getNumChannels(), static_cast<void*>(data));
}
......
......@@ -56,6 +56,7 @@ namespace campvis {
* \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).
* \param multichannelSideBySide Flag whether multichannel images are stored side by side
* \return A pointer to the newly created ImageRepresentationDisk, you do \b not own this pointer!
*/
static ImageRepresentationDisk* create(
......@@ -64,7 +65,8 @@ namespace campvis {
WeaklyTypedPointer::BaseType type,
size_t offset = 0,
EndianHelper::Endianness endianness = EndianHelper::IS_LITTLE_ENDIAN,
const tgt::svec3& stride = tgt::svec3::zero
const tgt::svec3& stride = tgt::svec3::zero,
bool multichannelSideBySide = false
);
......@@ -121,6 +123,7 @@ namespace campvis {
* \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).
* \param multichannelSideBySide Flag whether multichannel images are stored side by side
*/
ImageRepresentationDisk(
ImageData* parent,
......@@ -128,7 +131,8 @@ namespace campvis {
WeaklyTypedPointer::BaseType type,
size_t offset = 0,
EndianHelper::Endianness endianness = EndianHelper::IS_LITTLE_ENDIAN,
const tgt::svec3& stride = tgt::svec3::zero
const tgt::svec3& stride = tgt::svec3::zero,
bool multichannelSideBySide = false
);
/**
......@@ -150,6 +154,8 @@ namespace campvis {
**/
tgt::svec3 _stride;
bool _multichannelSideBySide; ///< Flag whether multichannel images are stored side by side
static const std::string loggerCat_;
};
......
......@@ -89,7 +89,7 @@ namespace campvis {
while (tgt::FileSystem::fileExists(base + StringUtils::toString(index, noExt.size() - offset, '0') + ".ltf")) {
ImageData* image = new ImageData(dimensionality, p_size.getValue(), p_numChannels.getValue());
ImageRepresentationDisk::create(image, base + StringUtils::toString(index, noExt.size() - offset, '0') + ".ltf", p_baseType.getOptionValue(), 0, EndianHelper::getLocalEndianness());
ImageRepresentationDisk::create(image, base + StringUtils::toString(index, noExt.size() - offset, '0') + ".ltf", p_baseType.getOptionValue(), 0, EndianHelper::getLocalEndianness(), tgt::svec3::zero, true);
image->setMappingInformation(ImageMappingInformation(p_size.getValue(), p_imageOffset.getValue(), p_voxelSize.getValue()));
series->addImage(image);
++index;
......
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