效果图:
核心代码:
qwt3d_rnrichment_std.h下:
1 class QWT3D_EXPORT Line3D: public VertexEnrichment
2
3 {
4 public:
5 Line3D();
6 Line3D(double thick,bool smooth);
7 Qwt3D::Enrichment * clone() const{ return new Line3D(*this);}
8 void configure(double thick, bool smooth); //粗 , 光滑
9 void drawBegin(int type);
10 void drawBegin();
11 void drawEnd();
12 virtual void draw(Qwt3D::Triple const&);
13 virtual void draw();
14 virtual void drawLines();//一条线的长度
15 virtual void add(Qwt3D::Triple const & t);
16 // virtual void setLineColor(RGBA color);
17 virtual void clear()
18 {
19 lineData.clear();
20 myColorMap.clear();
21 }
22 void removeData()
23 {
24 lineData.clear();
25 }
26 virtual void setLineColor(int startIndex,RGBA color);
27 virtual RGBA getColor(int pointIndex);
28 virtual RGBA getColor(double dIntensity);
29 virtual RGBA getRandomColor();
30 virtual int getDataSize(){return lineData.size();}
31 virtual void setLineSize(int nLineSize){m_nLineSize = nLineSize;}//数据的长度
32 public:
33 bool bShowData;
34 virtual void setDataEnable(bool b){bShowData = b;} //不显示数据
35 private:
36 bool smooth_;
37 double lineThick;
38 GLboolean oldstate_;
39 int m_nLineSize;
40 std::vector<</SPAN>Qwt3D::Triple> lineData;
41 // RGBA rgba;
42 std::map<</SPAN>int,RGBA> myColorMap;
43 };
qwt3d_enrichment_std.cpp下:
1 Qwt3D::Line3D::Line3D()
2
3 {
4 m_nLineSize = 0;
5 bShowData = true;
6 }
7 Qwt3D::Line3D::Line3D(double thick,bool smooth)
8 {
9 bShowData = true;
10 lineThick = thick;
11 smooth_ = smooth;
12 // rgba.a = 1;
13 // rgba.b = 0.3;
14 // rgba.r = 0.6;
15 // rgba.g = 1;
16 }
17 void Qwt3D::Line3D::configure(double thick, bool smooth)
18 {
19 lineThick = thick;
20 smooth_ = smooth;
21 }
22 void Qwt3D::Line3D::drawBegin()
23 {
24 setDeviceLineWidth(lineThick);
25 oldstate_ = glIsEnabled(GL_LINE_SMOOTH);
26 if (smooth_)
27 glEnable(GL_LINE_SMOOTH);
28 else
29 glDisable(GL_LINE_SMOOTH);
30 //glPointSize(10);
31 glBegin( GL_LINE_STRIP);
32 }
33 //type: GL_LINE_STRIP GL_LINES GL_POINTS GL_LINE_LOOP
34 void Qwt3D::Line3D::drawBegin(int type)
35 {
36 setDeviceLineWidth(lineThick);
37 oldstate_ = glIsEnabled(GL_LINE_SMOOTH);
38 if (smooth_)
39 glEnable(GL_LINE_SMOOTH);
40 else
41 glDisable(GL_LINE_SMOOTH);
42 //glPointSize(10);
43 glBegin( type);
44 }
45 void Qwt3D::Line3D::drawEnd()
46 {
47 glEnd();
48 if (oldstate_)
49 glEnable(GL_LINE_SMOOTH);
50 else
51 glDisable(GL_LINE_SMOOTH);
52 }
53 void Qwt3D::Line3D::draw(Qwt3D::Triple const& pos)
54 {
55 glVertex3d(pos.x,pos.y,pos.z);
56 }
57 void Qwt3D::Line3D::draw()
58 {
59 for (int i = 0; i <</SPAN> lineData.size(); i ++)
60 {
61 RGBA rgba = getColor(i);
62 glColor4d(rgba.r,rgba.g,rgba.b,rgba.a);
63 draw(lineData[i]);
64 }
65 }
66 void Qwt3D::Line3D::drawLines()//一条线的长度
67 {
68 if(!bShowData)return;
69 drawEnd();//GL_LINES GL_POINTS GL_LINE_LOOP GL_LINE_STRIP
70 drawBegin();
71 long index = 0;//从哪里开始
72 int nSize = lineData.size();
73 while(index <</SPAN> nSize)
74 {
75 // Qwt3D::RGBA rgba(1,1,1,1);
76 // RGBA rgba = getRandomColor();
77 for(int i = 0 ;i <</SPAN> m_nLineSize; i++)
78 {
79 if(i == m_nLineSize-1)
80 {
81 drawEnd();
82 drawBegin(GL_POINTS);//GL_POINTS
83 }
84 if(index <</SPAN> nSize){
85 RGBA rgba = getColor(lineData[index].z);
86 glColor4d(rgba.r,rgba.g,rgba.b,rgba.a);
87 draw(lineData[index]);
88 }
89 index++;
90 }
91 drawEnd();
92 drawBegin();
93 }
94 // qDebug() <<"drawLines end" ;
95 }
96 void Qwt3D::Line3D::add(Qwt3D::Triple const & t)
97 {
98 lineData.push_back(t);
99 }
100 void Qwt3D::Line3D::setLineColor(int startIndex,RGBA color)
101 {
102 myColorMap[startIndex] = color;
103 }
104 Qwt3D::RGBA Qwt3D::Line3D::getColor(int pointIndex)
105 {
106 Qwt3D::RGBA rgba(1,1,1,1);
107 for (std::map<</SPAN>int,RGBA>::iterator it = myColorMap.begin(); it != myColorMap.end(); it ++)
108 {
109 if (it->first <</SPAN> pointIndex)
110 {
111 rgba = it->second;
112 }
113 }
114 return rgba;
115 }
116 //by furui
117 Qwt3D::RGBA Qwt3D::Line3D::getColor(double dIntensity)
118 {
119 double max = 65535 ;
120 double r , g , b ;
121 r = g = b = 0;
122 double radio = dIntensity / max;
123 double v = radio;
124 double a0 = 1;
125 double a1= 0.8;
126 double a2 = 0.4;
127 double a3 = 0.1;
128 double a4 = 0.04;
129 double a5 = 0.004;
130 double a6 = 0;
131 if(radio >= a1)//红-黄
132 {
133 r = 1 ;
134 g = 1-( v - a1 ) * (1 / (a0 - a1)) ;//越来越大
135 b = 0;
136 }else if(radio >= a2)//黄-绿
137 {
138 r = ( v-a2 ) * ( 1 / (a1 - a2)) ;//越来越小
139 g = 1;
140 b = 0;
141 }else if(radio >= a3)//绿-绿蓝
142 {
143 r = 0;
144 g = 1 ;
145 b = 1 -( v-a3 ) * (1 / (a2 - a3)) ;//越来越大
146 }else if(radio >= a4)//绿蓝 - 蓝色
147 {
148 r = 0;
149 g = ( v-a4 ) * (1 / (a3 - a4)) ;//越来越小
150 b = 1;
151 }else if(radio >= a5) //蓝 - 紫
152 {
153 r = 1 - (v - a5) * (1 / (a4 - a5));
154 g = 0;
155 b = 1;
156 }else//紫红
157 {
158 r = 1;
159 g = 0;
160 b = (v - a6) * (1 / (a5 - a6));//越来越小
161 b = b <</SPAN> 0.6 ? 0.6 : b ;
162 }
163 Qwt3D::RGBA rgba(r,g,b,1);
164 return rgba;
165 }
166 //by furui
167 Qwt3D::RGBA Qwt3D::Line3D::getRandomColor()
168 {
169 Qwt3D::RGBA rgba( (double)(qrand()%255) / 255.0f,
170 (double)(qrand()%255) / 255.0f,
171 (double)(qrand()%255) / 255.0f,1);
172 return rgba;
173 }
174 //改变Y坐标轴的正负方向 qwt3d_movements.cpp 下
175 void Plot3D::setScale( double xVal, double yVal, double zVal )
176 {
177 if (xScale_ == xVal && yScale_ == yVal && zScale_ == zVal)
178 return;
179 xScale_ = (xVal <<SPAN style="COLOR: #c0c0c0"> DBL_EPSILON ) ? DBL_EPSILON : xVal;
180 // yScale_ = (yVal <</SPAN> DBL_EPSILON ) ? DBL_EPSILON : yVal;
181 zScale_ = (zVal < DBL_EPSILON ) ? DBL_EPSILON : zVal;
182 //20170206 by furui
183 yScale_ = (yVal && yVal > DBL_EPSILON * -1) ? DBL_EPSILON:yVal;
184 updateGL();
185 emit scaleChanged(xVal, yVal, zVal);
186 }
187
188 //对数据进行赋值
189 void QDockGraph3D::updateData()
190 {
191 if(m_fInterval_S <= 0)return;
192 if(m_pMulti == NULL)return;
193 double x=0 ;
194 double y=0 ;
195 double z=0 ;
196 int nCount = m_pMulti->Size();
197 if(nCount <= 0)return;
198 m_pL3dVertexEnrichment->setLineSize(m_pMulti->First()->Size());
199 for(int i = 0 ; i <</SPAN> nCount ; i++)//多少条线
200 {
201 x += (double)m_fInterval_S / 60.0000f;
202 QSpectraSingle *pSingle = m_pMulti->GetAt(i);
203 int nSize = pSingle->Size();
204 if(nSize <= 0)return;
205 for(int j = 0 ; j <</SPAN> nSize ; j++)
206 {
207 y = pSingle->GetDataX()[j];
208 z = pSingle->GetDataY()[j];
209 //QLine3D m_pL3dVertexEnrichment
210 m_pL3dVertexEnrichment->add(Qwt3D::Triple(x,y,z));
211 }
212 //
213 }
214 m_pL3dSurfacePlot->fitX(x);
215 m_pL3dSurfacePlot->tick();
216 }
217
218 //缩放比例的算法
219 void QLinePlot3D::updateScale()
220 {
221 updateRosenbrock();
222 double dDivX , dDivY , dDivZ , dMax;
223 dMax = 0;
224 dDivX = m_dMaxX - m_dMinX ;
225 dDivY = m_dMaxY - m_dMinY ;
226 dDivZ = m_dMaxZ - m_dMinZ ;
227 if(dMax <<SPAN style="COLOR: #000000">dDivX)dMax = dDivX;
228 if(dMax <<SPAN style="COLOR: #000000">dDivY)dMax = dDivY;
229 if(dMax <<SPAN style="COLOR: #000000">dDivZ)dMax = dDivZ;
230 if(dMax == dDivX && dDivY != 0 && dDivZ != 0)
231 {
232 //x最大
233 m_dScaleX = 1;
234 m_dScaleY = -dDivX / dDivY;
235 m_dScaleZ = dDivX / dDivZ;
236 }
237 else if(dMax == dDivY && dDivX != 0 && dDivZ != 0)
238 {
239 m_dScaleX = dDivY / dDivX;
240 m_dScaleY = -1;
241 m_dScaleZ = dDivY / dDivZ;
242 }
243 else if(dMax == dDivZ&& dDivX != 0 && dDivY != 0)
244 {
245 m_dScaleX = dDivZ / dDivX;
246 m_dScaleY = -dDivZ / dDivY;
247 m_dScaleZ = 1;
248 }
249 else
250 {
251 }
252 setScale(m_dScaleX , m_dScaleY, m_dScaleZ);
253 setZoom(DEFAULT_ZOOM);
254 UpdateLabel();
255 // this->update();
256 }