Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSprayClusterBasedDistribution Class Reference

Class that can generate randomly distributed values in the range [0..1] that follow a distribution that clusters the values towards 0 or 1. More...

#include <KisSprayRandomDistributions.h>

+ Inheritance diagram for KisSprayClusterBasedDistribution:

Public Member Functions

 KisSprayClusterBasedDistribution ()
 Construct an invalid KisSprayClusterBasedDistribution.
 
 KisSprayClusterBasedDistribution (double clusteringAmount)
 Construct a new cluster based distribution.
 
- Public Member Functions inherited from KisSprayFunctionBasedDistribution
bool isValid () const
 Return if this object is correctly initialized and can be used to generate values.
 
 KisSprayFunctionBasedDistribution ()
 Construct an invalid KisSprayFunctionBasedDistribution.
 
 KisSprayFunctionBasedDistribution (const KisSprayFunctionBasedDistribution &other)
 
template<typename Function >
 KisSprayFunctionBasedDistribution (int numberOfSamples, double a, double b, Function f)
 Construct a new distribution.
 
double max () const
 Return the maximum value that this distribution can produce.
 
double min () const
 Return the minimum value that this distribution can produce.
 
double operator() (KisRandomSourceSP rs) const
 Get a random value between min and max that follows the distribution.
 
KisSprayFunctionBasedDistributionoperator= (const KisSprayFunctionBasedDistribution &rhs)
 
 ~KisSprayFunctionBasedDistribution ()
 

Additional Inherited Members

- Protected Member Functions inherited from KisSprayFunctionBasedDistribution
template<typename Function >
void initialize (size_t numberOfSamples, double a, double b, Function f)
 Function used to setup the distribution and put it in a valid state. See the constructor for the explanation of the parameters.
 

Detailed Description

Class that can generate randomly distributed values in the range [0..1] that follow a distribution that clusters the values towards 0 or 1.

Definition at line 165 of file KisSprayRandomDistributions.h.

Constructor & Destructor Documentation

◆ KisSprayClusterBasedDistribution() [1/2]

KisSprayClusterBasedDistribution::KisSprayClusterBasedDistribution ( )

Construct an invalid KisSprayClusterBasedDistribution.

Definition at line 266 of file KisSprayRandomDistributions.cpp.

267{}

◆ KisSprayClusterBasedDistribution() [2/2]

KisSprayClusterBasedDistribution::KisSprayClusterBasedDistribution ( double clusteringAmount)
explicit

Construct a new cluster based distribution.

Parameters
clusteringAmountA value in the range [-100..100] that indicates how and how much the generated values should cluster. A positive clustering amount will make generated values cluster towards 0 whereas a negative amount will cluster them towards 1. The bigger the clustering amount, the more pronounced will be the clustering, and the smaller it is, the more evenly distributed the values will be

Definition at line 269 of file KisSprayRandomDistributions.cpp.

270{
271 KIS_SAFE_ASSERT_RECOVER_RETURN(clusteringAmount >= -100.0 && clusteringAmount <= 100.0);
272
273 if (clusteringAmount == 0.0) {
274 // Uniform distribution basically
276 [](double)
277 {
278 return 1.0;
279 }
280 );
281 return;
282 }
283 const double sigma = 1.0 / std::abs(clusteringAmount);
284 const double m_c1 = 2.0 * sigma * sigma;
285 if (clusteringAmount < 0.0) {
286 KisSprayFunctionBasedDistribution::initialize(1000, 1.0 - std::min(1.0, sigma * 4.0), 1.0,
287 [m_c1](double x)
288 {
289 const double xx = 1.0 - x;
290 return std::exp(-(xx * xx / m_c1));
291 }
292 );
293 } else {
294 KisSprayFunctionBasedDistribution::initialize(1000, 0.0, std::min(1.0, sigma * 4.0),
295 [m_c1](double x)
296 {
297 return std::exp(-(x * x / m_c1));
298 }
299 );
300 }
301}
void initialize(size_t numberOfSamples, double a, double b, Function f)
Function used to setup the distribution and put it in a valid state. See the constructor for the expl...
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References KisSprayFunctionBasedDistribution::initialize(), and KIS_SAFE_ASSERT_RECOVER_RETURN.


The documentation for this class was generated from the following files: