-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathITKImageProcessingPlugin.cpp
398 lines (357 loc) · 14.1 KB
/
ITKImageProcessingPlugin.cpp
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/* ============================================================================
* Copyright (c) 2009-2016 BlueQuartz Software, LLC
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* Neither the name of BlueQuartz Software, the US Air Force, nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The code contained herein was partially funded by the following contracts:
* United States Air Force Prime Contract FA8650-10-D-5210
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
#include "ITKImageProcessingPlugin.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QString>
#include "SIMPLib/Filtering/FilterFactory.hpp"
#include "SIMPLib/Filtering/FilterManager.h"
#include "ITKImageProcessing/ITKImageProcessingConstants.h"
#include "ITKImageProcessing/ITKImageProcessingVersion.h"
#ifdef ITK_IMAGE_PROCESSING_HAVE_SCIFIO
#include "itkSCIFIOImageIOFactory.h"
#endif
#include <itkConfigure.h>
#define SIMPL_ITK_VERSION_CHECK (ITK_VERSION_MAJOR == 4)
#if SIMPL_ITK_VERSION_CHECK
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wself-assign-field"
#endif
#endif
#include <itkBMPImageIOFactory.h>
#include <itkBioRadImageIOFactory.h>
#include <itkGE4ImageIOFactory.h>
#include <itkGE5ImageIOFactory.h>
#include <itkGiplImageIOFactory.h>
#include <itkJPEGImageIOFactory.h>
#include <itkMRCImageIOFactory.h>
#include <itkMetaImageIOFactory.h>
#include <itkNiftiImageIOFactory.h>
#include <itkNrrdImageIOFactory.h>
#include <itkPNGImageIOFactory.h>
#include <itkStimulateImageIOFactory.h>
#include <itkTIFFImageIOFactory.h>
#include <itkVTKImageIOFactory.h>
#include "itksys/SystemTools.hxx"
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
ITKImageProcessingPlugin::ITKImageProcessingPlugin()
: m_Version(ITKImageProcessing::Version::Complete())
, m_CompatibilityVersion(ITKImageProcessing::Version::Package())
, m_Vendor("BlueQuartz Software")
, // Initialize ITKImageProcessing's Vendor Name Here
m_URL("http://www.github.com/bluequartzsoftware/ITKImageProcessing")
, // Initialize Company URL Here
m_Location("")
, // Initialize ITKImageProcessing library Location Here
m_Description("")
, // Initialize ITKImageProcessing's Description Here
m_Copyright("")
, // Initialize ITKImageProcessing's Copyright Here
m_Filters(QList<QString>())
, // Initialize ITKImageProcessing's List of Dependencies Here
m_DidLoad(false)
{
#ifdef ITK_IMAGE_PROCESSING_HAVE_SCIFIO
ITKImageProcessingPlugin::setSCIFIOEnvironmentVariables();
#endif
itk::JPEGImageIOFactory::RegisterOneFactory();
itk::NrrdImageIOFactory::RegisterOneFactory();
itk::PNGImageIOFactory::RegisterOneFactory();
itk::TIFFImageIOFactory::RegisterOneFactory();
itk::JPEGImageIOFactory::RegisterOneFactory();
itk::BMPImageIOFactory::RegisterOneFactory();
itk::MetaImageIOFactory::RegisterOneFactory();
itk::NiftiImageIOFactory::RegisterOneFactory();
itk::GiplImageIOFactory::RegisterOneFactory();
itk::VTKImageIOFactory::RegisterOneFactory();
itk::StimulateImageIOFactory::RegisterOneFactory();
itk::BioRadImageIOFactory::RegisterOneFactory();
itk::GE4ImageIOFactory::RegisterOneFactory();
itk::GE5ImageIOFactory::RegisterOneFactory();
itk::MRCImageIOFactory::RegisterOneFactory();
#ifdef ITK_IMAGE_PROCESSING_HAVE_SCIFIO
itk::SCIFIOImageIOFactory::RegisterOneFactory();
#endif
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
ITKImageProcessingPlugin::~ITKImageProcessingPlugin() = default;
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ITKImageProcessingPlugin::setSCIFIOEnvironmentVariables()
{
QString applicationDir = QCoreApplication::applicationDirPath();
#ifndef WIN32
QFileInfo fi = QFileInfo(applicationDir);
applicationDir = fi.absolutePath(); // Goes up one directory (bin/..)
#endif
std::string SCIFIO_PATH = std::string("SCIFIO_PATH=") + applicationDir.toStdString() + "/lib/jars";
itksys::SystemTools::PutEnv(SCIFIO_PATH);
std::string JAVA_HOME = std::string("JAVA_HOME=") + applicationDir.toStdString() + "/lib/jre";
itksys::SystemTools::PutEnv(JAVA_HOME);
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getListSupportedReadExtensions()
{
QStringList supportedExtensions;
std::list<itk::LightObject::Pointer> allobjects = itk::ObjectFactoryBase::CreateAllInstance("itkImageIOBase");
if(!allobjects.empty())
{
for(std::list<itk::LightObject::Pointer>::iterator ii = allobjects.begin(); ii != allobjects.end(); ++ii)
{
itk::ImageIOBase* io = dynamic_cast<itk::ImageIOBase*>(ii->GetPointer());
itk::ImageIOBase::ArrayOfExtensionsType currentExtensions = io->GetSupportedReadExtensions();
for(size_t jj = 0; jj < currentExtensions.size(); jj++)
{
supportedExtensions << currentExtensions[jj].c_str();
}
}
}
return "*" + supportedExtensions.join(" *");
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getListSupportedWriteExtensions()
{
QStringList supportedExtensions;
std::list<itk::LightObject::Pointer> allobjects = itk::ObjectFactoryBase::CreateAllInstance("itkImageIOBase");
if(!allobjects.empty())
{
for(std::list<itk::LightObject::Pointer>::iterator ii = allobjects.begin(); ii != allobjects.end(); ++ii)
{
itk::ImageIOBase* io = dynamic_cast<itk::ImageIOBase*>(ii->GetPointer());
itk::ImageIOBase::ArrayOfExtensionsType currentExtensions = io->GetSupportedWriteExtensions();
for(size_t jj = 0; jj < currentExtensions.size(); jj++)
{
supportedExtensions << currentExtensions[jj].c_str();
}
}
}
return "*" + supportedExtensions.join(" *");
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QStringList ITKImageProcessingPlugin::getList2DSupportedFileExtensions()
{
QStringList supportedExtensions;
supportedExtensions << ".png"
<< ".tif"
<< ".jpg"
<< ".jpeg"
<< ".bmp";
return supportedExtensions;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getPluginFileName()
{
return ITKImageProcessingConstants::ITKImageProcessingPluginFile;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getPluginDisplayName()
{
return ITKImageProcessingConstants::ITKImageProcessingPluginDisplayName;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getPluginBaseName()
{
return ITKImageProcessingConstants::ITKImageProcessingBaseName;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getVersion()
{
return m_Version;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getCompatibilityVersion()
{
return m_CompatibilityVersion;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getVendor()
{
return m_Vendor;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getURL()
{
return m_URL;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getLocation()
{
return m_Location;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getDescription()
{
/* PLEASE UPDATE YOUR PLUGIN'S DESCRIPTION FILE.
It is located at ITKImageProcessing/Resources/ITKImageProcessing/ITKImageProcessingDescription.txt */
QFile licenseFile(":/ITKImageProcessing/ITKImageProcessingDescription.txt");
QFileInfo licenseFileInfo(licenseFile);
QString text = "<<--Description was not read-->>";
if(licenseFileInfo.exists())
{
if(licenseFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream in(&licenseFile);
text = in.readAll();
}
}
return text;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getCopyright()
{
return m_Copyright;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString ITKImageProcessingPlugin::getLicense()
{
/* PLEASE UPDATE YOUR PLUGIN'S LICENSE FILE.
It is located at ITKImageProcessing/Resources/ITKImageProcessing/ITKImageProcessingLicense.txt */
QFile licenseFile(":/ITKImageProcessing/ITKImageProcessingLicense.txt");
QFileInfo licenseFileInfo(licenseFile);
QString text = "<<--License was not read-->>";
if(licenseFileInfo.exists())
{
if(licenseFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream in(&licenseFile);
text = in.readAll();
}
}
return text;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QMap<QString, QString> ITKImageProcessingPlugin::getThirdPartyLicenses()
{
QMap<QString, QString> licenseMap;
QList<QString> fileStrList;
fileStrList.push_back(":/ThirdParty/HDF5.txt");
fileStrList.push_back(":/ThirdParty/Qt.txt");
fileStrList.push_back(":/ThirdParty/Qwt.txt");
for(QList<QString>::iterator iter = fileStrList.begin(); iter != fileStrList.end(); iter++)
{
QFile file(*iter);
QFileInfo licenseFileInfo(file);
if(licenseFileInfo.exists())
{
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream in(&file);
licenseMap.insert(licenseFileInfo.baseName(), in.readAll());
}
}
}
return licenseMap;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool ITKImageProcessingPlugin::getDidLoad()
{
return m_DidLoad;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ITKImageProcessingPlugin::setDidLoad(bool didLoad)
{
m_DidLoad = didLoad;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ITKImageProcessingPlugin::setLocation(QString filePath)
{
m_Location = filePath;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ITKImageProcessingPlugin::writeSettings(QSettings& prefs)
{
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ITKImageProcessingPlugin::readSettings(QSettings& prefs)
{
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ITKImageProcessingPlugin::registerFilterWidgets(FilterWidgetManager* fwm)
{
}
#include "ITKImageProcessingFilters/RegisterKnownFilters.cpp"
#if SIMPL_ITK_VERSION_CHECK
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
#undef SIMPL_ITK_VERSION_CHECK