quadricRGBfunctions.hpp 11.8 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 18
/*
 * 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() {
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
19

Pierre Kraemer's avatar
Pierre Kraemer committed
20 21
		for (unsigned i = 0; i < 6; ++i) {
			for (unsigned j = 0; j < 6; ++j)
22 23 24
				A[col](i,j) = REAL(0) ;

			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 38
		}

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

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

template <typename REAL>
QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const QuadricRGBfunctions& q) {
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
39

Pierre Kraemer's avatar
Pierre Kraemer committed
40 41
		for (unsigned i = 0; i < 6; ++i) {
			for (unsigned j = 0; j < 6; ++j)
42 43
				A[col](i,j) = q.A[col](i,j) ;
			b[col][i] = q.b[col][i] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
44 45
		}

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

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

54
	buildRotateMatrix(R1,gamma); // Rotation 1
55

56 57 58
	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
59

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

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

68 69 70
		A[col] = R2_A ; // Matrix A : integral
		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
71 72 73 74 75 76 77 78
	}
}

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

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

		REAL res_local = REAL(0) ;
84 85 86 87
		res_local += function * (A[col] * function) ; // l*A*lt
		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
88 89 90 91 92 93 94 95 96 97
		res += res_local;
	}

	return res;
}

template <typename REAL>
bool QuadricRGBfunctions<REAL>::findOptimizedRGBfunctions(RGBFUNCTIONS& cf) const {

	for (unsigned  col = RED; col < BLUE+1 ; ++col) {
98
		MATRIX66 Ainv ;
Pierre Kraemer's avatar
Pierre Kraemer committed
99

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

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

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

	return true;
}

template <typename REAL>
114 115 116 117
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
118 119 120 121 122 123
	REAL alphaAbs = alpha > 0 ? alpha : -alpha;

	const REAL pi = 3.141592 ;

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

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

129 130 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
	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
207 208 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
	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);
281
*/
Pierre Kraemer's avatar
Pierre Kraemer committed
282 283 284 285
}


template <typename REAL>
286 287 288
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
289 290 291 292
	REAL alphaAbs = alpha > 0 ? alpha : -alpha;

	const REAL pi = 3.141592 ;

293 294 295 296 297 298 299
	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
300 301 302 303

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

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

	M(0,2) = 0;

	M(0,3) = 0;

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

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

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

317
	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
318 319 320 321 322

	M(1,2) = 0;

	M(1,3) = 0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

template <typename REAL>
381 382 383 384
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
385 386 387 388
	REAL alphaAbs = alpha > 0 ? alpha : -alpha;

	const REAL pi = 3.141592 ;

389 390 391 392 393 394 395
	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
396 397 398 399

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

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

	M(0,2) = 0;

	M(0,3) = 0;

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

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

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

413
	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
414 415 416 417 418

	M(1,2) = 0;

	M(1,3) = 0;

419
	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
420

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

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

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

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

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

	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) ;

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

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

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

458
	M(4,4) = M(1,5) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
459

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

	// 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>
478
void QuadricRGBfunctions<REAL>::buildRotateMatrix(MATRIX66 &N, const REAL gamma) const {
Pierre Kraemer's avatar
Pierre Kraemer committed
479 480 481 482
	REAL cosinus = cos(gamma), cos2 = cosinus*cosinus;
	REAL sinus = sin(gamma), sin2 = sinus*sinus;
	REAL sincos = sinus*cosinus;

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

Pierre Kraemer's avatar
Pierre Kraemer committed
485 486 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
	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
525 526
	N(5,5) = REAL(1.0);

Pierre Kraemer's avatar
Pierre Kraemer committed
527 528 529 530 531
}

template <typename REAL>
void QuadricRGBfunctions<REAL>::operator += (const QuadricRGBfunctions& q) {
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
532

Pierre Kraemer's avatar
Pierre Kraemer committed
533 534 535
		for (unsigned i = 0; i < 6; ++i) {
			for (unsigned j = 0; j < 6; ++j)
				A[col](i,j) += q.A[col](i,j);
536
			b[col][i] += q.b[col][i];
Pierre Kraemer's avatar
Pierre Kraemer committed
537 538
		}
		c[col] += q.c[col];
539

Pierre Kraemer's avatar
Pierre Kraemer committed
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
	}
}

template <typename REAL>
void QuadricRGBfunctions<REAL>::operator -= (const QuadricRGBfunctions& q) {
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
		for (unsigned i = 0; i < 6; ++i) {
			b[col][i] -= q.b[col][i];
			for (unsigned j = 0; j < 6; ++j)
				A[col](i,j) -= q.A[col](i,j);
		}

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

template <typename REAL>
557
void QuadricRGBfunctions<REAL>::operator *= (const REAL v) {
Pierre Kraemer's avatar
Pierre Kraemer committed
558 559 560 561 562 563 564 565 566 567 568 569
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
		for (unsigned i = 0; i < 6; ++i) {
			b[col][i] *= v;
			for (unsigned j = 0; j < 6; ++j)
				A[col](i,j) *= v;
		}

		c[col] *= v;
	}
}

template <typename REAL>
570
void QuadricRGBfunctions<REAL>::operator /= (const REAL v) {
Pierre Kraemer's avatar
Pierre Kraemer committed
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
		for (unsigned i = 0; i < 6; ++i) {
			b[col][i] /= v;
			for (unsigned j = 0; j < 6; ++j)
				A[col](i,j) /= v;
		}

		c[col] /= v;
	}
}

template <typename REAL>
void QuadricRGBfunctions<REAL>::zero () {
	for (unsigned int i = 0 ; i < COLCHANNELS ; ++i) {
		A[i].zero();
		b[i].zero();
		c[i] = REAL(0) ;
	}
}

#endif /* QUADRICLF_HPP_ */