RDB 2
queryStat.hpp
Go to the documentation of this file.
1 /*
2  *******************************************************************************
3  *
4  * Copyright 2021 RIEGL Laser Measurement Systems
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  *
20  *******************************************************************************
21  */
22 /*!
23  *******************************************************************************
24  *
25  * \file queryStat.hpp
26  * \author RIEGL LMS GmbH, Austria
27  * \brief Point statistics query
28  * \version 2015-10-14/AW: Initial version
29  * \version 2016-11-07/AW: Optionally filter index graph nodes (#2390)
30  * \version 2017-11-24/AW: Constructors declared as "explicit" (#2825)
31  * \version 2018-07-05/AW: Wrappers for minimum() and maximum() added
32  * \version 2019-11-05/AW: Optionally return cleaned attribute extents (#3071)
33  *
34  *******************************************************************************
35  */
36 
37 #ifndef RIEGL_RDB_POINTCLOUD_QUERYSTAT_HPP
38 #define RIEGL_RDB_POINTCLOUD_QUERYSTAT_HPP
39 
40 //---< INCLUDES >---------------------------------------------------------------
41 
42 #include <memory>
43 #include <string>
44 #include <vector>
45 #include <cstdint>
50 
51 //---< NAMESPACE >--------------------------------------------------------------
52 
53 namespace riegl {
54 namespace rdb {
55 namespace pointcloud {
56 
57 //---< CLASS QueryStat >--------------------------------------------------------
58 /*!
59  * \brief Point statistics query
60  *
61  * This query provides point attribute statistics like minimum and
62  * maximum value.
63  *
64  * \see riegl::rdb::Pointcloud::stat()
65  *
66  * \note You either must delete the query object or call close()
67  * __before__ the parent Pointcloud instance is closed/deleted!
68  */
69 class QueryStat
70 {
71 public:
72  /*!
73  * \brief Default constructor
74  *
75  * Creates a null query - i.e. the query cannot be used to read stats.
76  *
77  * \see riegl::rdb::Pointcloud::stat()
78  */
79  explicit QueryStat();
80 
81  /*!
82  * \brief Constructor
83  *
84  * Creates a query prepared for reading stats.
85  *
86  * \note You cannot create new QueryStat objects this way,
87  * use riegl::rdb::Pointcloud::stat() instead.
88  */
89  explicit QueryStat(riegl::rdb::PointcloudData *pointcloud);
90 
91  /*!
92  * \brief Check if query is not null
93  *
94  * \see valid()
95  */
96  operator bool() const;
97 
98  /*!
99  * \brief Check if query is not null
100  *
101  * A null query cannot be used to read stats.
102  */
103  bool valid() const;
104 
105  /*!
106  * \brief Finish query
107  *
108  * Call this function when done with reading stats.
109  */
110  void close();
111 
112  /*!
113  * \brief Get index graph
114  *
115  * This function returns a simple directed graph which represents
116  * the index structure that is used to organize the point cloud.
117  *
118  * The optional filter expression can be used to select particular
119  * graph nodes - if no filter is given, all nodes will be returned.
120  * Filter expression syntax see riegl::rdb::Pointcloud::select().
121  *
122  * Details see description of class GraphNode.
123  */
124  void index(
125  GraphNode &root, //!< [out] graph root node
126  const std::string &filter = std::string() //!< [in] optional filter expression
127  );
129  const std::string &filter = std::string() //!< [in] optional filter expression
130  )
131  {
132  GraphNode result;
133  index(result, filter);
134  return result;
135  }
136 
137  /*!
138  * \brief Lowest value of node
139  *
140  * Provides the attribute's minimum value of a branch (i.e. node and children).
141  * If the node ID is zero, then the minimum value of all points is returned.
142  *
143  * The target buffer is expected to be s*d bytes large, where
144  * __s__ is the size of one element as defined by 'dataType' and
145  * __d__ is the number of attribute dimensions (elements).
146  */
147  void minimum(
148  const GraphNode::ID &nodeID, //!< [in] node identifier
149  const std::string &attribute, //!< [in] attribute name
150  const DataType dataType, //!< [in] data type of target buffer
151  void *buffer, //!< [out] buffer for minimum value
152  const bool cleaned=false //!< [in] true: ignore invalid values
153  );
154 
155  //! \copydoc minimum()
156  template <typename ValueType>
157  void minimum(
158  const GraphNode::ID &nodeID, //!< [in] node identifier
159  const std::string &attribute, //!< [in] attribute name
160  ValueType &buffer, //!< [out] buffer (data, pointer to data, std::array or std::vector)
161  const bool cleaned=false //!< [in] true: ignore invalid values
162  )
163  {
164  minimum(nodeID, attribute, dataTypeOf(buffer), dataPointerOf(buffer), cleaned);
165  }
166 
167  //! \copydoc minimum()
168  template <typename ValueType>
169  void minimum(
170  const GraphNode::ID &nodeID, //!< [in] node identifier
171  const std::string &attribute, //!< [in] attribute name
172  ValueType *buffer, //!< [out] buffer (data, pointer to data, std::array or std::vector)
173  const bool cleaned=false //!< [in] true: ignore invalid values
174  )
175  {
176  minimum(nodeID, attribute, dataTypeOf(buffer), buffer, cleaned);
177  }
178 
179  /*!
180  * \brief Highest value of node
181  *
182  * Provides the attribute's maximum value of a branch (i.e. node and children).
183  * If the node ID is zero, then the maximum value of all points is returned.
184  *
185  * The target buffer is expected to be s*d bytes large, where
186  * __s__ is the size of one element as defined by 'dataType' and
187  * __d__ is the number of attribute dimensions (elements).
188  */
189  void maximum(
190  const GraphNode::ID &nodeID, //!< [in] node identifier
191  const std::string &attribute, //!< [in] attribute name
192  const DataType dataType, //!< [in] data type of target buffer
193  void *buffer, //!< [out] buffer for maximum value
194  const bool cleaned=false //!< [in] true: ignore invalid values
195  );
196 
197  //! \copydoc maximum()
198  template <typename ValueType>
199  void maximum(
200  const GraphNode::ID &nodeID, //!< [in] node identifier
201  const std::string &attribute, //!< [in] attribute name
202  ValueType &buffer, //!< [out] buffer (data, pointer to data, std::array or std::vector)
203  const bool cleaned=false //!< [in] true: ignore invalid values
204  )
205  {
206  maximum(nodeID, attribute, dataTypeOf(buffer), dataPointerOf(buffer), cleaned);
207  }
208 
209  //! \copydoc maximum()
210  template <typename ValueType>
211  void maximum(
212  const GraphNode::ID &nodeID, //!< [in] node identifier
213  const std::string &attribute, //!< [in] attribute name
214  ValueType *buffer, //!< [out] buffer (data, pointer to data, std::array or std::vector)
215  const bool cleaned=false //!< [in] true: ignore invalid values
216  )
217  {
218  maximum(nodeID, attribute, dataTypeOf(buffer), buffer, cleaned);
219  }
220 
221  /*!
222  * \brief Attribute revision
223  *
224  * Provides the ID of the last transaction that has modified the attribute
225  * in any node of the given branch.
226  */
227  void revision(
228  const GraphNode::ID &nodeID, //!< [in] node identifier
229  const std::string &attribute, //!< [in] attribute name
230  Transaction::ID &revision //!< [out] transaction ID, see above
231  );
233  const GraphNode::ID &nodeID, //!< [in] node identifier
234  const std::string &attribute //!< [in] attribute name
235  )
236  {
237  Transaction::ID result;
238  revision(nodeID, attribute, result);
239  return result;
240  }
241 
242 private:
243  struct Private;
244  std::shared_ptr<Private> data;
245 };
246 
247 }}} // namespace riegl::rdb::pointcloud
248 
249 #endif // RIEGL_RDB_POINTCLOUD_QUERYSTAT_HPP
riegl::rdb::pointcloud::GraphNode
Graph Node.
Definition: graphNode.hpp:71
riegl::rdb::pointcloud::QueryStat::valid
bool valid() const
Check if query is not null.
riegl::rdb::pointcloud::QueryStat::close
void close()
Finish query.
riegl
RIEGL Laser Measurement Systems GmbH, Austria.
Definition: context.hpp:48
riegl::rdb::pointcloud::Transaction::ID
uint32_t ID
Definition: transaction.hpp:58
riegl::rdb::pointcloud::dataTypeOf
DataType dataTypeOf()
Convenience wrapper for DataTypeOf class.
Definition: dataTypes.hpp:146
riegl::rdb::pointcloud::QueryStat::index
GraphNode index(const std::string &filter=std::string())
Definition: queryStat.hpp:128
riegl::rdb::pointcloud::QueryStat::index
void index(GraphNode &root, const std::string &filter=std::string())
Get index graph.
riegl::rdb::pointcloud::QueryStat::maximum
void maximum(const GraphNode::ID &nodeID, const std::string &attribute, ValueType &buffer, const bool cleaned=false)
Highest value of node.
Definition: queryStat.hpp:199
riegl::rdb::pointcloud::QueryStat::minimum
void minimum(const GraphNode::ID &nodeID, const std::string &attribute, ValueType &buffer, const bool cleaned=false)
Lowest value of node.
Definition: queryStat.hpp:157
riegl::rdb::pointcloud::QueryStat::revision
Transaction::ID revision(const GraphNode::ID &nodeID, const std::string &attribute)
Definition: queryStat.hpp:232
transaction.hpp
Point cloud transaction.
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
dataTypes.hpp
Point attribute access data types.
riegl::rdb::pointcloud::dataPointerOf
ValueType * dataPointerOf(ValueType *const value)
Get pointer to variable or to data in a std::array or vector container.
Definition: dataTypes.hpp:175
riegl::rdb::pointcloud::QueryStat::minimum
void minimum(const GraphNode::ID &nodeID, const std::string &attribute, ValueType *buffer, const bool cleaned=false)
Lowest value of node.
Definition: queryStat.hpp:169
riegl::rdb::pointcloud::QueryStat::QueryStat
QueryStat()
Default constructor.
riegl::rdb::pointcloud::QueryStat::maximum
void maximum(const GraphNode::ID &nodeID, const std::string &attribute, ValueType *buffer, const bool cleaned=false)
Highest value of node.
Definition: queryStat.hpp:211
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.
graphNode.hpp
Index graph node.
pointcloudData.hpp
Pointcloud class implementation details.
riegl::rdb::pointcloud::QueryStat::revision
void revision(const GraphNode::ID &nodeID, const std::string &attribute, Transaction::ID &revision)
Attribute revision.
riegl::rdb::pointcloud::DataType
DataType
Point attribute access data type.
Definition: dataTypes.hpp:55
riegl::rdb::pointcloud::GraphNode::ID
uint32_t ID
Definition: graphNode.hpp:74