Skip to content

Commit

Permalink
Develop (#34)
Browse files Browse the repository at this point in the history
* adding new colorpicker and related widgets
* cleanup and reorg
* removing unused color functions.
* moving generic widgets to nanogui namespace.
* continuing snake casing
* adding box type, start of region of interest selection (ROI) support
* adding support for applying filters only to region of interest (ROI)
* adding crop command. fixing some async redraw issues
* adding keyboard shortcuts for tool switching
* adding copy-paste functionality
* adding keyboard shortcuts.
* bumping version
  • Loading branch information
wkjarosz authored Jun 2, 2021
1 parent 974b313 commit a277e27
Show file tree
Hide file tree
Showing 40 changed files with 2,447 additions and 672 deletions.
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required (VERSION 3.3)
project(hdrview)

set(HDRVIEW_VERSION "1.0.2")
set(HDRVIEW_VERSION "1.1.0")

# Set ourselves as the startup project in visual studio.
# Not available until cmake 3.6, but doesn't break older versions.
Expand Down Expand Up @@ -92,6 +92,10 @@ foreach(fname_in IN LISTS resources)
list(APPEND resources_processed ${fname_out})
endforeach()


file(GLOB patterns "${CMAKE_CURRENT_SOURCE_DIR}/resources/patterns/*.png")
list (APPEND resources_processed ${patterns})

# Concatenate resource files into a comma separated string
string(REGEX REPLACE "([^\\]|^);" "\\1," resources_string "${resources_processed}")
string(REGEX REPLACE "[\\](.)" "\\1" resources_string "${resources_string}")
Expand Down Expand Up @@ -133,10 +137,13 @@ add_executable(HDRView
hdrview_version.cpp
hdrview_resources.cpp
src/async.h
src/color.cpp
src/color.h
src/colorslider.cpp
src/colorslider.h
src/colorspace.cpp
src/colorspace.h
src/colorwheel.cpp
src/colorwheel.h
src/commandhistory.h
src/common.cpp
src/common.h
Expand All @@ -150,6 +157,8 @@ add_executable(HDRView
src/fwd.h
src/xpuimage.cpp
src/xpuimage.h
src/hdrcolorpicker.cpp
src/hdrcolorpicker.h
src/hdrimage.cpp
src/hdrimage.h
src/hdrimageio.cpp
Expand Down Expand Up @@ -221,7 +230,6 @@ endif()

add_executable(hdrbatch
hdrview_version.cpp
src/color.cpp
src/color.h
src/colorspace.cpp
src/colorspace.h
Expand Down
Binary file added resources/patterns/checker4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/patterns/checker8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/patterns/stripe7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
229 changes: 229 additions & 0 deletions src/box.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
//
// Copyright (C) Wojciech Jarosz <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE.txt file.
//

#pragma once

#include "fwd.h"
#include <limits> // for numeric_limits
#include <algorithm> // for min, max


//! Represents a bounded interval in higher dimensions.
/*!
Box is an N-D interval.
*/
template <typename Vec, typename Value, size_t Dims>
class Box
{
public:
using BoxT = Box<Vec, Value, Dims>;

Vec min; //!< The lower-bound of the interval
Vec max; //!< The upper-bound of the interval


//-----------------------------------------------------------------------
//@{ \name Constructors
//-----------------------------------------------------------------------
Box() {make_empty();}
Box(const Vec & point) : min(point), max(point) {}
Box(const Vec & minT, const Vec & maxT) : min(minT), max(maxT) {}
template <typename T>
Box(const Box<T> & box) : min((Vec)box.min), max((Vec)box.max) {}
template <typename T, typename S>
Box(const Box<T> & box1, const Box<S> & box2) :
min((Vec)box1.min), max((Vec)box1.max)
{
enclose((BoxT)box2);
}
//@}


//-----------------------------------------------------------------------
//@{ \name Equality and inequality
//-----------------------------------------------------------------------
bool operator==(const BoxT & other) const
{return(min == other.min && max == other.max);}
bool operator!=(const BoxT & other) const
{return(min != other.min || max != other.max);}
//@}


//-----------------------------------------------------------------------
//@{ \name Box manipulation
//-----------------------------------------------------------------------
void make_empty()
{
min = Vec(std::numeric_limits<Value>::max());
max = Vec(std::numeric_limits<Value>::lowest());
}
void enclose(const Vec & point)
{
for (size_t i = 0; i < Dims; ++i)
{
min[i] = std::min(point[i], min[i]);
max[i] = std::max(point[i], max[i]);
}
}
BoxT expanded(Value d) const
{
return BoxT(min-d, max+d);
}
BoxT expanded(const Vec & d) const
{
return BoxT(min-d, max+d);
}
BoxT expanded(const BoxT & d) const
{
return BoxT(min-d.min, max+d.max);
}
void enclose(const BoxT & box)
{
for (size_t i = 0; i < Dims; ++i)
{
min[i] = std::min(box.min[i], min[i]);
max[i] = std::max(box.max[i], max[i]);
}
}
void intersect(const BoxT & box)
{
for (size_t i = 0; i < Dims; ++i)
{
min[i] = std::max(box.min[i], min[i]);
max[i] = std::min(box.max[i], max[i]);
}
}
void move_min_to(const Vec &newMin)
{
Vec diff(newMin - min);
min = newMin;
max += diff;
}
void move_max_to(const Vec &newMax)
{
Vec diff(newMax - max);
max = newMax;
min += diff;
}
void make_valid()
{
for (size_t i = 0; i < Dims; ++i)
{
if (min[i] > max[i])
std::swap(min[i], max[i]);
}
}
//@}


//-----------------------------------------------------------------------
//@{ \name Query functions
//-----------------------------------------------------------------------
Vec size() const {return max-min;}
Vec center() const {return (max+min)/Value(2);}
Vec clamp(Vec point) const
{
for (size_t i = 0; i < Dims; ++i)
point[i] = std::min(std::max(point[i], min[i]), max[i]);
return point;
}
bool contains(const Vec & point, bool proper = false) const
{
if (proper)
{
for (size_t i = 0; i < Dims; ++i)
if (point[i] <= min[i] || point[i] >= max[i])
return false;
return true;
}
else
{
for (size_t i = 0; i < Dims; ++i)
if (point[i] < min[i] || point[i] > max[i])
return false;
return true;
}
}
bool intersects(const BoxT & box, bool proper = false) const
{
if (proper)
{
for (size_t i = 0; i < Dims; ++i)
if (box.max[i] <= min[i] || box.min[i] >= max[i])
return false;
return true;
}
else
{
for (size_t i = 0; i < Dims; ++i)
if (box.max[i] < min[i] || box.min[i] > max[i])
return false;
return true;
}
}
Value volume() const
{
Value ret_val(1);
Vec s = size();
for (size_t i = 0; i < Dims; ++i)
ret_val *= s[i];
return ret_val;
}
Value area() const
{
Value ret_val(0);
Vec s = size();
for (size_t i = 0; i < Dims; ++i)
for (size_t j = i+1; j < Dims; j++)
ret_val += s[i]*s[j];
return 2*ret_val;
}
size_t major_axis() const
{
size_t major = 0;
Vec s = size();

for (size_t i = 1; i < Dims; ++i)
if (s[i] > s[major])
major = i;
return major;
}
void bounding_sphere(Vec* center, Value* radius) const
{
*center = center();
*radius = intersects(*center) ?(*center - max).length() : 0.0f;
}
//@}


//-----------------------------------------------------------------------
//@{ \name Classification
//-----------------------------------------------------------------------
bool has_volume() const
{
for (size_t i = 0; i < Dims; ++i)
if (max[i] <= min[i])
return false;
return true;
}
bool is_empty() const
{
for (size_t i = 0; i < Dims; ++i)
if (max[i] < min[i])
return true;
return false;
}
//@}
};


template <typename Vec, typename Value, size_t Dims>
inline std::ostream&
operator<<(std::ostream &o, const Box<Vec,Value,Dims> &b)
{
return o << "[(" << b.min << "),(" << b.max << ")]";
}

63 changes: 0 additions & 63 deletions src/color.cpp

This file was deleted.

Loading

0 comments on commit a277e27

Please sign in to comment.