From 4f423bf555d6fb2327ef12f0cb804e3944fcb000 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 9 Dec 2019 20:06:48 +0100 Subject: [PATCH] implement algorithmic solution to determine whether triangle is visible --- src/Mod/Mesh/Gui/ViewProvider.cpp | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index 333672060f..935e815039 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -54,6 +54,11 @@ # include #endif +#include +#include +#include +#include + /// Here the FreeCAD includes sorted by Base,App,Gui...... #include #include @@ -1328,9 +1333,71 @@ void ViewProviderMesh::renderGLCallback(void * ud, SoAction * action) } } +namespace MeshGui { + +class Vertex +{ +public: + Vertex(const MeshCore::MeshKernel& kernel, + const MeshCore::MeshFacetGrid& grid, + const Base::Vector3f& pos) + : kernel(kernel) + , grid(grid) + , pos(pos) + { + } + bool visible(const Base::Vector3f& base) const + { + MeshCore::MeshAlgorithm meshAlg(kernel); + bool ok = meshAlg.IsVertexVisible(base, pos, grid); + return ok; + } + +private: + const MeshCore::MeshKernel& kernel; + const MeshCore::MeshFacetGrid& grid; + Base::Vector3f pos; +}; + +} + std::vector ViewProviderMesh::getVisibleFacets(const SbViewportRegion& vp, SoCamera* camera) const { +#if 1 + Q_UNUSED(vp) + + SbVec3f pos = camera->position.getValue(); + + const Mesh::PropertyMeshKernel& meshProp = static_cast(pcObject)->Mesh; + const Mesh::MeshObject& mesh = meshProp.getValue(); + + const MeshCore::MeshKernel& kernel = mesh.getKernel(); + MeshCore::MeshFacetGrid grid(kernel); + + std::vector points; + points.reserve(kernel.CountFacets()); + for (unsigned long i = 0; i < kernel.CountFacets(); i++) { + points.push_back(kernel.GetFacet(i).GetGravityPoint()); + } + + Vertex v(kernel, grid, Base::convertTo(pos)); + QFuture future = QtConcurrent::mapped + (points, boost::bind(&Vertex::visible, &v, _1)); + QFutureWatcher watcher; + watcher.setFuture(future); + watcher.waitForFinished(); + + unsigned long index = 0; + std::vector faces; + for (QFuture::const_iterator i = future.begin(); i != future.end(); ++i, index++) { + if ((*i)) { + faces.push_back(index); + } + } + + return faces; +#else const Mesh::PropertyMeshKernel& meshProp = static_cast(pcObject)->Mesh; const Mesh::MeshObject& mesh = meshProp.getValue(); uint32_t count = (uint32_t)mesh.countFacets(); @@ -1398,6 +1465,7 @@ std::vector ViewProviderMesh::getVisibleFacets(const SbViewportRe faces.erase(std::unique(faces.begin(), faces.end()), faces.end()); return faces; +#endif } void ViewProviderMesh::cutMesh(const std::vector& picked,