Commit 939f5290 authored by schurade's avatar schurade
Browse files

Merge with e21058799747fe27d7175ff6bc9a04ee84c3ec0d

parents 71a76519 c9ea4f74
......@@ -201,13 +201,6 @@ ADD_CUSTOM_TARGET( vtest
COMMENT "Runs the test in verboseness to see what actually went wrong"
)
#-------------------------------------------------------------------------------------------------------------
# Removes all tests thus forcing them to be recompiled during the next "make"
ADD_CUSTOM_TARGET( cleantest
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/../tools/CMakeModules/RemoveGeneratedTests.cmake
COMMENT "Remove all tests to force them to be recompiled"
)
#-------------------------------------------------------------------------------------------------------------
# Checks if all is well to commit (aka commitCheck, cicheck)
ADD_CUSTOM_TARGET( cicheck
......
......@@ -68,8 +68,6 @@ public:
*/
void reset();
// TODO(ebaum): add more default settings and camera setups here
protected:
/**
......
......@@ -36,7 +36,6 @@
#include "WGEViewer.h"
WGraphicsEngine::WGraphicsEngine( std::string shaderPath ):
WThreadedRunner(),
m_shaderPath( shaderPath )
{
WLogger::getLogger()->addLogMessage( "Initializing Graphics Engine", "GE", LL_DEBUG );
......@@ -61,16 +60,6 @@ std::string WGraphicsEngine::getShaderPath()
return m_shaderPath;
}
void WGraphicsEngine::threadMain()
{
// TODO(ebaum): is this thread actually needed since each viewer runs in separate thread
// while( !m_FinishRequested )
// {
// currently a dummy
// sleep( 1 );
// }
}
boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer(
osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height, WGECamera::ProjectionMode projectionMode )
{
......
......@@ -48,7 +48,7 @@
* engine.
* \ingroup ge
*/
class WGraphicsEngine: public WThreadedRunner
class WGraphicsEngine
{
public:
......@@ -98,11 +98,6 @@ protected:
*/
osg::ref_ptr<WGEScene> m_RootNode;
/**
* Handler for repainting and event handling. Gets executed in separate thread.
*/
virtual void threadMain();
/**
* All registered viewer.
*/
......
......@@ -69,7 +69,7 @@ void WMainWindow::setupGUI( QMainWindow *mainWindow )
mainWindow->setCentralWidget( m_centralwidget );
std::cout << "init main gl" << std::endl;
boost::shared_ptr<WQtGLWidget> widget = boost::shared_ptr<WQtGLWidget>( new WQtGLWidget( mainWindow, WGECamera::PERSPECTIVE ) );
boost::shared_ptr<WQtGLWidget> widget = boost::shared_ptr<WQtGLWidget>( new WQtGLWidget( mainWindow, WGECamera::ORTHOGRAPHIC ) );
m_glWidgets.push_back( widget );
mainWindow->setCentralWidget( widget.get() );
......
......@@ -129,11 +129,7 @@ int WKernel::run()
{
WLogger::getLogger()->addLogMessage( "Starting Kernel", "Kernel", LL_DEBUG );
// TODO(ebaum): add separate graphics thread here
m_graphicsEngine->run();
// run Gui
// TODO(all): clean up this option handler mess
m_gui->run();
// run? data handler stuff?
......@@ -152,9 +148,6 @@ int WKernel::run()
m_FinishRequested = true;
m_moduleContainer->stop();
// finally GE
m_graphicsEngine->wait( true );
// how to get QT return code from its thread?
return 0;
}
......@@ -180,11 +173,6 @@ void WKernel::init()
// initialize Datahandler
m_dataHandler = boost::shared_ptr< WDataHandler >( new WDataHandler() );
// m_gui->createMainWindow();
// TODO(ebaum): the old way
// m_dataHandler->getSignalAddDataset()->connect( boost::bind( &WKernel::slotFinishLoadData, this, _1 ) );
}
bool WKernel::findAppPath()
......
......@@ -109,11 +109,7 @@ void WModule::initialize()
// doing it twice is not allowed
if ( isInitialized() )
{
// TODO(ebaum): is this really needed?
std::ostringstream s;
s << "Could not initialize connectors for Module " << getName() << ". Reason: already initialized.";
throw WModuleConnectorInitFailed( s.str() );
throw WModuleConnectorInitFailed( "Could not initialize connectors for Module " + getName() + ". Reason: already initialized." );
}
connectors();
......
......@@ -260,11 +260,6 @@ public:
createModules();
initModules();
// init connectors
// TODO(ebaum): replace this with the module container, since the module container should manage this
// well actually this also tests the WModule::addConnector method and instantiation of WModuleInputConnector and
// WModuleOutputConnector.
// try initializing twice
TS_ASSERT_THROWS( m1->initialize(), WModuleConnectorInitFailed );
TS_ASSERT( m1->isInitialized() );
......
......@@ -27,6 +27,9 @@
#include <string>
#include <vector>
#include <cmath>
#include "WMMarchingCubes.h"
#include "marchingCubesCaseTables.h"
#include "WTriangleMesh.h"
......@@ -571,6 +574,18 @@ void WMMarchingCubes::renderMesh( const WTriangleMesh& mesh )
// TODO(wiebel): MC move this to a separate module in the future
bool WMMarchingCubes::save( std::string fileName, const WTriangleMesh& triMesh ) const
{
if( triMesh.getNumVertices() == 0 )
{
WLogger::getLogger()->addLogMessage( "Will not write file that contains 0 vertices.", "Marching Cubes", LL_ERROR );
return false;
}
if( triMesh.getNumTriangles() == 0 )
{
WLogger::getLogger()->addLogMessage( "Will not write file that contains 0 triangles.", "Marching Cubes", LL_ERROR );
return false;
}
const char* c_file = fileName.c_str();
std::ofstream dataFile( c_file );
......@@ -580,10 +595,12 @@ bool WMMarchingCubes::save( std::string fileName, const WTriangleMesh& triMesh )
}
else
{
WLogger::getLogger()->addLogMessage( "open file failed"+fileName , "Marching Cubes", LL_ERROR );
WLogger::getLogger()->addLogMessage( "open file failed" + fileName , "Marching Cubes", LL_ERROR );
return false;
}
dataFile.precision( 16 );
WLogger::getLogger()->addLogMessage( "start writing file", "Marching Cubes", LL_DEBUG );
dataFile << ( "# vtk DataFile Version 2.0\n" );
dataFile << ( "generated using OpenWalnut\n" );
......@@ -595,6 +612,11 @@ bool WMMarchingCubes::save( std::string fileName, const WTriangleMesh& triMesh )
for ( unsigned int i = 0; i < triMesh.getNumVertices(); ++i )
{
point = triMesh.getVertex( i );
if( !( std::isfinite( point[0] ) && std::isfinite( point[1] ) && std::isfinite( point[2] ) ) )
{
WLogger::getLogger()->addLogMessage( "Will not write file from data that contains NAN or INF.", "Marching Cubes", LL_ERROR );
return false;
}
dataFile << point[0] << " " << point[1] << " " << point[2] << "\n";
}
......@@ -618,7 +640,7 @@ bool WMMarchingCubes::save( std::string fileName, const WTriangleMesh& triMesh )
dataFile << "0\n";
}
dataFile.close();
std::cout << " saving done" << std::endl;
WLogger::getLogger()->addLogMessage( "saving done", "Marching Cubes", LL_DEBUG );
return true;
}
......@@ -698,7 +720,6 @@ WTriangleMesh WMMarchingCubes::load( std::string fileName )
size_t nbCells;
size_t nbNumbers;
ifs >> cellsMarker >> nbCells >> nbNumbers;
std::cout<< cellsMarker << " " << nbCells << " " << nbNumbers << std::endl;
triMesh.resizeTriangles( nbCells );
unsigned int nbCellVerts;
......@@ -711,14 +732,10 @@ WTriangleMesh WMMarchingCubes::load( std::string fileName )
WLogger::getLogger()->addLogMessage( "Number of cell vertices should be 3 but found " + nbCellVerts, "Marching Cubes", LL_ERROR );
}
// ----- Cell Types ---------
char* cells_typesMarker = new char[30];
size_t nbCellTypes;
ifs >> cells_typesMarker >> nbCellTypes;
std::cout << cells_typesMarker << " .... " << nbCellTypes << std::endl;
unsigned int cellType;
for( unsigned int i = 0; i < nbCellTypes; ++i )
{
......
......@@ -26,10 +26,15 @@
#define WMMARCHINGCUBES_TEST_H
#include <vector>
#include <string>
#include <cxxtest/TestSuite.h>
#include "../WMMarchingCubes.h"
#include "../../../common/WLogger.h"
static bool loggerInitialized = false;
static WLogger logger;
/**
* Test for WMMarchingCubes
......@@ -37,6 +42,7 @@
class WMMarchingCubesTest : public CxxTest::TestSuite
{
public:
/**
* Ensure instatiation does not throw and does initialization right.
*/
......@@ -191,11 +197,65 @@ public:
}
/**
* Test writing of surfaces
* Test rejection of surfaces with zero triangles or vertices for save
*/
void testSave()
void testSaveZero()
{
// TODO(wiebel): MC need to test this for #117
if( !loggerInitialized )
{
std::cout << "Initialize logger." << std::endl;
logger.run();
loggerInitialized = true;
}
WMMarchingCubes mc;
WTriangleMesh triMesh;
std::string fileName = "/tmp/dummerNameDenSichKeinerMerkenBraucht2.vtk";
bool result = mc.save( fileName, triMesh );
TS_ASSERT_EQUALS( result, false ); // should return false as we did not have any vertices or triangles.
}
/**
* Test rejection of surfaces with nan or inf in coordinates for save
*/
void testSaveInfinteNan()
{
if( !loggerInitialized )
{
std::cout << "Initialize logger." << std::endl;
logger.run();
loggerInitialized = true;
}
WMMarchingCubes mc;
WTriangleMesh triMesh;
const unsigned int nbPos = 10;
std::vector< Triangle > triangles( 0 );
Triangle tri;
for( unsigned int i = 0; i < 3; ++i )
{
tri.pointID[i] = i;
}
triangles.push_back( tri );
std::vector< wmath::WPosition > vertices( 0 );
for( unsigned int posId = 0; posId < nbPos; ++posId )
{
double x = posId * posId + 3.4;
double y = posId + 1;
double z = 3. / static_cast< double >( posId ); // provide nan values by dividing with zero
vertices.push_back( wmath::WPosition( x, y, z ) );
}
triMesh.setVertices( vertices );
std::string fileName = "/tmp/dummerNameDenSichKeinerMerkenBraucht.vtk";
mc.save( fileName, triMesh );
bool result = mc.save( fileName, triMesh );
TS_ASSERT_EQUALS( result, false ); // should return false as we did not have all coordinates values finite.
}
/**
......@@ -205,6 +265,66 @@ public:
{
// TODO(wiebel): MC need to test this for #118
}
/**
* Test first saving data and the loading it back.
*/
void testSaveAndLoad()
{
if( !loggerInitialized )
{
std::cout << "Initialize logger." << std::endl;
logger.run();
loggerInitialized = true;
}
WMMarchingCubes mc;
WTriangleMesh triMesh;
const unsigned int nbPos = 10;
const unsigned int nbTris = nbPos - 2;
std::vector< Triangle > triangles( 0 );
for( unsigned int triId = 0; triId < nbTris; ++triId )
{
Triangle tri;
for( unsigned int i = 0; i < 3; ++i )
{
tri.pointID[i] = triId + i;
}
triangles.push_back( tri );
}
triMesh.setTriangles( triangles );
std::vector< wmath::WPosition > vertices( 0 );
for( unsigned int posId = 0; posId < nbPos; ++posId )
{
double x = posId * posId + 3.4;
double y = posId + 1;
double z = 3. / static_cast< double >( posId + 1 );
vertices.push_back( wmath::WPosition( x, y, z ) );
}
triMesh.setVertices( vertices );
std::string fileName = "/tmp/dummerNameDenSichKeinerMerkenBraucht.vtk";
mc.save( fileName, triMesh );
WTriangleMesh result = mc.load( fileName );
TS_ASSERT_EQUALS( triMesh.getNumTriangles(), result.getNumTriangles() );
TS_ASSERT_EQUALS( triMesh.getNumVertices(), result.getNumVertices() );
TS_ASSERT_EQUALS( triMesh.getFastAddVertId(), result.getFastAddVertId() );
TS_ASSERT_EQUALS( triMesh.getFastAddTriangleId(), result.getFastAddTriangleId() );
for( unsigned int i = 0; i < nbPos; ++i)
{
for( unsigned int j = 0; j < 3; ++j)
{
double delta = 1e-5;
// TODO(wiebel): find out why this works only for delta=1e-5
TS_ASSERT_DELTA( triMesh.getVertex( i )[j], result.getVertex( i )[j], delta );
}
}
}
};
#endif // WMMARCHINGCUBES_TEST_H
......@@ -98,7 +98,7 @@ macro( CXXTEST_ADD_TEST _cxxtest_testname _cxxtest_outfname _cxxtest_testsuite )
add_custom_command(
OUTPUT ${_cxxtest_real_outfname}
DEPENDS ${ARGN}
DEPENDS ${_cxxtest_testsuite} ${ARGN}
COMMAND ${_cxxtest_executable}
--error-printer -o ${_cxxtest_real_outfname} ${_cxxtest_testsuite}
)
......
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