Skip to content

Commit aac66f8

Browse files
committed
assm library integration debugged.
1 parent f5aaa3b commit aac66f8

10 files changed

+32
-25
lines changed

external/assm/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
77
find_package (Eigen3)
88
if(NOT Eigen3_FOUND)
99
set(EIGEN3_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../eigen-3.3.9)
10-
1110
endif()
1211

1312
include_directories(${EIGEN3_INCLUDE_DIR})

external/assm/Grid.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ template <class T> class Grid: public std::vector<T> {
1010

1111
public:
1212
Grid() {}
13-
Grid(size_t rows, size_t cols, const T &zero) {
13+
Grid(size_t cols, size_t rows, const T &zero) {
1414
_rows = rows;
1515
_cols = cols;
1616
_zero = zero;
1717
this->resize(rows*cols, _zero);
1818
}
1919
size_t rows() const { return _rows; }
2020
size_t cols() const { return _cols; }
21-
T &at(size_t row, size_t col) { return (*this)[row + col*_rows]; }
22-
const T &at(size_t row, size_t col) const { return (*this)[row + col*_rows]; }
21+
T &at(size_t row, size_t col) { return (*this)[row + col*_cols]; }
22+
const T &at(size_t row, size_t col) const { return (*this)[row + col*_cols]; }
2323
void fill(T t) {
2424
for(T &v: *this)
2525
v = t;
@@ -54,8 +54,8 @@ template <class T> class Grid: public std::vector<T> {
5454
Grid result(_rows, _cols, _zero);
5555

5656
if (alongRows) {
57-
for (int i = 0; i < _rows; ++i) {
58-
for (int j = 0; j < _cols; ++j) {
57+
for (int i = 0; i < int(_rows); ++i) {
58+
for (int j = 0; j < int(_cols); ++j) {
5959
T sum = _zero;
6060
for (int k = -radius; k <= radius; ++k) {
6161
int idx = j + k;
@@ -67,12 +67,12 @@ template <class T> class Grid: public std::vector<T> {
6767
}
6868
}
6969
} else {
70-
for (int j = 0; j < _cols; ++j) {
71-
for (int i = 0; i < _rows; ++i) {
70+
for (int j = 0; j < int(_cols); ++j) {
71+
for (int i = 0; i < int(_rows); ++i) {
7272
T sum = _zero;
7373
for (int k = -radius; k <= radius; ++k) {
7474
int idx = i + k;
75-
if (idx >= 0 && idx < _rows) {
75+
if (idx >= 0 && idx < int(_rows)) {
7676
sum += at(idx, j) * kernel[k + radius];
7777
}
7878
}

external/assm/SurfaceMesh.h

-2
Original file line numberDiff line numberDiff line change
@@ -1926,8 +1926,6 @@ class SurfaceMesh
19261926
// are there any deleted entities?
19271927
inline bool has_garbage() const { return has_garbage_; }
19281928

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

external/assm/algorithms/Integration.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class Integration
7373
int n = mesh_.n_vertices();
7474

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

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

173174
Eigen::ConjugateGradient<Eigen::SparseMatrix<T>> cg;
174175
cg.compute(L);
175-
Eigen::Vector<T, -1> depth = cg.solve(b);
176+
//Eigen::Vector<T, -1> depth = cg.solve(b);
177+
Eigen::Matrix<T, -1, 1> depth = cg.solve(b);
176178

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

external/assm/algorithms/Rasterizer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Span::Span(float h1_, int x1, float h2_, int x2) {
6363

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

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

7575
void Rasterizer::SetPixel(float x, float y, float h, int id) {
76-
if(x < 0.0f || y < 0.0f)
77-
return;
76+
if(x < 0.0f || y < 0.0f)
77+
return;
7878

7979
SetPixel((unsigned int)x, (unsigned int)y, h, id);
8080
}

external/assm/algorithms/ScreenDifferentialGeometry.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class ScreenDifferentialGeometry
125125
int width = normals_.cols();
126126
int height = normals_.rows();
127127

128-
max_abs_curvatures_ = Grid<float>(height, width, 0.0f);
128+
max_abs_curvatures_ = Grid<float>(width, height, 0.0f);
129129

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

@@ -297,7 +297,7 @@ class ScreenDifferentialGeometry
297297
Scalar w, ww;
298298

299299
// and ... interpolate normal and max abs curvature from adjacent triangles with valid values
300-
for (int i = 0; i != mesh_.n_faces() && !undefined.empty(); ++i)
300+
for (size_t i = 0; i != mesh_.n_faces() && !undefined.empty(); ++i)
301301
{
302302
auto f = undefined.front(); undefined.pop();
303303
ww = 0;

external/assm/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Grid<Eigen::Vector3f> loadNormalMap(const char *filename) {
7575
for (int u = 0; u != normals_float.cols; ++u) {
7676
cv::Vec3f n = normals_float.at<cv::Vec3f>(v, u);
7777
n[0] = -n[0] + 127.0f;
78-
n[1] = n[1] - 127.0f;
78+
n[1] = -n[1] + 127.0f;
7979
n[2] = -n[2] + 127.0f;
8080
n /= sqrt(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]);
8181

relightlab/main.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
Project project;
1616

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

2019
RelightApp app(argc, argv);
2120

21+
setlocale(LC_ALL, "en_US.UTF8"); //needs to be called AFTER QApplication creation.
22+
2223
QCoreApplication::setOrganizationName("VCG");
2324
QCoreApplication::setOrganizationDomain("vcg.isti.cnr.it");
2425
QCoreApplication::setApplicationName("RelightLab");

relightlab/normalstask.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,17 @@ void NormalsTask::run() {
130130
std::function<bool(QString s, int d)> callback = [this](QString s, int n)->bool { return this->progressed(s, n); };
131131

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

138138
float precision = 0.1f;
139139
assm(filename, normals, precision);
140+
141+
proceed = progressed("Integrating normals bni...", 50);
142+
if(!proceed)
143+
return;
140144
std::vector<float> z;
141145
bni_integrate(callback, imageset.width, imageset.height, normals, z, bni_k);
142146
if(z.size() == 0) {
@@ -181,9 +185,12 @@ bool saveObj(const char *filename, pmp::SurfaceMesh &mesh) {
181185

182186
void NormalsTask::assm(QString filename, std::vector<float> &_normals, float approx_error) {
183187
Grid<Eigen::Vector3f> normals(imageset.width, imageset.height, Eigen::Vector3f(0.0f, 0.0f, 0.0f));
184-
for(int i = 0; i < _normals.size()/3; i++) {
185-
normals[i] = Eigen::Vector3f(_normals[i*3], _normals[i*3+1], _normals[i*3+2]);
186-
}
188+
for(size_t y = 0; y < imageset.height; y++)
189+
for(size_t x = 0; x < imageset.width; x++) {
190+
int i = 3*(x + y*imageset.width);
191+
normals.at(y, x) = Eigen::Vector3f(-_normals[i+0], -_normals[i+1], -_normals[i+2]);
192+
}
193+
187194
Grid<unsigned char> mask(imageset.width, imageset.height, 0);
188195
mask.fill(255);
189196

relightlab/relightlab.pro

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ win32:INCLUDEPATH += ../external/libjpeg-turbo-2.0.6/include \
1616
../src/
1717
win32:LIBS += ../external/libjpeg-turbo-2.0.6/lib/jpeg-static.lib
1818

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

0 commit comments

Comments
 (0)