Commit 0bf0cad5 authored by Martin Schultz's avatar Martin Schultz

added refinement functions for vertex and edge picking

refs #1908

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20587 383ad7c9-94d9-4d36-a494-682f7c89f535
parent cea6abe5
/**
* \file PolyMesh.cc
* This File contains all required includes for using Poly Meshes
*/
//== INCLUDES =================================================================
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ACG/Geometry/Algorithms.hh>
PolyMeshObject::PolyMeshObject(const PolyMeshObject& _object) : MeshObject< PolyMesh >(_object) {
}
PolyMeshObject::PolyMeshObject(DataType _typeId) : MeshObject< PolyMesh >(_typeId) {
}
PolyMeshObject::~PolyMeshObject() {
}
/// Refine picking on triangle meshes
ACG::Vec3d PolyMeshObject::refinePick(ACG::SceneGraph::PickTarget _pickTarget, const ACG::Vec3d _hitPoint, const ACG::Vec3d _start , const ACG::Vec3d _dir, const unsigned int _targetIdx ) {
if ( _pickTarget == ACG::SceneGraph::PICK_FACE) {
//don't refine poly faces
return _hitPoint;
}
if ( _pickTarget == ACG::SceneGraph::PICK_EDGE) {
// get picked edge handle
PolyMesh::EdgeHandle eh = mesh()->edge_handle(_targetIdx);
if(eh.is_valid())
{
PolyMesh::HalfedgeHandle heh = mesh()->halfedge_handle(eh,0);
//get vertices of the edge
PolyMesh::VertexHandle vhbegin = mesh()->to_vertex_handle(heh);
PolyMesh::VertexHandle vhend = mesh()->from_vertex_handle(heh);
ACG::Vec3d edgeStart = mesh()->point(vhbegin);
ACG::Vec3d edgeEnd = mesh()->point(vhend);
//retrieve the point on the edge that is closest to the backprojected hitpoint
ACG::Vec3d hitPointNew;
ACG::Geometry::distPointLineSquared(_hitPoint,edgeStart,edgeEnd,&hitPointNew);
return hitPointNew;
}
}
if ( _pickTarget == ACG::SceneGraph::PICK_VERTEX) {
// get picked vertex handle
PolyMesh::VertexHandle vh = mesh()->vertex_handle(_targetIdx);
if(vh.is_valid())
{
ACG::Vec3d hitpointNew = mesh()->point(vh);
//just return the vertex position
return hitpointNew;
}
}
return _hitPoint;
}
//=============================================================================
......@@ -59,8 +59,33 @@
#include <ObjectTypes/MeshObject/MeshObjectT.hh>
#include <ObjectTypes/PolyMesh/PolyMeshTypes.hh>
/// Typedef for a Meshobject containing a poly mesh
typedef MeshObject< PolyMesh > PolyMeshObject;
/// Type for a Meshobject containing a poly mesh
class DLLEXPORTONLY PolyMeshObject : public MeshObject< PolyMesh > {
public:
/** \brief copy constructor
*
* Create a copy of this object
*/
PolyMeshObject(const PolyMeshObject& _object);
/** \brief Constructor
*
* This is the standard constructor for MeshObjects. As triangle and Poly Meshes are handled by this class, the
* typeId is passed to the MeshObject to specify it.
*
* @param _typeId This is the type Id the Object will use. Should be typeId("TriangleMesh") or typeId("PolyMesh")
*/
PolyMeshObject(DataType _typeId);
/// destructor
virtual ~PolyMeshObject();
public:
/// Refine picking on triangle meshes
ACG::Vec3d refinePick(ACG::SceneGraph::PickTarget _pickTarget, const ACG::Vec3d _hitPoint, const ACG::Vec3d _start , const ACG::Vec3d _dir, const unsigned int _targetIdx );
};
#include <ObjectTypes/PolyMesh/PluginFunctionsPolyMesh.hh>
......
......@@ -73,7 +73,6 @@ TriMeshObject::~TriMeshObject() {
/// Refine picking on triangle meshes
ACG::Vec3d TriMeshObject::refinePick(ACG::SceneGraph::PickTarget _pickTarget, const ACG::Vec3d _hitPoint, const ACG::Vec3d _start , const ACG::Vec3d _dir, const unsigned int _targetIdx ) {
if ( _pickTarget == ACG::SceneGraph::PICK_FACE) {
std::cerr << "Refine Face picking" << std::endl;
// get picked face handle
TriMesh::FaceHandle fh = mesh()->face_handle(_targetIdx);
......@@ -95,23 +94,45 @@ ACG::Vec3d TriMeshObject::refinePick(ACG::SceneGraph::PickTarget _pickTarget, co
TriMesh::Scalar t,u,v;
if ( ACG::Geometry::triangleIntersection( _start, _dir, p1 , p2 , p3 , t , u , v) ) {
hitpointNew = _start + t * _dir;
} else {
std::cerr << "Refine Picking failed" << std::endl;
}
return hitpointNew;
}
if ( _pickTarget == ACG::SceneGraph::PICK_EDGE) {
// get picked edge handle
TriMesh::EdgeHandle eh = mesh()->edge_handle(_targetIdx);
if(eh.is_valid())
{
TriMesh::HalfedgeHandle heh = mesh()->halfedge_handle(eh,0);
//get vertices of the edge
TriMesh::VertexHandle vhbegin = mesh()->to_vertex_handle(heh);
TriMesh::VertexHandle vhend = mesh()->from_vertex_handle(heh);
ACG::Vec3d edgeStart = mesh()->point(vhbegin);
ACG::Vec3d edgeEnd = mesh()->point(vhend);
//retrieve the point on the edge that is closest to the backprojected hitpoint
ACG::Vec3d hitPointNew;
ACG::Geometry::distPointLineSquared(_hitPoint,edgeStart,edgeEnd,&hitPointNew);
std::cerr << "Refine on Triangle meshes" << std::endl;
std::cerr << "Original: " << _hitPoint << std::endl;
std::cerr << "MousePos : " << _start << std::endl;
std::cerr << "Update: " << hitpointNew << std::endl;
return hitpointNew;
return hitPointNew;
}
}
if ( _pickTarget == ACG::SceneGraph::PICK_VERTEX) {
// get picked vertex handle
TriMesh::VertexHandle vh = mesh()->vertex_handle(_targetIdx);
if(vh.is_valid())
{
ACG::Vec3d hitpointNew = mesh()->point(vh);
//just return the vertex position
return hitpointNew;
}
}
std::cerr << "No Refine on Triangle meshes" << std::endl;
return _hitPoint;
}
......
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