Commit ecd92e9c authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[CHANGE] Moved WTriangleMesh tests into new place, but they are deactive by...

[CHANGE] Moved WTriangleMesh tests into new place, but they are deactive by now.. This will change in next commits
parent d390179f
......@@ -255,117 +255,117 @@ void WTriangleMesh::computeVertNormals()
m_computedVertNormals = true;
}
std::ostream& tm_utils::operator<<( std::ostream& os, const WTriangleMesh& rhs )
{
std::stringstream ss;
ss << "WTriangleMesh( #vertices=" << rhs.getNumVertices() << " #triangles=" << rhs.getNumTriangles() << " )" << std::endl;
using string_utils::operator<<;
size_t count = 0;
ss << std::endl;
const std::vector< Triangle > triangles = rhs.getTriangles();
const std::vector< wmath::WPosition > vertices = rhs.getVertices();
for( std::vector< Triangle >::const_iterator triangle = triangles.begin(); triangle != triangles.end(); ++triangle, ++count )
{
std::stringstream prefix;
prefix << "triangle: " << count << "[ ";
std::string indent( prefix.str().size(), ' ' );
ss << prefix.str() << vertices[ triangle->pointID[0] ] << std::endl;
ss << indent << vertices[ triangle->pointID[1] ] << std::endl;
ss << indent << vertices[ triangle->pointID[2] ] << std::endl;
ss << std::string( indent.size() - 2, ' ' ) << "]" << std::endl;
}
return os << ss.str();
}
boost::shared_ptr< std::list< boost::shared_ptr< WTriangleMesh > > > tm_utils::componentDecomposition( const WTriangleMesh& mesh )
{
WUnionFind uf( mesh.getNumVertices() ); // idea: every vertex in own component, then successivley join in accordance with the triangles
const std::vector< Triangle >& triangles = mesh.getTriangles();
for( std::vector< Triangle >::const_iterator triangle = triangles.begin(); triangle != triangles.end(); ++triangle )
{
uf.merge( triangle->pointID[0], triangle->pointID[1] );
uf.merge( triangle->pointID[0], triangle->pointID[2] ); // uf.merge( triangle->pointID[2], triangle->pointID[1] ); they are already in same
}
// ATTENTION: The reason for using the complex BucketType instead of pasting vertices directly into a new WTriangleMesh
// is performance! For example: If there are many vertices reused inside the former WTriangleMesh mesh, then we want
// to reuse them in the new components too. Hence we must determine if a certain vertex is already inside the new component.
// Since the vertices are organized in a vector, we can use std::find( v.begin, v.end(), vertexToLookUp ) which results
// in O(N^2) or we could use faster lookUp via key and value leading to the map and the somehow complicated BucketType.
typedef std::map< wmath::WPosition, size_t > VertexType; // look up fast if a vertex is already inside the new mesh!
typedef std::vector< Triangle > TriangleType;
typedef std::pair< VertexType, TriangleType > BucketType; // Later on the Bucket will be transformed into the new WTriangleMesh component
std::map< size_t, BucketType > buckets; // Key identify with the cannonical element from UnionFind the new connected component
const std::vector< wmath::WPosition >& vertices = mesh.getVertices();
for( std::vector< Triangle >::const_iterator triangle = triangles.begin(); triangle != triangles.end(); ++triangle )
{
size_t component = uf.find( triangle->pointID[0] );
if( buckets.find( component ) == buckets.end() )
{
buckets[ component ] = BucketType( VertexType(), TriangleType() ); // create new bucket
}
// Note: We discard the order of the points and indices, but semantically the structure remains the same
VertexType& mapRef = buckets[ component ].first; // short hand alias
Triangle x = { { 0, 0, 0 } }; // NOLINT
for( int i = 0; i < 3; ++i )
{
size_t id = 0;
const wmath::WPosition& vertex = vertices[ triangle->pointID[i] ];
if( mapRef.find( vertex ) == mapRef.end() )
{
id = mapRef.size(); // since size might change in next line
mapRef[ vertex ] = id;
}
else
{
id = mapRef[ vertex ];
}
x.pointID[i] = id;
}
buckets[ component ].second.push_back( x );
}
boost::shared_ptr< std::list< boost::shared_ptr< WTriangleMesh > > > result( new std::list< boost::shared_ptr< WTriangleMesh > >() );
for( std::map< size_t, BucketType >::const_iterator cit = buckets.begin(); cit != buckets.end(); ++cit )
{
std::vector< wmath::WPosition > newVertices;
newVertices.resize( cit->second.first.size() );
for( VertexType::const_iterator vit = cit->second.first.begin(); vit != cit->second.first.end(); ++vit )
{
newVertices.at( vit->second ) = vit->first; // if you are sure that vit->second is always valid replace at() call with operator[]
}
boost::shared_ptr< WTriangleMesh > newMesh( new WTriangleMesh() );
newMesh->resizeVertices( newVertices.size() );
newMesh->setVertices( newVertices );
newMesh->resizeTriangles( cit->second.second.size() );
newMesh->setTriangles( cit->second.second );
result->push_back( newMesh );
}
return result;
}
boost::shared_ptr< std::set< size_t > > tm_utils::intersection( const WTriangleMesh& mesh, const WPlane& plane )
{
boost::shared_ptr< std::set< size_t > > result( new std::set< size_t > );
const std::vector< wmath::WPosition >& vertices = mesh.getVertices();
const std::vector< Triangle >& triangles = mesh.getTriangles();
for( std::vector< Triangle >::const_iterator triangle = triangles.begin(); triangle != triangles.end(); ++triangle )
{
if( wmath::testIntersectTriangle( vertices[ triangle->pointID[0] ],
vertices[ triangle->pointID[1] ],
vertices[ triangle->pointID[2] ],
plane ) )
{
result->insert( triangle->pointID[0] );
result->insert( triangle->pointID[1] );
result->insert( triangle->pointID[2] );
}
}
return result;
}
//std::ostream& tm_utils::operator<<( std::ostream& os, const WTriangleMesh& rhs )
//{
// std::stringstream ss;
// ss << "WTriangleMesh( #vertices=" << rhs.getNumVertices() << " #triangles=" << rhs.getNumTriangles() << " )" << std::endl;
// using string_utils::operator<<;
// size_t count = 0;
// ss << std::endl;
// const std::vector< Triangle > triangles = rhs.getTriangles();
// const std::vector< wmath::WPosition > vertices = rhs.getVertices();
// for( std::vector< Triangle >::const_iterator triangle = triangles.begin(); triangle != triangles.end(); ++triangle, ++count )
// {
// std::stringstream prefix;
// prefix << "triangle: " << count << "[ ";
// std::string indent( prefix.str().size(), ' ' );
// ss << prefix.str() << vertices[ triangle->pointID[0] ] << std::endl;
// ss << indent << vertices[ triangle->pointID[1] ] << std::endl;
// ss << indent << vertices[ triangle->pointID[2] ] << std::endl;
// ss << std::string( indent.size() - 2, ' ' ) << "]" << std::endl;
// }
// return os << ss.str();
//}
//
//boost::shared_ptr< std::list< boost::shared_ptr< WTriangleMesh > > > tm_utils::componentDecomposition( const WTriangleMesh& mesh )
//{
// WUnionFind uf( mesh.getNumVertices() ); // idea: every vertex in own component, then successivley join in accordance with the triangles
//
// const std::vector< Triangle >& triangles = mesh.getTriangles();
// for( std::vector< Triangle >::const_iterator triangle = triangles.begin(); triangle != triangles.end(); ++triangle )
// {
// uf.merge( triangle->pointID[0], triangle->pointID[1] );
// uf.merge( triangle->pointID[0], triangle->pointID[2] ); // uf.merge( triangle->pointID[2], triangle->pointID[1] ); they are already in same
// }
//
// // ATTENTION: The reason for using the complex BucketType instead of pasting vertices directly into a new WTriangleMesh
// // is performance! For example: If there are many vertices reused inside the former WTriangleMesh mesh, then we want
// // to reuse them in the new components too. Hence we must determine if a certain vertex is already inside the new component.
// // Since the vertices are organized in a vector, we can use std::find( v.begin, v.end(), vertexToLookUp ) which results
// // in O(N^2) or we could use faster lookUp via key and value leading to the map and the somehow complicated BucketType.
// typedef std::map< wmath::WPosition, size_t > VertexType; // look up fast if a vertex is already inside the new mesh!
// typedef std::vector< Triangle > TriangleType;
// typedef std::pair< VertexType, TriangleType > BucketType; // Later on the Bucket will be transformed into the new WTriangleMesh component
// std::map< size_t, BucketType > buckets; // Key identify with the cannonical element from UnionFind the new connected component
//
// const std::vector< wmath::WPosition >& vertices = mesh.getVertices();
// for( std::vector< Triangle >::const_iterator triangle = triangles.begin(); triangle != triangles.end(); ++triangle )
// {
// size_t component = uf.find( triangle->pointID[0] );
// if( buckets.find( component ) == buckets.end() )
// {
// buckets[ component ] = BucketType( VertexType(), TriangleType() ); // create new bucket
// }
//
// // Note: We discard the order of the points and indices, but semantically the structure remains the same
// VertexType& mapRef = buckets[ component ].first; // short hand alias
// Triangle x = { { 0, 0, 0 } }; // NOLINT
// for( int i = 0; i < 3; ++i )
// {
// size_t id = 0;
// const wmath::WPosition& vertex = vertices[ triangle->pointID[i] ];
// if( mapRef.find( vertex ) == mapRef.end() )
// {
// id = mapRef.size(); // since size might change in next line
// mapRef[ vertex ] = id;
// }
// else
// {
// id = mapRef[ vertex ];
// }
// x.pointID[i] = id;
// }
//
// buckets[ component ].second.push_back( x );
// }
//
// boost::shared_ptr< std::list< boost::shared_ptr< WTriangleMesh > > > result( new std::list< boost::shared_ptr< WTriangleMesh > >() );
// for( std::map< size_t, BucketType >::const_iterator cit = buckets.begin(); cit != buckets.end(); ++cit )
// {
// std::vector< wmath::WPosition > newVertices;
// newVertices.resize( cit->second.first.size() );
// for( VertexType::const_iterator vit = cit->second.first.begin(); vit != cit->second.first.end(); ++vit )
// {
// newVertices.at( vit->second ) = vit->first; // if you are sure that vit->second is always valid replace at() call with operator[]
// }
// boost::shared_ptr< WTriangleMesh > newMesh( new WTriangleMesh() );
// newMesh->resizeVertices( newVertices.size() );
// newMesh->setVertices( newVertices );
// newMesh->resizeTriangles( cit->second.second.size() );
// newMesh->setTriangles( cit->second.second );
// result->push_back( newMesh );
// }
//
// return result;
//}
//
//boost::shared_ptr< std::set< size_t > > tm_utils::intersection( const WTriangleMesh& mesh, const WPlane& plane )
//{
// boost::shared_ptr< std::set< size_t > > result( new std::set< size_t > );
// const std::vector< wmath::WPosition >& vertices = mesh.getVertices();
// const std::vector< Triangle >& triangles = mesh.getTriangles();
// for( std::vector< Triangle >::const_iterator triangle = triangles.begin(); triangle != triangles.end(); ++triangle )
// {
// if( wmath::testIntersectTriangle( vertices[ triangle->pointID[0] ],
// vertices[ triangle->pointID[1] ],
// vertices[ triangle->pointID[2] ],
// plane ) )
// {
// result->insert( triangle->pointID[0] );
// result->insert( triangle->pointID[1] );
// result->insert( triangle->pointID[2] );
// }
// }
//
// return result;
//}
......@@ -64,40 +64,40 @@ inline bool Triangle::operator==( const Triangle& rhs ) const
class WTriangleMesh;
/**
* TriangleMesh utils
*/
namespace tm_utils
{
/**
* Decompose the given mesh into connected components.
*
* \param mesh The triangle mesh to decompose
*
* \return List of components where each of them is a WTriangleMesh again.
*/
boost::shared_ptr< std::list< boost::shared_ptr< WTriangleMesh > > > componentDecomposition( const WTriangleMesh& mesh );
/**
* Compute all vertices which are involed with triangles intersecting the given plane.
*
* \param mesh The mesh
* \param plane The plane
*
* \return Set of vertices indices which triangles intersects the plane
*/
boost::shared_ptr< std::set< size_t > > intersection( const WTriangleMesh& mesh, const WPlane& plane );
/**
* Prints for each mesh \#vertices and \#triangles, as well as each triangle with its positions. No point IDs are printed.
*
* \param os Output stream to print on.
* \param rhs The mesh instance.
*
* \return The output stream again for further usage.
*/
std::ostream& operator<<( std::ostream& os, const WTriangleMesh& rhs );
}
///**
// * TriangleMesh utils
// */
//namespace tm_utils
//{
// /**
// * Decompose the given mesh into connected components.
// *
// * \param mesh The triangle mesh to decompose
// *
// * \return List of components where each of them is a WTriangleMesh again.
// */
// boost::shared_ptr< std::list< boost::shared_ptr< WTriangleMesh > > > componentDecomposition( const WTriangleMesh& mesh );
//
// /**
// * Compute all vertices which are involed with triangles intersecting the given plane.
// *
// * \param mesh The mesh
// * \param plane The plane
// *
// * \return Set of vertices indices which triangles intersects the plane
// */
// boost::shared_ptr< std::set< size_t > > intersection( const WTriangleMesh& mesh, const WPlane& plane );
//
// /**
// * Prints for each mesh \#vertices and \#triangles, as well as each triangle with its positions. No point IDs are printed.
// *
// * \param os Output stream to print on.
// * \param rhs The mesh instance.
// *
// * \return The output stream again for further usage.
// */
// std::ostream& operator<<( std::ostream& os, const WTriangleMesh& rhs );
//}
/**
* Triangle mesh data structure allowing for convenient access of the elements.
......
......@@ -26,7 +26,6 @@
#include <boost/shared_ptr.hpp>
#include "../../common/datastructures/WTriangleMesh.h"
#include "../../common/math/WLinearAlgebraFunctions.h"
#include "../../common/math/WPosition.h"
#include "../../common/math/WVector3D.h"
......
......@@ -285,7 +285,7 @@ template< typename Index_T >
std::size_t const WTensorBase< order, dim, Data_T >::getPos( Index_T const* const pos )
{
return WTensorBase< order - 1, dim, Data_T >::getPos( pos ) * dim + pos[ order - 1 ];
};
}
template< std::size_t order, std::size_t dim, typename Data_T >
template< typename Index_T >
......@@ -479,7 +479,7 @@ private:
* Get the mapped position.
*
* \param pos An array of indices.
*
*
* \return The position that corresponds to the indices.
*/
template< typename Index_T >
......@@ -512,21 +512,21 @@ private:
/**
* Copy operator.
*
*
* \param p The position to copy.
*/
explicit Position( Position const& p );
/**
* Increment position.
*
*
* \return *this.
*/
Position& operator++ ();
/**
* Sorted increment position.
*
*
* \return *this.
*/
Position& incrSym();
......@@ -534,7 +534,7 @@ private:
/**
* Get sorted position.
*
* \return A vector of sorted indices.
* \return A vector of sorted indices.
*/
Position operator() ();
......@@ -1035,18 +1035,18 @@ public:
/**
* Multiply with another matrix.
*
*
* \param other The matrix to multiply with.
*
*
* \return The product.
*/
WTensorFunc operator * ( WTensorFunc const& other ) const;
/**
* Multiply with a vector.
*
*
* \param other The vector to multiply with.
*
*
* \return The product.
*/
WTensorFunc< TensorBase_T, 1, dim, Data_T > operator * ( WTensorFunc< TensorBase_T, 1, dim, Data_T > const& other ) const;
......
......@@ -31,7 +31,7 @@
#include <cxxtest/ValueTraits.h>
#include "../../test/WTraitsBase.h"
#include "../WTriangleMesh.h"
#include "../WTriangleMesh2.h"
#ifdef CXXTEST_RUNNING
namespace CxxTest
......@@ -41,13 +41,13 @@ CXXTEST_TEMPLATE_INSTANTIATION
* Enables better UnitTest OutPut if something fails with WTriangleMeshs, so you see
* immedeatly what is failing.
*/
class ValueTraits< WTriangleMesh > : public WTraitsBase
class ValueTraits< WTriangleMesh2 > : public WTraitsBase
{
public:
/**
* Constructs a new ValueTrait of a WTriangleMesh for better test output
* Constructs a new ValueTrait of a WTriangleMesh2 for better test output
*/
explicit ValueTraits( const WTriangleMesh &mesh )
explicit ValueTraits( const WTriangleMesh2 &mesh )
{
std::stringstream ss;
using tm_utils::operator<<;
......
......@@ -32,7 +32,7 @@
#include <cxxtest/TestSuite.h>
#include "../../math/WVector3D.h"
#include "../WTriangleMesh.h"
#include "../WTriangleMesh2.h"
#include "WTriangleMeshTraits.h"
/**
......@@ -46,8 +46,8 @@ public:
*/
void testInstatiation()
{
TS_ASSERT_THROWS_NOTHING( WTriangleMesh() );
WTriangleMesh mesh;
TS_ASSERT_THROWS_NOTHING( WTriangleMesh2() );
WTriangleMesh2 mesh;
TS_ASSERT_EQUALS( mesh.m_fastAddVertId, 0 );
TS_ASSERT_EQUALS( mesh.m_fastAddTriangleId, 0 );
}
......@@ -57,7 +57,7 @@ public:
*/
void testClearMesh()
{
WTriangleMesh mesh;
WTriangleMesh2 mesh;
mesh.m_fastAddVertId = 9; // just a number
mesh.m_fastAddTriangleId = 10; // just a number
mesh.m_vertices.resize( 11 ); // just some size
......@@ -76,7 +76,7 @@ public:
*/
void testFastAddVert()
{
WTriangleMesh mesh;
WTriangleMesh2 mesh;
mesh.resizeVertices( 2 );
wmath::WPosition newVert;
......@@ -92,7 +92,7 @@ public:
*/
void testFastAddTriangle()
{
WTriangleMesh mesh;
WTriangleMesh2 mesh;
mesh.resizeTriangles( 2 );
TS_ASSERT_EQUALS( mesh.m_fastAddTriangleId, 0 );
......@@ -107,7 +107,7 @@ public:
*/
void testSetVertices()
{
WTriangleMesh mesh;
WTriangleMesh2 mesh;
std::vector< wmath::WPosition > vertices( 4 );
TS_ASSERT_EQUALS( mesh.m_fastAddVertId, 0 );
......@@ -122,7 +122,7 @@ public:
*/
void testSetTriangles()
{
WTriangleMesh mesh;
WTriangleMesh2 mesh;
std::vector< Triangle > triangles( 5 );
TS_ASSERT_EQUALS( mesh.m_fastAddTriangleId, 0 );
......@@ -137,7 +137,7 @@ public:
*/
void testgetTriangleNormal()
{
WTriangleMesh mesh;
WTriangleMesh2 mesh;
mesh.resizeVertices( 5 );
wmath::WPosition newVert0( 0, 0, 0 );
......@@ -172,7 +172,7 @@ public:
*/
void testComputeTriNormals()
{
WTriangleMesh mesh;
WTriangleMesh2 mesh;
mesh.resizeVertices( 5 );
wmath::WPosition newVert0( 0, 0, 0 );
......@@ -219,7 +219,7 @@ public:
*/
void testComputeVertNormals()
{
WTriangleMesh mesh;
WTriangleMesh2 mesh;
mesh.resizeVertices( 5 );
wmath::WPosition newVert0( 0, 0, 0 );
......@@ -297,7 +297,7 @@ public:
*/
void testEqualityOperator( void )
{
WTriangleMesh mesh;
WTriangleMesh2 mesh;
mesh.resizeVertices( 3 );
mesh.fastAddVert( wmath::WPosition( 1, 0, 0 ) );
mesh.fastAddVert( wmath::WPosition( 0, 1, 0 ) );
......@@ -305,7 +305,7 @@ public:
mesh.resizeTriangles( 1 );
mesh.fastAddTriangle( 0, 1, 2 );
WTriangleMesh expected( mesh );
WTriangleMesh2 expected( mesh );
TS_ASSERT_EQUALS( expected, mesh );
std::swap( mesh.m_triangles[0].pointID[0], mesh.m_triangles[0].pointID[1] );
......@@ -348,7 +348,7 @@ public:
*/
void testComponentDecomposition( void )
{
WTriangleMesh mesh;
WTriangleMesh2 mesh;
mesh.resizeVertices( 25 );
mesh.fastAddVert( wmath::WPosition( 1, 0, 0 ) ); // 0
......@@ -395,11 +395,11 @@ public:
mesh.fastAddTriangle( 16, 23, 24 ); // 14
mesh.fastAddTriangle( 17, 23, 24 ); // 15
boost::shared_ptr< std::list< boost::shared_ptr< WTriangleMesh > > > components = tm_utils::componentDecomposition( mesh );
boost::shared_ptr< std::list< boost::shared_ptr< WTriangleMesh2 > > > components = tm_utils::componentDecomposition( mesh );
TS_ASSERT_EQUALS( components->size(), 7 );
std::list< boost::shared_ptr< WTriangleMesh > >::const_iterator cit = components->begin();
WTriangleMesh expected;
std::list< boost::shared_ptr< WTriangleMesh2 > >::const_iterator cit = components->begin();
WTriangleMesh2 expected;
expected.resizeVertices( 3 );
expected.fastAddVert( wmath::WPosition( 1, 0, 0 ) );
expected.fastAddVert( wmath::WPosition( 0, 1, 0 ) );
......@@ -442,8 +442,8 @@ public:
*/
void testComponentDecompositionOnEmptyMesh( void )
{
WTriangleMesh mesh;
boost::shared_ptr< std::list< boost::shared_ptr< WTriangleMesh > > > result = tm_utils::componentDecomposition( mesh );
WTriangleMesh2 mesh;
boost::shared_ptr< std::list< boost::shared_ptr< WTriangleMesh2 > > > result = tm_utils::componentDecomposition( mesh );
TS_ASSERT( result->empty() );
}
};
......
......@@ -49,7 +49,7 @@ void WMClusterParamDisplay::connectors()
m_fibers = boost::shared_ptr< InFiberType >( new InFiberType( shared_from_this(), "fiberInput", "DataSetFibers to cluster and display" ) );
addConnector( m_fibers );
typedef WModuleInputForwardData< WDataSetSingle > InParamDSType;
typedef WModuleInputForwardData< WDataSetScalar > InParamDSType;
m_paramDS = boost::shared_ptr< InParamDSType >( new InParamDSType( shared_from_this(), "paramDS", "Parameter Dataset such as FA" ) );
addConnector( m_paramDS );
......@@ -59,10 +59,10 @@ void WMClusterParamDisplay::connectors()
void WMClusterParamDisplay::properties()
{
m_isoValue = m_properties->addProperty( "Iso Value", "", 0.2 );
m_drawISOSurface = m_properties2->addProperty( "ISO Surface", "En/Disables the display of the ISO Surface", true );
m_drawISOSurface = m_properties->addProperty( "ISO Surface", "En/Disables the display of the ISO Surface", true );
// TODO(math): when project files can handle forwarded properties => forward this again, not wrapping
m_go = m_properties2->addProperty( "Go", "Runs the fiberClustering submodule", false );
m_go = m_properties->addProperty( "Go", "Runs the fiberClustering submodule", false );
}
void WMClusterParamDisplay::moduleMain()
......@@ -77,9 +77,9 @@ void WMClusterParamDisplay::moduleMain()
initSubModules();
// initial values
m_isoSurface->getProperties2()->getProperty( "Iso Value" )->toPropDouble()->set( m_isoValue->get() );
m_clusterSlicer->getProperties2()->getProperty( "Iso Value" )->toPropDouble()->set( m_isoValue->get() );
m_fiberClustering->getProperties2()->getProperty( "Go" )->toPropBool()->set( true );
m_isoSurface->getProperties()->getProperty( "Iso Value" )->toPropDouble()->set( m_isoValue->get() );
m_clusterSlicer->getProperties()->getProperty( "Iso Value" )->toPropDouble()->set( m_isoValue->get() );
m_fiberClustering->getProperties()->getProperty( "Go" )->toPropBool()->set( true );
ready();
......@@ -100,13 +100,13 @@ void WMClusterParamDisplay::moduleMain()
if( m_drawISOSurface->changed() )
{
m_meshRenderer->getProperties2()->getProperty( "active" )->toPropBool()->set( m_drawISOSurface->get( true ) );
m_meshRenderer->getProperties()->getProperty( "active" )->toPropBool()->set( m_drawISOSurface->get( true ) );
}
// TODO(math): when project files c