Commit 1965c07e authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD] stub for intersection of triangles with planes

parent b2be9dc1
......@@ -31,6 +31,9 @@
#include <boost/shared_ptr.hpp>
#include "../math/WLine.h"
#include "../math/WMath.h"
#include "../math/WPlane.h"
#include "WTriangleMesh.h"
#include "WUnionFind.h"
......@@ -344,3 +347,21 @@ boost::shared_ptr< std::list< boost::shared_ptr< WTriangleMesh > > > tm_utils::c
return result;
}
boost::shared_ptr< wmath::WLine > tm_utils::intersection( const WTriangleMesh& mesh, const WPlane& plane )
{
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 ) )
{
// compute vertex and update result
}
}
return boost::shared_ptr< wmath::WLine >( new wmath::WLine );
}
......@@ -33,12 +33,12 @@
#include <boost/shared_ptr.hpp>
#include "../math/WLine.h"
#include "../math/WPlane.h"
#include "../math/WPosition.h"
#include "../math/WVector3D.h"
#include "../WTransferable.h"
/**
* A triangle consisting of 3 id of vertices that represent its corners
*/
......@@ -77,6 +77,8 @@ namespace tm_utils
*/
boost::shared_ptr< std::list< boost::shared_ptr< WTriangleMesh > > > componentDecomposition( const WTriangleMesh& mesh );
boost::shared_ptr< wmath::WLine > 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.
*
......
......@@ -23,3 +23,17 @@
//---------------------------------------------------------------------------
#include "WMath.h"
#include "WPosition.h"
#include "WVector3D.h"
bool wmath::testIntersectTriangle( const wmath::WPosition& p1, const wmath::WPosition& p2, const wmath::WPosition& p3, const WPlane& p )
{
const WVector3D& normal = p.getNormal();
const WPosition& planePoint = p.getPosition();
double r1 = normal.dotProduct( p1 - planePoint );
double r2 = normal.dotProduct( p2 - planePoint );
double r3 = normal.dotProduct( p3 - planePoint );
return false; // TODO(math): implement this via signums
}
......@@ -25,18 +25,25 @@
#ifndef WMATH_H
#define WMATH_H
#include "WPlane.h"
/**
* All classes and functions of math module of OpenWalnut.
* All helper functions of math module of OpenWalnut.
*/
namespace wmath
{
// wiebel:
// There is no code here yet, because I created this file only
// to have a good place to specify the documentation for the
// namespace. There are already classes belonging to this
// namespace in other files.
//
// Please remove this comment if it is not appropriate anymore.
/**
* Checks if the triangle intersects with the given plane. If you are interessted in the points of
* intersection if any \see intersection().
*
* \param p1 first point of the triangle
* \param p2 second point of the triangle
* \param p3 third point of the triangle
* \param p The plane to test with
*
* \return True if both intersects otherwise false.
*/
bool testIntersectTriangle( const wmath::WPosition& p1, const wmath::WPosition& p2, const wmath::WPosition& p3, const WPlane& p );
}
#endif // WMATH_H
......@@ -79,6 +79,20 @@ public:
*/
wmath::WPosition getPointInPlane( double x, double y ) const;
/**
* Returns a point in that plane.
*
* \return The point in that plane describing its position
*/
const wmath::WPosition& getPosition() const;
/**
* Returns the normal of the plane.
*
* \return Normalized normal vector.
*/
const wmath::WVector3D& getNormal() const;
// \cond
// /**
// * Computes sample points on that plane.
......@@ -110,4 +124,15 @@ protected:
private:
};
inline const wmath::WPosition& WPlane::getPosition() const
{
return m_normal;
}
inline const wmath::WVector3D& WPlane::getNormal() const
{
return m_pos;
}
#endif // WPLANE_H
......@@ -28,10 +28,11 @@
#include <osg/Array>
#include <osgUtil/DelaunayTriangulator>
#include "../common/datastructures/WTriangleMesh.h"
#include "../common/math/WPosition.h"
#include "exceptions/WGEException.h"
#include "WGEGeometryUtils.h"
#include "WGEUtils.h"
#include "../common/math/WPosition.h"
osg::ref_ptr< osg::Vec3Array > wge::generateCuboidQuads( const std::vector< wmath::WPosition >& corners )
{
......
......@@ -30,9 +30,9 @@
#include <cxxtest/TestSuite.h>
#include "../../../common/WLogger.h"
#include "../../../common/math/WPosition.h"
#include "../../../common/WIOTools.h"
#include "../../../common/WLogger.h"
#include "../WMMarchingCubes.h"
static WLogger logger;
......
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