]> Creatis software - clitk.git/blobdiff - vv/vvLandmarks.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvLandmarks.cxx
index fed697ebc2a218943ac125b4676e15ac1f3afd70..528669d0768977144760d2e8e77895087e186f22 100644 (file)
@@ -23,6 +23,7 @@
 #include <string>
 #include <locale.h>
 
+#include <vtkVersion.h>
 #include "vtkPolyData.h"
 #include "vtkPoints.h"
 #include "vtkFloatArray.h"
 vvLandmarks::vvLandmarks(int size)
 {
   mLandmarks.resize(size);
+  mLandmarksInitial.resize(size);
   mFilenames.resize(0);
   mTime = 0;
 
   for (int i = 0; i < size; i++) {
     mLandmarks[i].resize(0);
+    mLandmarksInitial[i].resize(0);
     vtkPoints *points = vtkPoints::New();
     mPoints.push_back(points);
     mIds.push_back(vtkFloatArray::New());
@@ -78,6 +81,7 @@ void vvLandmarks::AddLandmark(float x,float y,float z,float t,double value)
   point.coordinates[3] = t;
   point.pixel_value=value;
   mLandmarks[mTime].push_back(point);
+  mLandmarksInitial[mTime].push_back(point);
 
   idPoint = mPoints[int(t)]->InsertNextPoint(x,y,z);
   std::string str_vtkIdType;       // string which will contain the result
@@ -102,6 +106,27 @@ void vvLandmarks::AddLandmark(float x,float y,float z,float t,double value)
 }
 //--------------------------------------------------------------------
 
+//--------------------------------------------------------------------
+void vvLandmarks::TransformUpdate(vtkAbstractTransform* transform)
+{
+  //For all Time, For all landmarks, I apply the transform
+  for(int time=0; time<mLandmarks.size(); ++time)
+  {
+    for(int landmark=0; landmark<mLandmarks[time].size(); ++landmark)
+    {
+      double ptBeforeTransform[3], ptAfterTransform[3];
+      ptBeforeTransform[0]= mLandmarksInitial[time][landmark].coordinates[0];
+      ptBeforeTransform[1]= mLandmarksInitial[time][landmark].coordinates[1];
+      ptBeforeTransform[2]= mLandmarksInitial[time][landmark].coordinates[2];
+      transform->TransformPoint(ptBeforeTransform, ptAfterTransform);
+
+      mLandmarks[time][landmark].coordinates[0]= ptAfterTransform[0];
+      mLandmarks[time][landmark].coordinates[1]= ptAfterTransform[1];
+      mLandmarks[time][landmark].coordinates[2]= ptAfterTransform[2];
+    }
+  }
+}
+//--------------------------------------------------------------------
 
 //--------------------------------------------------------------------
 void vvLandmarks::RemoveLastLandmark()
@@ -109,6 +134,7 @@ void vvLandmarks::RemoveLastLandmark()
   mPoints[mTime]->SetNumberOfPoints(mPoints[mTime]->GetNumberOfPoints()-1);
   //  mText.pop_back();
   mLandmarks[mTime].pop_back();
+  mLandmarksInitial[mTime].pop_back();
   mIds[mTime]->RemoveLastTuple();
   mLabels[mTime]->SetNumberOfValues(mLabels[mTime]->GetNumberOfValues()-1);
   mLabels[mTime]->Modified();
@@ -117,6 +143,42 @@ 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);
+  mLandmarksInitial[t].erase(mLandmarksInitial[t].begin() + index);
+  mIds[t]->RemoveLastTuple();
+}
+//--------------------------------------------------------------------
+
+
 //--------------------------------------------------------------------
 void vvLandmarks::RemoveLandmark(int index)
 {
@@ -139,6 +201,7 @@ void vvLandmarks::RemoveLandmark(int index)
   mPolyData->Modified();
 
   mLandmarks[t].erase(mLandmarks[t].begin() + index);
+  mLandmarksInitial[t].erase(mLandmarksInitial[t].begin() + index);
   mIds[t]->RemoveLastTuple();
 }
 //--------------------------------------------------------------------
