RDB 2
rdb-example-01-create-database.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-01-create-database.cpp
* \author RIEGL LMS GmbH, Austria
* \brief RDB example 1: Create new database
* \version 2015-10-14/AW: Initial version
* \version 2016-01-20/AW: Point attribute storage class definition added
* \version 2016-11-29/AW: Shortcut for built-in RIEGL point attributes added
* \version 2018-07-10/AW: Show usage of RIEGL default point attributes
* \version 2019-01-15/AW: Add CreateSettings::chunkMode parameter
*
* This example shows how to create a new RDB point cloud database and define
* some point attributes.
*
* Build instructions see "interface/cpp/riegl/README.TXT".
*
*******************************************************************************
*/
#include <iostream>
#include <exception>
#include <riegl/rdb.hpp>
int main()
{
try
{
// New RDB library context
// New database instance
riegl::rdb::Pointcloud rdb(context);
// Step 1: Create new point cloud database
{
// This object contains all settings that are required
// to create a new RDB point cloud database.
// Define primary point attribute, usually the point coordinates
// details see class riegl::rdb::pointcloud::PointAttribute
settings.primaryAttribute.name = "riegl.xyz";
settings.primaryAttribute.title = "XYZ";
settings.primaryAttribute.description = "Cartesian point coordinates";
settings.primaryAttribute.unitSymbol = "m";
settings.primaryAttribute.length = 3;
settings.primaryAttribute.resolution = 0.00025;
settings.primaryAttribute.minimumValue = -535000.0; // minimum,
settings.primaryAttribute.maximumValue = +535000.0; // maximum and
settings.primaryAttribute.defaultValue = 0.0; // default in m
// Define database settings
settings.chunkSize = 50000; // maximum number of points per chunk
settings.compressionLevel = 10; // 10% compression rate
// Finally create new database
rdb.create("pointcloud.rdbx", settings);
}
// Step 2: Define some additional point attributes
// Please note that there is also a shortcut for built-in
// RIEGL default point attributes which we use to define
// the "riegl.class" attribute at the end of this block.
{
// Before we can modify the database, we must start a transaction
"Initialization", // transaction title
"Example program v1.0" // software name
);
// Target surface reflectance
{
//
attribute.name = "riegl.reflectance";
attribute.title = "Reflectance";
attribute.description = "Target surface reflectance";
attribute.unitSymbol = "dB";
attribute.length = 1;
attribute.resolution = 0.010;
attribute.minimumValue = -100.000; // minimum,
attribute.maximumValue = +100.000; // maximum and
attribute.defaultValue = 0.000; // default in dB
//
rdb.pointAttribute().add(attribute);
}
// Point color
{
//
attribute.name = "riegl.rgba";
attribute.title = "True Color";
attribute.description = "Point color acquired by camera";
attribute.unitSymbol = ""; // has no unit
attribute.length = 4;
attribute.resolution = 1.000;
attribute.minimumValue = 0.000;
attribute.maximumValue = 255.000;
attribute.defaultValue = 255.000;
//
rdb.pointAttribute().add(attribute);
}
// Point classification - by using a shortcut for built-in RIEGL attributes:
{
rdb.pointAttribute().add("riegl.class");
}
// Echo amplitude - by using the constant from "riegl/rdb/default.hpp"
{
rdb.pointAttribute().add(riegl::rdb::pointcloud::RDB_RIEGL_AMPLITUDE);
}
// Finally commit transaction
transaction.commit();
}
// 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::add
void add(const PointAttribute &attribute)
Add new attribute.
riegl::rdb::pointcloud::PointAttribute
Point attribute description.
Definition: pointAttribute.hpp:120
riegl::rdb::Pointcloud::create
void create(const std::string &location, const pointcloud::CreateSettings &settings)
Create new database.
riegl::rdb::pointcloud::CreateSettings::primaryAttribute
riegl::rdb::pointcloud::PointAttribute primaryAttribute
Primary point attribute.
Definition: createSettings.hpp:78
riegl::rdb::pointcloud::PointAttribute::minimumValue
double minimumValue
theoretical minimum value
Definition: pointAttribute.hpp:159
riegl::rdb::Error::details
virtual const char * details() const RDB_NO_EXCEPT
Get error details.
riegl::rdb::pointcloud::TransactionScope::commit
void commit()
Commit transaction.
Definition: transactionScope.hpp:108
riegl::rdb::pointcloud::PointAttribute::defaultValue
double defaultValue
default value (minimum <= default <= maximum)
Definition: pointAttribute.hpp:161
riegl::rdb::pointcloud::PointAttribute::storageClass
std::uint8_t storageClass
storage class
Definition: pointAttribute.hpp:164
riegl::rdb::pointcloud::PointAttribute::unitSymbol
std::string unitSymbol
physical unit symbol (e.g. "m", "rad", "K"), string size limits: [0, 100]
Definition: pointAttribute.hpp:156
riegl::rdb::pointcloud::PointAttribute::CONSTANT
value cannot be changed
Definition: pointAttribute.hpp:132
riegl::rdb::Error::what
virtual const char * what() const RDB_NO_EXCEPT
Get error text.
riegl::rdb::pointcloud::CreateSettings::chunkSize
std::uint32_t chunkSize
Point chunk size.
Definition: createSettings.hpp:122
riegl::rdb::pointcloud::CreateSettings::compressionLevel
std::uint8_t compressionLevel
Data compression level.
Definition: createSettings.hpp:208
riegl::rdb::pointcloud::TransactionScope
Point cloud transaction scope helper class.
Definition: transactionScope.hpp:59
riegl::rdb::Pointcloud
Main point cloud database class.
Definition: pointcloud.hpp:89
rdb.hpp
Main RDB library include file.
riegl::rdb::pointcloud::PointAttribute::VARIABLE
value can change from time to time
Definition: pointAttribute.hpp:133
riegl::rdb::pointcloud::PointAttribute::resolution
double resolution
expected value resolution
Definition: pointAttribute.hpp:158
riegl::rdb::pointcloud::CreateSettings::POINT_COUNT
Definition: createSettings.hpp:97
riegl::rdb::pointcloud::PointAttribute::length
std::uint32_t length
number of dimensions/elements (1: scalar, >1: vector, e.g. 3 for point coordinates)
Definition: pointAttribute.hpp:157
default.hpp
Master include file for RIEGL defaults.
riegl::rdb::pointcloud::CreateSettings::chunkMode
std::uint32_t chunkMode
Point chunk mode.
Definition: createSettings.hpp:113
riegl::rdb::Error
Database error class.
Definition: error.hpp:61
riegl::rdb::pointcloud::PointAttribute::title
std::string title
attribute title (for display), string size limits: [1, 100]
Definition: pointAttribute.hpp:153
riegl::rdb::pointcloud::CreateSettings
Database create settings.
Definition: createSettings.hpp:65
riegl::rdb::Pointcloud::pointAttribute
pointcloud::PointAttributes & pointAttribute()
Manage point attributes.
riegl::rdb::pointcloud::PointAttribute::description
std::string description
attribute description (for display), string size limits: [0, 5000]
Definition: pointAttribute.hpp:155
riegl::rdb::pointcloud::PointAttribute::maximumValue
double maximumValue
theoretical maximum value
Definition: pointAttribute.hpp:160
riegl::rdb::pointcloud::PointAttribute::name
std::string name
unique attribute name (for queries)
Definition: pointAttribute.hpp:152
riegl::rdb::Context
Library context.
Definition: context.hpp:75