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;
139 MultiRegions::ExpList2DSharedPtr Exp;
141 vFilenames.push_back(vFiles[0]);
142 vSession = LibUtilities::SessionReader::CreateInstance(2, argv, vFilenames);
148 graph2D = SpatialDomains::MeshGraph::Read(vSession);
159 int coordim = Exp->GetCoordim(0);
160 int nq = Exp->GetNpoints();
169 Exp->GetCoords(xc0,xc1);
172 Exp->GetCoords(xc0,xc1,xc2);
175 ASSERTL0(
false,
"Coordim not valid");
180 vtkPolyDataReader *vtkMeshReader = vtkPolyDataReader::New();
181 vtkMeshReader->SetFileName(infile.c_str());
182 vtkMeshReader->Update();
184 vtkPolyData *vtkMesh = vtkMeshReader->GetOutput();
185 vtkCellDataToPointData* c2p = vtkCellDataToPointData::New();
186 #if VTK_MAJOR_VERSION <= 5
187 c2p->SetInput(vtkMesh);
189 c2p->SetInputData(vtkMesh);
191 c2p->PassCellDataOn();
193 vtkPolyData *vtkDataAtPoints = c2p->GetPolyDataOutput();
195 vtkPoints *vtkPoints = vtkMesh->GetPoints();
196 ASSERTL0(vtkPoints,
"ERROR: cannot get points from mesh.");
198 vtkCellArray *vtkPolys = vtkMesh->GetPolys();
199 ASSERTL0(vtkPolys,
"ERROR: cannot get polygons from mesh.");
201 vtkPointData *vtkPData = vtkDataAtPoints->GetPointData();
202 ASSERTL0(vtkPolys,
"ERROR: cannot get point data from file.");
205 VertexSet::iterator vIter;
212 if (!vtkDataAtPoints->GetPointData()->HasArray(
name.c_str())) {
213 n = vtkDataAtPoints->GetPointData()->GetNumberOfArrays();
214 cerr <<
"Input file '" << infile
215 <<
"' does not have a field named '"
216 <<
name <<
"'" << endl;
217 cerr <<
"There are " << n <<
" arrays in this file." << endl;
218 for (
int i = 0; i < n; ++i)
221 << vtkDataAtPoints->GetPointData()->GetArray(i)->GetName()
230 n = vtkPoints->GetNumberOfPoints();
231 for (i = 0; i < n; ++i)
233 vtkPoints->GetPoint(i,
p);
234 val = vtkPData->GetScalars(
name.c_str())->GetTuple1(i);
235 std::shared_ptr<Vertex> v(
new Vertex(
p[0],
p[1],
p[2],val,factor));
241 for (i = 0; i < Exp->GetNumElmts(); ++i)
244 for (j = 0; j < e->GetNverts(); ++j)
247 coeff_idx = Exp->GetCoeff_Offset(i) + e->GetVertexMap(j);
255 std::shared_ptr<Vertex> v(
new Vertex(x,y,z,0.0,factor));
256 vIter = points.find(v);
261 if (vIter == points.end())
263 cerr <<
"Vertex " << i <<
" not found. Looking for ("
264 << x <<
", " << y <<
", " << z <<
")" << endl;
268 Exp->UpdateCoeffs()[coeff_idx] = (*vIter)->scalar;
272 Exp->SetPhysState(
false);
276 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
277 = Exp->GetFieldDefinitions();
278 std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
280 for(i = 0; i < FieldDef.size(); ++i)
282 FieldDef[i]->m_fields.push_back(outname);
283 Exp->AppendFieldData(FieldDef[i], FieldData[i]);
287 LibUtilities::FieldIO::CreateDefault(vSession);
288 vFld->Write(outfile, FieldDef, FieldData);
292 cout <<
"An error occurred." << endl;
#define ASSERTL0(condition, msg)
std::unordered_set< VertexSharedPtr, VertexHash > VertexSet
Define a set of Vertices with associated hash function.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
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
std::shared_ptr< FieldIO > FieldIOSharedPtr
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
std::shared_ptr< PointGeom > PointGeomSharedPtr
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
Represents a vertex in the mesh.