vtk-m/vtkm/filter/image_processing/ImageDifference.h
Kenneth Moreland c238cfea50 Improve deprecation support for moved or renamed headers
VTK-m has a deprecation method that supports API changes in minor
releases. When an API change is made, the old API is marked with the
VTKM_DEPRECATED macro. If code attempts to use the old API, it still
works, but the compiler issues a warning that the thing is deprecated
and where to find the new API.

We have recently run into an issue when the API changes have a header
file renamed or moved. We still keep the old header file with the old
API, so code including that file will still work. However, sometimes
code expected the contents of that header file without directly
including that header file. In these cases, the code could get an error
about missing classes.

As an example, consider the change from `DynamicCellSet` to
`UnknownCellSet`/`UncertainCellSet`. The deprecated `DynamicCellSet` is
still around. But there is a lot of code that did not directly include
DynamicCellSet.h. This header file was necessarily included by
DataSet.h. Now, when this code uses `vtkm::cont::DynamicCellSet`, you
get a confusing error that the class does not exist. Backward
compatibility broken.

In response to this, we should be more careful about where we put the
deprecated API. Instead of containing the deprecated API, moved headers
should be empty except for a warning and an inclusion of the new header
file. The deprecated API should be moved to the new header file. For
example, in the case of `DynamicCellSet`, the implementation for the
deprecated `DynamicCellSet` is moved to UnknownCellSet.h, which is
included by anything that was including DynamicCellSet.h before.
2022-02-16 07:08:05 -07:00

120 lines
4.3 KiB
C++

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_image_processing_ImageDifference_h
#define vtk_m_filter_image_processing_ImageDifference_h
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/image_processing/vtkm_filter_image_processing_export.h>
namespace vtkm
{
namespace filter
{
namespace image_processing
{
/// \brief Construct an ImageDifference of a given DataSet
///
/// The dataset generated by executing this filter is a Dataset with two Fields:
/// - "image-diff": Uniform Structured Dataset, difference values of image A - B
/// - "threshold-output": Uniform Structured Dataset, the magnitudes of the pixel differences
///
/// The threshold-output is calculated for each pixel using the `vtkm::Magnitude` vector function
/// on the individual pixel difference.
///
class VTKM_FILTER_IMAGE_PROCESSING_EXPORT ImageDifference : public vtkm::filter::NewFilterField
{
public:
VTKM_CONT ImageDifference();
VTKM_CONT vtkm::IdComponent GetAverageRadius() const { return this->AverageRadius; }
VTKM_CONT void SetAverageRadius(const vtkm::IdComponent& averageRadius)
{
this->AverageRadius = averageRadius;
}
VTKM_CONT vtkm::IdComponent GetPixelShiftRadius() const { return this->PixelShiftRadius; }
VTKM_CONT void SetPixelShiftRadius(const vtkm::IdComponent& pixelShiftRadius)
{
this->PixelShiftRadius = pixelShiftRadius;
}
VTKM_CONT vtkm::FloatDefault GetAllowedPixelErrorRatio() const
{
return this->AllowedPixelErrorRatio;
}
VTKM_CONT void SetAllowedPixelErrorRatio(const vtkm::FloatDefault& pixelErrorRatio)
{
this->AllowedPixelErrorRatio = pixelErrorRatio;
}
VTKM_CONT vtkm::FloatDefault GetPixelDiffThreshold() const { return this->PixelDiffThreshold; }
VTKM_CONT void SetPixelDiffThreshold(const vtkm::FloatDefault& threshold)
{
this->PixelDiffThreshold = threshold;
}
VTKM_CONT bool GetImageDiffWithinThreshold() const { return this->ImageDiffWithinThreshold; }
VTKM_CONT void SetThresholdFieldName(const std::string& name) { this->ThresholdFieldName = name; }
VTKM_CONT std::string GetThresholdFieldName() const { return this->ThresholdFieldName; }
/// Choose the primary field to operate on. For Image difference A - B, A is the
/// primary field.
VTKM_CONT
void SetPrimaryField(
const std::string& name,
vtkm::cont::Field::Association association = vtkm::cont::Field::Association::ANY)
{
this->SetActiveField(name, association);
}
VTKM_CONT std::string GetPrimaryFieldName() const { return this->GetActiveFieldName(); }
VTKM_CONT vtkm::cont::Field::Association GetPrimaryFieldAssociation() const
{
return this->GetActiveFieldAssociation();
}
/// Choose the secondary field to operate on. For Image difference A - B, B is the
/// secondary field.
VTKM_CONT
void SetSecondaryField(
const std::string& name,
vtkm::cont::Field::Association association = vtkm::cont::Field::Association::ANY)
{
this->SetActiveField(1, name, association);
}
VTKM_CONT std::string GetSecondaryFieldName() const { return this->GetActiveFieldName(1); }
VTKM_CONT vtkm::cont::Field::Association GetSecondaryFieldAssociation() const
{
return this->GetActiveFieldAssociation(1);
}
private:
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& primaryArray) override;
vtkm::IdComponent AverageRadius = 0;
vtkm::IdComponent PixelShiftRadius = 0;
vtkm::FloatDefault AllowedPixelErrorRatio = 0.00025f;
vtkm::FloatDefault PixelDiffThreshold = 0.05f;
bool ImageDiffWithinThreshold = true;
std::string ThresholdFieldName = "threshold-output";
};
} // namespace image_processing
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::image_processing::ImageDifference.") ImageDifference
: public vtkm::filter::image_processing::ImageDifference
{
using image_processing::ImageDifference::ImageDifference;
};
} // namespace filter
} // namespace vtkm
#endif // vtk_m_filter_image_processing_ImageDifference_h