MCPcopy Create free account
hub / github.com/Kitware/VTK / WriteDataArrayFallback

Function WriteDataArrayFallback

IO/XML/vtkXMLWriter.cxx:273–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271// Specialize for vtkDataArrays, which implicitly cast everything to double:
272template <class ValueType>
273void WriteDataArrayFallback(ValueType*, vtkDataArray* array, WriteBinaryDataBlockWorker& worker)
274{
275 // generic implementation for fixed component length arrays.
276 size_t blockWords = worker.Writer->GetBlockSize() / worker.OutWordSize;
277
278 // Prepare a buffer to move through the data.
279 std::vector<unsigned char> buffer(blockWords * worker.MemWordSize);
280 size_t wordsLeft = worker.NumWords;
281
282 if (buffer.empty())
283 {
284 // No data -- bail here, since the calls to buffer[0] below will segfault.
285 worker.Result = false;
286 return;
287 }
288
289 vtkIdType nComponents = array->GetNumberOfComponents();
290
291 // Do the complete blocks.
292 vtkXMLWriterHelper::SetProgressPartial(worker.Writer, 0);
293 worker.Result = true;
294 vtkIdType valueIdx = 0;
295 while (worker.Result && (wordsLeft >= blockWords))
296 {
297 // Copy data to contiguous buffer:
298 ValueType* bufferIter = reinterpret_cast<ValueType*>(buffer.data());
299 for (size_t i = 0; i < blockWords; ++i, ++valueIdx)
300 {
301 *bufferIter++ =
302 static_cast<ValueType>(array->GetComponent(valueIdx / nComponents, valueIdx % nComponents));
303 }
304
305 if (!vtkXMLWriterHelper::WriteBinaryDataBlock(
306 worker.Writer, buffer.data(), blockWords, worker.WordType))
307 {
308 worker.Result = false;
309 }
310 wordsLeft -= blockWords;
311 vtkXMLWriterHelper::SetProgressPartial(
312 worker.Writer, static_cast<float>(worker.NumWords - wordsLeft) / worker.NumWords);
313 }
314
315 // Do the last partial block if any.
316 if (worker.Result && (wordsLeft > 0))
317 {
318 ValueType* bufferIter = reinterpret_cast<ValueType*>(buffer.data());
319 for (size_t i = 0; i < wordsLeft; ++i, ++valueIdx)
320 {
321 *bufferIter++ =
322 static_cast<ValueType>(array->GetComponent(valueIdx / nComponents, valueIdx % nComponents));
323 }
324
325 if (!vtkXMLWriterHelper::WriteBinaryDataBlock(
326 worker.Writer, buffer.data(), wordsLeft, worker.WordType))
327 {
328 worker.Result = false;
329 }
330 }

Callers 1

Calls 6

WriteBinaryDataBlockFunction · 0.85
GetBlockSizeMethod · 0.80
emptyMethod · 0.45
GetNumberOfComponentsMethod · 0.45
dataMethod · 0.45
GetComponentMethod · 0.45

Tested by

no test coverage detected