-
Notifications
You must be signed in to change notification settings - Fork 23
/
GridTool.h
113 lines (95 loc) · 4.3 KB
/
GridTool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***********************************************************************
GridTool - Calibration tool for RawKinectViewer.
Copyright (c) 2010-2015 Oliver Kreylos
This file is part of the Kinect 3D Video Capture Project (Kinect).
The Kinect 3D Video Capture Project 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.
The Kinect 3D Video Capture Project 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 for more details.
You should have received a copy of the GNU General Public License along
with the Kinect 3D Video Capture Project; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
***********************************************************************/
#ifndef GRIDTOOL_INCLUDED
#define GRIDTOOL_INCLUDED
#include <vector>
#include <Geometry/Point.h>
#include <Geometry/Vector.h>
#include <Geometry/Plane.h>
#include <Geometry/ProjectiveTransformation.h>
#include <Vrui/Tool.h>
#include <Vrui/GenericToolFactory.h>
#include <Vrui/Application.h>
/* Forward declarations: */
class RawKinectViewer;
class GridTool;
typedef Vrui::GenericToolFactory<GridTool> GridToolFactory;
class GridTool:public Vrui::Tool,public Vrui::Application::Tool<RawKinectViewer>
{
friend class Vrui::GenericToolFactory<GridTool>;
/* Embedded classes: */
private:
typedef Geometry::ProjectiveTransformation<double,2> Homography;
typedef Homography::Point Point;
typedef Homography::Vector Vector;
typedef Geometry::Plane<double,3> Plane;
typedef Geometry::Point<double,3> Point3;
typedef Geometry::Vector<double,3> Vector3;
struct TiePoint // Structure to store a calibration tie point
{
/* Elements: */
public:
Homography depthHom; // Depth homography
Plane gridPlane; // Plane equation of grid in depth image space
Homography colorHom; // Color homography
};
enum DraggingMode // Enumerated type for grid dragging modes
{
IDLE,VERTEX,MOVE,ROTATE
};
/* Elements: */
private:
static GridToolFactory* factory; // Pointer to the factory object for this class
static int gridSize[2]; // Number of rows and columns in grid
static double tileSize[2]; // Size of each grid tile in world space units
std::vector<TiePoint> tiePoints; // List of already-created tie points
Homography homs[2]; // Homographies in depth image and color image
bool lockToPlane; // Flag whether to lock the depth grid to the depth plane
Plane camDepthPlane; // Camera-space equation of the plane to which the grid is locked
Plane worldDepthPlane; // World-space equation of the plane to which the grid is locked
Point lastDraggedPoints[4]; // Last four dragged points in grid coordinates
DraggingMode draggingMode; // Tool's current dragging mode
int draggedHom; // Flag which homography is being dragged
int draggedPointIndex; // Index of dragged point in list of previously dragged points
Vector dragOffset; // Offset from input device to dragged point
bool showTiePoints; // Flag whether to draw stored tie points
/* Private methods: */
Point getPoint(void) const;
static Homography calcHomography(const Point gridPoints[4],const Point imagePoints[4]);
void initHoms(void);
void startDrag(void);
void dragInPlane(const Point& moveHandle,const Point& rotateHandle);
void createTiePoint(void);
void calibrate(void);
void printWorldPoints(void);
static void drawGrid(const Homography& hom,bool active);
/* Constructors and destructors: */
public:
static GridToolFactory* initClass(Vrui::ToolManager& toolManager);
static void setGridSize(int newGridSize0,int newGridSize1);
static void setTileSize(double newTileSize0,double newTileSize1);
GridTool(const Vrui::ToolFactory* factory,const Vrui::ToolInputAssignment& inputAssignment);
virtual ~GridTool(void);
/* Methods from class Vrui::Tool: */
virtual void initialize(void);
virtual const Vrui::ToolFactory* getFactory(void) const;
virtual void buttonCallback(int buttonSlotIndex,Vrui::InputDevice::ButtonCallbackData* cbData);
virtual void frame(void);
virtual void display(GLContextData& contextData) const;
};
#endif