1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkSimpleImageFilterExample.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #include "vtkSimpleImageFilterExample.h"
16 
17 #include "vtkImageData.h"
18 #include "vtkObjectFactory.h"
19 
20 vtkStandardNewMacro(vtkSimpleImageFilterExample);
21 
22 // The switch statement in Execute will call this method with
23 // the appropriate input type (IT). Note that this example assumes
24 // that the output data type is the same as the input data type.
25 // This is not always the case.
26 template <class IT>
vtkSimpleImageFilterExampleExecute(vtkImageData * input,vtkImageData * output,IT * inPtr,IT * outPtr)27 void vtkSimpleImageFilterExampleExecute(vtkImageData* input,
28                                         vtkImageData* output,
29                                         IT* inPtr, IT* outPtr)
30 {
31   int dims[3];
32   input->GetDimensions(dims);
33   if (input->GetScalarType() != output->GetScalarType())
34     {
35     vtkGenericWarningMacro(<< "Execute: input ScalarType, " << input->GetScalarType()
36     << ", must match out ScalarType " << output->GetScalarType());
37     return;
38     }
39 
40   int size = dims[0]*dims[1]*dims[2];
41 
42   for(int i=0; i<size; i++)
43     {
44     outPtr[i] = inPtr[i];
45     }
46 }
47 
SimpleExecute(vtkImageData * input,vtkImageData * output)48 void vtkSimpleImageFilterExample::SimpleExecute(vtkImageData* input,
49                                                 vtkImageData* output)
50 {
51 
52   void* inPtr = input->GetScalarPointer();
53   void* outPtr = output->GetScalarPointer();
54 
55   switch(output->GetScalarType())
56     {
57     // This is simply a #define for a big case list. It handles all
58     // data types VTK supports.
59     vtkTemplateMacro(
60       vtkSimpleImageFilterExampleExecute(input, output,
61                                          static_cast<VTK_TT *>(inPtr),
62                                          static_cast<VTK_TT *>(outPtr)));
63     default:
64       vtkGenericWarningMacro("Execute: Unknown input ScalarType");
65       return;
66     }
67 }
68