Create extendable coloring for interactions.
This commit is contained in:
@@ -9,8 +9,26 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace fmri;
|
using namespace fmri;
|
||||||
|
|
||||||
ActivityAnimation::ActivityAnimation(const vector<pair<DType, pair<size_t, size_t>>> &interactions,
|
ActivityAnimation::Color ActivityAnimation::colorBySign(float intensity)
|
||||||
const float *aPositions, const float *bPositions, float xDist) :
|
{
|
||||||
|
if (intensity > 0) {
|
||||||
|
return {0, 1, 0};
|
||||||
|
} else {
|
||||||
|
return {1, 0, 0};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ActivityAnimation::ActivityAnimation(
|
||||||
|
const std::vector<std::pair<DType, std::pair<std::size_t, std::size_t>>> &interactions, const float *aPositions,
|
||||||
|
const float *bPositions, float xDist) :
|
||||||
|
ActivityAnimation(interactions, aPositions, bPositions, xDist, ActivityAnimation::colorBySign)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ActivityAnimation::ActivityAnimation(
|
||||||
|
const std::vector<std::pair<DType, std::pair<std::size_t, std::size_t>>> &interactions,
|
||||||
|
const float *aPositions, const float *bPositions, float xDist, ColoringFunction coloring)
|
||||||
|
:
|
||||||
bufferLength(3 * interactions.size())
|
bufferLength(3 * interactions.size())
|
||||||
{
|
{
|
||||||
startingPos.reserve(bufferLength);
|
startingPos.reserve(bufferLength);
|
||||||
@@ -21,13 +39,7 @@ ActivityAnimation::ActivityAnimation(const vector<pair<DType, pair<size_t, size_
|
|||||||
auto *aPos = &aPositions[3 * entry.second.first];
|
auto *aPos = &aPositions[3 * entry.second.first];
|
||||||
auto *bPos = &bPositions[3 * entry.second.second];
|
auto *bPos = &bPositions[3 * entry.second.second];
|
||||||
|
|
||||||
array<float, 3> color;
|
colorBuf.push_back(coloring(entry.first));
|
||||||
if (entry.first > 0) {
|
|
||||||
color = {0, 1, 0};
|
|
||||||
} else {
|
|
||||||
color = {1, 0, 0};
|
|
||||||
}
|
|
||||||
colorBuf.push_back(color);
|
|
||||||
|
|
||||||
for (auto i : Range(3)) {
|
for (auto i : Range(3)) {
|
||||||
startingPos.emplace_back(aPos[i]);
|
startingPos.emplace_back(aPos[i]);
|
||||||
|
|||||||
@@ -12,14 +12,21 @@ namespace fmri
|
|||||||
: public Animation
|
: public Animation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef std::array<float, 3> Color;
|
||||||
|
typedef std::function<Color(float)> ColoringFunction;
|
||||||
|
|
||||||
ActivityAnimation(const std::vector<std::pair<DType, std::pair<std::size_t, std::size_t>>> &interactions,
|
ActivityAnimation(const std::vector<std::pair<DType, std::pair<std::size_t, std::size_t>>> &interactions,
|
||||||
const float *aPositions, const float *bPositions, float xDist);
|
const float *aPositions, const float *bPositions, float xDist);
|
||||||
|
ActivityAnimation(const std::vector<std::pair<DType, std::pair<std::size_t, std::size_t>>> &interactions,
|
||||||
|
const float *aPositions, const float *bPositions, float xDist, ColoringFunction coloring);
|
||||||
void draw(float timeScale) override;
|
void draw(float timeScale) override;
|
||||||
|
|
||||||
|
static Color colorBySign(float intensity);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::size_t bufferLength;
|
std::size_t bufferLength;
|
||||||
std::vector<std::array<float, 3>> colorBuf;
|
std::vector<std::array<float, 3>> colorBuf;
|
||||||
std::vector<float> startingPos;
|
std::vector<float> startingPos;
|
||||||
std::vector<float> delta;
|
std::vector<float> delta;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user