Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
BSplineSurfaceSelectionFunctions.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 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #include "BSplineSurfaceSelectionPlugin.hh"
51 
53 
54  BaseObjectData* object = 0;
55 
56  if(!PluginFunctions::getObject(_objectId, object)) {
57  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
58  return;
59  }
60 
63 
64  if(surface) {
65  for(unsigned int i = 0; i < surface->n_control_points_m(); ++i) {
66  for(unsigned int j = 0; j < surface->n_control_points_n(); ++j) {
67  surface->select_controlpoint(i, j);
68  }
69  }
70  }
71 
72  // Switch to control point selection mode
73  if(so)
75 
76  emit scriptInfo("selectAllControlPoints(ObjectId)");
77 }
78 
80 
81  BaseObjectData* object = 0;
82 
83  if(!PluginFunctions::getObject(_objectId, object)) {
84  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
85  return;
86  }
87 
89  if(surface) {
90  for(unsigned int i = 0; i < surface->n_control_points_m(); ++i) {
91  for(unsigned int j = 0; j < surface->n_control_points_n(); ++j) {
92  surface->deselect_controlpoint(i,j);
93  }
94  }
95  }
96 
97  emit scriptInfo("deselectAllControlPoints(ObjectId)");
98 }
99 
101 
102  BaseObjectData* object = 0;
103 
104  if(!PluginFunctions::getObject(_objectId, object)) {
105  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
106  return;
107  }
108 
111 
112  if(surface) {
113  for(unsigned int i = 0; i < surface->n_control_points_m(); ++i) {
114  for(unsigned int j = 0; j < surface->n_control_points_n(); ++j) {
115  if(surface->controlpoint_selected(i,j))
116  surface->deselect_controlpoint(i,j);
117  else
118  surface->select_controlpoint(i,j);
119  }
120  }
121  }
122 
123  // Switch to control point selection mode
124  if(so)
126 
127  emit scriptInfo("invertControlPointSelection(ObjectId)");
128 }
129 
130 // void BSplineSurfaceSelectionPlugin::deleteSelectedControlPointsU(int _objectId) {
131 //
132 // BaseObjectData* object = 0;
133 //
134 // if(!PluginFunctions::getObject(_objectId, object)) {
135 // emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
136 // return;
137 // }
138 //
139 // BSplineSurface* surface = PluginFunctions::splineSurface(object);
140 // if(surface) {
141 //
142 // bool finished = false;
143 // while(!finished) {
144 //
145 // bool restartWhile = false;
146 // for(unsigned int i = 0; i < surface->n_control_points_m(); ++i) {
147 // for(unsigned int j = 0; j < surface->n_control_points_n(); ++j) {
148 // if(surface->controlpoint_selected(i,j)) {
149 // surface->delete_vector_n(j);
150 // restartWhile = true;
151 // break;
152 // }
153 // }
154 // if(restartWhile) {
155 // break;
156 // }
157 // }
158 //
159 // finished = true;
160 // }
161 // }
162 //
163 // emit scriptInfo("deleteSelectedControlPoints(ObjectId)");
164 // }
165 //
166 // void BSplineSurfaceSelectionPlugin::deleteSelectedControlPointsV(int _objectId) {
167 //
168 // BaseObjectData* object = 0;
169 //
170 // if(!PluginFunctions::getObject(_objectId, object)) {
171 // emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
172 // return;
173 // }
174 //
175 // BSplineSurface* surface = PluginFunctions::splineSurface(object);
176 // if(surface) {
177 //
178 // bool finished = false;
179 // while(!finished) {
180 //
181 // bool restartWhile = false;
182 // for(unsigned int i = 0; i < surface->n_control_points_m(); ++i) {
183 // for(unsigned int j = 0; j < surface->n_control_points_n(); ++j) {
184 // if(surface->controlpoint_selected(i,j)) {
185 // surface->delete_vector_m(i);
186 // restartWhile = true;
187 // break;
188 // }
189 // }
190 // if(restartWhile) {
191 // break;
192 // }
193 // }
194 //
195 // finished = true;
196 // }
197 // }
198 //
199 // emit scriptInfo("deleteSelectedControlPoints(ObjectId)");
200 // }
201 
202 void BSplineSurfaceSelectionPlugin::selectControlPoints(int _objectId, const IdList& _ids, bool _deselect) {
203 
204  if(_ids.empty() ) return;
205 
206  BaseObjectData* object = 0;
207 
208  if(!PluginFunctions::getObject(_objectId, object)) {
209  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
210  return;
211  }
212 
214  if(surface) {
215  for(IdList::const_iterator it = _ids.begin(); it != _ids.end(); ++it) {
216  if(*it < (int)surface->n_control_points_m()*(int)surface->n_control_points_n()) {
217 
218  int idx_m = *it / surface->n_control_points_n();
219  int idx_n = *it % surface->n_control_points_n();
220 
221  if(_deselect) surface->deselect_controlpoint(idx_m, idx_n);
222  else surface->select_controlpoint(idx_m, idx_n);
223  }
224  }
225  }
226 
227  QString selection = "selectControlPoints(ObjectId, [ " + QString::number(_ids[0]);
228 
229  for (uint i = 1 ; i < _ids.size(); ++i) {
230  selection += ", " + QString::number(_ids[i]);
231  }
232 
233  selection += " ])";
234 
235 
236  emit scriptInfo(selection);
237 }
238 
240 
241  BaseObjectData* object = 0;
242 
243  IdList list;
244 
245  if(!PluginFunctions::getObject(_objectId, object)) {
246  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
247  return list;
248  }
249 
251  if(surface) {
252  for(unsigned int i = 0; i < surface->n_control_points_m(); ++i) {
253  for(unsigned int j = 0; j < surface->n_control_points_n(); ++j) {
254  if(surface->controlpoint_selected(i,j))
255  list.push_back((int)i*surface->n_control_points_n() + (int)j);
256  }
257  }
258  }
259 
260  return list;
261 }
262 
263 //=====================================================================
264 
266 
267  BaseObjectData* object = 0;
268 
269  if(!PluginFunctions::getObject(_objectId, object)) {
270  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
271  return;
272  }
273 
276 
277  if(surface) {
278  for(unsigned int i = 0; i < surface->n_knots_m(); ++i) {
279  surface->get_knotvector_m_ref()->select(i);
280  }
281  for(unsigned int i = 0; i < surface->n_knots_n(); ++i) {
282  surface->get_knotvector_n_ref()->select(i);
283  }
284  }
285 
286  // Switch to control point selection mode
287  if(so)
289 
290  emit scriptInfo("selectAllKnots(ObjectId)");
291 }
292 
294 
295  BaseObjectData* object = 0;
296 
297  if(!PluginFunctions::getObject(_objectId, object)) {
298  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
299  return;
300  }
301 
303 
304  if(surface) {
305  for(unsigned int i = 0; i < surface->n_knots_m(); ++i) {
306  surface->get_knotvector_m_ref()->deselect(i);
307  }
308  for(unsigned int i = 0; i < surface->n_knots_n(); ++i) {
309  surface->get_knotvector_n_ref()->deselect(i);
310  }
311  }
312 
313  emit scriptInfo("deselectAllKnots(ObjectId)");
314 }
315 
317 
318  BaseObjectData* object = 0;
319 
320  if(!PluginFunctions::getObject(_objectId, object)) {
321  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
322  return;
323  }
324 
327 
328  if(surface) {
329  for(unsigned int i = 0; i < surface->n_knots_m(); ++i) {
330  if(surface->get_knotvector_m_ref()->selected(i))
331  surface->get_knotvector_m_ref()->deselect(i);
332  else
333  surface->get_knotvector_m_ref()->select(i);
334  }
335  for(unsigned int i = 0; i < surface->n_knots_n(); ++i) {
336  if(surface->get_knotvector_n_ref()->selected(i))
337  surface->get_knotvector_n_ref()->deselect(i);
338  else
339  surface->get_knotvector_n_ref()->select(i);
340  }
341  }
342 
343  // Switch to control point selection mode
344  if(so)
346 
347  emit scriptInfo("invertKnotSelection(ObjectId)");
348 }
349 
351 
352 //
353 // // I know this is a bit crappy, but knot indices
354 // // change forcably after each delete operation so we have to
355 // // start over each time...
356 // bool breakWhile = false;
357 // while(!breakWhile) {
358 // bool oneFound = false;
359 // unsigned int i = 0;
360 // for(; i < surface->n_knots_n(); ++i) {
361 // if(surface->get_knotvector_n_ref()->selected(i)) {
362 // surface->get_knotvector_n_ref()->deleteKnot(i);
363 // oneFound = true;
364 // break;
365 // }
366 // }
367 //
368 // if((i >= surface->n_knots_n()) && !oneFound) {
369 // // We are through
370 // breakWhile = true;
371 // }
372 // }
373 // }
374 //
375 // emit scriptInfo("deleteSelectedKnots(ObjectId)");
376 }
377 
379 
380 // BaseObjectData* object = 0;
381 //
382 // if(!PluginFunctions::getObject(_objectId, object)) {
383 // emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
384 // return;
385 // }
386 //
387 // BSplineSurface* surface = PluginFunctions::splineSurface(object);
388 // if(surface) {
389 //
390 // // I know this is a bit crappy, but knot indices
391 // // change forcably after each delete operation so we have to
392 // // start over each time...
393 // bool breakWhile = false;
394 // while(!breakWhile) {
395 // bool oneFound = false;
396 // unsigned int i = 0;
397 // for(; i < surface->n_knots(); ++i) {
398 // if(surface->get_knotvector_ref()->selected(i)) {
399 // surface->get_knotvector_ref()->deleteKnot(i);
400 // oneFound = true;
401 // break;
402 // }
403 // }
404 //
405 // if((i >= surface->n_knots()) && !oneFound) {
406 // // We are through
407 // breakWhile = true;
408 // }
409 // }
410 // }
411 //
412 // emit scriptInfo("deleteSelectedKnots(ObjectId)");
413 }
414 
415 void BSplineSurfaceSelectionPlugin::selectKnots(int _objectId, const IdList& _ids_u, const IdList& _ids_v, bool _deselect) {
416 
417  if(_ids_u.empty()) return;
418 
419  BaseObjectData* object = 0;
420 
421  if(!PluginFunctions::getObject(_objectId, object)) {
422  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
423  return;
424  }
425 
427  if(surface) {
428  for(IdList::const_iterator it = _ids_u.begin(); it != _ids_u.end(); ++it) {
429  if(*it < (int)surface->n_knots_m()) {
430  if(_deselect) surface->get_knotvector_m_ref()->deselect(*it);
431  else surface->get_knotvector_m_ref()->select(*it);
432  }
433  }
434  for(IdList::const_iterator it = _ids_v.begin(); it != _ids_v.end(); ++it) {
435  if(*it < (int)surface->n_knots_n()) {
436  if(_deselect) surface->get_knotvector_n_ref()->deselect(*it);
437  else surface->get_knotvector_n_ref()->select(*it);
438  }
439  }
440  }
441 
442  QString selection = "selectKnots(ObjectId, [ " + QString::number(_ids_u[0]);
443 
444  for (uint i = 1 ; i < _ids_u.size(); ++i) {
445  selection += ", " + QString::number(_ids_u[i]);
446  }
447 
448  selection += "; ";
449 
450  for (uint i = 0 ; i < _ids_v.size(); ++i) {
451  selection += ", " + QString::number(_ids_v[i]);
452  }
453 
454  selection += " ])";
455 
456 
457  emit scriptInfo(selection);
458 }
459 
461 
462  BaseObjectData* object = 0;
463 
464  IdList list;
465 
466  if(!PluginFunctions::getObject(_objectId, object)) {
467  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
468  return list;
469  }
470 
472  if(surface) {
473  for(unsigned int i = 0; i < surface->n_knots_m(); ++i) {
474  if(surface->get_knotvector_m_ref()->selected(i))
475  list.push_back((int)i);
476  }
477  }
478 
479  return list;
480 }
481 
483 
484  BaseObjectData* object = 0;
485 
486  IdList list;
487 
488  if(!PluginFunctions::getObject(_objectId, object)) {
489  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
490  return list;
491  }
492 
494  if(surface) {
495  for(unsigned int i = 0; i < surface->n_knots_n(); ++i) {
496  if(surface->get_knotvector_n_ref()->selected(i))
497  list.push_back((int)i);
498  }
499  }
500 
501  return list;
502 
503 }
Knotvector * get_knotvector_n_ref()
Get a reference to the knotvector in n direction.
BSplineSurface * splineSurface(BaseObjectData *_object)
Get a Bspline Surface from an object.
void deselectAllKnots(int _objectId)
Deselect all knots of a curve.
IdList getKnotSelectionV(int _objectId)
Select all control points of a curve.
unsigned int n_knots_n()
Returns the number of knots in n direction.
bool getObject(int _identifier, BSplineCurveObject *&_object)
void deleteSelectedKnotsU(int _objectId)
Delete selected knots.
IdList getKnotSelectionU(int _objectId)
Get current knot selection.
void selectAllKnots(int _objectId)
Select all knots of a curve.
unsigned int n_control_points_n() const
Returns the number of controlpoints in n direction.
IdList getControlPointSelection(int _objectId)
Get current control point selection.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:192
void deselectAllControlPoints(int _objectId)
Deselect all control points of a curve.
ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface > * splineSurfaceNode()
Return pointer to the bspline surface node.
Knotvector * get_knotvector_m_ref()
Get a reference to the knotvector in m direction.
void selectAllControlPoints(int _objectId)
Select all control points of a curve.
void deleteSelectedKnotsV(int _objectId)
Select all control points of a curve.
void invertKnotSelection(int _objectId)
Invert knot selection.
void selectKnots(int _objectId, const IdList &_ids_u, const IdList &_ids_v, bool _deselect=false)
Select specific knots of a curve.
void invertControlPointSelection(int _objectId)
Invert control point selection.
void selectControlPoints(int _objectId, const IdList &_ids, bool _deselect=false)
Delete selected control points.
unsigned int n_control_points_m() const
Returns the number of controlpoints in m direction.
BSplineSurfaceObject * bsplineSurfaceObject(BaseObjectData *_object)
Cast an BaseObject to a BSplineSurfaceObject if possible.
unsigned int n_knots_m()
Returns the number of knots in m direction.