MCPcopy Create free account
hub / github.com/MITK/MITK / AddPoint

Method AddPoint

Modules/Core/src/Interactions/mitkPointSetDataInteractor.cpp:44–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44void 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)

Callers 15

UpdateSplineMethod · 0.45
OnDeltaLevelWindowMethod · 0.45
OnDeltaThresholdMethod · 0.45
AddFunctionPointFunction · 0.45
RemoveAllFunctionPointsFunction · 0.45
TransferFunctionMethod · 0.45
AddScalarOpacityPointMethod · 0.45
InitializeByMitkImageMethod · 0.45
SetCtDefaultModeMethod · 0.45
SetCtBlackWhiteModeMethod · 0.45
SetCtThoraxLargeModeMethod · 0.45

Calls 15

UnselectAllMethod · 0.95
GetSenderMethod · 0.80
GetTimeMethod · 0.80
GetPositionInWorldMethod · 0.80
IsNotNullMethod · 0.80
IndexExistsMethod · 0.80
NotifyResultReadyMethod · 0.80
QueueEventMethod · 0.80
GetPointerMethod · 0.80
NewFunction · 0.50
GetTimeStepMethod · 0.45
GetDataMethod · 0.45

Tested by

no test coverage detected