diff --git a/tests/g2chromatic2.cpp b/tests/g2chromatic2.cpp index 5761de1..c820afc 100644 --- a/tests/g2chromatic2.cpp +++ b/tests/g2chromatic2.cpp @@ -81,6 +81,7 @@ void expandPixel(Grid2& grid, AnimationConfig config, std::vector(seed); Vec4 seedColor = std::get<2>(seed); std::vector neighbors = grid.getNeighbors(id); + grid.setSize(id, grid.getSize(id)+4); for (size_t neighbor : neighbors) { if (visitedThisFrame.count(neighbor)) { continue; @@ -106,12 +107,12 @@ void expandPixel(Grid2& grid, AnimationConfig config, std::vector> frames, AnimationConfig config) { diff --git a/util/grid/grid2.hpp b/util/grid/grid2.hpp index 3495bf4..92d74e5 100644 --- a/util/grid/grid2.hpp +++ b/util/grid/grid2.hpp @@ -262,12 +262,12 @@ public: } //get size from id - Vec4 getSize(size_t id) { - return Colors.at(id); + size_t getSize(size_t id) { + return Sizes.at(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); return getSize(id); } @@ -497,25 +497,37 @@ public: // For each position in the grid, find the corresponding pixel //#pragma omp parallel for for (const auto& [id, pos] : Positions) { - if (pos.x >= minCorner.x && pos.x < maxCorner.x && - pos.y >= minCorner.y && pos.y < maxCorner.y) { + size_t size = Sizes.at(id); + // if (pos.x >= minCorner.x && pos.x < maxCorner.x && + // pos.y >= minCorner.y && pos.y < maxCorner.y) { // Calculate pixel coordinates - int pixelX = static_cast(pos.x - minCorner.x); - int pixelY = static_cast(pos.y - minCorner.y); + int pixelXm = static_cast(pos.x - size/2 - minCorner.x); + int pixelXM = static_cast(pos.x + size/2 - minCorner.x); + int pixelYm = static_cast(pos.y - size/2 - minCorner.y); + int pixelYM = static_cast(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 - if (pixelX >= 0 && pixelX < width && pixelY >= 0 && pixelY < height) { - // Get color and convert to RGB + if (pixelXM >= minCorner.x && pixelXm < width && pixelYM >= minCorner.y && pixelYm < height) { const Vec4& color = Colors.at(id); - int index = (pixelY * width + pixelX) * 3; - - // Convert from [0,1] to [0,255] and store as RGB - rgbData[index] = static_cast(color.r * 255); - rgbData[index + 1] = static_cast(color.g * 255); - rgbData[index + 2] = static_cast(color.b * 255); + 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 + rgbData[index] = static_cast(color.r * 255); + rgbData[index + 1] = static_cast(color.g * 255); + rgbData[index + 2] = static_cast(color.b * 255); + } + } } - } + //} } } @@ -534,31 +546,43 @@ public: 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); // For each position in the grid, find the corresponding pixel //#pragma omp parallel for for (const auto& [id, pos] : Positions) { - if (pos.x >= minCorner.x && pos.x < maxCorner.x && - pos.y >= minCorner.y && pos.y < maxCorner.y) { + size_t size = Sizes.at(id); + // if (pos.x >= minCorner.x && pos.x < maxCorner.x && + // pos.y >= minCorner.y && pos.y < maxCorner.y) { // Calculate pixel coordinates - int pixelX = static_cast(pos.x - minCorner.x); - int pixelY = static_cast(pos.y - minCorner.y); + int pixelXm = static_cast(pos.x - size/2 - minCorner.x); + int pixelXM = static_cast(pos.x + size/2 - minCorner.x); + int pixelYm = static_cast(pos.y - size/2 - minCorner.y); + int pixelYM = static_cast(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 - if (pixelX >= 0 && pixelX < width && pixelY >= 0 && pixelY < height) { - // Get color and convert to BGR + if (pixelXM >= minCorner.x && pixelXm < width && pixelYM >= minCorner.y && pixelYm < height) { const Vec4& color = Colors.at(id); - int index = (pixelY * width + pixelX) * 3; - - // Convert from [0,1] to [0,255] and store as BGR - bgrData[index] = static_cast(color.b * 255); // Blue - bgrData[index + 1] = static_cast(color.g * 255); // Green - bgrData[index + 2] = static_cast(color.r * 255); // Red + 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 + bgrData[index + 2] = static_cast(color.r * 255); + bgrData[index + 1] = static_cast(color.g * 255); + bgrData[index] = static_cast(color.b * 255); + } + } } - } + //} } }