36#ifndef PCL_SURFACE_IMPL_MARCHING_CUBES_H_
37#define PCL_SURFACE_IMPL_MARCHING_CUBES_H_
39#include <pcl/surface/marching_cubes.h>
41#include <pcl/common/vector_average.h>
42#include <pcl/Vertices.h>
45template <
typename Po
intNT>
51template <
typename Po
intNT>
void
57 lower_boundary_ =
min_pt.getArray3fMap ();
58 upper_boundary_ =
max_pt.getArray3fMap ();
60 const Eigen::Array3f
size3_extend = 0.5f * percentage_extend_grid_
61 * (upper_boundary_ - lower_boundary_);
69template <
typename Po
intNT>
void
77 output = p1 + mu * (p2 - p1);
82template <
typename Po
intNT>
void
101 const Eigen::Vector3f
center = lower_boundary_
102 + size_voxel_ *
index_3d.cast<
float> ().array ();
104 std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > p;
106 for (
int i = 0; i < 8; ++i)
108 Eigen::Vector3f point =
center;
110 point[1] =
static_cast<float> (
center[1] + size_voxel_[1]);
113 point[2] =
static_cast<float> (
center[2] + size_voxel_[2]);
115 if ((i & 0x1) ^ ((i >> 1) & 0x1))
116 point[0] =
static_cast<float> (
center[0] + size_voxel_[0]);
122 std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> >
vertex_list;
154 cloud.push_back (p1);
156 cloud.push_back (p2);
158 cloud.push_back (p3);
164template <
typename Po
intNT>
void
171 leaf[1] = getGridValue (
index3d + Eigen::Vector3i (1, 0, 0));
172 leaf[2] = getGridValue (
index3d + Eigen::Vector3i (1, 0, 1));
173 leaf[3] = getGridValue (
index3d + Eigen::Vector3i (0, 0, 1));
174 leaf[4] = getGridValue (
index3d + Eigen::Vector3i (0, 1, 0));
175 leaf[5] = getGridValue (
index3d + Eigen::Vector3i (1, 1, 0));
176 leaf[6] = getGridValue (
index3d + Eigen::Vector3i (1, 1, 1));
177 leaf[7] = getGridValue (
index3d + Eigen::Vector3i (0, 1, 1));
179 for (
int i = 0; i < 8; ++i)
181 if (std::isnan (
leaf[i]))
191template <
typename Po
intNT>
float
195 if (pos[0] < 0 || pos[0] >= res_x_)
197 if (pos[1] < 0 || pos[1] >= res_y_)
199 if (pos[2] < 0 || pos[2] >= res_z_)
202 return grid_[pos[0]*res_y_*res_z_ + pos[1]*res_z_ + pos[2]];
207template <
typename Po
intNT>
void
212 performReconstruction (points,
output.polygons);
219template <
typename Po
intNT>
void
221 std::vector<pcl::Vertices> &polygons)
223 if (!(iso_level_ >= 0 && iso_level_ < 1))
225 PCL_ERROR (
"[pcl::%s::performReconstruction] Invalid iso level %f! Please use a number between 0 and 1.\n",
226 getClassName ().
c_str (), iso_level_);
236 grid_ = std::vector<float> (res_x_*res_y_*res_z_,
NAN);
240 size_voxel_ = (upper_boundary_ - lower_boundary_)
241 * Eigen::Array3f (res_x_, res_y_, res_z_).inverse ();
249 2.0 * 6.0 * (
double) (res_y_*res_z_ + res_x_*res_z_ + res_x_*res_y_));
252 for (
int x = 1; x < res_x_-1; ++x)
253 for (
int y = 1; y < res_y_-1; ++y)
254 for (
int z = 1; z < res_z_-1; ++z)
265 polygons.resize (points.
size () / 3);
266 for (std::size_t i = 0; i < polygons.size (); ++i)
270 for (
int j = 0; j < 3; ++j)
271 v.
vertices[j] =
static_cast<int> (i) * 3 + j;
276#define PCL_INSTANTIATE_MarchingCubes(T) template class PCL_EXPORTS pcl::MarchingCubes<T>;
Iterator class for point clouds with or without given indices.
std::size_t size() const
Size of the range the iterator is going through.
void performReconstruction(pcl::PolygonMesh &output) override
Extract the surface.
virtual float getGridValue(Eigen::Vector3i pos)
Method that returns the scalar value at the given grid position.
void getBoundingBox()
Get the bounding box for the input data points.
void interpolateEdge(Eigen::Vector3f &p1, Eigen::Vector3f &p2, float val_p1, float val_p2, Eigen::Vector3f &output)
Interpolate along the voxel edge.
void createSurface(const std::vector< float > &leaf_node, const Eigen::Vector3i &index_3d, pcl::PointCloud< PointNT > &cloud)
Calculate out the corresponding polygons in the leaf node.
void getNeighborList1D(std::vector< float > &leaf, Eigen::Vector3i &index3d)
Method that returns the scalar values of the neighbors of a given 3D position in the grid.
~MarchingCubes()
Destructor.
Define standard C methods and C++ classes that are common to all methods.
void getMinMax3D(const pcl::PointCloud< PointT > &cloud, PointT &min_pt, PointT &max_pt)
Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud.
void toPCLPointCloud2(const pcl::PointCloud< PointT > &cloud, pcl::PCLPointCloud2 &msg)
Convert a pcl::PointCloud<T> object to a PCLPointCloud2 binary data blob.
const unsigned int edgeTable[256]
const int triTable[256][16]
Describes a set of vertices in a polygon mesh, by basically storing an array of indices.