www.cemf.ir
triSurfaceFieldToVTK.cpp
Go to the documentation of this file.
1 #include "vocabs.hpp"
2 #include "vtkFile.hpp"
4 
6  systemControl &control,
7  const fileSystem &destPath,
8  const word &bName,
9  bool separate,
10  wordList& surfNames,
11  wordList& fileNames)
12 {
13 
14  auto timeFolder = control.geometry().path();
15 
16  surfNames.clear();
17  fileNames.clear();
18 
19  // check if pointStructure exist in this folder
20  IOfileHeader triSurfaeHeader(
21  objectFile(
23  timeFolder,
24  objectFile::READ_ALWAYS,
25  objectFile::WRITE_ALWAYS));
26 
27  if (!triSurfaeHeader.headerOk(true))
28  {
29  WARNING << "Time folder " << timeFolder << " does not contain any triSurface data file."
30  << " Skipping this folder . . ." << END_WARNING;
31  return true;
32  }
33 
34  auto triSurfaceObj = multiTriSurface(
35  objectFile(
37  "",
38  objectFile::READ_ALWAYS,
39  objectFile::WRITE_ALWAYS),
40  &control.geometry());
41 
42  if(separate)
43  {
45  triSurfaceObj,
46  destPath,
47  control.time().currentTime(),
48  bName,
49  surfNames,
50  fileNames);
51  }
52  else
53  {
55  triSurfaceObj,
56  destPath,
57  control.time().currentTime(),
58  bName,
59  surfNames,
60  fileNames );
61  }
62 }
63 
65  Ostream &os,
66  const realx3 *points,
67  const uint32x3 *vertices,
68  const subSurface &subSurf)
69 {
70  auto nP = subSurf.numPoints();
71 
72  os << "DATASET UNSTRUCTURED_GRID" << endl;
73  os << "POINTS " << nP << " float" << endl;
74 
75  for ( auto i=subSurf.pointStart(); i<subSurf.pointEnd(); i++ )
76  {
77  os << points[i].x() <<
78  " " << points[i].y() <<
79  " " << points[i].z() << endl;
80  if (!os) return false;
81  }
82 
83  auto nTri = subSurf.size();
84 
85  os << "CELLS " << nTri << " " << 4*nTri << endl;
86 
87  for(auto i=subSurf.start(); i<subSurf.end(); i++)
88  {
89  os<< 3 <<
90  " "<< vertices[i].x()-subSurf.pointStart() <<
91  " "<< vertices[i].y()-subSurf.pointStart() <<
92  " "<< vertices[i].z()-subSurf.pointStart()<<endl;
93  if (!os) return false;
94  }
95 
96  os<<"CELL_TYPES "<< nTri<<'\n';
97 
98  for(uint32 i=0; i<nTri; i++)
99  {
100  os<< 5 <<'\n';
101  }
102 
103  os << "CELL_DATA " << nTri << endl;
104 
105  return true;
106 }
107 
109  Ostream &os,
110  const realx3 *points,
111  const uint32x3 *vertices,
112  uint32 numPoints,
113  uint32 numTris)
114 {
115 
116  os << "DATASET UNSTRUCTURED_GRID" << endl;
117  os << "POINTS " << numPoints << " float" << endl;
118 
119  for ( auto i=0; i<numPoints; i++ )
120  {
121  os << points[i].x() <<
122  " " << points[i].y() <<
123  " " << points[i].z() << endl;
124  if (!os) return false;
125  }
126 
127  os << "CELLS " << numTris << " " << 4*numTris << endl;
128 
129  for(auto i=0; i<numTris; i++)
130  {
131  os<< 3 <<
132  " "<< vertices[i].x()<<
133  " "<< vertices[i].y()<<
134  " "<< vertices[i].z()<<endl;
135  if (!os) return false;
136  }
137 
138  os<<"CELL_TYPES "<< numTris<<'\n';
139 
140  for(uint32 i=0; i<numTris; i++)
141  {
142  os<< 5 <<'\n';
143  }
144 
145  os << "CELL_DATA " << numTris << endl;
146 
147  return true;
148 }
149 
151 (
153  const fileSystem &destPath,
154  real time,
155  const word &bName,
156  wordList& surfNames,
157  wordList& fileNames
158 )
159 {
160  vtkFile vtk(destPath, bName, time, false);
161 
162  if (!vtk)
163  return false;
164 
165  auto hPoints = surface.points().hostView();
166  auto hVertices = surface.vertices().hostView();
167 
168  realx3 const* pData = hPoints.data();
169  uint32x3 const* vData = hVertices.data();
170 
171  REPORT(2) << "Wrting surface to "<<
172  Green_Text(vtk.fileName()) << END_REPORT;
173 
174  if (! triSurfaceToVTK(
175  vtk(),
176  pData,
177  vData,
178  surface.numPoints(),
179  surface.size()))
180  {
182  "error in writing triSurface data to vtk file " <<
183  vtk.fileName() << endl;
184  return false;
185  }
186 
187  auto fileList = containingFiles(surface.path().dirPath());
188 
189  for(const auto& file:fileList)
190  {
191  IOfileHeader fieldHeader(
192  objectFile(
193  file.fileName(),
194  file.dirPath(),
195  objectFile::READ_ALWAYS,
196  objectFile::WRITE_ALWAYS) );
197 
198  if( fieldHeader.headerOk(true) )
199  {
200  convertRealx3TypetriSurfaceField(vtk(), fieldHeader, surface);
201  }
202  }
203 
204  surfNames.push_back(bName);
205  fileNames.push_back(vtk.fileName().wordPath());
206 
207  output<<endl;
208  return true;
209 }
210 
213  const fileSystem &destPath,
214  real time,
215  const word &bName,
216  wordList& surfNames,
217  wordList& fileNames)
218 {
219 
220  auto hPoints = surface.points().hostView();
221  auto hVertices = surface.vertices().hostView();
222 
223  realx3 const* pData = hPoints.data();
224  uint32x3 const* vData = hVertices.data();
225 
226  REPORT(1) << "Wrting triSurface geometry to vtk file . . ."<<
227  END_REPORT;
228 
229  wordList sNames, fNames;
230 
231  auto nSurf = surface.numSurfaces();
232  for(auto nS=0; nS<nSurf; nS++)
233  {
234  auto sName = surface.subSurfaceName(nS);
235  word fName = groupNames(bName,sName,'_');
236  vtkFile vtk(destPath, fName, time, false);
237  REPORT(2) << "Wrting sub-surface to "<<
239 
240  if (!vtk)
241  return false;
242 
243  fNames.push_back(vtk.fileName().wordPath());
244  sNames.push_back(fName);
245 
246  if (! triSurfaceToVTK(
247  vtk(),
248  pData,
249  vData,
250  surface.subSurfaces()[nS]) )
251  {
253  "error in writing triSurface data to vtk file " <<
254  vtk.fileName() << endl;
255  return false;
256  }
257  }
258 
259  auto fileList = containingFiles(surface.path().dirPath());
260 
261  for(const auto& file:fileList)
262  {
263  IOfileHeader fieldHeader(
264  objectFile(
265  file.fileName(),
266  file.dirPath(),
267  objectFile::READ_ALWAYS,
268  objectFile::WRITE_ALWAYS) );
269 
270  if( fieldHeader.headerOk(true) )
271  {
273  destPath,
274  fieldHeader,
275  surface,
276  bName,
277  time);
278  }
279 
280  }
281 
282  fileNames = fNames;
283  surfNames = sNames;
284  output<<endl;
285  return true;
286 }
287 
288 
290  Ostream& os,
291  const IOfileHeader& header,
292  multiTriSurface& tSurface)
293 {
294  word objectType = header.objectType();
295 
296  if(!checkTriFieldType<realx3>(objectType))return false;
297 
298  auto field = realx3TriSurfaceField_H
299  (
300  header,
301  tSurface,
302  static_cast<real>(0)
303  );
304 
305  const realx3* data = field.deviceViewAll().data();
306 
307  REPORT(1)<<"writing "<< greenColor <<header.objectName()<<
308  defaultColor<<" field to vtk."<<END_REPORT;
309 
311  (
312  os,
313  header.objectName(),
314  data,
315  field.size()
316  );
317 }
318 
319 
321 (
322  const fileSystem& destPath,
323  const IOfileHeader& header,
324  multiTriSurface& tSurface,
325  const word& bName,
326  real time
327 )
328 {
329  word objectType = header.objectType();
330 
331  if(!checkTriFieldType<realx3>(objectType))return false;
332 
333  auto field = realx3TriSurfaceField_H
334  (
335  header,
336  tSurface,
337  static_cast<real>(0)
338  );
339 
340  const realx3* data = field.deviceViewAll().data();
341 
342  /*REPORT(1)<<"writing "<< greenColor <<header.objectName()<<
343  defaultColor<<" field to vtk."<<END_REPORT;*/
344 
345  auto nSurf = tSurface.numSurfaces();
346 
347  for(auto nS=0; nS<nSurf; nS++)
348  {
349  auto& subSurf = tSurface.subSurfaces()[nS];
350 
351  auto sName = subSurf.name();
352  vtkFile vtk(destPath, groupNames(bName,sName,'_'), time, false, true);
353  REPORT(2) << "Wrting sub-surface to "<<
355 
357  (
358  vtk(),
359  header.objectName(),
360  data+subSurf.start(),
361  subSurf.size()
362  );
363  }
364 
365  return true;
366  /*return pFlow::PFtoVTK::addRealx3PointField
367  (
368  os,
369  header.objectName(),
370  data,
371  field.size()
372  );*/
373 }
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
pFlow::vtkFile
Definition: vtkFile.hpp:33
pFlow::List< word >
pFlow::IOfileHeader::objectType
const word & objectType() const
Definition: IOfileHeader.hpp:75
pFlow::real
float real
Definition: builtinTypes.hpp:45
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::subSurface::end
uint32 end() const
Definition: subSurface.hpp:67
pFlow::subSurface::pointEnd
uint32 pointEnd() const
Definition: subSurface.hpp:77
pFlow::vtkFile::fileName
virtual fileSystem fileName() const
Definition: vtkFile.cpp:79
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::containingFiles
fileSystemList containingFiles(const fileSystem &path)
A list of file paths that exist in the path.
Definition: fileSystem.cpp:359
pFlow::TSFtoVTK::convertRealx3TypetriSurfaceField
bool convertRealx3TypetriSurfaceField(Ostream &os, const IOfileHeader &header, multiTriSurface &tSurface)
Definition: triSurfaceFieldToVTK.cpp:289
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::subSurface::size
uint32 size() const
Definition: subSurface.hpp:87
pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFieldsSeparate
bool convertTimeFolderTriSurfaceFieldsSeparate(multiTriSurface &surface, const fileSystem &destPath, real time, const word &bName, wordList &surfNames, wordList &fileNames)
Definition: triSurfaceFieldToVTK.cpp:211
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
access component
Definition: triple.hpp:144
pFlow::multiTriSurface
Definition: multiTriSurface.hpp:32
pFlow::multiTriSurface::subSurfaces
const subSurfaceList & subSurfaces() const
Definition: multiTriSurface.hpp:86
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
triSurfaceFieldToVTK.hpp
END_WARNING
#define END_WARNING
Definition: streams.hpp:44
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
defaultColor
const char * defaultColor
char constants to alter output format and color
Definition: iOstream.hpp:27
pFlow::subSurface::numPoints
uint32 numPoints() const
Definition: subSurface.hpp:92
pFlow::subSurface::start
uint32 start() const
Definition: subSurface.hpp:62
pFlow::systemControl::time
const Time & time() const
Definition: systemControl.hpp:122
pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFields
bool convertTimeFolderTriSurfaceFields(systemControl &control, const fileSystem &destPath, const word &bName, bool separate, wordList &surfNames, wordList &fileNames)
Definition: triSurfaceFieldToVTK.cpp:5
pFlow::output
Ostream output
pFlow::TSFtoVTK::triSurfaceToVTK
bool triSurfaceToVTK(Ostream &os, const realx3 *points, const uint32x3 *vertices, const subSurface &subSurf)
Definition: triSurfaceFieldToVTK.cpp:64
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::triSurfaceFile__
const char *const triSurfaceFile__
Definition: vocabs.hpp:43
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
access component
Definition: triple.hpp:156
pFlow::repository::path
virtual fileSystem path() const
Definition: repository.cpp:70
pFlow::timeControl::currentTime
real currentTime() const
Definition: timeControl.hpp:127
pFlow::TSFtoVTK::convertRealx3TypetriSurfaceFieldSeparate
bool convertRealx3TypetriSurfaceFieldSeparate(const fileSystem &destPath, const IOfileHeader &header, multiTriSurface &tSurface, const word &bName, real time)
Definition: triSurfaceFieldToVTK.cpp:321
pFlow::subSurface::pointStart
uint32 pointStart() const
Definition: subSurface.hpp:72
pFlow::IOfileHeader
Definition: IOfileHeader.hpp:35
pFlow::systemControl::geometry
const repository & geometry() const
Definition: systemControl.hpp:132
pFlow::IOfileHeader::headerOk
bool headerOk(bool silent=false)
Definition: IOfileHeader.cpp:92
pFlow::groupNames
word groupNames(const word &bw, const word &tw, char sep='.')
Group words and output bw.tw.
Definition: bTypesFunctions.cpp:179
pFlow::IOfileHeader::objectName
const word & objectName() const
Definition: IOfileHeader.hpp:69
pFlow::fileSystem::wordPath
word wordPath() const
Path in word type.
Definition: fileSystem.hpp:160
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
access component
Definition: triple.hpp:132
vocabs.hpp
pFlow::triple< real >
pFlow::subSurface
Definition: subSurface.hpp:27
pFlow::Ostream
Standard output stream for BINARY and ASCII formats.
Definition: Ostream.hpp:39
greenColor
const char * greenColor
Definition: iOstream.hpp:30
pFlow::multiTriSurface::numSurfaces
uint32 numSurfaces() const
Definition: multiTriSurface.hpp:81
pFlow::realx3TriSurfaceField_H
triSurfaceField< realx3, HostSpace > realx3TriSurfaceField_H
Definition: triSurfaceFields.hpp:42
pFlow::triangle::surface
INLINE_FUNCTION_HD real surface(const realx3 &p1, const realx3 &p2, const realx3 &p3)
Definition: triangleFunctions.hpp:30
vtkFile.hpp
pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFieldsSingle
bool convertTimeFolderTriSurfaceFieldsSingle(multiTriSurface &surface, const fileSystem &destPath, real time, const word &bName, wordList &surfNames, wordList &fileNames)
Definition: triSurfaceFieldToVTK.cpp:151
pFlow::timeFolder
Definition: timeFolder.hpp:32
pFlow::PFtoVTK::addRealx3PointField
bool addRealx3PointField(Ostream &os, const word &fieldName, const realx3 *field, uint32 numData)
Definition: pointFieldToVTK.cpp:357
WARNING
#define WARNING
Definition: streams.hpp:43