33 #ifndef __H__UG_file_io_vtu_impl
34 #define __H__UG_file_io_vtu_impl
44 template <
class TAPosition>
50 UG_LOG(
"ERROR in LoadGridFromVTU: File not found: " << filename << std::endl);
55 UG_LOG(
"ERROR in LoadGridFromVTU: File contains no grid.\n");
59 vtuReader.
grid(grid, 0, aPos);
66 template <
class TAPosition>
71 std::ofstream out(filename);
95 template <
class TPositionAttachment>
138 out <<
" <Piece NumberOfPoints=\"" << grid.
num<
Vertex>() <<
"\""
139 <<
" NumberOfCells=\"" <<
m_cells.size() <<
"\">" << endl;
143 out <<
" <Points>" << endl;
144 write_vector_data<Vertex>(grid, aPos,
"");
145 out <<
" </Points>" << endl;
163 template <
class TElem,
class TAttachment>
173 typedef typename TAttachment::ValueType vector_t;
181 for(iter_t i = grid.
begin<TElem>(); i != grid.
end<TElem>(); ++i){
182 vector_t& v = aaData[*i];
183 for(
size_t c = 0; c < vector_t::Size; ++c){
191 template <
class TElem>
197 for(iter_t i = grid.
begin<TElem>(); i != grid.
end<TElem>(); ++i){
198 if(consider_elem(*i))
199 cellsOut.push_back(*i);
210 template <
class TPositionAttachment>
212 grid(
Grid& gridOut,
size_t index, TPositionAttachment& aPos)
214 using namespace rapidxml;
218 if(num_grids() <= index){
219 UG_LOG(
" GridReaderVTU::read: bad grid index!\n");
223 Grid& grid = gridOut;
239 m_entries[index].grid = &grid;
242 xml_node<>* gridNode = m_entries[index].node;
243 vector<Vertex*>&
vertices = m_entries[index].vertices;
244 vector<GridObject*>& cells = m_entries[index].cells;
247 xml_node<>* pieceNode = gridNode;
249 xml_node<>* pointsNode = pieceNode->first_node(
"Points");
250 UG_COND_THROW(pointsNode == NULL,
"Missing Points node in UnstructuredGrid node!")
253 create_vertices(
vertices, grid, pointsNode, aaPos);
255 xml_node<>* cellsNode = pieceNode->first_node(
"Cells");
256 UG_COND_THROW(cellsNode == NULL,
"Missing Cells node in UnstructuredGrid node!")
257 create_cells(cells, grid, cellsNode,
vertices, vrtOffset);
265 template <
class TAAPos>
268 rapidxml::xml_node<>* vrtNode, TAAPos aaPos)
270 using namespace rapidxml;
273 xml_node<>* dataNode = vrtNode->first_node(
"DataArray");
274 UG_COND_THROW(!dataNode,
"Missing DataArray node in Points node");
276 int numSrcCoords = -1;
277 xml_attribute<>* attrib = dataNode->first_attribute(
"NumberOfComponents");
279 numSrcCoords = atoi(attrib->value());
281 int numDestCoords = (int)TAAPos::ValueType::Size;
283 assert(numDestCoords > 0 &&
"bad position attachment type");
285 if(numSrcCoords < 1 || numDestCoords < 1)
289 string str(dataNode->value(), dataNode->value_size());
290 stringstream ss(str, ios_base::in);
293 if(numSrcCoords == numDestCoords){
296 typename TAAPos::ValueType v;
298 for(
int i = 0; i < numSrcCoords; ++i)
307 vrtsOut.push_back(vrt);
317 int minNumCoords = min(numSrcCoords, numDestCoords);
322 typename TAAPos::ValueType v;
325 for(iMin = 0; iMin < minNumCoords; ++iMin)
329 for(
int i = iMin; i < numSrcCoords; ++i)
333 for(
int i = iMin; i < numDestCoords; ++i)
338 UG_LOG(
"GridReaderVTU::create_vertices: Failed to read vertex.\n");
344 vrtsOut.push_back(vrt);
358 rapidxml::xml_node<>* dataNode,
367 string str(dataNode->value(), dataNode->value_size());
368 stringstream ss(str, ios_base::in);
379 dataOut.push_back(d);
385 check_indices(std::vector<T>& inds,
size_t first,
size_t num,
size_t validSize)
388 "Bad index range encountered during parsing of " << m_filename);
390 for(
size_t i = first; i < num; ++i){
392 "Bad index encountered during parsing of " << m_filename);
location name
Definition: checkpoint_util.lua:128
callback that always returns true
Definition: basic_callbacks.h:50
Base-class for edges.
Definition: grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
the generic attachment-accessor for access to grids attachment pipes.
Definition: grid.h:182
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
size_t num() const
Definition: grid_impl.hpp:230
void detach_from_vertices(IAttachment &attachment)
Definition: grid.h:787
geometry_traits< TGeomObj >::iterator begin()
Definition: grid_impl.hpp:164
bool has_vertex_attachment(IAttachment &attachment)
Definition: grid.h:798
void set_options(uint options)
Definition: grid.cpp:701
void attach_to_vertices(IAttachment &attachment, bool passOnValues)
Definition: grid.h:728
geometry_traits< TGeomObj >::iterator create(GridObject *pParent=NULL)
create a custom element.
Definition: grid_impl.hpp:69
geometry_traits< TGeomObj >::iterator end()
Definition: grid_impl.hpp:175
uint get_options() const
Definition: grid.cpp:706
Grants read access to vtu (vtk) files.
Definition: file_io_vtu.h:191
size_t num_grids() const
returns the number of grids in the given file
Definition: file_io_vtu.h:200
bool parse_file(const char *filename)
parses an xml file
Definition: file_io_vtu.cpp:451
bool subset_handler(ISubsetHandler &shOut, size_t refGridIndex, size_t subsetHandlerIndex)
fills the given subset-handler
Definition: file_io_vtu.cpp:592
bool create_vertices(std::vector< Vertex * > &vrtsOut, Grid &grid, rapidxml::xml_node<> *vrtNode, TAAPos aaPos)
creates vertices from a vertex-node.
Definition: file_io_vtu_impl.h:267
void read_scalar_data(std::vector< T > &dataOut, rapidxml::xml_node<> *dataNode, bool clearData=true)
Definition: file_io_vtu_impl.h:357
bool grid(Grid &gridOut, size_t index, TPositionAttachment &aPos)
returns the i-th grid.
Definition: file_io_vtu_impl.h:212
void check_indices(std::vector< T > &inds, size_t first, size_t num, size_t max)
Definition: file_io_vtu_impl.h:385
Grants write access to vtu files.
Definition: file_io_vtu.h:87
Mode m_pointDataMode
Definition: file_io_vtu.h:171
void write_data_array_footer()
Definition: file_io_vtu.cpp:195
Mode m_pieceMode
Definition: file_io_vtu.h:170
std::ostream * m_pout
Definition: file_io_vtu.h:169
std::vector< std::pair< ISubsetHandler *, std::string > > m_pieceSubsetHandlers
Definition: file_io_vtu.h:178
void set_stream(std::ostream *out)
Pass a pointer to an ostream to which the data shall be written.
Definition: file_io_vtu.cpp:153
void write_data_array_header(const char *type, const char *name, int numberOfComponents)
Definition: file_io_vtu.cpp:181
@ NONE
Definition: file_io_vtu.h:164
@ OPEN
Definition: file_io_vtu.h:165
Mode m_cellDataMode
Definition: file_io_vtu.h:172
bool new_piece(Grid &grid, ISubsetHandler *psh, TPositionAttachment &aPos)
Definition: file_io_vtu_impl.h:97
void write_vector_data(Grid &grid, TAttachment aData, const char *name="", typename Grid::traits< TElem >::callback consider_elem=ConsiderAll())
Definition: file_io_vtu_impl.h:165
Grid * m_curGrid
Definition: file_io_vtu.h:174
void finish()
Definition: file_io_vtu.cpp:380
std::vector< GridObject * > m_cells
Definition: file_io_vtu.h:177
std::ostream & out_stream()
Definition: file_io_vtu_impl.h:89
void end_piece()
Definition: file_io_vtu.cpp:358
void write_cells(std::vector< GridObject * > &cells, Grid &grid, AAVrtIndex aaInd)
Definition: file_io_vtu.cpp:286
ISubsetHandler * m_curSH
Definition: file_io_vtu.h:175
void add_subset_handler(ISubsetHandler &sh, const std::string &name)
You may add subset-handlers which will be written as regions to the vtk-file.
Definition: file_io_vtu.cpp:172
void collect_cells(std::vector< GridObject * > &cellsOut, Grid &grid, typename Grid::traits< TElem >::callback consider_elem=ConsiderAll())
Definition: file_io_vtu_impl.h:193
Definition: subset_handler_interface.h:223
Element callback that returns true, if an element is not contained in a subset.
Definition: subset_callbacks.h:68
A basic vertex-type.
Definition: grid_objects_0d.h:62
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
void AssignIndices(TIterator begin, TIterator end, TAAInt &aaInt, int baseIndex=0)
assigns indices to the elements between begin and end.
Definition: attachment_util_impl.hpp:178
@ GRIDOPT_NONE
Definition: grid_constants.h:91
#define UG_LOG(msg)
Definition: log.h:367
unsigned int uint
Definition: types.h:114
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
std::pair< counting_iterator< size_t >, counting_iterator< size_t > > vertices(ug::BidirectionalMatrix< T > const &M)
Definition: bidirectional_boost.h:60
Definition: smart_pointer.h:814
bool SaveGridToVTU(Grid &grid, ISubsetHandler *psh, const char *filename, TAPosition &aPos)
Writes a grid to a vtu (vtk unstructured mesh) file.
Definition: file_io_vtu_impl.h:67
bool LoadGridFromVTU(Grid &grid, ISubsetHandler &sh, const char *filename)
Reads a grid to a vtu (vtk unstructured mesh) file.
Definition: file_io_vtu.cpp:103
T value_type
Definition: sparsematrix_interface.h:2
boost::function< bool(base_object *)> callback
callback type for the elements base type.
Definition: grid.h:150
geometry_traits< TElem >::iterator iterator
Definition: grid.h:143