Skip to content

Commit 1355be6

Browse files
committed
ENH: Route PGRFSimulation logging through observer info() method
* Add defaulted virtual info() to ISimulationObserver — no-op by default so existing test doubles need no changes * ConsoleObserver overrides info() to emit via spdlog (CLI output unchanged) * FilterObserver overrides info() to forward through the simplnx IFilter::MessageHandler with Type::Info (no raw console lines from the DREAM3D-NX filter) * Convert all five direct spdlog::info() calls in PGRFSimulation::run to observer->info() with nullptr guard; drop the redundant per-field spdlog line that duplicated the updateProgress message * Remove unused #include <spdlog/spdlog.h> from PGRFSimulation.cpp Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
1 parent c79ed1e commit 1355be6

5 files changed

Lines changed: 47 additions & 21 deletions

File tree

src/LibMTRSim/ISimulationObserver.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class LIBMTRSIM_EXPORT ISimulationObserver
3030
/// names it. `total <= 0` means "indeterminate".
3131
virtual void updateProgress(int64_t done, int64_t total, const std::string& message) = 0;
3232

33+
/// Emit an informational/diagnostic message (not progress). Default: no-op.
34+
virtual void info(const std::string& message)
35+
{
36+
(void)message;
37+
}
38+
3339
/// Polled at checkpoints; returning true stops the simulation early.
3440
[[nodiscard]] virtual bool shouldCancel() const = 0;
3541
};

src/LibMTRSim/PGRFSimulation.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <algorithm>
1010
#include <cmath>
1111
#include <fmt/format.h>
12-
#include <spdlog/spdlog.h>
1312
#include <stdexcept>
1413

1514
namespace mtrsim
@@ -55,12 +54,16 @@ PGRFResult PGRFSimulation::run(const SimulationParams& params, ISimulationObserv
5554
throw std::invalid_argument("PGRFSimulation: thetaList must have one row per latent Gaussian");
5655
}
5756

58-
spdlog::info("PGRFSimulation: grid {}x{}x{} = {} voxels, {} components, {} "
59-
"latent fields",
60-
nx, ny, nz, N, numComponents, numGaussians);
57+
if(observer != nullptr)
58+
{
59+
observer->info(fmt::format("PGRFSimulation: grid {}x{}x{} = {} voxels, {} components, {} latent fields", nx, ny, nz, N, numComponents, numGaussians));
60+
}
6161

6262
// ── Select assignment-rule thresholds ────────────────────────────────────
63-
spdlog::info("PGRFSimulation: selecting assignment rule thresholds...");
63+
if(observer != nullptr)
64+
{
65+
observer->info("PGRFSimulation: selecting assignment rule thresholds...");
66+
}
6467
AssignmentRule ar(m_Rng);
6568
const AssignmentRuleThresholds thresholds = ar.selectThresholds(params.volumeFractions);
6669

@@ -84,7 +87,6 @@ PGRFResult PGRFSimulation::run(const SimulationParams& params, ISimulationObserv
8487
}
8588
observer->updateProgress(h, numGaussians, fmt::format("Simulating latent Gaussian field {}/{}", h + 1, numGaussians));
8689
}
87-
spdlog::info("PGRFSimulation: simulating latent Gaussian Y{} ...", h + 1);
8890

8991
const auto& thetaRow = params.thetaList[static_cast<std::size_t>(h)];
9092
if(thetaRow.size() < 3)
@@ -98,14 +100,20 @@ PGRFResult PGRFSimulation::run(const SimulationParams& params, ISimulationObserv
98100
}
99101

100102
// ── Apply assignment rule ─────────────────────────────────────────────────
101-
spdlog::info("PGRFSimulation: applying assignment rule...");
103+
if(observer != nullptr)
104+
{
105+
observer->info("PGRFSimulation: applying assignment rule...");
106+
}
102107
const Eigen::VectorXi mtrIndex = ar.evaluate(zAll, thresholds);
103108

104109
// Log empirical volume fractions for verification
105110
for(int j = 1; j <= numComponents; ++j)
106111
{
107112
const int count = (mtrIndex.array() == j).count();
108-
spdlog::info(" P{} empirical = {:.3f} (target {:.3f})", j, static_cast<double>(count) / static_cast<double>(N), params.volumeFractions[static_cast<std::size_t>(j - 1)]);
113+
if(observer != nullptr)
114+
{
115+
observer->info(fmt::format(" P{} empirical = {:.3f} (target {:.3f})", j, static_cast<double>(count) / static_cast<double>(N), params.volumeFractions[static_cast<std::size_t>(j - 1)]));
116+
}
109117
}
110118

111119
return PGRFResult{mtrIndex, zAll};

src/LibMTRSim/SimulationObservers.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class ConsoleObserver : public ISimulationObserver
4343
}
4444
}
4545
}
46+
void info(const std::string& message) override
47+
{
48+
spdlog::info("{}", message);
49+
}
50+
4651
[[nodiscard]] bool shouldCancel() const override
4752
{
4853
return false;

src/MTRSim/Filters/Algorithms/MTRSim.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class FilterObserver : public mtrsim::ISimulationObserver
3939
m_MessageHandler(IFilter::Message::Type::Progress, message, progress);
4040
}
4141

