fw4spl
ools/src/fwMedDataTools/ModelSeries.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2014-2016.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwMedDataTools/ModelSeries.hpp"
8 
9 #include <fwCom/Signal.hxx>
10 #include <fwCore/spyLog.hpp>
11 
12 namespace fwMedDataTools
13 {
14 
15 //------------------------------------------------------------------------------
16 
17 void ModelSeries::addMesh(::fwMedData::ModelSeries::sptr &_modelSeries, const ::fwData::Mesh::sptr& _mesh,
18  const std::string& _organName, const std::string& _structureType,
19  const ::fwData::Color::sptr& _colour, ::fwData::Material::RepresentationType _mode,
20  bool _visible)
21 {
22  //reconstruction creation
23  ::fwData::Reconstruction::sptr reconstructionQuadMesh =
24  createReconstructionFromMesh(_mesh, _organName, _structureType, _colour,_mode, _visible);
25 
26  addReconstruction(_modelSeries, reconstructionQuadMesh);
27 
28  auto sig = _modelSeries->signal< ::fwMedData::ModelSeries::ReconstructionsAddedSignalType>(
30 
31  ::fwMedData::ModelSeries::ReconstructionVectorType reconstructionsVector;
32  reconstructionsVector.push_back(reconstructionQuadMesh);
33  sig->asyncEmit(reconstructionsVector);
34 }
35 
36 //------------------------------------------------------------------------------
37 
38 ::fwData::Reconstruction::sptr ModelSeries::createReconstructionFromMesh( const ::fwData::Mesh::sptr& _mesh,
39  const std::string& _organName,
40  const std::string& _structureType,
41  const ::fwData::Color::sptr& _color,
43  bool _visible)
44 {
45  ::fwData::Color::sptr diffuse = ::fwData::Color::New();
46  diffuse->setRGBA(_color->red(), _color->green(), _color->blue(), _color->alpha());
47  ::fwData::Material::sptr pMaterial = ::fwData::Material::New();
48  pMaterial->setDiffuse(diffuse);
49  pMaterial->setRepresentationMode(_mode);
50 
51  ::fwData::Reconstruction::sptr reconstruction = ::fwData::Reconstruction::New();
52  reconstruction->setMesh(_mesh);
53  reconstruction->setIsVisible(_visible);
54  reconstruction->setOrganName(_organName);
55  reconstruction->setStructureType(_structureType);
56  reconstruction->setMaterial(pMaterial);
57 
58  return reconstruction;
59 }
60 
61 //------------------------------------------------------------------------------
62 
63 void ModelSeries::addReconstruction( ::fwMedData::ModelSeries::sptr& _modelSeries, ::fwData::Reconstruction::sptr& _rec)
64 {
65  ::fwMedData::ModelSeries::ReconstructionVectorType recDB = _modelSeries->getReconstructionDB();
66 
67  FW_RAISE_IF("Reconstruction is invalid.", _rec == nullptr);
68  FW_RAISE_IF("Reconstruction already exists in ModelSeries.",
69  std::find(recDB.begin(), recDB.end(), _rec) != recDB.end());
70 
71  recDB.push_back(_rec);
72  _modelSeries->setReconstructionDB(recDB);
73 }
74 
75 //------------------------------------------------------------------------------
76 
77 } // end namespace fwDataTools
78 
79 
static FWMEDDATATOOLS_API void addReconstruction(::fwMedData::ModelSeries::sptr &_modelSeries,::fwData::Reconstruction::sptr &_rec)
Add a mesh into a model series. A reconstruction for this mesh will be created.
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_RECONSTRUCTIONS_ADDED_SIG
Key in m_signals map of signal m_sigReconstructionsAdded.
static FWMEDDATATOOLS_API::fwData::Reconstruction::sptr createReconstructionFromMesh(const ::fwData::Mesh::sptr &_mesh, const std::string &_organName, const std::string &_structureType, const ::fwData::Color::sptr &_color=::fwData::Color::New(),::fwData::Material::RepresentationType _mode=::fwData::Material::SURFACE, bool _visible=true)
Create a reconstruction from a mesh.
static FWMEDDATATOOLS_API void addMesh(::fwMedData::ModelSeries::sptr &_modelSeries, const ::fwData::Mesh::sptr &_mesh, const std::string &_organName, const std::string &_structureType, const ::fwData::Color::sptr &_color=::fwData::Color::New(),::fwData::Material::RepresentationType _mode=::fwData::Material::SURFACE, bool _visible=true)
Add a mesh into a model series. A reconstruction for this mesh will be automatically created...
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...
RepresentationType
Representation models.
Contains utilities dedicated to fwMedData.