// Copyright (c) 2022 INRIA Sophia-Antipolis (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org). // // $URL$ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Julian Stahl #ifndef CGAL_IMPLICIT_CARTESIAN_GRID_DOMAIN_H #define CGAL_IMPLICIT_CARTESIAN_GRID_DOMAIN_H #include #include #include #include #include #include namespace CGAL { namespace Isosurfacing { /** * \ingroup PkgIsosurfacing3Ref * * \brief A domain that respesents a cartesian grid that discretizes an implicit function. It is a model of the concept * `IsosurfacingDomainWithGradient`. * * \tparam GeomTraits the traits type * \tparam PointFunction the type of the implicit function. It must implement `GeomTraits::FT operator()(const * GeomTraits::Point& point) const`. \tparam Gradient_ the type of the gradient functor. It must implement * `GeomTraits::Vector operator()(const GeomTraits::Point& point) const`. */ template using Implicit_cartesian_grid_domain = Base_domain, Implicit_function_with_geometry, PointFunction>, Gradient_>; /** * \ingroup PkgIsosurfacing3Ref * * \brief Creates a domain from an implicit function that can be used as input for isosurfacing algorithms. * * \details The implicit function will be evaluated on the grid points of the virtual grid * defined by the bounding box and spacing. By not storing any function values implicitly * less memory accesses are required in comparison to an `Explicit_cartesian_grid_domain`. * * \tparam GeomTraits the traits type * \tparam PointFunction the type of the implicit function. It must implement `GeomTraits::FT operator()(const * GeomTraits::Point& point) const`. * * \param bbox a bounding box that specifies the size of the functions domain * \param spacing the distance between discretized points on the function * \param point_function the function with a point as argument * \param gradient a function that describes the gradient of the data * * \return a new `Implicit_cartesian_grid_domain` */ template > Implicit_cartesian_grid_domain create_implicit_cartesian_grid_domain( const Bbox_3& bbox, const typename GeomTraits::Vector_3& spacing, const PointFunction& point_function, const Gradient_& gradient = Gradient_()) { typedef Implicit_cartesian_grid_domain Domain; typedef typename Domain::Topology Topology; typedef typename Domain::Geometry Geometry; typedef typename Domain::Function Function; typedef typename Domain::Gradient Gradient; typedef typename Function::element_type::Point_function Point_function; // calculate grid dimensions const std::size_t size_i = std::ceil(bbox.x_span() / spacing.x()) + 1; const std::size_t size_j = std::ceil(bbox.y_span() / spacing.y()) + 1; const std::size_t size_k = std::ceil(bbox.z_span() / spacing.z()) + 1; const typename GeomTraits::Vector_3 offset(bbox.xmin(), bbox.ymin(), bbox.zmin()); // create copies as shared_ptr for safe memory management const Topology topo = std::make_shared(size_i, size_j, size_k); const Geometry geom = std::make_shared(offset, spacing); const Point_function point_func = std::make_shared(point_function); const Function func = std::make_shared(geom, point_func); const Gradient grad = std::make_shared(gradient); return Domain(topo, geom, func, grad); } } // namespace Isosurfacing } // namespace CGAL #endif // CGAL_IMPLICIT_CARTESIAN_GRID_DOMAIN_H