forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkImageReader2Factory.cxx
184 lines (162 loc) · 5.17 KB
/
vtkImageReader2Factory.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImageReader2Factory.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkImageReader2Factory.h"
#include "vtkToolkits.h" // VTK_USE_METAIO
#include "vtkBMPReader.h"
#include "vtkGESignaReader.h"
#include "vtkImageReader2.h"
#include "vtkImageReader2Collection.h"
#include "vtkJPEGReader.h"
#include "vtkMINCImageReader.h"
#include "vtkObjectFactory.h"
#include "vtkObjectFactoryCollection.h"
#include "vtkPNGReader.h"
#include "vtkPNMReader.h"
#include "vtkSLCReader.h"
#include "vtkTIFFReader.h"
#ifdef VTK_USE_METAIO
#include "vtkMetaImageReader.h"
#endif
// Destroying the prototype readers requires information keys.
// Include the manager here to make sure the keys are not destroyed
// until after the AvailableReaders singleton has been destroyed.
#include "vtkFilteringInformationKeyManager.h"
vtkStandardNewMacro(vtkImageReader2Factory);
class vtkImageReader2FactoryCleanup
{
public:
inline void Use()
{
}
~vtkImageReader2FactoryCleanup()
{
if(vtkImageReader2Factory::AvailableReaders)
{
vtkImageReader2Factory::AvailableReaders->Delete();
vtkImageReader2Factory::AvailableReaders = 0;
}
}
};
static vtkImageReader2FactoryCleanup vtkImageReader2FactoryCleanupGlobal;
vtkImageReader2Collection* vtkImageReader2Factory::AvailableReaders;
void vtkImageReader2Factory::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Available Readers : ";
if(AvailableReaders)
{
AvailableReaders->PrintSelf(os, indent);
}
else
{
os << "None.";
}
}
vtkImageReader2Factory::vtkImageReader2Factory()
{
}
vtkImageReader2Factory::~vtkImageReader2Factory()
{
}
void vtkImageReader2Factory::RegisterReader(vtkImageReader2* r)
{
vtkImageReader2Factory::InitializeReaders();
AvailableReaders->AddItem(r);
}
vtkImageReader2* vtkImageReader2Factory::CreateImageReader2(const char* path)
{
vtkImageReader2Factory::InitializeReaders();
vtkImageReader2* ret;
vtkCollection* collection = vtkCollection::New();
vtkObjectFactory::CreateAllInstance("vtkImageReaderObject",
collection);
vtkObject* o;
// first try the current registered object factories to see
// if one of them can
for(collection->InitTraversal(); (o = collection->GetNextItemAsObject()); )
{
if(o)
{
ret = vtkImageReader2::SafeDownCast(o);
if(ret && ret->CanReadFile(path))
{
return ret;
}
}
}
// get rid of the collection
collection->Delete();
vtkCollectionSimpleIterator sit;
for(vtkImageReader2Factory::AvailableReaders->InitTraversal(sit);
(ret = vtkImageReader2Factory::AvailableReaders->GetNextImageReader2(sit));)
{
if(ret->CanReadFile(path))
{
// like a new call
return ret->NewInstance();
}
}
return 0;
}
void vtkImageReader2Factory::InitializeReaders()
{
if(vtkImageReader2Factory::AvailableReaders)
{
return;
}
vtkImageReader2FactoryCleanupGlobal.Use();
vtkImageReader2Factory::AvailableReaders = vtkImageReader2Collection::New();
vtkImageReader2* reader;
vtkImageReader2Factory::AvailableReaders->
AddItem((reader = vtkPNGReader::New()));
reader->Delete();
vtkImageReader2Factory::AvailableReaders->
AddItem((reader = vtkPNMReader::New()));
reader->Delete();
vtkImageReader2Factory::AvailableReaders->
AddItem((reader = vtkTIFFReader::New()));
reader->Delete();
vtkImageReader2Factory::AvailableReaders->
AddItem((reader = vtkBMPReader::New()));
reader->Delete();
vtkImageReader2Factory::AvailableReaders->
AddItem((reader = vtkSLCReader::New()));
reader->Delete();
vtkImageReader2Factory::AvailableReaders->
AddItem((reader = vtkJPEGReader::New()));
reader->Delete();
vtkImageReader2Factory::AvailableReaders->
AddItem((reader = vtkGESignaReader::New()));
reader->Delete();
vtkImageReader2Factory::AvailableReaders->
AddItem((reader = vtkMINCImageReader::New()));
reader->Delete();
#ifdef VTK_USE_METAIO
vtkImageReader2Factory::AvailableReaders->
AddItem((reader = vtkMetaImageReader::New()));
reader->Delete();
#endif
}
void vtkImageReader2Factory::GetRegisteredReaders(vtkImageReader2Collection* collection)
{
vtkImageReader2Factory::InitializeReaders();
// get all dynamic readers
vtkObjectFactory::CreateAllInstance("vtkImageReaderObject",
collection);
// get the current registered readers
vtkImageReader2* ret;
vtkCollectionSimpleIterator sit;
for(vtkImageReader2Factory::AvailableReaders->InitTraversal(sit);
(ret = vtkImageReader2Factory::AvailableReaders->GetNextImageReader2(sit));)
{
collection->AddItem(ret);
}
}