Skip to content

Commit

Permalink
Refs #3882 test for MantidColorMap
Browse files Browse the repository at this point in the history
Also, setting a NAN color. Finding more test suites in TestViewer.
  • Loading branch information
Janik Zikovsky committed Nov 8, 2011
1 parent d10b11b commit b58c13a
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 6 deletions.
22 changes: 22 additions & 0 deletions Code/Mantid/MantidQt/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ set ( MOC_FILES inc/MantidQtAPI/AlgorithmDialog.h
set ( UI_FILES inc/MantidQtAPI/ManageUserDirectories.ui
)

set( TEST_FILES
test/MantidColorMapTest.h
)

include_directories ( inc )
include_directories ( ../MantidWidgets/inc )
include_directories ( ../MantidWidgets )
Expand All @@ -66,6 +70,24 @@ add_library ( MantidQtAPI ${ALL_SRC} ${INC_FILES} ${UI_HDRS} )

target_link_libraries ( MantidQtAPI ${CORE_MANTIDLIBS} ${QT_LIBRARIES} ${QWT_LIBRARIES} )

###########################################################################
# Testing
###########################################################################

if ( CXXTEST_FOUND )
include_directories( inc ../../Framework/TestHelpers/inc ../../Framework/DataObjects/inc )
if ( GMOCK_FOUND AND GTEST_FOUND )
cxxtest_add_test ( MantidQtAPITest ${TEST_FILES} ${GMOCK_TEST_FILES} )
target_link_libraries( MantidQtAPITest MantidQtAPI ${MANTIDLIBS}
${GMOCK_LIBRARIES} ${GTEST_LIBRARIES}
TestHelpers DataObjects)
add_dependencies( FrameworkTests MantidQtAPITest )
# Add to the 'UnitTests' group in VS
set_property( TARGET MantidQtAPITest PROPERTY FOLDER "UnitTests" )
endif ()
endif ()


###########################################################################
# Installation settings
###########################################################################
Expand Down
5 changes: 5 additions & 0 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidColorMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class EXPORT_OPT_MANTIDQT_API MantidColorMap : public QwtColorMap
/// Load a color map file
bool loadMap(const QString & filename);

void setNanColor(int r, int g, int b);

/// Setup a default color map. This is used if a file is not available
void setupDefaultMap();

Expand Down Expand Up @@ -109,6 +111,9 @@ class EXPORT_OPT_MANTIDQT_API MantidColorMap : public QwtColorMap
/// The number of colors in this map
short m_num_colors;

/// Color to show for not-a-number
QRgb m_nan_color;

};


Expand Down
24 changes: 21 additions & 3 deletions Code/Mantid/MantidQt/API/src/MantidColorMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void MantidColorMap::changeScaleType(GraphOptions::ScaleType type)
m_scale_type = type;
}

//-------------------------------------------------------------------------------------------------
/**
* Load a color map from a file
* @param filename :: The full path to the color map file
Expand Down Expand Up @@ -112,6 +113,19 @@ bool MantidColorMap::loadMap(const QString & filename)
return is_success;
}

//-------------------------------------------------------------------------------------------------
/** Set a color for Not-a-number
*
* @param r :: red, from 0 to 255
* @param g :: green, from 0 to 255
* @param b :: blue, from 0 to 255
*/
void MantidColorMap::setNanColor(int r, int g, int b)
{
m_nan_color = qRgb(r,g,b);
}

//-------------------------------------------------------------------------------------------------
/**
* Define a default color map to be used if a file is unavailable.
*/
Expand Down Expand Up @@ -157,6 +171,7 @@ void MantidColorMap::setupDefaultMap()
reader >> red >> green >> blue;
m_colors.push_back(qRgb((unsigned char)(red), (unsigned char)green, (unsigned char)blue));
}
this->setNanColor(255,255,255);
}


Expand Down Expand Up @@ -209,14 +224,17 @@ double MantidColorMap::normalize(const QwtDoubleInterval &interval, double value
*/
QRgb MantidColorMap::rgb(const QwtDoubleInterval & interval, double value) const
{
// Special case for NAN which is != NAN
if (value != value)
return m_nan_color;

short ci = static_cast<short>(colorIndex(interval, value));
if( ci >= 0 && ci < m_num_colors )
{
return m_colors[ci];
}
return
// Return black
QRgb();
// Return black
return QRgb();

// QRgb col = getColor();
// float r(0.0f), g(0.0f), b(0.0f), a(0.0f);
Expand Down
38 changes: 38 additions & 0 deletions Code/Mantid/MantidQt/API/test/MantidColorMapTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef MANTIDQT_API_MANTIDCOLORMAPTEST_H_
#define MANTIDQT_API_MANTIDCOLORMAPTEST_H_

#include <cxxtest/TestSuite.h>
#include <iostream>
#include <iomanip>
#include "MantidQtAPI/MantidColorMap.h"
#include <limits>
#include <QRgb>

class MantidColorMapTest : public CxxTest::TestSuite
{
public:

/// Check default color map
void test_constructor()
{
MantidColorMap map;
QRgb col;
col = map.rgb( QwtDoubleInterval( 0.0, 1.0 ), 0.0);
TSM_ASSERT_EQUALS("Default min color.", col, qRgb(0, 172, 252) );
col = map.rgb( QwtDoubleInterval( 0.0, 1.0 ), 1.0);
TSM_ASSERT_EQUALS("Default max color.", col, qRgb(255,255,255) );
}

void test_nan_color()
{
MantidColorMap map;
map.setNanColor(123, 23, 34);
QRgb col;
double nan = std::numeric_limits<double>::quiet_NaN();
col = map.rgb( QwtDoubleInterval( 0.0, 1.0 ), nan);
TSM_ASSERT_EQUALS("Passing NAN to rgb returns the set color.", col, qRgb(123, 23, 34) );
}
};


#endif /* MANTIDQT_API_MANTIDCOLORMAPTEST_H_ */
14 changes: 12 additions & 2 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,21 @@ QwtDoubleInterval getRange(IMDIterator * it)
if (signal > maxSignal) maxSignal = signal;
} while (it->next());

if (minSignal == DBL_MAX)
{
minSignal = 0.0;
maxSignal = 1.0;
}
if (minSignal < maxSignal)
return QwtDoubleInterval(minSignal, maxSignal);
else
// Possibly only one value in range
return QwtDoubleInterval(minSignal*0.5, minSignal*1.5);
{
if (minSignal != 0)
// Possibly only one value in range
return QwtDoubleInterval(minSignal*0.5, minSignal*1.5);
else
return QwtDoubleInterval(0., 1.0);
}
}

//------------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion Code/Tools/TestViewer/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,8 @@ def discover_CXX_projects(self, path, source_path):
dirList=os.listdir(path)
for fname in dirList:
# Look for executables ending in Test
if fname.endswith("Test") and os.path.isfile(fname):
if fname.endswith("Test") and os.path.isfile( os.path.join(path, fname) ):
print fname, ' found'
testnames.add(fname)

# Now add the known tests, in case they were deleted
Expand Down

0 comments on commit b58c13a

Please sign in to comment.