7 #include "uiMedDataQt/editor/SOrganTransformation.hpp" 9 #include <fwData/Composite.hpp> 10 #include <fwData/Material.hpp> 11 #include <fwData/Mesh.hpp> 12 #include <fwData/Reconstruction.hpp> 14 #include <fwDataTools/helper/Composite.hpp> 15 #include <fwDataTools/helper/Field.hpp> 16 #include <fwDataTools/TransformationMatrix3D.hpp> 18 #include <fwGuiQt/container/QtContainer.hpp> 20 #include <fwMedData/ModelSeries.hpp> 22 #include <fwServices/macros.hpp> 24 #include <fwTools/fwID.hpp> 29 #include <QListWidget> 30 #include <QListWidgetItem> 31 #include <QPushButton> 33 #include <QStringList> 34 #include <QVBoxLayout> 45 static const ::fwServices::IService::KeyType s_MODEL_SERIES_INOUT =
"modelSeries";
46 static const ::fwServices::IService::KeyType s_COMPOSITE_INOUT =
"composite";
48 static const std::string s_MATRIX_FIELD_NAME =
"TransformMatrix";
54 m_reconstructionListBox( 0 ),
77 ::fwGuiQt::container::QtContainer::sptr qtContainer =
78 ::fwGuiQt::container::QtContainer::dynamicCast( this->getContainer() );
80 QVBoxLayout* layout =
new QVBoxLayout();
82 QGroupBox* groupBox =
new QGroupBox(tr(
"Organs") );
83 layout->addWidget( groupBox);
85 QVBoxLayout* layoutGroupBox =
new QVBoxLayout();
86 groupBox->setLayout(layoutGroupBox);
88 m_selectAllCheckBox =
new QCheckBox(tr(
"Select All") );
89 m_reconstructionListBox =
new QListWidget( groupBox);
90 m_resetButton =
new QPushButton(tr(
"Reset") );
91 m_saveButton =
new QPushButton(tr(
"Save") );
92 m_loadButton =
new QPushButton(tr(
"Load") );
93 m_saveSelectionComboBox =
new QComboBox();
95 QObject::connect(m_reconstructionListBox,
96 SIGNAL(itemClicked(QListWidgetItem*)),
98 SLOT(onReconstructionCheck(QListWidgetItem*)));
99 QObject::connect(m_resetButton, SIGNAL(clicked()),
this, SLOT(onResetClick()));
100 QObject::connect(m_saveButton, SIGNAL(clicked()),
this, SLOT(onSaveClick()));
101 QObject::connect(m_loadButton, SIGNAL(clicked()),
this, SLOT(onLoadClick()));
102 QObject::connect(m_selectAllCheckBox, SIGNAL(stateChanged(
int)),
this, SLOT(onSelectAllChanged(
int)));
104 layoutGroupBox->addWidget( m_selectAllCheckBox, 0);
105 layoutGroupBox->addWidget( m_reconstructionListBox, 1);
106 layoutGroupBox->addWidget( m_resetButton, 0);
107 layoutGroupBox->addWidget( m_saveButton, 0);
108 layoutGroupBox->addWidget( m_saveSelectionComboBox, 0);
109 layoutGroupBox->addWidget( m_loadButton, 0);
111 qtContainer->setLayout( layout );
120 QObject::disconnect(m_reconstructionListBox,
121 SIGNAL(itemClicked(QListWidgetItem*)),
123 SLOT(onReconstructionCheck(QListWidgetItem*)));
124 QObject::disconnect(m_resetButton, SIGNAL(clicked()),
this, SLOT(onResetClick()));
125 QObject::disconnect(m_saveButton, SIGNAL(clicked()),
this, SLOT(onSaveClick()));
126 QObject::disconnect(m_loadButton, SIGNAL(clicked()),
this, SLOT(onLoadClick()));
127 QObject::disconnect(m_selectAllCheckBox, SIGNAL(stateChanged(
int)),
this, SLOT(onSelectAllChanged(
int)));
143 this->addMeshTransform();
149 void SOrganTransformation::info( ::std::ostream& sstream )
155 void SOrganTransformation::refresh()
157 m_reconstructionMap.clear();
158 m_reconstructionListBox->clear();
160 ::fwMedData::ModelSeries::sptr series = this->getInOut< ::fwMedData::ModelSeries >(s_MODEL_SERIES_INOUT);
162 ::fwGuiQt::container::QtContainer::sptr qtContainer =
163 ::fwGuiQt::container::QtContainer::dynamicCast( this->getContainer() );
164 QWidget*
const container = qtContainer->getQtContainer();
165 SLM_ASSERT(
"container not instanced", container);
167 bool hasReconstructions = !series->getReconstructionDB().empty();
168 container->setEnabled( hasReconstructions );
170 if(hasReconstructions)
172 ::fwData::Composite::sptr pComposite = this->getInOut< ::fwData::Composite>(s_COMPOSITE_INOUT);
174 for(::fwData::Reconstruction::sptr rec : series->getReconstructionDB())
176 m_reconstructionMap[ rec->getOrganName() ] = rec;
179 for( ReconstructionMapType::iterator it = m_reconstructionMap.begin(); it != m_reconstructionMap.end(); ++it )
181 std::string organName = it->first;
182 QListWidgetItem* item =
new QListWidgetItem(QString::fromStdString(organName), m_reconstructionListBox);
183 if( pComposite && pComposite->find(organName) != pComposite->end())
185 item->setCheckState(Qt::Checked);
189 item->setCheckState(Qt::Unchecked);
191 m_reconstructionListBox->addItem(item);
198 void SOrganTransformation::notitfyTransformationMatrix(::fwData::TransformationMatrix3D::sptr aTransMat)
206 void SOrganTransformation::onReconstructionCheck(QListWidgetItem* currentItem)
208 ::fwData::Composite::sptr pComposite = this->getInOut< ::fwData::Composite>(s_COMPOSITE_INOUT);
209 if (pComposite !=
nullptr)
211 ::std::string item_name = currentItem->text().toStdString();
212 ::fwData::Reconstruction::sptr pReconstruction = m_reconstructionMap[item_name];
213 ::fwData::Mesh::sptr pMesh = pReconstruction->getMesh();
216 if ((currentItem->checkState()) == Qt::Checked)
218 if (pComposite->find(item_name) == pComposite->end())
220 aCompositeHelper.
add(item_name, pMesh);
224 aCompositeHelper.
swap(item_name, pMesh);
229 if (pComposite->find(item_name) != pComposite->end())
231 aCompositeHelper.
remove(item_name);
234 aCompositeHelper.
notify();
240 void SOrganTransformation::onResetClick()
242 ::fwMedData::ModelSeries::sptr series = this->getInOut< ::fwMedData::ModelSeries >(s_MODEL_SERIES_INOUT);
245 for(::fwData::Reconstruction::sptr rec : series->getReconstructionDB())
247 ::fwData::Mesh::sptr pTmpTrMesh = rec->getMesh();
249 ::fwData::TransformationMatrix3D::sptr pTmpMat =
254 this->notitfyTransformationMatrix(pTmpMat);
261 void SOrganTransformation::onSaveClick()
263 InnerMatMappingType matMap;
265 ::fwMedData::ModelSeries::sptr series = this->getInOut< ::fwMedData::ModelSeries >(s_MODEL_SERIES_INOUT);
267 if(!series->getReconstructionDB().empty())
269 for(::fwData::Reconstruction::sptr rec : series->getReconstructionDB())
271 ::fwData::Mesh::sptr pTmpTrMesh = rec->getMesh();
272 ::fwData::TransformationMatrix3D::sptr pTmpMat =
276 ::fwData::TransformationMatrix3D::sptr pCpyTmpMat;
278 matMap[pTmpTrMesh->getID()] = pCpyTmpMat;
282 ::std::stringstream tmpSaveName;
283 tmpSaveName <<
"save_" << m_saveCount;
284 m_saveListing[tmpSaveName.str()] = matMap;
285 m_saveSelectionComboBox->addItem(QString::fromStdString(tmpSaveName.str()));
292 void SOrganTransformation::onLoadClick()
294 if (m_saveSelectionComboBox->count() != 0)
296 InnerMatMappingType matMap = m_saveListing[m_saveSelectionComboBox->currentText().toStdString()];
298 ::fwMedData::ModelSeries::sptr series = this->getInOut< ::fwMedData::ModelSeries >(s_MODEL_SERIES_INOUT);
301 for(::fwData::Reconstruction::sptr rec : series->getReconstructionDB())
303 ::fwData::Mesh::sptr pTmpTrMesh = rec->getMesh();
304 if (matMap.find(pTmpTrMesh->getID()) != matMap.end())
306 ::fwData::TransformationMatrix3D::sptr pTmpMat =
311 this->notitfyTransformationMatrix(pTmpMat);
320 void SOrganTransformation::onSelectAllChanged(
int state)
323 ::fwData::Composite::sptr composite = this->getInOut< ::fwData::Composite>(s_COMPOSITE_INOUT);
326 if(state == Qt::Checked)
328 m_reconstructionListBox->setEnabled(
false);
330 ::fwMedData::ModelSeries::sptr series = this->getInOut< ::fwMedData::ModelSeries >(s_MODEL_SERIES_INOUT);
332 for(::fwData::Reconstruction::sptr rec : series->getReconstructionDB())
334 if(composite->find(rec->getOrganName()) == composite->end())
336 compositeHelper.add(rec->getOrganName(), rec->getMesh());
341 else if(state == Qt::Unchecked)
343 m_reconstructionListBox->setEnabled(
true);
345 QList<QListWidgetItem*> itemList = m_reconstructionListBox->findItems(
"", Qt::MatchContains);
346 for(QListWidgetItem* item : itemList)
348 if(item->checkState() == Qt::Unchecked)
350 compositeHelper.remove(item->text().toStdString());
356 compositeHelper.notify();
362 void SOrganTransformation::addMeshTransform()
364 ::fwMedData::ModelSeries::sptr series = this->getInOut< ::fwMedData::ModelSeries >(s_MODEL_SERIES_INOUT);
366 for(const ::fwData::Reconstruction::sptr& rec : series->getReconstructionDB())
368 ::fwData::Mesh::sptr mesh = rec->getMesh();
370 if (!mesh->getField( s_MATRIX_FIELD_NAME ))
373 fieldHelper.
setField(s_MATRIX_FIELD_NAME, ::fwData::TransformationMatrix3D::New());
The namespace uiMedDataQt contains editors for medical data.
This class is a helper to define the connections of a service and its data.
Defines the service interface managing the editor service for object.
FWGUI_API void destroy()
Stops sub-views and toobar services. Destroys view, sub-views and toolbar containers.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CHANGED_OBJECTS_SIG
Type of signal when objects are added.
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_RECONSTRUCTIONS_ADDED_SIG
Key in m_signals map of signal m_sigReconstructionsAdded.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_OBJECTS_SIG
Type of signal when objects are added.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWDATA_API::fwData::Object::sptr copy(const ::fwData::Object::csptr &source)
return a copy of the source. if source is a null pointer, return a null pointer.
FWGUI_API void create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_OBJECTS_SIG
Type of signal when objects are added.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_RECONSTRUCTIONS_REMOVED_SIG
Key in m_signals map of signal m_sigReconstructionsRemoved.
FWGUI_API void initialize()
Initialize managers.