Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
vtkMRMLTableStorageNode.h
Go to the documentation of this file.
1/*==============================================================================
2
3 Program: 3D Slicer
4
5 Portions (c) Copyright 2015 Brigham and Women's Hospital (BWH) All Rights Reserved.
6
7 See COPYRIGHT.txt
8 or http://www.slicer.org/copyright/copyright.txt for details.
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 This file was originally developed by Andras Lasso (PerkLab, Queen's
17 University) and Kevin Wang (Princess Margaret Hospital, Toronto) and was
18 supported through OCAIRO and the Applied Cancer Research Unit program of
19 Cancer Care Ontario.
20
21==============================================================================*/
22
23#ifndef __vtkMRMLTableStorageNode_h
24#define __vtkMRMLTableStorageNode_h
25
26#include "vtkMRMLStorageNode.h"
27
29class vtkTable;
30
44class VTK_MRML_EXPORT vtkMRMLTableStorageNode : public vtkMRMLStorageNode
45{
46public:
49 void PrintSelf(ostream& os, vtkIndent indent) override;
50
52
54 const char* GetNodeTagName() override {return "TableStorage";}
55
57 bool CanReadInReferenceNode(vtkMRMLNode *refNode) override;
58
60 static bool WriteTable(std::string filename, vtkTable* table, std::string delimiter,
61 std::map<vtkIdType, std::vector<std::string>> componentNamesMap);
62
63public:
65 virtual void SetSchemaFileName(const char* schemaFileName);
66 virtual std::string GetSchemaFileName();
67
69 std::string FindSchemaFileName(const char* fileName);
70
73 vtkSetMacro(AutoFindSchema, bool);
74 vtkGetMacro(AutoFindSchema, bool);
75 vtkBooleanMacro(AutoFindSchema, bool);
76
80 vtkSetMacro(ReadLongNameAsTitle, bool);
81 vtkGetMacro(ReadLongNameAsTitle, bool);
82 vtkBooleanMacro(ReadLongNameAsTitle, bool);
83
84protected:
89
92
95
97 int ReadDataInternal(vtkMRMLNode *refNode) override;
98
100 int WriteDataInternal(vtkMRMLNode *refNode) override;
101
102 std::string GenerateSchemaFileName(const char* fileName);
103
104 virtual std::string GetFieldDelimiterCharacters(std::string filename);
105
106 // Struct for managing column information
108 {
109 std::string ColumnName;
110 std::vector<vtkAbstractArray*> RawComponentArrays;
111 int ScalarType = VTK_STRING;
112 std::vector<std::string> ComponentNames;
113 std::string NullValueString;
114 };
116
120 std::vector<ColumnInfo> GetColumnInfo(vtkMRMLTableNode* tableNode, vtkTable* rawTable);
121
123 void FillDataFromStringArray(vtkStringArray* stringComponentArray, vtkDataArray* dataArray, std::string nullValueString="");
124
127 void AddColumnToTable(vtkTable* table, ColumnInfo columnInfo);
128
129 bool ReadSchema(std::string filename, vtkMRMLTableNode* tableNode);
130 bool ReadTable(std::string filename, vtkMRMLTableNode* tableNode);
131
132 bool WriteSchema(std::string filename, vtkMRMLTableNode* tableNode);
133
136};
137
138#endif
MRML node to represent a table object.
struct StructColumnInfo ColumnInfo
std::string FindSchemaFileName(const char *fileName)
Finds schema file corresponding to a table file.
void FillDataFromStringArray(vtkStringArray *stringComponentArray, vtkDataArray *dataArray, std::string nullValueString="")
Casts the data in the string array to the correct type and stores it in the data array.
bool ReadTable(std::string filename, vtkMRMLTableNode *tableNode)
int WriteDataInternal(vtkMRMLNode *refNode) override
Write data from a referenced node. Returns 0 on failure.
vtkMRMLNode * CreateNodeInstance() override
Create instance of the default node. Like New only virtual.
int ReadDataInternal(vtkMRMLNode *refNode) override
Read data and set it in the referenced node. Returns 0 on failure.
virtual std::string GetSchemaFileName()
virtual void SetSchemaFileName(const char *schemaFileName)
Get/Set schema file name, which contain description of data type of each column.
~vtkMRMLTableStorageNode() override
vtkMRMLTableStorageNode(const vtkMRMLTableStorageNode &)
void operator=(const vtkMRMLTableStorageNode &)
void PrintSelf(ostream &os, vtkIndent indent) override
void AddColumnToTable(vtkTable *table, ColumnInfo columnInfo)
std::vector< ColumnInfo > GetColumnInfo(vtkMRMLTableNode *tableNode, vtkTable *rawTable)
void InitializeSupportedWriteFileTypes() override
Initialize all the supported write file types.
bool CanReadInReferenceNode(vtkMRMLNode *refNode) override
Return true if the node can be read in.
virtual std::string GetFieldDelimiterCharacters(std::string filename)
static bool WriteTable(std::string filename, vtkTable *table, std::string delimiter, std::map< vtkIdType, std::vector< std::string > > componentNamesMap)
Helper function to write out table to file.
const char * GetNodeTagName() override
Get node XML tag name (like Storage, Model)
std::string GenerateSchemaFileName(const char *fileName)
static vtkMRMLTableStorageNode * New()
bool WriteSchema(std::string filename, vtkMRMLTableNode *tableNode)
bool ReadSchema(std::string filename, vtkMRMLTableNode *tableNode)
void InitializeSupportedReadFileTypes() override
Initialize all the supported write file types.
std::vector< vtkAbstractArray * > RawComponentArrays