forked from Slicer/SlicerGitSVNArchive
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vtkMRMLHierarchyStorageNode.cxx
154 lines (119 loc) · 4.43 KB
/
vtkMRMLHierarchyStorageNode.cxx
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*=auto=========================================================================
Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved.
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Program: 3D Slicer
Module: $RCSfile: vtkMRMLFiducialListStorageNode.cxx,v $
Date: $Date: 2006/03/17 15:10:10 $
Version: $Revision: 1.6 $
=========================================================================auto=*/
#include "vtkMRMLHierarchyStorageNode.h"
#include "vtkMRMLHierarchyNode.h"
#include "vtkMRMLScene.h"
#include <vtkObjectFactory.h>
#include <vtkStringArray.h>
//------------------------------------------------------------------------------
vtkMRMLNodeNewMacro(vtkMRMLHierarchyStorageNode);
//----------------------------------------------------------------------------
vtkMRMLHierarchyStorageNode::vtkMRMLHierarchyStorageNode()
{
this->DefaultWriteFileExtension = "txt";
}
//----------------------------------------------------------------------------
vtkMRMLHierarchyStorageNode::~vtkMRMLHierarchyStorageNode() = default;
//----------------------------------------------------------------------------
void vtkMRMLHierarchyStorageNode::PrintSelf(ostream& os, vtkIndent indent)
{
vtkMRMLStorageNode::PrintSelf(os,indent);
}
//----------------------------------------------------------------------------
bool vtkMRMLHierarchyStorageNode::CanReadInReferenceNode(vtkMRMLNode *refNode)
{
return refNode->IsA("vtkMRMLHierarchyNode");
}
//----------------------------------------------------------------------------
int vtkMRMLHierarchyStorageNode::ReadDataInternal(vtkMRMLNode *refNode)
{
std::string fullName = this->GetFullNameFromFileName();
if (fullName.empty())
{
vtkErrorMacro("vtkMRMLHierarchyStorageNode: File name not specified");
return 0;
}
// cast the input node
vtkMRMLHierarchyNode *hierarchyNode = nullptr;
if ( refNode->IsA("vtkMRMLHierarchyNode") )
{
hierarchyNode = dynamic_cast <vtkMRMLHierarchyNode *> (refNode);
}
if (hierarchyNode == nullptr)
{
vtkErrorMacro("ReadData: unable to cast input node " << refNode->GetID() << " to a hierarchy node");
return 0;
}
// open the file for reading input
fstream fstr;
fstr.open(fullName.c_str(), fstream::in);
if (fstr.is_open())
{
//turn off modified events
int modFlag = hierarchyNode->GetDisableModifiedEvent();
hierarchyNode->DisableModifiedEventOn();
// do the reading here if necessary, but it's not right now
hierarchyNode->SetDisableModifiedEvent(modFlag);
hierarchyNode->InvokeEvent(vtkMRMLScene::NodeAddedEvent, hierarchyNode);
fstr.close();
}
else
{
vtkErrorMacro("ERROR opening file " << this->FileName << endl);
return 0;
}
// make sure that the list node points to this storage node
//-------------------------> hierarchyNode->SetAndObserveStorageNodeID(this->GetID());
return 1;
}
//----------------------------------------------------------------------------
int vtkMRMLHierarchyStorageNode::WriteDataInternal(vtkMRMLNode *refNode)
{
std::string fullName = this->GetFullNameFromFileName();
if (fullName.empty())
{
vtkErrorMacro("vtkMRMLHierarchyStorageNode: File name not specified");
return 0;
}
// cast the input node
vtkMRMLHierarchyNode *hierarchyNode = nullptr;
if ( refNode->IsA("vtkMRMLHierarchyNode") )
{
hierarchyNode = dynamic_cast <vtkMRMLHierarchyNode *> (refNode);
}
if (hierarchyNode == nullptr)
{
vtkErrorMacro("WriteData: unable to cast input node " << refNode->GetID() << " to a known hierarchy node");
return 0;
}
// open the file for writing
fstream of;
of.open(fullName.c_str(), fstream::out);
if (!of.is_open())
{
vtkErrorMacro("WriteData: unable to open file " << fullName.c_str() << " for writing");
return 0;
}
// put down a header
of << "# hierarchy file " << (this->GetFileName() != nullptr ? this->GetFileName() : "null") << endl;
of.close();
this->StageWriteData(refNode);
return 1;
}
//----------------------------------------------------------------------------
void vtkMRMLHierarchyStorageNode::InitializeSupportedReadFileTypes()
{
this->SupportedReadFileTypes->InsertNextValue("Text (.txt)");
}
//----------------------------------------------------------------------------
void vtkMRMLHierarchyStorageNode::InitializeSupportedWriteFileTypes()
{
this->SupportedWriteFileTypes->InsertNextValue("Text (.txt)");
}