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 const RadiusType &
86 GetRadius() const
87 {
88 return m_Radius;
89 }
90
91 const unsigned int &
92 GetArrayIndex(unsigned int i) const
93 {
94 return m_ArrayIndex[i];
95 }
96
97 const OffsetType &
98 GetNeighborhoodOffset(unsigned int i) const
99 {
100 return m_NeighborhoodOffset[i];
101 }
102
103 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
122
123 void
124 Print(std::ostream & os, Indent indent) const;
125
126private:
127 char m_Pad1[128]{};
128 unsigned int m_Size{ 2 * Dimension };
130 std::vector<unsigned int> m_ArrayIndex{};
131 std::vector<OffsetType> m_NeighborhoodOffset{};
132
135 unsigned int m_StrideTable[Dimension]{};
136 char m_Pad2[128]{};
137};
138
250template <typename TInputImage, typename TOutputImage>
252 : public FiniteDifferenceImageFilter<TInputImage, TOutputImage>
253{
254public:
255 ITK_DISALLOW_COPY_AND_MOVE(ParallelSparseFieldLevelSetImageFilter);
256
262
264 using typename Superclass::TimeStepType;
266 using typename Superclass::RadiusType;
268
270 itkNewMacro(Self);
271
273 itkOverrideGetNameOfClassMacro(ParallelSparseFieldLevelSetImageFilter);
274
276 using InputImageType = TInputImage;
277 using OutputImageType = TOutputImage;
278 using IndexType = typename OutputImageType::IndexType;
279
280 static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension;
281
282 using PixelType = typename OutputImageType::PixelType;
283
284 using ThreadRegionType = typename OutputImageType::RegionType;
285
288 using ValueType = typename OutputImageType::ValueType;
289
292
296
298 using LayerListType = std::vector<LayerPointerType>;
299
301 using StatusType = signed char;
302
306
310
312
316 itkSetMacro(NumberOfLayers, StatusType);
317 itkGetConstMacro(NumberOfLayers, StatusType);
319
321 itkSetMacro(IsoSurfaceValue, ValueType);
322 itkGetConstMacro(IsoSurfaceValue, ValueType);
324
327 {
328 // get the 'z' value for the index
329 const unsigned int indexZ = index[m_SplitAxis];
330 // get the thread in whose region the index lies
331 const unsigned int ThreadNum = this->GetThreadNumber(indexZ);
332
333 // get the active list for that thread
334 return m_Data[ThreadNum].m_Layers[0];
335 }
336
337 itkConceptMacro(OutputEqualityComparableCheck, (Concept::EqualityComparable<PixelType>));
338 itkConceptMacro(DoubleConvertibleToOutputCheck, (Concept::Convertible<double, PixelType>));
339 itkConceptMacro(OutputOStreamWritableCheck, (Concept::OStreamWritable<PixelType>));
340
341protected:
344 void
345 PrintSelf(std::ostream & os, Indent indent) const override;
346
349
353
356
359
363
367
371
375
379
384 typename OutputImageType::Pointer m_ShiftedImage{};
385
391
397
400 typename OutputImageType::Pointer m_OutputImage{};
401
405 typename OutputImageType::Pointer m_OutputImageTemp{};
406
409
412
416 // ValueType m_RMSChange;
417
420 void
421 GenerateData() override;
422
427 void
429
431 void
433 {}
434
437 void
438 Initialize() override;
439
444 void
446
448 void
450
454 void
455 ConstructLayer(const StatusType & from, const StatusType & to);
456
458 void
460 const StatusType & ChangeToStatus,
461 const StatusType & SearchForStatus,
462 ThreadIdType ThreadId);
463
468 void
470
478 void
480 const StatusType & to,
481 const StatusType & promote,
482 unsigned int InOrOut);
483
488 virtual void
490
494 void
496
497 void
498 ThreadedInitializeData(ThreadIdType ThreadId, const ThreadRegionType & ThreadRegion);
499
509 void
511
513 unsigned int
514 GetThreadNumber(unsigned int splitAxisValue);
515
517 void
519
522 void
524
529 void
531
536 inline virtual ValueType
537 ThreadedCalculateUpdateValue(const ThreadIdType itkNotUsed(ThreadId),
538 const IndexType itkNotUsed(index),
539 const TimeStepType & dt,
540 const ValueType & value,
541 const ValueType & change)
542 {
543 return (value + static_cast<ValueType>(dt) * change);
544 }
545
546 // This method can be overridden in derived classes.
547 // The pixel at 'index' is entering the active layer for thread 'ThreadId'.
548 // The output image at 'index' will have the value as given by the
549 // 'value' parameter.
550 virtual void
552 const ValueType & itkNotUsed(value),
553 ThreadIdType itkNotUsed(ThreadId));
554
556 void
557 ApplyUpdate(const TimeStepType &) override
558 {}
559
562 virtual void
564
568 {
569 return TimeStepType{};
570 }
571
574 virtual TimeStepType
576
583 void
585 LayerType * UpList,
586 LayerType * DownList,
587 ThreadIdType ThreadId);
588
591 void
593
595 void
597
600 void
602 LayerPointerType List,
603 unsigned int InOrOut,
604 unsigned int BufferLayerNumber);
605
608 void
610 unsigned int InOrOut,
611 unsigned int BufferLayerNumber);
612
620 void
621 ThreadedProcessFirstLayerStatusLists(unsigned int InputLayerNumber,
622 unsigned int OutputLayerNumber,
623 const StatusType & SearchForStatus,
624 unsigned int InOrOut,
625 unsigned int BufferLayerNumber,
626 ThreadIdType ThreadId);
627
633 void
634 ThreadedProcessStatusList(unsigned int InputLayerNumber,
635 unsigned int OutputLayerNumber,
636 const StatusType & ChangeToStatus,
637 const StatusType & SearchForStatus,
638 unsigned int InOrOut,
639 unsigned int BufferLayerNumber,
640 ThreadIdType ThreadId);
641
645 void
646 ThreadedProcessOutsideList(unsigned int InputLayerNumber,
647 const StatusType & ChangeToStatus,
648 unsigned int InOrOut,
649 unsigned int BufferLayerNumber,
650 ThreadIdType ThreadId);
651
653 void
655 const StatusType & to,
656 const StatusType & promote,
657 unsigned int InOrOut,
658 ThreadIdType ThreadId);
659
662 void
664
670 void
672
683 virtual void
685
688 void
690 void
693
694 void
696
697 void
698 SignalNeighbor(unsigned int SemaphoreArrayNumber, ThreadIdType ThreadId);
699
700 void
701 WaitForNeighbor(unsigned int SemaphoreArrayNumber, ThreadIdType ThreadId);
702
705 virtual void
707
709 std::vector<TimeStepType> m_TimeStepList{};
712
715
717 unsigned int m_SplitAxis{ 0 };
718
720 unsigned int m_ZSize{ 0 };
721
724 bool m_BoundaryChanged{ false };
725
727 unsigned int * m_Boundary{ nullptr };
728
730 int * m_GlobalZHistogram{ nullptr };
731
734 unsigned int * m_MapZToThreadNumber{ nullptr };
735
738 int * m_ZCumulativeFrequency{ nullptr };
739
784
785 itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, ThreadDataUnaligned, ThreadDataPadded);
786 itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, ThreadDataPadded, ThreadData);
787
790 ThreadData * m_Data{ nullptr };
791
794 bool m_Stop{ false };
795
801
802private:
806};
807} // end namespace itk
808
809#ifndef ITK_MANUAL_INSTANTIATION
810# include "itkParallelSparseFieldLevelSetImageFilter.hxx"
811#endif
812
813#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