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
|
<!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="http://www.nevrax.org/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="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><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="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/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="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/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="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
<!------ End Box ------>
</TD>
<TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!-- title -->
<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG SRC="http://www.nevrax.org/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="http://www.nevrax.org/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:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>chain.cpp</h1><a href="chain_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00007 <font class="comment">/* Copyright, 2001 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="stdpacs_8h.html">stdpacs.h</a>"</font>
00027
00028 <font class="preprocessor">#include "<a class="code" href="chain_8h.html">pacs/chain.h</a>"</font>
00029
00030 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00031 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00032
00033
00034 <font class="comment">// Functions for vertices comparison.</font>
00035 <font class="comment">// total order relation</font>
<a name="l00036"></a><a class="code" href="chain_8cpp.html#a0">00036</a> <font class="keyword">static</font> <font class="keyword">inline</font> <font class="keywordtype">bool</font> <a class="code" href="chain_8cpp.html#a0">isStrictlyLess</a>(<font class="keyword">const</font> CVector &a, <font class="keyword">const</font> CVector &b)
00037 {
00038 <font class="keywordflow">if</font> (a.x < b.x) <font class="keywordflow">return</font> <font class="keyword">true</font>;
00039 <font class="keywordflow">if</font> (a.x > b.x) <font class="keywordflow">return</font> <font class="keyword">false</font>;
00040 <font class="keywordflow">if</font> (a.y < b.y) <font class="keywordflow">return</font> <font class="keyword">true</font>;
00041 <font class="keywordflow">if</font> (a.y > b.y) <font class="keywordflow">return</font> <font class="keyword">false</font>;
00042 <font class="keywordflow">if</font> (a.z < b.y) <font class="keywordflow">return</font> <font class="keyword">true</font>;
00043 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00044 }
00045
<a name="l00046"></a><a class="code" href="chain_8cpp.html#a1">00046</a> <font class="keyword">static</font> <font class="keyword">inline</font> <font class="keywordtype">bool</font> <a class="code" href="chain_8cpp.html#a1">isStrictlyGreater</a>(<font class="keyword">const</font> CVector &a, <font class="keyword">const</font> CVector &b)
00047 {
00048 <font class="keywordflow">if</font> (a.x > b.x) <font class="keywordflow">return</font> <font class="keyword">true</font>;
00049 <font class="keywordflow">if</font> (a.x < b.x) <font class="keywordflow">return</font> <font class="keyword">false</font>;
00050 <font class="keywordflow">if</font> (a.y > b.y) <font class="keywordflow">return</font> <font class="keyword">true</font>;
00051 <font class="keywordflow">if</font> (a.y < b.y) <font class="keywordflow">return</font> <font class="keyword">false</font>;
00052 <font class="keywordflow">if</font> (a.z > b.y) <font class="keywordflow">return</font> <font class="keyword">true</font>;
00053 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00054 }
00055
<a name="l00056"></a><a class="code" href="chain_8cpp.html#a2">00056</a> <font class="keyword">static</font> <font class="keyword">inline</font> <font class="keywordtype">bool</font> <a class="code" href="chain_8cpp.html#a2">isEqual</a>(<font class="keyword">const</font> CVector &a, <font class="keyword">const</font> CVector &b)
00057 {
00058 <font class="keywordflow">return</font> (a == b);
00059 }
00060
00061
00062 <font class="comment">// COrderedChain3f methods implementation</font>
00063
<a name="l00064"></a><a class="code" href="classNLPACS_1_1COrderedChain3f.html#a7">00064</a> <font class="keywordtype">void</font> <a class="code" href="classNLPACS_1_1COrderedChain3f.html#a7">NLPACS::COrderedChain3f::serial</a>(IStream &f)
00065 {
00066 <font class="comment">/*</font>
00067 <font class="comment"> Version 0:</font>
00068 <font class="comment"> - base version.</font>
00069 <font class="comment"> */</font>
00070 (void)f.serialVersion(0);
00071
00072 f.serialCont(<a class="code" href="classNLPACS_1_1COrderedChain3f.html#n0">_Vertices</a>);
00073 f.serial(<a class="code" href="classNLPACS_1_1COrderedChain3f.html#n1">_Forward</a>);
00074 f.serial(<a class="code" href="classNLPACS_1_1COrderedChain3f.html#n2">_ParentId</a>);
00075 f.serial(<a class="code" href="classNLPACS_1_1COrderedChain3f.html#n3">_IndexInParent</a>);
00076 }
00077
00078 <font class="comment">// end of COrderedChain3f methods implementation</font>
00079
00080 <font class="comment">// COrderedChain methods implementation</font>
00081
00082 <font class="comment">// translates the ordered chain by the vector translation</font>
<a name="l00083"></a><a class="code" href="classNLPACS_1_1COrderedChain.html#a8">00083</a> <font class="keywordtype">void</font> <a class="code" href="classNLPACS_1_1COrderedChain.html#a8">NLPACS::COrderedChain::translate</a>(<font class="keyword">const</font> CVector &translation)
00084 {
00085 uint i;
00086 CVector2s translat;
00087 translat.pack(translation);
00088 <font class="keywordflow">for</font> (i=0; i<<a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>.size(); ++i)
00089 <a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>[i] += translat;
00090 }
00091
00092 <font class="comment">//</font>
00093 <font class="keywordtype">void</font> <a class="code" href="classNLPACS_1_1COrderedChain.html#a11">NLPACS::COrderedChain::traverse</a>(sint from, sint to, <font class="keywordtype">bool</font> forward, vector<NLPACS::CVector2s> &path)<font class="keyword"> const</font>
00094 <font class="keyword"></font>{
00095 sint i;
00096 <font class="keywordflow">if</font> (forward)
00097 {
00098 <font class="keywordflow">if</font> (from < 0) from = 0;
00099 <font class="keywordflow">if</font> (to < 0) to = <a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>.size()-1;
00100
00101 <font class="keywordflow">for</font> (i=from+1; i<=to; ++i)
00102 path.push_back(<a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>[i]);
00103 }
00104 <font class="keywordflow">else</font>
00105 {
00106 <font class="keywordflow">if</font> (from < 0) from = <a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>.size()-2;
00107 <font class="keywordflow">if</font> (to < 0) to = -1;
00108
00109 <font class="keywordflow">for</font> (i=from; i>to; --i)
00110 path.push_back(<a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>[i]);
00111 }
00112 }
00113
00114 <font class="comment">//</font>
<a name="l00115"></a><a class="code" href="classNLPACS_1_1COrderedChain.html#a12">00115</a> <font class="keywordtype">float</font> <a class="code" href="classNLPACS_1_1COrderedChain.html#a12">NLPACS::COrderedChain::distance</a>(<font class="keyword">const</font> CVector &position)<font class="keyword"> const</font>
00116 <font class="keyword"></font>{
00117 <font class="keywordtype">float</font> minDist = 1.0e10f;
00118 uint i;
00119 CVector2f pos = CVector2f(position);
00120
00121 <font class="keywordflow">for</font> (i=0; i+1<<a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>.size(); ++i)
00122 {
00123 CVector2f a = <a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>[i].unpack(),
00124 b = <a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>[i+1].unpack();
00125
00126 CVector2f d = (b-a);
00127 <font class="keywordtype">float</font> len = d.norm();
00128 d /= len;
00129 CVector2f n = CVector2f(d.y, -d.x);
00130
00131 <font class="keywordtype">float</font> <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a> = (pos-a)*d;
00132 <font class="keywordtype">float</font> dist;
00133
00134 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a> < 0.0f)
00135 {
00136 dist = (pos-a).norm();
00137 }
00138 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a> > len)
00139 {
00140 dist = (pos-b).norm();
00141 }
00142 <font class="keywordflow">else</font>
00143 {
00144 dist = (float)fabs((pos-a)*n);
00145 }
00146
00147 <font class="keywordflow">if</font> (dist < minDist)
00148 {
00149 minDist = dist;
00150 }
00151 }
00152
00153 <font class="keywordflow">return</font> minDist;
00154 }
00155
00156
00157 <font class="comment">// serialises the ordered chain</font>
<a name="l00158"></a><a class="code" href="classNLPACS_1_1COrderedChain.html#a13">00158</a> <font class="keywordtype">void</font> <a class="code" href="classNLPACS_1_1COrderedChain.html#a13">NLPACS::COrderedChain::serial</a>(IStream &f)
00159 {
00160 <font class="comment">/*</font>
00161 <font class="comment"> Version 0:</font>
00162 <font class="comment"> - base version.</font>
00163 <font class="comment"> Version 1:</font>
00164 <font class="comment"> - added _Min and _Max vectors</font>
00165 <font class="comment"> */</font>
00166 sint ver= f.serialVersion(1);
00167
00168 f.serialCont(<a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>);
00169 f.serial(<a class="code" href="classNLPACS_1_1COrderedChain.html#n1">_Forward</a>);
00170 f.serial(<a class="code" href="classNLPACS_1_1COrderedChain.html#n2">_ParentId</a>);
00171 f.serial(<a class="code" href="classNLPACS_1_1COrderedChain.html#n3">_IndexInParent</a>);
00172 f.serial(<a class="code" href="classNLPACS_1_1COrderedChain.html#n4">_Length</a>);
00173
00174 <font class="keywordflow">if</font> (ver >= 1)
00175 {
00176 f.serial(<a class="code" href="classNLPACS_1_1COrderedChain.html#n5">_Min</a>, <a class="code" href="classNLPACS_1_1COrderedChain.html#n6">_Max</a>);
00177 }
00178 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (f.isReading() && !<a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>.empty())
00179 {
00180 uint i;
00181 <a class="code" href="classNLPACS_1_1COrderedChain.html#n6">_Max</a> = <a class="code" href="classNLPACS_1_1COrderedChain.html#n5">_Min</a> = <a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>[0];
00182 <font class="keywordflow">for</font> (i=1; i<<a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>.size(); ++i)
00183 {
00184 <a class="code" href="classNLPACS_1_1COrderedChain.html#n5">_Min</a>.minof(<a class="code" href="classNLPACS_1_1COrderedChain.html#n5">_Min</a>, <a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>[i]);
00185 <a class="code" href="classNLPACS_1_1COrderedChain.html#n6">_Max</a>.maxof(<a class="code" href="classNLPACS_1_1COrderedChain.html#n6">_Max</a>, <a class="code" href="classNLPACS_1_1COrderedChain.html#n0">_Vertices</a>[i]);
00186 }
00187 }
00188 }
00189
00190 <font class="comment">// end of COrderedChain methods implementation</font>
00191
00192
00193 <font class="comment">// CChain methods implementation</font>
00194
00195 <font class="comment">// builds the CChain from a list of vertices and a left and right surfaces id.</font>
00196 <font class="comment">// the chains vector is the vector where to store generated ordered chains.</font>
00197 <font class="comment">// thisId is the current id of the CChain, and edge is the number of the edge the CChain belongs to (-1</font>
00198 <font class="comment">// if none.)</font>
00199 <font class="keywordtype">void</font> <a class="code" href="classNLPACS_1_1CChain.html#b0">NLPACS::CChain::make</a>(<font class="keyword">const</font> vector<CVector> &vertices, sint32 left, sint32 right, vector<COrderedChain> &chains, uint16 thisId,
00200 vector<COrderedChain3f> &fullChains)
00201 {
00202 sint first = 0, last = 0, i;
00203
00204 _Left = left;
00205 _Right = right;
00206 <a class="code" href="classNLPACS_1_1COrderedChain.html#n4">_Length</a> = 0.0f;
00207
00208 <font class="comment">// splits the vertices list in ordered sub chains.</font>
00209 <font class="keywordflow">while</font> (first < (sint)vertices.size()-1)
00210 {
00211 last = first+1;
00212 <font class="keywordtype">bool</font> forward = <a class="code" href="chain_8cpp.html#a0">isStrictlyLess</a>(vertices[first], vertices[last]);
00213
00214 <font class="comment">// first checks if the subchain goes forward or backward.</font>
00215 <font class="keywordflow">if</font> (forward)
00216 <font class="keywordflow">for</font> (; last < (sint)vertices.size() && <a class="code" href="chain_8cpp.html#a0">isStrictlyLess</a>(vertices[last-1], vertices[last]); ++last)
00217 ;
00218 <font class="keywordflow">else</font>
00219 <font class="keywordflow">for</font> (; last < (sint)vertices.size() && <a class="code" href="chain_8cpp.html#a1">isStrictlyGreater</a>(vertices[last-1], vertices[last]); ++last)
00220 ;
00221 --last;
00222
00223 <font class="comment">// inserts the new subchain id within the CChain.</font>
00224 uint32 subChainId = chains.size();
00225 <font class="keywordflow">if</font> (subChainId > 65535)
00226 <a class="code" href="debug_8h.html#a3">nlerror</a>(<font class="stringliteral">"in NLPACS::CChain::make(): reached the maximum number of ordered chains"</font>);
00227 _SubChains.push_back((uint16)subChainId);
00228
00229 <font class="comment">// and creates a new COrderedChain</font>
00230 fullChains.resize(fullChains.size()+1);
00231 COrderedChain3f &subchain3f = fullChains.back();
00232 subchain3f._Vertices.reserve(last-first+1);
00233 subchain3f._Forward = forward;
00234 subchain3f._ParentId = thisId;
00235 subchain3f._IndexInParent = _SubChains.size()-1;
00236
00237 <font class="comment">// and then copies the vertices (sorted, btw!)</font>
00238 <font class="keywordflow">if</font> (forward)
00239 <font class="keywordflow">for</font> (i=first; i<=last; ++i)
00240 subchain3f._Vertices.push_back(vertices[i]);
00241 <font class="keywordflow">else</font>
00242 <font class="keywordflow">for</font> (i=last; i>=first; --i)
00243 subchain3f._Vertices.push_back(vertices[i]);
00244
00245 first = last;
00246
00247 chains.resize(chains.size()+1);
00248 COrderedChain &subchain = chains.back();
00249 subchain.pack(subchain3f);
00250 subchain.computeMinMax();
00251
00252 <font class="keywordtype">float</font> length = 0.0f;
00253 <font class="keywordflow">for</font> (i=0; i<(sint)subchain._Vertices.size()-1; ++i)
00254 length += (subchain._Vertices[i+1]-subchain._Vertices[i]).norm();
00255
00256 subchain._Length = length;
00257 <a class="code" href="classNLPACS_1_1COrderedChain.html#n4">_Length</a> += length;
00258 }
00259 }
00260
00261 <font class="comment">// serialises the CChain</font>
<a name="l00262"></a><a class="code" href="classNLPACS_1_1CChain.html#a14">00262</a> <font class="keywordtype">void</font> <a class="code" href="classNLPACS_1_1CChain.html#a14">NLPACS::CChain::serial</a>(IStream &f)
00263 {
00264 <font class="comment">/*</font>
00265 <font class="comment"> Version 0:</font>
00266 <font class="comment"> - base version.</font>
00267 <font class="comment"> */</font>
00268 (void)f.serialVersion(0);
00269
00270 f.serialCont(<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>);
00271 f.serial(<a class="code" href="classNLPACS_1_1CChain.html#n1">_Left</a>, <a class="code" href="classNLPACS_1_1CChain.html#n2">_Right</a>);
00272 f.serial(<a class="code" href="classNLPACS_1_1CChain.html#n3">_StartTip</a>, <a class="code" href="classNLPACS_1_1CChain.html#n4">_StopTip</a>);
00273 f.serial(<a class="code" href="classNLPACS_1_1CChain.html#n5">_Length</a>);
00274 f.serial(<a class="code" href="classNLPACS_1_1CChain.html#n6">_LeftLoop</a>, <a class="code" href="classNLPACS_1_1CChain.html#n7">_LeftLoopIndex</a>);
00275 f.serial(<a class="code" href="classNLPACS_1_1CChain.html#n8">_RightLoop</a>, <a class="code" href="classNLPACS_1_1CChain.html#n9">_RightLoopIndex</a>);
00276 }
00277
00278
00279
00280 <font class="comment">// unifiies the chain</font>
00281 <font class="keywordtype">void</font> <a class="code" href="classNLPACS_1_1CChain.html#b3">NLPACS::CChain::unify</a>(vector<NLPACS::COrderedChain> &ochains)
00282 {
00283 CVector2s snap;
00284 uint i;
00285
00286 snap = (ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[0]].isForward()) ? ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[0]]._Vertices.back() : ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[0]]._Vertices.front();
00287
00288 <font class="keywordflow">for</font> (i=1; i<<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.size(); ++i)
00289 {
00290 <font class="keywordflow">if</font> (ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[i]].isForward())
00291 {
00292 <font class="keywordflow">if</font> (ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[i]]._Vertices.front() != snap)
00293 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"ochain %d and %d are not stuck together"</font>, <a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[i-1], <a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[i]);
00294 ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[i]]._Vertices.front() = snap;
00295 snap = ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[i]]._Vertices.back();
00296 }
00297 <font class="keywordflow">else</font>
00298 {
00299 <font class="keywordflow">if</font> (ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[i]]._Vertices.back() != snap)
00300 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"ochain %d and %d are not stuck together"</font>, <a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[i-1], <a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[i]);
00301 ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[i]]._Vertices.back() = snap;
00302 snap = ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>[i]]._Vertices.front();
00303 }
00304 }
00305
00306 }
00307
00308 <font class="comment">//</font>
00309 <font class="keywordtype">void</font> <a class="code" href="classNLPACS_1_1CChain.html#b4">NLPACS::CChain::setStartVector</a>(<font class="keyword">const</font> <a class="code" href="classNLPACS_1_1CVector2s.html">NLPACS::CVector2s</a> &<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>, vector<NLPACS::COrderedChain> &ochains)
00310 {
00311 <font class="keywordflow">if</font> (ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.front()].isForward())
00312 ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.front()]._Vertices.front() = v;
00313 <font class="keywordflow">else</font>
00314 ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.front()]._Vertices.back() = v;
00315 }
00316
00317 <font class="comment">//</font>
00318 <font class="keywordtype">void</font> <a class="code" href="classNLPACS_1_1CChain.html#b5">NLPACS::CChain::setStopVector</a>(<font class="keyword">const</font> <a class="code" href="classNLPACS_1_1CVector2s.html">NLPACS::CVector2s</a> &<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>, vector<NLPACS::COrderedChain> &ochains)
00319 {
00320 <font class="keywordflow">if</font> (ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.back()].isForward())
00321 ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.back()]._Vertices.back() = v;
00322 <font class="keywordflow">else</font>
00323 ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.back()]._Vertices.front() = v;
00324 }
00325
00326 <font class="comment">//</font>
00327 <a class="code" href="classNLPACS_1_1CVector2s.html">NLPACS::CVector2s</a> <a class="code" href="classNLPACS_1_1CChain.html#b6">NLPACS::CChain::getStartVector</a>(vector<NLPACS::COrderedChain> &ochains)
00328 {
00329 <font class="keywordflow">if</font> (ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.front()].isForward())
00330 <font class="keywordflow">return</font> ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.front()]._Vertices.front();
00331 <font class="keywordflow">else</font>
00332 <font class="keywordflow">return</font> ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.front()]._Vertices.back();
00333 }
00334
00335 <font class="comment">//</font>
00336 <a class="code" href="classNLPACS_1_1CVector2s.html">NLPACS::CVector2s</a> <a class="code" href="classNLPACS_1_1CChain.html#b7">NLPACS::CChain::getStopVector</a>(vector<NLPACS::COrderedChain> &ochains)
00337 {
00338 <font class="keywordflow">if</font> (ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.back()].isForward())
00339 <font class="keywordflow">return</font> ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.back()]._Vertices.back();
00340 <font class="keywordflow">else</font>
00341 <font class="keywordflow">return</font> ochains[<a class="code" href="classNLPACS_1_1CChain.html#n0">_SubChains</a>.back()]._Vertices.front();
00342 }
00343
00344 <font class="comment">// end of CChain methods implementation</font>
00345
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|