I apparently need a lot more cpu optimizations.
This commit is contained in:
@@ -75,11 +75,11 @@ Grid3 setup(AnimationConfig config) {
|
|||||||
|
|
||||||
void Preview(AnimationConfig config, Grid3& grid) {
|
void Preview(AnimationConfig config, Grid3& grid) {
|
||||||
TIME_FUNCTION;
|
TIME_FUNCTION;
|
||||||
|
|
||||||
frame rgbData = grid.getGridAsFrame(Vec2(config.width, config.height), Ray3(Vec3(config.width + 10,config.height + 10,config.depth + 10), Vec3(0)), frame::colormap::RGB);
|
frame rgbData = grid.getGridAsFrame(Vec2(config.width, config.height), Ray3(Vec3(config.width + 10,config.height + 10,config.depth + 10), Vec3(0)), frame::colormap::RGB);
|
||||||
std::cout << "Frame looks like: " << rgbData << std::endl;
|
std::cout << "Frame looks like: " << rgbData << std::endl;
|
||||||
bool success = BMPWriter::saveBMP("output/grayscalesource3d.bmp", rgbData);
|
bool success = BMPWriter::saveBMP("output/grayscalesource3d.bmp", rgbData);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
std::cout << "yo! this failed in Preview" << std::endl;
|
std::cout << "yo! this failed in Preview" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,10 +117,16 @@ std::vector<std::tuple<size_t, Vec3, Vec4>> pickSeeds(Grid3& grid, AnimationConf
|
|||||||
for (int i = 0; i < config.numSeeds; ++i) {
|
for (int i = 0; i < config.numSeeds; ++i) {
|
||||||
Vec3 point(xDist(gen), yDist(gen), zDist(gen));
|
Vec3 point(xDist(gen), yDist(gen), zDist(gen));
|
||||||
Vec4 color(colorDist(gen), colorDist(gen), colorDist(gen), 255);
|
Vec4 color(colorDist(gen), colorDist(gen), colorDist(gen), 255);
|
||||||
size_t id = grid.getPositionVec(point, 0.5);
|
bool foundValidPos;
|
||||||
//size_t id = grid.getOrCreatePositionVec(point, 0.0, true);
|
int maxTries = 0;
|
||||||
grid.setColor(id, color);
|
while (!foundValidPos && maxTries < 10) {
|
||||||
seeds.push_back(std::make_tuple(id,point, color));
|
maxTries++;
|
||||||
|
size_t id = grid.getPositionVec(point, 0.5);
|
||||||
|
if (id > 0) foundValidPos = true;
|
||||||
|
//size_t id = grid.getOrCreatePositionVec(point, 0.0, true);
|
||||||
|
grid.setColor(id, color);
|
||||||
|
seeds.push_back(std::make_tuple(id,point, color));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std::cout << "picked seeds" << std::endl;
|
std::cout << "picked seeds" << std::endl;
|
||||||
return seeds;
|
return seeds;
|
||||||
@@ -260,7 +266,7 @@ void mainLogic(const AnimationConfig& config, Shared& state, int gradnoise) {
|
|||||||
}
|
}
|
||||||
grid.setDefault(Vec4(0,0,0,0));
|
grid.setDefault(Vec4(0,0,0,0));
|
||||||
{
|
{
|
||||||
std:: lock_guard<std::mutex> lock(state.mutex);
|
std::lock_guard<std::mutex> lock(state.mutex);
|
||||||
state.grid = grid;
|
state.grid = grid;
|
||||||
state.hasNewFrame = true;
|
state.hasNewFrame = true;
|
||||||
state.currentFrame = 0;
|
state.currentFrame = 0;
|
||||||
@@ -278,20 +284,20 @@ void mainLogic(const AnimationConfig& config, Shared& state, int gradnoise) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
expandPixel(grid,config,seeds);
|
//expandPixel(grid,config,seeds);
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(state.mutex);
|
std::lock_guard<std::mutex> lock(state.mutex);
|
||||||
state.grid = grid;
|
state.grid = grid;
|
||||||
state.hasNewFrame = true;
|
state.hasNewFrame = true;
|
||||||
state.currentFrame = i;
|
state.currentFrame = i;
|
||||||
|
|
||||||
//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(Vec2(config.width,config.height), Ray3(Vec3(config.width + 10,config.height + 10,config.depth + 10), Vec3(0)), frame::colormap::BGR);
|
bgrframe = grid.getGridAsFrame(Vec2(config.width,config.height), Ray3(Vec3(config.width + 10,config.height + 10,config.depth + 10), Vec3(0)), frame::colormap::BGR);
|
||||||
frames.push_back(bgrframe);
|
frames.push_back(bgrframe);
|
||||||
// BMPWriter::saveBMP(std::format("output/grayscalesource3d.{}.bmp", i), bgrframe);
|
// BMPWriter::saveBMP(std::format("output/grayscalesource3d.{}.bmp", i), bgrframe);
|
||||||
bgrframe.compressFrameLZ78();
|
bgrframe.compressFrameLZ78();
|
||||||
//bgrframe.printCompressionStats();
|
//bgrframe.printCompressionStats();
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -357,13 +357,13 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::out_of_range("Position not found");
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
auto results = getPositionVecRegion(pos, radius);
|
auto results = getPositionVecRegion(pos, radius);
|
||||||
if (!results.empty()) {
|
if (!results.empty()) {
|
||||||
return results[0]; // Return first found
|
return results[0]; // Return first found
|
||||||
}
|
}
|
||||||
throw std::out_of_range("No positions found in radius");
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,7 +441,7 @@ public:
|
|||||||
maxCorner.y = std::max(maxCorner.y, pos.y);
|
maxCorner.y = std::max(maxCorner.y, pos.y);
|
||||||
maxCorner.z = std::max(maxCorner.z, pos.z);
|
maxCorner.z = std::max(maxCorner.z, pos.z);
|
||||||
}
|
}
|
||||||
std::cout << "bounding box: " << minCorner << ", " << maxCorner << std::endl;
|
// std::cout << "bounding box: " << minCorner << ", " << maxCorner << std::endl;
|
||||||
return std::make_pair(minCorner, maxCorner);
|
return std::make_pair(minCorner, maxCorner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,8 +472,8 @@ public:
|
|||||||
|
|
||||||
// regenpreventer = true;
|
// regenpreventer = true;
|
||||||
|
|
||||||
std::cout << "Rendering 3D region: " << minCorner << " to " << maxCorner
|
// std::cout << "Rendering 3D region: " << minCorner << " to " << maxCorner
|
||||||
<< " at resolution: " << res << " with view: " << View.origin << std::endl;
|
// << " at resolution: " << res << " with view: " << View.origin << std::endl;
|
||||||
|
|
||||||
// Create output frame
|
// Create output frame
|
||||||
frame outframe(outputWidth, outputHeight, outChannels);
|
frame outframe(outputWidth, outputHeight, outChannels);
|
||||||
@@ -491,7 +491,7 @@ public:
|
|||||||
countBuffer.reserve(bufferSize);
|
countBuffer.reserve(bufferSize);
|
||||||
depthBuffer.reserve(bufferSize);
|
depthBuffer.reserve(bufferSize);
|
||||||
|
|
||||||
std::cout << "Built buffers for " << bufferSize << " pixels" << std::endl;
|
// std::cout << "Built buffers for " << bufferSize << " pixels" << std::endl;
|
||||||
|
|
||||||
// Pre-calculate view parameters
|
// Pre-calculate view parameters
|
||||||
Vec3 viewDirection = View.direction;
|
Vec3 viewDirection = View.direction;
|
||||||
@@ -508,7 +508,7 @@ public:
|
|||||||
float xScale = outputWidth / width;
|
float xScale = outputWidth / width;
|
||||||
float yScale = outputHeight / height;
|
float yScale = outputHeight / height;
|
||||||
|
|
||||||
std::cout << "Processing voxels..." << std::endl;
|
// std::cout << "Processing voxels..." << std::endl;
|
||||||
size_t voxelCount = 0;
|
size_t voxelCount = 0;
|
||||||
|
|
||||||
// Process all voxels in the region
|
// Process all voxels in the region
|
||||||
@@ -586,8 +586,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Processed " << voxelCount << " voxels" << std::endl;
|
// std::cout << "Processed " << voxelCount << " voxels" << std::endl;
|
||||||
std::cout << "Blending colors..." << std::endl;
|
// std::cout << "Blending colors..." << std::endl;
|
||||||
|
|
||||||
// Prepare output buffer based on color format
|
// Prepare output buffer based on color format
|
||||||
switch (outChannels) {
|
switch (outChannels) {
|
||||||
@@ -685,7 +685,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Rendering complete" << std::endl;
|
// std::cout << "Rendering complete" << std::endl;
|
||||||
// regenpreventer = false;
|
// regenpreventer = false;
|
||||||
|
|
||||||
return outframe;
|
return outframe;
|
||||||
|
|||||||
Reference in New Issue
Block a user