Developer Documentation

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