| 42 | } |
| 43 | |
| 44 | void mitk::PointSetDataInteractor::AddPoint(StateMachineAction *stateMachineAction, InteractionEvent *interactionEvent) |
| 45 | { |
| 46 | unsigned int timeStep = interactionEvent->GetSender()->GetTimeStep(GetDataNode()->GetData()); |
| 47 | ScalarType timeInMs = interactionEvent->GetSender()->GetTime(); |
| 48 | |
| 49 | // disallow adding of new points if maximum number of points is reached |
| 50 | if (m_MaxNumberOfPoints > 1 && m_PointSet->GetSize(timeStep) >= m_MaxNumberOfPoints) |
| 51 | { |
| 52 | return; |
| 53 | } |
| 54 | // To add a point the minimal information is the position, this method accepts all InteractionsPositionEvents |
| 55 | auto *positionEvent = dynamic_cast<InteractionPositionEvent *>(interactionEvent); |
| 56 | if (positionEvent != nullptr) |
| 57 | { |
| 58 | mitk::Point3D itkPoint = positionEvent->GetPositionInWorld(); |
| 59 | |
| 60 | if (m_Bounds.IsNotNull()) |
| 61 | { |
| 62 | if (!m_Bounds->IsInside(itkPoint)) |
| 63 | return; // Disallow adding new points outside of the required bounds. |
| 64 | } |
| 65 | |
| 66 | this->UnselectAll(timeStep, timeInMs); |
| 67 | |
| 68 | int lastPosition = 0; |
| 69 | mitk::PointSet::PointsIterator it, end; |
| 70 | it = m_PointSet->Begin(timeStep); |
| 71 | end = m_PointSet->End(timeStep); |
| 72 | while (it != end) |
| 73 | { |
| 74 | if (!m_PointSet->IndexExists(lastPosition, timeStep)) |
| 75 | break; |
| 76 | ++it; |
| 77 | ++lastPosition; |
| 78 | } |
| 79 | |
| 80 | // Insert a Point to the PointSet |
| 81 | // 2) Create the Operation inserting the point |
| 82 | if (m_PointSet->IsEmpty()) { lastPosition = 0; } |
| 83 | auto *doOp = new mitk::PointOperation(OpINSERT, timeInMs, itkPoint, lastPosition); |
| 84 | |
| 85 | // 3) If Undo is enabled, also create the inverse Operation |
| 86 | if (m_UndoEnabled) |
| 87 | { |
| 88 | auto *undoOp = new mitk::PointOperation(OpREMOVE, timeInMs, itkPoint, lastPosition); |
| 89 | // 4) Do and Undo Operations are combined in an Operation event which also contains the target of the operations |
| 90 | // (here m_PointSet) |
| 91 | OperationEvent *operationEvent = new OperationEvent(m_PointSet, doOp, undoOp, "Add point"); |
| 92 | // 5) Store the Operation in the UndoController |
| 93 | OperationEvent::IncCurrObjectEventId(); |
| 94 | m_UndoController->SetOperationEvent(operationEvent); |
| 95 | } |
| 96 | |
| 97 | // 6) Execute the Operation performs the actual insertion of the point into the PointSet |
| 98 | m_PointSet->ExecuteOperation(doOp); |
| 99 | |
| 100 | // 7) If Undo is not enabled the Do-Operation is to be dropped to prevent memory leaks. |
| 101 | if (!m_UndoEnabled) |
no test coverage detected