2021-11-15 10:08:39 +01:00
|
|
|
#ifndef HEXAGONREMESHER_HPP
|
|
|
|
#define HEXAGONREMESHER_HPP
|
|
|
|
#include "polymesh.hpp"
|
|
|
|
#include "vcgtrimesh.hpp"
|
|
|
|
#include <vcg/complex/algorithms/dual_meshing.h>
|
|
|
|
#include <vcg/complex/algorithms/isotropic_remeshing.h>
|
|
|
|
#include <vcg/complex/algorithms/point_sampling.h>
|
|
|
|
#include <vcg/complex/algorithms/polygon_support.h>
|
|
|
|
#include <vcg/complex/algorithms/polygonal_algorithms.h>
|
|
|
|
#include <vcg/complex/algorithms/voronoi_remesher.h>
|
|
|
|
|
|
|
|
namespace PolygonalRemeshing {
|
|
|
|
//std::shared_ptr<VCGPolyMesh>
|
2022-01-14 14:02:27 +01:00
|
|
|
inline std::shared_ptr<VCGPolyMesh> remeshWithPolygons(VCGTriMesh &surface)
|
2021-11-15 10:08:39 +01:00
|
|
|
{
|
|
|
|
// const std::string tileIntoFilePath(
|
|
|
|
// "/home/iason/Coding/build/PatternTillingReducedModel/RelWithDebInfo/plane.ply");
|
|
|
|
// const std::string tileIntoFilePath("/home/iason/Coding/build/PatternTillingReducedModel/"
|
|
|
|
// "RelWithDebInfo/hexagon.ply");
|
|
|
|
// const std::string tileIntoFilePath("/home/iason/Coding/build/PatternTillingReducedModel/"
|
|
|
|
// "RelWithDebInfo/instantMeshes_plane_34.ply");
|
|
|
|
// const std::string tileIntoFilePath("/home/iason/Coding/build/PatternTillingReducedModel/"
|
|
|
|
// "RelWithDebInfo/instantMeshes_plane.ply");
|
|
|
|
// assert(std::filesystem::exists(tileIntoFilePath));
|
|
|
|
// assert(tileInto_polyMesh.load(tileIntoFilePath));
|
|
|
|
|
|
|
|
///Load triangle mesh
|
|
|
|
// VCGTriMesh tileInto_triMesh;
|
|
|
|
// assert(std::filesystem::exists(tileIntoFilePath));
|
|
|
|
// tileInto_triMesh.load(tileIntoFilePath);
|
|
|
|
|
|
|
|
///Sample the triangle mesh
|
|
|
|
// std::vector<CoordType> pointVec;
|
|
|
|
// double radius = 1;
|
|
|
|
// int sampleNum = 50;
|
|
|
|
// // // vcg::tri::PoissonSampling<VCGTriMesh>(tileInto_triMesh, pointVec, sampleNum, radius);
|
|
|
|
// // // vcg::tri::TrivialSampler<VCGTriMesh> ps;
|
|
|
|
// // // vcg::tri::SurfaceSampling<VCGTriMesh>::VertexUniform(tileInto_triMesh, ps, sampleNum);
|
|
|
|
// // // pointVec = ps.SampleVec();
|
|
|
|
// vcg::tri::MontecarloSampling<VCGTriMesh>(tileInto_triMesh, pointVec, sampleNum);
|
|
|
|
|
|
|
|
// vcg::tri::VoronoiProcessingParameter vpp;
|
|
|
|
// vcg::tri::VoronoiProcessing<VCGTriMesh>::PreprocessForVoronoi(tileInto_triMesh, radius, vpp);
|
|
|
|
// std::vector<VCGTriMesh::VertexType *> seedVec;
|
|
|
|
// vcg::tri::VoronoiProcessing<VCGTriMesh>::SeedToVertexConversion(tileInto_triMesh,
|
|
|
|
// pointVec,
|
|
|
|
// seedVec);
|
|
|
|
|
|
|
|
// vcg::tri::EuclideanDistance<VCGTriMesh> df;
|
|
|
|
// vpp.geodesicRelaxFlag = false;
|
|
|
|
// const int iterNum = 100;
|
|
|
|
// int actualIter = vcg::tri::VoronoiProcessing<VCGTriMesh>::VoronoiRelaxing(tileInto_triMesh,
|
|
|
|
// seedVec,
|
|
|
|
// iterNum,
|
|
|
|
// df,
|
|
|
|
// vpp);
|
|
|
|
// std::cout << "Voronoi relaxation iterations performed:" << actualIter << std::endl;
|
|
|
|
|
|
|
|
// bool saveWasSuccessful
|
|
|
|
// = 0
|
|
|
|
// == vcg::tri::io::ExporterOBJ<VCGTriMesh>::Save(tileInto_triMesh,
|
|
|
|
// "./tileInto_triMesh.obj",
|
|
|
|
// vcg::tri::io::Mask::IOM_ALL);
|
|
|
|
|
|
|
|
// VCGTriMesh delaunay;
|
|
|
|
// vcg::tri::VoronoiProcessing<VCGTriMesh>::ConvertDelaunayTriangulationToMesh(tileInto_triMesh,
|
|
|
|
// delaunay,
|
|
|
|
// seedVec);
|
|
|
|
// delaunay.setLabel("Delaunay");
|
|
|
|
// delaunay.save(delaunay.getLabel() + ".ply");
|
|
|
|
// delaunay.registerForDrawing();
|
|
|
|
|
|
|
|
// ////Load surface
|
|
|
|
VCGPolyMesh tileInto_polyMesh, dual;
|
|
|
|
// vcg::tri::PolygonSupport<VCGTriMesh, VCGPolyMesh>::ImportFromTriMesh(tileInto_polyMesh,
|
|
|
|
// delaunay);
|
|
|
|
vcg::tri::PolygonSupport<VCGTriMesh, VCGPolyMesh>::ImportFromTriMesh(tileInto_polyMesh, surface);
|
|
|
|
vcg::tri::DualMeshing<VCGPolyMesh>::MakeDual(tileInto_polyMesh, dual, false);
|
|
|
|
|
|
|
|
// for(size_t i=0; i< Edges.size(); ++i)
|
|
|
|
// {
|
|
|
|
// std::vector<VCGPolyMesh> fpVec;
|
|
|
|
// std::vector<int> eiVec;
|
|
|
|
// face::EFStarFF(Edges[i].f,Edges[i].z,fpVec,eiVec);
|
|
|
|
// for(size_t j=0;j<fpVec.size();++j)
|
|
|
|
// fpVec[j]->FEp(eiVec[j])=&(m.edge[i]);
|
|
|
|
// }
|
|
|
|
dual.setLabel(surface.getLabel() + "_polyDual");
|
|
|
|
|
|
|
|
// bool saveWasSuccessful
|
|
|
|
// = 0
|
|
|
|
// == vcg::tri::io::ExporterOBJ<VCGPolyMesh>::Save(dual,
|
|
|
|
// (dual.getLabel() + ".obj").c_str(),
|
|
|
|
// vcg::tri::io::Mask::IOM_BITPOLYGONAL);
|
|
|
|
// assert(saveWasSuccessful);
|
|
|
|
vcg::tri::UpdateNormal<VCGPolyMesh>::PerFaceNormalized(dual);
|
|
|
|
|
|
|
|
// vcg::PolygonalAlgorithm<VCGPolyMesh>::SmoothReprojectPCA(dual, 1000, false, 0.5, 0, false, false);
|
|
|
|
// vcg::tri::io::ExporterOBJ<VCGPolyMesh>::Save(dual,
|
|
|
|
// "./dual_optimized.obj",
|
|
|
|
// vcg::tri::io::Mask::IOM_BITPOLYGONAL);
|
|
|
|
|
|
|
|
// if (vcg::tri::VoronoiProcessing<VCGTriMesh>::CheckVoronoiTopology(tileInto_triMesh, seedVec)) {
|
|
|
|
// VCGTriMesh voronoiMesh, voronoiPoly;
|
|
|
|
// vcg::tri::VoronoiProcessing<VCGTriMesh>::ConvertVoronoiDiagramToMesh(tileInto_triMesh,
|
|
|
|
// voronoiMesh,
|
|
|
|
// voronoiPoly,
|
|
|
|
// seedVec,
|
|
|
|
// vpp);
|
|
|
|
// vcg::tri::Allocator<VCGTriMesh>::CompactEveryVector(voronoiMesh);
|
|
|
|
// voronoiMesh.setLabel("Voro");
|
|
|
|
// voronoiMesh.save(voronoiMesh.getLabel() + ".ply");
|
|
|
|
// // voronoiMesh.registerForDrawing();
|
|
|
|
// vcg::tri::Allocator<VCGTriMesh>::CompactEveryVector(voronoiPoly);
|
|
|
|
// voronoiPoly.setLabel("Poly");
|
|
|
|
// voronoiPoly.save(voronoiPoly.getLabel() + ".ply");
|
|
|
|
// // voronoiPoly.registerForDrawing();
|
|
|
|
// // polyscope::show();
|
|
|
|
// }
|
|
|
|
// dual.registerForDrawing();
|
|
|
|
// polyscope::show();
|
|
|
|
// assert(vcg::tri::IsValidPointer(dual, dual.face[0].cFEp(0)));
|
|
|
|
return std::make_shared<VCGPolyMesh>(dual);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace PolygonalRemeshing
|
|
|
|
|
|
|
|
#endif // HEXAGONREMESHER_HPP
|