/*========================================================================= * * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * *=========================================================================*/ #ifndef itkImageAdaptor_hxx #define itkImageAdaptor_hxx #include "itkProcessObject.h" namespace itk { template ImageAdaptor::ImageAdaptor() { // Allocate an internal image. A process object might try to allocate an // temporary image that is the same type as its input or output. If that // image type is an adaptor, we need to make sure that an internal image is // available because the process object will not know to call SetImage on // the adaptor. m_Image = TImage::New(); } template void ImageAdaptor::Allocate(bool initialize) { m_Image->Allocate(initialize); } template void ImageAdaptor::Initialize() { // call the superclass' method first; then delegate Superclass::Initialize(); // delegation to internal image m_Image->Initialize(); } template void ImageAdaptor::SetPixelContainer(PixelContainer * container) { if (this->GetPixelContainer() != container) { m_Image->SetPixelContainer(container); this->Modified(); } } template void ImageAdaptor::Graft(const Self * imgData) { // call the superclass' implementation Superclass::Graft(imgData); if (imgData) { // Now copy anything remaining that is needed this->SetPixelContainer(const_cast(imgData)->GetPixelContainer()); } } template void ImageAdaptor::Graft(const DataObject * data) { if (data) { // Attempt to cast data to an ImageAdaptor const Self * imgData; try { imgData = dynamic_cast(data); } catch (...) { return; } if (imgData) { this->Graft(imgData); } else { // pointer could not be cast back down itkExceptionMacro("itk::ImageAdaptor::Graft() cannot cast " << typeid(data).name() << " to " << typeid(const Self *).name()); } } } template void ImageAdaptor::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent); } template auto ImageAdaptor::GetOffsetTable() const -> const OffsetValueType * { return m_Image->GetOffsetTable(); } template auto ImageAdaptor::ComputeIndex(OffsetValueType offset) const -> IndexType { return m_Image->ComputeIndex(offset); } template void ImageAdaptor::Update() { Superclass::Update(); m_Image->Update(); } template void ImageAdaptor::UpdateOutputInformation() { // call the superclass' method first, then delegate Superclass::UpdateOutputInformation(); // delegation to internal image m_Image->UpdateOutputInformation(); // As attributes such as the number of components may have changed // may need to update the accessor this->UpdateAccessor(m_Image.GetPointer()); } template void ImageAdaptor::UpdateOutputData() { // call the superclass' method first, then delegate Superclass::UpdateOutputData(); // delegation to internal image m_Image->UpdateOutputData(); SetBufferedRegion(m_Image->GetBufferedRegion()); } template void ImageAdaptor::PropagateRequestedRegion() { // call the superclass' method first, then delegate Superclass::PropagateRequestedRegion(); // delegation to internal image m_Image->PropagateRequestedRegion(); } template void ImageAdaptor::SetRequestedRegionToLargestPossibleRegion() { // call the superclass' method first, then delegate Superclass::SetRequestedRegionToLargestPossibleRegion(); // delegation to internal image m_Image->SetRequestedRegionToLargestPossibleRegion(); } template void ImageAdaptor::CopyInformation(const DataObject * data) { // call the superclass' method first, then delegate Superclass::CopyInformation(data); // delegation to internal image m_Image->CopyInformation(data); // As attributes such as the number of components may have changed // may need to update the accessor this->UpdateAccessor(m_Image.GetPointer()); } template auto ImageAdaptor::GetSpacing() const -> const SpacingType & { return m_Image->GetSpacing(); } template void ImageAdaptor::SetSpacing(const SpacingType & spacing) { // delegation to internal image m_Image->SetSpacing(spacing); } template void ImageAdaptor::SetSpacing(const double * spacing /*[Self::ImageDimension]*/) { // delegation to internal image m_Image->SetSpacing(spacing); } template void ImageAdaptor::SetSpacing(const float * spacing /*[Self::ImageDimension]*/) { // delegation to internal image m_Image->SetSpacing(spacing); } template void ImageAdaptor::SetOrigin(const PointType origin) { // delegation to internal image m_Image->SetOrigin(origin); } template void ImageAdaptor::SetOrigin(const double * origin /*[Self::ImageDimension]*/) { // delegation to internal image m_Image->SetOrigin(origin); } template void ImageAdaptor::SetOrigin(const float * origin /*[Self::ImageDimension]*/) { // delegation to internal image m_Image->SetOrigin(origin); } template auto ImageAdaptor::GetOrigin() const -> const PointType & { return m_Image->GetOrigin(); } template void ImageAdaptor::SetDirection(const DirectionType & direction) { // delegation to internal image m_Image->SetDirection(direction); } template auto ImageAdaptor::GetDirection() const -> const DirectionType & { return m_Image->GetDirection(); } template void ImageAdaptor::SetImage(TImage * image) { m_Image = image; Superclass::SetLargestPossibleRegion(m_Image->GetLargestPossibleRegion()); Superclass::SetBufferedRegion(m_Image->GetBufferedRegion()); Superclass::SetRequestedRegion(m_Image->GetRequestedRegion()); this->UpdateAccessor(m_Image.GetPointer()); } template auto ImageAdaptor::GetBufferPointer() const -> const InternalPixelType * { return m_Image->GetBufferPointer(); } template auto ImageAdaptor::GetBufferPointer() -> InternalPixelType * { return m_Image->GetBufferPointer(); } template void ImageAdaptor::Modified() const { Superclass::Modified(); m_Image->Modified(); } template ModifiedTimeType ImageAdaptor::GetMTime() const { ModifiedTimeType mtime1, mtime2; mtime1 = Superclass::GetMTime(); mtime2 = m_Image->GetMTime(); return (mtime1 >= mtime2 ? mtime1 : mtime2); } template void ImageAdaptor::SetBufferedRegion(const RegionType & region) { // call the superclass' method first, then delegate Superclass::SetBufferedRegion(region); // delegation to internal image m_Image->SetBufferedRegion(region); } template auto ImageAdaptor::GetBufferedRegion() const -> const RegionType & { // delegation to internal image return m_Image->GetBufferedRegion(); } template void ImageAdaptor::SetLargestPossibleRegion(const RegionType & region) { // call the superclass' method first, then delegate Superclass::SetLargestPossibleRegion(region); // delegation to internal image m_Image->SetLargestPossibleRegion(region); } template auto ImageAdaptor::GetLargestPossibleRegion() const -> const RegionType & { // delegation to internal image return m_Image->GetLargestPossibleRegion(); } template void ImageAdaptor::SetRequestedRegion(const RegionType & region) { // call the superclass' method first, then delegate Superclass::SetRequestedRegion(region); // delegation to internal image m_Image->SetRequestedRegion(region); } template void ImageAdaptor::SetRequestedRegion(const DataObject * data) { // call the superclass' method first, then delegate Superclass::SetRequestedRegion(data); // delegation to internal image m_Image->SetRequestedRegion(data); } template bool ImageAdaptor::VerifyRequestedRegion() { // call the superclass' method first, then delegate Superclass::VerifyRequestedRegion(); // delegation to internal image return m_Image->VerifyRequestedRegion(); } template auto ImageAdaptor::GetRequestedRegion() const -> const RegionType & { // delegation to internal image return m_Image->GetRequestedRegion(); } } // end namespace itk #endif