2004-02-10 02:11:28 +01:00
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
2016-06-13 07:29:25 +02:00
* Copyright ( C ) 2004 - 2016 \ / ) \ / *
2004-02-10 02:11:28 +01:00
* Visual Computing Lab / \ / | *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved . *
* *
2016-06-13 07:29:25 +02:00
* This program is free software ; you can redistribute it and / or modify *
2004-02-10 02:11:28 +01:00
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation ; either version 2 of the License , or *
* ( at your option ) any later version . *
* *
* This program 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 *
2016-06-13 07:29:25 +02:00
* GNU General Public License ( http : //www.gnu.org/licenses/gpl.txt) *
2004-02-10 02:11:28 +01:00
* for more details . *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# ifndef __VCGLIB_COLOR4
# define __VCGLIB_COLOR4
2004-07-15 13:01:43 +02:00
# include <vcg/space/point3.h>
2004-02-10 02:11:28 +01:00
# include <vcg/space/point4.h>
namespace vcg {
2004-03-10 22:38:40 +01:00
/** \addtogroup space */
/*@{*/
/**
The templated class for representing 4 entity color .
The class is templated over the ScalarType . class that is used to represent color with float or with unsigned chars . All the usual
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
operator overloading ( * + - . . . ) is present .
2004-03-10 22:38:40 +01:00
*/
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
template < class T >
2004-02-10 02:11:28 +01:00
class Color4 : public Point4 < T >
{
2014-06-24 10:46:49 +02:00
typedef Point4 < T > Base ;
2004-02-10 02:11:28 +01:00
public :
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
/// Constant for storing standard colors.
2004-02-10 02:11:28 +01:00
/// Each color is stored in a simple in so that the bit pattern match with the one of Color4b.
2014-06-24 10:46:49 +02:00
enum ColorConstant {
Black = 0xff000000 ,
Gray = 0xff808080 ,
White = 0xffffffff ,
Red = 0xff0000ff ,
Green = 0xff00ff00 ,
Blue = 0xffff0000 ,
Cyan = 0xffffff00 ,
Yellow = 0xff00ffff ,
Magenta = 0xffff00ff ,
LightGray = 0xffc0c0c0 ,
LightRed = 0xff8080ff ,
LightGreen = 0xff80ff80 ,
LightBlue = 0xffff8080 ,
DarkGray = 0xff404040 ,
DarkRed = 0xff000040 ,
DarkGreen = 0xff004000 ,
DarkBlue = 0xff400000
} ;
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
2012-10-19 13:52:57 +02:00
inline Color4 ( const T nx , const T ny , const T nz , const T nw ) : Point4 < T > ( nx , ny , nz , nw ) { }
inline Color4 ( const Point4 < T > & c ) : Point4 < T > ( c ) { }
inline Color4 ( ) { }
2004-02-10 02:11:28 +01:00
inline Color4 ( ColorConstant cc ) ;
2016-03-31 15:48:45 +02:00
inline Color4 ( unsigned int cc ) ;
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
template < class Q >
2014-06-24 10:46:49 +02:00
inline void Import ( const Color4 < Q > & b )
2004-02-10 02:11:28 +01:00
{
2014-06-24 10:46:49 +02:00
( * this ) [ 0 ] = T ( b [ 0 ] ) ;
( * this ) [ 1 ] = T ( b [ 1 ] ) ;
( * this ) [ 2 ] = T ( b [ 2 ] ) ;
( * this ) [ 3 ] = T ( b [ 3 ] ) ;
2004-02-10 02:11:28 +01:00
}
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
template < class Q >
2014-06-24 10:46:49 +02:00
inline void Import ( const Point4 < Q > & b )
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
{
2014-06-24 10:46:49 +02:00
( * this ) [ 0 ] = T ( b [ 0 ] ) ;
( * this ) [ 1 ] = T ( b [ 1 ] ) ;
( * this ) [ 2 ] = T ( b [ 2 ] ) ;
( * this ) [ 3 ] = T ( b [ 3 ] ) ;
2008-04-22 22:44:07 +02:00
}
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
template < class Q >
2008-04-22 22:44:07 +02:00
static inline Color4 Construct ( const Color4 < Q > & b )
{
return Color4 ( T ( b [ 0 ] ) , T ( b [ 1 ] ) , T ( b [ 2 ] ) , T ( b [ 3 ] ) ) ;
}
2004-05-07 12:06:55 +02:00
//inline void Import(const Color4<float> &b);
//inline void Import(const Color4<unsigned char> &b);
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
2008-07-09 17:18:08 +02:00
inline Color4 operator + ( const Color4 & p ) const
2014-06-24 10:46:49 +02:00
{
return Color4 ( ( * this ) [ 0 ] + p . V ( ) [ 0 ] , ( * this ) [ 1 ] + p . V ( ) [ 1 ] , ( * this ) [ 2 ] + p . V ( ) [ 2 ] , ( * this ) [ 3 ] + p . V ( ) [ 3 ] ) ;
}
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
2014-06-24 10:46:49 +02:00
template < class ScalarInterpType >
inline void lerp ( const Color4 & c0 , const Color4 & c1 , const ScalarInterpType x )
2012-10-19 13:52:57 +02:00
{
assert ( x > = 0 ) ;
assert ( x < = 1 ) ;
2004-02-10 02:11:28 +01:00
2012-10-19 13:52:57 +02:00
( * this ) [ 0 ] = ( T ) ( c1 . V ( ) [ 0 ] * x + c0 . V ( ) [ 0 ] * ( 1.0f - x ) ) ;
( * this ) [ 1 ] = ( T ) ( c1 . V ( ) [ 1 ] * x + c0 . V ( ) [ 1 ] * ( 1.0f - x ) ) ;
( * this ) [ 2 ] = ( T ) ( c1 . V ( ) [ 2 ] * x + c0 . V ( ) [ 2 ] * ( 1.0f - x ) ) ;
( * this ) [ 3 ] = ( T ) ( c1 . V ( ) [ 3 ] * x + c0 . V ( ) [ 3 ] * ( 1.0f - x ) ) ;
2004-02-10 02:11:28 +01:00
}
2012-10-19 13:52:57 +02:00
2014-06-24 10:46:49 +02:00
template < class ScalarInterpType >
inline void lerp ( const Color4 & c0 , const Color4 & c1 , const Color4 & c2 , const Point3 < ScalarInterpType > & ip )
2012-10-19 13:52:57 +02:00
{
assert ( fabs ( ip [ 0 ] + ip [ 1 ] + ip [ 2 ] - 1 ) < 0.00001 ) ;
( * this ) [ 0 ] = ( T ) ( c0 [ 0 ] * ip [ 0 ] + c1 [ 0 ] * ip [ 1 ] + c2 [ 0 ] * ip [ 2 ] ) ;
( * this ) [ 1 ] = ( T ) ( c0 [ 1 ] * ip [ 0 ] + c1 [ 1 ] * ip [ 1 ] + c2 [ 1 ] * ip [ 2 ] ) ;
( * this ) [ 2 ] = ( T ) ( c0 [ 2 ] * ip [ 0 ] + c1 [ 2 ] * ip [ 1 ] + c2 [ 2 ] * ip [ 2 ] ) ;
( * this ) [ 3 ] = ( T ) ( c0 [ 3 ] * ip [ 0 ] + c1 [ 3 ] * ip [ 1 ] + c2 [ 3 ] * ip [ 2 ] ) ;
}
/// given a float and a range set the corresponding color in the well known red->green->blue color ramp. To reverse the direction of the ramp just swap minf and maxf.
inline void SetColorRamp ( const float & minf , const float & maxf , float v )
{
if ( minf > maxf ) { SetColorRamp ( maxf , minf , maxf + ( minf - v ) ) ; return ; }
float step = ( maxf - minf ) / 4 ;
if ( v < minf ) { * this = Color4 < T > ( Color4 < T > : : Red ) ; return ; }
v - = minf ;
if ( v < step ) { lerp ( Color4 < T > ( Color4 < T > : : Red ) , Color4 < T > ( Color4 < T > : : Yellow ) , v / step ) ; return ; }
v - = step ;
if ( v < step ) { lerp ( Color4 < T > ( Color4 < T > : : Yellow ) , Color4 < T > ( Color4 < T > : : Green ) , v / step ) ; return ; }
v - = step ;
if ( v < step ) { lerp ( Color4 < T > ( Color4 < T > : : Green ) , Color4 < T > ( Color4 < T > : : Cyan ) , v / step ) ; return ; }
v - = step ;
if ( v < step ) { lerp ( Color4 < T > ( Color4 < T > : : Cyan ) , Color4 < T > ( Color4 < T > : : Blue ) , v / step ) ; return ; }
* this = Color4 < T > ( Color4 < T > : : Blue ) ;
}
2016-03-31 15:48:45 +02:00
inline void SetColorRampParula ( const float & minf , const float & maxf , float v )
{
if ( minf > maxf ) { SetColorRampParula ( maxf , minf , maxf + ( minf - v ) ) ; return ; }
SetColorRampParula ( ( v - minf ) / ( maxf - minf ) ) ;
}
inline void SetColorRampParula ( float v )
{
if ( v < 0 ) v = 0 ;
else if ( v > 1 ) v = 1 ;
unsigned int ParuVal [ 9 ] = { 0xff801627 , 0xffe16303 , 0xffd48514 ,
0xffc6a706 , 0xff9eb938 , 0xff73bf92 ,
0xff56bad9 , 0xff2ecefc , 0xff0afaff } ;
int ind = int ( floor ( v * 8.0f ) ) ;
float div = ( v * 8.0f - ind ) ;
if ( div < 0 ) div = 0 ;
else if ( div > 1 ) div = 1 ;
lerp ( Color4 < T > ( ParuVal [ ind ] ) , Color4 < T > ( ParuVal [ ind + 1 ] ) , div ) ;
}
2012-10-19 13:52:57 +02:00
void SetHSVColor ( float h , float s , float v )
{
float r , g , b ;
if ( s = = 0.0 ) { // gray color
r = g = b = v ;
( * this ) [ 0 ] = ( unsigned char ) ( 255 * r ) ;
( * this ) [ 1 ] = ( unsigned char ) ( 255 * g ) ;
( * this ) [ 2 ] = ( unsigned char ) ( 255 * b ) ;
( * this ) [ 3 ] = 255 ;
return ;
}
2016-10-07 00:49:34 +02:00
float dummy ;
h = modff ( h , & dummy ) ;
2012-10-19 13:52:57 +02:00
if ( h = = 1.0 ) h = 0.0 ;
2020-04-01 09:27:43 +02:00
int i = int ( floor ( h * 6.0f ) ) ;
float f = float ( h * 6.0f - floor ( h * 6.0f ) ) ;
2012-10-19 13:52:57 +02:00
float p = v * ( 1.0f - s ) ;
float q = v * ( 1.0f - s * f ) ;
float t = v * ( 1.0f - s * ( 1.0f - f ) ) ;
switch ( i )
{
case 0 : r = v ; g = t ; b = p ; break ;
case 1 : r = q ; g = v ; b = p ; break ;
case 2 : r = p ; g = v ; b = t ; break ;
case 3 : r = p ; g = q ; b = v ; break ;
case 4 : r = t ; g = p ; b = v ; break ;
case 5 : r = v ; g = p ; b = q ; break ;
default : r = 0 ; g = 0 ; b = 0 ; assert ( 0 ) ; break ;
}
( * this ) [ 0 ] = ( unsigned char ) ( 255 * r ) ;
( * this ) [ 1 ] = ( unsigned char ) ( 255 * g ) ;
( * this ) [ 2 ] = ( unsigned char ) ( 255 * b ) ;
( * this ) [ 3 ] = 255 ;
}
2004-02-10 02:11:28 +01:00
inline static Color4 GrayShade ( float f )
{
2016-03-31 15:48:45 +02:00
if ( f < 0 ) f = 0.0f ;
else if ( f > 1 ) f = 1.0f ;
return Color4 ( f , f , f , 1 ) ;
2004-02-10 02:11:28 +01:00
}
inline void SetGrayShade ( float f )
{
2016-04-02 07:42:05 +02:00
if ( f < 0 ) f = 0.0f ;
else if ( f > 1 ) f = 1.0f ;
Import ( Color4 < float > ( f , f , f , 1 ) ) ;
2004-02-10 02:11:28 +01:00
}
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
/** Given an integer returns a well ordering of colors
2004-02-10 02:11:28 +01:00
// so that every color differs as much as possible form the previous one
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
// params:
2012-01-18 12:24:33 +01:00
// range is the maximum expected value (max of the range)
// value is the requested position (it must be <range);
2004-03-10 22:38:40 +01:00
*/
2012-01-18 12:24:33 +01:00
inline static Color4 Scatter ( int range , int value , float Sat = .3f , float Val = .9f )
2004-02-10 02:11:28 +01:00
{
2012-01-18 12:24:33 +01:00
int b , k , m = range ;
int r = range ;
2004-02-10 02:11:28 +01:00
2014-06-24 10:46:49 +02:00
for ( b = 0 , k = 1 ; k < range ; k < < = 1 )
if ( value < < 1 > = m ) {
if ( b = = 0 ) r = k ;
b + = k ;
value - = ( m + 1 ) > > 1 ;
m > > = 1 ;
}
2020-04-01 09:27:43 +02:00
else m = ( m + 1 ) > > 1 ;
2014-06-24 10:46:49 +02:00
if ( r > range - b ) r = range - b ;
//TRACE("Scatter range 0..%i, in %i out %i\n",n,a,b);
Color4 rc ;
rc . SetHSVColor ( float ( b ) / float ( range ) , Sat , Val ) ;
return rc ;
2004-02-10 02:11:28 +01:00
}
2012-04-18 23:17:04 +02:00
inline static Color4 ColorRamp ( const float & minf , const float & maxf , float v )
{
Color4 rc ;
rc . SetColorRamp ( minf , maxf , v ) ;
return rc ;
}
2012-11-27 08:05:38 +01:00
2021-03-18 18:30:54 +01:00
inline static unsigned short ToUnsignedB5G5R5 ( const Color4 & ) { return 0 ; }
inline static unsigned short ToUnsignedR5G5B5 ( const Color4 & ) { return 0 ; }
2012-11-27 08:05:38 +01:00
inline static Color4 FromUnsignedB5G5R5 ( unsigned short )
{
return Color4 ( Color4 : : White ) ;
}
inline static Color4 FromUnsignedR5G5B5 ( unsigned short )
{
return Color4 ( Color4 : : White ) ;
}
} ; /// END CLASS ///////////////////
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
2012-10-19 13:52:57 +02:00
template < > template < >
2004-02-10 02:11:28 +01:00
inline void Color4 < float > : : Import ( const Color4 < unsigned char > & b )
{
2008-10-27 20:35:17 +01:00
( * this ) [ 0 ] = b [ 0 ] / 255.0f ;
( * this ) [ 1 ] = b [ 1 ] / 255.0f ;
( * this ) [ 2 ] = b [ 2 ] / 255.0f ;
( * this ) [ 3 ] = b [ 3 ] / 255.0f ;
2004-02-10 02:11:28 +01:00
}
2004-05-07 14:46:55 +02:00
2016-12-06 14:50:50 +01:00
template < > template < >
inline void Color4 < double > : : Import ( const Color4 < unsigned char > & b )
{
( * this ) [ 0 ] = b [ 0 ] / 255.0 ;
( * this ) [ 1 ] = b [ 1 ] / 255.0 ;
( * this ) [ 2 ] = b [ 2 ] / 255.0 ;
( * this ) [ 3 ] = b [ 3 ] / 255.0 ;
}
2012-10-19 13:52:57 +02:00
template < > template < >
2004-02-10 02:11:28 +01:00
inline void Color4 < unsigned char > : : Import ( const Color4 < float > & b )
{
2008-10-27 20:35:17 +01:00
( * this ) [ 0 ] = ( unsigned char ) ( b [ 0 ] * 255.0f ) ;
( * this ) [ 1 ] = ( unsigned char ) ( b [ 1 ] * 255.0f ) ;
( * this ) [ 2 ] = ( unsigned char ) ( b [ 2 ] * 255.0f ) ;
( * this ) [ 3 ] = ( unsigned char ) ( b [ 3 ] * 255.0f ) ;
2004-02-10 02:11:28 +01:00
}
2012-10-19 13:52:57 +02:00
template < > template < >
2008-04-22 22:44:07 +02:00
inline void Color4 < unsigned char > : : Import ( const Point4 < float > & b )
{
2008-10-27 20:35:17 +01:00
( * this ) [ 0 ] = ( unsigned char ) ( b [ 0 ] * 255.0f ) ;
( * this ) [ 1 ] = ( unsigned char ) ( b [ 1 ] * 255.0f ) ;
( * this ) [ 2 ] = ( unsigned char ) ( b [ 2 ] * 255.0f ) ;
( * this ) [ 3 ] = ( unsigned char ) ( b [ 3 ] * 255.0f ) ;
2008-04-22 22:44:07 +02:00
}
2016-12-06 14:50:50 +01:00
template < > template < >
inline void Color4 < unsigned char > : : Import ( const Point4 < double > & b )
{
( * this ) [ 0 ] = ( unsigned char ) ( b [ 0 ] * 255.0 ) ;
( * this ) [ 1 ] = ( unsigned char ) ( b [ 1 ] * 255.0 ) ;
( * this ) [ 2 ] = ( unsigned char ) ( b [ 2 ] * 255.0 ) ;
( * this ) [ 3 ] = ( unsigned char ) ( b [ 3 ] * 255.0 ) ;
}
2012-10-19 13:52:57 +02:00
template < > template < >
2008-04-22 22:44:07 +02:00
inline Color4 < unsigned char > Color4 < unsigned char > : : Construct ( const Color4 < float > & b )
{
return Color4 < unsigned char > (
2014-06-24 10:46:49 +02:00
( unsigned char ) ( b [ 0 ] * 255.0f ) ,
( unsigned char ) ( b [ 1 ] * 255.0f ) ,
( unsigned char ) ( b [ 2 ] * 255.0f ) ,
( unsigned char ) ( b [ 3 ] * 255.0f ) ) ;
2008-04-22 22:44:07 +02:00
}
2012-10-19 13:52:57 +02:00
template < > template < >
2008-04-22 22:44:07 +02:00
inline Color4 < float > Color4 < float > : : Construct ( const Color4 < unsigned char > & b )
{
return Color4 < float > (
2014-06-24 10:46:49 +02:00
( float ) ( b [ 0 ] ) / 255.0f ,
( float ) ( b [ 1 ] ) / 255.0f ,
( float ) ( b [ 2 ] ) / 255.0f ,
( float ) ( b [ 3 ] ) / 255.0f ) ;
2008-04-22 22:44:07 +02:00
}
2004-02-10 02:11:28 +01:00
2016-12-06 14:50:50 +01:00
template < > template < >
inline Color4 < double > Color4 < double > : : Construct ( const Color4 < unsigned char > & b )
{
return Color4 < double > (
( double ) ( b [ 0 ] ) / 255.0 ,
( double ) ( b [ 1 ] ) / 255.0 ,
( double ) ( b [ 2 ] ) / 255.0 ,
( double ) ( b [ 3 ] ) / 255.0 ) ;
}
2004-09-09 10:39:33 +02:00
template < >
2004-09-03 15:58:48 +02:00
inline Color4 < unsigned char > : : Color4 ( Color4 < unsigned char > : : ColorConstant cc )
2004-02-10 02:11:28 +01:00
{
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
* ( ( int * ) this ) = cc ;
2004-02-10 02:11:28 +01:00
}
2004-09-09 10:39:33 +02:00
template < >
2004-09-03 15:58:48 +02:00
inline Color4 < float > : : Color4 ( Color4 < float > : : ColorConstant cc )
2004-02-10 02:11:28 +01:00
{
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
Import ( Color4 < unsigned char > ( ( Color4 < unsigned char > : : ColorConstant ) cc ) ) ;
2004-02-10 02:11:28 +01:00
}
2016-12-06 14:50:50 +01:00
template < >
inline Color4 < double > : : Color4 ( Color4 < double > : : ColorConstant cc )
{
Import ( Color4 < unsigned char > ( ( Color4 < unsigned char > : : ColorConstant ) cc ) ) ;
}
2016-03-31 15:48:45 +02:00
template < >
inline Color4 < unsigned char > : : Color4 ( unsigned int cc )
{
* ( ( int * ) this ) = cc ;
}
template < >
inline Color4 < float > : : Color4 ( unsigned int cc )
{
Import ( Color4 < unsigned char > ( cc ) ) ;
}
2016-12-06 14:50:50 +01:00
template < >
inline Color4 < double > : : Color4 ( unsigned int cc )
{
Import ( Color4 < unsigned char > ( cc ) ) ;
}
2008-06-18 01:08:53 +02:00
inline Color4 < float > Clamp ( Color4 < float > & c )
{
2014-06-24 10:46:49 +02:00
c [ 0 ] = math : : Clamp ( c [ 0 ] , 0.0f , 1.0f ) ;
c [ 1 ] = math : : Clamp ( c [ 1 ] , 0.0f , 1.0f ) ;
c [ 2 ] = math : : Clamp ( c [ 2 ] , 0.0f , 1.0f ) ;
c [ 3 ] = math : : Clamp ( c [ 3 ] , 0.0f , 1.0f ) ;
return c ;
2008-06-18 01:08:53 +02:00
}
2004-02-10 02:11:28 +01:00
2016-12-06 14:50:50 +01:00
inline Color4 < double > Clamp ( Color4 < double > & c )
{
c [ 0 ] = math : : Clamp ( c [ 0 ] , 0.0 , 1.0 ) ;
c [ 1 ] = math : : Clamp ( c [ 1 ] , 0.0 , 1.0 ) ;
c [ 2 ] = math : : Clamp ( c [ 2 ] , 0.0 , 1.0 ) ;
c [ 3 ] = math : : Clamp ( c [ 3 ] , 0.0 , 1.0 ) ;
return c ;
}
2008-07-09 17:18:08 +02:00
template < >
inline Color4 < unsigned char > Color4 < unsigned char > : : operator + ( const Color4 < unsigned char > & p ) const
make point2 derived Eigen's Matrix, and a set of minimal fixes to make meshlab compile
with both old and new version. The fixes include:
- dot product: vec0 * vec1 => vec0.dot(vec1) (I added .dot() to the old Point classes too)
- Transpose: Transpose is an Eigen type, so we cannot keep it if Eigen is used. Therefore
I added a .tranpose() to old matrix classes, and modified most of the Transpose() to transpose()
both in vcg and meshlab. In fact, transpose() are free with Eigen, it simply returns a transpose
expression without copies. On the other be carefull: m = m.transpose() won't work as expected,
here me must evaluate to a temporary: m = m.transpose().eval(); However, this operation in very
rarely needed: you transpose at the same sime you set m, or you use m.transpose() directly.
- the last issue is Normalize which both modifies *this and return a ref to it. This behavior
don't make sense anymore when using expression template, e.g., in (a+b).Normalize(), the type
of a+b if not a Point (or whatever Vector types), it an expression of the addition of 2 points,
so we cannot modify the value of *this, since there is no value. Therefore I've already changed
all those .Normalize() of expressions to the Eigen's version .normalized().
- Finally I've changed the Zero to SetZero in the old Point classes too.
2008-10-28 01:59:46 +01:00
{
2014-06-24 10:46:49 +02:00
return Color4 < unsigned char > (
( unsigned char ) ( math : : Clamp ( int ( ( * this ) [ 0 ] ) + int ( p [ 0 ] ) , 0 , 255 ) ) ,
( unsigned char ) ( math : : Clamp ( int ( ( * this ) [ 1 ] ) + int ( p [ 1 ] ) , 0 , 255 ) ) ,
( unsigned char ) ( math : : Clamp ( int ( ( * this ) [ 2 ] ) + int ( p [ 2 ] ) , 0 , 255 ) ) ,
( unsigned char ) ( math : : Clamp ( int ( ( * this ) [ 3 ] ) + int ( p [ 3 ] ) , 0 , 255 ) )
) ;
2008-07-09 17:18:08 +02:00
}
2004-02-10 02:11:28 +01:00
typedef Color4 < unsigned char > Color4b ;
2012-10-19 13:52:57 +02:00
typedef Color4 < float > Color4f ;
typedef Color4 < double > Color4d ;
2004-02-10 02:11:28 +01:00
2012-11-27 08:05:38 +01:00
template < >
2021-03-18 18:30:54 +01:00
inline unsigned short Color4 < unsigned char > : : ToUnsignedB5G5R5 ( const Color4 < unsigned char > & cc )
2012-11-27 08:05:38 +01:00
{
unsigned short r = cc [ 0 ] / 8 ;
unsigned short g = cc [ 1 ] / 8 ;
unsigned short b = cc [ 2 ] / 8 ;
unsigned short res = b + g * 32 + r * 1024 ;
return res ;
}
template < >
2021-03-18 18:30:54 +01:00
inline unsigned short Color4 < unsigned char > : : ToUnsignedR5G5B5 ( const Color4 < unsigned char > & cc )
2012-11-27 08:05:38 +01:00
{
unsigned short r = cc [ 0 ] / 8 ;
unsigned short g = cc [ 1 ] / 8 ;
unsigned short b = cc [ 2 ] / 8 ;
unsigned short res = r + g * 32 + b * 1024 ;
return res ;
}
template < >
inline Color4 < unsigned char > Color4 < unsigned char > : : FromUnsignedR5G5B5 ( unsigned short val )
{
unsigned short r = val % 32 * 8 ;
unsigned short g = ( ( val / 32 ) % 32 ) * 8 ;
unsigned short b = ( ( val / 1024 ) % 32 ) * 8 ;
Color4b cc ( ( unsigned char ) r , ( unsigned char ) g , ( unsigned char ) b , ( unsigned char ) 255 ) ;
return cc ;
}
template < >
inline Color4 < unsigned char > Color4 < unsigned char > : : FromUnsignedB5G5R5 ( unsigned short val )
{
unsigned short b = val % 32 * 8 ;
unsigned short g = ( ( val / 32 ) % 32 ) * 8 ;
unsigned short r = ( ( val / 1024 ) % 32 ) * 8 ;
Color4b cc ( ( unsigned char ) r , ( unsigned char ) g , ( unsigned char ) b , ( unsigned char ) 255 ) ;
return cc ;
}
2004-03-10 22:38:40 +01:00
/*@}*/
2004-02-10 02:11:28 +01:00
} // end of NameSpace
2004-03-10 01:35:01 +01:00
# endif