Commit d1b82cfe authored by schurade's avatar schurade
Browse files

[CHANGE] made WColor lexical_castable, at this oportunity repaired the coding standard violation

parent 6b924ae8
......@@ -22,34 +22,97 @@
//
//---------------------------------------------------------------------------
#include "WColor.hpp"
#include <string>
#include <vector>
std::ostream& operator<<( std::ostream& out, const WColor& c )
#include "WColor.h"
WColor::WColor( float red, float green, float blue, float alpha )
: m_red( red ),
m_green( green ),
m_blue( blue ),
m_alpha( alpha )
{
float r = c.getRed();
float g = c.getGreen();
float b = c.getBlue();
float a = c.getAlpha();
}
out << r << ";" << g << ";" << b << ";" << a;
return out;
/**
* Sets the green channel for this color
*/
void WColor::setGreen( float green )
{
assert( green <= 1.0 && green >= 0.0 );
m_green = green;
}
std::istream& operator>>( std::istream& in, WColor& c )
/**
* Sets the blue channel for this color
*/
void WColor::setBlue( float blue )
{
std::vector<std::string> tokens;
std::string str;
in >> str;
c.tokenize(str, tokens, ";");
assert( blue <= 1.0 && blue >= 0.0 );
m_blue = blue;
}
c.setRed( boost::lexical_cast<float>( tokens[0] ) );
c.setGreen( boost::lexical_cast<float>( tokens[1] ) );
c.setBlue( boost::lexical_cast<float>( tokens[2] ) );
/**
* Sets the red channel for this color
*/
void WColor::setRed( float red )
{
assert( red <= 1.0 && red >= 0.0 );
m_red = red;
}
return in;
/**
* Sets the alpha channel for this color
*/
void WColor::setAlpha( float alpha )
{
assert( alpha <= 1.0 && alpha >= 0.0 );
m_alpha = alpha;
}
void WColor::tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters )
/**
* \return red channel for this color
*/
float WColor::getRed() const
{
return m_red;
}
/**
* \return green channel for this color
*/
float WColor::getGreen() const
{
return m_green;
}
/**
* \return blue channel for this color
*/
float WColor::getBlue() const
{
return m_blue;
}
/**
* \return alpha channel for this color
*/
float WColor::getAlpha() const
{
return m_alpha;
}
/**
* Makes a OSG compatible copy of this.
*/
osg::Vec4 WColor::getOSGColor() const
{
return osg::Vec4( m_red, m_green, m_blue, m_alpha );
}
void WColor::tokenize( const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters )
{
// Skip delimiters at beginning.
std::string::size_type lastPos = str.find_first_not_of( delimiters, 0 );
......@@ -67,3 +130,27 @@ void WColor::tokenize(const std::string& str, std::vector<std::string>& tokens,
}
}
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::vector<std::string> tokens;
std::string str;
in >> str;
c.tokenize( str, tokens, ";" );
c.setRed( boost::lexical_cast<float>( tokens[0] ) );
c.setGreen( boost::lexical_cast<float>( tokens[1] ) );
c.setBlue( boost::lexical_cast<float>( tokens[2] ) );
return in;
}
......@@ -22,12 +22,12 @@
//
//---------------------------------------------------------------------------
#ifndef WCOLOR_HPP
#define WCOLOR_HPP
#ifndef WCOLOR_H
#define WCOLOR_H
#include <cassert>
#include <istream>
#include <ostream>
#include <cassert>
#include <string>
#include <vector>
......@@ -47,89 +47,52 @@ 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 )
{
assert( alpha <= 1.0 && alpha >= 0.0 );
m_alpha = alpha;
}
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;
void tokenize( const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " " );
......@@ -142,4 +105,4 @@ private:
float m_alpha;
};
#endif // WCOLOR_HPP
#endif // WCOLOR_H
......@@ -30,7 +30,7 @@
#include <boost/lexical_cast.hpp>
#include "../gui/qt4/signalslib.hpp"
#include "WColor.hpp"
#include "WColor.h"
typedef enum
{
......
......@@ -30,7 +30,7 @@
#include "WFiberTestModule.h"
#include "../../math/WFiber.h"
#include "../../common/WLogger.h"
#include "../../common/WColor.hpp"
#include "../../common/WColor.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WSubject.h"
#include "../../dataHandler/WDataSetFibers.h"
......
......@@ -50,8 +50,6 @@
#include "../../graphicsEngine/WShader.h"
#include "../../common/WColor.hpp"
WNavigationSliceModule::WNavigationSliceModule():
WModule()
{
......@@ -113,8 +111,6 @@ void WNavigationSliceModule::properties()
m_properties->addBool( "showAxial", true );
m_properties->addBool( "showCoronal", true );
m_properties->addBool( "showSagittal", true );
m_properties->addColor( "testColor", WColor(0.3, 0.3, 0.5, 1.0) );
}
void WNavigationSliceModule::notifyDataChange( boost::shared_ptr<WModuleConnector> input,
......@@ -129,9 +125,6 @@ void WNavigationSliceModule::threadMain()
{
createGeometry();
WColor c = m_properties->getValue<WColor>( "testColor" );
std::cout << c << std::endl;
// Since the modules run in a separate thread: such loops are possible
while ( !m_FinishRequested )
{
......
......@@ -26,7 +26,7 @@
#include <cmath>
#include "WColorUtils.h"
#include "../common/WColor.hpp"
#include "../common/WColor.h"
#include "../math/WPosition.h"
namespace color_utils
......
......@@ -25,7 +25,7 @@
#ifndef WCOLORUTILS_H
#define WCOLORUTILS_H
#include "../common/WColor.hpp"
#include "../common/WColor.h"
#include "../math/WPosition.h"
/**
......
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