Developer Documentation
SplatCloudObjectSelectionPlugin2.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 // CLASS SplatCloudObjectSelectionPlugin - IMPLEMENTATION (continued)
53 //
54 //================================================================
55 
56 
57 //== INCLUDES ====================================================
58 
59 
60 #include "SplatCloudObjectSelectionPlugin.hh"
61 
62 #include "SplatCloudSelection.hh"
63 
64 
65 //== IMPLEMENTATION ==============================================
66 
67 
74 bool SplatCloudObjectSelectionPlugin::splatCloudDeleteSelection( SplatCloud *_splatCloud, PrimitiveType _primitiveType )
75 {
76  if( (_primitiveType & vertexType_) == 0 )
77  return false; // done
78 
79  if( _splatCloud == 0 )
80  return false; // error
81 
82  unsigned int numDeleted = _splatCloud->eraseSplatsByIndex( SplatCloudSelection::getVertexSelection( _splatCloud ) );
83 
84  return (numDeleted != 0);
85 }
86 
87 
88 //----------------------------------------------------------------
89 
90 
98 void SplatCloudObjectSelectionPlugin::splatCloudToggleSelection( SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, PrimitiveType _primitiveType )
99 {
100  if( (_primitiveType & vertexType_) == 0 )
101  return; // done
102 
103  if( _splatCloud == 0 )
104  return; // error
105 
106  if( /*(_index < 0) ||*/ (_index >= _splatCloud->numSplats()) )
107  return; // error
108 
109  if( !_splatCloud->hasSelections() )
110  {
111  if( !_splatCloud->requestSelections() )
112  return; // error
113 
114  unsigned int i, num = _splatCloud->numSplats();
115  for( i=0; i<num; ++i )
116  _splatCloud->selections( i ) = false;
117  }
118 
119  _splatCloud->selections( _index ) = !_splatCloud->selections( _index );
120 
121  if( _splatCloud->selections( _index ) )
122  emit scriptInfo( "selectVertices(ObjectId , [" + QString::number( _index ) + "])" );
123  else
124  emit scriptInfo( "unselectVertices(ObjectId , [" + QString::number( _index ) + "])" );
125 }
126 
127 
128 //----------------------------------------------------------------
129 
130 
140 void SplatCloudObjectSelectionPlugin::splatCloudSphereSelection( SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, double _radius, PrimitiveType _primitiveType, bool _deselection )
141 {
142  if( (_primitiveType & vertexType_) == 0 )
143  return; // done
144 
145  if( _splatCloud == 0 )
146  return; // error
147 
148  if( /*(_index < 0) ||*/ (_index >= _splatCloud->numSplats()) )
149  return; // error
150 
151  if( !_splatCloud->hasPositions() )
152  return; // error
153 
154  if( !_splatCloud->hasSelections() )
155  {
156  if( _deselection )
157  return; // done
158 
159  if( !_splatCloud->requestSelections() )
160  return; // error
161 
162  unsigned int i, num = _splatCloud->numSplats();
163  for( i=0; i<num; ++i )
164  _splatCloud->selections( i ) = false;
165  }
166 
167  if( _radius < 0.0 )
168  return; // done
169 
170  double sqrRadius = _radius * _radius;
171 
172  SplatCloud::Selection selection = !_deselection;
173 
174  unsigned int i, num = _splatCloud->numSplats();
175  for( i=0; i<num; ++i )
176  {
177  const SplatCloud::Position &pos = _splatCloud->positions( i );
178 
179  double dx = pos[0] - _hit_point[0];
180  double dy = pos[1] - _hit_point[1];
181  double dz = pos[2] - _hit_point[2];
182 
183  double sqrDist = dx*dx + dy*dy + dz*dz;
184 
185  if( sqrDist <= sqrRadius )
186  _splatCloud->selections( i ) = selection;
187  }
188 }
189 
190 
191 //----------------------------------------------------------------
192 
193 
203 bool SplatCloudObjectSelectionPlugin::splatCloudVolumeSelection( SplatCloud *_splatCloud, ACG::GLState &_state, QRegion *_region, PrimitiveType _primitiveType, bool _deselection )
204 {
205  if( (_primitiveType & vertexType_) == 0 )
206  return false; // done
207 
208  if( _splatCloud == 0 )
209  return false; // error
210 
211  if( !_splatCloud->hasPositions() )
212  return false; // error
213 
214  bool modify = true;
215 
216  if( !_splatCloud->hasSelections() )
217  {
218  if( _deselection )
219  {
220  modify = false;
221  }
222  else
223  {
224  if( !_splatCloud->requestSelections() )
225  return false; // error
226 
227  unsigned int i, num = _splatCloud->numSplats();
228  for( i=0; i<num; ++i )
229  _splatCloud->selections( i ) = false;
230  }
231  }
232 
233  bool rv = false;
234 
235  SplatCloud::Selection selection = !_deselection;
236 
237  int i, num = static_cast<int>(_splatCloud->numSplats());
238 #ifdef USE_OPENMP
239  #pragma omp parallel for
240 #endif
241  for( i=0; i<num; ++i )
242  {
243  const SplatCloud::Position &pos = _splatCloud->positions( i );
244 
245  ACG::Vec3d proj = _state.project( ACG::Vec3d( pos[0], pos[1], pos[2] ) );
246 
247  if( _region->contains( QPoint( (int) proj[0], _state.context_height() - (int) proj[1] ) ) )
248  {
249  if( modify )
250  _splatCloud->selections( i ) = selection;
251 
252  rv = true;
253  }
254  }
255 
256  return rv;
257 }
258 
259 
260 //----------------------------------------------------------------
261 
262 
272 void SplatCloudObjectSelectionPlugin::splatCloudColorizeSelection( SplatCloud *_splatCloud, PrimitiveType _primitiveTypes, int _r, int _g, int _b, int _a )
273 {
274  if( (_primitiveTypes & vertexType_) == 0 )
275  return; // done
276 
277  if( _splatCloud == 0 )
278  return; // error
279 
280  if( !_splatCloud->hasColors() )
281  {
282  if( !_splatCloud->requestColors() )
283  return; // error
284 
285  SplatCloud::Color black( 0, 0, 0 );
286 
287  unsigned int i, num = _splatCloud->numSplats();
288  for( i=0; i<num; ++i )
289  _splatCloud->colors( i ) = black;
290  }
291 
292  if( !_splatCloud->hasSelections() )
293  return; // done
294 
295  unsigned char r = (_r < 0) ? 0 : (_r > 255) ? 255 : (unsigned char) _r;
296  unsigned char g = (_g < 0) ? 0 : (_g > 255) ? 255 : (unsigned char) _g;
297  unsigned char b = (_b < 0) ? 0 : (_b > 255) ? 255 : (unsigned char) _b;
298 
299  SplatCloud::Color color( r, g, b ); // drop alpha
300 
301  unsigned int i, num = _splatCloud->numSplats();
302  for( i=0; i<num; ++i )
303  {
304  if( _splatCloud->selections( i ) )
305  _splatCloud->colors( i ) = color;
306  }
307 }
bool requestSelections()
Request the predefined property.
Definition: SplatCloud.hh:567
Position & positions(int _idx)
Get a reference of the predefined property&#39;s value.
Definition: SplatCloud.hh:631
unsigned int numSplats() const
Get the number of splats.
Definition: SplatCloud.hh:179
SelectionInterface::PrimitiveType vertexType_
Primitive type handle.
Color & colors(int _idx)
Get a reference of the predefined property&#39;s value.
Definition: SplatCloud.hh:633
bool hasSelections() const
Return the availability of the predefined property.
Definition: SplatCloud.hh:613
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
Definition: GLState.cc:640
void splatCloudColorizeSelection(SplatCloud *_splatCloud, PrimitiveType _primitiveTypes, int _r, int _g, int _b, int _a)
Colorize the selection.
bool hasPositions() const
Return the availability of the predefined property.
Definition: SplatCloud.hh:607
void splatCloudSphereSelection(SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, double _radius, PrimitiveType _primitiveTypes, bool _deselection)
Use the event to paint selection with a sphere.
bool hasColors() const
Return the availability of the predefined property.
Definition: SplatCloud.hh:608
bool requestColors()
Request the predefined property.
Definition: SplatCloud.hh:562
Selection & selections(int _idx)
Get a reference of the predefined property&#39;s value.
Definition: SplatCloud.hh:643
void splatCloudToggleSelection(SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, PrimitiveType _primitiveType)
Toggle SplatCloud selection.
bool splatCloudDeleteSelection(SplatCloud *_splatCloud, PrimitiveType _primitiveType)
Delete all selected elements of a SplatCloud.
unsigned int eraseSplatsByIndex(const T &_indices)
Delete the elements with given indices from the data vector of all splat-properties.
int context_height() const
get gl context height
Definition: GLState.hh:855
Functions for selection on a SplatCloud.
bool splatCloudVolumeSelection(SplatCloud *_splatCloud, ACG::GLState &_state, QRegion *_region, PrimitiveType _primitiveTypes, bool _deselection)
Surface volume selection tool.