File: BrainModelVolumeSureFitErrorCorrection.h

package info (click to toggle)
caret 5.6.4~dfsg.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 31,904 kB
  • ctags: 28,901
  • sloc: cpp: 378,050; python: 6,718; ansic: 5,507; makefile: 333; sh: 46
file content (333 lines) | stat: -rw-r--r-- 13,374 bytes parent folder | download | duplicates (2)
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


#ifndef __BRAIN_MODEL_VOLUME_SUREFIT_ERROR_CORRECTION_H__
#define __BRAIN_MODEL_VOLUME_SUREFIT_ERROR_CORRECTION_H__

/*LICENSE_START*/
/*
 *  Copyright 1995-2002 Washington University School of Medicine
 *
 *  http://brainmap.wustl.edu
 *
 *  This file is part of CARET.
 *
 *  CARET 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 2 of the License, or
 *  (at your option) any later version.
 *
 *  CARET 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 CARET; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
/*LICENSE_END*/

#include <map>
#include <vector>

#include "BrainModelAlgorithm.h"
#include "DebugControl.h"
#include "VolumeFile.h"

class BrainModelSurface;
class MetricFile;

/// class for correcting topological errors in segmentation volumes
class BrainModelVolumeSureFitErrorCorrection : public BrainModelAlgorithm {
   public:
      // Constructor
      BrainModelVolumeSureFitErrorCorrection(BrainSet* bs,
                                             VolumeFile* segmentationVolumeIn,
                                             VolumeFile* radialPositionMapVolumeIn,
                                             const VolumeFile::FILE_READ_WRITE_TYPE typeOfVolumeFilesToWriteIn,
                                             const int acIJKIn[3],
                                             const bool leftHemFlagIn,
                                             const bool saveIntermediateFilesIn);
      
      // Destructor
      ~BrainModelVolumeSureFitErrorCorrection();
      
      // get the output volume
      const VolumeFile* getOutputVolume() const { return outputVolume; }
      
      // execute the algorithm
      void execute() throw (BrainModelAlgorithmException);
   
   protected:
      /// class for storing error information
      class ErrorStats {
         public:
            ErrorStats () {
               StartingHandles=0;
               TestObjectNum=0;
               UncorrectedObjects=0;
               CurrentHandles=0;
               MaskHandlesBefore=0;
               MaskCavitiesBefore=0;
               RemainingObjectNum=0;
               CurrentTestNum=1;
               CumulativeTestNum=0;
               ObjectsPatched=0;
               CavitiesPatched=0;
               DisconnectFlag=0;
            }

            ~ErrorStats ()  {
            }      

            int getStartingHandles() const { return StartingHandles; }
            int getTestObjectNum() const { return TestObjectNum; }
            int getUncorrectedObjects() const { return UncorrectedObjects; }
            int getCurrentHandles() const { return CurrentHandles; }
            int getMaskHandlesBefore() const { return MaskHandlesBefore; }
            int getMaskCavitiesBefore() const { return MaskCavitiesBefore; }
            int getRemainingObjectNum() const { return RemainingObjectNum; }
            int getCurrentTestNum() const { return CurrentTestNum; }
            int getCumulativeTestNum() const { return CumulativeTestNum; }
            int getObjectsPatched() const { return ObjectsPatched; }
            int getCavitiesPatched() const { return CavitiesPatched; }
            int getDisconnectFlag() const { return DisconnectFlag; }

            void setStartingHandles(int value) {
               this->StartingHandles=value;
               if (DebugControl::getDebugOn()) {
                  std::cout << "StartingHandles = " << this->StartingHandles << std::endl;
               }
            }

            void setTestObjectNum(int value)  {
               this->TestObjectNum=value;
               if (DebugControl::getDebugOn()) {
                  std::cout << "TestObjectNum = " << this->TestObjectNum << std::endl;
               }
            }

            void setUncorrectedObjects(int value) {
               this->UncorrectedObjects=value;
               if (DebugControl::getDebugOn()) {
                  std::cout << "UncorrectedObjects = " << this->UncorrectedObjects << std::endl;
               }
            }

            void setCurrentHandles(int value) {
               this->CurrentHandles=value;
               if (DebugControl::getDebugOn()) {
                  std::cout << "CurrentHandles = " << this->CurrentHandles << std::endl;
               }
            }

            void setMaskHandlesBefore(int value) {
               this->MaskHandlesBefore=value;
               if (DebugControl::getDebugOn()) {
                  std::cout << "MaskHandlesBefore = " << this->MaskHandlesBefore << std::endl;
               }
            }

            void setMaskCavitiesBefore(int value) {
               this->MaskCavitiesBefore=value;
               if (DebugControl::getDebugOn()) {
                  std::cout << "MaskCavitiesBefore = " << this->MaskCavitiesBefore << std::endl;
               }
            }

            void setRemainingObjectNum(int value) {
               this->RemainingObjectNum=value;
               if (DebugControl::getDebugOn()) {
                  std::cout << "RemainingObjectNum = " << this->RemainingObjectNum << std::endl;
               }
            }

            void setCurrentTestNum(int value) {
               this->CurrentTestNum=value;
               if (DebugControl::getDebugOn()) {
                  std::cout << "CurrentTestNum = " << this->CurrentTestNum << std::endl;
               }
            }

            void setCumulativeTestNum(int value) {
               this->CumulativeTestNum=value;
               if (DebugControl::getDebugOn()) {
                  std::cout << "CumulativeTestNum = " << this->CumulativeTestNum << std::endl;
               }
            }

            void setObjectsPatched(int value) {
               this->ObjectsPatched=value;
               if (DebugControl::getDebugOn()) {
                  std::cout << "ObjectsPatched = " << this->ObjectsPatched << std::endl;
               }
            }

            void setCavitiesPatched(int value) {
               this->CavitiesPatched=value;
               if (DebugControl::getDebugOn()) {
                  std::cout << "CavitiesPatched = " << this->CavitiesPatched << std::endl;
               }
            }

            void setDisconnectFlag(int value) {
               this->DisconnectFlag=value;
               if (DebugControl::getDebugOn()) {
                  if ( this->DisconnectFlag > 0 ) {
                     std::cout << "Handle patched" << std::endl;
                  }
               }
            }

            void print () {
               std::cout << "StartingHandles = " << this->StartingHandles << std::endl;
               std::cout << "TestObjectNum = " << this->TestObjectNum << std::endl;
               std::cout << "UncorrectedObjects = " << this->UncorrectedObjects << std::endl;
               std::cout << "CurrentHandles = " << this->CurrentHandles << std::endl;
               std::cout << "MaskHandlesBefore = " << this->MaskHandlesBefore << std::endl;
               std::cout << "MaskCavitiesBefore = " << this->MaskCavitiesBefore << std::endl;
               std::cout << "RemainingObjectNum = " << this->RemainingObjectNum << std::endl;
               std::cout << "CurrentTestNum = " << this->CurrentTestNum << std::endl;
               std::cout << "CumulativeTestNum = " << this->CumulativeTestNum << std::endl;
               std::cout << "ObjectsPatched = " << this->ObjectsPatched << std::endl;
               std::cout << "CavitiesPatched = " << this->CavitiesPatched << std::endl;
            }
         
         protected:
            int StartingHandles;
            int TestObjectNum;
            int UncorrectedObjects;
            int CurrentHandles;
            int MaskHandlesBefore;
            int MaskCavitiesBefore;
            int RemainingObjectNum;
            int CurrentTestNum;
            int CumulativeTestNum;
            int ObjectsPatched;
            int CavitiesPatched;
            int DisconnectFlag;
      };
      
      // Find the nearest node that is not a crossover and has a compressed 
      void crossoverProjection(const BrainModelSurface* bms,
                    const MetricFile* crossoversMetric,
                    const int crossoverColumn,
                    const MetricFile* compressedMetric,
                    const int compressedMetricColumn,
                    MetricFile* outputMetric,
                    const int outputMetricColumn,
                    const float thresholdValue) throw (BrainModelAlgorithmException);
      