@@ -148,6 +211,7 @@ void vvLandmarks::RemoveAll()
 {
   for (unsigned int i = 0; i < mLandmarks.size(); i++) {
     mLandmarks[i].clear();
+    mLandmarksInitial[i].clear();
     mPoints[i]->SetNumberOfPoints(0);
     mLabels[i]->SetNumberOfValues(0);
     mIds[i]->SetNumberOfValues(0);
@@ -159,6 +223,7 @@ void vvLandmarks::RemoveAll()
 void vvLandmarks::ChangeComments(int index, std::string comments)
 {
   mLandmarks[mTime][index].comments = comments;
+  mLandmarksInitial[mTime][index].comments = comments;
 }
 //--------------------------------------------------------------------
 
@@ -206,6 +271,7 @@ bool vvLandmarks::LoadTxtFile(std::vector<std::string> filenames)
   mFilenames = filenames;
   for (unsigned int i = 0; i < mPoints.size(); i++) {
     mLandmarks[i].clear();
+    mLandmarksInitial[i].clear();
     mPoints[i]->SetNumberOfPoints(0);
   }
 
@@ -297,6 +363,7 @@ bool vvLandmarks::LoadTxtFile(std::vector<std::string> filenames)
         }
         //      DD(point.comments);
         mLandmarks[int(point.coordinates[3])].push_back(point);
+        mLandmarksInitial[int(point.coordinates[3])].push_back(point);
         mIds[int(point.coordinates[3])]->InsertNextTuple1(0.55);
         idPoint = mPoints[int(point.coordinates[3])]->InsertNextPoint(
                                                             point.coordinates[0],point.coordinates[1],point.coordinates[2]);
@@ -325,6 +392,7 @@ bool vvLandmarks::LoadPtsFile(std::vector<std::string> filenames)
   for (unsigned int i = 0; i < mPoints.size(); i++) {
     mPoints[i]->SetNumberOfPoints(0);
     mLandmarks[i].clear();
+    mLandmarksInitial[i].clear();
   }
 
   int err = 0;
@@ -379,6 +447,7 @@ bool vvLandmarks::LoadPtsFile(std::vector<std::string> filenames)
 
         //      DD(point.comments);
         mLandmarks[int(point.coordinates[3])].push_back(point);
+        mLandmarksInitial[int(point.coordinates[3])].push_back(point);
         mIds[int(point.coordinates[3])]->InsertNextTuple1(0.55);
         idPoint = mPoints[int(point.coordinates[3])]->InsertNextPoint(
                                                             point.coordinates[0],point.coordinates[1],point.coordinates[2]);
@@ -419,16 +488,16 @@ void vvLandmarks::SaveFile(std::string filename)
       std::stringstream out;
       out.imbue(std::locale("C")); //This is to specify that the dot is to be used as the decimal separator
       out << i << " "
-          << mLandmarks[t][i].coordinates[0] << " "
-          << mLandmarks[t][i].coordinates[1] << " "
-          << mLandmarks[t][i].coordinates[2] << " "
-          << mLandmarks[t][i].coordinates[3] << " "
-          << mLandmarks[t][i].pixel_value << " ";
+          << mLandmarksInitial[t][i].coordinates[0] << " "
+          << mLandmarksInitial[t][i].coordinates[1] << " "
+          << mLandmarksInitial[t][i].coordinates[2] << " "
+          << mLandmarksInitial[t][i].coordinates[3] << " "
+          << mLandmarksInitial[t][i].pixel_value << " ";
       fileContent += out.str();
-      if (mLandmarks[t][i].comments.size() == 0)
+      if (mLandmarksInitial[t][i].comments.size() == 0)
         fileContent += " ";
       else
-        fileContent += mLandmarks[t][i].comments;
+        fileContent += mLandmarksInitial[t][i].comments;
       fileContent += "\n";
     }
   }
@@ -451,7 +520,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;
   }
 }