Skip to content
Permalink
Browse files

ENH: replace itksys::hash_map and hash_set by std equivalents

itksys::hash_map and hash_set were deprecated.
Replacing them by std::unordered_map and  std::unordered_set.
Some filters assumed ascending ordering within the hash_map.
In those instances itksys::hash_map was replaced by std::map.
Updating new baseline for itkIsolatedWatershedImageFilterTest.png,
as watershed image filter is sensitive to details of computation.
  • Loading branch information...
dzenanz committed Nov 13, 2018
1 parent 78338e2 commit 0e2d4f2dc55e7aca4f40e8f019d24680bd3381de
Showing with 78 additions and 68 deletions.
  1. +2 −0 Documentation/ITK5MigrationGuide.md
  2. +3 −3 Modules/Core/Common/include/itkEquivalencyTable.h
  3. +14 −14 Modules/Core/Common/test/itkHashTableTest.cxx
  4. +3 −3 Modules/Core/Mesh/include/itkAutomaticTopologyMeshSource.h
  5. +2 −2 Modules/Filtering/ImageStatistics/include/itkAdaptiveEqualizationHistogram.h
  6. +2 −2 Modules/Filtering/ImageStatistics/include/itkLabelOverlapMeasuresImageFilter.h
  7. +6 −6 Modules/Filtering/QuadEdgeMeshFiltering/include/itkLaplacianDeformationQuadEdgeMeshFilter.h
  8. +1 −1 ...ring/QuadEdgeMeshFiltering/include/itkLaplacianDeformationQuadEdgeMeshFilterWithSoftConstraints.h
  9. +1 −1 ...ng/QuadEdgeMeshFiltering/include/itkLaplacianDeformationQuadEdgeMeshFilterWithSoftConstraints.hxx
  10. +4 −4 Modules/Nonunit/Review/include/itkLabelGeometryImageFilter.h
  11. +2 −2 Modules/Numerics/Statistics/include/itkKdTreeBasedKmeansEstimator.h
  12. +1 −1 Modules/Numerics/Statistics/include/itkKdTreeBasedKmeansEstimator.hxx
  13. +2 −2 Modules/Numerics/Statistics/include/itkMembershipSample.h
  14. +1 −2 Modules/Segmentation/ConnectedComponents/include/itkRelabelComponentImageFilter.hxx
  15. +18 −5 Modules/Segmentation/ConnectedComponents/test/itkRelabelComponentImageFilterTest.cxx
  16. +2 −2 Modules/Segmentation/LevelSetsv4/include/itkLevelSetEquationTermBase.h
  17. +2 −2 Modules/Segmentation/LevelSetsv4/include/itkLevelSetEquationTermContainer.h
  18. +2 −3 Modules/Segmentation/Watersheds/include/itkOneWayEquivalencyTable.h
  19. +2 −3 Modules/Segmentation/Watersheds/include/itkWatershedBoundary.h
  20. +2 −3 Modules/Segmentation/Watersheds/include/itkWatershedSegmentTable.h
  21. +1 −2 Modules/Segmentation/Watersheds/include/itkWatershedSegmentTreeGenerator.h
  22. +3 −3 Modules/Segmentation/Watersheds/include/itkWatershedSegmenter.h
  23. +1 −1 Modules/Segmentation/Watersheds/test/Baseline/itkIsolatedWatershedImageFilterTest.png.md5
  24. +1 −1 Modules/Segmentation/Watersheds/test/Baseline/itkIsolatedWatershedImageFilterTest.png.sha512
@@ -405,6 +405,8 @@ Class changes
[itk::FilterWatcher](../Modules/Core/TestKernel/include/itkFilterWatcher.h) was deleted.
It should be replaced by [itk::SimpleFilterWatcher](../Modules/Core/Common/include/itkSimpleFilterWatcher.h).
`itksys::hash_map` has been removed. It should be replaced by `std::unordered_map`.
Since `itk::ProgressReporter` does not work well with the new threading model,
it should be replaced by `itk::ProgressTransformer`.
This only applies to classes which use `GenerateData()` method, and either
@@ -20,7 +20,7 @@


