fw4spl
SMeshModifier.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
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 "Tuto14MeshGenerator/SMeshModifier.hpp"
8 
9 #include <fwCom/Signal.hxx>
10 
11 #include <fwData/Mesh.hpp>
12 
13 #include <fwDataTools/Mesh.hpp>
14 
15 #include <fwGui/dialog/MessageDialog.hpp>
16 
17 #include <fwServices/macros.hpp>
18 
19 namespace Tuto14MeshGenerator
20 {
21 
22 fwServicesRegisterMacro( ::fwGui::IActionSrv, ::Tuto14MeshGenerator::SMeshModifier, ::fwData::Mesh );
23 
24 //-----------------------------------------------------------------------------
25 
27 {
28 }
29 
30 //-----------------------------------------------------------------------------
31 
33 {
34 }
35 
36 //-----------------------------------------------------------------------------
37 
39 {
40  this->initialize();
41 
42  std::vector < ConfigurationType > vectConfig = m_configuration->find("config");
43 
44  SLM_ASSERT("There must be one (and only one) <config functor=... /> element.", vectConfig.size() == 1 );
45  ::fwRuntime::ConfigurationElement::sptr configElement = vectConfig.at(0);
46 
47  SLM_ASSERT( "There must be a functor attribute in the <config> xml element.",
48  configElement->hasAttribute("functor") );
49  m_functor = configElement->getExistingAttributeValue("functor");
50  OSLM_ASSERT("Wrong functor name "<<m_functor << " (required GenTriangle, GenQuad or GenTriangleQuad)",
51  m_functor == "ShakeMeshPoint"
52  || m_functor == "ColorizeMeshPoints"
53  || m_functor == "ColorizeMeshCells"
54  || m_functor == "ComputePointNormals"
55  || m_functor == "ComputeCellNormals"
56  || m_functor == "ShakePointNormals"
57  || m_functor == "ShakeCellNormals"
58  || m_functor == "MeshDeformation"
59  );
60 
61 }
62 
63 //-----------------------------------------------------------------------------
64 
66 {
68  this->actionServiceStarting();
70 }
71 
72 //-----------------------------------------------------------------------------
73 
75 {
77  this->actionServiceStopping();
78 }
79 
80 //-----------------------------------------------------------------------------
81 
83 {
85  ::fwData::Mesh::sptr mesh = this->getInOut< ::fwData::Mesh >("mesh");
86  SLM_ASSERT("Mesh dynamicCast failed", mesh);
87  try
88  {
89  if(m_functor == "ShakeMeshPoint")
90  {
92 
93  ::fwData::Mesh::VertexModifiedSignalType::sptr sig;
95  sig->asyncEmit();
96  }
97  else if(m_functor == "ColorizeMeshCells")
98  {
100 
101  ::fwData::Mesh::CellColorsModifiedSignalType::sptr sig;
102  sig = mesh->signal< ::fwData::Mesh::CellColorsModifiedSignalType >(
104  sig->asyncEmit();
105  }
106  else if(m_functor == "ColorizeMeshPoints")
107  {
109 
110  ::fwData::Mesh::PointColorsModifiedSignalType::sptr sig;
111  sig = mesh->signal< ::fwData::Mesh::PointColorsModifiedSignalType >(
113  sig->asyncEmit();
114  }
115  else if(m_functor == "ComputeCellNormals")
116  {
118 
119  ::fwData::Mesh::CellNormalsModifiedSignalType::sptr sig;
120  sig = mesh->signal< ::fwData::Mesh::CellNormalsModifiedSignalType >(
122  sig->asyncEmit();
123  }
124  else if(m_functor == "ComputePointNormals")
125  {
127 
128  ::fwData::Mesh::PointNormalsModifiedSignalType::sptr sig;
131  sig->asyncEmit();
132  }
133  else if(m_functor == "ShakeCellNormals")
134  {
136 
137  ::fwData::Mesh::CellNormalsModifiedSignalType::sptr sig;
138  sig = mesh->signal< ::fwData::Mesh::CellNormalsModifiedSignalType >(
140  sig->asyncEmit();
141  }
142  else if(m_functor == "ShakePointNormals")
143  {
145 
146  ::fwData::Mesh::PointNormalsModifiedSignalType::sptr sig;
149  sig->asyncEmit();
150  }
151  else if(m_functor == "MeshDeformation")
152  {
153  m_animator.computeDeformation( mesh, 100, 50 );
154  ::fwData::Object::ModifiedSignalType::sptr sig;
156  {
157  ::fwCom::Connection::Blocker block(sig->getConnection(m_slotUpdate));
158  sig->asyncEmit();
159  }
160  }
161  }
162  catch (const std::exception& e)
163  {
164  std::stringstream ss;
165  ss << "Warning during generating : " << e.what();
166 
168  "Warning",
169  ss.str(),
170  ::fwGui::dialog::IMessageDialog::WARNING);
171  }
172 }
173 
174 //-----------------------------------------------------------------------------
175 
176 void SMeshModifier::info(std::ostream& _sstream )
177 {
178  _sstream << "MeshGenerator Action" << std::endl;
179 }
180 
181 //-----------------------------------------------------------------------------
182 
183 }
184 
static FWDATATOOLS_API void shakeCellNormals(::fwData::Mesh::sptr mesh)
Shake cell Normals.
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
Definition: IActionSrv.cpp:160
virtual TUTO14MESHGENERATOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
#define OSLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:310
static FWDATATOOLS_API void shakePointNormals(::fwData::Mesh::sptr mesh)
Shake point Normals.
Class allowing to block a Connection.
Definition: Connection.hpp:20
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINT_NORMALS_MODIFIED_SIG
Key in m_signals map of signal m_sigPointNormalsModified.
static FWGUI_API IMessageDialog::Buttons showMessageDialog(const std::string &title, const std::string &message,::fwGui::dialog::IMessageDialog::Icons icon=INFO)
static FWDATATOOLS_API void generateCellNormals(::fwData::Mesh::sptr mesh)
Generate cell normals for the mesh.
virtual TUTO14MESHGENERATOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CELL_COLORS_MODIFIED_SIG
Key in m_signals map of signal m_sigCellColorsModified.
static FWDATATOOLS_API void colorizeMeshCells(::fwData::Mesh::sptr mesh)
Colorize mesh (cell color).
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CELL_NORMALS_MODIFIED_SIG
Key in m_signals map of signal m_sigCellNormalsModified.
static FWDATATOOLS_API void generatePointNormals(::fwData::Mesh::sptr mesh)
Generate point normals for the mesh.
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
Definition: IService.hpp:690
TUTO14MESHGENERATOR_API void computeDeformation(::fwData::Mesh::sptr _mesh, const unsigned int _nbStep, const unsigned int _amplitude)
Compute deformation or init algo if necessary.
TUTO14MESHGENERATOR_API SMeshModifier() noexcept
Constructor. Do nothing.
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
Definition: IService.hpp:670
virtual TUTO14MESHGENERATOR_API void info(std::ostream &_sstream) override
This method gives information about the class.
virtual TUTO14MESHGENERATOR_API void updating() override
Process the action: modifies the mesh using the selected functor.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_VERTEX_MODIFIED_SIG
Key in m_signals map of signal m_sigVertexModified.
virtual TUTO14MESHGENERATOR_API void starting() override
Initialize the service activity.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
virtual TUTO14MESHGENERATOR_API ~SMeshModifier() noexcept
Destructor. Do nothing.
static FWDATATOOLS_API void initRand()
Initialize &#39;rand&#39; seed.
static FWDATATOOLS_API void shakePoint(::fwData::Mesh::sptr mesh)
Shake points of the mesh.
This action modifies a mesh using specified functor in configuration. The purpose is to test all poss...
static FWDATATOOLS_API void colorizeMeshPoints(::fwData::Mesh::sptr mesh)
Colorize mesh (vertex point color).
Data holding a geometric structure composed of points, lines, triangles, quads or polygons...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINT_COLORS_MODIFIED_SIG
Key in m_signals map of signal m_sigPointColorsModified.