1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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
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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
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
525
526
527
528
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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
|
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>nevrax.org : docs</TITLE>
<LINK REL=stylesheet TYPE="text/css" HREF="/inc/css/nevrax.css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">
<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
<TR>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF='/'><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=><b>nevrax.com</B></FONT></A> </TD>
</TR>
</TABLE>
<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%>
<TR><TD BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG SRC="/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>
<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%>
<TR>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!------ Begin Box ------>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF>
<TABLE cellspacing=0 cellpadding=1 border=0>
<tr><td ALIGN=middle><a class='linkbox' href="/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
<!------ End Box ------>
</TD>
<TD WIDTH=15><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD ALIGN=left valign=top><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!-- title -->
<TABLE background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
<!-- block -->
<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
<TD><B>Documentation</B></TD>
<TD ALIGN=RIGHT> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>animation_optimizer.cpp</h1><a href="animation__optimizer_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00007 <font class="comment">/* Copyright, 2000-2002 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025
00026 <font class="preprocessor">#include "<a class="code" href="std3d_8h.html">std3d.h</a>"</font>
00027
00028 <font class="preprocessor">#include "<a class="code" href="animation__optimizer_8h.html">3d/animation_optimizer.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="mem__stream_8h.html">nel/misc/mem_stream.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="vectord_8h.html">nel/misc/vectord.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="track_8h.html">3d/track.h</a>"</font>
00032 <font class="preprocessor">#include "<a class="code" href="track__keyframer_8h.html">3d/track_keyframer.h</a>"</font>
00033 <font class="preprocessor">#include "<a class="code" href="animation_8h.html">3d/animation.h</a>"</font>
00034 <font class="preprocessor">#include "<a class="code" href="track__sampled__quat_8h.html">3d/track_sampled_quat.h</a>"</font>
00035 <font class="preprocessor">#include "<a class="code" href="track__sampled__vector_8h.html">3d/track_sampled_vector.h</a>"</font>
00036
00037
00038 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00039 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00040
00041
00042 <font class="keyword">namespace </font>NL3D
00043 {
00044
00045
00046 <font class="comment">// ***************************************************************************</font>
<a name="l00047"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a0">00047</a> CAnimationOptimizer::CAnimationOptimizer()
00048 {
00049 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o0">_SampleFrameRate</a>= 30;
00050 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o1">_QuaternionThresholdLowPrec</a>= 1.0 - 0.0001;
00051 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o2">_QuaternionThresholdHighPrec</a>= 1.0 - 0.000001;
00052 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o4">_VectorThresholdLowPrec</a>= 0.001;
00053 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o5">_VectorThresholdHighPrec</a>= 0.0001;
00054 }
00055
00056
00057 <font class="comment">// ***************************************************************************</font>
<a name="l00058"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a1">00058</a> <font class="keywordtype">void</font> CAnimationOptimizer::setQuaternionThreshold(<font class="keywordtype">double</font> lowPrecThre, <font class="keywordtype">double</font> highPrecThre)
00059 {
00060 <a class="code" href="debug_8h.html#a6">nlassert</a>(lowPrecThre>=0);
00061 <a class="code" href="debug_8h.html#a6">nlassert</a>(highPrecThre>=0);
00062 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o1">_QuaternionThresholdLowPrec</a>= 1.0 - lowPrecThre;
00063 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o2">_QuaternionThresholdHighPrec</a>= 1.0 - highPrecThre;
00064 }
00065
00066
00067 <font class="comment">// ***************************************************************************</font>
<a name="l00068"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a2">00068</a> <font class="keywordtype">void</font> CAnimationOptimizer::setVectorThreshold(<font class="keywordtype">double</font> lowPrecThre, <font class="keywordtype">double</font> highPrecThre)
00069 {
00070 <a class="code" href="debug_8h.html#a6">nlassert</a>(lowPrecThre>=0);
00071 <a class="code" href="debug_8h.html#a6">nlassert</a>(highPrecThre>=0);
00072 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o4">_VectorThresholdLowPrec</a>= lowPrecThre;
00073 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o5">_VectorThresholdHighPrec</a>= highPrecThre;
00074 }
00075
00076
00077 <font class="comment">// ***************************************************************************</font>
<a name="l00078"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a5">00078</a> <font class="keywordtype">void</font> CAnimationOptimizer::setSampleFrameRate(<font class="keywordtype">float</font> frameRate)
00079 {
00080 <a class="code" href="debug_8h.html#a6">nlassert</a>(frameRate>0);
00081 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o0">_SampleFrameRate</a>= frameRate;
00082 }
00083
00084
00085 <font class="comment">// ***************************************************************************</font>
<a name="l00086"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a6">00086</a> <font class="keywordtype">void</font> CAnimationOptimizer::optimize(<font class="keyword">const</font> CAnimation &animIn, CAnimation &animOut)
00087 {
00088 <font class="comment">// reset animOut</font>
00089 <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(animOut);
00090
00091 <font class="comment">// Parse all tracks of the animation.</font>
00092 set<string> setString;
00093 animIn.getTrackNames (setString);
00094 set<string>::iterator it;
00095
00096 <font class="keywordflow">for</font>(it=setString.begin();it!=setString.end();it++)
00097 {
00098 <font class="keyword">const</font> string &trackName= *it;
00099 uint trackId= animIn.getIdTrackByName(trackName);
00100 <a class="code" href="debug_8h.html#a6">nlassert</a>(trackId!=CAnimation::NotFound);
00101 <font class="keyword">const</font> ITrack *track= animIn.getTrack(trackId);
00102
00103 <font class="comment">// If the track is optimisable.</font>
00104 ITrack *newTrack;
00105 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c1">isTrackOptimisable</a>(track))
00106 {
00107 <font class="comment">// choose the threshold according to precision wanted</font>
00108 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c3">isLowPrecisionTrack</a>(trackName) )
00109 {
00110 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o3">_QuaternionThreshold</a>= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o1">_QuaternionThresholdLowPrec</a>;
00111 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o6">_VectorThreshold</a>= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o4">_VectorThresholdLowPrec</a>;
00112 }
00113 <font class="keywordflow">else</font>
00114 {
00115 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o3">_QuaternionThreshold</a>= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o2">_QuaternionThresholdHighPrec</a>;
00116 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o6">_VectorThreshold</a>= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o5">_VectorThresholdHighPrec</a>;
00117 }
00118
00119 <font class="comment">// optimize it.</font>
00120 newTrack= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c2">optimizeTrack</a>(track);
00121 }
00122 <font class="keywordflow">else</font>
00123 {
00124 <font class="comment">// just clone it.</font>
00125 newTrack= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c0">cloneTrack</a>(track);
00126 }
00127
00128 <font class="comment">// Add it to the animation</font>
00129 animOut.addTrack(trackName, newTrack);
00130 }
00131
00132 <font class="comment">// Set min animation length</font>
00133 animOut.setMinEndTime (animIn.getEndTime ());
00134 <a class="code" href="debug_8h.html#a6">nlassert</a> (animOut.getEndTime() == animIn.getEndTime());
00135 }
00136
00137 <font class="comment">// ***************************************************************************</font>
<a name="l00138"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c0">00138</a> ITrack *CAnimationOptimizer::cloneTrack(<font class="keyword">const</font> ITrack *trackIn)
00139 {
00140 CMemStream memStream;
00141
00142 <font class="comment">// write to the stream.</font>
00143 ITrack *trackInSerial= const_cast<ITrack*>(trackIn);
00144 memStream.serialPolyPtr(trackInSerial);
00145
00146 <font class="comment">// read from the stream.</font>
00147 memStream.invert();
00148 ITrack *ret= NULL;
00149 memStream.serialPolyPtr(ret);
00150
00151 <font class="keywordflow">return</font> ret;
00152 }
00153
00154
00155 <font class="comment">// ***************************************************************************</font>
<a name="l00156"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c1">00156</a> <font class="keywordtype">bool</font> CAnimationOptimizer::isTrackOptimisable(<font class="keyword">const</font> ITrack *trackIn)
00157 {
00158 <a class="code" href="debug_8h.html#a6">nlassert</a>(trackIn);
00159
00160 <font class="comment">// If the track is a Linear, Bezier or a TCB track, suppose we can optimize it. Constant may not be interressant....</font>
00161 <font class="keywordflow">if</font>( dynamic_cast<const CTrackKeyFramerTCBQuat*>(trackIn) ||
00162 dynamic_cast<const CTrackKeyFramerBezierQuat*>(trackIn) ||
00163 dynamic_cast<const CTrackKeyFramerLinearQuat*>(trackIn) )
00164 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00165
00166 <font class="comment">// If the track is a Linear, Bezier or a TCB track, suppose we can optimize it. Constant may not be interressant....</font>
00167 <font class="keywordflow">if</font>( dynamic_cast<const CTrackKeyFramerTCBVector*>(trackIn) ||
00168 dynamic_cast<const CTrackKeyFramerBezierVector*>(trackIn) ||
00169 dynamic_cast<const CTrackKeyFramerLinearVector*>(trackIn) )
00170 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00171
00172 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00173 }
00174
00175
00176 <font class="comment">// ***************************************************************************</font>
<a name="l00177"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c2">00177</a> ITrack *CAnimationOptimizer::optimizeTrack(<font class="keyword">const</font> ITrack *trackIn)
00178 {
00179 <font class="comment">// Get track param.</font>
00180 <font class="keywordtype">float</font> beginTime= trackIn->getBeginTime();
00181 <font class="keywordtype">float</font> endTime= trackIn->getEndTime();
00182 <a class="code" href="debug_8h.html#a6">nlassert</a>(endTime>=beginTime);
00183
00184 <font class="comment">// Get num Sample </font>
00185 uint numSamples= (uint)ceil( (endTime-beginTime)*<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o0">_SampleFrameRate</a>);
00186 numSamples= max(1U, numSamples);
00187 <a class="code" href="debug_8h.html#a6">nlassert</a>(numSamples<65535);
00188
00189
00190 <font class="comment">// Optimize Quaternion track??</font>
00191 <font class="comment">//================</font>
00192 <font class="keywordflow">if</font>( dynamic_cast<const CAnimatedValueQuat *>(&trackIn->getValue()) )
00193 {
00194 <font class="comment">// sample the animation. Store result in _TimeList/_QuatKeyList</font>
00195 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_0">sampleQuatTrack</a>(trackIn, beginTime, endTime, numSamples);
00196
00197 <font class="comment">// check if the sampled track can be reduced to a TrackDefaultQuat. Test _QuatKeyList.</font>
00198 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_1">testConstantQuatTrack</a>() )
00199 {
00200 <font class="comment">// create a default Track Quat.</font>
00201 CTrackDefaultQuat *trackDefault= <font class="keyword">new</font> CTrackDefaultQuat;
00202 <font class="comment">// setup the uniform value.</font>
00203 trackDefault->setValue(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[0]);
00204
00205 <font class="comment">// return the result.</font>
00206 <font class="keywordflow">return</font> trackDefault;
00207 }
00208 <font class="comment">// else optimize the sampled animation, and build.</font>
00209 <font class="keywordflow">else</font>
00210 {
00211 <font class="comment">// optimize.</font>
00212 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_2">optimizeQuatTrack</a>();
00213
00214 <font class="comment">// Create a sampled quaternion track</font>
00215 CTrackSampledQuat *trackSQ= <font class="keyword">new</font> CTrackSampledQuat;
00216
00217 <font class="comment">// Copy loop from track.</font>
00218 trackSQ->setLoopMode(trackIn->getLoopMode());
00219
00220 <font class="comment">// Build it.</font>
00221 trackSQ->build(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>, <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>, beginTime, endTime);
00222
00223 <font class="comment">// return result.</font>
00224 <font class="keywordflow">return</font> trackSQ;
00225 }
00226 }
00227 <font class="comment">// Optimize Position track??</font>
00228 <font class="comment">//================</font>
00229 <font class="keywordflow">else</font> <font class="keywordflow">if</font>( dynamic_cast<const CAnimatedValueVector *>(&trackIn->getValue()) )
00230 {
00231 <font class="comment">// sample the animation. Store result in _TimeList/_VectorKeyList</font>
00232 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_0">sampleVectorTrack</a>(trackIn, beginTime, endTime, numSamples);
00233
00234 <font class="comment">// check if the sampled track can be reduced to a TrackDefaultVector. Test _VectorKeyList.</font>
00235 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_1">testConstantVectorTrack</a>() )
00236 {
00237 <font class="comment">// create a default Track Vector.</font>
00238 CTrackDefaultVector *trackDefault= <font class="keyword">new</font> CTrackDefaultVector;
00239 <font class="comment">// setup the uniform value.</font>
00240 trackDefault->setValue(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[0]);
00241
00242 <font class="comment">// return the result.</font>
00243 <font class="keywordflow">return</font> trackDefault;
00244 }
00245 <font class="comment">// else optimize the sampled animation, and build.</font>
00246 <font class="keywordflow">else</font>
00247 {
00248 <font class="comment">// optimize.</font>
00249 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_2">optimizeVectorTrack</a>();
00250
00251 <font class="comment">// Create a sampled Vector track</font>
00252 CTrackSampledVector *trackSV= <font class="keyword">new</font> CTrackSampledVector;
00253
00254 <font class="comment">// Copy loop from track.</font>
00255 trackSV->setLoopMode(trackIn->getLoopMode());
00256
00257 <font class="comment">// Build it.</font>
00258 trackSV->build(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>, <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>, beginTime, endTime);
00259
00260 <font class="comment">// return result.</font>
00261 <font class="keywordflow">return</font> trackSV;
00262 }
00263 }
00264 <font class="keywordflow">else</font>
00265 {
00266 <font class="comment">// Must be a quaternion track or vector track for now.</font>
00267 <a class="code" href="debug_8h.html#a12">nlstop</a>;
00268 <font class="comment">// Avoid warning.</font>
00269 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c0">cloneTrack</a>(trackIn);
00270 }
00271 }
00272
00273
00274 <font class="comment">// ***************************************************************************</font>
00275 <font class="comment">// ***************************************************************************</font>
00276 <font class="comment">// Quaternion optimisation</font>
00277 <font class="comment">// ***************************************************************************</font>
00278 <font class="comment">// ***************************************************************************</font>
00279
00280
00281 <font class="comment">// ***************************************************************************</font>
<a name="l00282"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_0">00282</a> <font class="keywordtype">void</font> CAnimationOptimizer::sampleQuatTrack(<font class="keyword">const</font> ITrack *trackIn, <font class="keywordtype">float</font> beginTime, <font class="keywordtype">float</font> endTime, uint numSamples)
00283 {
00284 <font class="comment">// resize tmp samples</font>
00285 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>.resize(numSamples);
00286 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>.resize(numSamples);
00287
00288 <font class="comment">// Sample the animation.</font>
00289 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= beginTime;
00290 <font class="keywordtype">float</font> dt= 0;
00291 <font class="keywordflow">if</font>(numSamples>1)
00292 dt= (endTime-beginTime)/(numSamples-1);
00293 <font class="keywordflow">for</font>(uint i=0;i<numSamples; i++, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+=dt)
00294 {
00295 CQuat quat;
00296
00297 <font class="comment">// make exact endTime match (avoid precision problem)</font>
00298 <font class="keywordflow">if</font>(i==numSamples-1)
00299 <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= endTime;
00300
00301 <font class="comment">// evaluate the track</font>
00302 const_cast<ITrack*>(trackIn)->interpolate(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, quat);
00303
00304 <font class="comment">// normalize this quaternion</font>
00305 quat.normalize();
00306
00307 <font class="comment">// force on same hemisphere according to precedent frame.</font>
00308 <font class="keywordflow">if</font>(i>0)
00309 {
00310 quat.makeClosest(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i-1]);
00311 }
00312
00313 <font class="comment">// store time and key.</font>
00314 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i]= i;
00315 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i]= quat;
00316 }
00317
00318 }
00319
00320 <font class="comment">// ***************************************************************************</font>
<a name="l00321"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_1">00321</a> <font class="keywordtype">bool</font> CAnimationOptimizer::testConstantQuatTrack()
00322 {
00323 uint numSamples= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>.size();
00324 <a class="code" href="debug_8h.html#a6">nlassert</a>(numSamples>0);
00325
00326 <font class="comment">// Get the first sample as the reference quaternion, and test others from this one.</font>
00327 CQuat quatRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[0];
00328 <font class="keywordflow">for</font>(uint i=0;i<numSamples;i++)
00329 {
00330 <font class="comment">// All values must be nearly equal to the reference quaternion.</font>
00331 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_3">nearlySameQuaternion</a>(quatRef, <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i]))
00332 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00333 }
00334
00335 <font class="comment">// ok.</font>
00336 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00337 }
00338
00339
00340 <font class="comment">// ***************************************************************************</font>
<a name="l00341"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_2">00341</a> <font class="keywordtype">void</font> CAnimationOptimizer::optimizeQuatTrack()
00342 {
00343 uint numSamples= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>.size();
00344 <a class="code" href="debug_8h.html#a6">nlassert</a>(numSamples>0);
00345
00346 <font class="comment">// <=2 key? => no opt possible..</font>
00347 <font class="keywordflow">if</font>(numSamples<=2)
00348 <font class="keywordflow">return</font>;
00349
00350 <font class="comment">// prepare dest opt</font>
00351 std::vector<uint16> optTimeList;
00352 std::vector<CQuat> optKeyList;
00353 optTimeList.reserve(numSamples);
00354 optKeyList.reserve(numSamples);
00355
00356 <font class="comment">// Add the first key.</font>
00357 optTimeList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[0]);
00358 optKeyList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[0]);
00359 <font class="keywordtype">double</font> timeRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[0];
00360 CQuatD quatRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[0];
00361
00362 <font class="comment">// For all keys, but the first and the last, test if can remove them.</font>
00363 <font class="keywordflow">for</font>(uint i=1; i<numSamples-1; i++)
00364 {
00365 CQuatD quatCur= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i];
00366 CQuatD quatNext= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i+1];
00367 <font class="keywordtype">double</font> timeCur= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i];
00368 <font class="keywordtype">double</font> timeNext= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i+1];
00369
00370 <font class="comment">// must add the key?</font>
00371 <font class="keywordtype">bool</font> mustAdd= <font class="keyword">false</font>;
00372
00373 <font class="comment">// If the Delta time are too big, abort (CTrackSampledQuat limitation)</font>
00374 <font class="keywordflow">if</font>(timeNext-timeRef>255)
00375 {
00376 mustAdd= <font class="keyword">true</font>;
00377 }
00378 <font class="comment">// If the next quaternion or the current quaternion are not on same hemisphere than ref, abort.</font>
00379 <font class="keywordflow">else</font> <font class="keywordflow">if</font>( CQuatD::dotProduct(quatCur, quatRef)<0 || CQuatD::dotProduct(quatNext, quatRef)<0 )
00380 {
00381 mustAdd= <font class="keyword">true</font>;
00382 }
00383 <font class="comment">// else, test interpolation</font>
00384 <font class="keywordflow">else</font>
00385 {
00386 <font class="comment">// If the 3 quats are nearly equals, it is ok (avoid interpolation)</font>
00387 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_3">nearlySameQuaternion</a>(quatRef, quatCur) && <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_3">nearlySameQuaternion</a>(quatRef, quatNext) )
00388 mustAdd= <font class="keyword">false</font>;
00389 <font class="keywordflow">else</font>
00390 {
00391 <font class="comment">// interpolate.</font>
00392 CQuatD quatInterpolated;
00393 <font class="keywordtype">double</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= (timeCur-timeRef)/(timeNext/timeRef);
00394 quatInterpolated= CQuatD::slerp(quatRef, quatNext, (<font class="keywordtype">float</font>)<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00395
00396 <font class="comment">// test if cur and interpolate are equal.</font>
00397 <font class="keywordflow">if</font>( !<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_3">nearlySameQuaternion</a>(quatCur, quatInterpolated) )
00398 mustAdd= <font class="keyword">true</font>;
00399 }
00400 }
00401
00402 <font class="comment">// If must add the key to the optimized track.</font>
00403 <font class="keywordflow">if</font>(mustAdd)
00404 {
00405 optTimeList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i]);
00406 optKeyList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i]);
00407 timeRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i];
00408 quatRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i];
00409 }
00410 }
00411
00412 <font class="comment">// Add the last key.</font>
00413 optTimeList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[numSamples-1]);
00414 optKeyList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[numSamples-1]);
00415
00416 <font class="comment">// copy the optimized track to the main one.</font>
00417 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>= optTimeList;
00418 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>= optKeyList;
00419 }
00420
00421
00422 <font class="comment">// ***************************************************************************</font>
<a name="l00423"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_3">00423</a> <font class="keywordtype">bool</font> CAnimationOptimizer::nearlySameQuaternion(<font class="keyword">const</font> CQuatD &quat0, <font class="keyword">const</font> CQuatD &quat1)
00424 {
00425 <font class="comment">// true if exactly same, or exactly inverse</font>
00426 <font class="keywordflow">if</font>(quat0==quat1 || quat0==-quat1)
00427 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00428
00429 <font class="comment">// Else compute the rotation to go from qRef to q. Use double for better presion.</font>
00430 CQuatD quatDif;
00431 quatDif= quat1 * quat0.conjugate();
00432 <font class="comment">// inverse the quaternion if necessary. ie make closest to the identity quaternion.</font>
00433 <font class="keywordflow">if</font>(quatDif.w<0)
00434 quatDif= -quatDif;
00435
00436 <font class="comment">// compare "angle threshold"</font>
00437 <font class="keywordflow">return</font> (quatDif.w >= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o3">_QuaternionThreshold</a>);
00438 }
00439
00440
00441 <font class="comment">// ***************************************************************************</font>
00442 <font class="comment">// ***************************************************************************</font>
00443 <font class="comment">// Vector optimisation</font>
00444 <font class="comment">// ***************************************************************************</font>
00445 <font class="comment">// ***************************************************************************</font>
00446
00447
00448 <font class="comment">// ***************************************************************************</font>
<a name="l00449"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_0">00449</a> <font class="keywordtype">void</font> CAnimationOptimizer::sampleVectorTrack(<font class="keyword">const</font> ITrack *trackIn, <font class="keywordtype">float</font> beginTime, <font class="keywordtype">float</font> endTime, uint numSamples)
00450 {
00451 <font class="comment">// resize tmp samples</font>
00452 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>.resize(numSamples);
00453 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>.resize(numSamples);
00454
00455 <font class="comment">// Sample the animation.</font>
00456 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= beginTime;
00457 <font class="keywordtype">float</font> dt= 0;
00458 <font class="keywordflow">if</font>(numSamples>1)
00459 dt= (endTime-beginTime)/(numSamples-1);
00460 <font class="keywordflow">for</font>(uint i=0;i<numSamples; i++, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+=dt)
00461 {
00462 CVector vector;
00463
00464 <font class="comment">// make exact endTime match (avoid precision problem)</font>
00465 <font class="keywordflow">if</font>(i==numSamples-1)
00466 <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= endTime;
00467
00468 <font class="comment">// evaluate the track</font>
00469 const_cast<ITrack*>(trackIn)->interpolate(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, vector);
00470
00471 <font class="comment">// store time and key.</font>
00472 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i]= i;
00473 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[i]= vector;
00474 }
00475
00476 }
00477
00478 <font class="comment">// ***************************************************************************</font>
<a name="l00479"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_1">00479</a> <font class="keywordtype">bool</font> CAnimationOptimizer::testConstantVectorTrack()
00480 {
00481 uint numSamples= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>.size();
00482 <a class="code" href="debug_8h.html#a6">nlassert</a>(numSamples>0);
00483
00484 <font class="comment">// Get the first sample as the reference Vectorer, and test others from this one.</font>
00485 CVector vectorRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[0];
00486 <font class="keywordflow">for</font>(uint i=0;i<numSamples;i++)
00487 {
00488 <font class="comment">// All values must be nearly equal to the reference vector.</font>
00489 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_3">nearlySameVector</a>(vectorRef, <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[i]))
00490 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00491 }
00492
00493 <font class="comment">// ok.</font>
00494 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00495 }
00496
00497
00498 <font class="comment">// ***************************************************************************</font>
<a name="l00499"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_2">00499</a> <font class="keywordtype">void</font> CAnimationOptimizer::optimizeVectorTrack()
00500 {
00501 uint numSamples= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>.size();
00502 <a class="code" href="debug_8h.html#a6">nlassert</a>(numSamples>0);
00503
00504 <font class="comment">// <=2 key? => no opt possible..</font>
00505 <font class="keywordflow">if</font>(numSamples<=2)
00506 <font class="keywordflow">return</font>;
00507
00508 <font class="comment">// prepare dest opt</font>
00509 std::vector<uint16> optTimeList;
00510 std::vector<CVector> optKeyList;
00511 optTimeList.reserve(numSamples);
00512 optKeyList.reserve(numSamples);
00513
00514 <font class="comment">// Add the first key.</font>
00515 optTimeList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[0]);
00516 optKeyList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[0]);
00517 <font class="keywordtype">double</font> timeRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[0];
00518 CVectorD vectorRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[0];
00519
00520 <font class="comment">// For all keys, but the first and the last, test if can remove them.</font>
00521 <font class="keywordflow">for</font>(uint i=1; i<numSamples-1; i++)
00522 {
00523 CVectorD vectorCur= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[i];
00524 CVectorD vectorNext= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[i+1];
00525 <font class="keywordtype">double</font> timeCur= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i];
00526 <font class="keywordtype">double</font> timeNext= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i+1];
00527
00528 <font class="comment">// must add the key?</font>
00529 <font class="keywordtype">bool</font> mustAdd= <font class="keyword">false</font>;
00530
00531 <font class="comment">// If the Delta time are too big, abort (CTrackSampledVector limitation)</font>
00532 <font class="keywordflow">if</font>(timeNext-timeRef>255)
00533 {
00534 mustAdd= <font class="keyword">true</font>;
00535 }
00536 <font class="comment">// else, test interpolation</font>
00537 <font class="keywordflow">else</font>
00538 {
00539 <font class="comment">// If the 3 Vectors are nearly equals, it is ok (avoid interpolation)</font>
00540 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_3">nearlySameVector</a>(vectorRef, vectorCur) && <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_3">nearlySameVector</a>(vectorRef, vectorNext) )
00541 mustAdd= <font class="keyword">false</font>;
00542 <font class="keywordflow">else</font>
00543 {
00544 <font class="comment">// interpolate.</font>
00545 CVectorD vectorInterpolated;
00546 <font class="keywordtype">double</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= (timeCur-timeRef)/(timeNext/timeRef);
00547 vectorInterpolated= vectorRef*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>) + vectorNext*<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
00548
00549 <font class="comment">// test if cur and interpolate are equal.</font>
00550 <font class="keywordflow">if</font>( !<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_3">nearlySameVector</a>(vectorCur, vectorInterpolated) )
00551 mustAdd= <font class="keyword">true</font>;
00552 }
00553 }
00554
00555 <font class="comment">// If must add the key to the optimized track.</font>
00556 <font class="keywordflow">if</font>(mustAdd)
00557 {
00558 optTimeList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i]);
00559 optKeyList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[i]);
00560 timeRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i];
00561 vectorRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[i];
00562 }
00563 }
00564
00565 <font class="comment">// Add the last key.</font>
00566 optTimeList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[numSamples-1]);
00567 optKeyList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[numSamples-1]);
00568
00569 <font class="comment">// copy the optimized track to the main one.</font>
00570 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>= optTimeList;
00571 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>= optKeyList;
00572 }
00573
00574
00575 <font class="comment">// ***************************************************************************</font>
<a name="l00576"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_3">00576</a> <font class="keywordtype">bool</font> CAnimationOptimizer::nearlySameVector(<font class="keyword">const</font> CVectorD &v0, <font class="keyword">const</font> CVectorD &v1)
00577 {
00578 <font class="comment">// true if exactly same</font>
00579 <font class="keywordflow">if</font>(v0==v1)
00580 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00581
00582 <font class="comment">// Else compute the dif, use double for better precision</font>
00583 CVectorD vDif;
00584 vDif= v1-v0;
00585
00586 <font class="comment">// compare norm</font>
00587 <font class="keywordflow">return</font> (vDif.norm() <= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o6">_VectorThreshold</a>);
00588 }
00589
00590
00591 <font class="comment">// ***************************************************************************</font>
00592 <font class="comment">// ***************************************************************************</font>
00593 <font class="comment">// LowPrecisionTrack</font>
00594 <font class="comment">// ***************************************************************************</font>
00595 <font class="comment">// ***************************************************************************</font>
00596
00597
00598 <font class="comment">// ***************************************************************************</font>
<a name="l00599"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a3">00599</a> <font class="keywordtype">void</font> CAnimationOptimizer::addLowPrecisionTrack(<font class="keyword">const</font> std::string &name)
00600 {
00601 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o7">_LowPrecTrackKeyName</a>.push_back(name);
00602 }
00603
00604 <font class="comment">// ***************************************************************************</font>
<a name="l00605"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a4">00605</a> <font class="keywordtype">void</font> CAnimationOptimizer::clearLowPrecisionTracks()
00606 {
00607 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o7">_LowPrecTrackKeyName</a>.clear();
00608 }
00609
00610 <font class="comment">// ***************************************************************************</font>
<a name="l00611"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c3">00611</a> <font class="keywordtype">bool</font> CAnimationOptimizer::isLowPrecisionTrack(<font class="keyword">const</font> std::string &trackName)
00612 {
00613 <font class="keywordflow">for</font>(uint i=0; i<<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o7">_LowPrecTrackKeyName</a>.size(); i++)
00614 {
00615 <font class="comment">// if find a substr of the key, it is a low prec track</font>
00616 <font class="keywordflow">if</font>( trackName.find(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o7">_LowPrecTrackKeyName</a>[i]) != string::npos )
00617 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00618 }
00619
00620 <font class="comment">// no key found</font>
00621 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00622 }
00623
00624
00625 } <font class="comment">// NL3D</font>
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|