7 #include "visuVTKAdaptor/SLine.hpp" 9 #include <fwCom/Slots.hxx> 11 #include <fwServices/macros.hpp> 13 #include <boost/lexical_cast.hpp> 16 #include <vtkFloatArray.h> 17 #include <vtkImageData.h> 18 #include <vtkPointData.h> 19 #include <vtkProperty.h> 20 #include <vtkRenderer.h> 21 #include <vtkTexture.h> 22 #include <vtkTransform.h> 35 SLine::SLine() noexcept :
36 m_lineActor(vtkSmartPointer<vtkActor>::New()),
37 m_vtkLine(vtkSmartPointer<vtkLineSource>::New()),
38 m_mapper(vtkSmartPointer<vtkPolyDataMapper>::New()),
41 m_transformLine(vtkSmartPointer<vtkTransform>::New()),
50 SLine::~SLine() noexcept
61 this->buildPipeline();
87 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
89 m_length = config.get(
"length", 1.f);
90 m_width = config.get(
"width", 1.f);
92 const std::string strColor = config.get(
"color",
"#FFFFFF");
94 m_color = ::fwData::Color::New();
95 m_color->setRGBA(strColor);
97 const std::string strLineOptions = config.get(
"dotted",
"false");
98 if(strLineOptions ==
"true" || strLineOptions ==
"yes" || strLineOptions ==
"on" || strLineOptions ==
"1")
108 m_lineActor->SetVisibility(_isVisible);
116 void SLine::updateLine()
118 m_vtkLine->SetPoint2(0.0, 0.0, m_length);
122 vtkSmartPointer<vtkPolyData> line = m_vtkLine->GetOutput();
123 vtkSmartPointer<vtkFloatArray> textureCoordinates = vtkSmartPointer<vtkFloatArray>::New();
124 textureCoordinates->SetNumberOfComponents(2);
125 textureCoordinates->SetName(
"TextureCoordinates");
127 float tuple[2] = {0.0f, 0.0f};
128 textureCoordinates->InsertNextTuple(tuple);
129 tuple[0] = m_length / 8.0f;
131 textureCoordinates->InsertNextTuple(tuple);
133 line->GetPointData()->SetTCoords(textureCoordinates);
135 m_mapper->SetInputData(line);
140 void SLine::buildPipeline()
142 vtkTransform* transform = m_renderService.lock()->getOrAddVtkTransform(m_transformId);
145 m_vtkLine->SetPoint1(0.0, 0.0, 0.0);
146 m_vtkLine->SetPoint2(0.0, 0.0, m_length);
148 vtkSmartPointer<vtkPolyData> line = m_vtkLine->GetOutput();
151 vtkSmartPointer<vtkFloatArray> textureCoordinates = vtkSmartPointer<vtkFloatArray>::New();
152 textureCoordinates->SetNumberOfComponents(2);
153 textureCoordinates->SetName(
"TextureCoordinates");
155 float tuple[2] = {0.0f, 0.0f};
156 textureCoordinates->InsertNextTuple(tuple);
157 tuple[0] = m_length / 8.0f;
159 textureCoordinates->InsertNextTuple(tuple);
161 line->GetPointData()->SetTCoords(textureCoordinates);
163 m_mapper->SetInputData(line);
165 m_lineActor->SetMapper(m_mapper);
170 vtkSmartPointer<vtkImageData> stippleImage = vtkSmartPointer<vtkImageData>::New();
171 stippleImage->SetExtent( 0, 1, 0, 0, 0, 0 );
172 stippleImage->SetOrigin( 0.0, 0.0, 0.0 );
173 stippleImage->SetSpacing( 1.0, 1.0, 1.0 );
174 stippleImage->AllocateScalars(VTK_UNSIGNED_CHAR, 4);
177 unsigned char* iptr =
static_cast<unsigned char*
>(stippleImage->GetScalarPointer( 0, 0, 0 ));
179 std::memset(iptr, 0, 8 );
180 iptr[0] =
static_cast<unsigned char>(m_color->red() * 255.0f);
181 iptr[1] =
static_cast<unsigned char>(m_color->green() * 255.0f);
182 iptr[2] =
static_cast<unsigned char>(m_color->blue() * 255.0f);
186 vtkSmartPointer<vtkTexture> vtkTex = vtkSmartPointer< vtkTexture >::New();
187 vtkTex->SetInputData(stippleImage);
188 vtkTex->SetRepeat(1);
189 m_lineActor->GetProperty()->SetTexture(
"stipple", vtkTex);
193 m_lineActor->GetProperty()->SetColor(m_color->red(), m_color->green(), m_color->blue());
196 m_lineActor->GetProperty()->SetLineWidth(m_width);
197 m_lineActor->SetUserTransform(transform);
VISUVTKADAPTOR_API void updateVisibility(bool isVisible)
Slot: update axes visibility (true = visible)
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
FWRENDERVTK_API void addToRenderer(vtkProp *prop)
Adds the vtkProp to the renderer.
static VISUVTKADAPTOR_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_VISIBILITY_SLOT
Slot: update axes visibility (true = visible)
FWRENDERVTK_API vtkRenderer * getRenderer()
Returns the renderer.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
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 ...
VISUVTKADAPTOR_API void updateLength(float length)
Slot: update length of the line.
FWRENDERVTK_API void removeAllPropFromRenderer()
Removes all the vtkProp from the renderer.
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
Render line in the generic scene.
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
static VISUVTKADAPTOR_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_LENGTH_SLOT
Slot: update axes visibility (true = visible)
Base class for VTK adaptors.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.