From cb56d97fcfc33173b990ce9c7fe16af4f9062420 Mon Sep 17 00:00:00 2001 From: johannes hanika Date: Mon, 3 Nov 2014 16:10:26 +0100 Subject: [PATCH] hslt: verification.cpp: better validation of edge data structures --- src/libbidir/verification.cpp | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/libbidir/verification.cpp b/src/libbidir/verification.cpp index c8d910c2..1120d444 100644 --- a/src/libbidir/verification.cpp +++ b/src/libbidir/verification.cpp @@ -62,6 +62,25 @@ static bool validateValue(const std::string name, Float value, Float cached, std return valid; } +static bool validateValue(const std::string name, Vector value, Vector cached, std::ostream &os) { + bool valid = true; + + Float err = (cached-value).length(); + Float mag = std::max(cached.length(), value.length()); + + if(std::isnan(err)) + valid = false; + else if(mag < MTS_BD_MAXERR && err > MTS_BD_MAXERR) // absolute error threshold + valid = false; + else if(mag > MTS_BD_MAXERR && err/mag > MTS_BD_MAXERR) // relative error threshold + valid = false; + + if(!valid) + os << " " << name << " mismatch: cached=" << cached.toString() << ", computed=" << value.toString() << endl; + + return valid; +} + bool PathVertex::verify(const Scene *scene, const PathVertex *pred, const PathVertex *succ, ETransportMode mode, std::ostream &os) const { if (mode == ERadiance) @@ -151,10 +170,14 @@ bool PathEdge::verify(const Scene *scene, const PathVertex *pred, bool valid = true; if (!pred->isSupernode() && !succ->isSupernode()) { - Float refLength = (pred->getPosition()-succ->getPosition()).length(); - valid &= validateValue("length", refLength, length, os); + Vector refDireciton = succ->getPosition()-pred->getPosition(); + Float refLength = refDireciton.length(); + refDireciton /= refLength; + valid &= validateValue("length", refLength, length, os); + valid &= validateValue("d", refDireciton, d, os); } + valid &= validateValue("weight[ERadiance]", weightE, weight[ERadiance], os); valid &= validateValue("weight[EImportance]", weightL, weight[EImportance], os); valid &= validateValue("pdf[ERadiance]", pdfE, pdf[ERadiance], os); @@ -172,7 +195,14 @@ bool Path::verify(const Scene *scene, ETransportMode mode, std::ostream &os) con oss << "Vertex " << i << ":" << endl; if (!m_vertices[i]->verify(scene, pred, succ, mode, oss)) valid = false; + if(i > 0 && i < m_edges.size()) + { + oss << "Edge " << i << ":" << endl; + if(!m_edges[i-1]->verify(scene, pred, m_vertices[i], mode, oss)) + valid = false; + } } + if (!valid) { os << "Detected an inconsistency in the path " << endl; os << toString() << endl;