Browse Source

Fixed template errors

Former-commit-id: 5601f4e0c6d8f5a5593282149a088b6dca93572c
Joe Graus 7 years ago
parent
commit
324253ff0b
4 changed files with 40 additions and 100 deletions
  1. 10 25
      include/igl/inferno.cpp
  2. 10 25
      include/igl/magma.cpp
  3. 10 25
      include/igl/plasma.cpp
  4. 10 25
      include/igl/viridis.cpp

+ 10 - 25
include/igl/inferno.cpp

@@ -10,9 +10,8 @@
 
 
 // One of the new matplotlib colormaps by Nathaniel J.Smith, Stefan van der Walt, and (in the case of viridis) Eric Firing.
 // One of the new matplotlib colormaps by Nathaniel J.Smith, Stefan van der Walt, and (in the case of viridis) Eric Firing.
 // Released under the CC0 license / public domain dedication
 // Released under the CC0 license / public domain dedication
-static const unsigned int pal = 256;
 
 
-static float inferno_cm[pal][3] = {
+static float inferno_cm[256][3] = {
  { 0.001462, 0.000466, 0.013866 },
  { 0.001462, 0.000466, 0.013866 },
  { 0.002267, 0.001270, 0.018570 },
  { 0.002267, 0.001270, 0.018570 },
  { 0.003299, 0.002249, 0.024239 },
  { 0.003299, 0.002249, 0.024239 },
@@ -271,23 +270,6 @@ static float inferno_cm[pal][3] = {
  { 0.988362, 0.998364, 0.644924 }
  { 0.988362, 0.998364, 0.644924 }
 };
 };
 
 
-template <typename T>
-static float hue(float delta, T r, T g, T b) {
-	float h = 0.0f;
-
-	if (delta != 0.0f) {
-		if (r > g && r > b) {
-			h = 60.0f * std::fmod(g - b / delta, 6.0);
-		} else if (g > b) {
-			h = 60.0f * ((b - r / delta) + 2.0);
-		} else {
-			h = 60.0f * ((r - g / delta) + 4.0);
-		}
-	}
-
-	return h;
-}
-
 template <typename T>
 template <typename T>
 IGL_INLINE void igl::inferno(const T x, T * rgb)
 IGL_INLINE void igl::inferno(const T x, T * rgb)
 {
 {
@@ -297,9 +279,12 @@ IGL_INLINE void igl::inferno(const T x, T * rgb)
 template <typename T>
 template <typename T>
 IGL_INLINE void igl::inferno(const T x_in, T & r, T & g, T & b)
 IGL_INLINE void igl::inferno(const T x_in, T & r, T & g, T & b)
 {
 {
-	T x_in_clamped = static_cast<T>(std::max(0.0, std::min(1.0, x_in)));
+	static const unsigned int pal = 256;
+	const T zero = 0.0;
+	const T one = 1.0;
+	T x_in_clamped = static_cast<T>(std::max(zero, std::min(one, x_in)));
 
 
-	// simple rgb lerp from palette 
+	// simple rgb lerp from palette
 	unsigned int least = std::floor(x_in_clamped * static_cast<T>(pal - 1));
 	unsigned int least = std::floor(x_in_clamped * static_cast<T>(pal - 1));
 	unsigned int most = std::ceil(x_in_clamped * static_cast<T>(pal - 1));
 	unsigned int most = std::ceil(x_in_clamped * static_cast<T>(pal - 1));
 
 
@@ -307,11 +292,11 @@ IGL_INLINE void igl::inferno(const T x_in, T & r, T & g, T & b)
 	T _g[2] = { inferno_cm[least][1], inferno_cm[most][1] };
 	T _g[2] = { inferno_cm[least][1], inferno_cm[most][1] };
 	T _b[2] = { inferno_cm[least][2], inferno_cm[most][2] };
 	T _b[2] = { inferno_cm[least][2], inferno_cm[most][2] };
 
 
-	float t = std::max(0.0, std::min(1.0, fmod(x_in_clamped * static_cast<T>(pal), 1.0f)));
+	T t = std::max(zero, std::min(one, fmod(x_in_clamped * static_cast<T>(pal), 1.0f)));
 
 
-	r = std::max(0.0, std::min(1.0, (1.0f - t) * _r[0] + t * _r[1]));
-	g = std::max(0.0, std::min(1.0, (1.0f - t) * _g[0] + t * _g[1]));
-	b = std::max(0.0, std::min(1.0, (1.0f - t) * _b[0] + t * _b[1]));
+	r = std::max(zero, std::min(one, (one - t) * _r[0] + t * _r[1]));
+	g = std::max(zero, std::min(one, (one - t) * _g[0] + t * _g[1]));
+	b = std::max(zero, std::min(one, (one - t) * _b[0] + t * _b[1]));
 }
 }
 
 
 template <typename DerivedZ, typename DerivedC>
 template <typename DerivedZ, typename DerivedC>

+ 10 - 25
include/igl/magma.cpp

@@ -10,9 +10,8 @@
 
 
 // One of the new matplotlib colormaps by Nathaniel J.Smith, Stefan van der Walt, and (in the case of viridis) Eric Firing.
 // One of the new matplotlib colormaps by Nathaniel J.Smith, Stefan van der Walt, and (in the case of viridis) Eric Firing.
 // Released under the CC0 license / public domain dedication
 // Released under the CC0 license / public domain dedication
-static const unsigned int pal = 256;
 
 
-static float magma_cm[pal][3] = {
+static float magma_cm[256][3] = {
 	{ 0.001462, 0.000466, 0.013866 },
 	{ 0.001462, 0.000466, 0.013866 },
 	{ 0.002258, 0.001295, 0.018331 },
 	{ 0.002258, 0.001295, 0.018331 },
 	{ 0.003279, 0.002305, 0.023708 },
 	{ 0.003279, 0.002305, 0.023708 },
@@ -271,23 +270,6 @@ static float magma_cm[pal][3] = {
 	{ 0.987053, 0.991438, 0.749504 }
 	{ 0.987053, 0.991438, 0.749504 }
 };
 };
 
 
-template <typename T>
-static float hue(float delta, T r, T g, T b) {
-	float h = 0.0f;
-
-	if (delta != 0.0f) {
-		if (r > g && r > b) {
-			h = 60.0f * std::fmod(g - b / delta, 6.0);
-		} else if (g > b) {
-			h = 60.0f * ((b - r / delta) + 2.0);
-		} else {
-			h = 60.0f * ((r - g / delta) + 4.0);
-		}
-	}
-
-	return h;
-}
-
 template <typename T>
 template <typename T>
 IGL_INLINE void igl::magma(const T x, T * rgb)
 IGL_INLINE void igl::magma(const T x, T * rgb)
 {
 {
@@ -297,9 +279,12 @@ IGL_INLINE void igl::magma(const T x, T * rgb)
 template <typename T>
 template <typename T>
 IGL_INLINE void igl::magma(const T x_in, T & r, T & g, T & b)
 IGL_INLINE void igl::magma(const T x_in, T & r, T & g, T & b)
 {
 {
-	T x_in_clamped = static_cast<T>(std::max(0.0, std::min(1.0, x_in)));
+	static const unsigned int pal = 256;
+	const T zero = 0.0;
+	const T one = 1.0;
+	T x_in_clamped = static_cast<T>(std::max(zero, std::min(one, x_in)));
 
 
-	// simple rgb lerp from palette 
+	// simple rgb lerp from palette
 	unsigned int least = std::floor(x_in_clamped * static_cast<T>(pal - 1));
 	unsigned int least = std::floor(x_in_clamped * static_cast<T>(pal - 1));
 	unsigned int most = std::ceil(x_in_clamped * static_cast<T>(pal - 1));
 	unsigned int most = std::ceil(x_in_clamped * static_cast<T>(pal - 1));
 
 
@@ -307,11 +292,11 @@ IGL_INLINE void igl::magma(const T x_in, T & r, T & g, T & b)
 	T _g[2] = { magma_cm[least][1], magma_cm[most][1] };
 	T _g[2] = { magma_cm[least][1], magma_cm[most][1] };
 	T _b[2] = { magma_cm[least][2], magma_cm[most][2] };
 	T _b[2] = { magma_cm[least][2], magma_cm[most][2] };
 
 
-	float t = std::max(0.0, std::min(1.0, fmod(x_in_clamped * static_cast<T>(pal), 1.0f)));
+	T t = std::max(zero, std::min(one, fmod(x_in_clamped * static_cast<T>(pal), 1.0f)));
 
 
-	r = std::max(0.0, std::min(1.0, (1.0f - t) * _r[0] + t * _r[1]));
-	g = std::max(0.0, std::min(1.0, (1.0f - t) * _g[0] + t * _g[1]));
-	b = std::max(0.0, std::min(1.0, (1.0f - t) * _b[0] + t * _b[1]));
+	r = std::max(zero, std::min(one, (one - t) * _r[0] + t * _r[1]));
+	g = std::max(zero, std::min(one, (one - t) * _g[0] + t * _g[1]));
+	b = std::max(zero, std::min(one, (one - t) * _b[0] + t * _b[1]));
 }
 }
 
 
 template <typename DerivedZ, typename DerivedC>
 template <typename DerivedZ, typename DerivedC>

+ 10 - 25
include/igl/plasma.cpp

@@ -10,9 +10,8 @@
 
 
 // One of the new matplotlib colormaps by Nathaniel J.Smith, Stefan van der Walt, and (in the case of viridis) Eric Firing.
 // One of the new matplotlib colormaps by Nathaniel J.Smith, Stefan van der Walt, and (in the case of viridis) Eric Firing.
 // Released under the CC0 license / public domain dedication
 // Released under the CC0 license / public domain dedication
-static const unsigned int pal = 256;
 
 
-static float plasma_cm[pal][3] = {
+static float plasma_cm[256][3] = {
 	{ 0.050383, 0.029803, 0.527975 },
 	{ 0.050383, 0.029803, 0.527975 },
 	{ 0.063536, 0.028426, 0.533124 },
 	{ 0.063536, 0.028426, 0.533124 },
 	{ 0.075353, 0.027206, 0.538007 },
 	{ 0.075353, 0.027206, 0.538007 },
@@ -271,23 +270,6 @@ static float plasma_cm[pal][3] = {
 	{ 0.940015, 0.975158, 0.131326 }
 	{ 0.940015, 0.975158, 0.131326 }
 };
 };
 
 
-template <typename T>
-static float hue(float delta, T r, T g, T b) {
-	float h = 0.0f;
-
-	if (delta != 0.0f) {
-		if (r > g && r > b) {
-			h = 60.0f * std::fmod(g - b / delta, 6.0);
-		} else if (g > b) {
-			h = 60.0f * ((b - r / delta) + 2.0);
-		} else {
-			h = 60.0f * ((r - g / delta) + 4.0);
-		}
-	}
-
-	return h;
-}
-
 template <typename T>
 template <typename T>
 IGL_INLINE void igl::plasma(const T x, T * rgb)
 IGL_INLINE void igl::plasma(const T x, T * rgb)
 {
 {
@@ -297,9 +279,12 @@ IGL_INLINE void igl::plasma(const T x, T * rgb)
 template <typename T>
 template <typename T>
 IGL_INLINE void igl::plasma(const T x_in, T & r, T & g, T & b)
 IGL_INLINE void igl::plasma(const T x_in, T & r, T & g, T & b)
 {
 {
-	T x_in_clamped = static_cast<T>(std::max(0.0, std::min(1.0, x_in)));
+	static const unsigned int pal = 256;
+	const T zero = 0.0;
+	const T one = 1.0;
+	T x_in_clamped = static_cast<T>(std::max(zero, std::min(one, x_in)));
 
 
-	// simple rgb lerp from palette 
+	// simple rgb lerp from palette
 	unsigned int least = std::floor(x_in_clamped * static_cast<T>(pal - 1));
 	unsigned int least = std::floor(x_in_clamped * static_cast<T>(pal - 1));
 	unsigned int most = std::ceil(x_in_clamped * static_cast<T>(pal - 1));
 	unsigned int most = std::ceil(x_in_clamped * static_cast<T>(pal - 1));
 
 
@@ -307,11 +292,11 @@ IGL_INLINE void igl::plasma(const T x_in, T & r, T & g, T & b)
 	T _g[2] = { plasma_cm[least][1], plasma_cm[most][1] };
 	T _g[2] = { plasma_cm[least][1], plasma_cm[most][1] };
 	T _b[2] = { plasma_cm[least][2], plasma_cm[most][2] };
 	T _b[2] = { plasma_cm[least][2], plasma_cm[most][2] };
 
 
-	float t = std::max(0.0, std::min(1.0, fmod(x_in_clamped * static_cast<T>(pal), 1.0f)));
+	T t = std::max(zero, std::min(one, fmod(x_in_clamped * static_cast<T>(pal), 1.0f)));
 
 
-	r = std::max(0.0, std::min(1.0, (1.0f - t) * _r[0] + t * _r[1]));
-	g = std::max(0.0, std::min(1.0, (1.0f - t) * _g[0] + t * _g[1]));
-	b = std::max(0.0, std::min(1.0, (1.0f - t) * _b[0] + t * _b[1]));
+	r = std::max(zero, std::min(one, (one - t) * _r[0] + t * _r[1]));
+	g = std::max(zero, std::min(one, (one - t) * _g[0] + t * _g[1]));
+	b = std::max(zero, std::min(one, (one - t) * _b[0] + t * _b[1]));
 }
 }
 
 
 template <typename DerivedZ, typename DerivedC>
 template <typename DerivedZ, typename DerivedC>

+ 10 - 25
include/igl/viridis.cpp

@@ -10,9 +10,8 @@
 
 
 // One of the new matplotlib colormaps by Nathaniel J.Smith, Stefan van der Walt, and (in the case of viridis) Eric Firing.
 // One of the new matplotlib colormaps by Nathaniel J.Smith, Stefan van der Walt, and (in the case of viridis) Eric Firing.
 // Released under the CC0 license / public domain dedication
 // Released under the CC0 license / public domain dedication
-static const unsigned int pal = 256;
 
 
-static float viridis_cm[pal][3] = {
+static float viridis_cm[256][3] = {
 	{ 0.267004, 0.004874, 0.329415 },
 	{ 0.267004, 0.004874, 0.329415 },
 	{ 0.268510, 0.009605, 0.335427 },
 	{ 0.268510, 0.009605, 0.335427 },
 	{ 0.269944, 0.014625, 0.341379 },
 	{ 0.269944, 0.014625, 0.341379 },
@@ -271,23 +270,6 @@ static float viridis_cm[pal][3] = {
 	{ 0.993248, 0.906157, 0.143936 }
 	{ 0.993248, 0.906157, 0.143936 }
 };
 };
 
 
-template <typename T>
-static float hue(float delta, T r, T g, T b) {
-	float h = 0.0f;
-
-	if (delta != 0.0f) {
-		if (r > g && r > b) {
-			h = 60.0f * std::fmod(g - b / delta, 6.0);
-		} else if (g > b) {
-			h = 60.0f * ((b - r / delta) + 2.0);
-		} else {
-			h = 60.0f * ((r - g / delta) + 4.0);
-		}
-	}
-
-	return h;
-}
-
 template <typename T>
 template <typename T>
 IGL_INLINE void igl::viridis(const T x, T * rgb)
 IGL_INLINE void igl::viridis(const T x, T * rgb)
 {
 {
@@ -297,9 +279,12 @@ IGL_INLINE void igl::viridis(const T x, T * rgb)
 template <typename T>
 template <typename T>
 IGL_INLINE void igl::viridis(const T x_in, T & r, T & g, T & b)
 IGL_INLINE void igl::viridis(const T x_in, T & r, T & g, T & b)
 {
 {
-	T x_in_clamped = static_cast<T>(std::max(0.0, std::min(1.0, x_in)));
+	static const unsigned int pal = 256;
+	const T zero = 0.0;
+	const T one = 1.0;
+	T x_in_clamped = static_cast<T>(std::max(zero, std::min(one, x_in)));
 
 
-	// simple rgb lerp from palette 
+	// simple rgb lerp from palette
 	unsigned int least = std::floor(x_in_clamped * static_cast<T>(pal - 1));
 	unsigned int least = std::floor(x_in_clamped * static_cast<T>(pal - 1));
 	unsigned int most = std::ceil(x_in_clamped * static_cast<T>(pal - 1));
 	unsigned int most = std::ceil(x_in_clamped * static_cast<T>(pal - 1));
 
 
@@ -307,11 +292,11 @@ IGL_INLINE void igl::viridis(const T x_in, T & r, T & g, T & b)
 	T _g[2] = { viridis_cm[least][1], viridis_cm[most][1] };
 	T _g[2] = { viridis_cm[least][1], viridis_cm[most][1] };
 	T _b[2] = { viridis_cm[least][2], viridis_cm[most][2] };
 	T _b[2] = { viridis_cm[least][2], viridis_cm[most][2] };
 
 
-	float t = std::max(0.0, std::min(1.0, fmod(x_in_clamped * static_cast<T>(pal), 1.0f)));
+	T t = std::max(zero, std::min(one, fmod(x_in_clamped * static_cast<T>(pal), 1.0f)));
 
 
-	r = std::max(0.0, std::min(1.0, (1.0f - t) * _r[0] + t * _r[1]));
-	g = std::max(0.0, std::min(1.0, (1.0f - t) * _g[0] + t * _g[1]));
-	b = std::max(0.0, std::min(1.0, (1.0f - t) * _b[0] + t * _b[1]));
+	r = std::max(zero, std::min(one, (one - t) * _r[0] + t * _r[1]));
+	g = std::max(zero, std::min(one, (one - t) * _g[0] + t * _g[1]));
+	b = std::max(zero, std::min(one, (one - t) * _b[0] + t * _b[1]));
 }
 }
 
 
 template <typename DerivedZ, typename DerivedC>
 template <typename DerivedZ, typename DerivedC>