diff --git a/Wrapping/Python/pyWrap.cpp b/Wrapping/Python/pyWrap.cpp index 91fa0461..9eb934fa 100644 --- a/Wrapping/Python/pyWrap.cpp +++ b/Wrapping/Python/pyWrap.cpp @@ -100,9 +100,10 @@ class PylsGeometricAdvectDistribution PYBIND11_OVERLOAD(bool, ClassType, isInside, initial, candidate, eps); } - T getSignedDistance(const vectorType &initial, - const vectorType &candidate) const override { - PYBIND11_OVERLOAD_PURE(T, ClassType, getSignedDistance, initial, candidate); + T getSignedDistance(const vectorType &initial, const vectorType &candidate, + unsigned long initialPointId) const override { + PYBIND11_OVERLOAD_PURE(T, ClassType, getSignedDistance, initial, candidate, + initialPointId); } boundsType getBounds() const override { @@ -407,7 +408,7 @@ PYBIND11_MODULE(VIENNALS_MODULE_NAME, module) { pybind11::detail::pythonbuf buf(fileHandle); std::ostream stream(&buf); d.print(stream); - }, pybind11::arg("stream") = pybind11::module_::import("sys").attr("stdout")); + }, pybind11::arg("stream") = pybind11::module::import("sys").attr("stdout")); // enums pybind11::enum_>(module, "lsBoundaryConditionEnum") @@ -605,7 +606,7 @@ PYBIND11_MODULE(VIENNALS_MODULE_NAME, module) { const std::vector> &>)) // methods .def("insertNextPoint", - (void (lsPointCloud::*)(const std::vector &)) & + (void(lsPointCloud::*)(const std::vector &)) & lsPointCloud::insertNextPoint); // lsMakeGeometry @@ -631,22 +632,22 @@ PYBIND11_MODULE(VIENNALS_MODULE_NAME, module) { .def("setLevelSet", &lsMakeGeometry::setLevelSet, "Set the levelset in which to create the geometry.") .def("setGeometry", - (void (lsMakeGeometry::*)(lsSmartPointer>)) & + (void(lsMakeGeometry::*)(lsSmartPointer>)) & lsMakeGeometry::setGeometry) .def("setGeometry", - (void (lsMakeGeometry::*)(lsSmartPointer>)) & + (void(lsMakeGeometry::*)(lsSmartPointer>)) & lsMakeGeometry::setGeometry) .def("setGeometry", - (void (lsMakeGeometry::*)(lsSmartPointer>)) & + (void(lsMakeGeometry::*)(lsSmartPointer>)) & + lsMakeGeometry::setGeometry) + .def("setGeometry", + (void(lsMakeGeometry::*)(lsSmartPointer>)) & lsMakeGeometry::setGeometry) - .def("setGeometry", (void (lsMakeGeometry::*)( - lsSmartPointer>)) & - lsMakeGeometry::setGeometry) .def("setIgnoreBoundaryConditions", - (void (lsMakeGeometry::*)(bool)) & + (void(lsMakeGeometry::*)(bool)) & lsMakeGeometry::setIgnoreBoundaryConditions) .def("setIgnoreBoundaryConditions", - (void (lsMakeGeometry::*)(std::array)) & + (void(lsMakeGeometry::*)(std::array)) & lsMakeGeometry::setIgnoreBoundaryConditions) .def("apply", &lsMakeGeometry::apply, "Generate the geometry."); @@ -692,13 +693,13 @@ PYBIND11_MODULE(VIENNALS_MODULE_NAME, module) { .def(pybind11::init(&lsSmartPointer>::New<>)) // methods .def("insertNextScalarData", - (void (lsPointData::*)(const lsPointData::ScalarDataType &, - std::string)) & + (void(lsPointData::*)(const lsPointData::ScalarDataType &, + std::string)) & lsPointData::insertNextScalarData, pybind11::arg("scalars"), pybind11::arg("label") = "Scalars") .def("insertNextVectorData", - (void (lsPointData::*)(const lsPointData::VectorDataType &, - std::string)) & + (void(lsPointData::*)(const lsPointData::VectorDataType &, + std::string)) & lsPointData::insertNextVectorData, pybind11::arg("vectors"), pybind11::arg("label") = "Vectors") .def("getScalarDataSize", &lsPointData::getScalarDataSize) @@ -728,7 +729,7 @@ PYBIND11_MODULE(VIENNALS_MODULE_NAME, module) { lsMesh::getNodes, "Get all nodes of the mesh as a list.") .def("getNodes", - (const std::vector> &(lsMesh::*)() const) & + (std::vector> & (lsMesh::*)()) & lsMesh::getNodes, "Get all nodes of the mesh as a list.") .def("getVerticies", diff --git a/include/lsGeometricAdvect.hpp b/include/lsGeometricAdvect.hpp index 5f0cd103..081af244 100644 --- a/include/lsGeometricAdvect.hpp +++ b/include/lsGeometricAdvect.hpp @@ -52,6 +52,15 @@ template class lsGeometricAdvect { ++indices[dim]; } + template class MapType, class... Ts> + MapType inverseTranslator(MapType &map) { + MapType inv; + std::for_each(map.begin(), map.end(), [&inv](const std::pair &p) { + inv.insert(std::make_pair(p.second, p.first)); + }); + return inv; + } + public: lsGeometricAdvect() {} @@ -123,7 +132,11 @@ template class lsGeometricAdvect { // Extract the original surface as a point cloud of grid // points shifted to the surface (disk mesh) auto surfaceMesh = lsSmartPointer>::New(); - lsToDiskMesh(levelSet, surfaceMesh).apply(); + auto pointIdTranslator = + lsSmartPointer::TranslatorType>::New(); + lsToDiskMesh(levelSet, surfaceMesh, pointIdTranslator) + .apply(); + *pointIdTranslator = inverseTranslator(*pointIdTranslator); // find bounds of distribution auto distBounds = dist->getBounds(); @@ -359,10 +372,11 @@ template class lsGeometricAdvect { T distance = initialDistance; + unsigned long currentPointId = 0; // now check which surface points contribute to currentIndex for (typename SurfaceNodesType::const_iterator surfIt = surfaceNodes.begin(); - surfIt != surfaceNodes.end(); ++surfIt) { + surfIt != surfaceNodes.end(); ++surfIt, ++currentPointId) { auto ¤tNode = *surfIt; @@ -387,8 +401,10 @@ template class lsGeometricAdvect { } // get filling fraction from distance to dist surface - T tmpDistance = - dist->getSignedDistance(currentNode, currentCoords) / gridDelta; + T tmpDistance = dist->getSignedDistance( + currentNode, currentCoords, + pointIdTranslator->find(currentPointId)->second) / + gridDelta; // if cell is far within a distribution, set it filled if (distIsPositive) { diff --git a/include/lsGeometricAdvectDistributions.hpp b/include/lsGeometricAdvectDistributions.hpp index 936d010a..0cf19ba6 100644 --- a/include/lsGeometricAdvectDistributions.hpp +++ b/include/lsGeometricAdvectDistributions.hpp @@ -24,9 +24,9 @@ template class lsGeometricAdvectDistribution { /// Returns the signed distance of a point relative to the distributions /// center. This is the signed manhatten distance to the nearest surface /// point. - virtual T - getSignedDistance(const std::array &initial, - const std::array &candidate) const = 0; + virtual T getSignedDistance(const std::array &initial, + const std::array &candidate, + unsigned long initialPointId) const = 0; /// Sets bounds to the bounding box of the distribution. virtual std::array getBounds() const = 0; @@ -48,7 +48,7 @@ class lsSphereDistribution : public lsGeometricAdvectDistribution { bool isInside(const std::array &initial, const std::array &candidate, - double eps = 0.) const { + double eps = 0.) const override { hrleCoordType dot = 0.; for (unsigned i = 0; i < D; ++i) { double tmp = candidate[i] - initial[i]; @@ -62,7 +62,8 @@ class lsSphereDistribution : public lsGeometricAdvectDistribution { } T getSignedDistance(const std::array &initial, - const std::array &candidate) const { + const std::array &candidate, + unsigned long /*initialPointId*/) const override { T distance = std::numeric_limits::max(); std::array v{}; for (unsigned i = 0; i < D; ++i) { @@ -95,7 +96,7 @@ class lsSphereDistribution : public lsGeometricAdvectDistribution { } } - std::array getBounds() const { + std::array getBounds() const override { std::array bounds = {}; for (unsigned i = 0; i < D; ++i) { bounds[2 * i] = -radius; @@ -128,7 +129,7 @@ class lsBoxDistribution : public lsGeometricAdvectDistribution { bool isInside(const std::array &initial, const std::array &candidate, - double eps = 0.) const { + double eps = 0.) const override { for (unsigned i = 0; i < D; ++i) { if (std::abs(candidate[i] - initial[i]) > (std::abs(posExtent[i]) + eps)) { @@ -139,7 +140,8 @@ class lsBoxDistribution : public lsGeometricAdvectDistribution { } T getSignedDistance(const std::array &initial, - const std::array &candidate) const { + const std::array &candidate, + unsigned long /*initialPointId*/) const override { T distance = std::numeric_limits::lowest(); for (unsigned i = 0; i < D; ++i) { T vector = std::abs(candidate[i] - initial[i]); @@ -148,7 +150,7 @@ class lsBoxDistribution : public lsGeometricAdvectDistribution { return (posExtent[0] < 0) ? -distance : distance; } - std::array getBounds() const { + std::array getBounds() const override { std::array bounds = {}; for (unsigned i = 0; i < D; ++i) { bounds[2 * i] = -posExtent[i]; diff --git a/include/lsSmartPointer.hpp b/include/lsSmartPointer.hpp index 89bf0af0..d8c56422 100644 --- a/include/lsSmartPointer.hpp +++ b/include/lsSmartPointer.hpp @@ -14,11 +14,11 @@ template class lsSmartPointer : public std::shared_ptr { // Make visible all constructors of std::shared_ptr // including copy constructors template - lsSmartPointer(Args &&...args) + lsSmartPointer(Args &&... args) : std::shared_ptr(std::forward(args)...) {} /// Use this function to create new objects when using ViennaLS - template static lsSmartPointer New(TArgs &&...targs) { + template static lsSmartPointer New(TArgs &&... targs) { return lsSmartPointer(std::make_shared(std::forward(targs)...)); } }; diff --git a/include/lsToDiskMesh.hpp b/include/lsToDiskMesh.hpp index 67dcb130..8e2f8810 100644 --- a/include/lsToDiskMesh.hpp +++ b/include/lsToDiskMesh.hpp @@ -19,11 +19,14 @@ /// This allows for a simple setup of disks for ray tracing. template class lsToDiskMesh { typedef typename lsDomain::DomainType hrleDomainType; - typedef std::unordered_map translatorType; +public: + using TranslatorType = std::unordered_map; + +private: std::vector>> levelSets; lsSmartPointer> mesh = nullptr; - lsSmartPointer translator = nullptr; + lsSmartPointer translator = nullptr; T maxValue = 0.5; bool buildTranslator = false; static constexpr double wrappingLayerEpsilon = 1e-4; @@ -42,7 +45,7 @@ template class lsToDiskMesh { lsToDiskMesh(lsSmartPointer> passedLevelSet, lsSmartPointer> passedMesh, - lsSmartPointer passedTranslator, + lsSmartPointer passedTranslator, T passedMaxValue = 0.5) : mesh(passedMesh), translator(passedTranslator), maxValue(passedMaxValue) { @@ -61,7 +64,7 @@ template class lsToDiskMesh { void setMesh(lsSmartPointer> passedMesh) { mesh = passedMesh; } - void setTranslator(lsSmartPointer passedTranslator) { + void setTranslator(lsSmartPointer passedTranslator) { translator = passedTranslator; buildTranslator = true; }