diff --git a/Documentation/docs/migration_guides/itk_6_migration_guide.md b/Documentation/docs/migration_guides/itk_6_migration_guide.md index 89618eccf25..13cf8e92591 100644 --- a/Documentation/docs/migration_guides/itk_6_migration_guide.md +++ b/Documentation/docs/migration_guides/itk_6_migration_guide.md @@ -17,3 +17,12 @@ Remove support for ITKv4 interfaces `ITKV4_COMPATIBILITY` is no longer a supported option. Previously this option was off by default. Previously when enabled, the ITK API was modified to provide support for ITKV4 functions. + +Remove support for ITKv5 +----------------------------------- + +All contents of the Deprecated module were removed. This includes TreeContainer +and related classes; atomic primitives, mutexes and related classes which are +now part of C++ standard; specialized Vector filters - specialized versions are +no longer needed, as regular filters can work with vector images. For details, see +[ITKv5 Migration Guide](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Documentation/docs/migration_guides/itk_5_migration_guide.md). diff --git a/Modules/Compatibility/Deprecated/include/itkAtomicInt.h b/Modules/Compatibility/Deprecated/include/itkAtomicInt.h deleted file mode 100644 index 9af70976769..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkAtomicInt.h +++ /dev/null @@ -1,306 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Program: Visualization Toolkit - * Module: vtkAtomicInt.h - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * All rights reserved. - * See Copyright.txt or https://www.kitware.com/Copyright.htm 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 itkAtomicInt_h -#define itkAtomicInt_h - -#include "itkMacro.h" -#include "itkIntTypes.h" -#include "itkAtomicIntDetail.h" -#include "itkConceptChecking.h" - -#include -#include // For ptrdiff_t. - - -namespace itk -{ - -/** - * \class AtomicInt - * \brief Provides support for atomic integers - * - * - * Objects of atomic types are C++ objects that are free from data races; - * that is, if one thread writes to an atomic object while another thread - * reads from it, the behavior is well-defined. AtomicInt provides - * a subset of the std::atomic API and implementation, for 32 bit and 64 bit - * integers and pointer types. For these types, AtomicInt defines a - * number of operations that happen atomically - without interruption - * by another thread. Furthermore, these operations happen in a - * sequentially-consistent way and use full memory fences. This means - * that operations relating to atomic variables happen in the specified - * order and the results are made visible to other processing cores to - * guarantee proper sequential operation. Other memory access patterns - * supported by std::atomic are not currently supported. - * - * Note that when atomic operations are not available on a particular - * platform or compiler, mutexes, which are significantly slower, are used - * as a fallback. - * - * \ingroup ITKDeprecated - */ -template -class AtomicInt -{ -private: - using Impl = Detail::AtomicOps; - using ValueType = typename Impl::ValueType; - itkConceptMacro(SupportedInteger, (Detail::IsAtomicSupportedIntegralType)); - -public: - AtomicInt() - : m_Object(0) - {} - - AtomicInt(T val) - : m_Object(static_cast(val)) - {} - - AtomicInt(const AtomicInt & ai) - : m_Object(static_cast(ai.load())) - {} - - T - operator++() - { - return static_cast(++m_Object); - } - - T - operator++(int) - { - return static_cast(m_Object++); - } - - T - operator--() - { - return static_cast(--m_Object); - } - - T - operator--(int) - { - return static_cast(m_Object--); - } - - T - operator+=(T val) - { - return static_cast(m_Object += static_cast(val)); - } - - T - operator-=(T val) - { - return static_cast(m_Object -= static_cast(val)); - } - - operator T() const { return static_cast(m_Object.load()); } - - T - operator=(T val) - { - m_Object.store(static_cast(val)); - return val; - } - - AtomicInt & - operator=(const AtomicInt & ai) - { - this->store(ai.load()); - return *this; - } - - T - load() const - { - return static_cast(m_Object.load()); - } - - void - store(T val) - { - m_Object.store(static_cast(val)); - } - -private: - std::atomic::ValueType> m_Object; -}; - - -template -class AtomicInt -{ -private: - using Impl = Detail::AtomicOps; - using ValueType = typename Impl::ValueType; - -public: - AtomicInt() - : m_Object(0) - {} - - AtomicInt(T * val) - : m_Object(reinterpret_cast(val)) - {} - - AtomicInt(const AtomicInt & ai) - : m_Object(reinterpret_cast(ai.load())) - {} - - T * - operator++() - { - return reinterpret_cast(m_Object.fetch_add(sizeof(T)) + sizeof(T)); - } - - T * - operator++(int) - { - return reinterpret_cast(m_Object.fetch_add(sizeof(T))); - } - - T * - operator--() - { - return reinterpret_cast(m_Object.fetch_sub(sizeof(T)) - sizeof(T)); - } - - T * - operator--(int) - { - return reinterpret_cast(m_Object.fetch_sub(sizeof(T))); - } - - T * - operator+=(ptrdiff_t val) - { - return reinterpret_cast(m_Object += val * sizeof(T)); - } - - T * - operator-=(ptrdiff_t val) - { - return reinterpret_cast(m_Object -= val * sizeof(T)); - } - - operator T *() const { return reinterpret_cast(m_Object.load()); } - - T * - operator=(T * val) - { - m_Object.store(reinterpret_cast(val)); - return val; - } - - AtomicInt & - operator=(const AtomicInt & ai) - { - this->store(ai.load()); - return *this; - } - - T * - load() const - { - return reinterpret_cast(m_Object.load()); - } - - void - store(T * val) - { - m_Object.store(reinterpret_cast(val)); - } - -private: - std::atomic::ValueType> m_Object; -}; - - -template <> -class AtomicInt -{ -private: - using Impl = Detail::AtomicOps; - using ValueType = Impl::ValueType; - -public: - AtomicInt() - : m_Object(0) - {} - - AtomicInt(void * val) - : m_Object(reinterpret_cast(val)) - {} - - AtomicInt(const AtomicInt & ai) - : m_Object(reinterpret_cast(ai.load())) - {} - - operator void *() const { return reinterpret_cast(m_Object.load()); } - - void * - operator=(void * val) - { - m_Object.store(reinterpret_cast(val)); - return val; - } - - AtomicInt & - operator=(const AtomicInt & ai) - { - this->store(ai.load()); - return *this; - } - - void * - load() const - { - return reinterpret_cast(m_Object.load()); - } - - void - store(void * val) - { - m_Object.store(reinterpret_cast(val)); - } - -private: - std::atomic::ValueType> m_Object; -}; - - -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkAtomicIntDetail.h b/Modules/Compatibility/Deprecated/include/itkAtomicIntDetail.h deleted file mode 100644 index e8aeb7767e2..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkAtomicIntDetail.h +++ /dev/null @@ -1,101 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Program: Visualization Toolkit - * Module: vtkAtomicInt.h - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * All rights reserved. - * See Copyright.txt or https://www.kitware.com/Copyright.htm 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 itkAtomicIntDetail_h -#define itkAtomicIntDetail_h - -#include "itkMacro.h" -#include "itkConceptChecking.h" - -#include - -namespace itk -{ - -namespace Detail -{ - -template -struct BaseType; - -template -class AtomicOps -{ -public: - using AtomicType = typename BaseType::Type; - using ValueType = typename BaseType::Type; -}; - - -template <> -struct BaseType<8> -{ - itkAlignedTypedef(8, int64_t, Type); -}; - -template <> -struct BaseType<4> -{ - itkAlignedTypedef(4, int32_t, Type); -}; - -template -struct IsAtomicSupportedIntegralType -{ - using Self = IsAtomicSupportedIntegralType; - struct Constraints - { - using TrueT = Concept::Detail::UniqueType_bool; - using SpecializedT = Concept::Detail::UniqueType_bool::is_specialized>; - using IntegralT = Concept::Detail::UniqueType_bool::is_integer>; - using SizeT = Concept::Detail::UniqueType_bool; - void - constraints() - { - IntegralT a = TrueT(); - IntegralT b = TrueT(); - IntegralT c = TrueT(); - - IgnoreUnusedVariable(a); - IgnoreUnusedVariable(b); - IgnoreUnusedVariable(c); - } - }; - - - itkConceptConstraintsMacro(); -}; - -} // end namespace Detail -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkBarrier.h b/Modules/Compatibility/Deprecated/include/itkBarrier.h deleted file mode 100644 index cbc5c4ccbd6..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkBarrier.h +++ /dev/null @@ -1,87 +0,0 @@ -/*========================================================================= - * - * 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 itkBarrier_h -#define itkBarrier_h - -#include "itkLightObject.h" -#include "itkObjectFactory.h" -#include "ITKDeprecatedExport.h" -#include -#include - -namespace itk -{ -/** - * \class Barrier - * \brief Standard barrier class implementation for synchronizing the execution - * of threads. - * - * A barrier class is used to synchronize threaded execution by allowing - * threads to block until each has reached a desired state. As each thread - * enters the barrier it blocks. When all threads have entered the barrier, - * all released and continue to execute. - * - * A thread enters the barrier by calling Barrier::Wait() on the barrier - * class. To set up a barrier class, call Barrier::Initialize(unsigned int), - * specifying the number of waiting threads that will trigger a release of the - * barrier as the argument. - * - * NOTE: This class is only compatible with PlatformMultiThreader! - * - * \ingroup ITKDeprecated - */ -class ITKDeprecated_EXPORT Barrier : public LightObject -{ -public: - /** Standard class type aliases. */ - using Self = Barrier; - using Superclass = LightObject; - using Pointer = SmartPointer; - using ConstPointer = SmartPointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** \see LightObject::GetNameOfClass() */ - itkOverrideGetNameOfClassMacro(Barrier); - - /** Creates a new system variable used to implement the barrier. The - argument to this method is the number of threads that must Wait() on the - barrier before it is cleared. */ - void - Initialize(unsigned int); - - /** A thread calling this method waits until m_NumberOfThreads have called - * Wait() on the barrier. When the final expected thread calls Wait(), all - * threads are released. */ - void - Wait(); - -private: - Barrier(); - ~Barrier() override; - - unsigned int m_NumberArrived{ 0 }; - unsigned int m_NumberExpected{ 0 }; - unsigned int m_Generation{ 0 }; // Allows successive waits - std::condition_variable m_ConditionVariable{}; - std::mutex m_Mutex{}; -}; -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkChildTreeIterator.h b/Modules/Compatibility/Deprecated/include/itkChildTreeIterator.h deleted file mode 100644 index 68166ac1263..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkChildTreeIterator.h +++ /dev/null @@ -1,94 +0,0 @@ -/*========================================================================= - * - * 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 itkChildTreeIterator_h -#define itkChildTreeIterator_h - -#include "itkTreeIteratorBase.h" - -namespace itk -{ -template -class ITK_TEMPLATE_EXPORT ChildTreeIterator : public TreeIteratorBase -{ -public: - /** Typedefs */ - using Self = ChildTreeIterator; - using Superclass = TreeIteratorBase; - using TreeType = TTreeType; - using ValueType = typename TTreeType::ValueType; - using typename Superclass::TreeNodeType; - using ChildIdentifier = typename TreeNodeType::ChildIdentifier; - using typename Superclass::NodeType; - - /** Constructor */ - ChildTreeIterator(TreeType * tree, const TreeNodeType * start = nullptr); - - /** Constructor */ - ChildTreeIterator(const TreeIteratorBase & iterator); - - /** Get the type of the iterator. */ - NodeType - GetType() const override; - - /** Go to a specific child node. */ - bool - GoToChild(ChildIdentifier number = 0) override; - - /** Go to the parent node. */ - bool - GoToParent() override; - - /** Clone function */ - TreeIteratorBase * - Clone() override; - - /** operator = */ - Self & - operator=(Superclass & iterator) - { - if (this != &iterator) - { - Superclass::operator=(iterator); - auto & it = static_cast &>(iterator); - m_ListPosition = it.m_ListPosition; - m_ParentNode = it.m_ParentNode; - } - return *this; - } - -protected: - /** Get the next node. */ - const ValueType & - Next() override; - - /** Return true if the next node exists. */ - bool - HasNext() const override; - -private: - mutable ChildIdentifier m_ListPosition{}; - TreeNodeType * m_ParentNode{}; -}; - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -# include "itkChildTreeIterator.hxx" -#endif - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkChildTreeIterator.hxx b/Modules/Compatibility/Deprecated/include/itkChildTreeIterator.hxx deleted file mode 100644 index aa1d9bfa861..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkChildTreeIterator.hxx +++ /dev/null @@ -1,122 +0,0 @@ -/*========================================================================= - * - * 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 itkChildTreeIterator_hxx -#define itkChildTreeIterator_hxx - - -namespace itk -{ - -template -ChildTreeIterator::ChildTreeIterator(TTreeType * tree, const TreeNodeType * start) - : TreeIteratorBase(tree, start) -{ - m_ListPosition = 0; - m_ParentNode = this->m_Position; - this->m_Position = m_ParentNode->GetChild(m_ListPosition); - this->m_Begin = this->m_Position; -} - -template -ChildTreeIterator::ChildTreeIterator(const TreeIteratorBase & iterator) - : TreeIteratorBase(iterator.GetTree(), iterator.GetNode()) -{ - m_ListPosition = 0; - m_ParentNode = this->m_Position; - this->m_Position = m_ParentNode->GetChild(m_ListPosition); -} - -template -bool -ChildTreeIterator::GoToChild(ChildIdentifier number) -{ - if (m_ParentNode->GetChild(number) == nullptr) - { - return false; - } - - m_ListPosition = 0; - m_ParentNode = m_ParentNode->GetChild(number); - this->m_Position = m_ParentNode->GetChild(m_ListPosition); - this->m_Begin = this->m_Position; - return true; -} - -template -bool -ChildTreeIterator::GoToParent() -{ - TreeNodeType * parent = m_ParentNode->GetParent(); - - if (parent == nullptr) - { - return false; - } - - m_ListPosition = 0; - m_ParentNode = parent; - this->m_Position = m_ParentNode->GetChild(m_ListPosition); - this->m_Begin = this->m_Position; - return true; -} - -template -auto -ChildTreeIterator::GetType() const -> NodeType -{ - return TreeIteratorBaseEnums::TreeIteratorBaseNode::CHILD; -} - -template -bool -ChildTreeIterator::HasNext() const -{ - if (m_ListPosition < m_ParentNode->CountChildren() - 1) - { - return true; - } - else - { - return false; - } -} - -template -auto -ChildTreeIterator::Next() -> const ValueType & -{ - ++m_ListPosition; - this->m_Position = m_ParentNode->GetChild(m_ListPosition); - if (this->m_Position == nullptr) - { - return this->m_Root->Get(); // value irrelevant, but we have to return something - } - return this->m_Position->Get(); -} - -template -TreeIteratorBase * -ChildTreeIterator::Clone() -{ - auto * clone = new ChildTreeIterator(const_cast(this->m_Tree), this->m_Position); - *clone = *this; - return clone; -} -} // namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkConditionVariable.h b/Modules/Compatibility/Deprecated/include/itkConditionVariable.h deleted file mode 100644 index e510fec6e86..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkConditionVariable.h +++ /dev/null @@ -1,99 +0,0 @@ -/*========================================================================= - * - * 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 itkConditionVariable_h -#define itkConditionVariable_h - -#include "itkConfigure.h" -#include "itkMutexLock.h" -#include "itkLightObject.h" - -namespace itk -{ -/** - * \class ConditionVariable - * \brief A thread synchronization object used to suspend execution until some - * condition on shared data is met. - * - * A thread calls Wait() to suspend its execution until the condition is - * met. Each call to Signal() from an executing thread will then cause a single - * waiting thread to be released. A call to Signal() means, "signal - * that the condition is true." Broadcast() releases all threads waiting on - * the condition variable. - * - * The ITK ConditionVariable implementation is consistent with the standard - * definition and use of condition variables in pthreads and other common - * thread libraries. - * - * IMPORTANT: A condition variable always requires an associated SimpleMutexLock - * object. The mutex object is used to avoid a dangerous race condition when - * Wait() and Signal() are called simultaneously from two different - * threads. - * - * On systems using pthreads, this implementation abstract the - * standard calls to the pthread condition variable. On Win32 - * systems, there is no system provided condition variable. This - * class implements a condition variable using a critical section, a - * semaphore, an event and a number of counters. The implementation is - * almost an extract translation of the implementation presented by - * Douglas C Schmidt and Irfan Pyarali in "Strategies for Implementing - * POSIX Condition Variables on Win32". This article can be found at - * http://www.cs.wustl.edu/~schmidt/win32-cv-1.html - * - * \ingroup ITKDeprecated - */ -class ITKDeprecated_EXPORT ConditionVariable : public LightObject -{ -public: - ITK_DISALLOW_COPY_AND_MOVE(ConditionVariable); - - /** Standard class type aliases. */ - using Self = ConditionVariable; - using Superclass = LightObject; - using Pointer = SmartPointer; - using ConstPointer = SmartPointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** \see LightObject::GetNameOfClass() */ - itkOverrideGetNameOfClassMacro(ConditionVariable); - - /** Suspend execution of this thread until the condition is signaled. The - * argument is a SimpleMutex object that must be locked prior to calling - * this method. */ - void - Wait(SimpleMutexLock * mutex); - - /** Signal that the condition is true and release one waiting thread */ - void - Signal(); - - /** Signal that the condition is true and release all waiting threads */ - void - Broadcast(); - -protected: - ConditionVariable(); - ~ConditionVariable() override; - -private: - ConditionVariableType m_ConditionVariable{}; -}; -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/src/itkConditionVariable.cxx b/Modules/Compatibility/Deprecated/include/itkDeprecatedPlaceholder.h similarity index 75% rename from Modules/Compatibility/Deprecated/src/itkConditionVariable.cxx rename to Modules/Compatibility/Deprecated/include/itkDeprecatedPlaceholder.h index 9f49ed9b217..a69087b3846 100644 --- a/Modules/Compatibility/Deprecated/src/itkConditionVariable.cxx +++ b/Modules/Compatibility/Deprecated/include/itkDeprecatedPlaceholder.h @@ -15,12 +15,11 @@ * limitations under the License. * *=========================================================================*/ -#include "itkConditionVariable.h" +#ifndef itkDeprecatedPlaceholder_h +#define itkDeprecatedPlaceholder_h -#if defined(ITK_USE_PTHREADS) -# include "itkConditionVariablePThreads.cxx" -#elif defined(ITK_USE_WIN32_THREADS) -# include "itkConditionVariableWinThreads.cxx" -#else -# include "itkConditionVariableNoThreads.cxx" +#include + +extern std::string +dummy_deprecated_function_placeholder(); #endif diff --git a/Modules/Compatibility/Deprecated/include/itkFastMutexLock.h b/Modules/Compatibility/Deprecated/include/itkFastMutexLock.h deleted file mode 100644 index c231bda5a4f..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkFastMutexLock.h +++ /dev/null @@ -1,118 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#ifndef itkFastMutexLock_h -#define itkFastMutexLock_h - -#include "itkObject.h" -#include "itkSimpleFastMutexLock.h" -#include "itkObjectFactory.h" - -namespace itk -{ -/** - * \class FastMutexLock - * \brief Critical section locking class. - * - * FastMutexLock allows the locking of variables which are accessed - * through different threads. This header file also defines - * SimpleFastMutexLock which is not a subclass of Object. - * The API is identical to that of MutexLock, and the behavior is - * identical as well, except on Windows 9x/NT platforms. The only difference - * on these platforms is that MutexLock is more flexible, in that - * it works across processes as well as across threads, but also costs - * more, in that it evokes a 600-cycle x86 ring transition. The - * FastMutexLock provides a higher-performance equivalent (on - * Windows) but won't work across processes. Since it is unclear how, - * in itk, an object at the itk level can be shared across processes - * in the first place, one should use FastMutexLock unless one has - * a very good reason to use MutexLock. If higher-performance equivalents - * for non-Windows platforms (Irix, SunOS, etc) are discovered, they - * should replace the implementations in this class - * - * \ingroup OSSystemObjects - * \ingroup ITKDeprecated - */ -class ITKDeprecated_EXPORT FastMutexLock : public Object -{ -public: - ITK_DISALLOW_COPY_AND_MOVE(FastMutexLock); - - /** Standard class type aliases. */ - using Self = FastMutexLock; - using Superclass = Object; - using Pointer = SmartPointer; - using ConstPointer = SmartPointer; - - /** Method for creation. */ - itkNewMacro(Self); - - /** \see LightObject::GetNameOfClass() */ - itkOverrideGetNameOfClassMacro(FastMutexLock); - - /** Lock the itkFastMutexLock. */ - void - Lock(); - - /** Non-blocking Lock access. - \return bool - true if lock is captured, false if it was already held by someone else. - */ - bool - TryLock(); - - /** Unlock the FastMutexLock. */ - void - Unlock(); - -protected: - FastMutexLock() = default; - ~FastMutexLock() override = default; - - SimpleFastMutexLock m_SimpleFastMutexLock{}; - void - PrintSelf(std::ostream & os, Indent indent) const override; -}; - -inline void -FastMutexLock::Lock() -{ - m_SimpleFastMutexLock.Lock(); -} - -inline bool -FastMutexLock::TryLock() -{ - return m_SimpleFastMutexLock.TryLock(); -} - -inline void -FastMutexLock::Unlock() -{ - m_SimpleFastMutexLock.Unlock(); -} -} // namespace itk -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkImageTransformer.h b/Modules/Compatibility/Deprecated/include/itkImageTransformer.h deleted file mode 100644 index 73e962ae561..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkImageTransformer.h +++ /dev/null @@ -1,271 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#ifndef itkImageTransformer_h -#define itkImageTransformer_h - -#include "itkProcessObject.h" -#include "itkImage.h" - -namespace itk -{ -/** - * \class ImageTransformer - * \brief Base class for all process objects that transform an image into something else. - * - * ImageTransformer is the base class for all process objects that transform an - * image data. Specifically, this class defines the SetInput() method - * that takes a pointer to the input image. The class also defines - * some internal private data members that are used to manage streaming - * of data. - * - * Memory management in an ImageTransformer is slightly different than a - * standard ProcessObject. ProcessObject's always release the bulk - * data associated with their output prior to GenerateData() being - * called. ImageTransformers default to not releasing the bulk data incase - * that particular memory block is large enough to hold the new output - * values. This avoids unnecessary deallocation/allocation - * sequences. ImageTransformer's can be forced to use a memory management - * model similar to the default ProcessObject behaviour by calling - * ProcessObject::ReleaseDataBeforeUpdateFlagOn(). A user may want to - * set this flag to limit peak memory usage during a pipeline update. - * - * \ingroup ITKDeprecated - */ -template -class ITK_TEMPLATE_EXPORT ImageTransformer : public ProcessObject -{ -public: - ITK_DISALLOW_COPY_AND_MOVE(ImageTransformer); - - /** Standard class type aliases. */ - using Self = ImageTransformer; - using Superclass = ProcessObject; - using Pointer = SmartPointer; - using ConstPointer = SmartPointer; - - /** Smart Pointer type to a DataObject. */ - using DataObjectPointer = DataObject::Pointer; - - /** \see LightObject::GetNameOfClass() */ - itkOverrideGetNameOfClassMacro(ImageTransformer); - - /** Some convenient type alias. */ - using InputImageType = TInputImage; - using InputImagePointer = typename InputImageType::Pointer; - using InputImageRegionType = typename InputImageType::RegionType; - using InputImagePixelType = typename InputImageType::PixelType; - - /** ImageDimension constant */ - static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension; - - /** Set/Get the image input of this process object. */ - using Superclass::SetInput; - virtual void - SetInput(const InputImageType * image); - virtual void - SetInput(unsigned int, const TInputImage * image); - const InputImageType * - GetInput() const; - InputImageType * - GetInput(); - const InputImageType * - GetInput(unsigned int idx) const; - - /** Push/Pop the input of this process object. These methods allow a - * filter to model its input vector as a queue or stack. These - * routines may not be appropriate for all filters, especially - * filters with different types of inputs. These routines follow - * the semantics of STL. - * - * The routines are useful for applications that need to process - * "rolling" sets of images. For instance, if an application has 10 - * images and they need to run a filter on images 1, 2, 3, 4, then - * run the filter on images 2, 3, 4, 5, then run the filter on - * images 3, 4, 5, 6, the application can accomplish this by popping - * an input off the front of the input list and push a new image - * onto the back of input list. Again, this only makes sense for - * filters that single type of input. - * - * Other uses are also possible. For a single input filter, pushing - * and popping inputs allow the application to temporarily replace - * an input to a filter. - */ - virtual void - PushBackInput(const InputImageType * image); - void - PopBackInput() override; - virtual void - PushFrontInput(const InputImageType * image); - void - PopFrontInput() override; - -protected: - ImageTransformer(); - ~ImageTransformer() override = default; - - /** The image transformer is assumed to need the whole input. - * - * This implementation of GenerateInputRequestedRegion() only - * processes the inputs that are a subclass of the - * ImageBase. If an input is another type of - * DataObject (including an Image of a different dimension), they - * are skipped by this method. The subclasses of ImageToImageFilter - * are responsible for providing an implementation of - * GenerateInputRequestedRegion() when there are multiple inputs of - * different types. - * - * \sa ProcessObject::GenerateInputRequestedRegion(), - * ImageSource::GenerateInputRequestedRegion() */ - void - GenerateInputRequestedRegion() override; - - /** A version of GenerateData() specific for image processing - * filters. This implementation will split the processing across - * multiple threads. The buffer is allocated by this method. Then - * the BeforeThreadedGenerateData() method is called (if - * provided). Then, a series of threads are spawned each calling - * ThreadedGenerateData(). After all the threads have completed - * processing, the AfterThreadedGenerateData() method is called (if - * provided). If an image processing filter cannot be threaded, the - * filter should provide an implementation of GenerateData(). That - * implementation is responsible for allocating the output buffer. - * If a filter can be threaded, it should NOT provide a - * GenerateData() method but should provide a ThreadedGenerateData() - * instead. - * - * \sa ThreadedGenerateData() */ - void - GenerateData() override; - - /** If an imaging filter can be implemented as a multithreaded - * algorithm, the filter will provide an implementation of - * ThreadedGenerateData(). This superclass will automatically split - * the output image into a number of pieces, spawn multiple threads, - * and call ThreadedGenerateData() in each thread. Prior to spawning - * threads, the BeforeThreadedGenerateData() method is called. After - * all the threads have completed, the AfterThreadedGenerateData() - * method is called. If an image processing filter cannot support - * threading, that filter should provide an implementation of the - * GenerateData() method instead of providing an implementation of - * ThreadedGenerateData(). If a filter provides a GenerateData() - * method as its implementation, then the filter is responsible for - * allocating the output data. If a filter provides a - * ThreadedGenerateData() method as its implementation, then the - * output memory will allocated automatically by this superclass. - * The ThreadedGenerateData() method should only produce the output - * specified by "inputThreadRegion" - * parameter. ThreadedGenerateData() cannot write to any other - * portion of the output image (as this is responsibility of a - * different thread). - * - * \sa GenerateData(), SplitRequestedRegion() */ - virtual void - ThreadedGenerateData(const InputImageRegionType & inputRegionForThread, ThreadIdType threadId); - - /** Many filters do special management of image buffer and threading, - * so this method provides just the multi-threaded invocation part - * of GenerateData() method. */ - void - ClassicMultiThread(ThreadFunctionType callbackFunction); - - /** The GenerateData method normally allocates the buffers for all of the - * outputs of a filter. Some filters may want to override this default - * behavior. For example, a filter may have multiple outputs with - * varying resolution. Or a filter may want to process data in place by - * grafting its input to its output. */ - virtual void - AllocateOutputs(); - - /** If an imaging filter needs to perform processing after the buffer - * has been allocated but before threads are spawned, the filter can - * can provide an implementation for BeforeThreadedGenerateData(). The - * execution flow in the default GenerateData() method will be: - * 1) Allocate the output buffer - * 2) Call BeforeThreadedGenerateData() - * 3) Spawn threads, calling ThreadedGenerateData() in each thread. - * 4) Call AfterThreadedGenerateData() - * Note that this flow of control is only available if a filter provides - * a ThreadedGenerateData() method and NOT a GenerateData() method. */ - virtual void - BeforeThreadedGenerateData() - {} - - /** If an imaging filter needs to perform processing after all - * processing threads have completed, the filter can can provide an - * implementation for AfterThreadedGenerateData(). The execution - * flow in the default GenerateData() method will be: - * 1) Allocate the output buffer - * 2) Call BeforeThreadedGenerateData() - * 3) Spawn threads, calling ThreadedGenerateData() in each thread. - * 4) Call AfterThreadedGenerateData() - * Note that this flow of control is only available if a filter provides - * a ThreadedGenerateData() method and NOT a GenerateData() method. */ - virtual void - AfterThreadedGenerateData() - {} - - /** Split the input's RequestedRegion into "num" pieces, returning - * region "i" as "splitRegion". This method is called "num" times. The - * regions must not overlap. The method returns the number of pieces that - * the routine is capable of splitting the input RequestedRegion, - * i.e. return value is less than or equal to "num". */ - virtual unsigned int - SplitRequestedRegion(unsigned int i, unsigned int num, InputImageRegionType & splitRegion); - - /** Static function used as a "callback" by the MultiThreader. The threading - * library will call this routine for each thread, which will delegate the - * control to ThreadedGenerateData(). */ - static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION - ThreaderCallback(void * arg); - - /** - * PushBackInput(), PushFrontInput() in the public section force the - * input to be the type expected by an ImageTransformer. However, - * these methods end up "hiding" the versions from the superclass - * (ProcessObject) whose arguments are DataObjects. Here, we re-expose - * the versions from ProcessObject to avoid warnings about hiding - * methods from the superclass. - * NOTE: The same code resides in ImageToImageFilter - */ - using Superclass::PushBackInput; - using Superclass::PushFrontInput; - - /** Internal structure used for passing image data into the threading library - */ - struct ThreadStruct - { - Pointer Filter; - }; -}; -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -# include "itkImageTransformer.hxx" -#endif - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkImageTransformer.hxx b/Modules/Compatibility/Deprecated/include/itkImageTransformer.hxx deleted file mode 100644 index 8e7a0a12866..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkImageTransformer.hxx +++ /dev/null @@ -1,338 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#ifndef itkImageTransformer_hxx -#define itkImageTransformer_hxx - -#include "itkMath.h" - -namespace itk -{ -/** - * - */ -template -ImageTransformer::ImageTransformer() -{ - // Set the default behavior of an image source to NOT release its - // output bulk data prior to GenerateData() in case that bulk data - // can be reused (an thus avoid a costly deallocate/allocate cycle). - this->ReleaseDataBeforeUpdateFlagOff(); -} - -/** - * - */ -template -void -ImageTransformer::SetInput(const InputImageType * input) -{ - // Process object is not const-correct so the const_cast is required here - this->ProcessObject::SetNthInput(0, const_cast(input)); -} - -/** - * Connect one of the operands for pixel-wise addition - */ -template -void -ImageTransformer::SetInput(unsigned int index, const TInputImage * image) -{ - // Process object is not const-correct so the const_cast is required here - this->ProcessObject::SetNthInput(index, const_cast(image)); -} - -/** - * - */ -template -auto -ImageTransformer::GetInput() const -> const InputImageType * -{ - if (this->GetNumberOfInputs() < 1) - { - return 0; - } - - return itkDynamicCastInDebugMode(this->ProcessObject::GetInput(0)); -} - -/** - * - */ -template -auto -ImageTransformer::GetInput() -> InputImageType * -{ - if (this->GetNumberOfInputs() < 1) - { - return nullptr; - } - - return itkDynamicCastInDebugMode(this->ProcessObject::GetInput(0)); -} - -/** - * - */ -template -auto -ImageTransformer::GetInput(unsigned int idx) const -> const InputImageType * -{ - return itkDynamicCastInDebugMode(this->ProcessObject::GetInput(idx)); -} - -template -void -ImageTransformer::PushBackInput(const InputImageType * input) -{ - // Forward to the protected method in the superclass - this->ProcessObject::PushBackInput(input); -} - -template -void -ImageTransformer::PopBackInput() -{ - // Forward to the protected method in the superclass - this->ProcessObject::PopBackInput(); -} - -template -void -ImageTransformer::PushFrontInput(const InputImageType * input) -{ - // Forward to the protected method in the superclass - this->ProcessObject::PushFrontInput(input); -} - -template -void -ImageTransformer::PopFrontInput() -{ - // Forward to the protected method in the superclass - this->ProcessObject::PopFrontInput(); -} - -//----------------------------------------------------------------------- -// -template -void -ImageTransformer::GenerateInputRequestedRegion() -{ - Superclass::GenerateInputRequestedRegion(); - - for (unsigned int idx = 0; idx < this->GetNumberOfInputs(); ++idx) - { - if (this->GetInput(idx)) - { - // Check whether the input is an image of the appropriate - // dimension (use ProcessObject's version of the GetInput() - // method since it returns the input as a pointer to a - // DataObject as opposed to the subclass version which - // static_casts the input to an TInputImage). - using ImageBaseType = ImageBase; - typename ImageBaseType::ConstPointer constInput = - dynamic_cast(this->ProcessObject::GetInput(idx)); - - // If not an image, skip it, and let a subclass of - // ImageToImageFilter handle this input. - if (constInput.IsNull()) - { - continue; - } - - // Input is an image, cast away the constness so we can set - // the requested region. - InputImagePointer input = const_cast(this->GetInput(idx)); - - // transform is assumed to need the whole image - input->SetRequestedRegion(input->GetLargestPossibleRegion()); - } - } -} - -//---------------------------------------------------------------------------- -template -unsigned int -ImageTransformer::SplitRequestedRegion(unsigned int i, - unsigned int num, - InputImageRegionType & splitRegion) -{ - // Get the input pointer - InputImageType * inputPtr = this->GetInput(); - - const typename TInputImage::SizeType & requestedRegionSize = inputPtr->GetRequestedRegion().GetSize(); - - int splitAxis; - typename TInputImage::IndexType splitIndex; - typename TInputImage::SizeType splitSize; - - // Initialize the splitRegion to the input requested region - splitRegion = inputPtr->GetRequestedRegion(); - splitIndex = splitRegion.GetIndex(); - splitSize = splitRegion.GetSize(); - - // split on the outermost dimension available - splitAxis = inputPtr->GetImageDimension() - 1; - while (requestedRegionSize[splitAxis] == 1) - { - --splitAxis; - if (splitAxis < 0) - { // cannot split - itkDebugMacro(" Cannot Split"); - return 1; - } - } - - // determine the actual number of pieces that will be generated - typename TInputImage::SizeType::SizeValueType range = requestedRegionSize[splitAxis]; - if (num != 0 && range != 0) - { - auto valuesPerThread = Math::Ceil(range / static_cast(num)); - unsigned int maxThreadIdUsed = Math::Ceil(range / static_cast(valuesPerThread)) - 1; - // Split the region - if (i < maxThreadIdUsed) - { - splitIndex[splitAxis] += i * valuesPerThread; - splitSize[splitAxis] = valuesPerThread; - } - if (i == maxThreadIdUsed) - { - splitIndex[splitAxis] += i * valuesPerThread; - // last thread needs to process the "rest" dimension being split - splitSize[splitAxis] = splitSize[splitAxis] - i * valuesPerThread; - } - - // set the split region ivars - splitRegion.SetIndex(splitIndex); - splitRegion.SetSize(splitSize); - - itkDebugMacro(" Split Piece: " << splitRegion); - - return maxThreadIdUsed + 1; - } - else - { - itkDebugMacro("Division by zero: num/range = 0."); - return 1; - } -} - -//---------------------------------------------------------------------------- -template -void -ImageTransformer::AllocateOutputs() -{} - -//---------------------------------------------------------------------------- -template -void -ImageTransformer::ClassicMultiThread(ThreadFunctionType callbackFunction) -{ - ThreadStruct str; - str.Filter = this; - - this->GetMultiThreader()->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits()); - this->GetMultiThreader()->SetSingleMethodAndExecute(callbackFunction, &str); -} - -//---------------------------------------------------------------------------- -template -void -ImageTransformer::GenerateData() -{ - // Call a method that can be overridden by a subclass to allocate - // memory for the filter's outputs - this->AllocateOutputs(); - - // Call a method that can be overridden by a subclass to perform - // some calculations prior to splitting the main computations into - // separate threads - this->BeforeThreadedGenerateData(); - - this->ClassicMultiThread(this->ThreaderCallback); - - // Call a method that can be overridden by a subclass to perform - // some calculations after all the threads have completed - this->AfterThreadedGenerateData(); -} - -//---------------------------------------------------------------------------- -// The execute method created by the subclass. -template -void -ImageTransformer::ThreadedGenerateData(const InputImageRegionType &, ThreadIdType) -{ - // The following code is equivalent to: - // itkExceptionMacro("subclass should override this method!!!"); - // The ExceptionMacro is not used because gcc warns that a - // 'noreturn' function does return - std::ostringstream message; - - message << "itk::ERROR: " << this->GetNameOfClass() << '(' << this << "): " - << "Subclass should override this method!!!"; - ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); - throw e_; -} - -// Callback routine used by the threading library. This routine just calls -// the ThreadedGenerateData method after setting the correct region for this -// thread. -template -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -ImageTransformer::ThreaderCallback(void * arg) -{ - ThreadStruct * str; - ThreadIdType total, threadId, threadCount; - - threadId = ((MultiThreaderBase::WorkUnitInfo *)(arg))->WorkUnitID; - threadCount = ((MultiThreaderBase::WorkUnitInfo *)(arg))->NumberOfWorkUnits; - - str = (ThreadStruct *)(((MultiThreaderBase::WorkUnitInfo *)(arg))->UserData); - - // execute the actual method with appropriate output region - // first find out how many pieces extent can be split into. - typename TInputImage::RegionType splitRegion; - total = str->Filter->SplitRequestedRegion(threadId, threadCount, splitRegion); - - if (threadId < total) - { - str->Filter->ThreadedGenerateData(splitRegion, threadId); - } - // else - // { - // otherwise don't use this thread. Sometimes the threads don't - // break up very well and it is just as efficient to leave a - // few threads idle. - // } - - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkInOrderTreeIterator.h b/Modules/Compatibility/Deprecated/include/itkInOrderTreeIterator.h deleted file mode 100644 index ee2bb872bdd..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkInOrderTreeIterator.h +++ /dev/null @@ -1,182 +0,0 @@ -/*========================================================================= - * - * 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 itkInOrderTreeIterator_h -#define itkInOrderTreeIterator_h - -#include "itkTreeIteratorBase.h" - -namespace itk -{ -template -class ITK_TEMPLATE_EXPORT InOrderTreeIterator : public TreeIteratorBase -{ -public: - /** Typedefs */ - using Self = InOrderTreeIterator; - using Superclass = TreeIteratorBase; - using TreeType = TTreeType; - using ValueType = typename TTreeType::ValueType; - using typename Superclass::TreeNodeType; - using typename Superclass::NodeType; - - /** Constructors */ - InOrderTreeIterator(TreeType & start); - InOrderTreeIterator(TreeType * tree, TreeNodeType * start = nullptr); - - /** Get the type of iterator */ - NodeType - GetType() const override; - - /** Clone function */ - TreeIteratorBase * - Clone() override; - -protected: - /** Return the next node */ - const ValueType & - Next() override; - - /** Return true if the next node exists */ - bool - HasNext() const override; - -private: - /** Find the next node */ - const TreeNodeType * - FindNextNode() const; -}; - -/** Constructor */ -template -InOrderTreeIterator::InOrderTreeIterator(TTreeType & start) - : TreeIteratorBase(start) -{} - -/** Constructor */ -template -InOrderTreeIterator::InOrderTreeIterator(TTreeType * tree, TreeNodeType * start) - : TreeIteratorBase(tree, start) -{} - -/** Get the type of the iterator */ -template -auto -InOrderTreeIterator::GetType() const -> NodeType -{ - return TreeIteratorBaseEnums::TreeIteratorBaseNode::INORDER; -} - -/** Return true if the next node exists */ -template -bool -InOrderTreeIterator::HasNext() const -{ - if (const_cast(FindNextNode()) != nullptr) - { - return true; - } - return false; -} - -/** Return the next node */ -template -const typename InOrderTreeIterator::ValueType & -InOrderTreeIterator::Next() -{ - this->m_Position = const_cast(FindNextNode()); - if (this->m_Position == nullptr) - { - return this->m_Root->Get(); // value irrelevant, but we have to return something - } - return this->m_Position->Get(); -} - -/** Find the next node */ -template -const typename InOrderTreeIterator::TreeNodeType * -InOrderTreeIterator::FindNextNode() const -{ - if (this->m_Position == nullptr) - { - return nullptr; - } - - if (this->m_Position->HasChildren()) - { - return this->m_Position->GetChild(0); - } - - if (!this->m_Position->HasParent()) - { - return nullptr; - } - - TreeNodeType * child = this->m_Position; - TreeNodeType * parent = this->m_Position->GetParent(); - - int childPosition = parent->ChildPosition(child); - int lastChildPosition = parent->CountChildren() - 1; - - while (childPosition < lastChildPosition) - { - TreeNodeType * help = parent->GetChild(childPosition + 1); - if (help != nullptr) - { - return help; - } - ++childPosition; - } - - while (parent->HasParent()) - { - child = parent; - parent = parent->GetParent(); - - // Subtree - if (parent->ChildPosition(this->m_Root) >= 0) - { - return nullptr; - } - childPosition = parent->ChildPosition(child); - lastChildPosition = parent->CountChildren() - 1; - - while (childPosition < lastChildPosition) - { - TreeNodeType * help = parent->GetChild(childPosition + 1); - if (help != nullptr) - { - return help; - } - } - } - return nullptr; -} - -/** Clone function */ -template -TreeIteratorBase * -InOrderTreeIterator::Clone() -{ - auto * clone = new InOrderTreeIterator(const_cast(this->m_Tree)); - - *clone = *this; - return clone; -} -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkLeafTreeIterator.h b/Modules/Compatibility/Deprecated/include/itkLeafTreeIterator.h deleted file mode 100644 index 1ce97b49647..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkLeafTreeIterator.h +++ /dev/null @@ -1,185 +0,0 @@ -/*========================================================================= - * - * 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 itkLeafTreeIterator_h -#define itkLeafTreeIterator_h - -#include "itkPreOrderTreeIterator.h" - -namespace itk -{ -template -class ITK_TEMPLATE_EXPORT LeafTreeIterator : public TreeIteratorBase -{ -public: - /** Typedefs */ - using Self = LeafTreeIterator; - using Superclass = TreeIteratorBase; - using TreeType = TTreeType; - using ValueType = typename TreeType::ValueType; - using typename Superclass::TreeNodeType; - using typename Superclass::NodeType; - - /** Constructor */ - LeafTreeIterator(const TreeType * tree); - - /** Constructor */ - LeafTreeIterator(TreeType * tree); - - /** Destructor */ - ~LeafTreeIterator() override; - - /** Return the type of iterator */ - NodeType - GetType() const override; - - /** Clone function */ - TreeIteratorBase * - Clone() override; - -protected: - /** Return the next value */ - const ValueType & - Next() override; - - /** Return true if the next value exists */ - bool - HasNext() const override; - -private: - /** Find the next node */ - const TreeNodeType * - FindNextNode() const; -}; - -/** Constructor */ -template -LeafTreeIterator::LeafTreeIterator(const TTreeType * tree) - : TreeIteratorBase(tree, nullptr) -{ - this->m_Begin = const_cast(this->FindNextNode()); // - // - // Position - // the - // - // iterator - // to - // the - // first - // leaf; -} - -/** Constructor */ -template -LeafTreeIterator::LeafTreeIterator(TTreeType * tree) - : TreeIteratorBase(tree, nullptr) -{ - this->m_Begin = const_cast(this->FindNextNode()); // - // - // Position - // the - // - // iterator - // to - // the - // first - // leaf; -} - -/** Destructor */ -template -LeafTreeIterator::~LeafTreeIterator() = default; - -/** Return the type of iterator */ -template -auto -LeafTreeIterator::GetType() const -> NodeType -{ - return TreeIteratorBaseEnums::TreeIteratorBaseNode::LEAF; -} - -/** Return true if the next value exists */ -template -bool -LeafTreeIterator::HasNext() const -{ - if (this->m_Position == nullptr) - { - return false; - } - if (const_cast(FindNextNode()) != nullptr) - { - return true; - } - return false; -} - -/** Return the next node */ -template -const typename LeafTreeIterator::ValueType & -LeafTreeIterator::Next() -{ - this->m_Position = const_cast(FindNextNode()); - if (this->m_Position == nullptr) - { - return this->m_Root->Get(); // value irrelevant, but we have to return something - } - return this->m_Position->Get(); -} - -/** Find the next node given the position */ -template -const typename LeafTreeIterator::TreeNodeType * -LeafTreeIterator::FindNextNode() const -{ - PreOrderTreeIterator it(this->m_Tree, this->m_Position); - it.m_Root = this->m_Root; - ++it; // go next - if (it.IsAtEnd()) - { - return nullptr; - } - - if (!it.HasChild()) - { - return it.GetNode(); - } - - while (!it.IsAtEnd()) - { - if (!it.HasChild()) - { - return it.GetNode(); - } - ++it; - } - - return nullptr; -} - -/** Clone function */ -template -TreeIteratorBase * -LeafTreeIterator::Clone() -{ - auto * clone = new LeafTreeIterator(this->m_Tree); - *clone = *this; - return clone; -} -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkLevelOrderTreeIterator.h b/Modules/Compatibility/Deprecated/include/itkLevelOrderTreeIterator.h deleted file mode 100644 index 360f5b14c94..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkLevelOrderTreeIterator.h +++ /dev/null @@ -1,120 +0,0 @@ -/*========================================================================= - * - * 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 itkLevelOrderTreeIterator_h -#define itkLevelOrderTreeIterator_h - -#include -#include -#include "itkTreeIteratorBase.h" - -namespace itk -{ -/** - * \class LevelOrderTreeIterator - * \brief Iterate over a tree in level order. - * - * \ingroup ITKDeprecated - */ -template -class ITK_TEMPLATE_EXPORT LevelOrderTreeIterator : public TreeIteratorBase -{ -public: - /** Typedefs */ - using Self = LevelOrderTreeIterator; - using Superclass = TreeIteratorBase; - using TreeType = TTreeType; - using ValueType = typename TTreeType::ValueType; - using typename Superclass::TreeNodeType; - using typename Superclass::NodeType; - - /** Constructor with end level specification */ - LevelOrderTreeIterator(TreeType * tree, int endLevel = INT_MAX, const TreeNodeType * start = nullptr); - - /** Constructor with end level specification. */ - LevelOrderTreeIterator(TreeType * tree, int startLevel, int endLevel, const TreeNodeType * start = nullptr); - - ~LevelOrderTreeIterator() override = default; - - /** Get the type of the iterator. */ - NodeType - GetType() const override; - - /** Get the start level. */ - int - GetStartLevel() const; - - /** Get the end level. */ - int - GetEndLevel() const; - - /** Get the current level. */ - int - GetLevel() const; - - /** Clone function. */ - TreeIteratorBase * - Clone() override; - - /** operator = */ - const Self & - operator=(const Self & iterator) - { - if (this != &iterator) - { - this->Superclass::operator=(iterator); - m_StartLevel = iterator.m_StartLevel; - m_EndLevel = iterator.m_EndLevel; - m_Queue = iterator.m_Queue; - } - return *this; - } - -protected: - /** Get the next node. */ - const ValueType & - Next() override; - - /** Return true if the next node exists. */ - bool - HasNext() const override; - -private: - /** Find the next available node. */ - const TreeNodeType * - FindNextNode() const; - - /** Helper function to find the next node. */ - const TreeNodeType * - FindNextNodeHelp() const; - - /** Get the level given a node. */ - int - GetLevel(const TreeNodeType * node) const; - - int m_StartLevel{}; - int m_EndLevel{}; - mutable std::queue m_Queue{}; -}; - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -# include "itkLevelOrderTreeIterator.hxx" -#endif - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkLevelOrderTreeIterator.hxx b/Modules/Compatibility/Deprecated/include/itkLevelOrderTreeIterator.hxx deleted file mode 100644 index 33c2fda69a3..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkLevelOrderTreeIterator.hxx +++ /dev/null @@ -1,223 +0,0 @@ -/*========================================================================= - * - * 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 itkLevelOrderTreeIterator_hxx -#define itkLevelOrderTreeIterator_hxx - - -namespace itk -{ - -template -LevelOrderTreeIterator::LevelOrderTreeIterator(TTreeType * tree, int endLevel, const TreeNodeType * start) - : TreeIteratorBase(tree, start) -{ - m_StartLevel = -1; - m_EndLevel = endLevel; - if (start != nullptr) - { - m_Queue.push(start); - this->m_Position = const_cast(start); - } - else - { - if (tree->GetRoot()) - { - m_Queue.push(dynamic_cast(tree->GetRoot())); - this->m_Position = const_cast(dynamic_cast(tree->GetRoot())); - } - } - this->m_Begin = this->m_Position; -} - -template -LevelOrderTreeIterator::LevelOrderTreeIterator(TTreeType * tree, - int startLevel, - int endLevel, - const TreeNodeType * start) - : TreeIteratorBase(tree, start) -{ - m_StartLevel = startLevel; - m_EndLevel = endLevel; - if (start != nullptr) - { - m_Queue.push(start); - this->m_Position = const_cast(start); - } - else - { - if (tree->GetRoot()) - { - m_Queue.push(dynamic_cast(tree->GetRoot())); - this->m_Position = const_cast(dynamic_cast(tree->GetRoot())); - } - } - this->m_Begin = this->m_Position; -} - -template -auto -LevelOrderTreeIterator::GetType() const -> NodeType -{ - return TreeIteratorBaseEnums::TreeIteratorBaseNode::LEVELORDER; -} - -template -bool -LevelOrderTreeIterator::HasNext() const -{ - if (const_cast(FindNextNode())) - { - return true; - } - return false; -} - -template -auto -LevelOrderTreeIterator::Next() -> const ValueType & -{ - this->m_Position = const_cast(FindNextNode()); - if (this->m_Position == nullptr) - { - return this->m_Root->Get(); // value irrelevant, but we have to return something - } - return this->m_Position->Get(); -} - -template -int -LevelOrderTreeIterator::GetStartLevel() const -{ - return m_StartLevel; -} - -template -int -LevelOrderTreeIterator::GetEndLevel() const -{ - return m_EndLevel; -} - -template -auto -LevelOrderTreeIterator::FindNextNode() const -> const TreeNodeType * -{ - int level; - const TreeNodeType * node; - - do - { - node = FindNextNodeHelp(); - if (node == nullptr) - { - return nullptr; - } - level = GetLevel(node); - if (level > m_EndLevel) - { - return nullptr; - } - } while (level < m_StartLevel); - - return node; -} - -template -int -LevelOrderTreeIterator::GetLevel() const -{ - if (this->m_Position == nullptr) - { - return -1; - } - - int level = 0; - TreeNodeType * node = this->m_Position; - while (node->HasParent() && node != this->m_Root) - { - node = dynamic_cast(node->GetParent()); - ++level; - } - return level; -} - -template -int -LevelOrderTreeIterator::GetLevel(const TreeNodeType * node) const -{ - if (node == nullptr) - { - return -1; - } - int level = 0; - - while (node->HasParent() && node != this->m_Root) - { - node = dynamic_cast(node->GetParent()); - ++level; - } - return level; -} - -template -auto -LevelOrderTreeIterator::FindNextNodeHelp() const -> const TreeNodeType * -{ - if (m_Queue.empty()) - { - return nullptr; - } - - const TreeNodeType * currentNode = m_Queue.front(); - m_Queue.pop(); - - if (currentNode == nullptr) - { - return nullptr; - } - - int size = currentNode->CountChildren(); - - for (int i = 0; i < size; ++i) - { - auto * child = dynamic_cast(currentNode->GetChild(i)); - if (child != nullptr) - { - m_Queue.push(child); - } - } - - // If the current node is the root we try again - if (currentNode == this->m_Root) - { - currentNode = const_cast(FindNextNodeHelp()); - } - return currentNode; -} - -template -TreeIteratorBase * -LevelOrderTreeIterator::Clone() -{ - auto * clone = new LevelOrderTreeIterator(const_cast(this->m_Tree), m_StartLevel, m_EndLevel); - *clone = *this; - return clone; -} -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkMultiThreader.h b/Modules/Compatibility/Deprecated/include/itkMultiThreader.h deleted file mode 100644 index 669fe30a76c..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkMultiThreader.h +++ /dev/null @@ -1,48 +0,0 @@ -/*========================================================================= - * - * 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 itkMultiThreader_h -#define itkMultiThreader_h - -#if !defined(ITK_LEGACY_REMOVE) -# include "itkMultiThreaderBase.h" -# include "itkPlatformMultiThreader.h" -namespace itk -{ -/** Since ITK 5.0 MultiThreader has been split into a class hierarchy. - * Most of the time you will want to replace it by MultiThreaderBase. - * - * Additionally, call this->DynamicMultiThreadingOff(); prior to Update() - * (for example in constructor) if any of the following is true: - * - Your filter needs a constant, in-advance known number of threads - * - Your filter uses threadId parameter in ThreadedGenerateData() - * - Your filter uses a custom region splitting method */ -using MultiThreader = MultiThreaderBase; - - -/** Replace it by PlatformMultiThreader if any of the following is true: - * - Your filter uses cross-thread synchronization e.g. itkBarrier - * - Your filter uses MultipleMethodExecute() - * - Your filter uses SpawnThread/TerminateThread. */ -// using MultiThreader = PlatformMultiThreader; -} // namespace itk -#else // ITK_LEGACY_REMOVE -# error itkMultiThreader.h is a legacy file since ITK 5.0 and will be removed in the future. -#endif // ITK_LEGACY_REMOVE - -#endif // itkMultiThreader_h diff --git a/Modules/Compatibility/Deprecated/include/itkMutexLock.h b/Modules/Compatibility/Deprecated/include/itkMutexLock.h deleted file mode 100644 index da8bcae3fa2..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkMutexLock.h +++ /dev/null @@ -1,177 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#ifndef itkMutexLock_h -#define itkMutexLock_h - -#include "itkObject.h" -#include "itkObjectFactory.h" -#include "itkThreadSupport.h" -#include "ITKDeprecatedExport.h" - -namespace itk -{ - -/** - * \class SimpleMutexLock - * \brief Simple mutual exclusion locking class. - - * SimpleMutexLock allows the locking of variables which are accessed - * through different threads. This header file also defines - * SimpleMutexLock which is not a subclass of Object. - * - * \ingroup OSSystemObjects - * \ingroup ITKDeprecated - */ -class ITKDeprecated_EXPORT SimpleMutexLock -{ -public: - /** Standard class type aliases. */ - using Self = SimpleMutexLock; - - /** Constructor and destructor left public purposely. */ - SimpleMutexLock(); - virtual ~SimpleMutexLock(); - - /** Methods for creation and destruction through the object factory. */ - static SimpleMutexLock * - New(); - - void - Delete() - { - delete this; - } - - /** Used for debugging and other run-time purposes. */ - virtual const char * - GetNameOfClass() - { - return "itkSimpleMutexLock"; - } - - /** Lock the MutexLock. */ - void - Lock(); - - /** Non-blocking Lock access. - \return bool - true if lock is captured, false if it was already held by someone else. - */ - bool - TryLock(); - - /** Unlock the MutexLock. */ - void - Unlock(); - - /** Access the MutexType member variable from outside this class */ - MutexType & - GetMutexLock() - { - return m_MutexLock; - } - - MutexType - GetMutexLock() const - { - return *(const_cast(&m_MutexLock)); - } - -protected: - MutexType m_MutexLock{}; -}; - -/** - * \class MutexLock - * \brief Mutual exclusion locking class. - * - * MutexLock allows the locking of variables which are accessed - * through different threads. This header file also defines - * SimpleMutexLock which is not a subclass of itkObject. - * - * \ingroup OSSystemObjects - * \ingroup ITKDeprecated - */ -class ITKDeprecated_EXPORT MutexLock : public Object -{ -public: - ITK_DISALLOW_COPY_AND_MOVE(MutexLock); - - /** Standard class type aliases. */ - using Self = MutexLock; - using Superclass = Object; - using Pointer = SmartPointer; - using ConstPointer = SmartPointer; - - /** Method for creation. */ - itkNewMacro(Self); - - /** \see LightObject::GetNameOfClass() */ - itkOverrideGetNameOfClassMacro(MutexLock); - - /** Lock the itkMutexLock. */ - void - Lock(); - - /** Non-blocking Lock access. - \return bool - true if lock is captured, false if it was already held by someone else. - */ - bool - TryLock(); - - /** Unlock the MutexLock. */ - void - Unlock(); - -protected: - MutexLock() = default; - ~MutexLock() override = default; - - SimpleMutexLock m_SimpleMutexLock{}; - void - PrintSelf(std::ostream & os, Indent indent) const override; -}; - -inline void -MutexLock::Lock() -{ - m_SimpleMutexLock.Lock(); -} - -inline bool -MutexLock::TryLock() -{ - return m_SimpleMutexLock.TryLock(); -} - -inline void -MutexLock::Unlock() -{ - m_SimpleMutexLock.Unlock(); -} -} // namespace itk -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkMutexLockHolder.h b/Modules/Compatibility/Deprecated/include/itkMutexLockHolder.h deleted file mode 100644 index be0bd136c16..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkMutexLockHolder.h +++ /dev/null @@ -1,92 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#ifndef itkMutexLockHolder_h -#define itkMutexLockHolder_h - -#include "itkMacro.h" - -namespace itk -{ -/** - * \class MutexLockHolder - * \brief A container to store a Mutex. - * This holder class for ensuring that locks are released in - * the event of an exception being thrown after the lock was - * created. - * - * \ingroup ITKDeprecated - */ -template -class MutexLockHolder -{ -public: - ITK_DISALLOW_COPY_AND_MOVE(MutexLockHolder); - - using Self = MutexLockHolder; - using MutexType = TMutex; - - MutexLockHolder(MutexType & mutex, const bool noblock = false) - : m_Mutex(mutex) - , m_LockCaptured(true) - { - if (noblock == false) - { - m_Mutex.Lock(); - } - else - { - m_LockCaptured = m_Mutex.TryLock(); - } - } - - /** True if the holder has acquired the lock, for no-blocking - + constructor this will always be true. - */ - inline bool - GetLockCaptured() const - { - return this->m_LockCaptured; - } - operator bool() const { return this->m_LockCaptured; } - - ~MutexLockHolder() - { - if (m_LockCaptured) - { - m_Mutex.Unlock(); - } - } - -protected: - MutexType & m_Mutex; - bool m_LockCaptured; -}; - -} // namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkPostOrderTreeIterator.h b/Modules/Compatibility/Deprecated/include/itkPostOrderTreeIterator.h deleted file mode 100644 index f79c269ae6e..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkPostOrderTreeIterator.h +++ /dev/null @@ -1,232 +0,0 @@ -/*========================================================================= - * - * 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 itkPostOrderTreeIterator_h -#define itkPostOrderTreeIterator_h - -#include "itkTreeIteratorBase.h" - -namespace itk -{ -template -class ITK_TEMPLATE_EXPORT PostOrderTreeIterator : public TreeIteratorBase -{ -public: - /** Typedefs */ - using Self = PostOrderTreeIterator; - using Superclass = TreeIteratorBase; - using TreeType = TTreeType; - using ValueType = typename TTreeType::ValueType; - using typename Superclass::TreeNodeType; - using typename Superclass::NodeType; - - /** Constructor */ - PostOrderTreeIterator(TreeType * tree); - - /** Get the type of the iterator */ - NodeType - GetType() const override; - - /** Clone function */ - TreeIteratorBase * - Clone() override; - -protected: - /** Return the next node */ - const ValueType & - Next() override; - - /** Return true if the next node exists */ - bool - HasNext() const override; - -protected: - const TreeNodeType * - FindNextNode() const; - - const TreeNodeType * - FindMostRightLeaf(TreeNodeType * node) const; - - const TreeNodeType * - FindSister(TreeNodeType * node) const; -}; - -/** Constructor */ -template -PostOrderTreeIterator::PostOrderTreeIterator(TTreeType * tree) - : TreeIteratorBase(tree, nullptr) -{ - if (tree->GetRoot() == nullptr) - { - this->m_Begin = nullptr; - } - else - { - const auto * root = dynamic_cast(tree->GetRoot()); - if (root == nullptr) - { - itkGenericExceptionMacro("Can't downcast root node to TreeNodeType *"); - } - this->m_Position = const_cast(root); - this->m_Position = const_cast(FindMostRightLeaf(this->m_Position)); - this->m_Begin = this->m_Position; - } -} - -/** Return the type of the iterator */ -template -auto -PostOrderTreeIterator::GetType() const -> NodeType -{ - return TreeIteratorBaseEnums::TreeIteratorBaseNode::POSTORDER; -} - -/** Return true if the next node exists */ -template -bool -PostOrderTreeIterator::HasNext() const -{ - if (const_cast(FindNextNode()) != nullptr) - { - return true; - } - return false; -} - -/** Go to the next node */ -template -const typename PostOrderTreeIterator::ValueType & -PostOrderTreeIterator::Next() -{ - this->m_Position = const_cast(FindNextNode()); - return this->m_Position->Get(); -} - -/** Find the next node */ -template -const typename PostOrderTreeIterator::TreeNodeType * -PostOrderTreeIterator::FindNextNode() const -{ - if (this->m_Position == nullptr || this->m_Position == this->m_Root) - { - return nullptr; - } - auto * sister = const_cast(FindSister(this->m_Position)); - - if (sister != nullptr) - { - return FindMostRightLeaf(sister); - } - if (this->m_Position->GetParent() == nullptr) - { - return nullptr; - } - auto * rval = dynamic_cast(this->m_Position->GetParent()); - if (rval == nullptr) - { - itkGenericExceptionMacro("Can't downcast to TreeNodeType *"); - } - return rval; -} - -/** Find the sister node */ -template -const typename PostOrderTreeIterator::TreeNodeType * -PostOrderTreeIterator::FindSister(TreeNodeType * node) const -{ - if (!node->HasParent()) - { - return nullptr; - } - - auto * parent = dynamic_cast(node->GetParent()); - if (parent == nullptr) - { - itkGenericExceptionMacro("Can't downcast to TreeNodeType *"); - } - - int childPosition = parent->ChildPosition(node); - int lastChildPosition = parent->CountChildren() - 1; - - while (childPosition < lastChildPosition) - { - if (parent->GetChild(childPosition + 1) == nullptr) - { - ++childPosition; - } - else - { - auto * sister = dynamic_cast(parent->GetChild(childPosition + 1)); - if (sister == nullptr) - { - itkGenericExceptionMacro("Can't downcast to TreeNodeType *"); - } - return sister; - } - } - return nullptr; -} - -/** Find the most right leaf */ -template -const typename PostOrderTreeIterator::TreeNodeType * -PostOrderTreeIterator::FindMostRightLeaf(TreeNodeType * node) const -{ - while (node->HasChildren()) - { - TreeNodeType * helpNode; - int childCount = node->CountChildren(); - int i = 0; - - do - { - if (node->GetChild(i) == nullptr) - { - helpNode = nullptr; - } - else - { - helpNode = dynamic_cast(node->GetChild(i)); - if (helpNode == nullptr) - { - itkGenericExceptionMacro("Can't downcast to TreeNodeType *"); - } - } - ++i; - } while (helpNode == nullptr && i < childCount); - - if (helpNode == nullptr) - { - return node; - } - node = helpNode; - } - return node; -} - -/** Clone function */ -template -TreeIteratorBase * -PostOrderTreeIterator::Clone() -{ - auto * clone = new PostOrderTreeIterator(const_cast(this->m_Tree)); - *clone = *this; - return clone; -} -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkPreOrderTreeIterator.h b/Modules/Compatibility/Deprecated/include/itkPreOrderTreeIterator.h deleted file mode 100644 index 5de9ab18c96..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkPreOrderTreeIterator.h +++ /dev/null @@ -1,170 +0,0 @@ -/*========================================================================= - * - * 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 itkPreOrderTreeIterator_h -#define itkPreOrderTreeIterator_h - -#include "itkTreeIteratorBase.h" - -namespace itk -{ -// Forward reference because of circular dependencies -template -class ITK_TEMPLATE_EXPORT LeafTreeIterator; - -template -class ITK_TEMPLATE_EXPORT PreOrderTreeIterator : public TreeIteratorBase -{ -public: - /** Typedefs */ - using ValueType = typename TTreeType::ValueType; - using Superclass = TreeIteratorBase; - using typename Superclass::TreeNodeType; - using typename Superclass::NodeType; - - /** Constructor */ - PreOrderTreeIterator(const TTreeType * tree, const TreeNodeType * start = nullptr); - - /** Get the type of the iterator */ - NodeType - GetType() const override; - - /** Clone function */ - TreeIteratorBase * - Clone() override; - -protected: - /** Return the next node */ - const ValueType & - Next() override; - - /** Return true if the next node exists */ - bool - HasNext() const override; - -private: - /** Find the next node */ - const TreeNodeType * - FindNextNode() const; - - /** LeafTreeIterator uses PreOrderTreeIterator in its implementation, but it - * needs to adjust its root. A friend designation is added to correct - * behavior and retain backwards compatible behavior. */ - friend class LeafTreeIterator; -}; - -/** Constructor */ -template -PreOrderTreeIterator::PreOrderTreeIterator(const TTreeType * tree, const TreeNodeType * start) - : TreeIteratorBase(tree, start) -{} - -/** Return the type of the iterator */ -template -auto -PreOrderTreeIterator::GetType() const -> NodeType -{ - return TreeIteratorBaseEnums::TreeIteratorBaseNode::PREORDER; -} - -/** Return true if the next node exists */ -template -bool -PreOrderTreeIterator::HasNext() const -{ - if (const_cast(FindNextNode()) != nullptr) - { - return true; - } - return false; -} - -/** Return the next node */ -template -const typename PreOrderTreeIterator::ValueType & -PreOrderTreeIterator::Next() -{ - this->m_Position = const_cast(FindNextNode()); - if (this->m_Position == nullptr) - { - return this->m_Root->Get(); // value irrelevant, but we have to return something - } - return this->m_Position->Get(); -} - -/** Find the next node */ -template -const typename PreOrderTreeIterator::TreeNodeType * -PreOrderTreeIterator::FindNextNode() const -{ - if (this->m_Position == nullptr) - { - return nullptr; - } - if (this->m_Position->HasChildren()) - { - return dynamic_cast(this->m_Position->GetChild(0)); - } - - if (!this->m_Position->HasParent()) - { - return nullptr; - } - - TreeNodeType * child = this->m_Position; - TreeNodeType * parent = this->m_Position; - - while (parent->HasParent()) - { - child = parent; - parent = dynamic_cast(parent->GetParent()); - - // Subtree - if (parent->ChildPosition(this->m_Root) >= 0) - { - return nullptr; - } - - int childPosition = parent->ChildPosition(child); - int lastChildPosition = parent->CountChildren() - 1; - - while (childPosition < lastChildPosition) - { - auto * help = dynamic_cast(parent->GetChild(childPosition + 1)); - - if (help != nullptr) - { - return help; - } - ++childPosition; - } - } - return nullptr; -} - -/** Clone function */ -template -TreeIteratorBase * -PreOrderTreeIterator::Clone() -{ - auto * clone = new PreOrderTreeIterator(this->m_Tree, this->m_Position); - *clone = *this; - return clone; -} -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkRootTreeIterator.h b/Modules/Compatibility/Deprecated/include/itkRootTreeIterator.h deleted file mode 100644 index 2276ef711c3..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkRootTreeIterator.h +++ /dev/null @@ -1,131 +0,0 @@ -/*========================================================================= - * - * 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 itkRootTreeIterator_h -#define itkRootTreeIterator_h - -#include "itkTreeIteratorBase.h" - -namespace itk -{ -template -class ITK_TEMPLATE_EXPORT RootTreeIterator : public TreeIteratorBase -{ -public: - /** Typedefs */ - using Superclass = TreeIteratorBase; - using TreeType = TTreeType; - using ValueType = typename TTreeType::ValueType; - using typename Superclass::TreeNodeType; - using typename Superclass::NodeType; - - /** Constructor */ - RootTreeIterator(TreeType * tree, const TreeNodeType * start = nullptr); - - /** Return the type of the iterator */ - NodeType - GetType() const override; - - /** Clone function */ - TreeIteratorBase * - Clone() override; - -protected: - /** Return the next node */ - const ValueType & - Next() override; - - /** Return true if the next node exists */ - bool - HasNext() const override; - -private: - /** Find the next node */ - const TreeNodeType * - FindNextNode() const; -}; - -/** Constructor */ -template -RootTreeIterator::RootTreeIterator(TTreeType * tree, const TreeNodeType * start) - : TreeIteratorBase(tree, start) -{ - if (start) - { - this->m_Begin = const_cast *>(start); - } - this->m_Root = tree->GetRoot(); - this->m_Position = this->m_Begin; -} - -/** Return the type of the iterator */ -template -auto -RootTreeIterator::GetType() const -> NodeType -{ - return TreeIteratorBaseEnums::TreeIteratorBaseNode::ROOT; -} - -/** Return true if the next node exists */ -template -bool -RootTreeIterator::HasNext() const -{ - if (const_cast(FindNextNode()) != nullptr) - { - return true; - } - return false; -} - -/** Go to the next node */ -template -const typename RootTreeIterator::ValueType & -RootTreeIterator::Next() -{ - this->m_Position = const_cast(FindNextNode()); - return this->m_Position->Get(); -} - -/** Find the next node */ -template -const typename RootTreeIterator::TreeNodeType * -RootTreeIterator::FindNextNode() const -{ - if (this->m_Position == nullptr) - { - return nullptr; - } - if (this->m_Position == this->m_Root) - { - return nullptr; - } - return this->m_Position->GetParent(); -} - -/** Clone function */ -template -TreeIteratorBase * -RootTreeIterator::Clone() -{ - auto * clone = new RootTreeIterator(const_cast(this->m_Tree), this->m_Position); - *clone = *this; - return clone; -} -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkSimpleFastMutexLock.h b/Modules/Compatibility/Deprecated/include/itkSimpleFastMutexLock.h deleted file mode 100644 index 9a4679385d5..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkSimpleFastMutexLock.h +++ /dev/null @@ -1,80 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#ifndef itkSimpleFastMutexLock_h -#define itkSimpleFastMutexLock_h - -#include "itkMacro.h" -#include "itkThreadSupport.h" -#include "ITKDeprecatedExport.h" - -namespace itk -{ - -/** - * \class SimpleFastMutexLock - * \brief Critical section locking class that can be allocated on the stack. - * - * SimpleFastMutexLock is used by FastMutexLock to perform mutex locking. - * SimpleFastMutexLock is not a subclass of Object and is designed to be - * allocated on the stack. - * - * \ingroup OSSystemObjects - * \ingroup ITKDeprecated - */ - -// Critical Section object that is not a itkObject. -class ITKDeprecated_EXPORT SimpleFastMutexLock -{ -public: - /** Standard class type aliases. */ - using Self = SimpleFastMutexLock; - - /** Constructor and destructor left public purposely because of stack - allocation. */ - SimpleFastMutexLock(); - ~SimpleFastMutexLock(); - - /** Lock access. */ - void - Lock() const; - - /** Non-blocking Lock access. - \return bool - true if lock is captured, false if it was already held by someone else. - */ - bool - TryLock() const; - - /** Unlock access. */ - void - Unlock() const; - -protected: - mutable FastMutexType m_FastMutexLock; -}; -} // namespace itk -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkTreeChangeEvent.h b/Modules/Compatibility/Deprecated/include/itkTreeChangeEvent.h deleted file mode 100644 index 6beb2385486..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkTreeChangeEvent.h +++ /dev/null @@ -1,279 +0,0 @@ -/*========================================================================= - * - * 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 itkTreeChangeEvent_h -#define itkTreeChangeEvent_h - -#include "itkMacro.h" -#include "itkEventObject.h" -#include "itkTreeIteratorBase.h" - -namespace itk -{ -/** \class TreeChangeEvent - * \brief Checks if the position of a node in the tree has been changed. - * - * \ingroup ITKDeprecated - */ -template -class ITK_TEMPLATE_EXPORT TreeChangeEvent : public ModifiedEvent -{ -public: - /** Typedefs */ - using Self = TreeChangeEvent; - using Superclass = ModifiedEvent; - - Self & - operator=(const Self &) = delete; - - /** Constructor */ - TreeChangeEvent() - : m_ChangePosition(nullptr) - {} - - /** Copy constructor */ - TreeChangeEvent(const TreeIteratorBase & position) { m_ChangePosition = &position; } - - /** Destructor */ - ~TreeChangeEvent() override = default; - - /** Get the event name */ - const char * - GetEventName() const override - { - return "TreeChangeEvent"; - } - - /** Check the event */ - bool - CheckEvent(const itk::EventObject * e) const override - { - return (dynamic_cast(e) != nullptr); - } - - /** Make the event object */ - itk::EventObject * - MakeObject() const override - { - return new Self(*m_ChangePosition); - } - - /** Get the change position */ - const TreeIteratorBase & - GetChangePosition() const - { - return *m_ChangePosition; - } - - // cppcheck-suppress uninitVar - TreeChangeEvent(const Self & s) - : itk::ModifiedEvent(s) - {} - -protected: - const TreeIteratorBase * m_ChangePosition{}; -}; - -/** \class TreeNodeChangeEvent - * \brief Signals that a node has been set to another value. The position of the - * changed node is provided. - * \ingroup ITKDeprecated - */ -template -class ITK_TEMPLATE_EXPORT TreeNodeChangeEvent : public TreeChangeEvent -{ -public: - using Self = TreeNodeChangeEvent; - using Superclass = TreeChangeEvent; - - TreeNodeChangeEvent() = default; - - TreeNodeChangeEvent(const TreeIteratorBase & position) - : TreeChangeEvent(position) - {} - - const char * - GetEventName() const override - { - return "TreeNodeChangeEvent"; - } - - bool - CheckEvent(const itk::EventObject * e) const override - { - auto eSelf = dynamic_cast(e); - return eSelf != nullptr; - } - - itk::EventObject * - MakeObject() const override - { - return new Self(*this->m_ChangePosition); - } - - TreeNodeChangeEvent(const Self & s) - : TreeChangeEvent(s) - {} - - void - operator=(const Self &) = delete; -}; - -/** \class TreeAddEvent - * \brief Checks if a node has been added to the tree. - * \ingroup ITKDeprecated - */ -template -class ITK_TEMPLATE_EXPORT TreeAddEvent : public TreeChangeEvent -{ -public: - /** Typedefs */ - using Self = TreeAddEvent; - using Superclass = TreeChangeEvent; - - /** Constructor */ - TreeAddEvent() = default; - - /** Copy constructor */ - TreeAddEvent(const TreeIteratorBase & position) - : TreeChangeEvent(position) - {} - - /** Get the name of the event */ - const char * - GetEventName() const override - { - return "TreeAddEvent"; - } - - /** Check event function */ - bool - CheckEvent(const itk::EventObject * e) const override - { - return (dynamic_cast(e) != nullptr); - } - - /** Make the event object */ - itk::EventObject * - MakeObject() const override - { - return new Self(*this->m_ChangePosition); - } - - TreeAddEvent(const Self & s) - : TreeChangeEvent(s) - {} - - void - operator=(const Self &) = delete; -}; - -/** \class TreeRemoveEvent - * \brief Checks if a node has been removed from the tree. - * \ingroup ITKDeprecated - */ -template -class ITK_TEMPLATE_EXPORT TreeRemoveEvent : public TreeChangeEvent -{ -public: - /** Typedefs */ - using Self = TreeRemoveEvent; - using Superclass = TreeChangeEvent; - - /** Constructor */ - TreeRemoveEvent() = default; - - /** Copy constructor */ - TreeRemoveEvent(const TreeIteratorBase & position) - : TreeChangeEvent(position) - {} - - /** Get the event name */ - const char * - GetEventName() const override - { - return "TreeRemoveEvent"; - } - - /** Check the event */ - bool - CheckEvent(const itk::EventObject * e) const override - { - return (dynamic_cast(e) != nullptr); - } - - /** Make the event object */ - itk::EventObject * - MakeObject() const override - { - return new Self(*this->m_ChangePosition); - } - - TreeRemoveEvent(const Self & s) - : TreeChangeEvent(s) - {} - - void - operator=(const Self &) = delete; -}; - -/** \class TreePruneEvent - * \brief Signals that a node and all its children will shortly be - * removed. The position of the top-level removed node is provided. - * \ingroup ITKDeprecated - */ -template -class ITK_TEMPLATE_EXPORT TreePruneEvent : public TreeRemoveEvent -{ -public: - using Self = TreePruneEvent; - using Superclass = TreeRemoveEvent; - - TreePruneEvent() = default; - - TreePruneEvent(const TreeIteratorBase & position) - : TreeRemoveEvent(position) - {} - - const char * - GetEventName() const override - { - return "TreePruneEvent"; - } - - bool - CheckEvent(const itk::EventObject * e) const override - { - return (dynamic_cast(e) != nullptr); - } - - itk::EventObject * - MakeObject() const override - { - return new Self(*this->m_ChangePosition); - } - - TreePruneEvent(const Self & s) - : TreeRemoveEvent(s) - {} - - void - operator=(const Self &) = delete; -}; -} // namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkTreeContainer.h b/Modules/Compatibility/Deprecated/include/itkTreeContainer.h deleted file mode 100644 index 631071df4c4..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkTreeContainer.h +++ /dev/null @@ -1,137 +0,0 @@ -/*========================================================================= - * - * 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 itkTreeContainer_h -#define itkTreeContainer_h - -#include "itkTreeContainerBase.h" -#include "itkPreOrderTreeIterator.h" - -namespace itk -{ -/** \class TreeContainer - * \brief A tree container. - * - * This class derives from the TreeContainerBase class. - * The class is templated over the type of the elements. - * - * \tparam TValue Element type stored at each location in the Tree. - * - * \ingroup DataRepresentation - * \ingroup ITKDeprecated - */ -template -class ITK_TEMPLATE_EXPORT TreeContainer : public TreeContainerBase -{ -public: - /** Standard type alias */ - using Superclass = TreeContainerBase; - using Self = TreeContainer; - using Pointer = SmartPointer; - using ConstPointer = SmartPointer; - using ValueType = TValue; - using TreeNodeType = TreeNode; - - /** Iterators type alias */ - using IteratorType = TreeIteratorBase; - using PreOrderIteratorType = PreOrderTreeIterator; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** \see LightObject::GetNameOfClass() */ - itkOverrideGetNameOfClassMacro(TreeContainer); - - /** Constructor with default children count. */ - TreeContainer(int defaultChildrenCount); - - /** Constructor by adding a tree. */ - TreeContainer(TreeContainer & tree); - - /** Set the specified element as the root. */ - bool - SetRoot(const TValue element) override; - - /** Set the specified iterator position as the root. */ - bool - SetRoot(IteratorType & pos); - - /** Set the specified tree node as the root. */ - bool - SetRoot(TreeNode * node) override; - - /** Return true if the element is in the tree. */ - bool - Contains(const TValue element) override; - - /** Return the number of elements in the tree. */ - int - Count() const override; - - /** Return true if the node containing the given element is a leaf of the tree. */ - bool - IsLeaf(const TValue element) override; - - /** Return true if the node containing the given element is the root. */ - bool - IsRoot(const TValue element) override; - - /** Clear the tree. */ - bool - Clear() override; - - /** operator equal. */ - bool - operator==(TreeContainer & tree); - - /** Swap the iterators. */ - bool - Swap(IteratorType & v, IteratorType & w); - - /** Get the root. */ - const TreeNodeType * - GetRoot() const override - { - return m_Root.GetPointer(); - } - - /** Add a child to a given parent. */ - bool - Add(const TValue child, const TValue parent); - - /** Get the node corresponding to the given a value. */ - const TreeNodeType * - GetNode(TValue val) const; - -protected: - TreeContainer(); - ~TreeContainer() override = default; - - typename TreeNodeType::Pointer m_Root{}; - - int m_DefaultChildrenCount{}; - - void - PrintSelf(std::ostream & os, Indent indent) const override; -}; -} // namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -# include "itkTreeContainer.hxx" -#endif - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkTreeContainer.hxx b/Modules/Compatibility/Deprecated/include/itkTreeContainer.hxx deleted file mode 100644 index 9fcdabef877..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkTreeContainer.hxx +++ /dev/null @@ -1,331 +0,0 @@ -/*========================================================================= - * - * 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 itkTreeContainer_hxx -#define itkTreeContainer_hxx - - -namespace itk -{ - -template -TreeContainer::TreeContainer() -{ - m_Root = nullptr; - this->SetSubtree(false); - m_DefaultChildrenCount = 2; -} - -template -TreeContainer::TreeContainer(int dcc) -{ - m_Root = nullptr; - this->SetSubtree(false); - m_DefaultChildrenCount = dcc; -} - -template -TreeContainer::TreeContainer(TreeContainer &) -{ - m_Root = nullptr; - this->SetSubtree(false); - m_DefaultChildrenCount = 3; -} - -template -bool -TreeContainer::SetRoot(const TValue element) -{ - m_Root = TreeNodeType::New(); - m_Root->Set(element); - m_Root->SetParent(nullptr); - return true; -} - -template -bool -TreeContainer::SetRoot(TreeNode * node) -{ - m_Root = node; - return true; -} - -template -int -TreeContainer::Count() const -{ - if (!m_Root) - { - return 0; - } - int size = 0; - PreOrderTreeIterator it(this, this->m_Root); - it.GoToBegin(); - while (!it.IsAtEnd()) - { - ++size; - ++it; - } - return size; -} - -template -bool -TreeContainer::Swap(IteratorType & v, IteratorType & w) -{ - TreeNode * nv = v.GetNode(); - TreeNode * nw = w.GetNode(); - - if (nv == nullptr || nw == nullptr) - { - return false; - } - TreeNode * pv = nv->GetParent(); - TreeNode * pw = nw->GetParent(); - - if (pv == nullptr && pw == nullptr) - { - return false; - } - else if (pv == nullptr) - { - pw->ReplaceChild(nw, nv); - m_Root = nw; - } - else if (pw == nullptr) - { - pv->ReplaceChild(nv, nw); - m_Root = nv; - } - else - { - pv->ReplaceChild(nv, nw); - pw->ReplaceChild(nw, nv); - } - - nv->SetParent(pw); - nw->SetParent(pv); - - return true; -} - -template -bool -TreeContainer::Contains(const TValue element) -{ - PreOrderTreeIterator it(this, m_Root); - it.GoToBegin(); - while (!it.IsAtEnd()) - { - if (it.Get() == element) - { - return true; - } - ++it; - } - return false; -} - -template -bool -TreeContainer::operator==(TreeContainer & tree) -{ - PreOrderTreeIterator it(this, m_Root); - it.GoToBegin(); - PreOrderTreeIterator it2(&tree, tree.GetRoot()); - it2.GoToBegin(); - - while ((!it.IsAtEnd()) && (!it2.IsAtEnd())) - { - if (it.Get() != it2.Get()) - { - return false; - } - ++it; - ++it2; - } - - return true; -} - -template -bool -TreeContainer::IsLeaf(TValue element) -{ - PreOrderTreeIterator it(this, m_Root); - it.GoToBegin(); - while (!it.IsAtEnd()) - { - if (it.Get() == element) - { - if (it.IsLeaf()) - { - return true; - } - else - { - return false; - } - } - } - return false; -} - -template -bool -TreeContainer::IsRoot(TValue element) -{ - PreOrderTreeIterator it(this, m_Root); - it.GoToBegin(); - while (!it.IsAtEnd()) - { - if (it.Get() == element) - { - if (!it.HasParent()) - { - return true; - } - else - { - return false; - } - } - ++it; - } - return false; -} - -template -bool -TreeContainer::Clear() -{ - PreOrderTreeIterator it(this, m_Root); - bool success = it.Remove(); - m_Root = nullptr; - return success; -} - -template -const TreeNode * -TreeContainer::GetNode(TValue val) const -{ - PreOrderTreeIterator it(this, m_Root); - it.GoToBegin(); - while (!it.IsAtEnd()) - { - if (it.Get() == val) - { - return it.GetNode(); - } - ++it; - } - return nullptr; -} - -template -bool -TreeContainer::SetRoot(IteratorType & pos) -{ - if (this->m_SubTree) - { - return false; - } - TreeNode * node = pos.GetNode(); - if (node == nullptr) - { - return false; - } - - TreeNode * parent = node->GetParent(); - TreeNode * help = nullptr; - - if (parent == nullptr) - { - return false; - } - - m_Root = node; - node->AddChild(parent); - parent->Remove(node); - node->SetParent(nullptr); - help = parent->GetParent(); - parent->SetParent(node); - node = parent; - - while (help != nullptr) - { - parent = help; - help = help->GetParent(); - node->AddChild(parent); - parent->Remove(node); - parent->SetParent(node); - node = parent; - } - return true; -} - -template -bool -TreeContainer::Add(const TValue child, const TValue parent) -{ - if (!m_Root) - { - std::cout << "TreeContainer::Add() : The tree is empty" << std::endl; - return false; - } - // Find the first node in the tree that has the parent value - PreOrderTreeIterator it(this, m_Root); - it.GoToBegin(); - while (!it.IsAtEnd()) - { - if (it.Get() == parent) - { - it.Add(child); - return true; - } - ++it; - } - return false; -} - -template -void -TreeContainer::PrintSelf(std::ostream & os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - os << indent << "Number of objects = " << this->Count() << std::endl; - - if (this->Count() > 0) - { - os << indent << "Tree:" << std::endl; - // Now prints the tree - PreOrderTreeIterator it(this, m_Root); - it.GoToBegin(); - while (!it.IsAtEnd()) - { - if (it.GetParent()) - { - std::cout << it.GetParent()->Get() << " <- "; - } - std::cout << it.Get() << std::endl; - ++it; - } - } -} -} // namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkTreeContainerBase.h b/Modules/Compatibility/Deprecated/include/itkTreeContainerBase.h deleted file mode 100644 index 032a392fd79..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkTreeContainerBase.h +++ /dev/null @@ -1,94 +0,0 @@ -/*========================================================================= - * - * 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 itkTreeContainerBase_h -#define itkTreeContainerBase_h - -#include "itkMacro.h" -#include -#include "itkTreeNode.h" - -namespace itk -{ -/** \class TreeContainerBase - * \brief A base class for tree containers. - * - * \ingroup DataRepresentation - * \ingroup ITKDeprecated - */ -template -class TreeContainerBase : public Object -{ -public: - using Superclass = Object; - using Self = TreeContainerBase; - using Pointer = SmartPointer; - using ConstPointer = SmartPointer; - - using ValueType = TValue; - - /** \see LightObject::GetNameOfClass() */ - itkOverrideGetNameOfClassMacro(TreeContainerBase); - - /** Set the root element. - * A new node is created and the element is added to the node */ - virtual bool - SetRoot(const TValue element) = 0; - - /** Set the root has a node */ - virtual bool - SetRoot(TreeNode * node) = 0; - - /** Return true if the tree contains the element */ - virtual bool - Contains(const TValue element) = 0; - - /** Return the number of nodes in the tree */ - virtual int - Count() const = 0; - - /** Return if the element is a leaf */ - virtual bool - IsLeaf(const TValue element) = 0; - - /** Return if the element is root */ - virtual bool - IsRoot(const TValue element) = 0; - - /** Clear the tree */ - virtual bool - Clear() = 0; - - /** Get the root as a node */ - virtual const TreeNode * - GetRoot() const = 0; - - /** Set if the tree is a subtree */ - void - SetSubtree(bool val) - { - m_SubTree = val; - } - -protected: - TreeContainerBase() = default; - ~TreeContainerBase() override = default; - bool m_SubTree{ false }; -}; -} // namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkTreeIteratorBase.h b/Modules/Compatibility/Deprecated/include/itkTreeIteratorBase.h deleted file mode 100644 index 464ab68fd1e..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkTreeIteratorBase.h +++ /dev/null @@ -1,293 +0,0 @@ -/*========================================================================= - * - * 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 itkTreeIteratorBase_h -#define itkTreeIteratorBase_h - -#include "itkTreeNode.h" - -namespace itk -{ -/** \class TreeIteratorBaseEnums - * \brief Enum classes used in the TreeIteratorBase class. - * \ingroup ITKDeprecated - */ -class TreeIteratorBaseEnums -{ -public: - /** \class TreeIteratorBaseNode - * \ingroup ITKDeprecated - * Enumerations for node type - */ - enum class TreeIteratorBaseNode : uint8_t - { - UNDEFIND = 0, - PREORDER = 1, - INORDER = 2, - POSTORDER = 3, - LEVELORDER = 4, - CHILD = 5, - ROOT = 6, - LEAF = 7 - }; -}; -// Define how to print enumeration -extern ITKCOMMON_DEPRECATED_EXPORT std::ostream & - operator<<(std::ostream & out, const TreeIteratorBaseEnums::TreeIteratorBaseNode value); -/** \class TreeIteratorBase - * \brief This class provides the base implementation for tree iterators. - * - * Events will notify interested observers about tree changes. These events all derive from TreeChangeEvent. They are: - * - * - TreeNodeChangeEvent: invoked when Set() is called, i.e. exactly one node changes - * - TreeAddEvent: invoked when Add() is called. - * - TreeRemoveEvent: when a single node has been removed, i.e. Disconnect() has been called. - * - TreePruneEvent: when a node and all its children were removed, i.e. Remove() has been called. - * - * All those events have a member GetChangePosition(), which returns an iterator to the position that has changed. - * Please note that this iterator may not be fully functional, but you should always be able to use its Get() method to - * retrieve the thing it points to. - * - * \ingroup ITKDeprecated - */ -template -class ITK_TEMPLATE_EXPORT TreeIteratorBase -{ -public: - /** Typedefs */ - using Self = TreeIteratorBase; - using ValueType = typename TTreeType::ValueType; - using TreeNodeType = typename TTreeType::TreeNodeType; - using ChildIdentifier = typename TreeNodeType::ChildIdentifier; - - /** Backwards compatibility for enum values */ - using NodeType = TreeIteratorBaseEnums::TreeIteratorBaseNode; -#if !defined(ITK_LEGACY_REMOVE) - // We need to expose the enum values at the class level - // for backwards compatibility - static constexpr NodeType UNDEFIND = NodeType::UNDEFIND; - static constexpr NodeType PREORDER = NodeType::PREORDER; - static constexpr NodeType INORDER = NodeType::INORDER; - static constexpr NodeType POSTORDER = NodeType::POSTORDER; - static constexpr NodeType LEVELORDER = NodeType::LEVELORDER; - static constexpr NodeType CHILD = NodeType::CHILD; - static constexpr NodeType ROOT = NodeType::ROOT; - static constexpr NodeType LEAF = NodeType::LEAF; -#endif - - /** Add an element to the tree at the current node. - * - * Creates a new child node. - */ - virtual bool - Add(ValueType element); - - /** Add an element to the tree at a given position. */ - virtual bool - Add(int position, ValueType element); - - /** Add a subtree. */ - virtual bool - Add(TTreeType & subTree); - - /** Get the value of the current node. */ - virtual const ValueType & - Get() const; - - /** Get the subtree. */ - virtual TTreeType * - GetSubTree() const; - - /** Return true if the current node is a leaf. */ - virtual bool - IsLeaf() const; - - /** Return true if the current node is a root */ - virtual bool - IsRoot() const; - - /** Get the type of iterator */ - virtual NodeType - GetType() const = 0; - - /** Go to the specified child. */ - virtual bool - GoToChild(ChildIdentifier number = 0); - - /** Go to the parent of the current node. */ - virtual bool - GoToParent(); - - /** Set the specified value to the current node. */ - void - Set(ValueType element); - - /** Return true if the current node has a child. */ - virtual bool - HasChild(int number = 0) const; - - /** Return the current child position of an element. */ - virtual int - ChildPosition(ValueType element) const; - - /** Remove a child. - * - * Removes its child nodes as well. - * / - virtual bool - RemoveChild(int number); - - /** Count the number of children. */ - virtual int - CountChildren() const; - - /** Return true if the current node has a parent. */ - virtual bool - HasParent() const; - - /** Disconnect the tree. */ - virtual bool - Disconnect(); - - /** Return a list of children. */ - virtual TreeIteratorBase * - Children(); - - /** Return the list of parents. */ - virtual TreeIteratorBase * - Parents(); - - /** Get the child corresponding to the given a number at the current node. */ - virtual TreeIteratorBase * - GetChild(int number) const; - - /** Count the number of nodes. */ - virtual int - Count(); - - /** Remove the current node from the tree. */ - bool - Remove(); - - /** Get the current node. */ - virtual TreeNodeType * - GetNode(); - - virtual const TreeNodeType * - GetNode() const; - - /** Get the root. */ - TreeNodeType * - GetRoot(); - - const TreeNodeType * - GetRoot() const; - - /** Get the tree. */ - TTreeType * - GetTree() const; - - /** Return the first parent found. */ - const TreeNodeType * - GetParent() const; - - /** Move an iterator to the beginning of the tree. */ - void - GoToBegin() - { - m_Position = m_Begin; - } - - /** Move an iterator to the end of the tree. */ - void - GoToEnd() - { - m_Position = nullptr; - } - - /** Is the iterator at the beginning of the tree? */ - bool - IsAtBegin() const - { - return (m_Position == m_Begin); - } - - /** Is the iterator at the end of the tree? */ - bool - IsAtEnd() const - { - return (m_Position == nullptr); - } - - /** Clone the iterator */ - virtual TreeIteratorBase * - Clone() = 0; - - /** operator++ */ - Self & - operator++() - { - this->Next(); - return *this; - } - - /** operator++ */ - void - operator++(int) - { - this->Next(); - } - - /** operator = */ - Self & - operator=(const Self & iterator) - { - if (this != &iterator) - { - m_Position = iterator.m_Position; - m_Begin = iterator.m_Begin; - m_Root = iterator.m_Root; - m_Tree = iterator.m_Tree; - } - return *this; - } - - virtual ~TreeIteratorBase() = default; - -protected: - /** Constructors */ - TreeIteratorBase(TTreeType * tree, const TreeNodeType * start); - TreeIteratorBase(const TTreeType * tree, const TreeNodeType * start); - - mutable TreeNodeType * m_Position{}; // Current position of the iterator - mutable TreeNodeType * m_Begin{}; - const TreeNodeType * m_Root{}; - TTreeType * m_Tree{}; - - virtual bool - HasNext() const = 0; - - virtual const ValueType & - Next() = 0; -}; -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -# include "itkTreeIteratorBase.hxx" -#endif - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkTreeIteratorBase.hxx b/Modules/Compatibility/Deprecated/include/itkTreeIteratorBase.hxx deleted file mode 100644 index 5f4a77a4007..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkTreeIteratorBase.hxx +++ /dev/null @@ -1,503 +0,0 @@ -/*========================================================================= - * - * 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 itkTreeIteratorBase_hxx -#define itkTreeIteratorBase_hxx - -#include "itkTreeChangeEvent.h" - -/** There are some weird circular #include dependencies between TreeChangeEvent - * and TreeIteratorBase that cause the HeaderTest to fail without these forward - * declarations. */ -template -class ITK_TEMPLATE_EXPORT TreeNodeChangeEvent; - -template -class ITK_TEMPLATE_EXPORT TreeAddEvent; - -template -class ITK_TEMPLATE_EXPORT TreePruneEvent; - -template -class ITK_TEMPLATE_EXPORT TreeRemoveEvent; - -namespace itk -{ - -template -TreeIteratorBase::TreeIteratorBase(TTreeType * tree, const TreeNodeType * start) -{ - if (start) - { - m_Root = start; - } - else - { - m_Root = dynamic_cast(tree->GetRoot()); - } - - m_Position = const_cast(m_Root); - m_Tree = tree; - m_Begin = m_Position; -} - -template -TreeIteratorBase::TreeIteratorBase(const TTreeType * tree, const TreeNodeType * start) -{ - if (start) - { - m_Root = start; - } - else - { - m_Root = const_cast(dynamic_cast(tree->GetRoot())); - } - m_Position = const_cast(m_Root); - m_Tree = const_cast(tree); - m_Begin = m_Position; -} - -template -auto -TreeIteratorBase::Get() const -> const ValueType & -{ - return m_Position->Get(); -} - -template -void -TreeIteratorBase::Set(ValueType element) -{ - // itkAssertInDebugAndIgnoreInReleaseMacro(m_Position); - m_Position->Set(element); - m_Tree->Modified(); - m_Tree->InvokeEvent(TreeNodeChangeEvent(*this)); -} - -template -bool -TreeIteratorBase::Add(ValueType element) -{ - if (m_Position == nullptr && m_Root == nullptr) - { - bool returnValue = const_cast(m_Tree)->SetRoot(element); - // signal AddEvent for self - m_Root = dynamic_cast(const_cast(m_Tree)->GetRoot()); - m_Position = const_cast(m_Root); - m_Tree->Modified(); - m_Tree->InvokeEvent(TreeAddEvent(*this)); - return returnValue; - } - else if (m_Position == nullptr) - { - return false; - } - - auto node = TreeNodeType::New(); - node->Set(element); - m_Position->AddChild(node); - m_Tree->Modified(); - - // signal AddEvent for new child - TreeIteratorBase * childIterator = Clone(); - childIterator->m_Position = dynamic_cast(m_Position->GetChild(m_Position->ChildPosition(node))); - // signal "child has been added deleted" - m_Tree->InvokeEvent(TreeAddEvent(*childIterator)); - delete childIterator; - - return true; -} - -template -bool -TreeIteratorBase::Add(int itkNotUsed(childPosition), ValueType element) -{ - if (m_Position) - { - auto node = TreeNodeType::New(); - node->Set(element); - m_Position->AddChild(node); - m_Tree->Modified(); - - // signal AddEvent - TreeIteratorBase * childIterator = Clone(); - childIterator->m_Position = dynamic_cast(m_Position->GetChild(m_Position->ChildPosition(node))); - // signal "child has been added deleted" - m_Tree->InvokeEvent(TreeAddEvent(*childIterator)); - delete childIterator; - - return true; - } - return false; -} - -template -bool -TreeIteratorBase::IsLeaf() const -{ - return !(m_Position->HasChildren()); -} - -template -bool -TreeIteratorBase::IsRoot() const -{ - if (m_Root == nullptr) - { - return false; - } - - if (m_Position == m_Root) - { - return true; - } - return false; -} - -template -bool -TreeIteratorBase::Add(TTreeType & subTree) -{ - if (subTree.Count() == 0) - { - return false; - } - - if (!subTree.GetRoot()) - { - return false; - } - - if (m_Root == nullptr) - { - m_Root = static_cast(subTree.GetRoot()); - } - else - { - if (m_Position == nullptr) - { - return false; - } - m_Position->AddChild(const_cast(static_cast(subTree.GetRoot()))); - } - return true; -} - -template -TTreeType * -TreeIteratorBase::GetSubTree() const -{ - auto tree = TTreeType::New(); - tree->SetRoot(m_Position); - tree->SetSubtree(true); - return tree; -} - -template -bool -TreeIteratorBase::HasChild(int number) const -{ - if (m_Position == nullptr) - { - return false; - } - if (m_Position->GetChild(number) != nullptr) - { - return true; - } - return false; -} - -template -int -TreeIteratorBase::ChildPosition(ValueType element) const -{ - if (!m_Position) - { - return -1; - } - return m_Position->ChildPosition(element); -} - -template -bool -TreeIteratorBase::RemoveChild(int number) -{ - if (!HasChild(number)) - { - return false; - } - auto * child = dynamic_cast(m_Position->GetChild(number)); - - if (child != nullptr) - { - // signal PruneEvent (node plus all children are removed) - TreeIteratorBase * childIterator = Clone(); - childIterator->m_Position = child; - // signal "child has been added deleted" - m_Tree->InvokeEvent(TreePruneEvent(*childIterator)); - delete childIterator; - - // and really remove child (and subitems) - const_cast(m_Position)->Remove(child); - m_Tree->Modified(); - return true; - } - return false; -} - -template -int -TreeIteratorBase::CountChildren() const -{ - if (m_Position == nullptr) - { - return -1; - } - return m_Position->CountChildren(); -} - -template -bool -TreeIteratorBase::HasParent() const -{ - return (m_Position != nullptr && m_Position->GetParent() != nullptr); -} - -template -bool -TreeIteratorBase::Disconnect() -{ - if (m_Position == nullptr) - { - return false; - } - - if (m_Position->HasParent() == false) - { - return false; - } - - // keep node alive just a bit longer - typename TreeNodeType::Pointer position = m_Position; - - auto * parent = dynamic_cast(m_Position->GetParent()); - parent->Remove(const_cast(m_Position)); - m_Tree->Modified(); - - while (m_Position->CountChildren() > 0) - { - // always add first child in list, because AddChild() removes the added node - // from - // its former parent (== m_position) - auto * child = dynamic_cast(m_Position->GetChild(0)); - parent->AddChild(child); - } - - m_Tree->InvokeEvent(TreeRemoveEvent(*this)); - - m_Position = nullptr; - return true; -} - -template -TreeIteratorBase * -TreeIteratorBase::Children() -{ - itkGenericOutputMacro("Not implemented yet"); - itk::ExceptionObject e_(__FILE__, __LINE__, "Not implemented yet", ITK_LOCATION); - throw e_; /* Explicit naming to work around Intel compiler bug. */ - return nullptr; -} - -template -auto -TreeIteratorBase::GetParent() const -> const TreeNodeType * -{ - if (m_Position == nullptr) - { - return nullptr; - } - - return m_Position->GetParent(); -} - -template -TreeIteratorBase * -TreeIteratorBase::Parents() -{ - itkGenericOutputMacro("Not implemented yet"); - itk::ExceptionObject e_(__FILE__, __LINE__, "Not implemented yet", ITK_LOCATION); - throw e_; /* Explicit naming to work around Intel compiler bug. */ - return nullptr; -} - -template -bool -TreeIteratorBase::GoToChild(ChildIdentifier number) -{ - if (m_Position == nullptr) - { - return false; - } - - auto * next = dynamic_cast(m_Position->GetChild(number)); - - if (next == nullptr) - { - return false; - } - m_Position = next; - return true; -} - -template -bool -TreeIteratorBase::GoToParent() -{ - if (m_Position == nullptr) - { - return false; - } - - if (!m_Position->HasParent()) - { - return false; - } - - m_Position = dynamic_cast(m_Position->GetParent()); - return true; -} - -template -TreeIteratorBase * -TreeIteratorBase::GetChild(int number) const -{ - if (!m_Position) - { - return nullptr; - } - - auto * child = dynamic_cast(m_Position->GetChild(number)); - - if (!child) - { - return nullptr; - } - // return new WalkTreeIterator( child, m_Root, m_Tree, getType() - // ); - return nullptr; -} - -template -int -TreeIteratorBase::Count() -{ - int size = 0; - - this->GoToBegin(); - if (!m_Position->HasChildren()) - { - return 0; - } - while (this->Next()) - { - ++size; - } - return size; -} - -template -auto -TreeIteratorBase::GetNode() -> TreeNodeType * -{ - return const_cast(m_Position); -} - -template -auto -TreeIteratorBase::GetNode() const -> const TreeNodeType * -{ - return m_Position; -} - -template -auto -TreeIteratorBase::GetRoot() -> TreeNodeType * -{ - return const_cast(m_Root); -} - -template -auto -TreeIteratorBase::GetRoot() const -> const TreeNodeType * -{ - return m_Root; -} - -template -bool -TreeIteratorBase::Remove() -{ - if (m_Position == nullptr) - { - return false; - } - - // keep node alive just a bit longer (for the notification) - typename TreeNodeType::Pointer position = m_Position; - - if (m_Position->HasParent()) - { - TreeNodeType * parent = m_Position->GetParent(); - // removes this node (and implicitly all children, too) - parent->Remove(m_Position); - } - else if (m_Root == m_Position) - { - m_Root = nullptr; - m_Tree->SetRoot((TreeNodeType *)nullptr); - // this won't do anything if root is already != nullptr ==> root cannot be - // removed - } - - m_Position->SetParent(nullptr); // we don't have a parent anymore - m_Tree->InvokeEvent(TreePruneEvent(*this)); - while (m_Position->CountChildren() > 0) // remove all children - { - // always remove first child (id 0) - auto * child = dynamic_cast(m_Position->GetChild(0)); - m_Position->Remove(child); - } - - position = nullptr; - m_Position = nullptr; // Smart pointer, deletes *m_Position - - m_Tree->Modified(); - - return true; -} - -template -TTreeType * -TreeIteratorBase::GetTree() const -{ - return m_Tree; -} -} // namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkTreeIteratorClone.h b/Modules/Compatibility/Deprecated/include/itkTreeIteratorClone.h deleted file mode 100644 index 6c5b156cd87..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkTreeIteratorClone.h +++ /dev/null @@ -1,211 +0,0 @@ -/*========================================================================= - * - * 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 itkTreeIteratorClone_h -#define itkTreeIteratorClone_h - -#include "itkMacro.h" -#include - -namespace itk -{ -/** \class TreeIteratorClone - * \brief itkTreeIteratorClone class - * \ingroup DataRepresentation - * \ingroup ITKDeprecated - */ -template -class TreeIteratorClone -{ -public: - /** Typedefs */ - using Self = TreeIteratorClone; - using ObjectType = TObjectType; - - /** Constructor */ - TreeIteratorClone() { m_Pointer = 0; } - - /** Copy constructor */ - TreeIteratorClone(const TreeIteratorClone & p) - { - m_Pointer = nullptr; - if (p.m_Pointer != nullptr) - { - m_Pointer = p.m_Pointer->Clone(); - } - } - - /** Constructor to pointer p */ - TreeIteratorClone(ObjectType * p) - { - m_Pointer = 0; - if (p != nullptr) - { - m_Pointer = p->Clone(); - } - } - - /** Constructor to reference p */ - TreeIteratorClone(const ObjectType & p) - { - m_Pointer = nullptr; - m_Pointer = const_cast(&p)->Clone(); - } - - /** Destructor */ - ~TreeIteratorClone() - { - delete m_Pointer; - m_Pointer = nullptr; - } - - /** Overload operator -> */ - ObjectType * operator->() const { return m_Pointer; } - - /** Test if the pointer has been initialized */ - bool - IsNotNull() const - { - return m_Pointer != 0; - } - bool - IsNull() const - { - return m_Pointer == 0; - } - - /** Template comparison operators. */ - template - bool - operator==(TR r) const - { - return (m_Pointer == (ObjectType *)(r)); - } - -#ifndef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR - template - bool - operator!=(TR r) const - { - return (m_Pointer != (ObjectType *)(r)); - } -#endif - - /** Access function to pointer. */ - ObjectType * - GetPointer() const - { - return m_Pointer; - } - - /** Comparison of pointers. Less than comparison. */ - bool - operator<(const TreeIteratorClone & r) const - { - return (void *)m_Pointer < (void *)r.m_Pointer; - } - - /** Comparison of pointers. Greater than comparison. */ - bool - operator>(const TreeIteratorClone & r) const - { - return (void *)m_Pointer > (void *)r.m_Pointer; - } - - /** Comparison of pointers. Less than or equal to comparison. */ - bool - operator<=(const TreeIteratorClone & r) const - { - return (void *)m_Pointer <= (void *)r.m_Pointer; - } - - /** Comparison of pointers. Greater than or equal to comparison. */ - bool - operator>=(const TreeIteratorClone & r) const - { - return (void *)m_Pointer >= (void *)r.m_Pointer; - } - - /** Overload operator assignment. */ - TreeIteratorClone & - operator=(const TreeIteratorClone & r) - { - return this->operator=(r.GetPointer()); - } - - /** Overload operator assignment. */ - TreeIteratorClone & - operator=(const ObjectType * r) - { - if (m_Pointer != r) - { - delete m_Pointer; - m_Pointer = nullptr; - if (r != nullptr) - { - m_Pointer = const_cast(r)->Clone(); - } - } - return *this; - } - - Self & - operator++() - { - if (m_Pointer) - { - ++(*m_Pointer); - } - return *this; - } - - const Self - operator++(int) - { - if (m_Pointer) - { - const Self oldValue(m_Pointer); // create a copy of the iterator behind - // the pointer (Clone()) - ++(*m_Pointer); - return oldValue; - } - } - - /** Function to print object pointed to */ - ObjectType * - Print(std::ostream & os) const - { - // This prints the object pointed to by the pointer - m_Pointer->Print(os); - return m_Pointer; - } - -private: - /** The pointer to the object referred to by this smart pointer. */ - ObjectType * m_Pointer; -}; - -template -std::ostream & -operator<<(std::ostream & os, const TreeIteratorClone p) -{ - p.Print(os); - return os; -} -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkTreeNode.h b/Modules/Compatibility/Deprecated/include/itkTreeNode.h deleted file mode 100644 index a4326c6dcd6..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkTreeNode.h +++ /dev/null @@ -1,156 +0,0 @@ -/*========================================================================= - * - * 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 itkTreeNode_h -#define itkTreeNode_h - -#include -#include -#include -#include "itkObject.h" -#include "itkObjectFactory.h" -#include "itkIntTypes.h" - -namespace itk -{ -/** \class TreeNode - * \brief Represents a node in a tree. - * - * This class derives from the Object class. - * - * The class is templated over the type of the elements. - * - * \tparam TValue = Element type stored in the node - * - * \ingroup DataRepresentation - * \ingroup ITKDeprecated - */ -template -class ITK_TEMPLATE_EXPORT TreeNode : public Object -{ -public: - ITK_DISALLOW_COPY_AND_MOVE(TreeNode); - - /** Standard type alias */ - using Superclass = Object; - using Self = TreeNode; - using Pointer = SmartPointer; - using ConstPointer = SmartPointer; - using ChildrenListType = std::vector; - using ChildIdentifier = itk::OffsetValueType; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** \see LightObject::GetNameOfClass() */ - itkOverrideGetNameOfClassMacro(TreeNode); - - /** Get the value of the node */ - const TValue & - Get() const; - - /** Set the current value of the node */ - TValue - Set(const TValue data); - - /** Get the child node */ - Self * - GetChild(ChildIdentifier number) const; - - /** Get the parent node */ - Self * - GetParent() const; - - /** Return true if the node has children */ - bool - HasChildren() const; - - /** Return true if the node has a parent */ - bool - HasParent() const; - - /** Set the parent of the node */ - void - SetParent(Self * n); - - /** Return the number of children */ - ChildIdentifier - CountChildren() const; - - /** Remove a node from the node */ - bool - Remove(Self * n); - - /** Get the number of children given a name and depth */ - ChildIdentifier - GetNumberOfChildren(unsigned int depth = 0, char * name = nullptr) const; - - /** Replace a given child by a new one */ - bool - ReplaceChild(Self * oldChild, Self * newChild); - - /** Return the child position given a node */ - ChildIdentifier - ChildPosition(const Self * node) const; - - /** Return the child position given a value */ - ChildIdentifier - ChildPosition(TValue node) const; - - /** Add a child to the node */ - void - AddChild(Self * node); - - /** Add a child to the node and specify the number in the children list */ - virtual void - AddChild(ChildIdentifier number, Self * node); - - /** Get the children list */ -#if !defined(ITK_WRAPPING_PARSER) - virtual ChildrenListType * - GetChildren(unsigned int depth = 0, char * name = nullptr) const; - -#endif - - /** Get the internal list of children */ -#if !defined(ITK_WRAPPING_PARSER) - virtual ChildrenListType & - GetChildrenList() - { - return m_Children; - } -#endif - - /** Set the data of the node */ - // virtual void SetData(TValue data) {m_Data = data;} - -protected: - TreeNode() = default; - ~TreeNode() override; - - TValue m_Data{}; - Self * m_Parent{ nullptr }; - - ChildrenListType m_Children{}; -}; -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -# include "itkTreeNode.hxx" -#endif - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkTreeNode.hxx b/Modules/Compatibility/Deprecated/include/itkTreeNode.hxx deleted file mode 100644 index 6c86145786b..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkTreeNode.hxx +++ /dev/null @@ -1,303 +0,0 @@ -/*========================================================================= - * - * 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 itkTreeNode_hxx -#define itkTreeNode_hxx - -#include "itkMacro.h" -#include - -namespace itk -{ - -/** Destructor */ -template -TreeNode::~TreeNode() -{ - if (m_Parent) - { - m_Parent->Remove(this); - } - - const auto numberOfChildren = static_cast(m_Children.size()); - - for (ChildIdentifier i = numberOfChildren; i > 0; i--) - { - m_Children[i - 1]->SetParent(nullptr); - } - m_Children.clear(); - m_Parent = nullptr; - m_Data = 0; -} - -/** Return the parent node */ -template -TreeNode * -TreeNode::GetParent() const -{ - return m_Parent; -} - -/** Get a child */ -template -TreeNode * -TreeNode::GetChild(ChildIdentifier number) const -{ - const auto numberOfChildren = static_cast(m_Children.size()); - - if (number < numberOfChildren) - { - return m_Children[number]; - } - else - { - return nullptr; - } -} - -/** Set the value of a node */ -template -TValue -TreeNode::Set(const TValue data) -{ - TValue help = m_Data; - - m_Data = data; - return help; -} - -/** Get the data of node */ -template -const TValue & -TreeNode::Get() const -{ - return m_Data; -} - -/** Return true if has a parent */ -template -bool -TreeNode::HasParent() const -{ - return (m_Parent) ? true : false; -} - -/** Set the parent node */ -template -void -TreeNode::SetParent(TreeNode * node) -{ - // keep ourself alive just a bit longer - Pointer ourself = this; - - if (m_Parent != nullptr) - { - m_Parent->Remove(this); - } - m_Parent = node; -} - -/** Return true if the node has children */ -template -bool -TreeNode::HasChildren() const -{ - return (!m_Children.empty()) ? true : false; -} - -/** Return the number of children */ -template -auto -TreeNode::CountChildren() const -> ChildIdentifier -{ - return static_cast(m_Children.size()); -} - -/** Remove a child node from the current node */ -template -bool -TreeNode::Remove(Self * n) -{ - typename std::vector::iterator pos; - pos = std::find(m_Children.begin(), m_Children.end(), n); - if (pos != m_Children.end()) - { - // keep node alive just a bit longer - Pointer position = n; - m_Children.erase(pos); - n->SetParent(nullptr); - return true; - } - return false; -} - -/** Replace a child by a new one */ -template -bool -TreeNode::ReplaceChild(Self * oldChild, Self * newChild) -{ - const auto numberOfChildren = static_cast(m_Children.size()); - - for (ChildIdentifier i = 0; i < numberOfChildren; ++i) - { - if (m_Children[i] == oldChild) - { - m_Children[i] = newChild; - return true; - } - } - return false; -} - -/** Return the child position given a node */ -template -OffsetValueType -TreeNode::ChildPosition(const Self * node) const -{ - const auto numberOfChildren = static_cast(m_Children.size()); - - for (ChildIdentifier i = 0; i < numberOfChildren; ++i) - { - if (m_Children[i] == node) - { - return i; - } - } - return -1; -} - -/** Return the child position given an element, the first child found. */ -template -auto -TreeNode::ChildPosition(TValue element) const -> ChildIdentifier -{ - const auto numberOfChildren = static_cast(m_Children.size()); - - for (ChildIdentifier i = 0; i < numberOfChildren; ++i) - { - if (m_Children[i]->Get() == element) - { - return i; - } - } - return -1; -} - -/** Add a child node */ -template -void -TreeNode::AddChild(Self * node) -{ - Pointer nodeKeepAlive = node; - - node->SetParent(this); - m_Children.push_back(node); -} - -/** Add a child at a specific position in the children list */ -template -void -TreeNode::AddChild(ChildIdentifier number, Self * node) -{ - const auto numberOfChildren = static_cast(m_Children.size()); - auto childId = static_cast(number); - - if (childId > numberOfChildren) - { - m_Children.resize(childId); - for (ChildIdentifier i = numberOfChildren; i <= childId; ++i) - { - m_Children[i] = nullptr; - } - m_Children[number] = node; - return; - } - - m_Children[number] = node; -} - -/** Get the number of children given a name and a depth */ -template -auto -TreeNode::GetNumberOfChildren(unsigned int depth, char * name) const -> ChildIdentifier -{ - auto it = m_Children.begin(); - auto itEnd = m_Children.end(); - - ChildIdentifier cnt = 0; - while (it != itEnd) - { - if (name == nullptr || strstr(typeid(**it).name(), name)) - { - ++cnt; - } - ++it; - } - - it = m_Children.begin(); - itEnd = m_Children.end(); - if (depth > 0) - { - while (it != itEnd) - { - cnt += (*it)->GetNumberOfChildren(depth - 1, name); - ++it; - } - } - - return cnt; -} - -/** Get children given a name and a depth */ -#if !defined(ITK_WRAPPING_PARSER) -template -auto -TreeNode::GetChildren(unsigned int depth, char * name) const -> ChildrenListType * -{ - auto * children = new ChildrenListType; - - auto childrenListIt = m_Children.begin(); - auto childrenListEnd = m_Children.end(); - - while (childrenListIt != childrenListEnd) - { - if (name == nullptr || strstr(typeid(**childrenListIt).name(), name)) - { - children->push_back(*childrenListIt); - } - if (depth > 0) - { - ChildrenListType * nextchildren = (**childrenListIt).GetChildren(depth - 1, name); - // Add the child to the current list - typename ChildrenListType::const_iterator nextIt = nextchildren->begin(); - while (nextIt != nextchildren->end()) - { - children->push_back(*nextIt); - ++nextIt; - } - delete nextchildren; - } - ++childrenListIt; - } - - return children; -} - -#endif -} // namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkVectorCastImageFilter.h b/Modules/Compatibility/Deprecated/include/itkVectorCastImageFilter.h deleted file mode 100644 index 2d17af244cd..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkVectorCastImageFilter.h +++ /dev/null @@ -1,119 +0,0 @@ -/*========================================================================= - * - * 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 itkVectorCastImageFilter_h -#define itkVectorCastImageFilter_h - -#include "itkUnaryFunctorImageFilter.h" -#include "itkNumericTraitsFixedArrayPixel.h" - -namespace itk -{ -/** - * \class VectorCastImageFilter - * - * \brief Casts input vector pixels to output vector pixel type. - * - * This filter is templated over the input image type and - * output image type. - * - * The filter expect both images to have the same number of dimensions, - * and that both the input and output have itk::Vector pixel types - * of the same VectorDimension. - * - * \sa Vector - * - * \ingroup IntensityImageFilters MultiThreaded - * \ingroup ITKDeprecated - */ -namespace Functor -{ -template -class VectorCast -{ -public: - bool - operator!=(const VectorCast &) const - { - return false; - } - - bool - operator==(const VectorCast & other) const - { - return !(*this != other); - } - - inline TOutput - operator()(const TInput & A) const - { - using OutputValueType = typename TOutput::ValueType; - - TOutput value; - for (unsigned int k = 0; k < TOutput::Dimension; ++k) - { - value[k] = static_cast(A[k]); - } - return value; - } -}; -} // namespace Functor - -template -class VectorCastImageFilter - : public UnaryFunctorImageFilter< - TInputImage, - TOutputImage, - Functor::VectorCast> -{ -public: - ITK_DISALLOW_COPY_AND_MOVE(VectorCastImageFilter); - - /** Standard class type aliases. */ - using Self = VectorCastImageFilter; - using Superclass = - UnaryFunctorImageFilter>; - - using Pointer = SmartPointer; - using ConstPointer = SmartPointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** \see LightObject::GetNameOfClass() */ - itkOverrideGetNameOfClassMacro(VectorCastImageFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - // Begin concept checking - itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits)); - itkConceptMacro(OutputHasNumericTraitsCheck, - (Concept::HasNumericTraits)); - itkConceptMacro( - InputConvertibleToOutputCheck, - (Concept::Convertible)); - // End concept checking -#endif - -protected: - VectorCastImageFilter() = default; - ~VectorCastImageFilter() override = default; -}; -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkVectorCentralDifferenceImageFunction.h b/Modules/Compatibility/Deprecated/include/itkVectorCentralDifferenceImageFunction.h deleted file mode 100644 index 728c822de14..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkVectorCentralDifferenceImageFunction.h +++ /dev/null @@ -1,158 +0,0 @@ -/*========================================================================= - * - * 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 itkVectorCentralDifferenceImageFunction_h -#define itkVectorCentralDifferenceImageFunction_h - -#include "itkImageFunction.h" -#include "itkMatrix.h" - -namespace itk -{ - -/** - * \class VectorCentralDifferenceImageFunction - * \brief Calculate the derivative by central differencing. - * - * This class is templated over the input image type and - * the coordinate representation type (e.g. float or double). - * - * Possible improvements: - * - the use of Neighborhood operators may improve efficiency. - * - * \author Tom Vercauteren, INRIA & Mauna Kea Technologies - * - * This implementation was taken from the Insight Journal paper: - * https://www.insight-journal.org/browse/publication/154 - * - * \deprecated Please use CentralDifferenceImageFunction instead. - * - * \ingroup ImageFunctions - * \ingroup ITKDeprecated - */ -template -class ITK_TEMPLATE_EXPORT VectorCentralDifferenceImageFunction - : public ImageFunction, - TCoordRep> -{ -public: - ITK_DISALLOW_COPY_AND_MOVE(VectorCentralDifferenceImageFunction); - - using InputPixelType = typename TInputImage::PixelType; - - /** Extract the vector dimension from the pixel template parameter. */ - static constexpr unsigned int Dimension = InputPixelType::Dimension; - - /** Dimension underlying input image. */ - static constexpr unsigned int ImageDimension = TInputImage::ImageDimension; - - /** Standard class type aliases. */ - using Self = VectorCentralDifferenceImageFunction; - using Superclass = ImageFunction, TCoordRep>; - using Pointer = SmartPointer; - using ConstPointer = SmartPointer; - - /** \see LightObject::GetNameOfClass() */ - itkOverrideGetNameOfClassMacro(VectorCentralDifferenceImageFunction); - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** InputImageType type alias support */ - using InputImageType = TInputImage; - - /** OutputType typedef support. */ - using typename Superclass::OutputType; - - /** Index type alias support */ - using typename Superclass::IndexType; - - /** ContinuousIndex type alias support */ - using typename Superclass::ContinuousIndexType; - - /** Point type alias support */ - using typename Superclass::PointType; - - /** Evaluate the image derivative by central differencing at specified index. - * - * No bounds checking is done. - * The point is assume to lie within the image buffer. - * - * ImageFunction::IsInsideBuffer() can be used to check bounds before - * calling the method. */ - OutputType - EvaluateAtIndex(const IndexType & index) const override; - - /** Evaluate the image derivative by central differencing at non-integer - * positions. - * - * No bounds checking is done. - * The point is assumed to lie within the image buffer. - * - * ImageFunction::IsInsideBuffer() can be used to check bounds before - * calling the method. */ - OutputType - Evaluate(const PointType & point) const override - { - IndexType index; - - this->ConvertPointToNearestIndex(point, index); - return this->EvaluateAtIndex(index); - } - - OutputType - EvaluateAtContinuousIndex(const ContinuousIndexType & cindex) const override - { - IndexType index; - - this->ConvertContinuousIndexToNearestIndex(cindex, index); - return this->EvaluateAtIndex(index); - } - - /** The UseImageDirection flag determines whether image derivatives are - * computed with respect to the image grid or with respect to the physical - * space. When this flag is ON the derivatives are computed with respect to - * the coordinate system of physical space. The difference is whether we take - * into account the image Direction or not. The flag ON will take into - * account the image direction and will result in an extra matrix - * multiplication compared to the amount of computation performed when the - * flag is OFF. - * The default value of this flag is On. - */ - itkSetMacro(UseImageDirection, bool); - itkGetConstMacro(UseImageDirection, bool); - itkBooleanMacro(UseImageDirection); - -protected: - VectorCentralDifferenceImageFunction(); - ~VectorCentralDifferenceImageFunction() override = default; - void - PrintSelf(std::ostream & os, Indent indent) const override; - -private: - // flag to take or not the image direction into account - // when computing the derivatives. - bool m_UseImageDirection{ true }; -}; -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -# include "itkVectorCentralDifferenceImageFunction.hxx" -#endif - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkVectorCentralDifferenceImageFunction.hxx b/Modules/Compatibility/Deprecated/include/itkVectorCentralDifferenceImageFunction.hxx deleted file mode 100644 index 14ea29cce58..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkVectorCentralDifferenceImageFunction.hxx +++ /dev/null @@ -1,111 +0,0 @@ -/*========================================================================= - * - * 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 itkVectorCentralDifferenceImageFunction_hxx -#define itkVectorCentralDifferenceImageFunction_hxx - - -namespace itk -{ - -template -VectorCentralDifferenceImageFunction::VectorCentralDifferenceImageFunction() -{} - -template -void -VectorCentralDifferenceImageFunction::PrintSelf(std::ostream & os, Indent indent) const -{ - this->Superclass::PrintSelf(os, indent); - - os << indent << "UseImageDirection: " << m_UseImageDirection << std::endl; -} - -template -auto -VectorCentralDifferenceImageFunction::EvaluateAtIndex(const IndexType & index) const - -> OutputType -{ - OutputType derivative; - - derivative.Fill(0.0); - - IndexType neighIndex = index; - - const typename InputImageType::SizeType & size = this->GetInputImage()->GetBufferedRegion().GetSize(); - const typename InputImageType::IndexType & start = this->GetInputImage()->GetBufferedRegion().GetIndex(); - - for (unsigned int dim = 0; dim < TInputImage::ImageDimension; ++dim) - { - // bounds checking - if (index[dim] < start[dim] + 1 || index[dim] > (start[dim] + static_cast(size[dim]) - 2)) - { - for (unsigned int vdim = 0; vdim < Dimension; ++vdim) - { - derivative(vdim, dim) = 0.0; - } - continue; - } - - // compute derivative - const double deriv_weight = 0.5 / this->GetInputImage()->GetSpacing()[dim]; - - neighIndex[dim] += 1; - const InputPixelType & pixf = this->GetInputImage()->GetPixel(neighIndex); - for (unsigned int vdim = 0; vdim < Dimension; ++vdim) - { - derivative(vdim, dim) = pixf[vdim]; - } - - neighIndex[dim] -= 2; - const InputPixelType & pixb = this->GetInputImage()->GetPixel(neighIndex); - for (unsigned int vdim = 0; vdim < Dimension; ++vdim) - { - derivative(vdim, dim) -= pixb[vdim]; - derivative(vdim, dim) *= deriv_weight; - } - - neighIndex[dim] += 1; - } - - if (this->m_UseImageDirection) - { - OutputType orientedderivative; - const typename InputImageType::DirectionType & direction = this->GetInputImage()->GetDirection(); - for (unsigned int i = 0; i < TInputImage::ImageDimension; ++i) - { - std::vector sums(Dimension, 0.0); - for (unsigned int j = 0; j < TInputImage::ImageDimension; ++j) - { - for (unsigned int vdim = 0; vdim < Dimension; ++vdim) - { - sums[vdim] += direction[i][j] * derivative(vdim, j); - } - } - for (unsigned int vdim = 0; vdim < Dimension; ++vdim) - { - orientedderivative(vdim, i) = static_cast(sums[vdim]); - } - } - return orientedderivative; - } - - return (derivative); -} -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkVectorResampleImageFilter.h b/Modules/Compatibility/Deprecated/include/itkVectorResampleImageFilter.h deleted file mode 100644 index 688d5a45a64..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkVectorResampleImageFilter.h +++ /dev/null @@ -1,251 +0,0 @@ -/*========================================================================= - * - * 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 itkVectorResampleImageFilter_h -#define itkVectorResampleImageFilter_h - -#include "itkTransform.h" -#include "itkImageRegionIterator.h" -#include "itkImageToImageFilter.h" -#include "itkVectorInterpolateImageFunction.h" -#include "itkSize.h" - -namespace itk -{ -/** - * \class VectorResampleImageFilter - * \brief Resample an image via a coordinate transform - * - * VectorResampleImageFilter resamples an existing image through some coordinate - * transform, interpolating via some image function. The class is templated - * over the types of the input and output images. - * - * Note that the choice of interpolator function can be important. - * This function is set via SetInterpolator(). The default is - * itk::VectorLinearInterpolateImageFunction, which - * is reasonable for ordinary medical images. - * - * Since this filter produces an image which is a different size than - * its input, it needs to override several of the methods defined - * in ProcessObject in order to properly manage the pipeline execution model. - * In particular, this filter overrides - * ProcessObject::GenerateInputRequestedRegion() and - * ProcessObject::GenerateOutputInformation(). - * - * This filter is implemented as a multithreaded filter. It provides a - * DynamicThreadedGenerateData() method for its implementation. - * - * \deprecated ResampleImageFilter can now resample vector images and should - * be used instead of the VectorResampleImageFilter. - * - * \ingroup GeometricTransform - * \ingroup ITKDeprecated - * - * \sphinx - * \sphinxexample{Compatibility/Deprecated/ResampleRGBImage,Resample RGB Image} - * \sphinxexample{Core/Transform/TranslateAVectorImage,Translate A Vector Image} - * \sphinxexample{Compatibility/Deprecated/ResampleITK::VectorImage,Resample A Vector Image} - * \endsphinx - */ -template -class ITK_TEMPLATE_EXPORT VectorResampleImageFilter : public ImageToImageFilter -{ -public: - ITK_DISALLOW_COPY_AND_MOVE(VectorResampleImageFilter); - - /** Standard class type aliases. */ - using Self = VectorResampleImageFilter; - using Superclass = ImageToImageFilter; - using Pointer = SmartPointer; - using ConstPointer = SmartPointer; - - using InputImageType = TInputImage; - using OutputImageType = TOutputImage; - using InputImagePointer = typename InputImageType::Pointer; - using InputImageConstPointer = typename InputImageType::ConstPointer; - using OutputImagePointer = typename OutputImageType::Pointer; - using InputImageRegionType = typename InputImageType::RegionType; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** \see LightObject::GetNameOfClass() */ - itkOverrideGetNameOfClassMacro(VectorResampleImageFilter); - - /** Number of dimensions. */ - static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension; - - /** Transform type alias. - * - * \todo Check that input and output images have the same number of - * dimensions; this is required by the current implementation of - * AffineTransform. */ - using TransformType = Transform; - using TransformPointerType = typename TransformType::ConstPointer; - - /** Interpolator type alias. */ - using InterpolatorType = VectorInterpolateImageFunction; - using InterpolatorPointerType = typename InterpolatorType::Pointer; - - /** Image size type alias. */ - using SizeType = Size; - - /** Image index type alias. */ - using IndexType = typename TOutputImage::IndexType; - - /** Image point type alias. */ - using PointType = typename InterpolatorType::PointType; - - /** Image pixel value type alias. */ - using PixelType = typename TOutputImage::PixelType; - using PixelComponentType = typename PixelType::ValueType; - - /** Typedef to describe the output image region type. */ - using OutputImageRegionType = typename TOutputImage::RegionType; - - /** Image spacing, origin and direction type alias. */ - using SpacingType = typename TOutputImage::SpacingType; - using OriginPointType = typename TOutputImage::PointType; - using DirectionType = typename TOutputImage::DirectionType; - - /** Set/Get the coordinate transformation. - * Set the coordinate transform to use for resampling. Note that this - * must be in index coordinates and is the output-to-input transform, - * NOT the input-to-output transform that you might naively expect. - * The default is itk::AffineTransform. */ - itkSetConstObjectMacro(Transform, TransformType); - itkGetConstObjectMacro(Transform, TransformType); - - /** Set the interpolator function. The default is - * itk::VectorLinearInterpolateImageFunction. */ - itkSetObjectMacro(Interpolator, InterpolatorType); - - /** Get a pointer to the interpolator function. */ - itkGetModifiableObjectMacro(Interpolator, InterpolatorType); - - /** Set the size of the output image. */ - itkSetMacro(Size, SizeType); - - /** Get the size of the output image. */ - itkGetConstReferenceMacro(Size, SizeType); - - /** Set the pixel value when a transformed pixel is outside of the - * image. The default default pixel value is 0. */ - itkSetMacro(DefaultPixelValue, PixelType); - - /** Get the pixel value when a transformed pixel is outside of the image */ - itkGetConstMacro(DefaultPixelValue, PixelType); - - /** Set the output image spacing. */ - itkSetMacro(OutputSpacing, SpacingType); - virtual void - SetOutputSpacing(const double * values); - - /** Get the output image spacing. */ - itkGetConstReferenceMacro(OutputSpacing, SpacingType); - - /** Set the output image origin. */ - itkSetMacro(OutputOrigin, OriginPointType); - virtual void - SetOutputOrigin(const double * values); - - /** Get the output image origin. */ - itkGetConstReferenceMacro(OutputOrigin, OriginPointType); - - /** Set/Get the output direction cosine matrix. */ - itkSetMacro(OutputDirection, DirectionType); - itkGetConstReferenceMacro(OutputDirection, DirectionType); - - /** Set the start index of the output largest possible region. - * The default is an index of all zeros. */ - itkSetMacro(OutputStartIndex, IndexType); - - /** Get the start index of the output largest possible region. */ - itkGetConstReferenceMacro(OutputStartIndex, IndexType); - - /** VectorResampleImageFilter produces an image which is a different size - * than its input. As such, it needs to provide an implementation - * for GenerateOutputInformation() in order to inform the pipeline - * execution model. The original documentation of this method is - * below. \sa ProcessObject::GenerateOutputInformaton() */ - void - GenerateOutputInformation() override; - - /** VectorResampleImageFilter needs a different input requested region than - * the output requested region. As such, VectorResampleImageFilter needs - * to provide an implementation for GenerateInputRequestedRegion() - * in order to inform the pipeline execution model. - * \sa ProcessObject::GenerateInputRequestedRegion() */ - void - GenerateInputRequestedRegion() override; - - /** Set the state of the filter before multi-threading. - * Note that InterpolatorType::SetInputImage is not thread-safe and hence - * has to be set up before DynamicThreadedGenerateData. */ - void - BeforeThreadedGenerateData() override; - - /** Set the state of the filter after multi-threading. */ - void - AfterThreadedGenerateData() override; - - /** Compute the Modified Time based on changed to the components. */ - ModifiedTimeType - GetMTime() const override; - -#ifdef ITK_USE_CONCEPT_CHECKING - // Begin concept checking - itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits)); - itkConceptMacro(OutputHasNumericTraitsCheck, (Concept::HasNumericTraits)); - // End concept checking -#endif - -protected: - VectorResampleImageFilter(); - ~VectorResampleImageFilter() override = default; - void - PrintSelf(std::ostream & os, Indent indent) const override; - - /** VectorResampleImageFilter can be implemented as a multithreaded filter. Therefore, - * this implementation provides a DynamicThreadedGenerateData() routine which - * is called for each processing thread. The output image data is allocated - * automatically by the superclass prior to calling DynamicThreadedGenerateData(). - * DynamicThreadedGenerateData can only write to the portion of the output image - * specified by the parameter "outputRegionForThread" - * \sa ImageToImageFilter::ThreadedGenerateData(), - * ImageToImageFilter::GenerateData() */ - void - DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override; - - -private: - SizeType m_Size{}; - TransformPointerType m_Transform{}; - InterpolatorPointerType m_Interpolator{}; - PixelType m_DefaultPixelValue{}; - SpacingType m_OutputSpacing{}; - OriginPointType m_OutputOrigin{}; - DirectionType m_OutputDirection{}; - IndexType m_OutputStartIndex{}; -}; -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -# include "itkVectorResampleImageFilter.hxx" -#endif - -#endif diff --git a/Modules/Compatibility/Deprecated/include/itkVectorResampleImageFilter.hxx b/Modules/Compatibility/Deprecated/include/itkVectorResampleImageFilter.hxx deleted file mode 100644 index edc4f4ce5cf..00000000000 --- a/Modules/Compatibility/Deprecated/include/itkVectorResampleImageFilter.hxx +++ /dev/null @@ -1,250 +0,0 @@ -/*========================================================================= - * - * 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 itkVectorResampleImageFilter_hxx -#define itkVectorResampleImageFilter_hxx - -#include "itkIdentityTransform.h" -#include "itkVectorLinearInterpolateImageFunction.h" -#include "itkTotalProgressReporter.h" -#include "itkImageRegionIteratorWithIndex.h" -#include // For max. - -namespace itk -{ - -template -VectorResampleImageFilter::VectorResampleImageFilter() - : m_OutputSpacing(1.0) - , m_OutputOrigin(0.0) -{ - m_Size.Fill(0); - m_OutputStartIndex.Fill(0); - - m_OutputDirection.SetIdentity(); - - m_Transform = IdentityTransform::New(); - m_Interpolator = VectorLinearInterpolateImageFunction::New(); - - m_DefaultPixelValue = NumericTraits::ZeroValue(m_DefaultPixelValue); - this->DynamicMultiThreadingOn(); - this->ThreaderUpdateProgressOff(); -} - -template -void -VectorResampleImageFilter::SetOutputSpacing( - const double * spacing) -{ - SpacingType s; - for (unsigned int i = 0; i < TInputImage::ImageDimension; ++i) - { - s[i] = static_cast(spacing[i]); - } - this->SetOutputSpacing(s); -} - -template -void -VectorResampleImageFilter::SetOutputOrigin(const double * origin) -{ - OriginPointType p(origin); - - this->SetOutputOrigin(p); -} - -template -void -VectorResampleImageFilter::BeforeThreadedGenerateData() -{ - if (!m_Interpolator) - { - itkExceptionMacro("Interpolator not set"); - } - - // Connect input image to interpolator - m_Interpolator->SetInputImage(this->GetInput()); - - if (m_DefaultPixelValue.Size() == 0) - { - NumericTraits::SetLength(m_DefaultPixelValue, this->GetInput()->GetNumberOfComponentsPerPixel()); - m_DefaultPixelValue.Fill(0); - } -} - -template -void -VectorResampleImageFilter::AfterThreadedGenerateData() -{ - // Disconnect input image from the interpolator - m_Interpolator->SetInputImage(nullptr); -} - -template -void -VectorResampleImageFilter::DynamicThreadedGenerateData( - const OutputImageRegionType & outputRegionForThread) -{ - OutputImagePointer outputPtr = this->GetOutput(); - InputImageConstPointer inputPtr = this->GetInput(); - - TotalProgressReporter progress(this, outputPtr->GetRequestedRegion().GetNumberOfPixels()); - - // Create an iterator that will walk the output region for this thread. - using OutputIterator = ImageRegionIteratorWithIndex; - - OutputIterator outIt(outputPtr, outputRegionForThread); - - // Define a few indices that will be used to translate from an input pixel - // to an output pixel - PointType outputPoint; // Coordinates of current output pixel - PointType inputPoint; // Coordinates of current input pixel - - using ContinuousIndexType = ContinuousIndex; - - // Doc says this only works for VectorImage, but Image implementation says otherwise... - const unsigned int numberOfComponents = this->GetInput()->GetNumberOfComponentsPerPixel(); - - using OutputType = typename InterpolatorType::OutputType; - - // Walk the output region - outIt.GoToBegin(); - - while (!outIt.IsAtEnd()) - { - // Determine the index of the current output pixel - outputPtr->TransformIndexToPhysicalPoint(outIt.GetIndex(), outputPoint); - - // Compute corresponding input pixel position - inputPoint = m_Transform->TransformPoint(outputPoint); - const ContinuousIndexType inputIndex = - inputPtr->template TransformPhysicalPointToContinuousIndex(inputPoint); - - // Evaluate input at right position and copy to the output - if (m_Interpolator->IsInsideBuffer(inputIndex)) - { - PixelType pixval; - NumericTraits::SetLength(pixval, numberOfComponents); - - const OutputType value = m_Interpolator->EvaluateAtContinuousIndex(inputIndex); - for (unsigned int i = 0; i < numberOfComponents; ++i) - { - pixval[i] = static_cast(value[i]); - } - - outIt.Set(pixval); - } - else - { - outIt.Set(m_DefaultPixelValue); // default background value - } - - ++outIt; - progress.CompletedPixel(); - } -} - -template -void -VectorResampleImageFilter::GenerateInputRequestedRegion() -{ - // Call the superclass's implementation of this method - Superclass::GenerateInputRequestedRegion(); - - if (!this->GetInput()) - { - return; - } - - // Get the pointer to the input image - InputImagePointer inputPtr = const_cast(this->GetInput()); - - // Determining the actual input region is non-trivial, especially - // when we cannot assume anything about the transform being used. - // So we do the easy thing and request the entire input image. - // - InputImageRegionType inputRegion; - inputRegion = inputPtr->GetLargestPossibleRegion(); - inputPtr->SetRequestedRegion(inputRegion); -} - -template -void -VectorResampleImageFilter::GenerateOutputInformation() -{ - // Call the superclass' implementation of this method - Superclass::GenerateOutputInformation(); - - // Get the pointer to the output image - OutputImagePointer outputPtr = this->GetOutput(); - if (!outputPtr) - { - return; - } - - // Set the size of the output region - typename TOutputImage::RegionType outputLargestPossibleRegion; - outputLargestPossibleRegion.SetSize(m_Size); - outputLargestPossibleRegion.SetIndex(m_OutputStartIndex); - outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion); - - // Set spacing and origin - outputPtr->SetSpacing(m_OutputSpacing); - outputPtr->SetOrigin(m_OutputOrigin); - outputPtr->SetDirection(m_OutputDirection); -} - -template -ModifiedTimeType -VectorResampleImageFilter::GetMTime() const -{ - ModifiedTimeType latestTime = Object::GetMTime(); - - if (m_Transform) - { - latestTime = std::max(latestTime, m_Transform->GetMTime()); - } - - if (m_Interpolator) - { - latestTime = std::max(latestTime, m_Interpolator->GetMTime()); - } - - return latestTime; -} - -template -void -VectorResampleImageFilter::PrintSelf(std::ostream & os, - Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent - << "DefaultPixelValue: " << static_cast::PrintType>(m_DefaultPixelValue) - << std::endl; - os << indent << "Size: " << m_Size << std::endl; - os << indent << "OutputStartIndex: " << m_OutputStartIndex << std::endl; - os << indent << "OutputSpacing: " << m_OutputSpacing << std::endl; - os << indent << "OutputOrigin: " << m_OutputOrigin << std::endl; - os << indent << "OutputDirection: " << m_OutputDirection << std::endl; - os << indent << "Transform: " << m_Transform.GetPointer() << std::endl; - os << indent << "Interpolator: " << m_Interpolator.GetPointer() << std::endl; -} -} // end namespace itk - -#endif diff --git a/Modules/Compatibility/Deprecated/src/CMakeLists.txt b/Modules/Compatibility/Deprecated/src/CMakeLists.txt index 6c58174f062..349f4cc6c39 100644 --- a/Modules/Compatibility/Deprecated/src/CMakeLists.txt +++ b/Modules/Compatibility/Deprecated/src/CMakeLists.txt @@ -1,8 +1,4 @@ set(ITKDeprecated_SRCS - itkBarrier.cxx - itkConditionVariable.cxx - itkFastMutexLock.cxx - itkMutexLock.cxx - itkSimpleFastMutexLock.cxx) - + itkDeprecatedPlaceholder.cxx + ) itk_module_add_library(ITKDeprecated ${ITKDeprecated_SRCS}) diff --git a/Modules/Compatibility/Deprecated/src/itkBarrier.cxx b/Modules/Compatibility/Deprecated/src/itkBarrier.cxx deleted file mode 100644 index be060f518a4..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkBarrier.cxx +++ /dev/null @@ -1,52 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -#include "itkBarrier.h" - -namespace itk -{ -Barrier::Barrier() = default; - -Barrier::~Barrier() = default; - -void -Barrier::Initialize(unsigned int n) -{ - m_NumberExpected = n; -} - -void -Barrier::Wait() -{ - std::unique_lock lockHolder{ m_Mutex }; - unsigned int lGeneration = m_Generation; - ++m_NumberArrived; - if (m_NumberArrived == m_NumberExpected) - { - // Clear all blocked threads - ++m_Generation; - m_NumberArrived = 0; - m_ConditionVariable.notify_all(); - } - else - { - // Block this thread - m_ConditionVariable.wait(lockHolder, [this, lGeneration] { return lGeneration != m_Generation; }); - } -} - -} // end namespace itk diff --git a/Modules/Compatibility/Deprecated/src/itkConditionVariablePThreads.cxx b/Modules/Compatibility/Deprecated/src/itkConditionVariablePThreads.cxx deleted file mode 100644 index 256c21a1fb2..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkConditionVariablePThreads.cxx +++ /dev/null @@ -1,49 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -#include "itkConditionVariable.h" - -namespace itk -{ -ConditionVariable::ConditionVariable() -{ - pthread_cond_init(&m_ConditionVariable.m_ConditionVariable, nullptr); -} - -ConditionVariable::~ConditionVariable() -{ - pthread_cond_destroy(&m_ConditionVariable.m_ConditionVariable); -} - -void -ConditionVariable::Signal() -{ - pthread_cond_signal(&m_ConditionVariable.m_ConditionVariable); -} - -void -ConditionVariable::Broadcast() -{ - pthread_cond_broadcast(&m_ConditionVariable.m_ConditionVariable); -} - -void -ConditionVariable::Wait(SimpleMutexLock * mutex) -{ - pthread_cond_wait(&m_ConditionVariable.m_ConditionVariable, &mutex->GetMutexLock()); -} -} // end of namespace itk diff --git a/Modules/Compatibility/Deprecated/src/itkConditionVariableWinThreads.cxx b/Modules/Compatibility/Deprecated/src/itkConditionVariableWinThreads.cxx deleted file mode 100644 index 5b8d44cbb3a..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkConditionVariableWinThreads.cxx +++ /dev/null @@ -1,134 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -#include "itkConditionVariable.h" - -namespace itk -{ -ConditionVariable::ConditionVariable() -{ - m_ConditionVariable.m_NumberOfWaiters = 0; - m_ConditionVariable.m_WasBroadcast = 0; - m_ConditionVariable.m_Semaphore = CreateSemaphore(nullptr, // no security - 0, // initial value - 0x7fffffff, // max count - nullptr); // unnamed - InitializeCriticalSection(&m_ConditionVariable.m_NumberOfWaitersLock); - m_ConditionVariable.m_WaitersAreDone = CreateEvent(nullptr, // no security - FALSE, // auto-reset - FALSE, // non-signaled initially - nullptr); // unnamed -} - -ConditionVariable::~ConditionVariable() -{ - CloseHandle(m_ConditionVariable.m_Semaphore); - CloseHandle(m_ConditionVariable.m_WaitersAreDone); - DeleteCriticalSection(&m_ConditionVariable.m_NumberOfWaitersLock); -} - -void -ConditionVariable::Signal() -{ - EnterCriticalSection(&m_ConditionVariable.m_NumberOfWaitersLock); - bool haveWaiters = (m_ConditionVariable.m_NumberOfWaiters > 0); - LeaveCriticalSection(&m_ConditionVariable.m_NumberOfWaitersLock); - - // if there were not any waiters, then this is a no-op - if (haveWaiters) - { - ReleaseSemaphore(m_ConditionVariable.m_Semaphore, 1, 0); - } -} - -void -ConditionVariable::Broadcast() -{ - // This is needed to ensure that m_NumberOfWaiters and m_WasBroadcast are - // consistent - EnterCriticalSection(&m_ConditionVariable.m_NumberOfWaitersLock); - bool haveWaiters = false; - - if (m_ConditionVariable.m_NumberOfWaiters > 0) - { - // We are broadcasting, even if there is just one waiter... - // Record that we are broadcasting, which helps optimize Wait() - // for the non-broadcast case - m_ConditionVariable.m_WasBroadcast = 1; - haveWaiters = true; - } - - if (haveWaiters) - { - // Wake up all waiters atomically - ReleaseSemaphore(m_ConditionVariable.m_Semaphore, m_ConditionVariable.m_NumberOfWaiters, 0); - - LeaveCriticalSection(&m_ConditionVariable.m_NumberOfWaitersLock); - - // Wait for all the awakened threads to acquire the counting - // semaphore - WaitForSingleObject(m_ConditionVariable.m_WaitersAreDone, INFINITE); - // This assignment is ok, even without the m_NumberOfWaitersLock held - // because no other waiter threads can wake up to access it. - m_ConditionVariable.m_WasBroadcast = 0; - } - else - { - LeaveCriticalSection(&m_ConditionVariable.m_NumberOfWaitersLock); - } -} - -void -ConditionVariable::Wait(SimpleMutexLock * mutex) -{ - // Avoid race conditions - EnterCriticalSection(&m_ConditionVariable.m_NumberOfWaitersLock); - m_ConditionVariable.m_NumberOfWaiters++; - LeaveCriticalSection(&m_ConditionVariable.m_NumberOfWaitersLock); - - // This call atomically releases the mutex and waits on the - // semaphore until signaled - SignalObjectAndWait(mutex->GetMutexLock(), m_ConditionVariable.m_Semaphore, INFINITE, FALSE); - - // Reacquire lock to avoid race conditions - EnterCriticalSection(&m_ConditionVariable.m_NumberOfWaitersLock); - - // We're no longer waiting.... - m_ConditionVariable.m_NumberOfWaiters--; - - // Check to see if we're the last waiter after the broadcast - int lastWaiter = m_ConditionVariable.m_WasBroadcast && m_ConditionVariable.m_NumberOfWaiters == 0; - - LeaveCriticalSection(&m_ConditionVariable.m_NumberOfWaitersLock); - - // If we're the last waiter thread during this particular broadcast - // then let the other threads proceed - if (lastWaiter) - { - // This call atomically signals the m_WaitersAreDone event and waits - // until it can acquire the external mutex. This is required to - // ensure fairness - SignalObjectAndWait(m_ConditionVariable.m_WaitersAreDone, mutex->GetMutexLock(), INFINITE, FALSE); - } - else - { - // Always regain the external mutex since that's the guarantee we - // give to our callers - WaitForSingleObject(mutex->GetMutexLock(), INFINITE); - } -} -} // end of namespace itk diff --git a/Modules/Compatibility/Deprecated/src/itkConditionVariableNoThreads.cxx b/Modules/Compatibility/Deprecated/src/itkDeprecatedPlaceholder.cxx similarity index 72% rename from Modules/Compatibility/Deprecated/src/itkConditionVariableNoThreads.cxx rename to Modules/Compatibility/Deprecated/src/itkDeprecatedPlaceholder.cxx index 47b38546337..a5495d910de 100644 --- a/Modules/Compatibility/Deprecated/src/itkConditionVariableNoThreads.cxx +++ b/Modules/Compatibility/Deprecated/src/itkDeprecatedPlaceholder.cxx @@ -15,23 +15,14 @@ * limitations under the License. * *=========================================================================*/ -#include "itkConditionVariable.h" +#include +#include -namespace itk +// This small placeholder is needed to retain the +// infrastructure for future deprecated code +// in ITKv6 +std::string +dummy_deprecated_function_placeholder() { -ConditionVariable::ConditionVariable() {} - -ConditionVariable::~ConditionVariable() {} - -void -ConditionVariable::Signal() -{} - -void -ConditionVariable::Broadcast() -{} - -void -ConditionVariable::Wait(SimpleMutexLock *) -{} -} // end of namespace itk + return std::string(ITK_VERSION_STRING); +} diff --git a/Modules/Compatibility/Deprecated/src/itkFastMutexLock.cxx b/Modules/Compatibility/Deprecated/src/itkFastMutexLock.cxx deleted file mode 100644 index a187852c503..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkFastMutexLock.cxx +++ /dev/null @@ -1,37 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#include "itkFastMutexLock.h" - -namespace itk -{ -void -FastMutexLock::PrintSelf(std::ostream & os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} -} // end namespace itk diff --git a/Modules/Compatibility/Deprecated/src/itkMutexLock.cxx b/Modules/Compatibility/Deprecated/src/itkMutexLock.cxx deleted file mode 100644 index f219a2fe253..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkMutexLock.cxx +++ /dev/null @@ -1,52 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#include "itkMutexLock.h" - -#if defined(ITK_USE_PTHREADS) -# include "itkMutexLockPThreads.cxx" -#elif defined(ITK_USE_WIN32_THREADS) -# include "itkMutexLockWinThreads.cxx" -#else -# include "itkMutexLockNoThreads.cxx" -#endif - -namespace itk -{ -// New for the SimpleMutex -SimpleMutexLock * -SimpleMutexLock::New() -{ - return new SimpleMutexLock; -} - -void -MutexLock::PrintSelf(std::ostream & os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} -} // end namespace itk diff --git a/Modules/Compatibility/Deprecated/src/itkMutexLockNoThreads.cxx b/Modules/Compatibility/Deprecated/src/itkMutexLockNoThreads.cxx deleted file mode 100644 index d927d199d4a..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkMutexLockNoThreads.cxx +++ /dev/null @@ -1,56 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#include "itkMutexLock.h" - -namespace itk -{ - -// Construct a new MutexLock -SimpleMutexLock::SimpleMutexLock() {} - -// Destruct the MutexVariable -SimpleMutexLock::~SimpleMutexLock() {} - -// Lock the MutexLock -void -SimpleMutexLock::Lock() -{} - -// Lock the MutexLock -bool -SimpleMutexLock::TryLock() -{ - return true; -} - -// Unlock the MutexLock -void -SimpleMutexLock::Unlock() -{} - -} // end namespace itk diff --git a/Modules/Compatibility/Deprecated/src/itkMutexLockPThreads.cxx b/Modules/Compatibility/Deprecated/src/itkMutexLockPThreads.cxx deleted file mode 100644 index c82acf7b2e0..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkMutexLockPThreads.cxx +++ /dev/null @@ -1,71 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#include "itkMutexLock.h" - -namespace itk -{ -// Construct a new MutexLock -SimpleMutexLock::SimpleMutexLock() -{ - pthread_mutex_init(&m_MutexLock, nullptr); -} - -// Destruct the MutexVariable -SimpleMutexLock::~SimpleMutexLock() -{ - pthread_mutex_destroy(&m_MutexLock); -} - -// Lock the MutexLock -void -SimpleMutexLock::Lock() -{ - pthread_mutex_lock(&m_MutexLock); -} -// -// Lock the MutexLock -bool -SimpleMutexLock::TryLock() -{ - const bool lockCaptured = (pthread_mutex_trylock(&m_MutexLock) == 0); - /* - * non-blocking lock of mutex - * - if mutex is not already locked, you will obtain the lock & own the mutex, and return 0 immediately - * - if mutex is already locked, pthread_mutex_trylock() will return immediately wth return value EBUSY - */ - return lockCaptured; -} - -// Unlock the MutexLock -void -SimpleMutexLock::Unlock() -{ - pthread_mutex_unlock(&m_MutexLock); -} - -} // end namespace itk diff --git a/Modules/Compatibility/Deprecated/src/itkMutexLockWinThreads.cxx b/Modules/Compatibility/Deprecated/src/itkMutexLockWinThreads.cxx deleted file mode 100644 index eda0ad98c4a..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkMutexLockWinThreads.cxx +++ /dev/null @@ -1,72 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#include "itkMutexLock.h" - -namespace itk -{ - -// Construct a new MutexLock -SimpleMutexLock::SimpleMutexLock() -{ - m_MutexLock = CreateMutex(nullptr, FALSE, nullptr); -} - -// Destruct the MutexVariable -SimpleMutexLock::~SimpleMutexLock() -{ - CloseHandle(m_MutexLock); -} - -// Lock the MutexLock -void -SimpleMutexLock::Lock() -{ - WaitForSingleObject(m_MutexLock, INFINITE); -} - -// Lock the MutexLock -bool -SimpleMutexLock::TryLock() -{ - const bool lockCaptured = (WaitForSingleObject(m_MutexLock, 1) == WAIT_OBJECT_0); - /* - * non-blocking lock of mutex - * - if mutex is not already locked, you will obtain the lock & own the mutex, and return 0 immediately - * - if mutex is already locked, pthread_mutex_trylock() will return immediately wth return value EBUSY - */ - return lockCaptured; -} - -// Unlock the MutexLock -void -SimpleMutexLock::Unlock() -{ - ReleaseMutex(m_MutexLock); -} - -} // end namespace itk diff --git a/Modules/Compatibility/Deprecated/src/itkSimpleFastMutexLock.cxx b/Modules/Compatibility/Deprecated/src/itkSimpleFastMutexLock.cxx deleted file mode 100644 index 20a124fde9d..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkSimpleFastMutexLock.cxx +++ /dev/null @@ -1,36 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#include "itkSimpleFastMutexLock.h" - -#if defined(ITK_USE_PTHREADS) -# include "itkSimpleFastMutexLockPThreads.cxx" -#elif defined(ITK_USE_WIN32_THREADS) -# include "itkSimpleFastMutexLockWinThreads.cxx" -#else -# include "itkSimpleFastMutexLockNoThreads.cxx" -#endif diff --git a/Modules/Compatibility/Deprecated/src/itkSimpleFastMutexLockNoThreads.cxx b/Modules/Compatibility/Deprecated/src/itkSimpleFastMutexLockNoThreads.cxx deleted file mode 100644 index 9738a0e3b0d..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkSimpleFastMutexLockNoThreads.cxx +++ /dev/null @@ -1,54 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#include "itkSimpleFastMutexLock.h" - -namespace itk -{ -// Construct a new SimpleMutexLock -SimpleFastMutexLock::SimpleFastMutexLock() {} - -// Destruct the SimpleMutexVariable -SimpleFastMutexLock::~SimpleFastMutexLock() {} - -// Lock the FastMutexLock -void -SimpleFastMutexLock::Lock() const -{} - -// Non-blocking TryLock the FastMutexLock -bool -SimpleFastMutexLock::TryLock() const -{ - return true; -} - -// Unlock the FastMutexLock -void -SimpleFastMutexLock::Unlock() const -{} -} // end namespace itk diff --git a/Modules/Compatibility/Deprecated/src/itkSimpleFastMutexLockPThreads.cxx b/Modules/Compatibility/Deprecated/src/itkSimpleFastMutexLockPThreads.cxx deleted file mode 100644 index 63ab4144334..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkSimpleFastMutexLockPThreads.cxx +++ /dev/null @@ -1,73 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#include "itkSimpleFastMutexLock.h" - -namespace itk -{ -// Construct a new SimpleMutexLock -SimpleFastMutexLock::SimpleFastMutexLock() -{ - pthread_mutexattr_t mta; - pthread_mutexattr_init(&mta); - pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&(m_FastMutexLock), &mta); -} - -// Destruct the SimpleMutexVariable -SimpleFastMutexLock::~SimpleFastMutexLock() -{ - pthread_mutex_destroy(&m_FastMutexLock); -} - -// Lock the FastMutexLock -void -SimpleFastMutexLock::Lock() const -{ - pthread_mutex_lock(&m_FastMutexLock); -} - -// Non-blocking TryLock the FastMutexLock -bool -SimpleFastMutexLock::TryLock() const -{ - const bool lockCaptured = (pthread_mutex_trylock(&m_FastMutexLock) == 0); - /* - * non-blocking lock of mutex - * - if mutex is not already locked, you will obtain the lock & own the mutex, and return 0 immediately - * - if mutex is already locked, pthread_mutex_trylock() will return immediately wth return value EBUSY - */ - return lockCaptured; -} - -// Unlock the FastMutexLock -void -SimpleFastMutexLock::Unlock() const -{ - pthread_mutex_unlock(&m_FastMutexLock); -} -} // end namespace itk diff --git a/Modules/Compatibility/Deprecated/src/itkSimpleFastMutexLockWinThreads.cxx b/Modules/Compatibility/Deprecated/src/itkSimpleFastMutexLockWinThreads.cxx deleted file mode 100644 index bc0031ba377..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkSimpleFastMutexLockWinThreads.cxx +++ /dev/null @@ -1,71 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#include "itkSimpleFastMutexLock.h" - -namespace itk -{ -// Construct a new SimpleMutexLock -SimpleFastMutexLock::SimpleFastMutexLock() -{ - // this->MutexLock = CreateMutex( nullptr, FALSE, nullptr ); - InitializeCriticalSection(&m_FastMutexLock); -} - -// Destruct the SimpleMutexVariable -SimpleFastMutexLock::~SimpleFastMutexLock() -{ - DeleteCriticalSection(&m_FastMutexLock); -} - -// Lock the FastMutexLock -void -SimpleFastMutexLock::Lock() const -{ - EnterCriticalSection(&m_FastMutexLock); -} - -// Non-blocking TryLock the FastMutexLock -bool -SimpleFastMutexLock::TryLock() const -{ - const bool lockCaptured = TryEnterCriticalSection(&m_FastMutexLock); - /* - * non-blocking lock of mutex - * - if mutex is not already locked, you will obtain the lock & own the mutex, and return non-zero immediately - * - if mutex is already locked, TryEnterCriticalSection() will return immediately wth return value 0 - */ - return lockCaptured; -} - -// Unlock the FastMutexLock -void -SimpleFastMutexLock::Unlock() const -{ - LeaveCriticalSection(&m_FastMutexLock); -} -} // end namespace itk diff --git a/Modules/Compatibility/Deprecated/src/itkTreeIteratorBase.cxx b/Modules/Compatibility/Deprecated/src/itkTreeIteratorBase.cxx deleted file mode 100644 index 71cd66aec34..00000000000 --- a/Modules/Compatibility/Deprecated/src/itkTreeIteratorBase.cxx +++ /dev/null @@ -1,50 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -#include "itkTreeIteratorBase.h" - -namespace itk -{ -/** Print enum values */ -std::ostream & -operator<<(std::ostream & out, const TreeIteratorBaseEnums::TreeIteratorBaseNode value) -{ - return out << [value] { - switch (value) - { - case TreeIteratorBaseEnums::TreeIteratorBaseNode::UNDEFIND: - return "itk::TreeIteratorBaseEnums::TreeIteratorBaseNode::UNDEFIND"; - case TreeIteratorBaseEnums::TreeIteratorBaseNode::PREORDER: - return "itk::TreeIteratorBaseEnums::TreeIteratorBaseNode::PREORDER"; - case TreeIteratorBaseEnums::TreeIteratorBaseNode::INORDER: - return "itk::TreeIteratorBaseEnums::TreeIteratorBaseNode::INORDER"; - case TreeIteratorBaseEnums::TreeIteratorBaseNode::POSTORDER: - return "itk::TreeIteratorBaseEnums::TreeIteratorBaseNode::POSTORDER"; - case TreeIteratorBaseEnums::TreeIteratorBaseNode::LEVELORDER: - return "itk::TreeIteratorBaseEnums::TreeIteratorBaseNode::LEVELORDER"; - case TreeIteratorBaseEnums::TreeIteratorBaseNode::CHILD: - return "itk::TreeIteratorBaseEnums::TreeIteratorBaseNode::CHILD"; - case TreeIteratorBaseEnums::TreeIteratorBaseNode::ROOT: - return "itk::TreeIteratorBaseEnums::TreeIteratorBaseNode::ROOT"; - case TreeIteratorBaseEnums::TreeIteratorBaseNode::LEAF: - return "itk::TreeIteratorBaseEnums::TreeIteratorBaseNode::LEAF"; - default: - return "INVALID VALUE FOR itk::TreeIteratorBaseEnums::TreeIteratorBaseNode"; - } - }(); -} -} // end namespace itk diff --git a/Modules/Compatibility/Deprecated/test/CMakeLists.txt b/Modules/Compatibility/Deprecated/test/CMakeLists.txt index 955cc632658..63a371a36c1 100644 --- a/Modules/Compatibility/Deprecated/test/CMakeLists.txt +++ b/Modules/Compatibility/Deprecated/test/CMakeLists.txt @@ -1,98 +1,9 @@ -itk_module_test() -set(ITKDeprecatedTests - itkAtomicIntTest.cxx - itkBarrierTest.cxx - itkConditionVariableTest.cxx - itkSimpleFastMutexLockTest.cxx - itkVectorCentralDifferenceImageFunctionTest.cxx - itkVectorResampleImageFilterTest.cxx - itkTreeContainerTest.cxx - itkTreeContainerTest2.cxx) +#Placeholder for future deprecated tests +#itk_module_test() +#set(ITKDeprecatedTests +# ) -if(NOT ITK_LEGACY_REMOVE) - list(APPEND ITKDeprecatedTests itkSpawnThreadTest.cxx) -endif() +#createtestdriver(ITKDeprecated "${ITKDeprecated-Test_LIBRARIES}" "${ITKDeprecatedTests}") -createtestdriver(ITKDeprecated "${ITKDeprecated-Test_LIBRARIES}" "${ITKDeprecatedTests}") - -set(BASELINE "${ITK_DATA_ROOT}/Baseline/Common") -set(TEMP ${ITK_TEST_OUTPUT_DIR}) - -itk_add_test( - NAME - itkAtomicIntTest - COMMAND - ITKDeprecatedTestDriver - itkAtomicIntTest) - -if(NOT MINGW) - itk_add_test( - NAME - itkBarrierTest - COMMAND - ITKDeprecatedTestDriver - itkBarrierTest) - itk_add_test( - NAME - itkBarrierTest107 - COMMAND - ITKDeprecatedTestDriver - itkBarrierTest - 107) - itk_add_test( - NAME - itkConditionVariableTest - COMMAND - ITKDeprecatedTestDriver - itkConditionVariableTest) -endif() - -itk_add_test( - NAME - itkSimpleFastMutexLockTest - COMMAND - ITKDeprecatedTestDriver - itkSimpleFastMutexLockTest) -# short timeout because failing test will hang and test is quite small -set_tests_properties(itkSimpleFastMutexLockTest PROPERTIES TIMEOUT 60) - -if(NOT ITK_LEGACY_REMOVE) - itk_add_test( - NAME - itkSpawnThreadTest - COMMAND - ITKDeprecatedTestDriver - itkSpawnThreadTest - 100) -endif() - -itk_add_test( - NAME - itkVectorCentralDifferenceImageFunctionTest - COMMAND - ITKDeprecatedTestDriver - itkVectorCentralDifferenceImageFunctionTest) - -itk_add_test( - NAME - itkVectorResampleImageFilterTest - COMMAND - ITKDeprecatedTestDriver - --compare - DATA{${ITK_DATA_ROOT}/Baseline/BasicFilters/VectorResampleImageFilterTest.png} - ${ITK_TEST_OUTPUT_DIR}/VectorResampleImageFilterTest.png - itkVectorResampleImageFilterTest - ${ITK_TEST_OUTPUT_DIR}/VectorResampleImageFilterTest.png) - -itk_add_test( - NAME - itkTreeContainerTest - COMMAND - ITKDeprecatedTestDriver - itkTreeContainerTest) -itk_add_test( - NAME - itkTreeContainerTest2 - COMMAND - ITKDeprecatedTestDriver - itkTreeContainerTest2) +#set(BASELINE "${ITK_DATA_ROOT}/Baseline/Common") +#set(TEMP ${ITK_TEST_OUTPUT_DIR}) diff --git a/Modules/Compatibility/Deprecated/test/itkAtomicIntTest.cxx b/Modules/Compatibility/Deprecated/test/itkAtomicIntTest.cxx deleted file mode 100644 index 88f67e6d6a3..00000000000 --- a/Modules/Compatibility/Deprecated/test/itkAtomicIntTest.cxx +++ /dev/null @@ -1,335 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -/*========================================================================= - - Program: Visualization Toolkit - Module: TestAtomic.cxx - - Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - All rights reserved. - See Copyright.txt or https://www.kitware.com/Copyright.htm 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. - -=========================================================================*/ -#include "itkAtomicInt.h" -#include "itkMultiThreaderBase.h" -#include "itkObject.h" -#include - -namespace -{ - -int Total = 0; -itk::uint64_t Total64 = 0; -itk::AtomicInt TotalAtomic(0); -itk::AtomicInt TotalAtomic64(0); -constexpr unsigned int Target = 1000000; -itk::int32_t Values32[Target + 2]; -itk::int64_t Values64[Target + 2]; -itk::AtomicInt AtomicPtr(Values32); -itk::AtomicInt Atomic64Ptr(Values64); - -int NumThreads = 5; - -itk::Object::Pointer AnObject; -} // namespace - - -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -MyFunction(void *) -{ - for (unsigned int i = 0; i < Target / NumThreads; ++i) - { - Total++; - int idx = ++TotalAtomic; - Values32[idx] = 1; - - Total64++; - idx = ++TotalAtomic64; - Values64[idx] = 1; - - AnObject->Modified(); - } - - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} - -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -MyFunction2(void *) -{ - for (unsigned int i = 0; i < Target / NumThreads; ++i) - { - --TotalAtomic; - - --TotalAtomic64; - } - - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} - -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -MyFunction3(void *) -{ - for (unsigned int i = 0; i < Target / NumThreads; ++i) - { - int idx = TotalAtomic += 1; - Values32[idx]++; - - idx = TotalAtomic64 += 1; - Values64[idx]++; - } - - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} - -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -MyFunction4(void *) -{ - for (unsigned int i = 0; i < Target / NumThreads; ++i) - { - TotalAtomic++; - TotalAtomic += 1; - TotalAtomic--; - TotalAtomic -= 1; - - TotalAtomic64++; - TotalAtomic64 += 1; - TotalAtomic64--; - TotalAtomic64 -= 1; - } - - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} - -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -MyFunctionPtr(void *) -{ - for (unsigned int i = 0; i < Target / NumThreads; ++i) - { - itk::int32_t * ptr32 = ++AtomicPtr; - (*ptr32) = 1; - - itk::int64_t * ptr64 = ++Atomic64Ptr; - (*ptr64) = 1; - } - - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} - -template -int -TestAtomicOperators(std::string name) -{ - itk::AtomicInt testAtomic(1); - if (testAtomic != 1) - { - std::cout << "Expecting testAtomic" << name << " value to be 1. Got " << testAtomic << std::endl; - return 1; - } - testAtomic = 2; - if (testAtomic != 2) - { - std::cout << "Expecting testAtomic" << name << " value to be 2. Got " << testAtomic << std::endl; - return 1; - } - itk::AtomicInt testAtomicCopy(3); - testAtomic = testAtomicCopy; - if (testAtomic != 3) - { - std::cout << "Expecting testAtomic" << name << " value to be 3. Got " << testAtomic << std::endl; - return 1; - } - if (testAtomic.load() != 3) - { - std::cout << "Expecting testAtomic" << name << ".load() value to be 3. Got " << testAtomic.load() << std::endl; - return 1; - } - testAtomic.store(0); - if (testAtomic != 0) - { - std::cout << "Expecting testAtomic" << name << " value to be 0. Got " << testAtomic << std::endl; - return 1; - } - T preinc_val = ++testAtomic; - if (preinc_val != 1) - { - std::cout << "Expecting PreIncrement (" << name << ") value to be 1. Got " << preinc_val << std::endl; - return 1; - } - T postinc_val = testAtomic++; - if (postinc_val != 1) - { - std::cout << "Expecting PostIncrement (" << name << ") value to be 1. Got " << postinc_val << std::endl; - return 1; - } - T predec_val = --testAtomic; - if (predec_val != 1) - { - std::cout << "Expecting PreDecrement (" << name << ") value to be 1. Got " << predec_val << std::endl; - return 1; - } - T postdec_val = testAtomic--; - if (postdec_val != 1) - { - std::cout << "Expecting PostDecrement (" << name << ") value to be 1. Got " << postdec_val << std::endl; - return 1; - } - testAtomic += 2; - T addAndFetch_val = testAtomic; - if (addAndFetch_val != 2) - { - std::cout << "Expecting AddAndFetch (" << name << ") value to be 2. Got " << addAndFetch_val << std::endl; - return 1; - } - testAtomic -= 1; - T subAndFetch_val = testAtomic; - if (subAndFetch_val != 1) - { - std::cout << "Expecting SubAndFetch (" << name << ") value to be 1. Got " << subAndFetch_val << std::endl; - return 1; - } - return 0; -} - -int -itkAtomicIntTest(int, char *[]) -{ - // Verify all atomic operators - if (TestAtomicOperators("32") || TestAtomicOperators("64")) - { - return 1; - } - // Verify atomic behavior - Total = 0; - TotalAtomic = 0; - Total64 = 0; - TotalAtomic64 = 0; - - for (unsigned int i = 0; i < Target; ++i) - { - Values32[i] = 0; - Values64[i] = 0; - } - - itk::MultiThreaderBase::Pointer mt = itk::MultiThreaderBase::New(); - // depending on which multi-threader is instantiated by default, - // there might be different number of object modification times - // so the "initial" Mtime is recorder afterwards - AnObject = itk::Object::New(); - itk::ModifiedTimeType beforeMTime = AnObject->GetMTime(); - - mt->SetSingleMethod(MyFunction, nullptr); - mt->SetNumberOfWorkUnits(NumThreads); - mt->SingleMethodExecute(); - - mt->SetSingleMethod(MyFunction2, nullptr); - mt->SingleMethodExecute(); - - mt->SetSingleMethod(MyFunction3, nullptr); - mt->SingleMethodExecute(); - - // Making sure that atomic incr returned unique - // values each time. We expect all numbers from - // 1 to Target-1 to be 2. - if (Values32[0] != 0) - { - std::cout << "Expecting Values32[0] to be 0. Got " << Values32[0] << std::endl; - return 1; - } - if (Values64[0] != 0) - { - std::cout << "Expecting Values64[0] to be 0. Got " << Values64[0] << std::endl; - return 1; - } - for (unsigned int i = 1; i < Target; ++i) - { - if (Values32[i] != 2) - { - std::cout << "Expecting Values32[" << i << "] to be 2. Got " << Values32[i] << std::endl; - return 1; - } - if (Values64[i] != 2) - { - std::cout << "Expecting Values64[" << i << "] to be 2. Got " << Values64[i] << std::endl; - return 1; - } - } - - mt->SetSingleMethod(MyFunction4, nullptr); - mt->SingleMethodExecute(); - - std::cout << Total << ' ' << TotalAtomic.load() << std::endl; - std::cout << Total64 << ' ' << TotalAtomic64.load() << std::endl; - - std::cout << "MTime: " << AnObject->GetMTime() << std::endl; - - mt->SetSingleMethod(MyFunctionPtr, nullptr); - mt->SingleMethodExecute(); - - // Making sure that pointer atomic incr returned unique - // values each time incremented by the size of the pointer. - // We expect all numbers from 1 to Target-1 to be 1. - if (Values32[0] != 0) - { - std::cout << "Expecting Values32[0] to be 0. Got " << Values32[0] << std::endl; - return 1; - } - if (Values64[0] != 0) - { - std::cout << "Expecting Values64[0] to be 0. Got " << Values64[0] << std::endl; - return 1; - } - for (unsigned int i = 1; i < Target; ++i) - { - if (Values32[i] != 1) - { - std::cout << "Expecting Values32[" << i << "] to be 1. Got " << Values32[i] << std::endl; - return 1; - } - if (Values64[i] != 1) - { - std::cout << "Expecting Values64[" << i << "] to be 1. Got " << Values64[i] << std::endl; - return 1; - } - } - - if (TotalAtomic.load() != static_cast(Target)) - { - return 1; - } - - if (TotalAtomic64.load() != static_cast(Target)) - { - return 1; - } - - if (AnObject->GetReferenceCount() != 1) - { - return 1; - } - - if (AnObject->GetMTime() != Target + beforeMTime) - { - return 1; - } - - return 0; -} diff --git a/Modules/Compatibility/Deprecated/test/itkBarrierTest.cxx b/Modules/Compatibility/Deprecated/test/itkBarrierTest.cxx deleted file mode 100644 index 4675a567e3e..00000000000 --- a/Modules/Compatibility/Deprecated/test/itkBarrierTest.cxx +++ /dev/null @@ -1,178 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ - -#include "itkBarrier.h" -#include "itkMultiThreaderBase.h" -#include "itkTestingMacros.h" - - -class BarrierTestUserData -{ -public: - itk::Barrier::Pointer m_FirstBarrier; - itk::Barrier::Pointer m_SecondBarrier; - unsigned int m_Counter[itk::ITK_MAX_THREADS]; - unsigned int m_NumberOfIterations; - unsigned int m_NumberOfWorkUnits; - bool m_TestFailure; - - BarrierTestUserData(unsigned int number_of_threads) - { - m_TestFailure = false; - m_NumberOfWorkUnits = number_of_threads; - for (unsigned int i = 0; i < number_of_threads - 1; ++i) - { - m_Counter[i] = 0; - } - m_NumberOfIterations = 50; - m_FirstBarrier = itk::Barrier::New(); - m_SecondBarrier = itk::Barrier::New(); - m_FirstBarrier->Initialize(number_of_threads); - m_SecondBarrier->Initialize(number_of_threads); - } - ~BarrierTestUserData() = default; -}; - -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -BarrierTestIncrement(void * ptr) -{ - itk::ThreadIdType threadId = ((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->WorkUnitID; - auto * data = static_cast(((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->UserData); - - for (unsigned int i = 0; i < data->m_NumberOfIterations; ++i) - { - // set the value for this iteration - data->m_Counter[threadId] = i; - - // wait for all the other threads - data->m_FirstBarrier->Wait(); - data->m_SecondBarrier->Wait(); - } - - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} - -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -BarrierCheckIncrement(void * ptr) -{ - auto * data = static_cast(((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->UserData); - - for (unsigned int i = 0; i < data->m_NumberOfIterations; ++i) - { - // Wait for other threads to populate the m_Counter array - data->m_FirstBarrier->Wait(); - - // Check the values in the m_Counter array - for (unsigned int j = 0; j < data->m_NumberOfWorkUnits - 1; ++j) - { - if (data->m_Counter[j] != i) - { - data->m_TestFailure = true; - } - } - data->m_SecondBarrier->Wait(); - } - - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} - -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -BarrierTestCallback(void * ptr) -{ - itk::ThreadIdType threadId = ((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->WorkUnitID; - auto * data = static_cast(((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->UserData); - - if (threadId == data->m_NumberOfWorkUnits - 1) - { - BarrierCheckIncrement(ptr); - } - else - { - BarrierTestIncrement(ptr); - } - - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} - -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -BarrierSpecialTest(void * ptr) -{ - auto * data = static_cast(((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->UserData); - - for (unsigned int j = 0; j < 1000; ++j) - { - data->m_FirstBarrier->Wait(); - } - - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} - -int -itkBarrierTest(int argc, char * argv[]) -{ - itk::Barrier::Pointer barrier = itk::Barrier::New(); - ITK_EXERCISE_BASIC_OBJECT_METHODS(barrier, Barrier, LightObject); - - itk::ThreadIdType number_of_threads = 4; - if (argc > 1) - { - number_of_threads = std::stoi(argv[1]); - } - - BarrierTestUserData data(number_of_threads); - - try - { - itk::MultiThreaderBase::Pointer multithreader = itk::MultiThreaderBase::New(); - multithreader->SetMaximumNumberOfThreads(number_of_threads); - if (multithreader->GetMaximumNumberOfThreads() < number_of_threads) - { - std::cerr << "Could not increase number of threads to " << number_of_threads << " in " - << multithreader->GetNameOfClass() << std::endl; - return EXIT_FAILURE; - } - - multithreader->SetNumberOfWorkUnits(number_of_threads); - multithreader->SetSingleMethod(BarrierTestCallback, &data); - - for (unsigned int i = 0; i < 5; ++i) // repeat test 5 times - { - multithreader->SingleMethodExecute(); - } - - // perform another test - multithreader->SetSingleMethod(BarrierSpecialTest, &data); - multithreader->SingleMethodExecute(); - } - catch (const itk::ExceptionObject & e) - { - std::cerr << e << std::endl; - return EXIT_FAILURE; - } - - if (data.m_TestFailure == false) - { - std::cout << "[TEST PASSED]" << std::endl; - return EXIT_SUCCESS; - } - else - { - std::cout << "[TEST FAILED]" << std::endl; - return 2; - } -} diff --git a/Modules/Compatibility/Deprecated/test/itkConditionVariableTest.cxx b/Modules/Compatibility/Deprecated/test/itkConditionVariableTest.cxx deleted file mode 100644 index f8acf6ad9c6..00000000000 --- a/Modules/Compatibility/Deprecated/test/itkConditionVariableTest.cxx +++ /dev/null @@ -1,131 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ - -#include -#include "itkConditionVariable.h" -#include "itkPlatformMultiThreader.h" - -class ConditionVariableTestUserData -{ -public: - itk::SimpleMutexLock m_Mutex; - itk::ConditionVariable::Pointer m_ConditionVariable; - unsigned int m_Counter; - unsigned int m_CountLimit; - - ConditionVariableTestUserData() - { - m_ConditionVariable = itk::ConditionVariable::New(); - m_Counter = 0; - m_CountLimit = 12; - } - ~ConditionVariableTestUserData() = default; -}; - - -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -ConditionVariableTestIncCount(void * ptr) -{ - auto * data = static_cast(((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->UserData); - - double v = 400.0; - - for (unsigned int i = 0; i < 10; ++i) - { - data->m_Mutex.Lock(); - data->m_Counter++; - // Check the value of count. If the condition has been reached, signal - // waiting threads. - if (data->m_Counter == data->m_CountLimit) - { - // data->m_ConditionVariable->Signal(); - // Tests both Broadcast and Signal - data->m_ConditionVariable->Broadcast(); - } - - data->m_Mutex.Unlock(); - - // Do some work here. - for (unsigned int j = 0; j < 1000; ++j) - { - v = v / 2.4; - v = v * 2.4; - } - } - - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} - -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -ConditionVariableTestWatchCount(void * ptr) -{ - auto * data = static_cast(((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->UserData); - - // Lock the mutex and wait for the signal. - data->m_Mutex.Lock(); - while (data->m_Counter < data->m_CountLimit) - { - data->m_ConditionVariable->Wait(&data->m_Mutex); - } - data->m_Mutex.Unlock(); - - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} - -ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION -ConditionVariableTestCallback(void * ptr) -{ - itk::ThreadIdType threadId = ((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->WorkUnitID; - - if (threadId == 0) - { - ConditionVariableTestWatchCount(ptr); - } - else - { - ConditionVariableTestIncCount(ptr); - } - return ITK_THREAD_RETURN_DEFAULT_VALUE; -} - -int -itkConditionVariableTest(int, char *[]) -{ - ConditionVariableTestUserData cond; - - try - { - itk::PlatformMultiThreader::Pointer multithreader = itk::PlatformMultiThreader::New(); - multithreader->SetNumberOfWorkUnits(3); - multithreader->SetSingleMethod(ConditionVariableTestCallback, &cond); - - for (unsigned int i = 0; i < 1000; ++i) - { - cond.m_Counter = 0; - multithreader->SingleMethodExecute(); - } - } - catch (const itk::ExceptionObject & e) - { - std::cerr << e << std::endl; - return 2; - } - - std::cout << "[TEST PASSED]" << std::endl; - return EXIT_SUCCESS; -} diff --git a/Modules/Compatibility/Deprecated/test/itkSimpleFastMutexLockTest.cxx b/Modules/Compatibility/Deprecated/test/itkSimpleFastMutexLockTest.cxx deleted file mode 100644 index c797b687b9b..00000000000 --- a/Modules/Compatibility/Deprecated/test/itkSimpleFastMutexLockTest.cxx +++ /dev/null @@ -1,67 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ - - -#include "itkSimpleFastMutexLock.h" - -#include // For cout. - - -int -itkSimpleFastMutexLockTest(int, char *[]) -{ - { - itk::SimpleFastMutexLock lock; - - // Acquire the lock - lock.Lock(); - - // Acquire the lock again; as this call happens within the same thread, - // it shouldn't block. - // If the lock isn't recursive, it will block forever and the CTest - // timeout will cause the test to fail. - lock.Lock(); - } - - - { // Test non-blocking version - itk::SimpleFastMutexLock nblock; - nblock.Lock(); - nblock.Unlock(); - const bool testTryLockWhenFree = nblock.TryLock(); - if (testTryLockWhenFree != true) - { - std::cout << "Failed to capture a free lock with TryLock()" << std::endl; - return EXIT_FAILURE; - } - - if (!nblock.TryLock()) - { - std::cout << "Failed to recursively capture a lock with TryLock()" << std::endl; - return EXIT_FAILURE; - } - nblock.Unlock(); - nblock.Lock(); - // Ensure the TryLock() does not cause a deadlock. - // If the lock isn't recursive, it will block forever and the CTest - // timeout will cause the test to fail. - nblock.Unlock(); - } - - return EXIT_SUCCESS; -} diff --git a/Modules/Compatibility/Deprecated/test/itkSpawnThreadTest.cxx b/Modules/Compatibility/Deprecated/test/itkSpawnThreadTest.cxx deleted file mode 100644 index 9fb8edc961e..00000000000 --- a/Modules/Compatibility/Deprecated/test/itkSpawnThreadTest.cxx +++ /dev/null @@ -1,110 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ - -#define ITK_LEGACY_TEST // so deprecation warnings are not triggered by this test -#include "itkPlatformMultiThreader.h" -#include "itkMutexLock.h" -#include "itkTimeProbe.h" -#include "itkConfigure.h" -#include "itksys/SystemTools.hxx" - -struct SharedThreadData -{ - int numberOfLoop; - itk::MutexLock::Pointer sharedMutex; -}; - -void * -ThreadFunction(void * ptr) -{ - // Retrieve shared thread data and user data - auto * workUnitInfo = static_cast(ptr); - itk::ThreadIdType localthreadId = workUnitInfo->WorkUnitID; - auto * localThreadData = static_cast(workUnitInfo->UserData); - int localnumberOfLoop = localThreadData->numberOfLoop; - itk::MutexLock::Pointer localMutex = localThreadData->sharedMutex; - - for (int i = 0; i < localnumberOfLoop; ++i) - { - localMutex->Lock(); - std::cerr << "Thread #" << localthreadId << ":: counter = " << i << std::endl; - localMutex->Unlock(); - } - - localMutex->Lock(); - std::cerr << "Thread #" << localthreadId << " is done." << std::endl; - localMutex->Unlock(); - - return nullptr; -} - -int -itkSpawnThreadTest(int argc, char * argv[]) -{ - int loop = 100; - if (argc > 1) - { - const int nt = std::stoi(argv[1]); - if (nt > 1) - { - loop = nt; - } - } - - itk::PlatformMultiThreader::Pointer threader = itk::PlatformMultiThreader::New(); - itk::MutexLock::Pointer mutexlock = itk::MutexLock::New(); - if (threader.IsNull() || mutexlock.IsNull()) - { - return EXIT_FAILURE; - } - - SharedThreadData threadData; - threadData.numberOfLoop = loop; - threadData.sharedMutex = mutexlock; - - int id1 = threader->SpawnThread((itk::ThreadFunctionType)&ThreadFunction, &threadData); - int id2 = threader->SpawnThread((itk::ThreadFunctionType)&ThreadFunction, &threadData); - int id3 = threader->SpawnThread((itk::ThreadFunctionType)&ThreadFunction, &threadData); - int id4 = threader->SpawnThread((itk::ThreadFunctionType)&ThreadFunction, &threadData); - int id5 = threader->SpawnThread((itk::ThreadFunctionType)&ThreadFunction, &threadData); - int id6 = threader->SpawnThread((itk::ThreadFunctionType)&ThreadFunction, &threadData); - int id7 = threader->SpawnThread((itk::ThreadFunctionType)&ThreadFunction, &threadData); - - for (int i = 0; i < threadData.numberOfLoop; ++i) - { - mutexlock->Lock(); - std::cerr << "Main Thread:: counter = " << i << std::endl; - mutexlock->Unlock(); - } - - mutexlock->Lock(); - std::cerr << "Main Thread is done." << std::endl; - mutexlock->Unlock(); - - // wait for the threads - threader->TerminateThread(id1); - threader->TerminateThread(id2); - threader->TerminateThread(id3); - threader->TerminateThread(id4); - threader->TerminateThread(id5); - threader->TerminateThread(id6); - threader->TerminateThread(id7); - - std::cerr << "All theads are stopped ...." << std::endl; - return EXIT_SUCCESS; -} diff --git a/Modules/Compatibility/Deprecated/test/itkTreeContainerTest.cxx b/Modules/Compatibility/Deprecated/test/itkTreeContainerTest.cxx deleted file mode 100644 index 5a74409c072..00000000000 --- a/Modules/Compatibility/Deprecated/test/itkTreeContainerTest.cxx +++ /dev/null @@ -1,296 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ - -/** - * This is a test file for the itkTreeContainer class. - */ -#include "itkTreeContainer.h" -#include "itkChildTreeIterator.h" -#include "itkLeafTreeIterator.h" -#include "itkLevelOrderTreeIterator.h" -#include "itkInOrderTreeIterator.h" -#include "itkPostOrderTreeIterator.h" -#include "itkRootTreeIterator.h" -#include "itkTreeIteratorClone.h" -#include "itkTestingMacros.h" - -int -itkTreeContainerTest(int, char *[]) -{ - using NodeType = int; - using TreeType = itk::TreeContainer; - auto tree = TreeType::New(); - tree->SetRoot(0); - tree->Add(1, 0); - tree->Add(2, 0); - tree->Add(3, 0); - tree->Add(4, 2); - tree->Add(5, 2); - tree->Add(6, 5); - tree->Add(7, 1); - - unsigned int expectedIndex = 0; - - std::cout << "Testing PrintSelf: " << std::endl; - std::cout << tree << std::endl; - std::cout << "[SUCCESS]" << std::endl; - - // LevelOrderTreeIterator Test - std::cout << "Testing LevelOrderTreeIterator: " << std::endl; - itk::LevelOrderTreeIterator levelIt(tree, 10, tree->GetNode(2)); - levelIt.GoToBegin(); - while (!levelIt.IsAtEnd()) - { - std::cout << levelIt.Get() << " (" << levelIt.GetLevel() << ')' << std::endl; - ++levelIt; - } - - // Test some functionalities of TreeIteratorBase - // IsLeaf() - std::cout << "Testing IsLeaf(): "; - levelIt.GoToBegin(); - if (levelIt.IsLeaf()) - { - std::cout << "[FAILURE]" << std::endl; - return EXIT_FAILURE; - } - std::cout << "[SUCCESS]" << std::endl; - - // IsRoot() - std::cout << "Testing IsRoot(): "; - if (!levelIt.IsRoot()) - { - std::cout << "[FAILURE]" << std::endl; - return EXIT_FAILURE; - } - std::cout << "[SUCCESS]" << std::endl; - - // HasParent() - std::cout << "Testing HasParent(): "; - if (!levelIt.HasParent()) - { - std::cout << "[FAILURE]" << std::endl; - return EXIT_FAILURE; - } - std::cout << "[SUCCESS]" << std::endl; - - // CountChildren() - std::cout << "Testing CountChildren(): "; - if (levelIt.CountChildren() != 2) - { - std::cout << "[FAILURE]" << std::endl; - return EXIT_FAILURE; - } - std::cout << "[SUCCESS]" << std::endl; - - - // ChildTreeIterator Test - std::cout << "Testing ChildTreeIterator: " << std::endl; - NodeType expectedChild[] = { 1, 2, 3 }; - expectedIndex = 0; - itk::ChildTreeIterator childIt(tree); - childIt.GoToBegin(); - while (!childIt.IsAtEnd()) - { - std::cout << childIt.Get() << std::endl; - ITK_TEST_EXPECT_EQUAL(childIt.Get(), expectedChild[expectedIndex]); - ++expectedIndex; - ++childIt; - } - std::cout << std::endl; - - std::cout << "Starting to another branch: " << std::endl; - itk::ChildTreeIterator childIt2(tree, tree->GetNode(2)); - childIt2.GoToBegin(); - while (!childIt2.IsAtEnd()) - { - std::cout << childIt2.Get() << std::endl; - ++childIt2; - } - - childIt2.GoToBegin(); - - std::cout << "Testing other features : "; - - if (childIt2.GetType() != itk::TreeIteratorBaseEnums::TreeIteratorBaseNode::CHILD) - { - std::cout << "[FAILURE]" << std::endl; - return EXIT_FAILURE; - } - - if (!childIt2.GoToParent()) - { - std::cout << "[FAILURE]" << std::endl; - return EXIT_FAILURE; - } - - std::cout << "[SUCCESS]" << std::endl; - - std::cout << "Testing Clone() : "; - itk::TreeIteratorBase * childItClone = childIt2.Clone(); - if (!childItClone) - { - std::cout << "[FAILURE]" << std::endl; - return EXIT_FAILURE; - } - delete childItClone; - - std::cout << "[SUCCESS]" << std::endl; - - // LeafTreeIterator Test - std::cout << "Testing LeafTreeIterator: " << std::endl; - NodeType expectedLeaf[] = { 7, 4, 6, 3 }; - expectedIndex = 0; - itk::LeafTreeIterator leafIt(tree); - leafIt.GoToBegin(); - while (!leafIt.IsAtEnd()) - { - std::cout << leafIt.Get() << std::endl; - ITK_TEST_EXPECT_EQUAL(leafIt.Get(), expectedLeaf[expectedIndex]); - ++expectedIndex; - ++leafIt; - } - - std::cout << std::endl; - std::cout << "[SUCCESS]" << std::endl; - - - // InOrderTreeIterator Test - std::cout << "Testing InOrderTreeIterator: " << std::endl; - NodeType expectedInOrder[] = { 0, 1, 7, 2, 4, 5, 6, 3 }; - expectedIndex = 0; - itk::InOrderTreeIterator InOrderIt(tree); - InOrderIt.GoToBegin(); - while (!InOrderIt.IsAtEnd()) - { - std::cout << InOrderIt.Get() << std::endl; - ITK_TEST_EXPECT_EQUAL(InOrderIt.Get(), expectedInOrder[expectedIndex]); - ++expectedIndex; - ++InOrderIt; - } - std::cout << std::endl; - std::cout << "[SUCCESS]" << std::endl; - - - // PostOrderTreeIterator Test - std::cout << "Testing PostOrderTreeIterator: " << std::endl; - NodeType expectedPostOrder[] = { 7, 1, 4, 6, 5, 2, 3, 0 }; - expectedIndex = 0; - itk::PostOrderTreeIterator PostOrderIt(tree); - PostOrderIt.GoToBegin(); - while (!PostOrderIt.IsAtEnd()) - { - std::cout << PostOrderIt.Get() << std::endl; - ITK_TEST_EXPECT_EQUAL(PostOrderIt.Get(), expectedPostOrder[expectedIndex]); - ++expectedIndex; - ++PostOrderIt; - } - std::cout << std::endl; - std::cout << "[SUCCESS]" << std::endl; - - // RootTreeIterator Test - std::cout << "Testing RootTreeIterator: " << std::endl; - NodeType expectedRootTree[] = { 6, 5, 2, 0 }; - expectedIndex = 0; - itk::RootTreeIterator RootIt(tree, tree->GetNode(6)); - RootIt.GoToBegin(); - while (!RootIt.IsAtEnd()) - { - std::cout << RootIt.Get() << std::endl; - ITK_TEST_EXPECT_EQUAL(RootIt.Get(), expectedRootTree[expectedIndex]); - ++expectedIndex; - ++RootIt; - } - std::cout << std::endl; - std::cout << "[SUCCESS]" << std::endl; - - - // PreOrderTreeIterator Test - std::cout << "Testing PreOrderTreeIterator: " << std::endl; - NodeType expectedPreOrder[] = { 0, 1, 7, 2, 4, 5, 6, 3 }; - expectedIndex = 0; - itk::PreOrderTreeIterator PreOrderIt(tree); - PreOrderIt.GoToBegin(); - while (!PreOrderIt.IsAtEnd()) - { - std::cout << PreOrderIt.Get() << std::endl; - ITK_TEST_EXPECT_EQUAL(PreOrderIt.Get(), expectedPreOrder[expectedIndex]); - ++expectedIndex; - ++PreOrderIt; - } - std::cout << std::endl; - std::cout << "[SUCCESS]" << std::endl; - - - /** Now create the tree using iterators */ - std::cout << "Testing clear tree" << std::endl; - if (tree->Clear()) - { - std::cout << "[SUCCESS]" << std::endl; - } - else - { - std::cout << "[FAILURE]" << std::endl; - return EXIT_FAILURE; - } - - std::cout << tree << std::endl; - - // Testing the tree creation using iterators - itk::PreOrderTreeIterator PreOrderIt2(tree); - PreOrderIt2.Add(0); - PreOrderIt2.Add(1); - PreOrderIt2.Add(2); - PreOrderIt2.Add(3); - PreOrderIt2.GoToChild(2); - PreOrderIt2.Add(4); - PreOrderIt2.Add(5); - - std::cout << tree << std::endl; - std::cout << "[SUCCESS]" << std::endl; - // Try to add a bench of leaves - itk::LeafTreeIterator LeafIt2(tree); - LeafIt2.GoToBegin(); - int i = 6; - while (!LeafIt2.IsAtEnd()) - { - LeafIt2.Add(i); - i++; - ++LeafIt2; - if (!LeafIt2.IsAtEnd()) - { - ++LeafIt2; - } - } - std::cout << tree << std::endl; - std::cout << "[SUCCESS]" << std::endl; - - - // Test the TreeIteratorClone - using IteratorType = itk::TreeIteratorBase; - using MyIteratorClone = itk::TreeIteratorClone; - itk::PreOrderTreeIterator anIterator(tree); - MyIteratorClone aClone = anIterator; - ++aClone; // step forward in the cloned iterator, anIterator unchanged. - itk::PreOrderTreeIterator anotherIterator(tree); - aClone = anotherIterator; // the memory for the cloned version of "anIterator" is freed. - ++aClone; // step forward in the cloned iterator, but now in post-order! - - std::cout << "Test Done." << std::endl; - return EXIT_SUCCESS; -} diff --git a/Modules/Compatibility/Deprecated/test/itkTreeContainerTest2.cxx b/Modules/Compatibility/Deprecated/test/itkTreeContainerTest2.cxx deleted file mode 100644 index cdcafe15fe7..00000000000 --- a/Modules/Compatibility/Deprecated/test/itkTreeContainerTest2.cxx +++ /dev/null @@ -1,430 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ - -#include -#include "itkCommand.h" -#include - - -/** - * This is a test file for the itkTreeContainer class. - */ - -#include "itkTreeContainer.h" -#include "itkChildTreeIterator.h" -#include "itkLevelOrderTreeIterator.h" -#include "itkInOrderTreeIterator.h" -#include "itkPostOrderTreeIterator.h" -#include "itkRootTreeIterator.h" - -class TestData -{ -public: - TestData() - { - m_Value = 0; - m_Counter++; - } - - TestData(const int valueIn) - { - m_Value = valueIn; - m_Counter++; - } - - TestData(const TestData & t) - { - m_Value = t.m_Value; - m_Counter++; - } - - ~TestData() - { - m_Value = 0; - m_Counter--; - - if (m_Counter == 0) - { - std::cout << "last Data destroyed" << std::endl; - } - } - - int - Get() const - { - return m_Value; - } - - void - Set(int v) - { - m_Value = v; - } - - TestData & - operator=(const TestData & t) - { - m_Value = t.m_Value; - std::cout << "assignation: " << m_Value << std::endl; - return *this; - } - - bool - operator==(const TestData & t) - { - if (&t == this) - { - return true; - } - return false; - } - - friend std::ostream & - operator<<(std::ostream & o, TestData & t); - friend std::istream & - operator>>(std::istream & i, TestData & t); - -private: - int m_Value; - static int m_Counter; -}; - -int TestData::m_Counter = 0; - -std::ostream & -operator<<(std::ostream & o, TestData & t) -{ - return o << "( TestData Nr. " << t.Get() << " )"; -} - -std::istream & -operator>>(std::istream & i, TestData & t) -{ - char s[10]; - int value; - - i >> s; // { - i >> s; // TestData - i >> s; // Nr. - i >> s; // } - i >> value; - - t.Set(value); - return i; -} - - -using NodePointerType = TestData *; -using NodeListType = std::list; -using TreeType = itk::TreeContainer; - -class TreeChangeListener : public itk::Command -{ -public: - using Self = TreeChangeListener; - using Pointer = itk::SmartPointer; - using ConstPointer = itk::SmartPointer; - itkNewMacro(Self); - - void - Execute(itk::Object *, const itk::EventObject & event) override - { - std::cout << event.GetEventName() << std::endl; - } - - void - Execute(const itk::Object *, const itk::EventObject & event) override - { - std::cout << event.GetEventName(); - - const auto * e = static_cast *>(&event); - - std::cout << *e->GetChangePosition().Get() << std::endl; - } - -protected: - TreeChangeListener() = default; -}; - -/* - CreateTree_1() - - [1] - - * * * - * * * * - * * * * - [11] [12] [13] [14] - * * * * * * - * * * * * * - * * * * * * - [111] [112] [113] [121] [122] [123] - * - * - * - [9] - * * - * * - * * - [91] [92] - * * * - * * * - * * * - [991] [912] [913] - */ -TreeType::Pointer -CreateTree_1(NodeListType & internalList) -{ - std::cout << "create tree" << std::endl; - - auto tree = TreeType::New(); - - - auto treeChangeListener = TreeChangeListener::New(); - itk::TreeAddEvent ev; - unsigned long tag = tree->AddObserver(ev, treeChangeListener); - - - itk::PostOrderTreeIterator it(tree); - - auto * newNode = new TestData(1); - internalList.push_back(newNode); - it.Add(newNode); - newNode = new TestData(11); - internalList.push_back(newNode); - it.Add(newNode); - newNode = new TestData(12); - internalList.push_back(newNode); - it.Add(newNode); - newNode = new TestData(13); - internalList.push_back(newNode); - it.Add(newNode); - newNode = new TestData(14); - internalList.push_back(newNode); - it.Add(newNode); - it.GoToChild(0); - newNode = new TestData(111); - internalList.push_back(newNode); - it.Add(newNode); - newNode = new TestData(112); - internalList.push_back(newNode); - it.Add(newNode); - newNode = new TestData(113); - internalList.push_back(newNode); - it.Add(newNode); - it.GoToParent(); - it.GoToChild(1); - newNode = new TestData(121); - internalList.push_back(newNode); - it.Add(newNode); - newNode = new TestData(122); - internalList.push_back(newNode); - it.Add(newNode); - newNode = new TestData(123); - internalList.push_back(newNode); - it.Add(newNode); - tree->RemoveObserver(tag); - - std::cout << "end create tree" << std::endl; - return tree; -} - -/* - CreateTree_2() - - * - * - * - [9] - * * - * * - * * - [91] [92] - * * * - * * * - * * * - [991] [912] [913] - */ -TreeType::Pointer -CreateTree_2(NodeListType & internalList) -{ - std::cout << "create tree 2" << std::endl; - - auto tree = TreeType::New(); - auto * newNode = new TestData(9); - internalList.push_back(newNode); - tree->SetRoot(newNode); - itk::PostOrderTreeIterator it(tree); - - newNode = new TestData(91); - internalList.push_back(newNode); - it.Add(newNode); - newNode = new TestData(92); - internalList.push_back(newNode); - it.Add(newNode); - it.GoToChild(0); - newNode = new TestData(991); - internalList.push_back(newNode); - it.Add(newNode); - newNode = new TestData(912); - internalList.push_back(newNode); - it.Add(newNode); - newNode = new TestData(913); - internalList.push_back(newNode); - it.Add(newNode); - - std::cout << "end create tree 2" << std::endl; - return tree; -} - -int -IteratorTest(itk::TreeIteratorBase & i) -{ - int sum = 0; - - // childIt.GoToBegin(); - while (!i.IsAtEnd()) - { - sum += i.Get()->Get(); - std::cout << i.Get()->Get() << std::endl; - ++i; - } - - return sum; -} - -/** Print the results */ -int -PrintResult(int result, int value) -{ - if (result == value) - { - std::cout << "[SUCCESS]" << std::endl; - return 1; - } - else - { - std::cout << "[FAILURE]" << std::endl; - return 0; - } -} - -/** - * Test - */ -int -itkTreeContainerTest2(int, char *[]) -{ - int result; - int testCounter = 0; - NodeListType internalList; // used to delete the pointer in the tree - - TreeType::Pointer tree = CreateTree_1(internalList); - - std::cout << "\nPreOrderTreeIterator:" << std::endl; - itk::PreOrderTreeIterator preOrderIt(tree); - result = IteratorTest(preOrderIt); - testCounter += PrintResult(result, 753); - - std::cout << "\nLevelOrderTreeIterator:" << std::endl; - itk::LevelOrderTreeIterator levelIt(tree); - result = IteratorTest(levelIt); - testCounter += PrintResult(result, 753); - - std::cout << "\nInOrderTreeIterator:" << std::endl; - itk::InOrderTreeIterator inOrderIt(tree); - result = IteratorTest(inOrderIt); - testCounter += PrintResult(result, 753); - - std::cout << "\nPostOrderTreeIterator:" << std::endl; - itk::PostOrderTreeIterator postOrderIt(tree); - result = IteratorTest(postOrderIt); - testCounter += PrintResult(result, 753); - - std::cout << "\nChildTreeIterator Test 1:" << std::endl; - itk::ChildTreeIterator childIt_1(tree); - result = IteratorTest(childIt_1); - testCounter += PrintResult(result, 50); - - std::cout << "\nChildTreeIterator Test 2:" << std::endl; - itk::ChildTreeIterator childIt_2(tree); - childIt_2.GoToChild(0); - result = IteratorTest(childIt_2); - testCounter += PrintResult(result, 336); - - std::cout << "\nChildTreeIterator Test 3:" << std::endl; - itk::ChildTreeIterator childIt_3(tree); - childIt_3.GoToChild(1); - result = IteratorTest(childIt_3); - testCounter += PrintResult(result, 366); - - std::cout << "\nChildTreeIterator Test 4:" << std::endl; - itk::ChildTreeIterator childIt_4(tree); - childIt_4.GoToChild(1); - childIt_4.GoToChild(2); - result = IteratorTest(childIt_4); - testCounter += PrintResult(result, 0); - - std::cout << "\nRootTreeIterator Test 1:" << std::endl; - itk::RootTreeIterator rootIt_1(tree); - rootIt_1.GoToChild(1); - rootIt_1.GoToChild(2); - result = IteratorTest(rootIt_1); - testCounter += PrintResult(result, 136); - - // creat tree 2 - itk::PreOrderTreeIterator iterator_123(tree); - iterator_123.GoToChild(1); - iterator_123.GoToChild(2); - TreeType::Pointer tree_2 = CreateTree_2(internalList); - iterator_123.Add(*tree_2.GetPointer()); - - std::cout << "\nTree1 + Tree2:" << std::endl; - itk::PreOrderTreeIterator preOrderIt_Tree_1_2(tree); - result = IteratorTest(preOrderIt_Tree_1_2); - testCounter += PrintResult(result, 3761); - - auto treeChangeListener = TreeChangeListener::New(); - itk::TreeChangeEvent ev; - unsigned long tag = tree->AddObserver(ev, treeChangeListener); - tree->Clear(); - tree->RemoveObserver(tag); - - // Delete the list of pointer to TestData - auto it = internalList.begin(); - - while (it != internalList.end()) - { - auto it2 = it; - ++it; - TestData * t = *it2; - internalList.erase(it2); - delete t; - } - - if (testCounter == 10) - { - std::cout << "TEST DONE" << std::endl; - return EXIT_SUCCESS; - } - else - { - std::cout << "TEST [FAILURE]" << std::endl; - return EXIT_FAILURE; - } -} diff --git a/Modules/Compatibility/Deprecated/test/itkVectorCentralDifferenceImageFunctionTest.cxx b/Modules/Compatibility/Deprecated/test/itkVectorCentralDifferenceImageFunctionTest.cxx deleted file mode 100644 index 2de86210067..00000000000 --- a/Modules/Compatibility/Deprecated/test/itkVectorCentralDifferenceImageFunctionTest.cxx +++ /dev/null @@ -1,103 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ - -#include "itkVectorCentralDifferenceImageFunction.h" -#include "itkImageRegionIterator.h" - -int -itkVectorCentralDifferenceImageFunctionTest(int, char *[]) -{ - constexpr unsigned int ImageDimension = 2; - constexpr unsigned int VectorDimension = 3; - using PixelType = itk::Vector; - using ImageType = itk::Image; - - auto image = ImageType::New(); - ImageType::SizeType size; - size.Fill(16); - ImageType::RegionType region(size); - - image->SetRegions(region); - image->Allocate(); - - // make a test image - using Iterator = itk::ImageRegionIterator; - Iterator iter(image, region); - iter.GoToBegin(); - unsigned int counter = 0; - - while (!iter.IsAtEnd()) - { - iter.Set(counter++); - ++iter; - } - - // set up central difference calculator - using CoordRepType = float; - using FunctionType = itk::VectorCentralDifferenceImageFunction; - auto function = FunctionType::New(); - - function->SetInputImage(image); - - ImageType::IndexType index; - - // pick an index inside the image - index.Fill(8); - std::cout << "Index: " << index << " Derivative:" << std::endl; - std::cout << function->EvaluateAtIndex(index) << std::endl; - - if (function->IsInsideBuffer(index)) - { - std::cout << "Index: " << index << " is inside the BufferedRegion." << std::endl; - } - - FunctionType::ContinuousIndexType cindex; - cindex.Fill(8.0); - std::cout << "ContinuousIndex: " << cindex << " Derivative:" << std::endl; - std::cout << function->EvaluateAtContinuousIndex(cindex) << std::endl; - - FunctionType::PointType point; - point.Fill(8.0); - std::cout << "Point: " << cindex << " Derivative:" << std::endl; - std::cout << function->Evaluate(point) << std::endl; - - // pick an index on the image edge - index.Fill(8); - index[0] = 15; - std::cout << "Index: " << index << " Derivative:" << std::endl; - std::cout << function->EvaluateAtIndex(index) << std::endl; - - if (function->IsInsideBuffer(index)) - { - std::cout << "Index: " << index << " is inside the BufferedRegion." << std::endl; - } - - cindex.Fill(8.0); - cindex[0] = 15.0; - std::cout << "ContinuousIndex: " << cindex << " Derivative:" << std::endl; - std::cout << function->EvaluateAtContinuousIndex(cindex) << std::endl; - - point.Fill(8.0); - point[0] = 15.0; - std::cout << "Point: " << cindex << " Derivative:" << std::endl; - std::cout << function->Evaluate(point) << std::endl; - - - std::cout << "Test passed." << std::endl; - return EXIT_SUCCESS; -} diff --git a/Modules/Compatibility/Deprecated/test/itkVectorResampleImageFilterTest.cxx b/Modules/Compatibility/Deprecated/test/itkVectorResampleImageFilterTest.cxx deleted file mode 100644 index c74a9983645..00000000000 --- a/Modules/Compatibility/Deprecated/test/itkVectorResampleImageFilterTest.cxx +++ /dev/null @@ -1,155 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ - -#include "itkVectorResampleImageFilter.h" -#include "itkImageFileWriter.h" -#include "itkSimpleFilterWatcher.h" -#include "itkTestingMacros.h" - -int -itkVectorResampleImageFilterTest(int argc, char * argv[]) -{ - - if (argc < 2) - { - std::cerr << "Missing parameters." << std::endl; - std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv); - std::cerr << " outputImage" << std::endl; - return EXIT_FAILURE; - } - - constexpr unsigned int Dimension = 2; - using PixelComponentType = unsigned char; - - using PixelType = itk::RGBPixel; - using ImageType = itk::Image; - - using FilterType = itk::VectorResampleImageFilter; - - auto filter = FilterType::New(); - - ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, VectorResampleImageFilter, ImageToImageFilter); - - itk::SimpleFilterWatcher watcher(filter); - - using InterpolatorType = itk::VectorLinearInterpolateImageFunction; - - auto interpolator = InterpolatorType::New(); - - filter->SetInterpolator(interpolator); - ITK_TEST_SET_GET_VALUE(interpolator, filter->GetInterpolator()); - - using TransformType = itk::IdentityTransform; - auto transform = TransformType::New(); - - filter->SetTransform(transform); - ITK_TEST_SET_GET_VALUE(transform, filter->GetTransform()); - - ImageType::SpacingType spacing; - spacing.Fill(1.0); - - ImageType::PointType origin; - origin.Fill(0.0); - - ImageType::RegionType region; - ImageType::SizeType size; - ImageType::IndexType start; - - size[0] = 128; - size[1] = 128; - - start[0] = 0; - start[1] = 0; - - region.SetSize(size); - region.SetIndex(start); - - auto image = ImageType::New(); - - image->SetOrigin(origin); - image->SetSpacing(spacing); - image->SetRegions(region); - image->Allocate(); - - PixelType pixelValue; - - itk::ImageRegionIteratorWithIndex it(image, region); - - // Fill the image with some color pattern - it.GoToBegin(); - while (!it.IsAtEnd()) - { - ImageType::IndexType index = it.GetIndex(); - pixelValue.SetRed(index[0] * 2); - pixelValue.SetGreen(index[0] + index[1]); - pixelValue.SetBlue(index[1] * 2); - it.Set(pixelValue); - ++it; - } - - PixelType blackValue; - blackValue.Fill(0); - - filter->SetDefaultPixelValue(blackValue); - ITK_TEST_SET_GET_VALUE(blackValue, filter->GetDefaultPixelValue()); - - // Set the spacing for the resampling - spacing[0] *= 2.0; - spacing[1] *= 2.0; - - filter->SetOutputSpacing(spacing); - ITK_TEST_SET_GET_VALUE(spacing, filter->GetOutputSpacing()); - - // Keep the input image origin - filter->SetOutputOrigin(origin); - ITK_TEST_SET_GET_VALUE(origin, filter->GetOutputOrigin()); - - // Set the size - size[0] /= 2; - size[1] /= 2; - - filter->SetSize(size); - ITK_TEST_SET_GET_VALUE(size, filter->GetSize()); - - // Set the output direction - FilterType::DirectionType outputDirection = image->GetDirection(); - - filter->SetOutputDirection(outputDirection); - ITK_TEST_SET_GET_VALUE(outputDirection, filter->GetOutputDirection()); - - // Set the start index - FilterType::IndexType outputStartIndex = image->GetLargestPossibleRegion().GetIndex(); - - filter->SetOutputStartIndex(outputStartIndex); - ITK_TEST_SET_GET_VALUE(outputStartIndex, filter->GetOutputStartIndex()); - - - filter->SetInput(image); - - ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); - - // Write an image for regression testing - using WriterType = itk::ImageFileWriter; - auto writer = WriterType::New(); - writer->SetInput(filter->GetOutput()); - writer->SetFileName(argv[1]); - - ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update()); - - return EXIT_SUCCESS; -} diff --git a/Modules/Compatibility/Deprecated/wrapping/itkImageTransformer.wrap b/Modules/Compatibility/Deprecated/wrapping/itkImageTransformer.wrap deleted file mode 100644 index e8f43819894..00000000000 --- a/Modules/Compatibility/Deprecated/wrapping/itkImageTransformer.wrap +++ /dev/null @@ -1,9 +0,0 @@ -itk_wrap_class("itk::ImageTransformer" POINTER) -itk_wrap_image_filter("${WRAP_ITK_ALL_TYPES}" 1) - -foreach(d ${ITK_WRAP_IMAGE_DIMS}) - foreach(type ${WRAP_ITK_SCALAR}) - itk_wrap_template("${ITKM_VI${type}${d}}" "${ITKT_VI${type}${d}}") - endforeach() -endforeach() -itk_end_wrap_class() diff --git a/Modules/Compatibility/Deprecated/wrapping/itkVectorCastImageFilter.wrap b/Modules/Compatibility/Deprecated/wrapping/itkVectorCastImageFilter.wrap deleted file mode 100644 index fff6d81d143..00000000000 --- a/Modules/Compatibility/Deprecated/wrapping/itkVectorCastImageFilter.wrap +++ /dev/null @@ -1,12 +0,0 @@ -itk_wrap_class("itk::VectorCastImageFilter" POINTER_WITH_SUPERCLASS) -# vector <-> vector -itk_wrap_image_filter_combinations("${WRAP_ITK_VECTOR}" "${WRAP_ITK_VECTOR}") - -# RGB <-> RGB -unique(rgb "RGBUC;${WRAP_ITK_RGB}") -itk_wrap_image_filter_combinations("${rgb}" "${rgb}") - -# vector <-> RGB -# itk_wrap_image_filter_combinations("${WRAP_ITK_VECTOR}" "${WRAP_ITK_RGB}" 3) -# itk_wrap_image_filter_combinations("${WRAP_ITK_RGB}" "${WRAP_ITK_VECTOR}" 3) -itk_end_wrap_class() diff --git a/Modules/Compatibility/Deprecated/wrapping/itkVectorResampleImageFilter.wrap b/Modules/Compatibility/Deprecated/wrapping/itkVectorResampleImageFilter.wrap deleted file mode 100644 index 7a136022d7e..00000000000 --- a/Modules/Compatibility/Deprecated/wrapping/itkVectorResampleImageFilter.wrap +++ /dev/null @@ -1,3 +0,0 @@ -itk_wrap_class("itk::VectorResampleImageFilter" POINTER) -itk_wrap_image_filter("${WRAP_ITK_VECTOR_REAL}" 2) -itk_end_wrap_class() diff --git a/Modules/Compatibility/README b/Modules/Compatibility/README index 68985cb0305..f3a58c20587 100644 --- a/Modules/Compatibility/README +++ b/Modules/Compatibility/README @@ -6,4 +6,4 @@ considered as Legacy code, and will be removed from the toolkit in future releases. Deprecated: Any code that provides a feature or function - that is no longer supported in ITKv5 + that is no longer supported in ITKv6