@@ -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
7578using 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