27 #include <DGtal/base/Common.h>
28 #include <DGtal/helpers/StdDefs.h>
29 #include <DGtal/helpers/Shortcuts.h>
30 #include <DGtal/helpers/ShortcutsGeometry.h>
31 #include <DGtal/shapes/SurfaceMesh.h>
32 #include <DGtal/geometry/surfaces/DigitalSurfaceRegularization.h>
34 #include <DGtal/dec/PolygonalCalculus.h>
35 #include <DGtal/dec/GeodesicsInHeat.h>
37 #include <polyscope/polyscope.h>
38 #include <polyscope/surface_mesh.h>
39 #include <polyscope/point_cloud.h>
41 #include "ConfigExamples.h"
43 #include <Eigen/Dense>
44 #include <Eigen/Sparse>
46 using namespace DGtal;
58 polyscope::SurfaceMesh *psMesh;
59 polyscope::SurfaceMesh *psMeshReg;
80 bool useProjectedCalculus =
true;
85 if (!useProjectedCalculus)
90 auto params2 = SH3::defaultParameters() | SHG3::defaultParameters() | SHG3::parametersGeometryEstimation();
91 params2(
"r-radius", (
double) radiusII);
92 auto surfels = SH3::getSurfelRange( surface, params2 );
93 iinormals = SHG3::getIINormalVectors(binary_image, surfels,params2);
94 trace.
info()<<iinormals.size()<<std::endl;
97 const auto nn = iinormals[f];
105 centroid = centroid / (double)cpt;
107 auto cp = p-centroid;
111 psMesh->addFaceVectorQuantity(
"II normals", iinormals);
132 std::vector<std::pair<size_t,int>> counts;
133 for(
auto i=0; i< source.size(); ++i)
136 counts.push_back(std::pair<size_t,int>(i,1));
144 heat->addSource( pos );
146 psMesh->addVertexCountQuantity(
"Sources", source2count(source));
150 heatReg->addSource( pos );
152 psMeshReg->addVertexCountQuantity(
"Sources", source2count(source));
159 psMesh->addVertexScalarQuantity(
"source", heat->source());
162 void computeGeodesics()
164 heat->addSource( sourceVertexId );
166 psMesh->addVertexCountQuantity(
"Sources", source2count(source));
168 psMesh->addVertexDistanceQuantity(
"geodesic", dist);
172 heatReg->addSource( sourceVertexId );
174 psMeshReg->addVertexCountQuantity(
"Sources", source2count(sourceReg));
176 psMeshReg->addVertexDistanceQuantity(
"geodesic", dist);
180 bool isPrecomputed=
false;
183 ImGui::SliderFloat(
"dt", &dt, 0.,4.);
184 ImGui::SliderFloat(
"ii radius for normal vector estimation", &radiusII , 0.,10.);
185 ImGui::Checkbox(
"Skip regularization", &skipReg);
186 ImGui::Checkbox(
"Using projection", &useProjectedCalculus);
187 ImGui::InputInt(
"Index of the first source vertex", &sourceVertexId);
190 if(ImGui::Button(
"Precomputation (required if you change parameters)"))
196 if(ImGui::Button(
"Add a random source"))
205 if(ImGui::Button(
"Clear sources"))
215 if(ImGui::Button(
"Compute geodesic"))
228 auto params = SH3::defaultParameters() | SHG3::defaultParameters() | SHG3::parametersGeometryEstimation();
229 params(
"surfaceComponents",
"All");
230 params(
"r-radius", (
double) radiusII);
231 std::string filename = examplesPath + std::string(
"/samples/bunny-128.vol");
232 binary_image = SH3::makeBinaryImage(filename, params );
233 auto K = SH3::getKSpace( binary_image, params );
234 surface = SH3::makeDigitalSurface( binary_image,
K, params );
235 auto primalSurface = SH3::makePrimalSurfaceMesh(surface);
238 std::vector<std::vector<SH3::SurfaceMesh::Vertex>> faces;
239 std::vector<RealPoint> positions;
241 for(
auto face= 0 ; face < primalSurface->nbFaces(); ++face)
242 faces.push_back(primalSurface->incidentVertices( face ));
245 positions = primalSurface->positions();
247 surfmesh =
SurfMesh(positions.begin(),
251 std::cout << surfmesh << std::endl;
257 regul.attachConvolvedTrivialNormalVectors(params);
259 auto regularizedPosition = regul.getRegularizedPositions();
261 surfmeshReg =
SurfMesh(regularizedPosition.begin(),
262 regularizedPosition.end(),
269 psMesh = polyscope::registerSurfaceMesh(
"digital surface", positions, faces);
270 psMeshReg = polyscope::registerSurfaceMesh(
"regularized surface", regularizedPosition, faces);
271 psMeshReg->setEnabled(
false);
274 polyscope::state::userCallback = myCallback;
Aim: Smart pointer based on reference counts.
Aim: Implements Digital Surface Regularization as described in .
This class implements on polygonal surfaces (using Discrete differential calculus on polygonal surfa...
PolygonalCalculus::Vector Vector
Aim: Implements basic operations that will be used in Point and Vector classes.
auto dot(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::dotProduct(*this, v))
Dot product with a PointVector.
Implements differential operators on polygonal surfaces from .
void setEmbedder(const std::function< Real3dPoint(Face, Vertex)> &externalFunctor)
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
std::vector< RealVector > RealVectors
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
RealPoint & position(Vertex v)
const Vertices & incidentVertices(Face f) const
Edges computeNonManifoldEdges() const
int main(int argc, char **argv)
K init(Point(0, 0, 0), Point(512, 512, 512), true)
ShortcutsGeometry< Z3i::KSpace > SHG3