Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use perceptual diff for more robust image comparison in tests #405

Merged
merged 2 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "async++"]
path = async++
url = https://github.com/Amanieu/asyncplusplus.git
[submodule "perceptualdiff"]
path = perceptualdiff
url = https://github.com/myint/perceptualdiff.git
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ endif()
common_find_package(BBPTestData)
common_find_package(Lunchbox)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/perceptualdiff)
common_find_package(FreeImage)
if(FreeImage_FOUND)
add_subdirectory(perceptualdiff)
endif()

# OSPRay rendering engine
common_find_package(ospray 1.5 SYSTEM)
set(_ospray_unsupported_version 1.6)
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ RUN apt-get update \
libboost-serialization-dev \
libboost-system-dev \
libboost-test-dev \
libfreeimage-dev \
libhdf5-serial-dev \
libmagick++-dev \
libtbb-dev \
Expand Down Expand Up @@ -123,7 +124,7 @@ RUN cksum ${BRAYNS_SRC}/.gitsubprojects \
-DCMAKE_INSTALL_PREFIX=${DIST_PATH} \
-DBUILD_PYTHON_BINDINGS=OFF \
-DCOMMON_DISABLE_WERROR=TRUE \
&& ninja mvd-tool Brayns-install \
&& ninja mvd-tool perceptualdiff Brayns-install Brayns-tests \
&& rm -rf ${DIST_PATH}/include ${DIST_PATH}/cmake ${DIST_PATH}/share

# Final image, containing only Brayns and libraries required to run it
Expand Down
8 changes: 0 additions & 8 deletions doc/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,6 @@ simulations and volumes.
- Proximity: Displays information about element proximity in 3D space. Typically
used to find touches between neurons.

## Epsilon

The --epsilon command line argument defines the precision of the ray-tracer.

```
braynsViewer --epsilon 0.001
```

## Camera types

The --camera command line argument defines the type of camera to be used
Expand Down
1 change: 1 addition & 0 deletions perceptualdiff
Submodule perceptualdiff added at 7ae45f
62 changes: 35 additions & 27 deletions plugins/engines/ospray/ispc/geometry/ExtendedCylinders.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -78,62 +78,70 @@ void ExtendedCylinders_intersect(uniform ExtendedCylinders *uniform geometry,
return;

if (geometry->offset_radius >= 0)
radius = *((uniform float *)(cylinderPtr + geometry->offset_radius));
uniform vec3f v0 = *((uniform vec3f *)(cylinderPtr + geometry->offset_v0));
uniform vec3f v1 = *((uniform vec3f *)(cylinderPtr + geometry->offset_v1));
const vec3f A = v0 - ray.org;
const vec3f B = v1 - ray.org;
const float r = radius;
radius = *((float *uniform)(cylinderPtr + geometry->offset_radius));
uniform vec3f v0 = *((vec3f * uniform)(cylinderPtr + geometry->offset_v0));
uniform vec3f v1 = *((vec3f * uniform)(cylinderPtr + geometry->offset_v1));

const vec3f O = make_vec3f(0.f);
const vec3f V = ray.dir;
const vec3f center = 0.5f * (v0 + v1);
const float approxDist = dot(center - ray.org, ray.dir);
const vec3f closeOrg = ray.org + approxDist * ray.dir;

const vec3f A = v0 - closeOrg;
const vec3f B = v1 - closeOrg;

const vec3f V = ray.dir;
const vec3f AB = B - A;
const vec3f AO = O - A;

const vec3f AOxAB = cross(AO, AB);
const vec3f AOxAB = cross(AB, A);
const vec3f VxAB = cross(V, AB);
const float ab2 = dot(AB, AB);
const float a = dot(VxAB, VxAB);
const float b = 2 * dot(VxAB, AOxAB);
const float c = dot(AOxAB, AOxAB) - (r * r * ab2);
const float c = dot(AOxAB, AOxAB) - (sqr(radius) * ab2);

// clip to near and far cap of cylinder
const float tA = dot(AB, A) * rcp(dot(V, AB));
const float tB = dot(AB, B) * rcp(dot(V, AB));
const float rVAB = rcp(dot(V, AB));
const float tA = dot(AB, A) * rVAB + approxDist;
const float tB = dot(AB, B) * rVAB + approxDist;
const float tAB0 = max(ray.t0, min(tA, tB));
const float tAB1 = min(ray.t, max(tA, tB));

// ------------------------------------------------------------------
// abc formula: t0,1 = (-b +- sqrt(b^2-4*a*c)) / 2a
//
const float radical = b * b - 4.f * a * c;
if (radical < 0.f)
return;

const float srad = sqrt(radical);

const float t_in = (-b - srad) * rcpf(2.f * a);
const float t_out = (-b + srad) * rcpf(2.f * a);
const float t_in = (-b - srad) * rcpf(2.f * a) + approxDist;
const float t_out = (-b + srad) * rcpf(2.f * a) + approxDist;

bool hit = false;

if (t_in >= tAB0 && t_in <= tAB1)
if (t_in >= (tAB0) && t_in <= (tAB1))
{
ray.primID = primID;
ray.geomID = geometry->geometry.geomID;
hit = true;
ray.t = t_in;
const vec3f P = ray.org + ray.t * ray.dir - v0;
const vec3f V = cross(P, AB);
ray.Ng = cross(AB, V);
return;
}
else if (t_out >= tAB0 && t_out <= tAB1)
else if (t_out >= (tAB0) && t_out <= (tAB1))
{
hit = true;
ray.t = t_out;
}

if (hit)
{
ray.primID = primID;
ray.geomID = geometry->geometry.geomID;
ray.t = t_out;
const vec3f P = ray.t * ray.dir - A;
// cannot easily be moved to postIntersect
// we need hit in object-space, in postIntersect it is in world-space
const vec3f P = ray.org + ray.t * ray.dir - v0;
const vec3f V = cross(P, AB);
ray.Ng = cross(AB, V);
return;
ray.u = (ray.t - tA) * rcp(tB - tA);
}
return;
}

