NURBSDataVector.hh 5.06 KB
Newer Older
1 2 3 4 5
/***********************************************************************
 * Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. *
 * All rights reserved.                                                *
 * Distributed under the terms of the MIT License (see LICENSE.TXT).   *
 **********************************************************************/
6

7 8 9 10
// See http://www.graphics.rwth-aachen.de/redmine/projects/acgl/wiki/ACGL_compile_time_settings
// for a comment what unsupported means.
#ifdef ACGL_INCLUDE_UNSUPPORTED

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#ifndef ACGL_SCENE_NURBSDATAVECTOR_HH
#define ACGL_SCENE_NURBSDATAVECTOR_HH

#include <ACGL/ACGL.hh>
#include <ACGL/Math/Math.hh>
#include <ACGL/Utils/Log.hh>

namespace ACGL{
namespace Scene{

template<uint_t DATA_DIMENSION>
class NURBSDataVector
{
public:
    NURBSDataVector(void) {}
    NURBSDataVector(const float* _data)
    {
        for(uint_t i = 0; i < DATA_DIMENSION; ++i)
            data[i] = _data[i];
    }
    virtual ~NURBSDataVector(void) {}

    static const uint_t sDataDimension;
    uint_t getDataDimension (void) const { return sDataDimension;}

    const NURBSDataVector& operator+=(const NURBSDataVector<DATA_DIMENSION>& _v)
    {
        for(uint_t i = 0; i < DATA_DIMENSION; ++i)
            data[i] += _v.data[i];
        return *this;
    }

    const NURBSDataVector& operator-=(const NURBSDataVector<DATA_DIMENSION>& _v)
    {
        for(uint_t i = 0; i < DATA_DIMENSION; ++i)
            data[i] -= _v.data[i];
        return *this;
    }

50
    const NURBSDataVector& operator*=(const NURBSDataVector<DATA_DIMENSION>& _v)
51 52
    {
        for(uint_t i = 0; i < DATA_DIMENSION; ++i)
53 54
            data[i] *= _v.data[i];
        return *this;
55 56
    }

57
    const NURBSDataVector& operator/=(const NURBSDataVector<DATA_DIMENSION>& _v)
58 59
    {
        for(uint_t i = 0; i < DATA_DIMENSION; ++i)
60
            data[i] /= _v.data[i];
61 62 63
        return *this;
    }

64
    const NURBSDataVector& operator*=(float _value)
65 66
    {
        for(uint_t i = 0; i < DATA_DIMENSION; ++i)
67 68
            data[i] *= _value;
        return *this;
69 70
    }

71
    const NURBSDataVector& operator/=(float _value)
72 73
    {
        for(uint_t i = 0; i < DATA_DIMENSION; ++i)
74
            data[i] /= _value;
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
        return *this;
    }

    float getLength (void) const
    {
        double sum = 0.0;
        for(uint_t i = 0; i < DATA_DIMENSION; ++i)
            sum += data[i] * data[i];
        return ACGL::Math::Functions::sqrt(sum);
    }

    float operator[](int_t _id) const
    {
        return data[_id];
    }

    float data[DATA_DIMENSION];
};

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
template<uint_t DATA_DIMENSION>
NURBSDataVector<DATA_DIMENSION> operator+(const NURBSDataVector<DATA_DIMENSION>& _lhs, const NURBSDataVector<DATA_DIMENSION>& _rhs)
{
    NURBSDataVector<DATA_DIMENSION> v;
    for(uint_t i = 0; i < DATA_DIMENSION; ++i)
        v.data[i] = _lhs.data[i] + _rhs.data[i];
    return v;
}

template<uint_t DATA_DIMENSION>
NURBSDataVector<DATA_DIMENSION> operator-(const NURBSDataVector<DATA_DIMENSION>& _lhs, const NURBSDataVector<DATA_DIMENSION>& _rhs)
{
    NURBSDataVector<DATA_DIMENSION> v;
    for(uint_t i = 0; i < DATA_DIMENSION; ++i)
        v.data[i] = _lhs.data[i] - _rhs.data[i];
    return v;
}

template<uint_t DATA_DIMENSION>
NURBSDataVector<DATA_DIMENSION> operator*(const NURBSDataVector<DATA_DIMENSION>& _lhs, const NURBSDataVector<DATA_DIMENSION>& _rhs)
{
    NURBSDataVector<DATA_DIMENSION> v;
    for(uint_t i = 0; i < DATA_DIMENSION; ++i)
        v.data[i] = _lhs.data[i] * _rhs.data[i];
    return v;
}

template<uint_t DATA_DIMENSION>
NURBSDataVector<DATA_DIMENSION> operator/(const NURBSDataVector<DATA_DIMENSION>& _lhs, const NURBSDataVector<DATA_DIMENSION>& _rhs)
{
    NURBSDataVector<DATA_DIMENSION> v;
    for(uint_t i = 0; i < DATA_DIMENSION; ++i)
        v.data[i] = _lhs.data[i] / _rhs.data[i];
    return v;
}

template<uint_t DATA_DIMENSION>
NURBSDataVector<DATA_DIMENSION> operator*(const NURBSDataVector<DATA_DIMENSION>& _lhs, float _rhs)
{
    NURBSDataVector<DATA_DIMENSION> v;
    for(uint_t i = 0; i < DATA_DIMENSION; ++i)
        v.data[i] = _lhs.data[i] * _rhs;
    return v;
}

template<uint_t DATA_DIMENSION>
NURBSDataVector<DATA_DIMENSION> operator*(float _lhs, const NURBSDataVector<DATA_DIMENSION>& _rhs)
{
    NURBSDataVector<DATA_DIMENSION> v;
    for(uint_t i = 0; i < DATA_DIMENSION; ++i)
        v.data[i] = _lhs * _rhs.data[i];
    return v;
}

template<uint_t DATA_DIMENSION>
NURBSDataVector<DATA_DIMENSION> operator/(const NURBSDataVector<DATA_DIMENSION>& _lhs, float _rhs)
{
    NURBSDataVector<DATA_DIMENSION> v;
    for(uint_t i = 0; i < DATA_DIMENSION; ++i)
        v.data[i] = _lhs.data[i] / _rhs;
    return v;
}

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
template<uint_t DATA_DIMENSION>
const uint_t NURBSDataVector<DATA_DIMENSION>::sDataDimension = DATA_DIMENSION;

template<uint_t DATA_DIMENSION>
std::ostream& operator<<(std::ostream& _os, const NURBSDataVector<DATA_DIMENSION>& _v)
{
    _os << "(";
    for(uint_t i = 0; i < DATA_DIMENSION; ++i)
    {
        _os << _v.data[i];
        if(i + 1 < DATA_DIMENSION)
            _os << ", ";
    }
    _os << ")";
    return _os;
}


} // Scene
} // ACGL

#endif // ACGL_SCENE_NURBSDATAVECTOR_HH
179 180

#endif