Mercurial > hg > svcore
comparison data/model/Labeller.h @ 1292:4b0c968a581a subdivide-instants
Add Winnow as well
author | Chris Cannam |
---|---|
date | Fri, 25 Nov 2016 09:57:36 +0000 |
parents | 22f66068b464 |
children | 114de081a42d |
comparison
equal
deleted
inserted
replaced
1291:22f66068b464 | 1292:4b0c968a581a |
---|---|
276 } | 276 } |
277 | 277 |
278 return command->finish(); | 278 return command->finish(); |
279 } | 279 } |
280 | 280 |
281 /** | |
282 * Return a command that has been executed but not yet added to | |
283 * the history. | |
284 */ | |
285 template <typename PointType> | |
286 Command *winnow(SparseModel<PointType> &model, MultiSelection *ms, int n) { | |
287 | |
288 typename SparseModel<PointType>::PointList::iterator i; | |
289 typename SparseModel<PointType>::PointList pl(model.getPoints()); | |
290 | |
291 typename SparseModel<PointType>::EditCommand *command = | |
292 new typename SparseModel<PointType>::EditCommand | |
293 (&model, tr("Subdivide")); | |
294 | |
295 int counter = 0; | |
296 | |
297 for (i = pl.begin(); i != pl.end(); ++i) { | |
298 | |
299 bool inRange = true; | |
300 if (ms) { | |
301 Selection s(ms->getContainingSelection(i->frame, false)); | |
302 if (s.isEmpty() || !s.contains(i->frame)) { | |
303 inRange = false; | |
304 } | |
305 } | |
306 if (!inRange) { | |
307 counter = 0; | |
308 continue; | |
309 } | |
310 | |
311 ++counter; | |
312 | |
313 if (counter == n+1) counter = 1; | |
314 if (counter == 1) { | |
315 // this is an Nth instant, don't remove it | |
316 continue; | |
317 } | |
318 | |
319 command->deletePoint(*i); | |
320 } | |
321 | |
322 return command->finish(); | |
323 } | |
324 | |
281 template <typename PointType> | 325 template <typename PointType> |
282 void setValue(PointType &newPoint, PointType *prevPoint = 0) { | 326 void setValue(PointType &newPoint, PointType *prevPoint = 0) { |
283 if (m_type == ValueFromExistingNeighbour) { | 327 if (m_type == ValueFromExistingNeighbour) { |
284 if (!prevPoint) { | 328 if (!prevPoint) { |
285 std::cerr << "ERROR: Labeller::setValue: Previous point required but not provided" << std::endl; | 329 std::cerr << "ERROR: Labeller::setValue: Previous point required but not provided" << std::endl; |