From: Marco Feder Date: Wed, 8 Jun 2022 12:45:21 +0000 (+0200) Subject: Add header file for point conversion X-Git-Tag: v9.4.0-rc1~46^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13929%2Fhead;p=dealii.git Add header file for point conversion --- diff --git a/include/deal.II/cgal/point_conversion.h b/include/deal.II/cgal/point_conversion.h new file mode 100644 index 0000000000..9ccf20f516 --- /dev/null +++ b/include/deal.II/cgal/point_conversion.h @@ -0,0 +1,105 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2022 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +#ifndef dealii_cgal_point_conversion_h +#define dealii_cgal_point_conversion_h + +#include + +#include + +#ifdef DEAL_II_WITH_CGAL + +# include +# include +# include +# include + + +DEAL_II_NAMESPACE_OPEN +namespace CGALWrappers +{ + /** + * Convert from a deal.II Point to any compatible CGAL point. + * + * @tparam CGALPointType Any of the CGAL point types + * @tparam dim Dimension of the point + * @param [in] p An input deal.II Point + * @return CGALPointType A CGAL point + */ + template + inline CGALPointType + dealii_point_to_cgal_point(const dealii::Point &p); + + /** + * Convert from various CGAL point types to deal.II Point. + * + * @tparam dim Dimension of the point + * @tparam CGALPointType Any of the CGAL point types + * @param p An input CGAL point type + * @return dealii::Point The corresponding deal.II point. + */ + template + inline dealii::Point + cgal_point_to_dealii_point(const CGALPointType &p); + + +# ifndef DOXYGEN + // Template implementations + + template + inline CGALPointType + dealii_point_to_cgal_point(const dealii::Point &p) + { + constexpr int cdim = CGALPointType::Ambient_dimension::value; + static_assert(dim <= cdim, "Only dim <= cdim supported"); + if constexpr (cdim == 1) + return CGALPointType(p[0]); + else if constexpr (cdim == 2) + return CGALPointType(p[0], dim > 1 ? p[1] : 0); + else if constexpr (cdim == 3) + return CGALPointType(p[0], dim > 1 ? p[1] : 0, dim > 2 ? p[2] : 0); + else + Assert(false, dealii::ExcNotImplemented()); + return CGALPointType(); + } + + + + template + inline dealii::Point + cgal_point_to_dealii_point(const CGALPointType &p) + { + constexpr int cdim = CGALPointType::Ambient_dimension::value; + if constexpr (dim == 1) + return dealii::Point(CGAL::to_double(p.x())); + else if constexpr (dim == 2) + return dealii::Point(CGAL::to_double(p.x()), + cdim > 1 ? CGAL::to_double(p.y()) : 0); + else if constexpr (dim == 3) + return dealii::Point(CGAL::to_double(p.x()), + cdim > 1 ? CGAL::to_double(p.y()) : 0, + cdim > 2 ? CGAL::to_double(p.z()) : 0); + else + Assert(false, dealii::ExcNotImplemented()); + } +} // namespace CGALWrappers + +# endif + +DEAL_II_NAMESPACE_CLOSE + +#endif +#endif diff --git a/include/deal.II/cgal/surface_mesh.h b/include/deal.II/cgal/surface_mesh.h index 818be5c069..87f20fd5a4 100644 --- a/include/deal.II/cgal/surface_mesh.h +++ b/include/deal.II/cgal/surface_mesh.h @@ -23,11 +23,11 @@ #include -#include #ifdef DEAL_II_WITH_CGAL # include # include +# include DEAL_II_NAMESPACE_OPEN diff --git a/include/deal.II/cgal/utilities.h b/include/deal.II/cgal/utilities.h index d94bc384cf..719a3e7d7d 100644 --- a/include/deal.II/cgal/utilities.h +++ b/include/deal.II/cgal/utilities.h @@ -209,30 +209,6 @@ namespace CGALWrappers - /** - * Convert from a deal.II Point to any compatible CGAL point. - * - * @tparam CGALPointType Any of the CGAL point types - * @tparam dim Dimension of the point - * @param [in] p An input deal.II Point - * @return CGALPointType A CGAL point - */ - template - inline CGALPointType - dealii_point_to_cgal_point(const dealii::Point &p); - - /** - * Convert from various CGAL point types to deal.II Point. - * - * @tparam dim Dimension of the point - * @tparam CGALPointType Any of the CGAL point types - * @param p An input CGAL point type - * @return dealii::Point The corresponding deal.II point. - */ - template - inline dealii::Point - cgal_point_to_dealii_point(const CGALPointType &p); - /** * Given a closed CGAL::Surface_mesh, this function fills the * region bounded by the surface with tets. @@ -375,45 +351,6 @@ namespace CGALWrappers // Template implementations namespace CGALWrappers { - template - inline CGALPointType - dealii_point_to_cgal_point(const dealii::Point &p) - { - constexpr int cdim = CGALPointType::Ambient_dimension::value; - static_assert(dim <= cdim, "Only dim <= cdim supported"); - if constexpr (cdim == 1) - return CGALPointType(p[0]); - else if constexpr (cdim == 2) - return CGALPointType(p[0], dim > 1 ? p[1] : 0); - else if constexpr (cdim == 3) - return CGALPointType(p[0], dim > 1 ? p[1] : 0, dim > 2 ? p[2] : 0); - else - Assert(false, dealii::ExcNotImplemented()); - return CGALPointType(); - } - - - - template - inline dealii::Point - cgal_point_to_dealii_point(const CGALPointType &p) - { - constexpr int cdim = CGALPointType::Ambient_dimension::value; - if constexpr (dim == 1) - return dealii::Point(CGAL::to_double(p.x())); - else if constexpr (dim == 2) - return dealii::Point(CGAL::to_double(p.x()), - cdim > 1 ? CGAL::to_double(p.y()) : 0); - else if constexpr (dim == 3) - return dealii::Point(CGAL::to_double(p.x()), - cdim > 1 ? CGAL::to_double(p.y()) : 0, - cdim > 2 ? CGAL::to_double(p.z()) : 0); - else - Assert(false, dealii::ExcNotImplemented()); - } - - - template void cgal_surface_mesh_to_cgal_triangulation(