aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Fadel <samuelfadel@gmail.com>2015-09-03 17:05:54 -0300
committerSamuel Fadel <samuelfadel@gmail.com>2015-09-03 17:05:54 -0300
commite00551288d06fc7d913aab6473dcab8fa9934410 (patch)
tree5c4daa7ea8b2e11bf783a5d57b33db0e44ad6635
parente05a1bd658a7bacb4e13f05b7125ceed7a33dd4b (diff)
Code standardization and new builtin continuous color scales scheme.
-rw-r--r--colorscale.cpp12
-rw-r--r--continuouscolorscale.cpp789
-rw-r--r--continuouscolorscale.h9
-rw-r--r--dist.cpp3
-rw-r--r--forceScheme.cpp9
-rw-r--r--main.cpp7
-rw-r--r--scatterplot.cpp46
-rw-r--r--tsne.cpp15
8 files changed, 596 insertions, 294 deletions
diff --git a/colorscale.cpp b/colorscale.cpp
index 50fedae..85c036d 100644
--- a/colorscale.cpp
+++ b/colorscale.cpp
@@ -24,8 +24,9 @@ ColorScale::~ColorScale()
void ColorScale::setExtents(qreal min, qreal max)
{
- if (min >= max)
+ if (min >= max) {
return;
+ }
m_min = min;
m_max = max;
@@ -48,23 +49,26 @@ static QColor lerp(const QColor &c1, const QColor &c2, qreal t)
QColor ColorScale::color(qreal t) const
{
- if (t < m_min || t > m_max)
+ if (t < m_min || t > m_max) {
return QColor();
+ }
// normalize t
t = (t - m_min) / (m_max - m_min);
// two colors, use a simpler solution
- if (m_colors.size() == 2)
+ if (m_colors.size() == 2) {
return lerp(m_colors.first(), m_colors.last(), t);
+ }
// find which colors in the scale are adjacent to ours
qreal step = 1.0 / m_colors.size();
int i = (int) (t / step);
int j = i + 1;
- if (i >= m_colors.size() - 1)
+ if (i >= m_colors.size() - 1) {
return QColor(m_colors.last());
+ }
// normalize t between the two colors
t = (t - i*step) / (j*step - i*step);
diff --git a/continuouscolorscale.cpp b/continuouscolorscale.cpp
index c12db80..f3dbc42 100644
--- a/continuouscolorscale.cpp
+++ b/continuouscolorscale.cpp
@@ -2,264 +2,8 @@
#include <cmath>
-ContinuousColorScale::ContinuousColorScale()
- : ColorScale{
- QColor( 0, 0, 0),
- QColor( 35, 0, 0),
- QColor( 52, 0, 0),
- QColor( 60, 0, 0),
- QColor( 63, 1, 0),
- QColor( 64, 2, 0),
- QColor( 68, 5, 0),
- QColor( 69, 6, 0),
- QColor( 72, 8, 0),
- QColor( 74, 10, 0),
- QColor( 77, 12, 0),
- QColor( 78, 14, 0),
- QColor( 81, 16, 0),
- QColor( 83, 17, 0),
- QColor( 85, 19, 0),
- QColor( 86, 20, 0),
- QColor( 89, 22, 0),
- QColor( 91, 24, 0),
- QColor( 92, 25, 0),
- QColor( 94, 26, 0),
- QColor( 95, 28, 0),
- QColor( 98, 30, 0),
- QColor(100, 31, 0),
- QColor(102, 33, 0),
- QColor(103, 34, 0),
- QColor(105, 35, 0),
- QColor(106, 36, 0),
- QColor(108, 38, 0),
- QColor(109, 39, 0),
- QColor(111, 40, 0),
- QColor(112, 42, 0),
- QColor(114, 43, 0),
- QColor(115, 44, 0),
- QColor(117, 45, 0),
- QColor(119, 47, 0),
- QColor(119, 47, 0),
- QColor(120, 48, 0),
- QColor(122, 49, 0),
- QColor(123, 51, 0),
- QColor(125, 52, 0),
- QColor(125, 52, 0),
- QColor(126, 53, 0),
- QColor(128, 54, 0),
- QColor(129, 56, 0),
- QColor(129, 56, 0),
- QColor(131, 57, 0),
- QColor(132, 58, 0),
- QColor(134, 59, 0),
- QColor(134, 59, 0),
- QColor(136, 61, 0),
- QColor(137, 62, 0),
- QColor(137, 62, 0),
- QColor(139, 63, 0),
- QColor(139, 63, 0),
- QColor(140, 65, 0),
- QColor(142, 66, 0),
- QColor(142, 66, 0),
- QColor(143, 67, 0),
- QColor(143, 67, 0),
- QColor(145, 68, 0),
- QColor(145, 68, 0),
- QColor(146, 70, 0),
- QColor(146, 70, 0),
- QColor(148, 71, 0),
- QColor(148, 71, 0),
- QColor(149, 72, 0),
- QColor(149, 72, 0),
- QColor(151, 73, 0),
- QColor(151, 73, 0),
- QColor(153, 75, 0),
- QColor(153, 75, 0),
- QColor(154, 76, 0),
- QColor(154, 76, 0),
- QColor(154, 76, 0),
- QColor(156, 77, 0),
- QColor(156, 77, 0),
- QColor(157, 79, 0),
- QColor(157, 79, 0),
- QColor(159, 80, 0),
- QColor(159, 80, 0),
- QColor(159, 80, 0),
- QColor(160, 81, 0),
- QColor(160, 81, 0),
- QColor(162, 82, 0),
- QColor(162, 82, 0),
- QColor(163, 84, 0),
- QColor(163, 84, 0),
- QColor(165, 85, 0),
- QColor(165, 85, 0),
- QColor(166, 86, 0),
- QColor(166, 86, 0),
- QColor(166, 86, 0),
- QColor(168, 87, 0),
- QColor(168, 87, 0),
- QColor(170, 89, 0),
- QColor(170, 89, 0),
- QColor(171, 90, 0),
- QColor(171, 90, 0),
- QColor(173, 91, 0),
- QColor(173, 91, 0),
- QColor(174, 93, 0),
- QColor(174, 93, 0),
- QColor(176, 94, 0),
- QColor(176, 94, 0),
- QColor(177, 95, 0),
- QColor(177, 95, 0),
- QColor(179, 96, 0),
- QColor(179, 96, 0),
- QColor(180, 98, 0),
- QColor(182, 99, 0),
- QColor(182, 99, 0),
- QColor(183, 100, 0),
- QColor(183, 100, 0),
- QColor(185, 102, 0),
- QColor(185, 102, 0),
- QColor(187, 103, 0),
- QColor(187, 103, 0),
- QColor(188, 104, 0),
- QColor(188, 104, 0),
- QColor(190, 105, 0),
- QColor(191, 107, 0),
- QColor(191, 107, 0),
- QColor(193, 108, 0),
- QColor(193, 108, 0),
- QColor(194, 109, 0),
- QColor(196, 110, 0),
- QColor(196, 110, 0),
- QColor(197, 112, 0),
- QColor(197, 112, 0),
- QColor(199, 113, 0),
- QColor(200, 114, 0),
- QColor(200, 114, 0),
- QColor(202, 116, 0),
- QColor(202, 116, 0),
- QColor(204, 117, 0),
- QColor(205, 118, 0),
- QColor(205, 118, 0),
- QColor(207, 119, 0),
- QColor(208, 121, 0),
- QColor(208, 121, 0),
- QColor(210, 122, 0),
- QColor(211, 123, 0),
- QColor(211, 123, 0),
- QColor(213, 124, 0),
- QColor(214, 126, 0),
- QColor(214, 126, 0),
- QColor(216, 127, 0),
- QColor(217, 128, 0),
- QColor(217, 128, 0),
- QColor(219, 130, 0),
- QColor(221, 131, 0),
- QColor(221, 131, 0),
- QColor(222, 132, 0),
- QColor(224, 133, 0),
- QColor(224, 133, 0),
- QColor(225, 135, 0),
- QColor(227, 136, 0),
- QColor(227, 136, 0),
- QColor(228, 137, 0),
- QColor(230, 138, 0),
- QColor(230, 138, 0),
- QColor(231, 140, 0),
- QColor(233, 141, 0),
- QColor(233, 141, 0),
- QColor(234, 142, 0),
- QColor(236, 144, 0),
- QColor(236, 144, 0),
- QColor(238, 145, 0),
- QColor(239, 146, 0),
- QColor(241, 147, 0),
- QColor(241, 147, 0),
- QColor(242, 149, 0),
- QColor(244, 150, 0),
- QColor(244, 150, 0),
- QColor(245, 151, 0),
- QColor(247, 153, 0),
- QColor(247, 153, 0),
- QColor(248, 154, 0),
- QColor(250, 155, 0),
- QColor(251, 156, 0),
- QColor(251, 156, 0),
- QColor(253, 158, 0),
- QColor(255, 159, 0),
- QColor(255, 159, 0),
- QColor(255, 160, 0),
- QColor(255, 161, 0),
- QColor(255, 163, 0),
- QColor(255, 163, 0),
- QColor(255, 164, 0),
- QColor(255, 165, 0),
- QColor(255, 167, 0),
- QColor(255, 167, 0),
- QColor(255, 168, 0),
- QColor(255, 169, 0),
- QColor(255, 169, 0),
- QColor(255, 170, 0),
- QColor(255, 172, 0),
- QColor(255, 173, 0),
- QColor(255, 173, 0),
- QColor(255, 174, 0),
- QColor(255, 175, 0),
- QColor(255, 177, 0),
- QColor(255, 178, 0),
- QColor(255, 179, 0),
- QColor(255, 181, 0),
- QColor(255, 181, 0),
- QColor(255, 182, 0),
- QColor(255, 183, 0),
- QColor(255, 184, 0),
- QColor(255, 187, 7),
- QColor(255, 188, 10),
- QColor(255, 189, 14),
- QColor(255, 191, 18),
- QColor(255, 192, 21),
- QColor(255, 193, 25),
- QColor(255, 195, 29),
- QColor(255, 197, 36),
- QColor(255, 198, 40),
- QColor(255, 200, 43),
- QColor(255, 202, 51),
- QColor(255, 204, 54),
- QColor(255, 206, 61),
- QColor(255, 207, 65),
- QColor(255, 210, 72),
- QColor(255, 211, 76),
- QColor(255, 214, 83),
- QColor(255, 216, 91),
- QColor(255, 219, 98),
- QColor(255, 221, 105),
- QColor(255, 223, 109),
- QColor(255, 225, 116),
- QColor(255, 228, 123),
- QColor(255, 232, 134),
- QColor(255, 234, 142),
- QColor(255, 237, 149),
- QColor(255, 239, 156),
- QColor(255, 240, 160),
- QColor(255, 243, 167),
- QColor(255, 246, 174),
- QColor(255, 248, 182),
- QColor(255, 249, 185),
- QColor(255, 252, 193),
- QColor(255, 253, 196),
- QColor(255, 255, 204),
- QColor(255, 255, 207),
- QColor(255, 255, 211),
- QColor(255, 255, 218),
- QColor(255, 255, 222),
- QColor(255, 255, 225),
- QColor(255, 255, 229),
- QColor(255, 255, 233),
- QColor(255, 255, 236),
- QColor(255, 255, 240),
- QColor(255, 255, 244),
- QColor(255, 255, 247),
- QColor(255, 255, 255)}
+ContinuousColorScale::ContinuousColorScale(std::initializer_list<QColor> colors)
+ : ColorScale{colors}
{
}
@@ -275,11 +19,538 @@ QColor ContinuousColorScale::color(qreal t) const
qreal step = 1.0 / m_colors.size();
int i = (int) (t / step);
- if (i >= m_colors.size() - 1)
+ if (i >= m_colors.size() - 1) {
return m_colors.last();
+ }
// normalize t between the two colors
int j = i + 1;
t = (t - i*step) / (j*step - i*step);
return m_colors[i + round(t)];
}
+
+ContinuousColorScale ContinuousColorScale::builtin(BuiltinContinuousColorScale scale)
+{
+ switch (scale) {
+ case HEATED_OBJECTS:
+ return ContinuousColorScale{
+ QColor( 0, 0, 0),
+ QColor( 35, 0, 0),
+ QColor( 52, 0, 0),
+ QColor( 60, 0, 0),
+ QColor( 63, 1, 0),
+ QColor( 64, 2, 0),
+ QColor( 68, 5, 0),
+ QColor( 69, 6, 0),
+ QColor( 72, 8, 0),
+ QColor( 74, 10, 0),
+ QColor( 77, 12, 0),
+ QColor( 78, 14, 0),
+ QColor( 81, 16, 0),
+ QColor( 83, 17, 0),
+ QColor( 85, 19, 0),
+ QColor( 86, 20, 0),
+ QColor( 89, 22, 0),
+ QColor( 91, 24, 0),
+ QColor( 92, 25, 0),
+ QColor( 94, 26, 0),
+ QColor( 95, 28, 0),
+ QColor( 98, 30, 0),
+ QColor(100, 31, 0),
+ QColor(102, 33, 0),
+ QColor(103, 34, 0),
+ QColor(105, 35, 0),
+ QColor(106, 36, 0),
+ QColor(108, 38, 0),
+ QColor(109, 39, 0),
+ QColor(111, 40, 0),
+ QColor(112, 42, 0),
+ QColor(114, 43, 0),
+ QColor(115, 44, 0),
+ QColor(117, 45, 0),
+ QColor(119, 47, 0),
+ QColor(119, 47, 0),
+ QColor(120, 48, 0),
+ QColor(122, 49, 0),
+ QColor(123, 51, 0),
+ QColor(125, 52, 0),
+ QColor(125, 52, 0),
+ QColor(126, 53, 0),
+ QColor(128, 54, 0),
+ QColor(129, 56, 0),
+ QColor(129, 56, 0),
+ QColor(131, 57, 0),
+ QColor(132, 58, 0),
+ QColor(134, 59, 0),
+ QColor(134, 59, 0),
+ QColor(136, 61, 0),
+ QColor(137, 62, 0),
+ QColor(137, 62, 0),
+ QColor(139, 63, 0),
+ QColor(139, 63, 0),
+ QColor(140, 65, 0),
+ QColor(142, 66, 0),
+ QColor(142, 66, 0),
+ QColor(143, 67, 0),
+ QColor(143, 67, 0),
+ QColor(145, 68, 0),
+ QColor(145, 68, 0),
+ QColor(146, 70, 0),
+ QColor(146, 70, 0),
+ QColor(148, 71, 0),
+ QColor(148, 71, 0),
+ QColor(149, 72, 0),
+ QColor(149, 72, 0),
+ QColor(151, 73, 0),
+ QColor(151, 73, 0),
+ QColor(153, 75, 0),
+ QColor(153, 75, 0),
+ QColor(154, 76, 0),
+ QColor(154, 76, 0),
+ QColor(154, 76, 0),
+ QColor(156, 77, 0),
+ QColor(156, 77, 0),
+ QColor(157, 79, 0),
+ QColor(157, 79, 0),
+ QColor(159, 80, 0),
+ QColor(159, 80, 0),
+ QColor(159, 80, 0),
+ QColor(160, 81, 0),
+ QColor(160, 81, 0),
+ QColor(162, 82, 0),
+ QColor(162, 82, 0),
+ QColor(163, 84, 0),
+ QColor(163, 84, 0),
+ QColor(165, 85, 0),
+ QColor(165, 85, 0),
+ QColor(166, 86, 0),
+ QColor(166, 86, 0),
+ QColor(166, 86, 0),
+ QColor(168, 87, 0),
+ QColor(168, 87, 0),
+ QColor(170, 89, 0),
+ QColor(170, 89, 0),
+ QColor(171, 90, 0),
+ QColor(171, 90, 0),
+ QColor(173, 91, 0),
+ QColor(173, 91, 0),
+ QColor(174, 93, 0),
+ QColor(174, 93, 0),
+ QColor(176, 94, 0),
+ QColor(176, 94, 0),
+ QColor(177, 95, 0),
+ QColor(177, 95, 0),
+ QColor(179, 96, 0),
+ QColor(179, 96, 0),
+ QColor(180, 98, 0),
+ QColor(182, 99, 0),
+ QColor(182, 99, 0),
+ QColor(183, 100, 0),
+ QColor(183, 100, 0),
+ QColor(185, 102, 0),
+ QColor(185, 102, 0),
+ QColor(187, 103, 0),
+ QColor(187, 103, 0),
+ QColor(188, 104, 0),
+ QColor(188, 104, 0),
+ QColor(190, 105, 0),
+ QColor(191, 107, 0),
+ QColor(191, 107, 0),
+ QColor(193, 108, 0),
+ QColor(193, 108, 0),
+ QColor(194, 109, 0),
+ QColor(196, 110, 0),
+ QColor(196, 110, 0),
+ QColor(197, 112, 0),
+ QColor(197, 112, 0),
+ QColor(199, 113, 0),
+ QColor(200, 114, 0),
+ QColor(200, 114, 0),
+ QColor(202, 116, 0),
+ QColor(202, 116, 0),
+ QColor(204, 117, 0),
+ QColor(205, 118, 0),
+ QColor(205, 118, 0),
+ QColor(207, 119, 0),
+ QColor(208, 121, 0),
+ QColor(208, 121, 0),
+ QColor(210, 122, 0),
+ QColor(211, 123, 0),
+ QColor(211, 123, 0),
+ QColor(213, 124, 0),
+ QColor(214, 126, 0),
+ QColor(214, 126, 0),
+ QColor(216, 127, 0),
+ QColor(217, 128, 0),
+ QColor(217, 128, 0),
+ QColor(219, 130, 0),
+ QColor(221, 131, 0),
+ QColor(221, 131, 0),
+ QColor(222, 132, 0),
+ QColor(224, 133, 0),
+ QColor(224, 133, 0),
+ QColor(225, 135, 0),
+ QColor(227, 136, 0),
+ QColor(227, 136, 0),
+ QColor(228, 137, 0),
+ QColor(230, 138, 0),
+ QColor(230, 138, 0),
+ QColor(231, 140, 0),
+ QColor(233, 141, 0),
+ QColor(233, 141, 0),
+ QColor(234, 142, 0),
+ QColor(236, 144, 0),
+ QColor(236, 144, 0),
+ QColor(238, 145, 0),
+ QColor(239, 146, 0),
+ QColor(241, 147, 0),
+ QColor(241, 147, 0),
+ QColor(242, 149, 0),
+ QColor(244, 150, 0),
+ QColor(244, 150, 0),
+ QColor(245, 151, 0),
+ QColor(247, 153, 0),
+ QColor(247, 153, 0),
+ QColor(248, 154, 0),
+ QColor(250, 155, 0),
+ QColor(251, 156, 0),
+ QColor(251, 156, 0),
+ QColor(253, 158, 0),
+ QColor(255, 159, 0),
+ QColor(255, 159, 0),
+ QColor(255, 160, 0),
+ QColor(255, 161, 0),
+ QColor(255, 163, 0),
+ QColor(255, 163, 0),
+ QColor(255, 164, 0),
+ QColor(255, 165, 0),
+ QColor(255, 167, 0),
+ QColor(255, 167, 0),
+ QColor(255, 168, 0),
+ QColor(255, 169, 0),
+ QColor(255, 169, 0),
+ QColor(255, 170, 0),
+ QColor(255, 172, 0),
+ QColor(255, 173, 0),
+ QColor(255, 173, 0),
+ QColor(255, 174, 0),
+ QColor(255, 175, 0),
+ QColor(255, 177, 0),
+ QColor(255, 178, 0),
+ QColor(255, 179, 0),
+ QColor(255, 181, 0),
+ QColor(255, 181, 0),
+ QColor(255, 182, 0),
+ QColor(255, 183, 0),
+ QColor(255, 184, 0),
+ QColor(255, 187, 7),
+ QColor(255, 188, 10),
+ QColor(255, 189, 14),
+ QColor(255, 191, 18),
+ QColor(255, 192, 21),
+ QColor(255, 193, 25),
+ QColor(255, 195, 29),
+ QColor(255, 197, 36),
+ QColor(255, 198, 40),
+ QColor(255, 200, 43),
+ QColor(255, 202, 51),
+ QColor(255, 204, 54),
+ QColor(255, 206, 61),
+ QColor(255, 207, 65),
+ QColor(255, 210, 72),
+ QColor(255, 211, 76),
+ QColor(255, 214, 83),
+ QColor(255, 216, 91),
+ QColor(255, 219, 98),
+ QColor(255, 221, 105),
+ QColor(255, 223, 109),
+ QColor(255, 225, 116),
+ QColor(255, 228, 123),
+ QColor(255, 232, 134),
+ QColor(255, 234, 142),
+ QColor(255, 237, 149),
+ QColor(255, 239, 156),
+ QColor(255, 240, 160),
+ QColor(255, 243, 167),
+ QColor(255, 246, 174),
+ QColor(255, 248, 182),
+ QColor(255, 249, 185),
+ QColor(255, 252, 193),
+ QColor(255, 253, 196),
+ QColor(255, 255, 204),
+ QColor(255, 255, 207),
+ QColor(255, 255, 211),
+ QColor(255, 255, 218),
+ QColor(255, 255, 222),
+ QColor(255, 255, 225),
+ QColor(255, 255, 229),
+ QColor(255, 255, 233),
+ QColor(255, 255, 236),
+ QColor(255, 255, 240),
+ QColor(255, 255, 244),
+ QColor(255, 255, 247),
+ QColor(255, 255, 255)
+ };
+ case RED_GRAY_BLUE:
+ return ContinuousColorScale{
+ QColor(221, 68, 68),
+ QColor(220, 69, 68),
+ QColor(220, 70, 69),
+ QColor(220, 71, 70),
+ QColor(220, 73, 71),
+ QColor(220, 74, 72),
+ QColor(220, 75, 73),
+ QColor(220, 77, 74),
+ QColor(220, 78, 75),
+ QColor(220, 79, 76),
+ QColor(220, 80, 76),
+ QColor(220, 81, 77),
+ QColor(220, 83, 78),
+ QColor(220, 84, 79),
+ QColor(220, 85, 80),
+ QColor(220, 86, 81),
+ QColor(220, 87, 82),
+ QColor(220, 88, 83),
+ QColor(220, 89, 84),
+ QColor(220, 91, 85),
+ QColor(220, 92, 85),
+ QColor(220, 93, 86),
+ QColor(220, 94, 87),
+ QColor(220, 95, 88),
+ QColor(220, 96, 89),
+ QColor(220, 97, 90),
+ QColor(220, 98, 91),
+ QColor(219, 99, 92),
+ QColor(219, 100, 93),
+ QColor(219, 101, 94),
+ QColor(219, 102, 95),
+ QColor(219, 103, 95),
+ QColor(219, 104, 96),
+ QColor(219, 105, 97),
+ QColor(219, 106, 98),
+ QColor(219, 107, 99),
+ QColor(219, 108, 100),
+ QColor(218, 109, 101),
+ QColor(218, 110, 102),
+ QColor(218, 111, 103),
+ QColor(218, 112, 104),
+ QColor(218, 113, 105),
+ QColor(218, 114, 106),
+ QColor(218, 115, 107),
+ QColor(218, 116, 108),
+ QColor(217, 117, 108),
+ QColor(217, 118, 109),
+ QColor(217, 119, 110),
+ QColor(217, 120, 111),
+ QColor(217, 121, 112),
+ QColor(217, 122, 113),
+ QColor(217, 123, 114),
+ QColor(216, 124, 115),
+ QColor(216, 125, 116),
+ QColor(216, 126, 117),
+ QColor(216, 127, 118),
+ QColor(216, 127, 119),
+ QColor(215, 128, 120),
+ QColor(215, 129, 121),
+ QColor(215, 130, 122),
+ QColor(215, 131, 123),
+ QColor(215, 132, 124),
+ QColor(214, 133, 125),
+ QColor(214, 134, 126),
+ QColor(214, 135, 127),
+ QColor(214, 136, 127),
+ QColor(214, 137, 128),
+ QColor(213, 138, 129),
+ QColor(213, 138, 130),
+ QColor(213, 139, 131),
+ QColor(213, 140, 132),
+ QColor(212, 141, 133),
+ QColor(212, 142, 134),
+ QColor(212, 143, 135),
+ QColor(212, 144, 136),
+ QColor(211, 145, 137),
+ QColor(211, 146, 138),
+ QColor(211, 146, 139),
+ QColor(211, 147, 140),
+ QColor(210, 148, 141),
+ QColor(210, 149, 142),
+ QColor(210, 150, 143),
+ QColor(209, 151, 144),
+ QColor(209, 152, 145),
+ QColor(209, 153, 146),
+ QColor(208, 153, 147),
+ QColor(208, 154, 148),
+ QColor(208, 155, 149),
+ QColor(207, 156, 150),
+ QColor(207, 157, 151),
+ QColor(207, 158, 152),
+ QColor(206, 159, 153),
+ QColor(206, 160, 154),
+ QColor(206, 160, 155),
+ QColor(205, 161, 156),
+ QColor(205, 162, 157),
+ QColor(205, 163, 158),
+ QColor(204, 164, 159),
+ QColor(204, 165, 160),
+ QColor(203, 166, 161),
+ QColor(203, 166, 162),
+ QColor(203, 167, 163),
+ QColor(202, 168, 164),
+ QColor(202, 169, 165),
+ QColor(201, 170, 166),
+ QColor(201, 171, 167),
+ QColor(201, 171, 168),
+ QColor(200, 172, 169),
+ QColor(200, 173, 170),
+ QColor(199, 174, 171),
+ QColor(199, 175, 172),
+ QColor(198, 176, 173),
+ QColor(198, 177, 174),
+ QColor(197, 177, 175),
+ QColor(197, 178, 176),
+ QColor(196, 179, 177),
+ QColor(196, 180, 178),
+ QColor(195, 181, 179),
+ QColor(195, 182, 180),
+ QColor(194, 182, 181),
+ QColor(194, 183, 182),
+ QColor(193, 184, 183),
+ QColor(193, 185, 184),
+ QColor(192, 186, 185),
+ QColor(192, 187, 186),
+ QColor(191, 187, 187),
+ QColor(190, 188, 188),
+ QColor(190, 189, 189),
+ QColor(189, 189, 190),
+ QColor(189, 188, 190),
+ QColor(188, 187, 190),
+ QColor(187, 186, 191),
+ QColor(187, 185, 191),
+ QColor(186, 184, 191),
+ QColor(185, 183, 191),
+ QColor(185, 182, 192),
+ QColor(184, 181, 192),
+ QColor(184, 180, 192),
+ QColor(183, 179, 193),
+ QColor(182, 178, 193),
+ QColor(182, 177, 193),
+ QColor(181, 176, 194),
+ QColor(180, 175, 194),
+ QColor(180, 174, 194),
+ QColor(179, 173, 194),
+ QColor(178, 172, 195),
+ QColor(178, 171, 195),
+ QColor(177, 170, 195),
+ QColor(176, 169, 196),
+ QColor(176, 168, 196),
+ QColor(175, 167, 196),
+ QColor(174, 166, 196),
+ QColor(174, 165, 197),
+ QColor(173, 164, 197),
+ QColor(172, 163, 197),
+ QColor(172, 162, 197),
+ QColor(171, 161, 198),
+ QColor(170, 160, 198),
+ QColor(170, 159, 198),
+ QColor(169, 158, 199),
+ QColor(168, 157, 199),
+ QColor(167, 156, 199),
+ QColor(167, 155, 199),
+ QColor(166, 155, 200),
+ QColor(165, 154, 200),
+ QColor(165, 153, 200),
+ QColor(164, 152, 200),
+ QColor(163, 151, 201),
+ QColor(162, 150, 201),
+ QColor(162, 149, 201),
+ QColor(161, 148, 201),
+ QColor(160, 147, 202),
+ QColor(159, 146, 202),
+ QColor(159, 145, 202),
+ QColor(158, 144, 202),
+ QColor(157, 143, 203),
+ QColor(156, 142, 203),
+ QColor(155, 141, 203),
+ QColor(155, 140, 203),
+ QColor(154, 139, 204),
+ QColor(153, 138, 204),
+ QColor(152, 137, 204),
+ QColor(152, 136, 204),
+ QColor(151, 135, 205),
+ QColor(150, 134, 205),
+ QColor(149, 133, 205),
+ QColor(148, 132, 205),
+ QColor(147, 131, 206),
+ QColor(147, 130, 206),
+ QColor(146, 129, 206),
+ QColor(145, 128, 206),
+ QColor(144, 128, 207),
+ QColor(143, 127, 207),
+ QColor(142, 126, 207),
+ QColor(142, 125, 207),
+ QColor(141, 124, 208),
+ QColor(140, 123, 208),
+ QColor(139, 122, 208),
+ QColor(138, 121, 208),
+ QColor(137, 120, 209),
+ QColor(136, 119, 209),
+ QColor(135, 118, 209),
+ QColor(134, 117, 209),
+ QColor(133, 116, 209),
+ QColor(133, 115, 210),
+ QColor(132, 114, 210),
+ QColor(131, 113, 210),
+ QColor(130, 112, 210),
+ QColor(129, 111, 211),
+ QColor(128, 110, 211),
+ QColor(127, 109, 211),
+ QColor(126, 109, 211),
+ QColor(125, 108, 212),
+ QColor(124, 107, 212),
+ QColor(123, 106, 212),
+ QColor(122, 105, 212),
+ QColor(121, 104, 212),
+ QColor(120, 103, 213),
+ QColor(119, 102, 213),
+ QColor(118, 101, 213),
+ QColor(117, 100, 213),
+ QColor(115, 99, 213),
+ QColor(114, 98, 214),
+ QColor(113, 97, 214),
+ QColor(112, 96, 214),
+ QColor(111, 95, 214),
+ QColor(110, 94, 215),
+ QColor(109, 94, 215),
+ QColor(108, 93, 215),
+ QColor(106, 92, 215),
+ QColor(105, 91, 215),
+ QColor(104, 90, 216),
+ QColor(103, 89, 216),
+ QColor(101, 88, 216),
+ QColor(100, 87, 216),
+ QColor(99, 86, 216),
+ QColor(98, 85, 217),
+ QColor(96, 84, 217),
+ QColor(95, 83, 217),
+ QColor(94, 82, 217),
+ QColor(92, 81, 217),
+ QColor(91, 80, 218),
+ QColor(89, 80, 218),
+ QColor(88, 79, 218),
+ QColor(86, 78, 218),
+ QColor(85, 77, 219),
+ QColor(83, 76, 219),
+ QColor(82, 75, 219),
+ QColor(80, 74, 219),
+ QColor(78, 73, 219),
+ QColor(77, 72, 220),
+ QColor(75, 71, 220),
+ QColor(73, 70, 220),
+ QColor(71, 69, 220),
+ QColor(69, 68, 220),
+ QColor(68, 68, 221)
+ };
+ default:
+ return ContinuousColorScale::builtin(ContinuousColorScale::HEATED_OBJECTS);
+ }
+}
diff --git a/continuouscolorscale.h b/continuouscolorscale.h
index 1ca2092..f734702 100644
--- a/continuouscolorscale.h
+++ b/continuouscolorscale.h
@@ -6,9 +6,16 @@
class ContinuousColorScale : public ColorScale
{
public:
- ContinuousColorScale();
+ ContinuousColorScale(std::initializer_list<QColor> colors);
+
+ enum BuiltinContinuousColorScale {
+ HEATED_OBJECTS,
+ RED_GRAY_BLUE
+ };
QColor color(qreal t) const;
+
+ static ContinuousColorScale builtin(enum BuiltinContinuousColorScale);
};
#endif // CONTINUOUSCOLORSCALE_H
diff --git a/dist.cpp b/dist.cpp
index a5620ad..422aa10 100644
--- a/dist.cpp
+++ b/dist.cpp
@@ -10,11 +10,12 @@ arma::mat mp::dist(const arma::mat &X, mp::DistFunc dfunc)
arma::uword n = X.n_rows;
arma::mat D(n, n, arma::fill::zeros);
- for (arma::uword i = 0; i < n; i++)
+ for (arma::uword i = 0; i < n; i++) {
for (arma::uword j = 0; j < i; j++) {
D(i, j) = dfunc(X.row(i), X.row(j));
D(j, i) = D(i, j);
}
+ }
return D;
}
diff --git a/forceScheme.cpp b/forceScheme.cpp
index 90bf6c0..22ab293 100644
--- a/forceScheme.cpp
+++ b/forceScheme.cpp
@@ -14,8 +14,9 @@ arma::mat mp::forceScheme(const arma::mat &D,
{
arma::uword n = Y.n_rows;
V i(n), j(n);
- for (arma::uword k = 0; k < n; k++)
+ for (arma::uword k = 0; k < n; k++) {
i[k] = j[k] = k;
+ }
double prevDeltaSum = 1. / 0.;
for (size_t iter = 0; iter < maxIter; iter++) {
@@ -25,8 +26,9 @@ arma::mat mp::forceScheme(const arma::mat &D,
for (V::iterator a = i.begin(); a != i.end(); a++) {
arma::shuffle(j);
for (V::iterator b = j.begin(); b != j.end(); b++) {
- if (*a == *b)
+ if (*a == *b) {
continue;
+ }
arma::rowvec direction(Y.row(*b) - Y.row(*a));
double d2 = std::max(arma::norm(direction, 2), EPSILON);
@@ -36,8 +38,9 @@ arma::mat mp::forceScheme(const arma::mat &D,
}
}
- if (fabs(prevDeltaSum - deltaSum) < tol)
+ if (fabs(prevDeltaSum - deltaSum) < tol) {
break;
+ }
prevDeltaSum = deltaSum;
}
diff --git a/main.cpp b/main.cpp
index 233d22b..692cfb8 100644
--- a/main.cpp
+++ b/main.cpp
@@ -25,10 +25,11 @@ int main(int argc, char **argv)
QQmlApplicationEngine engine(QUrl("qrc:///main_view.qml"));
arma::mat dataset;
- if (argc > 1)
+ if (argc > 1) {
dataset.load(argv[1], arma::raw_ascii);
- else
+ } else {
dataset.load(std::cin, arma::raw_ascii);
+ }
arma::mat X = dataset.cols(0, dataset.n_cols - 2);
arma::vec labels = dataset.col(dataset.n_cols - 1);
@@ -60,7 +61,7 @@ int main(int argc, char **argv)
QObject::connect(&distortionObs, SIGNAL(mapChanged(const arma::vec &)),
plot, SLOT(setColorData(const arma::vec &)));
- ContinuousColorScale colorScale;
+ ContinuousColorScale colorScale = ContinuousColorScale::builtin(ContinuousColorScale::RED_GRAY_BLUE);
colorScale.setExtents(-1, 1);
plot->setColorScale(&colorScale);
interactionHandler.setSubsample(Ys);
diff --git a/scatterplot.cpp b/scatterplot.cpp
index ce8f590..9fa68b6 100644
--- a/scatterplot.cpp
+++ b/scatterplot.cpp
@@ -49,8 +49,9 @@ void Scatterplot::setColorScale(ColorScale *colorScale)
void Scatterplot::setXY(const arma::mat &xy)
{
- if (xy.n_cols != 2)
+ if (xy.n_cols != 2) {
return;
+ }
m_xy = xy;
m_xmin = xy.col(0).min();
@@ -65,8 +66,9 @@ void Scatterplot::setXY(const arma::mat &xy)
void Scatterplot::setColorData(const arma::vec &colorData)
{
- if (colorData.n_elem != m_xy.n_rows)
+ if (colorData.n_elem != m_xy.n_rows) {
return;
+ }
m_colorData = colorData;
emit colorDataChanged(m_colorData);
@@ -169,8 +171,9 @@ QSGNode *Scatterplot::createGlyphNodeTree()
QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
{
- if (m_xy.n_rows < 1)
+ if (m_xy.n_rows < 1) {
return 0;
+ }
QMatrix4x4 matrix;
qreal tx, ty, moveTranslationF;
@@ -179,14 +182,16 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
if (!oldNode) {
root = new QSGNode;
root->appendChildNode(createGlyphNodeTree());
- } else
+ } else {
root = oldNode;
+ }
if (m_currentInteractionState == INTERACTION_MOVING) {
tx = m_dragCurrentPos.x() - m_dragOriginPos.x();
ty = m_dragCurrentPos.y() - m_dragOriginPos.y();
- } else
+ } else {
tx = ty = 0;
+ }
QSGNode *node = root->firstChild()->firstChild();
for (arma::uword i = 0; i < m_xy.n_rows; i++) {
@@ -214,10 +219,12 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
node = node->nextSibling();
}
- if (m_shouldUpdateGeometry)
+ if (m_shouldUpdateGeometry) {
m_shouldUpdateGeometry = false;
- if (m_shouldUpdateMaterials)
+ }
+ if (m_shouldUpdateMaterials) {
m_shouldUpdateMaterials = false;
+ }
// Draw selection
if (m_currentInteractionState == INTERACTION_SELECTING) {
@@ -233,9 +240,10 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
selectionNode->setRect(QRectF(m_dragOriginPos, m_dragCurrentPos));
selectionNode->markDirty(QSGNode::DirtyGeometry);
} else {
- if (root->firstChild()->nextSibling()) {
- root->firstChild()->nextSibling()->markDirty(QSGNode::DirtyGeometry);
- root->removeChildNode(root->firstChild()->nextSibling());
+ node = root->firstChild()->nextSibling();
+ if (node) {
+ node->markDirty(QSGNode::DirtyGeometry);
+ root->removeChildNode(node);
}
}
@@ -247,8 +255,11 @@ void Scatterplot::mousePressEvent(QMouseEvent *event)
switch (m_currentInteractionState) {
case INTERACTION_NONE:
case INTERACTION_SELECTED:
- m_currentInteractionState = (event->modifiers() == Qt::AltModifier) ? INTERACTION_MOVING
- : INTERACTION_SELECTING;
+ if (event->modifiers() == Qt::AltModifier) {
+ m_currentInteractionState = INTERACTION_MOVING;
+ } else {
+ INTERACTION_SELECTING;
+ }
m_dragOriginPos = event->localPos();
m_dragCurrentPos = m_dragOriginPos;
break;
@@ -281,13 +292,14 @@ void Scatterplot::mouseMoveEvent(QMouseEvent *event)
void Scatterplot::mouseReleaseEvent(QMouseEvent *event)
{
- bool mergeSelection;
-
switch (m_currentInteractionState) {
case INTERACTION_SELECTING:
- mergeSelection = (event->modifiers() == Qt::ControlModifier);
- m_currentInteractionState = selectGlyphs(mergeSelection) ? INTERACTION_SELECTED
- : INTERACTION_NONE;
+ bool mergeSelection = (event->modifiers() == Qt::ControlModifier);
+ if (selectGlyphs(mergeSelection)) {
+ m_currentInteractionState = INTERACTION_SELECTED;
+ else {
+ m_currentInteractionState = INTERACTION_NONE;
+ }
update();
break;
diff --git a/tsne.cpp b/tsne.cpp
index 50022eb..9ef1f9f 100644
--- a/tsne.cpp
+++ b/tsne.cpp
@@ -68,8 +68,9 @@ void mp::tSNE(const arma::mat &X, arma::mat &Y, double perplexity, arma::uword n
Y += iY;
Y.each_row() -= mean(Y, 0);
- if (iter == EXAGGERATION_THRESHOLD_ITER)
+ if (iter == EXAGGERATION_THRESHOLD_ITER) {
P /= EARLY_EXAGGERATION; // remove early exaggeration
+ }
}
}
@@ -94,19 +95,21 @@ static void calcP(const arma::mat &X, arma::mat &P, double perplexity, double to
for (int tries = 0; fabs(hDiff) > tol && tries < MAX_BINSEARCH_TRIES; tries++) {
if (hDiff > 0) {
betaMin = beta[i];
- if (betaMax == arma::datum::inf || betaMax == -arma::datum::inf)
+ if (betaMax == arma::datum::inf || betaMax == -arma::datum::inf) {
beta[i] *= 2;
- else
+ } else {
beta[i] = (beta[i] + betaMax) / 2.;
+ }
} else {
betaMax = beta[i];
- if (betaMin == arma::datum::inf || betaMin == -arma::datum::inf)
+ if (betaMin == arma::datum::inf || betaMin == -arma::datum::inf) {
beta[i] /= 2;
- else
+ } else {
beta[i] = (beta[i] + betaMin) / 2.;
+ }
}
-
+
h = hBeta(Di, beta[i], Pi);
hDiff = h - logU;
}