2019-09-17 11:21:35 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2018 Michal Fratczak
|
|
|
|
|
|
|
|
This file is part of habdec.
|
|
|
|
|
|
|
|
habdec is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
habdec is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with habdec. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "CompressedVector.h"
|
|
|
|
|
|
|
|
namespace habdec
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
template<>
|
2019-09-17 20:24:16 +00:00
|
|
|
void CompressedVector<unsigned char>::copyValues(const std::vector<unsigned char>& rhs, double i_min, double i_max)
|
2019-09-17 11:21:35 +00:00
|
|
|
{
|
|
|
|
if(!rhs.size())
|
|
|
|
{
|
|
|
|
values_.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
values_.resize(rhs.size());
|
|
|
|
std::copy(rhs.begin(), rhs.end(), values_.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
template<>
|
2019-09-17 20:24:16 +00:00
|
|
|
void CompressedVector<uint16_t>::copyValues(const std::vector<uint16_t>& rhs, double i_min, double i_max)
|
2019-09-17 11:21:35 +00:00
|
|
|
{
|
|
|
|
if(!rhs.size())
|
|
|
|
{
|
|
|
|
values_.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
values_.resize(rhs.size());
|
|
|
|
std::copy(rhs.begin(), rhs.end(), values_.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
template<>
|
2019-09-17 20:24:16 +00:00
|
|
|
void CompressedVector<float>::copyValues(const std::vector<float>& rhs, double i_min, double i_max)
|
2019-09-17 11:21:35 +00:00
|
|
|
{
|
|
|
|
if(!rhs.size())
|
|
|
|
{
|
2019-09-17 20:24:16 +00:00
|
|
|
values_.clear();
|
2019-09-17 11:21:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-09-17 20:24:16 +00:00
|
|
|
values_.resize(rhs.size());
|
|
|
|
std::copy(rhs.begin(), rhs.end(), values_.begin());
|
2019-09-17 11:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-17 20:24:16 +00:00
|
|
|
// specialization: float --> unsigned char
|
2019-09-17 11:21:35 +00:00
|
|
|
template<>
|
|
|
|
template<>
|
2019-09-17 20:24:16 +00:00
|
|
|
void CompressedVector<unsigned char>::copyValues(const std::vector<float>& rhs, double i_min, double i_max)
|
2019-09-17 11:21:35 +00:00
|
|
|
{
|
2019-09-17 20:24:16 +00:00
|
|
|
// std::cout<<"specialization: float --> unsigned char"<<std::endl;
|
2019-09-17 11:21:35 +00:00
|
|
|
values_.clear();
|
|
|
|
// normalized_ = true; // ALWAYS NORMALIZED FOR NON-FLOAT TYPES
|
|
|
|
|
|
|
|
if(!rhs.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
values_.reserve(rhs.size());
|
|
|
|
for(auto rhs_v : rhs)
|
|
|
|
{
|
|
|
|
// if(!rhs.normalized_)
|
2019-09-17 20:24:16 +00:00
|
|
|
rhs_v = float(rhs_v - i_min) / (i_max - i_min);
|
2019-09-17 11:21:35 +00:00
|
|
|
unsigned char v_out = rhs_v * std::numeric_limits<unsigned char>::max();
|
|
|
|
values_.push_back(v_out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-17 20:24:16 +00:00
|
|
|
// specialization: float --> uint16_t
|
2019-09-17 11:21:35 +00:00
|
|
|
template<>
|
|
|
|
template<>
|
2019-09-17 20:24:16 +00:00
|
|
|
void CompressedVector<uint16_t>::copyValues(const std::vector<float>& rhs, double i_min, double i_max)
|
2019-09-17 11:21:35 +00:00
|
|
|
{
|
2019-09-17 20:24:16 +00:00
|
|
|
// std::cout<<"specialization: float --> uint16_t"<<std::endl;
|
2019-09-17 11:21:35 +00:00
|
|
|
values_.clear();
|
|
|
|
// normalized_ = true; // ALWAYS NORMALIZED FOR NON-FLOAT TYPES
|
|
|
|
|
|
|
|
if(!rhs.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
values_.reserve(rhs.size());
|
|
|
|
for(auto rhs_v : rhs)
|
|
|
|
{
|
|
|
|
// if(!rhs.normalized_)
|
2019-09-17 20:24:16 +00:00
|
|
|
rhs_v = float(rhs_v - i_min) / (i_max - i_min);
|
2019-09-17 11:21:35 +00:00
|
|
|
uint16_t v_out = rhs_v * std::numeric_limits<uint16_t>::max();
|
|
|
|
values_.push_back(v_out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-17 20:24:16 +00:00
|
|
|
|
2019-09-17 11:21:35 +00:00
|
|
|
// specialization: unsigned char --> float
|
|
|
|
template<>
|
|
|
|
template<>
|
2019-09-17 20:24:16 +00:00
|
|
|
void CompressedVector<float>::copyValues(const std::vector<unsigned char>& rhs, double i_min, double i_max)
|
2019-09-17 11:21:35 +00:00
|
|
|
{
|
|
|
|
// std::cout<<"specialization: unsigned char --> float"<<std::endl;
|
|
|
|
values_.clear();
|
|
|
|
// normalized_ = true; // ALWAYS NORMALIZED FOR NON-FLOAT TYPES
|
|
|
|
|
|
|
|
if(!rhs.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
values_.reserve(rhs.size());
|
|
|
|
for(auto rhs_v : rhs)
|
|
|
|
{
|
|
|
|
float rhs_v_0_1 = float(rhs_v) / std::numeric_limits<unsigned char>::max();
|
|
|
|
values_.push_back(rhs_v_0_1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// specialization: uint16_t --> float
|
|
|
|
template<>
|
|
|
|
template<>
|
2019-09-17 20:24:16 +00:00
|
|
|
void CompressedVector<float>::copyValues(const std::vector<uint16_t>& rhs, double i_min, double i_max)
|
2019-09-17 11:21:35 +00:00
|
|
|
{
|
|
|
|
// std::cout<<"specialization: uint16_t --> float"<<std::endl;
|
|
|
|
values_.clear();
|
|
|
|
// normalized_ = true; // ALWAYS NORMALIZED FOR NON-FLOAT TYPES
|
|
|
|
|
|
|
|
if(!rhs.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
values_.reserve(rhs.size());
|
|
|
|
for(auto rhs_v : rhs)
|
|
|
|
{
|
|
|
|
float rhs_v_0_1 = float(rhs_v) / std::numeric_limits<uint16_t>::max();
|
|
|
|
values_.push_back(rhs_v_0_1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace habdec
|