29 #include "WMeshReaderFreesurfer.h"
46 boost::filesystem::path file )
50 std::string fileName = file.string();
51 WAssert( !fileName.empty(),
"No filename specified." );
53 std::shared_ptr< std::ifstream > ifs(
new std::ifstream() );
54 ifs->open( fileName.c_str(), std::ifstream::in | std::ifstream::binary );
55 if( !ifs || ifs->bad() )
57 throw WDHIOFailure( std::string(
"internal error while opening" ) );
62 int *pointData =
new int[ 2 ];
63 ifs->read(
reinterpret_cast< char*
>( pointData ), 8 );
64 switchByteOrderOfArray( pointData, 2 );
65 size_t numVertices = pointData[0];
66 size_t numTriangles = pointData[1];
69 float* verts =
new float[ numVertices * 3 ];
70 ifs->read(
reinterpret_cast< char*
>( verts ), 3 *
sizeof(
float ) * numVertices );
71 switchByteOrderOfArray( verts, numVertices * 3 );
73 int* tris =
new int[ numTriangles * 3 ];
74 ifs->read(
reinterpret_cast< char*
>( tris ), 3 *
sizeof(
int ) * numTriangles );
75 switchByteOrderOfArray( tris, numTriangles * 3 );
77 std::shared_ptr< WTriangleMesh > triMesh(
new WTriangleMesh( numVertices, numTriangles ) );
79 for(
size_t i = 0; i < numVertices; ++i )
85 for(
size_t i = 0; i < numTriangles; ++i )
87 triMesh->addTriangle( tris[i * 3], tris[i * 3 + 2], tris[i * 3 + 1] );
Use this for IO error handling.
WMeshReaderFreesurfer()
Constructor.
WPropInt m_propDatasetSizeZ
Size of the dataset (Z)
virtual ~WMeshReaderFreesurfer()
Destructor.
WPropInt m_propDatasetSizeY
Size of the dataset (Y)
WPropInt m_propDatasetSizeX
Size of the dataset (X)
virtual WTriangleMesh::SPtr operator()(WProgressCombiner::SPtr parentProgress, boost::filesystem::path file)
Load the dataset.
Define the interface which is injected into an WObjectNDIP.
std::string getLine(std::shared_ptr< std::ifstream > ifs, const std::string &desc) const
Read a line from the given input stream and throw an exception on error.
This is a base class for everything which has a Name,Description,Icon and Properties (=NDIP).
WProperties::SPtr m_properties
the properties of the object.
std::shared_ptr< WProgressCombiner > SPtr
Abbreviate shared_ptr for this class.
Triangle mesh data structure allowing for convenient access of the elements.
std::shared_ptr< WTriangleMesh > SPtr
Shared pointer.
Some utilities for string manipulation and output operations.