Commit 7f850624 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Added concurrent conversion test to ImageRepresentationTest. Added...

Added concurrent conversion test to ImageRepresentationTest. Added ImageData::getNumRepresentations().
parent d7991a39
......@@ -40,7 +40,6 @@
#include "application/gui/mdi/mdidockablewindow.h"
#include "core/init.h"
#include "core/tools/simplejobprocessor.h"
#include "core/tools/stringutils.h"
#include "core/tools/quadrenderer.h"
#include "core/pipeline/abstractpipeline.h"
......
......@@ -37,6 +37,7 @@
#include "core/datastructures/geometrydatafactory.h"
#include "core/classification/tfgeometry1d.h"
#include "core/classification/geometry1dtransferfunction.h"
#include "core/tools/simplejobprocessor.h"
#include "datacontainerinspectorwidget.h"
......@@ -253,7 +254,7 @@ namespace campvis {
if (_quad != 0 && _paintShader != 0) {
// avoid recursive paints.
if (! cgt::GlContextManager::getRef().checkWhetherThisThreadHasAcquiredOpenGlContext()) {
std::thread([this] () {
SimpleJobProc.enqueueJob([this] () {
cgt::GLContextScopedLock lock(this);
paint();
});
......
......@@ -110,6 +110,10 @@ namespace campvis {
return cgt::svec3(x, y, z);
}
size_t ImageData::getNumRepresentations() const {
return _representations.size();
}
void ImageData::clearRepresentations() {
for (tbb::concurrent_vector<const AbstractImageRepresentation*>::iterator it = _representations.begin(); it != _representations.end(); ++it)
delete *it;
......
......@@ -31,6 +31,7 @@
#include "cgt/logmanager.h"
#include "cgt/vector.h"
#include "core/coreapi.h"
#include "core/datastructures/abstractdata.h"
#include "core/datastructures/abstractimagerepresentation.h"
......@@ -169,6 +170,12 @@ namespace campvis {
template<typename T>
const T* getRepresentation(bool performConversion = true) const;
/**
* Returns the number of currently stored representations.
* \return _representations.size();
*/
size_t getNumRepresentations() const;
protected:
template<typename T>
const T* tryPerformConversion() const;
......
......@@ -35,6 +35,7 @@
#include "core/datastructures/imagerepresentationconverter.h"
#include "core/tools/quadrenderer.h"
#include "core/tools/simplejobprocessor.h"
namespace campvis {
......@@ -42,6 +43,7 @@ namespace campvis {
// start sigslot signal manager
sigslot::signal_manager::init();
sigslot::signal_manager::getRef().start();
SimpleJobProcessor::init();
// Init CGT
cgt::init(cgt::InitFeature::ALL, cgt::Debug);
......@@ -81,6 +83,7 @@ namespace campvis {
cgt::deinitGL();
cgt::deinit();
SimpleJobProcessor::deinit();
ImageRepresentationConverter::deinit();
//PipelineFactory::deinit();
}
......
......@@ -25,11 +25,11 @@
#include "gtest/gtest.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagerepresentationdisk.h"
#include "core/datastructures/imagerepresentationlocal.h"
#include "core/datastructures/imagerepresentationgl.h"
#include "core/datastructures/genericimagerepresentationlocal.h"
#include "core/tools/simplejobprocessor.h"
using namespace campvis;
......@@ -150,3 +150,22 @@ TEST_F(ImageRepresentationTest, conversion_disk_gl_local_test) {
TEST_F(ImageRepresentationTest, basetype_conversion_test) {
performBasetypeConversionTest();
}
/**
* Tests multiple concurrent conversions.
* Tests that no redundant representations are created.
*/
TEST_F(ImageRepresentationTest, concurrent_conversion_test) {
tbb::atomic<int> _counter;
_counter = 0;
// hopefully, these jobs are spawned fast enough to simulate concurrent conversions...
const int numInstantiations = 128;
for (int i = 0; i < numInstantiations; ++i)
SimpleJobProc.enqueueJob([&] () { this->convertLocalGl(); ++_counter; });
while (_counter != numInstantiations)
std::this_thread::yield();
EXPECT_EQ(this->_image->getNumRepresentations(), 3U);
}
......@@ -180,8 +180,6 @@ protected:
TEST_F(SigslotTest, stressTest) {
const int NUM_SIGNALS = 1000000;
sigslot::signal_manager::getRef().setSignalHandlingMode(sigslot::signal_manager::DEFAULT);
tbb::parallel_for(tbb::blocked_range<int>(0, NUM_SIGNALS), [&] (const tbb::blocked_range<int>& range) {
for (int i = range.begin(); i < range.end(); ++i) {
sendRandomSignal();
......@@ -191,9 +189,7 @@ TEST_F(SigslotTest, stressTest) {
s_finished.emitSignal();
while (! _isFinished)
std::this_thread::yield();
sigslot::signal_manager::getRef().setSignalHandlingMode(sigslot::signal_manager::FORCE_DIRECT);
EXPECT_EQ(_countSent0, _countReceived0);
EXPECT_EQ(_countSent1, _countReceived1);
EXPECT_EQ(_countSent2, _countReceived2);
......
......@@ -43,7 +43,6 @@
#include "cgt/qt/qtthreadedcanvas.h"
#include "core/init.h"
#include "core/tools/simplejobprocessor.h"
#include "core/tools/quadrenderer.h"
QApplication *app;
......
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