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
vtkMRMLMarkupsJsonElement.h
Go to the documentation of this file.
1/*==============================================================================
2
3 Program: 3D Slicer
4
5 Portions (c) Copyright 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==============================================================================*/
17
18// Markups Module MRML storage nodes
19//
20// Helper objects for reading/writing markups from/to JSON file
21//
22
23#ifndef vtkMRMLMarkupsJsonElement_h
24#define vtkMRMLMarkupsJsonElement_h
25
26// Markups includes
27#include "vtkSlicerMarkupsModuleMRMLExport.h"
29
30#include "vtkSmartPointer.h"
31#include "vtkNew.h"
32
33#include <vector>
34
35class vtkCodedEntry;
36
39class VTK_SLICER_MARKUPS_MODULE_MRML_EXPORT vtkMRMLMarkupsJsonElement : public vtkObject
40{
41public:
43 vtkTypeMacro(vtkMRMLMarkupsJsonElement, vtkObject);
44 void PrintSelf(ostream& os, vtkIndent indent) override;
45
47 std::string GetSchema();
48
50 bool HasMember(const char* propertyName);
51
54 std::string GetStringProperty(const char* propertyName);
58 bool GetStringProperty(const char* propertyName, std::string& propertyValue);
59
61 bool GetBoolProperty(const char* propertyName);
62
66 bool GetDoubleProperty(const char* propertyName, double& propertyValue);
67
70 double GetDoubleProperty(const char* propertyName);
71
75 bool GetIntProperty(const char* propertyName, int& propertyValue);
76
79 int GetIntProperty(const char* propertyName);
80
83 bool GetVectorProperty(const char* propertyName, double* v, int numberOfComponents = 3);
84
89 bool GetMatrix4x4Property(const char* propertyName, double v[16], bool flipRasLps);
90
93 bool GetStringVectorProperty(const char* propertyName, std::vector<std::string>& arrayValues);
94
98 VTK_NEWINSTANCE
99 vtkCodedEntry* GetCodedEntryProperty(const char* propertyName);
100
104 VTK_NEWINSTANCE
105 vtkDoubleArray* GetDoubleArrayProperty(const char* propertyName);
106
109 bool GetArrayItemsStringProperty(const char* arrayName, const char* propertyName, std::vector<std::string>& propertyValues);
110
114 VTK_NEWINSTANCE
116
120 VTK_NEWINSTANCE
122
124 bool IsArray();
125
128
131 VTK_NEWINSTANCE
133
136
138 bool HasErrors();
139
140protected:
145
146 vtkNew<vtkMRMLMessageCollection> UserMessages;
147
148 class vtkInternal;
150 friend class vtkInternal;
152};
153
156class VTK_SLICER_MARKUPS_MODULE_MRML_EXPORT vtkMRMLMarkupsJsonReader : public vtkObject
157{
158public:
159
161 vtkTypeMacro(vtkMRMLMarkupsJsonReader, vtkObject);
162 void PrintSelf(ostream& os, vtkIndent indent) override;
163
167 VTK_NEWINSTANCE
169
172
174 bool HasErrors();
175
176protected:
181
182 vtkNew<vtkMRMLMessageCollection> UserMessages;
183};
184
185
188class VTK_SLICER_MARKUPS_MODULE_MRML_EXPORT vtkMRMLMarkupsJsonWriter : public vtkObject
189{
190public:
191
193 vtkTypeMacro(vtkMRMLMarkupsJsonWriter,vtkObject);
194 void PrintSelf(ostream& os, vtkIndent indent) override;
195
198 bool WriteToFileBegin(const char* filePath, const char* schema);
199
203
205 void WriteArrayPropertyStart(const std::string& propertyName);
208
213
215 void WriteObjectPropertyStart(const std::string& propertyName);
218
221 void WriteStringProperty(const std::string& propertyName, const std::string& propertyValue);
222 void WriteStringVectorProperty(const std::string& propertyName, const std::vector<std::string>& arrayValues);
223 void WriteCodedEntryProperty(const std::string& propertyName, vtkCodedEntry* codedEntry);
224 void WriteStringPropertyIfNotEmpty(const std::string& propertyName, const std::string& propertyValue);
225 void WriteBoolProperty(const std::string& propertyName, bool propertyValue);
226 void WriteIntProperty(const std::string& propertyName, int propertyValue);
227 void WriteDoubleProperty(const std::string& propertyName, double propertyValue);
228 void WriteVectorProperty(const std::string& propertyName, double* v, int numberOfComponents = 3);
229 void WriteMatrix4x4Property(const std::string& propertyName, double v[16], bool flipRasLps);
230 void WriteDoubleArrayProperty(const char* propertyName, vtkDoubleArray* doubleArray);
232
235
237 bool HasErrors();
238
239protected:
244
245 vtkNew<vtkMRMLMessageCollection> UserMessages;
246
247 class vtkInternal;
249 friend class vtkInternal;
250};
251
252#endif
Simple class for storing standard coded entries (coding scheme, value, meaning triplets)
Represents a json object or list.
double GetDoubleProperty(const char *propertyName)
VTK_NEWINSTANCE vtkMRMLMarkupsJsonElement * GetArrayItem(int childItemIndex)
bool GetVectorProperty(const char *propertyName, double *v, int numberOfComponents=3)
bool GetStringVectorProperty(const char *propertyName, std::vector< std::string > &arrayValues)
int GetArraySize()
Returns the number of elements in this array.
int GetIntProperty(const char *propertyName)
VTK_NEWINSTANCE vtkMRMLMarkupsJsonElement * GetArrayProperty(const char *arrayName)
bool GetDoubleProperty(const char *propertyName, double &propertyValue)
vtkMRMLMarkupsJsonElement(const vtkMRMLMarkupsJsonElement &)
bool GetArrayItemsStringProperty(const char *arrayName, const char *propertyName, std::vector< std::string > &propertyValues)
bool GetStringProperty(const char *propertyName, std::string &propertyValue)
bool HasErrors()
Returns true if user messages contain error messages.
bool GetIntProperty(const char *propertyName, int &propertyValue)
bool GetMatrix4x4Property(const char *propertyName, double v[16], bool flipRasLps)
VTK_NEWINSTANCE vtkDoubleArray * GetDoubleArrayProperty(const char *propertyName)
void operator=(const vtkMRMLMarkupsJsonElement &)
vtkNew< vtkMRMLMessageCollection > UserMessages
VTK_NEWINSTANCE vtkMRMLMarkupsJsonElement * GetObjectProperty(const char *objectName)
~vtkMRMLMarkupsJsonElement() override
VTK_NEWINSTANCE vtkCodedEntry * GetCodedEntryProperty(const char *propertyName)
std::string GetSchema()
Get the JSON schema name.
std::string GetStringProperty(const char *propertyName)
static vtkMRMLMarkupsJsonElement * New()
void PrintSelf(ostream &os, vtkIndent indent) override
bool GetBoolProperty(const char *propertyName)
Get Boolean property value.
bool HasMember(const char *propertyName)
Returns true if the JSON object contains a member by this name.
bool IsArray()
Returns true if this element is an array.
void PrintSelf(ostream &os, vtkIndent indent) override
void operator=(const vtkMRMLMarkupsJsonReader &)
vtkNew< vtkMRMLMessageCollection > UserMessages
~vtkMRMLMarkupsJsonReader() override
bool HasErrors()
Returns true if user messages contain error messages.
VTK_NEWINSTANCE vtkMRMLMarkupsJsonElement * ReadFromFile(const char *filePath)
vtkMRMLMarkupsJsonReader(const vtkMRMLMarkupsJsonReader &)
static vtkMRMLMarkupsJsonReader * New()
void PrintSelf(ostream &os, vtkIndent indent) override
vtkMRMLMarkupsJsonWriter(const vtkMRMLMarkupsJsonWriter &)
bool HasErrors()
Returns true if user messages contain error messages.
void WriteDoubleArrayProperty(const char *propertyName, vtkDoubleArray *doubleArray)
void WriteCodedEntryProperty(const std::string &propertyName, vtkCodedEntry *codedEntry)
void WriteStringProperty(const std::string &propertyName, const std::string &propertyValue)
void WriteStringPropertyIfNotEmpty(const std::string &propertyName, const std::string &propertyValue)
void WriteArrayPropertyEnd()
This method must be called when all array items are written.
void WriteMatrix4x4Property(const std::string &propertyName, double v[16], bool flipRasLps)
void WriteBoolProperty(const std::string &propertyName, bool propertyValue)
vtkNew< vtkMRMLMessageCollection > UserMessages
void WriteDoubleProperty(const std::string &propertyName, double propertyValue)
bool WriteToFileBegin(const char *filePath, const char *schema)
void operator=(const vtkMRMLMarkupsJsonWriter &)
~vtkMRMLMarkupsJsonWriter() override
static vtkMRMLMarkupsJsonWriter * New()
void WriteIntProperty(const std::string &propertyName, int propertyValue)
void WriteObjectEnd()
This method must be called when all properties of the object are written.
void WriteStringVectorProperty(const std::string &propertyName, const std::vector< std::string > &arrayValues)
void WriteObjectPropertyEnd()
This method must be called when all properties of the object are written.
void WriteObjectPropertyStart(const std::string &propertyName)
This method creates a new object as a property.
void WriteArrayPropertyStart(const std::string &propertyName)
This method creates a new array as a property.
void WriteObjectStart()
This method creates a new object in an array.
void WriteVectorProperty(const std::string &propertyName, double *v, int numberOfComponents=3)