homogeneous_point.hpp
Go to the documentation of this file.
00001 
00011 /*****************************************************************************
00012 ** Ifdefs
00013 *****************************************************************************/
00014 
00015 #ifndef ECL_GEOMETRY_HOMOGENEOUS_POINT_HPP_
00016 #define ECL_GEOMETRY_HOMOGENEOUS_POINT_HPP_
00017 
00018 /*****************************************************************************
00019 ** Includes
00020 *****************************************************************************/
00021 
00022 #include <ecl/mpl.hpp>
00023 #include <ecl/type_traits.hpp>
00024 
00025 #include <ecl/config/macros.hpp>
00026 #include <ecl/exceptions/standard_exception.hpp>
00027 #include <ecl/linear_algebra.hpp>
00028 #include <ecl/math.hpp>
00029 
00030 /*****************************************************************************
00031 ** Namespaces
00032 *****************************************************************************/
00033 
00034 namespace ecl {
00035 
00036 /*****************************************************************************
00037 ** Interface [HomogeneousPoint]
00038 *****************************************************************************/
00045 template <typename T, typename Enable = void>
00046 class HomogeneousPoint : public ecl::FailedObject {};
00047 
00055 template<typename T>
00056 class HomogeneousPoint<T, typename ecl::enable_if< ecl::is_float<T> >::type> {
00057 public:
00058     EIGEN_MAKE_ALIGNED_OPERATOR_NEW // needed for 16B alignment
00062         HomogeneousPoint(const T &value = T()) {
00063                 elements.template block<3,1>(0,0) = ecl::linear_algebra::Matrix<T,3,1>::Constant(value);
00064                 elements(3,0) = 1.0;
00065         }
00074         HomogeneousPoint(const ecl::linear_algebra::Matrix<T,3,1> &vec) {
00075                 elements.template block<3,1>(0,0) = vec;
00076                 elements[3] = 1.0;
00077         }
00085         HomogeneousPoint(const ecl::linear_algebra::Matrix<T,4,1> &vec) : elements(vec) {
00086                 ecl_assert_throw(elements[3] == 1.0, ecl::StandardException(LOC,ecl::InvalidInputError));
00087         }
00095         HomogeneousPoint(const T &x_i, const T &y_i, const T &z_i) {
00096                 elements << x_i, y_i, z_i, 1.0;
00097         }
00098 
00099         virtual ~HomogeneousPoint() {}
00100 
00101     /*********************
00102     ** Assignment
00103     **********************/
00117         ecl::linear_algebra::CommaInitializer< ecl::linear_algebra::Matrix<T,4,1> > operator<<(const T &value) {
00118                 return elements.operator<<(value);
00119     }
00120 
00128         ecl::linear_algebra::Matrix<T,4,1>& positionVector() { return elements; }
00129 
00137         const ecl::linear_algebra::Matrix<T,4,1>& positionVector() const { return elements; }
00138 
00144         const T& x() const { return elements[0]; }
00150         const T& y() const { return elements[1]; }
00156         const T& z() const { return elements[2]; }
00162         T x() { return elements[0]; }
00168         T y() { return elements[1]; }
00174         T z() { return elements[2]; }
00175 
00176         void x(const T& value) { elements[0] = value; } 
00177         void y(const T& value) { elements[1] = value; } 
00178         void z(const T& value) { elements[2] = value; } 
00180         template <typename OutputStream, typename Type>
00181         friend OutputStream& operator<<(OutputStream &ostream , const HomogeneousPoint<Type> &point);
00182 
00183 private:
00184         ecl::linear_algebra::Matrix<T,4,1> elements;
00185 };
00186 
00187 typedef HomogeneousPoint<float> HomogeneousPointf;  
00188 typedef HomogeneousPoint<double> HomogeneousPointd;  
00190 /*********************
00191 ** Streaming
00192 **********************/
00200 template <typename OutputStream, typename Type>
00201 OutputStream& operator<<(OutputStream &ostream , const HomogeneousPoint<Type> &point) {
00202         ostream << "[ " << point.x() << " " << point.y() << " " << point.z() << " ]";
00203         return ostream;
00204 }
00205 }  // namespace ecl
00206 
00207 #endif /* ECL_GEOMETRY_HOMOGENEOUS_POINT_HPP_ */


ecl_geometry
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:51