Commit 943b5ffb authored by schultezub's avatar schultezub
Browse files

further work on scr_msk module

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@483 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent d3090418
...@@ -51,9 +51,18 @@ namespace campvis { ...@@ -51,9 +51,18 @@ namespace campvis {
void TrackedUsFileReader::process(DataContainer& data) { void TrackedUsFileReader::process(DataContainer& data) {
try { try {
std::string path = tgt::FileSystem::parentDir(p_url.getValue()); 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(); TrackedUSFileIO* fio = new TrackedUSFileIO();
fio->parse(path.c_str()); fio->parse(path.c_str());
fio->open(0); if (! fio->open(0)) {
validate(INVALID_RESULT);
return;
}
TrackedUsFileIoData* file = new TrackedUsFileIoData(fio); TrackedUsFileIoData* file = new TrackedUsFileIoData(fio);
data.addData(p_targetImageID.getValue(), file); data.addData(p_targetImageID.getValue(), file);
......
...@@ -50,6 +50,46 @@ ...@@ -50,6 +50,46 @@
#include <usinterface/include/trackedusframe.h> #include <usinterface/include/trackedusframe.h>
#include <usinterface/include/trackedussweep.h> #include <usinterface/include/trackedussweep.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 { namespace campvis {
const std::string TrackedUsSweepFrameRenderer3D::loggerCat_ = "CAMPVis.modules.vis.TrackedUsSweepFrameRenderer3D"; const std::string TrackedUsSweepFrameRenderer3D::loggerCat_ = "CAMPVis.modules.vis.TrackedUsSweepFrameRenderer3D";
...@@ -60,6 +100,8 @@ namespace campvis { ...@@ -60,6 +100,8 @@ namespace campvis {
, p_camera("Camera", "Camera") , p_camera("Camera", "Camera")
, p_sweepNumber("sweepNumber", "SweepNumber", 0, 0, 0, AbstractProcessor::INVALID_RESULT | AbstractProcessor::INVALID_PROPERTIES) , p_sweepNumber("sweepNumber", "SweepNumber", 0, 0, 0, AbstractProcessor::INVALID_RESULT | AbstractProcessor::INVALID_PROPERTIES)
, p_frameNumber("sliceNumber", "Slice Number", 0, 0, 0) , 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)) , p_transferFunction("transferFunction", "Transfer Function", new SimpleTransferFunction(256))
, _shader(0) , _shader(0)
, _currentSweep(0) , _currentSweep(0)
...@@ -69,7 +111,10 @@ namespace campvis { ...@@ -69,7 +111,10 @@ namespace campvis {
addProperty(&p_camera); addProperty(&p_camera);
addProperty(&p_sweepNumber); addProperty(&p_sweepNumber);
addProperty(&p_frameNumber); addProperty(&p_frameNumber);
addProperty(&p_showConfidenceMap);
addProperty(&p_smoothButton);
addProperty(&p_transferFunction); addProperty(&p_transferFunction);
} }
TrackedUsSweepFrameRenderer3D::~TrackedUsSweepFrameRenderer3D() { TrackedUsSweepFrameRenderer3D::~TrackedUsSweepFrameRenderer3D() {
...@@ -79,9 +124,11 @@ namespace campvis { ...@@ -79,9 +124,11 @@ namespace campvis {
void TrackedUsSweepFrameRenderer3D::init() { void TrackedUsSweepFrameRenderer3D::init() {
VisualizationProcessor::init(); VisualizationProcessor::init();
_shader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "modules/scr_msk/glsl/trackedussweepframerenderer3d.frag", "", false); _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() { void TrackedUsSweepFrameRenderer3D::deinit() {
p_smoothButton.s_clicked.disconnect(this);
VisualizationProcessor::deinit(); VisualizationProcessor::deinit();
ShdrMgr.dispose(_shader); ShdrMgr.dispose(_shader);
delete _currentSweep; delete _currentSweep;
...@@ -105,69 +152,71 @@ namespace campvis { ...@@ -105,69 +152,71 @@ namespace campvis {
reinterpret_cast<const tgt::dvec3*>(_currentSweep->getCorner(frameNr)._corners) + 4); reinterpret_cast<const tgt::dvec3*>(_currentSweep->getCorner(frameNr)._corners) + 4);
std::vector<tgt::vec3> texCoords; std::vector<tgt::vec3> texCoords;
texCoords.push_back(tgt::vec3(0.f, 0.f, 0.f)); 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(1.f, 0.f, 0.f));
texCoords.push_back(tgt::vec3(1.f, 1.f, 0.f)); texCoords.push_back(tgt::vec3(0.f, 0.f, 0.f));
texCoords.push_back(tgt::vec3(0.f, 1.f, 0.f));
FaceGeometry slice(corners, texCoords); FaceGeometry slice(corners, texCoords);
MeshGeometry bb = MeshGeometry::createCube(_bounds, tgt::Bounds(tgt::vec3(-1.f), tgt::vec3(-1.f)));
std::pair<ImageData*, ImageRepresentationRenderTarget*> rt = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue());
const unsigned char* tmp = (p_showConfidenceMap.getValue() ? _currentSweep->getConfidenceMap(frameNr) : _currentSweep->getTrackedUSFrame(frameNr)->getImageBuffer());
glPushAttrib(GL_ALL_ATTRIB_BITS); if (tmp != 0) {
glEnable(GL_DEPTH_TEST); std::pair<ImageData*, ImageRepresentationRenderTarget*> rt = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue());
_shader->activate();
glPushAttrib(GL_ALL_ATTRIB_BITS);
_shader->setIgnoreUniformLocationError(true); glEnable(GL_DEPTH_TEST);
_shader->setUniform("_viewportSizeRCP", 1.f / tgt::vec2(_renderTargetSize.getValue())); _shader->activate();
_shader->setUniform("_projectionMatrix", cam.getProjectionMatrix()); _shader->setIgnoreUniformLocationError(true);
_shader->setUniform("_viewMatrix", cam.getViewMatrix()); _shader->setUniform("_viewportSizeRCP", 1.f / tgt::vec2(_renderTargetSize.getValue()));
_shader->setUniform("_projectionMatrix", cam.getProjectionMatrix());
tgt::TextureUnit inputUnit, tfUnit; _shader->setUniform("_viewMatrix", cam.getViewMatrix());
inputUnit.activate();
tgt::TextureUnit inputUnit, tfUnit;
tgt::Texture tex( inputUnit.activate();
const_cast<unsigned char*>(_currentSweep->getTrackedUSFrame(frameNr)->getImageBuffer()),
tgt::vec3(_currentSweep->Width(), _currentSweep->Height(), 1), tgt::Texture tex(
GL_ALPHA, const_cast<unsigned char*>(tmp),
GL_ALPHA8, tgt::vec3(_currentSweep->Width(), _currentSweep->Height(), 1),
GL_UNSIGNED_BYTE, GL_ALPHA,
tgt::Texture::LINEAR); GL_ALPHA8,
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); GL_UNSIGNED_BYTE,
tex.setType(GL_TEXTURE_2D); tgt::Texture::LINEAR);
tex.bind(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
tex.uploadTexture(); tex.setType(GL_TEXTURE_2D);
tex.setWrapping(tgt::Texture::CLAMP); tex.bind();
tex.setPixelData(0); tex.uploadTexture();
tex.setWrapping(tgt::Texture::CLAMP);
_shader->setUniform("_texture", inputUnit.getUnitNumber()); tex.setPixelData(0);
_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("_texture", inputUnit.getUnitNumber());
_shader->setUniform("_textureParameters._numChannels", 1); _shader->setUniform("_textureParameters._size", tgt::vec2(_currentSweep->Width(), _currentSweep->Height()));
_shader->setUniform("_textureParameters._sizeRCP", tgt::vec2(1.f) / tgt::vec2(_currentSweep->Width(), _currentSweep->Height()));
p_transferFunction.getTF()->bind(_shader, tfUnit); _shader->setUniform("_textureParameters._numChannels", 1);
rt.second->activate(); p_transferFunction.getTF()->bind(_shader, tfUnit);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_shader->setAttributeLocation(0, "in_Position"); rt.second->activate();
_shader->setAttributeLocation(1, "in_TexCoord"); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
slice.render(); _shader->setAttributeLocation(0, "in_Position");
rt.second->deactivate(); _shader->setAttributeLocation(1, "in_TexCoord");
_shader->deactivate(); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
tgt::TextureUnit::setZeroUnit(); bb.render();
glPopAttrib(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
data.addData(p_targetImageID.getValue(), rt.first); slice.render();
p_targetImageID.issueWrite(); rt.second->deactivate();
_shader->setIgnoreUniformLocationError(false);
_shader->deactivate();
tgt::TextureUnit::setZeroUnit();
glPopAttrib();
data.addData(p_targetImageID.getValue(), rt.first);
p_targetImageID.issueWrite();
}
} }
// if (img->getDimensionality() == 3) {
// updateProperties(img->getParent());
// }
// else {
// LERROR("Input image must have dimensionality of 3.");
// }
} }
else { else {
LERROR("No suitable input image found."); LERROR("No suitable input image found.");
...@@ -205,9 +254,15 @@ namespace campvis { ...@@ -205,9 +254,15 @@ namespace campvis {
_currentSweep->CalculateCornersAndPose(); _currentSweep->CalculateCornersAndPose();
_currentSweep->CalculatePrincipalAxes(); _currentSweep->CalculatePrincipalAxes();
tgt::dvec3 llf, urb; if (_currentSweep->getConfidenceMap() == 0) {
_currentSweep->BoundingBox(llf.elem, urb.elem); p_showConfidenceMap.setValue(false);
s_boundingBoxChanged(tgt::Bounds(llf, urb)); p_showConfidenceMap.setVisible(false);
}
else {
p_showConfidenceMap.setVisible(true);
}
updateBoundingBox();
} }
else { else {
_currentSweep = 0; _currentSweep = 0;
...@@ -224,4 +279,19 @@ namespace campvis { ...@@ -224,4 +279,19 @@ namespace campvis {
return _currentSweep; return _currentSweep;
} }
void TrackedUsSweepFrameRenderer3D::onSmoothButtonClicked() {
if (_currentSweep != 0) {
_currentSweep->SmoothCorners(AverageTopCornersAccessFunc(), GaussianSmoothingFunc<AverageTopCornersAccessFunc, 16>());
updateBoundingBox();
invalidate(AbstractProcessor::INVALID_RESULT);
}
}
void TrackedUsSweepFrameRenderer3D::updateBoundingBox() {
tgt::dvec3 llf, urb;
_currentSweep->BoundingBox(llf.elem, urb.elem);
_bounds = tgt::Bounds(llf, urb);
s_boundingBoxChanged(_bounds);
}
} }
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "core/pipeline/visualizationprocessor.h" #include "core/pipeline/visualizationprocessor.h"
#include "core/properties/datanameproperty.h" #include "core/properties/datanameproperty.h"
#include "core/properties/genericproperty.h" #include "core/properties/genericproperty.h"
#include "core/properties/buttonproperty.h"
#include "core/properties/numericproperty.h" #include "core/properties/numericproperty.h"
#include "core/properties/transferfunctionproperty.h" #include "core/properties/transferfunctionproperty.h"
#include "core/properties/cameraproperty.h" #include "core/properties/cameraproperty.h"
...@@ -85,6 +86,8 @@ namespace campvis { ...@@ -85,6 +86,8 @@ namespace campvis {
CameraProperty p_camera; CameraProperty p_camera;
IntProperty p_sweepNumber; ///< Number of the sweep to display IntProperty p_sweepNumber; ///< Number of the sweep to display
IntProperty p_frameNumber; ///< Number of the frame to display IntProperty p_frameNumber; ///< Number of the frame to display
BoolProperty p_showConfidenceMap; ///< Flag whether to show confidence map instead of US image
ButtonProperty p_smoothButton;
TransferFunctionProperty p_transferFunction; ///< Transfer function TransferFunctionProperty p_transferFunction; ///< Transfer function
...@@ -96,12 +99,16 @@ namespace campvis { ...@@ -96,12 +99,16 @@ namespace campvis {
sigslot::signal1<tgt::Bounds> s_boundingBoxChanged; sigslot::signal1<tgt::Bounds> s_boundingBoxChanged;
protected: protected:
void onSmoothButtonClicked();
void updateBoundingBox();
tgt::Shader* _shader; ///< Shader for slice rendering tgt::Shader* _shader; ///< Shader for slice rendering
TrackedUSSweep* _currentSweep; TrackedUSSweep* _currentSweep;
tgt::Bounds _bounds;
static const std::string loggerCat_; static const std::string loggerCat_;
}; };
} }
#endif // TRACKEDUSSWEEPFRAMERENDERER3D_H__ #endif // TRACKEDUSSWEEPFRAMERENDERER3D_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