~ubuntu-branches/debian/sid/simpleitk/sid

« back to all changes in this revision

Viewing changes to Code/BasicFilters/include/itkHashImageFilter.h

  • Committer: Package Import Robot
  • Author(s): Ghislain Antony Vaillant
  • Date: 2017-11-02 08:49:18 UTC
  • Revision ID: package-import@ubuntu.com-20171102084918-7hs09ih668xq87ej
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
*
 
3
*  Copyright Insight Software Consortium
 
4
*
 
5
*  Licensed under the Apache License, Version 2.0 (the "License");
 
6
*  you may not use this file except in compliance with the License.
 
7
*  You may obtain a copy of the License at
 
8
*
 
9
*         http://www.apache.org/licenses/LICENSE-2.0.txt
 
10
*
 
11
*  Unless required by applicable law or agreed to in writing, software
 
12
*  distributed under the License is distributed on an "AS IS" BASIS,
 
13
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
*  See the License for the specific language governing permissions and
 
15
*  limitations under the License.
 
16
*
 
17
*=========================================================================*/
 
18
#ifndef itkHashImageFilter_h
 
19
#define itkHashImageFilter_h
 
20
 
 
21
 
 
22
#include "itkSimpleDataObjectDecorator.h"
 
23
#include "itkImageLinearConstIteratorWithIndex.h"
 
24
#include "itkCastImageFilter.h"
 
25
#include "itkByteSwapper.h"
 
26
 
 
27
 
 
28
#include "Ancillary/hl_md5.h"
 
29
#include "Ancillary/hl_sha1.h"
 
30
 
 
31
namespace itk {
 
32
 
 
33
/** \class HashImageFilter
 
34
 * \brief Generates a hash string from an image.
 
35
 *
 
36
 * \note This class utlizes low level buffer pointer access, to work
 
37
 * with itk::Image and itk::VectorImage. It is modeled after the access
 
38
 * an ImageFileWriter provides to an ImageIO.
 
39
 *
 
40
 * \todo Update in-place on to default after fixing bug in InPlaceImageFilter
 
41
 */
 
42
template < class TImageType >
 
43
class HashImageFilter:
 
44
    public CastImageFilter< TImageType, TImageType >
 
45
{
 
46
public:
 
47
  /** Standard Self typedef */
 
48
  typedef HashImageFilter                           Self;
 
49
  typedef CastImageFilter< TImageType, TImageType > Superclass;
 
50
  typedef SmartPointer< Self >                      Pointer;
 
51
  typedef SmartPointer< const Self >                ConstPointer;
 
52
 
 
53
  typedef typename TImageType::RegionType RegionType;
 
54
 
 
55
  /** Method for creation through the object factory. */
 
56
  itkNewMacro(Self);
 
57
 
 
58
  /** Runtime information support. */
 
59
  itkTypeMacro(HashImageFilter, CastImageFilter);
 
60
 
 
61
  /** Smart Pointer type to a DataObject. */
 
62
  typedef typename DataObject::Pointer DataObjectPointer;
 
63
 
 
64
  /** Type of DataObjects used for scalar outputs */
 
65
  typedef SimpleDataObjectDecorator< std::string >  HashObjectType;
 
66
 
 
67
  /** Get the computed Hash values */
 
68
  std::string GetHash() const
 
69
  { return this->GetHashOutput()->Get(); }
 
70
  HashObjectType* GetHashOutput()
 
71
  { return static_cast< HashObjectType *>( this->ProcessObject::GetOutput(1) ); }
 
72
  const HashObjectType* GetHashOutput() const
 
73
  { return static_cast<const HashObjectType *>( this->ProcessObject::GetOutput(1) ); }
 
74
 
 
75
  enum  HashFunction { SHA1, MD5 };
 
76
 
 
77
  /** Set/Get hashing function as enumerated type */
 
78
  itkSetMacro( HashFunction, HashFunction );
 
79
  itkGetMacro( HashFunction, HashFunction );
 
80
 
 
81
/** Make a DataObject of the correct type to be used as the specified
 
82
   * output. */
 
83
  typedef ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;
 
84
  using Superclass::MakeOutput;
 
85
  virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) ITK_OVERRIDE;
 
86
 
 
87
protected:
 
88
 
 
89
  HashImageFilter();
 
90
 
 
91
  // virtual ~HashImageFilter(); // implementation not needed
 
92
 
 
93
  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
 
94
 
 
95
  // See superclass for doxygen documentation
 
96
  //
 
97
  // This method is to do work after the superclass potential threaded
 
98
  // copy.
 
99
  void AfterThreadedGenerateData() ITK_OVERRIDE;
 
100
 
 
101
  // See superclass for doxygen documentation
 
102
  //
 
103
  // Override since the filter produces all of its output
 
104
  void EnlargeOutputRequestedRegion(DataObject *data) ITK_OVERRIDE;
 
105
 
 
106
private:
 
107
  HashImageFilter(const Self &); //purposely not implemented
 
108
  void operator=(const Self &);  //purposely not implemented
 
109
 
 
110
 
 
111
  HashFunction m_HashFunction;
 
112
};
 
113
 
 
114
 
 
115
} // end namespace itk
 
116
 
 
117
 
 
118
#include "itkHashImageFilter.hxx"
 
119
 
 
120
#endif // itkHashImageFilter_h