File: LayerAssociation.txx

package info (click to toggle)
itksnap 3.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,132 kB
  • sloc: cpp: 91,089; ansic: 1,994; sh: 327; makefile: 16
file content (112 lines) | stat: -rw-r--r-- 2,852 bytes parent folder | download | duplicates (3)
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
#ifndef __Layer_Association_txx__
#define __Layer_Association_txx__

#include "LayerAssociation.h"
#include "IRISApplication.h"
#include "GenericImageData.h"
#include "IRISImageData.h"
#include "SNAPImageData.h"
#include "ImageWrapperBase.h"

template<class TObject, class TFilter, class TFactoryDelegate>
LayerAssociation<TObject, TFilter, TFactoryDelegate>
::LayerAssociation()
{
  m_Source = NULL;
  m_VisitCounter = 0;
}

template<class TObject, class TFilter, class TFactoryDelegate>
LayerAssociation<TObject, TFilter, TFactoryDelegate>
::~LayerAssociation()
{
  SetSource(NULL);
}


template<class TObject, class TFilter, class TFactoryDelegate>
void
LayerAssociation<TObject, TFilter, TFactoryDelegate>
::Update()
{
  m_VisitCounter++;

  // Iterate over all the objects in the image data
  if(m_Source)
    {
    // Iterate over all of the image data objects in IRISApplication
    GenericImageData *id[] = {m_Source->GetIRISImageData(),
                              m_Source->GetSNAPImageData()};

    for(int k = 0; k < 2; k++)
      {
      if(id[k])
        {
        for(LayerIterator lit = id[k]->GetLayers(); !lit.IsAtEnd(); ++lit)
          {
          ImageWrapperBase *wb = lit.GetLayer();
          TFilter *wf = dynamic_cast<TFilter *>(wb);
          if(wf && wf->IsInitialized())
            {
            iterator it = m_LayerMap.find(wf->GetUniqueId());
            if(it != m_LayerMap.end())
              {
              // Mark it as visited
              it->second.m_Visit = m_VisitCounter;
              }
            else
              {
              RHS rhs(m_Delegate.New(wf));
              rhs.m_Visit = m_VisitCounter;
              m_LayerMap.insert(std::make_pair(wf->GetUniqueId(), rhs));
              }
            }
          }
        }
      }
    }

  // Safely delete the objects that have not been visited
  iterator it = m_LayerMap.begin();
  while(it != m_LayerMap.end())
    {
    if(it->second.m_Visit != m_VisitCounter)
      {
      delete (TObject *) it->second;
      m_LayerMap.erase(it++);
      }
    else
      it++;
    }
}

template<class TObject, class TFilter, class TFactoryDelegate>
void
LayerAssociation<TObject, TFilter, TFactoryDelegate>
::SetSource(IRISApplication *source)
{
  if(source != m_Source)
    {
    m_Source = source;
    this->Update();
    }
}

template<class TObject, class TFilter, class TFactoryDelegate>
typename LayerAssociation<TObject, TFilter, TFactoryDelegate>::RHS &
LayerAssociation<TObject, TFilter, TFactoryDelegate>
::operator [] (const TFilter *p)
{
  return m_LayerMap[p->GetUniqueId()];
}

template<class TObject, class TFilter, class TFactoryDelegate>
bool
LayerAssociation<TObject, TFilter, TFactoryDelegate>
::HasLayer(const TFilter *p)
{
  return p && m_LayerMap.find(p->GetUniqueId()) != m_LayerMap.end();
}


#endif // __Layer_Association_txx__