ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkParallelSparseFieldLevelSetImageFilter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkParallelSparseFieldLevelSetImageFilter_h
19#define itkParallelSparseFieldLevelSetImageFilter_h
20
21#include "itkBooleanStdVector.h"
23#include "itkSparseFieldLayer.h"
24#include "itkObjectStore.h"
27#include <condition_variable>
28#include <vector>
29
30namespace itk
31{
37template <typename TNodeIndexType>
46
75template <typename TNeighborhoodType>
77{
78public:
79 using NeighborhoodType = TNeighborhoodType;
80 using OffsetType = typename NeighborhoodType::OffsetType;
81 using RadiusType = typename NeighborhoodType::RadiusType;
82
83 static constexpr unsigned int Dimension = NeighborhoodType::Dimension;
84
85 [[nodiscard]] const RadiusType &
86 GetRadius() const
87 {
88 return m_Radius;
89 }
90
91 [[nodiscard]] const unsigned int &
92 GetArrayIndex(unsigned int i) const
93 {
94 return m_ArrayIndex[i];
95 }
96
97 [[nodiscard]] const OffsetType &
98 GetNeighborhoodOffset(unsigned int i) const
99 {
100 return m_NeighborhoodOffset[i];
101 }
102
103 [[nodiscard]] const unsigned int &
104 GetSize() const
105 {
106 return m_Size;
107 }
108
109 unsigned int
110 GetStride(unsigned int i)
111 {
112 return m_StrideTable[i];
113 }
114
116
118
119 void
120 Print(std::ostream & os, Indent indent) const;
121
122private:
123 char m_Pad1[128]{};
124 unsigned int m_Size{ 2 * Dimension };
126 std::vector<unsigned int> m_ArrayIndex{};
127 std::vector<OffsetType> m_NeighborhoodOffset{};
128
131 unsigned int m_StrideTable[Dimension]{};
132 char m_Pad2[128]{};
133};
134
246template <typename TInputImage, typename TOutputImage>
248 : public FiniteDifferenceImageFilter<TInputImage, TOutputImage>
249{
250public:
251 ITK_DISALLOW_COPY_AND_MOVE(ParallelSparseFieldLevelSetImageFilter);
252
258
260 using typename Superclass::TimeStepType;
262 using typename Superclass::RadiusType;
264
266 itkNewMacro(Self);
267
269 itkOverrideGetNameOfClassMacro(ParallelSparseFieldLevelSetImageFilter);
270
272 using InputImageType = TInputImage;
273 using OutputImageType = TOutputImage;
274 using IndexType = typename OutputImageType::IndexType;
275
276 static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension;
277
278 using PixelType = typename OutputImageType::PixelType;
279
280 using ThreadRegionType = typename OutputImageType::RegionType;
281
284 using ValueType = typename OutputImageType::ValueType;
285
288
292
294 using LayerListType = std::vector<LayerPointerType>;
295
297 using StatusType = signed char;
298
300 using LayerCountType = StatusType; /* purposefully the same as StatusType
301 for backward compatibility. This value
302 is compared with up/down layer values
303 that can be signed. Max layer count of
304 127 is enough. */
305
309
313
315
320 itkSetMacro(NumberOfLayers, LayerCountType);
321 itkGetConstMacro(NumberOfLayers, LayerCountType);
325 itkSetMacro(IsoSurfaceValue, ValueType);
326 itkGetConstMacro(IsoSurfaceValue, ValueType);
330 {
331 // get the 'z' value for the index
332 const unsigned int indexZ = index[m_SplitAxis];
333 // get the thread in whose region the index lies
334 const unsigned int ThreadNum = this->GetThreadNumber(indexZ);
335
336 // get the active list for that thread
337 return m_Data[ThreadNum].m_Layers[0];
338 }
339
340 itkConceptMacro(OutputEqualityComparableCheck, (Concept::EqualityComparable<PixelType>));
341 itkConceptMacro(DoubleConvertibleToOutputCheck, (Concept::Convertible<double, PixelType>));
342 itkConceptMacro(OutputOStreamWritableCheck, (Concept::OStreamWritable<PixelType>));
343
344protected:
347 void
348 PrintSelf(std::ostream & os, Indent indent) const override;
349
352
356
359
362
366
370
374
378
382
387 typename OutputImageType::Pointer m_ShiftedImage{};
388
394
400
403 typename OutputImageType::Pointer m_OutputImage{};
404
408 typename OutputImageType::Pointer m_OutputImageTemp{};
409
412
415
419 // ValueType m_RMSChange;
420
423 void
424 GenerateData() override;
425
430 void
432
434 void
436 {}
437
440 void
441 Initialize() override;
442
447 void
449
451 void
453
457 void
458 ConstructLayer(const StatusType & from, const StatusType & to);
459
461 void
463 const StatusType & ChangeToStatus,
464 const StatusType & SearchForStatus,
465 ThreadIdType ThreadId);
466
471 void
473
481 void
483 const StatusType & to,
484 const StatusType & promote,
485 unsigned int InOrOut);
486
491 virtual void
493
497 void
499
500 void
501 ThreadedInitializeData(ThreadIdType ThreadId, const ThreadRegionType & ThreadRegion);
502
512 void
514
516 unsigned int
517 GetThreadNumber(unsigned int splitAxisValue);
518
520 void
522
525 void
527
532 void
534
539 inline virtual ValueType
540 ThreadedCalculateUpdateValue(const ThreadIdType itkNotUsed(ThreadId),
541 const IndexType itkNotUsed(index),
542 const TimeStepType & dt,
543 const ValueType & value,
544 const ValueType & change)
545 {
546 return value + static_cast<ValueType>(dt) * change;
547 }
548
549 // This method can be overridden in derived classes.
550 // The pixel at 'index' is entering the active layer for thread 'ThreadId'.
551 // The output image at 'index' will have the value as given by the
552 // 'value' parameter.
553 virtual void
555 const ValueType & itkNotUsed(value),
556 ThreadIdType itkNotUsed(ThreadId));
557
559 void
560 ApplyUpdate(const TimeStepType &) override
561 {}
562
565 virtual void
567
571 {
572 return TimeStepType{};
573 }
574
577 virtual TimeStepType
579
586 void
588 LayerType * UpList,
589 LayerType * DownList,
590 ThreadIdType ThreadId);
591
594 void
596
598 void
600
603 void
605 LayerPointerType List,
606 unsigned int InOrOut,
607 unsigned int BufferLayerNumber);
608
611 void
613 unsigned int InOrOut,
614 unsigned int BufferLayerNumber);
615
623 void
624 ThreadedProcessFirstLayerStatusLists(unsigned int InputLayerNumber,
625 unsigned int OutputLayerNumber,
626 const StatusType & SearchForStatus,
627 unsigned int InOrOut,
628 unsigned int BufferLayerNumber,
629 ThreadIdType ThreadId);
630
636 void
637 ThreadedProcessStatusList(unsigned int InputLayerNumber,
638 unsigned int OutputLayerNumber,
639 const StatusType & ChangeToStatus,
640 const StatusType & SearchForStatus,
641 unsigned int InOrOut,
642 unsigned int BufferLayerNumber,
643 ThreadIdType ThreadId);
644
648 void
649 ThreadedProcessOutsideList(unsigned int InputLayerNumber,
650 const StatusType & ChangeToStatus,
651 unsigned int InOrOut,
652 unsigned int BufferLayerNumber,
653 ThreadIdType ThreadId);
654
656 void
658 const StatusType & to,
659 const StatusType & promote,
660 unsigned int InOrOut,
661 ThreadIdType ThreadId);
662
665 void
667
673 void
675
686 virtual void
688
692 void
694 void
697 void
699
700 void
701 SignalNeighbor(unsigned int SemaphoreArrayNumber, ThreadIdType ThreadId);
702
703 void
704 WaitForNeighbor(unsigned int SemaphoreArrayNumber, ThreadIdType ThreadId);
705
708 virtual void
710
712 std::vector<TimeStepType> m_TimeStepList{};
715
718
720 unsigned int m_SplitAxis{ 0 };
721
723 unsigned int m_ZSize{ 0 };
724
727 bool m_BoundaryChanged{ false };
728
730 unsigned int * m_Boundary{ nullptr };
731
733 int * m_GlobalZHistogram{ nullptr };
734
737 unsigned int * m_MapZToThreadNumber{ nullptr };
738
741 int * m_ZCumulativeFrequency{ nullptr };
742
787
788 itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, ThreadDataUnaligned, ThreadDataPadded);
789 itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, ThreadDataPadded, ThreadData);
790
793 ThreadData * m_Data{ nullptr };
794
797 bool m_Stop{ false };
798
804
805private:
809};
810} // end namespace itk
811
812#ifndef ITK_MANUAL_INSTANTIATION
813# include "itkParallelSparseFieldLevelSetImageFilter.hxx"
814#endif
815
816#endif
typename FiniteDifferenceFunctionType::TimeStepType TimeStepType
typename FiniteDifferenceFunctionType::NeighborhoodScalesType NeighborhoodScalesType
FiniteDifferenceFunction< TOutputImage > FiniteDifferenceFunctionType
typename FiniteDifferenceFunctionType::RadiusType RadiusType
Templated n-dimensional image class.
Definition itkImage.h:89
Control indentation during Print() invocation.
Definition itkIndent.h:50
A specialized memory management object for allocating and destroying contiguous blocks of objects.
A convenience class for storing indices which reference neighbor pixels within a neighborhood.
void Print(std::ostream &os, Indent indent) const
typename FiniteDifferenceFunctionType::TimeStepType TimeStepType
void ConstructLayer(const StatusType &from, const StatusType &to)
void CopyInsertList(ThreadIdType ThreadId, LayerPointerType FromListPtr, LayerPointerType ToListPtr)
virtual void ThreadedProcessPixelEnteringActiveLayer(const IndexType &index, const ValueType &value, ThreadIdType ThreadId)
void ThreadedAllocateData(ThreadIdType ThreadId)
void ClearInterNeighborNodeTransferBufferLayers(ThreadIdType ThreadId, unsigned int InOrOut, unsigned int BufferLayerNumber)
FiniteDifferenceImageFilter< TInputImage, TOutputImage > Superclass
virtual void ThreadedApplyUpdate(const TimeStepType &dt, ThreadIdType ThreadId)
void ProcessStatusList(LayerType *InputList, const StatusType &ChangeToStatus, const StatusType &SearchForStatus, ThreadIdType ThreadId)
unsigned int GetThreadNumber(unsigned int splitAxisValue)
void ThreadedProcessFirstLayerStatusLists(unsigned int InputLayerNumber, unsigned int OutputLayerNumber, const StatusType &SearchForStatus, unsigned int InOrOut, unsigned int BufferLayerNumber, ThreadIdType ThreadId)
void ThreadedLoadBalance2(ThreadIdType ThreadId)
virtual TimeStepType ThreadedCalculateChange(ThreadIdType ThreadId)
void GetThreadRegionSplitUniformly(ThreadIdType ThreadId, ThreadRegionType &ThreadRegion)
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, ThreadDataPadded, ThreadData)
void ThreadedInitializeData(ThreadIdType ThreadId, const ThreadRegionType &ThreadRegion)
void SignalNeighborsAndWait(ThreadIdType ThreadId)
void ThreadedPostProcessOutput(const ThreadRegionType &regionToProcess)
void ClearList(ThreadIdType ThreadId, LayerPointerType ListPtr)
void CopyInsertInterNeighborNodeTransferBufferLayers(ThreadIdType ThreadId, LayerPointerType List, unsigned int InOrOut, unsigned int BufferLayerNumber)
void ThreadedUpdateActiveLayerValues(const TimeStepType &dt, LayerType *UpList, LayerType *DownList, ThreadIdType ThreadId)
void ThreadedProcessOutsideList(unsigned int InputLayerNumber, const StatusType &ChangeToStatus, unsigned int InOrOut, unsigned int BufferLayerNumber, ThreadIdType ThreadId)
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, ThreadDataUnaligned, ThreadDataPadded)
void ThreadedPropagateLayerValues(const StatusType &from, const StatusType &to, const StatusType &promote, unsigned int InOrOut, ThreadIdType ThreadId)
void SignalNeighbor(unsigned int SemaphoreArrayNumber, ThreadIdType ThreadId)
void PropagateLayerValues(const StatusType &from, const StatusType &to, const StatusType &promote, unsigned int InOrOut)
~ParallelSparseFieldLevelSetImageFilter() override=default
virtual ValueType ThreadedCalculateUpdateValue(const ThreadIdType ThreadId, const IndexType index, const TimeStepType &dt, const ValueType &value, const ValueType &change)
ParallelSparseFieldCityBlockNeighborList< NeighborhoodIterator< OutputImageType > > m_NeighborList
void PrintSelf(std::ostream &os, Indent indent) const override
void GetThreadRegionSplitByBoundary(ThreadIdType ThreadId, ThreadRegionType &ThreadRegion)
void ThreadedLoadBalance1(ThreadIdType ThreadId)
virtual void ThreadedInitializeIteration(ThreadIdType ThreadId)
void WaitForNeighbor(unsigned int SemaphoreArrayNumber, ThreadIdType ThreadId)
void ThreadedProcessStatusList(unsigned int InputLayerNumber, unsigned int OutputLayerNumber, const StatusType &ChangeToStatus, const StatusType &SearchForStatus, unsigned int InOrOut, unsigned int BufferLayerNumber, ThreadIdType ThreadId)
Implements transparent reference counting.
A very simple linked list that is used to manage nodes in a layer of a sparse field level-set solver.
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned int ThreadIdType
std::vector< Boolean > BooleanStdVectorType
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image.
Definition itkOffset.h:67