1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
27 #include "OpenImageDialog.h"
32 // dlopen, dlsym, etc.
36 typedef vtkImageData* (*GETIMAGEDATADIALOG)();
38 namespace creaMaracasVisuKernel{
39 OpenImageDialog::OpenImageDialog(bool usegimmick)
43 bool gimmickfound = false;
47 HINSTANCE gimmickhandle;
48 gimmickhandle = LoadLibrary(TEXT("creaImageIO.dll"));
49 std::cout<<"imagehandle "<<gimmickhandle<<std::endl;
50 if(gimmickhandle!=NULL){
52 GETIMAGEDATADIALOG getImageDataDialog;
54 getImageDataDialog = (GETIMAGEDATADIALOG)GetProcAddress(gimmickhandle, "getImageDataDialog");
56 std::cout<<"imagedatadialog "<<getImageDataDialog<<std::endl;
58 if(getImageDataDialog!=NULL){
59 img = getImageDataDialog();
62 if(!FreeLibrary(gimmickhandle)){
63 std::cout<<"Error while releasing the handle creaImageIO2.dll"<<std::endl;
68 GETIMAGEDATADIALOG getImageDataDialog;
71 gimmickhandle = dlopen ("libcreaImageIO.so", RTLD_LAZY);
72 if (! gimmickhandle) {
74 std::cout<<erreur<<"imagehandle "<<gimmickhandle<<std::endl;
76 getImageDataDialog = (GETIMAGEDATADIALOG) dlsym (gimmickhandle, "getImageDataDialog");
77 if(!getImageDataDialog)
80 std::cout<<erreur<<"getImageDataDialog "<<getImageDataDialog<<std::endl;
82 img = (*getImageDataDialog)();
85 } // if getImageDataDialog
86 /*dlclose returns 0 on success, non-zero on error*/
87 closingerror = dlclose(gimmickhandle);
89 std::cout<<closingerror<<"error closing handle "<<gimmickhandle<<std::endl;
91 std::cout<<"handle released..."<<std::endl;
98 if(!gimmickfound || !usegimmick){
99 //int i, j, k, extint[6];
101 //unsigned short* ptr1, *ptr2;
103 new wxFileDialog( 0, _T("Read Image"),wxEmptyString,wxEmptyString, _T("*.mhd"));
105 if (FD->ShowModal()==wxID_OK)
107 std::string path= crea::wx2std(FD->GetPath());
108 vtkMetaImageReader* reader = vtkMetaImageReader::New();
109 reader->SetFileName(path.c_str());
112 img = vtkImageData::New();
113 img->DeepCopy(reader->GetOutput());
114 //reader->GetOutput()->Delete();
116 /*std::cout<<"image reference count "<<img->GetReferenceCount()<<std::endl;
117 reader->GetOutput()->GetSpacing(spacing);
118 img->SetSpacing(spacing);
119 reader->GetOutput()->GetExtent(extint);
120 img->SetExtent(extint);
121 img->SetScalarType(reader->GetOutput()->GetScalarType());
122 img->AllocateScalars();
123 std::cout<<"image reference count "<<img->GetReferenceCount()<<std::endl;
124 for (i=extint[0];i <= extint[1];i++){
125 for (j=extint[2];j<=extint[3];j++){
126 for (k=extint[4];k<=extint[5];k++){
128 ptr1=(unsigned short*) reader->GetOutput()->GetScalarPointer(i,j,k);
129 ptr2=(unsigned short*)img->GetScalarPointer(i,j,k);
135 /*std::cout<<"image reference count "<<img->GetReferenceCount()<<std::endl;*/
141 //-------------------------------------------------------------------
142 OpenImageDialog::~OpenImageDialog()
147 vtkImageData* OpenImageDialog::getImageData(){
150 std::string OpenImageDialog::getFilename(){