18 #include "milxQtFile.h" 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> 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> 51 #include "itkImageToVTKImageFilter.h" 52 #include "itkVTKImageToImageFilter.h" 57 observeProgress = itkEventQtObserver::New();
58 Connector = vtkSmartPointer<vtkEventQtSlotConnect>::New();
67 linkProgressEventOf(milx::ProgressUpdates->GetUpdateObject());
77 QFileInfo fileInfo(filename);
78 QString extension = fileInfo.suffix().toLower();
79 bool charFormat =
false, integerFormat =
false, vtkFormat =
false, medical =
true;
82 const QString charStr =
"unsigned char";
83 const QString typeStr = data->GetScalarTypeAsString();
85 if(extension ==
"png" || extension ==
"jpg" || extension ==
"jpeg" || extension ==
"bmp")
90 else if(typeStr == charStr || typeStr ==
"unsigned_char")
93 itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<unsigned char, 3>::New() );
95 else if(typeStr ==
"unsigned" || typeStr ==
"unsigned_short" || typeStr ==
"short" || typeStr ==
"unsigned short" || typeStr ==
"unsigned_int" || typeStr ==
"unsigned int" || typeStr ==
"int")
97 else if(extension ==
"vti")
102 itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<float, 3>::New() );
105 vtkSmartPointer<vtkImageFlip> imageReorient = vtkSmartPointer<vtkImageFlip>::New();
106 vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
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() );
119 charImageType::Pointer charImg = milx::File::ReadImageUsingITK<charImageType>(filename.toStdString());
125 #if VTK_MAJOR_VERSION <=5 129 #endif // VTK_MAJOR_VERSION 133 vtkSmartPointer<vtkXMLImageDataReader> reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
135 if(reader->CanReadFile(filename.toStdString().c_str()))
137 reader->SetFileName(filename.toStdString().c_str());
138 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
139 linkProgressEventOf(reader);
142 if(!errorObserver->ReportsFailure())
144 data->DeepCopy(reader->GetOutput());
145 data->GetExtent(bounds);
149 cerr <<
"VTI Reader Encountered the following error." << endl;
150 cerr << errorObserver->GetMessage() << endl;
156 cerr <<
"Could not load VTI file!" << endl;
160 else if(integerFormat)
162 intImageType::Pointer intImg = milx::File::ReadImageUsingITK<intImageType>(filename.toStdString());
168 #if VTK_MAJOR_VERSION <=5 172 #endif // VTK_MAJOR_VERSION 176 floatImageType::Pointer floatImg = milx::File::ReadImageUsingITK<floatImageType>(filename.toStdString());
182 #if VTK_MAJOR_VERSION <=5 186 #endif // VTK_MAJOR_VERSION 191 imageReorient->SetFilteredAxis(1);
192 imageReorient->FlipAboutOriginOn();
194 linkProgressEventOf(imageReorient);
195 imageReorient->Update();
196 data->DeepCopy(imageReorient->GetOutput());
207 for(
size_t j = 0; j < extensions.size(); j ++)
208 exts +=
"*" + QString(extensions[j].c_str()) +
" ";
215 std::string pixelType, componentType;
216 errorEncountered =
false;
221 cerr <<
"Failed reading header of image. File may not be an image. Exiting" << endl;
222 errorEncountered =
true;
228 if(componentType ==
"unsigned_char" || componentType ==
"unsigned char")
236 std::string pixelType, componentType;
237 errorEncountered =
false;
242 cerr <<
"Failed reading header of image. File may not be an image. Exiting" << endl;
243 errorEncountered =
true;
249 if(componentType ==
"unsigned" || componentType ==
"unsigned_short" || componentType ==
"short" || componentType ==
"unsigned short" || componentType ==
"unsigned_int" || componentType ==
"unsigned int" || componentType ==
"int")
257 std::string pixelType, componentType;
258 errorEncountered =
false;
263 cerr <<
"Failed reading header of image. File may not be an image. Exiting" << endl;
264 errorEncountered =
true;
270 if(pixelType ==
"vector")
278 QFileInfo fileInfo(filename);
279 QString extension = fileInfo.suffix().toLower();
280 bool charFormat =
false, integerFormat =
false, vtkFormat =
false, deformField =
false, rgbImage =
false, pnmImage =
false;
282 if(extension ==
"png" || extension ==
"jpg" || extension ==
"jpeg" || extension ==
"bmp")
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() );
290 else if(extension ==
"vti")
294 else if(extension ==
"pbm" || extension ==
"pgm" || extension ==
"ppm")
299 if(!vtkFormat && !pnmImage)
301 cout <<
"Trying to read image header ..." << endl;
303 std::string pixelType, componentType;
306 cerr <<
"Failed reading header of image. File may not be an image. Exiting" << endl;
312 if((componentType ==
"unsigned_char" && pixelType ==
"scalar") || (componentType ==
"unsigned char" && pixelType ==
"scalar"))
314 cout <<
"Found 8-bit image ..." << endl;
317 else if(componentType ==
"unsigned" || componentType ==
"unsigned_short" || componentType ==
"short" || componentType ==
"unsigned short" || componentType ==
"unsigned_int" || componentType ==
"unsigned int" || componentType ==
"int")
319 cout <<
"Found integer-type image ..." << endl;
320 integerFormat =
true;
322 else if(pixelType ==
"vector")
324 else if( (pixelType ==
"rgb" || pixelType ==
"rgba") && componentType ==
"unsigned_char" )
331 vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
334 charImageType::Pointer charImg;
336 if( !milx::File::OpenImage<charImageType>(filename.toStdString(), charImg) )
341 else if(integerFormat)
343 intImageType::Pointer intImg;
345 if(!milx::File::OpenImage<intImageType>(filename.toStdString(), intImg))
352 vtkSmartPointer<vtkXMLImageDataReader> reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
354 if(reader->CanReadFile(filename.toStdString().c_str()))
356 reader->SetFileName(filename.toStdString().c_str());
357 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
358 linkProgressEventOf(reader);
361 if(!errorObserver->ReportsFailure())
362 data->
SetInput(reader->GetOutput());
365 cerr <<
"VTI Reader Encountered the following error." << endl;
366 cerr << errorObserver->GetMessage() << endl;
372 cerr <<
"Could not load VTI file!" << endl;
378 vtkSmartPointer<vtkPNMReader> reader = vtkSmartPointer<vtkPNMReader>::New();
380 if(reader->CanReadFile(filename.toStdString().c_str()))
382 reader->SetFileName(filename.toStdString().c_str());
383 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
384 linkProgressEventOf(reader);
387 if(!errorObserver->ReportsFailure())
389 cout <<
"Image Description: " << reader->GetDescriptiveName() << endl;
390 data->
SetInput(reader->GetOutput());
394 cerr <<
"PNM Reader Encountered the following error." << endl;
395 cerr << errorObserver->GetMessage() << endl;
401 cerr <<
"Could not load PNM file!" << endl;
407 itk::ObjectFactoryBase::RegisterFactory( itk::NrrdImageIOFactory::New() );
409 vectorImageType::Pointer vecImg;
411 if( !milx::File::OpenImage<vectorImageType>(filename.toStdString(), vecImg) )
418 #if (ITK_VERSION_MAJOR > 3) 421 vectorImageType::Pointer vecImg;
423 typedef itk::Image<floatPixelType, 4> float4DImageType;
424 if( !milx::File::OpenAsVectorImage<float4DImageType, 3>(filename.toStdString(), vecImg) )
434 rgbImageType::Pointer rgbImg;
436 if( !milx::File::OpenImage<rgbImageType>(filename.toStdString(), rgbImg) )
443 floatImageType::Pointer floatImg;
445 if( !milx::File::OpenImage<floatImageType>(filename.toStdString(), floatImg) )
457 QPointer<QFileDialog> fileOpener =
new QFileDialog;
458 QSettings settings(
"Shekhar Chandra",
"milxQt");
461 if(directoryPath.isEmpty())
463 QString path = settings.value(
"recentPath").toString();
464 directoryPath = fileOpener->getExistingDirectory(NULL, tr(
"Open DICOM Directory"),
466 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
469 if(directoryPath.isEmpty())
475 std::string seriesName;
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");
488 QVBoxLayout *uidLayout =
new QVBoxLayout;
489 uidLayout->addWidget(uidLabel);
490 uidLayout->addWidget(uidInfoLabel);
491 uidLayout->addWidget(uidComboBox);
492 uidLayout->addWidget(uidButton);
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()));
501 seriesName = uidComboBox->currentText().toStdString();
504 else if(UIDs.empty())
506 cerr <<
"Error. No DICOM series was found in directory" << endl;
510 seriesName = UIDs.begin()->c_str();
512 cout <<
"Reading series as float images" << endl;
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);
521 data->
setName(seriesName.c_str());
522 cout <<
"Completed Reading Series: " << seriesName << endl;
525 QFileInfo fi(directoryPath);
526 settings.setValue(
"recentPath",fi.absolutePath());
533 QFileInfo fileInfo(filename);
534 QString extension = fileInfo.suffix().toLower();
535 bool charFormat =
false, integerFormat =
false, medical =
true, vtkFormat =
false, success =
false;
538 const QString charStr =
"unsigned char";
539 const QString typeStr = data->GetScalarTypeAsString();
541 if(extension ==
"png" || extension ==
"jpg" || extension ==
"jpeg" || extension ==
"bmp")
546 else if(typeStr == charStr || typeStr ==
"unsigned_char")
549 itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<unsigned char, 3>::New() );
551 else if(typeStr ==
"unsigned" || typeStr ==
"unsigned_short" || typeStr ==
"short" || typeStr ==
"unsigned short" || typeStr ==
"unsigned_int" || typeStr ==
"unsigned int" || typeStr ==
"int")
553 integerFormat =
true;
556 itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<float, 3>::New() );
558 data->GetExtent(bounds);
560 if(extension ==
"vti")
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());
569 imageReorient->SetInputData(data);
571 imageReorient->SetFilteredAxis(1);
572 imageReorient->FlipAboutOriginOn();
573 linkProgressEventOf(imageReorient);
574 imageReorient->Update();
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() );
587 typedef itk::Image<rgbPixelType, 2> rgbImageSliceType;
589 success = milx::File::WriteImageUsingITK<rgbImageSliceType>(filename.toStdString(), charImg);
595 success = milx::File::WriteImageUsingITK<rgbImageType>(filename.toStdString(), charImg);
600 vtkSmartPointer<vtkXMLImageDataWriter> writer = vtkSmartPointer<vtkXMLImageDataWriter>::New();
601 #if VTK_MAJOR_VERSION <=5 602 writer->SetInput(data);
604 writer->SetInputData(data);
606 writer->SetFileName(filename.toStdString().c_str());
607 writer->SetDataModeToBinary();
608 writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
609 linkProgressEventOf(writer);
612 if(errorObserver->ReportsFailure())
614 cerr <<
"VTI Writer Encountered the following error." << endl;
615 cerr << errorObserver->GetMessage() << endl;
620 else if(integerFormat)
625 success = milx::File::WriteImageUsingITK<intImageType>(filename.toStdString(), intImg);
632 success = milx::File::WriteImageUsingITK<floatImageType>(filename.toStdString(), floatImg);
640 QFileInfo fileInfo(filename);
641 QString extension = fileInfo.suffix().toLower();
642 bool charFormat =
false, integerFormat =
false, medical =
true, rgbFormat =
false, vtkFormat =
false, success =
false;
644 if(extension ==
"png" || extension ==
"jpg" || extension ==
"jpeg" || extension ==
"bmp")
652 itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<unsigned char,3>::New() );
656 integerFormat =
true;
663 itk::ObjectFactoryBase::RegisterFactory( itk::RawImageIOFactory<float,3>::New() );
665 if(extension ==
"vti")
670 vtkSmartPointer<vtkImageCast> castVTKImage = vtkSmartPointer<vtkImageCast>::New();
671 castVTKImage->SetOutputScalarTypeToFloat();
672 #if VTK_MAJOR_VERSION <=5 673 castVTKImage->SetInput(data->
GetOutput());
675 castVTKImage->SetInputData(data->
GetOutput());
676 #endif // VTK_MAJOR_VERSION 677 castVTKImage->Update();
679 vtkSmartPointer<vtkImageFlip> imageReorient = vtkSmartPointer<vtkImageFlip>::New();
680 #if VTK_MAJOR_VERSION <=5 681 imageReorient->SetInput(castVTKImage->GetOutput());
683 imageReorient->SetInputData(castVTKImage->GetOutput());
685 imageReorient->SetFilteredAxis(1);
686 imageReorient->FlipAboutOriginOn();
687 linkProgressEventOf(imageReorient);
688 imageReorient->Update();
690 cout <<
"Converted VTK Image to ITK Image since saving requested medical image format" << endl;
696 vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
699 vtkSmartPointer<vtkXMLImageDataWriter> writer = vtkSmartPointer<vtkXMLImageDataWriter>::New();
700 #if VTK_MAJOR_VERSION <=5 704 #endif // VTK_MAJOR_VERSION 705 writer->SetFileName(filename.toStdString().c_str());
706 writer->SetDataModeToBinary();
707 linkProgressEventOf(writer);
708 writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
711 if(errorObserver->ReportsFailure())
713 cerr <<
"VTI Writer Encountered the following error." << endl;
714 cerr << errorObserver->GetMessage() << endl;
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() );
730 success = milx::File::WriteImageUsingITK<charImageType>(filename.toStdString(), data->
GetCharImage());
732 else if(integerFormat)
734 success = milx::File::WriteImageUsingITK<intImageType>(filename.toStdString(), data->
GetIntImage());
738 success = milx::File::WriteImageUsingITK<rgbImageType>(filename.toStdString(), data->
GetRGBImage());
742 success = milx::File::WriteImageUsingITK<vectorImageType>(filename.toStdString(), data->
GetVectorImage());
746 success = milx::File::WriteImageUsingITK<floatImageType>(filename.toStdString(), data->
GetFloatImage());
754 bool legacy =
false, wavefront =
false, stanford =
false, stereoLith =
false;
755 QFileInfo fileInfo(filename);
756 QString extension = fileInfo.suffix().toLower();
758 if(extension ==
"vtk")
760 else if(extension ==
"obj")
762 else if(extension ==
"ply")
764 else if(extension ==
"stl")
767 vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
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();
779 if(dreader->IsFileUnstructuredGrid())
781 vtkSmartPointer<vtkUnstructuredGridReader> reader = vtkSmartPointer<vtkUnstructuredGridReader>::New();
782 reader->SetFileName(filename.toStdString().c_str());
783 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
784 linkProgressEventOf(reader);
787 vtkSmartPointer<vtkGeometryFilter> geometryFilter = vtkSmartPointer<vtkGeometryFilter>::New();
788 geometryFilter->SetInputConnection(reader->GetOutputPort());
789 linkProgressEventOf(geometryFilter);
790 geometryFilter->Update();
792 if(!errorObserver->ReportsFailure())
793 data->DeepCopy(geometryFilter->GetOutput());
796 cerr <<
"Reader Encountered the following error." << endl;
797 cerr << errorObserver->GetMessage() << endl;
803 vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
804 reader->SetFileName(filename.toStdString().c_str());
805 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
806 linkProgressEventOf(reader);
809 if(!errorObserver->ReportsFailure())
810 data->DeepCopy(reader->GetOutput());
813 cerr <<
"Reader Encountered the following error." << endl;
814 cerr << errorObserver->GetMessage() << endl;
821 vtkSmartPointer<vtkOBJReader> reader = vtkSmartPointer<vtkOBJReader>::New();
822 reader->SetFileName(filename.toStdString().c_str());
823 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
824 linkProgressEventOf(reader);
827 if(!errorObserver->ReportsFailure())
828 data->DeepCopy(reader->GetOutput());
831 cerr <<
"Reader Encountered the following error." << endl;
832 cerr << errorObserver->GetMessage() << endl;
838 vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
839 reader->SetFileName(filename.toStdString().c_str());
840 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
841 linkProgressEventOf(reader);
844 if(!errorObserver->ReportsFailure())
845 data->DeepCopy(reader->GetOutput());
848 cerr <<
"Reader Encountered the following error." << endl;
849 cerr << errorObserver->GetMessage() << endl;
855 vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
856 reader->SetFileName(filename.toStdString().c_str());
857 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
858 linkProgressEventOf(reader);
861 if(!errorObserver->ReportsFailure())
862 data->DeepCopy(reader->GetOutput());
865 cerr <<
"Reader Encountered the following error." << endl;
866 cerr << errorObserver->GetMessage() << endl;
872 vtkSmartPointer<vtkXMLPolyDataReader> reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
873 reader->SetFileName(filename.toStdString().c_str());
874 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
875 linkProgressEventOf(reader);
877 if(!errorObserver->ReportsFailure())
878 data->DeepCopy(reader->GetOutput());
881 cerr <<
"Reader Encountered the following error." << endl;
882 cerr << errorObserver->GetMessage() << endl;
892 bool legacy =
false, wavefront =
false, stanford =
false, stereoLith =
false;
893 QFileInfo fileInfo(filename);
894 QString extension = fileInfo.suffix().toLower();
896 if(extension ==
"vtk")
898 else if(extension ==
"obj")
900 else if(extension ==
"ply")
902 else if(extension ==
"stl")
905 vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
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();
917 if(dreader->IsFileUnstructuredGrid())
919 vtkSmartPointer<vtkUnstructuredGridReader> reader = vtkSmartPointer<vtkUnstructuredGridReader>::New();
920 reader->SetFileName(filename.toStdString().c_str());
921 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
922 linkProgressEventOf(reader);
925 vtkSmartPointer<vtkGeometryFilter> geometryFilter = vtkSmartPointer<vtkGeometryFilter>::New();
926 geometryFilter->SetInputConnection(reader->GetOutputPort());
927 linkProgressEventOf(geometryFilter);
928 geometryFilter->Update();
930 if(!errorObserver->ReportsFailure())
931 data->
SetInput(geometryFilter->GetOutput());
934 cerr <<
"Reader Encountered the following error." << endl;
935 cerr << errorObserver->GetMessage() << endl;
941 vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
942 reader->SetFileName(filename.toStdString().c_str());
943 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
944 linkProgressEventOf(reader);
947 if(!errorObserver->ReportsFailure())
948 data->
SetInput(reader->GetOutput());
951 cerr <<
"Reader Encountered the following error." << endl;
952 cerr << errorObserver->GetMessage() << endl;
959 vtkSmartPointer<vtkOBJReader> reader = vtkSmartPointer<vtkOBJReader>::New();
960 reader->SetFileName(filename.toStdString().c_str());
961 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
962 linkProgressEventOf(reader);
965 if(!errorObserver->ReportsFailure())
966 data->
SetInput(reader->GetOutput());
969 cerr <<
"Reader Encountered the following error." << endl;
970 cerr << errorObserver->GetMessage() << endl;
976 vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
977 reader->SetFileName(filename.toStdString().c_str());
978 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
979 linkProgressEventOf(reader);
982 if(!errorObserver->ReportsFailure())
983 data->
SetInput(reader->GetOutput());
986 cerr <<
"Reader Encountered the following error." << endl;
987 cerr << errorObserver->GetMessage() << endl;
993 vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
994 reader->SetFileName(filename.toStdString().c_str());
995 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
996 linkProgressEventOf(reader);
999 if(!errorObserver->ReportsFailure())
1000 data->
SetInput(reader->GetOutput());
1003 cerr <<
"Reader Encountered the following error." << endl;
1004 cerr << errorObserver->GetMessage() << endl;
1010 vtkSmartPointer<vtkXMLPolyDataReader> reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
1011 reader->SetFileName(filename.toStdString().c_str());
1012 reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1013 linkProgressEventOf(reader);
1016 if(!errorObserver->ReportsFailure())
1017 data->
SetInput(reader->GetOutput());
1020 cerr <<
"Reader Encountered the following error." << endl;
1021 cerr << errorObserver->GetMessage() << endl;
1031 bool success =
true;
1032 QPointer<QFileDialog> fileOpener =
new QFileDialog;
1033 QSettings settings(
"Shekhar Chandra",
"milxQt");
1036 if(filenames.isEmpty())
1038 QString path = settings.value(
"recentPath").toString();
1039 filenames = fileOpener->getOpenFileNames(NULL,
1040 tr(
"Select File(s) to Open"),
1042 tr(openModelExts.c_str()));
1045 if(filenames.size() == 0)
1048 QFileInfo fi(filenames[0]);
1049 settings.setValue(
"recentPath", fi.absolutePath());
1051 for(
int j = 0; j < filenames.size(); j ++)
1053 vtkSmartPointer<vtkPolyData> data = vtkSmartPointer<vtkPolyData>::New();
1055 success =
openModel(filenames[j], data);
1059 cerr <<
"Encountered Error in Reading model. Aborting Collection Read." << endl;
1063 cout <<
"Opened " << filenames[j].toStdString() <<
" into collection." << endl;
1065 collection->AddItem(data);
1067 qApp->processEvents();
1075 bool legacy =
false, stanford =
false, stereoLith =
false;
1076 QFileInfo fileInfo(filename);
1077 QString extension = fileInfo.suffix().toLower();
1079 if(extension ==
"vtk")
1081 else if(extension ==
"ply")
1083 else if(extension ==
"stl")
1086 vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
1089 vtkSmartPointer<vtkPolyDataWriter> writer = vtkSmartPointer<vtkPolyDataWriter>::New();
1090 writer->SetFileName(filename.toStdString().c_str());
1091 #if VTK_MAJOR_VERSION <=5 1092 writer->SetInput(data);
1094 writer->SetInputData(data);
1095 #endif // VTK_MAJOR_VERSION 1096 writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1097 linkProgressEventOf(writer);
1102 vtkSmartPointer<vtkPLYWriter> writer = vtkSmartPointer<vtkPLYWriter>::New();
1103 writer->SetFileName(filename.toStdString().c_str());
1104 #if VTK_MAJOR_VERSION <=5 1105 writer->SetInput(data);
1107 writer->SetInputData(data);
1108 #endif // VTK_MAJOR_VERSION 1109 writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1110 linkProgressEventOf(writer);
1115 vtkSmartPointer<vtkSTLWriter> writer = vtkSmartPointer<vtkSTLWriter>::New();
1116 writer->SetFileName(filename.toStdString().c_str());
1117 #if VTK_MAJOR_VERSION <=5 1118 writer->SetInput(data);
1120 writer->SetInputData(data);
1121 #endif // VTK_MAJOR_VERSION 1122 writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1123 linkProgressEventOf(writer);
1128 vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
1129 writer->SetFileName(filename.toStdString().c_str());
1130 #if VTK_MAJOR_VERSION <=5 1131 writer->SetInput(data);
1133 writer->SetInputData(data);
1134 #endif // VTK_MAJOR_VERSION 1136 writer->SetDataModeToBinary();
1137 writer->SetCompressorTypeToZLib();
1138 writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1139 linkProgressEventOf(writer);
1143 if(errorObserver->ReportsFailure())
1145 cerr <<
"Writer Encountered the following error." << endl;
1146 cerr << errorObserver->GetMessage() << endl;
1155 bool legacy =
false, stanford =
false, wavefront =
false, stereoLith =
false;
1156 QFileInfo fileInfo(filename);
1157 QString extension = fileInfo.suffix().toLower();
1159 if(extension ==
"vtk")
1161 else if(extension ==
"ply")
1163 else if(extension ==
"obj")
1165 else if(extension ==
"stl")
1168 vtkSmartPointer<vtkErrorWarning> errorObserver = vtkSmartPointer<vtkErrorWarning>::New();
1171 vtkSmartPointer<vtkPolyDataWriter> writer = vtkSmartPointer<vtkPolyDataWriter>::New();
1172 writer->SetFileName(filename.toStdString().c_str());
1173 #if VTK_MAJOR_VERSION <=5 1176 writer->SetInputData(data->
GetOutput());
1177 #endif // VTK_MAJOR_VERSION 1178 writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1179 linkProgressEventOf(writer);
1184 vtkSmartPointer<vtkPLYWriter> writer = vtkSmartPointer<vtkPLYWriter>::New();
1185 writer->SetFileName(filename.toStdString().c_str());
1186 #if VTK_MAJOR_VERSION <=5 1189 writer->SetInputData(data->
GetOutput());
1190 #endif // VTK_MAJOR_VERSION 1191 writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1192 linkProgressEventOf(writer);
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());
1202 writer->SetInput(data->GetRenderWindow());
1203 writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1204 linkProgressEventOf(writer);
1209 vtkSmartPointer<vtkSTLWriter> writer = vtkSmartPointer<vtkSTLWriter>::New();
1210 writer->SetFileName(filename.toStdString().c_str());
1211 #if VTK_MAJOR_VERSION <=5 1214 writer->SetInputData(data->
GetOutput());
1215 #endif // VTK_MAJOR_VERSION 1216 writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1217 linkProgressEventOf(writer);
1222 vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
1223 writer->SetFileName(filename.toStdString().c_str());
1224 #if VTK_MAJOR_VERSION <=5 1227 writer->SetInputData(data->
GetOutput());
1228 #endif // VTK_MAJOR_VERSION 1230 writer->SetDataModeToBinary();
1231 writer->SetCompressorTypeToZLib();
1232 writer->AddObserver(vtkCommand::ErrorEvent, errorObserver);
1233 linkProgressEventOf(writer);
1237 if(errorObserver->ReportsFailure())
1239 cerr <<
"Writer Encountered the following error." << endl;
1240 cerr << errorObserver->GetMessage() << endl;
1249 bool csvOutput =
false;
1250 QFileInfo fileInfo(filename);
1251 QString extension = fileInfo.suffix().toLower();
1253 if(extension ==
"csv" || extension ==
"txt")
1258 QFile::setFileName(filename);
1259 if(!QFile::open(QIODevice::WriteOnly | QIODevice::Text))
1262 QTextStream outFile(
this);
1263 vtkSmartPointer<vtkDataArray> scalars = data->
GetOutput()->GetPointData()->GetScalars();
1267 for(
int j = 0; j < scalars->GetNumberOfTuples(); j ++)
1269 outFile << scalars->GetTuple1(j);
1270 if(j < scalars->GetNumberOfTuples()-1)
1286 void milxQtFile::linkProgressEventOf(vtkObject * obj)
1289 vtkCommand::ProgressEvent,
1291 SLOT( updateQtEvents() ),
QString dataComponentType
Component type of image read.
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 *...
static std::vector< std::string > GetSupportedImageFileExtensions()
Determines the supported image file format as file extensions from internal libraries and returns a l...
size_t dataDimensions
Dimensions of image read.
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.
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.
This class represents the MILX Qt Image Display object using VTK.
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.
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.
vectorImageType::Pointer GetVectorImage()
Returns the internal vector image data. Unlike the other Get*Image() members, the return value can be...
bool is32BitImage()
Returns true if image is an 32-bit (int) image.
This class represents the MILX Qt Model/Mesh Display object using VTK.
rgbImageType::Pointer GetRGBImage()
Returns the internal RGB image data.
bool is32BitFormat(const QString filename, bool &errorEncountered)
Returns if a image is an 32-bit image format or not.
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
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.
Represents an image (i.e. an regular rectangular array with scalar values) and their common operation...
bool openImage(const QString filename, vtkImageData *data)
Opens an image file, which is any of the following: JPEG, PNG, DICOM, TIFF, NIFTI, HDR etc.
bool openImageSeries(milxQtImage *data, QString directoryPath="")
Opens an DICOM series.
void SetInput(vtkSmartPointer< vtkImageData > newImg)
VTK interface function: Assigns the image data internally. Same as setData() function.
bool isVectorImage()
Returns true if image is a vector image.
virtual ~milxQtFile()
The standard destructor.
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.
vtkSmartPointer< vtkImageData > GetOutput()
Returns the image data object (ImageData) used internally VTK style.
milxQtFile(QObject *theParent=0)
The standard constructor.
charImageType::Pointer GetCharImage()
Returns the internal unsigned char image data.
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...
floatImageType::Pointer GetFloatImage()
Returns the internal float image data.
bool isRGBImage()
Returns true if image is an RGB (3-vector unsigned char image) image.
size_t dataComponents
Components of vector of image read.
static std::vector< std::string > GetDICOMSeriesUIDs(const std::string directoryPath, bool recursive=false)
DICOM Related.
bool is8BitImage()
Returns true if image is an 8-bit (unsigned char) image.
QString name
Name of the last opened file.
QString supportedImageFormats()
Returns a string of supported image formats from all libraries for in file dialogs in Qt...
bool is8BitFormat(const QString filename, bool &errorEncountered)
Returns if a image is an 8-bit image format or not.
intImageType::Pointer GetIntImage()
Returns the internal unsigned char image data.
void disableOrient()
Disables orientation marker.