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