Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Hurstel
CGoGN
Commits
167905bb
Commit
167905bb
authored
Jan 11, 2012
by
Kenneth Vanhoey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated comments
parent
7a24e258
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
45 deletions
+57
-45
include/Utils/colourConverter.h
include/Utils/colourConverter.h
+29
-27
include/Utils/colourConverter.hpp
include/Utils/colourConverter.hpp
+28
-18
No files found.
include/Utils/colourConverter.h
View file @
167905bb
...
...
@@ -25,26 +25,21 @@
#ifndef __COLOURCONVERTER_H__
#define __COLOURCONVERTER_H__
#include <iostream>
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
#include "Utils/cgognStream.h"
// #define DISPLAY
namespace
CGoGN
{
namespace
Utils
{
/**
* Supported colour spaces
*/
enum
ColourEncoding
{
C_RGB
=
0
,
C_XYZ
=
1
,
C_Luv
=
2
,
C_Lab
=
3
}
;
/**
/*!
* \class ColourConverter
* \brief Class for switching between different tri-channel color-spaces
*
* Class for colour conversions between the enumerated colour spaces.
* Usage :
* VEC3 colRGB ; // current colour in RGB for example
...
...
@@ -56,34 +51,45 @@ enum ColourEncoding
template
<
typename
REAL
>
class
ColourConverter
{
public:
// types
typedef
Geom
::
Vector
<
3
,
REAL
>
VEC3
;
/**
* \enum ColourEncoding
* Supported colour spaces
*/
enum
ColourEncoding
{
C_RGB
=
0
,
C_XYZ
=
1
,
C_Luv
=
2
,
C_Lab
=
3
}
;
typedef
Geom
::
Vector
<
3
,
REAL
>
VEC3
;
/*!< Triplet for color encoding */
public:
// methods
/**
* Constructor
*
\brief
Constructor
* @param col a VEC3 colour
* @param enc the colour space of provided colour
*/
ColourConverter
(
VEC3
col
,
enum
ColourEncoding
enc
)
;
ColourConverter
(
const
VEC3
&
col
,
const
enum
ColourEncoding
&
enc
)
;
/**
* Destructor
*
\brief
Destructor
*/
~
ColourConverter
()
;
/**
* getR
*
\brief
getR
* @return original value (in its original space)
*/
VEC3
getOriginal
()
;
/**
* getR
* @return
enc
value of provided colour
*
\brief
getR
* @return value of provided colour
*/
VEC3
getColour
(
enum
ColourEncoding
enc
)
;
/**
* getR
*
\brief
getR
* @return RGB value of provided colour
*/
VEC3
getRGB
()
;
...
...
@@ -104,10 +110,7 @@ public: // methods
VEC3
getXYZ
()
;
public:
// members
/**
* Colour space of original (unaltered) data
*/
enum
ColourEncoding
originalEnc
;
enum
ColourEncoding
originalEnc
;
/*!< Colour space of original (unaltered) data */
private:
// private members
VEC3
*
RGB
;
...
...
@@ -126,7 +129,6 @@ private: // private members
void
convertLabToXYZ
()
;
private:
// private constants
// D65 reference white
static
const
REAL
Xn
=
0.950456
;
static
const
REAL
Yn
=
1.0
;
...
...
include/Utils/colourConverter.hpp
View file @
167905bb
...
...
@@ -23,10 +23,11 @@
*******************************************************************************/
namespace
CGoGN
{
namespace
Utils
{
template
<
typename
REAL
>
ColourConverter
<
REAL
>::
ColourConverter
(
VEC3
col
,
enum
ColourEncoding
enc
)
:
ColourConverter
<
REAL
>::
ColourConverter
(
const
VEC3
&
col
,
const
enum
ColourEncoding
&
enc
)
:
RGB
(
NULL
),
Luv
(
NULL
),
Lab
(
NULL
),
...
...
@@ -36,26 +37,34 @@ ColourConverter<REAL>::ColourConverter(VEC3 col, enum ColourEncoding enc) :
switch
(
originalEnc
)
{
case
(
C_RGB
):
if
(
!
(
-
0.001
<
col
[
0
]
&&
col
[
0
]
<
1.001
&&
-
0.001
<
col
[
1
]
&&
col
[
1
]
<
1.001
&&
-
0.001
<
col
[
2
]
&&
col
[
2
]
<
1.001
))
CGoGNerr
<<
"Warning : an unvalid RGB color was entered in ColourConverter constructor"
<<
CGoGNendl
;
#ifdef DEBUG
if
(
!
(
-
0.001
<
col
[
0
]
&&
col
[
0
]
<
1.001
&&
-
0.001
<
col
[
1
]
&&
col
[
1
]
<
1.001
&&
-
0.001
<
col
[
2
]
&&
col
[
2
]
<
1.001
))
std
::
cerr
<<
"Warning : an unvalid RGB color was entered in ColourConverter constructor"
<<
std
::
endl
;
#endif
RGB
=
new
VEC3
(
col
)
;
break
;
case
(
C_Luv
)
:
if
(
!
(
-
0.001
<
col
[
0
]
&&
col
[
0
]
<
100.001
&&
-
83.001
<
col
[
1
]
&&
col
[
1
]
<
175.001
&&
-
134.001
<
col
[
2
]
&&
col
[
2
]
<
108.001
))
CGoGNerr
<<
"Warning : an unvalid Luv color was entered in ColourConverter constructor"
<<
CGoGNendl
;
#ifdef DEBUG
if
(
!
(
-
0.001
<
col
[
0
]
&&
col
[
0
]
<
100.001
&&
-
83.001
<
col
[
1
]
&&
col
[
1
]
<
175.001
&&
-
134.001
<
col
[
2
]
&&
col
[
2
]
<
108.001
))
std
::
cerr
<<
"Warning : an unvalid Luv color was entered in ColourConverter constructor"
<<
std
::
endl
;
#endif
Luv
=
new
VEC3
(
col
)
;
break
;
case
(
C_XYZ
)
:
if
(
!
(
-
0.001
<
col
[
0
]
&&
col
[
0
]
<
1.001
&&
-
0.001
<
col
[
1
]
&&
col
[
1
]
<
1.001
&&
-
0.001
<
col
[
2
]
&&
col
[
2
]
<
1.001
))
CGoGNerr
<<
"Warning : an unvalid XYZ color was entered in ColourConverter constructor"
<<
CGoGNendl
;
#ifdef DEBUG
if
(
!
(
-
0.001
<
col
[
0
]
&&
col
[
0
]
<
1.001
&&
-
0.001
<
col
[
1
]
&&
col
[
1
]
<
1.001
&&
-
0.001
<
col
[
2
]
&&
col
[
2
]
<
1.001
))
std
::
cerr
<<
"Warning : an unvalid XYZ color was entered in ColourConverter constructor"
<<
std
::
endl
;
#endif
XYZ
=
new
VEC3
(
col
)
;
break
;
case
(
C_Lab
)
:
if
(
!
(
-
0.001
<
col
[
0
]
&&
col
[
0
]
<
100.001
&&
-
86.001
<
col
[
1
]
&&
col
[
1
]
<
98.001
&&
-
108.001
<
col
[
2
]
&&
col
[
2
]
<
95.001
))
CGoGNerr
<<
"Warning : an unvalid Lab color was entered in ColourConverter constructor"
<<
CGoGNendl
;
#ifdef DEBUG
if
(
!
(
-
0.001
<
col
[
0
]
&&
col
[
0
]
<
100.001
&&
-
86.001
<
col
[
1
]
&&
col
[
1
]
<
98.001
&&
-
108.001
<
col
[
2
]
&&
col
[
2
]
<
95.001
))
std
::
cerr
<<
"Warning : an unvalid Lab color was entered in ColourConverter constructor"
<<
std
::
endl
;
#endif
Lab
=
new
VEC3
(
col
)
;
break
;
}
...
...
@@ -281,8 +290,10 @@ void ColourConverter<REAL>::convertLabToXYZ() {
template
<
typename
REAL
>
bool
ColourConverter
<
REAL
>::
convert
(
enum
ColourEncoding
from
,
enum
ColourEncoding
to
)
{
if
(
to
==
from
)
{
CGoGNerr
<<
"ColourConverter::convert(from,to) : conversion into same colour space"
<<
CGoGNendl
;
return
false
;
#ifdef DEBUG
std
::
cout
<<
"WARNING ColourConverter::convert(from,to) : conversion into same colour space"
<<
std
::
endl
;
#endif
return
true
;
}
switch
(
from
)
{
...
...
@@ -305,7 +316,7 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin
convertXYZtoLab
()
;
break
;
default
:
CGoGN
err
<<
"Colour conversion not supported"
<<
CGoGN
endl
;
std
::
c
err
<<
"Colour conversion not supported"
<<
std
::
endl
;
return
false
;
}
break
;
...
...
@@ -333,7 +344,7 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin
}
break
;
default
:
CGoGN
err
<<
"Colour conversion not supported"
<<
CGoGN
endl
;
std
::
c
err
<<
"Colour conversion not supported"
<<
std
::
endl
;
return
false
;
}
break
;
...
...
@@ -353,7 +364,7 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin
convertXYZtoLab
()
;
break
;
default
:
CGoGN
err
<<
"Colour conversion not supported"
<<
CGoGN
endl
;
std
::
c
err
<<
"Colour conversion not supported"
<<
std
::
endl
;
return
false
;
}
break
;
...
...
@@ -381,22 +392,21 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin
}
break
;
default
:
CGoGN
err
<<
"Colour conversion not supported"
<<
CGoGN
endl
;
std
::
c
err
<<
"Colour conversion not supported"
<<
std
::
endl
;
return
false
;
}
break
;
default
:
CGoGN
err
<<
"Colour conversion not supported"
<<
CGoGN
endl
;
std
::
c
err
<<
"Colour conversion not supported"
<<
std
::
endl
;
return
false
;
}
return
true
;
}
}
// namespace Utils
}
// namespace CGoGN
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment