quadricRGBfunctions.hpp 12 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * quadricLF.hpp
 *
 *  Created on: Nov 4, 2010
 *      Author: kenneth
 */

#ifndef QUADRICLF_HPP_
#define QUADRICLF_HPP_

template <typename REAL>
std::string QuadricRGBfunctions<REAL>::CGoGNnameOfType() {
	return std::string("QuadricColFuncs");
}

template <typename REAL>
QuadricRGBfunctions<REAL>::QuadricRGBfunctions() {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
18 19 20
	for (unsigned i = 0; i < 6; ++i)
		for (unsigned j = 0; j < 6; ++j)
			A(i,j) = REAL(0) ;
21

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
22
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
Pierre Kraemer's avatar
Pierre Kraemer committed
23
		for (unsigned i = 0; i < 6; ++i) {
24
			b[col][i] = REAL(0) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
25 26 27 28 29 30 31 32 33 34 35 36 37
		}

		c[col] = REAL(0);
	}
}

template <typename REAL>
QuadricRGBfunctions<REAL>::QuadricRGBfunctions(int i) {
	QuadricRGBfunctions();
}

template <typename REAL>
QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const QuadricRGBfunctions& q) {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
38 39 40 41
	for (unsigned i = 0; i < 6; ++i)
		for (unsigned j = 0; j < 6; ++j)
			A(i,j) = q.A(i,j) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
42
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
43

Pierre Kraemer's avatar
Pierre Kraemer committed
44
		for (unsigned i = 0; i < 6; ++i) {
45
			b[col][i] = q.b[col][i] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
46 47
		}

48
		c[col] = q.c[col] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
49 50 51 52
	}
}

template <typename REAL>
53
QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, const REAL gamma, const REAL alpha) {
Pierre Kraemer's avatar
Pierre Kraemer committed
54 55
	MATRIX66 R1,R2_A,R2_b,R2_c;

56
	buildRotateMatrix(R1,gamma); // Rotation 1
57

58 59 60
	buildIntegralMatrix_A(R2_A,alpha); // Parameterized integral matrix A
	buildIntegralMatrix_b(R2_b,alpha); // Parameterized integral matrix b
	buildIntegralMatrix_c(R2_c,alpha); // Parameterized integral matrix c
Pierre Kraemer's avatar
Pierre Kraemer committed
61

62
	// Quadric (A,b,c) => L*A*Lt - 2*b*Lt + c = ERROR
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
63
	A = R2_A ; // Matrix A : integral
Pierre Kraemer's avatar
Pierre Kraemer committed
64
	for (unsigned col = RED; col < BLUE+1; ++col) {
65
		Geom::Vector<6,REAL> function; // get function coefficients
66 67
		if (!cf.getSubVectorH(col,0,function))
			assert(!"QuadricRGBfunctions::constructor") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
68

69
		VEC6 coefs = R1 * function ; // Rotation 1
Pierre Kraemer's avatar
Pierre Kraemer committed
70

71 72
		b[col] = R2_b * function ;	// Vector b : integral + rotation on 1 vector
		c[col] = function * (R2_c * function) ;	// Scalar c : integral + rotation on 2 vectors
Pierre Kraemer's avatar
Pierre Kraemer committed
73 74 75 76 77 78 79 80
	}
}

template <typename REAL>
REAL QuadricRGBfunctions<REAL>::operator() (const RGBFUNCTIONS& cf) const {
	REAL res = REAL(0);

	for (unsigned col = RED; col < BLUE+1; ++col) {
81
		Geom::Vector<6,REAL> function ; // Get function coefficients
82 83
		if (!cf.getSubVectorH(col,0,function))
			assert (!"QuadricRGBfunctions::getSubVectorH") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
84 85

		REAL res_local = REAL(0) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
86
		res_local += function * (A * function) ; // l*A*lt
87 88 89
		res_local -= 2 * (function * b[col]) ; // -2*l*b
		res_local += c[col] ; // c
		// res = l*A*lT - 2*l*b + c
Pierre Kraemer's avatar
Pierre Kraemer committed
90 91 92 93 94 95 96 97
		res += res_local;
	}

	return res;
}

template <typename REAL>
bool QuadricRGBfunctions<REAL>::findOptimizedRGBfunctions(RGBFUNCTIONS& cf) const {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
98
	MATRIX66 Ainv ;
Pierre Kraemer's avatar
Pierre Kraemer committed
99

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
100 101 102
	REAL det = A.invert(Ainv) ; // Invert matrix
	if(det > -1e-8 && det < 1e-8)
		return false ; // invert failed
Pierre Kraemer's avatar
Pierre Kraemer committed
103

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
104
	for (unsigned  col = RED; col < BLUE+1 ; ++col) {
Pierre Kraemer's avatar
Pierre Kraemer committed
105

106
		VEC6 coefs = Ainv * b[col]; // function = A^(-1) * b
Pierre Kraemer's avatar
Pierre Kraemer committed
107

108
		if (!cf.setSubVectorH(col,0,coefs)) // save in argument cf
109
			assert (!"QuadricRGBfunctions::findOptimizedRGBfunctions(cf) setSubVector failed") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
110 111 112 113 114 115
	}

	return true;
}

template <typename REAL>
116 117 118 119
void QuadricRGBfunctions<REAL>::buildIntegralMatrix_A(MATRIX66 &M, const REAL alpha) const {
	// Int(phi=0..pi)(theta=0..pi-alpha) variables^2 dTheta dPhi      if alpha > 0
	// Int(phi=0..pi)(theta= -alpha..pi) variables^2 dTheta dPhi      if alpha < 0

Pierre Kraemer's avatar
Pierre Kraemer committed
120 121 122 123 124 125
	REAL alphaAbs = alpha > 0 ? alpha : -alpha;

	const REAL pi = 3.141592 ;

	const REAL cosinus = cos(alpha);
	const REAL sinus = sin(alpha);
126
	const REAL sinAbs = sin(alphaAbs); // = - sin(alpha) si alpha < 0
Pierre Kraemer's avatar
Pierre Kraemer committed
127 128 129 130

	// Line 1
	M(0,0) = 2.0*(pi-alphaAbs)/5.0f;

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
	M(0,1) = 2.0 * (pi - alphaAbs - cosinus*sinAbs) / 15.0 ;

	M(0,2) = 0;

	M(0,3) = 0;

	M(0,4) = sinAbs*pi / 8.0;

	M(0,5) = 2.0*(pi-alphaAbs)/3.0;

	// Line 2
	M(1,0) = M(0,1);

	M(1,1) = (-4.0 * sinAbs*cosinus*cosinus*cosinus + 6.0 * (pi - cosinus*sinAbs - alphaAbs)) / 15.0 ;

	M(1,2) = REAL(0);

	M(1,3) = REAL(0);

	M(1,4) = (sinus*cosinus*cosinus*pi + 2*sinus*pi) / 8.0;

	M(1,5) = 2.0*(pi-cosinus*sinAbs-alphaAbs)/3.0;

	// LINE 3
	M(2,0) = REAL(0);

	M(2,1) = REAL(0);

	M(2,2) = 2.0*(pi - alphaAbs - cosinus*sinAbs)/15.0;

	M(2,3) = pi*sinus/8.0f;

	M(2,4) = REAL(0) ;

	M(2,5) = REAL(0) ;

	// Line 4
	M(3,0) = REAL(0) ;

	M(3,1) = REAL(0) ;

	M(3,2) = M(2,3);

	M(3,3) = 2.0*(pi-alphaAbs)/3.0 ;

	M(3,4) = REAL(0) ;

	M(3,5) = REAL(0) ;

	// Line 5
	M(4,0) = M(0,4) ;

	M(4,1) = M(1,4) ;

	M(4,2) = REAL(0) ;

	M(4,3) = REAL(0) ;

	M(4,4) = 2.0 * (pi - cosinus*sinAbs - alphaAbs ) / 3.0 ;

	M(4,5) = pi*sinus / 2.0 ;

	// Line 6
	M(5,0) = M(0,5) ;

	M(5,1) = M(1,5) ;

	M(5,2) = REAL(0) ;

	M(5,3) = REAL(0) ;

	M(5,4) = M(4,5) ;

	M(5,5) = 2.0*(pi-alphaAbs);

/*	// Line 1
	M(0,0) = 2.0*(pi-alphaAbs)/5.0f;

Pierre Kraemer's avatar
Pierre Kraemer committed
209 210 211 212 213 214 215 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
	M(0,1) = 2.0 * (pi - alphaAbs - cosAbs*sinus) / 15.0 ;

	M(0,2) = 0;

	M(0,3) = 0;

	M(0,4) = - sinus*pi / 8.0;

	M(0,5) = 2.0*(pi-alphaAbs)/3.0;

	// Line 2
	M(1,0) = M(0,1);

	M(1,1) = -4.0 * sinus*cosAbs*cosAbs*cosAbs / 15.0 + 2.0 * (pi - cosAbs*sinus - alphaAbs) / 5.0 ;

	M(1,2) = 0;

	M(1,3) = 0;

	M(1,4) = -(sinus*cosinus*cosinus*pi + 2*sinus*pi) / 8.0;

	M(1,5) = 2.0*(pi-cosAbs*sinus-alphaAbs)/3.0;

	// LINE 3
	M(2,0) = REAL(0);

	M(2,1) = REAL(0);

	M(2,2) = 2.0*(pi - alphaAbs - cosAbs*sinus)/15.0;

	M(2,3) = -pi*sinus/8.0f;

	M(2,4) = REAL(0) ;

	M(2,5) = REAL(0) ;

	// Line 4
	M(3,0) = REAL(0) ;

	M(3,1) = REAL(0) ;

	M(3,2) = M(2,3);

	M(3,3) = 2.0*(pi-alphaAbs)/3.0 ;

	M(3,4) = REAL(0) ;

	M(3,5) = REAL(0) ;

	// Line 5
	M(4,0) = - M(0,4) ;

	M(4,1) = - (2*pi*sinus + sinus*cosinus*cosinus*pi ) / 8.0 ;

	M(4,2) = REAL(0) ;

	M(4,3) = REAL(0) ;

	M(4,4) = 2.0 * (pi - cosAbs*sinus - alphaAbs ) / 3.0 ;

	M(4,5) = - pi*sinus / 2.0 ;

	// Line 6
	M(5,0) = M(0,5) ;

	M(5,1) = M(1,5) ;

	M(5,2) = REAL(0) ;

	M(5,3) = REAL(0) ;

	M(5,4) = M(4,5) ;

	M(5,5) = 2.0*(pi-alphaAbs);
283
*/
Pierre Kraemer's avatar
Pierre Kraemer committed
284 285 286 287
}


template <typename REAL>
288 289 290
void QuadricRGBfunctions<REAL>::buildIntegralMatrix_b(MATRIX66 &M, const REAL alpha) const {
	// Int(phi=0..pi)(theta=0..pi-alpha) variables*variablesRotated dTheta dPhi * coefs     if alpha > 0
	// Int(phi=0..pi)(theta= -alpha..pi) variables*variablesRotated dTheta dPhi * coefs     if alpha < 0
Pierre Kraemer's avatar
Pierre Kraemer committed
291 292 293 294
	REAL alphaAbs = alpha > 0 ? alpha : -alpha;

	const REAL pi = 3.141592 ;

295 296 297 298 299 300 301
	const REAL cosinus = cos(alpha) ;
	const REAL cos2 = cosinus*cosinus ;
	const REAL cos3 = cos2*cosinus ;
	const REAL cos4 = cos3*cosinus ;
	const REAL cos5 = cos4*cosinus ;
	const REAL sinus = sin(alpha) ;
	const REAL sinAbs = sin(alphaAbs) ; // = - sin(alpha) si alpha < 0
Pierre Kraemer's avatar
Pierre Kraemer committed
302 303 304 305

	// Line 1
	M(0,0) = 2.0*(pi-alphaAbs)/5.0f;

306
	M(0,1) = ( 6*cosinus*sinAbs - 8*sinAbs*cos3 - 2*alphaAbs + 2*pi ) / 15.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
307 308 309 310 311

	M(0,2) = 0;

	M(0,3) = 0;

312
	M(0,4) = (sinus*pi + 2*pi*cosinus*sinus) / 8.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
313 314 315 316

	M(0,5) = 2.0*(pi-alphaAbs)/3.0;

	// Line 2
317
	M(1,0) = 2 * (pi - cosinus*sinAbs - alphaAbs ) / 15.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
318

319
	M(1,1) = ( 6*cosinus*sinAbs - 2*alphaAbs + 2*pi - 16*sinAbs*cos5+4*cos2*pi  - 4*alphaAbs * cos2 ) / 15.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
320 321 322 323 324

	M(1,2) = 0;

	M(1,3) = 0;

325
	M(1,4) = (sinus*pi + 2* (pi*sinus*cos3+pi*cosinus*sinus)) / 8.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
326

327
	M(1,5) = 2.0*(pi-cosinus*sinAbs-alphaAbs) / 3.0;
Pierre Kraemer's avatar
Pierre Kraemer committed
328 329 330 331 332 333

	// LINE 3
	M(2,0) = REAL(0);

	M(2,1) = REAL(0);

334
	M(2,2) = 2 * (sinAbs - cosinus*alphaAbs + cosinus*pi - 2*cos2*sinAbs) / 15.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
335

336
	M(2,3) = pi*sinus / 8.0f;
Pierre Kraemer's avatar
Pierre Kraemer committed
337 338 339 340 341 342 343 344 345 346

	M(2,4) = REAL(0) ;

	M(2,5) = REAL(0) ;

	// Line 4
	M(3,0) = REAL(0) ;

	M(3,1) = REAL(0) ;

347
	M(3,2) = ( sinus*pi + 2*pi*cosinus*sinus ) / 8.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
348 349 350 351 352 353 354 355

	M(3,3) = 2.0*(pi-alphaAbs)/3.0 ;

	M(3,4) = REAL(0) ;

	M(3,5) = REAL(0) ;

	// Line 5
356
	M(4,0) = pi*sinus / 8.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
357

358
	M(4,1) = (sinus*pi + 4 * sinus * cos4 + 2*pi*cosinus*sinus) / 8.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
359 360 361 362 363

	M(4,2) = REAL(0) ;

	M(4,3) = REAL(0) ;

364
	M(4,4) = 2*(sinAbs - cosinus*alphaAbs + cosinus*pi - 2*cos2*sinAbs) / 3.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
365 366 367 368 369 370

	M(4,5) = pi*sinus / 2.0 ;

	// Line 6
	M(5,0) = M(0,5) ;

371
	M(5,1) = 2*cosinus*sinAbs + 2*(pi-4*sinAbs*cos3-alphaAbs) / 3.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
372 373 374 375 376

	M(5,2) = REAL(0) ;

	M(5,3) = REAL(0) ;

377
	M(5,4) = sinus*pi / 2.0 + pi*cosinus*sinus ;
Pierre Kraemer's avatar
Pierre Kraemer committed
378 379 380 381 382

	M(5,5) = 2.0*(pi-alphaAbs);
}

template <typename REAL>
383 384 385 386
void QuadricRGBfunctions<REAL>::buildIntegralMatrix_c(MATRIX66 &M, const REAL alpha) const {
	// coefs * Int(phi=0..pi)(theta=0..pi-alpha) variablesRotated^2 dTheta dPhi * coefs     if alpha > 0
	// coefs * Int(phi=0..pi)(theta= -alpha..pi) variablesRotated^2 dTheta dPhi * coefs     if alpha < 0

Pierre Kraemer's avatar
Pierre Kraemer committed
387 388 389 390
	REAL alphaAbs = alpha > 0 ? alpha : -alpha;

	const REAL pi = 3.141592 ;

391 392 393 394 395 396 397
	const REAL cosinus = cos(alpha);
	const REAL cos2 = cosinus*cosinus ;
	const REAL cos3 = cos2*cosinus ;
	const REAL cos5 = cos2*cos3 ;
	const REAL cos7 = cos2*cos5 ;
	const REAL sinus = sin(alpha);
	const REAL sinAbs = sin(alphaAbs); // = - sin(alpha) si alpha < 0
Pierre Kraemer's avatar
Pierre Kraemer committed
398 399 400 401

	// Line 1
	M(0,0) = 2.0*(pi-alphaAbs)/5.0f;

402
	M(0,1) = 2.0 * (3*cosinus*sinAbs-4*sinAbs*cos3-alphaAbs+pi) / 15.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
403 404 405 406 407

	M(0,2) = 0;

	M(0,3) = 0;

408
	M(0,4) = (sinus*pi + 2*pi*cosinus*sinus) / 8.0;
Pierre Kraemer's avatar
Pierre Kraemer committed
409 410 411 412

	M(0,5) = 2.0*(pi-alphaAbs)/3.0;

	// Line 2
413
	M(1,0) = M(0,1);
Pierre Kraemer's avatar
Pierre Kraemer committed
414

415
	M(1,1) = (96*sinAbs*cos5 - 64*cos7*sinAbs+26*cosinus*sinAbs-68*sinAbs*cos3-6*alphaAbs+6*pi) / 15.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
416 417 418 419 420

	M(1,2) = 0;

	M(1,3) = 0;

421
	M(1,4) = (2*sinus*pi + pi * sinus*cos5 - pi*sinus*cos3 + 6*pi*cosinus*sinus + sinus*cos2*pi) / 8.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
422

423
	M(1,5) = 2*cosinus*sinAbs + (2*pi-8*sinAbs*cos3 - 2*alphaAbs) / 3.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
424 425 426 427 428 429

	// LINE 3
	M(2,0) = REAL(0);

	M(2,1) = REAL(0);

430
	M(2,2) = 2.0*(3*cosinus*sinAbs - 4*sinAbs*cos3 - alphaAbs + pi)/15.0;
Pierre Kraemer's avatar
Pierre Kraemer committed
431

432
	M(2,3) = pi*sinus/8.0f + cosinus*sinus*pi / 4.0f;
Pierre Kraemer's avatar
Pierre Kraemer committed
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453

	M(2,4) = REAL(0) ;

	M(2,5) = REAL(0) ;

	// Line 4
	M(3,0) = REAL(0) ;

	M(3,1) = REAL(0) ;

	M(3,2) = M(2,3);

	M(3,3) = 2.0*(pi-alphaAbs)/3.0 ;

	M(3,4) = REAL(0) ;

	M(3,5) = REAL(0) ;

	// Line 5
	M(4,0) = M(0,4) ;

454
	M(4,1) = M(1,4) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
455 456 457 458 459

	M(4,2) = REAL(0) ;

	M(4,3) = REAL(0) ;

460
	M(4,4) = M(1,5) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
461

462
	M(4,5) = pi*sinus / 2.0 + pi*cosinus*sinus ;
Pierre Kraemer's avatar
Pierre Kraemer committed
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479

	// Line 6
	M(5,0) = M(0,5) ;

	M(5,1) = M(1,5) ;

	M(5,2) = REAL(0) ;

	M(5,3) = REAL(0) ;

	M(5,4) = M(4,5) ;

	M(5,5) = 2.0*(pi-alphaAbs);
}


template <typename REAL>
480
void QuadricRGBfunctions<REAL>::buildRotateMatrix(MATRIX66 &N, const REAL gamma) const {
Pierre Kraemer's avatar
Pierre Kraemer committed
481 482 483 484
	REAL cosinus = cos(gamma), cos2 = cosinus*cosinus;
	REAL sinus = sin(gamma), sin2 = sinus*sinus;
	REAL sincos = sinus*cosinus;

485
	// Transposed matrix for left-hand side application
Kenneth Vanhoey's avatar
LF  
Kenneth Vanhoey committed
486

Pierre Kraemer's avatar
Pierre Kraemer committed
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
	N(0,0) = cos2;
	N(0,1) = sin2;
	N(0,2) = -sincos;
	N(0,3) = REAL(0);
	N(0,4) = REAL(0);
	N(0,5) = REAL(0);

	N(1,0) = sin2;
	N(1,1) = cos2;
	N(1,2) = sincos;
	N(1,3) = REAL(0);
	N(1,4) = REAL(0);
	N(1,5) = REAL(0);

	N(2,0) = 2*sincos;
	N(2,1) = -2*sincos;
	N(2,2) = cos2-sin2;
	N(2,3) = REAL(0);
	N(2,4) = REAL(0);
	N(2,5) = REAL(0);

	N(3,0) = REAL(0);
	N(3,1) = REAL(0);
	N(3,2) = REAL(0);
	N(3,3) = cosinus;
	N(3,4) = -sinus;
	N(3,5) = REAL(0);

	N(4,0) = REAL(0);
	N(4,1) = REAL(0);
	N(4,2) = REAL(0);
	N(4,3) = sinus;
	N(4,4) = cosinus;
	N(4,5) = REAL(0);

	N(5,0) = REAL(0);
	N(5,1) = REAL(0);
	N(5,2) = REAL(0);
	N(5,3) = REAL(0);
	N(5,4) = REAL(0);
Kenneth Vanhoey's avatar
LF  
Kenneth Vanhoey committed
527 528
	N(5,5) = REAL(1.0);

Pierre Kraemer's avatar
Pierre Kraemer committed
529 530 531 532
}

