Commit f924ccfd authored by Oliver Zettining's avatar Oliver Zettining Committed by Cristina Precup
Browse files

working dir files backup --jakob

parent b293e0b1
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, 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".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#include "itksegmentation.h"
#include "tgt/glmath.h"
#include "tgt/logmanager.h"
#include "modules/itk/core/genericimagerepresentationitk.h"
#include <itkIntTypes.h>
#include <itkGradientMagnitudeImageFilter.h>
#include <itkWatershedImageFilter.h>
#include <itkCastImageFilter.h>
#include <itkConnectedThresholdImageFilter.h>
#include <itkMaskImageFilter.h>
#include "core/datastructures/imagedata.h"
#include "core/datastructures/genericimagerepresentationlocal.h"
// In this class we want to use various ITK segmentation methods.
/**
* Executes the specified segmentation on the data.
* \param MA_baseType base type of input image
* \param MA_returnType base type of ouput image
* \param MA_numChannels number of channels of input image
* \param MA_dimensionality dimensionality of images
* \param MD_filterBody additional stuff to execute between filter definition and execution
*/
#define PERFORM_ITK_SEGMENTATION(MA_baseType, MA_returnType, MA_numChannels, MA_dimensionality, MA_filterType, MD_filterBody) \
{ \
GenericImageRepresentationItk<MA_baseType, MA_numChannels, MA_dimensionality>::ScopedRepresentation itkRep(data, p_sourceImageID.getValue()); \
if (itkRep != 0) { \
typedef GenericImageRepresentationItk<MA_baseType, MA_numChannels, MA_dimensionality>::ItkImageType InputImageType; \
typedef GenericImageRepresentationItk<MA_returnType, MA_numChannels, MA_dimensionality>::ItkImageType OutputImageType; \
itk::MA_filterType<InputImageType, OutputImageType>::Pointer filter = itk::MA_filterType<InputImageType, OutputImageType>::New(); \
typedef itk::Image<itk::IdentifierType, MA_dimensionality> LabelImageType; \
typedef itk::MaskImageFilter< OutputImageType, OutputImageType > MaskFilterType;\
MaskFilterType::Pointer maskFilter = MaskFilterType::New();\
MD_filterBody \
filter->SetInput(itkRep->getItkImage()); \
filter->Update(); \
maskFilter->SetInput(itkRep->getItkImage()); \
maskFilter->SetMaskImage(filter->GetOutput());\
itk::CastImageFilter<OutputImageType, OutputImageType>::Pointer caster = itk::CastImageFilter<OutputImageType, OutputImageType>::New(); \
caster->SetInput(maskFilter->GetOutput()); \
caster->Update(); \
\
GenericImageRepresentationItk<MA_baseType, MA_numChannels, MA_dimensionality>::create(id, caster->GetOutput()); \
} \
}
#define DISPATCH_ITK_SEGMENTATION_BRD(MA_WTP, MA_baseType, MA_returnType, MA_dimensionality, MA_filterType, MD_filterBody) \
tgtAssert(MA_WTP._numChannels == 1, "ItkSegmentation only supports single-channel images.") \
PERFORM_ITK_SEGMENTATION(MA_baseType, MA_returnType, 1, MA_dimensionality, MA_filterType, MD_filterBody)
#define DISPATCH_ITK_SEGMENTATION_D(MA_WTP, MA_dimensionality, MA_filterType, MD_filterBody) \
switch (MA_WTP._baseType) { \
case WeaklyTypedPointer::UINT8: \
DISPATCH_ITK_SEGMENTATION_BRD(MA_WTP, uint8_t, uint8_t, MA_dimensionality, MA_filterType, MD_filterBody) \
break; \
case WeaklyTypedPointer::INT8: \
DISPATCH_ITK_SEGMENTATION_BRD(MA_WTP, int8_t, int8_t, MA_dimensionality, MA_filterType, MD_filterBody) \
break; \
case WeaklyTypedPointer::UINT16: \
DISPATCH_ITK_SEGMENTATION_BRD(MA_WTP, uint16_t, uint16_t, MA_dimensionality, MA_filterType, MD_filterBody) \
break; \
case WeaklyTypedPointer::INT16: \
DISPATCH_ITK_SEGMENTATION_BRD(MA_WTP, int16_t, int16_t, MA_dimensionality, MA_filterType, MD_filterBody) \
break; \
case WeaklyTypedPointer::UINT32: \
DISPATCH_ITK_SEGMENTATION_BRD(MA_WTP, uint32_t, uint32_t, MA_dimensionality, MA_filterType, MD_filterBody) \
break; \
case WeaklyTypedPointer::INT32: \
DISPATCH_ITK_SEGMENTATION_BRD(MA_WTP, int32_t, int32_t, MA_dimensionality, MA_filterType, MD_filterBody) \
break; \
case WeaklyTypedPointer::FLOAT: \
DISPATCH_ITK_SEGMENTATION_BRD(MA_WTP, float, float, MA_dimensionality, MA_filterType, MD_filterBody) \
break; \
default: \
tgtAssert(false, "Should not reach this - wrong base type in WeaklyTypedPointer!"); \
} \
/**
* Dispatches the execution for the ITK filter \a MA_filterType for the image \a MA_localRep.
* \param MA_localRep local representation of the image to apply the filter to
* \param MA_filterType type name if the ITK filter to use (within itk:: namespace)
* \param MD_filterBody additional stuff to execute between filter definition and execution
*/
#define DISPATCH_ITK_SEGMENTATION(MA_localRep, MA_filterType, MD_filterBody) \
do { \
WeaklyTypedPointer wtp = MA_localRep->getWeaklyTypedPointer(); \
switch (MA_localRep->getDimensionality()) { \
case 2: DISPATCH_ITK_SEGMENTATION_D(wtp, 2, MA_filterType, MD_filterBody) break; \
case 3: DISPATCH_ITK_SEGMENTATION_D(wtp, 3, MA_filterType, MD_filterBody) break; \
default: tgtAssert(false, "Unsupported dimensionality!"); break; \
} \
} while (0)
// ================================================================================================
// = Macros defined, let the party begin! =
// ================================================================================================
namespace campvis {
static const GenericOption<std::string> segmentationTypes[1] = {
GenericOption<std::string>("regionGrowing", "Region Growing")
};
const std::string ItkSegmentation::loggerCat_ = "CAMPVis.modules.classification.ItkSegmentation";
ItkSegmentation::ItkSegmentation()
: AbstractProcessor()
, p_sourceImageID("InputVolume", "Input Volume ID", "volume", DataNameProperty::READ)
, p_targetImageID("OutputGradients", "Output Segmented Volume ID", "segmented_volume", DataNameProperty::WRITE)
, p_segmentationType("SegmentationType", "Segmentation Type", segmentationTypes, 1)
, p_seedX("SeedX", "Seed X", 162, 0, 0, 1)
, p_seedY("SeedY", "Seed Y", 169, 0, 0, 1)
, p_seedZ("SeedZ", "Seed Z", 182, 0, 0, 1)
, p_thresMin("ThresMin", "Min Threshold", 70, 0, 255, 1)
, p_thresMax("ThresMax", "Max Threshold", 130, 0, 255, 1)
{
addProperty(p_sourceImageID);
addProperty(p_targetImageID);
addProperty(p_segmentationType, INVALID_RESULT | INVALID_PROPERTIES);
addProperty(p_seedX);
addProperty(p_seedY);
addProperty(p_seedZ);
addProperty(p_thresMin);
addProperty(p_thresMax);
}
ItkSegmentation::~ItkSegmentation() {
}
void ItkSegmentation::updateResult(DataContainer& data) {
ImageRepresentationLocal::ScopedRepresentation input(data, p_sourceImageID.getValue());
if (input != 0 && input->getParent()->getNumChannels() == 1 && (input->getDimensionality() == 2 || input->getDimensionality() == 3)) {
const size_t dim = input->getDimensionality();
p_seedX.setMaxValue(input->getSize().elem[0]);
p_seedY.setMaxValue(input->getSize().elem[1]);
p_seedZ.setMaxValue(input->getSize().elem[2]);
ImageData* id = new ImageData(dim, input->getSize(), 1);
if (p_segmentationType.getOptionValue() == "regionGrowing") {
if (dim == 2) {
#pragma GCC diagnostic ignored "-Warray-bounds"
DISPATCH_ITK_SEGMENTATION(input, ConnectedThresholdImageFilter, \
InputImageType::IndexType index; \
index[0] = p_seedX.getValue(); \
index[1] = p_seedY.getValue(); \
filter->SetLower(p_thresMin.getValue()); \
filter->SetUpper(p_thresMax.getValue()); \
filter->SetReplaceValue(255); \
filter->SetSeed(index); \
);
} else if (dim == 3) {
#pragma GCC diagnostic ignored "-Warray-bounds"
DISPATCH_ITK_SEGMENTATION(input, ConnectedThresholdImageFilter, \
InputImageType::IndexType index; \
index[0] = p_seedX.getValue(); \
index[1] = p_seedY.getValue(); \
index[2] = p_seedZ.getValue(); \
filter->SetLower(p_thresMin.getValue()); \
filter->SetUpper(p_thresMax.getValue()); \
filter->SetReplaceValue(255); \
filter->SetSeed(index); \
);
} else {
tgtAssert(false, "Unsupported dimensionality!");
}
}
data.addData(p_targetImageID.getValue(), id);
}
else {
LDEBUG("No suitable input image found.");
}
validate(INVALID_RESULT);
}
void ItkSegmentation::updateProperties(DataContainer& /*dataContainer*/) {
if (p_segmentationType.getOptionValue() == "regionGrowing") {
p_seedX.setVisible(true);
p_seedY.setVisible(true);
p_seedZ.setVisible(true);
p_thresMin.setVisible(true);
p_thresMax.setVisible(true);
}
validate(AbstractProcessor::INVALID_PROPERTIES);
}
}
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, 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".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#ifndef ITKSEGMENTATION_H__
#define ITKSEGMENTATION_H__
#include <string>
#include "core/pipeline/visualizationprocessor.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/floatingpointproperty.h"
#include "core/properties/numericproperty.h"
#include "core/properties/optionproperty.h"
#include "modules/preprocessing/tools/abstractimagefilter.h"
namespace campvis {
/**
* Performs watershed image filter on input image using ITK.
*/
class ItkSegmentation : public AbstractProcessor {
public:
/**
* Constructs a new ItkSegmentation Processor
**/
ItkSegmentation();
/**
* Destructor
**/
virtual ~ItkSegmentation();
/// \see AbstractProcessor::getName()
virtual const std::string getName() const { return "ItkSegmentation"; };
/// \see AbstractProcessor::getDescription()
virtual const std::string getDescription() const { return "Performs a segmentation on input image using ITK."; };
/// \see AbstractProcessor::getAuthor()
virtual const std::string getAuthor() const { return "Cristina Precup <cristina.precup@tum.de>"; };
/// \see AbstractProcessor::getProcessorState()
virtual ProcessorState getProcessorState() const { return AbstractProcessor::TESTING; };
DataNameProperty p_sourceImageID; ///< ID for input volume
DataNameProperty p_targetImageID; ///< ID for output gradient volume
GenericOptionProperty<std::string> p_segmentationType; ///< Segmentation type
IntProperty p_seedX;
IntProperty p_seedY;
IntProperty p_seedZ;
IntProperty p_thresMin;
IntProperty p_thresMax;
protected:
/// \see AbstractProcessor::updateResult
virtual void updateResult(DataContainer& dataContainer);
/// \see AbstractProcessor::updateProperties
virtual void updateProperties(DataContainer& dataContainer);
static const std::string loggerCat_;
};
}
#endif // ITKSEGMENTATION_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.
//
// ================================================================================================
#include "segmentationdemo.h"
#include "tgt/event/keyevent.h"
#include "core/datastructures/imagedata.h"
#include "core/classification/geometry1dtransferfunction.h"
#include "core/classification/tfgeometry1d.h"
namespace campvis {
SegmentationDemo::SegmentationDemo(DataContainer* dc)
: AutoEvaluationPipeline(dc)
, _lsp()
, _imageReader()
, _ve(&_canvasSize)
, _itkFilter()
, _itkSegmentation()
{
addProcessor(&_lsp);
addProcessor(&_imageReader);
addProcessor(&_ve);
addProcessor(&_itkFilter);
addProcessor(&_itkSegmentation);
addEventListenerToBack(&_ve);
}
SegmentationDemo::~SegmentationDemo() {
}
void SegmentationDemo::init() {
AutoEvaluationPipeline::init();
_ve.p_outputImage.setValue("result");
_renderTargetID.setValue("result");
//_imageReader.setURL(CAMPVIS_SOURCE_DIR "/modules/vis/sampledata/smallHeart.mhd");
//_imageReader.setURL(CAMPVIS_SOURCE_DIR "/../misc/mha_loader_CAMPVis_volumes/prostate_phantom_US/prostate_phantom_fcal_volume_uncompressed.mhd");
_imageReader.setURL(CAMPVIS_SOURCE_DIR "/../misc/mha_loader_CAMPVis_volumes/prostate_phantom_US/prostate_phantom_fcal_volume_uncompressed.mha");
_imageReader.setTargetImageId("reader.output");
_imageReader.setTargetImageIdSharedProperty(&_ve.p_inputVolume);
Geometry1DTransferFunction* dvrTF = new Geometry1DTransferFunction(128, tgt::vec2(0.f, .05f));
dvrTF->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.4f, .5f), tgt::col4(32, 192, 0, 128), tgt::col4(32, 192, 0, 128)));
dvrTF->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.12f, .15f), tgt::col4(85, 0, 0, 128), tgt::col4(255, 0, 0, 128)));
dvrTF->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.19f, .28f), tgt::col4(89, 89, 89, 155), tgt::col4(89, 89, 89, 155)));
dvrTF->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.41f, .51f), tgt::col4(170, 170, 128, 64), tgt::col4(192, 192, 128, 64)));
static_cast<TransferFunctionProperty*>(_ve.getNestedProperty("VolumeRendererProperties::RaycasterProps::TransferFunction"))->replaceTF(dvrTF);
static_cast<FloatProperty*>(_ve.getNestedProperty("VolumeRendererProperties::RaycasterProps::SamplingRate"))->setValue(4.f);
}
void SegmentationDemo::deinit() {
_canvasSize.s_changed.disconnect(this);
AutoEvaluationPipeline::deinit();
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, 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".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#ifndef SegmentationDemo_H__
#define SegmentationDemo_H__
#include "core/pipeline/autoevaluationpipeline.h"
#include "modules/base/processors/lightsourceprovider.h"
#include "modules/io/processors/genericimagereader.h"
#include "modules/vis/processors/volumeexplorer.h"
#include "modules/itk/processors/itkimagefilter.h"
#include "modules/itk/processors/itksegmentation.h"
namespace campvis {
class SegmentationDemo : public AutoEvaluationPipeline {
public:
/**
* Creates a AutoEvaluationPipeline.
*/
SegmentationDemo(DataContainer* dc);
/**
* Virtual Destructor
**/
virtual ~SegmentationDemo();
/// \see AutoEvaluationPipeline::init()
virtual void init();
/// \see AutoEvaluationPipeline::deinit()
virtual void deinit();
/// \see AbstractPipeline::getName()
virtual const std::string getName() const { return getId(); };
/// \see AbstractPipeline::getId()
static const std::string getId() { return "SegmentationDemo"; };
protected:
LightSourceProvider _lsp;
GenericImageReader _imageReader;
VolumeExplorer _ve;
ItkImageFilter _itkFilter;
ItkSegmentation _itkSegmentation;
};
}
#endif // SegmentationDemo_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