SMILX  1.01
milxQtFile.cpp
1 /*=========================================================================
2  The Software is copyright (c) Commonwealth Scientific and Industrial Research Organisation (CSIRO)
3  ABN 41 687 119 230.
4  All rights reserved.
5 
6  Licensed under the CSIRO BSD 3-Clause License
7  You may not use this file except in compliance with the License.
8  You may obtain a copy of the License in the file LICENSE.md or at
9 
10  https://stash.csiro.au/projects/SMILI/repos/smili/browse/license.txt
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 =========================================================================*/
18 #include "milxQtFile.h"
19 
20 #include <zlib.h>
21 
22 #include <QFileInfo>
23 //VTK
24 #include <vtkImageFlip.h>
25 #include <vtkImageCast.h>
26 #include <vtkOBJReader.h>
27 #include <vtkOBJExporter.h>
28 #include <vtkPLYReader.h>
29 #include <vtkPLYWriter.h>
30 #include <vtkSTLReader.h>
31 #include <vtkSTLWriter.h>
32 #include <vtkPolyDataReader.h>
33 #include <vtkUnstructuredGridReader.h>
34 #include <vtkGeometryFilter.h>
35 #include <vtkPolyDataWriter.h>
36 #include <vtkXMLPolyDataReader.h>
37 #include <vtkXMLPolyDataWriter.h>
38 #include <vtkXMLImageDataReader.h>
39 #include <vtkXMLImageDataWriter.h>
40 #include <vtkPNMReader.h>
42 #include <itkImage.h>
43 #include <itkImageFileReader.h>
44 #include <itkImageFileWriter.h>
45 #include <itkPNGImageIOFactory.h>
46 #include <itkJPEGImageIOFactory.h>
47 #include <itkBMPImageIOFactory.h>
48 #include <itkNrrdImageIOFactory.h>
49 #include <itkRawImageIO.h>
50 
51 #include "itkImageToVTKImageFilter.h"
52 #include "itkVTKImageToImageFilter.h"
53 
54 milxQtFile::milxQtFile(QObject *theParent) : QFile(theParent)
55 {
56  //Allocate critical variables
57  observeProgress = itkEventQtObserver::New();
58  Connector = vtkSmartPointer<vtkEventQtSlotConnect>::New();
59 
60  name = "Empty";
61  dataPixelType = "scalar";
62  dataComponentType = "float";
63  dataDimensions = milx::imgDimension;
64  dataComponents = 1;
65 
67  linkProgressEventOf(milx::ProgressUpdates->GetUpdateObject()); //link itk observer propagator
68 }
69 
71 {
72  //dtor
73 }
74 
75 bool milxQtFile::openImage(const QString filename, vtkImageData* data)
76 {
77  QFileInfo fileInfo(filename);
78  QString extension = fileInfo.suffix().toLower();
79  bool charFormat = false, integerFormat = false, vtkFormat = false, medical = true;
80  int bounds[6];
81 
82  const QString charStr = "unsigned char";
83  const QString typeStr = data->GetScalarTypeAsString();
84 
85  if(extension == "png" || extension == "jpg" || extension == "jpeg" || extension == "bmp")
86  {
87  charFormat = true;
88  medical = false;
89  }
90  else if(typeStr == charStr || typeStr == "unsigned_char")
91  {
92  charFormat = true;
93  itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<unsigned char, 3>::New() );
94  }
95  else if(typeStr == "unsigned" || typeStr == "unsigned_short" || typeStr == "short" || typeStr == "unsigned short" || typeStr == "unsigned_int" || typeStr == "unsigned int" || typeStr == "int") //16-bit or 32-bit integers
96  integerFormat = true;
97  else if(extension == "vti")
98  {
99  vtkFormat = true;
100  }
101  else
102  itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<float, 3>::New() );
103 
105  vtkSmartPointer<vtkImageFlip> imageReorient = vtkSmartPointer<vtkImageFlip>::New();
106  vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
107 
108  if(charFormat)
109  {
110  if(!medical)
111  {
112  //Add some default image types
113  itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<unsigned char,2>::New() );
114  itk::ObjectFactoryBase::RegisterFactory( itk::PNGImageIOFactory::New() );
115  itk::ObjectFactoryBase::RegisterFactory( itk::JPEGImageIOFactory::New() );
116  itk::ObjectFactoryBase::RegisterFactory( itk::BMPImageIOFactory::New() );
117  }
118 
119  charImageType::Pointer charImg = milx::File::ReadImageUsingITK<charImageType>(filename.toStdString());
120 
121  if(!charImg)
122  return false;
123 
125  #if VTK_MAJOR_VERSION <=5
126  imageReorient->SetInput(milx::Image<charImageType>::ConvertITKImageToVTKImage(charImg));
127  #else
128  imageReorient->SetInputData(milx::Image<charImageType>::ConvertITKImageToVTKImage(charImg));
129  #endif // VTK_MAJOR_VERSION
130  }
131  else if(vtkFormat)
132  {
133  vtkSmartPointer<vtkXMLImageDataReader> reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
134 
135  if(reader->CanReadFile(filename.toStdString().c_str()))
136  {
137  reader->SetFileName(filename.toStdString().c_str());
138  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
139  linkProgressEventOf(reader);
140  reader->Update();
141 
142  if(!errorObserver->ReportsFailure())
143  {
144  data->DeepCopy(reader->GetOutput());
145  data->GetExtent(bounds);
146  }
147  else
148  {
149  cerr << "VTI Reader Encountered the following error." << endl;
150  cerr << errorObserver->GetMessage() << endl;
151  return false;
152  }
153  }
154  else
155  {
156  cerr << "Could not load VTI file!" << endl;
157  return false;
158  }
159  }
160  else if(integerFormat)
161  {
162  intImageType::Pointer intImg = milx::File::ReadImageUsingITK<intImageType>(filename.toStdString());
163 
164  if(!intImg)
165  return false;
166 
168 #if VTK_MAJOR_VERSION <=5
169  imageReorient->SetInput(milx::Image<intImageType>::ConvertITKImageToVTKImage(intImg));
170 #else
171  imageReorient->SetInputData(milx::Image<intImageType>::ConvertITKImageToVTKImage(intImg));
172 #endif // VTK_MAJOR_VERSION
173  }
174  else
175  {
176  floatImageType::Pointer floatImg = milx::File::ReadImageUsingITK<floatImageType>(filename.toStdString());
177 
178  if(!floatImg)
179  return false;
180 
182  #if VTK_MAJOR_VERSION <=5
183  imageReorient->SetInput(milx::Image<floatImageType>::ConvertITKImageToVTKImage(floatImg));
184  #else
185  imageReorient->SetInputData(milx::Image<floatImageType>::ConvertITKImageToVTKImage(floatImg));
186  #endif // VTK_MAJOR_VERSION
187  }
188 
189  if(!vtkFormat)
190  {
191  imageReorient->SetFilteredAxis(1);
192  imageReorient->FlipAboutOriginOn();
193 
194  linkProgressEventOf(imageReorient);
195  imageReorient->Update();
196  data->DeepCopy(imageReorient->GetOutput());
197  }
198 
199  return true;
200 }
201 
203 {
204  QString exts = "";
205  vector<string> extensions = milx::File::GetSupportedImageFileExtensions();
206 
207  for(size_t j = 0; j < extensions.size(); j ++)
208  exts += "*" + QString(extensions[j].c_str()) + " ";
209 
210  return exts;
211 }
212 
213 bool milxQtFile::is8BitFormat(const QString filename, bool &errorEncountered)
214 {
215  std::string pixelType, componentType;
216  errorEncountered = false;
217 
218  //Check type of medical image
219  if(!milx::File::ReadImageInformation(filename.toStdString(), pixelType, componentType, dataDimensions))
220  {
221  cerr << "Failed reading header of image. File may not be an image. Exiting" << endl;
222  errorEncountered = true;
223  return false;
224  }
225  dataPixelType = pixelType.c_str();
226  dataComponentType = componentType.c_str();
227 
228  if(componentType == "unsigned_char" || componentType == "unsigned char")
229  return true;
230 
231  return false;
232 }
233 
234 bool milxQtFile::is32BitFormat(const QString filename, bool &errorEncountered)
235 {
236  std::string pixelType, componentType;
237  errorEncountered = false;
238 
239  //Check type of medical image
240  if(!milx::File::ReadImageInformation(filename.toStdString(), pixelType, componentType, dataDimensions))
241  {
242  cerr << "Failed reading header of image. File may not be an image. Exiting" << endl;
243  errorEncountered = true;
244  return false;
245  }
246  dataPixelType = pixelType.c_str();
247  dataComponentType = componentType.c_str();
248 
249  if(componentType == "unsigned" || componentType == "unsigned_short" || componentType == "short" || componentType == "unsigned short" || componentType == "unsigned_int" || componentType == "unsigned int" || componentType == "int")
250  return true;
251 
252  return false;
253 }
254 
255 bool milxQtFile::isFieldFormat(const QString filename, bool &errorEncountered)
256 {
257  std::string pixelType, componentType;
258  errorEncountered = false;
259 
260  //Check type of medical image
261  if(!milx::File::ReadImageInformation(filename.toStdString(), pixelType, componentType, dataDimensions))
262  {
263  cerr << "Failed reading header of image. File may not be an image. Exiting" << endl;
264  errorEncountered = true;
265  return false;
266  }
267  dataPixelType = pixelType.c_str();
268  dataComponentType = componentType.c_str();
269 
270  if(pixelType == "vector")
271  return true;
272 
273  return false;
274 }
275 
276 bool milxQtFile::openImage(const QString filename, milxQtImage* data)
277 {
278  QFileInfo fileInfo(filename);
279  QString extension = fileInfo.suffix().toLower();
280  bool charFormat = false, integerFormat = false, vtkFormat = false, deformField = false, rgbImage = false, pnmImage = false;
281 
282  if(extension == "png" || extension == "jpg" || extension == "jpeg" || extension == "bmp")
283  {
284  //Add some default image types
285  itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<unsigned char,2>::New() );
286  itk::ObjectFactoryBase::RegisterFactory( itk::PNGImageIOFactory::New() );
287  itk::ObjectFactoryBase::RegisterFactory( itk::JPEGImageIOFactory::New() );
288  itk::ObjectFactoryBase::RegisterFactory( itk::BMPImageIOFactory::New() );
289  }
290  else if(extension == "vti")
291  {
292  vtkFormat = true;
293  }
294  else if(extension == "pbm" || extension == "pgm" || extension == "ppm")
295  {
296  pnmImage = true;
297  }
298 
299  if(!vtkFormat && !pnmImage)
300  {
301  cout << "Trying to read image header ..." << endl;
302  //Check type of medical image
303  std::string pixelType, componentType;
304  if(!milx::File::ReadImageInformation(filename.toStdString(), pixelType, componentType, dataDimensions))
305  {
306  cerr << "Failed reading header of image. File may not be an image. Exiting" << endl;
307  return false;
308  }
309  dataPixelType = pixelType.c_str();
310  dataComponentType = componentType.c_str();
311 
312  if((componentType == "unsigned_char" && pixelType == "scalar") || (componentType == "unsigned char" && pixelType == "scalar"))
313  {
314  cout << "Found 8-bit image ..." << endl;
315  charFormat = true;
316  }
317  else if(componentType == "unsigned" || componentType == "unsigned_short" || componentType == "short" || componentType == "unsigned short" || componentType == "unsigned_int" || componentType == "unsigned int" || componentType == "int") //16-bit or 32-bit integers
318  {
319  cout << "Found integer-type image ..." << endl;
320  integerFormat = true;
321  }
322  else if(pixelType == "vector")
323  deformField = true;
324  else if( (pixelType == "rgb" || pixelType == "rgba") && componentType == "unsigned_char" )
325  rgbImage = true;
326 
328  }
329 
330 // cerr << "Open Image" << endl;
331  vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
332  if(charFormat)
333  {
334  charImageType::Pointer charImg;
335 
336  if( !milx::File::OpenImage<charImageType>(filename.toStdString(), charImg) )
337  return false;
338 
339  data->SetInput(charImg, true);
340  }
341  else if(integerFormat)
342  {
343  intImageType::Pointer intImg;
344 
345  if(!milx::File::OpenImage<intImageType>(filename.toStdString(), intImg))
346  return false;
347 
348  data->SetInput(intImg, true);
349  }
350  else if(vtkFormat)
351  {
352  vtkSmartPointer<vtkXMLImageDataReader> reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
353 
354  if(reader->CanReadFile(filename.toStdString().c_str()))
355  {
356  reader->SetFileName(filename.toStdString().c_str());
357  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
358  linkProgressEventOf(reader);
359  reader->Update();
360 
361  if(!errorObserver->ReportsFailure())
362  data->SetInput(reader->GetOutput());
363  else
364  {
365  cerr << "VTI Reader Encountered the following error." << endl;
366  cerr << errorObserver->GetMessage() << endl;
367  return false;
368  }
369  }
370  else
371  {
372  cerr << "Could not load VTI file!" << endl;
373  return false;
374  }
375  }
376  else if(pnmImage)
377  {
378  vtkSmartPointer<vtkPNMReader> reader = vtkSmartPointer<vtkPNMReader>::New();
379 
380  if(reader->CanReadFile(filename.toStdString().c_str()))
381  {
382  reader->SetFileName(filename.toStdString().c_str());
383  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
384  linkProgressEventOf(reader);
385  reader->Update();
386 
387  if(!errorObserver->ReportsFailure())
388  {
389  cout << "Image Description: " << reader->GetDescriptiveName() << endl;
390  data->SetInput(reader->GetOutput());
391  }
392  else
393  {
394  cerr << "PNM Reader Encountered the following error." << endl;
395  cerr << errorObserver->GetMessage() << endl;
396  return false;
397  }
398  }
399  else
400  {
401  cerr << "Could not load PNM file!" << endl;
402  return false;
403  }
404  }
405  else if(deformField) //Read vector images
406  {
407  itk::ObjectFactoryBase::RegisterFactory( itk::NrrdImageIOFactory::New() );
408 
409  vectorImageType::Pointer vecImg;
410 
411  if( !milx::File::OpenImage<vectorImageType>(filename.toStdString(), vecImg) )
412  return false;
413 
414  dataComponents = vecImg->GetNumberOfComponentsPerPixel();
415 
416  data->SetInput(vecImg, true);
417  }
418 #if (ITK_VERSION_MAJOR > 3)
419  else if(dataDimensions > 3)
420  {
421  vectorImageType::Pointer vecImg;
422 
423  typedef itk::Image<floatPixelType, 4> float4DImageType;
424  if( !milx::File::OpenAsVectorImage<float4DImageType, 3>(filename.toStdString(), vecImg) )
425  return false;
426 
427  dataComponents = vecImg->GetNumberOfComponentsPerPixel();
428 
429  data->SetInput(vecImg, true);
430  }
431 #endif
432  else if(rgbImage)
433  {
434  rgbImageType::Pointer rgbImg;
435 
436  if( !milx::File::OpenImage<rgbImageType>(filename.toStdString(), rgbImg) )
437  return false;
438 
439  data->SetInput(rgbImg, true);
440  }
441  else
442  {
443  floatImageType::Pointer floatImg;
444 
445  if( !milx::File::OpenImage<floatImageType>(filename.toStdString(), floatImg) )
446  return false;
447 
448  data->SetInput(floatImg, true);
449  }
450 
451  return true;
452 }
453 
454 bool milxQtFile::openImageSeries(milxQtImage* data, QString directoryPath)
455 {
456  bool success = true;
457  QPointer<QFileDialog> fileOpener = new QFileDialog;
458  QSettings settings("Shekhar Chandra", "milxQt");
459 
461  if(directoryPath.isEmpty())
462  {
463  QString path = settings.value("recentPath").toString();
464  directoryPath = fileOpener->getExistingDirectory(NULL, tr("Open DICOM Directory"),
465  path,
466  QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
467  }
468 
469  if(directoryPath.isEmpty())
470  return !success;
471 
473  std::vector<std::string> UIDs = milx::File::GetDICOMSeriesUIDs(directoryPath.toStdString());
474 
475  std::string seriesName;
476  if(UIDs.size() > 1) //ask user which one to load
477  {
478  QLabel *uidLabel = new QLabel;
479  uidLabel->setText("<b>Select Series</b>");
480  QLabel *uidInfoLabel = new QLabel;
481  uidInfoLabel->setText("Multiple DICOM Series Found. Please choose one:");
482  QComboBox *uidComboBox = new QComboBox;
483  for(size_t j = 0; j < UIDs.size(); j ++)
484  uidComboBox->insertItem(j, UIDs[j].c_str());
485  QPushButton *uidButton = new QPushButton;
486  uidButton->setText("OK");
487 
488  QVBoxLayout *uidLayout = new QVBoxLayout;
489  uidLayout->addWidget(uidLabel);
490  uidLayout->addWidget(uidInfoLabel);
491  uidLayout->addWidget(uidComboBox);
492  uidLayout->addWidget(uidButton);
493 
494  QDialog *uidWidget = new QDialog;
495  uidWidget->setWindowTitle("Select Series to Load");
496  uidWidget->setLayout(uidLayout);
497  uidWidget->setModal(true);
498  QObject::connect(uidButton, SIGNAL(clicked()), uidWidget, SLOT(accept()));
499  uidWidget->exec();
500 
501  seriesName = uidComboBox->currentText().toStdString();
502  delete uidWidget;
503  }
504  else if(UIDs.empty())
505  {
506  cerr << "Error. No DICOM series was found in directory" << endl;
507  return false;
508  }
509  else
510  seriesName = UIDs.begin()->c_str();
511 
512  cout << "Reading series as float images" << endl;
513  std::string caseID;
514  std::string echoID = "";
515  std::string seriesID = "";
516  std::string acqID = "";
517  std::string instanceID = "";
518  intImageType::Pointer intImg;
519  milx::File::OpenDICOMSeries<intImageType>(directoryPath.toStdString(), intImg, seriesName, caseID, echoID, seriesID, acqID, instanceID);
520  data->SetInput(intImg, false);
521  data->setName(seriesName.c_str());
522  cout << "Completed Reading Series: " << seriesName << endl;
523 
524  //save path
525  QFileInfo fi(directoryPath);
526  settings.setValue("recentPath",fi.absolutePath());
527 
528  return success;
529 }
530 
531 bool milxQtFile::saveImage(const QString filename, vtkImageData* data)
532 {
533  QFileInfo fileInfo(filename);
534  QString extension = fileInfo.suffix().toLower();
535  bool charFormat = false, integerFormat = false, medical = true, vtkFormat = false, success = false;
536  int bounds[6];
537 
538  const QString charStr = "unsigned char";
539  const QString typeStr = data->GetScalarTypeAsString();
540 
541  if(extension == "png" || extension == "jpg" || extension == "jpeg" || extension == "bmp")
542  {
543  charFormat = true;
544  medical = false;
545  }
546  else if(typeStr == charStr || typeStr == "unsigned_char")
547  {
548  charFormat = true;
549  itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<unsigned char, 3>::New() );
550  }
551  else if(typeStr == "unsigned" || typeStr == "unsigned_short" || typeStr == "short" || typeStr == "unsigned short" || typeStr == "unsigned_int" || typeStr == "unsigned int" || typeStr == "int")
552  {
553  integerFormat = true;
554  }
555  else
556  itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<float, 3>::New() );
557 
558  data->GetExtent(bounds);
559 
560  if(extension == "vti")
561  vtkFormat = true;
562 
564  vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
565  vtkSmartPointer<vtkImageFlip> imageReorient = vtkSmartPointer<vtkImageFlip>::New();
566  #if VTK_MAJOR_VERSION <=5
567  imageReorient->SetInputConnection(data->GetProducerPort());
568  #else
569  imageReorient->SetInputData(data);
570  #endif
571  imageReorient->SetFilteredAxis(1);
572  imageReorient->FlipAboutOriginOn();
573  linkProgressEventOf(imageReorient);
574  imageReorient->Update();
575 
576  if(charFormat)
577  {
578  if(!medical)
579  {
580  //Add some default image types
581  itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<unsigned char, 2>::New() );
582  itk::ObjectFactoryBase::RegisterFactory( itk::PNGImageIOFactory::New() );
583  itk::ObjectFactoryBase::RegisterFactory( itk::JPEGImageIOFactory::New() );
584  itk::ObjectFactoryBase::RegisterFactory( itk::BMPImageIOFactory::New() );
585 //
587  typedef itk::Image<rgbPixelType, 2> rgbImageSliceType;
588  rgbImageSliceType::Pointer charImg = milx::Image<rgbImageSliceType>::ConvertVTKImageToITKImage(imageReorient->GetOutput());
589  success = milx::File::WriteImageUsingITK<rgbImageSliceType>(filename.toStdString(), charImg);
590  }
591  else
592  {
594  rgbImageType::Pointer charImg = milx::Image<rgbImageType>::ConvertVTKImageToITKImage(imageReorient->GetOutput());
595  success = milx::File::WriteImageUsingITK<rgbImageType>(filename.toStdString(), charImg);
596  }
597  }
598  else if(vtkFormat)
599  {
600  vtkSmartPointer<vtkXMLImageDataWriter> writer = vtkSmartPointer<vtkXMLImageDataWriter>::New();
601  #if VTK_MAJOR_VERSION <=5
602  writer->SetInput(data);
603  #else
604  writer->SetInputData(data);
605  #endif
606  writer->SetFileName(filename.toStdString().c_str());
607  writer->SetDataModeToBinary();
608  writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
609  linkProgressEventOf(writer);
610  writer->Write();
611 
612  if(errorObserver->ReportsFailure())
613  {
614  cerr << "VTI Writer Encountered the following error." << endl;
615  cerr << errorObserver->GetMessage() << endl;
616  }
617  else
618  success = true;
619  }
620  else if(integerFormat)
621  {
623  intImageType::Pointer intImg = milx::Image<intImageType>::ConvertVTKImageToITKImage(imageReorient->GetOutput());
624 
625  success = milx::File::WriteImageUsingITK<intImageType>(filename.toStdString(), intImg);
626  }
627  else
628  {
630  floatImageType::Pointer floatImg = milx::Image<floatImageType>::ConvertVTKImageToITKImage(imageReorient->GetOutput());
631 
632  success = milx::File::WriteImageUsingITK<floatImageType>(filename.toStdString(), floatImg);
633  }
634 
635  return success;
636 }
637 
638 bool milxQtFile::saveImage(const QString filename, milxQtImage* data)
639 {
640  QFileInfo fileInfo(filename);
641  QString extension = fileInfo.suffix().toLower();
642  bool charFormat = false, integerFormat = false, medical = true, rgbFormat = false, vtkFormat = false, success = false;
643 
644  if(extension == "png" || extension == "jpg" || extension == "jpeg" || extension == "bmp")
645  {
646  charFormat = true;
647  medical = false;
648  }
649  else if(data->is8BitImage())
650  {
651  charFormat = true;
652  itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<unsigned char,3>::New() );
653  }
654  else if(data->is32BitImage())
655  {
656  integerFormat = true;
657  }
658  else if(data->isRGBImage())
659  {
660  rgbFormat = true;
661  }
662  else
663  itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<float,3>::New() );
664 
665  if(extension == "vti")
666  vtkFormat = true;
667  else if(data->isVTKImage())
668  {
669  vtkFormat = false;
670  vtkSmartPointer<vtkImageCast> castVTKImage = vtkSmartPointer<vtkImageCast>::New();
671  castVTKImage->SetOutputScalarTypeToFloat();
672  #if VTK_MAJOR_VERSION <=5
673  castVTKImage->SetInput(data->GetOutput());
674  #else
675  castVTKImage->SetInputData(data->GetOutput());
676  #endif // VTK_MAJOR_VERSION
677  castVTKImage->Update();
678 
679  vtkSmartPointer<vtkImageFlip> imageReorient = vtkSmartPointer<vtkImageFlip>::New();
680  #if VTK_MAJOR_VERSION <=5
681  imageReorient->SetInput(castVTKImage->GetOutput());
682  #else
683  imageReorient->SetInputData(castVTKImage->GetOutput());
684  #endif
685  imageReorient->SetFilteredAxis(1);
686  imageReorient->FlipAboutOriginOn();
687  linkProgressEventOf(imageReorient);
688  imageReorient->Update();
689 
690  cout << "Converted VTK Image to ITK Image since saving requested medical image format" << endl;
691  floatImageType::Pointer ITKImage = milx::Image<floatImageType>::ConvertVTKImageToITKImage(imageReorient->GetOutput());
692  data->SetInput(ITKImage);
693  data->generateImage();
694  }
695 
696  vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
697  if(vtkFormat)
698  {
699  vtkSmartPointer<vtkXMLImageDataWriter> writer = vtkSmartPointer<vtkXMLImageDataWriter>::New();
700  #if VTK_MAJOR_VERSION <=5
701  writer->SetInput(data->GetOutput());
702  #else
703  writer->SetInputData(data->GetOutput());
704  #endif // VTK_MAJOR_VERSION
705  writer->SetFileName(filename.toStdString().c_str());
706  writer->SetDataModeToBinary();
707  linkProgressEventOf(writer);
708  writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
709  writer->Write();
710 
711  if(errorObserver->ReportsFailure())
712  {
713  cerr << "VTI Writer Encountered the following error." << endl;
714  cerr << errorObserver->GetMessage() << endl;
715  }
716  else
717  success = true;
718  }
719  else if(charFormat)
720  {
721  if(!medical)
722  {
723  //Add some default image types
724  itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<unsigned char, 2>::New() );
725  itk::ObjectFactoryBase::RegisterFactory( itk::PNGImageIOFactory::New() );
726  itk::ObjectFactoryBase::RegisterFactory( itk::JPEGImageIOFactory::New() );
727  itk::ObjectFactoryBase::RegisterFactory( itk::BMPImageIOFactory::New() );
728  }
729 
730  success = milx::File::WriteImageUsingITK<charImageType>(filename.toStdString(), data->GetCharImage());
731  }
732  else if(integerFormat)
733  {
734  success = milx::File::WriteImageUsingITK<intImageType>(filename.toStdString(), data->GetIntImage());
735  }
736  else if(rgbFormat)
737  {
738  success = milx::File::WriteImageUsingITK<rgbImageType>(filename.toStdString(), data->GetRGBImage());
739  }
740  else if(data->isVectorImage())
741  {
742  success = milx::File::WriteImageUsingITK<vectorImageType>(filename.toStdString(), data->GetVectorImage());
743  }
744  else
745  {
746  success = milx::File::WriteImageUsingITK<floatImageType>(filename.toStdString(), data->GetFloatImage());
747  }
748 
749  return success;
750 }
751 
752 bool milxQtFile::openModel(const QString filename, vtkPolyData* data)
753 {
754  bool legacy = false, wavefront = false, stanford = false, stereoLith = false;
755  QFileInfo fileInfo(filename);
756  QString extension = fileInfo.suffix().toLower();
757 
758  if(extension == "vtk")
759  legacy = true; //Load legacy VTK file
760  else if(extension == "obj")
761  wavefront = true;
762  else if(extension == "ply")
763  stanford = true;
764  else if(extension == "stl")
765  stereoLith = true;
766 
767  vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
768  if(legacy)
769  {
770  //Check legacy data type
771  vtkSmartPointer<vtkDataReader> dreader = vtkSmartPointer<vtkDataReader>::New();
772  dreader->SetFileName(filename.toStdString().c_str());
773  dreader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
774  linkProgressEventOf(dreader);
775  dreader->OpenVTKFile();
776  dreader->ReadHeader();
777  dreader->CloseVTKFile();
778 
779  if(dreader->IsFileUnstructuredGrid())
780  {
781  vtkSmartPointer<vtkUnstructuredGridReader> reader = vtkSmartPointer<vtkUnstructuredGridReader>::New();
782  reader->SetFileName(filename.toStdString().c_str());
783  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
784  linkProgressEventOf(reader);
785  reader->Update();
786 
787  vtkSmartPointer<vtkGeometryFilter> geometryFilter = vtkSmartPointer<vtkGeometryFilter>::New();
788  geometryFilter->SetInputConnection(reader->GetOutputPort());
789  linkProgressEventOf(geometryFilter);
790  geometryFilter->Update();
791 
792  if(!errorObserver->ReportsFailure())
793  data->DeepCopy(geometryFilter->GetOutput());
794  else
795  {
796  cerr << "Reader Encountered the following error." << endl;
797  cerr << errorObserver->GetMessage() << endl;
798  return false;
799  }
800  }
801  else
802  {
803  vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
804  reader->SetFileName(filename.toStdString().c_str());
805  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
806  linkProgressEventOf(reader);
807  reader->Update();
808 
809  if(!errorObserver->ReportsFailure())
810  data->DeepCopy(reader->GetOutput());
811  else
812  {
813  cerr << "Reader Encountered the following error." << endl;
814  cerr << errorObserver->GetMessage() << endl;
815  return false;
816  }
817  }
818  }
819  else if(wavefront)
820  {
821  vtkSmartPointer<vtkOBJReader> reader = vtkSmartPointer<vtkOBJReader>::New();
822  reader->SetFileName(filename.toStdString().c_str());
823  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
824  linkProgressEventOf(reader);
825  reader->Update();
826 
827  if(!errorObserver->ReportsFailure())
828  data->DeepCopy(reader->GetOutput());
829  else
830  {
831  cerr << "Reader Encountered the following error." << endl;
832  cerr << errorObserver->GetMessage() << endl;
833  return false;
834  }
835  }
836  else if(stanford)
837  {
838  vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
839  reader->SetFileName(filename.toStdString().c_str());
840  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
841  linkProgressEventOf(reader);
842  reader->Update();
843 
844  if(!errorObserver->ReportsFailure())
845  data->DeepCopy(reader->GetOutput());
846  else
847  {
848  cerr << "Reader Encountered the following error." << endl;
849  cerr << errorObserver->GetMessage() << endl;
850  return false;
851  }
852  }
853  else if(stereoLith)
854  {
855  vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
856  reader->SetFileName(filename.toStdString().c_str());
857  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
858  linkProgressEventOf(reader);
859  reader->Update();
860 
861  if(!errorObserver->ReportsFailure())
862  data->DeepCopy(reader->GetOutput());
863  else
864  {
865  cerr << "Reader Encountered the following error." << endl;
866  cerr << errorObserver->GetMessage() << endl;
867  return false;
868  }
869  }
870  else
871  {
872  vtkSmartPointer<vtkXMLPolyDataReader> reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
873  reader->SetFileName(filename.toStdString().c_str());
874  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
875  linkProgressEventOf(reader);
876  reader->Update();
877  if(!errorObserver->ReportsFailure())
878  data->DeepCopy(reader->GetOutput());
879  else
880  {
881  cerr << "Reader Encountered the following error." << endl;
882  cerr << errorObserver->GetMessage() << endl;
883  return false;
884  }
885  }
886 
887  return true;
888 }
889 
890 bool milxQtFile::openModel(const QString filename, milxQtModel* data)
891 {
892  bool legacy = false, wavefront = false, stanford = false, stereoLith = false;
893  QFileInfo fileInfo(filename);
894  QString extension = fileInfo.suffix().toLower();
895 
896  if(extension == "vtk")
897  legacy = true; //Load legacy VTK file
898  else if(extension == "obj")
899  wavefront = true;
900  else if(extension == "ply")
901  stanford = true;
902  else if(extension == "stl")
903  stereoLith = true;
904 
905  vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
906  if(legacy)
907  {
908  //Check legacy data type
909  vtkSmartPointer<vtkDataReader> dreader = vtkSmartPointer<vtkDataReader>::New();
910  dreader->SetFileName(filename.toStdString().c_str());
911  dreader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
912  linkProgressEventOf(dreader);
913  dreader->OpenVTKFile();
914  dreader->ReadHeader();
915  dreader->CloseVTKFile();
916 
917  if(dreader->IsFileUnstructuredGrid())
918  {
919  vtkSmartPointer<vtkUnstructuredGridReader> reader = vtkSmartPointer<vtkUnstructuredGridReader>::New();
920  reader->SetFileName(filename.toStdString().c_str());
921  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
922  linkProgressEventOf(reader);
923  reader->Update();
924 
925  vtkSmartPointer<vtkGeometryFilter> geometryFilter = vtkSmartPointer<vtkGeometryFilter>::New();
926  geometryFilter->SetInputConnection(reader->GetOutputPort());
927  linkProgressEventOf(geometryFilter);
928  geometryFilter->Update();
929 
930  if(!errorObserver->ReportsFailure())
931  data->SetInput(geometryFilter->GetOutput());
932  else
933  {
934  cerr << "Reader Encountered the following error." << endl;
935  cerr << errorObserver->GetMessage() << endl;
936  return false;
937  }
938  }
939  else
940  {
941  vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
942  reader->SetFileName(filename.toStdString().c_str());
943  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
944  linkProgressEventOf(reader);
945  reader->Update();
946 
947  if(!errorObserver->ReportsFailure())
948  data->SetInput(reader->GetOutput());
949  else
950  {
951  cerr << "Reader Encountered the following error." << endl;
952  cerr << errorObserver->GetMessage() << endl;
953  return false;
954  }
955  }
956  }
957  else if(wavefront)
958  {
959  vtkSmartPointer<vtkOBJReader> reader = vtkSmartPointer<vtkOBJReader>::New();
960  reader->SetFileName(filename.toStdString().c_str());
961  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
962  linkProgressEventOf(reader);
963  reader->Update();
964 
965  if(!errorObserver->ReportsFailure())
966  data->SetInput(reader->GetOutput());
967  else
968  {
969  cerr << "Reader Encountered the following error." << endl;
970  cerr << errorObserver->GetMessage() << endl;
971  return false;
972  }
973  }
974  else if(stanford)
975  {
976  vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
977  reader->SetFileName(filename.toStdString().c_str());
978  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
979  linkProgressEventOf(reader);
980  reader->Update();
981 
982  if(!errorObserver->ReportsFailure())
983  data->SetInput(reader->GetOutput());
984  else
985  {
986  cerr << "Reader Encountered the following error." << endl;
987  cerr << errorObserver->GetMessage() << endl;
988  return false;
989  }
990  }
991  else if(stereoLith)
992  {
993  vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
994  reader->SetFileName(filename.toStdString().c_str());
995  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
996  linkProgressEventOf(reader);
997  reader->Update();
998 
999  if(!errorObserver->ReportsFailure())
1000  data->SetInput(reader->GetOutput());
1001  else
1002  {
1003  cerr << "Reader Encountered the following error." << endl;
1004  cerr << errorObserver->GetMessage() << endl;
1005  return false;
1006  }
1007  }
1008  else
1009  {
1010  vtkSmartPointer<vtkXMLPolyDataReader> reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
1011  reader->SetFileName(filename.toStdString().c_str());
1012  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1013  linkProgressEventOf(reader);
1014  reader->Update();
1015 
1016  if(!errorObserver->ReportsFailure())
1017  data->SetInput(reader->GetOutput());
1018  else
1019  {
1020  cerr << "Reader Encountered the following error." << endl;
1021  cerr << errorObserver->GetMessage() << endl;
1022  return false;
1023  }
1024  }
1025 
1026  return true;
1027 }
1028 
1029 bool milxQtFile::openModelCollection(vtkPolyDataCollection* collection, QStringList &filenames)
1030 {
1031  bool success = true;
1032  QPointer<QFileDialog> fileOpener = new QFileDialog;
1033  QSettings settings("Shekhar Chandra", "milxQt");
1034 
1036  if(filenames.isEmpty())
1037  {
1038  QString path = settings.value("recentPath").toString();
1039  filenames = fileOpener->getOpenFileNames(NULL,
1040  tr("Select File(s) to Open"),
1041  path,
1042  tr(openModelExts.c_str()));
1043  }
1044 
1045  if(filenames.size() == 0)
1046  return !success;
1047 
1048  QFileInfo fi(filenames[0]);
1049  settings.setValue("recentPath", fi.absolutePath());
1050 
1051  for(int j = 0; j < filenames.size(); j ++)
1052  {
1053  vtkSmartPointer<vtkPolyData> data = vtkSmartPointer<vtkPolyData>::New();
1054 
1055  success = openModel(filenames[j], data);
1056 
1057  if(!success)
1058  {
1059  cerr << "Encountered Error in Reading model. Aborting Collection Read." << endl;
1060  break;
1061  }
1062  else
1063  cout << "Opened " << filenames[j].toStdString() << " into collection." << endl;
1064 
1065  collection->AddItem(data);
1066 
1067  qApp->processEvents();
1068  }
1069 
1070  return success;
1071 }
1072 
1073 bool milxQtFile::saveModel(const QString filename, vtkPolyData* data, const bool binary)
1074 {
1075  bool legacy = false, stanford = false, stereoLith = false;
1076  QFileInfo fileInfo(filename);
1077  QString extension = fileInfo.suffix().toLower();
1078 
1079  if(extension == "vtk")
1080  legacy = true; //Save legacy VTK file
1081  else if(extension == "ply")
1082  stanford = true; //Save Stanford Poly file
1083  else if(extension == "stl")
1084  stereoLith = true; //STL files
1085 
1086  vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
1087  if(legacy)
1088  {
1089  vtkSmartPointer<vtkPolyDataWriter> writer = vtkSmartPointer<vtkPolyDataWriter>::New();
1090  writer->SetFileName(filename.toStdString().c_str());
1091  #if VTK_MAJOR_VERSION <=5
1092  writer->SetInput(data);
1093  #else
1094  writer->SetInputData(data);
1095  #endif // VTK_MAJOR_VERSION
1096  writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1097  linkProgressEventOf(writer);
1098  writer->Write();
1099  }
1100  else if(stanford)
1101  {
1102  vtkSmartPointer<vtkPLYWriter> writer = vtkSmartPointer<vtkPLYWriter>::New();
1103  writer->SetFileName(filename.toStdString().c_str());
1104  #if VTK_MAJOR_VERSION <=5
1105  writer->SetInput(data);
1106  #else
1107  writer->SetInputData(data);
1108  #endif // VTK_MAJOR_VERSION
1109  writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1110  linkProgressEventOf(writer);
1111  writer->Write();
1112  }
1113  else if(stereoLith)
1114  {
1115  vtkSmartPointer<vtkSTLWriter> writer = vtkSmartPointer<vtkSTLWriter>::New();
1116  writer->SetFileName(filename.toStdString().c_str());
1117  #if VTK_MAJOR_VERSION <=5
1118  writer->SetInput(data);
1119  #else
1120  writer->SetInputData(data);
1121  #endif // VTK_MAJOR_VERSION
1122  writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1123  linkProgressEventOf(writer);
1124  writer->Write();
1125  }
1126  else
1127  {
1128  vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
1129  writer->SetFileName(filename.toStdString().c_str());
1130  #if VTK_MAJOR_VERSION <=5
1131  writer->SetInput(data);
1132  #else
1133  writer->SetInputData(data);
1134  #endif // VTK_MAJOR_VERSION
1135  if(binary)
1136  writer->SetDataModeToBinary();
1137  writer->SetCompressorTypeToZLib();
1138  writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1139  linkProgressEventOf(writer);
1140  writer->Write();
1141  }
1142 
1143  if(errorObserver->ReportsFailure())
1144  {
1145  cerr << "Writer Encountered the following error." << endl;
1146  cerr << errorObserver->GetMessage() << endl;
1147  return false;
1148  }
1149 
1150  return true;
1151 }
1152 
1153 bool milxQtFile::saveModel(const QString filename, milxQtModel* data, const bool binary)
1154 {
1155  bool legacy = false, stanford = false, wavefront = false, stereoLith = false;
1156  QFileInfo fileInfo(filename);
1157  QString extension = fileInfo.suffix().toLower();
1158 
1159  if(extension == "vtk")
1160  legacy = true; //Save legacy VTK file
1161  else if(extension == "ply")
1162  stanford = true; //Save Stanford Poly file
1163  else if(extension == "obj")
1164  wavefront = true;
1165  else if(extension == "stl")
1166  stereoLith = true; //STL files
1167 
1168  vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
1169  if(legacy)
1170  {
1171  vtkSmartPointer<vtkPolyDataWriter> writer = vtkSmartPointer<vtkPolyDataWriter>::New();
1172  writer->SetFileName(filename.toStdString().c_str());
1173  #if VTK_MAJOR_VERSION <=5
1174  writer->SetInput(data->GetOutput());
1175  #else
1176  writer->SetInputData(data->GetOutput());
1177  #endif // VTK_MAJOR_VERSION
1178  writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1179  linkProgressEventOf(writer);
1180  writer->Write();
1181  }
1182  else if(stanford)
1183  {
1184  vtkSmartPointer<vtkPLYWriter> writer = vtkSmartPointer<vtkPLYWriter>::New();
1185  writer->SetFileName(filename.toStdString().c_str());
1186  #if VTK_MAJOR_VERSION <=5
1187  writer->SetInput(data->GetOutput());
1188  #else
1189  writer->SetInputData(data->GetOutput());
1190  #endif // VTK_MAJOR_VERSION
1191  writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1192  linkProgressEventOf(writer);
1193  writer->Write();
1194  }
1195  else if(wavefront)
1196  {
1197  vtkSmartPointer<vtkOBJExporter> writer = vtkSmartPointer<vtkOBJExporter>::New();
1198  QString namePrefix = fileInfo.path() + "/" + fileInfo.baseName();
1199  cout << "Exporting with prefix " << namePrefix.toStdString().c_str() << endl;
1200  writer->SetFilePrefix(namePrefix.toStdString().c_str());
1201  data->disableOrient();
1202  writer->SetInput(data->GetRenderWindow());
1203  writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1204  linkProgressEventOf(writer);
1205  writer->Write();
1206  }
1207  else if(stereoLith)
1208  {
1209  vtkSmartPointer<vtkSTLWriter> writer = vtkSmartPointer<vtkSTLWriter>::New();
1210  writer->SetFileName(filename.toStdString().c_str());
1211  #if VTK_MAJOR_VERSION <=5
1212  writer->SetInput(data->GetOutput());
1213  #else
1214  writer->SetInputData(data->GetOutput());
1215  #endif // VTK_MAJOR_VERSION
1216  writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1217  linkProgressEventOf(writer);
1218  writer->Write();
1219  }
1220  else
1221  {
1222  vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
1223  writer->SetFileName(filename.toStdString().c_str());
1224  #if VTK_MAJOR_VERSION <=5
1225  writer->SetInput(data->GetOutput());
1226  #else
1227  writer->SetInputData(data->GetOutput());
1228  #endif // VTK_MAJOR_VERSION
1229  if(binary)
1230  writer->SetDataModeToBinary();
1231  writer->SetCompressorTypeToZLib();
1232  writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1233  linkProgressEventOf(writer);
1234  writer->Write();
1235  }
1236 
1237  if(errorObserver->ReportsFailure())
1238  {
1239  cerr << "Writer Encountered the following error." << endl;
1240  cerr << errorObserver->GetMessage() << endl;
1241  return false;
1242  }
1243 
1244  return true;
1245 }
1246 
1247 bool milxQtFile::saveScalarsOfModel(const QString filename, milxQtModel* data)
1248 {
1249  bool csvOutput = false;
1250  QFileInfo fileInfo(filename);
1251  QString extension = fileInfo.suffix().toLower();
1252 
1253  if(extension == "csv" || extension == "txt")
1254  csvOutput = true; //Save csv file
1255 
1256  if(csvOutput)
1257  {
1258  QFile::setFileName(filename);
1259  if(!QFile::open(QIODevice::WriteOnly | QIODevice::Text))
1260  return false;
1261 
1262  QTextStream outFile(this);
1263  vtkSmartPointer<vtkDataArray> scalars = data->GetOutput()->GetPointData()->GetScalars();
1264 
1265 // for(int k = 0; k < scalars->GetNumberOfComponents(); k ++)
1266 // {
1267  for(int j = 0; j < scalars->GetNumberOfTuples(); j ++)
1268  {
1269  outFile << scalars->GetTuple1(j);
1270  if(j < scalars->GetNumberOfTuples()-1)
1271  outFile << ", ";
1272  }
1273 // outFile << "\n";
1274 // }
1275 
1276  QFile::close();
1277  }
1278  else
1279  {
1280 
1281  }
1282 
1283  return true;
1284 }
1285 
1286 void milxQtFile::linkProgressEventOf(vtkObject * obj)
1287 {
1288  Connector->Connect(obj,
1289  vtkCommand::ProgressEvent,
1290  this,
1291  SLOT( updateQtEvents() ),
1292  NULL, 1.0); //High Priority
1293 }
QString dataComponentType
Component type of image read.
Definition: milxQtFile.h:242
bool openModel(const QString filename, vtkPolyData *data)
Opens a model file, which can be a VTK XML, Legacy VTK PolyData File (i.e. either a *...
Definition: milxQtFile.cpp:752
static std::vector< std::string > GetSupportedImageFileExtensions()
Determines the supported image file format as file extensions from internal libraries and returns a l...
Definition: milxFile.cxx:96
size_t dataDimensions
Dimensions of image read.
Definition: milxQtFile.h:244
void setName(const QString filename)
Set the name of the data.
static itk::SmartPointer< TImage > ConvertVTKImageToITKImage(vtkSmartPointer< vtkImageData > img)
Converts a VTK image object to an ITK image object.
Definition: milxImage.h:1093
bool saveImage(const QString filename, vtkImageData *data)
Saves data as an image file, which is any of the following: JPEG, PNG, DICOM, TIFF, NIFTI, HDR etc.
Definition: milxQtFile.cpp:531
This class represents the MILX Qt Image Display object using VTK.
Definition: milxQtImage.h:118
bool openModelCollection(vtkPolyDataCollection *collection, QStringList &filenames)
Opens a series of model files, which can be a VTK XML, Legacy VTK PolyData File (i.e. either a *.vtp or *.vtk), a Polygonal File (*.ply) or a Object file (*.obj) into a PolyData collection.
bool isVTKImage()
Returns true if image is a VTK-type image.
Definition: milxQtImage.h:618
void SetInput(vtkSmartPointer< vtkPolyData > mesh)
Assigns the mesh provided to the class, preparing for display. Call generateModel() and then show() t...
bool saveModel(const QString filename, vtkPolyData *data, const bool binary=false)
Saves a model as a file, which can be a VTK XML or Legacy VTK PolyData File (i.e. either a *...
void setActualNumberOfDimensions(const size_t dims)
Sets the actual number of dimensions of the image.
Definition: milxQtImage.h:667
vectorImageType::Pointer GetVectorImage()
Returns the internal vector image data. Unlike the other Get*Image() members, the return value can be...
Definition: milxQtImage.h:426
bool is32BitImage()
Returns true if image is an 32-bit (int) image.
Definition: milxQtImage.h:556
This class represents the MILX Qt Model/Mesh Display object using VTK.
Definition: milxQtModel.h:115
rgbImageType::Pointer GetRGBImage()
Returns the internal RGB image data.
Definition: milxQtImage.h:408
bool is32BitFormat(const QString filename, bool &errorEncountered)
Returns if a image is an 32-bit image format or not.
Definition: milxQtFile.cpp:234
void generateImage(const bool quietly=false)
Assigns the array data to the image and setups up the viewer.
QString dataPixelType
pixel type of image read
Definition: milxQtFile.h:241
bool saveScalarsOfModel(const QString filename, milxQtModel *data)
Saves the scalars of a model as a CSV or VTK Text file. The CSV format is output if the extension is ...
vtkSmartPointer< vtkEventQtSlotConnect > Connector
VTK Events to slots convertor.
Definition: milxQtFile.h:249
Represents an image (i.e. an regular rectangular array with scalar values) and their common operation...
Definition: milxImage.h:174
bool openImage(const QString filename, vtkImageData *data)
Opens an image file, which is any of the following: JPEG, PNG, DICOM, TIFF, NIFTI, HDR etc.
Definition: milxQtFile.cpp:75
bool openImageSeries(milxQtImage *data, QString directoryPath="")
Opens an DICOM series.
Definition: milxQtFile.cpp:454
void SetInput(vtkSmartPointer< vtkImageData > newImg)
VTK interface function: Assigns the image data internally. Same as setData() function.
Definition: milxQtImage.h:156
bool isVectorImage()
Returns true if image is a vector image.
Definition: milxQtImage.h:610
virtual ~milxQtFile()
The standard destructor.
Definition: milxQtFile.cpp:70
vtkSmartPointer< vtkPolyData > GetOutput()
Returns the mesh data object (PolyData) used internally VTK style.
bool isFieldFormat(const QString filename, bool &errorEncountered)
Returns if a image is a deformation field type image (a vector image) format or not.
Definition: milxQtFile.cpp:255
vtkSmartPointer< vtkImageData > GetOutput()
Returns the image data object (ImageData) used internally VTK style.
Definition: milxQtImage.h:384
milxQtFile(QObject *theParent=0)
The standard constructor.
Definition: milxQtFile.cpp:54
charImageType::Pointer GetCharImage()
Returns the internal unsigned char image data.
Definition: milxQtImage.h:392
static bool ReadImageInformation(const std::string filename, std::string &pixeltype, std::string &componentType, size_t &dimensions)
Reads just the header of an image file (without reading the image data), and writes the info into the...
Definition: milxFile.cxx:69
floatImageType::Pointer GetFloatImage()
Returns the internal float image data.
Definition: milxQtImage.h:416
bool isRGBImage()
Returns true if image is an RGB (3-vector unsigned char image) image.
Definition: milxQtImage.h:574
size_t dataComponents
Components of vector of image read.
Definition: milxQtFile.h:243
static std::vector< std::string > GetDICOMSeriesUIDs(const std::string directoryPath, bool recursive=false)
DICOM Related.
Definition: milxFile.cxx:115
bool is8BitImage()
Returns true if image is an 8-bit (unsigned char) image.
Definition: milxQtImage.h:537
QString name
Name of the last opened file.
Definition: milxQtFile.h:240
QString supportedImageFormats()
Returns a string of supported image formats from all libraries for in file dialogs in Qt...
Definition: milxQtFile.cpp:202
bool is8BitFormat(const QString filename, bool &errorEncountered)
Returns if a image is an 8-bit image format or not.
Definition: milxQtFile.cpp:213
intImageType::Pointer GetIntImage()
Returns the internal unsigned char image data.
Definition: milxQtImage.h:400
void disableOrient()
Disables orientation marker.