fixed some size things. turns out that getsize returned color!

This commit is contained in:
yggdrasil75
2025-11-17 20:57:18 -05:00
parent 274c786d27
commit 8bd8df8e46
2 changed files with 59 additions and 34 deletions

View File

@@ -81,6 +81,7 @@ void expandPixel(Grid2& grid, AnimationConfig config, std::vector<std::tuple<siz
Vec2 seedPOS = std::get<1>(seed); Vec2 seedPOS = std::get<1>(seed);
Vec4 seedColor = std::get<2>(seed); Vec4 seedColor = std::get<2>(seed);
std::vector<size_t> neighbors = grid.getNeighbors(id); std::vector<size_t> neighbors = grid.getNeighbors(id);
grid.setSize(id, grid.getSize(id)+4);
for (size_t neighbor : neighbors) { for (size_t neighbor : neighbors) {
if (visitedThisFrame.count(neighbor)) { if (visitedThisFrame.count(neighbor)) {
continue; continue;
@@ -106,12 +107,12 @@ void expandPixel(Grid2& grid, AnimationConfig config, std::vector<std::tuple<siz
newcolor = newcolor.clamp(0.0f, 1.0f); newcolor = newcolor.clamp(0.0f, 1.0f);
grid.setColor(neighbor, newcolor); grid.setColor(neighbor, newcolor);
newseeds.emplace_back(neighbor, neipos, newcolor); //newseeds.emplace_back(neighbor, neipos, newcolor);
} }
} }
seeds.clear(); //seeds.clear();
seeds.shrink_to_fit(); //seeds.shrink_to_fit();
seeds = std::move(newseeds); //seeds = std::move(newseeds);
} }
//bool exportavi(std::vector<std::vector<uint8_t>> frames, AnimationConfig config) { //bool exportavi(std::vector<std::vector<uint8_t>> frames, AnimationConfig config) {

View File

@@ -262,12 +262,12 @@ public:
} }
//get size from id //get size from id
Vec4 getSize(size_t id) { size_t getSize(size_t id) {
return Colors.at(id); return Sizes.at(id);
} }
//get size from position (use get id from position and then get size from id) //get size from position (use get id from position and then get size from id)
Vec4 getSize(float x, float y) { size_t getSize(float x, float y) {
size_t id = getPositionVec(Vec2(x,y),0.0); size_t id = getPositionVec(Vec2(x,y),0.0);
return getSize(id); return getSize(id);
} }
@@ -497,18 +497,28 @@ public:
// For each position in the grid, find the corresponding pixel // For each position in the grid, find the corresponding pixel
//#pragma omp parallel for //#pragma omp parallel for
for (const auto& [id, pos] : Positions) { for (const auto& [id, pos] : Positions) {
if (pos.x >= minCorner.x && pos.x < maxCorner.x && size_t size = Sizes.at(id);
pos.y >= minCorner.y && pos.y < maxCorner.y) { // if (pos.x >= minCorner.x && pos.x < maxCorner.x &&
// pos.y >= minCorner.y && pos.y < maxCorner.y) {
// Calculate pixel coordinates // Calculate pixel coordinates
int pixelX = static_cast<int>(pos.x - minCorner.x); int pixelXm = static_cast<int>(pos.x - size/2 - minCorner.x);
int pixelY = static_cast<int>(pos.y - minCorner.y); int pixelXM = static_cast<int>(pos.x + size/2 - minCorner.x);
int pixelYm = static_cast<int>(pos.y - size/2 - minCorner.y);
int pixelYM = static_cast<int>(pos.y + size/2 - minCorner.y);
pixelXm = std::max(0, pixelXm);
pixelXM = std::min(width - 1, pixelXM);
pixelYm = std::max(0, pixelYm);
pixelYM = std::min(height - 1, pixelYM);
// Ensure within bounds // Ensure within bounds
if (pixelX >= 0 && pixelX < width && pixelY >= 0 && pixelY < height) { if (pixelXM >= minCorner.x && pixelXm < width && pixelYM >= minCorner.y && pixelYm < height) {
// Get color and convert to RGB
const Vec4& color = Colors.at(id); const Vec4& color = Colors.at(id);
int index = (pixelY * width + pixelX) * 3; for (int py = pixelYm; py <= pixelYM; ++py){
for (int px = pixelXm; px <= pixelXM; ++px){
// Get color and convert to RGB
int index = (py * width + px) * 3;
// Convert from [0,1] to [0,255] and store as RGB // Convert from [0,1] to [0,255] and store as RGB
rgbData[index] = static_cast<unsigned char>(color.r * 255); rgbData[index] = static_cast<unsigned char>(color.r * 255);
@@ -517,6 +527,8 @@ public:
} }
} }
} }
//}
}
} }
// Get region as BGR // Get region as BGR
@@ -534,32 +546,44 @@ public:
return; return;
} }
// Initialize BGR data (3 bytes per pixel: B, G, R) // Initialize RGB data (3 bytes per pixel: R, G, B)
bgrData.resize(width * height * 3, 0); bgrData.resize(width * height * 3, 0);
// For each position in the grid, find the corresponding pixel // For each position in the grid, find the corresponding pixel
//#pragma omp parallel for //#pragma omp parallel for
for (const auto& [id, pos] : Positions) { for (const auto& [id, pos] : Positions) {
if (pos.x >= minCorner.x && pos.x < maxCorner.x && size_t size = Sizes.at(id);
pos.y >= minCorner.y && pos.y < maxCorner.y) { // if (pos.x >= minCorner.x && pos.x < maxCorner.x &&
// pos.y >= minCorner.y && pos.y < maxCorner.y) {
// Calculate pixel coordinates // Calculate pixel coordinates
int pixelX = static_cast<int>(pos.x - minCorner.x); int pixelXm = static_cast<int>(pos.x - size/2 - minCorner.x);
int pixelY = static_cast<int>(pos.y - minCorner.y); int pixelXM = static_cast<int>(pos.x + size/2 - minCorner.x);
int pixelYm = static_cast<int>(pos.y - size/2 - minCorner.y);
int pixelYM = static_cast<int>(pos.y + size/2 - minCorner.y);
pixelXm = std::max(0, pixelXm);
pixelXM = std::min(width - 1, pixelXM);
pixelYm = std::max(0, pixelYm);
pixelYM = std::min(height - 1, pixelYM);
// Ensure within bounds // Ensure within bounds
if (pixelX >= 0 && pixelX < width && pixelY >= 0 && pixelY < height) { if (pixelXM >= minCorner.x && pixelXm < width && pixelYM >= minCorner.y && pixelYm < height) {
// Get color and convert to BGR
const Vec4& color = Colors.at(id); const Vec4& color = Colors.at(id);
int index = (pixelY * width + pixelX) * 3; for (int py = pixelYm; py <= pixelYM; ++py){
for (int px = pixelXm; px <= pixelXM; ++px){
// Get color and convert to RGB
int index = (py * width + px) * 3;
// Convert from [0,1] to [0,255] and store as BGR // Convert from [0,1] to [0,255] and store as RGB
bgrData[index] = static_cast<unsigned char>(color.b * 255); // Blue bgrData[index + 2] = static_cast<unsigned char>(color.r * 255);
bgrData[index + 1] = static_cast<unsigned char>(color.g * 255); // Green bgrData[index + 1] = static_cast<unsigned char>(color.g * 255);
bgrData[index + 2] = static_cast<unsigned char>(color.r * 255); // Red bgrData[index] = static_cast<unsigned char>(color.b * 255);
} }
} }
} }
//}
}
} }
//get full as rgb/bgr //get full as rgb/bgr