2008-02-16 13:00:35 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* MeshLab o o *
|
|
|
|
* A versatile mesh processing toolbox o o *
|
|
|
|
* _ O _ *
|
|
|
|
* Copyright(C) 2008 \/)\/ *
|
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
|
|
History
|
|
|
|
$Log: not supported by cvs2svn $
|
2008-03-11 10:08:46 +01:00
|
|
|
Revision 1.1 2008/02/16 12:00:34 benedetti
|
|
|
|
first version, adapted from meshlab's editmeasure plugin
|
|
|
|
|
2008-02-16 13:00:35 +01:00
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef RUBBERBAND_H
|
|
|
|
#define RUBBERBAND_H
|
|
|
|
|
|
|
|
#include <vcg/space/color4.h>
|
|
|
|
#include <QGLWidget>
|
|
|
|
|
|
|
|
namespace vcg {
|
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
/*!
|
|
|
|
@brief The Rubberband class.
|
|
|
|
|
|
|
|
This class is useful for interactively draw a straight line between 2 pickable points in a GL widget.
|
|
|
|
*/
|
2008-02-16 13:00:35 +01:00
|
|
|
class Rubberband
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//data:
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
/// The color of the rubberband
|
|
|
|
Color4b color;
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
// functions:
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
/*!
|
|
|
|
@brief The constructor.
|
|
|
|
|
|
|
|
Initialize the rubberband data.
|
|
|
|
*/
|
2008-02-16 13:00:35 +01:00
|
|
|
Rubberband(Color4b);
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
/*!
|
|
|
|
@brief The destructor.
|
|
|
|
|
|
|
|
The destructor.
|
|
|
|
*/
|
2008-02-16 13:00:35 +01:00
|
|
|
virtual ~Rubberband() {}
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
/*!
|
|
|
|
@brief Render the rubberband and do the picking.
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
Is important that this function is called in order to apply the Drag and Pin commands.
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
@param glw the GL widget.
|
|
|
|
*/
|
|
|
|
void Render(QGLWidget* glw);
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
/*!
|
|
|
|
@brief Set the current rubberband endpoint.
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
This function should be called after MouseMove events.
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
@param cursor the cursor position.
|
|
|
|
*/
|
|
|
|
void Drag(QPoint cursor);
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
/*!
|
|
|
|
@brief Ask for picking.
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
This function should be called after MouseRelease events.
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
The first time is called, if the picking is successful, sets the startpoint.
|
|
|
|
The second time sets, if the picking is successful, the endpoint.
|
|
|
|
After the second time this has no effect.
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
@param cursor the cursor position.
|
|
|
|
*/
|
|
|
|
void Pin(QPoint cursor);
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
/*!
|
|
|
|
@brief Reset the rubberband.
|
|
|
|
*/
|
2008-02-16 13:00:35 +01:00
|
|
|
void Reset();
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
/*!
|
|
|
|
@brief Return true if the rubberband has been drawn.
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
@return true if the line has been drawn, false otherwise.
|
|
|
|
*/
|
2013-12-16 13:15:20 +01:00
|
|
|
bool IsReady();
|
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
/*!
|
|
|
|
@brief Get the rubberband start and end points.
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
@param startpoint is set to the rubberband start point.
|
|
|
|
@param endpoint is set to the rubberband end point.
|
|
|
|
@warning Don't call this function until IsReady() returns true!
|
|
|
|
*/
|
|
|
|
void GetPoints(Point3f &startpoint,Point3f &endpoint);
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
/*!
|
|
|
|
@brief Render a text label near the endpoint (if it exists).
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-03-11 10:08:46 +01:00
|
|
|
@param text the text to render.
|
|
|
|
@param glw the GL widget.
|
|
|
|
*/
|
2008-02-16 13:00:35 +01:00
|
|
|
private:
|
|
|
|
// types:
|
|
|
|
typedef enum { RUBBER_BEGIN = 0,
|
2013-12-16 13:15:20 +01:00
|
|
|
RUBBER_DRAGGING = 1,
|
|
|
|
RUBBER_DRAGGED = 2,
|
|
|
|
} RubberPhase;
|
|
|
|
// data:
|
2008-02-16 13:00:35 +01:00
|
|
|
RubberPhase currentphase;
|
|
|
|
QPoint qt_cursor;
|
|
|
|
Point3f start, end;
|
|
|
|
bool have_to_pick;
|
2013-12-16 13:15:20 +01:00
|
|
|
// QFont font;
|
2008-02-16 13:00:35 +01:00
|
|
|
// functions:
|
2013-12-16 13:15:20 +01:00
|
|
|
vcg::Point2f DevicePixelConvert(const Point3f);
|
|
|
|
|
2008-02-16 13:00:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}//namespace
|
|
|
|
|
|
|
|
#endif /*RUBBERBAND_H*/
|