GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/hpp/fcl/serialization/convex.h Lines: 27 28 96.4 %
Date: 2024-02-09 12:57:42 Branches: 21 40 52.5 %

Line Branch Exec Source
1
//
2
// Copyright (c) 2022 INRIA
3
//
4
5
#ifndef HPP_FCL_SERIALIZATION_CONVEX_H
6
#define HPP_FCL_SERIALIZATION_CONVEX_H
7
8
#include "hpp/fcl/shape/convex.h"
9
10
#include "hpp/fcl/serialization/fwd.h"
11
#include "hpp/fcl/serialization/geometric_shapes.h"
12
#include "hpp/fcl/serialization/memory.h"
13
#include "hpp/fcl/serialization/triangle.h"
14
#include "hpp/fcl/serialization/quadrilateral.h"
15
16
namespace boost {
17
namespace serialization {
18
19
namespace internal {
20
struct ConvexBaseAccessor : hpp::fcl::ConvexBase {
21
  typedef hpp::fcl::ConvexBase Base;
22
  using Base::own_storage_;
23
};
24
25
}  // namespace internal
26
27
template <class Archive>
28
4
void serialize(Archive &ar, hpp::fcl::ConvexBase &convex_base,
29
               const unsigned int /*version*/) {
30
  using namespace hpp::fcl;
31
32
  typedef internal::ConvexBaseAccessor Accessor;
33
4
  Accessor &accessor = reinterpret_cast<Accessor &>(convex_base);
34
35
4
  ar &make_nvp("base", boost::serialization::base_object<hpp::fcl::ShapeBase>(
36
4
                           convex_base));
37
4
  const unsigned int num_points_previous = convex_base.num_points;
38
4
  ar &make_nvp("num_points", convex_base.num_points);
39
40
  if (Archive::is_loading::value) {
41
2
    if (num_points_previous != convex_base.num_points ||
42
        !accessor.own_storage_) {
43
2
      delete[] convex_base.points;
44

10
      convex_base.points = new hpp::fcl::Vec3f[convex_base.num_points];
45
2
      accessor.own_storage_ = true;
46
    }
47
  }
48
49
  {
50
    typedef Eigen::Matrix<FCL_REAL, 3, Eigen::Dynamic> MatrixPoints;
51
4
    Eigen::Map<MatrixPoints> points_map(
52
4
        reinterpret_cast<double *>(convex_base.points), 3,
53
4
        convex_base.num_points);
54

4
    ar &make_nvp("points", points_map);
55
  }
56
57
4
  ar &make_nvp("center", convex_base.center);
58
  // We don't save neighbors as they will be computed directly by calling
59
  // fillNeighbors.
60
4
}
61
62
namespace internal {
63
template <typename PolygonT>
64
struct ConvexAccessor : hpp::fcl::Convex<PolygonT> {
65
  typedef hpp::fcl::Convex<PolygonT> Base;
66
  using Base::fillNeighbors;
67
};
68
69
}  // namespace internal
70
71
template <class Archive, typename PolygonT>
72
4
void serialize(Archive &ar, hpp::fcl::Convex<PolygonT> &convex_,
73
               const unsigned int /*version*/) {
74
  using namespace hpp::fcl;
75
  typedef internal::ConvexAccessor<PolygonT> Accessor;
76
77
4
  Accessor &convex = reinterpret_cast<Accessor &>(convex_);
78
4
  ar &make_nvp("base", boost::serialization::base_object<ConvexBase>(convex));
79
80
4
  const unsigned int num_polygons_previous = convex.num_polygons;
81
4
  ar &make_nvp("num_polygons", convex.num_polygons);
82
83
  if (Archive::is_loading::value) {
84
2
    if (num_polygons_previous != convex.num_polygons) {
85
2
      delete[] convex.polygons;
86

10
      convex.polygons = new PolygonT[convex.num_polygons];
87
    }
88
  }
89
90
4
  ar &make_array<PolygonT>(convex.polygons, convex.num_polygons);
91
92
2
  if (Archive::is_loading::value) convex.fillNeighbors();
93
4
}
94
95
}  // namespace serialization
96
}  // namespace boost
97
98
namespace hpp {
99
namespace fcl {
100
101
// namespace internal {
102
// template <typename BV>
103
// struct memory_footprint_evaluator< ::hpp::fcl::BVHModel<BV> > {
104
//   static size_t run(const ::hpp::fcl::BVHModel<BV> &bvh_model) {
105
//     return static_cast<size_t>(bvh_model.memUsage(false));
106
//   }
107
// };
108
// }  // namespace internal
109
110
}  // namespace fcl
111
}  // namespace hpp
112
113
#endif  // ifndef HPP_FCL_SERIALIZATION_CONVEX_H