Slicer 5.4
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
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
40class VTK_SLICER_MARKUPS_MODULE_MRML_EXPORT vtkMRMLMarkupsJsonElement : public vtkObject
41{
42public:
44 vtkTypeMacro(vtkMRMLMarkupsJsonElement, vtkObject);
45 void PrintSelf(ostream& os, vtkIndent indent) override;
46
48 std::string GetSchema();
49
51 bool HasMember(const char* propertyName);
52
55 std::string GetStringProperty(const char* propertyName);
59 bool GetStringProperty(const char* propertyName, std::string& propertyValue);
60
62 bool GetBoolProperty(const char* propertyName);
63
67 bool GetDoubleProperty(const char* propertyName, double& propertyValue);
68
71 double GetDoubleProperty(const char* propertyName);
72
76 bool GetIntProperty(const char* propertyName, int& propertyValue);
77
80 int GetIntProperty(const char* propertyName);
81
84 bool GetVectorProperty(const char* propertyName, double* v, int numberOfComponents = 3);
85
90 bool GetMatrix4x4Property(const char* propertyName, double v[16], bool flipRasLps);
91
94 bool GetStringVectorProperty(const char* propertyName, std::vector<std::string>& arrayValues);
95
99 VTK_NEWINSTANCE
100 vtkCodedEntry* GetCodedEntryProperty(const char* propertyName);
101
105 VTK_NEWINSTANCE
106 vtkDoubleArray* GetDoubleArrayProperty(const char* propertyName);
107
110 bool GetArrayItemsStringProperty(const char* arrayName, const char* propertyName, std::vector<std::string>& propertyValues);
111
115 VTK_NEWINSTANCE
117
121 VTK_NEWINSTANCE
123
125 bool IsArray();
126
129
132 VTK_NEWINSTANCE
134
136 vtkGetObjectMacro(UserMessages, vtkMRMLMessageCollection);
137
139 bool HasErrors();
140
141protected:
146
147 vtkNew<vtkMRMLMessageCollection> UserMessages;
148
149 class vtkInternal;
150 vtkInternal* Internal;
151 friend class vtkInternal;
153};
154
158class VTK_SLICER_MARKUPS_MODULE_MRML_EXPORT vtkMRMLMarkupsJsonReader : public vtkObject
159{
160public:
161
163 vtkTypeMacro(vtkMRMLMarkupsJsonReader, vtkObject);
164 void PrintSelf(ostream& os, vtkIndent indent) override;
165
169 VTK_NEWINSTANCE
171
173 vtkGetObjectMacro(UserMessages, vtkMRMLMessageCollection);
174
176 bool HasErrors();
177
178protected:
183
184 vtkNew<vtkMRMLMessageCollection> UserMessages;
185};
186
187
191class VTK_SLICER_MARKUPS_MODULE_MRML_EXPORT vtkMRMLMarkupsJsonWriter : public vtkObject
192{
193public:
194
196 vtkTypeMacro(vtkMRMLMarkupsJsonWriter,vtkObject);
197 void PrintSelf(ostream& os, vtkIndent indent) override;
198
201 bool WriteToFileBegin(const char* filePath, const char* schema);
202
206
208 void WriteArrayPropertyStart(const std::string& propertyName);
211
216
218 void WriteObjectPropertyStart(const std::string& propertyName);
221
224 void WriteStringProperty(const std::string& propertyName, const std::string& propertyValue);
225 void WriteStringVectorProperty(const std::string& propertyName, const std::vector<std::string>& arrayValues);
226 void WriteCodedEntryProperty(const std::string& propertyName, vtkCodedEntry* codedEntry);
227 void WriteStringPropertyIfNotEmpty(const std::string& propertyName, const std::string& propertyValue);
228 void WriteBoolProperty(const std::string& propertyName, bool propertyValue);
229 void WriteIntProperty(const std::string& propertyName, int propertyValue);
230 void WriteDoubleProperty(const std::string& propertyName, double propertyValue);
231 void WriteVectorProperty(const std::string& propertyName, double* v, int numberOfComponents = 3);
232 void WriteMatrix4x4Property(const std::string& propertyName, double v[16], bool flipRasLps);
233 void WriteDoubleArrayProperty(const char* propertyName, vtkDoubleArray* doubleArray);
235
237 vtkGetObjectMacro(UserMessages, vtkMRMLMessageCollection);
238
240 bool HasErrors();
241
242protected:
247
248 vtkNew<vtkMRMLMessageCollection> UserMessages;
249
250 class vtkInternal;
251 vtkInternal* Internal;
252 friend class vtkInternal;
253};
254
255#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.
Reads a JSON file into a vtkMRMLMarkupsJsonElement.
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()
Writes properties into a JSON file.
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)