#include "itkProcessObject.h"
#include "itksys/hash_map.hxx"
#include <unordered_map>

namespace itk
{
@@ -55,8 +55,8 @@ class ITKCommon_EXPORT EquivalencyTable:public DataObject
itkTypeMacro(EquivalencyTable, DataObject);

/** Define the container type for the table. */
using HashTableType = itksys::hash_map< unsigned long, unsigned long,
itksys::hash< unsigned long > >;
using HashTableType = std::unordered_map< unsigned long, unsigned long,
std::hash< unsigned long > >;

using Iterator = HashTableType::iterator;
using ConstIterator = HashTableType::const_iterator;
@@ -16,8 +16,8 @@
*
*=========================================================================*/

#include "itksys/hash_set.hxx"
#include "itksys/hash_map.hxx"
#include <unordered_set>
#include <unordered_map>
#include <iostream>
#include <cstring>

@@ -37,10 +37,10 @@ struct eqstr
}
};

void lookup(const itksys::hash_set<const char*, itksys::hash<const char*>, eqstr>& Set,
void lookup(const std::unordered_set<const char*, std::hash<const char*>, eqstr>& Set,
const char* word)
{
itksys::hash_set<const char*, itksys::hash<const char*>, eqstr>::const_iterator it
std::unordered_set<const char*, std::hash<const char*>, eqstr>::const_iterator it
= Set.find(word);
std::cout << word << ": "
<< (it != Set.end() ? "present" : "not present")
@@ -52,19 +52,19 @@ inline void println(const char *s)

int itkHashTableTest(int, char* [] )
{
println("Testing itksys::hash");
itksys::hash<const char*> H;
println("Testing std::hash");
std::hash<const char*> H;
std::cout << "foo -> " << H("foo") << std::endl;
std::cout << "bar -> " << H("bar") << std::endl;
itksys::hash<int> H1;
std::hash<int> H1;
std::cout << "1 -> " << H1(1) << std::endl;
std::cout << "234 -> " << H1(234) << std::endl;
itksys::hash<char> H2;
std::hash<char> H2;
std::cout << "a -> " << H2('a') << std::endl;
std::cout << "Z -> " << H2('Z') << std::endl;

println("Testing itksys::hash_set");
using HashSetType = itksys::hash_set<const char*, itksys::hash<const char*>, eqstr>;
println("Testing std::unordered_set");
using HashSetType = std::unordered_set<const char*, std::hash<const char*>, eqstr>;
HashSetType Set;
Set.insert("kiwi");
Set.insert("plum");
@@ -85,7 +85,7 @@ int itkHashTableTest(int, char* [] )
// This is to prevent the user from calling empty() when they mean clear().
if (Set.empty()) std::cout << "Set is empty." << std::endl;
Set.bucket_count();
Set.resize(50);
Set.rehash(50);
Set.insert("the horror");
Set.count("apple");
Set.find("kiwi");
@@ -95,8 +95,8 @@ int itkHashTableTest(int, char* [] )
HashSetType SetCopy;
SetCopy = Set;

println("Testing itksys::hash_map");
using HashMapType = itksys::hash_map<const char*, int, itksys::hash<const char*>, eqstr>;
println("Testing std::unordered_map");
using HashMapType = std::unordered_map<const char*, int, std::hash<const char*>, eqstr>;

HashMapType months;
months["january"] = 31;
@@ -125,7 +125,7 @@ int itkHashTableTest(int, char* [] )
// This is to prevent the user from calling empty() when they mean clear().
if (months.empty()) std::cout << "Set is empty." << std::endl;
months.bucket_count();
months.resize(50);
months.rehash(50);
HashMapType::value_type p("psychotic break", 2);
months.insert(p);
months.count("january");
@@ -20,7 +20,7 @@

#include "itkArray.h"
#include "itkDefaultStaticMeshTraits.h"
#include "itksys/hash_map.hxx"
#include <unordered_map>
#include "itkHexahedronCell.h"
#include "itkIntTypes.h"
#include "itkMesh.h"
@@ -145,7 +145,7 @@ class ITK_TEMPLATE_EXPORT AutomaticTopologyMeshSource:public MeshSource< TOutput

/** hash_map type alias. */

using PointHashMap = itksys::hash_map<
using PointHashMap = std::unordered_map<
PointType,
IdentifierType,
StructHashFunction< PointHashType > >;
@@ -388,7 +388,7 @@ class ITK_TEMPLATE_EXPORT AutomaticTopologyMeshSource:public MeshSource< TOutput
// are controlled manually

private:
using CellHashMap = itksys::hash_map<
using CellHashMap = std::unordered_map<
Array< IdentifierType >,
IdentifierType,
IdentifierArrayHashFunction,
@@ -18,7 +18,7 @@
#ifndef itkAdaptiveEqualizationHistogram_h
#define itkAdaptiveEqualizationHistogram_h

#include "itksys/hash_map.hxx"
#include <unordered_map>
#include "itkStructHashFunction.h"
#include "itkMath.h"
#include <cmath>
@@ -122,7 +122,7 @@ class AdaptiveEqualizationHistogram
}

private:
using MapType = typename itksys::hash_map< TInputPixel,
using MapType = typename std::unordered_map< TInputPixel,
size_t,
StructHashFunction< TInputPixel > >;

@@ -21,7 +21,7 @@
#include "itkImageToImageFilter.h"
#include "itkNumericTraits.h"

#include "itksys/hash_map.hxx"
#include <unordered_map>

namespace itk {

@@ -116,7 +116,7 @@ class ITK_TEMPLATE_EXPORT LabelOverlapMeasuresImageFilter :
};

/** Type of the map used to store data per label */
using MapType = itksys::hash_map<LabelType, LabelSetMeasures>;
using MapType = std::unordered_map<LabelType, LabelSetMeasures>;
using MapIterator = typename MapType::iterator;
using MapConstIterator = typename MapType::const_iterator;

@@ -23,7 +23,7 @@

#include "itkConceptChecking.h"

#include "itksys/hash_map.hxx"
#include <unordered_map>

namespace itk {
/** \class LaplacianDeformationQuadEdgeMeshFilter
@@ -180,11 +180,11 @@ class ITK_TEMPLATE_EXPORT LaplacianDeformationQuadEdgeMeshFilter:
LaplacianDeformationQuadEdgeMeshFilter();
~LaplacianDeformationQuadEdgeMeshFilter() override = default;

using OutputMapPointIdentifier = itksys::hash_map< OutputPointIdentifier, OutputPointIdentifier >;
using OutputMapPointIdentifier = std::unordered_map< OutputPointIdentifier, OutputPointIdentifier >;
using OutputMapPointIdentifierIterator = typename OutputMapPointIdentifier::iterator;
using OutputMapPointIdentifierConstIterator = typename OutputMapPointIdentifier::const_iterator;

using ConstraintMapType = itksys::hash_map< OutputPointIdentifier, OutputVectorType >;
using ConstraintMapType = std::unordered_map< OutputPointIdentifier, OutputVectorType >;
using ConstraintMapConstIterator = typename ConstraintMapType::const_iterator;

struct HashOutputQEPrimal
@@ -195,13 +195,13 @@ class ITK_TEMPLATE_EXPORT LaplacianDeformationQuadEdgeMeshFilter:
}
};

using CoefficientMapType = itksys::hash_map< OutputQEPrimal*, OutputCoordRepType, HashOutputQEPrimal >;
using CoefficientMapType = std::unordered_map< OutputQEPrimal*, OutputCoordRepType, HashOutputQEPrimal >;
using CoefficientMapConstIterator = typename CoefficientMapType::const_iterator;

using AreaMapType = itksys::hash_map< OutputPointIdentifier, OutputCoordRepType >;
using AreaMapType = std::unordered_map< OutputPointIdentifier, OutputCoordRepType >;
using AreaMapConstIterator = typename AreaMapType::const_iterator;

using RowType = itksys::hash_map< OutputPointIdentifier, OutputCoordRepType >;
using RowType = std::unordered_map< OutputPointIdentifier, OutputCoordRepType >;
using RowIterator = typename RowType::iterator;
using RowConstIterator = typename RowType::const_iterator;

@@ -110,7 +110,7 @@ class ITK_TEMPLATE_EXPORT LaplacianDeformationQuadEdgeMeshFilterWithSoftConstrai
OutputCoordRepType m_Lambda;
OutputCoordRepType m_LambdaSquare;

itksys::hash_map< OutputPointIdentifier, OutputCoordRepType > m_LocalLambdaSquare;
std::unordered_map< OutputPointIdentifier, OutputCoordRepType > m_LocalLambdaSquare;

};
} // end namespace itk
@@ -154,7 +154,7 @@ LaplacianDeformationQuadEdgeMeshFilterWithSoftConstraints< TInputMesh, TOutputMe

OutputCoordRepType l2 = m_LambdaSquare;

typename itksys::hash_map< OutputPointIdentifier, OutputCoordRepType >::const_iterator lambdaIt = this->m_LocalLambdaSquare.find( vId );
typename std::unordered_map< OutputPointIdentifier, OutputCoordRepType >::const_iterator lambdaIt = this->m_LocalLambdaSquare.find( vId );
if( lambdaIt != this->m_LocalLambdaSquare.end() )
{
l2 = lambdaIt->second;
@@ -22,7 +22,7 @@
#include "itkNumericTraits.h"
#include "itkArray.h"
#include "itkSimpleDataObjectDecorator.h"
#include "itksys/hash_map.hxx"
#include <map>
#include <vector>
#include "vnl/algo/vnl_symmetric_eigensystem.h"
#include "vnl/vnl_det.h"
@@ -245,9 +245,9 @@ class ITK_TEMPLATE_EXPORT LabelGeometryImageFilter:

/** Type of the map used to store data per label */
// Map from the label to the class storing all of the geometry information.
using MapType = itksys::hash_map< LabelPixelType, LabelGeometry >;
using MapIterator = typename itksys::hash_map< LabelPixelType, LabelGeometry >::iterator;
using MapConstIterator = typename itksys::hash_map< LabelPixelType, LabelGeometry >::const_iterator;
using MapType = std::map< LabelPixelType, LabelGeometry >;
using MapIterator = typename std::map< LabelPixelType, LabelGeometry >::iterator;
using MapConstIterator = typename std::map< LabelPixelType, LabelGeometry >::const_iterator;

// Macros for enabling the calculation of additional features.
itkGetMacro(CalculatePixelIndices, bool);
@@ -19,7 +19,7 @@
#define itkKdTreeBasedKmeansEstimator_h

#include <vector>
#include "itksys/hash_map.hxx"
#include <unordered_map>

#include "itkObject.h"
#include "itkEuclideanDistanceMetric.h"
@@ -152,7 +152,7 @@ class ITK_TEMPLATE_EXPORT KdTreeBasedKmeansEstimator:
* of changes in centroid positions) */
void StartOptimization();

using ClusterLabelsType = itksys::hash_map< InstanceIdentifier, unsigned int >;
using ClusterLabelsType = std::unordered_map< InstanceIdentifier, unsigned int >;

itkSetMacro(UseClusterLabels, bool);
itkGetConstMacro(UseClusterLabels, bool);
@@ -404,7 +404,7 @@ KdTreeBasedKmeansEstimator< TKdTree >
{
m_GenerateClusterLabels = true;
m_ClusterLabels.clear();
m_ClusterLabels.resize( m_KdTree->GetSample()->Size() );
m_ClusterLabels.rehash( m_KdTree->GetSample()->Size() );
for ( i = 0; i < (unsigned int)( m_Parameters.size() / m_MeasurementVectorSize ); i++ )
{
validIndexes.push_back(i);
@@ -18,7 +18,7 @@
#ifndef itkMembershipSample_h
#define itkMembershipSample_h

#include "itksys/hash_map.hxx"
#include <unordered_map>
#include "itkSubsample.h"

namespace itk
@@ -86,7 +86,7 @@ class ITK_TEMPLATE_EXPORT MembershipSample:public DataObject

/** Typedef for the storage that holds a class label for each instance.
* The relationship between instances and class label is one-to-one */
using ClassLabelHolderType = itksys::hash_map< InstanceIdentifier, ClassLabelType >;
using ClassLabelHolderType = std::unordered_map< InstanceIdentifier, ClassLabelType >;

/** Typedef for each subsample that stores instance identifiers of instances
* that belong to a class */
@@ -22,7 +22,6 @@
#include "itkImageRegionIterator.h"
#include "itkNumericTraits.h"
#include "itkProgressReporter.h"
#include "itksys/hash_map.hxx"
#include <map>

namespace itk
@@ -52,7 +51,7 @@ RelabelComponentImageFilter< TInputImage, TOutputImage >

// Use a map to keep track of the size of each object. Object
// number -> ObjectType (which has Object number and the two sizes)
using MapType = itksys::hash_map< LabelType, RelabelComponentObjectType >;
using MapType = std::map< LabelType, RelabelComponentObjectType >;
MapType sizeMap;
typename MapType::iterator mapIt;
using MapValueType = typename MapType::value_type;
@@ -37,6 +37,7 @@ int itkRelabelComponentImageFilterTest(int argc, char* argv[] )
return EXIT_FAILURE;
}

bool success = true;
using InternalPixelType = unsigned short;
using LabelPixelType = unsigned long;
using WritePixelType = unsigned char;
@@ -133,6 +134,7 @@ int itkRelabelComponentImageFilterTest(int argc, char* argv[] )
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
success = false;
}


@@ -149,6 +151,7 @@ int itkRelabelComponentImageFilterTest(int argc, char* argv[] )
std::cerr << "Exception caught during statistics calculation!"
<< std::endl;
std::cerr << excep << std::endl;
success = false;
}
try
{
@@ -220,6 +223,7 @@ int itkRelabelComponentImageFilterTest(int argc, char* argv[] )
catch (...)
{
std::cerr << "Exception caught while printing statistics" << std::endl;
success = false;
}

// Check for the sizes of the 7 first labels which should be sorted by default
@@ -230,7 +234,7 @@ int itkRelabelComponentImageFilterTest(int argc, char* argv[] )
{
std::cerr << "Comparing label size to reference value." << std::endl;
std::cerr << "Got " << relabel->GetSizeOfObjectsInPixels()[i] << ", expected " << ref1[i] << std::endl;
return EXIT_FAILURE;
success = false;
}
}

@@ -239,16 +243,25 @@ int itkRelabelComponentImageFilterTest(int argc, char* argv[] )
relabel->Update();

// Check for the sizes of the 7 first labels which are no more sorted
unsigned long ref2 [7] = { 1491, 2, 1, 906, 3, 40, 1 };
for ( int i=0; i<6; ++i )
unsigned long ref2[7] = { 1491, 2, 1, 906, 3, 40, 1 };
for ( int i=0; i<7; ++i )
{
if ( relabel->GetSizeOfObjectsInPixels()[i] != ref2[i] )
{
std::cerr << "Comparing label size to reference value." << std::endl;
std::cerr << "Got " << relabel->GetSizeOfObjectsInPixels()[i] << ", expected " << ref2[i] << std::endl;
return EXIT_FAILURE;
success = false;
}
}

return EXIT_SUCCESS;
if (success)
{
std::cout << "Test PASSED!" << std::endl;
return EXIT_SUCCESS;
}
else
{
std::cout << "Test FAILED!" << std::endl;
return EXIT_FAILURE;
}
}

0 comments on commit 0e2d4f2

Please sign in to comment.
You can’t perform that action at this time.