RDB 2
rdb-example-06-database-stat.cpp
/*
*******************************************************************************
*
* Copyright 2023 RIEGL Laser Measurement Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*******************************************************************************
*/
/*!
*******************************************************************************
*
* \file rdb-example-06-database-stat.cpp
* \author RIEGL LMS GmbH, Austria
* \brief RDB example 6: Database statistics
* \version 2015-10-14/AW: Initial version
* \version 2016-01-20/AW: Typos fixed
* \version 2017-01-31/AW: Check whether the file is a RDB 2 database file
* \version 2018-06-22/AW: Attribute length type changed to uint32 (#3117)
* \version 2018-07-10/AW: Use simplified versions of minimum() and maximum()
*
* This example shows how to open an existing database and output some
* information about the database like the list of point attributes,
* number of points and point cloud extents.
*
* Build instructions see "interface/cpp/riegl/README.TXT".
*
*******************************************************************************
*/
#include <array>
#include <vector>
#include <iomanip>
#include <iostream>
#include <exception>
#include <riegl/rdb.hpp>
int main()
{
try
{
// New RDB library context
// Before opening the file, we can (optionally) check whether it is
// a RDB 2 database file (otherwise open() will raise an exception):
if (!context.databaseFileTypeCheck("pointcloud.rdbx"))
{
throw std::runtime_error("This is not a RDB 2 database file!");
}
// Access existing database
riegl::rdb::Pointcloud rdb(context);
rdb.open("pointcloud.rdbx", settings);
std::cout << std::endl << "POINT ATTRIBUTES:" << std::endl;
{
// Get list of point attributes
std::vector<std::string> attributes = rdb.pointAttribute().list();
for (auto it = attributes.begin(); it != attributes.end(); it++)
{
// Get details of current point attribute
const PointAttribute attribute = rdb.pointAttribute().get(*it);
// Output point attribute
std::cout << " Name: " << attribute.name << std::endl;
std::cout << " Title: " << attribute.title << std::endl;
std::cout << " Description: " << attribute.description << std::endl;
std::cout << " Unit: " << attribute.unitSymbol << std::endl;
std::cout << " Length: " << attribute.length << std::endl;
std::cout << " Resolution: " << attribute.resolution << std::endl;
std::cout << " MinimumValue: " << attribute.minimumValue << std::endl;
std::cout << " MaximumValue: " << attribute.maximumValue << std::endl;
std::cout << " DefaultValue: " << attribute.defaultValue << std::endl;
std::cout << "------------------------------------------" << std::endl;
}
}
std::cout << std::endl << "POINT CLOUD STATISTICS:" << std::endl;
{
// Get index graph root node
// Get point cloud extents
using namespace riegl::rdb::pointcloud;
std::array<double, 3> minimum, maximum;
stat.minimum(root, RDB_RIEGL_XYZ, minimum);
stat.maximum(root, RDB_RIEGL_XYZ, maximum);
// Output point cloud statistics
std::cout << std::fixed << std::setprecision(3);
std::cout << " Total point count: " << root.pointCountTotal << std::endl;
std::cout << " Minimum X, Y, Z: " << minimum[0] << ", " << minimum[1] << ", " << minimum[2] << std::endl;
std::cout << " Maximum X, Y, Z: " << maximum[0] << ", " << maximum[1] << ", " << maximum[2] << std::endl;
}
// Success
return 0;
}
catch(const riegl::rdb::Error &error)
{
std::cerr << error.what() << " (" << error.details() << ")" << std::endl;
return 1; // error
}
catch(const std::exception &error)
{
std::cerr << error.what() << std::endl;
return 1; // error
}
}
riegl::rdb::pointcloud::PointAttributes::list
std::vector< std::string > list() const
Query attribute names.
riegl::rdb::pointcloud::GraphNode
Graph Node.
Definition: graphNode.hpp:75
riegl::rdb::Pointcloud::open
void open(const std::string &location, const pointcloud::OpenSettings &settings)
Open existing database.
riegl::rdb::pointcloud::PointAttribute
Point attribute description.
Definition: pointAttribute.hpp:120
riegl::rdb::Context::databaseFileTypeCheck
bool databaseFileTypeCheck(const std::string &location) const
Check file type.
riegl::rdb::Error::details
virtual const char * details() const RDB_NO_EXCEPT
Get error details.
riegl::rdb::pointcloud::OpenSettings
Database open settings.
Definition: openSettings.hpp:61
riegl::rdb::Error::what
virtual const char * what() const RDB_NO_EXCEPT
Get error text.
riegl::rdb::Pointcloud::stat
pointcloud::QueryStat stat()
Query point statistics.
riegl::rdb::pointcloud::QueryStat::index
void index(GraphNode &root, const std::string &filter=std::string())
Get index graph.
riegl::rdb::Pointcloud
Main point cloud database class.
Definition: pointcloud.hpp:89
riegl::rdb::pointcloud::QueryStat::maximum
void maximum(const GraphNode::ID &nodeID, const std::string &attribute, const DataType dataType, void *buffer, const bool cleaned=false)
Highest value of node.
riegl::rdb::pointcloud::QueryStat
Point statistics query.
Definition: queryStat.hpp:69
rdb.hpp
Main RDB library include file.
riegl::rdb::pointcloud
RDB point cloud classes.
Definition: context.hpp:55
default.hpp
Master include file for RIEGL defaults.
riegl::rdb::pointcloud::QueryStat::minimum
void minimum(const GraphNode::ID &nodeID, const std::string &attribute, const DataType dataType, void *buffer, const bool cleaned=false)
Lowest value of node.
riegl::rdb::Error
Database error class.
Definition: error.hpp:61
riegl::rdb::pointcloud::GraphNode::pointCountTotal
PointCount pointCountTotal
total number of points in all leaf nodes of the branch
Definition: graphNode.hpp:84
riegl::rdb::Pointcloud::pointAttribute
pointcloud::PointAttributes & pointAttribute()
Manage point attributes.
riegl::rdb::pointcloud::PointAttribute::name
std::string name
unique attribute name (for queries)
Definition: pointAttribute.hpp:152
riegl::rdb::pointcloud::PointAttributes::get
PointAttribute get(const std::string &name) const
Query attribute details.
riegl::rdb::Context
Library context.
Definition: context.hpp:75