File: ccMaterial.h

package info (click to toggle)
cloudcompare 2.10.1-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 55,916 kB
  • sloc: cpp: 219,837; ansic: 29,944; makefile: 67; sh: 45
file content (167 lines) | stat: -rw-r--r-- 6,127 bytes parent folder | download | duplicates (2)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
//##########################################################################
//#                                                                        #
//#                              CLOUDCOMPARE                              #
//#                                                                        #
//#  This program 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; version 2 or later of the License.      #
//#                                                                        #
//#  This program 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.                          #
//#                                                                        #
//#          COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI)             #
//#                                                                        #
//##########################################################################

#ifndef CC_MATERIAL_HEADER
#define CC_MATERIAL_HEADER

//Local
#include "ccColorTypes.h"
#include "ccSerializableObject.h"

//Qt
#include <QtGui/qopengl.h>
#include <QSharedPointer>

class QImage;
class QOpenGLContext;

//! Mesh (triangle) material
class QCC_DB_LIB_API ccMaterial : public ccSerializableObject
{
public:
	//! Const + Shared type
	typedef QSharedPointer<const ccMaterial> CShared;
	//! Shared type
	typedef QSharedPointer<ccMaterial> Shared;

	//! Default constructor
	ccMaterial(QString name = QString("default"));

	//! Copy constructor
	ccMaterial(const ccMaterial& mtl);

	//! Returns the material name
	inline const QString& getName() const { return m_name; }
	//! Returns the texture filename (if any)
	inline const QString& getTextureFilename() const { return m_textureFilename; }
	//! Sets the material name
	inline void setName(QString name) { m_name = name; }

	//! Sets diffuse color (both front and back)
	void setDiffuse(const ccColor::Rgbaf& color);
	//! Sets diffuse color (front)
	inline void setDiffuseFront(const ccColor::Rgbaf& color) { m_diffuseFront = color; }
	//! Sets diffuse color (back)
	inline void setDiffuseBack(const ccColor::Rgbaf& color) { m_diffuseBack = color; }
	//! Returns front diffuse color
	inline const ccColor::Rgbaf& getDiffuseFront() const { return m_diffuseFront; }
	//! Returns back diffuse color
	inline const ccColor::Rgbaf& getDiffuseBack() const { return m_diffuseBack; }

	//! Sets ambient color
	inline void setAmbient(const ccColor::Rgbaf& color) { m_ambient = color; }
	//! Returns ambient color
	inline const ccColor::Rgbaf& getAmbient() const { return m_ambient; }

	//! Sets specular color
	inline void setSpecular(const ccColor::Rgbaf& color) { m_specular = color; }
	//! Returns specular color
	inline const ccColor::Rgbaf& getSpecular() const { return m_specular; }

	//! Sets emission color
	inline void setEmission(const ccColor::Rgbaf& color) { m_emission = color; }
	//! Returns emission color
	inline const ccColor::Rgbaf& getEmission() const { return m_emission; }

	//! Sets shininess (both front - 100% - and back - 80%)
	void setShininess(float val);
	//! Sets shininess (front)
	inline void setShininessFront(float val) { m_shininessFront = val; }
	//! Sets shininess (back)
	inline void setShininessBack(float val) { m_shininessBack = val; }
	//! Returns front shininess
	inline float getShininessFront() const { return m_shininessFront; }
	//! Returns back shininess
	inline float getShininessBack() const { return m_shininessBack; }

	//! Sets transparency (all colors)
	void setTransparency(float val);

	//! Apply parameters (OpenGL)
	void applyGL(const QOpenGLContext* context, bool lightEnabled, bool skipDiffuse) const;

	//! Returns whether the material has an associated texture or not
	bool hasTexture() const;

	//! Sets texture
	/** If no filename is provided, a random one will be generated.
	**/
	void setTexture(QImage image, QString absoluteFilename =  QString(), bool mirrorImage = true);

	//! Loads texture from file (and set it if successful)
	/** If the filename is not already in DB, the corresponding file will be loaded.
		\return whether the file could be loaded (or is already in DB) or not
	**/
	bool loadAndSetTexture(QString absoluteFilename);

	//! Returns the texture (if any)
	const QImage getTexture() const;

	//! Returns the texture ID (if any)
	GLuint getTextureID() const;

	//! Helper: makes all active GL light sources neutral (i.e. 'gray')
	/** WARNING: an OpenGL context must be active!
	**/
	static void MakeLightsNeutral(const QOpenGLContext* context);

	//! Returns the texture image associated to a given name
	static QImage GetTexture(QString absoluteFilename);

	//! Adds a texture to the global texture DB
	static void AddTexture(QImage image, QString absoluteFilename);

	//! Release all texture objects
	/** Should be called BEFORE the global shared context is destroyed.
	**/
	static void ReleaseTextures();

	//! Release the texture
	/** \warning Make sure no more materials are using this texture!
	**/
	void releaseTexture();

	//! Compares this material with another one
	/** \return true if both materials are equivalent or false otherwise
	**/
	bool compare(const ccMaterial& mtl) const;

	//inherited from ccSerializableObject
	virtual bool isSerializable() const { return true; }
	/** \warning Doesn't save the texture image!
	**/
	virtual bool toFile(QFile& out) const;
	virtual bool fromFile(QFile& in, short dataVersion, int flags);

	//! Returns unique identifier (UUID)
	inline QString getUniqueIdentifier() const { return m_uniqueID; }

protected:
	QString m_name;
	QString m_textureFilename;
	QString m_uniqueID;

	ccColor::Rgbaf m_diffuseFront;
	ccColor::Rgbaf m_diffuseBack;
	ccColor::Rgbaf m_ambient;
	ccColor::Rgbaf m_specular;
	ccColor::Rgbaf m_emission;
	float m_shininessFront;
	float m_shininessBack;
};

#endif //CC_MATERIAL_HEADER