|
| 1 | +/** |
| 2 | + * @file tool_path.h |
| 3 | + * @brief Common Tesseract Tool Path |
| 4 | + * |
| 5 | + * @author Levi Armstrong |
| 6 | + * @date Nov 16, 2022 |
| 7 | + * @version TODO |
| 8 | + * @bug No known bugs |
| 9 | + * |
| 10 | + * @copyright Copyright (c) 2022, Levi Armstrong |
| 11 | + * |
| 12 | + * @par License |
| 13 | + * Software License Agreement (Apache License) |
| 14 | + * @par |
| 15 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 16 | + * you may not use this file except in compliance with the License. |
| 17 | + * You may obtain a copy of the License at |
| 18 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 19 | + * @par |
| 20 | + * Unless required by applicable law or agreed to in writing, software |
| 21 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 22 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 23 | + * See the License for the specific language governing permissions and |
| 24 | + * limitations under the License. |
| 25 | + */ |
| 26 | +#ifndef TESSERACT_COMMON_TOOL_PATH_H |
| 27 | +#define TESSERACT_COMMON_TOOL_PATH_H |
| 28 | + |
| 29 | +#include <string> |
| 30 | +#include <boost/uuid/uuid.hpp> |
| 31 | +#include <tesseract_common/tool_path_segment.h> |
| 32 | +#include <tesseract_common/serialization.h> |
| 33 | + |
| 34 | +namespace tesseract_common |
| 35 | +{ |
| 36 | +class ToolPath |
| 37 | +{ |
| 38 | +public: |
| 39 | + // LCOV_EXCL_START |
| 40 | + EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
| 41 | + // LCOV_EXCL_STOP |
| 42 | + |
| 43 | + ToolPath(std::string description = ""); |
| 44 | + ToolPath(boost::uuids::uuid uuid, std::string description = ""); |
| 45 | + virtual ~ToolPath() = default; |
| 46 | + |
| 47 | + /** @brief Get the uuid */ |
| 48 | + boost::uuids::uuid getUUID() const; |
| 49 | + |
| 50 | + /** @brief Regenerate uuid */ |
| 51 | + void regenerateUUID(); |
| 52 | + |
| 53 | + /** |
| 54 | + * @brief Get the parent uuid |
| 55 | + * @details This can be null |
| 56 | + */ |
| 57 | + const boost::uuids::uuid& getParentUUID() const; |
| 58 | + |
| 59 | + /** |
| 60 | + * @brief Set the parent uuid |
| 61 | + * @details This can be used in cases were a segment is split during a filter process and want tracability. |
| 62 | + * @param uuid |
| 63 | + */ |
| 64 | + void setParentUUID(const boost::uuids::uuid& uuid); |
| 65 | + |
| 66 | + /** @brief Set the tool path description */ |
| 67 | + void setDescription(const std::string& desc); |
| 68 | + |
| 69 | + /** @brief Get the tool path description */ |
| 70 | + const std::string& getDescription() const; |
| 71 | + |
| 72 | + /** |
| 73 | + * @brief Set a namespace for the tool path |
| 74 | + * @details This can be multiple namespace by separating by '::' for example 'main::left::place' |
| 75 | + * which will have it show up in the widget as a teared item in the tree view. |
| 76 | + * @param ns A namespace the tool path is associated with |
| 77 | + */ |
| 78 | + void setNamespace(std::string ns); |
| 79 | + |
| 80 | + /** |
| 81 | + * @brief Get the namespace for the tool path |
| 82 | + * @return The namespace |
| 83 | + */ |
| 84 | + const std::string& getNamespace() const; |
| 85 | + |
| 86 | + bool operator==(const ToolPath& rhs) const; |
| 87 | + bool operator!=(const ToolPath& rhs) const; |
| 88 | + |
| 89 | + // LCOV_EXCL_START |
| 90 | + |
| 91 | + /////////////////////////// |
| 92 | + // C++ container support // |
| 93 | + /////////////////////////// |
| 94 | + /** pointer */ |
| 95 | + using pointer = typename AlignedVector<ToolPathSegment>::pointer; |
| 96 | + /** const_pointer */ |
| 97 | + using const_pointer = typename AlignedVector<ToolPathSegment>::const_pointer; |
| 98 | + /** reference */ |
| 99 | + using reference = typename AlignedVector<ToolPathSegment>::reference; |
| 100 | + /** const_reference */ |
| 101 | + using const_reference = typename AlignedVector<ToolPathSegment>::const_reference; |
| 102 | + /** size_type */ |
| 103 | + using size_type = typename AlignedVector<ToolPathSegment>::size_type; |
| 104 | + /** difference_type */ |
| 105 | + using difference_type = typename AlignedVector<ToolPathSegment>::difference_type; |
| 106 | + /** iterator */ |
| 107 | + using iterator = typename AlignedVector<ToolPathSegment>::iterator; |
| 108 | + /** const_iterator */ |
| 109 | + using const_iterator = typename AlignedVector<ToolPathSegment>::const_iterator; |
| 110 | + /** reverse_iterator */ |
| 111 | + using reverse_iterator = typename AlignedVector<ToolPathSegment>::reverse_iterator; |
| 112 | + /** const_reverse_iterator */ |
| 113 | + using const_reverse_iterator = typename AlignedVector<ToolPathSegment>::const_reverse_iterator; |
| 114 | + |
| 115 | + /////////////// |
| 116 | + // Iterators // |
| 117 | + /////////////// |
| 118 | + /** @brief returns an iterator to the beginning */ |
| 119 | + iterator begin(); |
| 120 | + /** @brief returns an iterator to the beginning */ |
| 121 | + const_iterator begin() const; |
| 122 | + /** @brief returns an iterator to the end */ |
| 123 | + iterator end(); |
| 124 | + /** @brief returns an iterator to the end */ |
| 125 | + const_iterator end() const; |
| 126 | + /** @brief returns a reverse iterator to the beginning */ |
| 127 | + reverse_iterator rbegin(); |
| 128 | + /** @brief returns a reverse iterator to the beginning */ |
| 129 | + const_reverse_iterator rbegin() const; |
| 130 | + /** @brief returns a reverse iterator to the end */ |
| 131 | + reverse_iterator rend(); |
| 132 | + /** @brief returns a reverse iterator to the end */ |
| 133 | + const_reverse_iterator rend() const; |
| 134 | + /** @brief returns an iterator to the beginning */ |
| 135 | + const_iterator cbegin() const; |
| 136 | + /** @brief returns an iterator to the end */ |
| 137 | + const_iterator cend() const; |
| 138 | + /** @brief returns a reverse iterator to the beginning */ |
| 139 | + const_reverse_iterator crbegin() const; |
| 140 | + /** @brief returns a reverse iterator to the end */ |
| 141 | + const_reverse_iterator crend() const; |
| 142 | + |
| 143 | + ////////////// |
| 144 | + // Capacity // |
| 145 | + ////////////// |
| 146 | + /** @brief checks whether the container is empty */ |
| 147 | + bool empty() const; |
| 148 | + /** @brief returns the number of elements */ |
| 149 | + size_type size() const; |
| 150 | + /** @brief returns the maximum possible number of elements */ |
| 151 | + size_type max_size() const; |
| 152 | + /** @brief reserve number of elements */ |
| 153 | + void reserve(size_type n); |
| 154 | + /** @brief returns the number of elements that can be held in currently allocated storage */ |
| 155 | + size_type capacity() const; |
| 156 | + /** @brief reduces memory usage by freeing unused memory */ |
| 157 | + void shrink_to_fit(); |
| 158 | + |
| 159 | + //////////////////// |
| 160 | + // Element Access // |
| 161 | + //////////////////// |
| 162 | + /** @brief access the first element */ |
| 163 | + reference front(); |
| 164 | + /** @brief access the first element */ |
| 165 | + const_reference front() const; |
| 166 | + /** @brief access the last element */ |
| 167 | + reference back(); |
| 168 | + /** @brief access the last element */ |
| 169 | + const_reference back() const; |
| 170 | + /** @brief access specified element with bounds checking */ |
| 171 | + reference at(size_type n); |
| 172 | + /** @brief access specified element with bounds checking */ |
| 173 | + const_reference at(size_type n) const; |
| 174 | + /** @brief direct access to the underlying array */ |
| 175 | + pointer data(); |
| 176 | + /** @brief direct access to the underlying array */ |
| 177 | + const_pointer data() const; |
| 178 | + /** @brief access specified element */ |
| 179 | + reference operator[](size_type pos); |
| 180 | + /** @brief access specified element */ |
| 181 | + const_reference operator[](size_type pos) const; |
| 182 | + |
| 183 | + /////////////// |
| 184 | + // Modifiers // |
| 185 | + /////////////// |
| 186 | + /** @brief clears the contents */ |
| 187 | + void clear(); |
| 188 | + |
| 189 | + /** @brief inserts element */ |
| 190 | + iterator insert(const_iterator p, const ToolPathSegment& x); |
| 191 | + iterator insert(const_iterator p, ToolPathSegment&& x); |
| 192 | + iterator insert(const_iterator p, std::initializer_list<ToolPathSegment> l); |
| 193 | + template <class InputIt> |
| 194 | + void insert(const_iterator pos, InputIt first, InputIt last) |
| 195 | + { |
| 196 | + container_.insert(pos, first, last); |
| 197 | + } |
| 198 | + |
| 199 | + /** @brief constructs element in-place */ |
| 200 | + template <class... Args> |
| 201 | + iterator emplace(const_iterator pos, Args&&... args); |
| 202 | + |
| 203 | + /** @brief erases element */ |
| 204 | + iterator erase(const_iterator p); |
| 205 | + iterator erase(const_iterator first, const_iterator last); |
| 206 | + |
| 207 | + /** Append element to container */ |
| 208 | + void push_back(const ToolPathSegment& x); |
| 209 | + void push_back(const ToolPathSegment&& x); |
| 210 | + |
| 211 | + /** @brief constructs an element in-place at the end */ |
| 212 | + template <typename... Args> |
| 213 | +#if __cplusplus > 201402L |
| 214 | + reference emplace_back(Args&&... args); |
| 215 | +#else |
| 216 | + void emplace_back(Args&&... args); |
| 217 | +#endif |
| 218 | + |
| 219 | + /** @brief removes the last element */ |
| 220 | + void pop_back(); |
| 221 | + |
| 222 | + /** @brief swaps the contents */ |
| 223 | + void swap(AlignedVector<ToolPathSegment>& other); |
| 224 | + // LCOV_EXCL_STOP |
| 225 | + |
| 226 | +protected: |
| 227 | + /** @brief The uuid */ |
| 228 | + boost::uuids::uuid uuid_{}; |
| 229 | + |
| 230 | + /** @brief The parent uuid */ |
| 231 | + boost::uuids::uuid parent_uuid_{}; |
| 232 | + |
| 233 | + /** @brief The description */ |
| 234 | + std::string description_; |
| 235 | + |
| 236 | + /** @brief The container */ |
| 237 | + AlignedVector<ToolPathSegment> container_; |
| 238 | + |
| 239 | + /** @brief The namespace associated with the tool path */ |
| 240 | + std::string ns_{ "general" }; |
| 241 | + |
| 242 | + friend struct tesseract_common::Serialization; |
| 243 | + friend class boost::serialization::access; |
| 244 | + template <class Archive> |
| 245 | + void serialize(Archive& ar, const unsigned int version); // NOLINT |
| 246 | +}; |
| 247 | + |
| 248 | +} // namespace tesseract_common |
| 249 | + |
| 250 | +#include <boost/serialization/export.hpp> |
| 251 | +#include <boost/serialization/tracking.hpp> |
| 252 | +BOOST_CLASS_EXPORT_KEY2(tesseract_common::ToolPath, "ToolPath") |
| 253 | + |
| 254 | +#endif // TESSERACT_COMMON_TOOL_PATH_H |
0 commit comments