#include ".\pointjitterer.h" #include "ADFCreator_debug_flags.h" #include #include #include SDF::PointJitterer::~PointJitterer(void) { } SDF::PointJitterer::PointJitterer(unsigned int rand_seed, double jitter_box_halflength) : jitter_box_halflength(jitter_box_halflength) { __LOG__("A PointJitterer is resetting the rand seed to: " << rand_seed); srand(rand_seed); } SDF::PointJitterer::PointJitterer(double jitter_box_halflength) : jitter_box_halflength(jitter_box_halflength) { // Use the time as the rand seed unsigned int seed = (unsigned int) time(NULL); __LOG__("A PointJitterer is resetting the rand seed to: " << seed << " - this is the current time"); srand(seed); } // Helper // Returns a random double in [-1, 1] double random_unit() { double absval = ((double)rand()) / ((double) RAND_MAX); // Now generate another number to determine sign int sign = rand(); // If sign is even, return pos // Otherwise, return a negative if(sign % 2 == 0) { return absval; } else { return -1.0f * absval; } } Point SDF::PointJitterer::jitter(const Point &p) { //--------------------------------- // Randomly generate jitter proportions // These are values in [-1, 1] //--------------------------------- const double px = random_unit(); const double py = random_unit(); const double pz = random_unit(); //--------------------------------- // Create the jittering vector //--------------------------------- const Vector jit( this->jitter_box_halflength * px, this->jitter_box_halflength * py, this->jitter_box_halflength * pz); return p + jit; }