File: PreprocessingFilterConfigTraits.cxx

package info (click to toggle)
itksnap 3.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,196 kB
  • ctags: 9,196
  • sloc: cpp: 62,895; sh: 175; makefile: 13
file content (252 lines) | stat: -rw-r--r-- 7,393 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
/*=========================================================================

  Program:   ITK-SNAP
  Module:    $RCSfile: SNAPImageData.cxx,v $
  Language:  C++
  Date:      $Date: 2011/04/18 17:35:30 $
  Version:   $Revision: 1.11 $
  Copyright (c) 2007 Paul A. Yushkevich

  This file is part of ITK-SNAP

  ITK-SNAP is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

  -----

  Copyright (c) 2003 Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

  This software is distributed WITHOUT ANY WARRANTY; without even
  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "PreprocessingFilterConfigTraits.h"
#include "SlicePreviewFilterWrapper.h"
#include "SlicePreviewFilterWrapper.txx"
#include "GMMClassifyImageFilter.h"
#include "GMMClassifyImageFilter.txx"
#include "RandomForestClassifyImageFilter.h"
#include "RandomForestClassifyImageFilter.txx"
#include "IRISApplication.h"
#include "UnsupervisedClustering.h"
#include "RFClassificationEngine.h"
#include "Rebroadcaster.h"

void
SmoothBinaryThresholdFilterConfigTraits
::AttachInputs(SNAPImageData *sid, FilterType *filter, int channel)
{
  // The work of attaching inputs to the filter is done in SetActiveScalarLayer,
  // so this method does nothing.
}

ScalarImageWrapperBase *
SmoothBinaryThresholdFilterConfigTraits
::GetDefaultScalarLayer(SNAPImageData *sid)
{
  return sid->GetMain()->GetDefaultScalarRepresentation();
}

void
SmoothBinaryThresholdFilterConfigTraits
::DetachInputs(FilterType *filter)
{
  filter->SetInput(NULL);
  filter->SetInputImageMinimum(0);
  filter->SetInputImageMaximum(0);
}

void
SmoothBinaryThresholdFilterConfigTraits
::SetParameters(ParameterType *p, FilterType *filter, int channel)
{
  // Parameters are associated with the layer, so there is nothing to do here
}

void SmoothBinaryThresholdFilterConfigTraits::SetActiveScalarLayer(
    ScalarImageWrapperBase *layer, SmoothBinaryThresholdFilterConfigTraits::FilterType *filter, int channel)
{
  ScalarImageWrapperBase::CommonFormatImageType *image =
      layer->GetCommonFormatImage(
        static_cast<ScalarImageWrapperBase::ExportChannel>(channel));

  filter->SetInput(image);
  filter->SetInputImageMinimum(layer->GetImageMinAsDouble());
  filter->SetInputImageMaximum(layer->GetImageMaxAsDouble());

  // Check if we have threshold parameters already associated with this layer
  SmartPtr<ThresholdSettings> ts =
      dynamic_cast<ThresholdSettings *>(layer->GetUserData("ThresholdSettings"));

  if(!ts->GetInitialized())
    {
    // Associate threshold settings with this layer
    ts->InitializeToDefaultForImage(layer);
    }

  // Propagate modified events from the threshold settings object as events
  // from ImageWrapper. These events are further broadcast by GenericImageData
  // and IRISApplication, making it easy for GUI classes to respond to them
  Rebroadcaster::Rebroadcast(ts, itk::ModifiedEvent(),
                             layer, WrapperProcessingSettingsChangeEvent());

  // Pass the parameters to the filter
  filter->SetParameters(ts);
}

void
EdgePreprocessingFilterConfigTraits
::AttachInputs(SNAPImageData *sid, FilterType *filter, int channel)
{
  ScalarImageWrapperBase *scalar = sid->GetMain()->GetDefaultScalarRepresentation();
  ScalarImageWrapperBase::CommonFormatImageType *image =
      scalar->GetCommonFormatImage(
        static_cast<ScalarImageWrapperBase::ExportChannel>(channel));

  filter->SetInput(image);
  filter->SetInputImageMaximumGradientMagnitude(
        scalar->GetImageGradientMagnitudeUpperLimit());
}

void
EdgePreprocessingFilterConfigTraits
::DetachInputs(FilterType *filter)
{
  filter->SetInput(NULL);
}

void
EdgePreprocessingFilterConfigTraits
::SetParameters(ParameterType *p, FilterType *filter, int channel)
{
  filter->SetParameters(p);
}



void
GMMPreprocessingFilterConfigTraits
::AttachInputs(SNAPImageData *sid, FilterType *filter, int channel)
{
  // Iterate through all of the relevant layers
  for(LayerIterator it = sid->GetLayers(MAIN_ROLE | OVERLAY_ROLE);
      !it.IsAtEnd(); ++it)
    {
    if(it.GetLayerAsScalar())
      {
      AnatomicScalarImageWrapper *w = dynamic_cast<AnatomicScalarImageWrapper *>(it.GetLayer());
      filter->AddScalarImage(w->GetImage());
      }
    else if (it.GetLayerAsVector())
      {
      AnatomicImageWrapper *w = dynamic_cast<AnatomicImageWrapper *>(it.GetLayer());
      filter->AddVectorImage(w->GetImage());
      }
    }

  // Set the GMM input
  UnsupervisedClustering *uc = sid->GetParent()->GetClusteringEngine();
  assert(uc);
  filter->SetMixtureModel(uc->GetMixtureModel());
}

void
GMMPreprocessingFilterConfigTraits
::DetachInputs(FilterType *filter)
{
  while(filter->GetNumberOfValidRequiredInputs())
    filter->PopBackInput();

  filter->SetMixtureModel(NULL);
}

void
GMMPreprocessingFilterConfigTraits
::SetParameters(ParameterType *p, FilterType *filter, int channel)
{
  filter->SetMixtureModel(p);
}








void
RFPreprocessingFilterConfigTraits
::AttachInputs(SNAPImageData *sid, FilterType *filter, int channel)
{
  // Iterate through all of the relevant layers
  for(LayerIterator it = sid->GetLayers(MAIN_ROLE | OVERLAY_ROLE);
      !it.IsAtEnd(); ++it)
    {
    if(it.GetLayerAsScalar())
      {
      AnatomicScalarImageWrapper *w = dynamic_cast<AnatomicScalarImageWrapper *>(it.GetLayer());
      filter->AddScalarImage(w->GetImage());
      }
    else if (it.GetLayerAsVector())
      {
      AnatomicImageWrapper *w = dynamic_cast<AnatomicImageWrapper *>(it.GetLayer());
      filter->AddVectorImage(w->GetImage());
      }
    }

  // Set the classifier input
  RFClassificationEngine *rfe = sid->GetParent()->GetClassificationEngine();
  assert(rfe);
  filter->SetClassifier(rfe->GetClassifier());
}

void
RFPreprocessingFilterConfigTraits
::DetachInputs(FilterType *filter)
{
  while(filter->GetNumberOfValidRequiredInputs())
    filter->PopBackInput();

  filter->SetClassifier(NULL);
}

void
RFPreprocessingFilterConfigTraits
::SetParameters(ParameterType *p, FilterType *filter, int channel)
{
  filter->SetClassifier(p);
}

bool
RFPreprocessingFilterConfigTraits
::IsPreviewable(FilterType *filter[])
{
  return (filter[0]->GetClassifier() != NULL && filter[0]->GetClassifier()->IsValidClassifier());
}








// Instantiate preview wrappers
template class SlicePreviewFilterWrapper<SmoothBinaryThresholdFilterConfigTraits>;
template class SlicePreviewFilterWrapper<EdgePreprocessingFilterConfigTraits>;
template class SlicePreviewFilterWrapper<GMMPreprocessingFilterConfigTraits>;
template class SlicePreviewFilterWrapper<RFPreprocessingFilterConfigTraits>;