Commit 0a5144e7 authored by schultezub's avatar schultezub
Browse files

introducing LtfImageReader

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@514 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 9a100035
......@@ -31,6 +31,7 @@
#define STRINGUTILS_H__
#include "tgt/exception.h"
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
......@@ -119,6 +120,16 @@ namespace campvis {
template<class T>
static std::string toString(const T& value);
/**
* Converts the value \a value to a zero-padded string.
* \param value The value to convert, must be compatible with std::stringstream.
* \param paddingWidth Number of digits for padding to apply
* \param fill Fill character for padding
* \return A string representation of \a value.
*/
template<class T>
static std::string toString(const T& value, size_t paddingWidth, char fill);
/**
* Converts the string \a str to its original value.
* \param str The string to convert
......@@ -147,6 +158,12 @@ namespace campvis {
return stream.str();
}
template<class T>
std::string StringUtils::toString(const T& value, size_t paddingWidth, char fill) {
std::ostringstream stream;
stream << std::setw(paddingWidth) << std::setfill(fill) << value;
return stream.str();
}
template<class T>
T StringUtils::fromString(const std::string& str) throw (tgt::Exception) {
T toReturn;
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#include "ltfimagereader.h"
#include <limits>
#include "tgt/filesystem.h"
#include "core/tools/stringutils.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imageseries.h"
#include "core/datastructures/imagerepresentationdisk.h"
namespace campvis {
static const GenericOption<WeaklyTypedPointer::BaseType> baseTypeOptions[7] = {
GenericOption<WeaklyTypedPointer::BaseType>("uint8", "uint8", WeaklyTypedPointer::UINT8),
GenericOption<WeaklyTypedPointer::BaseType>("int8", "int8", WeaklyTypedPointer::INT8),
GenericOption<WeaklyTypedPointer::BaseType>("uint16", "uint16", WeaklyTypedPointer::UINT16),
GenericOption<WeaklyTypedPointer::BaseType>("int16", "int16", WeaklyTypedPointer::INT16),
GenericOption<WeaklyTypedPointer::BaseType>("uint32", "uint32", WeaklyTypedPointer::UINT32),
GenericOption<WeaklyTypedPointer::BaseType>("int32", "int32", WeaklyTypedPointer::INT32),
GenericOption<WeaklyTypedPointer::BaseType>("float", "float", WeaklyTypedPointer::FLOAT),
};
const std::string LtfImageReader::loggerCat_ = "CAMPVis.modules.io.LtfImageReader";
LtfImageReader::LtfImageReader()
: AbstractProcessor()
, p_url("url", "Image URL", "")
, p_size("Size", "Image Size", tgt::ivec3(1), tgt::ivec3(1), tgt::ivec3(2048))
, p_numChannels("NumChannels", "Number of Channels per Element", 1, 1, 9)
, p_baseType("BaseType", "Base Type", baseTypeOptions, 7)
, p_targetImageID("targetImageName", "Target Image ID", "LtfImageReader.output", DataNameProperty::WRITE)
, p_imageOffset("ImageOffset", "Image Offset in mm", tgt::vec3(0.f), tgt::vec3(-10000.f), tgt::vec3(10000.f))
, p_voxelSize("VoxelSize", "Voxel Size in mm", tgt::vec3(1.f), tgt::vec3(-100.f), tgt::vec3(100.f))
{
addProperty(&p_url);
addProperty(&p_size);
addProperty(&p_numChannels);
addProperty(&p_baseType);
addProperty(&p_targetImageID);
addProperty(&p_imageOffset);
addProperty(&p_voxelSize);
}
LtfImageReader::~LtfImageReader() {
}
void LtfImageReader::process(DataContainer& data) {
size_t dimensionality = 3;
if (p_size.getValue().z == 1) {
dimensionality = (p_size.getValue().y == 1) ? 1 : 2;
}
std::string noExt = tgt::FileSystem::fullBaseName(p_url.getValue());
std::string::size_type offset = noExt.find_last_not_of("0123456789");
if (offset != std::string::npos) {
std::string base = noExt.substr(0, offset);
int index = StringUtils::fromString<int>(noExt.substr(offset));
ImageSeries* series = new ImageSeries();
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, StringUtils::toString(index, noExt.size() - offset, '0'), p_baseType.getOptionValue(), 0, EndianHelper::getLocalEndianness());
image->setMappingInformation(ImageMappingInformation(p_size.getValue(), p_imageOffset.getValue(), p_voxelSize.getValue()));
series->addImage(image);
}
data.addData(p_targetImageID.getValue(), series);
p_targetImageID.issueWrite();
}
else {
LERROR("Could not deduce counting index.");
}
validate(INVALID_RESULT);
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#ifndef LTFIMAGEREADER_H__
#define LTFIMAGEREADER_H__
#include "core/pipeline/abstractprocessor.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/numericproperty.h"
#include "core/properties/optionproperty.h"
#include "core/tools/endianhelper.h"
#include "core/tools/weaklytypedpointer.h"
namespace campvis {
/**
* Reads raw images into the pipeline.
*/
class LtfImageReader : public AbstractProcessor {
public:
/**
* Constructs a new LtfImageReader Processor
**/
LtfImageReader();
/**
* Destructor
**/
virtual ~LtfImageReader();
/**
* Reads the raw file into an ImageRepresentationDisk representation
* \param data DataContainer to work on
*/
virtual void process(DataContainer& data);
/// \see AbstractProcessor::getName()
virtual const std::string getName() const { return "LtfImageReader"; };
/// \see AbstractProcessor::getDescription()
virtual const std::string getDescription() const { return "Reads a series of raw images into the pipeline."; };
StringProperty p_url; ///< URL for file to read
IVec3Property p_size; ///< Image size
IntProperty p_numChannels; ///< Number of channels per element
GenericOptionProperty<WeaklyTypedPointer::BaseType> p_baseType; ///< Base type
DataNameProperty p_targetImageID; ///< image ID for read image
Vec3Property p_imageOffset; ///< Image Offset in mm
Vec3Property p_voxelSize; ///< Voxel Size in mm
protected:
static const std::string loggerCat_;
};
}
#endif // LTFIMAGEREADER_H__
\ No newline at end of file
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