-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathimage_quantity_base.cpp
More file actions
135 lines (102 loc) · 3.93 KB
/
image_quantity_base.cpp
File metadata and controls
135 lines (102 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run
#include "polyscope/image_quantity_base.h"
#include "polyscope/camera_view.h"
#include "imgui.h"
namespace polyscope {
ImageQuantity::ImageQuantity(Structure& parent_, std::string name_, size_t dimX_, size_t dimY_,
ImageOrigin imageOrigin_)
: FloatingQuantity(name_, parent_), parent(parent_), dimX(dimX_), dimY(dimY_), imageOrigin(imageOrigin_),
transparency(uniquePrefix() + "transparency", 1.0),
isShowingFullscreen(uniquePrefix() + "isShowingFullscreen", false),
isShowingImGuiWindow(uniquePrefix() + "isShowingImGuiWindow", true),
isShowingCameraBillboard(uniquePrefix() + "isCameraBillboard", false) {
parentStructureCameraView = dynamic_cast<CameraView*>(&parent);
if (parentIsCameraView()) {
// different defaults for camera views
isShowingCameraBillboard.setPassive(true);
isShowingImGuiWindow.setPassive(false);
}
requestRedraw();
}
void ImageQuantity::draw() {
if (!isEnabled()) return;
if (getShowInImGuiWindow()) {
renderIntermediate();
}
}
void ImageQuantity::drawDelayed() {
if (!isEnabled()) return;
if (getShowFullscreen()) {
showFullscreen();
}
if (getShowInCameraBillboard()) {
glm::vec3 billboardCenter, billboardUp, billboardRight;
std::tie(billboardCenter, billboardUp, billboardRight) = parentStructureCameraView->getFrameBillboardGeometry();
showInBillboard(billboardCenter, billboardUp, billboardRight);
}
}
void ImageQuantity::renderIntermediate() {
// nothing by default, subclasses override
}
void ImageQuantity::disableFullscreenDrawing() {
if (getShowFullscreen() && isEnabled() && parent.isEnabled()) {
setEnabled(false);
}
}
size_t ImageQuantity::nPix() { return dimX * dimY; }
void ImageQuantity::setShowFullscreen(bool newVal) {
if (newVal && isEnabled()) {
// if drawing fullscreen, disable anything else which was already drawing fullscreen
disableAllFullscreenArtists();
setEnabled(true);
}
isShowingFullscreen = newVal;
requestRedraw();
}
bool ImageQuantity::getShowFullscreen() { return isShowingFullscreen.get(); }
void ImageQuantity::setShowInImGuiWindow(bool newVal) {
isShowingImGuiWindow = newVal;
requestRedraw();
}
bool ImageQuantity::getShowInImGuiWindow() { return isShowingImGuiWindow.get(); }
void ImageQuantity::setShowInCameraBillboard(bool newVal) {
if (!parentIsCameraView()) newVal = false; // don't allow setting to true if parent is not camera
isShowingCameraBillboard = newVal;
requestRedraw();
}
bool ImageQuantity::getShowInCameraBillboard() { return isShowingCameraBillboard.get(); }
void ImageQuantity::setTransparency(float newVal) {
transparency = newVal;
requestRedraw();
}
float ImageQuantity::getTransparency() { return transparency.get(); }
bool ImageQuantity::parentIsCameraView() { return parentStructureCameraView != nullptr; }
void ImageQuantity::buildImageOptionsUI() {
if (ImGui::MenuItem("Show in ImGui window", NULL, getShowInImGuiWindow()))
setShowInImGuiWindow(!getShowInImGuiWindow());
if (ImGui::MenuItem("Show fullscreen", NULL, getShowFullscreen())) setShowFullscreen(!getShowFullscreen());
if (parentIsCameraView()) {
if (ImGui::MenuItem("Show in camera billboard", NULL, getShowInCameraBillboard()))
setShowInCameraBillboard(!getShowInCameraBillboard());
}
if (ImGui::SliderFloat("transparency", &transparency.get(), 0, 1., "%.3f")) {
transparency.manuallyChanged();
requestRedraw();
}
}
void ImageQuantity::buildImageUI() {
if (getShowFullscreen()) {
ImGui::PushItemWidth(100 * options::uiScale);
if (ImGui::SliderFloat("transparency", &transparency.get(), 0.f, 1.f)) {
transparency.manuallyChanged();
requestRedraw();
}
ImGui::PopItemWidth();
}
if (isEnabled() && parent.isEnabled()) {
if (getShowInImGuiWindow()) {
showInImGuiWindow();
}
}
}
} // namespace polyscope