File: MultiLabelMeshPipeline.h

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 (194 lines) | stat: -rw-r--r-- 6,121 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
/*=========================================================================

  Program:   ITK-SNAP
  Module:    $RCSfile: MultiLabelMeshPipeline.h,v $
  Language:  C++
  Date:      $Date: 2009/01/23 20:09:38 $
  Version:   $Revision: 1.3 $
  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. 

=========================================================================*/
#ifndef __MultiLabelMeshPipeline_h_
#define __MultiLabelMeshPipeline_h_

#include "SNAPCommon.h"
#include "itkImageRegion.h"
#include "itkSmartPointer.h"
#include "vtkSmartPointer.h"
#include "itksys/MD5.h"
#include "itkObjectFactory.h"
#include "ImageWrapperTraits.h"
#include "RLERegionOfInterestImageFilter.h"
#include "RLEImageScanlineIterator.h"


// Forward reference to itk classes
namespace itk {
  template <class TPixel,unsigned int VDimension> class Image;
  template <class TInputImage, class TOutputImage> class BinaryThresholdImageFilter;
  template <class TImage> class ImageLinearConstIteratorWithIndex;
}


// Forward references
class MeshOptions;
class VTKMeshPipeline;
class vtkPolyData;
class AllPurposeProgressAccumulator;


/**
 * \class MultiLabelMeshPipeline
 * \brief A small pipeline used to convert a multi-label segmentation image to
 * a collection of VTK meshes.
 *
 * For each label, the pipeline uses the checksum mechanism to keep track of
 * whether it has been updated relative to the corresponding mesh. This makes
 * it possible for selective mesh recomputation, leading to fast mesh computation
 * even for big segmentations.
 */
class MultiLabelMeshPipeline : public itk::Object
{
public:

  // Cached information about a VTK mesh
  struct MeshInfo
  {
    // The pointer to the mesh
    vtkSmartPointer<vtkPolyData> Mesh;

    // The checksum for the mesh
    unsigned long CheckSum;

    // The extents of the bounding box
    Vector3i BoundingBox[2];

    // The number of voxels
    unsigned long Count;

    MeshInfo();
    ~MeshInfo();
  };

  // Collection of mesh data for labels present in the image
  typedef std::map<LabelType, MeshInfo> MeshInfoMap;


  irisITKObjectMacro(MultiLabelMeshPipeline, itk::Object)

  /** Input image type */
  typedef LabelImageWrapperTraits::ImageType InputImageType;
  typedef itk::SmartPointer<InputImageType> InputImagePointer;
  
  /** Set the input segmentation image */
  void SetImage(InputImageType *input);

  /** Compute the bounding boxes for different regions.  Prerequisite for 
   * calling ComputeMesh(). Returns the total number of voxels in all boxes */
  unsigned long ComputeBoundingBoxes();

  unsigned long GetVoxelsInBoundingBox(LabelType label) const;

  const MeshInfoMap& GetMeshInfo() { return m_MeshInfo; }

  /** Set the mesh options for this filter */
  void SetMeshOptions(const MeshOptions *options);

  /** Can we compute a mesh for this label? */
  bool CanComputeMesh(LabelType label)
  {
    return m_Histogram[label] > 0l;
  }

  /** Compute a mesh for a particular color label.  Returns true if 
   * the color label is not present in the image */
  bool ComputeMesh(LabelType label, vtkPolyData *outData);

  /** Update the meshes */
  void UpdateMeshes(itk::Command *progressCommand);

  /** Get the collection of computed meshes */
  std::map<LabelType, vtkSmartPointer<vtkPolyData> > GetMeshCollection();

  
  /** Get the progress accumulator from the VTK mesh pipeline */
  AllPurposeProgressAccumulator *GetProgressAccumulator();

protected:

  /** Constructor, which builds the pipeline */
  MultiLabelMeshPipeline();

  /** Deallocate the pipeline filters */
  ~MultiLabelMeshPipeline();

private:
  // Type definitions for the various filters used by this object
  typedef itk::Image<float,3>                InternalImageType;
  typedef itk::SmartPointer<InternalImageType>       InternalImagePointer;
  
  typedef itk::RegionOfInterestImageFilter<
    InputImageType,InputImageType>                   ROIFilter;
  typedef itk::SmartPointer<ROIFilter>               ROIFilterPointer;
  
  typedef itk::BinaryThresholdImageFilter<
    InputImageType,InternalImageType>                ThresholdFilter;
  typedef itk::SmartPointer<ThresholdFilter>         ThresholdFilterPointer;
  
  // Current set of mesh options
  SmartPtr<MeshOptions>       m_MeshOptions;

  // The input image
  InputImagePointer           m_InputImage;

  // The ROI extraction filter used for constructing a bounding box
  ROIFilterPointer            m_ROIFilter;

  // The thresholding filter used to map intensity in the bounding box to
  // standardized range
  ThresholdFilterPointer      m_ThrehsoldFilter;

  MeshInfoMap m_MeshInfo;

  // Set of bounding boxes
  itk::ImageRegion<3>         m_BoundingBox[MAX_COLOR_LABELS];

  // Histogram of the image
  long                        m_Histogram[MAX_COLOR_LABELS];

  // The VTK pipeline
  VTKMeshPipeline *           m_VTKPipeline;

  // Helper routine for the update command
  void UpdateMeshInfoHelper(
      MeshInfo *current_meshinfo,
      const itk::Index<3> &run_start,
      itk::ImageRegionConstIteratorWithIndex<InputImageType> &it,
      unsigned long pos);
};

#endif