diff --git a/libs/yocto/yocto_image.cpp b/libs/yocto/yocto_image.cpp index 437eb76f4..f3feccb5a 100644 --- a/libs/yocto/yocto_image.cpp +++ b/libs/yocto/yocto_image.cpp @@ -1451,51 +1451,105 @@ static vector split_string(const string& str) { return ret; } +// Convert numbert of components +static vector convert_components( + const vector& pixels, int components, int components_to) { + if (components <= 0 || components > 4 || components_to <= 0 || + components_to > 4) + throw std::invalid_argument{"components not supported"}; + if (components == components_to) return pixels; + + auto cpixels = vector((size_t)components_to * pixels.size()); + for (auto i = 0ull; i < pixels.size(); i++) { + auto vp = pixels.data() + i * components; + auto cp = cpixels.data() + i * components_to; + if (components_to > 0) cp[0] = (components > 0) ? vp[0] : 0; + if (components_to > 1) cp[1] = (components > 1) ? vp[1] : 0; + if (components_to > 2) cp[2] = (components > 2) ? vp[2] : 0; + if (components_to > 3) cp[3] = (components > 3) ? vp[3] : 1; + } + return cpixels; +} + +// Convert numbert of components +static vector convert_components( + const vector& pixels, int components, int components_to) { + if (components <= 0 || components > 4 || components_to <= 0 || + components_to > 4) + throw std::invalid_argument{"components not supported"}; + if (components == components_to) return pixels; + + auto cpixels = vector((size_t)components_to * pixels.size()); + for (auto i = 0ull; i < pixels.size(); i++) { + auto vp = pixels.data() + i * components; + auto cp = cpixels.data() + i * components_to; + if (components_to > 0) cp[0] = (components > 0) ? vp[0] : 0; + if (components_to > 1) cp[1] = (components > 1) ? vp[1] : 0; + if (components_to > 2) cp[2] = (components > 2) ? vp[2] : 0; + if (components_to > 3) cp[3] = (components > 3) ? vp[3] : 255; + } + return cpixels; +} + // Pfm load -static float* load_pfm(const char* filename, int* w, int* h, int* nc, int req) { +static bool load_pfm(const string& filename, int& width, int& height, + int& components, vector& pixels, string& error) { + // error helpers + auto open_error = [filename, &error]() { + error = filename + ": file not found"; + return false; + }; + auto parse_error = [filename, &error]() { + error = filename + ": parse error"; + return false; + }; + auto read_error = [filename, &error]() { + error = filename + ": read error"; + return false; + }; + auto fs = open_file(filename, "rb"); - if (!fs) return nullptr; + if (!fs) return open_error(); // buffer auto buffer = array{}; auto toks = vector(); // read magic - if (!read_line(fs, buffer)) return nullptr; - toks = split_string(buffer.data()); - if (toks[0] == "Pf") - *nc = 1; - else if (toks[0] == "PF") - *nc = 3; - else - return nullptr; - - // read w, h - if (!read_line(fs, buffer)) return nullptr; + if (!read_line(fs, buffer)) return read_error(); toks = split_string(buffer.data()); - *w = atoi(toks[0].c_str()); - *h = atoi(toks[1].c_str()); + if (toks[0] == "Pf") { + components = 1; + } else if (toks[0] == "PF") { + components = 3; + } else { + return parse_error(); + } + + // read width, height + if (!read_line(fs, buffer)) return read_error(); + toks = split_string(buffer.data()); + width = atoi(toks[0].c_str()); + height = atoi(toks[1].c_str()); // read scale - if (!read_line(fs, buffer)) return nullptr; + if (!read_line(fs, buffer)) return read_error(); toks = split_string(buffer.data()); auto s = atof(toks[0].c_str()); // read the data (flip y) - auto npixels = (size_t)(*w) * (size_t)(*h); - auto nvalues = npixels * (size_t)(*nc); - auto nrow = (size_t)(*w) * (size_t)(*nc); - auto pixels = std::unique_ptr(new float[nvalues]); - for (auto j = *h - 1; j >= 0; j--) { - if (!read_values(fs, pixels.get() + j * nrow, nrow)) return nullptr; + auto npixels = (size_t)width * (size_t)height; + auto nvalues = npixels * (size_t)components; + auto nrow = (size_t)width * (size_t)components; + pixels = vector(nvalues); + for (auto j = height - 1; j >= 0; j--) { + if (!read_values(fs, pixels.data() + j * nrow, nrow)) return {}; } // endian conversion if (s > 0) { for (auto i = 0; i < nvalues; ++i) { - auto dta = (uint8_t*)(pixels.get() + i); - std::swap(dta[0], dta[3]); - std::swap(dta[1], dta[2]); + pixels[i] = swap_endian(pixels[i]); } } @@ -1505,82 +1559,44 @@ static float* load_pfm(const char* filename, int* w, int* h, int* nc, int req) { for (auto i = 0; i < nvalues; i++) pixels[i] *= scl; } - // proper number of channels - if (req == 0 || *nc == req) return pixels.release(); - - // pack into channels - if (req < 0 || req > 4) { - return nullptr; - } - auto cpixels = std::unique_ptr(new float[req * npixels]); - for (auto i = 0ull; i < npixels; i++) { - auto vp = pixels.get() + i * (*nc); - auto cp = cpixels.get() + i * req; - if (*nc == 1) { - switch (req) { - case 1: cp[0] = vp[0]; break; - case 2: - cp[0] = vp[0]; - cp[1] = vp[0]; - break; - case 3: - cp[0] = vp[0]; - cp[1] = vp[0]; - cp[2] = vp[0]; - break; - case 4: - cp[0] = vp[0]; - cp[1] = vp[0]; - cp[2] = vp[0]; - cp[3] = 1; - break; - } - } else { - switch (req) { - case 1: cp[0] = vp[0]; break; - case 2: - cp[0] = vp[0]; - cp[1] = vp[1]; - break; - case 3: - cp[0] = vp[0]; - cp[1] = vp[1]; - cp[2] = vp[2]; - break; - case 4: - cp[0] = vp[0]; - cp[1] = vp[1]; - cp[2] = vp[2]; - cp[3] = 1; - break; - } - } - } - return cpixels.release(); + // done + return true; } // save pfm -static bool save_pfm( - const char* filename, int w, int h, int nc, const float* pixels) { +static bool save_pfm(const string& filename, int width, int height, + int components, const vector& pixels, string& error) { + // error helpers + auto open_error = [filename, &error]() { + error = filename + ": file not found"; + return false; + }; + auto write_error = [filename, &error]() { + error = filename + ": write error"; + return false; + }; + auto fs = open_file(filename, "wb"); - if (!fs) return false; + if (!fs) return open_error(); - if (!write_text(fs, (nc == 1) ? "Pf\n"s : "PF\n"s)) return false; - if (!write_text(fs, std::to_string(w) + " " + std::to_string(h) + "\n")) + if (!write_text(fs, (components == 1) ? "Pf\n"s : "PF\n"s)) + return write_error(); + if (!write_text( + fs, std::to_string(width) + " " + std::to_string(height) + "\n")) return false; - if (!write_text(fs, "-1\n")) return false; - if (nc == 1 || nc == 3) { - if (!write_values(fs, pixels, w * h * nc)) return false; + if (!write_text(fs, "-1\n")) return write_error(); + if (components == 1 || components == 3) { + if (!write_values(fs, pixels.data(), pixels.size())) return write_error(); } else { - for (auto i = 0; i < w * h; i++) { + for (auto i = 0; i < width * height; i++) { auto vz = 0.0f; - auto v = pixels + i * nc; - if (!write_value(fs, v + 0)) return false; - if (!write_value(fs, v + 1)) return false; - if (nc == 2) { - if (!write_value(fs, &vz)) return false; + auto v = pixels.data() + i * components; + if (!write_value(fs, v + 0)) return write_error(); + if (!write_value(fs, v + 1)) return write_error(); + if (components == 2) { + if (!write_value(fs, &vz)) return write_error(); } else { - if (!write_value(fs, v + 2)) return false; + if (!write_value(fs, v + 2)) return write_error(); } } } @@ -1588,6 +1604,208 @@ static bool save_pfm( return true; } +// Png load +static bool load_png(const string& filename, int& width, int& height, + int& components, vector& pixels, string& error) { + // error helpers + auto open_error = [filename, &error]() { + error = filename + ": file not found"; + return false; + }; + + auto pixels_ptr = stbi_load( + filename.c_str(), &width, &height, &components, 0); + if (!pixels_ptr) return open_error(); + pixels = {pixels_ptr, + pixels_ptr + (size_t)width * (size_t)height * (size_t)components}; + free(pixels_ptr); + return true; +} + +// save png +static bool save_png(const string& filename, int width, int height, + int components, const vector& pixels, string& error) { + // error helpers + auto write_error = [filename, &error]() { + error = filename + ": write error"; + return false; + }; + + if (!stbi_write_png(filename.c_str(), width, height, components, + pixels.data(), width * components)) + return write_error(); + return true; +} + +// jpg load +static bool load_jpg(const string& filename, int& width, int& height, + int& components, vector& pixels, string& error) { + // error helpers + auto open_error = [filename, &error]() { + error = filename + ": file not found"; + return false; + }; + + auto pixels_ptr = stbi_load( + filename.c_str(), &width, &height, &components, 0); + if (!pixels_ptr) return open_error(); + pixels = {pixels_ptr, + pixels_ptr + (size_t)width * (size_t)height * (size_t)components}; + free(pixels_ptr); + return true; +} + +// save jpg +static bool save_jpg(const string& filename, int width, int height, + int components, const vector& pixels, string& error) { + // error helpers + auto write_error = [filename, &error]() { + error = filename + ": write error"; + return false; + }; + + if (!stbi_write_jpg( + filename.c_str(), width, height, components, pixels.data(), 75)) + return write_error(); + return true; +} + +// tga load +static bool load_tga(const string& filename, int& width, int& height, + int& components, vector& pixels, string& error) { + // error helpers + auto open_error = [filename, &error]() { + error = filename + ": file not found"; + return false; + }; + + auto pixels_ptr = stbi_load( + filename.c_str(), &width, &height, &components, 0); + if (!pixels_ptr) return open_error(); + pixels = {pixels_ptr, + pixels_ptr + (size_t)width * (size_t)height * (size_t)components}; + free(pixels_ptr); + return true; +} + +// save tga +static bool save_tga(const string& filename, int width, int height, + int components, const vector& pixels, string& error) { + // error helpers + auto write_error = [filename, &error]() { + error = filename + ": write error"; + return false; + }; + + if (!stbi_write_tga( + filename.c_str(), width, height, components, pixels.data())) + return write_error(); + return true; +} + +// jpg load +static bool load_bmp(const string& filename, int& width, int& height, + int& components, vector& pixels, string& error) { + // error helpers + auto open_error = [filename, &error]() { + error = filename + ": file not found"; + return false; + }; + + auto pixels_ptr = stbi_load( + filename.c_str(), &width, &height, &components, 0); + if (!pixels_ptr) return open_error(); + pixels = {pixels_ptr, + pixels_ptr + (size_t)width * (size_t)height * (size_t)components}; + free(pixels_ptr); + return true; +} + +// save jpg +static bool save_bmp(const string& filename, int width, int height, + int components, const vector& pixels, string& error) { + // error helpers + auto write_error = [filename, &error]() { + error = filename + ": write error"; + return false; + }; + + if (!stbi_write_bmp( + filename.c_str(), width, height, components, pixels.data())) + return write_error(); + return true; +} + +// hdr load +static bool load_hdr(const string& filename, int& width, int& height, + int& components, vector& pixels, string& error) { + // error helpers + auto open_error = [filename, &error]() { + error = filename + ": file not found"; + return false; + }; + + auto pixels_ptr = stbi_loadf( + filename.c_str(), &width, &height, &components, 0); + if (!pixels_ptr) return open_error(); + pixels = {pixels_ptr, + pixels_ptr + (size_t)width * (size_t)height * (size_t)components}; + free(pixels_ptr); + return true; +} + +// save hdr +static bool save_hdr(const string& filename, int width, int height, + int components, const vector& pixels, string& error) { + // error helpers + auto write_error = [filename, &error]() { + error = filename + ": write error"; + return false; + }; + + if (!stbi_write_hdr( + filename.c_str(), width, height, components, pixels.data())) + return write_error(); + return true; +} + +// exr load +static bool load_exr(const string& filename, int& width, int& height, + int& components, vector& pixels, string& error) { + // error helpers + auto open_error = [filename, &error]() { + error = filename + ": file not found"; + return false; + }; + + auto pixels_ptr = (float*)nullptr; + if (LoadEXR(&pixels_ptr, &width, &height, filename.c_str(), nullptr) != 0) + return open_error(); + if (pixels_ptr == nullptr) return open_error(); + components = 4; + pixels = {pixels_ptr, + pixels_ptr + (size_t)width * (size_t)height * (size_t)components}; + free(pixels_ptr); + return true; +} + +// save exr +static bool save_exr(const string& filename, int width, int height, + int components, const vector& pixels, string& error) { + // error helpers + auto write_error = [filename, &error]() { + error = filename + ": write error"; + return false; + }; + + if (components != 4) throw std::invalid_argument{"not supported yet"}; + + if (SaveEXR(pixels.data(), width, height, components, 1, filename.c_str(), + nullptr) < 0) + return write_error(); + return true; +} + // Check if an image is HDR based on filename. bool is_hdr_filename(const string& filename) { auto ext = path_extension(filename); @@ -1595,8 +1813,7 @@ bool is_hdr_filename(const string& filename) { } // Loads an hdr image. -[[nodiscard]] bool load_image( - const string& filename, image& img, string& error) { +bool load_image(const string& filename, image& img, string& error) { auto format_error = [filename, &error]() { error = filename + ": unknown format"; return false; @@ -1618,22 +1835,27 @@ bool is_hdr_filename(const string& filename) { return true; } else if (ext == ".pfm" || ext == ".PFM") { auto width = 0, height = 0, ncomp = 0; - auto pixels = load_pfm(filename.c_str(), &width, &height, &ncomp, 4); - if (pixels == nullptr) return read_error(); - img = image{{width, height}, (const vec4f*)pixels}; - delete[] pixels; + auto pixels = vector{}; + if (!load_pfm(filename, width, height, ncomp, pixels, error)) return false; + if (pixels.empty()) return read_error(); + if (ncomp != 4) pixels = convert_components(pixels, ncomp, 4); + img = image{{width, height}, (const vec4f*)pixels.data()}; return true; } else if (ext == ".hdr" || ext == ".HDR") { auto width = 0, height = 0, ncomp = 0; - auto pixels = stbi_loadf(filename.c_str(), &width, &height, &ncomp, 4); - if (pixels == nullptr) return read_error(); - img = image{{width, height}, (const vec4f*)pixels}; - free(pixels); + auto pixels = vector{}; + if (!load_hdr(filename, width, height, ncomp, pixels, error)) return false; + if (pixels.empty()) return read_error(); + if (ncomp != 4) pixels = convert_components(pixels, ncomp, 4); + img = image{{width, height}, (const vec4f*)pixels.data()}; return true; } else if (!is_hdr_filename(filename)) { - auto imgb = image{}; - if (!load_image(filename, imgb, error)) return false; - img = srgb_to_rgb(imgb); + auto width = 0, height = 0, ncomp = 0; + auto pixels = vector{}; + if (!load_exr(filename, width, height, ncomp, pixels, error)) return false; + if (pixels.empty()) return read_error(); + if (ncomp != 4) pixels = convert_components(pixels, ncomp, 4); + img = image{{width, height}, (const vec4f*)pixels.data()}; return true; } else { return format_error(); @@ -1641,7 +1863,7 @@ bool is_hdr_filename(const string& filename) { } // Saves an hdr image. -[[nodiscard]] bool save_image( +bool save_image( const string& filename, const image& img, string& error) { auto format_error = [filename, &error]() { error = filename + ": unknown format"; @@ -1654,20 +1876,17 @@ bool is_hdr_filename(const string& filename) { auto ext = path_extension(filename); if (ext == ".hdr" || ext == ".HDR") { - if (!stbi_write_hdr( - filename.c_str(), img.width(), img.height(), 4, (float*)img.data())) - return write_error(); - return true; + return save_hdr(filename, img.width(), img.height(), 4, + {(const float*)img.data(), (const float*)img.data() + img.count() * 4}, + error); } else if (ext == ".pfm" || ext == ".PFM") { - if (!save_pfm( - filename.c_str(), img.width(), img.height(), 4, (float*)img.data())) - return write_error(); - return true; + return save_pfm(filename, img.width(), img.height(), 4, + {(const float*)img.data(), (const float*)img.data() + img.count() * 4}, + error); } else if (ext == ".exr" || ext == ".EXR") { - if (SaveEXR((float*)img.data(), img.width(), img.height(), 4, 1, - filename.c_str(), nullptr) < 0) - return write_error(); - return true; + return save_exr(filename, img.width(), img.height(), 4, + {(const float*)img.data(), (const float*)img.data() + img.count() * 4}, + error); } else if (!is_hdr_filename(filename)) { return save_image(filename, rgb_to_srgbb(img), error); } else { @@ -1676,8 +1895,7 @@ bool is_hdr_filename(const string& filename) { } // Loads an ldr image. -[[nodiscard]] bool load_image( - const string& filename, image& img, string& error) { +bool load_image(const string& filename, image& img, string& error) { auto format_error = [filename, &error]() { error = filename + ": unknown format"; return false; @@ -1688,13 +1906,37 @@ bool is_hdr_filename(const string& filename) { }; auto ext = path_extension(filename); - if (ext == ".png" || ext == ".PNG" || ext == ".jpg" || ext == ".JPG" || - ext == ".tga" || ext == ".TGA" || ext == ".bmp" || ext == ".BMP") { + if (ext == ".png" || ext == ".PNG") { auto width = 0, height = 0, ncomp = 0; - auto pixels = stbi_load(filename.c_str(), &width, &height, &ncomp, 4); - if (!pixels) return read_error(); - img = image{{width, height}, (const vec4b*)pixels}; - free(pixels); + auto pixels = vector{}; + if (!load_png(filename, width, height, ncomp, pixels, error)) return false; + if (pixels.empty()) return read_error(); + if (ncomp != 4) pixels = convert_components(pixels, ncomp, 4); + img = image{{width, height}, (const vec4b*)pixels.data()}; + return true; + } else if (ext == ".jpg" || ext == ".JPG") { + auto width = 0, height = 0, ncomp = 0; + auto pixels = vector{}; + if (!load_jpg(filename, width, height, ncomp, pixels, error)) return false; + if (pixels.empty()) return read_error(); + if (ncomp != 4) pixels = convert_components(pixels, ncomp, 4); + img = image{{width, height}, (const vec4b*)pixels.data()}; + return true; + } else if (ext == ".tga" || ext == ".TGA") { + auto width = 0, height = 0, ncomp = 0; + auto pixels = vector{}; + if (!load_tga(filename, width, height, ncomp, pixels, error)) return false; + if (pixels.empty()) return read_error(); + if (ncomp != 4) pixels = convert_components(pixels, ncomp, 4); + img = image{{width, height}, (const vec4b*)pixels.data()}; + return true; + } else if (ext == ".bmp" || ext == ".BMP") { + auto width = 0, height = 0, ncomp = 0; + auto pixels = vector{}; + if (!load_bmp(filename, width, height, ncomp, pixels, error)) return false; + if (pixels.empty()) return read_error(); + if (ncomp != 4) pixels = convert_components(pixels, ncomp, 4); + img = image{{width, height}, (const vec4b*)pixels.data()}; return true; } else if (is_hdr_filename(filename)) { auto imgf = image{}; @@ -1707,7 +1949,7 @@ bool is_hdr_filename(const string& filename) { } // Saves an ldr image. -[[nodiscard]] bool save_image( +bool save_image( const string& filename, const image& img, string& error) { auto format_error = [filename, &error]() { error = filename + ": unknown format"; @@ -1720,25 +1962,21 @@ bool is_hdr_filename(const string& filename) { auto ext = path_extension(filename); if (ext == ".png" || ext == ".PNG") { - if (!stbi_write_png(filename.c_str(), img.width(), img.height(), 4, - img.data(), img.width() * 4)) - return write_error(); - return true; + return save_png(filename, img.width(), img.height(), 4, + {(const byte*)img.data(), (const byte*)img.data() + img.count() * 4}, + error); } else if (ext == ".jpg" || ext == ".JPG") { - if (!stbi_write_jpg( - filename.c_str(), img.width(), img.height(), 4, img.data(), 75)) - return write_error(); - return true; + return save_jpg(filename, img.width(), img.height(), 4, + {(const byte*)img.data(), (const byte*)img.data() + img.count() * 4}, + error); } else if (ext == ".tga" || ext == ".TGA") { - if (!stbi_write_tga( - filename.c_str(), img.width(), img.height(), 4, img.data())) - return write_error(); - return true; + return save_tga(filename, img.width(), img.height(), 4, + {(const byte*)img.data(), (const byte*)img.data() + img.count() * 4}, + error); } else if (ext == ".bmp" || ext == ".BMP") { - if (!stbi_write_bmp( - filename.c_str(), img.width(), img.height(), 4, img.data())) - return write_error(); - return true; + return save_bmp(filename, img.width(), img.height(), 4, + {(const byte*)img.data(), (const byte*)img.data() + img.count() * 4}, + error); } else if (is_hdr_filename(filename)) { return save_image(filename, srgb_to_rgb(img), error); } else { @@ -1747,8 +1985,7 @@ bool is_hdr_filename(const string& filename) { } // Loads a 16 bit image. -[[nodiscard]] bool load_image( - const string& filename, image& img, string& error) { +bool load_image(const string& filename, image& img, string& error) { auto format_error = [filename, &error]() { error = filename + ": unknown format"; return false; @@ -1759,8 +1996,7 @@ bool is_hdr_filename(const string& filename) { }; auto ext = path_extension(filename); - if (ext == ".png" || ext == ".PNG" || ext == ".jpg" || ext == ".JPG" || - ext == ".tga" || ext == ".TGA" || ext == ".bmp" || ext == ".BMP") { + if (ext == ".png" || ext == ".PNG") { auto width = 0, height = 0, ncomp = 0; auto pixels = stbi_load_16(filename.c_str(), &width, &height, &ncomp, 4); if (pixels == nullptr) return read_error(); @@ -1805,135 +2041,76 @@ bool save_image(const string& filename, const image& imgf, namespace yocto { // Volume load -static float* load_yvol( - const char* filename, int* w, int* h, int* d, int* nc, int req) { +static bool load_yvol(const string& filename, int& width, int& height, + int& depth, int& components, vector& voxels, string& error) { + // error helpers + auto open_error = [filename, &error]() { + error = filename + ": file not found"; + return false; + }; + auto parse_error = [filename, &error]() { + error = filename + ": parse error"; + return false; + }; + auto read_error = [filename, &error]() { + error = filename + ": read error"; + return false; + }; + auto fs = open_file(filename, "rb"); - if (!fs) return nullptr; + if (!fs) return open_error(); // buffer auto buffer = array{}; auto toks = vector(); // read magic - if (!read_line(fs, buffer)) return nullptr; + if (!read_line(fs, buffer)) return parse_error(); toks = split_string(buffer.data()); - if (toks[0] != "YVOL") return nullptr; + if (toks[0] != "YVOL") return parse_error(); - // read w, h - if (!read_line(fs, buffer)) return nullptr; - toks = split_string(buffer.data()); - *w = atoi(toks[0].c_str()); - *h = atoi(toks[1].c_str()); - *d = atoi(toks[2].c_str()); - *nc = atoi(toks[3].c_str()); + // read width, height + if (!read_line(fs, buffer)) return parse_error(); + toks = split_string(buffer.data()); + width = atoi(toks[0].c_str()); + height = atoi(toks[1].c_str()); + depth = atoi(toks[2].c_str()); + components = atoi(toks[3].c_str()); // read data - auto nvoxels = (size_t)(*w) * (size_t)(*h) * (size_t)(*d); - auto nvalues = nvoxels * (size_t)(*nc); - auto voxels = std::unique_ptr(new float[nvalues]); - if (!read_values(fs, voxels.get(), nvalues)) return nullptr; - - // proper number of channels - if (req == 0 || *nc == req) return voxels.release(); + auto nvoxels = (size_t)width * (size_t)height * (size_t)depth; + auto nvalues = nvoxels * (size_t)components; + voxels = vector(nvalues); + if (!read_values(fs, voxels.data(), nvalues)) return read_error(); - // pack into channels - if (req < 0 || req > 4) { - return nullptr; - } - auto cvoxels = std::unique_ptr(new float[req * nvoxels]); - for (auto i = 0; i < nvoxels; i++) { - auto vp = voxels.get() + i * (*nc); - auto cp = cvoxels.get() + i * req; - if (*nc == 1) { - switch (req) { - case 1: cp[0] = vp[0]; break; - case 2: - cp[0] = vp[0]; - cp[1] = vp[0]; - break; - case 3: - cp[0] = vp[0]; - cp[1] = vp[0]; - cp[2] = vp[0]; - break; - case 4: - cp[0] = vp[0]; - cp[1] = vp[0]; - cp[2] = vp[0]; - cp[3] = 1; - break; - } - } else if (*nc == 2) { - switch (req) { - case 1: cp[0] = vp[0]; break; - case 2: - cp[0] = vp[0]; - cp[1] = vp[1]; - break; - case 3: - cp[0] = vp[0]; - cp[1] = vp[1]; - break; - case 4: - cp[0] = vp[0]; - cp[1] = vp[1]; - break; - } - } else if (*nc == 3) { - switch (req) { - case 1: cp[0] = vp[0]; break; - case 2: - cp[0] = vp[0]; - cp[1] = vp[1]; - break; - case 3: - cp[0] = vp[0]; - cp[1] = vp[1]; - cp[2] = vp[2]; - break; - case 4: - cp[0] = vp[0]; - cp[1] = vp[1]; - cp[2] = vp[2]; - cp[3] = 1; - break; - } - } else if (*nc == 4) { - switch (req) { - case 1: cp[0] = vp[0]; break; - case 2: - cp[0] = vp[0]; - cp[1] = vp[1]; - break; - case 3: - cp[0] = vp[0]; - cp[1] = vp[1]; - cp[2] = vp[2]; - break; - case 4: - cp[0] = vp[0]; - cp[1] = vp[1]; - cp[2] = vp[2]; - cp[3] = vp[3]; - break; - } - } - } - return cvoxels.release(); + // done + return true; } // save pfm -static bool save_yvol( - const char* filename, int w, int h, int d, int nc, const float* voxels) { +static bool save_yvol(const string& filename, int width, int height, int depth, + int components, const vector& voxels, string& error) { + // error helpers + auto open_error = [filename, &error]() { + error = filename + ": file not found"; + return false; + }; + auto write_error = [filename, &error]() { + error = filename + ": read error"; + return false; + }; + auto fs = open_file(filename, "wb"); - if (!fs) return false; + if (!fs) return open_error(); - if (!write_text(fs, "YVOL\n")) return false; - if (!write_text(fs, std::to_string(w) + " " + std::to_string(h) + " " + - std::to_string(d) + " " + std::to_string(nc) + "\n")) - return false; - auto nvalues = (size_t)w * (size_t)h * (size_t)d * (size_t)nc; - if (!write_values(fs, voxels, nvalues)) return false; + if (!write_text(fs, "YVOL\n")) return write_error(); + if (!write_text(fs, std::to_string(width) + " " + std::to_string(height) + + " " + std::to_string(depth) + " " + + std::to_string(components) + "\n")) + return write_error(); + auto nvalues = (size_t)width * (size_t)height * (size_t)depth * + (size_t)components; + if (!write_values(fs, voxels.data(), nvalues)) return write_error(); return true; } @@ -1944,24 +2121,19 @@ bool load_volume(const string& filename, volume& vol, string& error) { return false; }; auto width = 0, height = 0, depth = 0, ncomp = 0; - auto voxels = load_yvol(filename.c_str(), &width, &height, &depth, &ncomp, 1); - if (!voxels) return read_error(); - vol = volume{{width, height, depth}, (const float*)voxels}; - delete[] voxels; + auto voxels = vector{}; + if (!load_yvol(filename, width, height, depth, ncomp, voxels, error)) + return false; + if (ncomp != 1) voxels = convert_components(voxels, ncomp, 1); + vol = volume{{width, height, depth}, (const float*)voxels.data()}; return true; } // Saves volume data in binary format. bool save_volume( const string& filename, const volume& vol, string& error) { - auto write_error = [filename, &error]() { - error = filename + ": write error"; - return false; - }; - if (!save_yvol(filename.c_str(), vol.width(), vol.height(), vol.depth(), 1, - vol.data())) - return write_error(); - return true; + return save_yvol(filename, vol.width(), vol.height(), vol.depth(), 1, + {vol.data(), vol.data() + vol.count()}, error); } } // namespace yocto diff --git a/libs/yocto/yocto_mesh.cpp b/libs/yocto/yocto_mesh.cpp index 59070856e..879b1eb8d 100644 --- a/libs/yocto/yocto_mesh.cpp +++ b/libs/yocto/yocto_mesh.cpp @@ -1777,8 +1777,7 @@ vector strip_ascending_distance_field(const geodesic_solver& solver, return result; } -[[nodiscard]] bool check_strip( - const vector& adjacencies, const vector& strip) { +bool check_strip(const vector& adjacencies, const vector& strip) { auto faces = std::unordered_set{}; faces.insert(strip[0]); for (auto i = 1; i < strip.size(); ++i) { @@ -2212,7 +2211,7 @@ static float intersect_segments(const vec2f& start1, const vec2f& end1, return (a.x * d.y - a.y * d.x) / det; } -[[nodiscard]] bool path_check_strip( +bool path_check_strip( const vector& adjacencies, const vector& strip) { auto faces = unordered_set{}; faces.insert(strip[0]); @@ -2358,7 +2357,7 @@ static vector funnel( return lerps; } -[[nodiscard]] bool check_point(const mesh_point& point) { +bool check_point(const mesh_point& point) { assert(point.face != -1); assert(point.uv.x >= 0); assert(point.uv.y >= 0); @@ -2533,7 +2532,7 @@ mesh_point eval_path_point(const geodesic_path& path, namespace yocto { // Load ply mesh -[[nodiscard]] bool load_mesh(const string& filename, vector& triangles, +bool load_mesh(const string& filename, vector& triangles, vector& positions, vector& normals, vector& texcoords, vector& colors, string& error, bool flip_texcoord) { auto format_error = [filename, &error]() { @@ -2600,11 +2599,10 @@ namespace yocto { } // Save ply mesh -[[nodiscard]] bool save_mesh(const string& filename, - const vector& triangles, const vector& positions, - const vector& normals, const vector& texcoords, - const vector& colors, string& error, bool ascii, - bool flip_texcoord) { +bool save_mesh(const string& filename, const vector& triangles, + const vector& positions, const vector& normals, + const vector& texcoords, const vector& colors, string& error, + bool ascii, bool flip_texcoord) { auto format_error = [filename, &error]() { error = filename + ": unknown format"; return false; @@ -2645,7 +2643,7 @@ namespace yocto { } // Load ply mesh -[[nodiscard]] bool load_lines(const string& filename, vector& lines, +bool load_lines(const string& filename, vector& lines, vector& positions, vector& normals, vector& texcoords, vector& colors, string& error, bool flip_texcoord) { auto format_error = [filename, &error]() { @@ -2712,11 +2710,10 @@ namespace yocto { } // Save ply mesh -[[nodiscard]] bool save_lines(const string& filename, - const vector& lines, const vector& positions, - const vector& normals, const vector& texcoords, - const vector& colors, string& error, bool ascii, - bool flip_texcoord) { +bool save_lines(const string& filename, const vector& lines, + const vector& positions, const vector& normals, + const vector& texcoords, const vector& colors, string& error, + bool ascii, bool flip_texcoord) { auto format_error = [filename, &error]() { error = filename + ": unknown format"; return false; diff --git a/libs/yocto/yocto_mesh.h b/libs/yocto/yocto_mesh.h index eba0e2844..3bdcafd60 100644 --- a/libs/yocto/yocto_mesh.h +++ b/libs/yocto/yocto_mesh.h @@ -354,24 +354,22 @@ void meandering_triangles(const vector& field, float isoline, namespace yocto { // Load/save a shape as indexed meshes -[[nodiscard]] bool load_mesh(const string& filename, vector& triangles, +bool load_mesh(const string& filename, vector& triangles, vector& positions, vector& normals, vector& texcoords, vector& colors, string& error, bool flip_texcoords = true); -[[nodiscard]] bool save_mesh(const string& filename, - const vector& triangles, const vector& positions, - const vector& normals, const vector& texcoords, - const vector& colors, string& error, bool ascii = false, - bool flip_texcoords = true); +bool save_mesh(const string& filename, const vector& triangles, + const vector& positions, const vector& normals, + const vector& texcoords, const vector& colors, string& error, + bool ascii = false, bool flip_texcoords = true); // Load/save a set of lines -[[nodiscard]] bool load_lines(const string& filename, vector& lines, +bool load_lines(const string& filename, vector& lines, vector& positions, vector& normals, vector& texcoords, vector& colors, string& error, bool flip_texcoords = true); -[[nodiscard]] bool save_lines(const string& filename, - const vector& lines, const vector& positions, - const vector& normals, const vector& texcoords, - const vector& colors, string& error, bool ascii = false, - bool flip_texcoords = true); +bool save_lines(const string& filename, const vector& lines, + const vector& positions, const vector& normals, + const vector& texcoords, const vector& colors, string& error, + bool ascii = false, bool flip_texcoords = true); } // namespace yocto diff --git a/libs/yocto/yocto_modelio.cpp b/libs/yocto/yocto_modelio.cpp index 656208319..b216770ed 100644 --- a/libs/yocto/yocto_modelio.cpp +++ b/libs/yocto/yocto_modelio.cpp @@ -106,7 +106,7 @@ inline void remove_comment(string_view& str, char comment_char = '#') { } // Parse values from a string -[[nodiscard]] inline bool parse_value(string_view& str, string_view& value) { +inline bool parse_value(string_view& str, string_view& value) { skip_whitespace(str); if (str.empty()) return false; if (str.front() != '"') { @@ -129,76 +129,76 @@ inline void remove_comment(string_view& str, char comment_char = '#') { } return true; } -[[nodiscard]] inline bool parse_value(string_view& str, string& value) { +inline bool parse_value(string_view& str, string& value) { auto valuev = string_view{}; if (!parse_value(str, valuev)) return false; value = string{valuev}; return true; } -[[nodiscard]] inline bool parse_value(string_view& str, int8_t& value) { +inline bool parse_value(string_view& str, int8_t& value) { char* end = nullptr; value = (int8_t)strtol(str.data(), &end, 10); if (str.data() == end) return false; str.remove_prefix(end - str.data()); return true; } -[[nodiscard]] inline bool parse_value(string_view& str, int16_t& value) { +inline bool parse_value(string_view& str, int16_t& value) { char* end = nullptr; value = (int16_t)strtol(str.data(), &end, 10); if (str.data() == end) return false; str.remove_prefix(end - str.data()); return true; } -[[nodiscard]] inline bool parse_value(string_view& str, int32_t& value) { +inline bool parse_value(string_view& str, int32_t& value) { char* end = nullptr; value = (int32_t)strtol(str.data(), &end, 10); if (str.data() == end) return false; str.remove_prefix(end - str.data()); return true; } -[[nodiscard]] inline bool parse_value(string_view& str, int64_t& value) { +inline bool parse_value(string_view& str, int64_t& value) { char* end = nullptr; value = (int64_t)strtoll(str.data(), &end, 10); if (str.data() == end) return false; str.remove_prefix(end - str.data()); return true; } -[[nodiscard]] inline bool parse_value(string_view& str, uint8_t& value) { +inline bool parse_value(string_view& str, uint8_t& value) { char* end = nullptr; value = (uint8_t)strtoul(str.data(), &end, 10); if (str.data() == end) return false; str.remove_prefix(end - str.data()); return true; } -[[nodiscard]] inline bool parse_value(string_view& str, uint16_t& value) { +inline bool parse_value(string_view& str, uint16_t& value) { char* end = nullptr; value = (uint16_t)strtoul(str.data(), &end, 10); if (str.data() == end) return false; str.remove_prefix(end - str.data()); return true; } -[[nodiscard]] inline bool parse_value(string_view& str, uint32_t& value) { +inline bool parse_value(string_view& str, uint32_t& value) { char* end = nullptr; value = (uint32_t)strtoul(str.data(), &end, 10); if (str.data() == end) return false; str.remove_prefix(end - str.data()); return true; } -[[nodiscard]] inline bool parse_value(string_view& str, uint64_t& value) { +inline bool parse_value(string_view& str, uint64_t& value) { char* end = nullptr; value = (uint64_t)strtoull(str.data(), &end, 10); if (str.data() == end) return false; str.remove_prefix(end - str.data()); return true; } -[[nodiscard]] inline bool parse_value(string_view& str, float& value) { +inline bool parse_value(string_view& str, float& value) { char* end = nullptr; value = strtof(str.data(), &end); if (str.data() == end) return false; str.remove_prefix(end - str.data()); return true; } -[[nodiscard]] inline bool parse_value(string_view& str, double& value) { +inline bool parse_value(string_view& str, double& value) { char* end = nullptr; value = strtod(str.data(), &end); if (str.data() == end) return false; @@ -206,7 +206,7 @@ inline void remove_comment(string_view& str, char comment_char = '#') { return true; } #ifdef __APPLE__ -[[nodiscard]] inline bool parse_value(string_view& str, size_t& value) { +inline bool parse_value(string_view& str, size_t& value) { char* end = nullptr; value = (size_t)strtoull(str.data(), &end, 10); if (str.data() == end) return false; @@ -214,34 +214,34 @@ inline void remove_comment(string_view& str, char comment_char = '#') { return true; } #endif -[[nodiscard]] inline bool parse_value(string_view& str, bool& value) { +inline bool parse_value(string_view& str, bool& value) { auto valuei = 0; if (!parse_value(str, valuei)) return false; value = (bool)valuei; return true; } -[[nodiscard]] inline bool parse_value(string_view& str, vec2f& value) { +inline bool parse_value(string_view& str, vec2f& value) { for (auto i = 0; i < 2; i++) if (!parse_value(str, value[i])) return false; return true; } -[[nodiscard]] inline bool parse_value(string_view& str, vec3f& value) { +inline bool parse_value(string_view& str, vec3f& value) { for (auto i = 0; i < 3; i++) if (!parse_value(str, value[i])) return false; return true; } -[[nodiscard]] inline bool parse_value(string_view& str, vec4f& value) { +inline bool parse_value(string_view& str, vec4f& value) { for (auto i = 0; i < 4; i++) if (!parse_value(str, value[i])) return false; return true; } -[[nodiscard]] inline bool parse_value(string_view& str, mat4f& value) { +inline bool parse_value(string_view& str, mat4f& value) { for (auto i = 0; i < 4; i++) if (!parse_value(str, value[i])) return false; return true; } -[[nodiscard]] inline bool parse_value(string_view& str, frame3f& value) { +inline bool parse_value(string_view& str, frame3f& value) { for (auto i = 0; i < 4; i++) if (!parse_value(str, value[i])) return false; return true; @@ -261,14 +261,6 @@ ply_model::~ply_model() { for (auto element : elements) delete element; } -// Make ply -inline ply_element* add_property(ply_model* ply) { - return ply->elements.emplace_back(new ply_element{}); -} -inline ply_property* add_property(ply_element* element) { - return element->properties.emplace_back(new ply_property{}); -} - // Load ply bool load_ply(const string& filename, ply_model* ply, string& error) { // ply type names @@ -1165,7 +1157,7 @@ bool add_points(ply_model* ply, const vector& values) { // ----------------------------------------------------------------------------- namespace yocto { -[[nodiscard]] inline bool parse_value(string_view& str, obj_vertex& value) { +inline bool parse_value(string_view& str, obj_vertex& value) { value = obj_vertex{0, 0, 0}; if (!parse_value(str, value.position)) return false; if (!str.empty() && str.front() == '/') { @@ -1185,7 +1177,7 @@ namespace yocto { } // Input for OBJ textures -[[nodiscard]] inline bool parse_value(string_view& str, obj_texture& info) { +inline bool parse_value(string_view& str, obj_texture& info) { // initialize info = obj_texture(); @@ -1216,8 +1208,7 @@ namespace yocto { } // Read obj -[[nodiscard]] inline bool load_mtl( - const string& filename, obj_scene* obj, string& error) { +inline bool load_mtl(const string& filename, obj_scene* obj, string& error) { // error helpers auto open_error = [filename, &error]() { error = filename + ": file not found"; @@ -1443,8 +1434,7 @@ namespace yocto { } // Read obj -[[nodiscard]] inline bool load_objx( - const string& filename, obj_scene* obj, string& error) { +inline bool load_objx(const string& filename, obj_scene* obj, string& error) { // error helpers auto open_error = [filename, &error]() { error = filename + ": file not found"; @@ -1780,8 +1770,7 @@ inline void format_value(string& str, const obj_vertex& value) { } // Save obj -[[nodiscard]] inline bool save_mtl( - const string& filename, obj_scene* obj, string& error) { +inline bool save_mtl(const string& filename, obj_scene* obj, string& error) { // throw helpers // error helpers auto open_error = [filename, &error]() { @@ -1956,8 +1945,7 @@ inline void format_value(string& str, const obj_vertex& value) { } // Save obj -[[nodiscard]] inline bool save_objx( - const string& filename, obj_scene* obj, string& error) { +inline bool save_objx(const string& filename, obj_scene* obj, string& error) { // error helpers auto open_error = [filename, &error]() { error = filename + ": file not found"; @@ -2015,8 +2003,7 @@ inline void format_value(string& str, const obj_vertex& value) { } // Save obj -[[nodiscard]] bool save_obj( - const string& filename, obj_scene* obj, string& error) { +bool save_obj(const string& filename, obj_scene* obj, string& error) { // error helpers auto open_error = [filename, &error]() { error = filename + ": file not found"; @@ -2567,7 +2554,7 @@ struct pbrt_command { }; // get pbrt value -[[nodiscard]] inline bool get_pbrt_value(const pbrt_value& pbrt, string& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, string& val) { if (pbrt.type == pbrt_type::string || pbrt.type == pbrt_type::texture) { val = pbrt.value1s; return true; @@ -2575,7 +2562,7 @@ struct pbrt_command { return false; } } -[[nodiscard]] inline bool get_pbrt_value(const pbrt_value& pbrt, bool& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, bool& val) { if (pbrt.type == pbrt_type::boolean) { val = pbrt.value1b; return true; @@ -2583,7 +2570,7 @@ struct pbrt_command { return false; } } -[[nodiscard]] inline bool get_pbrt_value(const pbrt_value& pbrt, int& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, int& val) { if (pbrt.type == pbrt_type::integer) { val = pbrt.value1i; return true; @@ -2591,7 +2578,7 @@ struct pbrt_command { return false; } } -[[nodiscard]] inline bool get_pbrt_value(const pbrt_value& pbrt, float& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, float& val) { if (pbrt.type == pbrt_type::real) { val = pbrt.value1f; return true; @@ -2599,7 +2586,7 @@ struct pbrt_command { return false; } } -[[nodiscard]] inline bool get_pbrt_value(const pbrt_value& pbrt, vec2f& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, vec2f& val) { if (pbrt.type == pbrt_type::point2 || pbrt.type == pbrt_type::vector2) { val = pbrt.value2f; return true; @@ -2607,7 +2594,7 @@ struct pbrt_command { return false; } } -[[nodiscard]] inline bool get_pbrt_value(const pbrt_value& pbrt, vec3f& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, vec3f& val) { if (pbrt.type == pbrt_type::point || pbrt.type == pbrt_type::vector || pbrt.type == pbrt_type::normal || pbrt.type == pbrt_type::color) { val = pbrt.value3f; @@ -2619,8 +2606,7 @@ struct pbrt_command { return false; } } -[[nodiscard]] inline bool get_pbrt_value( - const pbrt_value& pbrt, vector& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, vector& val) { if (pbrt.type == pbrt_type::real) { if (!pbrt.vector1f.empty()) { val = pbrt.vector1f; @@ -2632,8 +2618,7 @@ struct pbrt_command { return false; } } -[[nodiscard]] inline bool get_pbrt_value( - const pbrt_value& pbrt, vector& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, vector& val) { if (pbrt.type == pbrt_type::point2 || pbrt.type == pbrt_type::vector2) { if (!pbrt.vector2f.empty()) { val = pbrt.vector2f; @@ -2652,8 +2637,7 @@ struct pbrt_command { return false; } } -[[nodiscard]] inline bool get_pbrt_value( - const pbrt_value& pbrt, vector& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, vector& val) { if (pbrt.type == pbrt_type::point || pbrt.type == pbrt_type::vector || pbrt.type == pbrt_type::normal || pbrt.type == pbrt_type::color) { if (!pbrt.vector3f.empty()) { @@ -2675,8 +2659,7 @@ struct pbrt_command { } } -[[nodiscard]] inline bool get_pbrt_value( - const pbrt_value& pbrt, vector& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, vector& val) { if (pbrt.type == pbrt_type::integer) { if (!pbrt.vector1i.empty()) { val = pbrt.vector1i; @@ -2688,8 +2671,7 @@ struct pbrt_command { return false; } } -[[nodiscard]] inline bool get_pbrt_value( - const pbrt_value& pbrt, vector& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, vector& val) { if (pbrt.type == pbrt_type::integer) { if (pbrt.vector1i.empty() || (pbrt.vector1i.size() % 3) != 0) throw std::invalid_argument{"expected int3 array"}; @@ -2702,8 +2684,7 @@ struct pbrt_command { return false; } } -[[nodiscard]] inline bool get_pbrt_value( - const pbrt_value& pbrt, pair& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, pair& val) { if (pbrt.type == pbrt_type::string || pbrt.type == pbrt_type::texture) { val.first = 0; return get_pbrt_value(pbrt, val.second); @@ -2712,8 +2693,7 @@ struct pbrt_command { return get_pbrt_value(pbrt, val.first); } } -[[nodiscard]] inline bool get_pbrt_value( - const pbrt_value& pbrt, pair& val) { +inline bool get_pbrt_value(const pbrt_value& pbrt, pair& val) { if (pbrt.type == pbrt_type::string || pbrt.type == pbrt_type::texture) { val.first = zero3f; return get_pbrt_value(pbrt, val.second); @@ -2723,7 +2703,7 @@ struct pbrt_command { } } template -[[nodiscard]] inline bool get_pbrt_value( +inline bool get_pbrt_value( const vector& pbrt, const string& name, T& val) { for (auto& p : pbrt) { if (p.name == name) { @@ -2820,7 +2800,7 @@ inline void remove_pbrt_comment(string_view& str, char comment_char = '#') { } // Read a pbrt command from file -[[nodiscard]] inline bool read_pbrt_cmdline(file_stream& fs, string& cmd) { +inline bool read_pbrt_cmdline(file_stream& fs, string& cmd) { auto buffer = array{}; cmd.clear(); auto found = false; @@ -2853,7 +2833,7 @@ inline void remove_pbrt_comment(string_view& str, char comment_char = '#') { } // parse a quoted string -[[nodiscard]] inline bool parse_command(string_view& str, string& value) { +inline bool parse_command(string_view& str, string& value) { skip_whitespace(str); if (!isalpha((int)str.front())) return false; auto pos = str.find_first_not_of( @@ -2870,7 +2850,7 @@ inline void remove_pbrt_comment(string_view& str, char comment_char = '#') { // parse pbrt value with optional parens template -[[nodiscard]] inline bool parse_param(string_view& str, T& value) { +inline bool parse_param(string_view& str, T& value) { skip_whitespace(str); auto parens = !str.empty() && str.front() == '['; if (parens) str.remove_prefix(1); @@ -2885,8 +2865,7 @@ template } // parse a quoted string -[[nodiscard]] inline bool parse_nametype( - string_view& str_, string& name, string& type) { +inline bool parse_nametype(string_view& str_, string& name, string& type) { auto value = ""s; if (!parse_value(str_, value)) return false; if (str_.empty()) return false; @@ -3079,8 +3058,7 @@ inline pair get_subsurface(const string& name) { return params.at(name); } -[[nodiscard]] inline bool parse_params( - string_view& str, vector& values) { +inline bool parse_params(string_view& str, vector& values) { auto parse_pvalues = [](string_view& str, auto& value, auto& values) -> bool { values.clear(); skip_whitespace(str); @@ -4054,13 +4032,12 @@ struct pbrt_context { }; // load pbrt -[[nodiscard]] inline bool load_pbrt(const string& filename, pbrt_scene* pbrt, - string& error, pbrt_context& ctx, - unordered_map& material_map, - unordered_map& named_materials, - unordered_map& named_textures, - unordered_map& named_mediums, - const string& ply_dirname) { +inline bool load_pbrt(const string& filename, pbrt_scene* pbrt, string& error, + pbrt_context& ctx, unordered_map& material_map, + unordered_map& named_materials, + unordered_map& named_textures, + unordered_map& named_mediums, + const string& ply_dirname) { // error helpers auto open_error = [filename, &error]() { error = filename + ": file not found"; diff --git a/libs/yocto/yocto_modelio.h b/libs/yocto/yocto_modelio.h index e2c6a8ae6..2276a836c 100644 --- a/libs/yocto/yocto_modelio.h +++ b/libs/yocto/yocto_modelio.h @@ -120,8 +120,6 @@ bool save_ply(const string& filename, ply_model* ply, string& error); // Get ply properties bool has_property( ply_model* ply, const string& element, const string& property); -ply_property* get_property( - ply_model* ply, const string& element, const string& property); bool get_value(ply_model* ply, const string& element, const string& property, vector& values); diff --git a/libs/yocto/yocto_shape.cpp b/libs/yocto/yocto_shape.cpp index 30e80116c..7ee5a4153 100644 --- a/libs/yocto/yocto_shape.cpp +++ b/libs/yocto/yocto_shape.cpp @@ -3499,7 +3499,7 @@ void make_heightfield(vector& quads, vector& positions, namespace yocto { // Load ply mesh -[[nodiscard]] bool load_shape(const string& filename, vector& points, +bool load_shape(const string& filename, vector& points, vector& lines, vector& triangles, vector& quads, vector& quadspos, vector& quadsnorm, vector& quadstexcoord, vector& positions, @@ -3611,7 +3611,7 @@ namespace yocto { } // Save ply mesh -[[nodiscard]] bool save_shape(const string& filename, const vector& points, +bool save_shape(const string& filename, const vector& points, const vector& lines, const vector& triangles, const vector& quads, const vector& quadspos, const vector& quadsnorm, const vector& quadstexcoord,