VTKUnstructuredGrid< T > Class Template Reference

#include <VTKData.h>

Public Member Functions

 VTKUnstructuredGrid (std::string filename, const VTKPointDescriptor< T > *descr)
 
 operator bool () const
 
template<typename C >
void write (const C &container)
 

Private Attributes

const VTKPointDescriptor< T > * descriptor_
 
std::ofstream outFile_
 

Detailed Description

template<typename T>
class VTKUnstructuredGrid< T >

This function writes single output frames. this requires an filename and a descriptor. To actually write it, we need a collection.

Constructor & Destructor Documentation

◆ VTKUnstructuredGrid()

template<typename T >
VTKUnstructuredGrid< T >::VTKUnstructuredGrid ( std::string  filename,
const VTKPointDescriptor< T > *  descr 
)
inline

Create a new VTK Unstructured grid file.

Parameters
filenameThe name of the output file
descrThe typedescriptor for T
317  : descriptor_(descr), outFile_(filename)
318  {
319  }
const VTKPointDescriptor< T > * descriptor_
Definition: Tools/VTKData.h:309
std::ofstream outFile_
Definition: Tools/VTKData.h:310

Member Function Documentation

◆ operator bool()

template<typename T >
VTKUnstructuredGrid< T >::operator bool ( ) const
inline

Returns true if this VTK output file is valid and has no errorbits set

323  {
324  return outFile_.good();
325  }

References VTKUnstructuredGrid< T >::outFile_.

◆ write()

template<typename T >
template<typename C >
void VTKUnstructuredGrid< T >::write ( const C &  container)
inline

Writes out the container C containing T's, which all get written using the information in the descriptor. C should contain the forward iterable traits, as well as a method size() to give the number of elements stored in this container. All STL containers have this property. Yours should too.

334  {
335  outFile_ <<
336  "<?xml version=\"1.0\"?>\n"
337  "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n"
338  " <UnstructuredGrid>\n"
339  " <Piece NumberOfPoints=\"" << container.size() << "\" NumberOfCells=\"0\">\n"
340  " <Cells>\n"
341  " <DataArray type=\"Int32\" name=\"connectivity\" format=\"ascii\">\n"
342  " 0\n"
343  " </DataArray>\n"
344  " <DataArray type=\"Float32\" name=\"offset\" format=\"ascii\">\n"
345  " 0\n"
346  " </DataArray>\n"
347  " <DataArray type=\"UInt8\" name=\"types\" format=\"ascii\">\n"
348  " 1\n"
349  " </DataArray>\n"
350  " </Cells>\n"
351  " <Points>\n";
352  Detail::VTKPointDescriptorEntry<T>* pDescr = descriptor_->positionEntry_;
353  outFile_ << "<DataArray type=\"" << pDescr->getTypeName() << "\" "
354  "NumberOfComponents=\"" << pDescr->getNumberOfComponents() << "\" "
355  "format=\"ascii\">\n";
356  for (const T& mem : container)
357  {
358  pDescr->emit(outFile_, mem);
359  }
360  outFile_ << "\n</DataArray>\n";
361 
362  outFile_ <<
363  " </Points>\n"
364  " <PointData>\n";
365 
366  for (Detail::VTKPointDescriptorEntry<T>* descr : descriptor_->entries_)
367  {
368  outFile_ << "<DataArray type=\"" << descr->getTypeName() << "\" "
369  "Name=\"" << descr->getName() << "\" "
370  "NumberOfComponents=\"" << descr->getNumberOfComponents() << "\" "
371  "format=\"ascii\">\n";
372  for (const T& mem : container)
373  {
374  descr->emit(outFile_, mem);
375  }
376  outFile_ << "\n</DataArray>\n";
377  }
378  outFile_ <<
379  " </PointData>\n"
380  " <CellData/>\n"
381  " </Piece>\n"
382  " </UnstructuredGrid>\n"
383  "</VTKFile>\n";
384  }
Definition: Tools/VTKData.h:46
std::string getName() const
Returns the name associated with this field.
Definition: Tools/VTKData.h:76
virtual void emit(std::ostream &out, const T &t) const =0
writes this VTKData to the given output stream for a single T
virtual std::size_t getNumberOfComponents() const =0
Returns the number of components in this type.
virtual std::string getTypeName() const =0
Gives the VTKDataType for VTK.

References VTKUnstructuredGrid< T >::descriptor_, Detail::VTKPointDescriptorEntry< T >::emit(), Detail::VTKPointDescriptorEntry< T >::getName(), Detail::VTKPointDescriptorEntry< T >::getNumberOfComponents(), Detail::VTKPointDescriptorEntry< T >::getTypeName(), and VTKUnstructuredGrid< T >::outFile_.

Referenced by transformMercuryToVTK().

Member Data Documentation

◆ descriptor_

template<typename T >
const VTKPointDescriptor<T>* VTKUnstructuredGrid< T >::descriptor_
private

◆ outFile_

template<typename T >
std::ofstream VTKUnstructuredGrid< T >::outFile_
private

The documentation for this class was generated from the following file: