Пример #1
0
	void Worley::SquareTest(int xi, int yi, float x, float y, std::map<float, Vector2f>& featurePoints) const
	{
		int ii = xi & 255;
		int jj = yi & 255;

		std::size_t seed = m_permutations[ii + m_permutations[jj]];

		//On initialise notre rng avec seed
		std::minstd_rand0 randomNumberGenerator(static_cast<unsigned int>(seed));

		//On prend un nombre de points à déterminer dans le cube, compris entre 1 et 8
		std::size_t m = (seed & 7) + 1;

		//On calcule les emplacements des différents points
		for(std::size_t i(0) ; i < m; ++i)
		{
			Nz::Vector2f featurePoint;
			featurePoint.x = (randomNumberGenerator() & 1023) / 1023.f + static_cast<float>(xi);
			featurePoint.y = (randomNumberGenerator() & 1023) / 1023.f + static_cast<float>(yi);

			// TODO : Check order is correct
			float distance = std::sqrt((featurePoint.x - x) * (featurePoint.x - x) +
									   (featurePoint.y - y) * (featurePoint.y - y));

			//Insertion dans la liste triée
			featurePoints[distance] = featurePoint;
		}
	}
Пример #2
0
void NzWorley2D::SquareTest(int xi, int yi, float x, float y)
{
    ii = xi & 255;
    jj = yi & 255;

    seed = perm[ii +     perm[jj]];

    //On initialise notre rng avec seed
    randomNumberGenerator.seed(seed);

    //On prend un nombre de points à déterminer dans le cube, compris entre 1 et 8
    unsigned int m = (seed & 7) + 1;

    //On calcule les emplacements des différents points
    for(unsigned int i(0) ; i < m ; ++i)
    {
        NzVector2f featurePoint;
        featurePoint.x = (randomNumberGenerator() & 1023) / 1023.f + static_cast<float>(xi);
        featurePoint.y = (randomNumberGenerator() & 1023) / 1023.f + static_cast<float>(yi);

        //Insertion dans la liste triée
        featurePoints[featurePoint.Distance(NzVector2f(x,y))] = featurePoint;
    }
}
Пример #3
0
int UsherBase::attemptToInsertParticlesInRegion
(
    int numberOfParticlesToInsert,
    double targetPotential, 
    double regionXMin,
    double regionYMin,
    double regionZMin,
    double regionXMax,
    double regionYMax,
    double regionZMax
)
{
    // Random number generator (see
    // cppreference.com/w/cpp/numeric/random/uniform_real_distribution)
    std::random_device randomDevice;
    std::mt19937 randomNumberGenerator (randomDevice());
    std::uniform_real_distribution<> randomX (regionXMin, regionXMax);
    std::uniform_real_distribution<> randomY (regionYMin, regionYMax);
    std::uniform_real_distribution<> randomZ (regionZMin, regionZMax);

    int insertedParticlesCount = 0;

    for (int n = 0; n < numberOfParticlesToInsert; ++n)
    {
        for (int attempt = 0; attempt < maxAttempts; ++attempt)
        {

            try
            {
                auto startX = randomX (randomNumberGenerator);
                auto startY = randomY (randomNumberGenerator);
                auto startZ = randomZ (randomNumberGenerator);


                Vector3D r = findPositionWithPotential 
                (
                    targetPotential, startX, startY, startZ
                );

                if 
                (
                    r.x >= regionXMin && r.x <= regionXMax && 
                    r.y >= regionYMin && r.y <= regionYMax && 
                    r.z >= regionZMin && r.z <= regionZMax
                )
                {
                    insertOneAtPosition (r.x, r.y, r.z); 
                    ++insertedParticlesCount;
                    break;
                }

            }
            catch (UsherTryAgain& e)
            {
                // Debug: std::cout << e.what() << std::endl;
            }

        }  
    }

    if (insertedParticlesCount < numberOfParticlesToInsert)
    {
        throw UsherFailToInsertAll 
        (
            numberOfParticlesToInsert,
            insertedParticlesCount
        );
    }

    return insertedParticlesCount;

}