Skip to content

Commit 6e7d483

Browse files
committed
GridPlot ignores "nan" points now
1 parent 20c8880 commit 6e7d483

File tree

4 files changed

+98
-66
lines changed

4 files changed

+98
-66
lines changed

include/qwt3d_global.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#define QWT3D_MAJOR_VERSION 0
88
#define QWT3D_MINOR_VERSION 3
9-
#define QWT3D_PATCH_VERSION 0
9+
#define QWT3D_PATCH_VERSION 1
1010

1111
//
1212
// Create Qwt3d DLL if QWT3D_DLL is defined (Windows only)

include/qwt3d_gridplot.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public slots:
3333

3434
protected:
3535
void createOpenGlData(const Plotlet& pl);
36-
void drawEnrichment(const Plotlet& pl, Enrichment& p);
36+
void processVertex(const Triple& vert1, const Triple& norm1, const Plotlet& pl, bool hl, bool& stripStarted);
37+
38+
void drawEnrichment(const Plotlet& pl, Enrichment& p);
3739

3840
int resolution_p;
3941

include/qwt3d_types.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,21 +362,17 @@ inline Triple normalizedcross(Triple const& u, Triple const& v)
362362
{
363363
Triple n;
364364

365-
/* compute the cross product (u x v for right-handed [ccw]) */
366-
n.x = u.y * v.z - u.z * v.y;
367-
n.y = u.z * v.x - u.x * v.z;
368-
n.z = u.x * v.y - u.y * v.x;
369-
370-
/* normalize */
371-
double l = n.length();
372-
if (l)
365+
/* compute the cross product (u x v for right-handed [ccw]) */
366+
n.x = u.y * v.z - u.z * v.y;
367+
n.y = u.z * v.x - u.x * v.z;
368+
n.z = u.x * v.y - u.y * v.x;
369+
370+
/* normalize */
371+
double l = n.length();
372+
if (l > 0)
373373
{
374374
n /= l;
375375
}
376-
else
377-
{
378-
n = Triple(0,0,0);
379-
}
380376

381377
return n;
382378
}

src/qwt3d_gridplot.cpp

Lines changed: 86 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#pragma warning ( disable : 4786 )
44
#endif
55

6+
//#include <QtCore/QElapsedTimer>
7+
//#include <QDebug>
8+
69
#include "qwt3d_gridplot.h"
710
#include "qwt3d_enrichment_std.h"
811

