#version 3.8; global_settings {assumed_gamma 1} //========================================================================= // Persistence of Vision Ray Tracer version 3.8 // Scene Description Language (SDL) // File: Remap Color_Map // Version: 1.0 // Last updated: 12-Feb-2023 // Stores an improperly indexed color map in an array and converts // it to a proper color map with indices spanning the range to 0-1 // // Author: Bill Walker "Bald Eagle", 2023 // email: see posts in news.povray.org // //------------------------------------------------------------------------ // should probably incorporate a sorting to make sure that the index values // are in the proper order #declare MisindexedColorMapArray = array mixed [256][2] { {0.0000, <1.00, 0.00, 1.00>}, {0.0216, <1.00, 0.00, 1.00>}, {0.0431, <1.00, 0.01, 0.99>}, {0.0647, <1.00, 0.01, 0.99>}, {0.0863, <1.00, 0.02, 0.98>}, {0.1078, <1.00, 0.02, 0.98>}, {0.1294, <1.00, 0.02, 0.98>}, {0.1510, <1.00, 0.03, 0.97>}, {0.1725, <1.00, 0.03, 0.97>}, {0.1941, <1.00, 0.04, 0.96>}, {0.2157, <1.00, 0.04, 0.96>}, {0.2373, <1.00, 0.04, 0.96>}, {0.2588, <1.00, 0.05, 0.95>}, {0.2804, <1.00, 0.05, 0.95>}, {0.3020, <1.00, 0.05, 0.95>}, {0.3235, <1.00, 0.06, 0.94>}, {0.3451, <1.00, 0.06, 0.94>}, {0.3667, <1.00, 0.07, 0.93>}, {0.3882, <1.00, 0.07, 0.93>}, {0.4098, <1.00, 0.07, 0.93>}, {0.4314, <1.00, 0.08, 0.92>}, {0.4529, <1.00, 0.08, 0.92>}, {0.4745, <1.00, 0.09, 0.91>}, {0.4961, <1.00, 0.09, 0.91>}, {0.5176, <1.00, 0.09, 0.91>}, {0.5392, <1.00, 0.10, 0.90>}, {0.5608, <1.00, 0.10, 0.90>}, {0.5824, <1.00, 0.11, 0.89>}, {0.6039, <1.00, 0.11, 0.89>}, {0.6255, <1.00, 0.11, 0.89>}, {0.6471, <1.00, 0.12, 0.88>}, {0.6686, <1.00, 0.12, 0.88>}, {0.6902, <1.00, 0.13, 0.87>}, {0.7118, <1.00, 0.13, 0.87>}, {0.7333, <1.00, 0.13, 0.87>}, {0.7549, <1.00, 0.14, 0.86>}, {0.7765, <1.00, 0.14, 0.86>}, {0.7980, <1.00, 0.15, 0.85>}, {0.8196, <1.00, 0.15, 0.85>}, {0.8412, <1.00, 0.15, 0.85>}, {0.8627, <1.00, 0.16, 0.84>}, {0.8843, <1.00, 0.16, 0.84>}, {0.9059, <1.00, 0.16, 0.84>}, {0.9275, <1.00, 0.17, 0.83>}, {0.9490, <1.00, 0.17, 0.83>}, {0.9706, <1.00, 0.18, 0.82>}, {0.9922, <1.00, 0.18, 0.82>}, {1.0137, <1.00, 0.18, 0.82>}, {1.0353, <1.00, 0.19, 0.81>}, {1.0569, <1.00, 0.19, 0.81>}, {1.0784, <1.00, 0.20, 0.80>}, {1.1000, <1.00, 0.20, 0.80>}, {1.1216, <1.00, 0.20, 0.80>}, {1.1431, <1.00, 0.21, 0.79>}, {1.1647, <1.00, 0.21, 0.79>}, {1.1863, <1.00, 0.22, 0.78>}, {1.2078, <1.00, 0.22, 0.78>}, {1.2294, <1.00, 0.22, 0.78>}, {1.2510, <1.00, 0.23, 0.77>}, {1.2725, <1.00, 0.23, 0.77>}, {1.2941, <1.00, 0.24, 0.76>}, {1.3157, <1.00, 0.24, 0.76>}, {1.3373, <1.00, 0.24, 0.76>}, {1.3588, <1.00, 0.25, 0.75>}, {1.3804, <1.00, 0.25, 0.75>}, {1.4020, <1.00, 0.25, 0.75>}, {1.4235, <1.00, 0.26, 0.74>}, {1.4451, <1.00, 0.26, 0.74>}, {1.4667, <1.00, 0.27, 0.73>}, {1.4882, <1.00, 0.27, 0.73>}, {1.5098, <1.00, 0.27, 0.73>}, {1.5314, <1.00, 0.28, 0.72>}, {1.5529, <1.00, 0.28, 0.72>}, {1.5745, <1.00, 0.29, 0.71>}, {1.5961, <1.00, 0.29, 0.71>}, {1.6176, <1.00, 0.29, 0.71>}, {1.6392, <1.00, 0.30, 0.70>}, {1.6608, <1.00, 0.30, 0.70>}, {1.6824, <1.00, 0.31, 0.69>}, {1.7039, <1.00, 0.31, 0.69>}, {1.7255, <1.00, 0.31, 0.69>}, {1.7471, <1.00, 0.32, 0.68>}, {1.7686, <1.00, 0.32, 0.68>}, {1.7902, <1.00, 0.33, 0.67>}, {1.8118, <1.00, 0.33, 0.67>}, {1.8333, <1.00, 0.33, 0.67>}, {1.8549, <1.00, 0.34, 0.66>}, {1.8765, <1.00, 0.34, 0.66>}, {1.8980, <1.00, 0.35, 0.65>}, {1.9196, <1.00, 0.35, 0.65>}, {1.9412, <1.00, 0.35, 0.65>}, {1.9627, <1.00, 0.36, 0.64>}, {1.9843, <1.00, 0.36, 0.64>}, {2.0059, <1.00, 0.36, 0.64>}, {2.0275, <1.00, 0.37, 0.63>}, {2.0490, <1.00, 0.37, 0.63>}, {2.0706, <1.00, 0.38, 0.62>}, {2.0922, <1.00, 0.38, 0.62>}, {2.1137, <1.00, 0.38, 0.62>}, {2.1353, <1.00, 0.39, 0.61>}, {2.1569, <1.00, 0.39, 0.61>}, {2.1784, <1.00, 0.40, 0.60>}, {2.2000, <1.00, 0.40, 0.60>}, {2.2216, <1.00, 0.40, 0.60>}, {2.2431, <1.00, 0.41, 0.59>}, {2.2647, <1.00, 0.41, 0.59>}, {2.2863, <1.00, 0.42, 0.58>}, {2.3078, <1.00, 0.42, 0.58>}, {2.3294, <1.00, 0.42, 0.58>}, {2.3510, <1.00, 0.43, 0.57>}, {2.3725, <1.00, 0.43, 0.57>}, {2.3941, <1.00, 0.44, 0.56>}, {2.4157, <1.00, 0.44, 0.56>}, {2.4373, <1.00, 0.44, 0.56>}, {2.4588, <1.00, 0.45, 0.55>}, {2.4804, <1.00, 0.45, 0.55>}, {2.5020, <1.00, 0.45, 0.55>}, {2.5235, <1.00, 0.46, 0.54>}, {2.5451, <1.00, 0.46, 0.54>}, {2.5667, <1.00, 0.47, 0.53>}, {2.5882, <1.00, 0.47, 0.53>}, {2.6098, <1.00, 0.47, 0.53>}, {2.6314, <1.00, 0.48, 0.52>}, {2.6529, <1.00, 0.48, 0.52>}, {2.6745, <1.00, 0.49, 0.51>}, {2.6961, <1.00, 0.49, 0.51>}, {2.7176, <1.00, 0.49, 0.51>}, {2.7392, <1.00, 0.50, 0.50>}, {2.7608, <1.00, 0.50, 0.50>}, {2.7824, <1.00, 0.51, 0.49>}, {2.8039, <1.00, 0.51, 0.49>}, {2.8255, <1.00, 0.51, 0.49>}, {2.8471, <1.00, 0.52, 0.48>}, {2.8686, <1.00, 0.52, 0.48>}, {2.8902, <1.00, 0.53, 0.47>}, {2.9118, <1.00, 0.53, 0.47>}, {2.9333, <1.00, 0.53, 0.47>}, {2.9549, <1.00, 0.54, 0.46>}, {2.9765, <1.00, 0.54, 0.46>}, {2.9980, <1.00, 0.55, 0.45>}, {3.0196, <1.00, 0.55, 0.45>}, {3.0412, <1.00, 0.55, 0.45>}, {3.0627, <1.00, 0.56, 0.44>}, {3.0843, <1.00, 0.56, 0.44>}, {3.1059, <1.00, 0.56, 0.44>}, {3.1275, <1.00, 0.57, 0.43>}, {3.1490, <1.00, 0.57, 0.43>}, {3.1706, <1.00, 0.58, 0.42>}, {3.1922, <1.00, 0.58, 0.42>}, {3.2137, <1.00, 0.58, 0.42>}, {3.2353, <1.00, 0.59, 0.41>}, {3.2569, <1.00, 0.59, 0.41>}, {3.2784, <1.00, 0.60, 0.40>}, {3.3000, <1.00, 0.60, 0.40>}, {3.3216, <1.00, 0.60, 0.40>}, {3.3431, <1.00, 0.61, 0.39>}, {3.3647, <1.00, 0.61, 0.39>}, {3.3863, <1.00, 0.62, 0.38>}, {3.4078, <1.00, 0.62, 0.38>}, {3.4294, <1.00, 0.62, 0.38>}, {3.4510, <1.00, 0.63, 0.37>}, {3.4725, <1.00, 0.63, 0.37>}, {3.4941, <1.00, 0.64, 0.36>}, {3.5157, <1.00, 0.64, 0.36>}, {3.5373, <1.00, 0.64, 0.36>}, {3.5588, <1.00, 0.65, 0.35>}, {3.5804, <1.00, 0.65, 0.35>}, {3.6020, <1.00, 0.65, 0.35>}, {3.6235, <1.00, 0.66, 0.34>}, {3.6451, <1.00, 0.66, 0.34>}, {3.6667, <1.00, 0.67, 0.33>}, {3.6882, <1.00, 0.67, 0.33>}, {3.7098, <1.00, 0.67, 0.33>}, {3.7314, <1.00, 0.68, 0.32>}, {3.7529, <1.00, 0.68, 0.32>}, {3.7745, <1.00, 0.69, 0.31>}, {3.7961, <1.00, 0.69, 0.31>}, {3.8176, <1.00, 0.69, 0.31>}, {3.8392, <1.00, 0.70, 0.30>}, {3.8608, <1.00, 0.70, 0.30>}, {3.8824, <1.00, 0.71, 0.29>}, {3.9039, <1.00, 0.71, 0.29>}, {3.9255, <1.00, 0.71, 0.29>}, {3.9471, <1.00, 0.72, 0.28>}, {3.9686, <1.00, 0.72, 0.28>}, {3.9902, <1.00, 0.73, 0.27>}, {4.0118, <1.00, 0.73, 0.27>}, {4.0333, <1.00, 0.73, 0.27>}, {4.0549, <1.00, 0.74, 0.26>}, {4.0765, <1.00, 0.74, 0.26>}, {4.0980, <1.00, 0.75, 0.25>}, {4.1196, <1.00, 0.75, 0.25>}, {4.1412, <1.00, 0.75, 0.25>}, {4.1627, <1.00, 0.76, 0.24>}, {4.1843, <1.00, 0.76, 0.24>}, {4.2059, <1.00, 0.76, 0.24>}, {4.2275, <1.00, 0.77, 0.23>}, {4.2490, <1.00, 0.77, 0.23>}, {4.2706, <1.00, 0.78, 0.22>}, {4.2922, <1.00, 0.78, 0.22>}, {4.3137, <1.00, 0.78, 0.22>}, {4.3353, <1.00, 0.79, 0.21>}, {4.3569, <1.00, 0.79, 0.21>}, {4.3784, <1.00, 0.80, 0.20>}, {4.4000, <1.00, 0.80, 0.20>}, {4.4216, <1.00, 0.80, 0.20>}, {4.4431, <1.00, 0.81, 0.19>}, {4.4647, <1.00, 0.81, 0.19>}, {4.4863, <1.00, 0.82, 0.18>}, {4.5078, <1.00, 0.82, 0.18>}, {4.5294, <1.00, 0.82, 0.18>}, {4.5510, <1.00, 0.83, 0.17>}, {4.5725, <1.00, 0.83, 0.17>}, {4.5941, <1.00, 0.84, 0.16>}, {4.6157, <1.00, 0.84, 0.16>}, {4.6373, <1.00, 0.84, 0.16>}, {4.6588, <1.00, 0.85, 0.15>}, {4.6804, <1.00, 0.85, 0.15>}, {4.7020, <1.00, 0.85, 0.15>}, {4.7235, <1.00, 0.86, 0.14>}, {4.7451, <1.00, 0.86, 0.14>}, {4.7667, <1.00, 0.87, 0.13>}, {4.7882, <1.00, 0.87, 0.13>}, {4.8098, <1.00, 0.87, 0.13>}, {4.8314, <1.00, 0.88, 0.12>}, {4.8529, <1.00, 0.88, 0.12>}, {4.8745, <1.00, 0.89, 0.11>}, {4.8961, <1.00, 0.89, 0.11>}, {4.9176, <1.00, 0.89, 0.11>}, {4.9392, <1.00, 0.90, 0.10>}, {4.9608, <1.00, 0.90, 0.10>}, {4.9824, <1.00, 0.91, 0.09>}, {5.0039, <1.00, 0.91, 0.09>}, {5.0255, <1.00, 0.91, 0.09>}, {5.0471, <1.00, 0.92, 0.08>}, {5.0686, <1.00, 0.92, 0.08>}, {5.0902, <1.00, 0.93, 0.07>}, {5.1118, <1.00, 0.93, 0.07>}, {5.1333, <1.00, 0.93, 0.07>}, {5.1549, <1.00, 0.94, 0.06>}, {5.1765, <1.00, 0.94, 0.06>}, {5.1980, <1.00, 0.95, 0.05>}, {5.2196, <1.00, 0.95, 0.05>}, {5.2412, <1.00, 0.95, 0.05>}, {5.2627, <1.00, 0.96, 0.04>}, {5.2843, <1.00, 0.96, 0.04>}, {5.3059, <1.00, 0.96, 0.04>}, {5.3275, <1.00, 0.97, 0.03>}, {5.3490, <1.00, 0.97, 0.03>}, {5.3706, <1.00, 0.98, 0.02>}, {5.3922, <1.00, 0.98, 0.02>}, {5.4137, <1.00, 0.98, 0.02>}, {5.4353, <1.00, 0.99, 0.01>}, {5.4569, <1.00, 0.99, 0.01>}, {5.4784, <1.00, 1.00, 0.00>}, {5.5000, <1.00, 1.00, 0.00>} } //------------------------------------------------------------------------ // Freya Holmer #declare Lerp = function (Start, End, Value) {(1 - Value) * Start + (End * Value)} #declare InvLerp = function (Start, End, Value) {(Value - Start) / (End - Start)} #declare ReMap = function (OldMin, OldMax, NewMin, NewMax, Value) {Lerp (NewMin, NewMax, InvLerp (OldMin, OldMax, Value) )} //------------------------------------------------------------------------ #macro FixColorMapArray (ColorMapArray) #local Indices = dimension_size (ColorMapArray, 1)-1; #declare NewColorMapArray = array mixed [Indices+1][2]; // Establish the min and max index values // use the first entry as a starting point // since we don't know WHAT the span of values is #declare Min = ColorMapArray [0][0]; #declare Max = ColorMapArray [0][0]; #for (I, 0, Indices) #declare Min = min (Min, ColorMapArray [I][0]); #declare Max = max (Max, ColorMapArray [I][0]); #end // Populate new array with color values matched to index values // remapped to the proper span of 0-1 #for (I, 0, Indices) #local OldIndex = ColorMapArray [I][0]; #local NewIndex = ReMap (Min, Max, 0, 1, OldIndex); //#debug concat ("Old Index = ", str (OldIndex, 0, 4), "\n") //#debug concat ("New Index = ", str (NewIndex, 0, 4), "\n") #debug "------------------\n" #declare NewColorMapArray [I][0] = NewIndex; #declare NewColorMapArray [I][1] = ColorMapArray [I][1]; #end NewColorMapArray #end //------------------------------------------------------------------------ #macro MakeColorMap (Array2D) #local Indices = dimension_size (Array2D, 1)-1; #local ColorMap = color_map { #for (I, 0, Indices) [Array2D [I][0], rgb Array2D [I][1]] #end } ColorMap #end //######################################################################### #declare Zoom = 50; camera { orthographic location -z*10 right x*image_width/Zoom up y*image_height/Zoom sky y look_at <0.00, 0, 0.00> } light_source{<0.0, 0.0, - 30.0> rgb 1} #declare Line = 0.03; text { ttf "timrom.ttf", "Using an array of indices and colors", 0.02, 0.0 scale 0.75 translate y*5 pigment {rgb 1} translate -x*6.5} text { ttf "timrom.ttf", "to remap a color_map to the span of 0 ... 1", 0.02, 0.0 scale 0.75 translate -y*5 pigment {rgb 1} translate -x*6.5} #declare OldColorMap = MakeColorMap (MisindexedColorMapArray); #local Indices = dimension_size (MisindexedColorMapArray, 1)-1; #declare Min = MisindexedColorMapArray [0][0]; #declare Max = MisindexedColorMapArray [0][0]; #for (I, 0, Indices) #declare Min = min (Min, MisindexedColorMapArray [I][0]); #declare Max = max (Max, MisindexedColorMapArray [I][0]); #end union { union { #for (I, 1, Indices) box {, pigment {rgb MisindexedColorMapArray [I][1]} } #end translate y*2 } union { sphere {<0, 0, 0> Line} cylinder {<0, 0, 0>, <1, 0, 0> Line } sphere {<1, 0, 0> Line} cylinder {<1, 0, 0>, <1, 1, 0> Line } sphere {<1, 1, 0> Line} cylinder {<1, 1, 0>, <0, 1, 0> Line } sphere {<0, 1, 0> Line} cylinder {<0, 1, 0>, <0, 0, 0> Line } pigment {rgb y} translate y*2 } union { cylinder {<1, 0, 0>, Line } sphere { Line} cylinder {, Line } sphere { Line} cylinder {, <1, 1, 0> Line } pigment {rgb x} translate y*2 } text { ttf "timrom.ttf", "Old color_map (out of range)", 0.02, 0.0 scale 0.5 translate y*3.5 pigment {rgb x*0.5}} translate -x*6 } sphere { <0,0,0>, 0.5 texture { pigment { gradient x color_map {OldColorMap} translate -x*0.5 scale 1 } finish { diffuse 1 } } translate -x*5.5 } #declare OldMax = Max; #declare NewColorMapArray = FixColorMapArray (MisindexedColorMapArray); #local Indices = dimension_size (NewColorMapArray, 1)-1; #declare Min = NewColorMapArray [0][0]; #declare Max = NewColorMapArray [0][0]; #for (I, 0, Indices) #declare Min = min (Min, NewColorMapArray [I][0]); #declare Max = max (Max, NewColorMapArray [I][0]); #end union { union { #for (I, 1, Indices) box {, pigment {rgb NewColorMapArray [I][1]} } #end translate -y*2 } union { sphere {<0, 0, 0> Line} cylinder {<0, 0, 0>, <1, 0, 0> Line } sphere {<1, 0, 0> Line} cylinder {<1, 0, 0>, <1, 1, 0> Line } sphere {<1, 1, 0> Line} cylinder {<1, 1, 0>, <0, 1, 0> Line } sphere {<0, 1, 0> Line} cylinder {<0, 1, 0>, <0, 0, 0> Line } pigment {rgb y} translate -y*2 } union { cylinder {<1, 0, 0>, Line } sphere { Line} cylinder {, Line } sphere { Line} cylinder {, <1, 1, 0> Line } pigment {rgb x} translate -y*2 } text { ttf "timrom.ttf", "New color_map (now in range)", 0.02, 0.0 scale 0.5 translate -y*2.5 pigment {rgb y*0.5}} translate x } #local Indices = dimension_size (NewColorMapArray, 1)-1; #debug "color_map {\n\n" #for (I, 0, Indices) #debug concat ("[", str (NewColorMapArray [I][0], 0, 4), ", rgb <", vstr (3, NewColorMapArray [I][1], ",", 0, 3), ">]\n") #end #debug "\n} \n" #declare NewColorMap = MakeColorMap (NewColorMapArray); sphere { <0,0,0>, 0.5 texture { pigment { gradient x color_map {NewColorMap} translate -x*0.5 scale 1 } finish { diffuse 1 } } translate x*1.5 } /* from math.inc // Adjusts input values (x) in the range [0, 1] to output values in range [Rmn, Rmx] ([y, z]). #declare adj_range = function (x, y, z) {x*(z - y) + y} // Adjusts values in a specified range [Rmn, Rmx] to the specified range [Min, Max] #declare adj_range2 = function (x, y, z, _Math_INC_OMn, _Math_INC_OMx) { ((x - y)/(z - y))*(_Math_INC_OMx - _Math_INC_OMn) + _Math_INC_OMn } */