(core): hard-coded label value to generate mesh
Description
Service sight::module::filter::mesh::SVTKMesher
uses a hard-coded label value (255) to generate a mesh.
Proposal
- Add a XML configuration setting
<config threshold="255" />
- Add a slot that takes a integer value to set the threshold
Besides this, sight::module::filter::mesh::action::SMeshCreation
does exactly the same job except that it is an IAction
. This should simply be removed.
It is only used once in Tuto05Mesher, it should be replaced by a sight::module::filter::mesh::SVTKMesher
called by a SStarter
(like in Tuto08MesherWithGenericScene
) or a SSlotCaller.
In tutorials/examples where the mesher is used, that would be nice to have a slider to set the threshold (SParameters
will be your friend).
Functional specifications
The value of the threshold can be set by the user, either in XML or with the UI.
Technical specifications
Details of the implementation
- add threshold configuration in
modules::filter::mesh::SVTKMesher.cpp
also set it inexamples::filter::ExDicomSegmentation::rc::VTKMesher
as<config threshold="255" />
Add threshold in config xml something like this
<service uid="mesherAct" type="sight::module::filter::mesh::SVTKMesher">
<in key="imageSeries" uid="${imageSeries}" />
<out key="modelSeries" uid="modelSeries" />
<config percentReduction="50" threshold="255" />
</service>
<service uid="mesher80Srv" type="sight::module::filter::mesh::SVTKMesher">
<in key="imageSeries" uid="imageSeries" />
<out key="modelSeries" uid="modelSeries" />
<config percentReduction="80" threshold="255" />
</service>
// contour filter
// set m_threshold instead of using 255 hard coded as it is in existing codes
auto contourFilter = vtkSmartPointer<vtkDiscreteMarchingCubes>::New();
contourFilter->SetInputData(vtkImage);
contourFilter->SetValue(0, m_threshold);
contourFilter->ComputeScalarsOn();
contourFilter->ComputeNormalsOn();
contourFilter->Update();
Add the value of threshold by using UI
<service uid="thresholdSliderSrv" type="sight::module::ui::qt::SParameters" >
<parameters>
<param type="int" name="threshold" key="threshold" widget="slider" defaultValue="255" min="0" max="255" depends="enable"/>
</parameters>
</service>
<connect>
<signal>thresholdSliderSrv/intChanged</signal>
<slot>SVTKMesher/updateThreshold</slot>
</connect>
// Implement updateThreshold slot function in the SVTKMesher.cpp
void SVTKMesher::updateThreshold(int threshold)
{
m_threshold = threshold
this->update()
}
- Remove
sight::module::filter::mesh::action::SMeshCreation
this should be replaced bysight::module::filter::mesh::SVTKMesher
in Tuto05Mesher where it is used. something like this
// use this
<service uid="createMeshAct" type="sight::module::ui::base::com::SSlotCaller" >
<slots>
<slot>svtkMesherSrv/updateThreshold</slot>
</slots>
</service>
// instead of this
<service uid="createMeshAct" type="sight::module::filter::mesh::action::SMeshCreation" >
<in key="image" uid="myImage" />
<inout key="mesh" uid="myMesh" />
<percentReduction value="0" />
</service>
Test plan
- Test the application
- We could write a basic test:
- validate the life cycle of the service
- test that a mesh is generated
- do not test the output mesh in detail (this might be fragile to maintain and we don't want to test VTK itself)
- maybe only the number of points if the threshold is right ( > N ) or not ( == 0)
- maybe also check that the percent reduction is applied (number of points superior or inferior)