Loading...
Searching...
No Matches
VTKStreamer.tpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25namespace bitpit{
26
37template<class T>
41
47template<class T>
49 m_ptr = &data;
50}
51
59template<class T>
60void VTKBaseStreamer::flushValue( std::fstream &str, VTKFormat format, const T &value) const {
61
62 if( format==VTKFormat::ASCII){
63 genericIO::flushASCII( str, value) ;
64
65 } else if( format==VTKFormat::APPENDED) {
66 genericIO::flushBINARY( str, value) ;
67
68 }
69
70}
71
80template<class T>
81void VTKBaseStreamer::flushValue( std::fstream &str, VTKFormat format, const T *values, int nValues) const {
82
83 if( format==VTKFormat::ASCII){
84 genericIO::flushASCII( str, values, nValues) ;
85
86 } else if( format==VTKFormat::APPENDED) {
87 genericIO::flushBINARY( str, values, nValues) ;
88
89 } else {
90 throw std::runtime_error("VTK format not supported.") ;
91
92 }
93
94}
95
102template<class T>
103void VTKVectorContainer<T>::flushData( std::fstream &str, VTKFormat format){
104
105 if( format==VTKFormat::ASCII){
106 genericIO::flushASCII( str, 8, *m_ptr) ;
107
108 } else if( format==VTKFormat::APPENDED) {
109 genericIO::flushBINARY( str, *m_ptr) ;
110
111 } else {
112 throw std::runtime_error("VTK format not supported.") ;
113
114 }
115
116}
117
126template<class T>
127void VTKVectorContainer<T>::absorbData( std::fstream &str, VTKFormat format, uint64_t entries, uint8_t components){
128
129 resize( std::is_fundamental<T>{}, entries, components) ;
130
131 if( format==VTKFormat::ASCII){
132 genericIO::absorbASCII( str, *m_ptr) ;
133
134 } else if( format==VTKFormat::APPENDED) {
135 genericIO::absorbBINARY( str, *m_ptr) ;
136
137 }
138
139}
140
147template<class T>
148void VTKVectorContainer<T>::resize( std::true_type, uint64_t entries, uint8_t components){
149
150 BITPIT_UNUSED(components) ;
151 m_ptr->resize(entries) ;
152
153}
154
161template<class T >
162void VTKVectorContainer<T>::resize( std::false_type, uint64_t entries, uint8_t components){
163
164 uint64_t elements = entries /components ;
165 m_ptr->resize(elements) ;
166
167 for( auto & element : (*m_ptr) ){
168 vtk::allocate( element, components) ;
169 }
170
171}
172
179template<class T>
180void VTKNativeStreamer::addData( const std::string &name, std::vector<T> &data ){
181
182 auto fieldItr = m_field.find(name) ;
183
184 if( fieldItr!=m_field.end() ){
185 m_field.erase(fieldItr) ;
186 }
187
188 std::unique_ptr<VTKBaseContainer> temp = std::unique_ptr<VTKBaseContainer>( new VTKVectorContainer<T>(data) ) ;
189 m_field.emplace( name, std::move(temp) ) ;
190
191}
192
193}
void flushValue(std::fstream &, VTKFormat, const T &value) const
void addData(const std::string &, std::vector< T > &)
Implementation of VTKBaseContainer in order to support natively std::vector in VTK.
Definition VTK.hpp:194
void absorbData(std::fstream &, VTKFormat, uint64_t, uint8_t) override
VTKVectorContainer * clone() const override
VTKVectorContainer(std::vector< T > &)
void flushData(std::fstream &, VTKFormat) override
void resize(std::true_type, uint64_t, uint8_t)
VTKFormat
Definition VTK.hpp:92
#define BITPIT_UNUSED(variable)
Definition compiler.hpp:63
void flushASCII(std::fstream &str, const uint8_t &data)
Definition GenericIO.cpp:37
void absorbBINARY(std::fstream &str, data_T &data)
void absorbASCII(std::fstream &str, data_T &data)
void flushBINARY(std::fstream &str, const data_T &data)
void allocate(std::vector< T > &, int)
Definition VTKUtils.tpp:20
--- layout: doxygen_footer ---