vcglib/wrap/gui/coordinateframe.h

233 lines
7.4 KiB
C
Raw Normal View History

2008-02-16 15:12:30 +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-04-10 13:09:34 +02:00
Revision 1.7 2008/03/14 16:54:34 benedetti
Added doxygen documentation
2008-03-14 17:54:34 +01:00
Revision 1.6 2008/03/02 16:44:18 benedetti
moved ActiveCoordinateFrame to its own files
Revision 1.5 2008/02/22 20:04:02 benedetti
many user interface improvements, cleaned up a little
Revision 1.4 2008/02/17 20:52:53 benedetti
some generalization made
2008-02-17 21:52:53 +01:00
Revision 1.3 2008/02/16 14:12:30 benedetti
first version
2008-02-16 15:12:30 +01:00
****************************************************************************/
#ifndef COORDINATEFRAME_H
#define COORDINATEFRAME_H
#include <vcg/math/similarity.h>
#include <vcg/space/color4.h>
#include <QGLWidget>
namespace vcg {
2008-03-14 17:54:34 +01:00
/*!
@brief The CoordinateFrame class.
This class can draw the standard icon for a 3D coordinate frame.
*/
2008-02-16 15:12:30 +01:00
class CoordinateFrame
{
public:
2008-03-14 17:54:34 +01:00
// functions:
/*!
@brief The constructor.
Initialize the CoordinateFrame data.
@param size the distance from the origin to the endpoint of the arrows.
*/
CoordinateFrame(float size);
/*!
@brief The destructor.
The destructor.
*/
2008-02-16 15:12:30 +01:00
virtual ~CoordinateFrame() {}
2008-03-14 17:54:34 +01:00
/*!
@brief Render the coordinate frame.
@param glw the GL widget.
*/
virtual void Render(QGLWidget* glw,QPainter* p = NULL);
2008-02-16 15:12:30 +01:00
// data
2008-03-14 17:54:34 +01:00
/// The color used for the ticks, the ticks values and the head of the arrows.
2008-02-16 15:12:30 +01:00
Color4b basecolor;
2008-03-14 17:54:34 +01:00
/// The color of the X axis and label.
2008-02-16 15:12:30 +01:00
Color4b xcolor;
2008-03-14 17:54:34 +01:00
/// The color of the Y axis and label.
2008-02-16 15:12:30 +01:00
Color4b ycolor;
2008-03-14 17:54:34 +01:00
/// The color of the Z axis and label.
2008-02-16 15:12:30 +01:00
Color4b zcolor;
2008-03-14 17:54:34 +01:00
/// The distance from the origin to the endpoint of the arrows.
2008-02-16 15:12:30 +01:00
float size;
2008-03-14 17:54:34 +01:00
/// The width of the lines.
2008-02-16 15:12:30 +01:00
float linewidth;
2008-03-14 17:54:34 +01:00
/// The font used for the labels and the ticks values.
2008-02-16 15:12:30 +01:00
QFont font;
2008-03-14 17:54:34 +01:00
/// The flag that enables axes rendering.
2008-02-16 15:12:30 +01:00
bool drawaxis;
2008-03-14 17:54:34 +01:00
/// The flag that enables lablels rendering.
2008-02-16 15:12:30 +01:00
bool drawlabels;
2008-03-14 17:54:34 +01:00
/// The flag that enables ticks values rendering.
2008-02-16 15:12:30 +01:00
bool drawvalues;
2008-03-14 17:54:34 +01:00
2008-04-10 13:09:34 +02:00
// useful functions:
static void drawTickedLine(const Point3d &, const Point3d &, float, float,float);
static float calcSlope(const Point3d &, const Point3d &, float, int , double *, double *, GLint *);
static float niceRound(float);
2008-02-16 15:12:30 +01:00
};
2008-03-14 17:54:34 +01:00
/*!
@brief The MovableCoordinateFrame class.
This class extends the coordinate frame with the ability of being programmatically rototranslated.
*/
2008-02-16 15:12:30 +01:00
class MovableCoordinateFrame: public CoordinateFrame
{
public:
2008-03-14 17:54:34 +01:00
/*!
@brief The constructor.
Initialize the MovableCoordinateFrame data.
@param size the distance from the origin to the endpoint of the arrows.
*/
2008-02-16 15:12:30 +01:00
MovableCoordinateFrame(float);
2008-03-14 17:54:34 +01:00
/*!
@brief The destructor.
The destructor.
*/
2008-02-16 15:12:30 +01:00
virtual ~MovableCoordinateFrame(){}
2008-03-14 17:54:34 +01:00
/*!
@brief Render the movable coordinate frame in its position.
@param glw the GL widget.
*/
virtual void Render(QGLWidget* glw);
/*!
@brief Reset the position and/or the rotation of the coordinate frame.
@param reset_position set to true to reset the position.
@param reset_alignment set to true to reset the rotation.
*/
virtual void Reset(bool reset_position,bool reset_alignment);
/*!
@brief Set the position of the coordinate frame.
@param new_position the new position of the coordinate frame.
*/
virtual void SetPosition(const Point3f new_position);
/*!
@brief Set the rotation of the coordinate frame.
@param new_rotation the new rotation of the coordinate frame.
*/
virtual void SetRotation(const Quaternionf rotation);
/*!
@brief Get the position of the coordinate frame.
@return the position of the coordinate frame.
*/
2008-02-16 15:12:30 +01:00
virtual Point3f GetPosition();
2008-03-14 17:54:34 +01:00
/*!
@brief Get the rotation of the coordinate frame.
@return the rotation of the coordinate frame.
*/
2008-02-16 15:12:30 +01:00
virtual Quaternionf GetRotation();
2008-03-14 17:54:34 +01:00
/*!
@brief Computes the transformation matrix relative to the current rototranslation.
@param m is set to the transformation matrix.
*/
virtual void GetTransform(Matrix44f &m);
/*!
@brief Rotates the coordinate frame wrt itself.
@param angle the angle of the rotation, in degrees.
@param axis the axis of the rotation.
*/
virtual void Rot(float angle,const Point3f axis);
/*!
@brief Align the coordinate frame to one or two directions.
If the primary direction of alignment is null this function does nothing, otherwise two rotations are performed: the first rotation aligns the axis named axis_1 to the primary direction of alignment, the second rotation never moves axis_1 away from the primary direction.
If the secondary direction of alignment is not null and is not parallel to the primary direction the axis named axis_2 is rotated as much as possible to be aligned to secondary direction.
If the secondary direction of alignment is null the axis named axis_2 is rotated as much as possible to be realigned to its old direction, if this is impossible the remaining axis is used.
@param primary the primary direction of alignment.
@param secondary the secondary direction of alignment.
@param axis_1 the name of the axis to align to the primary direction, must be a char choosen from 'X', 'Y' and 'Z'
@param axis_2 the name of the axis to align to the secondary direction, must be different from axis_1 and must be a char choosen from 'X', 'Y', 'Z' and ' '; if the char is ' ' the axis is choosen automatically.
*/
virtual void AlignWith(const Point3f primary, const Point3f secondary, const char axis_1, const char axis_2);
2008-02-16 15:12:30 +01:00
protected:
// data:
Point3f position;
Quaternionf rotation;
2008-03-14 17:54:34 +01:00
2008-02-16 15:12:30 +01:00
// functions:
virtual void Move(const Similarityf);
void RotateToAlign(const Point3f, const Point3f);
};
}//namespace
#endif /*COORDINATEFRAME_H*/