File: mvdStackedLayerModel.h

package info (click to toggle)
otb 7.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,005,476 kB
  • sloc: cpp: 270,143; xml: 128,722; ansic: 4,367; sh: 1,768; python: 1,084; perl: 92; makefile: 72
file content (782 lines) | stat: -rw-r--r-- 20,753 bytes parent folder | download
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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
/*
 * Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef mvdStackedLayerModel_h
#define mvdStackedLayerModel_h

//
// Configuration include.
//// Included at first position before any other ones.
#include "ConfigureMonteverdi.h"

#include "OTBMonteverdiCoreExport.h"

/*****************************************************************************/
/* INCLUDE SECTION                                                           */

//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
#include <QtCore>

//
// System includes (sorted by alphabetic order)

//
// ITK includes (sorted by alphabetic order)

//
// OTB includes (sorted by alphabetic order)

//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdAbstractModel.h"
#include "mvdTypes.h"

/*****************************************************************************/
/* PRE-DECLARATION SECTION                                                   */

//
// External classes pre-declaration.
namespace
{
}

namespace mvd
{
//
// Internal classes pre-declaration.
class AbstractLayerModel;

/*****************************************************************************/
/* CLASS DEFINITION SECTION                                                  */

/**
 * \class StackedLayerModel
 *
 * \ingroup OTBMonteverdiCore
 *
 * \brief WIP.
 */
class OTBMonteverdiCore_EXPORT StackedLayerModel : public AbstractModel
{

  /*-[ QOBJECT SECTION ]-----------------------------------------------------*/

  Q_OBJECT;

  //
  // Private types
private:
  // typedef std::vector< AbstractLayerModel * > LayerModelVector;
  typedef std::map<std::string, AbstractLayerModel*> LayerModelMap;

  // typedef std::pair< AbstractLayerModel *, void * > LayerModelPair;
  // typedef std::map< std::string, LayerDataPair > LayerModelPairMap;

  /*-[ PUBLIC SECTION ]------------------------------------------------------*/

  //
  // Public types.
public:
  typedef std::vector<LayerModelMap::key_type> KeyVector;

  typedef LayerModelMap::size_type      SizeType;
  typedef LayerModelMap::key_type       KeyType;
  typedef LayerModelMap::const_iterator ConstIterator;
  static const SizeType                 NIL_INDEX;

  //
  // Public methods.
public:
  /** \brief Constructor. */
  StackedLayerModel(QObject* p = NULL);

  /** \brief Destructor. */
  ~StackedLayerModel() override;

  inline const AbstractLayerModel* operator[](SizeType) const;
  inline AbstractLayerModel* operator[](SizeType);

  KeyType Add(AbstractLayerModel*);

  inline const AbstractLayerModel* At(SizeType) const;
  inline AbstractLayerModel*       At(SizeType);

  inline ConstIterator Begin() const;

  inline void BeginEditPixelInfo(){};

  void BeginEditResolutions(){};

  inline bool Contains(const KeyType& key) const;
  bool Contains(const AbstractLayerModel*) const;

  void CountSRT(size_t& unknown, size_t& carto, size_t& geo, size_t& sensor) const;

  inline ConstIterator End() const;

  inline void EndEditPixelInfo(const QPoint&, const PointType&);

  void EndEditResolutions();

  /*
  inline const AbstractLayerModel * Front() const;
  inline AbstractLayerModel * Front();
  */
  inline ConstIterator Find(const AbstractLayerModel*) const;

  inline const AbstractLayerModel* Get(const KeyType&) const;
  inline AbstractLayerModel*       Get(const KeyType&);

  inline SizeType GetCount() const;

  inline const KeyType& GetKey(SizeType) const;

  inline const KeyVector& GetKeys() const;

  template <typename T>
  T* GetCurrent() const;

  template <typename T>
  T* GetCurrent();

  AbstractLayerModel* GetCurrent() const;
  AbstractLayerModel* GetCurrent();

