Skip to content

Commit 4cc212a

Browse files
committed
ENH: Markups: Add RemovePointFromNthMarkup function
git-svn-id: http://svn.slicer.org/Slicer4/trunk@27947 3bd1e089-480b-0410-8dfb-8563597acbee
1 parent a3cb767 commit 4cc212a

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

Modules/Loadable/Markups/MRML/vtkMRMLMarkupsNode.cxx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,24 @@ int vtkMRMLMarkupsNode::AddPointToNthMarkup(vtkVector3d point, int n)
553553
return pointIndex;
554554
}
555555

556+
//-----------------------------------------------------------
557+
bool vtkMRMLMarkupsNode::RemovePointFromNthMarkup(int pointIndex, int n)
558+
{
559+
if (!this->MarkupExists(n))
560+
{
561+
return false;
562+
}
563+
if (pointIndex < 0 || pointIndex >= static_cast<int>(this->Markups[n].points.size()))
564+
{
565+
return false;
566+
}
567+
this->Markups[n].points.erase(this->Markups[n].points.begin() + pointIndex);
568+
int markupIndex = n;
569+
this->InvokeCustomModifiedEvent(
570+
vtkMRMLMarkupsNode::NthMarkupModifiedEvent, (void*)&markupIndex);
571+
return true;
572+
}
573+
556574
//-----------------------------------------------------------
557575
vtkVector3d vtkMRMLMarkupsNode::GetMarkupPointVector(int markupIndex, int pointIndex)
558576
{

Modules/Loadable/Markups/MRML/vtkMRMLMarkupsNode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ class VTK_SLICER_MARKUPS_MODULE_MRML_EXPORT vtkMRMLMarkupsNode : public vtkMRML
193193
int AddPointWorldToNewMarkup(vtkVector3d point, std::string label = std::string());
194194
/// Add a point to the nth markup, returning the point index, -1 on failure.
195195
int AddPointToNthMarkup(vtkVector3d point, int n);
196+
/// Remove a point from nth markup, returning true on success.
197+
bool RemovePointFromNthMarkup(int pointIndex, int n);
196198

197199
/// Get the position of the pointIndex'th point in markupIndex markup,
198200
/// returning it as a vtkVector3d

Modules/Loadable/Markups/Testing/Cxx/vtkMRMLMarkupsNodeTest1.cxx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ int vtkMRMLMarkupsNodeTest1(int , char * [] )
221221
// now add some markups
222222
//
223223
std::cout << "Adding markups with points" << std::endl;
224-
node1->AddMarkupWithNPoints(1);
225-
node1->AddMarkupWithNPoints(2);
226-
node1->AddMarkupWithNPoints(3);
227-
node1->AddMarkupWithNPoints(6);
224+
node1->AddMarkupWithNPoints(1); // markupIndex 0
225+
node1->AddMarkupWithNPoints(2); // markupIndex 1
226+
node1->AddMarkupWithNPoints(3); // markupIndex 2
227+
node1->AddMarkupWithNPoints(6); // markupIndex 3
228228

229229
numMarkups = node1->GetNumberOfMarkups();
230230
if (numMarkups != 4)
@@ -548,5 +548,37 @@ int vtkMRMLMarkupsNodeTest1(int , char * [] )
548548
return EXIT_FAILURE;
549549
}
550550

551+
// Test RemovePointFromNthMarkup
552+
std::cout << "Test RemovePointFromNthMarkup" << std::endl;
553+
int markupIndex = 2;
554+
555+
{
556+
double point0[3] = {0.0, 0.1, 0.2};
557+
node1->SetMarkupPointFromArray(markupIndex, 0, point0);
558+
double point1[3] = {1.0, 1.1, 1.2};
559+
node1->SetMarkupPointFromArray(markupIndex, 1, point1);
560+
double point2[3] = {2.0, 2.1, 2.2};
561+
node1->SetMarkupPointFromArray(markupIndex, 2, point2);
562+
563+
CHECK_INT(node1->GetNumberOfPointsInNthMarkup(markupIndex), 3);
564+
}
565+
566+
node1->RemovePointFromNthMarkup(1, markupIndex);
567+
CHECK_INT(node1->GetNumberOfPointsInNthMarkup(markupIndex), 2);
568+
569+
{
570+
double point0[3] = {0., 0., 0.};
571+
node1->GetMarkupPoint(markupIndex, 0, point0);
572+
CHECK_DOUBLE(point0[0], 0.0);
573+
CHECK_DOUBLE(point0[1], 0.1);
574+
CHECK_DOUBLE(point0[2], 0.2);
575+
576+
double point1[3] = {0., 0., 0.};
577+
node1->GetMarkupPoint(markupIndex, 1, point1);
578+
CHECK_DOUBLE(point1[0], 2.0);
579+
CHECK_DOUBLE(point1[1], 2.1);
580+
CHECK_DOUBLE(point1[2], 2.2);
581+
}
582+
551583
return EXIT_SUCCESS;
552584
}

0 commit comments

Comments
 (0)