52 #ifndef __PCL_AbstractImage_h
53 #define __PCL_AbstractImage_h
69 #ifdef __PCL_BUILDING_PIXINSIGHT_APPLICATION
81 #define m_width m_geometry->width
82 #define m_height m_geometry->height
83 #define m_numberOfChannels m_geometry->numberOfChannels
85 #define m_colorSpace m_color->colorSpace
86 #define m_RGBWS m_color->RGBWS
169 PCL_PRECONDITION( NumberOfChannels() != 0 )
178 PCL_PRECONDITION( NumberOfChannels() != 0 )
189 return NumberOfPixels() * NumberOfAlphaChannels();
202 PCL_PRECONDITION( 0 <= c && c < m_numberOfChannels )
203 m_selected.channel = m_selected.lastChannel = c;
204 ValidateChannelRange();
217 return m_selected.channel;
229 PCL_PRECONDITION( 0 <= c0 && c0 < m_numberOfChannels )
230 PCL_PRECONDITION( 0 <= c1 && c1 < m_numberOfChannels )
231 m_selected.channel = c0;
232 m_selected.lastChannel = c1;
233 ValidateChannelRange();
242 m_selected.channel = 0;
244 ValidateChannelRange();
257 m_selected.lastChannel = m_numberOfChannels-1;
258 ValidateChannelRange();
267 m_selected.channel = 0;
268 m_selected.lastChannel =
pcl::Max( 0, m_numberOfChannels-1 );
276 return 1 + m_selected.lastChannel - m_selected.channel;
284 return m_selected.channel;
292 return m_selected.lastChannel;
304 c0 = m_selected.channel;
305 c1 = m_selected.lastChannel;
316 m_selected.point.MoveTo( x, y );
324 m_selected.point = p;
332 m_selected.point = 0;
340 return m_selected.point;
358 m_selected.rectangle.Set( x0, y0, x1, y1 );
359 Clip( m_selected.rectangle );
372 SelectRectangle( p0.x, p0.y, p1.x, p1.y );
381 SelectRectangle( r.x0, r.y0, r.x1, r.y1 );
389 m_selected.rectangle.Set( 0, 0, m_width, m_height );
397 return m_selected.rectangle.IsPointOrLine();
406 return m_selected.rectangle.x0 <= 0 &&
407 m_selected.rectangle.y0 <= 0 &&
408 m_selected.rectangle.x1 >= m_width &&
409 m_selected.rectangle.y1 >= m_height;
417 return m_selected.rectangle;
430 return m_selected.channel == 0 &&
431 m_selected.lastChannel >= m_numberOfChannels-1 &&
432 m_selected.rectangle.x0 <= 0 &&
433 m_selected.rectangle.y0 <= 0 &&
434 m_selected.rectangle.x1 >= m_width &&
435 m_selected.rectangle.y1 >= m_height;
444 return size_type( m_selected.rectangle.Width() ) *
size_type( m_selected.rectangle.Height() );
457 return NumberOfSelectedPixels()*
size_type( NumberOfSelectedChannels() );
484 return m_selected.clippedLow || m_selected.clippedHigh;
497 return m_selected.clippedLow;
510 return m_selected.clippedHigh;
520 m_selected.clippedLow = enableLow;
521 m_selected.clippedHigh = enableHigh;
531 m_selected.clippedLow = !disableLow;
532 m_selected.clippedHigh = !disableHigh;
542 return m_selected.clipLow;
552 return m_selected.clipHigh;
562 m_selected.clipLow = clipLow;
563 if ( m_selected.clipHigh < m_selected.clipLow )
564 pcl::Swap( m_selected.clipLow, m_selected.clipHigh );
574 m_selected.clipHigh = clipHigh;
575 if ( m_selected.clipHigh < m_selected.clipLow )
576 pcl::Swap( m_selected.clipLow, m_selected.clipHigh );
587 if ( clipHigh < clipLow )
589 m_selected.clipLow = clipLow;
590 m_selected.clipHigh = clipHigh;
591 m_selected.clippedLow = m_selected.clippedHigh =
true;
603 m_selected.clipLow = 0;
604 m_selected.clipHigh = 1;
605 m_selected.clippedLow = m_selected.clippedHigh =
false;
631 ResetRangeClipping();
648 m_savedSelections.Append( m_selected );
661 if ( CanPopSelections() )
665 m_savedSelections.Remove( i );
676 return !m_savedSelections.IsEmpty();
693 if ( !rect.IsRect() )
695 rect = m_selected.rectangle;
696 if ( !rect.IsRect() )
718 channel = m_selected.channel;
722 if ( channel >= m_numberOfChannels )
754 if ( !ParseRect( rect ) || !ParseChannel( firstChannel ) )
757 if ( lastChannel < 0 )
759 lastChannel = m_selected.lastChannel;
760 if ( lastChannel < 0 )
763 if ( lastChannel >= m_numberOfChannels )
766 if ( lastChannel < firstChannel )
791 return ParseRect( rect ) && ParseChannel( channel );
811 return m_status.Callback();
830 m_status.SetCallback( callback );
861 return m_parallel ?
pcl::Min( (maxProcessors > 0) ? maxProcessors : m_maxProcessors,
899 return NumberOfThreads( (rowCount > 0) ? rowCount : Height(),
948 m_parallel ? ((maxProcessors > 0) ? maxProcessors : m_maxProcessors) : 1 );
987 : status( image.Status() )
1001 : status( a_status )
1071 template <
class thread>
1094 useAffinity =
false;
1098 for ( thread& t : threads )
1099 t.Start( ThreadPriority::DefaultMax, useAffinity ? n++ : -1 );
1103 waitTime += waitTime >> 2;
1109 if ( !i->Wait( waitTime ) )
1112 if ( ++i == threads.
End() )
1114 if ( data.
total > 0 )
1124 if ( data.
total > 0 )
1127 lastCount = data.
count;
1137 for ( thread& t : threads )
1139 for ( thread& t : threads )
1151 mutable selection_stack m_savedSelections;
1162 ImageGeometry::Swap( image );
1163 ImageColor::Swap( image );
1165 pcl::Swap( m_selected, image.m_selected );
1166 pcl::Swap( m_savedSelections, image.m_savedSelections );
1170 void ValidateChannelRange() const noexcept
1172 if ( m_numberOfChannels > 0 )
1176 else if ( m_selected.
channel >= m_numberOfChannels )
1177 m_selected.
channel = m_numberOfChannels-1;
1181 else if ( m_selected.
lastChannel >= m_numberOfChannels )
1193 #ifdef __PCL_BUILDING_PIXINSIGHT_APPLICATION
1194 friend class pi::SharedImage;
1202 #undef m_numberOfChannels
1226 #define INIT_THREAD_MONITOR() \
1227 size_type ___n___ = 0, ___n1___ = 0;
1314 #define UPDATE_THREAD_MONITOR( N ) \
1315 if ( ++___n1___ == (N) ) \
1317 if ( this->m_data.numThreads > 1 ) \
1319 if ( this->TryIsAborted() ) \
1322 if ( this->m_data.total > 0 ) \
1323 if ( this->m_data.mutex.TryLock() ) \
1325 this->m_data.count += ___n___; \
1326 this->m_data.mutex.Unlock(); \
1332 if ( this->m_data.total > 0 ) \
1333 this->m_data.status += (N); \
1335 ++this->m_data.status; \
1395 #define UPDATE_THREAD_MONITOR_CHUNK( N, chunkSize ) \
1396 if ( (___n1___ += (chunkSize)) == (N) ) \
1398 if ( this->m_data.numThreads > 1 ) \
1400 if ( this->TryIsAborted() ) \
1403 if ( this->m_data.total > 0 ) \
1404 if ( this->m_data.mutex.TryLock() ) \
1406 this->m_data.count += ___n___; \
1407 this->m_data.mutex.Unlock(); \
1413 if ( this->m_data.total > 0 ) \
1414 this->m_data.status += (N); \
1416 ++this->m_data.status; \
Base class of all two-dimensional images in PCL.
void ResetPoint() const noexcept
int NumberOfThreadsForRows(int rowCount=0, int rowWidth=0, int maxProcessors=0, size_type overheadLimitPx=1024u) const noexcept
void SelectAlphaChannels() const noexcept
bool IsLowRangeClippingEnabled() const noexcept
bool IsHighRangeClippingEnabled() const noexcept
void SelectChannelRange(int c0, int c1) const noexcept
void SetRangeClipLow(double clipLow) const noexcept
void GetSelectedChannelRange(int &c0, int &c1) const noexcept
bool CanPopSelections() const noexcept
void SelectRectangle(int x0, int y0, int x1, int y1) const noexcept
size_type NumberOfSelectedPixels() const noexcept
int NumberOfAlphaChannels() const noexcept
void EnableRangeClipping(bool enableLow=true, bool enableHigh=true) const noexcept
void ResetSelection() const noexcept
void SelectNominalChannels() const noexcept
int NumberOfNominalChannels() const noexcept
int LastSelectedChannel() const noexcept
double RangeClipHigh() const noexcept
~AbstractImage() override
void ResetRangeClipping() const noexcept
static void RunThreads(ReferenceArray< thread > &threads, ThreadData &data, bool useAffinity=true)
int NumberOfSelectedChannels() const noexcept
void SelectChannel(int c) const noexcept
bool IsCompletelySelected() const noexcept
int SelectedChannel() const noexcept
Array< size_type > OptimalThreadRows(int rowCount=0, int rowWidth=0, int maxProcessors=0, size_type overheadLimitPx=1024u) const noexcept
void SetRangeClipHigh(double clipHigh) const noexcept
bool ParseRect(Rect &rect) const noexcept
void SelectRectangle(const Point &p0, const Point &p1) const noexcept
size_type NumberOfNominalSamples() const noexcept
bool ParseChannel(int &channel) const noexcept
void PushSelections() const
int FirstSelectedChannel() const noexcept
void ResetSelections() const noexcept
bool IsRangeClippingEnabled() const noexcept
void SetStatusCallback(pcl::StatusCallback *callback) const noexcept
ImageSelections & Selections() const noexcept
pcl::StatusCallback * GetStatusCallback() const noexcept
const Rect & SelectedRectangle() const noexcept
double RangeClipLow() const noexcept
void PopSelections() const
pcl::StatusCallback * StatusCallback() const noexcept
void SelectRectangle(const Rect &r) const noexcept
StatusMonitor & Status() const noexcept
bool HasAlphaChannels() const noexcept
void SelectPoint(int x, int y) const noexcept
bool ParseSelection(Rect &rect, int &firstChannel, int &lastChannel) const noexcept
bool IsEmptySelection() const noexcept
void SetRangeClipping(double clipLow, double clipHigh) const noexcept
void SelectPoint(const Point &p) const noexcept
const Point & SelectedPoint() const noexcept
bool ParseSelection(Rect &rect, int &channel) const noexcept
size_type NumberOfAlphaSamples() const noexcept
void DisableRangeClipping(bool disableLow=true, bool disableHigh=true) const noexcept
size_type NumberOfSelectedSamples() const noexcept
int NumberOfThreads(size_type count, int maxProcessors=0, size_type overheadLimit=16u) const noexcept
bool IsFullSelection() const noexcept
void ResetChannelRange() const noexcept
A generic point in the two-dimensional space.
A generic rectangle in the two-dimensional space.
Implements color space properties of images.
ColorSpace::value_type color_space
Implements geometric properties of two-dimensional images.
Adaptive mutual exclusion lock variable.
A process using multiple concurrent execution threads.
void Swap(ParallelProcess &process) noexcept
An exception class signaling the interruption of a process.
Mutable ReferenceArray iterator.
Dynamic array of pointers to objects providing direct iteration and element access by reference.
void Destroy(iterator i, size_type n=1)
Provides status monitoring callback functions.
An asynchronous status monitoring system.
static unsigned RefreshRate()
static int NumberOfThreads(size_type count, size_type overheadLimit=1u)
static bool IsRootThread()
static Array< size_type > OptimalThreadLoads(size_type count, size_type overheadLimit=1u, int maxThreads=PCL_MAX_PROCESSORS)
void Swap(GenericPoint< T > &p1, GenericPoint< T > &p2) noexcept
constexpr const T & Min(const T &a, const T &b) noexcept
constexpr const T & Max(const T &a, const T &b) noexcept
int NumberOfNominalChannels(int colorSpace)
Thread synchronization data for status monitoring of parallel image processing tasks.
ThreadData(const AbstractImage &image, size_type N)
size_type count
current monitoring count.
Mutex mutex
Mutual exclusion for synchronized thread access.
StatusMonitor status
Status monitoring object.
size_type total
Total monitoring count.
ThreadData(const StatusMonitor &a_status, size_type N)
size_type numThreads
Number of concurrent threads being executed (set by RunThreads()).
A structure used to store rectangular image selections, channel ranges, anchor points,...
int lastChannel
Last selected channel.
int channel
First selected channel.