RDB 2
queryRemove.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 queryRemove.hpp
26  * \author RIEGL LMS GmbH, Austria
27  * \brief Point remove query
28  * \version 2015-10-14/AW: Initial version
29  * \version 2017-11-24/AW: Constructors declared as "explicit" (#2825)
30  * \version 2018-07-05/AW: Wrapper function bindBuffer() added
31  * \version 2020-01-17/AW: Wrapper function bindMember() added (#3497)
32  *
33  *******************************************************************************
34  */
35 
36 #ifndef RIEGL_RDB_POINTCLOUD_QUERYREMOVE_HPP
37 #define RIEGL_RDB_POINTCLOUD_QUERYREMOVE_HPP
38 
39 //---< INCLUDES >---------------------------------------------------------------
40 
41 #include <memory>
42 #include <string>
43 #include <cstdint>
46 
47 //---< NAMESPACE >--------------------------------------------------------------
48 
49 namespace riegl {
50 namespace rdb {
51 namespace pointcloud {
52 
53 //---< CLASS QueryRemove >------------------------------------------------------
54 /*!
55  * \brief Point remove query
56  *
57  * This class can be used to remove (delete) existing points.
58  *
59  * \see riegl::rdb::Pointcloud::remove()
60  *
61  * \note You either must delete the query object or call close()
62  * __before__ the parent Pointcloud instance is closed/deleted!
63  */
65 {
66 public:
67  /*!
68  * \brief Default constructor
69  *
70  * Creates a null query - i.e. the query cannot be used to remove points.
71  *
72  * \see riegl::rdb::Pointcloud::remove()
73  */
74  explicit QueryRemove();
75 
76  /*!
77  * \brief Constructor
78  *
79  * Creates a query prepared for removing points.
80  *
81  * \note You cannot create new QueryRemove objects this way,
82  * use riegl::rdb::Pointcloud::remove() instead.
83  */
84  explicit QueryRemove(riegl::rdb::PointcloudData *pointcloud);
85 
86  /*!
87  * \brief Check if query is not null
88  *
89  * \see valid()
90  */
91  operator bool() const;
92 
93  /*!
94  * \brief Check if query is not null
95  *
96  * A null query cannot be used to remove points.
97  */
98  bool valid() const;
99 
100  /*!
101  * \brief Finish query
102  *
103  * Call this function when done with removing points.
104  */
105  void close();
106 
107  /*!
108  * \brief Bind attribute buffer
109  *
110  * Use this function to define a source buffer for a point attribute.
111  * Exactly one buffer can be defined for an attribute (i.e. only the
112  * most recently defined buffer will be used).
113  *
114  * The buffer is expected to be n*s*d bytes large, where
115  * __n__ is the number of points defined in next(),
116  * __s__ is the size of one element as defined by 'dataType' and
117  * __d__ is the number of attribute dimensions (elements).
118  *
119  * \note This function just stores the buffer pointer - it does
120  * __NOT__ copy the data contained in the buffer. So make
121  * sure that the buffer remains valid until you call next().
122  *
123  * \note This function expects a buffer for the point ID attribute.
124  *
125  * \see riegl::rdb::pointcloud::PointAttributes
126  */
127  void bind(
128  const std::string &attribute, //!< [in] attribute name
129  const DataType dataType, //!< [in] buffer data type
130  const void *buffer, //!< [in] buffer location
131  const int32_t stride = 0 //!< [in] bytes between beginnings of successive elements (0: auto)
132  );
133 
134  //! \copydoc bind()
135  template <typename ValueType>
137  const std::string &attribute, //!< [in] attribute name
138  const ValueType &buffer, //!< [in] buffer (data, pointer to data, std::array or std::vector)
139  const int32_t stride = 0 //!< [in] bytes between beginnings of successive elements (0: auto)
140  )
141  {
142  bind(attribute, dataTypeOf(buffer), dataPointerOf(buffer), stride);
143  }
144 
145  /*!
146  * \brief Bind attribute buffer
147  *
148  * This is a variant of bindBuffer() that allows to bind a member variable
149  * of an object as attribute buffer. The object can be part of a container
150  * that stores the objects contiguously (e.g. std::vector, std::array) and
151  * the stride is automatically derived from the object size.
152  *
153  * \see bindBuffer()
154  */
155  template <typename ObjectType, typename MemberPointer>
157  const std::string &attribute, //!< [in] attribute name
158  const ObjectType &object, //!< [in] e.g. first object of container
159  const MemberPointer member //!< [in] object member variable pointer
160  )
161  {
162  bindBuffer(
163  attribute, object.*member,
164  static_cast<int32_t>(sizeof(ObjectType))
165  );
166  }
167 
168  //! \copydoc bindMember()
169  template <typename ObjectType, typename MemberPointer>
171  const std::string &attribute, //!< [in] attribute name
172  const ObjectType &object, //!< [in] e.g. first object of container
173  const MemberPointer member, //!< [in] object member variable pointer
174  const size_t index //!< [in] index for array-like object members
175  )
176  {
177  bindBuffer(
178  attribute, (object.*member)[index],
179  static_cast<int32_t>(sizeof(ObjectType))
180  );
181  }
182 
183  /*!
184  * \brief Remove points
185  *
186  * Use this function to actually remove (delete) the points.
187  * All points given by their point ID stored in the previously
188  * bound attribute buffer are removed from the database.
189  *
190  * Afterwards you may re-fill the buffers or define a new buffer
191  * with bind() and call next() again until all points have been
192  * removed.
193  *
194  * \note If __no__ point ID buffer is given and 'count' is 0xDEADFEED,
195  * then __all__ points are removed and next() always returns 1.
196  *
197  * \returns the number of points removed
198  */
199  uint32_t next(
200  uint32_t count //!< [in] size of source buffers in terms of points
201  );
202 
203 private:
204  struct Private;
205  std::shared_ptr<Private> data;
206 };
207 
208 }}} // namespace riegl::rdb::pointcloud
209 
210 #endif // RIEGL_RDB_POINTCLOUD_QUERYREMOVE_HPP
riegl::rdb::pointcloud::QueryRemove::bindMember
void bindMember(const std::string &attribute, const ObjectType &object, const MemberPointer member, const size_t index)
Bind attribute buffer.
Definition: queryRemove.hpp:170
riegl
RIEGL Laser Measurement Systems GmbH, Austria.
Definition: context.hpp:48
riegl::rdb::pointcloud::QueryRemove::QueryRemove
QueryRemove()
Default constructor.
riegl::rdb::pointcloud::QueryRemove::valid
bool valid() const
Check if query is not null.
riegl::rdb::pointcloud::QueryRemove::bindMember
void bindMember(const std::string &attribute, const ObjectType &object, const MemberPointer member)
Bind attribute buffer.
Definition: queryRemove.hpp:156
riegl::rdb::pointcloud::QueryRemove::close
void close()
Finish query.
riegl::rdb::pointcloud::dataTypeOf
DataType dataTypeOf()
Convenience wrapper for DataTypeOf class.
Definition: dataTypes.hpp:146
riegl::rdb::pointcloud::QueryRemove::next
uint32_t next(uint32_t count)
Remove points.
riegl::rdb::pointcloud::QueryRemove::bindBuffer
void bindBuffer(const std::string &attribute, const ValueType &buffer, const int32_t stride=0)
Bind attribute buffer.
Definition: queryRemove.hpp:136
riegl::rdb::pointcloud::QueryRemove::bind
void bind(const std::string &attribute, const DataType dataType, const void *buffer, const int32_t stride=0)
Bind attribute buffer.
riegl::rdb::pointcloud::QueryRemove
Point remove query.
Definition: queryRemove.hpp:64
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
pointcloudData.hpp
Pointcloud class implementation details.
riegl::rdb::pointcloud::DataType
DataType
Point attribute access data type.
Definition: dataTypes.hpp:55