colourConverter.hpp 13.1 KB
Newer Older
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* This library 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 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library 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 this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
21 22 23 24 25
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
26

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
27 28 29
namespace Utils {

template<typename REAL>
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
30
ColourConverter<REAL>::ColourConverter(const VEC3& col, const enum ColourEncoding& enc) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
31 32
	RGB(NULL),
	Luv(NULL),
33
	Lab(NULL),
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
34
	HSV(NULL),
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
35 36 37 38 39 40
	XYZ(NULL)
{
	originalEnc = enc ;

	switch(originalEnc) {
		case(C_RGB):
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
41 42 43 44
			#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
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
45 46 47 48
			RGB = new VEC3(col) ;
			break ;

		case (C_Luv) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
49 50 51 52
			#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
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
53 54 55 56
			Luv = new VEC3(col) ;
			break ;

		case (C_XYZ) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
57 58 59 60
			#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
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
61 62
			XYZ = new VEC3(col) ;
			break ;
63 64

		case (C_Lab) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
65 66 67 68
			#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
69 70
			Lab = new VEC3(col) ;
			break ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
71 72 73 74 75 76 77 78
		case (C_HSV) :
			#ifdef DEBUG
				if (!(-0.001 < col[0] && col[0] < 360.001 && -0.001 < col[1] && col[1] < 1.001 && -0.001 < col[2] && col[2] < 1.001))
						std::cerr << "Warning : an unvalid Lab color was entered in ColourConverter constructor" << std::endl ;
			#endif
			HSV = new VEC3(col) ;
			break ;

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
79 80 81
	}
}

82 83 84 85 86 87 88
template<typename REAL>
ColourConverter<REAL>::~ColourConverter()
{
	delete RGB ;
	delete Luv ;
	delete XYZ ;
	delete Lab ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
89
	delete HSV ;
90 91
}

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
template<typename REAL>
Geom::Vector<3,REAL> ColourConverter<REAL>::getColour(enum ColourEncoding enc) {
	switch (enc) {
	case (C_RGB) :
		return getRGB() ;
		break ;

	case (C_XYZ) :
		return getXYZ() ;
		break ;

	case (C_Luv) :
		return getLuv() ;
		break ;

	case (C_Lab) :
		return getLab() ;
		break ;

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
111 112 113 114
	case (C_Lab) :
		return getHSV() ;
		break ;

115 116 117 118 119 120 121 122 123 124 125
	default :
		assert(!"Should never arrive here : ColourConverter::getColour default case") ;
		return getOriginal() ;
	}
}

template<typename REAL>
Geom::Vector<3,REAL> ColourConverter<REAL>::getOriginal() {
	return getColour(this->originalEnc) ;
}

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
template<typename REAL>
Geom::Vector<3,REAL> ColourConverter<REAL>::getRGB() {
	if (RGB == NULL)
		convert(originalEnc,C_RGB) ;

	return *RGB ;
}

template<typename REAL>
Geom::Vector<3,REAL> ColourConverter<REAL>::getLuv() {
	if (Luv == NULL)
		convert(originalEnc,C_Luv) ;

	return *Luv ;
}

142 143
template<typename REAL>
Geom::Vector<3,REAL> ColourConverter<REAL>::getLab() {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
144
	if (Lab == NULL)
145 146
		convert(originalEnc,C_Lab) ;

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
147
	return *Lab ;
148 149
}

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
150 151 152 153 154 155 156 157 158
template<typename REAL>
Geom::Vector<3,REAL> ColourConverter<REAL>::getXYZ() {
	if (XYZ == NULL) {
		convert(originalEnc,C_XYZ) ;
	}

	return *XYZ ;
}

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
159 160 161 162 163 164 165 166
template<typename REAL>
Geom::Vector<3,REAL> ColourConverter<REAL>::getHSV() {
	if (HSV == NULL)
		convert(originalEnc,C_HSV) ;

	return *HSV ;
}

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
template<typename REAL>
void ColourConverter<REAL>::convertRGBtoXYZ() {
	Geom::Matrix<3,3,REAL> M ;

	M(0,0) = 0.412453 ;
	M(0,1) = 0.357580 ;
	M(0,2) = 0.180423 ;

	M(1,0) = 0.212671 ;
	M(1,1) = 0.715160 ;
	M(1,2) = 0.072169 ;

	M(2,0) = 0.019334 ;
	M(2,1) = 0.119193 ;
	M(2,2) = 0.950227 ;

	VEC3 c = M * (*RGB) ;

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
185 186 187 188
	if (XYZ != NULL)
		*XYZ = c ;
	else
		XYZ = new VEC3(c) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
}

template<typename REAL>
void ColourConverter<REAL>::convertXYZtoRGB() {
	Geom::Matrix<3,3,REAL> M ;

	M(0,0) = 3.240479 ;
	M(0,1) = -1.537150 ;
	M(0,2) = -0.498535 ;

	M(1,0) = -0.969256 ;
	M(1,1) = 1.875992 ;
	M(1,2) = 0.041556 ;

	M(2,0) = 0.055648 ;
	M(2,1) = -0.204043 ;
	M(2,2) = 1.057311 ;

	VEC3 c = M * (*XYZ) ;

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
209 210 211 212
	if (RGB != NULL)
		*RGB = c ;
	else
		RGB = new VEC3(c) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
213 214 215
}

template<typename REAL>
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
void ColourConverter<REAL>::convertRGBtoHSV()
{
	const REAL& r = (*RGB)[0] ;
	const REAL& g = (*RGB)[1] ;
	const REAL& b = (*RGB)[2] ;
	const REAL& max = std::max(std::max(r,g),b) ;
	const REAL& min = std::min(std::min(r,g),b) ;

	VEC3 c ;
	if (max == min)
	{
		c[0] = 0 ;
	}
	else if (max == r)
	{
		c[0] = 60 * (g - b) / (max - min) + 360 ;
		c[0] = (unsigned int)(c[0]) % 360 ;
	}
	else if (max == g)
	{
		c[0] = 60 * (b - r) / (max - min) + 120 ;
	}
	else if (max == b)
	{
		c[0] = 60 * (r - g) / (max - min) + 240 ;
	}

	c[1] = (max == 0) ? 0 : 1 - min/max ;
	c[2] = max ;

	if (HSV != NULL)
		*HSV = c ;
	else
		HSV = new VEC3(c) ;
}

template<typename REAL>
void ColourConverter<REAL>::convertHSVtoRGB()
{
	const REAL& H = (*HSV)[0] ;
	const REAL& s = (*HSV)[1] ;
	const REAL& v = (*HSV)[2] ;

	const unsigned int Hi = (unsigned int)(std::floor(H / 60)) % 6 ;
	const REAL f = (H / 60) - Hi ;
	const REAL l = v * (1 - s) ;
	const REAL m = v * (1 - f * s) ;
	const REAL n = v * (1 - (1 - f) * s) ;

	VEC3 c ;
	switch(Hi)
	{
		case(0) :
		{
			c = VEC3(v,n,l) ;
		}
		break ;
		case(1):
		{
			c = VEC3(m,v,l) ;
		}
		break ;
		case(2):
		{
			c = VEC3(l,v,n) ;
		}
		break ;
		case(3):
		{
			c = VEC3(l,m,v) ;
		}
		break ;
		case(4):
		{
			c = VEC3(n,l,v) ;
		}
		break ;

		case(5):
		{
			c = VEC3(v,l,m) ;
		}
		break ;

	}

	if (RGB != NULL)
		*RGB = c ;
	else
		RGB = new VEC3(c) ;
}

template<typename REAL>
void ColourConverter<REAL>::convertXYZtoLuv()
{
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
311 312 313 314 315 316
	REAL L,u,v ;

	REAL &X = (*XYZ)[0] ;
	REAL &Y = (*XYZ)[1] ;
	REAL &Z = (*XYZ)[2] ;

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
317 318
	REAL Ydiv = Y/Yn ;
	if (Ydiv > 0.008856)
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
319
		L = 116.0 * pow(Ydiv,1.0/3.0) - 16.0 ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
320
	else // near black
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
321
		L = 903.3 * Ydiv ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
322 323 324

	REAL den = X + 15.0 * Y + 3 * Z ;
	REAL u1 = (4.0 * X) / den ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
325 326 327
	REAL v1 = (9.0 * Y) / den ;
	u = 13*L * (u1 - un) ;
	v = 13*L * (v1 - vn) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
328

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
329 330 331 332
	if (Luv != NULL)
		*Luv = VEC3(L,u,v) ;
	else
		Luv = new VEC3(L,u,v) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
333 334 335
}

template<typename REAL>
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
336 337
void ColourConverter<REAL>::convertLuvToXYZ()
{
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
338 339 340 341 342 343 344 345 346
	REAL X,Y,Z ;

	REAL &L = (*Luv)[0] ;
	REAL &u = (*Luv)[1] ;
	REAL &v = (*Luv)[2] ;

	if (L > 8.0)
		Y = pow(((L+16.0) / 116.0),3) ;
	else // near black
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
347
		Y = Yn * L / 903.3 ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
348 349

	REAL den = 13.0 * L ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
350 351
	REAL u1 = u/den + un ;
	REAL v1 = v/den + vn ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
352
	den = 4.0*v1 ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
353
	X = Y * 9.0 * u1 / den ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
354
	Z = Y * (12.0 - 3.0*u1 - 20.0*v1) / den ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
355

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
356 357 358 359
	if (XYZ != NULL)
		*XYZ = VEC3(X,Y,Z) ;
	else
		XYZ = new VEC3(X,Y,Z) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
360 361
}

362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
template<typename REAL>
void ColourConverter<REAL>::convertXYZtoLab() {
	REAL L,a,b ;

	REAL &X = (*XYZ)[0] ;
	REAL &Y = (*XYZ)[1] ;
	REAL &Z = (*XYZ)[2] ;

	struct Local {
		static REAL f(REAL x) {
			if (x > 0.008856)
			return pow(x,1.0/3.0) ;
			else
				return 7.787 * x + 16.0/116.0 ;
		}
	} ;

	if (Y > 0.008856)
		L = 116.0f * pow(Y,1.0f/3.0) - 16 ;
	else // near black
		L = 903.3 * Y ;

	a = 500.0 * (Local::f(X/Xn) - Local::f(Y/Yn)) ;
	b = 200.0 * (Local::f(Y/Yn) - Local::f(Z/Zn)) ;

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
387 388 389 390
	if (Lab != NULL)
		*Lab = VEC3(L,a,b) ;
	else
		Lab = new VEC3(L,a,b) ;
391 392 393 394 395 396
}

template<typename REAL>
void ColourConverter<REAL>::convertLabToXYZ() {
	REAL X,Y,Z ;

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
397 398 399
	REAL &L = (*Lab)[0] ;
	REAL &a = (*Lab)[1] ;
	REAL &b = (*Lab)[2] ;
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418

	struct Local {
		static REAL f(REAL x) {
			if (x > 0.206893)
			return pow(x,3.0) ;
			else
				return x / 7.787 - 16.0/903.3 ;
		}
	} ;

	if (L > 8.0)
		Y = pow(((L+16.0) / 116.0),3) ;
	else // near black
		Y = L / 903.3 ;

	REAL nom = (L+16.0) / 116.0 ;
	X = Xn * Local::f( nom +  a/500.0) ;
	Z = Zn * Local::f( nom -  b/200.0) ;

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
419 420 421 422
	if (XYZ != NULL)
		*XYZ = VEC3(X,Y,Z) ;
	else
		XYZ = new VEC3(X,Y,Z) ;
423 424
}

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
425 426
template<typename REAL>
bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncoding to) {
427
	if (to == from) {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
428 429 430 431
		#ifdef DEBUG
			std::cout << "WARNING ColourConverter::convert(from,to) : conversion into same colour space" << std::endl ;
		#endif
		return true ;
432 433
	}

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
434 435 436 437 438 439 440 441 442
	switch(from) {
		case(C_RGB) :
			switch (to) {
				case (C_XYZ) :
					if (XYZ == NULL)
						convertRGBtoXYZ() ;
					break ;
				case (C_Luv) :
					if (Luv == NULL)
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
443 444 445
					{
						if (XYZ == NULL)
							convertRGBtoXYZ() ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
446
						convertXYZtoLuv() ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
447
					}
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
448
					break ;
449 450
				case(C_Lab) :
					if (Lab == NULL)
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
451 452 453
					{
						if (XYZ == NULL)
							convertRGBtoXYZ() ;
454
						convertXYZtoLab() ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
455 456 457 458 459
					}
				break ;
				case(C_HSV) :
					if (HSV == NULL)
						convertRGBtoHSV() ;
460
					break ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
461
				default :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
462
					std::cerr << "Colour conversion not supported" << std::endl ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
					return false ;
			}
			break ;

		case(C_Luv) :
			switch(to) {
				case(C_RGB) : {
					if (RGB == NULL) {
						if (XYZ == NULL)
							convertLuvToXYZ() ;
						convertXYZtoRGB() ;
					}
					break ;
				}
				case(C_XYZ) : {
					if (XYZ == NULL)
						convertLuvToXYZ() ;
					break ;
				}
482 483 484 485 486 487 488
				case(C_Lab) :
					if (Lab == NULL) {
						if (XYZ == NULL)
							convertLuvToXYZ() ;
						convertXYZtoLab() ;
					}
					break ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
489 490 491 492 493 494 495 496 497 498 499
				case(C_HSV) : {
					if (HSV == NULL) {
						if (RGB == NULL) {
							if (XYZ == NULL)
								convertLuvToXYZ() ;
							convertXYZtoRGB() ;
						}
						convertRGBtoHSV() ;
					}
					break ;
				}
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
500
				default :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
501
					std::cerr << "Colour conversion not supported" << std::endl ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
502 503 504 505 506 507 508 509 510 511 512 513 514 515
					return false ;
			}
			break ;

		case(C_XYZ) :
			switch (to) {
				case(C_RGB) :
					if (RGB==NULL)
						convertXYZtoRGB() ;
					break ;
				case(C_Luv) :
					if (Luv == NULL)
						convertXYZtoLuv() ;
					break ;
516 517 518 519
				case(C_Lab) :
					if (Lab == NULL)
						convertXYZtoLab() ;
					break ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
520 521 522 523 524 525 526
				case(C_HSV) :
						if (HSV==NULL) {
							if (RGB==NULL)
								convertXYZtoRGB() ;
							convertRGBtoHSV() ;
						}
					break ;
527
				default :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
528
					std::cerr << "Colour conversion not supported" << std::endl ;
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
					return false ;
			}
			break ;

		case(C_Lab) :
			switch (to) {
				case(C_RGB) : {
					if (RGB == NULL) {
						if (XYZ == NULL)
							convertLabToXYZ() ;
						convertXYZtoRGB() ;
					}
					break ;
				}
				case(C_XYZ) : {
					if (XYZ == NULL)
						convertLabToXYZ() ;
					break ;
				}
				case(C_Luv) :
					if (Luv == NULL) {
						if (XYZ == NULL)
							convertLabToXYZ() ;
						convertXYZtoLuv() ;
					}
					break ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
555 556 557 558 559 560 561 562 563 564 565 566
				case(C_HSV) : {
					if (HSV == NULL) {
						if (RGB == NULL) {
							if (XYZ == NULL)
								convertLabToXYZ() ;
							convertXYZtoRGB() ;
						}
						convertRGBtoHSV() ;
					}
					break ;
				}

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
567
				default :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
568
					std::cerr << "Colour conversion not supported" << std::endl ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
569 570 571
					return false ;
			}
			break ;
572

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
		case(C_HSV) :
				switch (to) {
					case(C_RGB) : {
						if (RGB == NULL) {
							convertHSVtoRGB() ;
						}
						break ;
					}
					case(C_XYZ) : {
						if (XYZ == NULL)
						{
							if (RGB == NULL)
								convertHSVtoRGB() ;
							convertRGBtoXYZ() ;
						}
						break ;
					}
					case(C_Lab) :
						if (Lab == NULL) {
							if (XYZ == NULL)
							{
								if (RGB == NULL)
								{
									convertHSVtoRGB() ;
								}
								convertRGBtoXYZ() ;
							}
							convertXYZtoLab() ;
						}
						break ;
					case(C_Luv) :
						if (Luv == NULL) {
							if (XYZ == NULL)
							{
								if (RGB == NULL)
								{
									convertHSVtoRGB() ;
								}
								convertRGBtoXYZ() ;
							}
							convertXYZtoLuv() ;
						}
						break ;
					default :
						std::cerr << "Colour conversion not supported" << std::endl ;
						return false ;
				}
				break ;

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
622
		default :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
623
			std::cerr << "Colour conversion not supported" << std::endl ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
624 625 626 627 628 629 630
			return false ;
	}

	return true ;
}

} // namespace Utils
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
631

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
632 633 634
} // namespace CGoGN