Skip to content

Commit

Permalink
assm library integration debugged.
Browse files Browse the repository at this point in the history
  • Loading branch information
ponchio committed Nov 27, 2024
1 parent f5aaa3b commit aac66f8
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 25 deletions.
1 change: 0 additions & 1 deletion external/assm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package (Eigen3)
if(NOT Eigen3_FOUND)
set(EIGEN3_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../eigen-3.3.9)

endif()

include_directories(${EIGEN3_INCLUDE_DIR})
Expand Down
16 changes: 8 additions & 8 deletions external/assm/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ template <class T> class Grid: public std::vector<T> {

public:
Grid() {}
Grid(size_t rows, size_t cols, const T &zero) {
Grid(size_t cols, size_t rows, const T &zero) {
_rows = rows;
_cols = cols;
_zero = zero;
this->resize(rows*cols, _zero);
}
size_t rows() const { return _rows; }
size_t cols() const { return _cols; }
T &at(size_t row, size_t col) { return (*this)[row + col*_rows]; }
const T &at(size_t row, size_t col) const { return (*this)[row + col*_rows]; }
T &at(size_t row, size_t col) { return (*this)[row + col*_cols]; }
const T &at(size_t row, size_t col) const { return (*this)[row + col*_cols]; }
void fill(T t) {
for(T &v: *this)
v = t;
Expand Down Expand Up @@ -54,8 +54,8 @@ template <class T> class Grid: public std::vector<T> {
Grid result(_rows, _cols, _zero);

if (alongRows) {
for (int i = 0; i < _rows; ++i) {
for (int j = 0; j < _cols; ++j) {
for (int i = 0; i < int(_rows); ++i) {
for (int j = 0; j < int(_cols); ++j) {
T sum = _zero;
for (int k = -radius; k <= radius; ++k) {
int idx = j + k;
Expand All @@ -67,12 +67,12 @@ template <class T> class Grid: public std::vector<T> {
}
}
} else {
for (int j = 0; j < _cols; ++j) {
for (int i = 0; i < _rows; ++i) {
for (int j = 0; j < int(_cols); ++j) {
for (int i = 0; i < int(_rows); ++i) {
T sum = _zero;
for (int k = -radius; k <= radius; ++k) {
int idx = i + k;
if (idx >= 0 && idx < _rows) {
if (idx >= 0 && idx < int(_rows)) {
sum += at(idx, j) * kernel[k + radius];
}
}
Expand Down
2 changes: 0 additions & 2 deletions external/assm/SurfaceMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -1926,8 +1926,6 @@ class SurfaceMesh
// are there any deleted entities?
inline bool has_garbage() const { return has_garbage_; }

// io functions that need access to internal details
friend void read_pmp(SurfaceMesh&, const std::filesystem::path&);
//friend void write_pmp(const SurfaceMesh&, const std::filesystem::path&,
// const IOFlags&);

Expand Down
6 changes: 4 additions & 2 deletions external/assm/algorithms/Integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class Integration
int n = mesh_.n_vertices();

Eigen::SparseMatrix<T> L(n, n);
Eigen::Vector<T, -1> b = Eigen::Vector<T, -1>::Zero(n);
//Eigen::Vector<T, -1> b = Eigen::Vector<T, -1>::Zero(n);
Eigen::Matrix<T, -1, 1> b = Eigen::Matrix<T, -1, 1>::Zero(n);

// Assembly:
std::vector<Eigen::Triplet<T>> coefficients; // list of non-zeros coefficients
Expand Down Expand Up @@ -172,7 +173,8 @@ class Integration

Eigen::ConjugateGradient<Eigen::SparseMatrix<T>> cg;
cg.compute(L);
Eigen::Vector<T, -1> depth = cg.solve(b);
//Eigen::Vector<T, -1> depth = cg.solve(b);
Eigen::Matrix<T, -1, 1> depth = cg.solve(b);

depth.array() -= depth.mean();

Expand Down
6 changes: 3 additions & 3 deletions external/assm/algorithms/Rasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Span::Span(float h1_, int x1, float h2_, int x2) {

void Rasterizer::SetPixel(unsigned int x, unsigned int y, float h, int id) {
if(x >= width || y >= height)
return;
return;
ids[x + y*width] = id;
}

Expand All @@ -73,8 +73,8 @@ void Rasterizer::SetPixel(int x, int y, float h, int id) {
}

void Rasterizer::SetPixel(float x, float y, float h, int id) {
if(x < 0.0f || y < 0.0f)
return;
if(x < 0.0f || y < 0.0f)
return;

SetPixel((unsigned int)x, (unsigned int)y, h, id);
}
Expand Down
4 changes: 2 additions & 2 deletions external/assm/algorithms/ScreenDifferentialGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ScreenDifferentialGeometry
int width = normals_.cols();
int height = normals_.rows();

max_abs_curvatures_ = Grid<float>(height, width, 0.0f);
max_abs_curvatures_ = Grid<float>(width, height, 0.0f);

Eigen::GeneralizedSelfAdjointEigenSolver<Eigen::Matrix<Scalar, 2, 2>> solver;

Expand Down Expand Up @@ -297,7 +297,7 @@ class ScreenDifferentialGeometry
Scalar w, ww;

// and ... interpolate normal and max abs curvature from adjacent triangles with valid values
for (int i = 0; i != mesh_.n_faces() && !undefined.empty(); ++i)
for (size_t i = 0; i != mesh_.n_faces() && !undefined.empty(); ++i)
{
auto f = undefined.front(); undefined.pop();
ww = 0;
Expand Down
2 changes: 1 addition & 1 deletion external/assm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Grid<Eigen::Vector3f> loadNormalMap(const char *filename) {
for (int u = 0; u != normals_float.cols; ++u) {
cv::Vec3f n = normals_float.at<cv::Vec3f>(v, u);
n[0] = -n[0] + 127.0f;
n[1] = n[1] - 127.0f;
n[1] = -n[1] + 127.0f;
n[2] = -n[2] + 127.0f;
n /= sqrt(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]);

Expand Down
3 changes: 2 additions & 1 deletion relightlab/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
Project project;

int main(int argc, char *argv[]) {
setlocale(LC_ALL, ".UTF8");

RelightApp app(argc, argv);

setlocale(LC_ALL, "en_US.UTF8"); //needs to be called AFTER QApplication creation.

QCoreApplication::setOrganizationName("VCG");
QCoreApplication::setOrganizationDomain("vcg.isti.cnr.it");
QCoreApplication::setApplicationName("RelightLab");
Expand Down
15 changes: 11 additions & 4 deletions relightlab/normalstask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,17 @@ void NormalsTask::run() {
std::function<bool(QString s, int d)> callback = [this](QString s, int n)->bool { return this->progressed(s, n); };

if(exportPly) {
bool proceed = progressed("Integrating normals...", 0);
bool proceed = progressed("Integrating normals assm...", 0);
if(!proceed)
return;
QString filename = output.left(output.size() -4) + ".obj";

float precision = 0.1f;
assm(filename, normals, precision);

proceed = progressed("Integrating normals bni...", 50);
if(!proceed)
return;
std::vector<float> z;
bni_integrate(callback, imageset.width, imageset.height, normals, z, bni_k);
if(z.size() == 0) {
Expand Down Expand Up @@ -181,9 +185,12 @@ bool saveObj(const char *filename, pmp::SurfaceMesh &mesh) {

void NormalsTask::assm(QString filename, std::vector<float> &_normals, float approx_error) {
Grid<Eigen::Vector3f> normals(imageset.width, imageset.height, Eigen::Vector3f(0.0f, 0.0f, 0.0f));
for(int i = 0; i < _normals.size()/3; i++) {
normals[i] = Eigen::Vector3f(_normals[i*3], _normals[i*3+1], _normals[i*3+2]);
}
for(size_t y = 0; y < imageset.height; y++)
for(size_t x = 0; x < imageset.width; x++) {
int i = 3*(x + y*imageset.width);
normals.at(y, x) = Eigen::Vector3f(-_normals[i+0], -_normals[i+1], -_normals[i+2]);
}

Grid<unsigned char> mask(imageset.width, imageset.height, 0);
mask.fill(255);

Expand Down
2 changes: 1 addition & 1 deletion relightlab/relightlab.pro
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ win32:INCLUDEPATH += ../external/libjpeg-turbo-2.0.6/include \
../src/
win32:LIBS += ../external/libjpeg-turbo-2.0.6/lib/jpeg-static.lib

unix:INCLUDEPATH += /usr/include/eigen3
unix:INCLUDEPATH += ../external/eigen-3.3.9/
unix:LIBS += -ljpeg -ltiff -lgomp
unix:QMAKE_CXXFLAGS += -fopenmp

Expand Down

0 comments on commit aac66f8

Please sign in to comment.