4 #include <vtkPolyDataWriter.h> 5 #include <vtkXMLPolyDataWriter.h> 6 #include <vtksys/SystemTools.hxx> 8 #include <vtkPointData.h> 17 std::string extensionName = m_FileName.substr(m_FileName.find_last_of(
'.') + 1);
18 if (extensionName ==
"vtk")
20 else if ((extensionName ==
"vtp")||(extensionName ==
""))
22 if (extensionName ==
"")
26 else if (extensionName ==
"fds")
28 else if (extensionName ==
"csv")
31 throw itk::ExceptionObject(__FILE__, __LINE__,
"Unsupported shapes extension.",ITK_LOCATION);
36 vtkSmartPointer <vtkPolyDataWriter> vtkWriter = vtkPolyDataWriter::New();
37 vtkWriter->SetInputData(m_InputData);
38 vtkWriter->SetFileName(m_FileName.c_str());
44 vtkSmartPointer <vtkXMLPolyDataWriter> vtkWriter = vtkXMLPolyDataWriter::New();
45 vtkWriter->SetInputData(m_InputData);
46 vtkWriter->SetFileName(m_FileName.c_str());
47 vtkWriter->SetDataModeToBinary();
48 vtkWriter->EncodeAppendedDataOff();
49 vtkWriter->SetCompressorTypeToZLib();
55 std::replace(m_FileName.begin(),m_FileName.end(),
'\\',
'/');
58 std::size_t lastDotPos = m_FileName.find_last_of(
'.');
59 baseName.append(m_FileName.begin(),m_FileName.begin() + lastDotPos);
61 std::string noPathName = baseName;
62 std::size_t lastSlashPos = baseName.find_last_of(
"/");
64 if (lastSlashPos != std::string::npos)
67 noPathName.append(baseName.begin() + lastSlashPos + 1,baseName.end());
70 vtksys::SystemTools::MakeDirectory(baseName.c_str());
72 std::string vtkFileName = noPathName +
"/";
73 vtkFileName += noPathName;
74 vtkFileName +=
"_0.vtp";
76 std::string vtkWriteFileName = baseName +
"/";
77 vtkWriteFileName += noPathName +
"_0.vtp";
79 vtkSmartPointer <vtkXMLPolyDataWriter> vtkWriter = vtkXMLPolyDataWriter::New();
80 vtkWriter->SetInputData(m_InputData);
81 vtkWriter->SetFileName(vtkWriteFileName.c_str());
82 vtkWriter->SetDataModeToBinary();
83 vtkWriter->EncodeAppendedDataOff();
84 vtkWriter->SetCompressorTypeToZLib();
87 std::ofstream outputHeaderFile(m_FileName.c_str());
88 outputHeaderFile <<
"<?xml version=\"1.0\"?>" << std::endl;
89 outputHeaderFile <<
"<VTKFile type=\"vtkFiberDataSet\" version=\"1.0\" byte_order=\"LittleEndian\" compressor=\"vtkZLibDataCompressor\">" << std::endl;
90 outputHeaderFile <<
"<vtkFiberDataSet>" << std::endl;
91 outputHeaderFile <<
"\t<Fibers index=\"0\" file=\"" << vtkFileName <<
"\">" << std::endl;
92 outputHeaderFile <<
"\t</Fibers>" << std::endl;
93 outputHeaderFile <<
"</vtkFiberDataSet>" << std::endl;
94 outputHeaderFile <<
"</VTKFile>" << std::endl;
96 outputHeaderFile.close();
101 vtkSmartPointer<vtkPointData> inputData = m_InputData->GetPointData();
104 std::ofstream outputFile;
105 outputFile.open(m_FileName.c_str(), std::ios_base::out);
106 outputFile.precision(std::numeric_limits<long double>::digits10);
108 if (outputFile.bad())
109 throw itk::ExceptionObject(__FILE__, __LINE__,
"The output file could not be opened", ITK_LOCATION);
112 typedef std::vector<int> IndexVectorType;
113 unsigned int numArrays = inputData->GetNumberOfArrays();
114 IndexVectorType arraySizes(numArrays, 0);
116 outputFile <<
"X,Y,Z,PointId,StreamlineId";
118 for (
unsigned int i = 0;i < numArrays;++i)
120 int arraySize = inputData->GetArray(i)->GetNumberOfComponents();
121 arraySizes[i] = arraySize;
125 outputFile <<
"," << inputData->GetArrayName(i);
129 for (
unsigned int j = 0;j < arraySize;++j)
130 outputFile <<
"," << inputData->GetArrayName(i) <<
"#" << j;
137 unsigned int numberOfPoints = m_InputData->GetNumberOfPoints();
138 unsigned int numberOfStreamlines = m_InputData->GetNumberOfLines();
139 std::cout <<
"Number of data points: " << numberOfPoints << std::endl;
140 std::cout <<
"Number of streamlines: " << numberOfStreamlines << std::endl;
143 IndexVectorType pointId(numberOfPoints, -1);
144 IndexVectorType streamlineId(numberOfPoints, -1);
145 m_InputData->GetLines()->InitTraversal();
146 vtkSmartPointer<vtkIdList> idList = vtkSmartPointer<vtkIdList>::New();
147 for (
unsigned int i = 0;i < numberOfStreamlines;++i)
149 m_InputData->GetLines()->GetNextCell(idList);
151 unsigned int streamlineSize = idList->GetNumberOfIds();
153 if (streamlineSize == 1)
156 for (
unsigned int j = 0;j < streamlineSize;++j)
158 unsigned int pid = idList->GetId(j);
159 streamlineId[pid] = i+1;
165 for (
unsigned int i = 0;i < numberOfPoints;++i)
167 if (numberOfStreamlines != 0)
168 if (streamlineId[i] == -1)
171 outputFile << std::endl;
175 m_InputData->GetPoint(i, p);
177 for (
unsigned int j = 0;j < 3;++j)
178 outputFile << p[j] <<
",";
181 outputFile << pointId[i] <<
"," << streamlineId[i];
184 for (
unsigned int k = 0;k < numArrays;++k)
185 for (
unsigned int j = 0;j < arraySizes[k];++j)
186 outputFile <<
"," << inputData->GetArray(k)->GetComponent(i, j);
189 outputFile << std::endl;
void WriteFileAsMedinriaFibers()
void WriteFileAsVTKAscii()