  inline SizeType GetCurrentIndex() const;

  inline const KeyType& GetCurrentKey() const;

  template <typename T>
  T* GetReference() const;

  template <typename T>
  T* GetReference();

  AbstractLayerModel* GetReference() const;
  AbstractLayerModel* GetReference();

  inline SizeType GetReferenceIndex() const;

  inline bool HasCurrent() const;

  inline bool HasReference() const;

  inline SizeType IndexOf(const AbstractLayerModel*) const;

  KeyType Insert(AbstractLayerModel*, SizeType index);

  inline bool IsEmpty() const;

  inline const PixelInfo::Vector& PixelInfos() const;
  inline PixelInfo::Vector&       PixelInfos();

  inline void SetCurrent(SizeType, bool = false);
  void        SetCurrent(const KeyType&);
  void        SetCurrent(const AbstractLayerModel*);

  inline void SetReference(SizeType, bool = false);
  void        SetReference(const KeyType&);
  void        SetReference(const AbstractLayerModel*);

  /*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/

  //
  // Public SLOTS.
public slots:
  void Clear();
  void Deleting(unsigned int index);
  inline void Delete(const KeyType&);
  inline void DeleteCurrent();
  inline void LowerCurrent();
  inline void MoveCurrentToBottom();
  inline void MoveCurrentToTop();
  inline void RaiseCurrent();
  inline void RotateLayers(int);
  inline void SelectFirst();
  inline void SelectLast();
  inline void SelectPrevious();
  inline void SelectNext();

  /*-[ SIGNALS SECTION ]-----------------------------------------------------*/

  //
  // Signals.
signals:
  void AboutToChangeSelectedLayerModel(const StackedLayerModel::KeyType&);
  void SelectedLayerModelChanged(const StackedLayerModel::KeyType&);

  void ContentAboutToBeChanged();
  void ContentAboutToBeReset();
  void ContentChanged();
  void ContentReset();

  void CurrentAboutToBeChanged(size_t);
  void CurrentChanged(size_t);

  void LayerAboutToBeDeleted(size_t index);
  void LayerAdded(size_t index);
  void LayerDeleted(size_t index);

  void OrderAboutToBeChanged();
  void OrderChanged();

  void PixelInfoChanged(const QPoint&, const PointType&, const PixelInfo::Vector&);

  void ReferenceAboutToBeChanged(size_t);
  void ReferenceChanged(size_t);

  void ResolutionsChanged(const PixelInfo::Vector&);

  void LayerRenamed();

  /*-[ PROTECTED SECTION ]---------------------------------------------------*/

  //
  // Protected methods.
protected:
  //
  // Protected attributes.
protected:
  /*-[ PRIVATE SECTION ]-----------------------------------------------------*/

  //
  // Private methods.
private:
  static KeyType GenerateKey(AbstractLayerModel*);

  inline void ClearPixelInfos();

  void Delete(SizeType);

  inline SizeType FindKey(const KeyType&) const;

  inline SizeType Next(SizeType);
  inline SizeType Prev(SizeType);

  void RaiseLayer(SizeType);
  void LowerLayer(SizeType);

  void RotateLayerUp(SizeType);
  void RotateLayerDown(SizeType);

  void MoveTo(SizeType index, SizeType position);
  void MoveToTop(SizeType);
  void MoveToBottom(SizeType);

  // inline void Swap( SizeType, SizeType );

  inline const KeyType& KeyOf(const AbstractLayerModel*) const;

  //
  // Private attributes.
private:
  static const KeyType NIL_KEY;

  static SizeType m_LayerCount;

  LayerModelMap m_LayerModels;
  KeyVector     m_Keys;
  SizeType      m_Current;
  SizeType      m_Reference;

  // Usually, information is a singular term which denotes a
  // plural. Since there's a container of several pixel-infos and we
  // usually name container variables by using the plural form, an 's'
  // is appended to PixelInfo.
  PixelInfo::Vector m_PixelInfos;

