Commit 0517ea47 authored by David Bommes's avatar David Bommes

added halfedge selection and fixed halfedge point computation

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9991 383ad7c9-94d9-4d36-a494-682f7c89f535
parent c5804f48
......@@ -175,6 +175,32 @@ update_cache()
fh_cache_.push_back(f_it);
}
}
typename Mesh::ConstHalfedgeIter he_it(mesh_.halfedges_sbegin()),
he_end(mesh_.halfedges_end());
// mesh_.request_face_normals();
he_points_.clear();
he_normals_.clear();
for (; he_it!=he_end; ++he_it)
{
if (Mod::is_halfedge_selected(mesh_, he_it))
{
// add vertices
he_points_.push_back( halfedge_point(he_it));
he_points_.push_back( halfedge_point(mesh_.prev_halfedge_handle(he_it)));
// add normals
FaceHandle fh;
if(!mesh_.is_boundary(he_it))
fh = mesh_.face_handle(he_it);
else
fh = mesh_.face_handle(mesh_.opposite_halfedge_handle(he_it));
he_normals_.push_back( mesh_.normal(fh));
he_normals_.push_back( mesh_.normal(fh));
}
}
}
......@@ -205,6 +231,9 @@ draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
bool edges = ((drawMode() == DrawModes::DEFAULT) |
(_drawMode & DrawModes::WIREFRAME));
bool halfedges = ((drawMode() == DrawModes::DEFAULT) |
(_drawMode & DrawModes::WIREFRAME));
bool faces = ((drawMode() == DrawModes::DEFAULT) |
(_drawMode & DrawModes::SOLID_FLAT_SHADED));
......@@ -267,6 +296,17 @@ draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
}
}
// edges
if (halfedges)
{
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(&he_points_[0]);
glNormalPointer(&he_normals_[0]);
draw_halfedges();
}
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
......@@ -310,6 +350,19 @@ draw_edges()
//----------------------------------------------------------------------------
template <class Mesh, class Mod>
void
StatusNodeT<Mesh, Mod>::
draw_halfedges()
{
if ( !he_points_.empty() )
glDrawArrays(GL_LINES, 0, he_points_.size() );
}
//----------------------------------------------------------------------------
template <class Mesh, class Mod>
void
StatusNodeT<Mesh, Mod>::
......@@ -365,6 +418,40 @@ draw_faces(bool _per_vertex)
}
//----------------------------------------------------------------------------
template <class Mesh, class Mod>
typename Mesh::Point
StatusNodeT<Mesh, Mod>::
halfedge_point(const HalfedgeHandle _heh)
{
typename Mesh::Point p = mesh_.point(mesh_.to_vertex_handle (_heh));
typename Mesh::Point pp = mesh_.point(mesh_.from_vertex_handle(_heh));
typename Mesh::Point pn = mesh_.point(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(_heh)));
// typename Mesh::Point n = (p-pp)%(pn-p);
typename Mesh::Point fn;
if( !mesh_.is_boundary(_heh))
fn = mesh_.normal(mesh_.face_handle(_heh));
else
fn = mesh_.normal(mesh_.face_handle(mesh_.opposite_halfedge_handle(_heh)));
typename Mesh::Point upd = ((fn%(pn-p)).normalize() + (fn%(p-pp)).normalize()).normalize();
upd *= ((pn-p).norm()+(p-pp).norm())*0.08;
return (p+upd);
// double alpha = 0.1;
// // correct weighting for concave triangles (or at concave boundaries)
// if( (fn | n) < 0.0) alpha *=-1.0;
// return (p*(1.0-2.0*alpha) + pp*alpha + pn*alpha);
}
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
......
......@@ -110,16 +110,23 @@ public:
private:
typedef typename Mesh::Face Face;
typedef typename Mesh::Vertex Vertex;
typedef typename Mesh::Halfedge Halfedge;
typedef typename Mesh::Edge Edge;
typedef typename Mesh::FaceHandle FaceHandle;
typedef typename Mesh::Face Face;
typedef typename Mesh::Vertex Vertex;
typedef typename Mesh::Halfedge Halfedge;
typedef typename Mesh::Edge Edge;
typedef typename Mesh::FaceHandle FaceHandle;
typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
typedef typename Mesh::Point Point;
typedef typename Mesh::Normal Normal;
void draw_points();
void draw_edges();
void draw_halfedges();
void draw_faces(bool _per_vertex);
Point halfedge_point(const HalfedgeHandle _heh);
private:
......@@ -127,6 +134,9 @@ private:
std::vector<unsigned int> v_cache_, e_cache_, f_cache_;
std::vector<FaceHandle> fh_cache_;
std::vector<Point> he_points_;
std::vector<Normal> he_normals_;
// bounding box
Vec3d bbMin_;
Vec3d bbMax_;
......@@ -152,6 +162,12 @@ struct StatusModT
return _mesh.status(_eh).is_bit_set(Bit);
}
static bool is_halfedge_selected(const Mesh& _mesh,
typename Mesh::HalfedgeHandle _heh)
{
return _mesh.status(_heh).is_bit_set(Bit);
}
static bool is_face_selected(const Mesh& _mesh,
typename Mesh::FaceHandle _fh)
{
......
......@@ -73,7 +73,7 @@ updatePerFaceBuffers_(true),
textureIndexPropertyName_("Not Set"),
perFaceTextureCoordinatePropertyName_("Not Set")
{
mesh_.request_face_normals();
}
template <class Mesh>
......@@ -831,7 +831,24 @@ halfedge_point(const typename Mesh::HalfedgeHandle _heh) {
typename Mesh::Point pp = mesh_.point(mesh_.from_vertex_handle(_heh));
typename Mesh::Point pn = mesh_.point(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(_heh)));
return (p*0.8 + pp*0.1 + pn*0.1);
// typename Mesh::Point n = (p-pp)%(pn-p);
typename Mesh::Point fn;
if( !mesh_.is_boundary(_heh))
fn = mesh_.normal(mesh_.face_handle(_heh));
else
fn = mesh_.normal(mesh_.face_handle(mesh_.opposite_halfedge_handle(_heh)));
typename Mesh::Point upd = ((fn%(pn-p)).normalize() + (fn%(p-pp)).normalize()).normalize();
upd *= ((pn-p).norm()+(p-pp).norm())*0.08;
return (p+upd);
// double alpha = 0.1;
// // correct weighting for concave triangles (or at concave boundaries)
// if( (fn | n) < 0.0) alpha *=-1.0;
// return (p*(1.0-2.0*alpha) + pp*alpha + pn*alpha);
}
template <class 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