From 32ff33d8ab05f2d16c9481ac2d9c4077d0663532 Mon Sep 17 00:00:00 2001 From: Christian Heinemann Date: Thu, 21 Nov 2024 17:36:37 +0100 Subject: [PATCH] + further unit tests for strength changes + constructor test repaired --- .../EngineGpuKernels/RadiationProcessor.cuh | 4 +- source/EngineInterface/RadiationSource.h | 6 +- .../SimulationParametersEditService.cpp | 42 ++- .../SimulationParametersEditService.h | 2 +- source/EngineTests/ConstructorTests.cpp | 9 +- .../SimulationParametersEditServiceTests.cpp | 305 +++++++++++++++++- source/Gui/RadiationSourcesWindow.cpp | 40 ++- .../AuxiliaryDataParserService.cpp | 6 +- .../LegacyAuxiliaryDataParserService.cpp | 2 +- 9 files changed, 363 insertions(+), 53 deletions(-) diff --git a/source/EngineGpuKernels/RadiationProcessor.cuh b/source/EngineGpuKernels/RadiationProcessor.cuh index 1cd079a22..eda8473b3 100644 --- a/source/EngineGpuKernels/RadiationProcessor.cuh +++ b/source/EngineGpuKernels/RadiationProcessor.cuh @@ -230,7 +230,7 @@ __inline__ __device__ void RadiationProcessor::radiate(SimulationData& data, flo auto sumActiveRatios = 0.0f; for (int i = 0; i < numActiveSources; ++i) { auto index = data.preprocessedSimulationData.activeRadiationSources.getActiveSource(i); - sumActiveRatios += cudaSimulationParameters.radiationSources[index].strengthRatio; + sumActiveRatios += cudaSimulationParameters.radiationSources[index].strength; } if (sumActiveRatios > 0) { auto randomRatioValue = data.numberGen1.random(1.0f); @@ -239,7 +239,7 @@ __inline__ __device__ void RadiationProcessor::radiate(SimulationData& data, flo auto matchSource = false; for (int i = 0; i < numActiveSources; ++i) { sourceIndex = data.preprocessedSimulationData.activeRadiationSources.getActiveSource(i); - sumActiveRatios += cudaSimulationParameters.radiationSources[sourceIndex].strengthRatio; + sumActiveRatios += cudaSimulationParameters.radiationSources[sourceIndex].strength; if (randomRatioValue <= sumActiveRatios) { matchSource = true; break; diff --git a/source/EngineInterface/RadiationSource.h b/source/EngineInterface/RadiationSource.h index 1cb28da79..a11477af1 100644 --- a/source/EngineInterface/RadiationSource.h +++ b/source/EngineInterface/RadiationSource.h @@ -36,8 +36,8 @@ enum RadiationSourceShapeType_ struct RadiationSource { - float strengthRatio = 0.0f; - bool strengthRatioPinned = false; + float strength = 0.0f; + bool strengthPinned = false; float posX = 0; float posY = 0; float velX = 0; @@ -64,7 +64,7 @@ struct RadiationSource } } return posX == other.posX && posY == other.posY && velX == other.velX && velY == other.velY && useAngle == other.useAngle && angle == other.angle - && strengthRatio == other.strengthRatio && strengthRatioPinned == other.strengthRatioPinned; + && strength == other.strength && strengthPinned == other.strengthPinned; } bool operator!=(RadiationSource const& other) const { return !operator==(other); } }; diff --git a/source/EngineInterface/SimulationParametersEditService.cpp b/source/EngineInterface/SimulationParametersEditService.cpp index 446db6ad3..1c1926922 100644 --- a/source/EngineInterface/SimulationParametersEditService.cpp +++ b/source/EngineInterface/SimulationParametersEditService.cpp @@ -9,7 +9,7 @@ auto SimulationParametersEditService::getRadiationStrengths(SimulationParameters auto baseStrength = 1.0f; for (int i = 0; i < parameters.numRadiationSources; ++i) { - baseStrength -= parameters.radiationSources[i].strengthRatio; + baseStrength -= parameters.radiationSources[i].strength; } if (baseStrength < 0) { baseStrength = 0; @@ -17,8 +17,8 @@ auto SimulationParametersEditService::getRadiationStrengths(SimulationParameters result.values.emplace_back(baseStrength); for (int i = 0; i < parameters.numRadiationSources; ++i) { - result.values.emplace_back(parameters.radiationSources[i].strengthRatio); - if (parameters.radiationSources[i].strengthRatioPinned) { + result.values.emplace_back(parameters.radiationSources[i].strength); + if (parameters.radiationSources[i].strengthPinned) { result.pinned.insert(i + 1); } } @@ -28,30 +28,41 @@ auto SimulationParametersEditService::getRadiationStrengths(SimulationParameters return result; } -void SimulationParametersEditService::applyRadiationStrengthValues(SimulationParameters& parameters, RadiationStrengths const& strengths) +void SimulationParametersEditService::applyRadiationStrengths(SimulationParameters& parameters, RadiationStrengths const& strengths) { CHECK(parameters.numRadiationSources + 1 == strengths.values.size()); + parameters.baseStrengthRatioPinned = strengths.pinned.contains(0); for (int i = 0; i < parameters.numRadiationSources; ++i) { - parameters.radiationSources[i].strengthRatio = strengths.values.at(i + 1); + parameters.radiationSources[i].strength = strengths.values.at(i + 1); + parameters.radiationSources[i].strengthPinned = strengths.pinned.contains(i + 1); } } void SimulationParametersEditService::adaptRadiationStrengths(RadiationStrengths& strengths, RadiationStrengths& origStrengths, int changeIndex) const { - if (strengths.values.size() == strengths.pinned.size()) { + auto pinnedValues = strengths.pinned; + pinnedValues.insert(changeIndex); + + if (strengths.values.size() == pinnedValues.size()) { strengths = origStrengths; return; } + for (auto const& strength : strengths.values) { + if (strength < 0) { + strengths = origStrengths; + return; + } + } auto sum = 0.0f; - for (auto const& ratio : strengths.values) { - sum += ratio; + for (auto const& strength : strengths.values) { + sum += strength; } auto diff = sum - 1; auto sumWithoutFixed = 0.0f; for (int i = 0; i < strengths.values.size(); ++i) { - if (!strengths.pinned.contains(i)) { + if (!pinnedValues.contains(i)) { sumWithoutFixed += strengths.values.at(i); } } @@ -64,14 +75,14 @@ void SimulationParametersEditService::adaptRadiationStrengths(RadiationStrengths auto reduction = 1.0f - diff / sumWithoutFixed; for (int i = 0; i < strengths.values.size(); ++i) { - if (!strengths.pinned.contains(i)) { + if (!pinnedValues.contains(i)) { strengths.values.at(i) *= reduction; } } } else { for (int i = 0; i < strengths.values.size(); ++i) { - if (!strengths.pinned.contains(i)) { - strengths.values.at(i) = -diff / toFloat(strengths.values.size() - strengths.pinned.size()); + if (!pinnedValues.contains(i)) { + strengths.values.at(i) = -diff / toFloat(strengths.values.size() - pinnedValues.size()); } } } @@ -104,11 +115,11 @@ auto SimulationParametersEditService::calcRadiationStrengthsForAddingSpot(Radiat auto SimulationParametersEditService::calcRadiationStrengthsForDeletingSpot( RadiationStrengths const& strengths, int deleteIndex) const -> RadiationStrengths { - auto numRemainingUnpinned = 0; + auto existsUnpinned = false; auto sumRemainingUnpinnedStrengths = 0.0f; for (int i = 0; i < strengths.values.size(); ++i) { if (!strengths.pinned.contains(i) && i != deleteIndex) { - ++numRemainingUnpinned; + existsUnpinned = true; sumRemainingUnpinnedStrengths += strengths.values.at(i); } } @@ -129,6 +140,9 @@ auto SimulationParametersEditService::calcRadiationStrengthsForDeletingSpot( } } } + if (!existsUnpinned) { + result.pinned.erase(0); + } return result; } diff --git a/source/EngineInterface/SimulationParametersEditService.h b/source/EngineInterface/SimulationParametersEditService.h index 4ada3cd4d..b4cae0430 100644 --- a/source/EngineInterface/SimulationParametersEditService.h +++ b/source/EngineInterface/SimulationParametersEditService.h @@ -19,7 +19,7 @@ class SimulationParametersEditService public: RadiationStrengths getRadiationStrengths(SimulationParameters const& parameters) const; - void applyRadiationStrengthValues(SimulationParameters& parameters, RadiationStrengths const& strengths); + void applyRadiationStrengths(SimulationParameters& parameters, RadiationStrengths const& strengths); void adaptRadiationStrengths(RadiationStrengths& strengths, RadiationStrengths& origStrengths, int changeIndex) const; RadiationStrengths calcRadiationStrengthsForAddingSpot(RadiationStrengths const& strengths) const; diff --git a/source/EngineTests/ConstructorTests.cpp b/source/EngineTests/ConstructorTests.cpp index cfc2b889c..54e4d1f94 100644 --- a/source/EngineTests/ConstructorTests.cpp +++ b/source/EngineTests/ConstructorTests.cpp @@ -591,7 +591,12 @@ TEST_F(ConstructorTests, constructFirstCell_noSeparation) auto genome = GenomeDescriptionService::get().convertDescriptionToBytes( GenomeDescription() .setHeader(GenomeHeaderDescription().setSeparateConstruction(false).setStiffness(0.35f)) - .setCells({CellGenomeDescription().setColor(2).setExecutionOrderNumber(4).setInputExecutionOrderNumber(5).setOutputBlocked(true)})); + .setCells({CellGenomeDescription() + .setCellFunction(ConstructorGenomeDescription().setMakeSelfCopy()) + .setColor(2) + .setExecutionOrderNumber(4) + .setInputExecutionOrderNumber(5) + .setOutputBlocked(true)})); DataDescription data; data.addCell( @@ -627,7 +632,7 @@ TEST_F(ConstructorTests, constructFirstCell_noSeparation) EXPECT_EQ(4, actualConstructedCell.executionOrderNumber); EXPECT_EQ(5, actualConstructedCell.inputExecutionOrderNumber); EXPECT_TRUE(actualConstructedCell.outputBlocked); - EXPECT_EQ(CellFunction_None, actualConstructedCell.getCellFunctionType()); + EXPECT_EQ(CellFunction_Constructor, actualConstructedCell.getCellFunctionType()); EXPECT_EQ(123, actualConstructedCell.activationTime); EXPECT_TRUE(approxCompare(0.35f, actualConstructedCell.stiffness, 0.01f)); EXPECT_TRUE(approxCompare(_parameters.cellNormalEnergy[0], actualConstructedCell.energy)); diff --git a/source/EngineTests/SimulationParametersEditServiceTests.cpp b/source/EngineTests/SimulationParametersEditServiceTests.cpp index 0dd03c1d4..19187f6a4 100644 --- a/source/EngineTests/SimulationParametersEditServiceTests.cpp +++ b/source/EngineTests/SimulationParametersEditServiceTests.cpp @@ -19,8 +19,8 @@ TEST_F(SimulationParametersEditServiceTests, getRadiationStrengths) { SimulationParameters parameters; parameters.numRadiationSources = 2; - parameters.radiationSources[0].strengthRatio = 0.3f; - parameters.radiationSources[1].strengthRatio = 0.6f; + parameters.radiationSources[0].strength = 0.3f; + parameters.radiationSources[1].strength = 0.6f; auto strengths = SimulationParametersEditService::get().getRadiationStrengths(parameters); @@ -35,10 +35,13 @@ TEST_F(SimulationParametersEditServiceTests, applyRadiationStrengthValues) SimulationParameters parameters; parameters.numRadiationSources = 2; - SimulationParametersEditService::get().applyRadiationStrengthValues(parameters, strengths); + SimulationParametersEditService::get().applyRadiationStrengths(parameters, strengths); - checkApproxEqual(0.3f, parameters.radiationSources[0].strengthRatio); - checkApproxEqual(0.6f, parameters.radiationSources[1].strengthRatio); + EXPECT_TRUE(parameters.baseStrengthRatioPinned); + checkApproxEqual(0.3f, parameters.radiationSources[0].strength); + EXPECT_FALSE(parameters.radiationSources[0].strengthPinned); + checkApproxEqual(0.6f, parameters.radiationSources[1].strength); + EXPECT_TRUE(parameters.radiationSources[1].strengthPinned); } TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_increase_allUnpinned) @@ -49,7 +52,7 @@ TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_increase_al RadiationStrengths strengths; strengths.values = {0.1f, 0.5f, 0.6f}; - strengths.pinned = {1}; + strengths.pinned = {}; SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); @@ -57,4 +60,294 @@ TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_increase_al checkApproxEqual(0.1f * factor, strengths.values[0]); checkApproxEqual(0.5f, strengths.values[1]); checkApproxEqual(0.6f * factor, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_increase_basePinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {0}; + + RadiationStrengths strengths; + strengths.values = {0.1f, 0.5f, 0.6f}; + strengths.pinned = {0}; + + SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); + + checkApproxEqual(0.1f, strengths.values[0]); + checkApproxEqual(0.5f, strengths.values[1]); + checkApproxEqual(0.4f, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_increase_spotPinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {2}; + + RadiationStrengths strengths; + strengths.values = {0.1f, 0.4f, 0.6f}; + strengths.pinned = {2}; + + SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); + + checkApproxEqual(0.0f, strengths.values[0]); + checkApproxEqual(0.4f, strengths.values[1]); + checkApproxEqual(0.6f, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_increase_allPinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {0, 1, 2}; + + RadiationStrengths strengths; + strengths.values = {0.1f, 0.5f, 0.6f}; + strengths.pinned = {0, 1, 2}; + + SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); + + checkApproxEqual(0.1f, strengths.values[0]); + checkApproxEqual(0.3f, strengths.values[1]); + checkApproxEqual(0.6f, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_decrease_allUnpinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {}; + + RadiationStrengths strengths; + strengths.values = {0.1f, 0.1f, 0.6f}; + strengths.pinned = {}; + + SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); + + auto factor = 1 + 0.2f / 0.7f; + checkApproxEqual(0.1f * factor, strengths.values[0]); + checkApproxEqual(0.1f, strengths.values[1]); + checkApproxEqual(0.6f * factor, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_decrease_basePinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {0}; + + RadiationStrengths strengths; + strengths.values = {0.1f, 0.1f, 0.6f}; + strengths.pinned = {0}; + + SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); + + checkApproxEqual(0.1f, strengths.values[0]); + checkApproxEqual(0.1f, strengths.values[1]); + checkApproxEqual(0.8f, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_decrease_spotPinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {2}; + + RadiationStrengths strengths; + strengths.values = {0.1f, 0.1f, 0.6f}; + strengths.pinned = {2}; + + SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); + + checkApproxEqual(0.3f, strengths.values[0]); + checkApproxEqual(0.1f, strengths.values[1]); + checkApproxEqual(0.6f, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_decrease_allPinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {0, 1, 2}; + + RadiationStrengths strengths; + strengths.values = {0.1f, 0.1f, 0.6f}; + strengths.pinned = {0, 1, 2}; + + SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); + + checkApproxEqual(0.1f, strengths.values[0]); + checkApproxEqual(0.3f, strengths.values[1]); + checkApproxEqual(0.6f, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_exceed_aboveOne_allUnpinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {}; + + RadiationStrengths strengths; + strengths.values = {0.1f, 1.1f, 0.6f}; + strengths.pinned = {}; + + SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); + + checkApproxEqual(0.0f, strengths.values[0]); + checkApproxEqual(1.0f, strengths.values[1]); + checkApproxEqual(0.0f, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_exceed_aboveOne_basePinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {0}; + + RadiationStrengths strengths; + strengths.values = {0.1f, 1.1f, 0.6f}; + strengths.pinned = {0}; + + SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); + + checkApproxEqual(0.1f, strengths.values[0]); + checkApproxEqual(0.9f, strengths.values[1]); + checkApproxEqual(0.0f, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_exceed_aboveOne_zonePinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {2}; + + RadiationStrengths strengths; + strengths.values = {0.1f, 1.1f, 0.6f}; + strengths.pinned = {2}; + + SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); + + checkApproxEqual(0.0f, strengths.values[0]); + checkApproxEqual(0.4f, strengths.values[1]); + checkApproxEqual(0.6f, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_exceed_negative_explicit) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {}; + + RadiationStrengths strengths; + strengths.values = {0.1f, -0.1f, 0.6f}; + strengths.pinned = {}; + + SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); + + checkApproxEqual(0.1f, strengths.values[0]); + checkApproxEqual(0.3f, strengths.values[1]); + checkApproxEqual(0.6f, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, adaptRadiationStrengths_exceed_negative_implicit) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {2}; + + RadiationStrengths strengths; + strengths.values = {0.1f, 0.5f, 0.6f}; + strengths.pinned = {2}; + + SimulationParametersEditService::get().adaptRadiationStrengths(strengths, origStrengths, 1); + + checkApproxEqual(0.0f, strengths.values[0]); + checkApproxEqual(0.4f, strengths.values[1]); + checkApproxEqual(0.6f, strengths.values[2]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, calcRadiationStrengthsForAddingSpot_allUnpinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {}; + + auto strengths = SimulationParametersEditService::get().calcRadiationStrengthsForAddingSpot(origStrengths); + + ASSERT_EQ(4, strengths.values.size()); + + auto factor = 1.0f - 1.0f / 4; + checkApproxEqual(0.1f * factor, strengths.values[0]); + checkApproxEqual(0.3f * factor, strengths.values[1]); + checkApproxEqual(0.6f * factor, strengths.values[2]); + checkApproxEqual(0.25f, strengths.values[3]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, calcRadiationStrengthsForAddingSpot_basePinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {0}; + + auto strengths = SimulationParametersEditService::get().calcRadiationStrengthsForAddingSpot(origStrengths); + + ASSERT_EQ(4, strengths.values.size()); + + auto factor = 1.0f - 1.0f / 3; + checkApproxEqual(0.1f, strengths.values[0]); + checkApproxEqual(0.3f * factor, strengths.values[1]); + checkApproxEqual(0.6f * factor, strengths.values[2]); + checkApproxEqual((0.3f + 0.6f) * (1.0f - factor), strengths.values[3]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + +TEST_F(SimulationParametersEditServiceTests, calcRadiationStrengthsForAddingSpot_spotPinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {2}; + + auto strengths = SimulationParametersEditService::get().calcRadiationStrengthsForAddingSpot(origStrengths); + + ASSERT_EQ(4, strengths.values.size()); + + auto factor = 1.0f - 1.0f / 3; + checkApproxEqual(0.1f * factor, strengths.values[0]); + checkApproxEqual(0.3f * factor, strengths.values[1]); + checkApproxEqual(0.6f, strengths.values[2]); + checkApproxEqual((0.1f + 0.3f) * (1.0f - factor), strengths.values[3]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); +} + + +TEST_F(SimulationParametersEditServiceTests, calcRadiationStrengthsForAddingSpot_allPinned) +{ + RadiationStrengths origStrengths; + origStrengths.values = {0.1f, 0.3f, 0.6f}; + origStrengths.pinned = {0, 1, 2}; + + auto strengths = SimulationParametersEditService::get().calcRadiationStrengthsForAddingSpot(origStrengths); + + ASSERT_EQ(4, strengths.values.size()); + + checkApproxEqual(0.1f, strengths.values[0]); + checkApproxEqual(0.3f, strengths.values[1]); + checkApproxEqual(0.6f, strengths.values[2]); + checkApproxEqual(0.0f, strengths.values[3]); + EXPECT_EQ(origStrengths.pinned, strengths.pinned); } diff --git a/source/Gui/RadiationSourcesWindow.cpp b/source/Gui/RadiationSourcesWindow.cpp index 2c5fac8e2..5b00e072b 100644 --- a/source/Gui/RadiationSourcesWindow.cpp +++ b/source/Gui/RadiationSourcesWindow.cpp @@ -71,9 +71,9 @@ void RadiationSourcesWindow::processBaseTab() auto& editService = SimulationParametersEditService::get(); - auto ratios = editService.getRadiationStrengths(parameters); - auto origRatios = editService.getRadiationStrengths(origParameters); - auto newRatios = ratios; + auto strength = editService.getRadiationStrengths(parameters); + auto origStrengths = editService.getRadiationStrengths(origParameters); + auto editedStrength = strength; if (AlienImGui::SliderFloat( AlienImGui::SliderFloatParameters() .name("Strength ratio") @@ -81,13 +81,12 @@ void RadiationSourcesWindow::processBaseTab() .min(0.0f) .max(1.0f) .format("%.3f") - .defaultValue(&origRatios.values.front()), - &newRatios.values.front(), + .defaultValue(&origStrengths.values.front()), + &editedStrength.values.front(), nullptr, ¶meters.baseStrengthRatioPinned)) { - newRatios.pinned.insert(0); - editService.adaptRadiationStrengths(newRatios, ratios, 0); - editService.applyRadiationStrengthValues(parameters, newRatios); + editService.adaptRadiationStrengths(editedStrength, strength, 0); + editService.applyRadiationStrengths(parameters, editedStrength); } if (parameters != lastParameters) { @@ -130,7 +129,7 @@ bool RadiationSourcesWindow::processSourceTab(int index) } } - auto ratios = editService.getRadiationStrengths(parameters); + auto origStrengths = editService.getRadiationStrengths(parameters); if (AlienImGui::SliderFloat( AlienImGui::SliderFloatParameters() .name("Strength ratio") @@ -138,15 +137,14 @@ bool RadiationSourcesWindow::processSourceTab(int index) .min(0.0f) .max(1.0f) .format("%.3f") - .defaultValue(&origSource.strengthRatio), - &source.strengthRatio, + .defaultValue(&origSource.strength), + &source.strength, nullptr, - &source.strengthRatioPinned)) { - auto newRatios = ratios; - newRatios.values.at(index + 1) = source.strengthRatio; - newRatios.pinned.insert(index + 1); - editService.adaptRadiationStrengths(newRatios, ratios, index + 1); - editService.applyRadiationStrengthValues(parameters, newRatios); + &source.strengthPinned)) { + auto editedStrengths = origStrengths; + editedStrengths.values.at(index + 1) = source.strength; // Set new strength + editService.adaptRadiationStrengths(editedStrengths, origStrengths, index + 1); + editService.applyRadiationStrengths(parameters, editedStrengths); } auto getMousePickerEnabledFunc = [&]() { return SimulationInteractionController::get().isPositionSelectionMode(); }; @@ -238,8 +236,8 @@ void RadiationSourcesWindow::onAppendTab() ++parameters.numRadiationSources; ++origParameters.numRadiationSources; - editService.applyRadiationStrengthValues(parameters, newStrengths); - editService.applyRadiationStrengthValues(origParameters, newStrengths); + editService.applyRadiationStrengths(parameters, newStrengths); + editService.applyRadiationStrengths(origParameters, newStrengths); _simulationFacade->setSimulationParameters(parameters); _simulationFacade->setOriginalSimulationParameters(origParameters); @@ -261,8 +259,8 @@ void RadiationSourcesWindow::onDeleteTab(int index) --parameters.numRadiationSources; --origParameters.numRadiationSources; - editService.applyRadiationStrengthValues(parameters, newStrengths); - editService.applyRadiationStrengthValues(origParameters, newStrengths); + editService.applyRadiationStrengths(parameters, newStrengths); + editService.applyRadiationStrengths(origParameters, newStrengths); _simulationFacade->setSimulationParameters(parameters); _simulationFacade->setOriginalSimulationParameters(origParameters); diff --git a/source/PersisterInterface/AuxiliaryDataParserService.cpp b/source/PersisterInterface/AuxiliaryDataParserService.cpp index ae06e4897..f9b89ee1c 100644 --- a/source/PersisterInterface/AuxiliaryDataParserService.cpp +++ b/source/PersisterInterface/AuxiliaryDataParserService.cpp @@ -670,7 +670,7 @@ namespace tree, parameters.baseStrengthRatioPinned, defaultParameters.baseStrengthRatioPinned, - "simulation parameters.particle sources.base strength ratio pinned", + "simulation parameters.particle sources.base strength pinned", parserTask); for (int index = 0; index < parameters.numRadiationSources; ++index) { std::string base = "simulation parameters.particle sources." + std::to_string(index) + "."; @@ -681,8 +681,8 @@ namespace ParameterParser::encodeDecode(tree, source.velX, defaultSource.velX, base + "vel.x", parserTask); ParameterParser::encodeDecode(tree, source.velY, defaultSource.velY, base + "vel.y", parserTask); ParameterParser::encodeDecode(tree, source.useAngle, defaultSource.useAngle, base + "use angle", parserTask); - ParameterParser::encodeDecode(tree, source.strengthRatio, defaultSource.strengthRatio, base + "strength ratio", parserTask); - ParameterParser::encodeDecode(tree, source.strengthRatioPinned, defaultSource.strengthRatioPinned, base + "strength ratio pinned", parserTask); + ParameterParser::encodeDecode(tree, source.strength, defaultSource.strength, base + "strength", parserTask); + ParameterParser::encodeDecode(tree, source.strengthPinned, defaultSource.strengthPinned, base + "strength pinned", parserTask); ParameterParser::encodeDecode(tree, source.angle, defaultSource.angle, base + "angle", parserTask); ParameterParser::encodeDecode(tree, source.shapeType, defaultSource.shapeType, base + "shape.type", parserTask); if (source.shapeType == SpotShapeType_Circular) { diff --git a/source/PersisterInterface/LegacyAuxiliaryDataParserService.cpp b/source/PersisterInterface/LegacyAuxiliaryDataParserService.cpp index aecaf7e22..ac6a3f392 100644 --- a/source/PersisterInterface/LegacyAuxiliaryDataParserService.cpp +++ b/source/PersisterInterface/LegacyAuxiliaryDataParserService.cpp @@ -175,7 +175,7 @@ void LegacyAuxiliaryDataParserService::updateParametersAndFeaturesForLegacyFiles if (parameters.numRadiationSources > 0) { auto strengthRatio = 1.0f / parameters.numRadiationSources; for (int i = 0; i < parameters.numRadiationSources; ++i) { - parameters.radiationSources[i].strengthRatio = strengthRatio; + parameters.radiationSources[i].strength = strengthRatio; } parameters.baseStrengthRatioPinned = true; }