7 #include "fwVtkIO/ModelSeriesObjWriter.hpp" 9 #include "fwVtkIO/helper/Mesh.hpp" 10 #include "fwVtkIO/vtk.hpp" 12 #include <fwCore/base.hpp> 14 #include <fwData/Material.hpp> 15 #include <fwData/Reconstruction.hpp> 17 #include <fwDataIO/writer/registry/macros.hpp> 19 #include <fwJobs/IJob.hpp> 20 #include <fwJobs/Observer.hpp> 22 #include <fwMedData/ModelSeries.hpp> 24 #include <fwTools/UUID.hpp> 26 #include <boost/filesystem.hpp> 29 #include <vtkOBJExporter.h> 30 #include <vtkPolyData.h> 31 #include <vtkPolyDataMapper.h> 32 #include <vtkProperty.h> 33 #include <vtkRenderer.h> 34 #include <vtkRenderWindow.h> 35 #include <vtkSmartPointer.h> 44 ::
fwData::location::enableFolder< ::
fwDataIO::writer::IObjectWriter >(this),
45 m_job(::
fwJobs::Observer::New(
"ModelSeries Writer"))
59 vtkSmartPointer< vtkActor > createActor( const ::fwData::Reconstruction::sptr& pReconstruction )
61 vtkSmartPointer< vtkActor > actor = vtkSmartPointer< vtkActor >::New();
63 ::fwData::Mesh::sptr mesh = pReconstruction->getMesh();
64 ::fwData::Material::sptr material = pReconstruction->getMaterial();
66 vtkSmartPointer< vtkPolyData > polyData = vtkSmartPointer< vtkPolyData >::New();
68 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
69 mapper->SetInputData(polyData);
70 actor->SetMapper(mapper);
72 vtkProperty*
property = actor->GetProperty();
74 ::fwData::Color::sptr diffuse = material->diffuse();
75 property->SetDiffuseColor(diffuse->red(), diffuse->green(), diffuse->blue());
76 property->SetOpacity( diffuse->alpha() );
78 ::fwData::Color::sptr ambient = material->ambient();
79 property->SetAmbientColor(ambient->red(), ambient->green(), ambient->blue());
81 property->SetSpecularColor(1., 1., 1.);
82 property->SetSpecularPower(100.);
84 property->SetInterpolationToPhong();
96 ::boost::filesystem::path prefix = this->
getFolder();
100 m_job->setTotalWorkUnits(modelSeries->getReconstructionDB().size());
101 std::uint64_t units = 0;
102 for(const ::fwData::Reconstruction::sptr& rec : modelSeries->getReconstructionDB() )
104 vtkSmartPointer< vtkRenderer > renderer = vtkSmartPointer< vtkRenderer >::New();
105 vtkSmartPointer< vtkActor > actor = createActor(rec);
106 renderer->AddActor(actor);
108 vtkSmartPointer< vtkRenderWindow > renderWindow = vtkSmartPointer< vtkRenderWindow >::New();
109 renderWindow->AddRenderer(renderer);
111 std::string filename = (prefix / (rec->getOrganName() +
"_" +
::fwTools::UUID::get(rec))).string();
113 vtkSmartPointer< vtkOBJExporter > exporter = vtkSmartPointer< vtkOBJExporter >::New();
114 exporter->SetRenderWindow(renderWindow);
115 exporter->SetFilePrefix(filename.c_str());
117 m_job->doneWork(++units);
ILocation::PathType getFolder()
Get folder filesystem path.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
FWVTKIO_API ~ModelSeriesObjWriter()
Destructor.
static FWVTKIO_API void toVTKMesh(const ::fwData::Mesh::csptr &_mesh, vtkSmartPointer< vtkPolyData > _polyData)
Convert a ::fwData::Mesh::csptr to a vtkPolyData.
This namespace fwDataIO contains reader and writer for several framework's data.
::fwTools::Object::cwptr m_object
Object write on filesystem by the process.
virtual std::shared_ptr< const DataType > getConcreteObject() const
m_object getter.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
std::shared_ptr< ::fwJobs::IJob > sptr
Cancel request callback type.
FWVTKIO_API ModelSeriesObjWriter(::fwDataIO::writer::IObjectWriter::Key key)
Constructor.
Write a fwData::Reconstruction.
FWVTKIO_API std::string extension() override
Contains the representation of the data objects used in the framework.
FWVTKIO_API std::shared_ptr< ::fwJobs::IJob > getJob() const override
FWVTKIO_API void write() override
Writing operator.
This namespace fwJobs provides jobs management.