7 #include "visuVTKAdaptor/SImagesProbeCursor.hpp" 9 #include <fwData/Composite.hpp> 10 #include <fwData/Image.hpp> 11 #include <fwData/Integer.hpp> 13 #include <fwDataTools/fieldHelper/Image.hpp> 14 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp> 15 #include <fwDataTools/helper/Image.hpp> 17 #include <fwRenderVTK/vtk/Helpers.hpp> 19 #include <fwServices/macros.hpp> 21 #include <boost/foreach.hpp> 22 #include <boost/format.hpp> 24 #include <vtkAbstractPropPicker.h> 26 #include <vtkCellArray.h> 27 #include <vtkCellData.h> 28 #include <vtkCommand.h> 29 #include <vtkInteractorStyleImage.h> 30 #include <vtkPolyData.h> 31 #include <vtkPolyDataMapper.h> 32 #include <vtkProperty.h> 33 #include <vtkRenderWindowInteractor.h> 34 #include <vtkTextActor.h> 35 #include <vtkTextMapper.h> 36 #include <vtkTextProperty.h> 37 #include <vtkTransform.h> 41 #define START_PROBE_EVENT vtkCommand::LeftButtonPressEvent 42 #define STOP_PROBE_EVENT vtkCommand::LeftButtonReleaseEvent 47 static const ::fwServices::IService::KeyType s_IMAGE_GROUP =
"image";
51 SImagesProbeCursor::SImagesProbeCursor() noexcept
58 SImagesProbeCursor::~SImagesProbeCursor() noexcept
68 const ConfigType config = this->
getConfigTree().get_child(
"inout");
70 SLM_ASSERT(
"configured group must be '" + s_IMAGE_GROUP +
"'",
71 config.get<std::string>(
"<xmlattr>.group",
"") == s_IMAGE_GROUP);
73 BOOST_FOREACH(const ::fwServices::IService::ConfigType::value_type &v, config.equal_range(
"key"))
75 const ::fwServices::IService::ConfigType& specAssoc = v.second;
76 const ::fwServices::IService::ConfigType& attr = specAssoc.get_child(
"<xmlattr>");
77 const std::string name = attr.get(
"name",
"");
78 m_imagesNames.push_back(name);
93 ::fwData::Image::sptr firstImage = this->getInOut< ::fwData::Image >(s_IMAGE_GROUP, 0);
97 this->setVisibility(
false);
111 void SImagesProbeCursor::updateView(
double world[3] )
114 SLM_ASSERT(
"There must be as much images as names", nbImages == m_imagesNames.size());
116 std::stringstream txt;
118 ::fwData::Image::sptr firstImage = this->getInOut< ::fwData::Image >(s_IMAGE_GROUP, 0);
127 OSLM_TRACE(
"index=" << index[0] <<
"," << index[1] <<
"," << index[2] );
129 if ( world[0] < firstImage->getOrigin()[0] ||
130 world[1] < firstImage->getOrigin()[1] ||
131 world[2] < firstImage->getOrigin()[2] ||
132 index[0] < 0 || index[1] < 0 || index[2] < 0 ||
133 static_cast<size_t>(index[0]) >= firstImage->getSize()[0] ||
134 static_cast<size_t>(index[1]) >= firstImage->getSize()[1] ||
135 static_cast<size_t>(index[2]) >= firstImage->getSize()[2]
138 txt <<
"(---,---,---)" << std::endl;
143 txt << (::boost::format(
"(% 4li,% 4li,% 4li)") % index[0] % index[1] % index[2] ).str() << std::endl;
146 double worldCross[4][3];
147 this->computeCrossExtremity(firstImage, index, worldCross);
149 vtkPoints* points = m_cursorPolyData->GetPoints();
150 for (
int i = 0; i < 4; ++i)
152 OSLM_TRACE(
"p=" << worldCross[i][0] <<
"," << worldCross[i][2] <<
"," << worldCross[i][2] <<
"," );
153 points->SetPoint(i, worldCross[i]);
155 m_cursorPolyData->Modified();
160 for(
size_t i = 0; i < nbImages; ++i)
162 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_GROUP, i);
172 OSLM_TRACE(
"index=" << index[0] <<
"," << index[1] <<
"," << index[2] <<
"," );
174 if ( !( world[0] < image->getOrigin()[0] ||
175 world[1] < image->getOrigin()[1] ||
176 world[2] < image->getOrigin()[2] ||
177 index[0] < 0 || index[1] < 0 || index[2] < 0 ||
178 static_cast<size_t>(index[0]) >= image->getSize()[0] ||
179 static_cast<size_t>(index[1]) >= image->getSize()[1] ||
180 static_cast<size_t>(index[2]) >= image->getSize()[2])
183 std::string greyLevel = imageHelper.
getPixelAsString(static_cast<size_t>(index[0]),
184 static_cast<size_t>(index[1]),
185 static_cast<size_t>(index[2]) );
186 txt << m_imagesNames[i] <<
" : " << greyLevel << std::endl;
191 m_textMapper->SetInput(txt.str().c_str());
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_SLICE_INDEX_MODIFIED_SIG
Type of signal when image's buffer is added.
This class is a helper to define the connections of a service and its data.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
FWRENDERVTK_API void requestRender()
notify a render request iff vtkPipeline is modified
FWRENDERVTK_API void setVtkPipelineModified()
End-user have to call this method when a vtk structure has been modified, thus a render request will ...
#define OSLM_TRACE(message)
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
size_t getKeyGroupSize(const KeyType &keybase) const
Return the number of key in a group of keys.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_BUFFER_MODIFIED_SIG
Type of signal when image's buffer is added.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
Displays pixel information from images.
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Base class for VTK adaptors.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.