Skip to content
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

Merge 101 #12

Merged
merged 17 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apps/texrecon/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define KEEP_UNSEEN_FACES "keep_unseen_faces"
#define NADIR_MODE "nadir_mode"
#define NADIR_WEIGHT "nadir_weight"
#define NUM_THREADS "num_threads"

Arguments parse_args(int argc, char **argv) {
util::Arguments args;
Expand All @@ -34,7 +35,7 @@ Arguments parse_args(int argc, char **argv) {
"\nA .cam file is structured as follows:"
"\n tx ty tz R00 R01 R02 R10 R11 R12 R20 R21 R22"
"\n f d0 d1 paspect ppx ppy"
"\nFirst line: Extrinsics - translation vector and rotation matrix"
"\nFirst line: Extrinsics - translation vector and rotation matrix (the transform from world to camera)"
"\nSecond line: Intrinsics - focal length, distortion coefficients, pixel aspect ratio and principal point"
"\nThe focal length is the distance between camera center and image plane normalized by dividing with the larger image dimension."
"\nFor non zero distortion coefficients the image will be undistorted prior to the texturing process."
Expand Down Expand Up @@ -92,6 +93,8 @@ Arguments parse_args(int argc, char **argv) {
"Write out timings for each algorithm step (OUT_PREFIX + _timings.csv)");
args.add_option('\0', NO_INTERMEDIATE_RESULTS, false,
"Do not write out intermediate results");
args.add_option('\0', NUM_THREADS, true,
"How many threads to use. Set 1 for determinism.");
args.parse(argc, argv);

Arguments conf;
Expand All @@ -107,6 +110,8 @@ Arguments parse_args(int argc, char **argv) {
conf.write_intermediate_results = true;
conf.write_view_selection_model = false;

conf.num_threads = -1;

/* Handle optional arguments. */
for (util::ArgResult const* i = args.next_option();
i != 0; i = args.next_option()) {
Expand Down Expand Up @@ -152,6 +157,8 @@ Arguments parse_args(int argc, char **argv) {
conf.write_timings = true;
} else if (i->opt->lopt == NO_INTERMEDIATE_RESULTS) {
conf.write_intermediate_results = false;
} else if (i->opt->lopt == NUM_THREADS) {
conf.num_threads = std::stoi(i->arg);
} else {
throw std::invalid_argument("Invalid long option");
}
Expand Down
2 changes: 2 additions & 0 deletions apps/texrecon/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ struct Arguments {
bool write_intermediate_results;
bool write_view_selection_model;

int num_threads;

/** Returns a muliline string of the current arguments. */
std::string to_string();
};
Expand Down
9 changes: 9 additions & 0 deletions apps/texrecon/texrecon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <tbb/task_scheduler_init.h>
#include <omp.h>

#include <util/timer.h>
#include <util/system.h>
Expand Down Expand Up @@ -57,6 +59,13 @@ int main(int argc, char **argv) {
std::exit(EXIT_FAILURE);
}

// Set the number of threads to use.
tbb::task_scheduler_init schedule(conf.num_threads > 0 ? conf.num_threads : tbb::task_scheduler_init::automatic);
if (conf.num_threads > 0) {
omp_set_dynamic(0);
omp_set_num_threads(conf.num_threads);
}

std::cout << "Load and prepare mesh: " << std::endl;
mve::TriangleMesh::Ptr mesh;
try {
Expand Down
7 changes: 4 additions & 3 deletions elibs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ externalproject_add(ext_rayint

externalproject_add(ext_eigen
PREFIX ext_eigen
URL https://bitbucket.org/eigen/eigen/get/3.3.2.tar.gz
URL_MD5 36b5731ab7d7e0c10843ac93bd9fd270
URL https://gitlab.com/libeigen/eigen/-/archive/3.3.2/eigen-3.3.2.tar.gz
URL_MD5 02edfeec591ae09848223d622700a10b
SOURCE_DIR ${CMAKE_SOURCE_DIR}/elibs/eigen
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
Expand All @@ -32,7 +32,8 @@ externalproject_add(ext_eigen

externalproject_add(ext_mve
PREFIX mve
GIT_REPOSITORY https://github.com/simonfuhrmann/mve.git
GIT_REPOSITORY https://github.com/OpenDroneMap/mve.git
GIT_TAG 099
UPDATE_COMMAND ""
SOURCE_DIR ${CMAKE_SOURCE_DIR}/elibs/mve
CONFIGURE_COMMAND ""
Expand Down
4 changes: 3 additions & 1 deletion libs/tex/build_obj_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ build_model(mve::TriangleMesh::ConstPtr mesh,

if (texture_atlas->is_grayscale()){
// Use only first channel (other two should be the same)
if (material.diffuse_map->get_type() == mve::IMAGE_TYPE_UINT16){
if (material.diffuse_map->get_type() == mve::IMAGE_TYPE_FLOAT){
material.diffuse_map = condense_grayscale<float>(std::dynamic_pointer_cast<mve::FloatImage>(texture_atlas->get_image()));
}else if (material.diffuse_map->get_type() == mve::IMAGE_TYPE_UINT16){
material.diffuse_map = condense_grayscale<uint16_t>(std::dynamic_pointer_cast<mve::RawImage>(texture_atlas->get_image()));
}else{
material.diffuse_map = condense_grayscale<uint8_t>(std::dynamic_pointer_cast<mve::ByteImage>(texture_atlas->get_image()));
Expand Down
13 changes: 10 additions & 3 deletions libs/tex/calculate_data_costs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,19 @@ calculate_face_projection_infos(mve::TriangleMesh::ConstPtr mesh,

TextureView * texture_view = &texture_views->at(j);
texture_view->load_image();
if (texture_view->get_image()->get_type() == mve::IMAGE_TYPE_UINT16){
if (texture_view->get_image()->get_type() == mve::IMAGE_TYPE_FLOAT){
texture_view->generate_validity_mask<float>();
}else if (texture_view->get_image()->get_type() == mve::IMAGE_TYPE_UINT16){
texture_view->generate_validity_mask<uint16_t>();
}else{
texture_view->generate_validity_mask<uint8_t>();
}

if (settings.data_term == DATA_TERM_GMI) {
if (texture_view->get_image()->get_type() == mve::IMAGE_TYPE_UINT16){
if (texture_view->get_image()->get_type() == mve::IMAGE_TYPE_FLOAT){
texture_view->generate_gradient_magnitude<float>();
texture_view->erode_validity_mask();
}else if (texture_view->get_image()->get_type() == mve::IMAGE_TYPE_UINT16){
texture_view->generate_gradient_magnitude<uint16_t>();
texture_view->erode_validity_mask();
}else{
Expand Down Expand Up @@ -234,7 +239,9 @@ calculate_face_projection_infos(mve::TriangleMesh::ConstPtr mesh,
FaceProjectionInfo info = {j, 0.0f, math::Vec3f(0.0f, 0.0f, 0.0f)};

/* Calculate quality. */
if (texture_view->get_image()->get_type() == mve::IMAGE_TYPE_UINT16){
if (texture_view->get_image()->get_type() == mve::IMAGE_TYPE_FLOAT){
texture_view->get_face_info<float>(v1, v2, v3, &info, settings);
}else if (texture_view->get_image()->get_type() == mve::IMAGE_TYPE_UINT16){
texture_view->get_face_info<uint16_t>(v1, v2, v3, &info, settings);
}else{
texture_view->get_face_info<uint8_t>(v1, v2, v3, &info, settings);
Expand Down
7 changes: 5 additions & 2 deletions libs/tex/generate_texture_patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ generate_candidate(int label, TextureView const & texture_view,
}

mve::FloatImage::Ptr image;
if (view_image->get_type() == mve::IMAGE_TYPE_UINT16){
if (view_image->get_type() == mve::IMAGE_TYPE_FLOAT){
mve::FloatImage::Ptr float_image = texture_view.get_image<float>();
image = mve::image::crop<float>(float_image, width, height, min_x, min_y, *math::Vec3f(3.402823466E38, 0, 3.402823466E38));
}else if (view_image->get_type() == mve::IMAGE_TYPE_UINT16){
mve::RawImage::Ptr raw_image = texture_view.get_image<uint16_t>();
raw_image = mve::image::crop<uint16_t>(raw_image, width, height, min_x, min_y, *math::Vec3us(65535, 0, 65535));
image = mve::image::raw_to_float_image(raw_image);
Expand All @@ -134,7 +137,7 @@ generate_candidate(int label, TextureView const & texture_view,
image = mve::image::byte_to_float_image(byte_image);
}

if (!settings.tone_mapping == TONE_MAPPING_NONE) {
if (settings.tone_mapping == TONE_MAPPING_GAMMA) {
mve::image::gamma_correct(image, 2.2f);
}

Expand Down
15 changes: 14 additions & 1 deletion libs/tex/generate_texture_views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,27 @@ from_nvm_scene(std::string const & nvm_file,
try {
image = mve::image::load_file(nvm_cam.filename);
} catch (...) {}

if (image == nullptr){
try{
image = mve::image::load_tiff_16_file(nvm_cam.filename);
}catch (...) {}
}

if (image == nullptr){
image = mve::image::load_tiff_16_file(nvm_cam.filename);
image = mve::image::load_tiff_float_file(nvm_cam.filename);
}

int const maxdim = std::max(image->width(), image->height());
mve_cam.flen = mve_cam.flen / static_cast<float>(maxdim);


switch (image->get_type()) {
case mve::IMAGE_TYPE_FLOAT: {
image = mve::image::image_undistort_vsfm<float>
(std::dynamic_pointer_cast<mve::FloatImage>(image), mve_cam.flen, nvm_cam.radial_distortion);
break;
}
case mve::IMAGE_TYPE_UINT16: {
image = mve::image::image_undistort_vsfm<uint16_t>
(std::dynamic_pointer_cast<mve::RawImage>(image), mve_cam.flen, nvm_cam.radial_distortion);
Expand Down
7 changes: 5 additions & 2 deletions libs/tex/material_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ MaterialLib::save_to_files(std::string const & prefix) const {
for (Material const & material : *this) {
std::string diffuse_map_postfix = "_" + material.name + "_map_Kd";
std::string ext = ".png";
if (material.diffuse_map->get_type() == mve::IMAGE_TYPE_UINT16){
if (material.diffuse_map->get_type() == mve::IMAGE_TYPE_UINT16 ||
material.diffuse_map->get_type() == mve::IMAGE_TYPE_FLOAT){
ext = ".tif";
}

Expand All @@ -46,7 +47,9 @@ MaterialLib::save_to_files(std::string const & prefix) const {

for (Material const & material : *this) {
std::string filename = prefix + "_" + material.name + "_map_Kd";
if (material.diffuse_map->get_type() == mve::IMAGE_TYPE_UINT16){
if (material.diffuse_map->get_type() == mve::IMAGE_TYPE_FLOAT){
mve::image::save_tiff_float_file(std::dynamic_pointer_cast<mve::FloatImage>(material.diffuse_map), filename + ".tif");
}else if (material.diffuse_map->get_type() == mve::IMAGE_TYPE_UINT16){
mve::image::save_tiff_16_file(std::dynamic_pointer_cast<mve::RawImage>(material.diffuse_map), filename + ".tif");
}else{
mve::image::save_png_file(std::dynamic_pointer_cast<mve::ByteImage>(material.diffuse_map), filename + ".png");
Expand Down
10 changes: 5 additions & 5 deletions libs/tex/sparse_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include "util/file_system.h"
#include "util/exception.h"

#define HEADER "SPT"
#define VERSION "0.2"
#define TEX_SPARSE_TABLE_HEADER "SPT"
#define TEX_SPARSE_TABLE_VERSION "0.2"

/**
* Class representing a sparse table optimized for row and column wise access.
Expand Down Expand Up @@ -118,7 +118,7 @@ SparseTable<C, R, T>::save_to_file(SparseTable const & sparse_table, const std::
C cols = sparse_table.cols();
R rows = sparse_table.rows();
std::size_t nnz = sparse_table.get_nnz();
out << HEADER << " " << VERSION << " " << cols << " " << rows << " " << nnz << std::endl;
out << TEX_SPARSE_TABLE_HEADER << " " << TEX_SPARSE_TABLE_VERSION << " " << cols << " " << rows << " " << nnz << std::endl;

for (C col = 0; col < cols; ++col) {
SparseTable::Column column = sparse_table.col(col);
Expand All @@ -145,15 +145,15 @@ SparseTable<C, R, T>::load_from_file(const std::string & filename, SparseTable<C

in >> header;

if (header != HEADER) {
if (header != TEX_SPARSE_TABLE_HEADER) {
in.close();
throw util::FileException(filename, "Not a SparseTable file!");
}

std::string version;
in >> version;

if (version != VERSION) {
if (version != TEX_SPARSE_TABLE_VERSION) {
in.close();
throw util::FileException(filename, "Incompatible version of SparseTable file!");
}
Expand Down
12 changes: 9 additions & 3 deletions libs/tex/texture_atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ TextureAtlas::TextureAtlas(unsigned int size, mve::ImageType type, bool grayscal

bin = RectangularBin::create(size, size);

if (type == mve::IMAGE_TYPE_UINT16){
if (type == mve::IMAGE_TYPE_FLOAT){
image = mve::FloatImage::create(size, size, 3);
}else if (type == mve::IMAGE_TYPE_UINT16){
image = mve::RawImage::create(size, size, 3);
}else{
image = mve::ByteImage::create(size, size, 3);
Expand Down Expand Up @@ -94,7 +96,9 @@ TextureAtlas::insert(TexturePatch::ConstPtr texture_patch) {
/* Update texture atlas and its validity mask. */


if (image->get_type() == mve::IMAGE_TYPE_UINT16){
if (image->get_type() == mve::IMAGE_TYPE_FLOAT){
copy_into<float>(texture_patch->get_image(), rect.min_x, rect.min_y, std::dynamic_pointer_cast<mve::FloatImage>(image), padding);
}else if (image->get_type() == mve::IMAGE_TYPE_UINT16){
mve::RawImage::Ptr patch_image = float_to_raw_image(
texture_patch->get_image(), 0.0f, 1.0f);
copy_into<uint16_t>(patch_image, rect.min_x, rect.min_y, std::dynamic_pointer_cast<mve::RawImage>(image), padding);
Expand Down Expand Up @@ -279,7 +283,9 @@ TextureAtlas::finalize() {
}

this->bin.reset();
if (image->get_type() == mve::IMAGE_TYPE_UINT16){
if (image->get_type() == mve::IMAGE_TYPE_FLOAT){
this->apply_edge_padding<float>();
}else if (image->get_type() == mve::IMAGE_TYPE_UINT16){
this->apply_edge_padding<uint16_t>();
}else{
this->apply_edge_padding<uint8_t>();
Expand Down
17 changes: 14 additions & 3 deletions libs/tex/texture_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@ TextureView::load_image(void) {
} catch (...) {}

if (image == NULL){
image = mve::image::load_tiff_16_file(image_file);
try{
image = mve::image::load_tiff_16_file(image_file);
} catch (...) {}
}

if (image == NULL){
image = mve::image::load_tiff_float_file(image_file);
}

// Assure images have always at least 3 channels
if (image->channels() == 1){
if (image->get_type() == mve::IMAGE_TYPE_UINT16){
if (image->get_type() == mve::IMAGE_TYPE_FLOAT){
image = mve::image::expand_grayscale<float>(std::dynamic_pointer_cast<mve::FloatImage>(image));
}else if (image->get_type() == mve::IMAGE_TYPE_UINT16){
image = mve::image::expand_grayscale<uint16_t>(std::dynamic_pointer_cast<mve::RawImage>(image));
}else{
image = mve::image::expand_grayscale<uint8_t>(std::dynamic_pointer_cast<mve::ByteImage>(image));
Expand Down Expand Up @@ -135,7 +143,10 @@ TextureView::export_triangle(math::Vec3f v1, math::Vec3f v2, math::Vec3f v3,

assert(width > 0 && height > 0);

if (image->get_type() == mve::IMAGE_TYPE_UINT16){
if (image->get_type() == mve::IMAGE_TYPE_FLOAT){
mve::image::save_tiff_float_file(mve::image::crop(get_image<float>(), width, height, left, top,
*math::Vec3f(3.402823466E38, 0, 3.402823466E38)), filename);
}else if (image->get_type() == mve::IMAGE_TYPE_UINT16){
mve::image::save_tiff_16_file(mve::image::crop(get_image<uint16_t>(), width, height, left, top,
*math::Vec3us(65535, 0, 65535)), filename);
}else{
Expand Down
4 changes: 2 additions & 2 deletions libs/tex/texture_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ TextureView::generate_validity_mask(void) {
int const x = pixel[0];
int const y = pixel[1];

int sum = 0;
double sum = 0.0;
for (int c = 0; c < image->channels(); ++c) {
sum += image->at(x, y, c);
}

if (sum == 0) {
if (sum == 0.0) {
validity_mask[x + y * width] = false;

std::vector<math::Vec2i> neighbours;
Expand Down