Commit 7a5cc187 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[CHANGE] removed now duplicate code

parent 5a8c789c
......@@ -276,13 +276,6 @@ void WMMarchingCubes::renderSurface()
{
renderMesh( m_triMesh );
m_output->updateData( m_triMesh );
// TODO(wiebel): MC make the filename set automatically
// bool saved = save( "/tmp/isosurfaceTestMesh.vtk", triMesh );
// if( saved )
// {
// WLogger::getLogger()->addLogMessage( "File opened", "Marching Cubes", LL_DEBUG );
// }
}
void WMMarchingCubes::renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh )
......@@ -537,115 +530,6 @@ bool WMMarchingCubes::save() const
return true;
}
WTriangleMesh2 WMMarchingCubes::load( std::string /*fileName*/ )
{
WTriangleMesh2 triMesh( 0, 0 );
// triMesh.clearMesh();
//
// namespace su = string_utils;
//
// std::ifstream ifs;
// ifs.open( fileName.c_str(), std::ifstream::in );
// if( !ifs || ifs.bad() )
// {
// WLogger::getLogger()->addLogMessage( "Try load broken file '" + fileName + "'", "Marching Cubes", LL_ERROR );
// throw std::runtime_error( "Problem during reading file. Probably file not found." );
// }
// std::string line;
//
// // ------ HEADER -------
// std::vector< std::string > header;
// for( int i = 0; i < 4; ++i ) // strip first four lines
// {
// std::getline( ifs, line );
// if( !ifs.good() )
// {
// WLogger::getLogger()->addLogMessage( "Unexpected end of file: " + fileName, "Marching Cubes", LL_ERROR );
// }
// header.push_back( line );
// }
// if( header.at(0) != "# vtk DataFile Version 2.0" )
// {
// WLogger::getLogger()->addLogMessage( "Unsupported format version string: " + header.at( 0 ), "Marching Cubes", LL_WARNING );
// }
//
// if( su::toUpper( su::trim( header.at( 2 ) ) ) != "ASCII" )
// {
// WLogger::getLogger()->addLogMessage( "Only ASCII files supported, not " + header.at( 2 ), "Marching Cubes", LL_ERROR );
// }
//
// if( su::tokenize( header.at( 3 ) ).size() < 2 ||
// su::toUpper( su::tokenize( header.at( 3 ) )[1] ) != "UNSTRUCTURED_GRID" )
// {
// WLogger::getLogger()->addLogMessage( "Invalid VTK DATASET type: " + su::tokenize( header.back() )[1], "Marching Cubes", LL_ERROR );
// }
//
// // ------ POINTS -------
//
// std::getline( ifs, line );
// size_t numPoints = 0;
// std::vector< std::string > tokens = su::tokenize( line );
// if( tokens.size() != 3 || su::toLower( tokens.at( 2 ) ) != "float" || su::toLower( tokens.at( 0 ) ) != "points" )
// {
// WLogger::getLogger()->addLogMessage( "Invalid VTK POINTS declaration: " + line, "Marching Cubes", LL_ERROR );
// }
// try
// {
// numPoints = boost::lexical_cast< size_t >( tokens.at( 1 ) );
// }
// catch( const boost::bad_lexical_cast &e )
// {
// WLogger::getLogger()->addLogMessage( "Invalid number of points: " + tokens.at( 1 ), "Marching Cubes", LL_ERROR );
// }
//
// std::vector< wmath::WPosition > points;
// points.reserve( numPoints );
// float pointData[3];
// for( unsigned int i = 0; i < numPoints; ++i )
// {
// ifs >> pointData[0] >> pointData[1] >> pointData[2];
// points.push_back( wmath::WPosition( pointData[0], pointData[1], pointData[2] ) );
// }
// triMesh.setVertices( points );
//
// // ----- Vertex Ids For Cells---------
// char* cellsMarker = new char[30];
// size_t nbCells;
// size_t nbNumbers;
// ifs >> cellsMarker >> nbCells >> nbNumbers;
//
// triMesh.resizeTriangles( nbCells );
// unsigned int nbCellVerts;
// for( unsigned int i = 0; i < nbCells; ++i )
// {
// unsigned int tri[3];
// ifs >> nbCellVerts >> tri[0] >> tri[1] >> tri[2];
// triMesh.fastAddTriangle( tri[0], tri[1], tri[2] );
// if( nbCellVerts != 3 )
// WLogger::getLogger()->addLogMessage( "Number of cell vertices should be 3 but found " + nbCellVerts, "Marching Cubes", LL_ERROR );
// }
//
// // ----- Cell Types ---------
// char* cells_typesMarker = new char[30];
// size_t nbCellTypes;
// ifs >> cells_typesMarker >> nbCellTypes;
// unsigned int cellType;
// for( unsigned int i = 0; i < nbCellTypes; ++i )
// {
// ifs >> cellType;
// if( cellType != 5 )
// {
// WLogger::getLogger()->addLogMessage( "Invalid cell type: " + cellType, "Marching Cubes", LL_ERROR );
// }
// }
//
// ifs.close();
//
// // TODO(wiebel): probably load point data some time
//
return triMesh;
}
void WMMarchingCubes::updateGraphics()
{
if ( m_active->get() )
......
......@@ -28,6 +28,7 @@
#include "../../kernel/WKernel.h"
#include "../../common/datastructures/WTriangleMesh.h"
#include "../../graphicsEngine/WTriangleMesh2.h"
#include "WMTriangleMeshRenderer.h"
#include "trianglemeshrenderer.xpm"
......@@ -68,8 +69,8 @@ const std::string WMTriangleMeshRenderer::getDescription() const
void WMTriangleMeshRenderer::connectors()
{
m_input = boost::shared_ptr< WModuleInputData < WTriangleMesh > >(
new WModuleInputData< WTriangleMesh >( shared_from_this(), "in", "The mesh to display" )
m_input = boost::shared_ptr< WModuleInputData < WTriangleMesh2 > >(
new WModuleInputData< WTriangleMesh2 >( shared_from_this(), "in", "The mesh to display" )
);
addConnector( m_input );
......@@ -109,7 +110,7 @@ void WMTriangleMeshRenderer::moduleMain()
break;
}
// invalid data
boost::shared_ptr< WTriangleMesh > mesh = m_input->getData();
boost::shared_ptr< WTriangleMesh2 > mesh = m_input->getData();
if ( !mesh )
{
debugLog() << "Invalid Data. Disabling.";
......@@ -120,44 +121,43 @@ void WMTriangleMeshRenderer::moduleMain()
}
}
void WMTriangleMeshRenderer::renderMesh( boost::shared_ptr< WTriangleMesh > mesh )
void WMTriangleMeshRenderer::renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh )
{
m_moduleNode->remove( m_surfaceGeode );
osg::Geometry* surfaceGeometry = new osg::Geometry();
m_surfaceGeode = osg::ref_ptr< osg::Geode >( new osg::Geode );
osg::Vec3Array* vertices = new osg::Vec3Array;
for( size_t i = 0; i < mesh->getNumVertices(); ++i )
for( size_t i = 0; i < mesh->vertSize(); ++i )
{
wmath::WPosition vertPos;
vertPos = mesh->getVertex( i );
vertices->push_back( osg::Vec3( vertPos[0], vertPos[1], vertPos[2] ) );
// wmath::WPosition vertPos;
// vertPos = mesh->getVertex( i );
vertices->push_back( mesh->getVertex( i ) );
}
surfaceGeometry->setVertexArray( vertices );
osg::DrawElementsUInt* surfaceElement;
surfaceElement = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
for( unsigned int triId = 0; triId < mesh->getNumTriangles(); ++triId )
for( unsigned int triId = 0; triId < mesh->triangleSize(); ++triId )
{
for( unsigned int vertId = 0; vertId < 3; ++vertId )
{
surfaceElement->push_back( mesh->getTriangleVertexId( triId, vertId ) );
}
surfaceElement->push_back( mesh->getTriVertId0( triId ) );
surfaceElement->push_back( mesh->getTriVertId1( triId ) );
surfaceElement->push_back( mesh->getTriVertId2( triId ) );
}
surfaceGeometry->addPrimitiveSet( surfaceElement );
// ------------------------------------------------
// normals
osg::ref_ptr< osg::Vec3Array> normals( new osg::Vec3Array() );
mesh->computeVertNormals(); // time consuming
for( unsigned int vertId = 0; vertId < mesh->getNumVertices(); ++vertId )
{
wmath::WVector3D tmpNormal = mesh->getVertexNormal( vertId );
normals->push_back( osg::Vec3( tmpNormal[0], tmpNormal[1], tmpNormal[2] ) );
}
surfaceGeometry->setNormalArray( normals.get() );
// osg::ref_ptr< osg::Vec3Array> normals( new osg::Vec3Array() );
// mesh->computeVertNormals(); // time consuming
// for( unsigned int vertId = 0; vertId < mesh->getNumVertices(); ++vertId )
// {
// wmath::WVector3D tmpNormal = mesh->getVertexNormal( vertId );
// normals->push_back( osg::Vec3( tmpNormal[0], tmpNormal[1], tmpNormal[2] ) );
// }
surfaceGeometry->setNormalArray( mesh->getVertexNormalArray() );
surfaceGeometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
m_surfaceGeode->addDrawable( surfaceGeometry );
......
......@@ -35,6 +35,7 @@
#include "../../kernel/WModuleOutputData.h"
class WTriangleMesh;
class WTriangleMesh2;
/**
* Someone should add some documentation here.
......@@ -118,7 +119,7 @@ private:
/**
* An input connector used to get mehses from other modules. The connection management between connectors must not be handled by the module.
*/
boost::shared_ptr< WModuleInputData< WTriangleMesh > > m_input;
boost::shared_ptr< WModuleInputData< WTriangleMesh2 > > m_input;
WPropInt m_opacityProp; //!< Property holding the opacity valueassigned to the surface
......@@ -133,7 +134,7 @@ private:
* This function generates the osg geometry from the WTriangleMesh.
* \param mesh The triangle mesh that will be rendered.
*/
void renderMesh( boost::shared_ptr< WTriangleMesh > mesh );
void renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh );
};
/**
......
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