9 changed files with 312 additions and 41 deletions
@ -0,0 +1,19 @@ |
|||
//
|
|||
// Created by cflin on 4/17/23.
|
|||
//
|
|||
#include <string> |
|||
#include "SimTargetOption.h" |
|||
namespace ssim{ |
|||
const std::string SimTargetOption::TAEGET_NAME[SimTargetOption::ENUM_SIZE] = { |
|||
"位移范数", |
|||
"位移-X", |
|||
"位移-Y", |
|||
"位移-Z", |
|||
"应力范数", |
|||
"冯氏应力", |
|||
"应力-X", |
|||
"应力-Y", |
|||
"应力-Z", |
|||
"柔顺度" |
|||
}; |
|||
}; |
@ -0,0 +1,129 @@ |
|||
//
|
|||
// Created by cflin on 4/17/23.
|
|||
//
|
|||
|
|||
#include "ColorbarPlugin.h" |
|||
#include <igl/opengl/glfw/imgui/ImGuiPlugin.h> |
|||
|
|||
namespace ssim { |
|||
|
|||
|
|||
void ColorbarPlugin::init_colormaps() { |
|||
auto texture_from_colormap = [](const Eigen::MatrixXd &rgb, GLuint &id) { |
|||
int width = 1; |
|||
int height = (int) rgb.rows(); |
|||
|
|||
Eigen::Matrix<unsigned char, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> cmap; |
|||
if (rgb.maxCoeff() > 1.0) { |
|||
cmap = rgb.cast<unsigned char>(); |
|||
} else { |
|||
cmap = (rgb.array() * 255.f).cast<unsigned char>(); |
|||
} |
|||
assert(cmap.cols() == 3); |
|||
cmap.conservativeResize(cmap.rows(), 4); |
|||
cmap.col(3).setConstant(255); |
|||
|
|||
if (id == 0) { |
|||
glGenTextures(1, &id); |
|||
} |
|||
glBindTexture(GL_TEXTURE_2D, id); |
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|||
glTexImage2D( |
|||
GL_TEXTURE_2D, 0, GL_RGBA, |
|||
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, cmap.data()); |
|||
glGenerateMipmap(GL_TEXTURE_2D); |
|||
glBindTexture(GL_TEXTURE_2D, 0); |
|||
}; |
|||
|
|||
Eigen::MatrixXd rgb; |
|||
for (size_t i = 0; i < igl::NUM_COLOR_MAP_TYPES; ++i) { |
|||
GLuint id = 0; |
|||
colormap(static_cast<igl::ColorMapType>(i), Eigen::VectorXd::LinSpaced(100, 1, 0), false, rgb); |
|||
texture_from_colormap(rgb, id); |
|||
colormaps_[i] = id; |
|||
} |
|||
} |
|||
|
|||
// Draws a combo box for selecting the colormap
|
|||
int ColorbarPlugin::draw_colormap_combo() const { |
|||
const char *items[]{ |
|||
"Inferno", |
|||
"Jet", |
|||
"Magma", |
|||
"Parula", |
|||
"Plasma", |
|||
"Viridis", |
|||
}; |
|||
static int selected_index = 1; |
|||
static const char *current_item = items[selected_index]; |
|||
ImVec2 combo_pos = ImGui::GetCursorScreenPos(); |
|||
if (ImGui::BeginCombo("Colormap##combo", "")) { |
|||
for (int n = 0; n < IM_ARRAYSIZE(items); ++n) { |
|||
// You can store your selection however you want, outside or inside your objects
|
|||
bool is_selected = (current_item == items[n]); |
|||
ImGui::PushID(n); |
|||
if (ImGui::Selectable("", is_selected)) { |
|||
current_item = items[n]; |
|||
selected_index = n; |
|||
} |
|||
ImGui::SameLine(0, 0); |
|||
ImGui::Image( |
|||
reinterpret_cast<ImTextureID>(colormaps_[n]), |
|||
ImVec2(ImGui::GetTextLineHeight(), ImGui::GetTextLineHeight()), |
|||
ImVec2(0, 0), ImVec2(1, 1)); |
|||
ImGui::SameLine(); |
|||
ImGui::Text("%s", items[n]); |
|||
if (is_selected) { |
|||
ImGui::SetItemDefaultFocus(); |
|||
} |
|||
ImGui::PopID(); |
|||
} |
|||
ImGui::EndCombo(); |
|||
} |
|||
|
|||
ImVec2 backup_pos = ImGui::GetCursorScreenPos(); |
|||
ImGuiStyle &style = ImGui::GetStyle(); |
|||
ImGui::SetCursorScreenPos(ImVec2(combo_pos.x + style.FramePadding.x, combo_pos.y + style.FramePadding.y)); |
|||
float h = ImGui::GetTextLineHeight(); |
|||
ImGui::Image( |
|||
reinterpret_cast<ImTextureID>(colormaps_[selected_index]), |
|||
ImVec2(h, h)); |
|||
ImGui::SameLine(); |
|||
ImGui::Text("%s", current_item); |
|||
ImGui::SetCursorScreenPos(backup_pos); |
|||
|
|||
return selected_index; |
|||
} |
|||
|
|||
// Draws the actual colorbar with min/max values
|
|||
void ColorbarPlugin::draw_colorbar(igl::ColorMapType cm, float xmin, float xmax, |
|||
const Eigen::Vector4f &background_color) const { |
|||
ImVec4 color(0, 0, 0, 1); |
|||
// auto rgb = background_color;
|
|||
// // http://stackoverflow.com/a/3943023/112731
|
|||
// if (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114 > 186) {
|
|||
color = ImVec4(1, 1, 1, 1); |
|||
// }
|
|||
float w = 20; |
|||
float h = 200; |
|||
ImGui::BeginGroup(); |
|||
ImGui::BeginGroup(); |
|||
static const int num_interval=5; |
|||
static const float interval=(h - 1.0*(num_interval+1) * ImGui::GetTextLineHeightWithSpacing())/num_interval; |
|||
ImGui::TextColored(color, "%.3g", xmax); |
|||
|
|||
for(int i=num_interval-1;i>=0;--i){ |
|||
ImGui::Dummy(ImVec2(0, interval)); |
|||
ImGui::TextColored(color, "%.3g", (xmax-xmin)/num_interval*i+xmin); |
|||
} |
|||
|
|||
ImGui::EndGroup(); |
|||
ImGui::SameLine(); |
|||
ImGui::Image(reinterpret_cast<ImTextureID>(colormaps_[cm]), ImVec2(w, h)); |
|||
ImGui::EndGroup(); |
|||
} |
|||
|
|||
} // ssim
|
@ -0,0 +1,36 @@ |
|||
//
|
|||
// Created by cflin on 4/17/23.
|
|||
//
|
|||
|
|||
#ifndef EXAMPLE_COLORBARPLUGIN_H |
|||
#define EXAMPLE_COLORBARPLUGIN_H |
|||
#include <Eigen/Eigen> |
|||
#include <igl/opengl/glfw/Viewer.h> |
|||
|
|||
namespace ssim { |
|||
|
|||
class ColorbarPlugin { |
|||
public: |
|||
ColorbarPlugin(){ |
|||
init_colormaps(); |
|||
} |
|||
void draw_colorbar_jet(float xmin,float xmax){ |
|||
draw_colorbar(igl::COLOR_MAP_TYPE_JET,xmin,xmax, Eigen::Vector4f(0.9f, 0.9f, 0.9f, 0.4f)); |
|||
} |
|||
protected: |
|||
void init_colormaps(); |
|||
|
|||
int draw_colormap_combo() const; |
|||
|
|||
void draw_colorbar(igl::ColorMapType cm, float xmin, float xmax, |
|||
const Eigen::Vector4f &background_color) const; |
|||
|
|||
protected: |
|||
std::array <GLuint, igl::NUM_COLOR_MAP_TYPES> colormaps_; |
|||
|
|||
igl::ColorMapType colormap_type_ = igl::COLOR_MAP_TYPE_JET; |
|||
}; |
|||
|
|||
} // ssim
|
|||
|
|||
#endif //EXAMPLE_COLORBARPLUGIN_H
|
Loading…
Reference in new issue