/*========================================================================= 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 #include #include #include #include #include #include "vtkVOXImageWriter.h" #include #include #include "clitkCommon.h" #include "vvSlicerManager.h" #include "vvDeformableRegistration.h" #include "vvImage.h" #include "vvImage.h" #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) { } void vvDeformableRegistration::abort() { aborted=true; int tempReturn = std::system("killall deformableregistration"); tempReturn = std::system("killall clitkVFMerge"); } unsigned int vvDeformableRegistration::getProgress() { 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]); #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()); tempReturn = std::system(command.str().c_str()); cleanup(images.size()); if (aborted) { tempReturn = 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(); }