Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fillarea creates black area #254

Closed
doutriaux1 opened this issue Sep 12, 2017 · 21 comments
Closed

fillarea creates black area #254

doutriaux1 opened this issue Sep 12, 2017 · 21 comments
Assignees
Labels
Milestone

Comments

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Sep 12, 2017

import vcs
x=vcs.init()
o = vcs.createfillarea()
xs = [-70.0, -66.0, -62.0, -58.0, -54.0, -50.0, -46.0, -46.0, -50.0, -54.0, -58.0, -62.0, -66.0, -70.0]
ys = [97.40004179212772, 99.24051369561087, 99.64501380920407, 99.50791666242807, 99.25809764862053, 98.72724999321828, 97.86243057250978, 66.1760279867384, 78.08891693751016, 84.6064443588257, 75.83586128552756, 54.88270839055378, 33.08841943740845, 32.207757042513954]
o.x = xs
o.y = ys
o.worldcoordinate = [-70,-35,30,100]
x.plot(o)

generates:
badfill

@doutriaux1 doutriaux1 added the bug label Sep 12, 2017
@doutriaux1 doutriaux1 added this to the 3.0 milestone Sep 12, 2017
@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Sep 12, 2017

why is there black?

Loading

@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Sep 12, 2017

using a line produce the correct result:
okline

Loading

@durack1
Copy link
Member

@durack1 durack1 commented Sep 12, 2017

@doutriaux1 even though it's wrong, the top image kinda looks like 3D.. Kinda cool

Loading

@jypeter
Copy link
Member

@jypeter jypeter commented Sep 13, 2017

Not much 3D. I have tried to shake my screen to see if the shadow was moving, but no result :p

Loading

@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Oct 9, 2017

@danlipsa @aashish24 any progress on this? I ran into this again last week.

Loading

@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Oct 9, 2017

went back all the way to commit: 3c70e0f bug was here.

At this commit vtk api changed and I can't get a working vtk

Loading

@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Oct 9, 2017

@danlipsa @aashish24 I can reproduce this in pure vtk

import vtk

xs = [-70.0, -66.0, -62.0, -58.0, -54.0, -50.0, -46.0, -46.0, -50.0, -54.0, -58.0, -62.0, -66.0, -70.0]
ys = [97.40004179212772, 99.24051369561087, 99.64501380920407, 99.50791666242807, 99.25809764862053, 98.72724999321828, 97.86243057250978, 66.1760279867384, 78.08891693751016, 84.6064443588257, 75.83586128552756, 54.88270839055378, 33.08841943740845, 32.207757042513954]

N = len(xs)
pts = vtk.vtkPoints()
for i in range(N):
    pts.InsertNextPoint(xs[i],ys[i],0.)

polygon = vtk.vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(N)
for i in range(N):
    polygon.GetPointIds().SetId(i,i)

polygons = vtk.vtkCellArray()
polygons.InsertNextCell(polygon)
polygonPolyData = vtk.vtkPolyData()
polygonPolyData.SetPoints(pts)
polygonPolyData.SetPolys(polygons)

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(polygonPolyData)

actor = vtk.vtkActor()
actor.SetMapper(mapper)

renderer = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()

renWin.AddRenderer(renderer)
renIter = vtk.vtkRenderWindowInteractor()
renIter.SetRenderWindow(renWin)

renderer.AddActor(actor)
renderer.SetBackground(.5,.3,.31)
renWin.Render()
renIter.Start()

Should I submit a bug on VTK site?

Loading

@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Oct 9, 2017

Loading

@danlipsa
Copy link
Contributor

@danlipsa danlipsa commented Oct 10, 2017

@doutriaux1 You cannot fill concave polygons in OpenGL. You'll have to split them in triangles.
https://www.opengl.org/discussion_boards/showthread.php/153256-How-draw-fill-non-convex-polygon-in-OpenGl
Do we need to add this functionality to VCS?

Loading

@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Oct 10, 2017

yes! definitely! I ran into this twice in two weeks now. I'll take a closer look at your post and see if we can "hack" this.

Loading

@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Oct 11, 2017

@danlipsa actually it was easy to make it work:

