surfaceDeformation.h 3.38 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef _SURFACEDEFORMATION_PLUGIN_H_
#define _SURFACEDEFORMATION_PLUGIN_H_

#include "plugin.h"
#include "surfaceDeformationDockTab.h"

#include "mapHandler.h"

#include "Utils/pointSprite.h"

#include "Container/fakeAttribute.h"

#include "NL/nl.h"
#include "Algo/LinearSolving/basic.h"
#include "Eigen/Dense"

namespace CGoGN
{

namespace SCHNApps
{


enum SelectionMode
{
	LOCKED,
	HANDLE
};


typedef NoNameIOAttribute<Eigen::Matrix3f> Eigen_Matrix3f ;

struct PerMapParameterSet
{
	PerMapParameterSet(MapHandlerGen* mh);
	~PerMapParameterSet();

	void initParameters();

	MapHandlerGen* mh;

	VertexAttribute<PFP2::VEC3> positionAttribute;
	CellMarker<VERTEX>* lockingMarker;
	CellMarker<VERTEX>* handleMarker;
	SelectionMode verticesSelectionMode;
	std::vector<PFP2::VEC3> lockedVertices;
	std::vector<PFP2::VEC3> handleVertices;
	std::vector<unsigned int> handleVerticesId;
	Utils::VBO* lockedVerticesVBO;
	Utils::VBO* handleVerticesVBO;

	VertexAttribute<PFP2::VEC3> positionInit;
	VertexAttribute<PFP2::VEC3> vertexNormal;
	EdgeAttribute<PFP2::REAL> edgeAngle;
	EdgeAttribute<PFP2::REAL> edgeWeight;
	VertexAttribute<PFP2::REAL> vertexArea;
	VertexAttribute<PFP2::VEC3> diffCoord;
	VertexAttribute<Eigen_Matrix3f> vertexRotationMatrix;
	VertexAttribute<PFP2::VEC3> rotatedDiffCoord;

	VertexAttribute<unsigned int> vIndex;
	unsigned int nb_vertices;
	NLContext nlContext;
};

struct ParameterSet
{
	ParameterSet() : selectedMap(NULL)
	{}

	PerMapParameterSet* getCurrentMapParameterSet()
	{
		if(selectedMap)
			return perMap[selectedMap->getName()];
		else
			return NULL;
	}

	QHash<QString, PerMapParameterSet*> perMap;
	MapHandlerGen* selectedMap;
};


class SurfaceDeformationPlugin : public Plugin
{
	Q_OBJECT
	Q_INTERFACES(CGoGN::SCHNApps::Plugin)

public:
	SurfaceDeformationPlugin() :
		selecting(false),
		dragging(false)
	{
		setProvidesRendering(true);
	}

	~SurfaceDeformationPlugin()
	{}

	virtual bool enable();
	virtual void disable();

	virtual void redraw(View *view);

	virtual void keyPress(View* view, QKeyEvent* event);
	virtual void keyRelease(View* view, QKeyEvent* event);
	virtual void mousePress(View* view, QMouseEvent* event);
	virtual void mouseRelease(View* view, QMouseEvent* event);
	virtual void mouseMove(View* view, QMouseEvent* event);
	virtual void wheelEvent(View* view, QWheelEvent* event);

protected:
	SurfaceDeformationDockTab* m_dockTab;
	QHash<View*, ParameterSet*> h_viewParams;

	Utils::PointSprite* m_pointSprite;

	Utils::VBO* selectionSphereVBO;

	bool selecting;
	PFP2::VEC3 selectionCenter;
	PFP2::REAL selectionRadius;
	bool dragging;
	PFP2::REAL dragZ;
	qglviewer::Vec dragPrevious;

public slots:
	void viewLinked(View* view, Plugin* plugin);
	void viewUnlinked(View* view, Plugin* plugin);
	void currentViewChanged(View* view);

	void mapLinked(MapHandlerGen* m);
	void mapUnlinked(MapHandlerGen* m);

protected:
	void addManagedMap(View *v, MapHandlerGen* m);
	void removeManagedMap(View *v, MapHandlerGen* m);

public slots:
	void changeSelectedMap(View* view, MapHandlerGen* map);

	void changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP2::VEC3> attribute, bool fromUI = false);
	void changeVerticesSelectionMode(View* view, MapHandlerGen* map, SelectionMode m, bool fromUI = false);

protected:
	void matchDiffCoord(View* view, MapHandlerGen* map);
	void asRigidAsPossible(View* view, MapHandlerGen* map);
};

} // namespace SCHNApps

} // namespace CGoGN

#endif