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