template <typename REAL>
void QuadricRGBfunctions<REAL>::operator += (const QuadricRGBfunctions& q) {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
533 534 535 536
	for (unsigned i = 0; i < 6; ++i)
		for (unsigned j = 0; j < 6; ++j)
			A(i,j) += q.A(i,j);

Pierre Kraemer's avatar
Pierre Kraemer committed
537
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
538

Pierre Kraemer's avatar
Pierre Kraemer committed
539
		for (unsigned i = 0; i < 6; ++i) {
540
			b[col][i] += q.b[col][i];
Pierre Kraemer's avatar
Pierre Kraemer committed
541 542
		}
		c[col] += q.c[col];
543

Pierre Kraemer's avatar
Pierre Kraemer committed
544 545 546 547 548
	}
}

template <typename REAL>
void QuadricRGBfunctions<REAL>::operator -= (const QuadricRGBfunctions& q) {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
549 550 551 552
	for (unsigned i = 0; i < 6; ++i)
		for (unsigned j = 0; j < 6; ++j)
			A(i,j) -= q.A(i,j);

Pierre Kraemer's avatar
Pierre Kraemer committed
553 554 555 556 557 558 559 560 561 562
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
		for (unsigned i = 0; i < 6; ++i) {
			b[col][i] -= q.b[col][i];
		}

		c[col] -= q.c[col];
	}
}

template <typename REAL>
563
void QuadricRGBfunctions<REAL>::operator *= (const REAL v) {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
564 565 566 567
	for (unsigned i = 0; i < 6; ++i)
		for (unsigned j = 0; j < 6; ++j)
			A(i,j) *= v;

Pierre Kraemer's avatar
Pierre Kraemer committed
568 569 570 571 572 573 574 575 576 577
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
		for (unsigned i = 0; i < 6; ++i) {
			b[col][i] *= v;
		}

		c[col] *= v;
	}
}

template <typename REAL>
578
void QuadricRGBfunctions<REAL>::operator /= (const REAL v) {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
579 580 581 582
	for (unsigned i = 0; i < 6; ++i)
		for (unsigned j = 0; j < 6; ++j)
			A(i,j) /= v;

Pierre Kraemer's avatar
Pierre Kraemer committed
583 584 585 586 587 588 589 590 591 592 593
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
		for (unsigned i = 0; i < 6; ++i) {
			b[col][i] /= v;
		}

		c[col] /= v;
	}
}

template <typename REAL>
void QuadricRGBfunctions<REAL>::zero () {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
594
	A.zero();
Pierre Kraemer's avatar
Pierre Kraemer committed
595 596 597 598 599 600 601
	for (unsigned int i = 0 ; i < COLCHANNELS ; ++i) {
		b[i].zero();
		c[i] = REAL(0) ;
	}
}

#endif /* QUADRICLF_HPP_ */