From 4c066a82962a9a0634dcfe0a305de7b2a4cacc5b Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Sat, 16 Jan 2016 20:55:45 +0100 Subject: Added the Colormap component. * The Colormap component is a simple rect with a texture mapped that displays a ColorScale with a fixed number of samples. This number of samples is exported as a member const, which is used on other components (such as VoronoiSplat). * The texture mapping is reflecting the colormap lookup used in VoronoiSplat. * The ColorScale class now has a method for sampling the color scale and outputs the samples to iterator-style objects, providing easy intergration with existing code. --- main.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 4d43c4c..b79f6ff 100644 --- a/main.cpp +++ b/main.cpp @@ -15,6 +15,7 @@ #include "voronoisplat.h" #include "historygraph.h" #include "barchart.h" +#include "colormap.h" #include "interactionhandler.h" #include "selectionhandler.h" #include "skelft.h" @@ -97,6 +98,7 @@ int main(int argc, char **argv) qmlRegisterType("PM", 1, 0, "HistoryGraph"); qmlRegisterType("PM", 1, 0, "BarChart"); qmlRegisterType("PM", 1, 0, "VoronoiSplat"); + qmlRegisterType("PM", 1, 0, "Colormap"); qmlRegisterType("PM", 1, 0, "InteractionHandler"); qmlRegisterSingletonType
("PM", 1, 0, "Main", mainProvider); @@ -113,21 +115,22 @@ int main(int argc, char **argv) QQmlApplicationEngine engine(QUrl("qrc:///main_view.qml")); - //ColorScale colorScale{ - // QColor("#1f77b4"), - // QColor("#ff7f0e"), - // QColor("#2ca02c"), - // QColor("#d62728"), - // QColor("#9467bd"), - // QColor("#8c564b"), - // QColor("#e377c2"), - // QColor("#17becf"), - // QColor("#7f7f7f"), - //}; + ColorScale colorScale{ + QColor("#1f77b4"), + QColor("#ff7f0e"), + QColor("#2ca02c"), + QColor("#d62728"), + QColor("#9467bd"), + QColor("#8c564b"), + QColor("#e377c2"), + QColor("#17becf"), + QColor("#7f7f7f"), + }; + colorScale.setExtents(labels.min(), labels.max()); + + //ContinuousColorScale colorScale = ContinuousColorScale::builtin(ContinuousColorScale::RED_GRAY_BLUE); //colorScale.setExtents(labels.min(), labels.max()); - ContinuousColorScale colorScale = ContinuousColorScale::builtin(ContinuousColorScale::RED_GRAY_BLUE); - colorScale.setExtents(labels.min(), labels.max()); Scatterplot *cpPlot = engine.rootObjects()[0]->findChild("cpPlot"); cpPlot->setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton); // cpPlot->setColorData(arma::zeros(cpSize)); @@ -135,6 +138,7 @@ int main(int argc, char **argv) Scatterplot *plot = engine.rootObjects()[0]->findChild("plot"); VoronoiSplat *splat = engine.rootObjects()[0]->findChild("splat"); skelft2DInitialization(splat->width()); + Colormap *colormap = engine.rootObjects()[0]->findChild("colormap"); // Keep track of the current cp (in order to save them later, if requested) QObject::connect(cpPlot, SIGNAL(xyChanged(const arma::mat &)), @@ -176,10 +180,11 @@ int main(int argc, char **argv) barChart->setValues(arma::randn(100)); //history->addHistoryItem(Ys); + colormap->setColorScale(colorScale); plot->setColorScale(&colorScale); plot->setColorData(labels, false); + //splat->setColormap(colorScale); splat->setValues(labels); - splat->update(); cpPlot->setAutoScale(false); cpPlot->setColorData(labels(cpIndices), false); -- cgit v1.2.3