2021-01-14 15:49:18 -05:00
|
|
|
/*
|
|
|
|
|
Copyright (c) 2010-2021, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <rtabmap/core/PDALWriter.h>
|
|
|
|
|
#include <rtabmap/utilite/UFile.h>
|
|
|
|
|
#include <rtabmap/utilite/ULogger.h>
|
|
|
|
|
#include <rtabmap/utilite/UStl.h>
|
2021-03-01 09:56:37 -05:00
|
|
|
#include <rtabmap/utilite/UConversion.h>
|
2021-01-14 15:49:18 -05:00
|
|
|
#include <pdal/io/BufferReader.hpp>
|
|
|
|
|
#include <pdal/StageFactory.hpp>
|
|
|
|
|
#include <pdal/PluginManager.hpp>
|
|
|
|
|
|
|
|
|
|
#ifdef RTABMAP_PDAL_16
|
|
|
|
|
#include <pdal/pdal_defines.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <pdal/pdal_features.hpp>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace rtabmap {
|
|
|
|
|
|
|
|
|
|
std::string getPDALSupportedWriters()
|
|
|
|
|
{
|
|
|
|
|
std::string output;
|
|
|
|
|
// Force plugin loading.
|
|
|
|
|
#if PDAL_VERSION_MAJOR>1 || (PDAL_VERSION_MAJOR == 1 && PDAL_VERSION_MINOR > 7) || (PDAL_VERSION_MAJOR == 1 && PDAL_VERSION_MINOR == 7 && PDAL_VERSION_MINOR>=1)
|
|
|
|
|
pdal::StageFactory f;
|
|
|
|
|
pdal::PluginManager<pdal::Stage>::loadAll();
|
|
|
|
|
pdal::StringList stages = pdal::PluginManager<pdal::Stage>::names();
|
|
|
|
|
#else
|
|
|
|
|
pdal::StageFactory f(false);
|
|
|
|
|
pdal::StringList stages = pdal::PluginManager::names(PF_PluginType_Writer);
|
|
|
|
|
#endif
|
|
|
|
|
for(pdal::StringList::iterator iter=stages.begin(); iter!=stages.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
if(!uStrContains(*iter, "writers"))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(iter->compare("writers.null") == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(iter!=stages.begin())
|
|
|
|
|
{
|
|
|
|
|
output += " ";
|
|
|
|
|
}
|
|
|
|
|
output += UFile::getExtension(*iter);
|
|
|
|
|
}
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 09:56:37 -05:00
|
|
|
int savePDALFile(const std::string & filePath,
|
|
|
|
|
const pcl::PointCloud<pcl::PointXYZ> & cloud,
|
|
|
|
|
const std::vector<int> & cameraIds,
|
|
|
|
|
bool binary)
|
2021-01-14 15:49:18 -05:00
|
|
|
{
|
2021-03-01 09:56:37 -05:00
|
|
|
UASSERT_MSG(cameraIds.empty() || cameraIds.size() == cloud.size(),
|
|
|
|
|
uFormat("cameraIds=%d cloud=%d", (int)cameraIds.size(), (int)cloud.size()).c_str());
|
|
|
|
|
|
2021-01-14 15:49:18 -05:00
|
|
|
pdal::PointTable table;
|
|
|
|
|
|
2021-03-01 09:56:37 -05:00
|
|
|
if(!cameraIds.empty())
|
|
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::PointSourceId});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z});
|
|
|
|
|
}
|
2021-01-14 15:49:18 -05:00
|
|
|
pdal::BufferReader bufferReader;
|
|
|
|
|
|
|
|
|
|
pdal::PointViewPtr view(new pdal::PointView(table));
|
|
|
|
|
for(size_t i=0; i<cloud.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
view->setField(pdal::Dimension::Id::X, i, cloud.at(i).x);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Y, i, cloud.at(i).y);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Z, i, cloud.at(i).z);
|
2021-03-01 09:56:37 -05:00
|
|
|
if(!cameraIds.empty())
|
|
|
|
|
{
|
|
|
|
|
view->setField(pdal::Dimension::Id::PointSourceId, i, cameraIds.at(i));
|
|
|
|
|
}
|
2021-01-14 15:49:18 -05:00
|
|
|
}
|
|
|
|
|
bufferReader.addView(view);
|
|
|
|
|
|
|
|
|
|
pdal::StageFactory factory;
|
2021-03-01 09:56:37 -05:00
|
|
|
std::string ext = UFile::getExtension(filePath);
|
2025-03-29 19:08:32 -07:00
|
|
|
pdal::Stage *writer = factory.createStage("writers." + (ext.compare("laz")==0?"las":ext));
|
2021-01-14 15:49:18 -05:00
|
|
|
if(writer)
|
|
|
|
|
{
|
|
|
|
|
pdal::Options writerOps;
|
|
|
|
|
writerOps.add("filename", filePath);
|
2021-03-01 09:56:37 -05:00
|
|
|
if(ext.compare("ply")==0) writerOps.add("storage_mode", binary?"little endian":"ascii"); // PLY
|
|
|
|
|
if(ext.compare("pcd")==0) writerOps.add("compression", binary?"binary":"ascii"); // PCD
|
2025-03-29 19:08:32 -07:00
|
|
|
if(ext.compare("laz")==0) writerOps.add("compression", "lazperf");
|
2021-01-14 15:49:18 -05:00
|
|
|
|
|
|
|
|
writer->setOptions(writerOps);
|
|
|
|
|
writer->setInput(bufferReader);
|
|
|
|
|
|
|
|
|
|
writer->prepare(table);
|
|
|
|
|
writer->execute(table);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UERROR("PDAL: cannot find writer for extension \"%s\". Available extensions: \"%s\"",
|
|
|
|
|
UFile::getExtension(filePath).c_str(),
|
|
|
|
|
getPDALSupportedWriters().c_str());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0; //success
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 09:56:37 -05:00
|
|
|
int savePDALFile(const std::string & filePath,
|
|
|
|
|
const pcl::PointCloud<pcl::PointXYZRGB> & cloud,
|
|
|
|
|
const std::vector<int> & cameraIds,
|
2021-09-07 15:57:23 -04:00
|
|
|
bool binary,
|
|
|
|
|
const std::vector<float> & intensities)
|
2021-01-14 15:49:18 -05:00
|
|
|
{
|
2021-03-01 09:56:37 -05:00
|
|
|
UASSERT_MSG(cameraIds.empty() || cameraIds.size() == cloud.size(),
|
|
|
|
|
uFormat("cameraIds=%d cloud=%d", (int)cameraIds.size(), (int)cloud.size()).c_str());
|
2021-09-07 15:57:23 -04:00
|
|
|
UASSERT_MSG(intensities.empty() || intensities.size() == cloud.size(),
|
|
|
|
|
uFormat("intensities=%d cloud=%d", (int)intensities.size(), (int)cloud.size()).c_str());
|
2021-03-01 09:56:37 -05:00
|
|
|
|
2021-01-14 15:49:18 -05:00
|
|
|
pdal::PointTable table;
|
|
|
|
|
|
2021-09-07 15:57:23 -04:00
|
|
|
if(!intensities.empty() && !cameraIds.empty())
|
|
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::Red,
|
|
|
|
|
pdal::Dimension::Id::Green,
|
|
|
|
|
pdal::Dimension::Id::Blue,
|
|
|
|
|
pdal::Dimension::Id::PointSourceId,
|
|
|
|
|
pdal::Dimension::Id::Intensity});
|
|
|
|
|
}
|
|
|
|
|
else if(!intensities.empty())
|
|
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::Red,
|
|
|
|
|
pdal::Dimension::Id::Green,
|
|
|
|
|
pdal::Dimension::Id::Blue,
|
|
|
|
|
pdal::Dimension::Id::Intensity});
|
|
|
|
|
}
|
|
|
|
|
else if(!cameraIds.empty())
|
2021-03-01 09:56:37 -05:00
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::Red,
|
|
|
|
|
pdal::Dimension::Id::Green,
|
|
|
|
|
pdal::Dimension::Id::Blue,
|
|
|
|
|
pdal::Dimension::Id::PointSourceId});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::Red,
|
|
|
|
|
pdal::Dimension::Id::Green,
|
|
|
|
|
pdal::Dimension::Id::Blue});
|
|
|
|
|
}
|
2021-01-14 15:49:18 -05:00
|
|
|
pdal::BufferReader bufferReader;
|
|
|
|
|
|
|
|
|
|
pdal::PointViewPtr view(new pdal::PointView(table));
|
|
|
|
|
for(size_t i=0; i<cloud.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
view->setField(pdal::Dimension::Id::X, i, cloud.at(i).x);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Y, i, cloud.at(i).y);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Z, i, cloud.at(i).z);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Red, i, cloud.at(i).r);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Green, i, cloud.at(i).g);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Blue, i, cloud.at(i).b);
|
2021-03-01 09:56:37 -05:00
|
|
|
if(!cameraIds.empty())
|
|
|
|
|
{
|
|
|
|
|
view->setField(pdal::Dimension::Id::PointSourceId, i, cameraIds.at(i));
|
|
|
|
|
}
|
2021-09-07 15:57:23 -04:00
|
|
|
if(!intensities.empty())
|
|
|
|
|
{
|
|
|
|
|
view->setField(pdal::Dimension::Id::Intensity, i, (unsigned short)intensities.at(i));
|
|
|
|
|
}
|
2021-01-14 15:49:18 -05:00
|
|
|
}
|
|
|
|
|
bufferReader.addView(view);
|
|
|
|
|
|
|
|
|
|
pdal::StageFactory factory;
|
2021-03-01 09:56:37 -05:00
|
|
|
std::string ext = UFile::getExtension(filePath);
|
2025-03-29 19:08:32 -07:00
|
|
|
pdal::Stage *writer = factory.createStage("writers." + (ext.compare("laz")==0?"las":ext));
|
2021-01-14 15:49:18 -05:00
|
|
|
if(writer)
|
|
|
|
|
{
|
|
|
|
|
pdal::Options writerOps;
|
|
|
|
|
writerOps.add("filename", filePath);
|
2021-03-01 09:56:37 -05:00
|
|
|
if(ext.compare("ply")==0) writerOps.add("storage_mode", binary?"little endian":"ascii"); // PLY
|
|
|
|
|
if(ext.compare("pcd")==0) writerOps.add("compression", binary?"binary":"ascii"); // PCD
|
2025-03-29 19:08:32 -07:00
|
|
|
if(ext.compare("laz")==0) writerOps.add("compression", "lazperf");
|
2021-01-14 15:49:18 -05:00
|
|
|
|
|
|
|
|
writer->setOptions(writerOps);
|
|
|
|
|
writer->setInput(bufferReader);
|
|
|
|
|
|
|
|
|
|
writer->prepare(table);
|
|
|
|
|
writer->execute(table);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UERROR("PDAL: cannot find writer for extension \"%s\". Available extensions: \"%s\"",
|
|
|
|
|
UFile::getExtension(filePath).c_str(),
|
|
|
|
|
getPDALSupportedWriters().c_str());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0; //success
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 09:56:37 -05:00
|
|
|
int savePDALFile(const std::string & filePath,
|
|
|
|
|
const pcl::PointCloud<pcl::PointXYZRGBNormal> & cloud,
|
|
|
|
|
const std::vector<int> & cameraIds,
|
2021-09-07 15:57:23 -04:00
|
|
|
bool binary,
|
|
|
|
|
const std::vector<float> & intensities)
|
2021-01-14 15:49:18 -05:00
|
|
|
{
|
2021-03-01 09:56:37 -05:00
|
|
|
UASSERT_MSG(cameraIds.empty() || cameraIds.size() == cloud.size(),
|
|
|
|
|
uFormat("cameraIds=%d cloud=%d", (int)cameraIds.size(), (int)cloud.size()).c_str());
|
2021-09-07 15:57:23 -04:00
|
|
|
UASSERT_MSG(intensities.empty() || intensities.size() == cloud.size(),
|
|
|
|
|
uFormat("intensities=%d cloud=%d", (int)intensities.size(), (int)cloud.size()).c_str());
|
2021-03-01 09:56:37 -05:00
|
|
|
|
2021-01-14 15:49:18 -05:00
|
|
|
pdal::PointTable table;
|
|
|
|
|
|
2021-09-07 15:57:23 -04:00
|
|
|
if(!intensities.empty() && !cameraIds.empty())
|
|
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::Red,
|
|
|
|
|
pdal::Dimension::Id::Green,
|
|
|
|
|
pdal::Dimension::Id::Blue,
|
|
|
|
|
pdal::Dimension::Id::NormalX,
|
|
|
|
|
pdal::Dimension::Id::NormalY,
|
|
|
|
|
pdal::Dimension::Id::NormalZ,
|
|
|
|
|
pdal::Dimension::Id::PointSourceId,
|
|
|
|
|
pdal::Dimension::Id::Intensity});
|
|
|
|
|
}
|
|
|
|
|
else if(!intensities.empty())
|
|
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::Red,
|
|
|
|
|
pdal::Dimension::Id::Green,
|
|
|
|
|
pdal::Dimension::Id::Blue,
|
|
|
|
|
pdal::Dimension::Id::NormalX,
|
|
|
|
|
pdal::Dimension::Id::NormalY,
|
|
|
|
|
pdal::Dimension::Id::NormalZ,
|
|
|
|
|
pdal::Dimension::Id::Intensity});
|
|
|
|
|
}
|
|
|
|
|
else if(!cameraIds.empty())
|
2021-03-01 09:56:37 -05:00
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::Red,
|
|
|
|
|
pdal::Dimension::Id::Green,
|
|
|
|
|
pdal::Dimension::Id::Blue,
|
|
|
|
|
pdal::Dimension::Id::NormalX,
|
|
|
|
|
pdal::Dimension::Id::NormalY,
|
|
|
|
|
pdal::Dimension::Id::NormalZ,
|
|
|
|
|
pdal::Dimension::Id::PointSourceId});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::Red,
|
|
|
|
|
pdal::Dimension::Id::Green,
|
|
|
|
|
pdal::Dimension::Id::Blue,
|
|
|
|
|
pdal::Dimension::Id::NormalX,
|
|
|
|
|
pdal::Dimension::Id::NormalY,
|
|
|
|
|
pdal::Dimension::Id::NormalZ});
|
|
|
|
|
}
|
2021-01-14 15:49:18 -05:00
|
|
|
pdal::BufferReader bufferReader;
|
|
|
|
|
|
|
|
|
|
pdal::PointViewPtr view(new pdal::PointView(table));
|
|
|
|
|
for(size_t i=0; i<cloud.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
view->setField(pdal::Dimension::Id::X, i, cloud.at(i).x);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Y, i, cloud.at(i).y);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Z, i, cloud.at(i).z);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Red, i, cloud.at(i).r);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Green, i, cloud.at(i).g);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Blue, i, cloud.at(i).b);
|
|
|
|
|
view->setField(pdal::Dimension::Id::NormalX, i, cloud.at(i).normal_x);
|
|
|
|
|
view->setField(pdal::Dimension::Id::NormalY, i, cloud.at(i).normal_y);
|
|
|
|
|
view->setField(pdal::Dimension::Id::NormalZ, i, cloud.at(i).normal_z);
|
2021-03-01 09:56:37 -05:00
|
|
|
if(!cameraIds.empty())
|
|
|
|
|
{
|
|
|
|
|
view->setField(pdal::Dimension::Id::PointSourceId, i, cameraIds.at(i));
|
|
|
|
|
}
|
2021-09-07 15:57:23 -04:00
|
|
|
if(!intensities.empty())
|
|
|
|
|
{
|
|
|
|
|
view->setField(pdal::Dimension::Id::Intensity, i, (unsigned short)intensities.at(i));
|
|
|
|
|
}
|
2021-01-14 15:49:18 -05:00
|
|
|
}
|
|
|
|
|
bufferReader.addView(view);
|
|
|
|
|
|
|
|
|
|
pdal::StageFactory factory;
|
2021-03-01 09:56:37 -05:00
|
|
|
std::string ext = UFile::getExtension(filePath);
|
2025-03-29 19:08:32 -07:00
|
|
|
pdal::Stage *writer = factory.createStage("writers." + (ext.compare("laz")==0?"las":ext));
|
2021-01-14 15:49:18 -05:00
|
|
|
if(writer)
|
|
|
|
|
{
|
|
|
|
|
pdal::Options writerOps;
|
|
|
|
|
writerOps.add("filename", filePath);
|
2021-03-01 09:56:37 -05:00
|
|
|
if(ext.compare("ply")==0) writerOps.add("storage_mode", binary?"little endian":"ascii"); // PLY
|
|
|
|
|
if(ext.compare("pcd")==0) writerOps.add("compression", binary?"binary":"ascii"); // PCD
|
2025-03-29 19:08:32 -07:00
|
|
|
if(ext.compare("laz")==0) writerOps.add("compression", "lazperf");
|
2021-01-14 15:49:18 -05:00
|
|
|
|
|
|
|
|
writer->setOptions(writerOps);
|
|
|
|
|
writer->setInput(bufferReader);
|
|
|
|
|
|
|
|
|
|
writer->prepare(table);
|
|
|
|
|
writer->execute(table);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UERROR("PDAL: cannot find writer for extension \"%s\". Available extensions: \"%s\"",
|
|
|
|
|
UFile::getExtension(filePath).c_str(),
|
|
|
|
|
getPDALSupportedWriters().c_str());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0; //success
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 09:56:37 -05:00
|
|
|
int savePDALFile(const std::string & filePath,
|
|
|
|
|
const pcl::PointCloud<pcl::PointXYZI> & cloud,
|
|
|
|
|
const std::vector<int> & cameraIds,
|
|
|
|
|
bool binary)
|
2021-01-14 15:49:18 -05:00
|
|
|
{
|
2021-03-01 09:56:37 -05:00
|
|
|
UASSERT_MSG(cameraIds.empty() || cameraIds.size() == cloud.size(),
|
|
|
|
|
uFormat("cameraIds=%d cloud=%d", (int)cameraIds.size(), (int)cloud.size()).c_str());
|
|
|
|
|
|
2021-01-14 15:49:18 -05:00
|
|
|
pdal::PointTable table;
|
|
|
|
|
|
2021-03-01 09:56:37 -05:00
|
|
|
if(!cameraIds.empty())
|
|
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::Intensity,
|
|
|
|
|
pdal::Dimension::Id::PointSourceId});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::Intensity});
|
|
|
|
|
}
|
2021-01-14 15:49:18 -05:00
|
|
|
pdal::BufferReader bufferReader;
|
|
|
|
|
|
|
|
|
|
pdal::PointViewPtr view(new pdal::PointView(table));
|
|
|
|
|
for(size_t i=0; i<cloud.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
view->setField(pdal::Dimension::Id::X, i, cloud.at(i).x);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Y, i, cloud.at(i).y);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Z, i, cloud.at(i).z);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Intensity, i, (unsigned short)cloud.at(i).intensity);
|
2021-03-01 09:56:37 -05:00
|
|
|
if(!cameraIds.empty())
|
|
|
|
|
{
|
|
|
|
|
view->setField(pdal::Dimension::Id::PointSourceId, i, cameraIds.at(i));
|
|
|
|
|
}
|
2021-01-14 15:49:18 -05:00
|
|
|
}
|
|
|
|
|
bufferReader.addView(view);
|
|
|
|
|
|
|
|
|
|
pdal::StageFactory factory;
|
2021-03-01 09:56:37 -05:00
|
|
|
std::string ext = UFile::getExtension(filePath);
|
2025-03-29 19:08:32 -07:00
|
|
|
pdal::Stage *writer = factory.createStage("writers." + (ext.compare("laz")==0?"las":ext));
|
2021-01-14 15:49:18 -05:00
|
|
|
if(writer)
|
|
|
|
|
{
|
|
|
|
|
pdal::Options writerOps;
|
|
|
|
|
writerOps.add("filename", filePath);
|
2021-03-01 09:56:37 -05:00
|
|
|
if(ext.compare("ply")==0) writerOps.add("storage_mode", binary?"little endian":"ascii"); // PLY
|
|
|
|
|
if(ext.compare("pcd")==0) writerOps.add("compression", binary?"binary":"ascii"); // PCD
|
2025-03-29 19:08:32 -07:00
|
|
|
if(ext.compare("laz")==0) writerOps.add("compression", "lazperf");
|
2021-01-14 15:49:18 -05:00
|
|
|
|
|
|
|
|
writer->setOptions(writerOps);
|
|
|
|
|
writer->setInput(bufferReader);
|
|
|
|
|
|
|
|
|
|
writer->prepare(table);
|
|
|
|
|
writer->execute(table);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UERROR("PDAL: cannot find writer for extension \"%s\". Available extensions: \"%s\"",
|
|
|
|
|
UFile::getExtension(filePath).c_str(),
|
|
|
|
|
getPDALSupportedWriters().c_str());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0; //success
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 09:56:37 -05:00
|
|
|
int savePDALFile(const std::string & filePath,
|
|
|
|
|
const pcl::PointCloud<pcl::PointXYZINormal> & cloud,
|
|
|
|
|
const std::vector<int> & cameraIds,
|
|
|
|
|
bool binary)
|
2021-01-14 15:49:18 -05:00
|
|
|
{
|
2021-03-01 09:56:37 -05:00
|
|
|
UASSERT_MSG(cameraIds.empty() || cameraIds.size() == cloud.size(),
|
|
|
|
|
uFormat("cameraIds=%d cloud=%d", (int)cameraIds.size(), (int)cloud.size()).c_str());
|
|
|
|
|
|
2021-01-14 15:49:18 -05:00
|
|
|
pdal::PointTable table;
|
|
|
|
|
|
2021-03-01 09:56:37 -05:00
|
|
|
if(!cameraIds.empty())
|
|
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::Intensity,
|
|
|
|
|
pdal::Dimension::Id::NormalX,
|
|
|
|
|
pdal::Dimension::Id::NormalY,
|
|
|
|
|
pdal::Dimension::Id::NormalZ,
|
|
|
|
|
pdal::Dimension::Id::PointSourceId});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
table.layout()->registerDims({
|
|
|
|
|
pdal::Dimension::Id::X,
|
|
|
|
|
pdal::Dimension::Id::Y,
|
|
|
|
|
pdal::Dimension::Id::Z,
|
|
|
|
|
pdal::Dimension::Id::Intensity,
|
|
|
|
|
pdal::Dimension::Id::NormalX,
|
|
|
|
|
pdal::Dimension::Id::NormalY,
|
|
|
|
|
pdal::Dimension::Id::NormalZ});
|
|
|
|
|
}
|
2021-01-14 15:49:18 -05:00
|
|
|
pdal::BufferReader bufferReader;
|
|
|
|
|
|
|
|
|
|
pdal::PointViewPtr view(new pdal::PointView(table));
|
|
|
|
|
for(size_t i=0; i<cloud.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
view->setField(pdal::Dimension::Id::X, i, cloud.at(i).x);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Y, i, cloud.at(i).y);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Z, i, cloud.at(i).z);
|
|
|
|
|
view->setField(pdal::Dimension::Id::Intensity, i, (unsigned short)cloud.at(i).intensity);
|
|
|
|
|
view->setField(pdal::Dimension::Id::NormalX, i, cloud.at(i).normal_x);
|
|
|
|
|
view->setField(pdal::Dimension::Id::NormalY, i, cloud.at(i).normal_y);
|
|
|
|
|
view->setField(pdal::Dimension::Id::NormalZ, i, cloud.at(i).normal_z);
|
2021-03-01 09:56:37 -05:00
|
|
|
if(!cameraIds.empty())
|
|
|
|
|
{
|
|
|
|
|
view->setField(pdal::Dimension::Id::PointSourceId, i, cameraIds.at(i));
|
|
|
|
|
}
|
2021-01-14 15:49:18 -05:00
|
|
|
}
|
|
|
|
|
bufferReader.addView(view);
|
|
|
|
|
|
|
|
|
|
pdal::StageFactory factory;
|
2021-03-01 09:56:37 -05:00
|
|
|
std::string ext = UFile::getExtension(filePath);
|
2025-03-29 19:08:32 -07:00
|
|
|
pdal::Stage *writer = factory.createStage("writers." + (ext.compare("laz")==0?"las":ext));
|
2021-01-14 15:49:18 -05:00
|
|
|
if(writer)
|
|
|
|
|
{
|
|
|
|
|
pdal::Options writerOps;
|
|
|
|
|
writerOps.add("filename", filePath);
|
2021-03-01 09:56:37 -05:00
|
|
|
if(ext.compare("ply")==0) writerOps.add("storage_mode", binary?"little endian":"ascii"); // PLY
|
|
|
|
|
if(ext.compare("pcd")==0) writerOps.add("compression", binary?"binary":"ascii"); // PCD
|
2025-03-29 19:08:32 -07:00
|
|
|
if(ext.compare("laz")==0) writerOps.add("compression", "lazperf");
|
2021-01-14 15:49:18 -05:00
|
|
|
|
|
|
|
|
writer->setOptions(writerOps);
|
|
|
|
|
writer->setInput(bufferReader);
|
|
|
|
|
|
|
|
|
|
writer->prepare(table);
|
|
|
|
|
writer->execute(table);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UERROR("PDAL: cannot find writer for extension \"%s\". Available extensions: \"%s\"",
|
|
|
|
|
UFile::getExtension(filePath).c_str(),
|
|
|
|
|
getPDALSupportedWriters().c_str());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0; //success
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|