7 #include "visuVTKAdaptor/SMaterial.hpp" 9 #include <fwData/Material.hpp> 10 #include <fwData/mt/ObjectReadLock.hpp> 12 #include <fwServices/macros.hpp> 14 #include <fwTools/fwID.hpp> 16 #include <fwVtkIO/vtk.hpp> 18 #include <vtkImageData.h> 19 #include <vtkOpenGLRenderWindow.h> 20 #include <vtkOpenGLTexture.h> 21 #include <vtkProperty.h> 22 #include <vtkRenderer.h> 23 #include <vtkRenderWindowInteractor.h> 24 #include <vtkSmartPointer.h> 25 #include <vtkTexture.h> 26 #include <vtkTextureObject.h> 33 const ::fwServices::IService::KeyType SMaterial::s_MATERIAL_INPUT =
"material";
37 SMaterial::SMaterial() noexcept :
38 m_property(vtkProperty::New()),
39 m_manageProperty(true),
46 SMaterial::~SMaterial() noexcept
57 void SMaterial::setVtkProperty(vtkProperty* property)
67 m_manageProperty =
false;
68 m_property = property;
72 m_manageProperty =
true;
73 m_property = vtkProperty::New();
80 vtkProperty* SMaterial::getVtkProperty()
const 103 ::fwData::Material::csptr material = this->getInput < ::fwData::Material >(s_MATERIAL_INPUT);
124 ::fwData::Color::sptr diffuse = material->
diffuse();
125 m_property->SetDiffuseColor(diffuse->red(), diffuse->green(), diffuse->blue());
128 m_property->SetOpacity( diffuse->alpha() );
130 ::fwData::Color::sptr ambient = material->
ambient();
131 m_property->SetAmbientColor(ambient->red(), ambient->green(), ambient->blue());
133 m_property->SetSpecularColor(1., 1., 1.);
134 m_property->SetSpecularPower(100.);
143 if (diffTex->getSizeInBytes() != 0)
145 vtkSmartPointer< vtkImageData > vtkImage = vtkSmartPointer< vtkImageData >::New();
146 ::fwVtkIO::toVTKImage( diffTex, vtkImage );
148 vtkRenderWindow* win = this->
getRenderer()->GetRenderWindow();
150 vtkSmartPointer<vtkTexture> vtkTex;
151 if(win->IsA(
"vtkOpenGLRenderWindow"))
154 vtkImage->GetDimensions(dims);
155 const int type = vtkImage->GetScalarType();
156 const int noc = vtkImage->GetNumberOfScalarComponents();
159 vtkSmartPointer<vtkTextureObject> to = vtkSmartPointer< vtkTextureObject >::New();
160 to->SetContext(dynamic_cast<vtkOpenGLRenderWindow*>(this->
getRenderer()->GetRenderWindow()));
161 to->Create2DFromRaw(dims[0], dims[1], noc, type,
162 const_cast<void*>(static_cast<const void* const>(vtkImage->GetScalarPointer())));
164 vtkSmartPointer<vtkOpenGLTexture> vtkGLTex = vtkSmartPointer< vtkOpenGLTexture >::New();
165 vtkGLTex->SetTextureObject(to);
170 vtkTex = vtkSmartPointer< vtkTexture >::New();
171 vtkTex->SetInputData(vtkImage);
176 vtkTex->SetRepeat( wrapping == ::fwData::Material::REPEAT );
177 vtkTex->SetEdgeClamp( wrapping == ::fwData::Material::CLAMP );
178 vtkTex->SetInterpolate( filtering == ::fwData::Material::LINEAR );
179 m_property->RemoveTexture(
"diffuse");
180 m_property->SetTexture(
"diffuse", vtkTex);
186 case ::fwData::Material::SURFACE:
187 m_property->SetRepresentationToSurface();
188 m_property->EdgeVisibilityOff();
191 case ::fwData::Material::EDGE:
192 m_property->SetRepresentationToSurface();
193 m_property->EdgeVisibilityOn();
196 case ::fwData::Material::WIREFRAME:
197 m_property->SetRepresentationToWireframe();
200 case ::fwData::Material::POINT:
201 m_property->SetRepresentationToPoints();
211 case ::fwData::Material::AMBIENT:
213 case ::fwData::Material::PHONG:
214 m_property->SetInterpolationToPhong();
217 case ::fwData::Material::GOURAUD:
218 m_property->SetInterpolationToGouraud();
221 case ::fwData::Material::FLAT:
222 m_property->SetInterpolationToFlat();
229 m_property->Modified();
void updateMaterial(std::shared_ptr< const ::fwData::Material > material)
This class is a helper to define the connections of a service and its data.
WrappingType & getDiffuseTextureWrapping()
get/set the texture wrapping
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWRENDERVTK_API vtkRenderer * getRenderer()
Returns the renderer.
WrappingType
Texture wrapping types.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
This class defines a material. A material is represented by an ambient color and a diffuse color...
Manage material representation of meshes.
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
A helper to lock object on read mode.
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
FilteringType
Texture filtering types.
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 ...
ShadingType & getShadingMode()
get/set the shading models(flat, gouraud, phong)
FWDATA_API Color::sptr diffuse() const
returns editable diffuse color
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
FWDATA_API Image::sptr getDiffuseTexture() const
returns editable diffuse texture
RepresentationType & getRepresentationMode()
get/set the representation models (edge, point, wireframe, surface)
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
FilteringType & getDiffuseTextureFiltering()
get/set the texture filtering
FWDATA_API Color::sptr ambient() const
returns editable ambient color
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Base class for VTK adaptors.