surfaceDeformation.h 3.56 KB
Newer Older
1 2 3 4
#ifndef _SURFACEDEFORMATION_PLUGIN_H_
#define _SURFACEDEFORMATION_PLUGIN_H_

#include "plugin.h"
5 6 7 8
#include "mapHandler.h"

#include "ui_surfaceDeformation.h"

9
#include "Container/fakeAttribute.h"
10

11 12
#include "OpenNL/linear_solver.h"
#include "Algo/LinearSolving/basic.h"
13 14 15 16 17


using namespace CGoGN;
using namespace SCHNApps;

18 19
namespace CGoGN { namespace Utils { class Drawer; } }

20

21 22 23 24 25 26 27
enum SelectionMode
{
	LOCKED,
	HANDLE
};


28 29
typedef NoNameIOAttribute<Eigen::Matrix3f> Eigen_Matrix3f ;

30 31 32 33
struct PerMapParameterSet
{
	PerMapParameterSet() {}
	PerMapParameterSet(MapHandlerGen* mh);
34
	~PerMapParameterSet();
35 36

	VertexAttribute<PFP2::VEC3> positionAttribute;
37 38 39
	CellMarker<VERTEX>* lockingMarker;
	CellMarker<VERTEX>* handleMarker;
	SelectionMode verticesSelectionMode;
40 41
	std::vector<unsigned int> locked_vertices;
	std::vector<unsigned int> handle_vertices;
42 43 44 45 46 47 48 49 50 51 52 53 54

	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;
	LinearSolver<PFP2::REAL>* solver;
55 56 57 58 59 60 61
};

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

62
	PerMapParameterSet* getCurrentMapParameterSet()
63 64 65 66
	{
		return perMap[selectedMap->getName()];
	}

67
	QHash<QString, PerMapParameterSet*> perMap;
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
	MapHandlerGen* selectedMap;
};


class SurfaceDeformationPlugin;

class SurfaceDeformationDockTab : public QWidget, public Ui::SurfaceDeformationWidget
{
public:
	SurfaceDeformationDockTab(SurfaceDeformationPlugin* p) : plugin(p)
	{
		setupUi(this);
	}

	void refreshUI(ParameterSet* params);

private:
	SurfaceDeformationPlugin* plugin;
};


89 90 91 92 93 94
class SurfaceDeformationPlugin : public Plugin
{
	Q_OBJECT
	Q_INTERFACES(CGoGN::SCHNApps::Plugin)

public:
95 96 97 98
	SurfaceDeformationPlugin() :
		b_refreshingUI(false),
		selecting(false),
		dragging(false)
99
	{
100
		setProvidesRendering(true);
101 102 103 104 105 106
	}

	~SurfaceDeformationPlugin()
	{}

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

109 110 111 112 113 114 115 116
	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);
117

118
	void setRefreshingUI(bool b) { b_refreshingUI = b; }
119 120

public slots:
121 122 123 124 125 126 127
	void viewLinked(View* view, Plugin* plugin);
	void viewUnlinked(View* view, Plugin* plugin);
	void currentViewChanged(View* view);

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

128 129
	void attributeAdded();

130 131
	void changeSelectedMap(View* view, MapHandlerGen* map);
	void changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP2::VEC3> attribute);
132
	void changeVerticesSelectionMode(View* view, MapHandlerGen* map, SelectionMode m);
133 134 135

	void cb_selectedMapChanged();
	void cb_positionAttributeChanged(int index);
136 137
	void cb_selectLockedVertices(bool b);
	void cb_selectHandleVertices(bool b);
138

139 140 141
	void matchDiffCoord(View* view, MapHandlerGen* map);
	void asRigidAsPossible(View* view, MapHandlerGen* map);

142
private:
143
	SurfaceDeformationDockTab* m_dockTab;
144
	QHash<View*, ParameterSet*> h_viewParams;
145

146 147
	Utils::Drawer* m_drawer;

148
	bool b_refreshingUI;
149 150 151 152 153 154 155

	bool selecting;
	PFP2::VEC3 selectionCenter;
	PFP2::REAL selectionRadius;
	bool dragging;
	PFP2::REAL dragZ;
	qglviewer::Vec dragPrevious;
156 157 158
};

#endif