1 #ifndef __CURVE_H__
2 #define __CURVE_H__
3 
4 #include <QList>
5 #include <QVector>
6 #include <QtDebug>
7 
8 #include "qwt3d_plot.h"
9 
10 // Shorthand definitions
11 #define TITLE		"QwtPlot3D (Use Ctrl-Alt-Shift-LeftBtn-Wheel or keyboard)"
12 
13 namespace Qwt3D
14 {
15 
16 //! A class representing Curved Surfaces
17 /**
18     A Curved Surface ...
19 
20 */
21 class QWT3D_EXPORT Curve : public QObject
22 {
23     Q_OBJECT
24 
25 public:
26 	Curve(QWidget* parent = 0);
27 	virtual ~Curve();
28 
setPlot(Qwt3D::Plot3D * p)29 	void setPlot(Qwt3D::Plot3D* p)				{ plot_p = p; }
plot()30 	Qwt3D::Plot3D* plot() const					{ return plot_p; }			//!< Returns pointer to parent Plot3D object
title()31 	Qwt3D::Label* title() const					{ return title_p; }			//!< Returns pointer to title Label object
legend()32 	Qwt3D::ColorLegend* legend()				{ return &legend_; }		//!< Returns pointer to key ColorLegend object
33 	virtual void draw();
34 
35 	void connects();
36 	void disconnects();
37 	void updateNormals();													//!< Recalculates surface normals;
38 
39 	std::pair<int,int> facets() const;										//!< Returns the number of mesh cells for the ORIGINAL data
40 	bool loadFromData(Qwt3D::Triple** data, unsigned int columns, unsigned int rows, QString titlestr = QString(),
41 					  bool uperiodic = false, bool vperiodic = false);
42 	bool loadFromData(double** data, unsigned int columns, unsigned int rows,
43 					  double minx, double maxx, double miny, double maxy, QString titlestr = QString());
44 	bool loadFromData(Qwt3D::TripleField const& data, Qwt3D::CellField const& poly, QString titlestr = QString());
45 
floorStyle()46 	Qwt3D::FLOORSTYLE floorStyle() const		{ return floorstyle_; }		//!< Returns floor style
userStyle()47 	Qwt3D::Enrichment* userStyle() const		{ return userplotstyle_p; }	//!< Returns current Enrichment object used for plotting styles (if set, zero else)
plotStyle()48 	Qwt3D::PLOTSTYLE plotStyle() const			{ return plotstyle_; }		//!< Returns plotting style
shading()49 	Qwt3D::SHADINGSTYLE shading() const			{ return shading_; }		//!< Returns shading style
resolution()50 	unsigned int resolution() const				{ return resolution_p; }	//!< Returns data resolution (1 means all data)
isolines()51 	unsigned int isolines() const				{ return isolines_; }		//!< Returns number of isolines
smoothDataMesh()52 	bool smoothDataMesh() const					{ return smoothdatamesh_p; }//!< True if mesh antialiasing is on
meshColor()53 	Qwt3D::RGBA meshColor() const				{ return meshcolor_; }		//!< Returns color for data mesh
meshLineWidth()54 	double meshLineWidth() const				{ return meshLineWidth_; }	//!< Returns line width for data mesh
dataColor()55 	const Qwt3D::Color* dataColor() const		{ return datacolor_p; }		//!< Returns data color object
polygonOffset()56 	double polygonOffset() const				{ return polygonOffset_; }	//!< Returns relative value for polygon offset [0..1]
57 
normals()58 	bool normals() const						{ return datanormals_p; }	//!< Returns \c true, if normal drawing is on
normalLength()59 	double normalLength() const					{ return normalLength_p; }	//!< Returns relative length of normals
normalQuality()60 	int normalQuality() const					{ return normalQuality_p; }	//!< Returns plotting quality of normal arrows
61 
hull()62 	Qwt3D::ParallelEpiped hull() const			{ return hull_; }			//!< Returns rectangular hull
data()63 	const Qwt3D::Data* data() const				{ return actualData_p; }	//!< the data pointer
hasData()64 	bool hasData() const						{ return (actualData_p) ? !actualData_p->empty() : false; }	//!< Returns true if valid data available, false else
dataProjected()65 	bool dataProjected() const					{ return datapoints_; }		//!< Returns projected state of data points
66 
enrichmentList()67 	QList<Qwt3D::Enrichment*> enrichmentList(){return elist_p;}; //!< Returns the Enrichments list
68 	virtual Qwt3D::Enrichment* addEnrichment(Qwt3D::Enrichment const&);		//!< Add an Enrichment
69 	virtual bool degrade(Qwt3D::Enrichment*);								//!< Remove an Enrichment
70 
isColorLegend()71 	bool isColorLegend() const					{ return displaylegend_; }	//!< Returns Color Legend display state
72 	void setColorLegend(int index, bool doublemode = false, QSize size = QSize(3, 32), QPoint pos = QPoint(3, 10));
73 
74 	void clearEnrichments();//!< Remove all Enrichments
75 
76 	double** getData(int *cols, int *rows);
77 	Qwt3D::CellField* getCellData(int *cells);
78 	Qwt3D::TripleField* getNodeData(int *nodes);
79 
80 	void deleteData(double**data, int columns);
81 	void deleteData(CellField* poly);
82 	void deleteData(TripleField* data);
83 
84     void queueUpdate();
85 
86     // Public data members
87 	Qwt3D::Tuple	titlerel_;
88 	Qwt3D::ANCHOR	titleanchor_;
89 	double			titlespace_;
90 	unsigned int	titlepos_;
91 
92 signals:
93     void resolutionChanged(int);
94     void updatePlotData(bool);
95     void updatePlot();
96 	void readInFinished(const QString&);
97 
98 public slots:
99     void setResolution(int);
100     void setPlotStyle(Qwt3D::PLOTSTYLE val);
101     void setPlotStyle(Qwt3D::Enrichment& val);
102     void setPolygonOffset(double d);
setFloorStyle(Qwt3D::FLOORSTYLE val)103     void setFloorStyle(Qwt3D::FLOORSTYLE val) { floorstyle_ = val; update_displaylists_ = true;} //!< Sets floor style
104     void setShading(Qwt3D::SHADINGSTYLE val);
105     void setIsolines(unsigned int isolines);
106 
107 	void updateColorLegend(int majors, int minors);							//!< Updates the curve data color legend
108 	void showColorLegend(bool);												//!< Show curve data color legend
109     void showNormals(bool); 												//!< Draw normals to every vertex
110     void setNormalLength(double val);										//!< Sets length of normals in percent per hull diagonale
111     void setNormalQuality(int val);											//!< Increases plotting quality of normal arrows
112 
setSmoothMesh(bool val)113     void setSmoothMesh(bool val) { smoothdatamesh_p = val; update_displaylists_ = true;} //!< Enables/disables smooth data mesh lines. Default is false
114     void setMeshColor(Qwt3D::RGBA rgba);									//!< Sets color for data mesh
115     void setMeshLineWidth(double lw);										//!< Sets line width for data mesh
116 
117     void setDataColor(Color* col);											//!< Sets new data color object
118     void setDataProjection(bool toggle = true)	{ datapoints_ = toggle; }	//!< Sets data point projection on & off
119     void setProjection(Qwt3D::PROJECTMODE val, bool toggle = true);			//!< Sets projection modes
120 
setTitleColor(Qwt3D::RGBA col)121     void setTitleColor(Qwt3D::RGBA col)			{ title_p->setColor(col); }	//!< Set caption color
setTitle(const QString & title)122     void setTitle(const QString& title) {									//!< Set caption text (one row only)
123         if (title.isEmpty() || ((title == TITLE) && (plot_p->titleList().size() > 1)))
124             plot_p->removeTitle(title_p);
125         title_p->setString(title);				// allows title to be reset & removed
126     }
127 
128     void setTitlePosition(double rely, double relx = 0.5, Qwt3D::ANCHOR anchor = Qwt3D::TopCenter);
129     void setTitleFont(const QString& family, int pointSize, int weight = QFont::Normal, bool italic = false);
130 
131     void createData();
132     void createEnrichments();
133 
134 protected:
135     typedef QList<Qwt3D::Enrichment*> EnrichmentList;
136     typedef EnrichmentList::iterator ELIT;
137 
138     Qwt3D::Plot3D*		plot_p;
139     Qwt3D::Label*		title_p;
140     Qwt3D::Data* 		actualData_p;
141 
142     bool				update_displaylists_;
143     Qwt3D::Color*		datacolor_p;
144     Qwt3D::Enrichment*	userplotstyle_p;
145     EnrichmentList		elist_p;
146 
147     Qwt3D::RGBA			meshcolor_;
148     double				meshLineWidth_;
149     Qwt3D::RGBA			bgcolor_;
150     Qwt3D::PLOTSTYLE	plotstyle_;
151     Qwt3D::SHADINGSTYLE shading_;
152     Qwt3D::FLOORSTYLE	floorstyle_;
153     double				polygonOffset_;
154 
155     unsigned int		isolines_;
156     unsigned int		point_size_;
157 
158     bool	datapoints_;
159     bool	facemode_;
160     bool	sidemode_;
161     bool	floormode_;
162     bool	smoothdatamesh_p;
163     bool	datanormals_p;
164     double	normalLength_p;
165     int		normalQuality_p;
166     int		resolution_p;
167 
168     void updateData(bool coord = true);
169     virtual void drawImplementation();
170 
setHull(Qwt3D::ParallelEpiped p)171     void setHull(Qwt3D::ParallelEpiped p) {hull_ = p;}
172     virtual void calculateHull();
173 
174     virtual void createEnrichment(Qwt3D::Enrichment& p);
175     virtual void createFloorData();
176     virtual void createSideData();
177     virtual void createFaceData();
178     void createNormals();
179     void createPoints();
180 
181     void drawVertex(Qwt3D::Triple& vertex, double shift, unsigned int comp = 3);
182     virtual void drawIntersections(std::vector<Qwt3D::Triple>& intersection, double shift, unsigned int comp,
183 								   bool projected, std::vector<RGBA>* colour = 0);
184 
185     void readIn(Qwt3D::GridData& gdata, Qwt3D::Triple** data, unsigned int columns, unsigned int rows);
186     void readIn(Qwt3D::GridData& gdata, double** data, unsigned int columns, unsigned int rows,
187                 double minx, double maxx, double miny, double maxy);
188     void calcNormals(Qwt3D::GridData& gdata);
189     void sewPeriodic(Qwt3D::GridData& gdata);
190 
191     void animateData(double** data);
192     void animateData(Qwt3D::TripleField* data, Qwt3D::CellField* poly);
193     void animateData(Qwt3D::TripleField* data);
194 
195 private:
196 	enum OBJECTS {
197 		DataObject=0,
198 		NormalObject,
199 		DisplayListSize // only to have a vector length ...
200 	};
201 	QVector<GLuint> displaylists_p;
202 
203 	void Data2Floor();
204 	void Isolines2Floor();
205 
206     Qwt3D::ParallelEpiped hull_;
207 
208 	// grid plot
209 	Qwt3D::GridData* actualDataG_;
210 	virtual void createDataG();
211 	virtual void createFaceDataG();
212 	virtual void createSideDataG();
213 	virtual void createFloorDataG();
214 	void createNormalsG();
215 
Data2FloorG()216 	void Data2FloorG()									{ DatamapG(2); }
Data2FrontG()217 	void Data2FrontG()									{ DatamapG(1); }
Data2SideG()218 	void Data2SideG()									{ DatamapG(0); }
219 	void DatamapG(unsigned int comp);
220 
221 	void Isolines2FloorG(bool projected = false)		{ IsolinesG(2, projected); }
222 	void Isolines2FrontG(bool projected = false)		{ IsolinesG(1, projected); }
223 	void Isolines2SideG(bool projected = false)			{ IsolinesG(0, projected); }
224 	void IsolinesG(unsigned int comp, bool projected);
225 
226 	void setColorFromVertexG(int ix, int iy, bool skip = false);
227 
228 	void DataPointsG(unsigned int comp, bool projected);
229 	void DataPoints2SideG(bool projected = false)		{ DataPointsG(0, projected); }
230 	void DataPoints2BackG(bool projected = false)		{ DataPointsG(1, projected); }
231 
232 	// mesh plot
233 	Qwt3D::CellData* actualDataC_;
234 	virtual void createDataC();
235 	virtual void createFaceDataC();
236 	virtual void createSideDataC();
237 	virtual void createFloorDataC();
238 	void createNormalsC();
239 
Data2FloorC()240 	void Data2FloorC()									{ DatamapC(2); }
Data2FrontC()241 	void Data2FrontC()									{ DatamapC(1); }
Data2SideC()242 	void Data2SideC()									{ DatamapC(0); }
243 	void DatamapC(unsigned int comp);
244 
245 	void Isolines2FloorC(bool projected = false)		{ IsolinesC(2, projected); }
246 	void Isolines2FrontC(bool projected = false)		{ IsolinesC(1, projected); }
247 	void Isolines2SideC(bool projected = false)			{ IsolinesC(0, projected); }
248 	void IsolinesC(unsigned int comp, bool projected);
249 
250 	void setColorFromVertexC(int node, bool skip = false);
251 
252 	bool					displaylegend_;
253     Qwt3D::ColorLegend		legend_;
254 };
255 
256 }
257 
258 #endif
259