Programming tasks to Scientific Computing I
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
shellFE::LegacyVtkWriter< MeshType > Class Template Reference

#include <legacyVtkWriter.h>

Classes

struct  ScalarData
 
struct  VectorData
 

Public Types

typedef MeshType::RealType RealType
 
typedef MeshType::Point3DType Point3DType
 
typedef MeshType::Indices3DType Indices3DType
 
typedef MeshType::VectorType VectorType
 

Public Member Functions

 LegacyVtkWriter (const MeshType &mesh)
 
 LegacyVtkWriter (const MeshType &mesh, int precision)
 
LegacyVtkWriteraddScalarData (const VectorType &data, string dataDescr, DataSupp supp)
 
LegacyVtkWriteraddVectorData (const VectorType &data, const int numComponents, string dataDescr, DataSupp supp, VectorSpec vSpec=VECTORS)
 
void setPrecisionTo (int prec)
 set precision in saving methods More...
 
void save (string filename) const
 

Protected Attributes

std::vector< ScalarData_scalarVertexData
 
std::vector< VectorData_vectorVertexData
 
std::vector< ScalarData_scalarFaceData
 
std::vector< VectorData_vectorFaceData
 
const MeshType _mesh
 
int _precision
 

Detailed Description

template<class MeshType>
class shellFE::LegacyVtkWriter< MeshType >

Use this class like: aol::LegacyVtkWriter<> ( mesh ) -> .addData ( result, "color", VERTEX_DATA ) -> .saveAsLegacyVTK ( "result.vtk" ); This class is a container for a mesh plus data vectors on vertices and faces. We will not store any of the data vectors here, but only keep pointers to them.

Definition at line 14 of file legacyVtkWriter.h.

Member Typedef Documentation

Definition at line 18 of file legacyVtkWriter.h.

Definition at line 17 of file legacyVtkWriter.h.

template<class MeshType>
typedef MeshType::RealType shellFE::LegacyVtkWriter< MeshType >::RealType

Definition at line 16 of file legacyVtkWriter.h.

template<class MeshType>
typedef MeshType::VectorType shellFE::LegacyVtkWriter< MeshType >::VectorType

Definition at line 19 of file legacyVtkWriter.h.

Constructor & Destructor Documentation

template<class MeshType>
shellFE::LegacyVtkWriter< MeshType >::LegacyVtkWriter ( const MeshType mesh)
inline

Definition at line 21 of file legacyVtkWriter.h.

21 : _mesh ( mesh ), _precision( 8 ) {}
template<class MeshType>
shellFE::LegacyVtkWriter< MeshType >::LegacyVtkWriter ( const MeshType mesh,
int  precision 
)
inline

Definition at line 22 of file legacyVtkWriter.h.

22 : _mesh ( mesh ), _precision( precision ) {}

Member Function Documentation

template<class MeshType>
LegacyVtkWriter& shellFE::LegacyVtkWriter< MeshType >::addScalarData ( const VectorType data,
string  dataDescr,
DataSupp  supp 
)
inline

Definition at line 24 of file legacyVtkWriter.h.

24  {
25 
26  ScalarData entry = { dataDescr, &data };
27 
28  switch ( supp ) {
29  case VERTEX_DATA:
30  if ( data.size() != static_cast<unsigned>( _mesh.getNumVertices () ) ) throw std::invalid_argument( aol::strprintf ( "Wrong size. In File %s at line %d.", __FILE__, __LINE__ ).c_str() );
31  _scalarVertexData.push_back ( entry );
32  break;
33 
34  case FACE_DATA:
35  if ( data.size() != static_cast<unsigned>( _mesh.getNumTriangs () ) ) throw std::invalid_argument( aol::strprintf ( "Wrong size. In File %s at line %d.", __FILE__, __LINE__ ).c_str() );
36  _scalarFaceData.push_back ( entry );
37  break;
38 
39  default:
40  throw std::invalid_argument( aol::strprintf ( "Unknown DataSupp. In File %s at line %d.", __FILE__, __LINE__ ).c_str() );
41  }
42  return *this;
43  }
int getNumVertices() const
Definition: triangMesh.h:42
int getNumTriangs() const
Definition: triangMesh.h:46
std::vector< ScalarData > _scalarFaceData
string strprintf(const char *format,...)
Give back formatted string, analogously to sprintf, but save the long way &#39;round with char arrays...
Definition: aol.cpp:5
std::vector< ScalarData > _scalarVertexData
template<class MeshType>
LegacyVtkWriter& shellFE::LegacyVtkWriter< MeshType >::addVectorData ( const VectorType data,
const int  numComponents,
string  dataDescr,
DataSupp  supp,
VectorSpec  vSpec = VECTORS 
)
inline

Definition at line 45 of file legacyVtkWriter.h.

45  {
46 
47  VectorData entry = { dataDescr, vSpec, &data, numComponents };
48 
49  switch ( supp ) {
50  case VERTEX_DATA:
51  _vectorVertexData.push_back ( entry );
52  break;
53  case FACE_DATA:
54  _vectorFaceData.push_back ( entry );
55  break;
56  default:
57  throw std::invalid_argument( aol::strprintf ( "Unknown DataSupp. In File %s at line %d.", __FILE__, __LINE__ ).c_str() );
58  }
59  return *this;
60  }
std::vector< VectorData > _vectorVertexData
std::vector< VectorData > _vectorFaceData
string strprintf(const char *format,...)
Give back formatted string, analogously to sprintf, but save the long way &#39;round with char arrays...
Definition: aol.cpp:5
template<class MeshType>
void shellFE::LegacyVtkWriter< MeshType >::save ( string  filename) const
inline

Definition at line 65 of file legacyVtkWriter.h.

65  {
66  const int numVertices = _mesh.getNumVertices();
67 
68  std::ofstream out ( filename.c_str() ); // ctor checks if file could be opened
69 
70  out << "# vtk DataFile Version 2.0" << endl
71  << "written by method MeshWithData::saveAsLegacyVTK" << endl // paraview supports time = x.x here. useful?
72  << "ASCII" << endl
73  << "DATASET POLYDATA" << endl
74  << "POINTS " << numVertices << " float" << endl;
75 
76  // vertex coordinates
77  for ( int nodeIter = 0; nodeIter < _mesh.getNumVertices(); ++nodeIter ) {
78  const Point3DType& coords ( _mesh.getVertex(nodeIter) );
79  for ( short i = 0; i < 3; ++i )
80  out << ( i == 0 ? "" : " " ) << coords[i];
81  out << endl;
82  }
83 
84  out << "POLYGONS " << _mesh.getNumTriangs() << " " << 4 * _mesh.getNumTriangs() << endl;
85  // triangles' vertex indices
86  for ( int elementIter = 0; elementIter < _mesh.getNumTriangs(); ++elementIter ) {
87  out << "3 ";
88  for ( short i = 0; i < 3; ++i )
89  out << ( i == 0 ? "" : " " ) << _mesh.getTriangNodeIdx( elementIter, i );
90  out << endl;
91  }
92 
93  if ( _scalarVertexData.size() > 0 || _vectorVertexData.size() > 0 )
94  out << "POINT_DATA " << numVertices << endl;
95  // scalar data on vertices
96  for (size_t i = 0; i < _scalarVertexData.size(); ++i) {
97  out << "SCALARS " << _scalarVertexData[i]._descr << " float" << endl;
98  out << "LOOKUP_TABLE default" << endl;
99  for ( unsigned vx = 0; vx < (*_scalarVertexData[i]._data).size(); ++vx )
100  out << (*_scalarVertexData[i]._data)[vx] << endl;
101  }
102 
103  if ( _scalarFaceData.size() > 0 )
104  out << "CELL_DATA " << _mesh.getNumTriangs() << endl;
105  // scalar data on vertices
106  for (size_t i = 0; i < _scalarFaceData.size(); ++i) {
107  out << "SCALARS " << _scalarFaceData[i]._descr << " float 1" << endl;
108  out << "LOOKUP_TABLE default" << endl;
109  for ( unsigned vx = 0; vx < (*_scalarFaceData[i]._data).size(); ++vx )
110  out << (*_scalarFaceData[i]._data)[vx] << endl;
111  }
112 
113  // vector data on vertices
114  for (size_t i = 0; i < _vectorVertexData.size(); ++i) {
115  string spec;
116  if ( _vectorVertexData[i]._spec == VECTORS ) spec = "VECTORS";
117  if ( _vectorVertexData[i]._spec == NORMALS ) spec = "NORMALS";
118  out << spec << " " << _vectorVertexData[i]._descr << " float" << endl;
119  for ( int vx = 0; vx < numVertices; ++vx ) {
120  for ( int comp = 0; comp < _vectorVertexData[i]._numComponents; ++comp )
121  out << ( comp == 0 ? "" : " " ) << (*_vectorVertexData[i]._data)(vx + comp * numVertices); //TODO index mapper
122  out << endl;
123  }
124  }
125  }
const Point3DType & getVertex(const int num) const
Definition: triangMesh.h:66
int getNumVertices() const
Definition: triangMesh.h:42
int getNumTriangs() const
Definition: triangMesh.h:46
std::vector< VectorData > _vectorVertexData
std::vector< ScalarData > _scalarFaceData
int getTriangNodeIdx(const int num, const int localNode) const
Definition: triangMesh.h:104
std::vector< ScalarData > _scalarVertexData
MeshType::Point3DType Point3DType
template<class MeshType>
void shellFE::LegacyVtkWriter< MeshType >::setPrecisionTo ( int  prec)
inline

set precision in saving methods

Definition at line 63 of file legacyVtkWriter.h.

Member Data Documentation

template<class MeshType>
const MeshType shellFE::LegacyVtkWriter< MeshType >::_mesh
protected

Definition at line 146 of file legacyVtkWriter.h.

template<class MeshType>
int shellFE::LegacyVtkWriter< MeshType >::_precision
protected

Definition at line 147 of file legacyVtkWriter.h.

template<class MeshType>
std::vector<ScalarData> shellFE::LegacyVtkWriter< MeshType >::_scalarFaceData
protected

Definition at line 143 of file legacyVtkWriter.h.

template<class MeshType>
std::vector<ScalarData> shellFE::LegacyVtkWriter< MeshType >::_scalarVertexData
protected

Definition at line 141 of file legacyVtkWriter.h.

template<class MeshType>
std::vector<VectorData> shellFE::LegacyVtkWriter< MeshType >::_vectorFaceData
protected

Definition at line 144 of file legacyVtkWriter.h.

template<class MeshType>
std::vector<VectorData> shellFE::LegacyVtkWriter< MeshType >::_vectorVertexData
protected

Definition at line 142 of file legacyVtkWriter.h.


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