import vcs
x=vcs.init(bg=True,geometry=(300,300))
f = vcs.createfillarea()
xs = [-70.0, -66.0, -62.0, -58.0, -54.0, -50.0, -46.0, -46.0, -50.0, -54.0, -58.0, -62.0, -66.0, -70.0]
ys = [97.40004179212772, 99.24051369561087, 99.64501380920407, 99.50791666242807, 99.25809764862053, 98.72724999321828, 97.86243057250978, 66.1760279867384, 78.08891693751016, 84.6064443588257, 75.83586128552756, 54.88270839055378, 33.08841943740845, 32.207757042513954]
f.x = xs[::-1]
f.y = ys[::-1]
f.worldcoordinate = [-70,-35,30,100]
x.plot(f)

simply revert the vertices. I'll implement a patch soon. It's clockwise vs counterclockwise issue

Loading

doutriaux1 added a commit that referenced this issue Oct 11, 2017
@danlipsa
Copy link
Contributor

@danlipsa danlipsa commented Oct 11, 2017

@doutriaux1 Great.

Loading

@danlipsa danlipsa closed this Oct 11, 2017
@danlipsa danlipsa reopened this Oct 11, 2017
@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Oct 12, 2017

hum... that wasn't it. It was enough for this example but not enough for my full blown example. @danlipsa any good/fast functions I can use in VTK to triangulate the polygon first?

Loading

@jypeter
Copy link
Member

@jypeter jypeter commented Oct 12, 2017

Loading

@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Oct 12, 2017

@jypeter I will try it, but I would like to avoid making scipy a dependency of vcs.

Loading

@danlipsa
Copy link
Contributor

@danlipsa danlipsa commented Oct 12, 2017

@doutriaux1 Try this:
https://www.vtk.org/doc/nightly/html/classvtkContourTriangulator.html
I don't think Delaunay works as the input is points not a polygon. But VTK has that as well.

Loading

@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Oct 13, 2017

@danlipsa @aashish24 I got a barebone example of what essentially vcs is doing for a fillarea but in pure VTK

Not sure how to use the vtkContoureTraingulate though any hint welcome:

import vtk
pts = vtk.vtkPoints()
polygons = vtk.vtkCellArray()
polygonPolyData = vtk.vtkPolyData()
polygonPolyData.SetPoints(pts)
polygonPolyData.SetPolys(polygons)
colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(4)
colors.SetNumberOfTuples(n)
colors.SetName("Colors")
polygonPolyData.GetCellData().SetScalars(colors)

xs = [0,10,10,5,0,0]
ys = [0,0,6,3,6,0]

x = numpy.array(xs)
x /= x.max()
y = numpy.array(ys)
y /= y.max()
x = x.tolist()
y = y.tolist()

points, polys, pd, color_arr = pts, polygons, polygonPolyData, colors
N = max(len(x), len(y))
polygon = vtk.vtkPolygon()
# Add current polygon
pid = polygon.GetPointIds()
pid.SetNumberOfIds(N)
for j in range(N):
    pid.SetId(j, points.InsertNextPoint(x[j], y[j], 0.))
cellId = polys.InsertNextCell(polygon)
color = [ 255,0,0,255]
color_arr.SetTypedTuple(cellId, color)
polygonPolyData.SetPoints(pts)
tr = vtk.vtkContourTriangulator()
#o = tr.TriangulatePolygon(pid,points,polys.GetCell())
m = vtk.vtkPolyDataMapper()
m.SetInputData(polygonPolyData)
a = vtk.vtkActor()
a.SetMapper(m)
    
renWin = vtk.vtkRenderWindow()
renWin.SetSize(600,600)
ren = vtk.vtkRenderer()
ren.AddActor(a)
renWin.AddRenderer(ren)
i = vtk.vtkRenderWindowInteractor()
renWin.SetInteractor(i)
i.Initialize()
#i.SetRenderWindow(renWin)
renWin.Render()
i.Start()

Loading

@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Jan 24, 2018

@aashish24 @danlipsa @scottwittenburg who at Kitware can take a look?

Loading

@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Feb 21, 2018

@danlipsa you think OpenGL2,.0 will fix this?

Loading

@danlipsa
Copy link
Contributor

@danlipsa danlipsa commented Feb 21, 2018

@doutriaux1 I was just thinking to fix this. I had to do something similar in my other project. It should work with what we have.

Loading

@doutriaux1
Copy link
Contributor Author

@doutriaux1 doutriaux1 commented Feb 21, 2018

That would be fantastic!

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants