47 #include <boost/uuid/random_generator.hpp>
49 #include <pcl/common/utils.h>
50 #include <pcl/outofcore/octree_abstract_node_container.h>
51 #include <pcl/io/pcd_io.h>
52 #include <pcl/PCLPointCloud2.h>
56 #define _fseeki64 fseeko
57 #elif defined __MINGW32__
58 #define _fseeki64 fseeko64
74 template<
typename Po
intT = pcl::Po
intXYZ>
101 operator[] (std::uint64_t idx)
const override;
160 readRangeSubSample (
const std::uint64_t start,
const std::uint64_t count,
const double percent,
181 return (filelen_ + writebuff_.size ());
189 return ((filelen_ == 0) && writebuff_.empty ());
194 flush (
const bool force_cache_dealloc)
196 flushWritebuff (force_cache_dealloc);
203 return (disk_storage_filename_);
212 PCL_DEBUG (
"[Octree Disk Container] Removing the point data from disk, in file %s\n", disk_storage_filename_.c_str ());
213 boost::filesystem::remove (
static_cast<boost::filesystem::path
> (disk_storage_filename_.c_str ()));
225 if (boost::filesystem::exists (disk_storage_filename_))
227 FILE* fxyz = fopen (
path.string ().c_str (),
"we");
229 FILE* f = fopen (disk_storage_filename_.c_str (),
"rbe");
230 assert (f !=
nullptr);
232 std::uint64_t num =
size ();
234 char* loc =
reinterpret_cast<char*
> ( &p );
236 for (std::uint64_t i = 0; i < num; i++)
238 int seekret = _fseeki64 (f, i *
sizeof (
PointT), SEEK_SET);
240 assert (seekret == 0);
241 std::size_t readlen = fread (loc,
sizeof (
PointT), 1, f);
243 assert (readlen == 1);
246 std::stringstream ss;
249 ss << p.x <<
"\t" << p.y <<
"\t" << p.z <<
"\n";
251 fwrite (ss.str ().c_str (), 1, ss.str ().size (), fxyz);
253 int res = fclose (f);
282 flushWritebuff (
const bool force_cache_dealloc);
285 std::string disk_storage_filename_;
290 std::uint64_t filelen_;
295 const static std::uint64_t READ_BLOCK_SIZE_;
297 static const std::uint64_t WRITE_BUFF_MAX_;
299 static std::mutex rng_mutex_;
300 static boost::mt19937 rand_gen_;
301 static boost::uuids::basic_random_generator<boost::mt19937> uuid_gen_;
std::vector< PointT, Eigen::aligned_allocator< PointT > > AlignedPointTVector
Class responsible for serialization and deserialization of out of core point data.
int read(pcl::PCLPointCloud2::Ptr &output_cloud)
Reads the entire point contents from disk into output_cloud.
void flush(const bool force_cache_dealloc)
Exposed functionality for manually flushing the write buffer during tree creation.
OutofcoreOctreeDiskContainer()
Empty constructor creates disk container and sets filename from random uuid string.
static void getRandomUUIDString(std::string &s)
Generate a universally unique identifier (UUID)
void insertRange(const AlignedPointTVector &src)
Inserts a vector of points into the disk data structure.
void readRangeSubSample_bernoulli(const std::uint64_t start, const std::uint64_t count, const double percent, AlignedPointTVector &dst)
Use bernoulli trials to select points.
void readRange(const std::uint64_t start, const std::uint64_t count, AlignedPointTVector &dst) override
Reads count points into memory from the disk container.
std::uint64_t getDataSize() const
Returns the number of points in the PCD file by reading the PCD header.
std::string & path()
Returns this objects path name.
typename OutofcoreAbstractNodeContainer< PointT >::AlignedPointTVector AlignedPointTVector
std::uint64_t size() const override
Returns the total number of points for which this container is responsible, filelen_ + points in writ...
void convertToXYZ(const boost::filesystem::path &path) override
write points to disk as ascii
void readRangeSubSample(const std::uint64_t start, const std::uint64_t count, const double percent, AlignedPointTVector &dst) override
grab percent*count random points.
bool empty() const override
STL-like empty test.
void push_back(const PointT &p)
Adds a single point to the buffer to be written to disk when the buffer grows sufficiently large,...
PointT operator[](std::uint64_t idx) const override
provides random access to points based on a linear index
~OutofcoreOctreeDiskContainer() override
flushes write buffer, then frees memory
void ignore(const T &...)
Utility function to eliminate unused variable warnings.
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
A point structure representing Euclidean xyz coordinates, and the RGB color.