]> Creatis software - clitk.git/commitdiff
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
authorRomulo Pinho <romulo.pinho@lyon.unicancer.fr>
Thu, 6 Dec 2012 13:02:11 +0000 (14:02 +0100)
committerRomulo Pinho <romulo.pinho@lyon.unicancer.fr>
Thu, 6 Dec 2012 13:02:11 +0000 (14:02 +0100)
vv/vv.cxx
vv/vvLandmarks.cxx
vv/vvLandmarks.h
vv/vvLandmarksPanel.cxx
vv/vvLandmarksPanel.h
vv/vvMainWindow.cxx
vv/vvMainWindow.h

index 47057e4a0ed335cc3720cec279c5ffcfab6f9c29..d4ef1eac3e629e8d60a816b9aa984e246759d6c7 100644 (file)
--- a/vv/vv.cxx
+++ b/vv/vv.cxx
@@ -45,7 +45,7 @@
 #include <sys/stat.h>
 #include <errno.h>
 
-typedef enum {O_BASE,O_OVERLAY,O_FUSION,O_VF,O_CONTOUR} OpenModeType;
+typedef enum {O_BASE,O_OVERLAY,O_FUSION,O_VF,O_CONTOUR,O_LANDMARKS} OpenModeType;
 typedef enum {P_NORMAL,P_SEQUENCE,P_WINDOW,P_LEVEL} ParseModeType;
 
 void load_image_first_error()
@@ -195,6 +195,9 @@ int main( int argc, char** argv )
         } else if (current=="--fusion") {
           if (!n_image_loaded) load_image_first_error();
           open_mode = O_FUSION;
+        } else if (current=="--landmarks") {
+          if (!n_image_loaded) load_image_first_error();
+          open_mode = O_LANDMARKS;
         } else if (current == "--sequence") {
           if(open_mode==O_BASE) n_image_loaded++; //count only one for the whole sequence
           parse_mode=P_SEQUENCE;
@@ -273,6 +276,8 @@ int main( int argc, char** argv )
           window.AddDCStructContour(n_image_loaded-1,current.c_str());
         else if (open_mode==O_FUSION)
           window.AddFusionImage(n_image_loaded-1,current.c_str());
+        else if (open_mode==O_LANDMARKS)
+          window.AddLandmarks(n_image_loaded-1,current.c_str());
         open_mode = O_BASE;
       }
     }
index 0bab2f4305a8434023ffaa9751fdaf236f5f3fda..94fb9756b93918ca20349a1eb1ce96baf6b35406 100644 (file)
@@ -28,6 +28,7 @@
 #include "vtkFloatArray.h"
 #include "vtkPointData.h"
 #include "clitkCommon.h"
+#include <itksys/SystemTools.hxx>
 
 //--------------------------------------------------------------------
 vvLandmarks::vvLandmarks(int size)
@@ -177,12 +178,24 @@ std::string vvLandmarks::GetComments(int index)
 
 
 //--------------------------------------------------------------------
-void vvLandmarks::LoadFile(std::string filename)
+bool vvLandmarks::LoadFile(std::string filename)
+{
+  std::string extension = itksys::SystemTools::GetFilenameExtension(filename);
+  if (extension == ".txt")
+    return LoadTxtFile(filename);
+  else if (extension == ".pts")
+    return LoadPtsFile(filename);
+
+  return false;
+}
+
+//--------------------------------------------------------------------
+bool vvLandmarks::LoadTxtFile(std::string filename)
 {
   std::ifstream fp(filename.c_str(), std::ios::in|std::ios::binary);
   if (!fp.is_open()) {
     std::cerr <<"Unable to open file " << filename << std::endl;
-    return;
+    return false;
   }
   mFilename = filename;
   mLandmarks.clear();
@@ -278,9 +291,102 @@ void vvLandmarks::LoadFile(std::string filename)
     }
   }
   SetTime(0);
+  
+  return true;
 }
 //--------------------------------------------------------------------
 
