1
/*=========================================================================
3
* Copyright Insight Software Consortium
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
9
* http://www.apache.org/licenses/LICENSE-2.0.txt
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.
17
*=========================================================================*/
18
#ifndef itkHashImageFilter_h
19
#define itkHashImageFilter_h
22
#include "itkSimpleDataObjectDecorator.h"
23
#include "itkImageLinearConstIteratorWithIndex.h"
24
#include "itkCastImageFilter.h"
25
#include "itkByteSwapper.h"
28
#include "Ancillary/hl_md5.h"
29
#include "Ancillary/hl_sha1.h"
33
/** \class HashImageFilter
34
* \brief Generates a hash string from an image.
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.
40
* \todo Update in-place on to default after fixing bug in InPlaceImageFilter
42
template < class TImageType >
43
class HashImageFilter:
44
public CastImageFilter< TImageType, TImageType >
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;
53
typedef typename TImageType::RegionType RegionType;
55
/** Method for creation through the object factory. */
58
/** Runtime information support. */
59
itkTypeMacro(HashImageFilter, CastImageFilter);
61
/** Smart Pointer type to a DataObject. */
62
typedef typename DataObject::Pointer DataObjectPointer;
64
/** Type of DataObjects used for scalar outputs */
65
typedef SimpleDataObjectDecorator< std::string > HashObjectType;
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) ); }
75
enum HashFunction { SHA1, MD5 };
77
/** Set/Get hashing function as enumerated type */
78
itkSetMacro( HashFunction, HashFunction );
79
itkGetMacro( HashFunction, HashFunction );
81
/** Make a DataObject of the correct type to be used as the specified
83
typedef ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;
84
using Superclass::MakeOutput;
85
virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) ITK_OVERRIDE;
91
// virtual ~HashImageFilter(); // implementation not needed
93
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
95
// See superclass for doxygen documentation
97
// This method is to do work after the superclass potential threaded
99
void AfterThreadedGenerateData() ITK_OVERRIDE;
101
// See superclass for doxygen documentation
103
// Override since the filter produces all of its output
104
void EnlargeOutputRequestedRegion(DataObject *data) ITK_OVERRIDE;
107
HashImageFilter(const Self &); //purposely not implemented
108
void operator=(const Self &); //purposely not implemented
111
HashFunction m_HashFunction;
115
} // end namespace itk
118
#include "itkHashImageFilter.hxx"
120
#endif // itkHashImageFilter_h