31 #ifndef SHARK_ALGORITHMS_DIRECTSEARCH_HYPERVOLUMECALCULATOR_3D_H 32 #define SHARK_ALGORITHMS_DIRECTSEARCH_HYPERVOLUMECALCULATOR_3D_H 51 template<
typename Set,
typename VectorType >
53 if (points.empty())
return 0.0;
57 std::vector<VectorType>
set;
58 for (std::size_t i=0; i<points.size(); i++)
61 if (p[0] < refPoint[0] && p[1] < refPoint[1] && p[2] < refPoint[2])
set.push_back(p);
63 if (
set.empty())
return 0.0;
64 std::sort(
set.begin(),
set.end(),
66 {
return (x[2] < y[2]); }
70 std::map<double, double> front2D;
72 front2D[x0[0]] = x0[1];
73 double prev_x2 = x0[2];
74 double area = (refPoint[0] - x0[0]) * (refPoint[1] - x0[1]);
78 for (
size_t i=1; i<
set.size(); i++)
80 assert(! front2D.empty());
86 double t = refPoint[1];
87 std::map<double, double>::iterator right = front2D.lower_bound(x[0]);
88 std::map<double, double>::iterator left = right;
89 if (right == front2D.end())
96 if (right->first == x[0])
100 else if (left != front2D.begin())
106 if (x[1] >= t)
continue;
109 volume += area * (x[2] - prev_x2);
112 while (right != front2D.end() && right->second >= x[1])
114 std::map<double, double>::iterator tmp = right;
116 const double r = (right == front2D.end()) ? refPoint[0] : right->first;
117 area -= (r - tmp->first) * (t - tmp->second);
122 const double r = (right == front2D.end()) ? refPoint[0] : right->first;
123 area += (r - x[0]) * (t - x[1]);
124 front2D[x[0]] = x[1];
131 volume += area * (refPoint[2] - prev_x2);