| 159 | #endif |
| 160 | |
| 161 | bool CgalKernel::convert(const taxonomy::shell::ptr l, cgal_shape_t& shape) { |
| 162 | for (auto& f : l->children) { |
| 163 | if (f->basis && f->basis->kind() != taxonomy::PLANE) { |
| 164 | Logger::Error("CGAL Kernel: Non-planar faces not supported at the moment"); |
| 165 | throw not_supported_error(); |
| 166 | } |
| 167 | for (auto& w : f->children) { |
| 168 | for (auto& e : w->children) { |
| 169 | if (e->basis && e->basis->kind() == taxonomy::BSPLINE_CURVE) { |
| 170 | Logger::Error("CGAL Kernel: B-spline edge curves not supported at the moment"); |
| 171 | throw not_supported_error(); |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | if (false && l->children.size() > 100) { |
| 177 | static double inf = 1.e9; // std::numeric_limits<double>::infinity(); |
| 178 | std::pair<Eigen::Vector3d, Eigen::Vector3d> minmax( |
| 179 | Eigen::Vector3d(+inf, +inf, +inf), |
| 180 | Eigen::Vector3d(-inf, -inf, -inf) |
| 181 | ); |
| 182 | size_t num_points = 0; |
| 183 | visit_2<taxonomy::point3, taxonomy::shell>(l, [&minmax, &num_points](const taxonomy::point3::ptr p) { |
| 184 | auto& c = p->ccomponents(); |
| 185 | ++num_points; |
| 186 | for (int i = 0; i < 3; ++i) { |
| 187 | if (c(i) < minmax.first(i)) { |
| 188 | minmax.first(i) = c(i); |
| 189 | } |
| 190 | if (c(i) > minmax.second(i)) { |
| 191 | minmax.second(i) = c(i); |
| 192 | } |
| 193 | } |
| 194 | }); |
| 195 | auto diag = minmax.second - minmax.first; |
| 196 | double volume = diag(0) * diag(1) * diag(2); |
| 197 | // @todo volume van be zero also.. |
| 198 | double density = num_points / volume; |
| 199 | Logger::Notice("Density " + boost::lexical_cast<std::string>(density), l->instance); |
| 200 | if (density > 5000) { |
| 201 | Logger::Notice("Substituted element with " + boost::lexical_cast<std::string>(density) + " vertices / m3 with a bounding box"); |
| 202 | CGAL::Point_3<Kernel_> lower(minmax.first(0), minmax.first(1), minmax.first(2)); |
| 203 | CGAL::Point_3<Kernel_> upper(minmax.second(0), minmax.second(1), minmax.second(2)); |
| 204 | shape = utils::create_cube(lower, upper); |
| 205 | return true; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | std::list<cgal_face_t> face_list; |
| 210 | for (auto& f : l->children) { |
| 211 | bool success = false; |
| 212 | try { |
| 213 | success = convert(f, face_list); |
| 214 | } catch (...) {} |
| 215 | |
| 216 | if (!success) { |
| 217 | Logger::Message(Logger::LOG_WARNING, "Failed to convert face:", f->instance); |
| 218 | continue; |
nothing calls this directly
no test coverage detected