fixed some size things. turns out that getsize returned color!
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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,25 +497,37 @@ 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);
|
||||||
rgbData[index + 1] = static_cast<unsigned char>(color.g * 255);
|
rgbData[index + 1] = static_cast<unsigned char>(color.g * 255);
|
||||||
rgbData[index + 2] = static_cast<unsigned char>(color.b * 255);
|
rgbData[index + 2] = static_cast<unsigned char>(color.b * 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,31 +546,43 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user