added eigen, dropping my own for the speed potential. its still kinda broken, but its faster.

This commit is contained in:
yggdrasil75
2026-01-26 21:06:53 -05:00
parent c3916d146a
commit e0764318b4
2 changed files with 16 additions and 19 deletions

View File

@@ -34,7 +34,7 @@ int main() {
Eigen::Vector3f greenColor(0.0f, 1.0f, 0.0f); // green Eigen::Vector3f greenColor(0.0f, 1.0f, 0.0f); // green
// Add points on sphere surface (simplified representation) // Add points on sphere surface (simplified representation)
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 10000; ++i) {
// Spherical coordinates // Spherical coordinates
float u = static_cast<float>(rand()) / RAND_MAX; float u = static_cast<float>(rand()) / RAND_MAX;
float v = static_cast<float>(rand()) / RAND_MAX; float v = static_cast<float>(rand()) / RAND_MAX;
@@ -59,7 +59,7 @@ int main() {
std::cout << "Added " << pointCount << " points to the green sphere." << std::endl; std::cout << "Added " << pointCount << " points to the green sphere." << std::endl;
// Set camera parameters // Set camera parameters
PointType cameraPos(0.0f, 0.0f, 5.0f); // camera position PointType cameraPos(0.0f, 0.0f, 3.0f); // camera position
PointType lookDir(0.0f, 0.0f, -1.0f); // looking at sphere PointType lookDir(0.0f, 0.0f, -1.0f); // looking at sphere
PointType upDir(0.0f, 1.0f, 0.0f); // up direction PointType upDir(0.0f, 1.0f, 0.0f); // up direction
PointType rightDir(1.0f, 0.0f, 0.0f); // right direction PointType rightDir(1.0f, 0.0f, 0.0f); // right direction

View File

@@ -4,6 +4,13 @@
#include "../../eigen/Eigen/Dense" #include "../../eigen/Eigen/Dense"
#include "../timing_decorator.hpp" #include "../timing_decorator.hpp"
#include "../output/frame.hpp" #include "../output/frame.hpp"
#include <vector>
#include <array>
#include <memory>
#include <algorithm>
#include <limits>
#include <cmath>
#ifdef SSE #ifdef SSE
#include <immintrin.h> #include <immintrin.h>
#endif #endif
@@ -181,8 +188,6 @@ private:
arr[i].second = values[i]; arr[i].second = values[i];
arr[i].first = (uint8_t)indices[i]; arr[i].first = (uint8_t)indices[i];
} }
#else #else
auto a0 = arr[0], a1 = arr[1], a2 = arr[2], a3 = arr[3]; auto a0 = arr[0], a1 = arr[1], a2 = arr[2], a3 = arr[3];
auto a4 = arr[4], a5 = arr[5], a6 = arr[6], a7 = arr[7]; auto a4 = arr[4], a5 = arr[5], a6 = arr[6], a7 = arr[7];
@@ -247,7 +252,7 @@ private:
public: public:
Octree(const PointType& minBound, const PointType& maxBound, size_t maxPointsPerNode=16, size_t maxDepth = 16) : Octree(const PointType& minBound, const PointType& maxBound, size_t maxPointsPerNode=16, size_t maxDepth = 16) :
root_(std::make_unique<OctreeNode>(minBound, maxBound)), maxPointsPerNode(maxPointsPerNode), root_(std::make_unique<OctreeNode>(minBound, maxBound)), maxPointsPerNode(maxPointsPerNode),
maxDepth(maxDepth), size(size) {} maxDepth(maxDepth), size(0) {}
bool set(const T& data, const PointType& pos, Eigen::Vector3f color, float size, bool active) { bool set(const T& data, const PointType& pos, Eigen::Vector3f color, float size, bool active) {
auto pointData = std::make_shared<NodeData>(data, pos, color, size, active); auto pointData = std::make_shared<NodeData>(data, pos, color, size, active);
@@ -269,20 +274,12 @@ public:
if (!node || tMin > tMax) return; if (!node || tMin > tMax) return;
if (node->isLeaf) { if (node->isLeaf) {
for (const auto& pointData : node->points) { for (const auto& pointData : node->points) {
//if (!pointData->active) continue; PointType toPoint = pointData->position - origin;
float projection = toPoint.dot(dir);
// Calculate intersection with axis-aligned cube if (projection >= 0 && projection <= maxDist) {
float halfSize = pointData->size * 0.5f; PointType closestPoint = origin + dir * projection;
PointType cubeMin = pointData->position - PointType::Constant(halfSize); float distSq = (pointData->position - closestPoint).squaredNorm();
PointType cubeMax = pointData->position + PointType::Constant(halfSize); if (distSq < pointData->size * pointData->size) {
// Ray-cube intersection test
float cubeTMin = tMin;
float cubeTMax = tMax;
if (rayBoxIntersect(origin, dir, {cubeMin, cubeMax}, cubeTMin, cubeTMax)) {
// Check if intersection is within max distance
if (cubeTMin <= maxDist) {
hits.emplace_back(pointData); hits.emplace_back(pointData);
if (stopAtFirstHit) return; if (stopAtFirstHit) return;
} }