Developer Documentation
PolyLineCollectionT.hh
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42#pragma once
43
44#include <ObjectTypes/PolyLine/PolyLineT.hh>
45
46#include <queue>
47
48template <typename T>
50public:
51 typedef typename ACG::PolyLineT<T> PolyLine;
52
53 struct iterator{
54 iterator(typename std::vector<PolyLine*>::iterator _begin, typename std::vector<PolyLine*>::iterator _end) :
55 i_(0),
56 it_(_begin),
57 end_(_end)
58 { }
59
60 PolyLine*& operator* (){
61 return *it_;
62 }
63
64 PolyLine* operator-> (){
65 return *it_;
66 }
67
68 void operator++(){
69 ++i_;
70 ++it_;
71 }
72
73 int idx(){
74 return i_;
75 }
76
77 operator bool() const{
78 return it_ != end_;
79 }
80
81 int i_;
82 typename std::vector<PolyLine*>::iterator it_;
83 typename std::vector<PolyLine*>::iterator end_;
84 };
85
87 index_iterator(std::vector<PolyLine*>& _lines, typename std::vector<size_t>::iterator _begin, typename std::vector<size_t>::iterator _end) :
88 lines_(_lines),
89 it_(_begin),
90 end_(_end)
91 { }
92
93 PolyLine*& operator* (){
94 return lines_[*it_];
95 }
96
97 PolyLine* operator-> (){
98 return lines_[*it_];
99 }
100
101 void operator++(){
102 ++it_;
103 }
104
105 int idx(){
106 return *it_;
107 }
108
109 operator bool() const{
110 return it_ != end_;
111 }
112
113 std::vector<PolyLine*>& lines_;
114 typename std::vector<size_t>::iterator it_;
115 typename std::vector<size_t>::iterator end_;
116 };
117
118public:
119
120
126 const size_t n = poly_lines_.size();
127 for(size_t i = 0; i < n; ++i){
128 delete poly_lines_[i];
129 }
130 }
131
137 size_t add_poly_line(PolyLine* _poly_line){
138
139 ;
140 if(empty_slots_.empty()){
141
142 const size_t new_idx = poly_lines_.size();
143 poly_lines_.push_back(_poly_line);
144 visible_.push_back(new_idx);
145 return new_idx;
146
147 } else {
148
149 const size_t new_idx = empty_slots_.front();
150 empty_slots_.pop();
151 poly_lines_[new_idx] = _poly_line;
152 visible_.push_back(new_idx);
153 return new_idx;
154
155 }
156
157 }
158
164
165 PolyLine* pl = new PolyLine();
166 pl->request_vertex_selections();
167 pl->request_edge_selections();
168 pl->request_vertex_vhandles();
169 pl->request_vertex_ehandles();
170 pl->request_vertex_fhandles();
171 pl->request_edge_scalars();
172
173 return add_poly_line(pl);
174 }
175
177 void reserve(size_t _count){
178 poly_lines_.reserve(poly_lines_.size() + _count);
179 }
180
181
182 //===========================================================================
185 //===========================================================================
186 inline size_t n_polylines(){return poly_lines_.size();}
187 inline PolyLine* polyline(size_t _i){return poly_lines_[_i];}
188
189 inline size_t n_visible_polylines(){return visible_.size();}
190 inline PolyLine* visible_polyline(size_t _i){return poly_lines_[visible_[_i]];}
194 //===========================================================================
197 //===========================================================================
198 inline iterator iter(){return iterator(poly_lines_.begin(), poly_lines_.end());}
199 inline index_iterator visible_iter(){return index_iterator(poly_lines_, visible_.begin(), visible_.end());}
200 inline index_iterator selected_iter(){return index_iterator(poly_lines_, selected_.begin(), selected_.end());}
207 {
208 size_t n_lines = poly_lines_.size();
209 visible_.resize(n_lines);
210 for(size_t i = 0; i < n_lines; ++i){
211 visible_[i] = i;
212 }
213 }
214
219 void set_visible(const std::vector<size_t>& _visible)
220 {
221 visible_ = _visible;
222 }
223
228 void set_selected(const std::vector<size_t>& _selected)
229 {
230 selected_ = _selected;
231 }
232
235 selected_.clear();
236 }
237
242 void clear(){
243 for (size_t i = 0; i < poly_lines_.size(); ++i)
244 {
245 delete poly_lines_[i];
246 }
247 poly_lines_.clear();
248 visible_.clear();
249
250 while(!empty_slots_.empty()) empty_slots_.pop();
251 }
252
259 void remove_polyline(int _id){
260 if(_id < int(poly_lines_.size()) && poly_lines_[_id] != 0){
261 delete poly_lines_[_id];
262 poly_lines_[_id] = 0;
263 empty_slots_.push(_id);
264 }
265 }
266
267 //===========================================================================
270 //===========================================================================
271 inline void set_color(size_t _edge_scalar, const ACG::Vec4uc& _color) {color_map_[_edge_scalar] = _color;}
272 inline ACG::Vec4uc color(size_t _edge_scalar) {return color_map_[_edge_scalar];}
275protected:
276 std::vector<PolyLine*> poly_lines_;
277 std::vector<size_t> visible_;
278 std::vector<size_t> selected_;
279
280 std::queue<size_t> empty_slots_;
281
282 // Color map for edge scalars
283 std::map<size_t, ACG::Vec4uc> color_map_;
284};
void set_visible_all()
Set all polylines to visible.
void set_visible(const std::vector< size_t > &_visible)
Set given polylines to visible.
void remove_polyline(int _id)
Remove one polyline from the collection.
void clear()
Clear Collection.
void set_selected(const std::vector< size_t > &_selected)
Set given polylines to selected.
void reserve(size_t _count)
Reserve space for additional _count polylines.
void clear_selection()
unselect all polylines in collection
virtual ~PolyLineCollectionT()
Destructor.
int new_poly_line()
Create empty polyline and return id.
size_t add_poly_line(PolyLine *_poly_line)