]> Creatis software - clitk.git/blobdiff - vv/vvLandmarks.cxx
Add histogram tool
[clitk.git] / vv / vvLandmarks.cxx
index 0b5f98a264886c6b11bad1e6a0a488d1557511cd..dc38cd228f69b27981960e24b220bf3fafa5c4eb 100644 (file)
@@ -23,6 +23,7 @@
 #include <string>
 #include <locale.h>
 
+#include <vtkVersion.h>
 #include "vtkPolyData.h"
 #include "vtkPoints.h"
 #include "vtkFloatArray.h"
@@ -117,6 +118,41 @@ void vvLandmarks::RemoveLastLandmark()
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+void vvLandmarks::RemoveLandmarkWithLabel(vtkStdString label, int time)
+{
+  if (label != "P1" && label != "P2")
+    return;
+  // erase a vtkPoint by shifiting the array .
+  // not a problem here because there are no 
+  // pologyons linking the points
+  int t = time;//mLandmarks[index].coordinates[3];
+  int npoints = mPoints[t]->GetNumberOfPoints();
+  
+  //search of the index corresponding to the label
+  int index(0);
+  while (mLabels[t]->GetValue(index) != label)
+    ++index;
+  
+  for (int i = index; i < npoints - 1; i++) {
+    mPoints[t]->InsertPoint(i, mPoints[t]->GetPoint(i+1));
+       std::string str_i;                   // string which will contain the result
+       std::ostringstream convert;      // stream used for the conversion
+       convert << i;                        // insert the textual representation of 'i' in the characters in the stream
+       str_i = convert.str();           // set 'str_i' to the contents of the stream
+       mLabels[t]->SetValue(i,mLabels[t]->GetValue(i+1));
+    }
+  mPoints[t]->SetNumberOfPoints(npoints-1);
+  mLabels[t]->SetNumberOfValues(npoints-1);
+  mLabels[t]->Modified();
+  mPolyData->Modified();
+
+  mLandmarks[t].erase(mLandmarks[t].begin() + index);
+  mIds[t]->RemoveLastTuple();
+}
+//--------------------------------------------------------------------
+
+
 //--------------------------------------------------------------------
 void vvLandmarks::RemoveLandmark(int index)
 {
@@ -143,6 +179,17 @@ void vvLandmarks::RemoveLandmark(int index)
 }
 //--------------------------------------------------------------------
 
+//--------------------------------------------------------------------
+void vvLandmarks::RemoveAll()
+{
+  for (unsigned int i = 0; i < mLandmarks.size(); i++) {
+    mLandmarks[i].clear();
+    mPoints[i]->SetNumberOfPoints(0);
+    mLabels[i]->SetNumberOfValues(0);
+    mIds[i]->SetNumberOfValues(0);
+  }
+}
+//--------------------------------------------------------------------
 
 //--------------------------------------------------------------------
 void vvLandmarks::ChangeComments(int index, std::string comments)
@@ -440,7 +487,11 @@ void vvLandmarks::SetTime(int time)
     mPolyData->GetPointData()->SetScalars(mIds[time]);
     mPolyData->GetPointData()->AddArray(mLabels[time]);
     mPolyData->Modified();
+#if VTK_MAJOR_VERSION <= 5
     mPolyData->Update();
+#else
+    //mPolyData->Update();
+#endif
     mTime = time;
   }
 }