Commit d5352af0 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[MERGE]

parents a5a079b7 610ab1b9
......@@ -3,6 +3,7 @@ wiebel@hegel.informatik.uni-leipzig.de Alexander_Wiebel
openwalnut@dergrosse.de Alexander_Wiebel
wiebel_openwalnut@dergrosse.de Alexander_Wiebel
math Mathias_Goldau
lmath@voltaire.informatik.uni-leipzig.de Mathias_Goldau
math@informatik.uni-leipzig.de Mathias_Goldau
schurade Ralph_Schurade
ebaum Sebastian_Eichelbaum
......
......@@ -59,6 +59,19 @@ section stem from the following website:
\item[Composition] usually has a strong life cycle dependency between instances of the container class and instances of the
contained class(es): If the container is destroyed, normally every instance that it contains is destroyed as well.
\end{description}
\chapter{Code Organization}
\section{Directories}
\begin{description}
\item[\texttt{src}:] The source code of our whole project should reside here. Some things like parts of the build system, or unit test system, are not considered as source code.
\item[\texttt{src/common}:] Here you should find often needed pieces of source code, you want to share for reuse, and may use almost everywhere. E.g. WLimits.h for sharing several limits like \texttt{MAX\_DOUBLE}.
\item[\texttt{src/common/dataStructures}:] Various modules need additional data structures. You may place them here. This is
because of increasing reuse of that data structures. A developer doesn't have to look into every module's directory for
gaining the following information: "Has someone already coded a KD-Tree implementation I can make use of?". A developer should
look into this directory before he starts developing some new data structures. Even if there is just one module using e.g. a
KD-Tree at the moment, maybe someone needs that in the future too. So, place your possibly reusable data structures here!
\end{description}
\chapter{Math}
......@@ -70,7 +83,7 @@ section stem from the following website:
For a general overview on visualization in medicine \cite{Preim:2007:VMT} can be recommended.
\chapter{GUI}
The GUI module is the only part where we allow gui-toolkit related code. For example, this means that the use of any QT class is
The GUI module is the only part where we allow GUI-toolkit related code. For example, this means that the use of any QT class is
prohibited outside the GUI module.
\chapter{GE (Graphics Engine)}
The graphics engine is mainly realized by integrating OpenSceneGraph (OSG) so far.
......
......@@ -125,8 +125,8 @@ ELSE( NOT CMAKE_BUILD_TYPE STREQUAL "Static" )
ENDIF ( NOT CMAKE_BUILD_TYPE STREQUAL "Static" )
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/bin/shaders)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/modules/navigationSlices/slice.vs ${CMAKE_BINARY_DIR}/bin/shaders/)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/modules/navigationSlices/slice.fs ${CMAKE_BINARY_DIR}/bin/shaders/)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/modules/navSlices/slice.vs ${CMAKE_BINARY_DIR}/bin/shaders/)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/modules/navSlices/slice.fs ${CMAKE_BINARY_DIR}/bin/shaders/)
# Special targets:
......
......@@ -22,5 +22,98 @@
//
//---------------------------------------------------------------------------
#include "WColor.hpp"
#include <cassert>
#include <string>
#include <vector>
#include "WColor.h"
#include "WStringUtils.hpp"
WColor::WColor( float red, float green, float blue, float alpha )
: m_red( red ),
m_green( green ),
m_blue( blue ),
m_alpha( alpha )
{
// check if the given values are correct in range
assert( m_green <= 1.0 && m_green >= 0.0 && "WColor comopnent out of range" );
assert( m_blue <= 1.0 && m_blue >= 0.0 && "WColor comopnent out of range" );
assert( m_red <= 1.0 && m_red >= 0.0 && "WColor comopnent out of range" );
assert( m_alpha <= 1.0 && m_alpha >= 0.0 && "WColor comopnent out of range" );
}
void WColor::setGreen( float green )
{
assert( green <= 1.0 && green >= 0.0 );
m_green = green;
}
void WColor::setBlue( float blue )
{
assert( blue <= 1.0 && blue >= 0.0 );
m_blue = blue;
}
void WColor::setRed( float red )
{
assert( red <= 1.0 && red >= 0.0 );
m_red = red;
}
void WColor::setAlpha( float alpha )
{
assert( alpha <= 1.0 && alpha >= 0.0 );
m_alpha = alpha;
}
float WColor::getRed() const
{
return m_red;
}
float WColor::getGreen() const
{
return m_green;
}
float WColor::getBlue() const
{
return m_blue;
}
float WColor::getAlpha() const
{
return m_alpha;
}
osg::Vec4 WColor::getOSGColor() const
{
return osg::Vec4( m_red, m_green, m_blue, m_alpha );
}
std::ostream& operator<<( std::ostream& out, const WColor& c )
{
float r = c.getRed();
float g = c.getGreen();
float b = c.getBlue();
float a = c.getAlpha();
out << r << ";" << g << ";" << b << ";" << a;
return out;
}
std::istream& operator>>( std::istream& in, WColor& c )
{
std::string str;
in >> str;
std::vector<std::string> tokens;
tokens = string_utils::tokenize( str, ";" );
assert( tokens.size() == 4 && "There weren't 4 color values for a WColor" );
c.setRed( boost::lexical_cast< float >( tokens[0] ) );
c.setGreen( boost::lexical_cast< float >( tokens[1] ) );
c.setBlue( boost::lexical_cast< float >( tokens[2] ) );
c.setAlpha( boost::lexical_cast< float >( tokens[3] ) );
return in;
}
......@@ -22,10 +22,16 @@
//
//---------------------------------------------------------------------------
#ifndef WCOLOR_HPP
#define WCOLOR_HPP
#ifndef WCOLOR_H
#define WCOLOR_H
#include <istream>
#include <ostream>
#include <cassert>
#include <string>
#include <vector>
#include <boost/lexical_cast.hpp>
#include <osg/Vec4>
......@@ -35,83 +41,57 @@
class WColor
{
public:
/**
* Standard way of constructing colors, alpha is optional, and black is default
*/
WColor( float red = 0.0, float green = 0.0, float blue = 0.0, float alpha = 1.0 )
: m_red( red ),
m_green( green ),
m_blue( blue ),
m_alpha( alpha )
{
}
WColor( float red = 0.0, float green = 0.0, float blue = 0.0, float alpha = 1.0 );
/**
* Sets the green channel for this color
*/
void setGreen( float green )
{
assert( green <= 1.0 && green >= 0.0 );
m_green = green;
}
void setGreen( float green );
/**
* Sets the blue channel for this color
*/
void setBlue( float blue )
{
assert( blue <= 1.0 && blue >= 0.0 );
m_blue = blue;
}
void setBlue( float blue );
/**
* Sets the red channel for this color
*/
void setRed( float red )
{
assert( red <= 1.0 && red >= 0.0 );
m_red = red;
}
void setRed( float red );
/**
* Sets the alpha channel for this color
*/
void setAlpha( float alpha );
/**
* \return red channel for this color
*/
float getRed() const
{
return m_red;
}
float getRed() const;
/**
* \return green channel for this color
*/
float getGreen() const
{
return m_green;
}
float getGreen() const;
/**
* \return blue channel for this color
*/
float getBlue() const
{
return m_blue;
}
float getBlue() const;
/**
* \return alpha channel for this color
*/
float getAlpha() const
{
return m_alpha;
}
float getAlpha() const;
/**
* Makes a OSG compatible copy of this.
*/
osg::Vec4 getOSGColor() const
{
return osg::Vec4( m_red, m_green, m_blue, m_alpha );
}
osg::Vec4 getOSGColor() const;
protected:
private:
float m_red;
......@@ -120,4 +100,7 @@ private:
float m_alpha;
};
#endif // WCOLOR_HPP
std::ostream& operator<<( std::ostream& out, const WColor& c );
std::istream& operator>>( std::istream& in, WColor& c );
#endif // WCOLOR_H
......@@ -25,6 +25,8 @@
#ifndef WLIMITS_H
#define WLIMITS_H
#include <limits>
/**
* Project wide limits for different quantitities.
*/
......@@ -56,6 +58,11 @@ namespace wlimits
* Maximum samplimg frequency of a recording.
*/
const unsigned int MAX_RECORDING_SAMPLING_FREQUENCY = 20000;
/**
* Maximum double value
*/
const double MAX_DOUBLE = std::numeric_limits< double >::max();
}
#endif // WLIMITS_H
......@@ -92,6 +92,14 @@ boost::signal1< void, std::string >* WProperties::addString( std::string name, s
return prop->getSignalValueChanged();
}
boost::signal1< void, std::string >* WProperties::addColor( std::string name, WColor value, std::string shortDesc, std::string longDesc )
{
WProperty* prop = new WProperty( name, value, shortDesc, longDesc );
m_propertyList[name] = prop;
m_propertyVector.push_back( prop );
return prop->getSignalValueChanged();
}
WProperty* WProperties::findProp( std::string name )
{
if ( m_propertyList.count( name) != 0 )
......
......@@ -32,6 +32,7 @@
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread.hpp>
#include "WProperty.h"
......@@ -72,15 +73,21 @@ public:
boost::signal1< void, std::string >* addFloat( std::string name, float value = 0.0, std::string shortDesc = "", std::string longDesc = "" );
boost::signal1< void, std::string >* addDouble( std::string name, double value = 0.0, std::string shortDesc = "", std::string longDesc = "" );
boost::signal1< void, std::string >* addString( std::string name, std::string value = "", std::string shortDesc = "", std::string longDesc = "" );
boost::signal1< void, std::string >* addColor( std::string name, WColor value, std::string shortDesc = "", std::string longDesc = "" );
std::string getValueString( const std::string prop );
template < typename T > void setValue( std::string prop, const T& arg )
{
boost::shared_lock<boost::shared_mutex> slock;
slock = boost::shared_lock<boost::shared_mutex>( m_updateLock );
if ( findProp( prop ) )
{
findProp( prop )->setValue( arg );
}
slock.unlock();
}
template < typename T > void setMin( std::string prop, const T& arg )
......@@ -133,6 +140,8 @@ private:
std::map < std::string, WProperty* >m_propertyList;
std::vector< WProperty* >m_propertyVector;
boost::shared_mutex m_updateLock;
};
#endif // WPROPERTIES_H
......@@ -94,6 +94,17 @@ WProperty::WProperty( std::string name, double value, std::string shortDesc, std
setValue( value );
}
WProperty::WProperty( std::string name, WColor value, std::string shortDesc, std::string longDesc )
: m_type( P_DOUBLE ),
m_name( name ),
m_shortDesc( shortDesc ),
m_longDesc( longDesc ),
m_isHidden( false )
{
setValue( value );
}
WProperty::~WProperty()
{
......
......@@ -30,6 +30,8 @@
#include <boost/lexical_cast.hpp>
#include "../gui/qt4/signalslib.hpp"
#include "WColor.h"
typedef enum
{
P_UNDEFINED,
......@@ -59,6 +61,7 @@ public:
WProperty( std::string name, int value, std::string shortDesc = "", std::string longDesc = "" );
WProperty( std::string name, float value, std::string shortDesc = "", std::string longDesc = "" );
WProperty( std::string name, double value, std::string shortDesc = "", std::string longDesc = "" );
WProperty( std::string name, WColor value, std::string shortDesc = "", std::string longDesc = "" );
/**
* destructor
......
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
#include <cassert>
#include <cmath>
#include <string>
#include "WStatusReport.h"
WStatusReport::WStatusReport( unsigned int totalSteps )
: m_totalSteps( totalSteps ),
m_finishedSteps( 0 )
{
}
WStatusReport& WStatusReport::operator++() // prefix increment
{
assert( m_totalSteps > m_finishedSteps );
m_finishedSteps++;
return *this;
}
double WStatusReport::operator+=( unsigned int numSteps )
{
assert( m_totalSteps > m_finishedSteps );
if( m_totalSteps - m_finishedSteps < numSteps )
{
m_finishedSteps = m_totalSteps;
}
else
{
m_finishedSteps += numSteps;
}
return progress();
}
std::string WStatusReport::stringBar( char symbol, unsigned int finalNumOfSymbols ) const
{
unsigned int numSymbols = progress() * finalNumOfSymbols;
return std::string( numSymbols, symbol );
}
//---------------------------------------------------------------------------
//
// 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 WSTATUSREPORT_H
#define WSTATUSREPORT_H
#include <string>
/**
* A counter for reporting the progress of some work.
*/
class WStatusReport
{
friend class WStatusReportTest;
public:
/**
* Constructs a new status reporter with the number of total steps
* which it should reach to reach the 100 percent.
*/
explicit WStatusReport( unsigned int totalSteps );
/**
* Returns the total number of steps which are considered as 100 percent
* work.
*/
unsigned int getTotalSteps() const
{
return m_totalSteps;
}
/**
* Returns the number of steps done so far
*/
unsigned int getFinishedSteps() const
{
return m_finishedSteps;
}
/**
* Returns the progress in percentage done so far: e.g. 0.7 == 70%
*/
double progress() const
{
return static_cast< double >( m_finishedSteps ) / m_totalSteps;
}
/**
* Increments the finished work by one step.
*/
WStatusReport& operator++(); // prefix increment
/**
* Increments the finished work by the number of the given steps.
*
* \return The progress()
*/
double operator+=( unsigned int numSteps );
/**
* Generates a string which represents the progress in terms of
* characters. When reaching 100 percent finally finalNumOfSymbols are
* returned.
*/
std::string stringBar( char symbol = '#', unsigned int finalNumOfSymbols = 50 ) const;
protected:
private:
unsigned int m_totalSteps;
unsigned int m_finishedSteps;
};
#endif // WSTATUSREPORT_H
......@@ -67,8 +67,8 @@ std::string string_utils::toLower( const std::string& source )
}
std::vector< std::string > string_utils::tokenize( const std::string& source,
bool compress,
const std::string& t )
const std::string& delim,
bool compress )
{
std::vector< std::string > result;
namespace ba = boost::algorithm;
......@@ -77,7 +77,7 @@ std::vector< std::string > string_utils::tokenize( const std::string& source,
{
compression = ba::token_compress_off;
}
ba::split( result, source, ba::is_any_of( t ), compression );
ba::split( result, source, ba::is_any_of( delim ), compression );
if( result.back() == "" )
{
result.pop_back();
......
......@@ -118,13 +118,13 @@ namespace string_utils
* \param source String to tokenize
* \param compress If true, charactes matching between two tokens are
* collapsed and handled as just one character.
* \param t String representing a set containg all characters considered
* \param delim String representing a set containg all characters considered
* as whitespace.
* \return A vector of strings containing the tokens.
*/
std::vector< std::string > tokenize( const std::string& source,
bool compress = true,
const std::string& t = WHITESPACE );
const std::string& delim = WHITESPACE,
bool compress = true );
/**
* Writes every vector to an output stream such as cout, if its elements
......
//---------------------------------------------------------------------------
//
// 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 WCOLOR_TEST_H
#define WCOLOR_TEST_H
#include <string>
#include <sstream>
#include <cxxtest/TestSuite.h>
#include "../WColor.h"
/**