pushing
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -103,5 +103,6 @@
|
|||||||
"**/*.rpa": true,
|
"**/*.rpa": true,
|
||||||
"**/*.rpymc": true,
|
"**/*.rpymc": true,
|
||||||
"**/cache/": true
|
"**/cache/": true
|
||||||
}
|
},
|
||||||
|
"cmake.ignoreCMakeListsMissing": true
|
||||||
}
|
}
|
||||||
@@ -84,10 +84,10 @@ void Preview(Grid2& grid) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void livePreview(Grid2& grid) {
|
void livePreview(Grid2& grid, AnimationConfig config) {
|
||||||
std::lock_guard<std::mutex> lock(previewMutex);
|
std::lock_guard<std::mutex> lock(previewMutex);
|
||||||
|
|
||||||
currentPreviewFrame = grid.getGridAsFrame(frame::colormap::RGBA);
|
currentPreviewFrame = grid.getTempAsFrame(Vec2(0,0), Vec2(config.height,config.width), Vec2(256,256));
|
||||||
// Vec2 min;
|
// Vec2 min;
|
||||||
// Vec2 max;
|
// Vec2 max;
|
||||||
// grid.getBoundingBox(min, max);
|
// grid.getBoundingBox(min, max);
|
||||||
@@ -246,7 +246,7 @@ bool exportavi(std::vector<frame> frames, AnimationConfig config) {
|
|||||||
void mainLogic(const AnimationConfig& config, Shared& state, int gradnoise) {
|
void mainLogic(const AnimationConfig& config, Shared& state, int gradnoise) {
|
||||||
TIME_FUNCTION;
|
TIME_FUNCTION;
|
||||||
if (isGenerating) return; //apparently sometimes this function is called twice. dont know how, but this might resolve that.
|
if (isGenerating) return; //apparently sometimes this function is called twice. dont know how, but this might resolve that.
|
||||||
isGenerating = true;
|
|
||||||
try {
|
try {
|
||||||
Grid2 grid;
|
Grid2 grid;
|
||||||
if (gradnoise == 0) {
|
if (gradnoise == 0) {
|
||||||
@@ -273,7 +273,7 @@ void mainLogic(const AnimationConfig& config, Shared& state, int gradnoise) {
|
|||||||
if (!success) {
|
if (!success) {
|
||||||
std::cout << "yo! this failed in Preview" << std::endl;
|
std::cout << "yo! this failed in Preview" << std::endl;
|
||||||
}
|
}
|
||||||
|
isGenerating = true;
|
||||||
std::vector<frame> frames;
|
std::vector<frame> frames;
|
||||||
|
|
||||||
for (int i = 0; i < config.totalFrames; ++i){
|
for (int i = 0; i < config.totalFrames; ++i){
|
||||||
@@ -284,6 +284,7 @@ void mainLogic(const AnimationConfig& config, Shared& state, int gradnoise) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//expandPixel(grid,config,seeds);
|
//expandPixel(grid,config,seeds);
|
||||||
|
grid.diffuseTemperatures(1.0, 1.0, 1.0);
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(state.mutex);
|
std::lock_guard<std::mutex> lock(state.mutex);
|
||||||
state.grid = grid;
|
state.grid = grid;
|
||||||
@@ -291,7 +292,7 @@ void mainLogic(const AnimationConfig& config, Shared& state, int gradnoise) {
|
|||||||
state.currentFrame = i;
|
state.currentFrame = i;
|
||||||
|
|
||||||
// Print compression info for this frame
|
// Print compression info for this frame
|
||||||
if (i % 10 == 0 ) {
|
//if (i % 10 == 0 ) {
|
||||||
frame bgrframe;
|
frame bgrframe;
|
||||||
std::cout << "Processing frame " << i + 1 << "/" << config.totalFrames << std::endl;
|
std::cout << "Processing frame " << i + 1 << "/" << config.totalFrames << std::endl;
|
||||||
bgrframe = grid.getTempAsFrame(Vec2(0,0), Vec2(config.height,config.width), Vec2(256,256), frame::colormap::BGR);
|
bgrframe = grid.getTempAsFrame(Vec2(0,0), Vec2(config.height,config.width), Vec2(256,256), frame::colormap::BGR);
|
||||||
@@ -300,7 +301,7 @@ void mainLogic(const AnimationConfig& config, Shared& state, int gradnoise) {
|
|||||||
//BMPWriter::saveBMP(std::format("output/grayscalesource.{}.bmp", i), bgrframe);
|
//BMPWriter::saveBMP(std::format("output/grayscalesource.{}.bmp", i), bgrframe);
|
||||||
bgrframe.compressFrameLZ78();
|
bgrframe.compressFrameLZ78();
|
||||||
//bgrframe.printCompressionStats();
|
//bgrframe.printCompressionStats();
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
exportavi(frames,config);
|
exportavi(frames,config);
|
||||||
}
|
}
|
||||||
@@ -457,7 +458,7 @@ int main() {
|
|||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(state.mutex);
|
std::lock_guard<std::mutex> lock(state.mutex);
|
||||||
if (state.hasNewFrame) {
|
if (state.hasNewFrame) {
|
||||||
livePreview(state.grid);
|
livePreview(state.grid, config);
|
||||||
state.hasNewFrame = false;
|
state.hasNewFrame = false;
|
||||||
previewText = "Generating... Frame: " + std::to_string(state.currentFrame);
|
previewText = "Generating... Frame: " + std::to_string(state.currentFrame);
|
||||||
}
|
}
|
||||||
@@ -486,7 +487,7 @@ int main() {
|
|||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(state.mutex);
|
std::lock_guard<std::mutex> lock(state.mutex);
|
||||||
if (state.hasNewFrame) {
|
if (state.hasNewFrame) {
|
||||||
livePreview(state.grid);
|
livePreview(state.grid, config);
|
||||||
state.hasNewFrame = false;
|
state.hasNewFrame = false;
|
||||||
previewText = "Generating... Frame: " + std::to_string(state.currentFrame);
|
previewText = "Generating... Frame: " + std::to_string(state.currentFrame);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,8 +201,6 @@ protected:
|
|||||||
//grid max
|
//grid max
|
||||||
Vec2 gridMax;
|
Vec2 gridMax;
|
||||||
|
|
||||||
//neighbor map
|
|
||||||
//std::unordered_map<size_t, std::vector<size_t>> neighborMap;
|
|
||||||
float neighborRadius = 1.0f;
|
float neighborRadius = 1.0f;
|
||||||
|
|
||||||
//TODO: spatial map
|
//TODO: spatial map
|
||||||
@@ -1202,6 +1200,112 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void diffuseTemperatures(double thermalDiffusivity, double timeStep, double gridSpacing = 1.0) {
|
||||||
|
TIME_FUNCTION;
|
||||||
|
|
||||||
|
if (tempMap.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a copy of current temperatures to avoid modifying while iterating
|
||||||
|
std::unordered_map<size_t, double> newTemps;
|
||||||
|
newTemps.reserve(tempMap.size());
|
||||||
|
|
||||||
|
// Diffuse heat for each point
|
||||||
|
for (const auto& [id, tempObj] : tempMap) {
|
||||||
|
Vec2 position = Positions.at(id);
|
||||||
|
double currentTemp = tempObj.temp;
|
||||||
|
|
||||||
|
// Get nearby points for diffusion
|
||||||
|
std::unordered_map<Vec2, Temp> neighbors;
|
||||||
|
std::vector<size_t> neighborIDs = spatialGrid.queryRange(position, neighborRadius * 2.0); // Use larger radius for temp diffusion
|
||||||
|
|
||||||
|
for (size_t neighborID : neighborIDs) {
|
||||||
|
if (neighborID != id && tempMap.find(neighborID) != tempMap.end()) {
|
||||||
|
Vec2 neighborPos = Positions.at(neighborID);
|
||||||
|
neighbors.emplace(neighborPos, tempMap.at(neighborID));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Diffuse heat using the existing function from Temp class
|
||||||
|
double newTemp = Temp::diffuseHeat(position, neighbors, currentTemp,
|
||||||
|
thermalDiffusivity, timeStep, gridSpacing);
|
||||||
|
|
||||||
|
newTemps[id] = newTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update temperatures
|
||||||
|
for (const auto& [id, newTemp] : newTemps) {
|
||||||
|
tempMap.at(id).temp = newTemp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void diffuseTemperaturesWeighted(double thermalDiffusivity, double timeStep) {
|
||||||
|
TIME_FUNCTION;
|
||||||
|
|
||||||
|
if (tempMap.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a copy of current temperatures to avoid modifying while iterating
|
||||||
|
std::unordered_map<size_t, double> newTemps;
|
||||||
|
newTemps.reserve(tempMap.size());
|
||||||
|
|
||||||
|
// Diffuse heat for each point using weighted method
|
||||||
|
for (const auto& [id, tempObj] : tempMap) {
|
||||||
|
Vec2 position = Positions.at(id);
|
||||||
|
double currentTemp = tempObj.temp;
|
||||||
|
|
||||||
|
// Get nearby points for diffusion
|
||||||
|
std::unordered_map<Vec2, Temp> neighbors;
|
||||||
|
std::vector<size_t> neighborIDs = spatialGrid.queryRange(position, neighborRadius * 2.0);
|
||||||
|
|
||||||
|
for (size_t neighborID : neighborIDs) {
|
||||||
|
if (neighborID != id && tempMap.find(neighborID) != tempMap.end()) {
|
||||||
|
Vec2 neighborPos = Positions.at(neighborID);
|
||||||
|
neighbors.emplace(neighborPos, tempMap.at(neighborID));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Diffuse heat using the weighted method
|
||||||
|
double newTemp = Temp::diffuseHeatWeighted(position, neighbors, currentTemp,
|
||||||
|
thermalDiffusivity, timeStep);
|
||||||
|
|
||||||
|
newTemps[id] = newTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update temperatures
|
||||||
|
for (const auto& [id, newTemp] : newTemps) {
|
||||||
|
tempMap.at(id).temp = newTemp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optional: Diffuse temperature for a specific point
|
||||||
|
double diffuseTemperatureAtPoint(size_t id, double thermalDiffusivity, double timeStep, double gridSpacing = 1.0) {
|
||||||
|
if (tempMap.find(id) == tempMap.end()) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 position = Positions.at(id);
|
||||||
|
double currentTemp = tempMap.at(id).temp;
|
||||||
|
|
||||||
|
// Get nearby points
|
||||||
|
std::unordered_map<Vec2, Temp> neighbors;
|
||||||
|
std::vector<size_t> neighborIDs = spatialGrid.queryRange(position, neighborRadius * 2.0);
|
||||||
|
|
||||||
|
for (size_t neighborID : neighborIDs) {
|
||||||
|
if (neighborID != id && tempMap.find(neighborID) != tempMap.end()) {
|
||||||
|
Vec2 neighborPos = Positions.at(neighborID);
|
||||||
|
neighbors.emplace(neighborPos, tempMap.at(neighborID));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double newTemp = Temp::diffuseHeat(position, neighbors, currentTemp,
|
||||||
|
thermalDiffusivity, timeStep, gridSpacing);
|
||||||
|
|
||||||
|
tempMap.at(id).temp = newTemp;
|
||||||
|
return newTemp;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ protected:
|
|||||||
public:
|
public:
|
||||||
double temp;
|
double temp;
|
||||||
Temp(float temp) : temp(temp) {
|
Temp(float temp) : temp(temp) {
|
||||||
//std::cout << "setting temp to: " << temp << std::endl;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Temp(const Vec2& testPos, const std::unordered_map<Vec2, Temp>& others) {
|
Temp(const Vec2& testPos, const std::unordered_map<Vec2, Temp>& others) {
|
||||||
@@ -133,7 +132,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (validNeighbors > 0) {
|
if (validNeighbors > 0) {
|
||||||
laplacian /= (gridSpacing * gridSpacing);
|
laplacian /= (validNeighbors * gridSpacing * gridSpacing);
|
||||||
|
|
||||||
double tempChange = thermalDiffusivity * timeStep * laplacian;
|
double tempChange = thermalDiffusivity * timeStep * laplacian;
|
||||||
return currentTemp + tempChange;
|
return currentTemp + tempChange;
|
||||||
|
|||||||
Reference in New Issue
Block a user