42+
void info(const std::string& message) override
43+
{
44+
m_MessageHandler(IFilter::Message::Type::Info, message);
45+
}
46+
4247
[[nodiscard]] bool shouldCancel() const override
4348
{
4449
return m_ShouldCancel.load();

src/MTRSim/Filters/MTRSimFilter.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,6 @@ Parameters MTRSimFilter::parameters() const
7070
{
7171
Parameters params;
7272

73-
params.insertSeparator(Parameters::Separator{"Input ODF"});
74-
params.insert(std::make_unique<GeometrySelectionParameter>(k_InputOdfGeometry_Key, "Input ODF Geometry", "Image Geometry holding the ODF (from the Read/Compute ODF filters).", DataPath{},
75-
GeometrySelectionParameter::AllowedTypes{IGeometry::Type::Image}));
76-
params.insert(std::make_unique<MultiArraySelectionParameter>(k_OdfComponentArrays_Key, "ODF Component Arrays",
77-
"Ordered list of per-component ODF cell arrays. Order maps to Volume "
78-
"Fraction columns.",
79-
MultiArraySelectionParameter::ValueType{}, MultiArraySelectionParameter::AllowedTypes{IArray::ArrayType::DataArray},
80-
GetAllNumericTypes(), MultiArraySelectionParameter::AllowedComponentShapes{{1}}));
81-
8273
params.insertSeparator(Parameters::Separator{"Configuration Source"});
8374
params.insertLinkableParameter(std::make_unique<BoolParameter>(k_UseConfigFile_Key, "Load Simulation Parameters from Config File",
8475
"When ON, read volume fractions, theta list, physical size/spacing, and seed from an MTRSim JSON config "
@@ -116,20 +107,31 @@ Parameters MTRSimFilter::parameters() const
116107
params.insert(std::make_unique<VectorFloat32Parameter>(k_PhysicalSpacing_Key, "Physical Spacing (microns)", "Voxel spacing X,Y,Z.", std::vector<float32>{0.02f, 0.02f, 0.02f},
117108
std::vector<std::string>{"X", "Y", "Z"}));
118109

110+
params.insertSeparator(Parameters::Separator{"Input ODF"});
111+
params.insert(std::make_unique<GeometrySelectionParameter>(k_InputOdfGeometry_Key, "Input ODF Geometry", "Image Geometry holding the ODF (from the Read/Compute ODF filters).", DataPath{},
112+
GeometrySelectionParameter::AllowedTypes{IGeometry::Type::Image}));
113+
params.insert(std::make_unique<MultiArraySelectionParameter>(k_OdfComponentArrays_Key, "ODF Component Arrays",
114+
"Ordered list of per-component ODF cell arrays. Order maps to Volume "
115+
"Fraction columns.",
116+
MultiArraySelectionParameter::ValueType{}, MultiArraySelectionParameter::AllowedTypes{IArray::ArrayType::DataArray},
117+
GetAllNumericTypes(), MultiArraySelectionParameter::AllowedComponentShapes{{1}}));
118+
119119
params.insertSeparator(Parameters::Separator{"Random Number Seed Parameters"});
120120
params.insertLinkableParameter(std::make_unique<BoolParameter>(k_UseSeed_Key, "Use Seed for Random Generation", "When true the user can supply a fixed seed.", false));
121121
params.insert(std::make_unique<NumberParameter<uint64>>(k_SeedValue_Key, "Seed Value", "The seed fed into the random generator.", std::mt19937::default_seed));
122122
params.insert(std::make_unique<DataObjectNameParameter>(k_SeedArrayName_Key, "Stored Seed Value Array Name", "Top-level array recording the seed used.", "MTRSim SeedValue"));
123123

124124
params.insertSeparator(Parameters::Separator{"Output Data Object(s)"});
125-
params.insertLinkableParameter(std::make_unique<BoolParameter>(k_GeneratePolarColoring_Key, "Generate Polar Coloring",
126-
"Create a 3-component UInt8 RGB array using the MATLAB polar color "
127-
"mapping.",
128-
false));
125+
129126
params.insert(std::make_unique<DataGroupCreationParameter>(k_OutputGeometry_Key, "Output Image Geometry", "Path of the new microstructure Image Geometry.", DataPath({"MTR Microstructure"})));
130127
params.insert(std::make_unique<DataObjectNameParameter>(k_CellAttrMatName_Key, "Cell Attribute Matrix Name", "Name of the created cell AttributeMatrix.", "Cell Data"));
131128
params.insert(std::make_unique<DataObjectNameParameter>(k_MtrIdsArrayName_Key, "MTR Ids Array Name", "Int32 per-voxel MTR component id (1-based).", "MTRIds"));
132129
params.insert(std::make_unique<DataObjectNameParameter>(k_EulersArrayName_Key, "Euler Angles Array Name", "Float32 3-component Bunge Euler angles [rad].", "Eulers"));
130+
131+
params.insertLinkableParameter(std::make_unique<BoolParameter>(k_GeneratePolarColoring_Key, "Generate Polar Coloring",
132+
"Create a 3-component UInt8 RGB array using the MATLAB polar color "
133+
"mapping.",
134+
false));
133135
params.insert(std::make_unique<DataObjectNameParameter>(k_PolarColorsArrayName_Key, "Polar Colors Array Name", "UInt8 3-component RGB polar coloring.", "Polar Colors"));
134136

135137
params.linkParameters(k_UseSeed_Key, k_SeedValue_Key, true);

0 commit comments

Comments
 (0)