Commit 496e6d89 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD #180] function that scales colors to fit [0..1] range

parent 893107d8
......@@ -616,6 +616,34 @@ void WTriangleMesh::zoomMesh( float zoom )
}
}
void WTriangleMesh::rescaleVertexColors()
{
float maxR = 0;
float maxG = 0;
float maxB = 0;
for( size_t vertId = 0; vertId < m_vertColors->size(); ++vertId )
{
if( ( *m_vertColors )[vertId][0] > maxR )
{
maxR = ( *m_vertColors )[vertId][0];
}
if( ( *m_vertColors )[vertId][1] > maxG )
{
maxG = ( *m_vertColors )[vertId][1];
}
if( ( *m_vertColors )[vertId][2] > maxB )
{
maxB = ( *m_vertColors )[vertId][2];
}
}
for( size_t vertId = 0; vertId < m_vertColors->size(); ++vertId )
{
( *m_vertColors )[vertId][0] /= maxR;
( *m_vertColors )[vertId][1] /= maxG;
( *m_vertColors )[vertId][2] /= maxB;
}
}
std::ostream& tm_utils::operator<<( std::ostream& os, const WTriangleMesh& rhs )
{
std::stringstream ss;
......
......@@ -374,6 +374,11 @@ public:
*/
bool operator==( const WTriangleMesh& rhs ) const;
/**
* Rescale the vertex colors so that the maximum of all r, g and b values is 1
*/
void rescaleVertexColors();
protected:
static boost::shared_ptr< WPrototyped > m_prototype; //!< The prototype as singleton.
private:
......
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