Somewhere on the way to porting the camera keypoints processing

This commit is contained in:
Pascal Serrarens 2025-06-30 15:44:45 +02:00
parent a7a25bde6e
commit abeef72514
4 changed files with 100 additions and 5 deletions

View File

@ -1,5 +1,5 @@
#include "Matrix.h"
#if !defined(NO_STD)
#if !defined(NO_STD)
#include <iostream>
#endif
@ -7,6 +7,8 @@ namespace LinearAlgebra {
#pragma region Matrix1
Matrix1::Matrix1() {}
Matrix1::Matrix1(int size) : size(size) {
if (this->size == 0)
data = nullptr;
@ -257,6 +259,37 @@ void Matrix2::UpdateSlice(int rowStart,
}
}
Matrix2 Matrix2::DeleteRows(int rowStart, int rowStop) {
Matrix2 r = Matrix2(this->nRows - (rowStop - rowStart), this->nCols);
int resultRowIx = 0;
for (int i = 0; i < this->nRows; i++) {
if (i >= rowStart && i < rowStop)
continue;
for (int j = 0; j < this->nCols; j++)
r.data[resultRowIx * r.nCols + j] = this->data[i * this->nCols + j];
resultRowIx++;
}
return r;
}
Matrix2 Matrix2::DeleteColumns(int colStart, int colStop) {
Matrix2 r = Matrix2(this->nRows, this->nCols - (colStop - colStart));
for (int i = 0; i < this->nRows; i++) {
int resultColIx = 0;
for (int j = 0; j < this->nCols; j++) {
if (j >= colStart && j < colStop)
continue;
r.data[i * r.nCols + resultColIx++] = this->data[i * this->nCols + j];
}
}
return r;
}
/// @brief Compute the Omega matrix of a 3D vector
/// @param v The vector
/// @return 4x4 Omega matrix

View File

@ -12,12 +12,33 @@ class Matrix1 {
float* data = nullptr;
int size = 0;
Matrix1();
Matrix1(int size);
Matrix1(float* data, int size);
static Matrix1 FromQuaternion(Quaternion q);
Quaternion ToQuaternion();
Matrix1 Slice(int start, int stop);
void Set(unsigned int start, unsigned int stop, float value) {
if (stop > this->size)
stop = this->size;
for (unsigned int ix = start; ix < stop; ix++)
this->data[ix] = value;
}
void Set(unsigned int start, unsigned int stop, Matrix1 source) {
if (stop > this->size)
stop = this->size;
if (stop > source.size)
stop = source.size;
// Do I need to check on start???
unsigned int sourceIx = 0;
for (unsigned int ix = start; ix < stop; ix++, sourceIx++)
this->data[ix] = source.data[sourceIx];
}
private:
bool externalData = true;
};
@ -96,13 +117,33 @@ class Matrix2 {
return r;
}
Matrix2 GetRows(int from, int to) {
if (from < 0 || to >= this->nRows)
std::cerr << "Slice index out of range." << "std::endl";
Matrix2 result = Matrix2(to-from, this->nCols);
int resultRowIx = 0;
for (int rowIx = from; rowIx < to; rowIx++) {
for (int colIx = 0; colIx < this->nCols; colIx++)
result.data[resultRowIx * result.nCols + colIx] = this->data[rowIx * this->nCols + colIx];
resultRowIx++;
}
return result;
}
Matrix2 Slice(int rawStart, int rowStop, int colStart, int colStop);
void UpdateSlice(int rowStart,
int rowStop,
int colStart,
int colStop,
const Matrix2& m) const;
int rowStop,
int colStart,
int colStop,
const Matrix2& m) const;
Matrix2 DeleteRows(int rowStart, int rowStop);
Matrix2 DeleteColumns(int colStart, int colStop);
// private:
// move constructor and move assignment operator
Matrix2(Matrix2&& other) noexcept;

View File

@ -180,3 +180,13 @@ Vector2 Vector2::Lerp(const Vector2& v1, const Vector2& v2, float f) {
Vector2 v = v1 + (v2 - v1) * f;
return v;
}
#pragma region Vector2Of
template <typename T>
Vector2Of<T>::Vector2Of() {
this->horizontal = 0;
this->vertical = 0;
}
#pragma endregion Vector2Of

View File

@ -201,6 +201,17 @@ struct Vector2 : Vec2 {
static Vector2 Lerp(const Vector2& v1, const Vector2& v2, float f);
};
template <typename T>
struct Vector2Of {
public:
Vector2Of();
T horizontal = 0;
T vertical = 0;
};
using Vector2Int = Vector2Of<int>;
} // namespace LinearAlgebra
using namespace LinearAlgebra;