TGSTK  0.0.1
The Tumour Growth Simulation ToolKit
tgstkImageProcessorBase.h
Go to the documentation of this file.
1 /*==========================================================================
2 
3  This file is part of the Tumor Growth Simulation ToolKit (TGSTK)
4  (<https://github.com/cormarte/TGSTK>, <https://cormarte.github.io/TGSTK>).
5 
6  Copyright (C) 2021 Corentin Martens
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <https://www.gnu.org/licenses/>.
20 
21  Contact: corentin.martens@ulb.be
22 
23 ==========================================================================*/
24 
36 #ifndef TGSTKIMAGEPROCESSORBASE_H
37 #define TGSTKIMAGEPROCESSORBASE_H
38 
39 #define assertImageNumberOfScalarComponents(image, numberOfScalarComponents) _assertImageNumberOfScalarComponents(image, numberOfScalarComponents, #image)
40 #define assertImageScalarType(image, scalarTypes) _assertImageScalarType(image, scalarTypes, #image)
41 
42 #include <tgstk/tgstkGlobal.h>
44 
45 #include <vector>
46 #include <vtkImageData.h>
47 #include <vtkSmartPointer.h>
48 
50 
51  public:
52 
53  virtual ~tgstkImageProcessorBase();
54 
55  protected:
56 
58 
59  bool _assertImageNumberOfScalarComponents(vtkSmartPointer<vtkImageData> image, std::vector<int> numberOfScalarComponents, std::string name);
60  bool _assertImageScalarType(vtkSmartPointer<vtkImageData> image, std::vector<int> scalarTypes, std::string name);
61  bool assertEqualImageDimensions(std::vector<vtkSmartPointer<vtkImageData>> images);
62  bool assertEqualImageSpacings(std::vector<vtkSmartPointer<vtkImageData>> images);
63  template<typename Type> static void fillImage(vtkSmartPointer<vtkImageData> image, Type value);
64  static vtkSmartPointer<vtkImageData> getNewImageFromReferenceImage(vtkSmartPointer<vtkImageData> reference, int type, int numberOfComponents=1);
65 };
66 
67 template<typename Type>
68 void tgstkImageProcessorBase::fillImage(vtkSmartPointer<vtkImageData> image, Type value) {
69 
70  int* dimensions = image->GetDimensions();
71  int components = image->GetNumberOfScalarComponents();
72 
73  for (int z=0; z<dimensions[2]; z++) {
74 
75  for (int y=0; y<dimensions[1]; y++) {
76 
77  for (int x=0; x<dimensions[0]; x++) {
78 
79  for (int c=0; c<components; c++) {
80 
81  static_cast<Type*>(image->GetScalarPointer(x, y, z))[c] = value;
82  }
83  }
84  }
85  }
86 }
87 
88 #endif // TGSTKIMAGEPROCESSORBASE_H
tgstkImageProcessorBase
Base class for TGSTK image processors.
Definition: tgstkImageProcessorBase.h:49
tgstkGlobal.h
tgstkAlgorithmBase.h
TGSTK_EXPORT
#define TGSTK_EXPORT
Definition: tgstkGlobal.h:31
tgstkImageProcessorBase::fillImage
static void fillImage(vtkSmartPointer< vtkImageData > image, Type value)
Definition: tgstkImageProcessorBase.h:68
tgstkAlgorithmBase
Base class for TGSTK algorithms.
Definition: tgstkAlgorithmBase.h:45