  /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/

  //
  // Slots.
private slots:
};

#if OTB_DEBUG
inline void trace(const StringVector&);
#endif

} // end namespace 'mvd'.

/*****************************************************************************/
/* INLINE SECTION                                                            */

//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.

//
// System includes (sorted by alphabetic order)

//
// ITK includes (sorted by alphabetic order)

//
// OTB includes (sorted by alphabetic order)

//
// Monteverdi includes (sorted by alphabetic order)

namespace mvd
{

/*****************************************************************************/
inline const AbstractLayerModel* StackedLayerModel::operator[](SizeType i) const
{
  return At(i);
}

/*****************************************************************************/
inline AbstractLayerModel* StackedLayerModel::operator[](SizeType i)
{
  return At(i);
}

/*****************************************************************************/
inline const AbstractLayerModel* StackedLayerModel::At(SizeType i) const
{
  return const_cast<StackedLayerModel*>(this)->At(i);
}

/*****************************************************************************/
inline AbstractLayerModel* StackedLayerModel::At(SizeType i)
{
  if (i >= GetCount())
    return NULL;

  assert(!GetKey(i).empty());

  LayerModelMap::const_iterator it(m_LayerModels.find(GetKey(i)));

  assert(it != m_LayerModels.end());

  return it->second;
}

/*****************************************************************************/
inline StackedLayerModel::ConstIterator StackedLayerModel::Begin() const
{
  return m_LayerModels.begin();
}

/*****************************************************************************/
inline void StackedLayerModel::ClearPixelInfos()
{
  m_PixelInfos.reserve(0);
}

/*****************************************************************************/
inline bool StackedLayerModel::Contains(const KeyType& key) const
{
  return m_LayerModels.find(key) != m_LayerModels.end();
}

/*****************************************************************************/
inline void StackedLayerModel::Delete(const KeyType& key)
{
  // qDebug() << this << "::Delete(" << key << ")";

  Delete(FindKey(key));
}

/*****************************************************************************/
inline void StackedLayerModel::DeleteCurrent()
{
  // qDebug() << this << "::DeleteCurrent()";

  Delete(m_Current);
}

/*****************************************************************************/
inline StackedLayerModel::SizeType StackedLayerModel::FindKey(const KeyType& key) const
{
  KeyVector::const_iterator it(std::find(m_Keys.begin(), m_Keys.end(), key));

  if (it == m_Keys.end())
    return StackedLayerModel::NIL_INDEX;

  return std::distance(m_Keys.begin(), it);
}

/*****************************************************************************/
inline StackedLayerModel::SizeType StackedLayerModel::GetCount() const
{
  return m_LayerModels.size();
}

/*****************************************************************************/
inline const StackedLayerModel::KeyVector& StackedLayerModel::GetKeys() const
{
  return m_Keys;
}

/*****************************************************************************/
inline bool StackedLayerModel::HasCurrent() const
{
  return m_Current < GetCount();
}

/*****************************************************************************/
inline bool StackedLayerModel::HasReference() const
{
  return m_Reference < GetCount();
}

/*****************************************************************************/
inline StackedLayerModel::ConstIterator StackedLayerModel::End() const
{
  return m_LayerModels.end();
}

/*****************************************************************************/
inline void StackedLayerModel::EndEditPixelInfo(const QPoint& screen, const PointType& view)
{
  emit PixelInfoChanged(screen, view, m_PixelInfos);
}

/*****************************************************************************/
StackedLayerModel::ConstIterator StackedLayerModel::Find(const AbstractLayerModel* layer) const
{
  for (LayerModelMap::const_iterator it(m_LayerModels.begin()); it != m_LayerModels.end(); ++it)
    if (it->second == layer)
      return it;

  return m_LayerModels.end();
}

/*****************************************************************************/
const AbstractLayerModel* StackedLayerModel::Get(const KeyType& key) const
{
  return const_cast<StackedLayerModel*>(this)->Get(key);
}

/*****************************************************************************/
AbstractLayerModel* StackedLayerModel::Get(const KeyType& key)
{
  ConstIterator it(m_LayerModels.find(key));

  return it == m_LayerModels.end() ? NULL : it->second;
}

/*****************************************************************************/
template <typename T>
inline T* StackedLayerModel::GetCurrent()
{
  return dynamic_cast<T*>(GetCurrent());
}

/*****************************************************************************/
template <typename T>
inline T* StackedLayerModel::GetCurrent() const
{
  return dynamic_cast<T*>(GetCurrent());
}

/*****************************************************************************/
inline AbstractLayerModel* StackedLayerModel::GetCurrent()
{
  if (m_Current >= GetCount())
    return NULL;

  LayerModelMap::const_iterator it(m_LayerModels.find(m_Keys[m_Current]));

  if (it == m_LayerModels.end())
    return NULL;

  return it->second;
}

/*****************************************************************************/
inline AbstractLayerModel* StackedLayerModel::GetCurrent() const
{
  return const_cast<StackedLayerModel*>(this)->GetCurrent();
}

/*****************************************************************************/
inline StackedLayerModel::SizeType StackedLayerModel::GetCurrentIndex() const
{
  return m_Current;
}

/*****************************************************************************/
inline const StackedLayerModel::KeyType& StackedLayerModel::GetCurrentKey() const
{
  return GetKey(m_Current);
}

/*****************************************************************************/
inline const StackedLayerModel::KeyType& StackedLayerModel::GetKey(SizeType index) const
{
  if (index >= GetCount())
    return StackedLayerModel::NIL_KEY;

  return m_Keys[index];
}

/*****************************************************************************/
template <typename T>
inline T* StackedLayerModel::GetReference()
{
  return dynamic_cast<T*>(GetReference());
}

/*****************************************************************************/
template <typename T>
inline T* StackedLayerModel::GetReference() const
{
  return dynamic_cast<T*>(GetReference());
}

/*****************************************************************************/
inline AbstractLayerModel* StackedLayerModel::GetReference()
{
  if (m_Reference >= GetCount())
    return NULL;

  LayerModelMap::const_iterator it(m_LayerModels.find(m_Keys[m_Reference]));

  if (it == m_LayerModels.end())
    return NULL;

  return it->second;
}

/*****************************************************************************/
inline AbstractLayerModel* StackedLayerModel::GetReference() const
{
  return const_cast<StackedLayerModel*>(this)->GetReference();
}

/*****************************************************************************/
inline StackedLayerModel::SizeType StackedLayerModel::GetReferenceIndex() const
{
  return m_Reference;
}


/*****************************************************************************/
inline StackedLayerModel::SizeType StackedLayerModel::IndexOf(const AbstractLayerModel* layer) const
{
  KeyType key(KeyOf(layer));

  if (key == StackedLayerModel::NIL_KEY)
    return StackedLayerModel::NIL_INDEX;

  for (KeyVector::size_type i = 0; i < m_Keys.size(); ++i)
    if (m_Keys[i] == key)
      return i;

  return StackedLayerModel::NIL_INDEX;
}

/*****************************************************************************/
inline bool StackedLayerModel::IsEmpty() const
{
  return m_LayerModels.empty();
}

/*****************************************************************************/
inline const StackedLayerModel::KeyType& StackedLayerModel::KeyOf(const AbstractLayerModel* layerModel) const
{
  for (LayerModelMap::const_iterator it(m_LayerModels.begin()); it != m_LayerModels.end(); ++it)
    if (it->second == layerModel)
      return it->first;

  return StackedLayerModel::NIL_KEY;
}

/*****************************************************************************/
inline void StackedLayerModel::LowerCurrent()
{
  if (GetCount() < 2)
    return;

  assert(m_Current < GetCount());

  if (m_Current == GetCount() - 1)
    RotateLayerDown(1);
  else
    LowerLayer(m_Current);
}

/*****************************************************************************/
void StackedLayerModel::MoveCurrentToBottom()
{
  if (m_Current >= GetCount())
    return;

  MoveToBottom(m_Current);
}

/*****************************************************************************/
void StackedLayerModel::MoveCurrentToTop()
{
  if (m_Current >= GetCount())
    return;

  MoveToTop(m_Current);
}

/*****************************************************************************/
inline StackedLayerModel::SizeType StackedLayerModel::Next(SizeType index)
{
  return index >= GetCount() ? 0 : (index + 1) % GetCount();
}

/*****************************************************************************/
inline const PixelInfo::Vector& StackedLayerModel::PixelInfos() const
{
  return m_PixelInfos;
}

/*****************************************************************************/
inline PixelInfo::Vector& StackedLayerModel::PixelInfos()
{
  return m_PixelInfos;
}

/*****************************************************************************/
inline StackedLayerModel::SizeType StackedLayerModel::Prev(SizeType index)
{
  return index >= GetCount() || index == 0 ? GetCount() - 1 : index - 1;
}

/*****************************************************************************/
inline void StackedLayerModel::RaiseCurrent()
{
  if (GetCount() < 2)
    return;

  assert(m_Current < GetCount());

  if (m_Current == 0)
    RotateLayerUp(1);
  else
    RaiseLayer(m_Current);
}

/*****************************************************************************/
inline void StackedLayerModel::RotateLayers(int steps)
{
  if (IsEmpty())
    return;

  if (steps >= 0)
    RotateLayerUp(steps % GetCount());

  else
    RotateLayerDown((-steps) % GetCount());
}

/*****************************************************************************/
inline void StackedLayerModel::SelectFirst()
{
  if (GetCount() < 1)
    return;

  SetCurrent(SizeType(0));
}

/*****************************************************************************/
inline void StackedLayerModel::SelectLast()
{
  if (GetCount() < 1)
    return;

  SetCurrent(m_Keys.size() - 1);
}

/*****************************************************************************/
inline void StackedLayerModel::SelectNext()
{
  if (IsEmpty())
    return;

  SetCurrent(Next(m_Current));
}

/*****************************************************************************/
inline void StackedLayerModel::SelectPrevious()
{
  if (IsEmpty())
    return;

  SetCurrent(Prev(m_Current));
}

/*****************************************************************************/
inline void StackedLayerModel::SetCurrent(SizeType index, bool force)
{
  // qDebug() << this << "::SetCurrent(" << index << ")";

  if (index == m_Current && !force)
    return;

  KeyType key(GetKey(index));

  // qDebug()
  //   << QString( "'%1'" ).arg( GetCurrentKey().c_str() )
  //   << "->"
  //   << QString( "'%1'" ).arg( key.c_str() );

  emit CurrentAboutToBeChanged(index);
  emit AboutToChangeSelectedLayerModel(key);

  m_Current = index;

  emit CurrentChanged(index);
  emit SelectedLayerModelChanged(key);
}

/*****************************************************************************/
inline void StackedLayerModel::SetReference(SizeType index, bool force)
{
  // qDebug() << this << "::SetReference(" << index << ")";

  if (index == m_Reference && !force)
    return;

  emit ReferenceAboutToBeChanged(index);

  m_Reference = index;

  emit ReferenceChanged(index);
}

/*****************************************************************************/
#if OTB_DEBUG

inline void trace(const StringVector& strv)
{
  qDebug() << "{";

  for (StringVector::const_iterator it(strv.begin()); it != strv.end(); ++it)
    qDebug() << QString("%1").arg(it->c_str());

  qDebug() << "}";
}

#endif

} // end namespace 'mvd'

#endif // mvdStackedLayerModel_h