Plot Tubular Paths from xyz

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Plot Tubular Paths from xyz

Justin Clark


Hi all,

Total vtk newbie here trying to figure out a solution in vtk python.  I would like to plot multiple tubular paths defined by a set of (x, y, z) data.  Multiple paths.  I'm trying to plot wellbores. Once the wellbores are plotted I intend to use them as sources and sinks for simulation and streamline purposes.  Any guidance would be helpful!

Using existing examples I believe I need to insert my xyz's into a vtkPoints object. Then interpolate using a spline, and use the spline to define my tube path?

Thanks!
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plot Tubular Paths from xyz

Bill Lorensen
Here is a C++ example:
https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/TubesFromSplines/


On Mon, Aug 7, 2017 at 1:03 PM, Justin Clark <[hidden email]> wrote:

>
>
> Hi all,
>
> Total vtk newbie here trying to figure out a solution in vtk python.  I would like to plot multiple tubular paths defined by a set of (x, y, z) data.  Multiple paths.  I'm trying to plot wellbores. Once the wellbores are plotted I intend to use them as sources and sinks for simulation and streamline purposes.  Any guidance would be helpful!
>
> Using existing examples I believe I need to insert my xyz's into a vtkPoints object. Then interpolate using a spline, and use the spline to define my tube path?
>
> Thanks!
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers



--
Unpaid intern in BillsBasement at noware dot com
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plot Tubular Paths from xyz

Justin Clark
RE: [vtkusers] Plot Tubular Paths from xyz

Sorry, Not a C++ programmer.  I'm confused by multiple parts so far in the code.

double r;

  for (unsigned int i = 0; i < n; ++i)

    {

    double t = (tMax - tMin) / (n - 1) * i + tMin;

    interpolatedRadius->InterpolateTuple(t, &r);

    tubeRadius->SetTuple1(i, r);

    }

What does "&r" mean above?  We instantiate r as a double, but we don't assign it a value. Then we interpolate between t and the memory address of r?

Any help converting this into python?

So far I have...

import vtk

points = vtk.vtkPoints()

points.InsertPoint(0,1,0,0)

points.InsertPoint(1,2,0,0)

points.InsertPoint(2,3,1,0)

points.InsertPoint(3,4,1,0)

points.InsertPoint(4,5,0,0)

points.InsertPoint(5,6,0,0)

spline = vtk.vtkParametricSpline()

spline.SetPoints(points)

functionSource = vtk.vtkParametricFunctionSource()

functionSource.SetParametricFunction(spline)

functionSource.SetUResolution(10*points.GetNumberOfPoints())

functionSource.Update()

interpolatedRadius = vtk.vtkTupleInterpolator()

interpolatedRadius.SetInterpolationTypetoLinear()

interpolatedRadius.SetNumberOfComponents(1)

interpolatedRadius.AddTuple(0,0.2)

interpolatedRadius.AddTuple(0,0.2)

interpolatedRadius.AddTuple(0,0.2)

interpolatedRadius.AddTuple(0,0.1)

interpolatedRadius.AddTuple(0,0.1)

interpolatedRadius.AddTuple(0,0.1)

n = functionSource.GetUresolution()

tubeRadius = vtk.vtkDoubleArray()

tubeRadius.SetNumberOfValues(n)

tmin = interpolatedRadius.GetMinimumT()

tmax = interpolatedRadius.GetMaximumT()

for i in range(n):

    t = ((tmax - tmin)/(n-1))*i + tmin

    interpolatedRadius.InterpolateTuple(t,???)

-----Original Message-----
From: Bill Lorensen [[hidden email]]
Sent: Monday, August 7, 2017 12:05 PM
To: Justin Clark <[hidden email]>
Cc: VTK Users <[hidden email]>
Subject: Re: [vtkusers] Plot Tubular Paths from xyz

Here is a C++ example:

https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/TubesFromSplines/


On Mon, Aug 7, 2017 at 1:03 PM, Justin Clark <[hidden email]> wrote:

>

>

> Hi all,

>

> Total vtk newbie here trying to figure out a solution in vtk python.  I would like to plot multiple tubular paths defined by a set of (x, y, z) data.  Multiple paths.  I'm trying to plot wellbores. Once the wellbores are plotted I intend to use them as sources and sinks for simulation and streamline purposes.  Any guidance would be helpful!

>

> Using existing examples I believe I need to insert my xyz's into a vtkPoints object. Then interpolate using a spline, and use the spline to define my tube path?

>

> Thanks!

> _______________________________________________

> Powered by www.kitware.com

>

> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

>

> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

>

> Search the list archives at: http://markmail.org/search/?q=vtkusers

>

> Follow this link to subscribe/unsubscribe:

> http://public.kitware.com/mailman/listinfo/vtkusers



--

Unpaid intern in BillsBasement at noware dot com


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plot Tubular Paths from xyz

Justin Clark
In reply to this post by Bill Lorensen
Also,

"interpolatedRadius.AddTuple(0,0.2)"  fails in python. The kernel completely crashes. I've tried tuple and list arguments as well. Nothing works.

-----Original Message-----
From: Bill Lorensen [mailto:[hidden email]]
Sent: Monday, August 7, 2017 12:05 PM
To: Justin Clark <[hidden email]>
Cc: VTK Users <[hidden email]>
Subject: Re: [vtkusers] Plot Tubular Paths from xyz

Here is a C++ example:
https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/TubesFromSplines/


On Mon, Aug 7, 2017 at 1:03 PM, Justin Clark <[hidden email]> wrote:

>
>
> Hi all,
>
> Total vtk newbie here trying to figure out a solution in vtk python.  I would like to plot multiple tubular paths defined by a set of (x, y, z) data.  Multiple paths.  I'm trying to plot wellbores. Once the wellbores are plotted I intend to use them as sources and sinks for simulation and streamline purposes.  Any guidance would be helpful!
>
> Using existing examples I believe I need to insert my xyz's into a vtkPoints object. Then interpolate using a spline, and use the spline to define my tube path?
>
> Thanks!
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers



--
Unpaid intern in BillsBasement at noware dot com

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plot Tubular Paths from xyz

Eric
Below is a "TubesFromSpline" example that works with Python 3.6 and VTK 7.

 
import vtk
 
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
iren.SetRenderWindow(renWin)
iren.Initialize()
 
 
points = vtk.vtkPoints()
points.InsertPoint(0, 1, 0, 0)
points.InsertPoint(1, 2, 0, 0)
points.InsertPoint(2, 3, 1, 0)
points.InsertPoint(3, 4, 1, 0)
points.InsertPoint(4, 5, 0, 0)
points.InsertPoint(5, 6, 0, 0)
 
# Fit a spline to the points
spline = vtk.vtkParametricSpline()
spline.SetPoints(points)
functionSource = vtk.vtkParametricFunctionSource()
functionSource.SetParametricFunction(spline)
functionSource.SetUResolution(10 * points.GetNumberOfPoints())
functionSource.Update()
 
# Interpolate the scalars
interpolatedRadius = vtk.vtkTupleInterpolator()
interpolatedRadius.SetInterpolationTypeToLinear()
interpolatedRadius.SetNumberOfComponents(1)
interpolatedRadius.AddTuple(0, [0.2,])
interpolatedRadius.AddTuple(1, (0.2,))
interpolatedRadius.AddTuple(2, (0.2,))
interpolatedRadius.AddTuple(3, (0.1,))
interpolatedRadius.AddTuple(4, (0.1,))
interpolatedRadius.AddTuple(5, (0.1,))
 
# Generate the radius scalars
tubeRadius = vtk.vtkDoubleArray()
n = functionSource.GetOutput().GetNumberOfPoints()
tubeRadius.SetNumberOfTuples(n)
tubeRadius.SetName("TubeRadius")
 
tMin = interpolatedRadius.GetMinimumT()
tMax = interpolatedRadius.GetMaximumT()
for i in range(n):
    t = (tMax - tMin) / (n - 1) * i + tMin
    r = list([1.0])
    interpolatedRadius.InterpolateTuple(t, r)
    tubeRadius.SetTuple1(i, r[0])
 
# Add the scalars to the polydata
tubePolyData = functionSource.GetOutput()
tubePolyData.GetPointData().AddArray(tubeRadius)
tubePolyData.GetPointData().SetActiveScalars("TubeRadius")
 
# Create the tubes
tuber = vtk.vtkTubeFilter()
tuber.SetInputData(tubePolyData)
tuber.SetNumberOfSides(20)
tuber.SetVaryRadiusToVaryRadiusByAbsoluteScalar()
 
# Setup actors and mappers
lineMapper = vtk.vtkPolyDataMapper()
lineMapper.SetInputData(tubePolyData)
lineMapper.SetScalarRange(tubePolyData.GetScalarRange())
 
tubeMapper = vtk.vtkPolyDataMapper()
tubeMapper.SetInputConnection(tuber.GetOutputPort())
tubeMapper.SetScalarRange(tubePolyData.GetScalarRange())
 
lineActor = vtk.vtkActor()
lineActor.SetMapper(lineMapper)
tubeActor = vtk.vtkActor()
tubeActor.SetMapper(tubeMapper)
 
ren.AddActor(tubeActor)
ren.AddActor(lineActor)
 
ren.SetBackground(.4,.5,.6)
renWin.Render()
iren.Start()

Eric

Sent from my iPhone

> On Aug 7, 2017, at 11:22 PM, Justin Clark <[hidden email]> wrote:
>
> Also,
>
> "interpolatedRadius.AddTuple(0,0.2)"  fails in python. The kernel completely crashes. I've tried tuple and list arguments as well. Nothing works.
>
> -----Original Message-----
> From: Bill Lorensen [mailto:[hidden email]]
> Sent: Monday, August 7, 2017 12:05 PM
> To: Justin Clark <[hidden email]>
> Cc: VTK Users <[hidden email]>
> Subject: Re: [vtkusers] Plot Tubular Paths from xyz
>
> Here is a C++ example:
> https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/TubesFromSplines/
>
>
>> On Mon, Aug 7, 2017 at 1:03 PM, Justin Clark <[hidden email]> wrote:
>>
>>
>> Hi all,
>>
>> Total vtk newbie here trying to figure out a solution in vtk python.  I would like to plot multiple tubular paths defined by a set of (x, y, z) data.  Multiple paths.  I'm trying to plot wellbores. Once the wellbores are plotted I intend to use them as sources and sinks for simulation and streamline purposes.  Any guidance would be helpful!
>>
>> Using existing examples I believe I need to insert my xyz's into a vtkPoints object. Then interpolate using a spline, and use the spline to define my tube path?
>>
>> Thanks!
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Loading...