File indexing completed on 2024-05-19 04:25:10
0001 /* 0002 * SPDX-FileCopyrightText: 2023 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef KISSAMPLERECTITERATOR_H 0007 #define KISSAMPLERECTITERATOR_H 0008 0009 #include "kritaglobal_export.h" 0010 0011 #include <boost/iterator_adaptors.hpp> 0012 0013 #include <QSharedDataPointer> 0014 #include <QRectF> 0015 0016 0017 /** 0018 * A simple generator-style iterator that samples the passed rectangle 0019 * (QRectF) with semi-random points. 0020 * 0021 * The first _nine_ points returned by the iterator correspond to 0022 * the corners and midpoints of the rectangle. From 10th and further 0023 * the iterator returns "random" samples inside the rectangle generated 0024 * by a fixed Halton sequence. 0025 * 0026 * Usage: 0027 * \code{.cpp} 0028 * 0029 * KisSampleRectIterator sampler(rect); 0030 * while (1) { 0031 * const QPointF sampledPoint = *sampler++; 0032 * /// ... do something ... 0033 * } 0034 * 0035 * \endcode 0036 */ 0037 class KRITAGLOBAL_EXPORT KisSampleRectIterator 0038 : public boost::iterator_facade<KisSampleRectIterator, 0039 QPointF, 0040 boost::forward_traversal_tag, 0041 QPointF> 0042 { 0043 public: 0044 KisSampleRectIterator(); 0045 KisSampleRectIterator(const QRectF &rect); 0046 KisSampleRectIterator(const KisSampleRectIterator &rhs); 0047 KisSampleRectIterator(KisSampleRectIterator &&rhs); 0048 KisSampleRectIterator& operator=(const KisSampleRectIterator &rhs); 0049 KisSampleRectIterator& operator=(KisSampleRectIterator &&rhs); 0050 ~KisSampleRectIterator(); 0051 0052 public: 0053 int numSamples() const; 0054 0055 private: 0056 friend class boost::iterator_core_access; 0057 0058 void increment(); 0059 QPointF dereference() const; 0060 0061 private: 0062 struct HaltonSampler; 0063 QSharedDataPointer<HaltonSampler> m_sampler; 0064 0065 QRectF m_rect; 0066 int m_index = 0; 0067 }; 0068 0069 #endif // KISSAMPLERECTITERATOR_H