#include <itkImageRegionConstIterator.h>
#include <itkImageRegionIterator.h>
+#include <fstream>
+
//--------------------------------------------------------------------
namespace clitk {
*
-------------------------------------------------*/
+//-------------------------------------------------------
+// Utility functions for text file parsing (author: joel schaerer)
+
+template<class ElementType>
+ElementType parse_value(std::string str)
+{
+ std::istringstream parser(str);
+ ElementType value;
+ parser >> value;
+ assert(!parser.fail());
+ return value;
+}
+
+template<class ElementType>
+std::vector<ElementType> parse_string(std::string str,char delim)
+{
+ std::istringstream ss(str);
+ std::string token;
+ std::vector<ElementType> result;
+ while (std::getline(ss,token,delim)) {
+ result.push_back(parse_value<ElementType>(token));
+ }
+ return result;
+}
+
+template<class ElementType>
+std::vector<std::vector<ElementType> > parse_file(const char* filename,char delim)
+{
+ std::ifstream fs(filename);
+ std::string line;
+ std::vector<std::vector<ElementType> > result;
+ while (std::getline(fs,line)) {
+ if (line[0] != '#') //skip comments
+ result.push_back(parse_string<ElementType>(line,delim));
+ }
+ return result;
+}
+
//--------------------------------------------------------------------
// Convert float, double ... to string
template<class T>
};
//--------------------------------------------------------------------
- //--------------------------------------------------------------------
- template<class ElementType>
- ElementType parse_value(std::string str)
- {
- std::istringstream parser(str);
- ElementType value;
- parser >> value;
- if (parser.fail()) {
- DD(str);
- DD(value);
- }
- assert(!parser.fail());
- return value;
- }
-
- template<class ElementType>
- std::vector<ElementType> parse_string(std::string str,char delim) {
- std::istringstream ss(str);
- std::string token;
- std::vector<ElementType> result;
- while (getline(ss,token,delim))
- {
- result.push_back(parse_value<ElementType>(token));
- }
- return result;
- }
- //--------------------------------------------------------------------
} // end namespace clitk
#include "clitkCommon.h"
#include "vvMeshReader.h"
#include "vvProgressDialog.h"
+#include <clitkCommon.h>
vvMeshReader::vvMeshReader() :
vtk_mode(false)
}
}
-template<class ElementType>
-ElementType parse_value(std::string str)
-{
- std::istringstream parser(str);
- ElementType value;
- parser >> value;
- assert(!parser.fail());
- return value;
-}
-
-template<class ElementType>
-std::vector<ElementType> parse_string(std::string str,char delim)
-{
- std::istringstream ss(str);
- std::string token;
- std::vector<ElementType> result;
- while (getline(ss,token,delim)) {
- result.push_back(parse_value<ElementType>(token));
- }
- return result;
-}
-
std::vector<std::pair<int,std::string> > vvMeshReader::GetROINames()
{
assert(filename!="");
ss >> roi_number;
if (std::find(selected_contours.begin(),selected_contours.end(),roi_number) != selected_contours.end()) { //Only read selected ROIs
vvMesh::Pointer current_roi=vvMesh::New();
- std::vector<double> rgb=parse_string<double>(i->GetEntryValue(0x3006,0x002a),'\\');
+ std::vector<double> rgb=clitk::parse_string<double>(i->GetEntryValue(0x3006,0x002a),'\\');
assert(rgb.size()==3);
current_roi->r=rgb[0]/255;
current_roi->g=rgb[1]/255;
for(gdcm::SQItem* j=contours->GetFirstSQItem(); j!=0; j=contours->GetNextSQItem()) { //loop over 2D contours
std::string contour_type=j->GetEntryValue(0x3006,0x0042);
if (contour_type=="CLOSED_PLANAR ") {
- int point_number=parse_value<int>(j->GetEntryValue(0x3006,0x0046));
- std::vector<float> points=parse_string<float>(j->GetEntryValue(0x3006,0x0050),'\\');
+ int point_number=clitk::parse_value<int>(j->GetEntryValue(0x3006,0x0046));
+ std::vector<float> points=clitk::parse_string<float>(j->GetEntryValue(0x3006,0x0050),'\\');
assert(points.size() == static_cast<unsigned int>(point_number)*3);
if (z0 == -1) //First contour
z0=points[2];