@@ -158,12 +161,16 @@ void GridPlot::readIn(GridData& gdata, double** data, unsigned int columns, unsi
158161

159162
gdata_ij.x = minx + i*dx;
160163
gdata_ij.y = miny + j*dy;
161-
gdata_ij.z = val;
162164

163-
if (val > tmax)
164-
tmax = val;
165-
if (val < tmin)
166-
tmin = val;
165+
gdata_ij.z = val;
166+
167+
if (!_isnan(val))
168+
{
169+
if (val > tmax)
170+
tmax = val;
171+
if (val < tmin)
172+
tmin = val;
173+
}
167174
}
168175
}
169176
ParallelEpiped hull =
@@ -186,60 +193,71 @@ void GridPlot::readIn(GridData& gdata, double** data, unsigned int columns, unsi
186193

187194
void GridPlot::calcNormals(GridData& gdata)
188195
{
196+
//QElapsedTimer timer;
197+
//timer.start();
198+
189199
unsigned int rows = gdata.rows();
190200
unsigned int columns = gdata.columns();
191201

192-
// normals
193-
202+
// normals
194203
Triple u, v, n; // for cross product
195-
Triple vert_ip1j;
196-
Triple vert_ijp1;
197-
Triple vert_im1j;
198-
Triple vert_ijm1;
199204

200-
for (unsigned i = 0; i < columns; ++i)
205+
for (unsigned i = 0; i != columns; ++i)
201206
{
202-
for (unsigned j = 0; j < rows; ++j)
207+
for (unsigned j = 0; j != rows; ++j)
203208
{
204-
Triple& n = gdata.normals[i][j];
205209
n = Triple(0,0,0);
206210

207211
const Triple& vert_ij = gdata.vertices[i][j];
208212

213+
if (_isnan(vert_ij.z))
214+
{
215+
//gdata.normals[i][j] = n;
216+
continue;
217+
}
218+
209219
if (i<columns-1 && j<rows-1)
210220
{
211-
vert_ip1j = gdata.vertices[i+1][j] - vert_ij;
212-
vert_ijp1 = gdata.vertices[i][j+1] - vert_ij;
213-
n += normalizedcross(vert_ip1j, vert_ijp1); // right hand system here !
221+
/* get two vectors to cross */
222+
u = gdata.vertices[i+1][j] - vert_ij;
223+
v = gdata.vertices[i][j+1] - vert_ij;
224+
/* get the normalized cross product */
225+
n += normalizedcross(u,v); // right hand system here !
214226
}
215227

216-
if (i>0 && j>0)
228+
if (i>0 && j<rows-1)
217229
{
218-
vert_im1j = gdata.vertices[i-1][j] - vert_ij;
219-
vert_ijm1 = gdata.vertices[i][j-1] - vert_ij;
220-
n += normalizedcross(vert_im1j, vert_ijm1);
230+
u = gdata.vertices[i][j+1] - vert_ij;
231+
v = gdata.vertices[i-1][j] - vert_ij;
232+
n += normalizedcross(u,v);
221233
}
222234

223-
if (i>0 && j<rows-1)
235+
if (i>0 && j>0)
224236
{
225-
n += normalizedcross(vert_ijp1, vert_im1j);
237+
u = gdata.vertices[i-1][j] - vert_ij;
238+
v = gdata.vertices[i][j-1] - vert_ij;
239+
n += normalizedcross(u,v);
226240
}
227241

228242
if (i<columns-1 && j>0)
229243
{
230-
n += normalizedcross(vert_ijm1, vert_ip1j);
244+
u = gdata.vertices[i][j-1] - vert_ij;
245+
v = gdata.vertices[i+1][j] - vert_ij;
246+
n += normalizedcross(u,v);
231247
}
232-
233248
n.normalize();
249+
250+
gdata.normals[i][j] = n;
234251
}
235252
}
253+
254+
//qDebug() << "GridPlot::calcNormals(): " << timer.elapsed();
236255
}
237256

238257

239258
void GridPlot::sewPeriodic(GridData& gdata)
240259
{
241260
// sewing
242-
243261
Triple n;
244262

245263
unsigned int columns = gdata.columns();
@@ -486,8 +504,8 @@ void GridPlot::createOpenGlData(const Plotlet& pl)
486504
GLStateBewarer sb2(GL_LINE_SMOOTH, app.smoothDataMesh());
487505
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
488506

489-
int lastcol = data.columns();
490-
int lastrow = data.rows();
507+
int lastcol = data.columns();
508+
int lastrow = data.rows();
491509

492510
if (app.plotStyle() != WIREFRAME)
493511
{
@@ -502,40 +520,29 @@ void GridPlot::createOpenGlData(const Plotlet& pl)
502520

503521
for (i = 0; i < lastcol - step; i += step)
504522
{
505-
glBegin(GL_TRIANGLE_STRIP);
523+
bool stripStarted = false;
506524

507525
const Triple& norm1 = data.normals[i][0];
508526
const Triple& vert1 = data.vertices[i][0];
509-
510-
setColorFromVertex(pl, vert1, hl);
511-
glNormal3d(norm1.x, norm1.y, norm1.z);
512-
glVertex3d(vert1.x, vert1.y, vert1.z);
527+
processVertex(vert1, norm1, pl, hl, stripStarted);
513528

514529
const Triple& norm2 = data.normals[i+step][0];
515530
const Triple& vert2 = data.vertices[i+step][0];
516-
517-
setColorFromVertex(pl, vert2, hl);
518-
glNormal3d(norm2.x, norm2.y, norm2.z);
519-
glVertex3d(vert2.x, vert2.y, vert2.z);
531+
processVertex(vert2, norm2, pl, hl, stripStarted);
520532

521533
for (j = 0; j < lastrow - step; j += step)
522534
{
523535
const Triple& norm1 = data.normals[i][j+step];
524536
const Triple& vert1 = data.vertices[i][j+step];
525-
526-
setColorFromVertex(pl, vert1, hl);
527-
glNormal3d(norm1.x, norm1.y, norm1.z);
528-
glVertex3d(vert1.x, vert1.y, vert1.z);
537+
processVertex(vert1, norm1, pl, hl, stripStarted);
529538

530539
const Triple& norm2 = data.normals[i+step][j+step];
531540
const Triple& vert2 = data.vertices[i+step][j+step];
532-
533-
setColorFromVertex(pl, vert2, hl);
534-
glNormal3d(norm2.x, norm2.y, norm2.z);
535-
glVertex3d(vert2.x, vert2.y, vert2.z);
541+
processVertex(vert2, norm2, pl, hl, stripStarted);
536542
}
537543

538-
glEnd();
544+
if (stripStarted)
545+
glEnd();
539546
}
540547
}
541548

@@ -550,25 +557,29 @@ void GridPlot::createOpenGlData(const Plotlet& pl)
550557
for (i = 0; i < data.columns() - step; i += step)
551558
{
552559
const Triple& vert1 = data.vertices[i][0];
553-
glVertex3d(vert1.x, vert1.y, vert1.z);
560+
if (!_isnan(vert1.z))
561+
glVertex3d(vert1.x, vert1.y, vert1.z);
554562
}
555563

556564
for (j = 0; j < data.rows() - step; j += step)
557565
{
558566
const Triple& vert1 = data.vertices[i][j];
559-
glVertex3d(vert1.x, vert1.y, vert1.z);
567+
if (!_isnan(vert1.z))
568+
glVertex3d(vert1.x, vert1.y, vert1.z);
560569
}
561570

562571
for (; i >= 0; i -= step)
563572
{
564573
const Triple& vert1 = data.vertices[i][j];
565-
glVertex3d(vert1.x, vert1.y, vert1.z);
574+
if (!_isnan(vert1.z))
575+
glVertex3d(vert1.x, vert1.y, vert1.z);
566576
}
567577

568578
for (; j >= 0; j -= step)
569579
{
570580
const Triple& vert1 = data.vertices[0][j];
571-
glVertex3d(vert1.x, vert1.y, vert1.z);
581+
if (!_isnan(vert1.z))
582+
glVertex3d(vert1.x, vert1.y, vert1.z);
572583
}
573584

574585
glEnd();
@@ -581,7 +592,8 @@ void GridPlot::createOpenGlData(const Plotlet& pl)
581592
for (j = 0; j < data.rows(); j += step)
582593
{
583594
const Triple& vert1 = data.vertices[i][j];
584-
glVertex3d(vert1.x, vert1.y, vert1.z);
595+
if (!_isnan(vert1.z))
596+
glVertex3d(vert1.x, vert1.y, vert1.z);
585597
}
586598
glEnd();
587599
}
@@ -592,13 +604,35 @@ void GridPlot::createOpenGlData(const Plotlet& pl)
592604
for (i = 0; i < data.columns(); i += step)
593605
{
594606
const Triple& vert1 = data.vertices[i][j];
595-
glVertex3d(vert1.x, vert1.y, vert1.z);
607+
if (!_isnan(vert1.z))
608+
glVertex3d(vert1.x, vert1.y, vert1.z);
596609
}
597610
glEnd();
598611
}
599612
}
600613
}
601614

615+
void GridPlot::processVertex(const Triple& vert1, const Triple& norm1, const Plotlet& pl, bool hl, bool& stripStarted)
616+
{
617+
if (_isnan(vert1.z))
618+
{
619+
if (stripStarted){
620+
stripStarted = false;
621+
glEnd();
622+
}
623+
}
624+
else{
625+
if (!stripStarted){
626+
stripStarted = true;
627+
glBegin(GL_TRIANGLE_STRIP);
628+
}
629+
630+
setColorFromVertex(pl, vert1, hl);
631+
glNormal3d(norm1.x, norm1.y, norm1.z);
632+
glVertex3d(vert1.x, vert1.y, vert1.z);
633+
}
634+
}
635+
602636
void GridPlot::drawEnrichment(const Plotlet& pl, Enrichment& p)
603637
{
604638
switch(p.type())

0 commit comments

Comments
 (0)