Commit 756eb3a9 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Introduced manualsegmentation module with a HIGHLY EXPERIMENTAL processor and...

Introduced manualsegmentation module with a HIGHLY EXPERIMENTAL processor and pipeline for manual segmentation of tissue layers. This code not really intended for use in other code but only to keep the somewhat extensive code for later reuse.
parent 266ed881
# CMake file for manualsegmentation module
IF(ModuleEnabled)
# Source files:
FILE(GLOB ThisModSources RELATIVE ${ModulesDir}
modules/manualsegmentation/pipelines/*.cpp
modules/manualsegmentation/processors/*.cpp
modules/manualsegmentation/tools/*.cpp
)
# Header files (including GLSL files so that they'll appear in VS projects)
FILE(GLOB ThisModHeaders RELATIVE ${ModulesDir}
modules/manualsegmentation/pipelines/*.h
modules/manualsegmentation/processors/*.h
modules/manualsegmentation/tools/*.h
)
SET(ThisModDependencies io itk vis)
ENDIF(ModuleEnabled)
SET(ThisModStatus EXPERIMENTAL)
SET(ThisModExternalDependencies FALSE)
// ================================================================================================
//
// 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 "manualtissuesegmentation.h"
#include "tgt/filesystem.h"
#include "core/datastructures/imagerepresentationlocal.h"
#ifdef CAMPVIS_HAS_MODULE_DEVIL
#include <IL/il.h>
#include <IL/ilu.h>
#endif
#include <sstream>
#include <iomanip>
namespace campvis {
ManualTissueSegmentation::ManualTissueSegmentation(DataContainer* dc)
: AutoEvaluationPipeline(dc)
, _reader()
, _mts(&_canvasSize)
, _writer()
, _wheelHandler(&_mts.p_frameNumber)
{
addProcessor(&_reader);
addProcessor(&_mts);
addProcessor(&_writer);
addEventListenerToBack(&_wheelHandler);
addEventListenerToBack(&_mts);
}
ManualTissueSegmentation::~ManualTissueSegmentation() {
}
void ManualTissueSegmentation::init() {
AutoEvaluationPipeline::init();
_reader.p_url.setValue(CAMPVIS_SOURCE_DIR "/modules/advancedusvis/sampledata/Volume_0_small.mhd");
//_reader.p_url.setValue("D:/Medical Data/us_carotid_2014-02/christian/christian_bmode_2D_compounded_cropped.mhd");
_reader.p_targetImageID.addSharedProperty(&_mts.p_sourceImageID);
_mts.p_targetImageID.setValue("segmentation");
_writer.p_inputImage.setValue("LabelImage");
_writer.p_fileName.setValue(CAMPVIS_SOURCE_DIR "/modules/advancedusvis/sampledata/layers_0_small.mhd");
//_writer.p_fileName.setValue("D:/Medical Data/us_carotid_2014-02/christian/christian_bmode_2D_compounded_cropped_layers.mhd");
_renderTargetID.setValue(_mts.p_targetImageID.getValue());
}
void ManualTissueSegmentation::deinit() {
AutoEvaluationPipeline::deinit();
}
void ManualTissueSegmentation::onRenderTargetSizeChanged(const AbstractProperty* prop) {
}
}
\ 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 MANUALTISSUESEGMENTATION_H__
#define MANUALTISSUESEGMENTATION_H__
#include "core/eventhandlers/mwheeltonumericpropertyeventlistener.h"
#include "core/pipeline/autoevaluationpipeline.h"
#include "modules/io/processors/mhdimagereader.h"
#include "modules/io/processors/mhdimagewriter.h"
#include "modules/manualsegmentation/processors/manualtissuesegmenter.h"
namespace campvis {
/**
* VERY EXPERIMENTAL pipeline for manual segmentation of tissue layers.
*/
class ManualTissueSegmentation : public AutoEvaluationPipeline {
public:
/**
* Creates a VisualizationPipeline.
*/
ManualTissueSegmentation(DataContainer* dc);
/**
* Virtual Destructor
**/
virtual ~ManualTissueSegmentation();
/// \see VisualizationPipeline::init()
virtual void init();
/// \see VisualizationPipeline::deinit()
virtual void deinit();
/// \see AbstractPipeline::getName()
virtual const std::string getName() const { return getId(); };
static const std::string getId() { return "ManualTissueSegmentation"; };
protected:
void onRenderTargetSizeChanged(const AbstractProperty* prop);
MhdImageReader _reader;
ManualTissueSegmenter _mts;
MhdImageWriter _writer;
MWheelToNumericPropertyEventListener _wheelHandler;
};
}
#endif // MANUALTISSUESEGMENTATION_H__
// ================================================================================================
//
// 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.
//
// ================================================================================================
#ifndef MANUALTISSUESEGMENTER_H__
#define MANUALTISSUESEGMENTER_H__
#include <string>
#include <map>
#include "tgt/bounds.h"
#include "tgt/event/eventlistener.h"
#include "core/datastructures/datahandle.h"
#include "core/pipeline/visualizationprocessor.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/buttonproperty.h"
#include "core/properties/numericproperty.h"
#include "core/properties/transferfunctionproperty.h"
#include "core/properties/cameraproperty.h"
#include "modules/manualsegmentation/tools/tissuesegmentation.h"
namespace tgt {
class Shader;
}
namespace campvis {
class ImageData;
/**
* VERY EXPERIMENTAL processor for manual segmentation of tissue layers.
*/
class ManualTissueSegmenter : public VisualizationProcessor, public tgt::EventListener {
public:
/**
* Constructs a new ManualTissueSegmenter Processor
**/
ManualTissueSegmenter(IVec2Property* viewportSizeProp);
/**
* Destructor
**/
virtual ~ManualTissueSegmenter();
/// \see AbstractProcessor::init
virtual void init();
/// \see AbstractProcessor::deinit
virtual void deinit();
/// \see AbstractEventHandler::execute()
virtual void onEvent(tgt::Event* e);
/// \see AbstractProcessor::getName()
virtual const std::string getName() const { return "ManualTissueSegmenter"; };
/// \see AbstractProcessor::getDescription()
virtual const std::string getDescription() const { return "VERY EXPERIMENTAL processor for manual segmentation of tissue layers."; };
/// \see AbstractProcessor::getAuthor()
virtual const std::string getAuthor() const { return "Christian Schulte zu Berge <christian.szb@in.tum.de>"; };
/// \see AbstractProcessor::getProcessorState()
virtual ProcessorState getProcessorState() const { return AbstractProcessor::EXPERIMENTAL; };
DataNameProperty p_sourceImageID; ///< image ID for input FileIO
DataNameProperty p_targetImageID; ///< image ID for output image
IntProperty p_frameNumber; ///< Number of the frame to display
TransferFunctionProperty p_transferFunction; ///< Transfer function
BoolProperty p_fullWidth;
IntProperty p_splineOrder;
IntProperty p_NumControlPoints;
IntProperty p_NumLevels;
ButtonProperty p_computeSamples;
BoolProperty p_showSamples;
StringProperty p_sampleFile;
ButtonProperty p_saveSamples;
StringProperty p_controlpointFile;
ButtonProperty p_saveCPs;
ButtonProperty p_loadCPs;
IntProperty p_activeLayer;
ButtonProperty p_addLayer;
ButtonProperty p_exportToLabelImage;
protected:
struct ControlPoint {
tgt::vec2 _pixel;
};
/// \see AbstractProcessor::updateResult()
virtual void updateResult(DataContainer& data);
/// adapts the range of the p_frameNumber property to the image
virtual void updateProperties(DataContainer& data);
/// \see AbstractProcessor::onPropertyChanged
virtual void onPropertyChanged(const AbstractProperty* prop);
void computeSpline();
void computeSamples();
void saveSamples();
void saveControlPoints();
void loadControlPoints();
void onAddLayer();
tgt::Shader* _shader; ///< Shader for slice rendering
bool _mousePressed; ///< Flag whether the mouse is currently pressed
tgt::ivec2 _mouseDownPosition; ///< Viewport coordinates where mouse button has been pressed
ControlPoint* _currentControlPoint;
tgt::vec4* _currentBounds;
DataHandle _currentImage;
std::vector< std::map< int, std::vector< ControlPoint > > > _controlPoints;
std::map< int, std::vector< float > > _splines;
std::map< int, tgt::vec4 > _vesselBounds;
TissueSegmentation _segmentation;
static const std::string loggerCat_;
};
}
#endif // MANUALTISSUESEGMENTER_H__
#include "tissuesegmentation.h"
namespace campvis {
TissueSegmentation::TissueSegmentation() {
}
TissueSegmentation::~TissueSegmentation() {
}
size_t TissueSegmentation::getNumLayers() const {
return _layers.size();
}
TissueSegmentation::Layer& TissueSegmentation::getLayer(size_t i) {
return _layers[i];
}
const TissueSegmentation::Layer& TissueSegmentation::getLayer(size_t i) const {
return _layers[i];
}
void TissueSegmentation::addLayer(const Layer& l) {
_layers.push_back(l);
}
void TissueSegmentation::setLayer(size_t index, const Layer& l) {
if (_layers.size() < index+1)
_layers.resize(index+1);
_layers[index] = l;
}
void TissueSegmentation::clear() {
_layers.clear();
}
void TissueSegmentation::loadFromStream(std::istream& s) {
clear();
size_t numLayers = 0;
s.read(reinterpret_cast<char*>(&numLayers), sizeof(size_t));
for (size_t l = 0; l < numLayers; ++l) {
size_t numFrames = 0;
s.read(reinterpret_cast<char*>(&numFrames), sizeof(size_t));
Layer layer;
for (size_t i = 0; i < numFrames; ++i) {
size_t numSamples = 0;
s.read(reinterpret_cast<char*>(&numSamples), sizeof(size_t));
Layer::Frame frame;
frame._points.resize(numSamples);
frame._gradients.resize(numSamples);
if (numSamples > 0) {
s.read(reinterpret_cast<char*>(&(frame._points.front())), numSamples * sizeof(tgt::vec2));
s.read(reinterpret_cast<char*>(&(frame._gradients.front())), numSamples * sizeof(tgt::vec2));
}
layer._frames.push_back(frame);
}
_layers.push_back(layer);
}
}
void TissueSegmentation::saveToStream(std::ostream& s) {
size_t numLayers = _layers.size();
s.write(reinterpret_cast<char*>(&numLayers), sizeof(size_t));
for (size_t l = 0; l < numLayers; ++l) {
Layer& layer = _layers[l];
size_t numFrames = layer._frames.size();
s.write(reinterpret_cast<char*>(&numFrames), sizeof(size_t));
for (size_t i = 0; i < numFrames; ++i) {
size_t numSamples = layer._frames[i]._points.size();
s.write(reinterpret_cast<char*>(&numSamples), sizeof(size_t));
if (numSamples > 0) {
s.write(reinterpret_cast<char*>(&layer._frames[i]._points.front()), numSamples * sizeof(tgt::vec2));
s.write(reinterpret_cast<char*>(&layer._frames[i]._gradients.front()), numSamples * sizeof(tgt::vec2));
}
}
}
}
}
\ No newline at end of file
#ifndef TISSUESEGMENTATION_H__
#define TISSUESEGMENTATION_H__
#include "tgt/vector.h"
#include <iostream>
#include <vector>
namespace campvis {
class TissueSegmentation {
public:
// A segmentation layer consists of a vector of Frames, each containing a vector of points.
struct Layer {
struct Frame {
std::vector<tgt::vec2> _points;
std::vector<tgt::vec2> _gradients;
};
std::vector<Frame> _frames;
};
TissueSegmentation();
~TissueSegmentation();
size_t getNumLayers() const;
const Layer& getLayer(size_t i) const;
Layer& getLayer(size_t i);
void addLayer(const Layer& l);
void setLayer(size_t index, const Layer& l);
void clear();
void loadFromStream(std::istream& s);
void saveToStream(std::ostream& s);
// vector of centerlines
std::vector<tgt::vec4> _centerlines;
protected:
// Vector of segmentation layers
std::vector<Layer> _layers;
};
}
#endif // TISSUESEGMENTATION_H__
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