diff --git a/DRAMSys/traceAnalyzer/CMakeLists.txt b/DRAMSys/traceAnalyzer/CMakeLists.txt index 3ce4cceb..74b5e4c9 100644 --- a/DRAMSys/traceAnalyzer/CMakeLists.txt +++ b/DRAMSys/traceAnalyzer/CMakeLists.txt @@ -76,6 +76,7 @@ add_executable(TraceAnalyzer data/tracedb.cpp presentation/tracenavigator.cpp presentation/util/colorgenerator.cpp + presentation/util/colorobject.cpp presentation/tracedrawing.cpp presentation/traceplotitem.cpp gototimedialog.cpp diff --git a/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp b/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp index 463fde5c..5ee4e694 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp @@ -177,16 +177,20 @@ void Phase::drawPhaseDependencies(traceTime begin, traceTime end, double y, QColor Phase::getColor(const TraceDrawingProperties &drawingProperties) const { - switch (drawingProperties.colorGrouping) - { - case ColorGrouping::PhaseType: - return getPhaseColor(); - case ColorGrouping::Thread: - return ColorGenerator::getColor(static_cast(transaction.lock()->thread)); - case ColorGrouping::AlphaTransaction: - return ColorGenerator::getAlphaColored(transaction.lock()->id); - case ColorGrouping::Transaction: default: - return ColorGenerator::getColor(transaction.lock()->id); + switch (drawingProperties.colorGrouping) { + case ColorGrouping::PhaseType: + return getPhaseColor(); + break; + case ColorGrouping::Thread: + return ColorGenerator::getColor(static_cast(transaction.lock()->thread)); + break; + case ColorGrouping::AlphaTransaction: + return ColorGenerator::getAlphaColored(transaction.lock()->id, ColorName::HSV15); + + break; + case ColorGrouping::Transaction: + default: + return ColorGenerator::getColor(transaction.lock()->id); } } diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.cpp b/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.cpp index ae3070a6..11cf1023 100644 --- a/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.cpp +++ b/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.cpp @@ -38,79 +38,30 @@ #include "colorgenerator.h" #include -ColorGenerator::ColorGenerator() + +QColor ColorGenerator::getColor(unsigned int i, ColorName color) { - r[0] = 0xFF; - r[1] = 0x00; - r[2] = 0x00; - r[3] = 0xFF; - g[0] = 0x00; - g[1] = 0xFF; - g[2] = 0x00; - g[3] = 0xFF; - b[0] = 0x00; - b[1] = 0x00; - b[2] = 0xFF; - b[3] = 0x00; - - r[4] = 0xFF; - r[5] = 0x00; - r[6] = 0xFF; - r[7] = 0x6B; - g[4] = 0x00; - g[5] = 0xFF; - g[6] = 0xA5; - g[7] = 0x8E; - b[4] = 0xFF; - b[5] = 0xFF; - b[6] = 0x00; - b[7] = 0x23; - - r[8] = 0x8A; - r[9] = 0xFF; - r[10] = 0x7C; - r[11] = 0x00; - g[8] = 0x2B; - g[9] = 0xD7; - g[10] = 0xFC; - g[11] = 0x00; - b[8] = 0xE2; - b[9] = 0x00; - b[10] = 0x00; - b[11] = 0x80; - - r[12] = 0x80; - r[13] = 0x00; - r[14] = 0xEE; - r[15] = 0xFF; - g[12] = 0x00; - g[13] = 0x80; - g[14] = 0x82; - g[15] = 0x45; - b[12] = 0x00; - b[13] = 0x00; - b[14] = 0xEE; - b[15] = 0x00; + switch(color) { + case ColorName::Default: + return cDefault.getColor(i); + case ColorName::HSV15: + return cHSV15.getColor(i); + } + return {0, 0, 0}; } -QColor ColorGenerator::getColor(unsigned int i) +QColor ColorGenerator::getAlphaColored(unsigned int i, ColorName color) { - static ColorGenerator gen; - i = i % 16; - QColor result(gen.r[i], gen.g[i], gen.b[i]); - result.setAlpha(130); - return result; + switch(color) { + case ColorName::Default: + return cDefault.getAlphaColored(i); + case ColorName::HSV15: + return cHSV15.getAlphaColored(i); + } + + return {0, 0, 0}; } -QColor ColorGenerator::getAlphaColored(unsigned int i) -{ - static ColorGenerator gen; - const int minAlpha = 25; - const int alphaLevels = 40 - 255 / minAlpha; - int alpha = minAlpha + (int)(((255. - minAlpha) / alphaLevels) * (i % alphaLevels)); - i = (i / alphaLevels) % 16; - QColor result(gen.r[i], gen.g[i], gen.b[i]); - result.setAlpha(alpha); - return result; -} +ColorDefault ColorGenerator::cDefault; +ColorHSV15 ColorGenerator::cHSV15; diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.h b/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.h index 35941474..7897393d 100644 --- a/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.h +++ b/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.h @@ -39,21 +39,28 @@ #ifndef COLORGENERATOR_H #define COLORGENERATOR_H +#include "colorobject.h" + #include #include +enum ColorName +{ + Default, + HSV15 +}; + class ColorGenerator { private: - static constexpr int NumberOfColors = 16; - int r[NumberOfColors]; - int g[NumberOfColors]; - int b[NumberOfColors]; - ColorGenerator(); + ColorGenerator() = delete; + + static ColorDefault cDefault; + static ColorHSV15 cHSV15; public: - static QColor getColor(unsigned int i); - static QColor getAlphaColored(unsigned int i); + static QColor getColor(unsigned int i, ColorName color = ColorName::Default); + static QColor getAlphaColored(unsigned int i, ColorName color = ColorName::Default); }; diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp b/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp new file mode 100644 index 00000000..9f708e98 --- /dev/null +++ b/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2015, Technische Universität Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Janik Schlemminger + * Robert Gernhardt + * Matthias Jung + * Iron Prando da Silva + */ + +#include "colorobject.h" + + +QColor ColorObject::getColor(unsigned int i) +{ + i = i % numberOfColors; + QColor result(r[i], g[i], b[i]); + result.setAlpha(130); + return result; +} + +QColor ColorObject::getAlphaColored(unsigned int i) +{ + const int minAlpha = 50; + const int alphaLevels = 20 - 255 / minAlpha; + + int alpha = minAlpha + (int)(((255. - minAlpha) / alphaLevels) * (i % alphaLevels)); + i = (i / alphaLevels) % numberOfColors; + QColor result(r[i], g[i], b[i]); + result.setAlpha(alpha); + + return result; +} + +ColorDefault::ColorDefault() +{ + numberOfColors = 16; + + r.resize(numberOfColors); + g.resize(numberOfColors); + b.resize(numberOfColors); + + r[0] = 0xFF; + r[1] = 0x00; + r[2] = 0x00; + r[3] = 0xFF; + g[0] = 0x00; + g[1] = 0xFF; + g[2] = 0x00; + g[3] = 0xFF; + b[0] = 0x00; + b[1] = 0x00; + b[2] = 0xFF; + b[3] = 0x00; + + r[4] = 0xFF; + r[5] = 0x00; + r[6] = 0xFF; + r[7] = 0x6B; + g[4] = 0x00; + g[5] = 0xFF; + g[6] = 0xA5; + g[7] = 0x8E; + b[4] = 0xFF; + b[5] = 0xFF; + b[6] = 0x00; + b[7] = 0x23; + + r[8] = 0x8A; + r[9] = 0xFF; + r[10] = 0x7C; + r[11] = 0x00; + g[8] = 0x2B; + g[9] = 0xD7; + g[10] = 0xFC; + g[11] = 0x00; + b[8] = 0xE2; + b[9] = 0x00; + b[10] = 0x00; + b[11] = 0x80; + + r[12] = 0x80; + r[13] = 0x00; + r[14] = 0xEE; + r[15] = 0xFF; + g[12] = 0x00; + g[13] = 0x80; + g[14] = 0x82; + g[15] = 0x45; + b[12] = 0x00; + b[13] = 0x00; + b[14] = 0xEE; + b[15] = 0x00; +} + +ColorHSV15::ColorHSV15() +{ + numberOfColors = 15; + + r.resize(numberOfColors); + g.resize(numberOfColors); + b.resize(numberOfColors); + + r[0] = 0XFF; + r[1] = 0XFF; + r[2] = 0XFF; + r[3] = 0XD1; + r[4] = 0X6C; + r[5] = 0X08; + r[6] = 0X00; + r[7] = 0X00; + r[8] = 0X00; + r[9] = 0X00; + r[10] = 0X00; + r[11] = 0X54; + r[12] = 0XB9; + r[13] = 0XFF; + r[14] = 0XFF; + + g[0] = 0X00; + g[1] = 0X64; + g[2] = 0XC9; + g[3] = 0XFF; + g[4] = 0XFF; + g[5] = 0XFF; + g[6] = 0XFF; + g[7] = 0XFF; + g[8] = 0XD9; + g[9] = 0X74; + g[10] = 0X10; + g[11] = 0X00; + g[12] = 0X00; + g[13] = 0X00; + g[14] = 0X00; + + b[0] = 0X00; + b[1] = 0X00; + b[2] = 0X00; + b[3] = 0X00; + b[4] = 0X00; + b[5] = 0X00; + b[6] = 0X5C; + b[7] = 0XC1; + b[8] = 0XFF; + b[9] = 0XFF; + b[10] = 0XFF; + b[11] = 0XFF; + b[12] = 0XFF; + b[13] = 0XE1; + b[14] = 0X7C; +} diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorobject.h b/DRAMSys/traceAnalyzer/presentation/util/colorobject.h new file mode 100644 index 00000000..f54ee8f4 --- /dev/null +++ b/DRAMSys/traceAnalyzer/presentation/util/colorobject.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2015, Technische Universität Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Janik Schlemminger + * Robert Gernhardt + * Matthias Jung + * Iron Prando da Silva + */ + +#pragma once + +#include + +class ColorObject +{ +protected: + int numberOfColors = 0; + + std::vector r; + std::vector g; + std::vector b; + // std::vector a; + + ColorObject() {}; + +public: + + virtual QColor getColor(unsigned int i); + virtual QColor getAlphaColored(unsigned int i); +}; + +class ColorDefault : public ColorObject +{ +public: + ColorDefault(); +}; + +class ColorHSV15 : public ColorObject +{ +public: + ColorHSV15(); +};