Commit 109f93d8 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

removed obsolete scr_msk module. Code for Christian's IPCAI '13 submission on...

removed obsolete scr_msk module. Code for Christian's IPCAI '13 submission on orientation-driven ultrasound compounding will be reimplemented from scratch at some point anyway.
parent 756eb3a9
// ================================================================================================
//
// 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 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".
//
// 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 USINTERFACEDATA_H__
#define USINTERFACEDATA_H__
#include "core/datastructures/genericpointerdata.h"
#include <usinterface/include/trackedusfileio.h>
namespace campvis {
typedef GenericPointerData<TrackedUSFileIO> TrackedUsFileIoData;
}
#endif // USINTERFACEDATA_H__
// ================================================================================================
//
// 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 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".
//
// 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.
//
// ================================================================================================
in vec3 ex_TexCoord;
out vec4 out_Color;
#include "tools/texture2d.frag"
#include "tools/transferfunction.frag"
uniform sampler2D _texture;
uniform TextureParameters2D _textureParameters;
uniform sampler1D _transferFunction;
uniform TFParameters1D _transferFunctionParams;
void main() {
if (ex_TexCoord.x < 0.0) {
out_Color = vec4(1.0);
}
else {
float intensity = texture(_texture, ex_TexCoord.xy).a;
out_Color = lookupTF(_transferFunction, _transferFunctionParams, intensity);
// don't write fragment if fully transparent (in particular don't write to depth buffer!)
if (out_Color == 0.0)
discard;
}
}
// ================================================================================================
//
// 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 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".
//
// 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 "uscompounding.h"
namespace campvis {
UsCompounding::UsCompounding(DataContainer* dc)
: AutoEvaluationPipeline(dc)
, p_camera("Camera", "Camera")
, _reader()
, _renderer(&_canvasSize)
, _trackballEH(0)
{
addProcessor(&_reader);
addProcessor(&_renderer);
addProperty(&p_camera);
_trackballEH = new TrackballNavigationEventListener(&p_camera, &_canvasSize);
addEventListenerToBack(_trackballEH);
}
UsCompounding::~UsCompounding() {
delete _trackballEH;
}
void UsCompounding::init() {
AutoEvaluationPipeline::init();
p_camera.addSharedProperty(&_renderer.p_camera);
_reader.p_url.setValue("C:/Users/SchuCh01/Documents/Data/Ultrasound/2012-12-12-Test/9l4sweep/content.xml");
_reader.p_targetImageID.addSharedProperty(&_renderer.p_sourceImageID);
_renderer.s_boundingBoxChanged.connect(this, &UsCompounding::onBoundingBoxChanged);
_renderer.p_targetImageID.setValue("us.frame.output");
_renderTargetID.setValue(_renderer.p_targetImageID.getValue());
}
void UsCompounding::deinit() {
_canvasSize.s_changed.disconnect(this);
AutoEvaluationPipeline::deinit();
}
void UsCompounding::onBoundingBoxChanged(tgt::Bounds b) {
_trackballEH->reinitializeCamera(b);
}
}
\ 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 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".
//
// 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 USCOMPOUNDING_H__
#define USCOMPOUNDING_H__
#include "core/datastructures/imagerepresentationlocal.h"
#include "core/eventhandlers/trackballnavigationeventlistener.h"
#include "core/pipeline/autoevaluationpipeline.h"
#include "core/properties/cameraproperty.h"
#include "modules/scr_msk/processors/trackedusfilereader.h"
#include "modules/scr_msk/processors/trackedussweepframerenderer3d.h"
namespace campvis {
class UsCompounding : public AutoEvaluationPipeline {
public:
/**
* Creates a AutoEvaluationPipeline.
*/
UsCompounding(DataContainer* dc);
/**
* Virtual Destructor
**/
virtual ~UsCompounding();
/// \see AutoEvaluationPipeline::init()
virtual void init();
/// \see AutoEvaluationPipeline::deinit()
virtual void deinit();
/// \see AbstractPipeline::getName()
virtual const std::string getName() const { return getId(); };
static const std::string getId() { return "UsCompounding"; };
protected:
void onBoundingBoxChanged(tgt::Bounds b);
CameraProperty p_camera;
TrackedUsFileReader _reader;
TrackedUsSweepFrameRenderer3D _renderer;
TrackballNavigationEventListener* _trackballEH;
};
}
#endif // USCOMPOUNDING_H__
// ================================================================================================
//
// 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 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".
//
// 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 "trackedusfilereader.h"
#include "tgt/filesystem.h"
#include "modules/scr_msk/datastructures/usinterfacedata.h"
namespace campvis {
const std::string TrackedUsFileReader::loggerCat_ = "CAMPVis.modules.io.TrackedUsFileReader";
TrackedUsFileReader::TrackedUsFileReader()
: AbstractProcessor()
, p_url("url", "Image URL", "")
, p_targetImageID("targetImageName", "Target Image ID", "TrackedUsFileReader.output", DataNameProperty::WRITE)
{
addProperty(&p_url);
addProperty(&p_targetImageID);
}
TrackedUsFileReader::~TrackedUsFileReader() {
}
void TrackedUsFileReader::process(DataContainer& data) {
try {
std::string path = tgt::FileSystem::parentDir(p_url.getValue());
if (! tgt::FileSystem::fileExists(path + "/content.xml")) {
LERROR("No Tracked US data in this directory");
validate(INVALID_RESULT);
return;
}
TrackedUSFileIO* fio = new TrackedUSFileIO();
fio->parse(path.c_str());
if (! fio->open(0)) {
validate(INVALID_RESULT);
return;
}
TrackedUsFileIoData* file = new TrackedUsFileIoData(fio);
data.addData(p_targetImageID.getValue(), file);
}
catch (std::exception& e) {
LERROR("Error : " << e.what());
validate(INVALID_RESULT);
return;
}
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-2013, 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".
//
// 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 TRACKEDUSFILEREADER_H__
#define TRACKEDUSFILEREADER_H__
#include <string>
#include "core/pipeline/abstractprocessor.h"
#include "core/properties/datanameproperty.h"
namespace campvis {
/**
* Reads a MHD image file into the pipeline.
*
* \note Full format specification at http://www.itk.org/Wiki/MetaIO/Documentation
*/
class TrackedUsFileReader : public AbstractProcessor {
public:
/**
* Constructs a new TrackedUsFileReader Processor
**/
TrackedUsFileReader();
/**
* Destructor
**/
virtual ~TrackedUsFileReader();
/**
* Reads the MHD 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 "TrackedUsFileReader"; };
/// \see AbstractProcessor::getDescription()
virtual const std::string getDescription() const { return "Reads an MHD image into the pipeline."; };
/// \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::TESTING; };
StringProperty p_url; ///< URL for file to read
DataNameProperty p_targetImageID; ///< image ID for read image
protected:
static const std::string loggerCat_;
};
}
#endif // TRACKEDUSFILEREADER_H__
// ================================================================================================
//
// 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 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".
//
// 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 "trackedussweepframerenderer3d.h"
#include "tgt/bounds.h"
#include "tgt/logmanager.h"
#include "tgt/shadermanager.h"
#include "tgt/texture.h"
#include "tgt/textureunit.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagerepresentationgl.h"
#include "core/datastructures/renderdata.h"
#include "core/datastructures/meshgeometry.h"
#include "core/datastructures/facegeometry.h"
#include "core/classification/simpletransferfunction.h"
#include "core/tools/quadrenderer.h"
#include "modules/scr_msk/datastructures/usinterfacedata.h"
#include <usinterface/include/trackedusfileio.h>
#include <usinterface/include/trackedusframe.h>
#include <usinterface/include/trackedussweep.h>
#include <usinterface/include/sweepvisitor/sweepsmoothinggaussian.h>
namespace {
struct AverageTopCornersAccessFunc {
vct3 operator() (const TrackedUSSweep::CornerUnion* corners, size_t index) {
return (corners[index]._topLeftCorner + corners[index]._topRightCorner) * 0.5;
}
};
template<class AccessFunc, int KERNEL_SIZE>
struct GaussianSmoothingFunc {
AccessFunc a;
double kernel[KERNEL_SIZE + 1];
double sigma;
GaussianSmoothingFunc() {
sigma = static_cast<double>(KERNEL_SIZE) / 2.5; // rough estimate
for (size_t i = 0; i <= KERNEL_SIZE; ++i) {
double f = static_cast<float>(i);
kernel[i] = exp(-(f*f) / (2.0 * sigma * sigma));
}
}
vct3 operator() (const TrackedUSSweep::CornerUnion* corners, size_t index, size_t start, size_t end) {
vct3 toReturn(0.0);
double norm = 0.0;
for (int offset = -KERNEL_SIZE; offset <= KERNEL_SIZE; ++offset) {
int i = static_cast<int>(index) + offset;
if (i >= start && i < end) {
toReturn += a(corners, i) * kernel[abs(offset)];
norm += kernel[abs(offset)];
}
}
toReturn /= norm;
return toReturn;
}
};
}
namespace campvis {
const std::string TrackedUsSweepFrameRenderer3D::loggerCat_ = "CAMPVis.modules.vis.TrackedUsSweepFrameRenderer3D";
TrackedUsSweepFrameRenderer3D::TrackedUsSweepFrameRenderer3D(IVec2Property* viewportSizeProp)
: VisualizationProcessor(viewportSizeProp)
, p_sourceImageID("sourceFioID", "Input Tracked US File IO", "", DataNameProperty::READ, AbstractProcessor::INVALID_RESULT | AbstractProcessor::INVALID_PROPERTIES)
, p_targetImageID("targetImageID", "Output Image", "", DataNameProperty::WRITE)
, p_camera("Camera", "Camera")
, p_sweepNumber("sweepNumber", "SweepNumber", 0, 0, 0, 1, AbstractProcessor::INVALID_RESULT | AbstractProcessor::INVALID_PROPERTIES)
, p_frameNumber("sliceNumber", "Slice Number", 0, 0, 0)
, p_showConfidenceMap("ShowConfidenceMap", "Show Confidence Map", false)
, p_smoothButton("SmoothButton", "Smooth Tracking")
, p_transferFunction("transferFunction", "Transfer Function", new SimpleTransferFunction(256))
, _shader(0)
, _currentSweep(0)
{
addProperty(&p_sourceImageID);
addProperty(&p_targetImageID);
addProperty(&p_camera);
addProperty(&p_sweepNumber);
addProperty(&p_frameNumber);
addProperty(&p_showConfidenceMap);
addProperty(&p_smoothButton);
addProperty(&p_transferFunction);
}
TrackedUsSweepFrameRenderer3D::~TrackedUsSweepFrameRenderer3D() {
}
void TrackedUsSweepFrameRenderer3D::init() {
VisualizationProcessor::init();
_shader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "modules/scr_msk/glsl/trackedussweepframerenderer3d.frag", "", false);
p_smoothButton.s_clicked.connect(this, &TrackedUsSweepFrameRenderer3D::onSmoothButtonClicked);
}
void TrackedUsSweepFrameRenderer3D::deinit() {
p_smoothButton.s_clicked.disconnect(this);
VisualizationProcessor::deinit();
ShdrMgr.dispose(_shader);
delete _currentSweep;
}
void TrackedUsSweepFrameRenderer3D::process(DataContainer& data) {
ScopedTypedData< TrackedUsFileIoData > fio(data, p_sourceImageID.getValue());
if (fio != 0) {
if (_currentSweep != 0) {
int frameNr = p_frameNumber.getValue();
const tgt::Camera& cam = p_camera.getValue();
// ultra ugly and dirty hacking:
std::vector<tgt::vec3> corners(
reinterpret_cast<const tgt::dvec3*>(_currentSweep->getCorner(frameNr)._corners),
reinterpret_cast<const tgt::dvec3*>(_currentSweep->getCorner(frameNr)._corners) + 4);
std::vector<tgt::vec3> texCoords;
texCoords.push_back(tgt::vec3(0.f, 1.f, 0.f)); // swapped top/bottom texture coordinates to
texCoords.push_back(tgt::vec3(1.f, 1.f, 0.f)); // comply with mirrored y axis in OpenGL
texCoords.push_back(tgt::vec3(1.f, 0.f, 0.f));
texCoords.push_back(tgt::vec3(0.f, 0.f, 0.f));
FaceGeometry slice(corners, texCoords);
MeshGeometry bb = MeshGeometry::createCube(_bounds, tgt::Bounds(tgt::vec3(-1.f), tgt::vec3(-1.f)));
const unsigned char* tmp = (p_showConfidenceMap.getValue() ? _currentSweep->getConfidenceMap(frameNr) : _currentSweep->getTrackedUSFrame(frameNr)->getImageBuffer());
size_t width = (p_showConfidenceMap.getValue() ? _currentSweep->Width() / 4 : _currentSweep->Width());
size_t height = (p_showConfidenceMap.getValue() ? _currentSweep->Height() / 4 : _currentSweep->Height());
if (tmp != 0) {
FramebufferActivationGuard fag(this);
createAndAttachColorTexture();
createAndAttachDepthTexture();
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable(GL_DEPTH_TEST);
_shader->activate();
_shader->setIgnoreUniformLocationError(true);
_shader->setUniform("_viewportSizeRCP", 1.f / tgt::vec2(getEffectiveViewportSize()));
_shader->setUniform("_projectionMatrix", cam.getProjectionMatrix());
_shader->setUniform("_viewMatrix", cam.getViewMatrix());
tgt::TextureUnit inputUnit, tfUnit;
inputUnit.activate();
tgt::Texture tex(
const_cast<unsigned char*>(tmp),
tgt::vec3(width, height, 1),
GL_ALPHA,
GL_ALPHA8,
GL_UNSIGNED_BYTE,
tgt::Texture::LINEAR);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
tex.setType(GL_TEXTURE_2D);
tex.bind();
tex.uploadTexture();
tex.setWrapping(tgt::Texture::CLAMP);
tex.setPixelData(0);
_shader->setUniform("_texture", inputUnit.getUnitNumber());
_shader->setUniform("_textureParameters._size", tgt::vec2(_currentSweep->Width(), _currentSweep->Height()));
_shader->setUniform("_textureParameters._sizeRCP", tgt::vec2(1.f) / tgt::vec2(_currentSweep->Width(), _currentSweep->Height()));
_shader->setUniform("_textureParameters._numChannels", 1);
p_transferFunction.getTF()->bind(_shader, tfUnit);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_shader->setAttributeLocation(0, "in_Position");
_shader->setAttributeLocation(1, "in_TexCoord");
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
bb.render(GL_LINE_LOOP);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
slice.render(GL_POLYGON);
_shader->setIgnoreUniformLocationError(false);
_shader->deactivate();
tgt::TextureUnit::setZeroUnit();
glPopAttrib();
data.addData(p_targetImageID.getValue(), new RenderData(_fbo));
}