-
Notifications
You must be signed in to change notification settings - Fork 40
Task06 Вадим Бенкевич НИИЧАВО #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,6 @@ | |
|
|
||
| #define LAMBDA_OUT 1.0 | ||
| #define LAMBDA_IN 1.0 | ||
|
|
||
| // Tolerance parameter for weight fading | ||
| #define SIGMA_FACTOR 3.0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,12 +58,15 @@ void MinCutModelBuilder::appendToTriangulation( | |
| // проверяем насколько ближайшая точка далеко | ||
| vector3d np = from_cgal_point(nearest_vertex->point()); | ||
| // TODO 2001 appendToTriangulation(): реализуйте нормальную проверку объединять ли точку с уже добавленной ранее (с учетом r и MERGE_THRESHOLD_RADIUS_KOEF) | ||
| to_merge = false; | ||
| to_merge = cv::norm(np - p) < MERGE_THRESHOLD_RADIUS_KOEF * r; | ||
| // to_merge = false; | ||
| } | ||
|
|
||
| vertex_info_t p_info(camera_id, color); | ||
| p_info.radius = r; | ||
| if (to_merge) { | ||
| nearest_vertex->info().merge(p_info); | ||
| proxy->triangulation.move(nearest_vertex, CGAL::midpoint(nearest_vertex->point(), to_cgal_point(p))); | ||
| } else { | ||
| points_to_insert.push_back(std::make_pair(to_cgal_point(p), p_info)); | ||
| } | ||
|
|
@@ -145,9 +148,11 @@ void MinCutModelBuilder::insertBoundingBoxVertices(vector3d& bb_min, vector3d& b | |
| p[d] = corners[(i / powOf3) % 3][d]; | ||
| powOf3 *= 3; | ||
| } | ||
| vertex_info_t bounding_box_corner_empty_info; | ||
| vertex_info_t bounding_box_corner_info; | ||
| bounding_box_corner_info.sentinel = true; | ||
|
|
||
| debug_bounding_box_points.push_back(p); | ||
| points_to_insert.push_back(std::make_pair(to_cgal_point(p), bounding_box_corner_empty_info)); | ||
| points_to_insert.push_back(std::make_pair(to_cgal_point(p), bounding_box_corner_info)); | ||
| } | ||
| proxy->triangulation.insert(points_to_insert.begin(), points_to_insert.end()); | ||
|
|
||
|
|
@@ -319,6 +324,11 @@ void MinCutModelBuilder::buildMesh(std::vector<cv::Vec3i>& mesh_faces, std::vect | |
| const vector3d point0 = from_cgal_point(vi->point()); | ||
| const std::vector<cgal_facet_t> facets_around_point0 = fetchVertexBoundingFacets(proxy->triangulation, vi); | ||
|
|
||
| double sigma = 0.0; | ||
| if (vi->info().radius) { | ||
| sigma = SIGMA_FACTOR * *vi->info().radius; | ||
| } | ||
|
|
||
| for (unsigned int ci = 0; ci < vi->info().camera_ids.size(); ++ci) { | ||
| // для каждой вершины триангуляции point0 и каждой камеры к которой эта точка имеет отношение (т.е. содержится где-то в карте глубины) | ||
|
|
||
|
|
@@ -341,9 +351,11 @@ void MinCutModelBuilder::buildMesh(std::vector<cv::Vec3i>& mesh_faces, std::vect | |
| rassert(intersected_facet != cgal_facet_t(), 2378213120305); | ||
|
|
||
| // это ячейка триангуляции лежащая под поверхностью (т.е. сразу за вершиной) | ||
| const cell_handle_t cell_after_point = intersected_facet.first; | ||
| // const cell_handle_t cell_after_point = intersected_facet.first; | ||
| // добавляем пропускной способности из этой ячейки (из этого тетрагедрончика) к стоку | ||
| cell_after_point->info().t_capacity += LAMBDA_IN; | ||
| // cell_after_point->info().t_capacity += LAMBDA_IN; | ||
| const cell_handle_t sink_cell = proxy->triangulation.locate(to_cgal_point(point0 + sigma * ray_from_camera)); | ||
| sink_cell->info().t_capacity += LAMBDA_IN; | ||
| } | ||
|
|
||
| // шагаем от точки до камеры выставляя веса на треугольниках (они же ребра в графе) которые пересекаются по мере трассировки луча | ||
|
|
@@ -388,7 +400,11 @@ void MinCutModelBuilder::buildMesh(std::vector<cv::Vec3i>& mesh_faces, std::vect | |
| prev_distance = distance_from_surface; | ||
|
|
||
| // увеличиваем пропускную способность на треугольнике-ребре (в направлении от камеры к точке) | ||
| next_cell->info().facets_capacities[next_cell_facet_subindex] += LAMBDA_OUT; | ||
| double face_capacity = LAMBDA_OUT; | ||
| if (sigma != 0.0) { | ||
| face_capacity *= (1.0 - std::exp(-prev_distance * prev_distance / (2.0 * sigma * sigma))); | ||
| } | ||
| next_cell->info().facets_capacities[next_cell_facet_subindex] += face_capacity; | ||
|
|
||
| if (cur_facets.size() == 0) { | ||
| // если на будущее у нас нет кандидатов-треугольников, значит мы закончили наш путь и следующая ячейка содержит нашу камеру | ||
|
|
@@ -478,6 +494,16 @@ void MinCutModelBuilder::buildMesh(std::vector<cv::Vec3i>& mesh_faces, std::vect | |
| // TODO 2002 добавьте проверку - не опирается ли треугольник на одну из фиктивных вершин (лежащих на гранях вспомогательного bounding box), можете для этого использовать bb_min и bb_max, или добавьте явный флаг в каждую вершину | ||
| // иначе говоря сделайте так чтобы такие треугольники не добавлялись в результирующую модель эти большие красные треугольники | ||
|
|
||
| bool isSentinel = false; | ||
| for (int v_index = 1; v_index <= 3; ++v_index) { | ||
| auto vi = ci->vertex((i + v_index) % 4); | ||
| isSentinel |= vi->info().sentinel; | ||
| } | ||
|
|
||
| if (isSentinel) { | ||
| continue; | ||
| } | ||
|
|
||
| for (int v_index = 1; v_index <= 3; ++v_index) { | ||
| auto vi = ci->vertex((i + v_index) % 4); | ||
| size_t& surface_vertex_id = vi->info().vertex_on_surface_id; | ||
|
|
@@ -490,6 +516,16 @@ void MinCutModelBuilder::buildMesh(std::vector<cv::Vec3i>& mesh_faces, std::vect | |
| // TODO 2003 некоторые треугольники выглядят темными в результирующей модели, проблема уходит если выключить в MeshLab освещение (кнопка желтой лампочка - Light on/off) которое учитывает нормаль, которая строится с учетом | ||
| // порядка вершин треугольника (по часовой стрелке или против) иначе говоря оказывается что порядок обхода вершин в треугольнике не всегда корректен подумайте чем это вызывано и поправьте (лучше всего это делать посматривая на | ||
| // картинку 'Figure 44.1' в документации https://doc.cgal.org/latest/Triangulation_3/index.html ) | ||
| vector3d p0 = from_cgal_point(ci->vertex((i + 1) % 4)->point()); | ||
| vector3d p1 = from_cgal_point(ci->vertex((i + 2) % 4)->point()); | ||
| vector3d p2 = from_cgal_point(ci->vertex((i + 3) % 4)->point()); | ||
|
|
||
| vector3d normal = cv::normalize(((p1 - p0).cross(p2 - p1))); | ||
|
|
||
| vector3d p3 = from_cgal_point(ci->vertex(i)->point()); | ||
| if ((p3 - p0).dot(normal) > 0) { | ||
| std::swap(face[0], face[1]); | ||
| } | ||
|
|
||
| mesh_faces.push_back(face); | ||
| } | ||
|
|
@@ -537,8 +573,13 @@ void MinCutModelBuilder::buildMesh(std::vector<cv::Vec3i>& mesh_faces, std::vect | |
| // TODO 3500 Weak support: реализуйте идею из jancosek2011 - Multi-View Reconstruction Preserving Weakly-Supported Surfaces - https://compsciclub.ru/attachments/classes/file_XyLpDjLx/jancosek2011.pdf | ||
|
|
||
| // TODO 4001 подвиньте вершины в среднюю координату среди всех точек которые в ней зачлись | ||
| // Считаю нечестное среднее (считаю среднее для двух точек при слиянии), но зато обновляю триангуляцию. Интересно насколько сильно это отличается от честного усреднения. | ||
| // Я бы предположил, что вряд ли это можно заметить. | ||
| // TODO 4002 поэкспериментируйте со значением MERGE_THRESHOLD_RADIUS_KOEF, есть ли интересности? какое значение вы бы предложили использовать в условной финальной версии? | ||
| // Небольшое изменение порога (0.1 -> 0.5) резко снижает количество треугольников (84000->34000). По качеству модели сложно что-либо сказать (она выглядит плохо | ||
| // при любом значении :) ). А дальше даже увеличение в 100 раз не дает такого сильного выигрыша (34000->24000) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :) |
||
| // TODO 4003 добавьте усреднение цветов среди всех склеившихся вершин, приложите скриншот с/без усреднения | ||
| // Аналогично позициям осредняю цвет при каждом слиянии | ||
|
|
||
| // TODO 5001 как в целом можно ускорить реализацию? есть ли идеи? попробуйте это сделать (и запишите какого ускорения получилось добиться, а так же изменился ли результат) | ||
| // подсказки-идеи: | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, тоже так думаю, надежнее всего проверить посмотрев на результат с/без (т.н. ablations), еще приятнее делать "честный" вариант тем что это делает алгоритм более легко интерпретируемым - помогает при анализе проблем