Skip to content
Snippets Groups Projects
Commit e91ca83b authored by Pierre EVEN's avatar Pierre EVEN
Browse files

added missing files

parent 713f7e88
Branches
No related merge requests found
#version 430
precision highp float;
layout(location = 0) out vec4 out_color;
layout(location = 0) in vec3 normal;
layout(location = 2) uniform vec3 color;
vec3 light_dir = normalize(vec3(1, 1, -1));
void main()
{
out_color = vec4(max(dot(normal, light_dir), 0.1) * color, 1);
}
\ No newline at end of file
#version 460
#include "world_data.cginc"
layout(location = 0) in vec3 pos;
layout(location = 1) in vec3 normal;
layout(location = 0) out vec3 o_normal;
layout(location = 1) uniform mat4 model;
void main()
{
o_normal = normal;
gl_Position = pv_matrix * model * vec4(pos, 1.0);
}
\ No newline at end of file
#include "slice_view.hpp"
#include <corecrt_math_defines.h>
#include <imgui.h>
#include <common/point_cloud.hpp>
#include <tree_cloud_density/circular_density_map.hpp>
#include <tree_cloud_density/cloud_cutter.hpp>
#include <tree_cloud_density/tree_processor.hpp>
#include "image_3d_display.hpp"
SliceView::SliceView(const std::shared_ptr<ut::PointCloud>& in_point_cloud) : initial_pc(in_point_cloud)
{
window_name = "Slices view";
tree_pos = ut::find_tree_position(*in_point_cloud, 100);
point_cloud = *in_point_cloud;
auto rotation = Eigen::Affine3d::Identity();
rotation.rotate(Eigen::Quaterniond::FromTwoVectors(Eigen::Vector3d{0, 0, -1}, Eigen::Vector3d{0, 1, 0}));
rotation.translate(-Eigen::Vector3d{tree_pos.x(), tree_pos.y(), 0});
point_cloud.transform(rotation);
}
void SliceView::draw()
{
ImGui::Checkbox("Draw slices", &draw_slices);
if (ImGui::SliderInt("Slice count", &slice_count, 2, 50))
rebuild = true;
ImGui::SliderFloat("alpha level", &alpha_level, 0, 1);
if (ImGui::SliderInt("Pixel per unit", &pixel_per_unit, 10, 200))
rebuild = true;
if (ImGui::SliderFloat("Contrast", &contrast, 0.001f, 1))
rebuild = true;
ImGui::Separator();
ImGui::Checkbox("Draw sum slice", &show_average_slice);
ImGui::DragFloat("Sum slice rotation", &average_slice_rotation, 0.1f);
if (rebuild)
{
slices.clear();
average_slice = nullptr;
rebuild = false;
ut::CloudSlice slice;
slice.cut_radial(point_cloud, slice_count);
const auto final_bounds = ut::DensityViewerRadial::compute_bounds(&point_cloud);
ut::DensityViewerRadial viewer;
viewer.set_pixels_per_unit(pixel_per_unit);
viewer.set_bounds_override(final_bounds);
image_res = {
static_cast<uint32_t>(final_bounds.radius * pixel_per_unit),
static_cast<uint32_t>((final_bounds.z_max - final_bounds.z_min) * pixel_per_unit)
};
ut::DensityMap sum_map(image_res.x(), image_res.y());
for (auto cut : slice.get_cuts())
{
viewer.set_point_cloud(&cut);
auto map = viewer.compute_density_map();
map.contrast_remap(contrast);
slices.emplace_back(Image3DView());
slices.back().set_image(map.get_image().cast<uint8_t>());
map.binarize();
sum_map.append(map);
}
sum_map.contrast_remap(contrast);
average_slice = std::make_shared<Image3DView>();
average_slice->set_image(sum_map.get_image().cast<uint8_t>());
}
double step = M_PI * 2 / slices.size();
double angle = step / 2;
if (draw_slices)
{
for (auto& slice : slices)
{
const auto image_dir = Eigen::Vector3d{cos(angle), sin(angle), 0};
slice.scale = Eigen::Vector3d(image_res.x() / static_cast<double>(pixel_per_unit),
image_res.y() / static_cast<double>(pixel_per_unit), 0);
slice.position = Eigen::Vector3d(tree_pos.x() + image_dir.x() * image_res.x() / 2 / pixel_per_unit,
tree_pos.y() + image_dir.y() * image_res.x() / 2 / pixel_per_unit,
initial_pc->get_bounds().origin().z());
slice.rotation =
Eigen::Quaterniond::FromTwoVectors(Eigen::Vector3d{1, 0, 0}, image_dir) *
Eigen::Quaterniond::FromTwoVectors(Eigen::Vector3d{0, 1, 0}, Eigen::Vector3d{0, 0, -1});
slice.draw();
slice.alpha_level = alpha_level;
angle += step;
}
}
if (average_slice && show_average_slice)
{
average_slice->alpha_level = alpha_level;
const auto image_dir = Eigen::Vector3d{cos(average_slice_rotation), sin(average_slice_rotation), 0};
average_slice->scale = Eigen::Vector3d(image_res.x() / static_cast<double>(pixel_per_unit),
image_res.y() / static_cast<double>(pixel_per_unit), 0);
average_slice->position = Eigen::Vector3d(tree_pos.x() + image_dir.x() * image_res.x() / 2 / pixel_per_unit,
tree_pos.y() + image_dir.y() * image_res.x() / 2 / pixel_per_unit,
initial_pc->get_bounds().origin().z());
average_slice->rotation =
Eigen::Quaterniond::FromTwoVectors(Eigen::Vector3d{1, 0, 0}, image_dir) *
Eigen::Quaterniond::FromTwoVectors(Eigen::Vector3d{0, 1, 0}, Eigen::Vector3d{0, 0, -1});
average_slice->draw();
}
}
#pragma once
#include <vector>
#include <common/point_cloud.hpp>
#include "ui/ui.hpp"
#include <Eigen/Dense>
class Image3DView;
class SliceView : public ImGuiWindow
{
public:
SliceView(const std::shared_ptr<ut::PointCloud>& in_point_cloud);
void draw() override;
private:
ut::PointCloud point_cloud;
std::shared_ptr<ut::PointCloud> initial_pc;
bool draw_slices = true;
bool show_average_slice = false;
std::vector<Image3DView> slices;
std::shared_ptr<Image3DView> average_slice;
bool rebuild = true;
Eigen::Vector2d tree_pos;
int slice_count = 5;
int pixel_per_unit = 100;
float contrast = 0.25;
Eigen::Vector2i image_res;
float average_slice_rotation = 0.f;
float alpha_level = 0.001f;
};
#include "tree_trunc_viewer.hpp"
#include <corecrt_math_defines.h>
#include <imgui.h>
#include <iostream>
#include <common/point_cloud.hpp>
#include <tree_cloud_density/tree_processor.hpp>
#include "engine/material.hpp"
#include "engine/mesh.hpp"
static std::shared_ptr<Mesh> mesh;
static std::shared_ptr<Material> material = nullptr;
TreeTruncViewer::TreeTruncViewer(std::shared_ptr<ut::PointCloud> in_point_cloud) : point_cloud(
std::move(in_point_cloud))
{
window_name = "Tree trunc extractor";
}
void TreeTruncViewer::draw()
{
if (ImGui::SliderInt("pixel per unit", &pixel_per_unit, 5, 200))
rebuild = true;
if (ImGui::SliderFloat("Min threshold", &min_threshold, 0.7f, 0.9999f))
rebuild = true;
if (rebuild)
{
rebuild = false;
const auto tree_pos = ut::find_tree_position(*point_cloud, pixel_per_unit, min_threshold);
transform = Eigen::Affine3d::Identity();
transform.translate(Eigen::Vector3d{
tree_pos.x(), tree_pos.y(), point_cloud->get_bounds().origin().z() - point_cloud->get_bounds().extent().z() / 2
});
transform.scale(Eigen::Vector3d{0.05, 0.05, point_cloud->get_bounds().extent().z()});
}
if (!mesh)
{
mesh = Mesh::create("trunc cylinder");
std::vector<Eigen::Vector3f> vertices;
std::vector<Eigen::Vector3f> normals;
std::vector<uint32_t> indices;
static const int U = 5;
for (int i = 0; i < U; ++i)
{
const auto angle = i / static_cast<float>(U) * static_cast<float>(M_PI) * 2;
vertices.emplace_back(Eigen::Vector3f(cos(angle) * 0.5f, sin(angle) * 0.5f, 0));
vertices.emplace_back(Eigen::Vector3f(cos(angle) * 0.5f, sin(angle) * 0.5f, 1));
normals.emplace_back(Eigen::Vector3f(cos(angle), sin(angle), 0));
normals.emplace_back(Eigen::Vector3f(cos(angle), sin(angle), 0));
indices.emplace_back(i * 2);
indices.emplace_back((i + 1) % U * 2 + 1);
indices.emplace_back(i * 2 + 1);
indices.emplace_back(i * 2);
indices.emplace_back((i + 1) % U * 2);
indices.emplace_back((i + 1) % U * 2 + 1);
}
mesh->set_positions(vertices, 0, true);
mesh->set_normals(vertices, 1, true);
mesh->set_indices(indices);
material = Material::create("Mat_MeshNormal", "resources/shaders/mesh_normal.vs",
"resources/shaders/mesh_normal.fs");
if (!material->bind())
{
std::cout << "failed to load shader material" << std::endl;
if (material->compilation_error)
{
std::cout << material->compilation_error.value().file << " :" << std::endl;
std::cout << material->compilation_error.value().error << std::endl;
}
}
}
if (!material->bind())
std::cout << "failed to bind mesh normal material" << std::endl;
material->set_vec3("color", Eigen::Vector3f(10, 10, 1));
material->set_transform("model", transform);
mesh->draw();
}
#pragma once
#include "ui/ui.hpp"
#include <Eigen/Dense>
namespace ut
{
class PointCloud;
}
class TreeTruncViewer : public ImGuiWindow
{
public:
TreeTruncViewer(std::shared_ptr<ut::PointCloud> in_point_cloud);
void draw() override;
private:
std::shared_ptr<ut::PointCloud> point_cloud;
Eigen::Affine3d transform = Eigen::Affine3d::Identity();
bool rebuild = true;
int pixel_per_unit = 100;
float min_threshold = 0.9f;
};
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment