X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvLandmarks.cxx;h=0bab2f4305a8434023ffaa9751fdaf236f5f3fda;hb=f8f487135ec75a4a88e1d325cad6375313b59a29;hp=d9dfa65ed47f13b55eac96de6b1699c463817b33;hpb=3e42f6f79b50fb2eed087ea54aefb5c0fbd535c5;p=clitk.git diff --git a/vv/vvLandmarks.cxx b/vv/vvLandmarks.cxx index d9dfa65..0bab2f4 100644 --- a/vv/vvLandmarks.cxx +++ b/vv/vvLandmarks.cxx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,7 +14,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ======================================================================-====*/ + ===========================================================================**/ #include "vvLandmarks.h" #include @@ -41,6 +41,8 @@ vvLandmarks::vvLandmarks(int size) } mPolyData = vtkPolyData::New(); mIds = vtkFloatArray::New(); + mLabels = vtkStringArray::New(); + mLabels->SetName("labels"); } //-------------------------------------------------------------------- @@ -58,6 +60,8 @@ vvLandmarks::~vvLandmarks() mIds->Delete(); if (mPolyData) mPolyData->Delete(); + if (mLabels) + mLabels->Delete(); } //-------------------------------------------------------------------- @@ -66,20 +70,31 @@ vvLandmarks::~vvLandmarks() void vvLandmarks::AddLandmark(float x,float y,float z,float t,double value) { vvLandmark point; + vtkIdType idPoint; point.coordinates[0] = x; point.coordinates[1] = y; point.coordinates[2] = z; point.coordinates[3] = t; point.pixel_value=value; mLandmarks.push_back(point); - mPoints[int(t)]->InsertNextPoint(x,y,z); - - /*std::stringstream numberVal; - numberVal << (mLandmarks.size()-1); - vvLandmarksGlyph *number = vvLandmarksGlyph::New(); - number->SetText(numberVal.str().c_str()); - number->BackingOff(); - mText.push_back(number);*/ + + idPoint = mPoints[int(t)]->InsertNextPoint(x,y,z); + std::string str_vtkIdType; // string which will contain the result + std::ostringstream convert; // stream used for the conversion + convert << idPoint; // insert the textual representation of 'idPoint' in the characters in the stream + str_vtkIdType = convert.str(); // set 'str_vtkIdType' to the contents of the stream + mLabels->InsertNextValue(str_vtkIdType.c_str()); + + std::stringstream numberVal; + numberVal << (mLandmarks.size()-1); + /* + vvLandmarksGlyph *number = vvLandmarksGlyph::New(); + number->SetText(numberVal.str().c_str()); + number->BackingOff(); + DD(numberVal.str().c_str()); + mText.push_back(number); + */ + mIds->InsertNextTuple1(0.55); //mIds->InsertTuple1(mLandmarks.size(),mLandmarks.size()); SetTime(int(t)); @@ -92,10 +107,39 @@ void vvLandmarks::RemoveLastLandmark() { mPoints[mLandmarks.back().coordinates[3]]->SetNumberOfPoints( mPoints[mLandmarks.back().coordinates[3]]->GetNumberOfPoints()-1); - mPolyData->Modified(); - //mText.pop_back(); + // mText.pop_back(); mLandmarks.pop_back(); mIds->RemoveLastTuple(); + mLabels->SetNumberOfValues(mLabels->GetNumberOfValues()-1); + mLabels->Modified(); + mPolyData->Modified(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void vvLandmarks::RemoveLandmark(int index) +{ + // erase a vtkPoint by shifiting the array . + // not a problem here because there are no + // pologyons linking the points + int npoints = mPoints[mLandmarks[index].coordinates[3]]->GetNumberOfPoints(); + int t = mLandmarks[index].coordinates[3]; + 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->SetValue(i,str_i.c_str()); + } + mPoints[t]->SetNumberOfPoints(npoints-1); + mLabels->SetNumberOfValues(npoints-1); + mLabels->Modified(); + mPolyData->Modified(); + + mLandmarks.erase(mLandmarks.begin() + index); + mIds->RemoveLastTuple(); } //-------------------------------------------------------------------- @@ -142,6 +186,7 @@ void vvLandmarks::LoadFile(std::string filename) } mFilename = filename; mLandmarks.clear(); + vtkIdType idPoint; char line[255]; for (unsigned int i = 0; i < mPoints.size(); i++) mPoints[i]->SetNumberOfPoints(0); @@ -223,8 +268,13 @@ void vvLandmarks::LoadFile(std::string filename) // DD(point.comments); mLandmarks.push_back(point); mIds->InsertNextTuple1(0.55); - mPoints[int(point.coordinates[3])]->InsertNextPoint( + idPoint = mPoints[int(point.coordinates[3])]->InsertNextPoint( point.coordinates[0],point.coordinates[1],point.coordinates[2]); + std::string str_vtkIdType; // string which will contain the result + std::ostringstream convert; // stream used for the conversion + convert << idPoint; // insert the textual representation of 'idPoint' in the characters in the stream + str_vtkIdType = convert.str(); // set 'str_vtkIdType' to the contents of the stream + mLabels->InsertNextValue(str_vtkIdType.c_str()); } } SetTime(0); @@ -278,6 +328,7 @@ void vvLandmarks::SetTime(int time) if (time >= 0 && time <= ((int)mPoints.size() -1)) { mPolyData->SetPoints(mPoints[time]); mPolyData->GetPointData()->SetScalars(mIds); + mPolyData->GetPointData()->AddArray(mLabels); mPolyData->Modified(); mPolyData->Update(); }