stuff working better now. still kinda meh, but its decent enough.
This commit is contained in:
1
makefile
1
makefile
@@ -18,6 +18,7 @@ CXXFLAGS += $(PKG_FLAGS)
|
|||||||
|
|
||||||
# Source files
|
# Source files
|
||||||
SRC := $(SRC_DIR)/g2temp.cpp
|
SRC := $(SRC_DIR)/g2temp.cpp
|
||||||
|
#SRC := $(SRC_DIR)/g2chromatic2.cpp
|
||||||
SRC += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
|
SRC += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
|
||||||
SRC += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
|
SRC += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
|
||||||
SRC += $(SRC_DIR)/stb_image.cpp
|
SRC += $(SRC_DIR)/stb_image.cpp
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ void mainLogic(const AnimationConfig& config, Shared& state, int gradnoise) {
|
|||||||
if (gradnoise == 0) {
|
if (gradnoise == 0) {
|
||||||
grid = setup(config);
|
grid = setup(config);
|
||||||
} else if (gradnoise == 1) {
|
} else if (gradnoise == 1) {
|
||||||
grid = grid.noiseGenGrid(0,0,config.height, config.width, 0.01, 1.0, false, config.noisemod);
|
grid = grid.noiseGenGridTemps(0,0,config.height, config.width, 0.01, 1.0, false, config.noisemod);
|
||||||
}
|
}
|
||||||
grid.setDefault(Vec4(0,0,0,0));
|
grid.setDefault(Vec4(0,0,0,0));
|
||||||
{
|
{
|
||||||
@@ -261,7 +261,7 @@ void mainLogic(const AnimationConfig& config, Shared& state, int gradnoise) {
|
|||||||
state.hasNewFrame = true;
|
state.hasNewFrame = true;
|
||||||
state.currentFrame = 0;
|
state.currentFrame = 0;
|
||||||
}
|
}
|
||||||
pickTempSeeds(grid,config);
|
//pickTempSeeds(grid,config);
|
||||||
|
|
||||||
//std::vector<std::tuple<size_t, Vec2, Vec4>> seeds = pickSeeds(grid, config);
|
//std::vector<std::tuple<size_t, Vec2, Vec4>> seeds = pickSeeds(grid, config);
|
||||||
std::cout << "generated grid" << std::endl;
|
std::cout << "generated grid" << std::endl;
|
||||||
@@ -294,7 +294,7 @@ void mainLogic(const AnimationConfig& config, Shared& state, int gradnoise) {
|
|||||||
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.getGridAsFrame(frame::colormap::BGR);
|
bgrframe = grid.getTempAsFrame(Vec2(0,0), Vec2(config.height,config.width), Vec2(256,256), frame::colormap::BGR);
|
||||||
frames.push_back(bgrframe);
|
frames.push_back(bgrframe);
|
||||||
//bgrframe.decompress();
|
//bgrframe.decompress();
|
||||||
//BMPWriter::saveBMP(std::format("output/grayscalesource.{}.bmp", i), bgrframe);
|
//BMPWriter::saveBMP(std::format("output/grayscalesource.{}.bmp", i), bgrframe);
|
||||||
@@ -407,7 +407,7 @@ int main() {
|
|||||||
static int i4 = 8;
|
static int i4 = 8;
|
||||||
static int noisemod = 42;
|
static int noisemod = 42;
|
||||||
static float fs = 1.0;
|
static float fs = 1.0;
|
||||||
int gradnoise = 0;
|
int gradnoise = 1;
|
||||||
|
|
||||||
std::future<void> mainlogicthread;
|
std::future<void> mainlogicthread;
|
||||||
Shared state;
|
Shared state;
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
Vec4 newc = Vec4(alpha,alpha,alpha,1.0);
|
Vec4 newc = Vec4(alpha,alpha,alpha,1.0);
|
||||||
colors.push_back(newc);
|
colors.push_back(newc);
|
||||||
poses.push_back(pos);
|
poses.push_back(Vec2(x,y));
|
||||||
sizes.push_back(1.0f);
|
sizes.push_back(1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -619,13 +619,13 @@ public:
|
|||||||
size_t id = Positions.set(poses[i]);
|
size_t id = Positions.set(poses[i]);
|
||||||
Colors[id] = colors[i];
|
Colors[id] = colors[i];
|
||||||
Sizes[id] = sizes[i];
|
Sizes[id] = sizes[i];
|
||||||
tempMap.emplace(id, Temp(temps[i]));
|
Temp temptemp = Temp(temps[i]);
|
||||||
|
tempMap.insert({id, temptemp});
|
||||||
spatialGrid.insert(id,poses[i]);
|
spatialGrid.insert(id,poses[i]);
|
||||||
newids.push_back(id);
|
newids.push_back(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
shrinkIfNeeded();
|
shrinkIfNeeded();
|
||||||
// updateNeighborMap();
|
|
||||||
|
|
||||||
usable = true;
|
usable = true;
|
||||||
return newids;
|
return newids;
|
||||||
@@ -663,13 +663,6 @@ public:
|
|||||||
// Initialize RGB data with default background color
|
// Initialize RGB data with default background color
|
||||||
std::vector<Vec4> rgbaBuffer(width * height, Vec4(0,0,0,0));
|
std::vector<Vec4> rgbaBuffer(width * height, Vec4(0,0,0,0));
|
||||||
|
|
||||||
// for (int x = minCorner.x; x < maxCorner.x; x++) {
|
|
||||||
// for (int y = minCorner.y; x < maxCorner.y; y++){
|
|
||||||
// Vec2 pos = Vec2(x,y);
|
|
||||||
// size_t posID = getPositionVec(pos, 1.0f, false);
|
|
||||||
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// For each position in the grid, find the corresponding pixel
|
// For each position in the grid, find the corresponding pixel
|
||||||
for (const auto& [id, pos] : Positions) {
|
for (const auto& [id, pos] : Positions) {
|
||||||
size_t size = Sizes.at(id);
|
size_t size = Sizes.at(id);
|
||||||
@@ -993,59 +986,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// void updateNeighborMap() {
|
|
||||||
// //std::cout << "updateNeighborMap()" << std::endl;
|
|
||||||
// TIME_FUNCTION;
|
|
||||||
// neighborMap.clear();
|
|
||||||
// optimizeSpatialGrid();
|
|
||||||
|
|
||||||
// // For each object, find nearby neighbors
|
|
||||||
// float radiusSq = neighborRadius * neighborRadius;
|
|
||||||
// #pragma omp parallel for
|
|
||||||
// for (const auto& [id1, pos1] : Positions) {
|
|
||||||
// std::vector<size_t> neighbors;
|
|
||||||
// //std::vector<size_t> candidate_ids = spatialGrid.queryRange(pos1, neighborRadius);
|
|
||||||
// std::unordered_set<size_t> candidate_idset = spatialGrid.find(pos1);
|
|
||||||
// std::vector<size_t> candidate_ids;
|
|
||||||
// candidate_ids.reserve(candidate_idset.size());
|
|
||||||
// for (auto it = candidate_idset.begin(); it != candidate_idset.end();) {
|
|
||||||
// candidate_ids.push_back(std::move(candidate_idset.extract(it++).value()));
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// for (size_t id2 : candidate_ids) {
|
|
||||||
// if (id1 != id2) { // && Positions.at(id1).distanceSquared(Positions.at(id2)) <= radiusSq) {
|
|
||||||
// neighbors.push_back(id2);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// #pragma omp critical
|
|
||||||
// neighborMap[id1] = std::move(neighbors);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Update neighbor map for a single object
|
|
||||||
// void updateNeighborForID(size_t id) {
|
|
||||||
// TIME_FUNCTION;
|
|
||||||
// Vec2 pos_it = Positions.at(id);
|
|
||||||
|
|
||||||
// std::vector<size_t> neighbors;
|
|
||||||
// float radiusSq = neighborRadius * neighborRadius;
|
|
||||||
|
|
||||||
// for (const auto& [id2, pos2] : Positions) {
|
|
||||||
// if (id != id2 && pos_it.distanceSquared(pos2) <= radiusSq) {
|
|
||||||
// neighbors.push_back(id2);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// neighborMap[id] = std::move(neighbors);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Get neighbors for an ID
|
|
||||||
// const std::vector<size_t>& getNeighbors(size_t id) const {
|
|
||||||
// static const std::vector<size_t> empty;
|
|
||||||
// auto it = neighborMap.find(id);
|
|
||||||
// return it != neighborMap.end() ? it->second : empty;
|
|
||||||
// }
|
|
||||||
|
|
||||||
std::vector<size_t> getNeighbors(size_t id) const {
|
std::vector<size_t> getNeighbors(size_t id) const {
|
||||||
Vec2 pos = Positions.at(id);
|
Vec2 pos = Positions.at(id);
|
||||||
std::vector<size_t> candidates = spatialGrid.queryRange(pos, neighborRadius);
|
std::vector<size_t> candidates = spatialGrid.queryRange(pos, neighborRadius);
|
||||||
@@ -1071,7 +1011,6 @@ public:
|
|||||||
optimizeSpatialGrid();
|
optimizeSpatialGrid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//temp stuff
|
//temp stuff
|
||||||
void setTemp(const Vec2 pos, double temp) {
|
void setTemp(const Vec2 pos, double temp) {
|
||||||
size_t id = getOrCreatePositionVec(pos, 0.0, true);
|
size_t id = getOrCreatePositionVec(pos, 0.0, true);
|
||||||
@@ -1092,33 +1031,38 @@ public:
|
|||||||
std::vector<Vec2> poses;
|
std::vector<Vec2> poses;
|
||||||
std::vector<Vec4> colors;
|
std::vector<Vec4> colors;
|
||||||
std::vector<float> sizes;
|
std::vector<float> sizes;
|
||||||
|
std::vector<float> temps;
|
||||||
|
int callnumber = 0;
|
||||||
for (int x = minx; x < maxx; x++) {
|
for (int x = minx; x < maxx; x++) {
|
||||||
for (int y = miny; y < maxy; y++) {
|
for (int y = miny; y < maxy; y++) {
|
||||||
float nx = (x+noisemod)/(maxx+EPSILON)/0.1;
|
float nx = (x+noisemod)/(maxx+EPSILON)/0.1;
|
||||||
float ny = (y+noisemod)/(maxy+EPSILON)/0.1;
|
float ny = (y+noisemod)/(maxy+EPSILON)/0.1;
|
||||||
Vec2 pos = Vec2(nx,ny);
|
Vec2 pos = Vec2(nx,ny);
|
||||||
|
float temp = noisegen.permute(Vec2(nx*0.2+1,ny*0.1+2));
|
||||||
float alpha = noisegen.permute(pos);
|
float alpha = noisegen.permute(pos);
|
||||||
if (alpha > minChance && alpha < maxChance) {
|
if (alpha > minChance && alpha < maxChance) {
|
||||||
if (color) {
|
if (color) {
|
||||||
float red = noisegen.permute(Vec2(nx*0.3,ny*0.3));
|
float red = noisegen.permute(Vec2(nx*0.3,ny*0.3));
|
||||||
float green = noisegen.permute(Vec2(nx*0.6,ny*.06));
|
float green = noisegen.permute(Vec2(nx*0.6,ny*.06));
|
||||||
float blue = noisegen.permute(Vec2(nx*0.9,ny*0.9));
|
float blue = noisegen.permute(Vec2(nx*0.9,ny*0.9));
|
||||||
std::uniform_real_distribution<> temp(0.0f, 100.0f);
|
|
||||||
Vec4 newc = Vec4(red,green,blue,1.0);
|
Vec4 newc = Vec4(red,green,blue,1.0);
|
||||||
colors.push_back(newc);
|
colors.push_back(newc);
|
||||||
poses.push_back(Vec2(x,y));
|
poses.push_back(Vec2(x,y));
|
||||||
sizes.push_back(1.0f);
|
sizes.push_back(1.0f);
|
||||||
|
temps.push_back(temp * 100);
|
||||||
|
//std::cout << "temp: " << temp << std::endl;
|
||||||
} else {
|
} else {
|
||||||
Vec4 newc = Vec4(alpha,alpha,alpha,1.0);
|
Vec4 newc = Vec4(alpha,alpha,alpha,1.0);
|
||||||
colors.push_back(newc);
|
colors.push_back(newc);
|
||||||
poses.push_back(pos);
|
poses.push_back(Vec2(x,y));
|
||||||
sizes.push_back(1.0f);
|
sizes.push_back(1.0f);
|
||||||
|
temps.push_back(temp * 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "noise generated" << std::endl;
|
std::cout << "noise generated" << std::endl;
|
||||||
bulkAddObjects(poses,colors,sizes);
|
bulkAddObjects(poses, colors, sizes, temps);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1147,9 +1091,11 @@ public:
|
|||||||
std::vector<size_t> tval = spatialGrid.queryRange(Positions.at(id), 10);
|
std::vector<size_t> tval = spatialGrid.queryRange(Positions.at(id), 10);
|
||||||
for (size_t tempid : tval) {
|
for (size_t tempid : tval) {
|
||||||
Vec2 pos = Positions.at(tempid);
|
Vec2 pos = Positions.at(tempid);
|
||||||
|
if (tempMap.find(id) != tempMap.end()) {
|
||||||
Temp temp = tempMap.at(tempid);
|
Temp temp = tempMap.at(tempid);
|
||||||
out.insert({pos, temp});
|
out.insert({pos, temp});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1163,12 +1109,12 @@ public:
|
|||||||
else return tempMap.at(id).temp;
|
else return tempMap.at(id).temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame getTempAsFrame(Vec2 minCorner, Vec2 maxCorner, Vec2 res) {
|
frame getTempAsFrame(Vec2 minCorner, Vec2 maxCorner, Vec2 res, frame::colormap outcolor = frame::colormap::RGB) {
|
||||||
TIME_FUNCTION;
|
TIME_FUNCTION;
|
||||||
if (updatingView) return frame();
|
if (updatingView) return frame();
|
||||||
updatingView = true;
|
updatingView = true;
|
||||||
int pcount = 0;
|
int pcount = 0;
|
||||||
std::cout << "getTempAsFrame() started" << pcount++ << std::endl;
|
// std::cout << "getTempAsFrame() started" << pcount++ << std::endl;
|
||||||
size_t sheight = maxCorner.x - minCorner.x;
|
size_t sheight = maxCorner.x - minCorner.x;
|
||||||
size_t swidth = maxCorner.y - minCorner.y;
|
size_t swidth = maxCorner.y - minCorner.y;
|
||||||
// std::cout << "getTempAsFrame() started" << pcount++ << std::endl;
|
// std::cout << "getTempAsFrame() started" << pcount++ << std::endl;
|
||||||
@@ -1200,21 +1146,62 @@ public:
|
|||||||
std::cout << "max temp: " << maxTemp << " min temp: " << minTemp << std::endl;
|
std::cout << "max temp: " << maxTemp << " min temp: " << minTemp << std::endl;
|
||||||
// std::cout << "getTempAsFrame() middle" << std::endl;
|
// std::cout << "getTempAsFrame() middle" << std::endl;
|
||||||
|
|
||||||
|
switch (outcolor) {
|
||||||
|
case frame::colormap::RGBA: {
|
||||||
|
std::vector<uint8_t> rgbaBuffer(width*height*4, 0);
|
||||||
|
for (const auto& [v2, temp] : tempBuffer) {
|
||||||
|
size_t index = (v2.y * width + v2.x) * 4;
|
||||||
|
uint8_t atemp = static_cast<unsigned char>((((temp-minTemp)) / (maxTemp-minTemp)) * 255);
|
||||||
|
rgbaBuffer[index+0] = atemp;
|
||||||
|
rgbaBuffer[index+1] = atemp;
|
||||||
|
rgbaBuffer[index+2] = atemp;
|
||||||
|
rgbaBuffer[index+3] = 255;
|
||||||
|
}
|
||||||
|
// std::cout << "rgba buffer is " << rgbaBuffer.size() << std::endl;
|
||||||
|
frame result = frame(res.x,res.y, frame::colormap::RGBA);
|
||||||
|
result.setData(rgbaBuffer);
|
||||||
|
updatingView = false;
|
||||||
|
return result;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case frame::colormap::BGR: {
|
||||||
std::vector<uint8_t> rgbaBuffer(width*height*3, 0);
|
std::vector<uint8_t> rgbaBuffer(width*height*3, 0);
|
||||||
for (const auto& [v2, temp] : tempBuffer) {
|
for (const auto& [v2, temp] : tempBuffer) {
|
||||||
size_t index = (v2.y * width + v2.x) * 3;
|
size_t index = (v2.y * width + v2.x) * 3;
|
||||||
uint8_t atemp = static_cast<unsigned char>((((temp-minTemp)) / (maxTemp-minTemp)) * 255);
|
uint8_t atemp = static_cast<unsigned char>((((temp-minTemp)) / (maxTemp-minTemp)) * 255);
|
||||||
rgbaBuffer[index] = atemp;
|
rgbaBuffer[index+2] = atemp;
|
||||||
|
rgbaBuffer[index+1] = atemp;
|
||||||
|
rgbaBuffer[index+0] = atemp;
|
||||||
|
//rgbaBuffer[index+3] = 255;
|
||||||
|
}
|
||||||
|
// std::cout << "rgba buffer is " << rgbaBuffer.size() << std::endl;
|
||||||
|
frame result = frame(res.x,res.y, frame::colormap::BGR);
|
||||||
|
result.setData(rgbaBuffer);
|
||||||
|
updatingView = false;
|
||||||
|
return result;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case frame::colormap::RGB:
|
||||||
|
default: {
|
||||||
|
std::vector<uint8_t> rgbaBuffer(width*height*3, 0);
|
||||||
|
for (const auto& [v2, temp] : tempBuffer) {
|
||||||
|
size_t index = (v2.y * width + v2.x) * 3;
|
||||||
|
uint8_t atemp = static_cast<unsigned char>((((temp-minTemp)) / (maxTemp-minTemp)) * 255);
|
||||||
|
rgbaBuffer[index+0] = atemp;
|
||||||
rgbaBuffer[index+1] = atemp;
|
rgbaBuffer[index+1] = atemp;
|
||||||
rgbaBuffer[index+2] = atemp;
|
rgbaBuffer[index+2] = atemp;
|
||||||
//rgbaBuffer[index+3] = 255;
|
//rgbaBuffer[index+3] = 255;
|
||||||
}
|
}
|
||||||
std::cout << "rgba buffer is " << rgbaBuffer.size() << std::endl;
|
// std::cout << "rgba buffer is " << rgbaBuffer.size() << std::endl;
|
||||||
frame result = frame(res.x,res.y, frame::colormap::RGB);
|
frame result = frame(res.x,res.y, frame::colormap::RGB);
|
||||||
result.setData(rgbaBuffer);
|
result.setData(rgbaBuffer);
|
||||||
updatingView = false;
|
updatingView = false;
|
||||||
return result;
|
return result;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -145,12 +145,9 @@ public:
|
|||||||
|
|
||||||
static bool saveBMP(const std::string& filename, frame& frame) {
|
static bool saveBMP(const std::string& filename, frame& frame) {
|
||||||
if (frame.colorFormat == frame::colormap::RGB) {
|
if (frame.colorFormat == frame::colormap::RGB) {
|
||||||
std::cout << "found correct colormap" << std::endl;
|
|
||||||
return saveBMP(filename, frame.getData(), frame.getWidth(), frame.getHeight());
|
return saveBMP(filename, frame.getData(), frame.getWidth(), frame.getHeight());
|
||||||
} else if (frame.colorFormat == frame::colormap::RGBA) {
|
} else if (frame.colorFormat == frame::colormap::RGBA) {
|
||||||
std::cout << "found incorrect colormap. converting from RGBA" << std::endl;
|
|
||||||
std::vector<uint8_t> fdata = convertRGBAtoRGB(frame.getData());
|
std::vector<uint8_t> fdata = convertRGBAtoRGB(frame.getData());
|
||||||
std::cout << "source data: " << frame.getData().size() << " out data: " << fdata.size() << std::endl;
|
|
||||||
return saveBMP(filename, fdata, frame.getWidth(), frame.getHeight());
|
return saveBMP(filename, fdata, frame.getWidth(), frame.getHeight());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ public:
|
|||||||
_compressedData.shrink_to_fit();
|
_compressedData.shrink_to_fit();
|
||||||
overheadmap.clear();
|
overheadmap.clear();
|
||||||
sourceSize = data.size();
|
sourceSize = data.size();
|
||||||
std::cout << "wrote " << data.size() << " as frame" << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<uint8_t>& getData() const {
|
const std::vector<uint8_t>& getData() const {
|
||||||
|
|||||||
@@ -10,10 +10,31 @@ class Temp {
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
static Vec2 findClosestPoint(const Vec2& position, std::unordered_map<Vec2, Temp> others) {
|
||||||
|
if (others.empty()) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto closest = others.begin();
|
||||||
|
double minDistance = position.distance(closest->first);
|
||||||
|
|
||||||
|
for (auto it = std::next(others.begin()); it != others.end(); ++it) {
|
||||||
|
double distance = position.distance(it->first);
|
||||||
|
if (distance < minDistance) {
|
||||||
|
minDistance = distance;
|
||||||
|
closest = it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return closest->first;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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) {
|
||||||
TIME_FUNCTION;
|
TIME_FUNCTION;
|
||||||
@@ -52,6 +73,48 @@ public:
|
|||||||
}
|
}
|
||||||
return num / den;
|
return num / den;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float calGrad(const Vec2& testPos, std::unordered_map<Vec2, Temp> others) {
|
||||||
|
std::vector<std::pair<Vec2, double>> nearbyPoints;
|
||||||
|
for (const auto& [point, temp] : others) {
|
||||||
|
if (point.distance(testPos) <= 25) {
|
||||||
|
nearbyPoints.emplace_back(point, temp.temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
double sumX, sumY, sumT, sumX2, sumY2, sumXY, sumXT, sumYT = 0;
|
||||||
|
int n = nearbyPoints.size();
|
||||||
|
for (const auto& [point, temp] : nearbyPoints) {
|
||||||
|
double x = point.x - testPos.x;
|
||||||
|
double y = point.y - testPos.y;
|
||||||
|
|
||||||
|
sumX += x;
|
||||||
|
sumY += y;
|
||||||
|
sumT += temp;
|
||||||
|
sumX2 += x * x;
|
||||||
|
sumY2 += y * y;
|
||||||
|
sumXY += x * y;
|
||||||
|
sumXT += x * temp;
|
||||||
|
sumYT += y * temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
double det = sumX2 * sumY2 - sumXY * sumXY;
|
||||||
|
|
||||||
|
if (std::abs(det) < 1e-10) {
|
||||||
|
Vec2 calpoint = Vec2(0, 0); // Singular matrix, cannot solve
|
||||||
|
}
|
||||||
|
|
||||||
|
double a = (sumXT * sumY2 - sumYT * sumXY) / det;
|
||||||
|
double b = (sumX2 * sumYT - sumXY * sumXT) / det;
|
||||||
|
|
||||||
|
Vec2 calpoint = Vec2(a, b); // ∇T = (∂T/∂x, ∂T/∂y)
|
||||||
|
|
||||||
|
Vec2 closest = findClosestPoint(testPos, others);
|
||||||
|
Vec2 displacement = testPos - closest;
|
||||||
|
|
||||||
|
float refTemp = others.at(closest).temp;
|
||||||
|
float estimatedTemp = refTemp + (calpoint.x * displacement.x + calpoint.y * displacement.y);
|
||||||
|
return estimatedTemp;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user