+//--------------------------------------------------------------------
+bool vvLandmarks::LoadPtsFile(std::string filename)
+{
+  std::ifstream fp(filename.c_str(), std::ios::in|std::ios::binary);
+  if (!fp.is_open()) {
+    std::cerr <<"Unable to open file " << filename << std::endl;
+    return false;
+  }
+  mFilename = filename;
+  mLandmarks.clear();
+  vtkIdType idPoint;
+  char line[255];
+  for (unsigned int i = 0; i < mPoints.size(); i++)
+    mPoints[i]->SetNumberOfPoints(0);
+  bool first_line=true;
+  while (fp.getline(line,255)) {
+    //    DD(line);
+    std::string stringline = line;
+    if (stringline.size() > 1) {
+      vvLandmark point;
+      int previousSpace = 0;
+      int space=0;
+      
+      if (stringline[0] == '#') // comments
+        continue;
+      
+      space = stringline.find("\t", previousSpace+1);
+      if (space < -1 || space > (int)stringline.size()) {
+        ErrorMsg(mLandmarks.size(),"x position");
+        continue;
+      }
+      point.coordinates[0] = atof(replace_dots(stringline.substr(previousSpace,space - previousSpace)).c_str());
+      //      DD(point.coordinates[0]);
+      previousSpace = space;
+      space = stringline.find("\t", previousSpace+1);
+      if (space < -1 || space > (int)stringline.size()) {
+        ErrorMsg(mLandmarks.size(),"y position");
+        continue;
+      }
+      point.coordinates[1] = atof(replace_dots(stringline.substr(previousSpace,space - previousSpace)).c_str());
+      //      DD(point.coordinates[1]);
+      previousSpace = space;
+      space = stringline.find("\t", previousSpace+1);
+      if (space < -1 || space > (int)stringline.size()) {
+        ErrorMsg(mLandmarks.size(),"z position");
+        continue;
+      }
+      point.coordinates[2] = atof(replace_dots(stringline.substr(previousSpace,space - previousSpace)).c_str());
+      previousSpace = space;
+      if (mFormatVersion>0) {
+        space = stringline.find("\t", previousSpace+1);
+        if (space < -1 || space > (int)stringline.size()) {
+          ErrorMsg(mLandmarks.size(),"t position");
+          continue;
+        }
+        point.coordinates[3] = atof(replace_dots(stringline.substr(previousSpace,space - previousSpace)).c_str());
+        previousSpace = space;
+        space = stringline.find("\t", previousSpace+1);
+        if (space < -1 || space > (int)stringline.size()) {
+          ErrorMsg(mLandmarks.size(),"pixel value");
+          continue;
+        }
+        point.pixel_value = atof(replace_dots(stringline.substr(previousSpace,space - previousSpace)).c_str());
+        //        DD(point.pixel_value);
+      } else {
+        point.pixel_value=0.; //Not in file
+        point.coordinates[3]=0.;
+      }
+      previousSpace = space;
+      //this is the maximum size of comments
+      space = (stringline.find("\n", previousSpace+1) < 254 ? stringline.find("\n", previousSpace+1) : 254);
+      if (previousSpace != -1) {
+        point.comments = stringline.substr(previousSpace,space - (previousSpace)).c_str();
+      }
+      //      DD(point.comments);
+      mLandmarks.push_back(point);
+      mIds->InsertNextTuple1(0.55);
+     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);
+  
+  return true;
+}
+//--------------------------------------------------------------------
 
 //--------------------------------------------------------------------
 bool vvLandmarks::ErrorMsg(int num,const char * text)
index 8f9471729d92462a0145f78e4ee95c92b0aca3c4..0abaf61ff13440334c4d04e34dd0d10a5275cfe1 100644 (file)
@@ -39,7 +39,7 @@ public :
     vvLandmarks(int size);
     ~vvLandmarks();
 
-    void LoadFile(std::string filename);
+    bool LoadFile(std::string filename);
     void SaveFile(std::string filename);
 
     void AddLandmark(float x,float y,float z,float t,double value);
@@ -71,6 +71,10 @@ private:
     vtkStringArray* mLabels;
     std::string mFilename;
     int mFormatVersion;
+
+    bool LoadTxtFile(std::string filename);
+    bool LoadPtsFile(std::string filename);
+  
 };
 
 #endif
index 7fb80276ad5c8f6bbfb6642b76cdc45f9cc46680..46c7c0e80b12ddded4dd20da624208e50b950bcc 100644 (file)
@@ -46,9 +46,14 @@ vvLandmarksPanel::vvLandmarksPanel(QWidget * parent):QWidget(parent)
 void vvLandmarksPanel::Load()
 {
   QString file = QFileDialog::getOpenFileName(this,tr("Load Landmarks"),
-                 mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
+                 mCurrentPath.c_str(),tr("Landmarks ( *.txt *.pts)"));
   if (!file.isEmpty())
-    mCurrentLandmarks->LoadFile(file.toStdString());
+    LoadFromFile(file.toStdString());
+}
+
+void vvLandmarksPanel::LoadFromFile(std::string file)
+{
+  mCurrentLandmarks->LoadFile(file);
   SetCurrentLandmarks(mCurrentLandmarks,2);
   emit UpdateRenderWindows();
 }
index 9966d8820f6672802e8e597d5795c03ac1847c6a..d352a9a0f1077f99ac833292305d39c10c44d1ec 100644 (file)
@@ -41,6 +41,7 @@ public:
 
 public slots:
     void Load();
+    void LoadFromFile(std::string file);
     void Save();
     void RemoveSelectedPoints();
     void AddPoint();
index 22041dffa23f3694b14d12f75d32012371666005..3add36d466e4e116c146310286b8e3ea9578b8a4 100644 (file)
@@ -2116,7 +2116,18 @@ void vvMainWindow::AddFusionImage(int index, QString file)
     QMessageBox::information(this,tr("Problem reading Fusion !"),"File doesn't exist!");
 }
 //------------------------------------------------------------------------------
-
+//------------------------------------------------------------------------------
+void vvMainWindow::AddLandmarks(int index, QString file)
+{
+  if (QFile::exists(file))
+  {
+    landmarksPanel->LoadFromFile(file.toStdString());
+    landmarksPanel->SetCurrentPath(mInputPathName.toStdString());
+    landmarksPanel->SetCurrentImage(mSlicerManagers[index]->GetFileName().c_str());
+  }
+  else
+    QMessageBox::information(this,tr("Problem reading Landmarks !"),"File doesn't exist!");
+}
 
 //------------------------------------------------------------------------------
 void vvMainWindow::OpenField()
index e308314c59620094e59ac7bb778856154089283c..efcd6a26b41f8b7c89b5f6854f1ff730ad88ad8e 100644 (file)
@@ -57,7 +57,8 @@ class vvMainWindow: public vvMainWindowBase,
   void AddOverlayImage(int index, std::vector<std::string> fileNames, vvImageReader::LoadedImageType type);
   void AddFusionImage(int index, QString filename);
   void AddROI(int index, QString filename);
-  ///Adds a mesh to a SlicerManager, with optional warping by vector field
+  void AddLandmarks(int index, QString file);
+///Adds a mesh to a SlicerManager, with optional warping by vector field
   void AddContour(int image_index, vvMesh::Pointer contour, bool propagation);
   ///This is used to show an image when opened or computed
   void ShowLastImage();