Browse Source

eigen types

Former-commit-id: 164557dd2bf8e7b44f649dcff9b7f41f4513f5ab
Alec Jacobson 10 years ago
parent
commit
20a3ad28f1
4 changed files with 59 additions and 1 deletions
  1. 25 0
      include/igl/hsv_to_rgb.cpp
  2. 5 0
      include/igl/hsv_to_rgb.h
  3. 23 0
      include/igl/rgb_to_hsv.cpp
  4. 6 1
      include/igl/rgb_to_hsv.h

+ 25 - 0
include/igl/hsv_to_rgb.cpp

@@ -41,3 +41,28 @@ IGL_INLINE void igl::hsv_to_rgb(
   case 5: r = v; g = p; b = q; break;
   }
 }
+
+template <typename DerivedH, typename DerivedR>
+void igl::hsv_to_rgb(
+  const Eigen::PlainObjectBase<DerivedH> & H,
+  Eigen::PlainObjectBase<DerivedR> & R)
+{
+  assert(H.cols() == 3);
+  R.resize(H.rows(),H.cols());
+  for(typename DerivedH::Index r = 0;r<H.rows();r++)
+  {
+    typename DerivedH::Scalar hsv[3];
+    hsv[0] = H(r,0);
+    hsv[1] = H(r,1);
+    hsv[2] = H(r,2);
+    typename DerivedR::Scalar rgb[3];
+    hsv_to_rgb(hsv,rgb);
+    R(r,0) = rgb[0];
+    R(r,1) = rgb[1];
+    R(r,2) = rgb[2];
+  }
+}
+
+#ifdef IGL_STATIC_LIBRARY
+template void igl::hsv_to_rgb<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+#endif

+ 5 - 0
include/igl/hsv_to_rgb.h

@@ -8,6 +8,7 @@
 #ifndef IGL_HSV_TO_RGB_H
 #define IGL_HSV_TO_RGB_H
 #include "igl_inline.h"
+#include <Eigen/Core>
 namespace igl
 {
   // Convert RGB to HSV
@@ -26,6 +27,10 @@ namespace igl
   IGL_INLINE void hsv_to_rgb( 
     const T & h, const T & s, const T & v, 
     T & r, T & g, T & b);
+  template <typename DerivedH, typename DerivedR>
+  void hsv_to_rgb(
+    const Eigen::PlainObjectBase<DerivedH> & H,
+    Eigen::PlainObjectBase<DerivedR> & R);
 };
 
 #ifndef IGL_STATIC_LIBRARY

+ 23 - 0
include/igl/rgb_to_hsv.cpp

@@ -70,8 +70,31 @@ IGL_INLINE void igl::rgb_to_hsv(const R * rgb, H * hsv)
   }
 }
 
+
+template <typename DerivedR,typename DerivedH>
+IGL_INLINE void igl::rgb_to_hsv(
+  const Eigen::PlainObjectBase<DerivedR> & R,
+  Eigen::PlainObjectBase<DerivedH> & H)
+{
+  assert(R.cols() == 3);
+  H.resize(R.rows(),R.cols());
+  for(typename DerivedR::Index r = 0;r<R.rows();r++)
+  {
+    typename DerivedR::Scalar rgb[3];
+    rgb[0] = R(r,0);
+    rgb[1] = R(r,1);
+    rgb[2] = R(r,2);
+    typename DerivedH::Scalar hsv[3];
+    rgb_to_hsv(rgb,hsv);
+    H(r,0) = hsv[0];
+    H(r,1) = hsv[1];
+    H(r,2) = hsv[2];
+  }
+}
+
 #ifdef IGL_STATIC_LIBRARY
 // Explicit instanciation
 template void igl::rgb_to_hsv<float, double>(float const*, double*);
 template void igl::rgb_to_hsv<double, double>(double const*, double*);
+template void igl::rgb_to_hsv<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
 #endif

+ 6 - 1
include/igl/rgb_to_hsv.h

@@ -1,6 +1,6 @@
 // This file is part of libigl, a simple c++ geometry processing library.
 // 
-// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
+// Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
 // 
 // This Source Code Form is subject to the terms of the Mozilla Public License 
 // v. 2.0. If a copy of the MPL was not distributed with this file, You can 
@@ -8,6 +8,7 @@
 #ifndef IGL_RGB_TO_HSV_H
 #define IGL_RGB_TO_HSV_H
 #include "igl_inline.h"
+#include <Eigen/Core>
 namespace igl
 {
   // Convert RGB to HSV
@@ -22,6 +23,10 @@ namespace igl
   //   v  value value ([0,1])
   template <typename R,typename H>
   IGL_INLINE void rgb_to_hsv(const R * rgb, H * hsv);
+  template <typename DerivedR,typename DerivedH>
+  IGL_INLINE void rgb_to_hsv(
+    const Eigen::PlainObjectBase<DerivedR> & R,
+    Eigen::PlainObjectBase<DerivedH> & H);
 };
 
 #ifndef IGL_STATIC_LIBRARY