Commit 4416a527 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[python] register magnitude functions

parent ab339ad6
add_subdirectory(common)
add_subdirectory(geometry)
add_subdirectory(io)
add_subdirectory(magnitude)
add_subdirectory(occutilities)
add_subdirectory(precision)
add_subdirectory(sampling)
install(FILES
magnitude.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/frackit/python/magnitude)
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
* See the file COPYING for full copying permissions. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#ifndef FRACKIT_PYTHON_MAGNITUDE_HH
#define FRACKIT_PYTHON_MAGNITUDE_HH
#include <pybind11/pybind11.h>
#include <frackit/common/extractctype.hh>
// supported (registered) geometry types (so far)
#include <frackit/geometry/disk.hh>
#include <frackit/geometry/segment.hh>
#include <frackit/geometry/quadrilateral.hh>
#include <frackit/geometry/box.hh>
#include <frackit/geometry/cylinder.hh>
#include <frackit/python/occutilities/brepwrapper.hh>
#include <frackit/magnitude/magnitude.hh>
#include <frackit/magnitude/containedmagnitude.hh>
namespace Frackit::Python {
namespace py = pybind11;
namespace Detail {
// helper struct for ctype traits to achieve support for brepwrappers
template<class Geo>
struct CTypeTraits : public Frackit::CoordinateTypeTraits<Geo> {};
template<class S>
struct CTypeTraits<OCCUtilities::BRepWrapper<S>> : public Frackit::CoordinateTypeTraits<S> {};
//! overload for computation of the magnitude of the contained part of a shape wrapper
template<class Geo, class Domain>
typename CTypeTraits<Geo>::type
computeContainedMagnitude(const Geo& geo, const Domain& domain)
{
static constexpr bool isWrapperGeo = OCCUtilities::IsBRepWrapper<Geo>::value;
static constexpr bool isWrapperDomain = OCCUtilities::IsBRepWrapper<Domain>::value;
if constexpr (isWrapperGeo && isWrapperDomain)
return Frackit::computeContainedMagnitude(geo.get(), domain.get());
else if constexpr (isWrapperGeo && !isWrapperDomain)
return Frackit::computeContainedMagnitude(geo.get(), domain);
else if constexpr (!isWrapperGeo && isWrapperDomain)
return Frackit::computeContainedMagnitude(geo, domain.get());
else
return Frackit::computeContainedMagnitude(geo, domain);
}
//! overload for computation of the magnitude of the contained part of a shape wrapper
template<class Geo>
typename CTypeTraits<Geo>::type
computeMagnitude(const Geo& geo)
{
if constexpr (OCCUtilities::IsBRepWrapper<Geo>::value)
return Frackit::computeMagnitude(geo.get());
else
return Frackit::computeMagnitude(geo);
}
template<class Geo>
void registerMagnitude(py::module& module)
{
module.def("computeMagnitude",
py::overload_cast<const Geo&>(&computeMagnitude<Geo>),
"compute the magnitude (length/area/volume) of a geometry");
}
template<class Geo, class Domain>
void registerContainedMagnitude(py::module& module)
{
module.def("computeContainedMagnitude",
py::overload_cast<const Geo&, const Domain&>(&computeContainedMagnitude<Geo, Domain>),
"compute the magnitude of the part of an entity geometry contained in a domain geometry");
}
} // end namespace Detail
template<class ctype>
void registerMagnitude(py::module& module)
{
using namespace Frackit;
using namespace Frackit::Python::OCCUtilities;
Detail::registerMagnitude< Segment<ctype, 3> >(module);
Detail::registerMagnitude< Disk<ctype> >(module);
Detail::registerMagnitude< Quadrilateral<ctype, 3> >(module);
Detail::registerMagnitude< EdgeWrapper >(module);
Detail::registerMagnitude< FaceWrapper >(module);
Detail::registerMagnitude< SolidWrapper >(module);
}
template<class ctype>
void registerContainedMagnitude(py::module& module)
{
using namespace Frackit;
using namespace Frackit::Python::OCCUtilities;
Detail::registerContainedMagnitude< Segment<ctype, 3>, Box<ctype> >(module);
Detail::registerContainedMagnitude< Segment<ctype, 3>, Cylinder<ctype> >(module);
Detail::registerContainedMagnitude< Segment<ctype, 3>, SolidWrapper >(module);
Detail::registerContainedMagnitude< Disk<ctype>, Box<ctype> >(module);
Detail::registerContainedMagnitude< Disk<ctype>, Cylinder<ctype> >(module);
Detail::registerContainedMagnitude< Disk<ctype>, SolidWrapper >(module);
Detail::registerContainedMagnitude< Quadrilateral<ctype, 3>, Box<ctype> >(module);
Detail::registerContainedMagnitude< Quadrilateral<ctype, 3>, Cylinder<ctype> >(module);
Detail::registerContainedMagnitude< Quadrilateral<ctype, 3>, SolidWrapper >(module);
Detail::registerContainedMagnitude< FaceWrapper, Box<ctype> >(module);
Detail::registerContainedMagnitude< FaceWrapper, Cylinder<ctype> >(module);
Detail::registerContainedMagnitude< FaceWrapper, SolidWrapper >(module);
}
} // end namespace Frackit::Python
#endif
......@@ -2,6 +2,7 @@ add_subdirectory(common)
add_subdirectory(entitynetwork)
add_subdirectory(geometry)
add_subdirectory(io)
add_subdirectory(magnitude)
add_subdirectory(occutilities)
add_subdirectory(precision)
add_subdirectory(sampling)
frackit_symlink_or_copy(FILES __init__.py)
pybind11_add_module(_magnitude _magnitude.cc)
target_link_libraries(_magnitude PRIVATE ${OCC_LIBS})
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
* See the file COPYING for full copying permissions. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#include <pybind11/pybind11.h>
#include <frackit/python/magnitude/magnitude.hh>
PYBIND11_MODULE(_magnitude, module)
{
Frackit::Python::registerMagnitude<double>(module);
Frackit::Python::registerContainedMagnitude<double>(module);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment