+//--------------------------------------------------------------------
+bool vvLandmarks::LoadPtsFile(std::vector<std::string> filenames)
+{
+ mFilenames = filenames;
+ for (unsigned int i = 0; i < mPoints.size(); i++) {
+ mPoints[i]->SetNumberOfPoints(0);
+ mLandmarks[i].clear();
+ }
+
+ int err = 0;
+ for (unsigned int f = 0; f < filenames.size(); f++) {
+ std::ifstream fp(filenames[f].c_str(), std::ios::in|std::ios::binary);
+ if (!fp.is_open()) {
+ std::cerr <<"Unable to open file " << filenames[f] << std::endl;
+ err++;
+ }
+ vtkIdType idPoint;
+ char line[255];
+ bool first_line=true;
+ while (fp.getline(line,255)) {
+ std::string stringline = line;
+ stringline += "\n";
+
+ std::string separators = "\t\n\r ";
+ if (stringline.size() > 1) {
+ vvLandmark point;
+ int previousSpace = 0;
+ int space=0;
+
+ if (stringline[0] == '#') // comments
+ continue;
+
+ space = stringline.find_first_of(separators, previousSpace+1);
+ if (space == std::string::npos) {
+ 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_first_of(separators, previousSpace+1);
+ if (space == std::string::npos) {
+ 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_first_of(separators, previousSpace+1);
+ if (space == std::string::npos) {
+ ErrorMsg(mLandmarks.size(),"z position");
+ continue;
+ }
+ point.coordinates[2] = atof(replace_dots(stringline.substr(previousSpace,space - previousSpace)).c_str());
+ previousSpace = space;
+ point.pixel_value=0.; //Not in file
+ point.coordinates[3]=(float)f; //Not in file
+ point.comments = ""; //Not in file
+
+ // DD(point.comments);
+ mLandmarks[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::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[int(point.coordinates[3])]->InsertNextValue(str_vtkIdType.c_str());
+ }
+ }
+ }
+
+ SetTime(0);
+ DD("vvLandmarks::LoadPtsFile")
+ if (err > 0 && err == filenames.size())
+ return false;
+
+
+ return true;
+}
+//--------------------------------------------------------------------