#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());
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
}
//--------------------------------------------------------------------
+//--------------------------------------------------------------------
+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()
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();
//--------------------------------------------------------------------
+//--------------------------------------------------------------------
+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)
{
mPolyData->Modified();
mLandmarks[t].erase(mLandmarks[t].begin() + index);
+ mLandmarksInitial[t].erase(mLandmarksInitial[t].begin() + index);
mIds[t]->RemoveLastTuple();
}
//--------------------------------------------------------------------
+//--------------------------------------------------------------------
+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);
+ }
+}
+//--------------------------------------------------------------------
//--------------------------------------------------------------------
void vvLandmarks::ChangeComments(int index, std::string comments)
{
mLandmarks[mTime][index].comments = comments;
+ mLandmarksInitial[mTime][index].comments = comments;
}
//--------------------------------------------------------------------
mFilenames = filenames;
for (unsigned int i = 0; i < mPoints.size(); i++) {
mLandmarks[i].clear();
+ mLandmarksInitial[i].clear();
mPoints[i]->SetNumberOfPoints(0);
}
}
// 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]);
for (unsigned int i = 0; i < mPoints.size(); i++) {
mPoints[i]->SetNumberOfPoints(0);
mLandmarks[i].clear();
+ mLandmarksInitial[i].clear();
}
int err = 0;
// 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]);
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";
}
}
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;
}
}