surface_radiance.h 5.27 KB
Newer Older
1 2 3 4 5
#ifndef _SURFACE_RADIANCE_PLUGIN_H_
#define _SURFACE_RADIANCE_PLUGIN_H_

#include "plugin_interaction.h"
#include "surface_radiance_dockTab.h"
6
#include "dialog_computeRadianceDistance.h"
7 8

#include "Utils/sphericalHarmonics.h"
9
#include "Utils/bivariatePolynomials.h"
10
#include "Utils/Shaders/shaderRadiancePerVertex.h"
11
#include "Utils/Shaders/shaderRadiancePerVertex_P.h"
12
#include "Utils/drawer.h"
13

14
#include "Algo/Decimation/decimation.h"
15 16 17 18 19 20 21 22 23 24 25

namespace CGoGN
{

namespace SCHNApps
{

struct MapParameters
{
	MapParameters() :
		positionVBO(NULL),
26
		tangentVBO(NULL),
27
		normalVBO(NULL),
28 29 30
		binormalVBO(NULL),
		radiancePerVertexShader(NULL),
		radiancePerVertexPShader(NULL),
31
		radianceTexture(NULL),
32 33 34 35 36
		paramVBO(NULL),
		positionApproximator(NULL),
		normalApproximator(NULL),
		radianceApproximator(NULL),
		selector(NULL)
37 38
	{}

39 40
	unsigned int nbVertices;

41
	Utils::VBO* positionVBO;
42
	Utils::VBO* tangentVBO;
43
	Utils::VBO* normalVBO;
44
	Utils::VBO* binormalVBO;
45 46

	CGoGN::Utils::ShaderRadiancePerVertex* radiancePerVertexShader;
47
	CGoGN::Utils::ShaderRadiancePerVertex_P* radiancePerVertexPShader;
48

49
	VertexAttribute<Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>, PFP2::MAP> radiance;
50 51
	VertexAttribute<Utils::BivariatePolynomials<PFP2::REAL, PFP2::VEC3>, PFP2::MAP> radiance_P;

52 53 54
	Utils::Texture<2, Geom::Vec3f>* radianceTexture;
	VertexAttribute<Geom::Vec2i, PFP2::MAP> param;
	Utils::VBO* paramVBO;
55

56
//	DartAttribute<PFP2::REAL, PFP2::MAP> halfedgeError;
57

58 59 60
	Algo::Surface::Decimation::ApproximatorGen<PFP2>* positionApproximator;
	Algo::Surface::Decimation::ApproximatorGen<PFP2>* normalApproximator;
	Algo::Surface::Decimation::ApproximatorGen<PFP2>* radianceApproximator;
61 62

	Algo::Surface::Decimation::Selector<PFP2>* selector;
63 64 65 66 67 68
};

class Surface_Radiance_Plugin : public PluginInteraction
{
	Q_OBJECT
	Q_INTERFACES(CGoGN::SCHNApps::Plugin)
Sylvain Thery's avatar
Sylvain Thery committed
69 70 71
#if CGOGN_QT_DESIRED_VERSION == 5
	Q_PLUGIN_METADATA(IID "CGoGN.SCHNapps.Plugin")
#endif
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
	friend class Surface_Radiance_DockTab;

public:
	Surface_Radiance_Plugin()
	{}

	~Surface_Radiance_Plugin()
	{}

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

	virtual void draw(View *view) {}
	virtual void drawMap(View* view, MapHandlerGen* map);

	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) {}

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

private slots:
	// slots called from SCHNApps signals
	void selectedViewChanged(View* prev, View* cur);
	void selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur);
	void mapAdded(MapHandlerGen* map);
	void mapRemoved(MapHandlerGen* map);
104
	void schnappsClosing();
105 106 107 108 109 110

	// slots called from MapHandler signals
	void vboAdded(Utils::VBO* vbo);
	void vboRemoved(Utils::VBO* vbo);
	void attributeModified(unsigned int orbit, QString nameAttr);

111 112
	void importFromFileDialog_SH();
	void importFromFileDialog_P();
113

114 115 116
	void openComputeRadianceDistanceDialog();
	void computeRadianceDistanceFromDialog();

117 118 119 120
public slots:
	// slots for Python calls
	void changePositionVBO(const QString& map, const QString& vbo);
	void changeNormalVBO(const QString& map, const QString& vbo);
121 122
	MapHandlerGen* importFromFile_SH(const QString& fileName);
	MapHandlerGen* importFromFile_P(const QString& fileName);
123 124 125 126 127
	void decimate(
		const QString& mapName,
		const QString& positionAttributeName,
		const QString& normalAttributeName,
		float decimationGoal,
128 129 130
		bool halfCollapse = false,
		bool exportMeshes = false
	);
131
	void computeRadianceDistance(const QString& mapName1,
132
		const QString& positionAttributeName1,
133
		const QString& normalAttributeName1,
134 135 136
		const QString& distanceAttributeName1,
		const QString& mapName2,
		const QString& positionAttributeName2,
137
		const QString& normalAttributeName2,
138
		const QString& distanceAttributeName2
139
	);
140 141 142 143 144
	void exportPLY(
		const QString& mapName,
		const QString& positionAttributeName,
		const QString& normalAttributeName,
		const QString& filename
145
	);
146 147

protected:
148
	MapHandlerGen* currentlyDecimatedMap() { return m_currentlyDecimatedMap; }
149
	bool currentDecimationHalf() { return m_currentDecimationHalf; }
150 151
	static void checkNbVerticesAndExport(Surface_Radiance_Plugin* p, const unsigned int* nbVertices);

152
	Surface_Radiance_DockTab* m_dockTab;
153 154 155 156

	Dialog_ComputeRadianceDistance* m_computeRadianceDistanceDialog;
	QAction* m_computeRadianceDistanceAction;

157 158
	QHash<MapHandlerGen*, MapParameters> h_mapParameterSet;

159
	MapHandlerGen* m_currentlyDecimatedMap;
160
	bool m_currentDecimationHalf;
161 162 163
	std::vector<unsigned int> exportNbVert;
	unsigned int nextExportIndex;

164 165
	QAction* m_importSHAction;
	QAction* m_importPAction;
166 167 168 169 170 171 172 173 174 175

	static bool isInHemisphere(double x, double y, double z, void* u)
	{ // true iff [x,y,z] and u have the same direction
		PFP2::REAL* n = (PFP2::REAL*)(u);
		return x*n[0] + y*n[1] + z*n[2] >= 0.0;
	}

	static double SHEvalCartesian_Error(double x, double y, double z, void* u)
	{
		Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>& e = *(Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>*)(u);
176
		PFP2::VEC3 c = e.evaluate_at(x, y, z, 0);
177 178
		return c.norm2();
	}
179 180 181 182 183 184
};

} // namespace SCHNApps

} // namespace CGoGN

185
#endif // _SURFACE_RADIANCE_PLUGIN_H_