X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvDeformableRegistration.cxx;h=12a2959aa33679b8ab5f6bde9349e0d859eeba5c;hb=82b7d4913d5fbd074f7ab4cc641513546d9f39a4;hp=e5f861c49d08ba290b6ed5646f4068da26a11a30;hpb=931a42358442f4ee4f314613c991c838d4b4e3b7;p=clitk.git diff --git a/vv/vvDeformableRegistration.cxx b/vv/vvDeformableRegistration.cxx index e5f861c..12a2959 100644 --- a/vv/vvDeformableRegistration.cxx +++ b/vv/vvDeformableRegistration.cxx @@ -1,3 +1,20 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://www.centreleonberard.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +===========================================================================**/ #include #include #include @@ -10,6 +27,7 @@ #include "vtkVOXImageWriter.h" #include +#include #include "clitkCommon.h" #include "vvSlicerManager.h" @@ -19,162 +37,158 @@ #include "vvImageReader.h" vvDeformableRegistration::vvDeformableRegistration(vvImage::Pointer image,unsigned int ref,\ - unsigned int iter, unsigned int nthread,double a, double s,std::string output_f,unsigned int stop) : - mImage(image), - refimage(ref), - nb_iter(iter), - n_thread(nthread), - progress(0), - stop(stop), - alpha(a), - sigma(s), - output_filename(output_f), - aborted(false) + unsigned int iter, unsigned int nthread,double a, double s,std::string output_f,unsigned int stop) : + mImage(image), + refimage(ref), + nb_iter(iter), + n_thread(nthread), + progress(0), + stop(stop), + alpha(a), + sigma(s), + output_filename(output_f), + aborted(false) { } void vvDeformableRegistration::abort() { - aborted=true; - std::system("killall deformableregistration"); - std::system("killall clitkVFMerge"); + aborted=true; + std::system("killall deformableregistration"); + std::system("killall clitkVFMerge"); } unsigned int vvDeformableRegistration::getProgress() { - QMutexLocker locker(&progress_mutex); - unsigned int retval=progress; - return retval; + QMutexLocker locker(&progress_mutex); + unsigned int retval=progress; + return retval; } void vvDeformableRegistration::cleanup(int frame_number) //remove temporary files { - std::string temp_dir=mTempPath.toStdString(); - for (int i=0;iapplicationPid()); - QDir temp_qt_dir; - DD(temp_qt_dir.mkpath(mTempPath)); - std::string temp_dir=mTempPath.toStdString(); - DD(temp_dir); - std::vector images=mImage->GetVTKImages(); - for (unsigned int i=0;iSetInput(images[i]); - vox->SetFileName(filename.str().c_str()); - if (i==refimage) - ref_file=filename.str(); - vox->Write(); - } - vox->Delete(); - progress++; - int reg_per_thread=static_cast(images.size()-1)/n_thread; - int remainder=static_cast(images.size()-1) - reg_per_thread*n_thread; + clock_t start,finish; + start=clock(); + vtkVOXImageWriter * vox = vtkVOXImageWriter::New(); + std::stringstream command; + std::string ref_file; + mTempPath=QDir::tempPath()+QString("/vv-")+QString::number(qApp->applicationPid()); + QDir temp_qt_dir; + DD(temp_qt_dir.mkpath(mTempPath)); + std::string temp_dir=mTempPath.toStdString(); + DD(temp_dir); + std::vector images=mImage->GetVTKImages(); + for (unsigned int i=0; iSetInput(images[i]); +#else + vox->SetInputData(images[i]); +#endif + vox->SetFileName(filename.str().c_str()); + if (i==refimage) + ref_file=filename.str(); + vox->Write(); + } + vox->Delete(); + progress++; + int reg_per_thread=static_cast(images.size()-1)/n_thread; + int remainder=static_cast(images.size()-1) - reg_per_thread*n_thread; #pragma omp parallel for num_threads(n_thread) schedule(static) - for (int i=0;i(n_thread);i++) - { - ///Static scheduling - int remainder_shift=((iGetOrigin()[0]; - command << " --yorigin " << images[0]->GetOrigin()[1]; - command << " --zorigin " << images[0]->GetOrigin()[2]; - command << " -o " << output_filename << std::endl; - DD(command.str()); - std::system(command.str().c_str()); + for (int i=0; i(n_thread); i++) { + ///Static scheduling + int remainder_shift=((i(CLOCKS_PER_SEC)); - mOutput=reader.GetOutput(); + return; + } + command.str(""); + int computed_vf=(refimage==0)?1:0; //index of an image that isn't the reference image + command << "clitkZeroVF -i " << temp_dir << "/deformation_" << computed_vf << ".vf -o " << temp_dir << + "/deformation_" << refimage << ".vf"; + DD(command.str()); //create zero VF for the ref image + std::system(command.str().c_str()); + command.str(""); + command << "clitkVFMerge "; + for (unsigned int i=0; iGetOrigin()[0]; + command << " --yorigin " << images[0]->GetOrigin()[1]; + command << " --zorigin " << images[0]->GetOrigin()[2]; + command << " -o " << output_filename << std::endl; + DD(command.str()); + std::system(command.str().c_str()); + cleanup(images.size()); + if (aborted) { + std::system(("rm " + output_filename).c_str()); + return; + } + vvImageReader::Pointer reader = vvImageReader::New(); + reader->SetInputFilename(output_filename); + reader->Update(vvImageReader::VECTORFIELD); + finish=clock(); + DD((finish - start)/static_cast(CLOCKS_PER_SEC)); + mOutput = reader->GetOutput(); }