implement algorithmic solution to determine whether triangle is visible

This commit is contained in:
wmayer
2019-12-09 20:06:48 +01:00
parent ce4ab3eafe
commit 4f423bf555

View File

@@ -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>
@@ -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();
@@ -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,