RDB 2: rdb-example-08-invert-points.py

| RDB 2

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rdb-example-08-invert-points.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 #
4 #*******************************************************************************
5 #
6 # Copyright 2026 RIEGL Laser Measurement Systems
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20 # SPDX-License-Identifier: Apache-2.0
21 #
22 #*******************************************************************************
23 #
24 """
25 rdb-example-08-invert-points.py
26
27 This example shows how to open an existing database and to invert
28 a point attribute by switching the "riegl.selected" and "riegl.visible"
29 bits from 0 to 1 and vice-versa ("bit flip").
30 Please note that this could also be accomplished by combining select and
31 update queries as shown in "rdb-example-4-update-points.cpp", but the
32 invert query might be faster (lower processing time) and easier to use.
33 This example is based on the database of rdb-example-1-create-database.
34 """
35
36 import riegl.rdb
37
38 # Access existing database
39 with riegl.rdb.rdb_open("pointcloud.rdbx") as rdb:
40 # Before we can modify the database, we must start a transaction
41 with riegl.rdb.Transaction(
42 rdb, # point cloud object
43 "Invert", # transaction title
44 "Point Switcher v1.0" # software name
45 ) as transaction:
46
47 def define_attribute(name, title, description, default_value):
48 """Helper function to define a dynamic point attribute"""
49 if not rdb.point_attributes.exists(name):
50 attribute = riegl.rdb.PointAttribute(rdb)
51 attribute.name = name
52 attribute.title = title
53 attribute.description = description
54 attribute.unit_symbol = ""
55 attribute.length = 1
56 attribute.resolution = 1
57 attribute.minimum_value = 0
58 attribute.maximum_value = 1
59 attribute.default_value = default_value
60 attribute.storage_class = riegl.rdb.PointAttribute.StorageClass.DYNAMIC
61 rdb.point_attributes.add(attribute)
62
63 # Make sure that "selected" and "visible" attributes are defined
64 define_attribute("riegl.selected", "Selected", "Point selected", 0.0)
65 define_attribute("riegl.visible", "Visible", "Point visible", 1.0)
66
67 # Flip the "riegl.selected" bits of all points
68 with rdb.invert() as invert:
69 invert.attribute("riegl.selected")
70 while invert.next(10000) > 0:
71 print(f"{invert.progress()}% done")
72
73 # Flip the "riegl.visible" bits of all selected points (i.e.
74 # where the point attribute "riegl.selected" is set to 1).
75 with rdb.invert("riegl.selected == 1") as invert:
76 invert.attribute("riegl.visible")
77 while invert.next(10000) > 0:
78 print(f"{invert.progress()}% done")
79
80 # Finally commit transaction
81 transaction.commit()