Skip to content

Commit

Permalink
Uncertain grid seed updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nyoungbq committed Oct 18, 2023
1 parent 05dcc24 commit dcc41d2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "UncertainRegularGridSampleSurfaceMesh.hpp"

#include "complex/DataStructure/DataArray.hpp"
#include "complex/DataStructure/DataGroup.hpp"

#include <random>

Expand Down Expand Up @@ -39,14 +38,7 @@ void UncertainRegularGridSampleSurfaceMesh::generatePoints(std::vector<Point3Df>

std::random_device randomDevice; // Will be used to obtain a seed for the random number engine
std::mt19937 generator(randomDevice()); // Standard mersenne_twister_engine seeded with rd()
std::mt19937::result_type seed = m_InputValues->SeedValue;

if(!m_InputValues->UseSeed)
{
seed = static_cast<std::mt19937::result_type>(std::chrono::steady_clock::now().time_since_epoch().count());
}

generator.seed(seed);
generator.seed(m_InputValues->SeedValue);
std::uniform_real_distribution<float32> distribution(0.0F, 1.0F);

for(usize k = 0; k < dims[2]; k++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace complex
{
struct COMPLEXCORE_EXPORT UncertainRegularGridSampleSurfaceMeshInputValues
{
bool UseSeed;
uint64 SeedValue;
VectorUInt64Parameter::ValueType Dimensions;
VectorFloat32Parameter::ValueType Spacing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ Parameters UncertainRegularGridSampleSurfaceMeshFilter::parameters() const
Parameters params;

// Create the parameter descriptors that are needed for this filter
params.insertSeparator(Parameters::Separator{"Optional Variables"});
params.insertSeparator(Parameters::Separator{"Seeded Randomness"});
params.insertLinkableParameter(std::make_unique<BoolParameter>(k_UseSeed_Key, "Use Seed for Random Generation", "When true the user will be able to put in a seed for random generation", false));
params.insert(std::make_unique<NumberParameter<uint64>>(k_SeedValue_Key, "Seed", "The seed fed into the random generator", std::mt19937::default_seed));
params.insert(std::make_unique<DataObjectNameParameter>(k_SeedArrayName_Key, "Stored Seed Value Array Name", "", "_Uncertain_Regular_Grid_Sample_Surface_Mesh_Seed_Value_"));

params.insertSeparator(Parameters::Separator{"Input Parameters"});
params.insert(std::make_unique<VectorUInt64Parameter>(k_Dimensions_Key, "Number of Cells per Axis", "The dimensions of the created Image geometry", std::vector<uint64>{128, 128, 128},
Expand Down Expand Up @@ -102,6 +103,7 @@ IFilter::PreflightResult UncertainRegularGridSampleSurfaceMeshFilter::preflightI
auto pImageGeomPathValue = filterArgs.value<DataPath>(k_ImageGeomPath_Key);
auto pCellAMNameValue = filterArgs.value<std::string>(k_CellAMName_Key);
auto pFeatureIdsArrayNameValue = filterArgs.value<std::string>(k_FeatureIdsArrayName_Key);
auto pSeedArrayNameValue = filterArgs.value<std::string>(k_SeedArrayName_Key);

PreflightResult preflightResult;
complex::Result<OutputActions> resultOutputActions;
Expand All @@ -125,6 +127,11 @@ IFilter::PreflightResult UncertainRegularGridSampleSurfaceMeshFilter::preflightI
resultOutputActions.value().appendAction(std::move(createDataGroupAction));
}

{
auto createAction = std::make_unique<CreateArrayAction>(DataType::uint64, std::vector<usize>{1}, std::vector<usize>{1}, DataPath({pSeedArrayNameValue}));
resultOutputActions.value().appendAction(std::move(createAction));
}

// Return both the resultOutputActions and the preflightUpdatedValues via std::move()
return {std::move(resultOutputActions), std::move(preflightUpdatedValues)};
}
Expand All @@ -133,11 +140,18 @@ IFilter::PreflightResult UncertainRegularGridSampleSurfaceMeshFilter::preflightI
Result<> UncertainRegularGridSampleSurfaceMeshFilter::executeImpl(DataStructure& dataStructure, const Arguments& filterArgs, const PipelineFilter* pipelineNode, const MessageHandler& messageHandler,
const std::atomic_bool& shouldCancel) const
{
auto seed = filterArgs.value<std::mt19937_64::result_type>(k_SeedValue_Key);
if(!filterArgs.value<bool>(k_UseSeed_Key))
{
seed = static_cast<std::mt19937_64::result_type>(std::chrono::steady_clock::now().time_since_epoch().count());
}

// Store Seed Value in Top Level Array
dataStructure.getDataRefAs<UInt64Array>(DataPath({filterArgs.value<std::string>(k_SeedArrayName_Key)}))[0] = seed;

UncertainRegularGridSampleSurfaceMeshInputValues inputValues;

inputValues.UseSeed = filterArgs.value<bool>(k_UseSeed_Key);
inputValues.SeedValue = filterArgs.value<uint64>(k_SeedValue_Key);
inputValues.SeedValue = seed;
inputValues.Dimensions = filterArgs.value<VectorUInt64Parameter::ValueType>(k_Dimensions_Key);
inputValues.Spacing = filterArgs.value<VectorFloat32Parameter::ValueType>(k_Spacing_Key);
inputValues.Origin = filterArgs.value<VectorFloat32Parameter::ValueType>(k_Origin_Key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class COMPLEXCORE_EXPORT UncertainRegularGridSampleSurfaceMeshFilter : public IF
static inline constexpr StringLiteral k_FeatureIdsArrayName_Key = "feature_ids_array_name";
static inline constexpr StringLiteral k_UseSeed_Key = "use_seed";
static inline constexpr StringLiteral k_SeedValue_Key = "seed_value";
static inline constexpr StringLiteral k_SeedArrayName_Key = "seed_array_name";
static inline constexpr StringLiteral k_Dimensions_Key = "dimensions";

/**
Expand Down

0 comments on commit dcc41d2

Please sign in to comment.