Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkMesh.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkMesh.h"
14 #include "mitkInteractionConst.h"
15 #include "mitkLine.h"
16 #include "mitkLineOperation.h"
17 #include "mitkLineOperation.h"
18 #include "mitkNumericTypes.h"
19 #include "mitkOperation.h"
20 #include "mitkOperationActor.h"
21 #include "mitkPointOperation.h"
22 #include "mitkRenderingManager.h"
23 #include "mitkStatusBar.h"
24 
26 {
27 }
28 
30 {
31 }
32 
34 {
35  return m_PointSetSeries[t];
36 }
37 
39 {
40  return m_PointSetSeries[t];
41 }
42 
43 void mitk::Mesh::SetMesh(DataType *mesh, int t)
44 {
45  this->Expand(t + 1);
46  m_PointSetSeries[t] = mesh;
47 }
48 
49 unsigned long mitk::Mesh::GetNumberOfCells(int t)
50 {
51  return m_PointSetSeries[t]->GetNumberOfCells();
52 }
53 
54 // search a line that is close enough according to the given position
55 bool mitk::Mesh::SearchLine(Point3D point, float distance, unsigned long &lineId, unsigned long &cellId, int t)
56 {
57  // returns true if a line is found
58  ScalarType bestDist = distance;
59 
60  // iterate through all cells.
61  ConstCellIterator cellIt = m_PointSetSeries[t]->GetCells()->Begin();
62  ConstCellIterator cellEnd = m_PointSetSeries[t]->GetCells()->End();
63  while (cellIt != cellEnd)
64  {
65  if (cellIt.Value()->GetNumberOfPoints() > 1)
66  {
67  // then iterate through all indexes of points in it->Value()
68  PointIdIterator inAIt = cellIt.Value()->PointIdsBegin(); // first point
69  PointIdIterator inBIt = cellIt.Value()->PointIdsBegin(); // second point
70  PointIdIterator inEnd = cellIt.Value()->PointIdsEnd();
71 
72  ++inAIt; // so it points to the point before inBIt
73 
74  int currentLineId = 0;
75  while (inAIt != inEnd)
76  {
77  mitk::PointSet::PointType pointA, pointB;
78  if (m_PointSetSeries[t]->GetPoint((*inAIt), &pointA) && m_PointSetSeries[t]->GetPoint((*inBIt), &pointB))
79  {
80  auto line = new Line<CoordinateType>();
81  line->SetPoints(pointA, pointB);
82  double thisDistance = line->Distance(point);
83  if (thisDistance < bestDist)
84  {
85  cellId = cellIt->Index();
86  lineId = currentLineId;
87  bestDist = thisDistance;
88  }
89  }
90  ++inAIt;
91  ++inBIt;
92  ++currentLineId;
93  }
94 
95  // If the cell is closed, then check the line from the last index to
96  // the first index if inAIt points to inEnd, then inBIt points to the
97  // last index.
98  CellDataType cellData;
99  bool dataOk = m_PointSetSeries[t]->GetCellData(cellIt->Index(), &cellData);
100  if (dataOk)
101  {
102  if (cellData.closed)
103  {
104  // get the points
105  PointIdIterator inAIt = cellIt.Value()->PointIdsBegin(); // first point
106  // inBIt points to last.
107  mitk::PointSet::PointType pointA, pointB;
108  if (m_PointSetSeries[t]->GetPoint((*inAIt), &pointA) && m_PointSetSeries[t]->GetPoint((*inBIt), &pointB))
109  {
110  auto line = new Line<CoordinateType>();
111  line->SetPoints(pointA, pointB);
112  double thisDistance = line->Distance(point);
113  if (thisDistance < bestDist)
114  {
115  cellId = cellIt->Index();
116  lineId = currentLineId;
117  bestDist = thisDistance;
118  }
119  }
120  }
121  }
122  }
123  ++cellIt;
124  }
125  return (bestDist < distance);
126 }
127 
128 int mitk::Mesh::SearchFirstCell(unsigned long pointId, int t)
129 {
130  // iterate through all cells and find the cell the given pointId is inside
131  ConstCellIterator it = m_PointSetSeries[t]->GetCells()->Begin();
132  ConstCellIterator end = m_PointSetSeries[t]->GetCells()->End();
133  while (it != end)
134  {
135  PointIdIterator position = std::find(it->Value()->PointIdsBegin(), it->Value()->PointIdsEnd(), pointId);
136 
137  if (position != it->Value()->PointIdsEnd())
138  {
139  return it->Index();
140  }
141  ++it;
142  }
143  return -1;
144 }
145 
146 // Due to not implemented itk::CellInterface::EvaluatePosition and errors in
147 // using vtkCell::EvaluatePosition (changing iterator!) we must implement
148 // it in mitk::Mesh
149 // make it easy and look for hit points and hit lines: needs to be done anyway!
150 bool mitk::Mesh::EvaluatePosition(mitk::Point3D point, unsigned long &cellId, float precision, int t)
151 {
152  int pointId = this->SearchPoint(point, precision, t);
153  if (pointId > -1)
154  {
155  // search the cell the point lies inside
156  cellId = this->SearchFirstCell(pointId, t);
157  return true;
158  }
159  unsigned long lineId = 0;
160  if (this->SearchLine(point, precision, lineId, cellId, t))
161  {
162  return true;
163  }
164 
165  return false;
166 }
167 
168 unsigned long mitk::Mesh::GetNewCellId(int t)
169 {
170  long nextCellId = -1;
171  ConstCellIterator it = m_PointSetSeries[t]->GetCells()->Begin();
172  ConstCellIterator end = m_PointSetSeries[t]->GetCells()->End();
173 
174  while (it != end)
175  {
176  nextCellId = it.Index();
177  ++it;
178  }
179  ++nextCellId;
180  return nextCellId;
181 }
182 
184 {
185  CellDataIterator cellDataIt, cellDataEnd;
186  cellDataEnd = m_PointSetSeries[t]->GetCellData()->End();
187  for (cellDataIt = m_PointSetSeries[t]->GetCellData()->Begin(); cellDataIt != cellDataEnd; cellDataIt++)
188  {
189  // then declare an operation which unselects this line; UndoOperation as well!
190  if (cellDataIt->Value().selected)
191  {
192  return cellDataIt->Index();
193  }
194  }
195  return -1;
196 }
197 
198 // get the cell; then iterate through the Ids times lineId. Then IdA ist the
199 // one, IdB ist ne next.don't forget the last closing line if the cell is
200 // closed
201 bool mitk::Mesh::GetPointIds(unsigned long cellId, unsigned long lineId, int &idA, int &idB, int t)
202 {
203  CellAutoPointer cellAutoPointer;
204  bool ok = m_PointSetSeries[t]->GetCell(cellId, cellAutoPointer);
205  if (ok)
206  {
207  CellType *cell = cellAutoPointer.GetPointer();
208 
209  // Get the cellData to also check the closing line
210  CellDataType cellData;
211  m_PointSetSeries[t]->GetCellData(cellId, &cellData);
212  bool closed = cellData.closed;
213 
214  PointIdIterator pointIdIt = cell->PointIdsBegin();
215  PointIdIterator pointIdEnd = cell->PointIdsEnd();
216  unsigned int counter = 0;
217  bool found = false;
218  while (pointIdIt != pointIdEnd)
219  {
220  if (counter == lineId)
221  {
222  idA = (*pointIdIt);
223  ++pointIdIt;
224  found = true;
225  break;
226  }
227  ++counter;
228  ++pointIdIt;
229  }
230  if (found)
231  {
232  // if in the middle
233  if (pointIdIt != pointIdEnd)
234  {
235  idB = (*pointIdIt);
236  }
237  // if found but on the end, then it is the closing connection, so the
238  // last and the first point
239  else if (closed)
240  {
241  pointIdIt = cell->PointIdsBegin();
242  idB = (*pointIdIt);
243  }
244  }
245  else
246  ok = false;
247  }
248  return ok;
249 }
250 
252 {
253  // adding only the operations, that aren't implemented by the pointset.
254  switch (operation->GetOperationType())
255  {
256  case OpNOTHING:
257  break;
258 
259  case OpNEWCELL:
260  {
261  auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
262 
263  // if no lineoperation, then call superclass pointSet
264  if (lineOp == nullptr)
265  {
266  Superclass::ExecuteOperation(operation);
267  }
268 
269  bool ok;
270  int cellId = lineOp->GetCellId();
271  CellAutoPointer cellAutoPointer;
272  ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
273 
274  // if it doesn't already exist
275  if (!ok)
276  {
277  cellAutoPointer.TakeOwnership(new PolygonType);
278  m_PointSetSeries[0]->SetCell(cellId, cellAutoPointer);
279  CellDataType cellData;
280  cellData.selected = true;
281  cellData.selectedLines.clear();
282  cellData.closed = false;
283  m_PointSetSeries[0]->SetCellData(cellId, cellData);
284  }
285  }
286  break;
287 
288  case OpDELETECELL:
289  {
290  auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
291  if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet
292  {
293  Superclass::ExecuteOperation(operation);
294  }
295  m_PointSetSeries[0]->GetCells()->DeleteIndex((unsigned)lineOp->GetCellId());
296  m_PointSetSeries[0]->GetCellData()->DeleteIndex((unsigned)lineOp->GetCellId());
297  }
298  break;
299 
300  case OpCLOSECELL:
301  // sets the bolean flag closed from a specified cell to true.
302  {
303  auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
304  if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet
305  {
306  // then search the selected cell!//TODO
307  Superclass::ExecuteOperation(operation);
308  }
309  bool ok;
310  int cellId = lineOp->GetCellId();
311  if (cellId < 0) // cellId isn't set
312  {
313  cellId = this->SearchSelectedCell(0);
314  if (cellId < 0) // still not found
315  return;
316  }
317  CellAutoPointer cellAutoPointer;
318 
319  // get directly the celldata!TODO
320  ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
321  if (ok)
322  {
323  CellDataType cellData;
324  m_PointSetSeries[0]->GetCellData(cellId, &cellData);
325  cellData.closed = true;
326  m_PointSetSeries[0]->SetCellData(cellId, cellData);
327  }
328  }
329  break;
330 
331  case OpOPENCELL:
332  {
333  auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
334  if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet
335  {
336  Superclass::ExecuteOperation(operation);
337  }
338  bool ok;
339  int cellId = lineOp->GetCellId();
340  CellAutoPointer cellAutoPointer;
341  ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
342  if (ok)
343  {
344  CellDataType cellData;
345  m_PointSetSeries[0]->GetCellData(cellId, &cellData);
346  cellData.closed = false;
347  ;
348  m_PointSetSeries[0]->SetCellData(cellId, cellData);
349  }
350  }
351  break;
352 
353  case OpADDLINE:
354  // inserts the ID of the selected point into the indexes of lines in the
355  // selected cell afterwars the added line is selected
356  {
357  auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
358 
359  int cellId = -1;
360  int pId = -1;
361 
362  if (lineOp == nullptr)
363  {
364  cellId = this->SearchSelectedCell(0);
365  if (cellId == -1)
366  return;
367 
368  pId = this->SearchSelectedPoint(0);
369  if (pId == -1)
370  return;
371  }
372  else
373  {
374  cellId = lineOp->GetCellId();
375  if (cellId == -1)
376  return;
377  pId = lineOp->GetPIdA();
378  if (pId == -1)
379  return;
380  }
381 
382  bool ok;
383  CellAutoPointer cellAutoPointer;
384  ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
385  if (ok)
386  {
387  CellType *cell = cellAutoPointer.GetPointer();
388  if (cell->GetType() == CellType::POLYGON_CELL)
389  {
390  auto *polygon = static_cast<PolygonType *>(cell);
391  // add the pointId to the Cell. filling the empty cell with
392  // one id doesn't mean to add a line, it means, that the
393  // initilal PointId is set. The next addition of a pointId adds
394  // a line
395  polygon->AddPointId(pId);
396 
397  // select the line, if we really added a line, so now have more than
398  // 1 pointID in the cell
399  CellDataType cellData;
400  ok = m_PointSetSeries[0]->GetCellData(cellId, &cellData);
401  if (ok)
402  {
403  // A line between point 0 and 1 has the Id 0. A line between
404  // 1 and 2 has a Id = 1. So we add getnumberofpoints-2.
405  if (polygon->GetNumberOfPoints() > 1)
406  cellData.selectedLines.push_back(polygon->GetNumberOfPoints() - 2);
407  }
408  m_PointSetSeries[0]->SetCellData(cellId, cellData);
409  m_PointSetSeries[0]->SetCell(cellId, cellAutoPointer);
410  }
411  }
412  }
413  break;
414 
415  case OpDELETELINE:
416  {
417  // deleted the last line through removing the index PIdA
418  // (if set to -1, use the last point) in the given cellId
419  auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
420  int cellId = -1;
421  int pId = -1;
422 
423  if (lineOp == nullptr)
424  {
425  cellId = this->SearchSelectedCell(0);
426  if (cellId == -1)
427  return;
428  pId = this->SearchSelectedPoint(0);
429  }
430  else
431  {
432  cellId = lineOp->GetCellId();
433  if (cellId == -1)
434  return;
435  pId = lineOp->GetPIdA();
436  }
437 
438  bool ok;
439  CellAutoPointer cellAutoPointer;
440  ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
441  if (ok)
442  {
443  CellType *cell = cellAutoPointer.GetPointer();
444  if (cell->GetType() == CellType::POLYGON_CELL)
445  {
446  auto *oldPolygon = static_cast<PolygonType *>(cell);
447 
448  auto newPolygonCell = new PolygonType;
449  CellAutoPointer newCell;
450  newCell.TakeOwnership(newPolygonCell);
451 
452  PointIdConstIterator it, oldend;
453  oldend = oldPolygon->PointIdsEnd();
454  if (pId >= 0)
455  {
456  for (it = oldPolygon->PointIdsBegin(); it != oldend; ++it)
457  {
458  if ((*it) != (MeshType::PointIdentifier)pId)
459  {
460  newPolygonCell->AddPointId(*it);
461  }
462  }
463  }
464  else
465  {
466  --oldend;
467  for (it = oldPolygon->PointIdsBegin(); it != oldend; ++it)
468  newPolygonCell->AddPointId(*it);
469  }
470  oldPolygon->SetPointIds(0, newPolygonCell->GetNumberOfPoints(), newPolygonCell->PointIdsBegin());
471  }
472  }
473  }
474  break;
475 
476  case OpREMOVELINE:
477  // Remove the given Index in the given cell through copying everything
478  // into a new cell accept the one that has to be deleted.
479  {
480  auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
481  if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet
482  {
483  Superclass::ExecuteOperation(operation);
484  }
485 
486  bool ok;
487  CellAutoPointer cellAutoPointer;
488  int cellId = lineOp->GetCellId();
489  ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
490  if (!ok)
491  return;
492 
493  CellType *cell = cellAutoPointer.GetPointer();
494  CellAutoPointer newCellAutoPointer;
495  newCellAutoPointer.TakeOwnership(new PolygonType);
496  auto *newPolygon = static_cast<PolygonType *>(cell);
497 
498  PointIdIterator it = cell->PointIdsBegin();
499  PointIdIterator end = cell->PointIdsEnd();
500  int pointId = lineOp->GetPIdA();
501  if (pointId < 0) // if not initialized!!
502  return;
503 
504  while (it != end)
505  {
506  if ((*it) == (unsigned int)pointId)
507  {
508  break;
509  }
510  else
511  {
512  newPolygon->AddPointId(*it);
513  }
514  ++it;
515  }
516  while (it != end)
517  {
518  newPolygon->AddPointId(*it);
519  it++;
520  }
521  m_PointSetSeries[0]->SetCell(cellId, newCellAutoPointer);
522  }
523  break;
524 
525  case OpINSERTLINE:
526  // //insert line between two other points.
528  // //the points A, B and C have to be in the pointset.
529  // //needed: CellId, Id of C , Id A and Id B
531  //{
532  // mitk::LineOperation *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
533  // if (lineOp == nullptr)//if no lineoperation, then call superclass pointSet
534  // {
535  // Superclass::ExecuteOperation(operation);
536  // }
537  // int cellId = lineOp->GetCellId();
538  // int pIdC = lineOp->GetPIdC();
539  // int pIdA = lineOp->GetPIdA();
540  // int pIdB = lineOp->GetPIdB();
541 
542  // //the points of the given PointIds have to exist in the PointSet
543  // bool ok;
544  // ok = m_PointSetSeries[0]->GetPoints()->IndexExists(pIdA);
545  // if (!ok)
546  // return;
547  // ok = m_PointSetSeries[0]->GetPoints()->IndexExists(pIdB);
548  // if (!ok)
549  // return;
550  // ok = m_PointSetSeries[0]->GetPoints()->IndexExists(pIdC);
551  // if (!ok)
552  // return;
553 
554  // // so the points do exist. So now check, if there is already a cell
555  // // with the given Id
556  // DataType::CellAutoPointer cell;
557  // ok = m_PointSetSeries[0]->GetCell(cellId, cell);
558  // if (!ok)
559  // return;
560 
561  // //pIdA and pIdB should exist in the cell
562  //
563  // PointIdIterator pit = cell->PointIdsBegin();
564  // PointIdIterator end = cell->PointIdsEnd();
565  //
566  // //now arrange the new Ids in the cell like desired; pIdC between
567  // // pIdA and pIdB
568  // unsigned int nuPoints = cell->GetNumberOfPoints();
569 
570  // std::vector<unsigned int> newPoints;
571  // pit = cell->PointIdsBegin();
572  // end = cell->PointIdsEnd();
573  // int i = 0;
574  // while( pit != end )
575  // {
576  // if ((*pit) = pIdA)
577  // {
578  // //now we have found the place to add pIdC after
579  // newPoints[i] = (*pit);
580  // i++;
581  // newPoints[i] = pIdC;
582  // }
583  // else
584  // newPoints[i] = (*pit);
585  // pit++;
586  // }
587 
588  // //now we have the Ids, that existed before combined with the new ones
589  // //so delete the old cell
590  // //doesn't seem to be necessary!
591  // //cell->ClearPoints();
592  // pit = cell->PointIdsBegin();
593  // cell->SetPointIds(pit);
594  //}
595  break;
596 
597  case OpMOVELINE: //(moves two points)
598  {
599  auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
600 
601  if (lineOp == nullptr)
602  {
604  "Message from mitkMesh: Recieved wrong type of operation! See mitkMeshInteractor.cpp", 10000);
605  return;
606  }
607 
608  // create two operations out of the one operation and call superclass
609  // through the transmitted pointIds get the koordinates of the points.
610  // then add the transmitted vestor to them
611  // create two operations and send them to superclass
612  Point3D pointA, pointB;
613  pointA.Fill(0.0);
614  pointB.Fill(0.0);
615  m_PointSetSeries[0]->GetPoint(lineOp->GetPIdA(), &pointA);
616  m_PointSetSeries[0]->GetPoint(lineOp->GetPIdB(), &pointB);
617 
618  pointA[0] += lineOp->GetVector()[0];
619  pointA[1] += lineOp->GetVector()[1];
620  pointA[2] += lineOp->GetVector()[2];
621  pointB[0] += lineOp->GetVector()[0];
622  pointB[1] += lineOp->GetVector()[1];
623  pointB[2] += lineOp->GetVector()[2];
624 
625  auto operationA = new mitk::PointOperation(OpMOVE, pointA, lineOp->GetPIdA());
626  auto operationB = new mitk::PointOperation(OpMOVE, pointB, lineOp->GetPIdB());
627 
628  Superclass::ExecuteOperation(operationA);
629  Superclass::ExecuteOperation(operationB);
630  }
631  break;
632 
633  case OpSELECTLINE: //(select the given line)
634  {
635  auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
636  if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet
637  {
638  Superclass::ExecuteOperation(operation);
639  }
640  int cellId = lineOp->GetCellId();
641  CellAutoPointer cellAutoPointer;
642  bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
643  if (ok)
644  {
645  CellDataType cellData;
646  m_PointSetSeries[0]->GetCellData(cellId, &cellData);
647  SelectedLinesType *selectedLines = &(cellData.selectedLines);
648  auto position = std::find(selectedLines->begin(), selectedLines->end(), (unsigned int)lineOp->GetId());
649 
650  if (position == selectedLines->end()) // if not alsready selected
651  {
652  cellData.selectedLines.push_back(lineOp->GetId());
653  }
654  m_PointSetSeries[0]->SetCellData(lineOp->GetCellId(), cellData);
655  }
656  }
657  break;
658 
659  case OpDESELECTLINE: //(deselect the given line)
660  {
661  auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
662  if (lineOp == nullptr)
663  {
664  Superclass::ExecuteOperation(operation);
665  }
666  int cellId = lineOp->GetCellId();
667  CellAutoPointer cellAutoPointer;
668  bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
669  if (ok)
670  {
671  CellDataType cellData;
672  m_PointSetSeries[0]->GetCellData(cellId, &cellData);
673  SelectedLinesType *selectedLines = &(cellData.selectedLines);
674  auto position = std::find(selectedLines->begin(), selectedLines->end(), (unsigned int)lineOp->GetId());
675 
676  if (position != selectedLines->end()) // if found
677  {
678  selectedLines->erase(position);
679  }
680  m_PointSetSeries[0]->SetCellData(cellId, cellData);
681  }
682  }
683  break;
684 
685  case OpSELECTCELL: //(select the given cell)
686  {
687  auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
688  if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet
689  {
690  Superclass::ExecuteOperation(operation);
691  }
692 
693  int cellId = lineOp->GetCellId();
694  CellAutoPointer cellAutoPointer;
695 
696  // directly get the data!//TODO
697  bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
698  if (ok)
699  {
700  CellDataType cellData;
701  m_PointSetSeries[0]->GetCellData(cellId, &cellData);
702  cellData.selected = true;
703  m_PointSetSeries[0]->SetCellData(cellId, cellData);
704  }
705  }
706  break;
707 
708  case OpDESELECTCELL: //(deselect the given cell)
709  {
710  auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
711  if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet
712  {
713  Superclass::ExecuteOperation(operation);
714  }
715  int cellId = lineOp->GetCellId();
716  CellAutoPointer cellAutoPointer;
717  bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
718  if (ok)
719  {
720  CellDataType cellData;
721  m_PointSetSeries[0]->GetCellData(cellId, &cellData);
722  cellData.selected = false;
723  m_PointSetSeries[0]->SetCellData(cellId, cellData);
724  }
725  }
726  break;
727 
728  case OpMOVECELL:
729  // moves all Points of one cell according to the given vector
730  {
731  auto *lineOp = dynamic_cast<mitk::CellOperation *>(operation);
732  if (lineOp == nullptr) // if no celloperation, then call superclass pointSet
733  {
734  Superclass::ExecuteOperation(operation);
735  }
736 
737  int cellId = lineOp->GetCellId();
738  Vector3D vector = lineOp->GetVector();
739 
740  // get the cell
741  CellAutoPointer cellAutoPointer;
742  bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
743  if (!ok)
744  return;
745 
746  CellDataType cellData;
747  m_PointSetSeries[0]->GetCellData(cellId, &cellData);
748  // iterate through the pointIds of the CellData and move those points in
749  // the pointset
750  PointIdIterator it = cellAutoPointer->PointIdsBegin();
751  PointIdIterator end = cellAutoPointer->PointIdsEnd();
752  while (it != end)
753  {
754  unsigned int position = (*it);
755  PointType point;
756  point.Fill(0);
757  m_PointSetSeries[0]->GetPoint(position, &point);
758  point = point + vector;
759  m_PointSetSeries[0]->SetPoint(position, point);
760  ++it;
761  }
762  }
763  break;
764 
765  default:
766  // if the operation couldn't be handled here, then send it to superclass
767  Superclass::ExecuteOperation(operation);
768  return;
769  }
770  // to tell the mappers, that the data is modifierd and has to be updated
771  this->Modified();
772 
773  mitk::OperationEndEvent endevent(operation);
774  ((const itk::Object *)this)->InvokeEvent(endevent);
775 
776  // As discussed lately, don't mess with rendering from inside data structures
777  //*todo has to be done here, cause of update-pipeline not working yet
778  // mitk::RenderingManager::GetInstance()->RequestUpdateAll();
779 }
780 
782 {
783  // itk::CellInterface has also a GetBoundingBox, but it
784  // returns CoordRepType [PointDimension *2]
785  DataType::BoundingBoxPointer bBoxPointer = nullptr;
786  CellAutoPointer cellAutoPointer;
787  if (m_PointSetSeries[t]->GetCell(cellId, cellAutoPointer))
788  {
789  DataType::PointsContainerPointer pointsContainer = DataType::PointsContainer::New();
790  PointIdIterator bbIt = cellAutoPointer.GetPointer()->PointIdsBegin();
791  PointIdIterator bbEnd = cellAutoPointer.GetPointer()->PointIdsEnd();
792  while (bbIt != bbEnd)
793  {
795  bool pointOk = m_PointSetSeries[t]->GetPoint((*bbIt), &point);
796  if (pointOk)
797  pointsContainer->SetElement((*bbIt), point);
798  ++bbIt;
799  }
800  bBoxPointer = DataType::BoundingBoxType::New();
801  bBoxPointer->SetPoints(pointsContainer);
802  bBoxPointer->ComputeBoundingBox();
803  }
804  return bBoxPointer;
805 }
MeshType DataType
Definition: mitkPointSet.h:131
Descibes a line.
Definition: mitkLine.h:28
static char * line
Definition: svm.cpp:2870
void Expand(unsigned int timeSteps) override
Expands the TimeGeometry to a number of TimeSteps.
virtual bool GetPointIds(unsigned long cellId, unsigned long lineId, int &idA, int &idB, int t=0)
searches a line according to the cellId and lineId and returns the PointIds, that assign the line; if...
Definition: mitkMesh.cpp:201
int SearchPoint(Point3D point, ScalarType distance, int t=0) const
searches a point in the list == point +/- distance
DataType::CellDataContainerIterator CellDataIterator
Definition: mitkMesh.h:65
Base class of all Operation-classes.
Definition: mitkOperation.h:29
double ScalarType
CellTraits::PointIdConstIterator PointIdConstIterator
Definition: mitkMesh.h:62
virtual int SearchSelectedPoint(int t=0) const
searches a selected point and returns the id of that point. If no point is found, then -1 is returned...
Operation, that holds everything necessary for an operation on a line.
void SetMesh(DataType *mesh, int t=0)
Definition: mitkMesh.cpp:43
Constants for most interaction classes, due to the generic StateMachines.
PointSetSeries m_PointSetSeries
Definition: mitkPointSet.h:286
CellType::CellAutoPointer CellAutoPointer
Definition: mitkMesh.h:60
virtual unsigned long GetNumberOfCells(int t=0)
returns the current number of cells in the mesh
Definition: mitkMesh.cpp:49
std::vector< unsigned int > SelectedLinesType
cellDataType, that stores all indexes of the lines, that are selected e.g.: points A...
Definition: mitkPointSet.h:108
~Mesh() override
Definition: mitkMesh.cpp:29
virtual const DataType * GetMesh(int t=0) const
returns the mesh
Definition: mitkMesh.cpp:33
virtual DataType::BoundingBoxPointer GetBoundingBoxFromCell(unsigned long cellId, int t=0)
creates a BoundingBox and computes it with the given points of the cell.
Definition: mitkMesh.cpp:781
void DisplayText(const char *t)
Send a string to the applications StatusBar.
Operation that handles all actions on one Point.
SelectedLinesType selectedLines
Definition: mitkPointSet.h:116
void ExecuteOperation(Operation *operation) override
executes the given Operation
Definition: mitkMesh.cpp:251
itk::PolygonCell< CellType > PolygonType
Definition: mitkMesh.h:68
Operation, that holds everything necessary for an operation on a cell.
static StatusBar * GetInstance()
static method to get the GUI dependent StatusBar-instance so the methods DisplayText, etc. can be called No reference counting, cause of decentral static use!
virtual bool SearchLine(Point3D point, float distance, unsigned long &lineId, unsigned long &cellId, int t=0)
searches for a line, that is hit by the given point. Then returns the lineId and the cellId ...
Definition: mitkMesh.cpp:55
Superclass::DataType::CellsContainer::ConstIterator ConstCellIterator
Definition: mitkMesh.h:67
virtual int SearchSelectedCell(int t=0)
searches a selected cell and returns the id of that cell. If no cell is found, then -1 is returned ...
Definition: mitkMesh.cpp:183
virtual bool EvaluatePosition(Point3D point, unsigned long &cellId, float precision, int t=0)
checks if the given point is in a cell and returns that cellId. Basicaly it searches lines and points...
Definition: mitkMesh.cpp:150
PointsIterator Begin(int t=0)
unsigned long GetNewCellId(int t=0)
searches for the next new cellId and returns that id
Definition: mitkMesh.cpp:168
PointType GetPoint(PointIdentifier id, int t=0) const
Get the point with ID id in world coordinates.
virtual int SearchFirstCell(unsigned long pointId, int t=0)
returns the first cell that includes the given pointId
Definition: mitkMesh.cpp:128
OperationType GetOperationType()
CellTraits::PointIdIterator PointIdIterator
Definition: mitkMesh.h:63
BoundingBoxType::Pointer BoundingBoxPointer
Superclass::DataType::CellType CellType
Definition: mitkMesh.h:57