7 #include "opVTKMesh/action/SMeshCreation.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 11 #include <fwCom/Signals.hpp> 13 #include <fwData/Image.hpp> 14 #include <fwData/Mesh.hpp> 16 #include <fwServices/macros.hpp> 18 #include <fwTools/fwID.hpp> 20 #include <fwVtkIO/helper/Mesh.hpp> 21 #include <fwVtkIO/vtk.hpp> 23 #include <vtkDecimatePro.h> 24 #include <vtkDiscreteMarchingCubes.h> 25 #include <vtkGeometryFilter.h> 26 #include <vtkImageData.h> 27 #include <vtkPolyDataMapper.h> 28 #include <vtkSmartPointer.h> 29 #include <vtkThreshold.h> 30 #include <vtkWindowedSincPolyDataFilter.h> 45 SMeshCreation::SMeshCreation() noexcept :
52 SMeshCreation::~SMeshCreation() noexcept
80 m_configuration->findConfigurationElement(
"percentReduction")->hasAttribute(
"value"))
82 std::string reduce =
m_configuration->findConfigurationElement(
"percentReduction")->getExistingAttributeValue(
84 m_reduction = boost::lexical_cast<
unsigned int>(reduce);
87 OSLM_INFO(
"Reduction value = " << m_reduction);
97 auto pImage = this->getInput< ::fwData::Image >(
"image");
99 auto pMesh = this->getInOut< ::fwData::Mesh >(
"mesh");
105 vtkSmartPointer< vtkImageData > vtkImage = vtkSmartPointer< vtkImageData >::New();
106 ::fwVtkIO::toVTKImage( pImage, vtkImage );
109 vtkSmartPointer< vtkDiscreteMarchingCubes > contourFilter = vtkSmartPointer< vtkDiscreteMarchingCubes >::New();
110 contourFilter->SetInputData(vtkImage);
111 contourFilter->SetValue(0, 255);
112 contourFilter->ComputeScalarsOn();
113 contourFilter->ComputeNormalsOn();
114 contourFilter->Update();
117 vtkSmartPointer< vtkWindowedSincPolyDataFilter > smoothFilter =
118 vtkSmartPointer< vtkWindowedSincPolyDataFilter >::New();
119 smoothFilter->SetInputConnection(contourFilter->GetOutputPort());
120 smoothFilter->SetNumberOfIterations( 50 );
121 smoothFilter->BoundarySmoothingOn();
122 smoothFilter->SetPassBand ( 0.1 );
123 smoothFilter->SetFeatureAngle(120.0);
124 smoothFilter->SetEdgeAngle(90);
125 smoothFilter->FeatureEdgeSmoothingOn();
126 smoothFilter->Update();
130 vtkSmartPointer< vtkPolyData > polyData;
133 unsigned int reduction = m_reduction;
136 vtkSmartPointer< vtkDecimatePro > decimate = vtkSmartPointer< vtkDecimatePro >::New();
137 decimate->SetInputConnection( smoothFilter->GetOutputPort() );
138 decimate->SetTargetReduction( reduction/100.0 );
139 decimate->PreserveTopologyOff();
140 decimate->SplittingOn();
141 decimate->BoundaryVertexDeletionOn();
142 decimate->SetSplitAngle( 120 );
144 polyData = decimate->GetOutput();
145 OSLM_TRACE(
"final GetNumberOfCells = " << polyData->GetNumberOfCells());
150 polyData = smoothFilter->GetOutput();
151 OSLM_TRACE(
"final GetNumberOfCells = " << polyData->GetNumberOfCells());
156 ::fwData::Object::ModifiedSignalType::sptr sig;
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
Class allowing to block a Connection.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
OPVTKMESH_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
The namespace opVTKMesh contains an implementation of a VTK mesher.
#define OSLM_INFO(message)
#define OSLM_TRACE(message)
Defines the service interface managing the menu items.
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
OPVTKMESH_API void configuring() override
Configure the service.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWGUI_API void initialize()
Initialize the action.
OPVTKMESH_API void updating() override
Process the mesh creation from the image.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
Action to create a mesh from an image using VTK library.
static FWVTKIO_API void fromVTKMesh(vtkSmartPointer< vtkPolyData > _polyData,::fwData::Mesh::sptr _mesh)
Convert a vtkPolyData to a ::fwData::Mesh::sptr.
OPVTKMESH_API void starting() override
Initialize the service activity.