Commit ee9ce82f authored by David Bommes's avatar David Bommes
Browse files

Added support for vertex->sphere visualization and picking

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17780 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ba563504
......@@ -75,7 +75,8 @@ PolyLineNodeT<PolyLine>::PolyLineNodeT(PolyLine& _pl, BaseNode* _parent, std::st
BaseNode(_parent, _name),
polyline_(_pl),
vbo_(0),
updateVBO_(true)
updateVBO_(true),
sphere_(0)
{
drawMode(DrawModes::WIREFRAME | DrawModes::POINTS);
......@@ -104,7 +105,7 @@ DrawModes::DrawMode
PolyLineNodeT<PolyLine>::
availableDrawModes() const
{
return (DrawModes::WIREFRAME | DrawModes::POINTS);
return (DrawModes::WIREFRAME | DrawModes::POINTS | DrawModes::POINTS_SHADED);
}
......@@ -168,7 +169,6 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
}
// draw line segments
if (_drawMode & DrawModes::WIREFRAME) {
......@@ -238,6 +238,34 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
//Disable the vertex array
ACG::GLState::disableClientState(GL_VERTEX_ARRAY);
// draw vertices as spheres
if (_drawMode & DrawModes::POINTS_SHADED)
{
// create sphere if not yet done
if(!sphere_)
sphere_ = new GLSphere(10,10);
if( polyline_.vertex_selections_available())
{
for(unsigned int i=0; i<polyline_.n_vertices(); ++i)
{
if(polyline_.vertex_selected(i))
_state.set_color( Vec4f(1,0,0,1) );
else
_state.set_color( color );
sphere_->draw(_state, polyline_.vertex_radius(), (Vec3f)polyline_.point(i));
}
}
else
{
_state.set_color( color );
for(unsigned int i=0; i<polyline_.n_vertices(); ++i)
sphere_->draw(_state, polyline_.vertex_radius(), (Vec3f)polyline_.point(i));
}
}
}
//----------------------------------------------------------------------------
......@@ -286,6 +314,10 @@ pick(GLState& _state, PickTarget _target)
if (drawMode() & DrawModes::POINTS)
pick_vertices( _state);
if (drawMode() & DrawModes::POINTS_SHADED)
pick_spheres( _state);
pick_edges( _state, polyline_.n_vertices());
break;
}
......@@ -334,6 +366,27 @@ pick_vertices( GLState& _state )
//----------------------------------------------------------------------------
template <class PolyLine>
void
PolyLineNodeT<PolyLine>::
pick_spheres( GLState& _state )
{
if(!sphere_)
sphere_ = new GLSphere(10,10);
_state.pick_set_name(0);
for(unsigned int i=0; i<polyline_.n_vertices(); ++i)
{
_state.pick_set_name (i);
sphere_->draw(_state, polyline_.vertex_radius(), (Vec3f)polyline_.point(i));
}
}
//----------------------------------------------------------------------------
template <class PolyLine>
void
PolyLineNodeT<PolyLine>::
......
......@@ -62,6 +62,7 @@
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/IRenderer.hh>
#include <ACG/GL/GLPrimitives.hh>
//== FORWARDDECLARATIONS ======================================================
......@@ -128,6 +129,7 @@ public:
private:
void pick_vertices( GLState& _state );
void pick_spheres ( GLState& _state );
void pick_edges( GLState& _state, unsigned int _offset);
/// Copy constructor (not used)
......@@ -162,6 +164,9 @@ private:
/// Flag to trigger update of vbo
bool updateVBO_;
/// Sphere for VertexSphere DrawMode
GLSphere* sphere_;
};
......
......@@ -33,6 +33,10 @@ void PolyLineObjectSerializer::serialize(std::ostream& _stream) {
fout << current_point[2] << std::endl;
}
fout << "VERTEXRADIUS" << std::endl << _polyLine.vertex_radius() << std::endl;
fout << "EDGERADIUS" << std::endl << _polyLine.edge_radius() << std::endl;
// ###########################
// Write properties(unsigned int)CircleType
......@@ -142,7 +146,19 @@ void PolyLineObjectSerializer::deserialize(std::istream& _stream) {
{
token = "-";
fin >> token;
if(token == "VVHANDLES")
if(token == "VERTEXRADIUS")
{
double r;
fin >> r;
_polyLine.set_vertex_radius(r);
}
else if(token == "EDGERADIUS")
{
double r;
fin >> r;
_polyLine.set_edge_radius(r);
}
else if(token == "VVHANDLES")
{
if(!_polyLine.vertex_vhandles_available()) _polyLine.request_vertex_vhandles();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
......@@ -211,6 +227,7 @@ void PolyLineObjectSerializer::deserialize(std::istream& _stream) {
}
else if(token != "") break; //eat up empty lines
}
}
......
......@@ -87,6 +87,8 @@ template <class PointT>
PolyLineT<PointT>::
PolyLineT( bool _closed )
: closed_(_closed),
vertex_radius_(0.01),
edge_radius_(0.01),
ref_count_vnormals_(0),
ref_count_vbinormals_(0),
ref_count_vcolors_(0),
......
......@@ -337,6 +337,19 @@ public:
/// \brief Print information string to cerr
void print() const;
/// \brief get ball-radius of vertices
Scalar vertex_radius() const { return vertex_radius_;}
/// \brief set ball-radius of vertices
void set_vertex_radius(const Scalar _r) { vertex_radius_ = _r;}
/// \brief get cylinder-radius of edges
Scalar edge_radius() const { return edge_radius_;}
/// \brief set cylinder-radius of edges
void set_edge_radius(const Scalar _r) { edge_radius_ = _r;}
// ############################### Standard Property Handling #############################
// request properties
......@@ -523,6 +536,12 @@ private:
/// \brief Connect first and last point?
bool closed_;
/// \brief ball-radius of vertices
Scalar vertex_radius_;
/// \brief cylinder-radius of edges
Scalar edge_radius_;
// ############################### Standard Property Handling #############################
// list of vertex properties
......
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