Skip to content

Commit fb54072

Browse files
committed
Fix colorRGB string parsing
Default white color in ShowField resurrected.
1 parent 75ffc0b commit fb54072

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
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/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
}

0 commit comments

Comments
 (0)