Skip to content

Commit

Permalink
implement algorithmic solution to determine whether triangle is visible
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Dec 9, 2019
1 parent 46792a9 commit 42196ea
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/Mod/Mesh/Gui/ViewProvider.cpp
Expand Up @@ -54,6 +54,11 @@
# include <Inventor/nodes/SoTransform.h>
#endif

#include <QFuture>
#include <QFutureWatcher>
#include <QtConcurrentMap>
#include <boost/bind.hpp>

/// Here the FreeCAD includes sorted by Base,App,Gui......
#include <Base/Console.h>
#include <Base/Exception.h>
Expand Down Expand Up @@ -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<unsigned long> ViewProviderMesh::getVisibleFacets(const SbViewportRegion& vp,
SoCamera* camera) const
{
#if 1
Q_UNUSED(vp)

SbVec3f pos = camera->position.getValue();

const Mesh::PropertyMeshKernel& meshProp = static_cast<Mesh::Feature*>(pcObject)->Mesh;
const Mesh::MeshObject& mesh = meshProp.getValue();

const MeshCore::MeshKernel& kernel = mesh.getKernel();
MeshCore::MeshFacetGrid grid(kernel);

std::vector<Base::Vector3f> 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<Base::Vector3f>(pos));
QFuture<bool> future = QtConcurrent::mapped
(points, boost::bind(&Vertex::visible, &v, _1));
QFutureWatcher<bool> watcher;
watcher.setFuture(future);
watcher.waitForFinished();

unsigned long index = 0;
std::vector<unsigned long> faces;
for (QFuture<bool>::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<Mesh::Feature*>(pcObject)->Mesh;
const Mesh::MeshObject& mesh = meshProp.getValue();
uint32_t count = (uint32_t)mesh.countFacets();
Expand Down Expand Up @@ -1398,6 +1465,7 @@ std::vector<unsigned long> ViewProviderMesh::getVisibleFacets(const SbViewportRe
faces.erase(std::unique(faces.begin(), faces.end()), faces.end());
return faces;
#endif
}

void ViewProviderMesh::cutMesh(const std::vector<SbVec2f>& picked,
Expand Down

0 comments on commit 42196ea

Please sign in to comment.