7 #include "fwDataIO/writer/MeshWriter.hpp" 9 #include "fwDataIO/writer/registry/macros.hpp" 11 #include <fwDataTools/helper/Array.hpp> 12 #include <fwDataTools/helper/MeshGetter.hpp> 13 #include <fwDataTools/Mesh.hpp> 44 assert(
getFile().empty() ==
false );
47 FW_RAISE_IF(
"Can't convert this Mesh to Trian file",
51 file.open(
getFile().
string().c_str(), std::fstream::out);
52 file.precision(std::numeric_limits< float >::digits10);
57 std::string str =
"Unable to write ";
59 throw std::ios_base::failure(str);
64 size_t i, nbPts, nbCells;
65 nbPts = mesh->getNumberOfPoints();
66 ::fwData::Mesh::ConstPointsMultiArrayType points = meshHelper.
getPoints();
67 file<<nbPts<<std::endl;
68 for( i = 0; i < nbPts; ++i )
70 file << points[i][0] <<
" " << points[i][1] <<
" " << points[i][2] << std::endl;
73 nbCells = mesh->getNumberOfCells();
74 ::fwData::Array::sptr cells = mesh->getCellDataArray();
78 FW_RAISE_IF(
"Not able to write " << cells->getType().string() <<
" cell type in trian file.",
79 cells->getType() != ::fwTools::Type::create< std::uint64_t >());
81 std::uint64_t* cellBuf = cellsArrayHelper.
begin< std::uint64_t >();
82 std::uint64_t* cellBufEnd = cellBuf + 3*nbCells;
84 SLM_ASSERT(
"Wrong CellDataMultiArray size", cells->getNumberOfElements() >= nbCells*3);
85 file << nbCells << std::endl;
87 ::fwData::Array::sptr normals = mesh->getCellNormalsArray();
91 && normals->getType() == ::fwTools::Type::create<float>()
92 && normals->getNumberOfComponents() == 3
93 && normals->getNumberOfDimensions() == 1
94 && nbCells == normals->getSize().at(0)
98 float* normalBuf = normalsArrayHelper.
begin<
float >();
100 while (cellBuf != cellBufEnd)
102 file << (*cellBuf++) <<
" ";
103 file << (*cellBuf++) <<
" ";
104 file << (*cellBuf++) <<
" ";
105 file << (*normalBuf++) <<
" ";
106 file << (*normalBuf++) <<
" ";
107 file << (*normalBuf++) << std::endl;
112 while (cellBuf != cellBufEnd)
114 file << (*cellBuf++) <<
" ";
115 file << (*cellBuf++) <<
" ";
116 file << (*cellBuf++) <<
" -1 -1 -1" << std::endl;
This namespace fwDataIO contains reader and writer for several framework's data.
virtual std::shared_ptr< const DataType > getConcreteObject() const
m_object getter.
virtual FWDATAIO_API std::string extension() override
Defines extension supported by this reader ".trian".
#define OSLM_INFO(message)
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
FWDATAIO_API MeshWriter(::fwDataIO::writer::IObjectWriter::Key key)
Constructor. Do nothing.
#define OSLM_ERROR(message)
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
Mesh writer. Write file format .trian.
Base class for all object writers.
ILocation::PathType getFile()
Get file system path.
virtual FWDATAIO_API ~MeshWriter()
Destructor. Do nothing.
virtual FWDATAIO_API void write() override
Contains the representation of the data objects used in the framework.