int test() { int Error = 0; gli::texture2D Texture(gli::FORMAT_RGBA8_UNORM, gli::texture2D::dim_type(64)); for(std::size_t j = 0, n = Texture.dimensions().y; j < n; ++j) for(std::size_t i = 0, m = Texture.dimensions().x; i < n; ++i) Texture.store<gli::u8vec4>(gli::dim2_t(i , j), 0, gli::u8vec4(i * 4, j * 4, 0, 255)); gli::texture2D TextureView(gli::view(Texture, 0, 0)); // Custom mipmaps generation using a sampler object gli::fsampler2D SamplerA(gli::texture2D(gli::copy(Texture)), gli::WRAP_CLAMP_TO_EDGE, gli::FILTER_LINEAR, gli::FILTER_LINEAR); SamplerA.generate_mipmaps(); gli::texture2D MipmapsA = SamplerA(); gli::texture2D MipmapViewA(gli::view(MipmapsA, 0, 0)); Error += TextureView == MipmapViewA ? 0 : 1; // Mipmaps generation using the wrapper function gli::texture2D MipmapsB = gli::generate_mipmaps(gli::texture2D(gli::copy(Texture))); gli::texture2D MipmapViewB(gli::view(MipmapsB, 0, 0)); Error += TextureView == MipmapViewB ? 0 : 1; // Compare custom mipmaps generation and wrapper mipmaps generation Error += MipmapViewA == MipmapViewB ? 0 : 1; Error += MipmapsA == MipmapsB ? 0 : 1; return Error; }
void from_nvm_scene(std::string const & nvm_file, std::vector<TextureView> * texture_views) { std::vector<mve::NVMCameraInfo> nvm_cams; mve::Bundle::Ptr bundle = mve::load_nvm_bundle(nvm_file, &nvm_cams); mve::Bundle::Cameras& cameras = bundle->get_cameras(); ProgressCounter view_counter("\tLoading", cameras.size()); #pragma omp parallel for for (std::size_t i = 0; i < cameras.size(); ++i) { view_counter.progress<SIMPLE>(); mve::CameraInfo& mve_cam = cameras[i]; mve::NVMCameraInfo const& nvm_cam = nvm_cams[i]; mve::ByteImage::Ptr image = mve::image::load_file(nvm_cam.filename); int const maxdim = std::max(image->width(), image->height()); mve_cam.flen = mve_cam.flen / static_cast<float>(maxdim); image = mve::image::image_undistort_vsfm<uint8_t> (image, mve_cam.flen, nvm_cam.radial_distortion); texture_views->push_back(TextureView(i, mve_cam, image)); view_counter.inc(); } }
TEX_NAMESPACE_BEGIN void from_mve_scene(std::string const & scene_dir, std::string const & embedding_name, std::vector<TextureView> * texture_views) { mve::Scene::Ptr scene; try { scene = mve::Scene::create(scene_dir); } catch (std::exception& e) { std::cerr << "Could not open scene: " << e.what() << std::endl; std::exit(EXIT_FAILURE); } std::size_t num_views = scene->get_views().size(); texture_views->reserve(num_views); ProgressCounter view_counter("\tLoading", num_views); for (std::size_t i = 0; i < num_views; ++i) { view_counter.progress<SIMPLE>(); mve::View::Ptr view = scene->get_view_by_id(i); if (view == NULL) { view_counter.inc(); continue; } if (!view->has_embedding(embedding_name)) { std::cout << "Warning: View " << view->get_name() << " has no embedding " << embedding_name << std::endl; continue; } mve::ByteImage::Ptr image = view->get_byte_image(embedding_name); if (image == NULL) { std::cerr << "Embedding " << embedding_name << " of view " << view->get_name() << " is not a byte embedding!" << std::endl; exit(EXIT_FAILURE); } if (image->channels() < 3) { std::cerr << "Embedding " << embedding_name << " of view " << view->get_name() << " is not a color image!" << std::endl; exit(EXIT_FAILURE); } texture_views->push_back(TextureView(view->get_id(), view->get_camera(), image)); view_counter.inc(); } }
int test() { int Error = 0; glm::u8vec4 const Black(0, 0, 0, 255); glm::u8vec4 const Color(255, 127, 0, 255); gli::texture3d Texture(gli::FORMAT_RGBA8_UNORM_PACK8, gli::texture3d::extent_type(8), 5); Texture.clear(Black); glm::u8vec4 const TexelA = Texture.load<glm::u8vec4>(gli::texture3d::extent_type(0), 0); glm::u8vec4 const TexelB = Texture.load<glm::u8vec4>(gli::texture3d::extent_type(0), 1); glm::u8vec4 const TexelC = Texture.load<glm::u8vec4>(gli::texture3d::extent_type(0), 2); Error += TexelA == Black ? 0 : 1; Error += TexelB == Black ? 0 : 1; Error += TexelC == Black ? 0 : 1; Texture.clear<glm::u8vec4>(1, glm::u8vec4(255, 127, 0, 255)); gli::texture3d::extent_type Coords(0); for(; Coords.z < Texture.extent(1).z; ++Coords.z) for(; Coords.y < Texture.extent(1).y; ++Coords.y) for(; Coords.x < Texture.extent(1).x; ++Coords.x) { glm::u8vec4 const TexelD = Texture.load<glm::u8vec4>(Coords, 1); Error += TexelD == Color ? 0 : 1; } gli::texture3d TextureView(Texture, 1, 1); gli::texture3d TextureImage(gli::FORMAT_RGBA8_UNORM_PACK8, gli::texture3d::extent_type(4), 1); TextureImage.clear(Color); Error += TextureView == TextureImage ? 0 : 1; return Error; }
CTextureView* CMainFrame::GetTextureView() { return TextureView (); }
void from_images_and_camera_files(std::string const & path, std::vector<TextureView> * texture_views) { util::fs::Directory dir(path); std::sort(dir.begin(), dir.end()); std::vector<std::string> files; for (std::size_t i = 0; i < dir.size(); ++i) { util::fs::File const & cam_file = dir[i]; if (cam_file.is_dir) continue; std::string cam_file_ext = util::string::uppercase(util::string::right(cam_file.name, 4)); if (cam_file_ext != ".CAM") continue; std::string prefix = util::string::left(cam_file.name, cam_file.name.size() - 4); if (prefix.empty()) continue; /* Find corresponding image file. */ int step = 1; for (std::size_t j = i + 1; j < dir.size(); j += step) { util::fs::File const & img_file = dir[j]; /* Since the files are sorted we can break - no more files with the same prefix exist. */ if (util::string::left(img_file.name, prefix.size()) != prefix) { if (step == 1) { j = i; step = -1; continue; } else { break; } } /* Image file (based on extension)? */ std::string img_file_ext = util::string::uppercase(util::string::right(img_file.name, 4)); if (img_file_ext != ".PNG" && img_file_ext != ".JPG" && img_file_ext != "TIFF" && img_file_ext != "JPEG") continue; files.push_back(cam_file.get_absolute_name()); files.push_back(img_file.get_absolute_name()); break; } } ProgressCounter view_counter("\tLoading", files.size() / 2); #pragma omp parallel for for (std::size_t i = 0; i < files.size(); i += 2) { view_counter.progress<SIMPLE>(); std::string cam_file = files[i]; std::string img_file = files[i + 1]; mve::ByteImage::Ptr image = mve::image::load_file(img_file); /* Read CAM file. */ std::ifstream infile(cam_file.c_str(), std::ios::binary); if (!infile.good()) throw util::FileException(util::fs::basename(cam_file), std::strerror(errno)); std::string cam_int_str, cam_ext_str; std::getline(infile, cam_ext_str); std::getline(infile, cam_int_str); util::Tokenizer tok_ext, tok_int; tok_ext.split(cam_ext_str); tok_int.split(cam_int_str); #pragma omp critical if (tok_ext.size() != 12 || tok_int.size() < 1) { std::cerr << "Invalid CAM file: " << util::fs::basename(cam_file) << std::endl; std::exit(EXIT_FAILURE); } /* Create cam_info and eventually undistort image. */ mve::CameraInfo cam_info; cam_info.from_ext_string(cam_ext_str); cam_info.from_int_string(cam_int_str); mve::ByteImage::Ptr undist; if (cam_info.dist[0] != 0.0f) { if (cam_info.dist[1] != 0.0f) { undist = mve::image::image_undistort_bundler<uint8_t>(image, cam_info.flen, cam_info.dist[0], cam_info.dist[1]); } else { undist = mve::image::image_undistort_vsfm<uint8_t>(image, cam_info.flen, cam_info.dist[0]); } } else { undist = image; } mve::image::save_png_file(undist, std::string("/tmp/") + util::fs::basename(img_file)); #pragma omp critical texture_views->push_back(TextureView(i / 2, cam_info, undist)); view_counter.inc(); } }