Skip to content

Commit 1ef0463

Browse files
committed
Merge pull request #1067 from doutriaux1/line_duplicate_points_fix
Line duplicate points fix
2 parents 151cd8b + ea74f00 commit 1ef0463

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

Packages/vcs/Lib/vcs2vtk.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,29 +1181,38 @@ def prepMarker(renWin,marker,cmap=None):
11811181
return actors
11821182

11831183
def prepLine(renWin,line,cmap=None):
1184-
n = prepPrimitive(line)
1185-
if n==0:
1184+
number_lines = prepPrimitive(line)
1185+
1186+
if number_lines == 0:
11861187
return
1188+
11871189
actors = []
1188-
for i in range(n):
1190+
1191+
for i in range(number_lines):
11891192
l = vtk.vtkLine()
11901193
lines = vtk.vtkCellArray()
11911194
x = line.x[i]
1192-
y=line.y[i]
1193-
c=line.color[i]
1194-
w=line.width[i]
1195-
t=line.type[i]
1196-
N = max(len(x),len(y))
1195+
y = line.y[i]
1196+
c = line.color[i]
1197+
w = line.width[i]
1198+
t = line.type[i]
1199+
number_points = max(len(x),len(y))
1200+
1201+
# Extend x or y to the length of the other by duplicating the last coord.
11971202
for a in [x,y]:
1198-
while len(a)<n:
1203+
while len(a)<number_points:
11991204
a.append(a[-1])
1205+
12001206
pts = vtk.vtkPoints()
1201-
for j in range(N):
1207+
1208+
for j in range(number_points):
12021209
pts.InsertNextPoint(x[j],y[j],0.)
1203-
for j in range(N-1):
1210+
1211+
for j in range(number_points - 1):
12041212
l.GetPointIds().SetId(0,j)
12051213
l.GetPointIds().SetId(1,j+1)
12061214
lines.InsertNextCell(l)
1215+
12071216
linesPoly = vtk.vtkPolyData()
12081217
geo,pts=project(pts,line.projection,line.worldcoordinate)
12091218
linesPoly.SetPoints(pts)

testing/vcs/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ add_test(vcs_verify_import
44
"${PYTHON_EXECUTABLE}"
55
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_import.py
66
)
7+
add_test(vcs_line_duplicate_points_fix
8+
"${PYTHON_EXECUTABLE}"
9+
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_line_point_extension.py
10+
)
711
add_test(vcs_mkscale_zero_range
812
"${PYTHON_EXECUTABLE}"
913
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_mkscale_zero_range.py
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import vcs, os, sys
2+
3+
x = vcs.init()
4+
5+
line = x.createline()
6+
line.x = [[0, .1], [.2, .3], [.4, .5], [.6, .7]]
7+
line.y = [[0, .1], [.2, .3, .4], [.5], [.6, .7]]
8+
9+
x.plot(line, bg=1)
10+
11+
if line.x[0] != [0, .1]:
12+
print "line.x[0] should be [0, .1]; is %s" % line.x[0]
13+
sys.exit(-1)
14+
15+
if line.x[1] != [.2, .3, .3]:
16+
print 'line.x[1] should be [.2, .3, .3]; is %s' % line.x[1]
17+
sys.exit(-1)
18+
19+
if line.y[2] != [.5, .5]:
20+
print "line.y[2] should be [.5, .5]; is %s" % line.y[2]
21+
sys.exit(-1)
22+
23+
sys.exit(0)

0 commit comments

Comments
 (0)