47 #include <boost/random/mersenne_twister.hpp>
48 #include <boost/uuid/random_generator.hpp>
50 #include <pcl/common/utils.h>
51 #include <pcl/outofcore/octree_abstract_node_container.h>
52 #include <pcl/io/pcd_io.h>
53 #include <pcl/PCLPointCloud2.h>
57 #define _fseeki64 fseeko
58 #elif defined __MINGW32__
59 #define _fseeki64 fseeko64
75 template<
typename Po
intT = pcl::Po
intXYZ>
102 operator[] (std::uint64_t idx)
const override;
161 readRangeSubSample (
const std::uint64_t start,
const std::uint64_t count,
const double percent,
182 return (filelen_ + writebuff_.size ());
190 return ((filelen_ == 0) && writebuff_.empty ());
195 flush (
const bool force_cache_dealloc)
197 flushWritebuff (force_cache_dealloc);
204 return (disk_storage_filename_);
213 PCL_DEBUG (
"[Octree Disk Container] Removing the point data from disk, in file %s\n", disk_storage_filename_.c_str ());
214 boost::filesystem::remove (
static_cast<boost::filesystem::path
> (disk_storage_filename_.c_str ()));
226 if (boost::filesystem::exists (disk_storage_filename_))
228 FILE* fxyz = fopen (
path.string ().c_str (),
"we");
230 FILE* f = fopen (disk_storage_filename_.c_str (),
"rbe");
231 assert (f !=
nullptr);
233 std::uint64_t num =
size ();
235 char* loc =
reinterpret_cast<char*
> ( &p );
237 for (std::uint64_t i = 0; i < num; i++)
239 int seekret = _fseeki64 (f, i *
sizeof (
PointT), SEEK_SET);
241 assert (seekret == 0);
242 std::size_t readlen = fread (loc,
sizeof (
PointT), 1, f);
244 assert (readlen == 1);
247 std::stringstream ss;
250 ss << p.x <<
"\t" << p.y <<
"\t" << p.z <<
"\n";
252 fwrite (ss.str ().c_str (), 1, ss.str ().size (), fxyz);
254 int res = fclose (f);
283 flushWritebuff (
const bool force_cache_dealloc);
286 std::string disk_storage_filename_;
291 std::uint64_t filelen_;
296 const static std::uint64_t READ_BLOCK_SIZE_;
298 static const std::uint64_t WRITE_BUFF_MAX_;
300 static std::mutex rng_mutex_;
301 static boost::mt19937 rand_gen_;
302 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.