quadricRGBfunctions.hpp 12.2 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
	R1.transpose() ;
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
68
		if (!cf.getSubVectorH(col,0,function))
			assert(!"QuadricRGBfunctions::constructor") ;
69
70
71
72
//		std::cout << "gamma = " << gamma << " -- function = " << function ;
		function = R1 * function ; // Rotation 1
//		std::cout << " -- function after R1 = " << function << std::endl ;
//		std::cout << "R1 = " << R1 << std::endl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
73

74
75
		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
76
77
78
79
80
81
82
83
	}
}

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

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

		REAL res_local = REAL(0) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
89
		res_local += function * (A * function) ; // l*A*lt
90
91
92
		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
93
94
95
96
97
98
99
100
		res += res_local;
	}

	return res;
}

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

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

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
108
	for (unsigned  col = RED; col < BLUE+1 ; ++col) {
109
		VEC6 function = Ainv * b[col]; // function = A^(-1) * b
Pierre Kraemer's avatar
Pierre Kraemer committed
110

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

	return true;
}

template <typename REAL>
119
120
121
122
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
123
124
125
126
127
	REAL alphaAbs = alpha > 0 ? alpha : -alpha;

	const REAL pi = 3.141592 ;

	const REAL cosinus = cos(alpha);
128
129
	const REAL cos2 = cosinus*cosinus;
	const REAL cos3 = cos2*cosinus;
Pierre Kraemer's avatar
Pierre Kraemer committed
130
	const REAL sinus = sin(alpha);
131
	const REAL sinAbs = sin(alphaAbs); // = - sin(alpha) si alpha < 0
Pierre Kraemer's avatar
Pierre Kraemer committed
132
133
134
135

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

136
137
138
139
140
141
142
143
144
145
146
147
148
	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);

149
	M(1,1) = (-4.0 * sinAbs*cos3 + 6.0 * (pi - cosinus*sinAbs - alphaAbs)) / 15.0 ;
150
151
152
153
154

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

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

155
	M(1,4) = (sinus*cos2*pi + 2*sinus*pi) / 8.0;
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
209
210
211
212
213

	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
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
283
284
285
286
287
	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);
288
*/
Pierre Kraemer's avatar
Pierre Kraemer committed
289
290
291
292
}


template <typename REAL>
293
294
295
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
296
297
298
299
	REAL alphaAbs = alpha > 0 ? alpha : -alpha;

	const REAL pi = 3.141592 ;

300
301
302
303
304
305
306
	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
307
308
309
310

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

311
	M(0,1) = ( 6*cosinus*sinAbs - 8*sinAbs*cos3 - 2*alphaAbs + 2*pi ) / 15.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
312
313
314
315
316

	M(0,2) = 0;

	M(0,3) = 0;

317
	M(0,4) = (sinus*pi + 2*pi*cosinus*sinus) / 8.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
318
319
320
321

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

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

324
	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
325
326
327
328
329

	M(1,2) = 0;

	M(1,3) = 0;

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

332
	M(1,5) = 2.0*(pi-cosinus*sinAbs-alphaAbs) / 3.0;
Pierre Kraemer's avatar
Pierre Kraemer committed
333
334
335
336
337
338

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

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

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

341
	M(2,3) = pi*sinus / 8.0f;
Pierre Kraemer's avatar
Pierre Kraemer committed
342
343
344
345
346
347
348
349
350
351

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

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

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

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

352
	M(3,2) = ( sinus*pi + 2*pi*cosinus*sinus ) / 8.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
353
354
355
356
357
358
359
360

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

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

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

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

363
	M(4,1) = (sinus*pi + 4 * sinus * cos4 + 2*pi*cosinus*sinus) / 8.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
364
365
366
367
368

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

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

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

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

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

376
	M(5,1) = 2*cosinus*sinAbs + 2*(pi-4*sinAbs*cos3-alphaAbs) / 3.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
377
378
379
380
381

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

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

382
	M(5,4) = sinus*pi / 2.0 + pi*cosinus*sinus ;
Pierre Kraemer's avatar
Pierre Kraemer committed
383
384
385
386
387

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

template <typename REAL>
388
389
390
391
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
392
393
394
395
	REAL alphaAbs = alpha > 0 ? alpha : -alpha;

	const REAL pi = 3.141592 ;

396
397
398
399
400
401
402
	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
403
404
405
406

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

407
	M(0,1) = 2.0 * (3*cosinus*sinAbs-4*sinAbs*cos3-alphaAbs+pi) / 15.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
408
409
410
411
412

	M(0,2) = 0;

	M(0,3) = 0;

413
	M(0,4) = (sinus*pi + 2*pi*cosinus*sinus) / 8.0;
Pierre Kraemer's avatar
Pierre Kraemer committed
414
415
416
417

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

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

420
	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
421
422
423
424
425

	M(1,2) = 0;

	M(1,3) = 0;

426
	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
427

428
	M(1,5) = 2*cosinus*sinAbs + (2*pi-8*sinAbs*cos3 - 2*alphaAbs) / 3.0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
429
430
431
432
433
434

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

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

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

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

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

459
	M(4,1) = M(1,4) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
460
461
462
463
464

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

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

465
	M(4,4) = M(1,5) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
466

467
	M(4,5) = pi*sinus / 2.0 + pi*cosinus*sinus ;
Pierre Kraemer's avatar
Pierre Kraemer committed
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484

	// 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>
485
void QuadricRGBfunctions<REAL>::buildRotateMatrix(MATRIX66 &N, const REAL gamma) const {
Pierre Kraemer's avatar
Pierre Kraemer committed
486
487
488
489
	REAL cosinus = cos(gamma), cos2 = cosinus*cosinus;
	REAL sinus = sin(gamma), sin2 = sinus*sinus;
	REAL sincos = sinus*cosinus;

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

Pierre Kraemer's avatar
Pierre Kraemer committed
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
527
528
529
530
531
	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);
532
	N(5,5) = REAL(1);
Kenneth Vanhoey's avatar
LF    
Kenneth Vanhoey committed
533

Pierre Kraemer's avatar
Pierre Kraemer committed
534
535
536
537
}

template <typename REAL>
void QuadricRGBfunctions<REAL>::operator += (const QuadricRGBfunctions& q) {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
538
539
540
541
	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
542
	for (unsigned col = RED; col < BLUE+1 ; ++col) {
543

Pierre Kraemer's avatar
Pierre Kraemer committed
544
		for (unsigned i = 0; i < 6; ++i) {
545
			b[col][i] += q.b[col][i];
Pierre Kraemer's avatar
Pierre Kraemer committed
546
547
		}
		c[col] += q.c[col];
548

Pierre Kraemer's avatar
Pierre Kraemer committed
549
550
551
552
553
	}
}

template <typename REAL>
void QuadricRGBfunctions<REAL>::operator -= (const QuadricRGBfunctions& q) {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
554
555
556
557
	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
558
559
560
561
562
563
564
565
566
567
	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>
568
void QuadricRGBfunctions<REAL>::operator *= (const REAL v) {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
569
570
571
572
	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
573
574
575
576
577
578
579
580
581
582
	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>
583
void QuadricRGBfunctions<REAL>::operator /= (const REAL v) {
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
584
585
586
587
	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
588
589
590
591
592
593
594
595
596
597
598
	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
599
	A.zero();
Pierre Kraemer's avatar
Pierre Kraemer committed
600
601
602
603
604
605
606
	for (unsigned int i = 0 ; i < COLCHANNELS ; ++i) {
		b[i].zero();
		c[i] = REAL(0) ;
	}
}

#endif /* QUADRICLF_HPP_ */