Main function.
84 po::options_description desc(
"Available options");
86 (
"help,h",
"Produce this help message.")
87 (
"name,n", po::value<string>()->default_value(
"Intensity"),
88 "Name of field in VTK file to use for intensity.")
89 (
"outname,m", po::value<string>()->default_value(
"intensity"),
90 "Name of field in output FLD file.")
91 (
"precision,p", po::value<double>()->default_value(1),
92 "Precision of vertex matching.");
94 po::options_description hidden(
"Hidden options");
96 (
"file", po::value<vector<string> >(),
"Input filename");
98 po::options_description cmdline_options;
99 cmdline_options.add(desc).add(hidden);
101 po::positional_options_description p;
104 po::variables_map vm;
109 po::store(po::command_line_parser(argc, argv).
110 options(cmdline_options).positional(p).run(), vm);
113 catch (
const std::exception& e)
115 cerr << e.what() << endl;
120 if ( vm.count(
"help") || vm.count(
"file") == 0 ||
121 vm[
"file"].as<vector<string> >().size() != 3) {
122 cerr <<
"Usage: VtkToFld session.xml intensity.vtk output.fld [options]"
129 std::vector<std::string> vFiles = vm[
"file"].as<vector<string> >();
130 const string infile = vFiles[1];
131 const string outfile = vFiles[2];
132 const double factor = vm[
"precision"].as<
double>();
133 const string name = vm[
"name"].as<
string>();
134 const string outname = vm[
"outname"].as<
string>();
136 std::vector<std::string> vFilenames;
141 vFilenames.push_back(vFiles[0]);
142 vSession = LibUtilities::SessionReader::CreateInstance(2, argv, vFilenames);
160 int coordim = Exp->GetCoordim(0);
161 int nq = Exp->GetNpoints();
170 Exp->GetCoords(xc0,xc1);
173 Exp->GetCoords(xc0,xc1,xc2);
176 ASSERTL0(
false,
"Coordim not valid");
181 vtkPolyDataReader *vtkMeshReader = vtkPolyDataReader::New();
182 vtkMeshReader->SetFileName(infile.c_str());
183 vtkMeshReader->Update();
185 vtkPolyData *vtkMesh = vtkMeshReader->GetOutput();
186 vtkCellDataToPointData* c2p = vtkCellDataToPointData::New();
187 #if VTK_MAJOR_VERSION <= 5
188 c2p->SetInput(vtkMesh);
190 c2p->SetInputData(vtkMesh);
192 c2p->PassCellDataOn();
194 vtkPolyData *vtkDataAtPoints = c2p->GetPolyDataOutput();
196 vtkPoints *vtkPoints = vtkMesh->GetPoints();
197 ASSERTL0(vtkPoints,
"ERROR: cannot get points from mesh.");
199 vtkCellArray *vtkPolys = vtkMesh->GetPolys();
200 ASSERTL0(vtkPolys,
"ERROR: cannot get polygons from mesh.");
202 vtkPointData *vtkPData = vtkDataAtPoints->GetPointData();
203 ASSERTL0(vtkPolys,
"ERROR: cannot get point data from file.");
213 if (!vtkDataAtPoints->GetPointData()->HasArray(name.c_str())) {
214 n = vtkDataAtPoints->GetPointData()->GetNumberOfArrays();
215 cerr <<
"Input file '" << infile
216 <<
"' does not have a field named '"
217 << name <<
"'" << endl;
218 cerr <<
"There are " << n <<
" arrays in this file." << endl;
219 for (
int i = 0; i < n; ++i)
222 << vtkDataAtPoints->GetPointData()->GetArray(i)->GetName()
231 n = vtkPoints->GetNumberOfPoints();
232 for (i = 0; i < n; ++i)
234 vtkPoints->GetPoint(i,p);
235 val = vtkPData->GetScalars(name.c_str())->GetTuple1(i);
236 boost::shared_ptr<Vertex> v(
new Vertex(p[0],p[1],p[2],val,factor));
242 for (i = 0; i < Exp->GetNumElmts(); ++i)
245 for (j = 0; j < e->GetNverts(); ++j)
248 coeff_idx = Exp->GetCoeff_Offset(i) + e->GetVertexMap(j);
256 boost::shared_ptr<Vertex> v(
new Vertex(x,y,z,0.0,factor));
257 vIter = points.find(v);
262 if (vIter == points.end())
264 cerr <<
"Vertex " << i <<
" not found. Looking for ("
265 << x <<
", " << y <<
", " << z <<
")" << endl;
269 Exp->UpdateCoeffs()[coeff_idx] = (*vIter)->scalar;
273 Exp->SetPhysState(
false);
277 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
278 = Exp->GetFieldDefinitions();
279 std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
281 for(i = 0; i < FieldDef.size(); ++i)
283 FieldDef[i]->m_fields.push_back(outname);
284 Exp->AppendFieldData(FieldDef[i], FieldData[i]);
288 vFld.
Write(outfile, FieldDef, FieldData);
292 cout <<
"An error occurred." << endl;
#define ASSERTL0(condition, msg)
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
boost::unordered_set< VertexSharedPtr, VertexHash > VertexSet
Define a set of Vertices with associated hash function.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
void GetCoords(Array< OneD, NekDouble > &coords_1, Array< OneD, NekDouble > &coords_2=NullNekDouble1DArray, Array< OneD, NekDouble > &coords_3=NullNekDouble1DArray)
this function returns the physical coordinates of the quadrature points of the expansion ...
boost::shared_ptr< ExpList2D > ExpList2DSharedPtr
Shared pointer to an ExpList2D object.
Represents a vertex in the mesh.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
Class for operating on FLD files.
void Write(const std::string &outFile, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, const FieldMetaDataMap &fieldinfomap=NullFieldMetaDataMap)
Write data in FLD format.
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
boost::shared_ptr< PointGeom > PointGeomSharedPtr