feat (wip): real-time gui with rendering in opengl

This commit is contained in:
2025-01-03 19:57:10 +01:00
parent c92d0bc2a9
commit c23a33ebef
22 changed files with 656 additions and 62 deletions

46
src/linalg/mat.cu Normal file
View File

@@ -0,0 +1,46 @@
#include "mat.h"
#include <vector>
#include <algorithm>
using namespace std;
__device__ Vec3 computeGradient(float* volumeData, const int volW, const int volH, const int volD, int x, int y, int z) {
// Finite difference for partial derivatives.
// For boundary voxels - clamp to the boundary.
// Normal should point from higher to lower intensities
int xm = max(x - 1, 0);
int xp = min(x + 1, volW - 1);
int ym = max(y - 1, 0);
int yp = min(y + 1, volH - 1);
int zm = max(z - 1, 0);
int zp = min(z + 1, volD - 1);
// Note: Assuming data is linearized (idx = z*w*h + y*w + x) TODO: Unlinearize if data not linear
float gx = volumeData[z * volW * volH + y * volW + xp]
- volumeData[z * volW * volH + y * volW + xm];
float gy = volumeData[z * volW * volH + yp * volW + x ]
- volumeData[z * volW * volH + ym * volW + x ];
float gz = volumeData[zp * volW * volH + y * volW + x ]
- volumeData[zm * volW * volH + y * volW + x ];
return Vec3::init(gx, gy, gz);
};
// TESTING: haven't tested this function at all tbh
__device__ unsigned int packUnorm4x8(float r, float g, float b, float a) {
union {
unsigned char in[4];
uint out;
} u;
double len = sqrt(r*r + g*g + b*b + a*a);
// This is a Vec4 but i can't be bothered to make that its own struct/class; FIXME: maybe do that if we need to?
std::vector<float> v{r/len, g/len, b/len, a/len};
for (int i = 0; i < v.size(); i++) {
u.in[i] = round(std::clamp(v[i], 0.0f, 1.0f) * 255.0f);
}
return u.out;
}

View File

@@ -1,24 +1,10 @@
#pragma once
#ifndef MAT_H
#define MAT_H
__device__ Vec3 computeGradient(float* volumeData, const int volW, const int volH, const int volD, int x, int y, int z) {
// Finite difference for partial derivatives.
// For boundary voxels - clamp to the boundary.
// Normal should point from higher to lower intensities
#include "vec.h"
int xm = max(x - 1, 0);
int xp = min(x + 1, volW - 1);
int ym = max(y - 1, 0);
int yp = min(y + 1, volH - 1);
int zm = max(z - 1, 0);
int zp = min(z + 1, volD - 1);
__device__ Vec3 computeGradient(float* volumeData, const int volW, const int volH, const int volD, int x, int y, int z);
// Note: Assuming data is linearized (idx = z*w*h + y*w + x) TODO: Unlinearize if data not linear
float gx = volumeData[z * volW * volH + y * volW + xp]
- volumeData[z * volW * volH + y * volW + xm];
float gy = volumeData[z * volW * volH + yp * volW + x ]
- volumeData[z * volW * volH + ym * volW + x ];
float gz = volumeData[zp * volW * volH + y * volW + x ]
- volumeData[zm * volW * volH + y * volW + x ];
__device__ unsigned int packUnorm4x8(float r, float g, float b, float a);
return Vec3::init(gx, gy, gz);
}
#endif // MAT_H

View File

@@ -27,4 +27,4 @@ struct Vec3 { // TODO: Maybe make this into a class ... maybe
};
typedef Vec3 Point3;
typedef Vec3 Color3;
typedef Vec3 Color3;