Easy3D 2.5.3
graph.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_CORE_GRAPH_H
28#define EASY3D_CORE_GRAPH_H
29
30
31#include <easy3d/core/model.h>
32
33#include <vector>
34
35#include <easy3d/core/types.h>
36#include <easy3d/core/property.h>
37
38
39namespace easy3d {
40
41
50 class Graph : public virtual Model
51 {
52
53 public: //------------------------------------------------------ topology types
54
55
59 {
60 public:
61
63 explicit BaseHandle(int _idx = -1) : idx_(_idx) {}
64
66 int idx() const { return idx_; }
67
69 void reset() { idx_ = -1; }
70
72 bool is_valid() const { return idx_ != -1; }
73
75 bool operator==(const BaseHandle& _rhs) const {
76 return idx_ == _rhs.idx_;
77 }
78
80 bool operator!=(const BaseHandle& _rhs) const {
81 return idx_ != _rhs.idx_;
82 }
83
85 bool operator<(const BaseHandle& _rhs) const {
86 return idx_ < _rhs.idx_;
87 }
88
90 struct Hash {
91 std::size_t operator()(const BaseHandle& h) const { return h.idx(); }
92 };
93
94 private:
95 friend class Graph;
96 int idx_;
97 };
98
99
102 struct Vertex : public BaseHandle
103 {
105 explicit Vertex(int _idx = -1) : BaseHandle(_idx) {}
106 std::ostream& operator<<(std::ostream& os) const { return os << 'v' << idx(); }
107 };
108
111 struct Edge : public BaseHandle
112 {
114 explicit Edge(int _idx = -1) : BaseHandle(_idx) {}
115 };
116
117
118 public: //-------------------------------------------------- connectivity types
119
123 {
125 std::vector<Edge> edges_;
126 };
127
128
132 {
133 Vertex source_;
134 Vertex target_;
135 };
136
137
138 public: //------------------------------------------------------ property types
139
142 template <class T> class VertexProperty : public Property<T>
143 {
144 public:
145
147 explicit VertexProperty() = default;
148 explicit VertexProperty(Property<T> p) : Property<T>(p) {}
149
151 typename Property<T>::reference operator[](Vertex v)
152 {
153 return Property<T>::operator[](v.idx());
154 }
155
157 typename Property<T>::const_reference operator[](Vertex v) const
158 {
159 return Property<T>::operator[](v.idx());
160 }
161 };
162
163
166 template <class T> class EdgeProperty : public Property<T>
167 {
168 public:
169
171 explicit EdgeProperty() = default;
172 explicit EdgeProperty(Property<T> p) : Property<T>(p) {}
173
175 typename Property<T>::reference operator[](Edge e)
176 {
177 return Property<T>::operator[](e.idx());
178 }
179
181 typename Property<T>::const_reference operator[](Edge e) const
182 {
183 return Property<T>::operator[](e.idx());
184 }
185 };
186
189 template <class T> class ModelProperty : public Property<T>
190 {
191 public:
192
194 explicit ModelProperty() = default;
195 explicit ModelProperty(Property<T> p) : Property<T>(p) {}
196
198 typename Property<T>::reference operator[](size_t idx)
199 {
200 return Property<T>::operator[](idx);
201 }
202
204 typename Property<T>::const_reference operator[](size_t idx) const
205 {
206 return Property<T>::operator[](idx);
207 }
208 };
209
210
211
212 public: //------------------------------------------------------ iterator types
213
218 {
219 public:
220
222 explicit VertexIterator(Vertex v = Vertex(), const Graph* g = nullptr) : hnd_(v), graph_(g)
223 {
224 if (graph_ && graph_->has_garbage()) while (graph_->is_valid(hnd_) && graph_->is_deleted(hnd_)) ++hnd_.idx_;
225 }
226
228 Vertex operator*() const { return hnd_; }
229
231 bool operator==(const VertexIterator& rhs) const
232 {
233 return (hnd_ == rhs.hnd_);
234 }
235
237 bool operator!=(const VertexIterator& rhs) const
238 {
239 return !operator==(rhs);
240 }
241
244 {
245 ++hnd_.idx_;
246 assert(graph_);
247 while (graph_->has_garbage() && graph_->is_valid(hnd_) && graph_->is_deleted(hnd_)) ++hnd_.idx_;
248 return *this;
249 }
250
253 {
254 --hnd_.idx_;
255 assert(graph_);
256 while (graph_->has_garbage() && graph_->is_valid(hnd_) && graph_->is_deleted(hnd_)) --hnd_.idx_;
257 return *this;
258 }
259
260 private:
261 Vertex hnd_;
262 const Graph* graph_;
263 };
264
265
270 {
271 public:
272
274 explicit EdgeIterator(Edge e = Edge(), const Graph* g = nullptr) : hnd_(e), graph_(g)
275 {
276 if (graph_ && graph_->has_garbage()) while (graph_->is_valid(hnd_) && graph_->is_deleted(hnd_)) ++hnd_.idx_;
277 }
278
280 Edge operator*() const { return hnd_; }
281
283 bool operator==(const EdgeIterator& rhs) const
284 {
285 return (hnd_ == rhs.hnd_);
286 }
287
289 bool operator!=(const EdgeIterator& rhs) const
290 {
291 return !operator==(rhs);
292 }
293
296 {
297 ++hnd_.idx_;
298 assert(graph_);
299 while (graph_->has_garbage() && graph_->is_valid(hnd_) && graph_->is_deleted(hnd_)) ++hnd_.idx_;
300 return *this;
301 }
302
305 {
306 --hnd_.idx_;
307 assert(graph_);
308 while (graph_->has_garbage() && graph_->is_valid(hnd_) && graph_->is_deleted(hnd_)) --hnd_.idx_;
309 return *this;
310 }
311
312 private:
313 Edge hnd_;
314 const Graph* graph_;
315 };
316
317
318 public: //-------------------------- containers for C++11 range-based for loops
319
324 {
325 public:
326 VertexContainer(VertexIterator _begin, VertexIterator _end) : begin_(_begin), end_(_end) {}
327 VertexIterator begin() const { return begin_; }
328 VertexIterator end() const { return end_; }
329 private:
330 VertexIterator begin_, end_;
331 };
332
337 {
338 public:
339 EdgeContainer(EdgeIterator _begin, EdgeIterator _end) : begin_(_begin), end_(_end) {}
340 EdgeIterator begin() const { return begin_; }
341 EdgeIterator end() const { return end_; }
342 private:
343 EdgeIterator begin_, end_;
344 };
345
346
347 public: //---------------------------------------------------- circulator types
348
349
354 {
355 public:
356
359 : graph_(g), vertex_(v), finished_(false)
360 {
361 iterator_ = graph_->vconn_[vertex_].edges_.begin();
362 end_ = graph_->vconn_[vertex_].edges_.end();
363 }
364
366 bool operator==(const EdgeAroundVertexCirculator& rhs) const {
367 assert(graph_);
368 return ((graph_ == rhs.graph_) && (vertex_ == rhs.vertex_) && (iterator_ == rhs.iterator_))
369 || (finished_); // to behave like a circulator
370 }
371
373 bool operator!=(const EdgeAroundVertexCirculator& rhs) const {
374 return !operator==(rhs);
375 }
376
379 assert(graph_);
380 ++iterator_;
381 if (iterator_ == end_) { // to behave like a circulator
382 iterator_ = graph_->vconn_[vertex_].edges_.begin();
383 finished_ = true;
384 }
385 return *this;
386 }
387
390 {
391 assert(graph_);
392 --iterator_;
393 return *this;
394 }
395
397 Edge operator*() const {
398 assert(graph_);
399 if (iterator_ != end_) return *iterator_;
400 else return Edge();
401 }
402
404 operator bool() const { return !graph_->vconn_[vertex_].edges_.empty(); }
405
407 Vertex vertex() const { return vertex_; }
408
409 // helper for C++11 range-based for-loops
410 EdgeAroundVertexCirculator& begin() { iterator_ = graph_->vconn_[vertex_].edges_.begin(); return *this; }
411 // helper for C++11 range-based for-loops
412 EdgeAroundVertexCirculator& end() { iterator_ = end_; return *this; }
413
414 private:
415 const Graph* graph_;
416 const Vertex vertex_;
417 std::vector<Edge>::const_iterator iterator_;
418 // helper for C++11 range-based for-loops
419 std::vector<Edge>::const_iterator end_;
420 bool finished_; // for the circulator behavior
421 };
422
423
424
429 {
430 public:
431
434 : graph_(g), vertex_(v), finished_(false)
435 {
436 iterator_ = graph_->vconn_[vertex_].edges_.begin();
437 end_ = graph_->vconn_[vertex_].edges_.end();
438 }
439
442 assert(graph_);
443 return ((graph_ == rhs.graph_) && (vertex_ == rhs.vertex_) && (iterator_ == rhs.iterator_))
444 || (finished_); // to behave like a circulator
445 }
446
449 return !operator==(rhs);
450 }
451
454 assert(graph_);
455 ++iterator_;
456 if (iterator_ == end_) { // to behave like a circulator
457 iterator_ = graph_->vconn_[vertex_].edges_.begin();
458 finished_ = true;
459 }
460 return *this;
461 }
462
465 {
466 assert(graph_);
467 --iterator_;
468 return *this;
469 }
470
473 assert(graph_);
474 if (iterator_ != end_) {
475 Vertex v = graph_->vertex(*iterator_, 1);
476 if (v != vertex_) return v;
477 else return graph_->vertex(*iterator_, 0);
478 }
479 return Vertex();
480 }
481
483 operator bool() const { return !graph_->vconn_[vertex_].edges_.empty(); }
484
486 Vertex vertex() const { return vertex_; }
487
488 // helper for C++11 range-based for-loops
490 iterator_ = graph_->vconn_[vertex_].edges_.begin();
491 return *this;
492 }
493 // helper for C++11 range-based for-loops
495 iterator_ = end_;
496 return *this;
497 }
498
499 private:
500 const Graph* graph_;
501 const Vertex vertex_;
502 std::vector<Edge>::const_iterator iterator_;
503 // helper for C++11 range-based for-loops
504 std::vector<Edge>::const_iterator end_;
505 bool finished_; // for the circulator behavior
506 };
507
508
509
510 public: //-------------------------------------------- constructor / destructor
511
513
514
516 Graph();
517
519 ~Graph() override = default;
520
522 Graph(const Graph& rhs) { operator=(rhs); }
523
525 Graph& operator=(const Graph& rhs);
526
528 Graph& assign(const Graph& rhs);
529
531
532 public: //----------------------------------------------- add new vertex / face
533
535
536
538 Vertex add_vertex(const vec3& p);
539
541 Edge add_edge(const Vertex& v1, const Vertex& v2);
543
544 public: //--------------------------------------------------- memory management
545
547
548
550 unsigned int vertices_size() const { return (unsigned int)vprops_.size(); }
552 unsigned int edges_size() const { return (unsigned int)eprops_.size(); }
553
555 unsigned int n_vertices() const { return vertices_size() - deleted_vertices_; }
557 unsigned int n_edges() const { return edges_size() - deleted_edges_; }
558
561 void clear();
562
564 void reserve(unsigned int nvertices, unsigned int nedges);
565
568 void resize(unsigned int nv, unsigned int ne) {
569 vprops_.resize(nv);
570 eprops_.resize(ne);
571 }
572
574 bool has_garbage() const { return garbage_; }
575
577 void collect_garbage();
578
579
582 bool is_deleted(Vertex v) const
583 {
584 return vdeleted_[v];
585 }
588 bool is_deleted(Edge e) const
589 {
590 return edeleted_[e];
591 }
592
594 bool is_valid(Vertex v) const
595 {
596 return (0 <= v.idx()) && (v.idx() < (int)vertices_size());
597 }
599 bool is_valid(Edge e) const
600 {
601 return (0 <= e.idx()) && (e.idx() < (int)edges_size());
602 }
604
605
606 public: //---------------------------------------------- low-level connectivity
607
609
610
612 bool is_isolated(Vertex v) const
613 {
614 return vconn_[v].edges_.empty();
615 }
616
618 Vertex vertex(Edge e, unsigned int i) const
619 {
620 assert(i<=1);
621 if (i == 0)
622 return econn_[e].source_;
623 else
624 return econn_[e].target_;
625 }
626
628 Vertex source(Edge e) const { return econn_[e].source_; }
629
631 Vertex target(Edge e) const { return econn_[e].target_; }
633
634 public: //--------------------------------------------------- property handling
635
637
638
642 template <class T> VertexProperty<T> add_vertex_property(const std::string& name, const T t = T())
643 {
644 return VertexProperty<T>(vprops_.add<T>(name, t));
645 }
649 template <class T> EdgeProperty<T> add_edge_property(const std::string& name, const T t = T())
650 {
651 return EdgeProperty<T>(eprops_.add<T>(name, t));
652 }
656 template <class T> ModelProperty<T> add_model_property(const std::string& name, const T t = T())
657 {
658 return ModelProperty<T>(mprops_.add<T>(name, t));
659 }
660
661
664 template <class T> VertexProperty<T> get_vertex_property(const std::string& name) const
665 {
666 return VertexProperty<T>(vprops_.get<T>(name));
667 }
670 template <class T> EdgeProperty<T> get_edge_property(const std::string& name) const
671 {
672 return EdgeProperty<T>(eprops_.get<T>(name));
673 }
676 template <class T> ModelProperty<T> get_model_property(const std::string& name) const
677 {
678 return ModelProperty<T>(mprops_.get<T>(name));
679 }
680
681
684 template <class T> VertexProperty<T> vertex_property(const std::string& name, const T t = T())
685 {
686 return VertexProperty<T>(vprops_.get_or_add<T>(name, t));
687 }
690 template <class T> EdgeProperty<T> edge_property(const std::string& name, const T t = T())
691 {
692 return EdgeProperty<T>(eprops_.get_or_add<T>(name, t));
693 }
694
697 template <class T> ModelProperty<T> model_property(const std::string& name, const T t = T())
698 {
699 return ModelProperty<T>(mprops_.get_or_add<T>(name, t));
700 }
701
703 template<class T>
704 bool remove_vertex_property(VertexProperty<T> &p) { return vprops_.remove(p); }
705
707 bool remove_vertex_property(const std::string &n) { return vprops_.remove(n); }
708
710 template<class T>
711 bool remove_edge_property(EdgeProperty<T> &p) { return eprops_.remove(p); }
712
714 bool remove_edge_property(const std::string &n) { return eprops_.remove(n); }
715
717 template<class T>
718 bool remove_model_property(ModelProperty<T> &p) { return mprops_.remove(p); }
719
721 bool remove_model_property(const std::string &n) { return mprops_.remove(n); }
722
724 bool rename_vertex_property(const std::string &old_name, const std::string &new_name) {
725 return vprops_.rename(old_name, new_name);
726 }
727
729 bool rename_edge_property(const std::string &old_name, const std::string &new_name) {
730 return eprops_.rename(old_name, new_name);
731 }
732
734 bool rename_model_property(const std::string &old_name, const std::string &new_name) {
735 return mprops_.rename(old_name, new_name);
736 }
737
740 const std::type_info& get_vertex_property_type(const std::string& name) const
741 {
742 return vprops_.get_type(name);
743 }
746 const std::type_info& get_edge_property_type(const std::string& name) const
747 {
748 return eprops_.get_type(name);
749 }
752 const std::type_info& get_model_property_type(const std::string& name) const
753 {
754 return mprops_.get_type(name);
755 }
756
757
759 std::vector<std::string> vertex_properties() const
760 {
761 return vprops_.properties();
762 }
764 std::vector<std::string> edge_properties() const
765 {
766 return eprops_.properties();
767 }
769 std::vector<std::string> model_properties() const
770 {
771 return mprops_.properties();
772 }
773
775 void property_stats(std::ostream& output) const override;
776
778
779
780 public: //--------------------------------------------- iterators & circulators
781
783
784
787 {
788 return VertexIterator(Vertex(0), this);
789 }
790
793 {
794 return VertexIterator(Vertex(static_cast<int>(vertices_size())), this);
795 }
796
799 {
801 }
802
805 {
806 return EdgeIterator(Edge(0), this);
807 }
808
811 {
812 return EdgeIterator(Edge(static_cast<int>(edges_size())), this);
813 }
814
817 {
819 }
820
823 {
824 return VertexAroundVertexCirculator(this, v);
825 }
826
829 {
830 return EdgeAroundVertexCirculator(this, v);
831 }
833
834
835 public: //--------------------------------------------- higher-level operations
836
838
839
840
843 unsigned int valence(Vertex v) const;
844
846 Edge find_edge(Vertex a, Vertex b) const;
847
849 void delete_vertex(Vertex v);
850
852 void delete_edge(Edge e);
854
855
856 public: //------------------------------------------ geometry-related functions
857
859
860
862 const vec3& position(Vertex v) const { return vpoint_[v]; }
863
865 vec3& position(Vertex v) { return vpoint_[v]; }
866
868 const std::vector<vec3>& points() const override { return vpoint_.vector(); }
869
871 std::vector<vec3>& points() override { return vpoint_.vector(); }
872
874 float edge_length(Edge e) const;
875
877
878
879 private: //---------------------------------------------- allocate new elements
880
882 Vertex new_vertex()
883 {
884 vprops_.push_back();
885 return Vertex(static_cast<int>(vertices_size() - 1));
886 }
887
889 Edge new_edge()
890 {
891 eprops_.push_back();
892 return Edge(static_cast<int>(edges_size() - 1));
893 }
894
895
896 private: //------------------------------------------------------- private data
897
898 PropertyContainer vprops_;
899 PropertyContainer eprops_;
900 PropertyContainer mprops_;
901
902 VertexProperty<VertexConnectivity> vconn_;
903 EdgeProperty<EdgeConnectivity> econn_;
904
905 VertexProperty<bool> vdeleted_;
906 EdgeProperty<bool> edeleted_;
907
908 VertexProperty<vec3> vpoint_;
909
910 unsigned int deleted_vertices_;
911 unsigned int deleted_edges_;
912 bool garbage_;
913 };
914
915
916 //------------------------------------------------------------ output operators
917
918
920 inline std::ostream& operator<<(std::ostream& os, Graph::Vertex v)
921 {
922 return (os << 'v' << v.idx());
923 }
924
926 inline std::ostream& operator<<(std::ostream& os, Graph::Edge e)
927 {
928 return (os << 'e' << e.idx());
929 }
930
931} // namespace easy3d
932
933#endif // EASY3D_CORE_GRAPH_H
934
935
Definition: graph.h:59
bool operator!=(const BaseHandle &_rhs) const
are two handles different?
Definition: graph.h:80
bool is_valid() const
return whether the handle is valid, i.e., the index is not equal to -1.
Definition: graph.h:72
int idx() const
Get the underlying index of this handle.
Definition: graph.h:66
bool operator<(const BaseHandle &_rhs) const
compare operator useful for sorting handles
Definition: graph.h:85
bool operator==(const BaseHandle &_rhs) const
are two handles equal?
Definition: graph.h:75
void reset()
reset handle to be invalid (index=-1)
Definition: graph.h:69
BaseHandle(int _idx=-1)
constructor
Definition: graph.h:63
EdgeAroundVertexCirculator & operator--()
pre-decrement
Definition: graph.h:389
EdgeAroundVertexCirculator & operator++()
pre-increment
Definition: graph.h:378
bool operator==(const EdgeAroundVertexCirculator &rhs) const
are two circulators equal?
Definition: graph.h:366
Edge operator*() const
get the edge the circulator refers to
Definition: graph.h:397
Vertex vertex() const
return current vertex
Definition: graph.h:407
bool operator!=(const EdgeAroundVertexCirculator &rhs) const
are two circulators different?
Definition: graph.h:373
EdgeAroundVertexCirculator(const Graph *g, Vertex v=Vertex())
default constructor
Definition: graph.h:358
Definition: graph.h:337
Definition: graph.h:270
bool operator!=(const EdgeIterator &rhs) const
are two iterators different?
Definition: graph.h:289
EdgeIterator & operator++()
pre-increment iterator
Definition: graph.h:295
EdgeIterator(Edge e=Edge(), const Graph *g=nullptr)
Default constructor.
Definition: graph.h:274
Edge operator*() const
get the edge the iterator refers to
Definition: graph.h:280
bool operator==(const EdgeIterator &rhs) const
are two iterators equal?
Definition: graph.h:283
EdgeIterator & operator--()
pre-decrement iterator
Definition: graph.h:304
Definition: graph.h:167
EdgeProperty()=default
default constructor
Property< T >::reference operator[](Edge e)
access the data stored for edge e
Definition: graph.h:175
Property< T >::const_reference operator[](Edge e) const
access the data stored for edge e
Definition: graph.h:181
Definition: graph.h:190
ModelProperty()=default
default constructor
Property< T >::const_reference operator[](size_t idx) const
access the data stored for the graph
Definition: graph.h:204
Property< T >::reference operator[](size_t idx)
access the data stored for the graph
Definition: graph.h:198
bool operator!=(const VertexAroundVertexCirculator &rhs) const
are two circulators different?
Definition: graph.h:448
VertexAroundVertexCirculator & operator++()
pre-increment
Definition: graph.h:453
Vertex operator*() const
get the vertex the circulator refers to
Definition: graph.h:472
Vertex vertex() const
return current vertex
Definition: graph.h:486
bool operator==(const VertexAroundVertexCirculator &rhs) const
are two circulators equal?
Definition: graph.h:441
VertexAroundVertexCirculator & operator--()
pre-decrement
Definition: graph.h:464
VertexAroundVertexCirculator(const Graph *g, Vertex v=Vertex())
default constructor
Definition: graph.h:433
Definition: graph.h:324
Definition: graph.h:218
Vertex operator*() const
get the vertex the iterator refers to
Definition: graph.h:228
VertexIterator(Vertex v=Vertex(), const Graph *g=nullptr)
Default constructor.
Definition: graph.h:222
bool operator==(const VertexIterator &rhs) const
are two iterators equal?
Definition: graph.h:231
VertexIterator & operator--()
pre-decrement iterator
Definition: graph.h:252
bool operator!=(const VertexIterator &rhs) const
are two iterators different?
Definition: graph.h:237
VertexIterator & operator++()
pre-increment iterator
Definition: graph.h:243
Definition: graph.h:143
Property< T >::const_reference operator[](Vertex v) const
access the data stored for vertex v
Definition: graph.h:157
Property< T >::reference operator[](Vertex v)
access the data stored for vertex v
Definition: graph.h:151
VertexProperty()=default
default constructor
A Graph data structure with easy property management.
Definition: graph.h:51
const vec3 & position(Vertex v) const
position of a vertex (read only)
Definition: graph.h:862
EdgeContainer edges() const
returns edge container for C++11 range-based for-loops
Definition: graph.h:816
Graph(const Graph &rhs)
copy constructor: copies rhs to *this. performs a deep copy of all properties.
Definition: graph.h:522
const std::type_info & get_vertex_property_type(const std::string &name) const
Definition: graph.h:740
bool remove_vertex_property(const std::string &n)
remove the vertex property named n
Definition: graph.h:707
EdgeIterator edges_end() const
returns end iterator for edges
Definition: graph.h:810
EdgeAroundVertexCirculator edges(Vertex v) const
returns circulator for edges around vertex v
Definition: graph.h:828
VertexAroundVertexCirculator vertices(Vertex v) const
returns circulator for vertices around vertex v
Definition: graph.h:822
unsigned int n_edges() const
returns number of edges in the graph
Definition: graph.h:557
bool is_valid(Edge e) const
return whether edge e is valid, i.e. the index is stores it within the array bounds.
Definition: graph.h:599
bool rename_vertex_property(const std::string &old_name, const std::string &new_name)
rename a vertex property given its name
Definition: graph.h:724
unsigned int valence(Vertex v) const
Definition: graph.cpp:248
VertexContainer vertices() const
returns vertex container for C++11 range-based for-loops
Definition: graph.h:798
~Graph() override=default
destructor
const std::type_info & get_edge_property_type(const std::string &name) const
Definition: graph.h:746
Graph & assign(const Graph &rhs)
assign rhs to *this. does not copy custom properties.
Definition: graph.cpp:82
bool has_garbage() const
are there deleted vertices or edges?
Definition: graph.h:574
VertexProperty< T > vertex_property(const std::string &name, const T t=T())
Definition: graph.h:684
unsigned int edges_size() const
returns number of (deleted and valid)edges in the graph
Definition: graph.h:552
void reserve(unsigned int nvertices, unsigned int nedges)
reserve memory (mainly used in file readers)
Definition: graph.cpp:151
ModelProperty< T > get_model_property(const std::string &name) const
Definition: graph.h:676
std::vector< std::string > vertex_properties() const
returns the names of all vertex properties
Definition: graph.h:759
EdgeProperty< T > get_edge_property(const std::string &name) const
Definition: graph.h:670
void resize(unsigned int nv, unsigned int ne)
Definition: graph.h:568
EdgeIterator edges_begin() const
returns start iterator for edges
Definition: graph.h:804
Edge find_edge(Vertex a, Vertex b) const
find the edge (a,b)
Definition: graph.cpp:232
VertexProperty< T > get_vertex_property(const std::string &name) const
Definition: graph.h:664
Vertex source(Edge e) const
returns the starting vertex of an edge, which is equal to vertex(e, 0).
Definition: graph.h:628
std::vector< std::string > edge_properties() const
returns the names of all edge properties
Definition: graph.h:764
bool is_deleted(Vertex v) const
Definition: graph.h:582
std::vector< std::string > model_properties() const
returns the names of all model properties
Definition: graph.h:769
void collect_garbage()
remove deleted vertices/edges
Definition: graph.cpp:319
bool rename_edge_property(const std::string &old_name, const std::string &new_name)
rename an edge property given its name
Definition: graph.h:729
bool is_deleted(Edge e) const
Definition: graph.h:588
const std::type_info & get_model_property_type(const std::string &name) const
Definition: graph.h:752
std::vector< vec3 > & points() override
vector of vertex positions
Definition: graph.h:871
bool remove_edge_property(const std::string &n)
remove the edge property named n
Definition: graph.h:714
ModelProperty< T > model_property(const std::string &name, const T t=T())
Definition: graph.h:697
VertexProperty< T > add_vertex_property(const std::string &name, const T t=T())
Definition: graph.h:642
bool remove_model_property(ModelProperty< T > &p)
remove the model property p
Definition: graph.h:718
bool rename_model_property(const std::string &old_name, const std::string &new_name)
rename a model property given its name
Definition: graph.h:734
ModelProperty< T > add_model_property(const std::string &name, const T t=T())
Definition: graph.h:656
EdgeProperty< T > edge_property(const std::string &name, const T t=T())
Definition: graph.h:690
bool remove_edge_property(EdgeProperty< T > &p)
remove the edge property p
Definition: graph.h:711
void property_stats(std::ostream &output) const override
prints the names of all properties to an output stream (e.g., std::cout)
Definition: graph.cpp:162
void delete_edge(Edge e)
deletes the edge e from the graph
Definition: graph.cpp:303
Vertex add_vertex(const vec3 &p)
add a new vertex with position p
Definition: graph.cpp:204
void clear()
Removes all vertices, edges, and properties (and resets garbage state).
Definition: graph.cpp:123
bool is_isolated(Vertex v) const
returns whether v is isolated, i.e., not incident to any edge
Definition: graph.h:612
vec3 & position(Vertex v)
position of a vertex
Definition: graph.h:865
unsigned int vertices_size() const
returns number of (deleted and valid) vertices in the graph
Definition: graph.h:550
bool remove_model_property(const std::string &n)
remove the model property named n
Definition: graph.h:721
float edge_length(Edge e) const
compute the length of edge e.
Definition: graph.cpp:256
EdgeProperty< T > add_edge_property(const std::string &name, const T t=T())
Definition: graph.h:649
Vertex target(Edge e) const
returns the ending vertex of an edge, which is equal to vertex(e, 1).
Definition: graph.h:631
void delete_vertex(Vertex v)
deletes the vertex v from the graph
Definition: graph.cpp:264
VertexIterator vertices_begin() const
returns start iterator for vertices
Definition: graph.h:786
bool remove_vertex_property(VertexProperty< T > &p)
remove the vertex property p
Definition: graph.h:704
VertexIterator vertices_end() const
returns end iterator for vertices
Definition: graph.h:792
Edge add_edge(const Vertex &v1, const Vertex &v2)
add a new edge connecting vertices v1 and v2
Definition: graph.cpp:212
bool is_valid(Vertex v) const
return whether vertex v is valid, i.e. the index is stores it within the array bounds.
Definition: graph.h:594
Vertex vertex(Edge e, unsigned int i) const
returns the i'th vertex of edge e. i has to be 0 or 1.
Definition: graph.h:618
Graph & operator=(const Graph &rhs)
assign rhs to *this. performs a deep copy of all properties.
Definition: graph.cpp:53
Graph()
default constructor
Definition: graph.cpp:33
const std::vector< vec3 > & points() const override
vector of vertex positions (read only)
Definition: graph.h:868
unsigned int n_vertices() const
returns number of vertices in the graph
Definition: graph.h:555
The base class of renderable 3D models.
Definition: model.h:49
const std::string & name() const
The name of a model.
Definition: model.h:60
Implementation of a generic property.
Definition: property.h:253
Definition: collider.cpp:182
std::ostream & operator<<(std::ostream &os, Graph::Vertex v)
Definition: graph.h:920
helper structure to be able to use std::unordered_map
Definition: graph.h:90
Definition: graph.h:132
Definition: graph.h:112
Edge(int _idx=-1)
default constructor (with invalid index)
Definition: graph.h:114
Definition: graph.h:123
std::vector< Edge > edges_
all edges connected with the vertex
Definition: graph.h:125
Definition: graph.h:103
Vertex(int _idx=-1)
default constructor (with invalid index)
Definition: graph.h:105