Developer Documentation
SplatCloudSelection.cc
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 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 //================================================================
51 //
52 // SplatCloudSelection - IMPLEMENTATION
53 //
54 //================================================================
55 
56 
57 //== INCLUDES =================================================================
58 
59 
60 #include "SplatCloudSelection.hh"
61 
62 
63 //== NAMESPACES ===============================================================
64 
65 
66 namespace SplatCloudSelection {
67 
68 
69 //== IMPLEMENTATION ==========================================================
70 
71 
72 //=========================================================
73 //== Vertex Selection =====================================
74 //=========================================================
75 
76 
77 void selectVertices( SplatCloud *_splatCloud, const std::vector<int> &_vertices )
78 {
79  if( _splatCloud == 0 )
80  return; // error
81 
82  if( _vertices.empty() )
83  return; // done
84 
85  if( !_splatCloud->hasSelections() )
86  {
87  if( !_splatCloud->requestSelections() )
88  return; // error
89 
90  unsigned int i, num = _splatCloud->numSplats();
91  for( i=0; i<num; ++i )
92  _splatCloud->selections( i ) = false;
93  }
94 
95  int n_vertices = (int) _splatCloud->numSplats();
96 
97  unsigned int i;
98  for( i=0; i<_vertices.size(); ++i )
99  {
100  int v = _vertices[ i ];
101  if( (v >= 0) && (v < n_vertices) )
102  _splatCloud->selections( v ) = true;
103  }
104 }
105 
106 
107 //----------------------------------------------------------------
108 
109 
110 void unselectVertices( SplatCloud *_splatCloud, const std::vector<int> &_vertices )
111 {
112  if( _splatCloud == 0 )
113  return; // error
114 
115  if( _vertices.empty() )
116  return; // done
117 
118  if( !_splatCloud->hasSelections() )
119  return; // done
120 
121  int n_vertices = (int) _splatCloud->numSplats();
122 
123  unsigned int i;
124  for( i=0; i<_vertices.size(); ++i )
125  {
126  int v = _vertices[ i ];
127  if( (v >= 0) && (v < n_vertices) )
128  _splatCloud->selections( v ) = false;
129  }
130 }
131 
132 
133 //----------------------------------------------------------------
134 
135 
136 void selectAllVertices( SplatCloud *_splatCloud )
137 {
138  if( _splatCloud == 0 )
139  return; // error
140 
141  if( !_splatCloud->hasSelections() )
142  {
143  if( !_splatCloud->requestSelections() )
144  return; // error
145  }
146 
147  unsigned int i, num = _splatCloud->numSplats();
148  for( i=0; i<num; ++i )
149  _splatCloud->selections( i ) = true;
150 }
151 
152 
153 //----------------------------------------------------------------
154 
155 
156 void clearVertexSelection( SplatCloud *_splatCloud )
157 {
158  if( _splatCloud == 0 )
159  return; // error
160 
161  if( !_splatCloud->hasSelections() )
162  return; // done
163 
164  unsigned int i, num = _splatCloud->numSplats();
165  for( i=0; i<num; ++i )
166  _splatCloud->selections( i ) = false;
167 }
168 
169 
170 //----------------------------------------------------------------
171 
172 
173 void invertVertexSelection( SplatCloud *_splatCloud )
174 {
175  if( _splatCloud == 0 )
176  return; // error
177 
178  if( _splatCloud->hasSelections() )
179  {
180  unsigned int i, num = _splatCloud->numSplats();
181  for( i=0; i<num; ++i )
182  _splatCloud->selections( i ) = !_splatCloud->selections( i );
183  }
184  else
185  {
186  if( !_splatCloud->requestSelections() )
187  return; // error
188 
189  unsigned int i, num = _splatCloud->numSplats();
190  for( i=0; i<num; ++i )
191  _splatCloud->selections( i ) = true;
192  }
193 }
194 
195 
196 //----------------------------------------------------------------
197 
198 
199 static unsigned int countSelected( const SplatCloud *_splatCloud )
200 {
201  unsigned int count = 0;
202 
203  unsigned int i, num = _splatCloud->numSplats();
204  for( i=0; i<num; ++i )
205  {
206  if( _splatCloud->selections( i ) )
207  ++count;
208  }
209 
210  return count;
211 }
212 
213 
214 //----------------------------------------------------------------
215 
216 
217 std::vector<int> getVertexSelection( const SplatCloud *_splatCloud )
218 {
219  std::vector<int> vertices;
220 
221  if( _splatCloud == 0 )
222  return vertices; // error
223 
224  if( !_splatCloud->hasSelections() )
225  return vertices; // done
226 
227  unsigned int numSelected = countSelected( _splatCloud );
228 
229  vertices.reserve( numSelected );
230 
231  unsigned int i, num = _splatCloud->numSplats();
232  for( i=0; i<num; ++i )
233  {
234  if( _splatCloud->selections( i ) )
235  vertices.push_back( i );
236  }
237 
238  return vertices;
239 }
240 
241 
242 //----------------------------------------------------------------
243 
244 
245 std::vector<int> getVertexSelection( const SplatCloud *_splatCloud, bool &_inverted )
246 {
247  _inverted = false;
248 
249  std::vector<int> vertices;
250 
251  if( _splatCloud == 0 )
252  return vertices; // error
253 
254  if( !_splatCloud->hasSelections() )
255  return vertices; // done
256 
257  unsigned int numSelected = countSelected( _splatCloud );
258  unsigned int numUnselected = _splatCloud->numSplats() - numSelected;
259 
260  if( numSelected <= numUnselected )
261  {
262  vertices.reserve( numSelected );
263 
264  unsigned int i, num = _splatCloud->numSplats();
265  for( i=0; i<num; ++i )
266  {
267  if( _splatCloud->selections( i ) )
268  vertices.push_back( i );
269  }
270  }
271  else
272  {
273  _inverted = true;
274 
275  vertices.reserve( numUnselected );
276 
277  unsigned int i, num = _splatCloud->numSplats();
278  for( i=0; i<num; ++i )
279  {
280  if( !_splatCloud->selections( i ) )
281  vertices.push_back( i );
282  }
283  }
284 
285  return vertices;
286 }
287 
288 
289 //=============================================================================
290 
291 
292 } // namespace SplatCloudSelection
293 
294 
295 //=============================================================================
bool requestSelections()
Request the predefined property.
Definition: SplatCloud.hh:567
Selection & selections(int _idx)
Get a reference of the predefined property&#39;s value.
Definition: SplatCloud.hh:643
void selectAllVertices(MeshT *_mesh)
Select all vertices of a mesh.
void selectVertices(MeshT *_mesh, const std::vector< int > &_vertices)
Select given vertices of a mesh.
unsigned int numSplats() const
Get the number of splats.
Definition: SplatCloud.hh:179
void clearVertexSelection(MeshT *_mesh)
Set all vertices to unselected.
bool hasSelections() const
Return the availability of the predefined property.
Definition: SplatCloud.hh:613
std::vector< int > getVertexSelection(MeshT *_mesh)
Get the current vertex selection.
void invertVertexSelection(MeshT *_mesh)
invert vertex selection
Functions for selection on a SplatCloud.
void unselectVertices(MeshT *_mesh, const std::vector< int > &_vertices)
Unselect given vertices of a mesh.