Skip to content

Commit d876c79

Browse files
committed
Merge branch 'master' into modules_Q
2 parents 042372b + fb54072 commit d876c79

File tree

15 files changed

+462
-121
lines changed

15 files changed

+462
-121
lines changed

src/Core/Datatypes/Color.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,12 @@ ColorRGB::ColorRGB(const std::string& rgb) : r_(1.0), g_(1.0), b_(1.0)
4949
{
5050
try
5151
{
52-
static boost::regex r("Color\\((\\d+),(\\d+),(\\d+)\\)");
52+
static boost::regex r("Color\\((.+),(.+),(.+)\\)");
5353
boost::smatch what;
5454
regex_match(rgb, what, r);
55-
int red = boost::lexical_cast<int>(what[1]);
56-
int green = boost::lexical_cast<int>(what[2]);
57-
int blue = boost::lexical_cast<int>(what[3]);
58-
59-
r_ = static_cast<double>(red) / 255.0f;
60-
g_ = static_cast<double>(green) / 255.0f;
61-
b_ = static_cast<double>(blue) / 255.0f;
55+
r_ = boost::lexical_cast<double>(what[1]);
56+
g_ = boost::lexical_cast<double>(what[2]);
57+
b_ = boost::lexical_cast<double>(what[3]);
6258
}
6359
catch (...)
6460
{

src/Core/Datatypes/Color.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Copyright (c) 2012 Scientific Computing and Imaging Institute,
77
University of Utah.
88
9-
9+
1010
Permission is hereby granted, free of charge, to any person obtaining a
1111
copy of this software and associated documentation files (the "Software"),
1212
to deal in the Software without restriction, including without limitation
@@ -26,10 +26,10 @@
2626
DEALINGS IN THE SOFTWARE.
2727
*/
2828

29-
/// @todo Documentation Core/Datatypes/Color.h
29+
/// @todo Documentation Core/Datatypes/Color.h
3030

3131
#ifndef CORE_DATATYPES_COLORRGB_H
32-
#define CORE_DATATYPES_COLORRGB_H
32+
#define CORE_DATATYPES_COLORRGB_H
3333

3434
#include <iosfwd>
3535
#include <Core/Datatypes/Datatype.h>
@@ -39,14 +39,14 @@ namespace SCIRun {
3939
namespace Core {
4040
namespace Datatypes {
4141

42-
class SCISHARE ColorRGB
42+
class SCISHARE ColorRGB
4343
{
4444
private:
4545
double r_, g_, b_;
4646
public:
4747
ColorRGB();
4848
explicit ColorRGB(const std::string& rgb);
49-
ColorRGB(double, double, double);
49+
ColorRGB(double r, double g, double b);
5050

5151
// These equality operations should use floating point comparisons.
5252
inline bool operator==(const ColorRGB& c) const {

src/Core/Datatypes/ColorMap.cc

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@
3131

3232
using namespace SCIRun::Core::Datatypes;
3333

34-
ColorMap::ColorMap(const std::string& name) : name_(name)
35-
{
36-
37-
}
34+
ColorMap::ColorMap(const std::string& name, const size_t resolution, const double shift)
35+
: name_(name), resolution_(resolution), shift_(shift) {}
3836

3937
ColorMap* ColorMap::clone() const
4038
{
@@ -45,13 +43,62 @@ ColorMapHandle StandardColorMapFactory::create(const std::string& name)
4543
{
4644
if (name == "Rainbow")
4745
return ColorMapHandle(rainbow_.clone());
48-
if (name == "Gray")
46+
if (name == "Grayscale")
4947
return ColorMapHandle(grayscale_.clone());
5048
if (name == "Blackbody")
5149
return ColorMapHandle(blackbody_.clone());
5250
THROW_INVALID_ARGUMENT("Unknown standard colormap name: " + name);
5351
}
5452

53+
float ColorMap::Hue_2_RGB(float v1, float v2, float vH) {
54+
if ( vH < 0 ) vH += 1.;
55+
if ( vH > 1 ) vH -= 1.;
56+
if ( ( 6 * vH ) < 1 ) return ( v1 + ( v2 - v1 ) * 6. * vH );
57+
if ( ( 2 * vH ) < 1 ) return ( v2 );
58+
if ( ( 3 * vH ) < 2 ) return ( v1 + ( v2 - v1 ) * ( ( .666667 ) - vH ) * 6. );
59+
return ( v1 );
60+
}
61+
62+
ColorRGB ColorMap::hslToRGB(float h, float s, float l) {
63+
float r,g,b;
64+
if ( s == 0. ) {
65+
r = g = b = l ;
66+
} else {
67+
float var_1, var_2;
68+
if ( l < 0.5 ) var_2 = l * ( 1. + s );
69+
else var_2 = ( l + s ) - ( s * l );
70+
71+
var_1 = 2 * l - var_2;
72+
73+
r = Hue_2_RGB( var_1, var_2, h + ( .333333 ) );
74+
g = Hue_2_RGB( var_1, var_2, h );
75+
b = Hue_2_RGB( var_1, var_2, h - ( .333333 ) );
76+
}
77+
return ColorRGB(r,g,b);
78+
}
79+
80+
ColorRGB ColorMap::getColorMapVal(float v) {
81+
//@todo this will not be needed with rescale color map.
82+
v = std::min(std::max(0.f,v),1.f);
83+
float shift = (static_cast<float>(shift_)+1.f)/2.f;
84+
v = (v + shift) / (shift + 0.5f);
85+
//apply the resolution
86+
v = static_cast<double>((static_cast<int>(v * static_cast<float>(resolution_)))) / static_cast<double>(resolution_ - 1);
87+
ColorRGB col;
88+
if (name_ == "Rainbow")
89+
col = hslToRGB((1.0-v) * 0.8, 0.95, 0.5);
90+
else if (name_ == "Blackbody") {
91+
if (v < 0.333333)
92+
col = ColorRGB(v * 3., 0., 0.);
93+
else if (v < 0.6666667)
94+
col = ColorRGB(1.,(v - 0.333333) * 3., 0.);
95+
else
96+
col = ColorRGB(1., 1., (v - 0.6666667) * 3.);
97+
} else if (name_ == "Grayscale")
98+
col = hslToRGB(0., 0., v);
99+
return col;
100+
}
101+
55102
ColorMap StandardColorMapFactory::rainbow_("Rainbow");
56103
ColorMap StandardColorMapFactory::grayscale_("Grayscale");
57104
ColorMap StandardColorMapFactory::blackbody_("Blackbody");

src/Core/Datatypes/ColorMap.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <Core/Datatypes/Datatype.h>
3333
#include <boost/noncopyable.hpp>
34+
#include <Core/Datatypes/Color.h>
3435
#include <Core/Datatypes/share.h>
3536

3637
namespace SCIRun {
@@ -40,14 +41,19 @@ namespace Datatypes {
4041
class SCISHARE ColorMap : public Datatype
4142
{
4243
public:
43-
explicit ColorMap(const std::string& name);
44+
explicit ColorMap(const std::string& name, const size_t resolution = 256, const double shift = 0.0);
4445

4546
virtual ColorMap* clone() const;
4647

4748
std::string getColorMapName() const {return name_;}
49+
Core::Datatypes::ColorRGB getColorMapVal(float v);
4850
private:
4951
std::string name_;
52+
size_t resolution_;
53+
double shift_;
5054
boost::shared_ptr<class ColorMapImpl> impl_;
55+
float Hue_2_RGB(float v1, float v2, float vH);
56+
Core::Datatypes::ColorRGB hslToRGB(float h, float s, float l);
5157
};
5258

5359
class SCISHARE StandardColorMapFactory : boost::noncopyable

src/Core/Datatypes/Geometry.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Copyright (c) 2012 Scientific Computing and Imaging Institute,
77
University of Utah.
88
9-
9+
1010
Permission is hereby granted, free of charge, to any person obtaining a
1111
copy of this software and associated documentation files (the "Software"),
1212
to deal in the Software without restriction, including without limitation
@@ -28,7 +28,7 @@
2828
/// @todo Documentation Core/Datatypes/Geometry.h
2929

3030
#ifndef CORE_DATATYPES_GEOMETRY_H
31-
#define CORE_DATATYPES_GEOMETRY_H
31+
#define CORE_DATATYPES_GEOMETRY_H
3232

3333
#include <cstdint>
3434
#include <list>
@@ -79,7 +79,7 @@ namespace Datatypes {
7979
DatatypeConstHandle get_underlying() const;
8080
virtual GeometryObject* clone() const { return new GeometryObject(*this); }
8181

82-
std::string objectName; ///< Name of this object. Should be unique
82+
std::string objectName; ///< Name of this object. Should be unique
8383
///< across all modules in the network.
8484

8585
// Could require rvalue references...
@@ -149,7 +149,7 @@ namespace Datatypes {
149149
struct SpireSubPass
150150
{
151151
SpireSubPass() {}
152-
SpireSubPass(const std::string& name, const std::string& vboName,
152+
SpireSubPass(const std::string& name, const std::string& vboName,
153153
const std::string& iboName, const std::string& program,
154154
ColorScheme scheme, const RenderState& state,
155155
RenderType renType, const SpireVBO& vbo, const SpireIBO& ibo) :
@@ -161,8 +161,8 @@ namespace Datatypes {
161161
renderType(renType),
162162
vbo(vbo),
163163
ibo(ibo),
164-
mColorScheme(scheme),
165-
scalar(1.0)
164+
scalar(1.0),
165+
mColorScheme(scheme)
166166
{}
167167

168168
static const char* getName() { return "SpireSubPass"; }

src/Core/Datatypes/Tests/ScalarTests.cc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,27 @@ using ::testing::DefaultValue;
3636
using ::testing::Return;
3737
using namespace SCIRun::Core::Datatypes;
3838

39-
/// @todo DAN
40-
/// Re-enable tests below to take into account floating point colors.
41-
4239
TEST(ColorTests, CanParseString)
4340
{
44-
// ColorRGB c(1.0,2.0,3.0);
45-
// const std::string expected = "Color(1,2,3)";
46-
// EXPECT_EQ(expected, c.toString());
47-
// ColorRGB c2(expected);
48-
// EXPECT_EQ(c, c2);
41+
ColorRGB c(1.0,2.0,3.0);
42+
const std::string expected = "Color(1,2,3)";
43+
EXPECT_EQ(expected, c.toString());
44+
ColorRGB c2(expected);
45+
EXPECT_EQ(c, c2);
46+
}
47+
48+
TEST(ColorTests, CanParseStringFloating)
49+
{
50+
ColorRGB c(1.3,2.9,3.00014);
51+
const std::string expected = "Color(1.3,2.9,3.00014)";
52+
EXPECT_EQ(expected, c.toString());
53+
ColorRGB c2(expected);
54+
EXPECT_EQ(c, c2);
4955
}
5056

5157
TEST(ColorTests, EmptyStringYieldsWhite)
5258
{
53-
// ColorRGB c(255.0,255.0,255.0);
54-
// ColorRGB c2("");
55-
// EXPECT_EQ(c, c2);
59+
ColorRGB c(1.0,1.0,1.0);
60+
ColorRGB c2("");
61+
EXPECT_EQ(c, c2);
5662
}

src/Interface/Modules/Base/ModuleDialogGeneric.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,36 @@ void ModuleDialogGeneric::addDynamicLabelManager(QLabel* label, const AlgorithmP
582582
{
583583
addWidgetSlotManager(boost::make_shared<DynamicLabelSlotManager>(state_, *this, stateKey, label));
584584
}
585+
/*
586+
class SliderSlotManager : public WidgetSlotManager
587+
{
588+
public:
589+
SliderSlotManager(ModuleStateHandle state, ModuleDialogGeneric& dialog, const AlgorithmParameterName& stateKey, QSlider* slider) :
590+
WidgetSlotManager(state, dialog), stateKey_(stateKey), slider_(slider)
591+
{
592+
}
593+
virtual void pull() override
594+
{
595+
auto newValue = state_->getValue(stateKey_).toInt();
596+
if (newValue != slider_->value())
597+
{
598+
LOG_DEBUG("In new version of pull code for QSlider: " << newValue);
599+
slider_->setValue(newValue);
600+
}
601+
}
602+
virtual void pushImpl() override
603+
{
604+
}
605+
private:
606+
AlgorithmParameterName stateKey_;
607+
QSlider* slider_;
608+
};
585609
610+
void ModuleDialogGeneric::addSliderManager(QSlider* slider, const AlgorithmParameterName& stateKey)
611+
{
612+
addWidgetSlotManager(boost::make_shared<DynamicLabelSlotManager>(state_, *this, stateKey, slider));
613+
}
614+
*/
586615
class RadioButtonGroupSlotManager : public WidgetSlotManager
587616
{
588617
public:

src/Interface/Modules/Base/ModuleDialogGeneric.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ namespace Gui {
112112
void addTwoChoiceBooleanComboBoxManager(QComboBox* comboBox, const Core::Algorithms::AlgorithmParameterName& stateKey);
113113
void addDynamicLabelManager(QLabel* label, const Core::Algorithms::AlgorithmParameterName& stateKey);
114114
void addRadioButtonGroupManager(std::initializer_list<QRadioButton*> radioButtons, const Core::Algorithms::AlgorithmParameterName& stateKey);
115+
//void addSliderManager(QSlider* slider, const Core::Algorithms::AlgorithmParameterName& stateKey);
115116
private:
116117
void addWidgetSlotManager(WidgetSlotManagerPtr ptr);
117118
void createExecuteAction();

src/Interface/Modules/Render/ES/SRInterface.cc

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ DEALINGS IN THE SOFTWARE.
7171
#include "systems/RenderColorMapSys.h"
7272
#include "systems/RenderTransBasicSys.h"
7373
#include "systems/RenderTransColorMapSys.h"
74+
#include <Core/Datatypes/ColorMap.h>
75+
76+
using namespace SCIRun::Core::Datatypes;
7477

7578
using namespace std::placeholders;
7679

@@ -913,60 +916,16 @@ namespace SCIRun {
913916
}
914917
}
915918

916-
float SRInterface::Hue_2_RGB(float v1, float v2, float vH) {
917-
if ( vH < 0 ) vH += 1.;
918-
if ( vH > 1 ) vH -= 1.;
919-
if ( ( 6 * vH ) < 1 ) return ( v1 + ( v2 - v1 ) * 6. * vH );
920-
if ( ( 2 * vH ) < 1 ) return ( v2 );
921-
if ( ( 3 * vH ) < 2 ) return ( v1 + ( v2 - v1 ) * ( ( .666667 ) - vH ) * 6. );
922-
return ( v1 );
923-
}
924-
925-
Core::Datatypes::ColorRGB SRInterface::hslToRGB(float h, float s, float l) {
926-
float r,g,b;
927-
if ( s == 0. ) {
928-
r = g = b = l ;
929-
} else {
930-
float var_1, var_2;
931-
if ( l < 0.5 ) var_2 = l * ( 1. + s );
932-
else var_2 = ( l + s ) - ( s * l );
933-
934-
var_1 = 2 * l - var_2;
935-
936-
r = Hue_2_RGB( var_1, var_2, h + ( .333333 ) );
937-
g = Hue_2_RGB( var_1, var_2, h );
938-
b = Hue_2_RGB( var_1, var_2, h - ( .333333 ) );
939-
}
940-
return Core::Datatypes::ColorRGB(r,g,b);
941-
}
942-
943-
Core::Datatypes::ColorRGB SRInterface::getColorMapVal(float v, std::string which) {
944-
Core::Datatypes::ColorRGB col;
945-
std::string str = which;
946-
if (str == "Rainbow")
947-
col = hslToRGB((1.0-v) * 0.8, 0.95, 0.5);
948-
else if (str == "Blackbody") {
949-
if (v < 0.333333)
950-
col = Core::Datatypes::ColorRGB(v * 3., 0., 0.);
951-
else if (v < 0.6666667)
952-
col = Core::Datatypes::ColorRGB(1.,(v - 0.333333) * 3., 0.);
953-
else
954-
col = Core::Datatypes::ColorRGB(1., 1., (v - 0.6666667) * 3.);
955-
} else if (str == "Grayscale")
956-
col = hslToRGB(0., 0., v);
957-
return col;
958-
}
959-
960919
// Create default colormaps.
961920
void SRInterface::generateColormaps()
962921
{
963922
size_t resolution = 1000;
964923
float step = 1.f / static_cast<float>(resolution);
965-
924+
ColorMap cm("Rainbow");
966925
std::vector<uint8_t> rainbow;
967926
rainbow.reserve(resolution * 3);
968927
for (float i = 0.f; i < 1.f; i+=step) {
969-
Core::Datatypes::ColorRGB col = getColorMapVal(i, "Rainbow");
928+
ColorRGB col = cm.getColorMapVal(i);
970929
rainbow.push_back(static_cast<uint8_t>(col.r() * 255.0f));
971930
rainbow.push_back(static_cast<uint8_t>(col.g() * 255.0f));
972931
rainbow.push_back(static_cast<uint8_t>(col.b() * 255.0f));
@@ -987,11 +946,12 @@ Core::Datatypes::ColorRGB SRInterface::getColorMapVal(float v, std::string which
987946
GL_RGBA,
988947
GL_UNSIGNED_BYTE, &rainbow[0]));
989948

949+
cm = ColorMap("Grayscale");
990950
// build grayscale texture.
991951
std::vector<uint8_t> grayscale;
992952
grayscale.reserve(resolution * 3);
993953
for (float i = 0.f; i < 1.f; i+=step) {
994-
Core::Datatypes::ColorRGB col = getColorMapVal(i, "Grayscale");
954+
ColorRGB col = cm.getColorMapVal(i);
995955
grayscale.push_back(static_cast<uint8_t>(col.r() * 255.0f));
996956
grayscale.push_back(static_cast<uint8_t>(col.g() * 255.0f));
997957
grayscale.push_back(static_cast<uint8_t>(col.b() * 255.0f));
@@ -1012,11 +972,12 @@ Core::Datatypes::ColorRGB SRInterface::getColorMapVal(float v, std::string which
1012972
GL_RGBA,
1013973
GL_UNSIGNED_BYTE, &grayscale[0]));
1014974

975+
cm = ColorMap("Blackbody");
1015976
//blackbody texture
1016977
std::vector<uint8_t> blackbody;
1017978
blackbody.reserve(resolution * 3);
1018979
for (float i = 0.f; i < 1.f; i+=step) {
1019-
Core::Datatypes::ColorRGB col = getColorMapVal(i, "Blackbody");
980+
ColorRGB col = cm.getColorMapVal(i);
1020981
blackbody.push_back(static_cast<uint8_t>(col.r() * 255.0f));
1021982
blackbody.push_back(static_cast<uint8_t>(col.g() * 255.0f));
1022983
blackbody.push_back(static_cast<uint8_t>(col.b() * 255.0f));

0 commit comments

Comments
 (0)