RDB 2
rdb-example-08-invert-points.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-08-invert-points.cpp
* \author RIEGL LMS GmbH, Austria
* \brief RDB example 8: Invert points
* \version 2016-11-14/AW: Initial version
* \version 2018-07-10/AW: Use RIEGL default point attribute constants
*
* This example shows how to open an existing database and to invert
* a point attribute by switching the "riegl.selected" and "riegl.visible"
* bits from 0 to 1 and vice-versa ("bit flip").
* Please note that this could also be accomplished by combining select and
* update queries as shown in "rdb-example-4-update-points.cpp", but the
* invert query might be faster (lower processing time) and easier to use.
* This example is based on the database of rdb-example-1-create-database.
*
* Build instructions see "interface/cpp/riegl/README.TXT".
*
*******************************************************************************
*/
#include <cstdint>
#include <iostream>
#include <exception>
#include <riegl/rdb.hpp>
int main()
{
try
{
// New RDB library context
// Access existing database
riegl::rdb::Pointcloud rdb(context);
rdb.open("pointcloud.rdbx", settings);
// Before we can modify the database, we must start a transaction
rdb, // point cloud object
"Invert", // transaction title
"Point Switcher v1.0" // software name
);
// Make sure that "selected" and "visible" attributes are defined
{
using namespace riegl::rdb::pointcloud;
if (!rdb.pointAttribute().exists(RDB_RIEGL_SELECTED))
{
rdb.pointAttribute().add(RDB_RIEGL_SELECTED);
}
if (!rdb.pointAttribute().exists(RDB_RIEGL_VISIBLE))
{
rdb.pointAttribute().add(RDB_RIEGL_VISIBLE);
}
}
// Flip the "riegl.selected" bits of all points
{
using namespace riegl::rdb::pointcloud;
QueryInvert invert = rdb.invert();
invert.attribute(RDB_RIEGL_SELECTED);
while (const uint32_t count = invert.next(10000))
{
std::cout << invert.progress() << "% done" << std::endl;
}
}
// Flip the "riegl.visible" bits of all selected points (i.e.
// where the point attribute "riegl.selected" is set to 1).
{
using namespace riegl::rdb::pointcloud;
QueryInvert invert = rdb.invert("riegl.selected == 1");
invert.attribute(RDB_RIEGL_VISIBLE);
while (const uint32_t count = invert.next(10000))
{
std::cout << invert.progress() << "% done" << std::endl;
}
}
// 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::open
void open(const std::string &location, const pointcloud::OpenSettings &settings)
Open existing database.
riegl::rdb::pointcloud::PointAttributes::add
void add(const PointAttribute &attribute)
Add new attribute.
riegl::rdb::pointcloud::QueryInvert::attribute
void attribute(const std::string &name)
Define attribute.
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::QueryInvert::next
std::uint32_t next(std::uint32_t count)
Invert points.
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::invert
pointcloud::QueryInvert invert(const std::string &filter=std::string())
Invert points.
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::PointAttributes::exists
bool exists(const std::string &name) const
Check if attribute exists.
riegl::rdb::pointcloud
RDB point cloud classes.
Definition: context.hpp:55
riegl::rdb::pointcloud::QueryInvert::progress
std::uint32_t progress() const
Progress.
default.hpp
Master include file for RIEGL defaults.
riegl::rdb::pointcloud::QueryInvert
Point invert query.
Definition: queryInvert.hpp:77
riegl::rdb::Error
Database error class.
Definition: error.hpp:61
riegl::rdb::Pointcloud::pointAttribute
pointcloud::PointAttributes & pointAttribute()
Manage point attributes.
riegl::rdb::Context
Library context.
Definition: context.hpp:75