Further work on Similarity Measure: introducing option to choose between SAD/SSD

parent 7bd28140
......@@ -67,35 +67,37 @@ namespace campvis {
}
float GlReduction::reduce(const ImageData* image) {
std::vector<float> GlReduction::reduce(const ImageData* image) {
tgtAssert(image != 0, "Image must not be 0!");
if (_shader == 0) {
LERROR("Could not load Shader for OpenGL reduction. Reduction will not work!");
return 0.f;
return std::vector<float>();
}
if (image == 0) {
LERROR("Empty image received - nothing to reduce!");
return 0.f;
return std::vector<float>();
}
const ImageRepresentationGL* repGl = image->getRepresentation<ImageRepresentationGL>();
if (repGl == 0) {
LERROR("Could not convert input image to OpenGL texture - no reduction possible!");
return 0.f;
return std::vector<float>();
}
return reduce(repGl->getTexture());
}
float GlReduction::reduce(const tgt::Texture* texture) {
std::vector<float> GlReduction::reduce(const tgt::Texture* texture) {
std::vector<float> toReturn;
tgtAssert(texture != 0, "Image must not be 0!");
if (_shader == 0) {
LERROR("Could not load Shader for OpenGL reduction. Reduction will not work!");
return 0.f;
return toReturn;
}
if (texture == 0) {
LERROR("Empty texture received - nothing to reduce!");
return 0.f;
return toReturn;
}
//tgtAssert(texture->getNumChannels() == 1, "Reduction of images with more than one channel currently not implemented! Somebody was too lazy (or stressed - deadline was close) to do that...");
......@@ -168,9 +170,9 @@ namespace campvis {
// read back stuff
GLenum readBackFormat = _tempTextures[_readTex]->getFormat();
size_t channels = _tempTextures[_readTex]->getNumChannels();
readBackBuffer.resize(currentSize.x * currentSize.y * channels);
toReturn.resize(currentSize.x * currentSize.y * channels);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glReadPixels(0, 0, currentSize.x, currentSize.y, readBackFormat, GL_FLOAT, &readBackBuffer.front());
glReadPixels(0, 0, currentSize.x, currentSize.y, readBackFormat, GL_FLOAT, &toReturn.front());
LGL_ERROR;
// clean up...
......@@ -183,7 +185,7 @@ namespace campvis {
delete _tempTextures[1];
LGL_ERROR;
return readBackBuffer.front();
return toReturn;
}
void GlReduction::reduceSizes(tgt::ivec2& currentSize, tgt::vec2& texCoordMultiplier) {
......
......@@ -35,6 +35,7 @@
#include "tgt/vector.h"
#include <string>
#include <vector>
namespace tgt {
class FramebufferObject;
......@@ -58,9 +59,9 @@ namespace campvis {
float reduce(const ImageData* image);
std::vector<float> reduce(const ImageData* image);
float reduce(const tgt::Texture* texture);
std::vector<float> reduce(const tgt::Texture* texture);
private:
......
......@@ -44,6 +44,7 @@ uniform mat4 _registrationInverse;
uniform bool _applyMask;
uniform vec2 _xClampRange;
uniform vec2 _yClampRange;
uniform vec2 _zClampRange;
void main() {
float sad = 0.0;
......
......@@ -51,6 +51,11 @@ namespace campvis {
GenericOption<nlopt::algorithm>("neldermead", "Nelder-Mead Simplex", nlopt::LN_NELDERMEAD)
};
static const GenericOption<std::string> metrics[2] = {
GenericOption<std::string>("SAD", "SAD"),
GenericOption<std::string>("SSD", "SSD")
};
const std::string SimilarityMeasure::loggerCat_ = "CAMPVis.modules.vis.SimilarityMeasure";
SimilarityMeasure::SimilarityMeasure()
......@@ -61,9 +66,10 @@ namespace campvis {
, p_clipY("clipY", "Y Axis Clip Coordinates", tgt::ivec2(0), tgt::ivec2(0), tgt::ivec2(0))
, p_clipZ("clipZ", "Z Axis Clip Coordinates", tgt::ivec2(0), tgt::ivec2(0), tgt::ivec2(0))
, p_applyMask("ApplyMask", "Apply Mask", true)
, p_translation("Translation", "Moving Image Translation", tgt::vec3(0.f), tgt::vec3(-1000.f), tgt::vec3(1000.f), tgt::vec3(1.f), tgt::vec3(1.f))
, p_rotation("Rotation", "Moving Image Rotation", tgt::vec3(0.f), tgt::vec3(-tgt::PIf), tgt::vec3(tgt::PIf), tgt::vec3(.1f), tgt::vec3(2.f))
, p_translation("Translation", "Moving Image Translation", tgt::vec3(0.f), tgt::vec3(-100.f), tgt::vec3(100.f), tgt::vec3(1.f), tgt::vec3(5.f))
, p_rotation("Rotation", "Moving Image Rotation", tgt::vec3(0.f), tgt::vec3(-tgt::PIf), tgt::vec3(tgt::PIf), tgt::vec3(.01f), tgt::vec3(7.f))
, p_viewportSize("ViewportSize", "Viewport Size", tgt::ivec2(1), tgt::ivec2(1), tgt::ivec2(1000), tgt::ivec2(1), AbstractProcessor::VALID)
, p_metric("Metric", "Similarity Metric", metrics, 2)
, p_computeSimilarity("ComputeSimilarity", "Compute Similarity")
, p_optimizer("Optimizer", "Optimizer", optimizers, 3)
, p_performOptimization("PerformOptimization", "Perform Optimization", AbstractProcessor::INVALID_RESULT | PERFORM_OPTIMIZATION)
......@@ -84,6 +90,7 @@ namespace campvis {
addProperty(&p_translation);
addProperty(&p_rotation);
addProperty(&p_metric);
addProperty(&p_computeSimilarity);
addProperty(&p_differenceImageId);
......@@ -268,14 +275,19 @@ namespace campvis {
_fbo->deactivate();
// reduce the juice
float similarity = _glr->reduce(similarityTex);
std::vector<float> similarities = _glr->reduce(similarityTex);
delete similarityTex;
tgt::TextureUnit::setZeroUnit();
LGL_ERROR;
return similarity;
if (similarities.empty())
return 0.f;
if (p_metric.getOptionValue() == "SAD")
return similarities[0];
if (p_metric.getOptionValue() == "SSD")
return similarities[1];
}
double SimilarityMeasure::optimizerFunc(const std::vector<double>& x, std::vector<double>& grad, void* my_func_data) {
......@@ -289,7 +301,7 @@ namespace campvis {
float similarity = mfd->_object->computeSimilarity(mfd->_reference, mfd->_moving, translation, rotation);
GLGC.deleteGarbage();
LDEBUG(translation << rotation << " : " << similarity);
std::cout << translation << rotation << " : " << similarity << "\n";
return similarity;
}
......
......@@ -106,6 +106,7 @@ namespace campvis {
Vec3Property p_translation; ///< Moving image translation
Vec3Property p_rotation; ///< Moving image rotation
GenericOptionProperty<std::string> p_metric;
ButtonProperty p_computeSimilarity;
DataNameProperty p_differenceImageId;
......
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