VMTK
Loading...
Searching...
No Matches
vtkvmtkImageBoxPainter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkImageBoxPainter.cxx,v $
5 Language: C++
6 Date: $Date: 2005/03/04 11:13:24 $
7 Version: $Revision: 1.2 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
22
23#include "vtkImageData.h"
24#include "vtkObjectFactory.h"
25#include "vtkVersion.h"
26#include "vtkInformation.h"
27#include "vtkStreamingDemandDrivenPipeline.h"
28#include <cmath>
29
31
33{
34 this->PaintValue = 0.0;
35
36 this->BoxBounds[0] = this->BoxBounds[2] = this->BoxBounds[4] = 0.0;
37 this->BoxBounds[1] = this->BoxBounds[3] = this->BoxBounds[5] = 1.0;
38
39 this->BoxExtent[0] = this->BoxExtent[2] = this->BoxExtent[4] = 0;
40 this->BoxExtent[1] = this->BoxExtent[3] = this->BoxExtent[5] = 1;
41
43}
44
45// The switch statement in Execute will call this method with
46// the appropriate input type (IT). Note that this example assumes
47// that the output data type is the same as the input data type.
48// This is not always the case.
49template <class IT>
50void vtkvmtkImageBoxPainterExecute(vtkImageData* input,
51 vtkImageData* output,
52 IT* inPtr, IT* outPtr,
53 int* boxExtent, IT paintValue)
54{
55 int dims[3];
56 input->GetDimensions(dims);
57 if (input->GetScalarType() != output->GetScalarType())
58 {
59 vtkGenericWarningMacro(<< "Execute: input ScalarType, " << input->GetScalarType()
60 << ", must match out ScalarType " << output->GetScalarType());
61 return;
62 }
63
64 int size = dims[0]*dims[1]*dims[2];
65
66 int ijk[3];
67 vtkIdType id;
68
69 for (int i=0; i<size; i++)
70 {
71 outPtr[i] = inPtr[i];
72 }
73
74 for (ijk[2]=boxExtent[4]; ijk[2]<=boxExtent[5]; ++ijk[2])
75 {
76 for (ijk[1]=boxExtent[2]; ijk[1]<=boxExtent[3]; ++ijk[1])
77 {
78 for (ijk[0]=boxExtent[0]; ijk[0]<=boxExtent[1]; ++ijk[0])
79 {
80 id = input->ComputePointId(ijk);
81 outPtr[id] = paintValue;
82 }
83 }
84 }
85}
86
88 vtkImageData* output)
89{
90
91 void* inPtr = input->GetScalarPointer();
92 void* outPtr = output->GetScalarPointer();
93
94 double spacing[3];
95 input->GetSpacing(spacing);
96
98 {
99 this->BoxExtent[0] = (vtkIdType) std::ceil(this->BoxBounds[0] / spacing[0]);
100 this->BoxExtent[1] = (vtkIdType) std::floor(this->BoxBounds[1] / spacing[0]);
101 this->BoxExtent[2] = (vtkIdType) std::ceil(this->BoxBounds[2] / spacing[1]);
102 this->BoxExtent[3] = (vtkIdType) std::floor(this->BoxBounds[3] / spacing[1]);
103 this->BoxExtent[4] = (vtkIdType) std::ceil(this->BoxBounds[4] / spacing[2]);
104 this->BoxExtent[5] = (vtkIdType) std::floor(this->BoxBounds[5] / spacing[2]);
105 }
106
107 int extent[6];
108 vtkInformation *inInfoImage = this->GetInputPortInformation(0);
109 inInfoImage->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), extent);
110
111 if ( this->BoxExtent[0] < extent[0] || this->BoxExtent[1] > extent[1] ||
112 this->BoxExtent[2] < extent[2] || this->BoxExtent[3] > extent[3] ||
113 this->BoxExtent[4] < extent[4] || this->BoxExtent[5] > extent[5] )
114 {
115 vtkErrorMacro(<<"BoxExtent exceeds input WholeExtent");
116 return;
117 }
118
119 int relativeBoxExtent[6];
120 relativeBoxExtent[0] = this->BoxExtent[0] - extent[0];
121 relativeBoxExtent[1] = this->BoxExtent[1] - extent[0];
122 relativeBoxExtent[2] = this->BoxExtent[2] - extent[2];
123 relativeBoxExtent[3] = this->BoxExtent[3] - extent[2];
124 relativeBoxExtent[4] = this->BoxExtent[4] - extent[4];
125 relativeBoxExtent[5] = this->BoxExtent[5] - extent[4];
126
127 switch(output->GetScalarType())
128 {
129 // This is simple a #define for a big case list. It handles
130 // all data types vtk can handle.
131 vtkTemplateMacro(vtkvmtkImageBoxPainterExecute( input, output,
132 static_cast<VTK_TT *>(inPtr), static_cast<VTK_TT *>(outPtr), relativeBoxExtent,
133 static_cast<VTK_TT>(this->PaintValue)));
134 default:
135 vtkGenericWarningMacro("Execute: Unknown input ScalarType");
136 return;
137 }
138}
Create a box shaped sub-volume within a 3D image and paint (assign a value to) every sub-volume eleme...
virtual void SimpleExecute(vtkImageData *input, vtkImageData *output) override
vtkStandardNewMacro(vtkvmtkImageBoxPainter)
void vtkvmtkImageBoxPainterExecute(vtkImageData *input, vtkImageData *output, IT *inPtr, IT *outPtr, int *boxExtent, IT paintValue)