30 #include <DGtal/base/Common.h>
31 #include <DGtal/helpers/StdDefs.h>
32 #include <DGtal/helpers/Shortcuts.h>
33 #include <DGtal/helpers/ShortcutsGeometry.h>
34 #include <polyscope/polyscope.h>
35 #include <polyscope/surface_mesh.h>
36 #include <polyscope/point_cloud.h>
38 #include <DGtal/shapes/WindingNumbersShape.h>
39 #include <DGtal/shapes/GaussDigitizer.h>
41 #include "ConfigExamples.h"
43 using namespace DGtal;
54 auto params = SH3::defaultParameters() | SHG3::defaultParameters() | SHG3::parametersGeometryEstimation();
55 params(
"surfaceComponents",
"All")(
"gridstep", 1. )(
"r-radius" , 4.0);
57 std::string filename = examplesPath + std::string(
"/samples/bunny-32.vol");
58 auto binary_image = SH3::makeBinaryImage(filename, params );
62 auto primalSurface = SH3::makePrimalSurfaceMesh(
surface);
63 auto surfels = SH3::getSurfelRange(
surface, params);
64 auto embedder = SH3::getSCellEmbedder(
K );
68 std::vector<std::vector<SH3::SurfaceMesh::Vertex>> faces;
69 std::vector<RealPoint> positions;
70 for(
auto face= 0 ; face < primalSurface->nbFaces(); ++face)
71 faces.push_back(primalSurface->incidentVertices( face ));
73 positions = primalSurface->positions();
81 trace.
info()<<
"Got "<<surfels.size()<<
" surfels."<<std::endl;
87 auto psMesh = polyscope::registerSurfaceMesh(
"input digital surface", positions, faces);
90 Eigen::MatrixXd points(surfels.size(),3);
91 Eigen::MatrixXd normals(surfels.size(),3);
92 std::ofstream ofs (
"bunny.pts", std::ofstream::out);
93 for(
auto i=0; i< surfels.size(); ++i)
95 auto p = embedder(surfels[i]);
104 ofs<<p(0)<<
" "<<p(1)<<
" "<<p(2)<<
" "<<n(0)<<
" "<< n(1)<<
" "<<n(2)<<std::endl;
107 auto pc= polyscope::registerPointCloud(
"input boundary points", points);
108 pc->addVectorQuantity(
"normals", normals);
117 auto resample_h = [&](
double h){
120 pointEmbedder.
init( h );
128 Eigen::MatrixXd queries(size,3);
130 for(
const auto &vox:
domain)
132 Eigen::RowVector3<double> p(vox[0],vox[1],vox[2]);
134 queries.row(cpt) = p;
137 trace.
info()<<
"Cpt= "<<cpt<<
" size= "<<size<<std::endl;
138 auto orientations = wnshape.orientationBatch(queries);
143 for(
const auto &voxel:
domain)
145 if (orientations[cpt]==
INSIDE)
146 voxels.insertNew(voxel);
149 trace.
info() <<
"Number of voxels = "<<voxels.size()<<std::endl;
153 kspace.
init(lowerPoint, upperPoint,
true);
159 MySurfelAdjacency surfAdj(
true );
160 MySetOfSurfels theSetOfSurfels( kspace, surfAdj );
166 trace.
info()<<
"Surfel set size= "<<theSetOfSurfels.surfelSet().size()<<std::endl;
170 auto primalSurfaceReco = SH3::makePrimalSurfaceMesh(surfPtr);
172 std::vector<RealPoint> positionsReco = primalSurfaceReco->positions();
174 std::for_each(std::begin(positionsReco), std::end(positionsReco), [&](
RealPoint &p){p=p*h;});
176 std::vector<std::vector<SH3::SurfaceMesh::Vertex>> facesReco;
177 for(
auto face= 0 ; face < primalSurfaceReco->nbFaces(); ++face)
178 facesReco.push_back(primalSurfaceReco->incidentVertices( face ));
179 auto psMesh = polyscope::registerSurfaceMesh(
"Reconstruction "+std::to_string(h), positionsReco, facesReco);
189 trace.
warning() <<
"CMake Debug mode detected, limiting upscaling to 0.5.";
Aim: Smart pointer based on reference counts.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Aim: A simple point embedder where grid steps are given for each axis. Note that the real point (0,...
Point floor(const RealPoint &p) const
Point ceil(const RealPoint &p) const
void init(typename RealVector::Component gridStep)
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
std::map< Cell, IdxVertex > Cell2Index
static void sMakeBoundary(SCellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
SurfaceMesh< RealPoint, RealVector > SurfMesh
polyscope::SurfaceMesh * psMesh
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
SHG3::RealVectors iinormals
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
MyDigitalSurface::SurfelSet SurfelSet
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 ...
int main(int argc, char **argv)
K init(Point(0, 0, 0), Point(512, 512, 512), true)
ShortcutsGeometry< Z3i::KSpace > SHG3
Vector lower(const Vector &z, unsigned int k)
Vector upper(const Vector &z, unsigned int k)