3
* $Id: comandoexportacion.cpp 3527 2011-03-16 21:45:37Z carlos $
6
* Copyright 2008-10 MetaEmotion S.L. All rights reserved.
7
* http://ginkgo-cadx.com
9
* This file is licensed under LGPL v3 license.
10
* See License.txt for details
15
#pragma warning(disable: 4996)
20
#include <wx/filename.h>
23
#include <wx/confbase.h>
25
#include <api/globals.h>
26
#include <api/ientorno.h>
27
#include <api/internacionalizacion.h>
28
#include <api/icontextoestudio.h>
30
#include <main/entorno.h>
31
#include <main/controllers/controladoreventos.h>
33
#include <eventos/eventosginkgo.h>
35
#include "comandoexportacion.h"
37
#include <itkExceptionObject.h>
39
#include <itkOrientedImage.h>
40
#include <itkRGBPixel.h>
41
#include <itkGDCMImageIO.h>
42
#include <itkJPEGImageIO.h>
43
#include <itkPNGImageIO.h>
44
#include <itkVectorResampleImageFilter.h>
45
#include <itkLinearInterpolateImageFunction.h>
46
#include <itkImageFileWriter.h>
52
ComandoExportacion::ComandoExportacion(ComandoExportacionParams* pParams): GNC::GCS::IComando(pParams,"Exportacion")
54
m_pExportacionParams = pParams;
57
void ComandoExportacion::Execute()
59
if (!NotificarProgreso(0.0, _Std("Exporting files...")) )
61
if(m_pExportacionParams->m_pDatosPersistentes->m_formatoDestino == GNC::GUI::DICOM){
69
void ComandoExportacion::Update()
71
if (m_pExportacionParams->m_hasError)
73
GNC::GCS::ControladorEventos::Instance()->ProcesarEvento(new GNC::GCS::Eventos::EventoMensajes(NULL,m_pExportacionParams->m_Error, GNC::GCS::Eventos::EventoMensajes::StatusMessage,true, GNC::GCS::Eventos::EventoMensajes::Error));
75
GNC::GCS::ControladorEventos::Instance()->ProcesarEvento(new GNC::GCS::Eventos::EventoMensajes(NULL, _Std("Export has been finished sucessfully"), GNC::GCS::Eventos::EventoMensajes::StatusMessage,true, GNC::GCS::Eventos::EventoMensajes::Informacion));
81
void ComandoExportacion::ExportarDICOM()
83
GnkPtr<GNC::GUI::TipoWizardExportacion> pDatosPersistentes = m_pExportacionParams->m_pDatosPersistentes;
86
std::vector<std::string> resultado;
87
std::vector<std::string> listaPaths;
90
if (pDatosPersistentes->m_ficheroActual) {
91
listaPaths.push_back(pDatosPersistentes->m_pVista->GetEstudio()->GetRutaDeImagenActiva());
92
if(pDatosPersistentes->m_exportarDiagnostico) {
93
listaPaths.push_back(pDatosPersistentes->m_pVista->GetEstudio()->GetRutaDeDiagnosticoActivo());
98
listaPaths = pDatosPersistentes->m_pVista->GetRutasImagenes();
99
if(pDatosPersistentes->m_exportarDiagnostico) {
100
std::vector<std::string> diagnosticos;
101
diagnosticos = pDatosPersistentes->m_pVista->GetRutasDiagnosticos();
102
for(std::vector<std::string>::iterator it = diagnosticos.begin(); it!= diagnosticos.end(); it++) {
103
listaPaths.push_back((*it));
108
GIL::DICOM::IDICOMManager* pDICOMManager;
110
wxString wxPath = FROMPATH(pDatosPersistentes->m_pathDestino);
111
wxString destino(wxT(""));
114
for(std::vector<std::string>::iterator it = listaPaths.begin(); it!= listaPaths.end(); ++it,++contador) {
115
wxString cadena = wxString::Format(_("Exporting file %d of %d"), contador, listaPaths.size());
116
if (!NotificarProgreso((float)contador/listaPaths.size(), std::string(cadena.ToUTF8())))
119
GIL::DICOM::TipoJerarquia base;
121
pDICOMManager = GNC::Entorno::Instance()->GetControladorImportacionPACS()->CrearInstanciaDeDICOMManager();
122
pDICOMManager->CargarFichero((*it), base);
124
pDICOMManager->ActualizarJerarquia(pDatosPersistentes->m_base);
126
//anonimizar tags Ginkgo
127
if(!pDatosPersistentes->m_incluirTagsGinkgo){
128
pDICOMManager->AnonimizarTagsPrivados();
131
wxString destino = GetFichero(wxPath,wxT("dcm"));
133
std::string destinoStd(TOPATH(destino));
134
correcto = correcto && pDICOMManager->AlmacenarFichero(destinoStd);
135
resultado.push_back(destinoStd);
136
GNC::Entorno::Instance()->GetControladorImportacionPACS()->LiberarInstanciaDeDICOMManager(pDICOMManager);
140
m_pExportacionParams->m_Error = _Std("Error storing file, check the permissions over the directory.");
141
m_pExportacionParams->m_hasError = true;
146
void ComandoExportacion::ExportarImagenes()
148
GnkPtr<GNC::GUI::TipoWizardExportacion> pDatosPersistentes = m_pExportacionParams->m_pDatosPersistentes;
149
std::vector<std::string> resultado;
151
GNC::GCS::IContratoExportacionImages* pContratoImages = dynamic_cast<GNC::GCS::IContratoExportacionImages*>(pDatosPersistentes->m_pVista);
153
if(pContratoImages == NULL){
154
//error!!!! no deberia llegar porque en el paso uno no le deberia haber dejado seleccionar otra cosa que un dicom
155
m_pExportacionParams->m_Error = _Std("Unexpected Error exporting, the view is not allowed to export to the format selected");
156
m_pExportacionParams->m_hasError = true;
160
std::vector<std::string> listaPaths;
161
GNC::GCS::IContratoExportacionImages::ImageType::Pointer img;
163
if(pDatosPersistentes->m_ficheroActual){
164
wxString cadena = wxString::Format(_("Exporting file %d of %d"), 1, 1);
165
if (!NotificarProgreso(0.2, std::string(cadena.ToUTF8())))
168
pContratoImages->GetImageActual(img, pDatosPersistentes->m_mapasValoracion, pDatosPersistentes->m_incluirWidgets, GNC::GCS::Vector::NaN());
169
wxString res=ExportarImage(img);
170
if(res!=wxEmptyString){
171
std::string strTmp(TOPATH(res));
172
resultado.push_back(strTmp);
177
int size = pDatosPersistentes->m_pVista->GetRutasImagenes().size();
178
for(std::string::size_type i = 0; (int)i < size; i++){
179
wxString cadena = wxString::Format(_("Exporting file %d of %d"), i+1, size);
180
if (!NotificarProgreso((float)i/size, std::string(cadena.ToUTF8())))
183
pContratoImages->GetImage(img, i, pDatosPersistentes->m_mapasValoracion, pDatosPersistentes->m_incluirWidgets, GNC::GCS::Vector::NaN());
184
wxString res = ExportarImage(img);
185
if(res != wxEmptyString){
186
std::string strTmp(TOPATH(res));
187
resultado.push_back(strTmp);
192
catch(itk::ExceptionObject& ex) {
193
std::cerr << "Error" << ex.GetDescription() << std::endl;
195
m_pExportacionParams->m_Error = _Std("Failed to store the file, check permissions on the directory");
196
m_pExportacionParams->m_hasError = true;
200
wxString ComandoExportacion::ExportarImage(GNC::GCS::IContratoExportacionImages::ImageType::Pointer img)
202
GnkPtr<GNC::GUI::TipoWizardExportacion> pDatosPersistentes = m_pExportacionParams->m_pDatosPersistentes;
204
m_pExportacionParams->m_Error = _Std("The key files will not be exported");
205
m_pExportacionParams->m_hasError = true;
206
return wxEmptyString;
209
wxString destino = wxEmptyString;
211
wxString wxPath = FROMPATH(pDatosPersistentes->m_pathDestino);
213
typedef itk::ImageFileWriter<GNC::GCS::IContratoExportacionImages::ImageType> TipoWriter;
214
TipoWriter::Pointer writer = TipoWriter::New();
215
writer->SetInput(img);
218
switch(pDatosPersistentes->m_formatoDestino) {
221
destino = GetFichero(wxPath,wxT("bmp"));
222
std::string strTmp (TOPATH(destino));
223
writer->SetFileName(strTmp.c_str());
228
destino = GetFichero(wxPath,wxT("jpg"));
229
std::string strTmp (TOPATH(destino));
230
writer->SetFileName(strTmp.c_str());
231
itk::JPEGImageIO::Pointer imageIO = itk::JPEGImageIO::New();
232
writer->SetImageIO(imageIO);
233
imageIO->SetUseCompression(true);
234
imageIO->SetQuality(pDatosPersistentes->m_jpegCalidad);
239
destino = GetFichero(wxPath,wxT("png"));
240
std::string strTmp (TOPATH(destino));
241
writer->SetFileName(strTmp.c_str());
244
case GNC::GUI::DICOM:
252
wxString ComandoExportacion::GetFichero(const wxString& dir, const wxString& extension){
253
wxString destino(wxEmptyString);
254
std::string nombre (wxDateTime::Now().Format(_("image_%m-%d-%Y_")).ToUTF8());
255
std::string stdDir(TOPATH(dir));
256
std::string stdExtension(TOPATH(extension));
258
//yy-mm-dd_imagen_indice
260
std::ostringstream ostr;
261
ostr << stdDir << (char)wxFileName::GetPathSeparator() << nombre << indice++ << "." << stdExtension;
262
destino = FROMPATH(ostr.str());
263
} while(wxFile::Exists(destino));