Commit 934c0cfb authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[MERGE]

parents 767467ae f863e5aa
...@@ -24,6 +24,9 @@ syntax: regexp ...@@ -24,6 +24,9 @@ syntax: regexp
^src/tags ^src/tags
^src/cscope.out ^src/cscope.out
# files geneterated by build system
^src/version.h
# local vim rc # local vim rc
^lvimrc ^lvimrc
......
See the "doc" directory for more information. ------------------------------------------------------
See the "doc" directory for more information.
------------------------------------------------------ ------------------------------------------------------
...@@ -12,4 +14,5 @@ Directory Structure: ...@@ -12,4 +14,5 @@ Directory Structure:
-src -src
The sources, i.e. code, icons, ... The sources, i.e. code, icons, ...
-tools -tools
Tools used during development and building (e.g. style checker) Tools used during development and building
(e.g. style checker)
This directory is intended to serve as the place where one can compile OpenWalnut. This directory is intended to serve as the place where one can compile OpenWalnut.
This .README file is in the build directory so that the directory will be recognized and created by mercurial. Only remove it if you know what you are doing or if the behavior of mercurial concerning empty directories has changed.
\ No newline at end of file
...@@ -8,6 +8,13 @@ ...@@ -8,6 +8,13 @@
# default=HUD # default=HUD
#whiteList =Isosurface,Bounding Box, Direct Volume Rendering,Distance Map Isosurface,Gauss Filtering,HUD,Vector Plot,Write NIfTI # A list of modules that will be provided through the GUI. If the list is empty all available modules are provided. #whiteList =Isosurface,Bounding Box, Direct Volume Rendering,Distance Map Isosurface,Gauss Filtering,HUD,Vector Plot,Write NIfTI # A list of modules that will be provided through the GUI. If the list is empty all available modules are provided.
## Specify a ";" separated list of additional paths for modules. The order of appearance is the order of loading. The following additional rules apply here:
## 1. if the directory contains one or more libOWmodule_XYZ it/they get loaded
## 2. if the directory does not contain any libOWmodule_XYZ, the subdirectories get searched.
## 3. DO NOT use this string thing --> " <-- to enclose the string!
## NOTE: you do not need to specify the global module path as it gets search automatically
#path = /home/user/otherModules;/usr/local/OpenWalnut/niceModule/
[qt4gui] [qt4gui]
#################################################################### ####################################################################
# Views # Views
......
...@@ -14,6 +14,13 @@ allowOnlyOneFiberDataSet = yes # This will prevent you from accidently loading m ...@@ -14,6 +14,13 @@ allowOnlyOneFiberDataSet = yes # This will prevent you from accidently loading m
## If the list is empty all available modules are provided. ## If the list is empty all available modules are provided.
whiteList = Isosurface,Bounding Box,Isosurface Raytracer,Distance Map Isosurface,Gauss Filtering,HUD,Vector Plot,Write NIfTI,Mesh Reader,Triangle Mesh Renderer,Arbitrary Rois,LIC,Voxelizer,Superquadric Glyphs whiteList = Isosurface,Bounding Box,Isosurface Raytracer,Distance Map Isosurface,Gauss Filtering,HUD,Vector Plot,Write NIfTI,Mesh Reader,Triangle Mesh Renderer,Arbitrary Rois,LIC,Voxelizer,Superquadric Glyphs
## Specify a ";" separated list of additional paths for modules. The order of appearance is the order of loading. The following additional rules apply here:
## 1. if the directory contains one or more libOWmodule_XYZ it/they get loaded
## 2. if the directory does not contain any libOWmodule_XYZ, the subdirectories get searched.
## 3. DO NOT use this string thing --> " <-- to enclose the string!
## NOTE: you do not need to specify the global module path as it gets search automatically
#path = /home/user/otherModules;/usr/local/OpenWalnut/niceModule/
[qt4gui] [qt4gui]
#################################################################### ####################################################################
# Views # Views
......
#!/bin/sh
# get path of this script
BINDIR=`dirname "$0"`
# assume that this script is in the bin dir
# go there to ensure walnuts working directory is set correctly
cd "$BINDIR"
#run walnut
echo "OpenWalnut built from: $(cat ./revision)"
./walnut-bin $@
...@@ -12,7 +12,6 @@ echo run $@ > $PARAM_FILENAME ...@@ -12,7 +12,6 @@ echo run $@ > $PARAM_FILENAME
cd "$BINDIR" cd "$BINDIR"
# run walnut # run walnut
echo "OpenWalnut built from: $(cat ./revision)" gdb ./walnut -command=$PARAM_FILENAME
gdb ./walnut-bin -command=$PARAM_FILENAME
rm $PARAM_FILENAME rm $PARAM_FILENAME
...@@ -12,6 +12,5 @@ PARAMS="$*" ...@@ -12,6 +12,5 @@ PARAMS="$*"
echo "Parameters: $PARAMS" echo "Parameters: $PARAMS"
# run walnut # run walnut
echo "OpenWalnut built from: $(cat ./revision)" kdbg -a "$PARAMS" walnut
kdbg -a "$PARAMS" walnut-bin
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT( OpenWalnut ) PROJECT( OpenWalnut )
# append search path for FindModules: # append search path for FindModules:
#------------------------------------ #------------------------------------
LIST( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../tools/CMakeModules ) LIST( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../tools/CMakeModules )
...@@ -13,6 +12,7 @@ INCLUDE( ${PROJECT_SOURCE_DIR}/../tools/CMakeModules/Utils.cmake ) ...@@ -13,6 +12,7 @@ INCLUDE( ${PROJECT_SOURCE_DIR}/../tools/CMakeModules/Utils.cmake )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin ) SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib ) SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib )
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib ) SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib )
SET( SHARED_FILES_RELATIVE "../share/${CMAKE_PROJECT_NAME}" CACHE INTERNAL "Relative path to bin/ denoting the destination for shaders and cfg files." ) # this path us the relative path to bin/ used for all shared files like shaders and config file
# CMAKE automatism to select static vs. shared building: # CMAKE automatism to select static vs. shared building:
#------------------------------------------------------- #-------------------------------------------------------
...@@ -139,23 +139,34 @@ ADD_SUBDIRECTORY( gui ) ...@@ -139,23 +139,34 @@ ADD_SUBDIRECTORY( gui )
ADD_SUBDIRECTORY( kernel ) ADD_SUBDIRECTORY( kernel )
ADD_SUBDIRECTORY( common ) ADD_SUBDIRECTORY( common )
ADD_SUBDIRECTORY( modules ) ADD_SUBDIRECTORY( modules )
ADD_EXECUTABLE( walnut-bin OpenWalnut.cpp )
TARGET_LINK_LIBRARIES( walnut-bin kernel dataHandler gui guiqt4 common ge ${Boost_LIBRARIES} ) #-------------------------------------------------------------------------------------------------------------
# Writes information about the revision of the current code to the file version.h which then gets included by OpenWalnut.cpp
add_custom_command( OUTPUT ${PROJECT_SOURCE_DIR}/version.h
MAIN_DEPENDENCY ${PROJECT_SOURCE_DIR}/../.hg/dirstate
COMMAND hg parents --template '\#define W_VERSION \"{node|short} {rev} {branches} {tags}\"' > ${PROJECT_SOURCE_DIR}/version.h
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Creating version.h"
)
# finally, build walnut
ADD_EXECUTABLE( walnut OpenWalnut.cpp version.h )
TARGET_LINK_LIBRARIES( walnut OWkernel OWdataHandler OWgui OWguiqt4 OWcommon OWge ${Boost_LIBRARIES} )
#---------- Shaders ------------- #---------- Shaders -------------
option( OW_COPY_SHADERS "This enables copying shaders with every make call." ON ) option( OW_COPY_SHADERS "This enables copying shaders with every make call." ON )
if( OW_COPY_SHADERS ) if( OW_COPY_SHADERS )
add_custom_target( shaderDirectoryConfiguration add_custom_target( shaderDirectoryConfiguration
ALL ALL
COMMAND ${CMAKE_COMMAND} -D OW_SOURCE_DIR:STRING=${PROJECT_SOURCE_DIR} -P ${PROJECT_SOURCE_DIR}/../tools/CMakeModules/UpdateShaders.cmake COMMAND ${CMAKE_COMMAND} -D OW_SOURCE_DIR:STRING=${PROJECT_SOURCE_DIR} -D SHARED_FILES_RELATIVE:PATH=${SHARED_FILES_RELATIVE} -P ${PROJECT_SOURCE_DIR}/../tools/CMakeModules/UpdateShaders.cmake
COMMENT "Put all shaders to the right place or update them if they are already there." COMMENT "Put all global shaders to the right place or update them if they are already there."
) )
endif( OW_COPY_SHADERS ) endif( OW_COPY_SHADERS )
#---------- fonts ------------- #---------- fonts -------------
add_custom_target( fontsDirectoryConfiguration add_custom_target( fontsDirectoryConfiguration
ALL ALL
COMMAND ${CMAKE_COMMAND} -D OW_SOURCE_DIR:STRING=${PROJECT_SOURCE_DIR} -P ${PROJECT_SOURCE_DIR}/../tools/CMakeModules/CopyFonts.cmake COMMAND ${CMAKE_COMMAND} -D OW_SOURCE_DIR:STRING=${PROJECT_SOURCE_DIR} -D SHARED_FILES_RELATIVE:PATH=${SHARED_FILES_RELATIVE} -P ${PROJECT_SOURCE_DIR}/../tools/CMakeModules/CopyFonts.cmake
COMMENT "Put all fonts to the right place." COMMENT "Put all fonts to the right place."
) )
...@@ -175,9 +186,9 @@ ELSE() ...@@ -175,9 +186,9 @@ ELSE()
ENDIF() ENDIF()
#---------- walnut.cfg file ------------- #---------- walnut.cfg file -------------
IF( NOT EXISTS ${PROJECT_BINARY_DIR}/bin/walnut.cfg ) IF( NOT EXISTS ${PROJECT_BINARY_DIR}/bin/${SHARED_FILES_RELATIVE}/walnut.cfg )
CONFIGURE_FILE( ${PROJECT_SOURCE_DIR}/../doc/user/walnut.cfg.mpi ${PROJECT_BINARY_DIR}/bin/walnut.cfg COPYONLY ) CONFIGURE_FILE( ${PROJECT_SOURCE_DIR}/../doc/user/walnut.cfg.mpi ${PROJECT_BINARY_DIR}/bin/${SHARED_FILES_RELATIVE}/walnut.cfg COPYONLY )
MESSAGE( STATUS "Copied ${PROJECT_SOURCE_DIR}/../doc/user/walnut.cfg.mpi to ${PROJECT_BINARY_DIR}/bin/walnut.cfg" ) MESSAGE( STATUS "Copied ${PROJECT_SOURCE_DIR}/../doc/user/walnut.cfg.mpi to ${PROJECT_BINARY_DIR}/bin/${SHARED_FILES_RELATIVE}/walnut.cfg" )
ENDIF() ENDIF()
# Special targets: # Special targets:
...@@ -221,6 +232,18 @@ ADD_CUSTOM_COMMAND( OUTPUT cscope ...@@ -221,6 +232,18 @@ ADD_CUSTOM_COMMAND( OUTPUT cscope
# The command "make tags" creates ctags and cscope tag files # The command "make tags" creates ctags and cscope tag files
ADD_CUSTOM_TARGET( tags DEPENDS ctags DEPENDS cscope ) ADD_CUSTOM_TARGET( tags DEPENDS ctags DEPENDS cscope )
#-------------------------------------------------------------------------------------------------------------
# Determines the number of cores available on this machine
SET( NUM_CORES_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../tools/numCores )
SET( NUM_CORES_BINARY_DIR ${PROJECT_BINARY_DIR}/numCores )
SET( NUM_CORES_BINARY ${NUM_CORES_BINARY_DIR}/numCores )
ADD_CUSTOM_TARGET( numCores
COMMAND ${CMAKE_COMMAND} -E make_directory ${NUM_CORES_BINARY_DIR}
COMMAND cd ${NUM_CORES_BINARY_DIR} && ${CMAKE_COMMAND} ${NUM_CORES_SOURCE_DIR} > /dev/null
COMMAND $(MAKE) -C ${NUM_CORES_BINARY_DIR} > /dev/null
COMMENT "Determines the number of cores available on this machine"
)
#------------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------------
# Checks style guide lines via the BrainLint tool against all source code files # Checks style guide lines via the BrainLint tool against all source code files
# The output is colored when variable CMAKE_COLOR_MAKEFILE is set to ON, # The output is colored when variable CMAKE_COLOR_MAKEFILE is set to ON,
...@@ -241,6 +264,7 @@ FOREACH( dirname ${EXCLUDE_DIRS} ) ...@@ -241,6 +264,7 @@ FOREACH( dirname ${EXCLUDE_DIRS} )
LIST( REMOVE_ITEM STYLE_CPP ${fname} ) LIST( REMOVE_ITEM STYLE_CPP ${fname} )
ENDFOREACH( fname ) ENDFOREACH( fname )
ENDFOREACH( dirname ) ENDFOREACH( dirname )
LIST( REMOVE_ITEM STYLE_H ${PROJECT_SOURCE_DIR}/version.h )
IF( CMAKE_COLOR_MAKEFILE ) IF( CMAKE_COLOR_MAKEFILE )
SET( STYLECHECK_OPTIONS "--color" ) SET( STYLECHECK_OPTIONS "--color" )
...@@ -249,28 +273,23 @@ ELSE() ...@@ -249,28 +273,23 @@ ELSE()
ENDIF() ENDIF()
IF( CMAKE_HOST_WIN32 ) IF( CMAKE_HOST_WIN32 )
SET( XARGS_OPTIONS "-n 128" ) SET( XARGS_OPTIONS "-n 128" )
ELSEIF( CMAKE_HOST_UNIX )
SET( XARGS_OPTIONS -P \$\$\(${NUM_CORES_BINARY}\) -n 64 )
ELSE() ELSE()
SET( XARGS_OPTIONS "" ) SET( XARGS_OPTIONS "" )
ENDIF() ENDIF()
FILE( WRITE ${PROJECT_BINARY_DIR}/brainlintlist "" ) FILE( WRITE ${PROJECT_BINARY_DIR}/brainlintlist "" )
FOREACH( fname ${STYLE_CPP} ${STYLE_H} ) FOREACH( fname ${STYLE_CPP} ${STYLE_H} )
FILE( APPEND ${PROJECT_BINARY_DIR}/brainlintlist "${fname}\n" ) FILE( APPEND ${PROJECT_BINARY_DIR}/brainlintlist "${fname}\n" )
ENDFOREACH() ENDFOREACH()
ADD_CUSTOM_TARGET( stylecheck ADD_CUSTOM_TARGET( stylecheck
COMMAND cat ${PROJECT_BINARY_DIR}/brainlintlist | xargs ${XARGS_OPTIONS} ${PROJECT_SOURCE_DIR}/../tools/brainlint.py ${STYLECHECK_OPTIONS} COMMAND cat ${PROJECT_BINARY_DIR}/brainlintlist | xargs ${XARGS_OPTIONS} ${PROJECT_SOURCE_DIR}/../tools/brainlint.py ${STYLECHECK_OPTIONS} 2>&1 | grep -iv 'Total errors found: 0$$' | cat
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} DEPENDS numCores
COMMENT "Check if code complies to CodingStandard" WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
) COMMENT "Check if code complies to CodingStandard"
#-------------------------------------------------------------------------------------------------------------
# Writes information about the revision of the current code to a file
ADD_CUSTOM_TARGET( identify
ALL
COMMAND hg identify --cwd ${PROJECT_SOURCE_DIR} -n -i -b -t > ${PROJECT_BINARY_DIR}/bin/revision
COMMENT "Write information about the revision of the current code to a file"
) )
#------------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------------
...@@ -287,43 +306,14 @@ ADD_CUSTOM_TARGET( cicheck ...@@ -287,43 +306,14 @@ ADD_CUSTOM_TARGET( cicheck
COMMENT "Checks if all is well to commit" COMMENT "Checks if all is well to commit"
) )
#-------------------------------------------------------------------------------------------------------------
# Copies fixtures used for tests to the binary directory (where they are expected).
IF( NOT CMAKE_GENERATOR MATCHES "Visual Studio" )
ADD_CUSTOM_TARGET( fixtures
ALL
COMMAND cp -rf ${PROJECT_SOURCE_DIR}/dataHandler/test/fixtures ${PROJECT_BINARY_DIR}/dataHandler/
COMMAND cp -rf ${PROJECT_SOURCE_DIR}/dataHandler/io/test/fixtures ${PROJECT_BINARY_DIR}/dataHandler/io
# TODO(wiebel): we need to find a way to do this automatically
COMMAND cp -rf ${PROJECT_SOURCE_DIR}/modules/marchingCubes/test/fixtures ${PROJECT_BINARY_DIR}/modules/marchingCubes
COMMENT "Copy fixtures to the right place."
)
ELSE()
ADD_CUSTOM_TARGET( fixtures
ALL
COMMAND ${CMAKE_COMMAND} -D OW_SOURCE_DIR:STRING=${PROJECT_SOURCE_DIR} -P ${PROJECT_SOURCE_DIR}/../tools/CMakeModules/FixturesWin.cmake
COMMENT "Copy fixtures to the right place."
)
ENDIF()
#------------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------------
# Makes many special make targets in combination. Default number of cores is 1. # Makes many special make targets in combination. Default number of cores is 1.
SET( NUM_CORES_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../tools/numCores )
SET( NUM_CORES_BINARY_DIR ${PROJECT_BINARY_DIR}/numCores )
SET( NUM_CORES_BINARY ${NUM_CORES_BINARY_DIR}/numCores )
ADD_CUSTOM_TARGET( many ADD_CUSTOM_TARGET( many
COMMAND ${CMAKE_COMMAND} ${PROJECT_SOURCE_DIR} COMMAND echo Using \$\$\(${NUM_CORES_BINARY}\) cores.\; $(MAKE) all -j\$\$\(${NUM_CORES_BINARY}\)
COMMAND ${CMAKE_COMMAND} -E make_directory ${NUM_CORES_BINARY_DIR}
COMMAND cd ${NUM_CORES_BINARY_DIR} && ${CMAKE_COMMAND} ${NUM_CORES_SOURCE_DIR} > /dev/null
COMMAND $(MAKE) -C ${NUM_CORES_BINARY_DIR} > /dev/null
COMMAND if [ -e ${NUM_CORES_BINARY} ]\; then echo Using \$\$\(${NUM_CORES_BINARY}\) cores.\; $(MAKE) all -j\$\$\(${NUM_CORES_BINARY}\)\; else echo WARNING: No binary for numCores found: ${NUM_CORES_BINARY}. Using 1 core.\; $(MAKE) all -j1\; fi
COMMAND $(MAKE) test COMMAND $(MAKE) test
COMMAND $(MAKE) stylecheck COMMAND $(MAKE) stylecheck
COMMAND $(MAKE) doc COMMAND $(MAKE) doc
DEPENDS numCores
COMMENT "Make many special make targets in combination." COMMENT "Make many special make targets in combination."
) )
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "gui/qt4/WQt4Gui.h" #include "gui/qt4/WQt4Gui.h"
#include "version.h" // this header gets created by our build system.
/** /**
* \mainpage OpenWalnut Inline Documentation * \mainpage OpenWalnut Inline Documentation
* \par * \par
...@@ -43,7 +45,8 @@ ...@@ -43,7 +45,8 @@
*/ */
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
std::cout << "OpenWalnut ( http://www.openwalnut.org )\n" std::cout << "OpenWalnut ( http://www.openwalnut.org )" << std::endl <<
"Build from: " << W_VERSION << std::endl << std::endl <<
"Copyright (C) 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS\n" "Copyright (C) 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS\n"
"For more information see http://www.openwalnut.org/copying\n" "For more information see http://www.openwalnut.org/copying\n"
"This program comes with ABSOLUTELY NO WARRANTY.\n" "This program comes with ABSOLUTELY NO WARRANTY.\n"
......
...@@ -7,14 +7,19 @@ ADD_SUBDIRECTORY( datastructures ) ...@@ -7,14 +7,19 @@ ADD_SUBDIRECTORY( datastructures )
ADD_SUBDIRECTORY( constraints ) ADD_SUBDIRECTORY( constraints )
ADD_SUBDIRECTORY( math ) ADD_SUBDIRECTORY( math )
ADD_LIBRARY( common ${COMMON_SRC} ${COMMON_DATASTRUCTURES_SRC} ${COMMON_EXCEPTIONS_SRC} ${MATH_SRC} ${FIBERSIMILARITY_SRC} ) ADD_LIBRARY( OWcommon ${COMMON_SRC} ${COMMON_DATASTRUCTURES_SRC} ${COMMON_EXCEPTIONS_SRC} ${MATH_SRC} ${FIBERSIMILARITY_SRC} )
TARGET_LINK_LIBRARIES( common ${Boost_LIBRARIES} ) TARGET_LINK_LIBRARIES( OWcommon ${Boost_LIBRARIES} ${CMAKE_DL_LIBS} )
# Set the prefix and suffix of dynamically loadable modules to match
# CMAKEs naming of them. The quotes are necessary so the shell doesn't mess
# with these defines.
add_definitions( '-DW_LIB_PREFIX="${CMAKE_SHARED_LIBRARY_PREFIX}"' )
add_definitions( '-DW_LIB_SUFFIX="${CMAKE_SHARED_LIBRARY_SUFFIX}"' )
# Unit tests # Unit tests
IF( OW_COMPILE_TESTS ) IF( OW_COMPILE_TESTS )
CXXTEST_ADD_TESTS_FROM_LIST( "${COMMON_SRC}" CXXTEST_ADD_TESTS_FROM_LIST( "${COMMON_SRC}"
"common" "OWcommon"
"WSegmentationFault.cpp" # can't test seg-faults ;-) "WSegmentationFault.cpp" # can't test seg-faults ;-)
"WTransferable.cpp" # its an empty class "WTransferable.cpp" # its an empty class
"WPropertyBase.cpp" # its an abstract class. Its small functionality is tested in WPropertyVariable_test.h "WPropertyBase.cpp" # its an abstract class. Its small functionality is tested in WPropertyVariable_test.h
......
...@@ -22,54 +22,65 @@ ...@@ -22,54 +22,65 @@
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#ifndef WLOADER_TEST_H #include <algorithm>
#define WLOADER_TEST_H #include <iomanip>
#include <numeric>
#include <string> #include "WAssert.h"
#include "WHistogram.h"
#include "WLimits.h"
#include "WLogger.h"
#include <cxxtest/TestSuite.h> WHistogram::WHistogram( double min, double max, size_t size )
: m_bins( size, 0 ),
m_min( min ),
m_max( max )
{
if( min > max )
{
std::swap( m_min, m_max );
}
WAssert( m_bins.size() > 0, "Error: A histogram with a size of 0 does not make any sense" );
m_intervalWidth = std::abs( m_min - m_max ) / m_bins.size();
}
#include "../WLoader.h" WHistogram::~WHistogram()
#include "../WDataSet.h" {
}
/** void WHistogram::insert( double value )
* Just a dummy for testing the base class
*/
class DummyLoader : public WLoader
{ {
public: if( value > m_max || value < m_min )
/**
* Constructor of Dummy class for testing of WLoader
* \param fileName this file will be loaded
*/
explicit DummyLoader( std::string fileName )
: WLoader( fileName )
{ {
wlog::warn( "WHistogram" ) << std::scientific << std::setprecision( 16 ) << "Inserted value out of bounds, thread: "
<< value << " as min, resp. max: " << m_min << "," << m_max;
return; // value = ( value > m_max ? m_max : m_min );
} }
virtual boost::shared_ptr< WDataSet > load() if( value == m_max )
{ {
return boost::shared_ptr< WDataSet >(); value = m_max - wlimits::DBL_EPS;
} }
};
/** m_bins.at( static_cast< size_t >( std::abs( value - m_min ) / m_intervalWidth ) )++;
* Unit tests the Loader base class. }
*/
class WLoaderTest : public CxxTest::TestSuite size_t WHistogram::binSize() const
{ {
public: return m_bins.size();
/** }
* If the given file name is invalid an exception should be thrown.
*/ size_t WHistogram::valuesSize() const
void testExceptionOnInvalidFilename( void ) {
return std::accumulate( m_bins.begin(), m_bins.end(), 0 );
}
size_t WHistogram::operator[]( size_t index ) const
{
if( index >= m_bins.size() )
{ {
TS_ASSERT_THROWS_EQUALS( DummyLoader( "no such file" ), wlog::error( "WHistogram" ) << index << "th interval is not available, there are only: " << m_bins.size();
const WDHIOFailure &e, return 0;
e.what(),
std::string( "file 'no such file' doesn't exists." ) );
TS_ASSERT_THROWS_NOTHING( DummyLoader( "fixtures/scalar_float.nii.gz" ) );
} }
}; return m_bins[ index ];
}
#endif // WLOADER_TEST_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WHISTOGRAM_H
#define WHISTOGRAM_H
#include <vector>
/**
* Container which associate values with (uniform width) bins (aka intervals or buckets).
*/
class WHistogram
{
public:
/**
* Default constructor.
*
* \param min
* \param max
* \param size
*/
WHistogram( double min, double max, size_t size = 1000 );
/**
* Default destructor.
*/
~WHistogram();
/**
* Inserts a given value within the given range (min, max) into exactly one bin and increment its size.
*
* \param value Value to insert.
*/
void insert( double value );
/**
* Computes number of invervals.
*
* \return Number of intervals.
*/
size_t binSize() const;
/**
* Computes the number of inserted values so far.
*
* \return Number of values so far.
*/
size_t valuesSize() const;
/**
* LooksUp how many elements are in this bin with the given index.
*
* \param index The bin number to look up for
*
* \return Number of values associated with this interval.
*/
size_t operator[]( size_t index ) const;