1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkGenericIOUtilities.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkGenericIOUtilities -- Utility functions for GenericIO readers
//
// .SECTION Description
// This file provides some common utility functions that are used in the
// implementation of GenericIO readers.
#ifndef vtkGenericIOUtilities_h
#define vtkGenericIOUtilities_h
#include "vtkType.h"
#include <algorithm>
#include <functional>
#include <string>
#include "mpi.h"
class vtkMultiProcessController;
class vtkDataArray;
namespace gio {
class GenericIOReader;
class GenericIOWriter;
}
namespace vtkGenericIOUtilities {
//==============================================================================
// Description:
// Trims leading whitespace from a string.
inline std::string <rim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
//==============================================================================
// Description:
// Trims trailing whitespace from a string.
inline std::string &rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(),
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
return s;
}
//==============================================================================
// Description:
// Trims leading & trailing whitespace from a string.
inline std::string &trim(std::string &s) {
return ltrim(rtrim(s));
}
//==============================================================================
// Description:
// Returns the corresponding MPI communicator for the multi-process
// controller used by this instance.
MPI_Comm GetMPICommunicator(vtkMultiProcessController *mpc);
//==============================================================================
// Description:
// This method parses the data in the rawbuffer and reads it into a vtkDataArray
// that can be attached as vtkPointData to a vtkDataSet, in this case, a
// vtkUnstructuredGrid that consists of the particles.
vtkDataArray* GetVtkDataArray(
std::string name, int type, void* rawBuffer, int N);
//==============================================================================
// Description:
// This method accesses the user-supplied buffer at the given index and
// returns the data as a vtkIdType. It is intended as a convenience method
// to allow the user to access the data in an agnostic-type fashion.
vtkIdType GetIdFromRawBuffer(
const int type, void* buffer, vtkIdType buffer_idx);
//==============================================================================
// Description:
// This method accesses the user-supplied buffer at the given index and
// returns the data as a double. It is intended as a convenience method
// to allow the user to access the data in an agnostic-type fashion.
double GetDoubleFromRawBuffer(
const int type, void* buffer, vtkIdType buffer_idx);
//==============================================================================
// Description:
// This method constructs and returns the underlying GenericIO reader.
gio::GenericIOReader* GetReader(
MPI_Comm comm, bool posix, int distribution, const std::string& fileName);
//==============================================================================
// Description:
// This method constructs and returns the underlying GenericIO writer.
// The returned writer will have its filename set already
gio::GenericIOWriter* GetWriter(MPI_Comm comm,const std::string& fileName);
//==============================================================================
// Description:
// If the pointer given is non-null this function deletes the string and
// set the pointer to NULL. This sets the pointer variable in the calling
// function since the pointer is passed by reference.
inline void SafeDeleteString(char* & str)
{
if(str != NULL)
{
delete [] str;
str = NULL;
}
}
}
#endif /* vtkGenericIOUtilities_h */
|