Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04e0ec1

Browse files
authored
Merge pull request Tom94#215 from iRath96/statistics-over-crops
WIP: Statistics only over selected regions of the image
2 parents d33a46c + 1c25e99 commit 04e0ec1

File tree

9 files changed

+291
-102
lines changed

9 files changed

+291
-102
lines changed

include/tev/Box.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <tev/Common.h>
77

8-
98
namespace tev {
109

1110
template <typename T, uint32_t N_DIMS>
@@ -20,8 +19,15 @@ struct Box {
2019
template <typename U>
2120
Box(const Box<U, N_DIMS>& other) : min{other.min}, max{other.max} {}
2221

22+
Box(const std::vector<Vector>& points) : Box() {
23+
for (const auto& point : points) {
24+
min = nanogui::min(min, point);
25+
max = nanogui::max(max, point);
26+
}
27+
}
28+
2329
Vector size() const {
24-
return max - min;
30+
return nanogui::max(max - min, Vector{(T)0});
2531
}
2632

2733
Vector middle() const {
@@ -44,6 +50,26 @@ struct Box {
4450
return result;
4551
}
4652

53+
bool contains_inclusive(const Vector& pos) const {
54+
bool result = true;
55+
for (uint32_t i = 0; i < N_DIMS; ++i) {
56+
result &= pos[i] >= min[i] && pos[i] <= max[i];
57+
}
58+
return result;
59+
}
60+
61+
bool contains(const Box& other) const {
62+
return contains_inclusive(other.min) && contains_inclusive(other.max);
63+
}
64+
65+
Box intersect(const Box& other) const {
66+
return {nanogui::max(min, other.min), nanogui::min(max, other.max)};
67+
}
68+
69+
Box translate(const Vector& offset) const {
70+
return {min + offset, max + offset};
71+
}
72+
4773
bool operator==(const Box& other) const {
4874
return min == other.min && max == other.max;
4975
}
@@ -55,6 +81,12 @@ struct Box {
5581
Vector min, max;
5682
};
5783

84+
template <typename Stream, typename T, uint32_t N_DIMS, std::enable_if_t<std::is_base_of_v<std::ostream, Stream>, int> = 0>
85+
Stream& operator<<(Stream& os, const Box<T, N_DIMS>& v) {
86+
os << '[' << v.min << ", " << v.max << ']';
87+
return os;
88+
}
89+
5890
using Box2f = Box<float, 2>;
5991
using Box3f = Box<float, 3>;
6092
using Box4f = Box<float, 4>;

include/tev/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,5 +396,6 @@ void redrawWindow();
396396

397397
static const nanogui::Color IMAGE_COLOR = {0.35f, 0.35f, 0.8f, 1.0f};
398398
static const nanogui::Color REFERENCE_COLOR = {0.7f, 0.4f, 0.4f, 1.0f};
399+
static const nanogui::Color CROP_COLOR = {0.2f, 0.5f, 0.2f, 1.0f};
399400

400401
}

include/tev/ImageCanvas.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
#pragma once
55

6-
#include <tev/UberShader.h>
6+
#include <tev/Box.h>
77
#include <tev/Image.h>
88
#include <tev/Lazy.h>
9+
#include <tev/UberShader.h>
910

1011
#include <nanogui/canvas.h>
1112

1213
#include <memory>
14+
#include <optional>
1315

1416
namespace tev {
1517

@@ -65,6 +67,7 @@ class ImageCanvas : public nanogui::Canvas {
6567
}
6668

6769
nanogui::Vector2i getImageCoords(const Image& image, nanogui::Vector2i mousePos);
70+
nanogui::Vector2i getDisplayWindowCoords(const Image& image, nanogui::Vector2i mousePos);
6871

6972
void getValuesAtNanoPos(nanogui::Vector2i nanoPos, std::vector<float>& result, const std::vector<std::string>& channels);
7073
std::vector<float> getValuesAtNanoPos(nanogui::Vector2i nanoPos, const std::vector<std::string>& channels) {
@@ -94,6 +97,14 @@ class ImageCanvas : public nanogui::Canvas {
9497
mMetric = metric;
9598
}
9699

100+
void setCrop(const std::optional<Box2i>& crop) {
101+
mCrop = crop;
102+
}
103+
104+
std::optional<Box2i> getCrop() {
105+
return mCrop;
106+
}
107+
97108
static float applyMetric(float value, float reference, EMetric metric);
98109
float applyMetric(float value, float reference) const {
99110
return applyMetric(value, reference, mMetric);
@@ -141,6 +152,7 @@ class ImageCanvas : public nanogui::Canvas {
141152
std::shared_ptr<Image> reference,
142153
const std::string& requestedChannelGroup,
143154
EMetric metric,
155+
const Box2i& region,
144156
int priority
145157
);
146158

@@ -174,6 +186,7 @@ class ImageCanvas : public nanogui::Canvas {
174186

175187
ETonemap mTonemap = SRGB;
176188
EMetric mMetric = Error;
189+
std::optional<Box2i> mCrop;
177190

178191
std::map<std::string, std::shared_ptr<Lazy<std::shared_ptr<CanvasStatistics>>>> mCanvasStatistics;
179192
std::map<int, std::vector<std::string>> mImageIdToCanvasStatisticsKey;

include/tev/ImageViewer.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,18 @@ class ImageViewer : public nanogui::Screen {
252252

253253
HelpWindow* mHelpWindow = nullptr;
254254

255-
bool mIsDraggingSidebar = false;
256-
bool mIsDraggingImage = false;
257-
bool mIsDraggingImageButton = false;
255+
enum class EMouseDragType {
256+
None,
257+
ImageDrag,
258+
ImageCrop,
259+
ImageButtonDrag,
260+
SidebarDrag,
261+
};
262+
263+
nanogui::Vector2i mDraggingStartPosition;
264+
EMouseDragType mDragType = EMouseDragType::None;
258265
size_t mDraggedImageButtonId;
259266

260-
nanogui::Vector2f mDraggingStartPosition;
261-
262267
size_t mClipboardIndex = 0;
263268

264269
bool mSupportsHdr = false;

include/tev/UberShader.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33

44
#pragma once
55

6+
#include <tev/Box.h>
7+
68
#include <nanogui/shader.h>
79
#include <nanogui/texture.h>
810
#include <nanogui/vector.h>
911

12+
#include <optional>
13+
1014
namespace tev {
1115

1216
class UberShader {
@@ -27,7 +31,8 @@ class UberShader {
2731
float offset,
2832
float gamma,
2933
bool clipToLdr,
30-
ETonemap tonemap
34+
ETonemap tonemap,
35+
const std::optional<Box2i>& crop
3136
);
3237

3338
// Draws a difference between a reference and an image.
@@ -43,7 +48,8 @@ class UberShader {
4348
float gamma,
4449
bool clipToLdr,
4550
ETonemap tonemap,
46-
EMetric metric
51+
EMetric metric,
52+
const std::optional<Box2i>& crop
4753
);
4854

4955
const nanogui::Color& backgroundColor() {

src/HelpWindow.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ HelpWindow::HelpWindow(Widget* parent, bool supportsHdr, function<void()> closeC
8282
addRow(imageSelection, "Home / End", "Select first / last image");
8383
addRow(imageSelection, "Space", "Toggle playback of images as video");
8484

85-
addRow(imageSelection, "Click & Drag (+Shift/" + COMMAND + ")", "Translate image");
85+
addRow(imageSelection, "Click & Drag (+Shift/" + COMMAND + ")", "Translate image");
86+
addRow(imageSelection, "Click & Drag+C (hold)", "Select region of histogram");
8687
addRow(imageSelection, "+ / - / Scroll (+Shift/" + COMMAND + ")", "Zoom in / out of image");
8788

8889
addRow(imageSelection, COMMAND + "+0", "Zoom to actual size");
@@ -110,7 +111,7 @@ HelpWindow::HelpWindow(Widget* parent, bool supportsHdr, function<void()> closeC
110111
auto referenceSelection = new Widget{shortcuts};
111112
referenceSelection->set_layout(new BoxLayout{Orientation::Vertical, Alignment::Fill, 0, 0});
112113

113-
addRow(referenceSelection, ALT + " (hold)", "View currently selected reference");
114+
addRow(referenceSelection, "Shift (hold)", "View currently selected reference");
114115
addRow(referenceSelection, "Shift+Left Click or Right Click", "Select hovered image as reference");
115116
addRow(referenceSelection, "Shift+1…9", "Select N-th image as reference");
116117
addRow(referenceSelection, "Shift+Down or Shift+S / Shift+Up or Shift+W", "Select next / previous image as reference");

0 commit comments

Comments
 (0)