performance improvements for decimate
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include <igl/circulation.h>
|
||||
#include <igl/collapse_edge.h>
|
||||
#include <igl/edge_flaps.h>
|
||||
#include <igl/decimate.h>
|
||||
#include <igl/shortest_edge_and_midpoint.h>
|
||||
#include <igl/parallel_for.h>
|
||||
#include <igl/read_triangle_mesh.h>
|
||||
#include <igl/opengl/glfw/Viewer.h>
|
||||
#include <Eigen/Core>
|
||||
@@ -33,9 +35,8 @@ int main(int argc, char * argv[])
|
||||
// Prepare array-based edge data structures and priority queue
|
||||
VectorXi EMAP;
|
||||
MatrixXi E,EF,EI;
|
||||
typedef std::set<std::pair<double,int> > PriorityQueue;
|
||||
PriorityQueue Q;
|
||||
std::vector<PriorityQueue::iterator > Qit;
|
||||
igl::min_heap< std::tuple<double,int,int> > Q;
|
||||
Eigen::VectorXi EQ;
|
||||
// If an edge were collapsed, we'd collapse it to these points:
|
||||
MatrixXd C;
|
||||
int num_collapsed;
|
||||
@@ -46,19 +47,28 @@ int main(int argc, char * argv[])
|
||||
F = OF;
|
||||
V = OV;
|
||||
edge_flaps(F,E,EMAP,EF,EI);
|
||||
Qit.resize(E.rows());
|
||||
|
||||
C.resize(E.rows(),V.cols());
|
||||
VectorXd costs(E.rows());
|
||||
Q.clear();
|
||||
for(int e = 0;e<E.rows();e++)
|
||||
// https://stackoverflow.com/questions/2852140/priority-queue-clear-method
|
||||
// Q.clear();
|
||||
Q = {};
|
||||
EQ = Eigen::VectorXi::Zero(E.rows());
|
||||
{
|
||||
double cost = e;
|
||||
RowVectorXd p(1,3);
|
||||
shortest_edge_and_midpoint(e,V,F,E,EMAP,EF,EI,cost,p);
|
||||
C.row(e) = p;
|
||||
Qit[e] = Q.insert(std::pair<double,int>(cost,e)).first;
|
||||
Eigen::VectorXd costs(E.rows());
|
||||
igl::parallel_for(E.rows(),[&](const int e)
|
||||
{
|
||||
double cost = e;
|
||||
RowVectorXd p(1,3);
|
||||
shortest_edge_and_midpoint(e,V,F,E,EMAP,EF,EI,cost,p);
|
||||
C.row(e) = p;
|
||||
costs(e) = cost;
|
||||
},10000);
|
||||
for(int e = 0;e<E.rows();e++)
|
||||
{
|
||||
Q.emplace(costs(e),e,0);
|
||||
}
|
||||
}
|
||||
|
||||
num_collapsed = 0;
|
||||
viewer.data().clear();
|
||||
viewer.data().set_mesh(V,F);
|
||||
@@ -75,8 +85,7 @@ int main(int argc, char * argv[])
|
||||
const int max_iter = std::ceil(0.01*Q.size());
|
||||
for(int j = 0;j<max_iter;j++)
|
||||
{
|
||||
if(!collapse_edge(
|
||||
shortest_edge_and_midpoint, V,F,E,EMAP,EF,EI,Q,Qit,C))
|
||||
if(!collapse_edge(shortest_edge_and_midpoint,V,F,E,EMAP,EF,EI,Q,EQ,C))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user