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 126
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
/**
* @class vtkCellGridIOQuery
* @brief Serialize/deserialize vtkCellMetadata records.
*
* vtkCellGridIOQuery is a concrete subclass of vtkCellGridQuery that helps
* serialize/deserialize vtkCellGrid objects to/from JSON.
* Specifically, it reads/writes data specific to subclasses of vtkCellMetadata.
*
* @sa
* vtkCellGridQuery
*/
#ifndef vtkCellGridIOQuery_h
#define vtkCellGridIOQuery_h
#include "vtkCellAttribute.h" // For vtkCellAttribute::CellTypeInfo
#include "vtkCellGridQuery.h"
#include "vtkIOCellGridModule.h" // For export macro
#include <vtk_nlohmannjson.h> // For API.
#include VTK_NLOHMANN_JSON(json.hpp) // For API.
VTK_ABI_NAMESPACE_BEGIN
class vtkDataArraySelection;
class vtkFieldData;
class vtkImageData;
class vtkStringArray;
class VTKIOCELLGRID_EXPORT vtkCellGridIOQuery : public vtkCellGridQuery
{
public:
static vtkCellGridIOQuery* New();
vtkTypeMacro(vtkCellGridIOQuery, vtkCellGridQuery);
void PrintSelf(ostream& os, vtkIndent indent) override;
///@name Deserialization Deserialization
///@{
/**
* Prepare to deserialize cell metadata from the given \a sourceData JSON object.
*
* Note that \a sourceData, \a attributeData, and \a attributeList must be kept
* alive for the duration of the query's execution; the query only references
* them (rather than copying them).
*/
void PrepareToDeserialize(const nlohmann::json& sourceData, const nlohmann::json& attributeData,
std::vector<vtkCellAttribute*>& attributeList);
///@}
///@name Serialization Serialization
///@{
/**
* Prepare to serialize cell metadata to the given \a parent JSON object.
*/
void PrepareToSerialize(nlohmann::json& destination, nlohmann::json& attributeData,
const std::unordered_map<vtkAbstractArray*, vtkStringToken>& arrayLocations);
///@}
///@name ResponderUtilities Responder utilities
///@{
/// Return the JSON object that is our source or target.
nlohmann::json* GetData() { return this->Data; }
/// Return the JSON object that holds attribute data.
nlohmann::json* GetAttributeData() { return this->AttributeData; }
/// Return the map of array pointers to the names of groups which contain them.
const std::unordered_map<vtkAbstractArray*, vtkStringToken>& GetArrayLocations() const
{
return this->ArrayLocations;
}
std::unordered_map<vtkAbstractArray*, vtkStringToken>& GetArrayLocations()
{
return this->ArrayLocations;
}
/// Return a vector of cell-attributes that matches AttributeData.
const std::vector<vtkCellAttribute*>& GetAttributeList() const { return *this->AttributeList; }
/// Return true if the query is serializing cells (as opposed to deserializing).
bool IsSerializing() const { return this->Serializing; }
/// Extract JSON array information into vtkCellAttribute::CellTypeInfo.
///
/// This is a helper intended to be called by responders.
/// It extracts data from \a jsonInfo specific to \a cellType
/// into the \a cellTypeInfo you pass in.
///
/// The \a jsonInfo object point to data for one cell-attribute's "cell-info" key.
bool ExtractCellTypeAttributeInfo(vtkCellGrid* grid, vtkCellAttribute::CellTypeInfo& cellTypeInfo,
const nlohmann::json& jsonInfo, vtkStringToken cellTypeName);
/// Insert vtkCellAttribute::CellTypeInfo into the given \a jsonInfo object
/// for the given \a cellTypeName.
///
/// This is a helper intended to be called by responders to insert
/// the base CellTypeInfo data into \a jsonInfo. If subclasses of
/// vtkCellMetadata ever insert subclasses of CellTypeInfo (not currently
/// supported), then they will also need to add information specific to
/// the subclass.
bool InsertCellTypeAttributeInfo(vtkCellGrid* grid,
const vtkCellAttribute::CellTypeInfo& cellTypeInfo, nlohmann::json& jsonInfo,
vtkStringToken cellTypeName);
/// Add a metadata entry for \a cellTypeName to the output.
nlohmann::json& AddMetadataEntry(vtkStringToken cellTypeName);
///@}
protected:
vtkCellGridIOQuery() = default;
~vtkCellGridIOQuery() override = default;
nlohmann::json* Data{ nullptr };
nlohmann::json* AttributeData{ nullptr };
std::vector<vtkCellAttribute*>* AttributeList;
std::unordered_map<vtkAbstractArray*, vtkStringToken> ArrayLocations;
bool Serializing{ true };
private:
vtkCellGridIOQuery(const vtkCellGridIOQuery&) = delete;
void operator=(const vtkCellGridIOQuery&) = delete;
};
VTK_ABI_NAMESPACE_END
#endif
|