      // Generate a surface from the specified volume.
      void generateSurfaceAndMeasurements(const VolumeFile* vf) throw (BrainModelAlgorithmException);

      // Correct errors in segmetation.
      int correctErrors() throw (BrainModelAlgorithmException);
                                                      
      // 
      void uncorrectedObject() throw (BrainModelAlgorithmException);

      // patch an object
      ErrorStats patchObjectBatch(VolumeFile& rodata, 
                                  VolumeFile& sbpdata, 
                                  const int CurrentHandles, 
                                  const int TestObjectNum) throw (BrainModelAlgorithmException);
                 
      // perform a cycle of patching
      void patchCycle(VolumeFile& ctodata, 
                      VolumeFile& errorsdata, 
                      VolumeFile& sbpdata, 
                      int ctoextent[6], 
                      int TestStats[3], 
                      ErrorStats es) throw (BrainModelAlgorithmException);
            
      // Patch an "endo" handle.
      void patchEndoHandle(VolumeFile& sbpdata, 
                           int ctoextent[6], 
                           int TestStats[3], 
                           ErrorStats es, 
                           const int endo_count) throw (BrainModelAlgorithmException);
                     
      // patch an "Exo" handle.
      void patchExoHandle(VolumeFile& sbpdata, 
                          int ctoextent[6], 
                          int TestStats[3], 
                          ErrorStats es, 
                          const int exoCount) throw (BrainModelAlgorithmException);
                     
      // Patch invaginations
      void patchInvagination(VolumeFile& sbpdata, 
                             int TestStats[3], 
                             ErrorStats es) throw (BrainModelAlgorithmException);

      // read an intermediate volume
      void readIntermediateVolume(VolumeFile* vf,
                      const QString& nameIn) throw (BrainModelAlgorithmException);
                               
      // read an intermediate volume
      void readIntermediateVolume(VolumeFile& vf,
                      const QString& nameIn) throw (BrainModelAlgorithmException);
      
      // write an intermediate volume
      void writeIntermediateVolume(VolumeFile* vf,
                       const QString& nameIn) throw (BrainModelAlgorithmException);
                               
      // write an intermediate volume
      void writeIntermediateVolume(VolumeFile& vf,
                       const QString& nameIn) throw (BrainModelAlgorithmException);
                               
      // convert metric surface data into a volume
      VolumeFile* convertMetricToVolume(const BrainModelSurface* bms,
                                        const MetricFile* mf,
                                        const int metricColumn,
                                        const float scaling,
                                        const float voxelBoxSize);
                            
      // the input segmentation volume
      VolumeFile* segmentationVolume;
      
      // the input radial position map volume
      VolumeFile* radialPositionMapVolume;
      
      // x dimensions of volume being segmented
      int xDim;

      // y dimensions of volume being segmented
      int yDim;

      // z dimensions of volume being segmented
      int zDim;

      // Anterior Commissure voxel indices
      int acIJK[3];

      // hemisphere
      int leftHemFlag;
      
      // intermediate files subdirectory
      QString intermediateFilesSubDirectory;
      
      // save (do not delete) the intermediate files
      bool saveIntermediateFiles;
      
      // intermediate files generated by this algorithm
      std::vector<QString> intermediateFileNames;
      
      // intermediate volume files in memory
      std::map<QString,VolumeFile*> intermediateVolumeFilesInMemory;
      
      // keep intermediate files in memory flag
      bool keepIntermediateFilesInMemoryFlag;
      
      // the output volume
      VolumeFile* outputVolume;
      
      /// type of volume files to write
      VolumeFile::FILE_READ_WRITE_TYPE typeOfVolumeFilesToWrite;
      
      /// was error correction successful?
      bool errorCorrectionWasSuccessfulFlag;
};

#endif //  __BRAIN_MODEL_VOLUME_SUREFIT_ERROR_CORRECTION_H__