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 659aa814 authored by schultezub's avatar schultezub
Browse files

* moved tools back to core

 * un-templated ImageDataDisk

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@165 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent bdf1c858
......@@ -35,4 +35,4 @@ ADD_EXECUTABLE(tumvis-application
)
ADD_DEFINITIONS(${TUMVIS_DEFINITIONS} ${QT_DEFINITIONS})
INCLUDE_DIRECTORIES(${TUMVIS_INCLUDE_DIRECTORIES})
TARGET_LINK_LIBRARIES(tumvis-application tumvis-core tgt ${TUMVIS_EXTERNAL_LIBRARIES} ${QT_LIBRARIES})
TARGET_LINK_LIBRARIES(tumvis-application tumvis-core tumvis-modules tgt ${TUMVIS_EXTERNAL_LIBRARIES} ${QT_LIBRARIES})
......@@ -59,7 +59,7 @@ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${TUMVIS_HOME}/bin")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${TUMVIS_HOME}/bin")
# common include directories
LIST(APPEND TUMVIS_INCLUDE_DIRECTORIES "${TUMVIS_HOME}/core" "${TUMVIS_HOME}/modules" "${TUMVIS_HOME}/ext" "${TUMVIS_HOME}/tools")
LIST(APPEND TUMVIS_INCLUDE_DIRECTORIES "${TUMVIS_HOME}/ext")
LIST(APPEND TUMVIS_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
# platform-dependent configuration
......
......@@ -4,12 +4,14 @@ INCLUDE(../cmake/commonconf.cmake)
MESSAGE(STATUS "Configuring TUMVis Core")
FILE(GLOB TUMVIS_CORE_SOURCES
FILE(GLOB TUMVIS_CORE_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
datastructures/*.cpp
tools/*.cpp
)
FILE(GLOB TUMVIS_CORE_HEADERS
FILE(GLOB TUMVIS_CORE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
datastructures/*.h
tools/*.h
)
#SET(TUMVIS_CORE_SOURCES
......
#ifndef DATACONTAINER_H__
#define DATACONTAINER_H__
#include "datastructures/abstractdata.h"
#include "datastructures/datahandle.h"
#include "core/datastructures/abstractdata.h"
#include "core/datastructures/datahandle.h"
#include <string>
#include <map>
......@@ -76,3 +78,5 @@ namespace TUMVis {
};
}
#endif // DATACONTAINER_H__
......@@ -2,7 +2,7 @@
#define datahandle_h__
#include "tgt/logmanager.h"
#include "datastructures/abstractdata.h"
#include "core/datastructures/abstractdata.h"
#include <string>
#include <set>
......
#ifndef imagedata_h__
#define imagedata_h__
#ifndef IMAGEDATA_H__
#define IMAGEDATA_H__
#include "datastructures/abstractdata.h"
#include "datastructures/imagemappinginformation.h"
#include "core/datastructures/abstractdata.h"
#include "core/datastructures/imagemappinginformation.h"
#include "tgt/vector.h"
namespace TUMVis {
......@@ -52,9 +52,9 @@ namespace TUMVis {
* \param urb Upper-Right-Back coordinates of subimage
* \return An image containing the subimage of this with the given coordinates.
*/
virtual ImageData* getSubImage(const tgt::svec3& llf, const tgt::svec3& urb) = 0;
virtual ImageData* getSubImage(const tgt::svec3& llf, const tgt::svec3& urb) const = 0;
private:
protected:
size_t _dimensionality; ///< Dimensionality of this image
tgt::svec3 _size; ///< Size of this image (number of elements per dimension)
ImageMappingInformation _mappingInformation; ///< Mapping information of this image
......@@ -64,4 +64,4 @@ namespace TUMVis {
}
#endif // imagedata_h__
#endif // IMAGEDATA_H__
#ifndef imagedata_h__
#define imagedata_h__
#ifndef IMAGEDATADISK_H__
#define IMAGEDATADISK_H__
#include "tgt/vector.h"
#include "datastructures/imagedata.h"
#include "tools/endianhelper.h"
#include "tools/typetraits.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>
......@@ -15,7 +18,6 @@ namespace TUMVis {
*
* \todo
*/
template<typename T>
class ImageDataDisk : public ImageData {
public:
/**
......@@ -24,6 +26,7 @@ namespace TUMVis {
* \param url Path to file with raw data
* \param dimensionality Dimensionality of data
* \param size Size of this image (number of elements per dimension)
* \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 _elemments_ _between_ adjacent elements for each dimension (\see ImageDataDisk::_stride).
......@@ -31,28 +34,35 @@ namespace TUMVis {
ImageDataDisk(
const std::string& url,
size_t dimensionality,
const tgt::vec3& size,
const tgt::svec3& size,
WeaklyTypedPointer::PointerType type,
size_t offset = 0,
EndianHelper::Endianness endianness = EndianHelper::LITTLE_ENDIAN,
const tgt::svec3& stride = tgt::svec2::zero
const tgt::svec3& stride = tgt::svec3::zero
);
/**
* Destructor
*/
virtual ~ImageDataDisk() {};
virtual ~ImageDataDisk();
/**
* \see AbstractData::clone()
**/
virtual AbstractData* clone() const;
/**
* \see ImageData::getSubImage
*/
virtual ImageDataDisk<T>* getSubImage(const tgt::vec3& llf, const tgt::vec3& urb);
virtual ImageData* getSubImage(const tgt::svec3& llf, const tgt::svec3& urb) const;
/**
* Downloads the whole image data to local memory.
* \return Pointer to the image data in the local memory.
*/
T* getImageData() const;
WeaklyTypedPointer getImageData() const;
private:
/**
......@@ -64,6 +74,7 @@ namespace TUMVis {
std::string _url; ///< path to file with raw data
size_t _offset; ///< offset of first data element in file (in bytes)
WeaklyTypedPointer::PointerType _type; ///< base type of data
EndianHelper::Endianness _endianess; ///< endianess of data
/**
......@@ -75,122 +86,6 @@ namespace TUMVis {
};
// - Template implementation ----------------------------------------------------------------------
template<typename T>
TUMVis::ImageDataDisk<T>::ImageDataDisk(const std::string& url, size_t dimensionality, const tgt::vec3& size, size_t offset /*= 0*/, EndianHelper::Endianness endianness /*= false*/, const tgt::svec3& stride /*= tgt::svec2::zero */)
: ImageData(dimensionality, size)
, _url(url)
, _offset(offset)
, _endianess(endianness)
, _stride(stride)
{
}
template<typename T>
ImageDataDisk<T>* TUMVis::ImageDataDisk<T>::getSubImage(const tgt::vec3& llf, const tgt::vec3& urb) {
tgtAssert(tgt::hand(tgt::lessThan(llf, urb)), "Coordinates in LLF must be componentwise smaller than the ones in URB!");
tgt::svec3 newSize = urb - llf;
if (newSize == _size) {
// nothing has changed, just provide a copy:
return new ImageDataDisk<T>(_url, _dimensionality, newSize, _offset, _isBigEndian, _stride);
}
size_t newOffset = _offset + TypeTraits<T>::numBytes * llf.x;
tgt::svec3 newStride = (_stride == tgt::svec3::zero) ? getCanonicStride(_size) : _stride;
return new ImageDataDisk<T>(_url, _dimensionality, newSize, newOffset, _isBigEndian, newStride);
}
template<typename T>
T* TUMVis::ImageDataDisk<T>::getImageData() const {
size_t numElements = tgt::hmul(_size);
size_t numBytes = numElements * TypeTraits<T>::numBytes;
// open file and prepare for read
std::ifstream file(_url, std::ios::in | std::ios::binary | std::ios::ate);
if (file.is_open()) {
size_t fileSize = file.tellg();
if (fileSize < numBytes) {
LERROR("File is smaller than expected.");
return 0;
}
file.seekg(_offset, std::ios::beg);
// handle stride:
tgt::svec3 canonicStride = getCanonicStride(_size);
if (_stride == tgt::svec3::zero || _stride == canonicStride) {
// no stride is easy - we have just one chunk of data:
T* data = new T[numElements];
file.read(data, numBytes);
}
else {
// TODO: Check for correctness when being adequately awake! ;)
size_t index = 0;
size_t bytesPerElement = TypeTraits<T>::numBytes;
// we have a stride at at least one direction
if (_stride.z == 0 || canonicStride.z) {
if (_stride.y == 0 || canonicStride.y) {
// we have a stride only in the last dimension so we can read the elements from the first two dimension in a row
size_t sz = _size.x*_size.y;
for (size_t z = 0; z < _size.z; ++z) {
file.read(data + index, sz * bytesPerElement);
file.seekg((_stride.z - sz) * bytesPerElement, std::ios::cur);
index += sz;
}
}
else {
// we have a stride only in the last 2 dimensions so we can read the elements from the first dimension in a row
for (size_t z = 0; z < _size.z; ++z) {
for (size_t y = 0; y < _size.y; ++y) {
file.read(data + index, _size.x * bytesPerElement);
file.seekg((_stride.y - _size.x) * bytesPerElement, std::ios::cur);
index + _size.x;
}
file.seekg((_stride.z - (_size.x*_size.y)) * bytesPerElement, std::ios::cur);
}
}
}
else {
// read each element separately
for (size_t z = 0; z < _size.z; ++z) {
for (size_t y = 0; y < _size.y; ++y) {
for (size_t x = 0; x < _size.x; ++x) {
file.read(data + index, bytesPerElement);
file.seekg((_stride.x - 1) * bytesPerElement, std::ios::cur);
++index;
}
file.seekg((_stride.y - _size.x) * bytesPerElement, std::ios::cur);
}
file.seekg((_stride.z - (_size.x*_size.y)) * bytesPerElement, std::ios::cur);
}
}
}
file.close();
// handle endianess
EndianHelper::Endianness localEndianess = EndianHelper::getLocalEndianness();
if (_endianess != localEndianess) {
for (size_t i = 0; i < numElements; ++i)
data[i] = EndianHelper::swapEndian(data[i]);
}
return data;
}
else {
LERROR("Could not open file " << _url << " for reading.");
return 0;
}
}
template<typename T>
tgt::svec3 TUMVis::ImageDataDisk<T>::getCanonicStride(const tgt::svec3& size) const {
return tgt::svec3(0, size.x, size.x * size.y);
}
}
#endif // imagedata_h__
#endif // IMAGEDATADISK_H__
......@@ -2,7 +2,7 @@
#define imagemapping_h__
#include "tgt/matrix.h"
#include "tools/mapping.h"
#include "core/tools/mapping.h"
namespace TUMVis {
......
......@@ -10,7 +10,7 @@ namespace {
template<typename T, size_t N>
struct SwapHelper {
static inline T swap(T value) {
LERRORC("TUMVis.Tools.EndianHelper", "Tried to call SwapHelper<T,N>::swap() with unsupported template arguments.")
LERRORC("TUMVis.Tools.EndianHelper", "Tried to call SwapHelper<T,N>::swap() with unsupported template arguments.");
return value;
}
};
......@@ -93,7 +93,7 @@ namespace TUMVis {
* \return Endian-swapped version of \a value.
*/
template<typename T>
inline T swapEndian(T value) {
static inline T swapEndian(T value) {
return SwapHelper<T, sizeof(T)>::swap(value);
}
......
#ifndef WEAKLYTYPEDPOINTER_H__
#define WEAKLYTYPEDPOINTER_H__
#include "tgt/assert.h"
namespace TUMVis {
struct WeaklyTypedPointer {
enum PointerType {
UCHAR,
CHAR,
USHORT,
SHORT,
UINT,
INT,
FLOAT,
ULONG,
LONG,
DOUBLE
};
/**
* Returns the number of bytes occupied by one element of the type \a pt.
* \param pt Data type to check.
**/
static size_t numBytes(PointerType pt) {
switch (pt) {
case WeaklyTypedPointer::UCHAR:
case WeaklyTypedPointer::CHAR:
return sizeof(char);
case WeaklyTypedPointer::USHORT:
case WeaklyTypedPointer::SHORT:
return sizeof(short);
case WeaklyTypedPointer::UINT:
case WeaklyTypedPointer::INT:
return sizeof(int);
case WeaklyTypedPointer::FLOAT:
return sizeof(float);
case WeaklyTypedPointer::ULONG:
case WeaklyTypedPointer::LONG:
return sizeof(long);
case WeaklyTypedPointer::DOUBLE:
return sizeof(double);
default:
tgtAssert(false, "Should not reach this - called WeaklyTypedPointer::numBytes() with wrong argument!");
return 1;
}
};
/**
*
*
* \param pt
* \param ptr
**/
WeaklyTypedPointer(PointerType pt, void* ptr)
: _pointerType(pt)
, _pointer(ptr)
{
};
PointerType _pointerType;
void* _pointer;
};
}
#endif // WEAKLYTYPEDPOINTER_H__
......@@ -30,8 +30,8 @@ FIND_PACKAGE(Qt4 ${TUMVIS_REQUIRED_QT_VERSION} REQUIRED QtCore QtGui QtOpenGL)
INCLUDE(${QT_USE_FILE})
ADD_LIBRARY(tumvis-modules
${TUMVIS_CORE_SOURCES} ${TUMVIS_CORE_HEADERS}
# ${TUMVIS_CORE_MOC}
${TUMVIS_MODULES_SOURCES} ${TUMVIS_MODULES_HEADERS}
# ${TUMVIS_MODULES_MOC}
)
ADD_DEFINITIONS(${TUMVIS_DEFINITIONS} ${QT_DEFINITIONS})
INCLUDE_DIRECTORIES(${TUMVIS_INCLUDE_DIRECTORIES})
......
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