2020-09-13 15:47:24 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
//##########################################################################
|
|
|
|
|
//# #
|
|
|
|
|
//# CLOUDCOMPARE PLUGIN: ColorimetricSegmenter #
|
|
|
|
|
//# #
|
|
|
|
|
//# This program is free software; you can redistribute it and/or modify #
|
|
|
|
|
//# it under the terms of the GNU General Public License as published by #
|
|
|
|
|
//# the Free Software Foundation; version 2 of the License. #
|
|
|
|
|
//# #
|
|
|
|
|
//# This program is distributed in the hope that it will be useful, #
|
|
|
|
|
//# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
|
|
|
|
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
|
|
|
|
//# GNU General Public License for more details. #
|
|
|
|
|
//# #
|
|
|
|
|
//# COPYRIGHT: Tri-Thien TRUONG, Ronan COLLIER, Mathieu LETRONE #
|
|
|
|
|
//# #
|
|
|
|
|
//##########################################################################
|
|
|
|
|
|
|
|
|
|
//qCC_db
|
|
|
|
|
#include <ccColorTypes.h>
|
|
|
|
|
|
|
|
|
|
//! HSV color
|
|
|
|
|
struct Hsv
|
|
|
|
|
{
|
|
|
|
|
//! Default constrctor
|
|
|
|
|
Hsv()
|
|
|
|
|
: h(0)
|
|
|
|
|
, s(0)
|
|
|
|
|
, v(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! Constrctor from a RGB color
|
|
|
|
|
Hsv(const ccColor::Rgb& rgb)
|
|
|
|
|
{
|
|
|
|
|
float r = rgb.r / 255.0f;
|
|
|
|
|
float g = rgb.g / 255.0f;
|
|
|
|
|
float b = rgb.b / 255.0f;
|
|
|
|
|
float maxComp = std::max(std::max(r, g), b);
|
|
|
|
|
float minComp = std::min(std::min(r, g), b);
|
|
|
|
|
float deltaComp = maxComp - minComp;
|
|
|
|
|
|
2020-09-13 21:35:37 +02:00
|
|
|
float hue = 0;
|
2020-09-13 15:47:24 +02:00
|
|
|
if (deltaComp != 0)
|
|
|
|
|
{
|
|
|
|
|
if (r == maxComp)
|
|
|
|
|
{
|
2020-09-13 21:35:37 +02:00
|
|
|
hue = (g - b) / deltaComp;
|
2020-09-13 15:47:24 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (g == maxComp)
|
|
|
|
|
{
|
2020-09-13 21:35:37 +02:00
|
|
|
hue = 2 + (b - r) / deltaComp;
|
2020-09-13 15:47:24 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-13 21:35:37 +02:00
|
|
|
hue = 4 + (r - g) / deltaComp;
|
2020-09-13 15:47:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-13 21:35:37 +02:00
|
|
|
hue *= 60;
|
|
|
|
|
if (hue < 0)
|
|
|
|
|
hue += 360;
|
2020-09-13 15:47:24 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-13 21:35:37 +02:00
|
|
|
h = (static_cast<uint16_t>(hue) % 360);
|
|
|
|
|
s = static_cast<uint16_t>(maxComp == 0 ? 0 : (deltaComp / maxComp) * 100);
|
|
|
|
|
v = static_cast<uint16_t>(maxComp * 100);
|
2020-09-13 15:47:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HSV components
|
2020-09-13 21:35:37 +02:00
|
|
|
uint16_t h, s, v;
|
2020-09-13 15:47:24 +02:00
|
|
|
};
|