Commit 0015465e authored by schurade's avatar schurade
Browse files

[FIX] reactived the save function in mc module again

parent 1daf4ec5
......@@ -152,13 +152,13 @@ std::vector< size_t >WTriangleMesh2::getTriangles()
return m_triangles;
}
osg::Vec3 WTriangleMesh2::getVertex( size_t index )
osg::Vec3 WTriangleMesh2::getVertex( size_t index ) const
{
WAssert( index < m_countVerts, "get vertex: index out of range" );
return ( *m_verts )[index];
}
wmath::WPosition WTriangleMesh2::getVertexAsPosition( size_t index )
wmath::WPosition WTriangleMesh2::getVertexAsPosition( size_t index ) const
{
WAssert( index < m_countVerts, "get vertex as position: index out of range" );
return wmath::WPosition( ( *m_verts )[index][0], ( *m_verts )[index][1], ( *m_verts )[index][2] );
......@@ -276,12 +276,12 @@ osg::Vec3 WTriangleMesh2::calcNormal( osg::Vec3 vert0, osg::Vec3 vert1, osg::Vec
return tempNormal;
}
size_t WTriangleMesh2::vertSize()
size_t WTriangleMesh2::vertSize() const
{
return m_countVerts;
}
size_t WTriangleMesh2::triangleSize()
size_t WTriangleMesh2::triangleSize() const
{
return m_countTriangles;
}
......
......@@ -201,7 +201,7 @@ public:
* \param index
* \return vertex
*/
osg::Vec3 getVertex( size_t index );
osg::Vec3 getVertex( size_t index ) const;
/**
* getter
......@@ -218,7 +218,7 @@ public:
* \param index
* \return vertex
*/
wmath::WPosition getVertexAsPosition( size_t index );
wmath::WPosition getVertexAsPosition( size_t index ) const;
/**
* getter
......@@ -234,20 +234,45 @@ public:
*
* \return number of vertexes in the mesh
*/
size_t vertSize();
size_t vertSize() const;
/**
* getter
*
* \return number of triangles in the mesh
*/
size_t triangleSize();
size_t triangleSize() const;
/**
* performs a loop subdivision on the triangle mesh
*/
void doLoopSubD();
/**
* returns the id of the first vertex of a triangle
*
* \param triId id of the triangle
* \return id of the vertex
*/
size_t getTriVertId0( size_t triId ) const;
/**
* returns the id of the second vertex of a triangle
*
* \param triId id of the triangle
* \return id of the vertex
*/
size_t getTriVertId1( size_t triId ) const;
/**
* return the id of the third vertex of a triangle
*
* \param triId id of the triangle
* \return id of the vertex
*/
size_t getTriVertId2( size_t triId ) const;
protected:
static boost::shared_ptr< WPrototyped > m_prototype; //!< The prototype as singleton.
private:
......@@ -343,31 +368,6 @@ private:
*/
void setTriVert2( size_t triId, size_t vertId );
/**
* returns the id of the first vertex of a triangle
*
* \param triId id of the triangle
* \return id of the vertex
*/
size_t getTriVertId0( size_t triId );
/**
* returns the id of the second vertex of a triangle
*
* \param triId id of the triangle
* \return id of the vertex
*/
size_t getTriVertId1( size_t triId );
/**
* return the id of the third vertex of a triangle
*
* \param triId id of the triangle
* \return id of the vertex
*/
size_t getTriVertId2( size_t triId );
// the next functions are helper functions for the loop subdivision algorithm and exist only for that
// purpose, for more information read http://research.microsoft.com/en-us/um/people/cloop/thesis.pdf
......@@ -530,19 +530,19 @@ inline osg::Vec3 WTriangleMesh2::getTriVert( size_t triId, size_t vertNum )
return ( *m_verts )[ m_triangles[ triId * 3 + vertNum] ];
}
inline size_t WTriangleMesh2::getTriVertId0( size_t triId )
inline size_t WTriangleMesh2::getTriVertId0( size_t triId ) const
{
WAssert( triId < m_countTriangles, "get tri vert id 0: triangle id out of range" );
return m_triangles[triId * 3];
}
inline size_t WTriangleMesh2::getTriVertId1( size_t triId )
inline size_t WTriangleMesh2::getTriVertId1( size_t triId ) const
{
WAssert( triId < m_countTriangles, "get tri vert id 1: triangle id out of range" );
return m_triangles[triId * 3 + 1];
}
inline size_t WTriangleMesh2::getTriVertId2( size_t triId )
inline size_t WTriangleMesh2::getTriVertId2( size_t triId ) const
{
WAssert( triId < m_countTriangles, "get tri vert id 2: triangle id out of range" );
return m_triangles[triId * 3 + 2];
......
......@@ -809,75 +809,75 @@ void WMMarchingCubes::notifyTextureChange()
}
// TODO(wiebel): MC move this to a separate module in the future
bool WMMarchingCubes::save( std::string /*fileName*/, const WTriangleMesh2& /*triMesh*/ ) const
bool WMMarchingCubes::save( std::string fileName, const WTriangleMesh2& triMesh ) const
{
// if( triMesh.getNumVertices() == 0 )
// {
// WLogger::getLogger()->addLogMessage( "Will not write file that contains 0 vertices.", "Marching Cubes", LL_ERROR );
// return false;
// }
//
// if( triMesh.getNumTriangles() == 0 )
// {
// WLogger::getLogger()->addLogMessage( "Will not write file that contains 0 triangles.", "Marching Cubes", LL_ERROR );
// return false;
// }
//
// const char* c_file = fileName.c_str();
// std::ofstream dataFile( c_file );
//
// if ( dataFile )
// {
// WLogger::getLogger()->addLogMessage( "opening file", "Marching Cubes", LL_DEBUG );
// }
// else
// {
// WLogger::getLogger()->addLogMessage( "open file failed" + fileName , "Marching Cubes", LL_ERROR );
// return false;
// }
//
// dataFile.precision( 16 );
//
// WLogger::getLogger()->addLogMessage( "start writing file", "Marching Cubes", LL_DEBUG );
// dataFile << ( "# vtk DataFile Version 2.0\n" );
// dataFile << ( "generated using OpenWalnut\n" );
// dataFile << ( "ASCII\n" );
// dataFile << ( "DATASET UNSTRUCTURED_GRID\n" );
//
// wmath::WPosition point;
// dataFile << "POINTS " << triMesh.getNumVertices() << " float\n";
// for ( unsigned int i = 0; i < triMesh.getNumVertices(); ++i )
// {
// point = triMesh.getVertex( i );
// if( !( myIsfinite( point[0] ) && myIsfinite( point[1] ) && myIsfinite( point[2] ) ) )
// {
// WLogger::getLogger()->addLogMessage( "Will not write file from data that contains NAN or INF.", "Marching Cubes", LL_ERROR );
// return false;
// }
// dataFile << point[0] << " " << point[1] << " " << point[2] << "\n";
// }
//
// dataFile << "CELLS " << triMesh.getNumTriangles() << " " << triMesh.getNumTriangles() * 4 << "\n";
// for ( unsigned int i = 0; i < triMesh.getNumTriangles(); ++i )
// {
// dataFile << "3 " << triMesh.getTriangleVertexId( i, 0 ) << " "
// << triMesh.getTriangleVertexId( i, 1 ) << " "
// << triMesh.getTriangleVertexId( i, 2 ) << "\n";
// }
// dataFile << "CELL_TYPES "<< triMesh.getNumTriangles() <<"\n";
// for ( unsigned int i = 0; i < triMesh.getNumTriangles(); ++i )
// {
// dataFile << "5\n";
// }
// dataFile << "POINT_DATA " << triMesh.getNumVertices() << "\n";
// dataFile << "SCALARS scalars float\n";
// dataFile << "LOOKUP_TABLE default\n";
// for ( unsigned int i = 0; i < triMesh.getNumVertices(); ++i )
// {
// dataFile << "0\n";
// }
// dataFile.close();
// WLogger::getLogger()->addLogMessage( "saving done", "Marching Cubes", LL_DEBUG );
if( triMesh.vertSize() == 0 )
{
WLogger::getLogger()->addLogMessage( "Will not write file that contains 0 vertices.", "Marching Cubes", LL_ERROR );
return false;
}
if( triMesh.triangleSize() == 0 )
{
WLogger::getLogger()->addLogMessage( "Will not write file that contains 0 triangles.", "Marching Cubes", LL_ERROR );
return false;
}
const char* c_file = fileName.c_str();
std::ofstream dataFile( c_file );
if ( dataFile )
{
WLogger::getLogger()->addLogMessage( "opening file", "Marching Cubes", LL_DEBUG );
}
else
{
WLogger::getLogger()->addLogMessage( "open file failed" + fileName , "Marching Cubes", LL_ERROR );
return false;
}
dataFile.precision( 16 );
WLogger::getLogger()->addLogMessage( "start writing file", "Marching Cubes", LL_DEBUG );
dataFile << ( "# vtk DataFile Version 2.0\n" );
dataFile << ( "generated using OpenWalnut\n" );
dataFile << ( "ASCII\n" );
dataFile << ( "DATASET UNSTRUCTURED_GRID\n" );
wmath::WPosition point;
dataFile << "POINTS " << triMesh.vertSize() << " float\n";
for ( size_t i = 0; i < triMesh.vertSize(); ++i )
{
point = triMesh.getVertexAsPosition( i );
if( !( myIsfinite( point[0] ) && myIsfinite( point[1] ) && myIsfinite( point[2] ) ) )
{
WLogger::getLogger()->addLogMessage( "Will not write file from data that contains NAN or INF.", "Marching Cubes", LL_ERROR );
return false;
}
dataFile << point[0] << " " << point[1] << " " << point[2] << "\n";
}
dataFile << "CELLS " << triMesh.triangleSize() << " " << triMesh.triangleSize() * 4 << "\n";
for ( size_t i = 0; i < triMesh.triangleSize(); ++i )
{
dataFile << "3 " << triMesh.getTriVertId0( i ) << " "
<< triMesh.getTriVertId1( i ) << " "
<< triMesh.getTriVertId2( i ) << "\n";
}
dataFile << "CELL_TYPES "<< triMesh.triangleSize() <<"\n";
for ( size_t i = 0; i < triMesh.triangleSize(); ++i )
{
dataFile << "5\n";
}
dataFile << "POINT_DATA " << triMesh.vertSize() << "\n";
dataFile << "SCALARS scalars float\n";
dataFile << "LOOKUP_TABLE default\n";
for ( size_t i = 0; i < triMesh.vertSize(); ++i )
{
dataFile << "0\n";
}
dataFile.close();
WLogger::getLogger()->addLogMessage( "saving done", "Marching Cubes", LL_DEBUG );
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment