Skip to content

Commit

Permalink
Merge pull request #166 from untereiner/fix-types
Browse files Browse the repository at this point in the history
float/double to float32/float64 to be more consistant
  • Loading branch information
pierrekraemer committed Mar 24, 2016
2 parents 54db651 + aa5016a commit 8c3ba0f
Show file tree
Hide file tree
Showing 53 changed files with 245 additions and 242 deletions.
2 changes: 1 addition & 1 deletion benchmarks/multithreading/bench_multithreading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const cgogn::Orbit FACE = Face::ORBIT;
const uint32 ITERATIONS = 1u;

//using Vec3 = Eigen::Vector3d;
using Vec3 = cgogn::geometry::Vec_T<std::array<double,3>>;
using Vec3 = cgogn::geometry::Vec_T<std::array<float64,3>>;

template <typename T>
using VertexAttributeHandler = Map2::VertexAttributeHandler<T>;
Expand Down
4 changes: 2 additions & 2 deletions cgogn/core/container/chunk_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace cgogn
template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, bool>;
template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, uint32>;
template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, unsigned char>;
template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, std::array<float, 3>>;
template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, std::array<double, 3>>;
template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, std::array<float32, 3>>;
template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, std::array<float64, 3>>;

} // namespace cgogn
4 changes: 2 additions & 2 deletions cgogn/core/container/chunk_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,8 @@ class ChunkArray<CHUNKSIZE, bool> : public ChunkArrayGen<CHUNKSIZE>
extern template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, bool>;
extern template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, uint32>;
extern template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, unsigned char>;
extern template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, std::array<float, 3>>;
extern template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, std::array<double, 3>>;
extern template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, std::array<float32, 3>>;
extern template class CGOGN_CORE_API ChunkArray<DEFAULT_CHUNK_SIZE, std::array<float64, 3>>;
#endif // defined(CGOGN_USE_EXTERNAL_TEMPLATES) && (!defined(CORE_CONTAINER_CHUNK_ARRAY_CPP_))

} // namespace cgogn
Expand Down
4 changes: 2 additions & 2 deletions cgogn/core/container/chunk_array_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ class ChunkArrayContainer
* @brief fragmentation of container (size/index of last lines): 100% = no holes
* @return 1 is full filled - 0 is lots of holes
*/
float fragmentation() const
float32 fragmentation() const
{
return float(size()) / float(end());
return float32(size()) / float32(end());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions cgogn/core/container/chunk_array_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ class ChunkArrayFactory
// register_CA<unsigned short>();
// register_CA<unsigned long>();
// register_CA<unsigned long long>();
register_CA<float>();
register_CA<double>();
register_CA<float32>();
register_CA<float64>();
register_CA<std::string>();
register_CA<std::array<double,3>>();
register_CA<std::array<float,3>>();
register_CA<std::array<float32,3>>();
register_CA<std::array<float64,3>>();
// NOT TODO : add Eigen.

known_types_initialized_ = true;
Expand Down
16 changes: 8 additions & 8 deletions cgogn/core/examples/chunk_array/bench_chunk_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ int test5();
*/
class Vec3f
{
float data_[3];
float32 data_[3];

public:

Vec3f()
{}

Vec3f(float x,float y, float z)
Vec3f(float32 x,float32 y, float32 z)
{
data_[0] = x;
data_[1] = y;
Expand All @@ -44,7 +44,7 @@ int test1()

ChunkArrayContainer<BLK_SZ, unsigned char> container;
ChunkArray<BLK_SZ,int32>* att1 = container.add_attribute<int32>("entier");
ChunkArray<BLK_SZ,float>* att2 = container.add_attribute<float>("reel");
ChunkArray<BLK_SZ,float32>* att2 = container.add_attribute<float32>("reel");
ChunkArray<BLK_SZ,Vec3f>* att3 = container.add_attribute<Vec3f>("Vec3f");

for (uint32 i = 0; i < NB_LINES; ++i)
Expand All @@ -53,8 +53,8 @@ int test1()
for(uint32 i = container.begin(); i != container.end(); container.next(i))
{
(*att1)[i] = 1+int32(i);
(*att2)[i] = 3.0f + 0.1f*float(i);
(*att3)[i] = Vec3f(float(i), float(i), float(i));
(*att2)[i] = 3.0f + 0.1f*float32(i);
(*att3)[i] = Vec3f(float32(i), float32(i), float32(i));
}

for (uint32 j = 0; j < 100; ++j)
Expand All @@ -80,7 +80,7 @@ int test2()

ChunkArrayContainer<BLK_SZ, bool> container;
ChunkArray<BLK_SZ,int32>* att1 = container.add_attribute<int32>("entier");
ChunkArray<BLK_SZ,float>* att2 = container.add_attribute<float>("reel");
ChunkArray<BLK_SZ,float32>* att2 = container.add_attribute<float32>("reel");
ChunkArray<BLK_SZ,Vec3f>* att3 = container.add_attribute<Vec3f>("Vec3f");

for (uint32 i = 0; i < NB_LINES; ++i)
Expand All @@ -89,8 +89,8 @@ int test2()
for(uint32 i = container.begin(); i != container.end(); container.next(i))
{
(*att1)[i] = 1+int32(i);
(*att2)[i] = 3.0f + 0.1f*float(i);
(*att3)[i] = Vec3f(float(i), float(i), float(i));
(*att2)[i] = 3.0f + 0.1f*float32(i);
(*att3)[i] = Vec3f(float32(i), float32(i), float32(i));
}

for (uint32 j = 0; j < 100; ++j)
Expand Down
18 changes: 9 additions & 9 deletions cgogn/core/examples/chunk_array/chunk_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ int test1()

ChunkArrayContainer<uint32> container;
ChunkArray<int32>* att1 = container.add_attribute<int32>("entier");
ChunkArray<float>* att2 = container.add_attribute<float>("reel");
ChunkArray<float32>* att2 = container.add_attribute<float32>("reel");

for (uint32 i = 0; i < 41; ++i)
container.insert_lines<1>();

for(uint32 i = container.begin(); i != container.end(); container.next(i))
{
(*att1)[i] = 1+int32(i);
(*att2)[i] = 3.0f + 0.1f*float(i);
(*att2)[i] = 3.0f + 0.1f*float32(i);
}

container.remove_lines<1>(3);
Expand Down Expand Up @@ -212,11 +212,11 @@ int test3()
int test4()
{
std::cout << "############### TEST 4 ###############" << std::endl;
using vecvecdouble = std::vector< std::vector< double > >;
using veclistdouble = std::vector< std::list< double > >;
using vecvecdouble = std::vector< std::vector< float64 > >;
using veclistdouble = std::vector< std::list< float64 > >;
ChunkArrayContainer<uint32> container;
ChunkArray<int32>* att1 = container.add_attribute<int32>("entier");
ChunkArray<float>* att2 = container.add_attribute<float>("reel");
ChunkArray<float32>* att2 = container.add_attribute<float32>("reel");
ChunkArray<bool>* att3 = container.add_attribute<bool>("bools");
ChunkArray<vecvecdouble>* att4 = container.add_attribute<vecvecdouble>("vecvecdouble");
ChunkArray<veclistdouble>* att5 = container.add_attribute<veclistdouble>("veclistdouble");
Expand All @@ -227,10 +227,10 @@ int test4()
for(uint32 i = container.begin(); i != container.end(); container.next(i))
{
(*att1)[i] = 1+int32(i);
(*att2)[i] = 3.0f + 0.1f*float(i);
(*att2)[i] = 3.0f + 0.1f*float32(i);
(*att3).set_value(i, static_cast<bool>(i%2 != 0));
(*att4)[i] = {{3.0 + 0.1*double(i),15.0 + 0.1*double(i)}, {103.0 + 0.1*double(i), 203.0 + 0.1*double(i), 303.0 + 0.1*double(i)}};
(*att5)[i] = {{3.0 + 0.1*double(i),15.0 + 0.1*double(i)}, {103.0 + 0.1*double(i), 203.0 + 0.1*double(i), 303.0 + 0.1*double(i)}};
(*att4)[i] = {{3.0 + 0.1*float64(i),15.0 + 0.1*float64(i)}, {103.0 + 0.1*float64(i), 203.0 + 0.1*float64(i), 303.0 + 0.1*float64(i)}};
(*att5)[i] = {{3.0 + 0.1*float64(i),15.0 + 0.1*float64(i)}, {103.0 + 0.1*float64(i), 203.0 + 0.1*float64(i), 303.0 + 0.1*float64(i)}};
}

container.remove_lines<3>(3);
Expand All @@ -246,7 +246,7 @@ int test4()
ifi.close();

ChunkArray<int32>* load_att1 = cont2.get_attribute<int32>("entier");
ChunkArray<float>* load_att2 = cont2.get_attribute<float>("reel");
ChunkArray<float32>* load_att2 = cont2.get_attribute<float32>("reel");
ChunkArray<bool>* load_att3 = cont2.get_attribute<bool>("bools");
ChunkArray<vecvecdouble>* load_att4 = cont2.get_attribute<vecvecdouble>("vecvecdouble");
ChunkArray<veclistdouble>* load_att5 = cont2.get_attribute<veclistdouble>("veclistdouble");
Expand Down
10 changes: 5 additions & 5 deletions cgogn/core/examples/chunk_array/chunk_array2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using ChunkArray = cgogn::ChunkArray<SIZE, T>;
using ChunkArrayContainer = cgogn::ChunkArrayContainer<SIZE, uint32>;
using ChunkArrayFactory = cgogn::ChunkArrayFactory<SIZE>;

using DoubleVecList = std::list< std::vector< double > >;
using DoubleVecList = std::list< std::vector< float64 > >;
using StringListVec = std::vector< std::list < std::string > >;
using StringArray = std::array< std::string, 2>;

Expand All @@ -27,7 +27,7 @@ int test_save()

ChunkArrayContainer container;

ChunkArray<float>* att1 = container.add_attribute<float>("float");
ChunkArray<float32>* att1 = container.add_attribute<float32>("float32");
ChunkArray<std::string>* att4 = container.add_attribute<std::string>("std::string");
ChunkArray<DoubleVecList>* att2 = container.add_attribute<DoubleVecList>("ListVecDouble");
ChunkArray<StringListVec>* att3 = container.add_attribute<StringListVec>("VecListString");
Expand All @@ -38,10 +38,10 @@ int test_save()

for(uint32 i = container.begin(); i != container.end(); container.next(i))
{
(*att1)[i] = 0.1f*float(i);
(*att1)[i] = 0.1f*float32(i);
(*att4)[i] = std::string(3,char('Z'-i));

(*att2)[i] = {{3.0 + 0.1*double(i),15.0 + 0.1*double(i)}, {103.0 + 0.1*double(i), 203.0 + 0.1*double(i), 303.0 + 0.1*double(i)}};
(*att2)[i] = {{3.0 + 0.1*float64(i),15.0 + 0.1*float64(i)}, {103.0 + 0.1*float64(i), 203.0 + 0.1*float64(i), 303.0 + 0.1*float64(i)}};

(*att3)[i] = {{"riri","riri"},{"fifi","fifi"},{"loulou","loulou"}};

Expand Down Expand Up @@ -127,7 +127,7 @@ int test_load(bool with_register)
cont2.load(ifi);
ifi.close();

ChunkArray<float>* att1 = cont2.get_attribute<float>("float");
ChunkArray<float32>* att1 = cont2.get_attribute<float32>("float32");
ChunkArray<std::string>* att4 = cont2.get_attribute<std::string>("std::string");
ChunkArray<DoubleVecList>* att2 = cont2.get_attribute<DoubleVecList>("ListVecDouble");
ChunkArray<StringListVec>* att3 = cont2.get_attribute<StringListVec>("VecListString");
Expand Down
26 changes: 13 additions & 13 deletions cgogn/core/examples/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,39 @@ using Map3 = CMap3<DefaultMapTraits>;


template <typename MAP>
void fonc_const(const typename MAP::template VertexAttributeHandler<float>& ah);
void fonc_const(const typename MAP::template VertexAttributeHandler<float32>& ah);

template <typename MAP>
void fonc_non_const(typename MAP::template VertexAttributeHandler<float>& ah);
void fonc_non_const(typename MAP::template VertexAttributeHandler<float32>& ah);

template <typename MAP>
int test1(MAP& map);


template <typename MAP>
void fonc_const(const typename MAP::template VertexAttributeHandler<float>& ah)
void fonc_const(const typename MAP::template VertexAttributeHandler<float32>& ah)
{
for (const float& f : ah)
for (const float32& f : ah)
{
std::cout << f << std::endl;
}

// equivalent to
for (typename MAP::template VertexAttributeHandler<float>::const_iterator it = ah.begin(); it != ah.end(); ++it)
for (typename MAP::template VertexAttributeHandler<float32>::const_iterator it = ah.begin(); it != ah.end(); ++it)
std::cout << *it << std::endl;
}

template <typename MAP>
void fonc_non_const(typename MAP::template VertexAttributeHandler<float>& ah)
void fonc_non_const(typename MAP::template VertexAttributeHandler<float32>& ah)
{
for (float& f : ah)
for (float32& f : ah)
{
f *= 2.0f;
std::cout << f << std::endl;
}

// equivalent to
for (typename MAP::template VertexAttributeHandler<float>::iterator it = ah.begin(); it != ah.end(); ++it)
for (typename MAP::template VertexAttributeHandler<float32>::iterator it = ah.begin(); it != ah.end(); ++it)
{
*it /= 2.0f;
}
Expand All @@ -60,12 +60,12 @@ int test1(MAP& map)
using Face = typename MAP::Face;

// add an attribute on vertex of map with
typename MAP::template VertexAttributeHandler<float> ah = map.template add_attribute<float, Vertex::ORBIT>("floats");
typename MAP::template VertexAttributeHandler<float32> ah = map.template add_attribute<float32, Vertex::ORBIT>("floats");

typename MAP::template FaceAttributeHandler<float> ahf = map.template add_attribute<float, Face::ORBIT>("floats");
typename MAP::template FaceAttributeHandler<float32> ahf = map.template add_attribute<float32, Face::ORBIT>("floats");

// get attribute and change type (dangerous!)
typename MAP::template VertexAttributeHandler<int32> ahf2 = map.template get_attribute_force_type<int32,float, Vertex::ORBIT>("floats");
typename MAP::template VertexAttributeHandler<int32> ahf2 = map.template get_attribute_force_type<int32,float32, Vertex::ORBIT>("floats");

map.remove_attribute(ahf);
std::cout << "ahf valid : " << std::boolalpha << ahf.is_valid() << std::endl;
Expand Down Expand Up @@ -114,7 +114,7 @@ int test1(MAP& map)

// get ChunkArrayContainer -> get ChunkArray -> fill
// typename MAP::template ChunkArrayContainer<uint32>& container = map.get_attribute_container(MAP::Vertex);
// typename MAP::template ChunkArray<float>* att = container.template get_attribute<float>("floats");
// typename MAP::template ChunkArray<float32>* att = container.template get_attribute<float32>("floats");
// for (uint32 i = 0; i < 10; ++i)
// container.template insert_lines<1>();
for (auto& v : ah)
Expand All @@ -127,7 +127,7 @@ int test1(MAP& map)
fonc_const<MAP>(ah);

// // traverse container with for range
// for (float f:ah)
// for (float32 f:ah)
// std::cout << f << std::endl;

return 0;
Expand Down
3 changes: 3 additions & 0 deletions cgogn/core/utils/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ using uint16 = std::uint16_t;
using uint32 = std::uint32_t;
using uint64 = std::uint64_t;

using float32 = float;
using float64 = double;

}

using namespace numerics;
Expand Down
12 changes: 6 additions & 6 deletions cgogn/core/utils/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,24 @@ inline std::int64_t swap_endianness64(std::int64_t x)
(step16 & 0xFF00FF00FF00FF00ULL) >> 8);
}

inline float swap_endianness_float(float x)
inline float32 swap_endianness_float(float32 x)
{
union U32F32
{
std::uint32_t as_u32;
float as_f32;
float32 as_f32;
} u;
u.as_f32 = x;
u.as_u32 = swap_endianness32u(u.as_u32);
return u.as_f32;
}

inline double swap_endianness_double(double x)
inline float64 swap_endianness_double(float64 x)
{
union U64F64
{
std::uint64_t as_u64;
double as_f64;
float64 as_f64;
} u;
u.as_f64 = x;
u.as_u64 = swap_endianness64u(u.as_u64);
Expand Down Expand Up @@ -185,15 +185,15 @@ inline std::int64_t swap_endianness_if(std::int64_t x)
}

template< bool COND>
inline float swap_endianness_if(float x)
inline float32 swap_endianness_if(float32 x)
{
if (COND)
return swap_endianness_float(x);
return x;
}

template< bool COND>
inline double swap_endianness_if(double x)
inline float64 swap_endianness_if(float64 x)
{
if (COND)
return swap_endianness_double(x);
Expand Down
4 changes: 2 additions & 2 deletions cgogn/geometry/types/bounding_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace geometry

template class CGOGN_GEOMETRY_API BoundingBox<Eigen::Vector3d>;
template class CGOGN_GEOMETRY_API BoundingBox<Eigen::Vector3f>;
template class CGOGN_GEOMETRY_API BoundingBox<Vec_T<std::array<double,3>>>;
template class CGOGN_GEOMETRY_API BoundingBox<Vec_T<std::array<float,3>>>;
template class CGOGN_GEOMETRY_API BoundingBox<Vec_T<std::array<float32,3>>>;
template class CGOGN_GEOMETRY_API BoundingBox<Vec_T<std::array<float64,3>>>;


} // namespace geometry
Expand Down
4 changes: 2 additions & 2 deletions cgogn/geometry/types/bounding_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ std::istream& operator>>(std::istream& in, BoundingBox<VEC_T>& bb)
#if defined(CGOGN_USE_EXTERNAL_TEMPLATES) && (!defined(GEOMETRY_BOUNDING_BOX_CPP_))
//extern template class CGOGN_GEOMETRY_API BoundingBox<Eigen::Vector3d>;
//extern template class CGOGN_GEOMETRY_API BoundingBox<Eigen::Vector3f>;
extern template class CGOGN_GEOMETRY_API BoundingBox<Vec_T<std::array<double, 3>>>;
extern template class CGOGN_GEOMETRY_API BoundingBox<Vec_T<std::array<float,3>>>;
extern template class CGOGN_GEOMETRY_API BoundingBox<Vec_T<std::array<float32, 3>>>;
extern template class CGOGN_GEOMETRY_API BoundingBox<Vec_T<std::array<float64,3>>>;
#endif // defined(CGOGN_USE_EXTERNAL_TEMPLATES) && (!defined(GEOMETRY_BOUNDING_BOX_CPP_))

} // namespace geometry
Expand Down
8 changes: 4 additions & 4 deletions cgogn/geometry/types/geometry_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ struct vector_traits<Eigen::Matrix<Scalar_,Rows,1,Options,Rows,1>>
// specialization 3 & 4: is for uniform manip of vec & scalar (vbo)
// specialization 3 : float
template<>
struct vector_traits<float>
struct vector_traits<float32>
{
static const std::size_t SIZE = 1;
using Scalar = float;
using Scalar = float32;
};

// specialization 4 : double
template<>
struct vector_traits<double>
struct vector_traits<float64>
{
static const std::size_t SIZE = 1;
using Scalar = double;
using Scalar = float64;
};

template<typename T, typename Enable = void>
Expand Down
Loading

0 comments on commit 8c3ba0f

Please sign in to comment.