static void ExtendedCylinders_postIntersect(uniform Geometry *uniform geometry,
Expand Down
32 changes: 18 additions & 14 deletions plugins/engines/ospray/ispc/geometry/ExtendedSpheres.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,16 @@ void ExtendedSpheres_intersect(uniform ExtendedSpheres *uniform geometry,

uniform float radius = geometry->radius;
if (geometry->offset_radius >= 0)
radius = *((uniform float *)(spherePtr + geometry->offset_radius));

radius =
*((uniform float *uniform)(spherePtr + geometry->offset_radius));
uniform vec3f center =
*((uniform vec3f *)(spherePtr + geometry->offset_center));
const vec3f A = center - ray.org;
*((uniform vec3f * uniform)(spherePtr + geometry->offset_center));
const float approxDist = dot(center - ray.org, ray.dir);
const vec3f closeOrg = ray.org + approxDist * ray.dir;
const vec3f A = center - closeOrg;

const float a = dot(ray.dir, ray.dir);
const float b = -2.f * dot(ray.dir, A);
const float b = 2.f * dot(ray.dir, A);
const float c = dot(A, A) - radius * radius;

const float radical = b * b - 4.f * a * c;
Expand All @@ -174,26 +176,28 @@ void ExtendedSpheres_intersect(uniform ExtendedSpheres *uniform geometry,

const float srad = sqrt(radical);

const float t_in = (-b - srad) * rcpf(2.f * a);
const float t_out = (-b + srad) * rcpf(2.f * a);
const float t_in = (b - srad) * rcpf(2.f * a) + approxDist;
const float t_out = (b + srad) * rcpf(2.f * a) + approxDist;

bool hit = false;
if (t_in > ray.t0 && t_in < ray.t)
{
ray.primID = primID;
ray.geomID = geometry->geometry.geomID;
hit = true;
ray.t = t_in;
ray.Ng = ray.org + ray.t * ray.dir - center;
return;
}
else if (t_out > ray.t0 && t_out < ray.t)
{
hit = true;
ray.t = t_out;
}
if (hit)
{
ray.primID = primID;
ray.geomID = geometry->geometry.geomID;
ray.t = t_out;
// cannot easily be moved to postIntersect
// we need hit in object space, in postIntersect it is in world-space
ray.Ng = ray.org + ray.t * ray.dir - center;
return;
}
return;
}

export void *uniform ExtendedSpheres_create(void *uniform cppEquivalent)
Expand Down
9 changes: 8 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
#
# This file is part of Brayns <https://github.com/BlueBrain/Brayns>

set(TEST_LIBRARIES ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} brayns)
set(TEST_LIBRARIES ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} brayns)

if(TARGET pdiff)
list(APPEND TEST_LIBRARIES pdiff ${Magick++_LIBRARIES})
else()
list(APPEND EXCLUDE_FROM_TESTS braynsTestData.cpp snapshot.cpp)
endif()

configure_file(paths.h.in ${PROJECT_BINARY_DIR}/tests/paths.h)
if(TARGET BBPTestData AND TARGET Lunchbox)
Expand Down
36 changes: 1 addition & 35 deletions tests/brayns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(defaults)
BOOST_CHECK(renderParams.getCameraType() == brayns::CameraType::default_);
BOOST_CHECK(renderParams.getStereoMode() == brayns::StereoMode::none);
BOOST_CHECK(renderParams.getRenderer() == brayns::RendererType::default_);
BOOST_CHECK_EQUAL(renderParams.getRenderers().size(), 7);
BOOST_CHECK_EQUAL(renderParams.getRenderers().size(), 8);
BOOST_CHECK(!renderParams.getShadows());
BOOST_CHECK(!renderParams.getSoftShadows());
BOOST_CHECK_EQUAL(renderParams.getAmbientOcclusionStrength(), 0.f);
Expand Down Expand Up @@ -141,37 +141,3 @@ BOOST_AUTO_TEST_CASE(defaults)
BOOST_CHECK_EQUAL(scene.getBounds(), defaultBoundingBox);
BOOST_CHECK(geomParams.getMemoryMode() == brayns::MemoryMode::shared);
}

BOOST_AUTO_TEST_CASE(render_two_frames_and_compare_they_are_same)
{
auto& testSuite = boost::unit_test::framework::master_test_suite();
const char* app = testSuite.argv[0];
const char* argv[] = {app, "demo", "--synchronous-mode", "on"};
const int argc = sizeof(argv) / sizeof(char*);
brayns::Brayns brayns(argc, argv);

auto& fb = brayns.getEngine().getFrameBuffer();
const auto& size = fb.getSize();
fb.setAccumulation(false);
fb.resize(size);

uint16_t depth = fb.getColorDepth();
const size_t bytes = size[0] * size[1] * depth;
std::vector<uint8_t> oldBuffer(bytes, 0);

fb.clear();
brayns.render();

fb.map();
memcpy(oldBuffer.data(), fb.getColorBuffer(), bytes);
fb.unmap();

fb.clear();
brayns.render();

fb.map();
BOOST_CHECK_EQUAL_COLLECTIONS(oldBuffer.begin(), oldBuffer.end(),
fb.getColorBuffer(),
fb.getColorBuffer() + bytes);
fb.unmap();
}
Loading