added eigen, dropping my own for the speed potential. its still kinda broken, but its faster.
This commit is contained in:
@@ -34,7 +34,7 @@ int main() {
|
||||
Eigen::Vector3f greenColor(0.0f, 1.0f, 0.0f); // green
|
||||
|
||||
// Add points on sphere surface (simplified representation)
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
// Spherical coordinates
|
||||
float u = 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;
|
||||
|
||||
// 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 upDir(0.0f, 1.0f, 0.0f); // up direction
|
||||
PointType rightDir(1.0f, 0.0f, 0.0f); // right direction
|
||||
|
||||
@@ -4,6 +4,13 @@
|
||||
#include "../../eigen/Eigen/Dense"
|
||||
#include "../timing_decorator.hpp"
|
||||
#include "../output/frame.hpp"
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
|
||||
#ifdef SSE
|
||||
#include <immintrin.h>
|
||||
#endif
|
||||
@@ -181,8 +188,6 @@ private:
|
||||
arr[i].second = values[i];
|
||||
arr[i].first = (uint8_t)indices[i];
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
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];
|
||||
@@ -247,7 +252,7 @@ private:
|
||||
public:
|
||||
Octree(const PointType& minBound, const PointType& maxBound, size_t maxPointsPerNode=16, size_t maxDepth = 16) :
|
||||
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) {
|
||||
auto pointData = std::make_shared<NodeData>(data, pos, color, size, active);
|
||||
@@ -269,20 +274,12 @@ public:
|
||||
if (!node || tMin > tMax) return;
|
||||
if (node->isLeaf) {
|
||||
for (const auto& pointData : node->points) {
|
||||
//if (!pointData->active) continue;
|
||||
|
||||
// Calculate intersection with axis-aligned cube
|
||||
float halfSize = pointData->size * 0.5f;
|
||||
PointType cubeMin = pointData->position - PointType::Constant(halfSize);
|
||||
PointType cubeMax = pointData->position + PointType::Constant(halfSize);
|
||||
|
||||
// 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) {
|
||||
PointType toPoint = pointData->position - origin;
|
||||
float projection = toPoint.dot(dir);
|
||||
if (projection >= 0 && projection <= maxDist) {
|
||||
PointType closestPoint = origin + dir * projection;
|
||||
float distSq = (pointData->position - closestPoint).squaredNorm();
|
||||
if (distSq < pointData->size * pointData->size) {
|
||||
hits.emplace_back(pointData);
|
||||
if (stopAtFirstHit) return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user