Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
parameter-dart.cc
Go to the documentation of this file.
1 /*
2  * lib-controler-gmap : Le contrôleur de 3-G-cartes, surcouche de lib-controler.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-controler-gmap
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 //******************************************************************************
25 #include "controler-gmap-types.hh"
26 #include "math-extension.hh"
28 #include "parameter-dart.hh"
29 #include <cassert>
30 #include <cstring>
31 using namespace std;
32 using namespace GMap3d;
33 //******************************************************************************
34 CParameterDart::CParameterDart(int ANbSelectionLevels, int ANbRef) :
35  CParameter (ANbRef),
36  FNbSelectionLevels(ANbSelectionLevels)
37 {
38  assert(FNbSelectionLevels>0);
39 
40  FCLUnsel = new float * [FNbSelectionLevels];
41  FCLSel = new float * [FNbSelectionLevels];
42  FCLLastSel = new float * [FNbSelectionLevels];
43  FCL0Remove = new float * [FNbSelectionLevels];
44  FCL1Remove = new float * [FNbSelectionLevels];
45 
46  for (int i=0; i<FNbSelectionLevels; ++i)
47  {
48  FCLUnsel[i] = new float[3];
49  FCLSel[i] = new float[3];
50  FCLLastSel[i] = new float[3];
51  FCL0Remove[i] = new float[3];
52  FCL1Remove[i] = new float[3];
53  }
54 
55  reinit();
56 }
57 //******************************************************************************
59  CParameter (AParam),
60  FNbSelectionLevels(AParam.FNbSelectionLevels),
61  FLWDarts (AParam.FLWDarts),
62  FSAloneDarts (AParam.FSAloneDarts)
63 {
64  assert(FNbSelectionLevels>0);
65 
66  FCLUnsel = new float * [FNbSelectionLevels];
67  FCLSel = new float * [FNbSelectionLevels];
68  FCLLastSel = new float * [FNbSelectionLevels];
69  FCL0Remove = new float * [FNbSelectionLevels];
70  FCL1Remove = new float * [FNbSelectionLevels];
71 
72  for (int i=0; i<FNbSelectionLevels; ++i)
73  {
74  FCLUnsel[i] = new float[3];
75  setCLUnsel(i, AParam.getCLUnsel(i));
76 
77  FCLSel[i] = new float[3];
78  setCLSel(i, AParam.getCLSel(i));
79 
80  FCLLastSel[i] = new float[3];
81  setCLLastSel(i, AParam.getCLLastSel(i));
82 
83  FCL0Remove[i] = new float[3];
84  setCL0Remove(i, AParam.getCL0Remove(i));
85 
86  FCL1Remove[i] = new float[3];
87  setCL1Remove(i, AParam.getCL1Remove(i));
88  }
89 }
90 //******************************************************************************
92 {
93  for (int i=0; i<FNbSelectionLevels; ++i)
94  {
95  delete [] FCLUnsel [i];
96  delete [] FCLSel [i];
97  delete [] FCLLastSel[i];
98  delete [] FCL0Remove [i];
99  delete [] FCL1Remove [i];
100  }
101 
102  delete [] FCLUnsel ;
103  delete [] FCLSel ;
104  delete [] FCLLastSel;
105  delete [] FCL0Remove;
106  delete [] FCL1Remove;
107 }
108 //******************************************************************************
110 { return new CParameterDart(*this); }
111 //******************************************************************************
112 void CParameterDart::save(ostream& AStream)
113 { AStream<<(*this); }
114 //------------------------------------------------------------------------------
115 void CParameterDart::load(istream& AStream)
116 { AStream>>(*this); }
117 //------------------------------------------------------------------------------
119 {
120  assert (FNbSelectionLevels>0);
121 
122  FLWDarts = DEFAULT_DART_LINE_WIDTH;
123  FSAloneDarts = DEFAULT_DART_SIZE_ALONE;
124 
125  setCLUnsel(0,
129  setCLSel(0,
133  setCLLastSel(0,
137  setCL0Remove(0,
141  setCL1Remove(0,
145 
147 
148  if (FNbSelectionLevels==1) return;
149 
150  setCLUnsel(1,
154  setCLSel(1,
158  setCLLastSel(1,
162  setCL0Remove(1,
166  setCL1Remove(1,
170 
171  if (FNbSelectionLevels==2) return;
172 
173  setCLUnsel(2,
177  setCLSel(2,
181  setCLLastSel(2,
185  setCL0Remove(2,
189  setCL1Remove(2,
193 
194  for (int i=3; i<FNbSelectionLevels; ++i)
195  {
196  setCLUnsel(i,
200  setCLSel(i,
204  setCLLastSel(i,
208  setCL0Remove(i,
212  setCL1Remove(i,
216  }
217 }
218 //******************************************************************************
219 namespace GMap3d
220 {
221 //------------------------------------------------------------------------------
222 ostream& operator<<(ostream& AStream, const CParameterDart & AParameter)
223 {
224  AStream<<"CParameterDart:"<<endl;
225 
226  AStream<<" LineWidth: "<<AParameter.FLWDarts<<endl;
227 
228  AStream<<" SizeAlone: "<<AParameter.FSAloneDarts<<endl;
229 
230  AStream<<" SelectionLevelNumber: "<<AParameter.FNbSelectionLevels<<endl;
231 
232  for (int i=0; i<AParameter.FNbSelectionLevels; ++i)
233  {
234  AStream<<" ColorUnsel "<<i<<": "<<AParameter.FCLUnsel[i][0]<<" "
235  <<AParameter.FCLUnsel[i][1]<<" "<<AParameter.FCLUnsel[i][2]<<endl;
236 
237  AStream<<" ColorSel "<<i<<": "<<AParameter.FCLSel[i][0]<<" "
238  <<AParameter.FCLSel[i][1]<<" "<<AParameter.FCLSel[i][2]<<endl;
239 
240  AStream<<" ColorLast "<<i<<": "<<AParameter.FCLLastSel[i][0]<<" "
241  <<AParameter.FCLLastSel[i][1]<<" "<<AParameter.FCLLastSel[i][2]<<endl;
242 
243  AStream<<" Color0Remove "<<i<<": "<<AParameter.FCL0Remove[i][0]<<" "
244  <<AParameter.FCL0Remove[i][1]<<" "<<AParameter.FCL0Remove[i][2]<<endl;
245 
246  AStream<<" Color1Remove "<<i<<": "<<AParameter.FCL1Remove[i][0]<<" "
247  <<AParameter.FCL1Remove[i][1]<<" "<<AParameter.FCL1Remove[i][2]<<endl;
248  }
249 
250  AStream<<endl;
251 
252  return AStream;
253 }
254 //------------------------------------------------------------------------------
255 istream& operator>>(istream& AStream, CParameterDart & AParameter)
256 {
257  char tmp[256];
258 
259  AStream>>tmp; assert ( !strcmp(tmp, "CParameterDart:") );
260 
261  AStream>>tmp; assert ( !strcmp(tmp, "LineWidth:") );
262  AStream>>AParameter.FLWDarts;
263 
264  AStream>>tmp; assert ( !strcmp(tmp, "SizeAlone:") );
265  AStream>>AParameter.FSAloneDarts;
266 
267  int nb, toRead, toIgnore;
268  AStream>>tmp; assert ( !strcmp(tmp, "SelectionLevelNumber:") );
269  AStream>>nb;
270 
271  toRead = MIN(nb,AParameter.FNbSelectionLevels);
272  toIgnore = nb - AParameter.FNbSelectionLevels;
273 
274  int i;
275  for (i=0; i<toRead; ++i)
276  {
277  AStream>>tmp; assert( !strcmp(tmp,"ColorUnsel") ); AStream>>tmp;
278  AStream>>AParameter.FCLUnsel[i][0]
279  >>AParameter.FCLUnsel[i][1]>>AParameter.FCLUnsel[i][2];
280 
281  AStream>>tmp; assert( !strcmp(tmp,"ColorSel") ); AStream>>tmp;
282  AStream>>AParameter.FCLSel[i][0]
283  >>AParameter.FCLSel[i][1]>>AParameter.FCLSel[i][2];
284 
285  AStream>>tmp; assert( !strcmp(tmp,"ColorLast") ); AStream>>tmp;
286  AStream>>AParameter.FCLLastSel[i][0]
287  >>AParameter.FCLLastSel[i][1]>>AParameter.FCLLastSel[i][2];
288 
289  AStream>>tmp; assert( !strcmp(tmp,"Color0Remove") ); AStream>>tmp;
290  AStream>>AParameter.FCL0Remove[i][0]
291  >>AParameter.FCL0Remove[i][1]>>AParameter.FCL0Remove[i][2];
292 
293  AStream>>tmp; assert( !strcmp(tmp,"Color1Remove") ); AStream>>tmp;
294  AStream>>AParameter.FCL1Remove[i][0]
295  >>AParameter.FCL1Remove[i][1]>>AParameter.FCL1Remove[i][2];
296  }
297 
298  for (i=0; i<toIgnore; ++i)
299  {
300  float dummy;
301  AStream>>tmp; assert( !strcmp(tmp,"ColorUnsel") ); AStream>>tmp;
302  AStream>>dummy>>dummy>>dummy;
303  AStream>>tmp; assert( !strcmp(tmp,"ColorSel") ); AStream>>tmp;
304  AStream>>dummy>>dummy>>dummy;
305  AStream>>tmp; assert( !strcmp(tmp,"ColorLast") ); AStream>>tmp;
306  AStream>>dummy>>dummy>>dummy;
307  AStream>>tmp; assert( !strcmp(tmp,"Color0Remove") ); AStream>>tmp;
308  AStream>>dummy>>dummy>>dummy;
309  AStream>>tmp; assert( !strcmp(tmp,"Color1Remove") ); AStream>>tmp;
310  AStream>>dummy>>dummy>>dummy;
311  }
312 
313  AParameter.putAllNeedToUpdate();
314 
315  return AStream;
316 }
317 //------------------------------------------------------------------------------
318 } // namespace GMap3d
319 //******************************************************************************
321 { return FLWDarts; }
322 
324 {
325  if (FLWDarts!=AValue)
326  {
328  FLWDarts= AValue;
329  }
330 }
331 //******************************************************************************
333 { return FSAloneDarts; }
334 
336 {
337  if (FSAloneDarts!=AValue)
338  {
340  FSAloneDarts= AValue;
341  }
342 }
343 //******************************************************************************
344 float CParameterDart::getCLUnsel(int ALevel, int AIndice) const
345 {
346  assert(0<=ALevel && ALevel<FNbSelectionLevels);
347  assert(0<=AIndice && AIndice<=2);
348  return FCLUnsel[ALevel][AIndice];
349 }
350 
351 void CParameterDart::setCLUnsel(int ALevel, int AIndice, float AValue)
352 {
353  assert(0<=ALevel && ALevel<FNbSelectionLevels);
354  assert(0<=AIndice && AIndice<=2);
355  if (FCLUnsel[ALevel][AIndice]!=AValue)
356  {
358  FCLUnsel[ALevel][AIndice]= AValue;
359  }
360 }
361 
362 const float * CParameterDart::getCLUnsel(int ALevel) const
363 {
364  assert(0<=ALevel && ALevel<FNbSelectionLevels);
365  return FCLUnsel[ALevel];
366 }
367 
369  float AValue0, float AValue1, float AValue2)
370 {
371  assert(0<=ALevel && ALevel<FNbSelectionLevels);
372  if ( FCLUnsel[ALevel][0]!=AValue0 ||
373  FCLUnsel[ALevel][1]!=AValue1 ||
374  FCLUnsel[ALevel][2]!=AValue2 )
375  {
377  FCLUnsel[ALevel][0]= AValue0;
378  FCLUnsel[ALevel][1]= AValue1;
379  FCLUnsel[ALevel][2]= AValue2;
380  }
381 }
382 void CParameterDart::setCLUnsel(int ALevel,const float ATab[3])
383 { setCLUnsel(ALevel,ATab[0],ATab[1],ATab[2]); }
384 //******************************************************************************
385 float CParameterDart::getCLSel(int ALevel, int AIndice) const
386 {
387  assert(0<=ALevel && ALevel<FNbSelectionLevels);
388  assert(0<=AIndice && AIndice<=2);
389  return FCLSel[ALevel][AIndice];
390 }
391 void CParameterDart::setCLSel(int ALevel, int AIndice, float AValue)
392 {
393  assert(0<=ALevel && ALevel<FNbSelectionLevels);
394  assert(0<=AIndice && AIndice<=2);
395  if (FCLSel[ALevel][AIndice]!=AValue)
396  {
398  FCLSel[ALevel][AIndice]= AValue;
399  }
400 }
401 const float * CParameterDart::getCLSel(int ALevel) const
402 {
403  assert(0<=ALevel && ALevel<FNbSelectionLevels);
404  return FCLSel[ALevel];
405 }
406 void CParameterDart::setCLSel(int ALevel,
407  float AValue0, float AValue1, float AValue2)
408 {
409  assert(0<=ALevel && ALevel<FNbSelectionLevels);
410  if ( FCLSel[ALevel][0]!=AValue0 ||
411  FCLSel[ALevel][1]!=AValue1 ||
412  FCLSel[ALevel][2]!=AValue2 )
413  {
415  FCLSel[ALevel][0]= AValue0;
416  FCLSel[ALevel][1]= AValue1;
417  FCLSel[ALevel][2]= AValue2;
418  }
419 }
420 void CParameterDart::setCLSel(int ALevel,const float ATab[3])
421 { setCLSel(ALevel,ATab[0],ATab[1],ATab[2]); }
422 //******************************************************************************
423 float CParameterDart::getCLLastSel(int ALevel, int AIndice) const
424 {
425  assert(0<=ALevel && ALevel<FNbSelectionLevels);
426  assert(0<=AIndice && AIndice<=2);
427  return FCLLastSel[ALevel][AIndice];
428 }
429 void CParameterDart::setCLLastSel(int ALevel, int AIndice, float AValue)
430 {
431  assert(0<=ALevel && ALevel<FNbSelectionLevels);
432  assert(0<=AIndice && AIndice<=2);
433  if (FCLLastSel[ALevel][AIndice]!=AValue)
434  {
436  FCLLastSel[ALevel][AIndice]= AValue;
437  }
438 }
439 const float * CParameterDart::getCLLastSel(int ALevel) const
440 {
441  assert(0<=ALevel && ALevel<FNbSelectionLevels);
442  return FCLLastSel[ALevel];
443 }
445  float AValue0, float AValue1, float AValue2)
446 {
447  assert(0<=ALevel && ALevel<FNbSelectionLevels);
448  if ( FCLLastSel[ALevel][0]!=AValue0 ||
449  FCLLastSel[ALevel][1]!=AValue1 ||
450  FCLLastSel[ALevel][2]!=AValue2 )
451  {
453  FCLLastSel[ALevel][0]= AValue0;
454  FCLLastSel[ALevel][1]= AValue1;
455  FCLLastSel[ALevel][2]= AValue2;
456  }
457 }
458 void CParameterDart::setCLLastSel(int ALevel,const float ATab[3])
459 { setCLLastSel(ALevel,ATab[0],ATab[1],ATab[2]); }
460 //******************************************************************************
461 float CParameterDart::getCL0Remove(int ALevel, int AIndice) const
462 {
463  assert(0<=ALevel && ALevel<FNbSelectionLevels);
464  assert(0<=AIndice && AIndice<=2);
465  return FCL0Remove[ALevel][AIndice];
466 }
467 
468 void CParameterDart::setCL0Remove(int ALevel, int AIndice, float AValue)
469 {
470  assert(0<=ALevel && ALevel<FNbSelectionLevels);
471  assert(0<=AIndice && AIndice<=2);
472  if (FCL0Remove[ALevel][AIndice]!=AValue)
473  {
475  FCL0Remove[ALevel][AIndice]= AValue;
476  }
477 }
478 
479 const float * CParameterDart::getCL0Remove(int ALevel) const
480 {
481  assert(0<=ALevel && ALevel<FNbSelectionLevels);
482  return FCL0Remove[ALevel];
483 }
484 
486  float AValue0, float AValue1, float AValue2)
487 {
488  assert(0<=ALevel && ALevel<FNbSelectionLevels);
489  if ( FCL0Remove[ALevel][0]!=AValue0 ||
490  FCL0Remove[ALevel][1]!=AValue1 ||
491  FCL0Remove[ALevel][2]!=AValue2 )
492  {
494  FCL0Remove[ALevel][0]= AValue0;
495  FCL0Remove[ALevel][1]= AValue1;
496  FCL0Remove[ALevel][2]= AValue2;
497  }
498 }
499 void CParameterDart::setCL0Remove(int ALevel,const float ATab[3])
500 { setCL0Remove(ALevel,ATab[0],ATab[1],ATab[2]); }
501 //******************************************************************************
502 float CParameterDart::getCL1Remove(int ALevel, int AIndice) const
503 {
504  assert(0<=ALevel && ALevel<FNbSelectionLevels);
505  assert(0<=AIndice && AIndice<=2);
506  return FCL1Remove[ALevel][AIndice];
507 }
508 
509 void CParameterDart::setCL1Remove(int ALevel, int AIndice, float AValue)
510 {
511  assert(0<=ALevel && ALevel<FNbSelectionLevels);
512  assert(0<=AIndice && AIndice<=2);
513  if (FCL1Remove[ALevel][AIndice]!=AValue)
514  {
516  FCL1Remove[ALevel][AIndice]= AValue;
517  }
518 }
519 
520 const float * CParameterDart::getCL1Remove(int ALevel) const
521 {
522  assert(0<=ALevel && ALevel<FNbSelectionLevels);
523  return FCL1Remove[ALevel];
524 }
525 
527  float AValue0, float AValue1, float AValue2)
528 {
529  assert(0<=ALevel && ALevel<FNbSelectionLevels);
530  if ( FCL1Remove[ALevel][0]!=AValue0 ||
531  FCL1Remove[ALevel][1]!=AValue1 ||
532  FCL1Remove[ALevel][2]!=AValue2 )
533  {
535  FCL1Remove[ALevel][0]= AValue0;
536  FCL1Remove[ALevel][1]= AValue1;
537  FCL1Remove[ALevel][2]= AValue2;
538  }
539 }
540 void CParameterDart::setCL1Remove(int ALevel,const float ATab[3])
541 { setCL1Remove(ALevel,ATab[0],ATab[1],ATab[2]); }
542 //******************************************************************************
544 { return PARAMETER_DART; }
545 //******************************************************************************