surface_deformation.h 3.05 KB
Newer Older
1 2 3
#ifndef _SURFACE_DEFORMATION_PLUGIN_H_
#define _SURFACE_DEFORMATION_PLUGIN_H_

4
#include "dll.h"
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
#include "plugin_interaction.h"
#include "surface_deformation_dockTab.h"

#include "mapHandler.h"

#include "Container/fakeAttribute.h"

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

namespace CGoGN
{

namespace SCHNApps
{

typedef NoTypeNameAttribute<Eigen::Matrix3f> Eigen_Matrix3f;

struct MapParameters
{
	MapParameters();
	~MapParameters();

	void start(MapHandlerGen* mh);
	void stop(MapHandlerGen* mh);

Sylvain Thery's avatar
Sylvain Thery committed
32
	VertexAttribute<PFP2::VEC3, PFP2::MAP> positionAttribute;
33

34 35
	CellSelector<PFP2::MAP, VERTEX>* handleSelector;
	CellSelector<PFP2::MAP, VERTEX>* freeSelector;
36 37 38

	bool initialized;

Sylvain Thery's avatar
Sylvain Thery committed
39 40 41 42
	VertexAttribute<PFP2::VEC3, PFP2::MAP> positionInit;
	VertexAttribute<PFP2::VEC3, PFP2::MAP> diffCoord;
	VertexAttribute<Eigen_Matrix3f, PFP2::MAP> vertexRotationMatrix;
	VertexAttribute<PFP2::VEC3, PFP2::MAP> rotatedDiffCoord;
43

Sylvain Thery's avatar
Sylvain Thery committed
44
	VertexAttribute<unsigned int, PFP2::MAP> vIndex;
45 46 47 48 49
	unsigned int nb_vertices;

	NLContext nlContext;
};

50
class SURFACE_DEFORMATION_API Surface_Deformation_Plugin : public PluginInteraction
51 52 53
{
	Q_OBJECT
	Q_INTERFACES(CGoGN::SCHNApps::Plugin)
Sylvain Thery's avatar
Sylvain Thery committed
54 55 56
#if CGOGN_QT_DESIRED_VERSION == 5
	Q_PLUGIN_METADATA(IID "CGoGN.SCHNapps.Plugin")
#endif
57 58 59 60 61

	friend class Surface_Deformation_DockTab;

public:
	Surface_Deformation_Plugin() :
62
		m_draginit(false),
63 64 65 66 67 68 69 70 71
		m_dragging(false)
	{}

	~Surface_Deformation_Plugin()
	{}

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

72
	virtual void draw(View *view);
73 74 75
	virtual void drawMap(View* view, MapHandlerGen* map) {}

	virtual void keyPress(View* view, QKeyEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
76 77 78
	virtual void keyRelease(View* , QKeyEvent* ) {}
	virtual void mousePress(View* , QMouseEvent* ) {}
	virtual void mouseRelease(View* , QMouseEvent* ) {}
79
	virtual void mouseMove(View* view, QMouseEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
80
	virtual void wheelEvent(View* , QWheelEvent* ) {}
81 82 83 84 85 86 87 88 89 90 91 92 93 94

	virtual void viewLinked(View *view) {}
	virtual void viewUnlinked(View *view) {}

private slots:
	// slots called from SCHNApps signals
	void selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur);
	void mapAdded(MapHandlerGen* map);
	void mapRemoved(MapHandlerGen* map);

	// slots called from MapHandler signals
	void attributeAdded(unsigned int orbit, const QString& name);
	void cellSelectorAdded(unsigned int orbit, const QString& name);
	void cellSelectorRemoved(unsigned int orbit, const QString& name);
95
	void selectedCellsChanged(CellSelectorGen *cs);
96 97 98 99 100

public slots:
	// slots for Python calls
	void changePositionAttribute(const QString& map, const QString& name);
	void changeHandleSelector(const QString& map, const QString& name);
101
	void changeFreeSelector(const QString& map, const QString& name);
102 103 104 105 106 107 108 109 110 111

protected:
	void toggleMapDeformation(MapHandlerGen* map);
	void matchDiffCoord(MapHandlerGen* map);
	void asRigidAsPossible(MapHandlerGen* map);

protected:
	Surface_Deformation_DockTab* m_dockTab;
	QHash<MapHandlerGen*, MapParameters> h_parameterSet;

112
	bool m_draginit;
113 114 115 116 117 118 119 120 121 122
	bool m_dragging;
	PFP2::REAL m_dragZ;
	qglviewer::Vec m_dragPrevious;
};

} // namespace SCHNApps

} // namespace CGoGN

#endif