1 #include <visp3/ustk_core/usConfig.h>
3 #ifdef USTK_HAVE_VTK_QT
5 #include <visp3/ustk_core/usImageIo.h>
6 #include <visp3/ustk_core/usPreScanToPostScan3DConverter.h>
7 #include <visp3/ustk_gui/usVTKConverter.h>
8 #include <vtkImageImport.h>
9 #include <vtkMetaImageWriter.h>
11 int main(
int argc,
char **argv)
13 std::string mhd_filename;
15 for (
int i = 0; i < argc; i++) {
16 if (std::string(argv[i]) ==
"--input")
17 mhd_filename = std::string(argv[i + 1]);
18 else if (std::string(argv[i]) ==
"--help") {
19 std::cout <<
"\nUsage: " << argv[0] <<
" [--input <preScan3D.xml>] [--help]\n" << std::endl;
25 if (mhd_filename.empty()) {
27 if (!env_ipath.empty())
28 mhd_filename = env_ipath +
"/pre-scan/3D_xml/sequencepreScan3D.xml";
30 std::cout <<
"You should set USTK_DATASET_PATH environment var to access to ustk dataset" << std::endl;
48 double startTime = vpTime::measureTimeMs();
49 std::cout <<
"init converter..." << std::endl;
50 converter.
init(preScanImage);
51 double endInitTime = vpTime::measureTimeMs();
52 std::cout <<
"init time (sec) = " << (endInitTime - startTime) / 1000.0 << std::endl;
55 converter.
convert(postScanImage, preScanImage);
56 converter.
convert(postScanImage2, preScanImage2);
59 std::cout <<
"image 1 @ : " << (
void *)postScanImage.
getConstData() << std::endl;
60 std::cout <<
"image 2 @ : " << (
void *)postScanImage2.
getConstData() << std::endl;
64 vtkSmartPointer<vtkImageData> vtkImage = vtkSmartPointer<vtkImageData>::New();
65 vtkImageImport *importer = vtkImageImport::New();
66 importer->SetDataScalarTypeToUnsignedChar();
67 importer->SetImportVoidPointer((
void *)postScanImage.
getConstData());
68 importer->SetWholeExtent(0, postScanImage.
getWidth() - 1, 0, postScanImage.
getHeight() - 1, 0,
70 importer->SetDataExtentToWholeExtent();
71 importer->SetNumberOfScalarComponents(1);
75 for (
int i = 0; i < 20; i++) {
76 double t1 = vpTime::measureTimeMs();
80 converter.
convert(postScanImage, preScanImage);
82 converter.
convert(postScanImage2, preScanImage2);
84 double endConvertTime = vpTime::measureTimeMs();
85 std::cout <<
"scan convert time (ms) = " << (endConvertTime - t1) << std::endl;
93 double t2 = vpTime::measureTimeMs();
95 std::cout <<
"vtk convert time (ms) = " << t2 - endConvertTime << std::endl;
96 std::cout <<
"full convert time (ms) = " << t2 - t1 << std::endl;
97 std::cout <<
"vtk image @ : " << vtkImage->GetScalarPointer() << std::endl;
104 int main() { std::cout <<
"Install vtk with qt4 or qt5 support to run this tutorial." << std::endl; }
unsigned int getNumberOfFrames() const
Type * getConstData() const
unsigned int getHeight() const
unsigned int getWidth() const
static void read(usImageRF2D< short int > &imageRf2D, const std::string &headerFileName)
void init(const usImagePreScan3D< unsigned char > &preScanImage, double down=1)
void convert(usImagePostScan3D< unsigned char > &postScanImage, const usImagePreScan3D< unsigned char > &preScanImage)
static void convert(const usImagePostScan3D< unsigned char > &postScanImage, vtkSmartPointer< vtkImageData > &vtkPostScanImage, vtkSmartPointer< vtkImageImport > importer=NULL)
VISP_EXPORT std::string getDataSetPath()