Beispiel #1
0
    def __init__(self):
        super().__init__()

        self._annotInstance = vtkAnnotation()
        self._locationKey = keys.MakeKey(keys.IntegerVectorKey, "COORDINATES",
                                         "Annotation")
        self._vtkKey = keys.MakeKey(keys.InformationKey, "ANNOTATION",
                                    "Annotation")

        self.annot_id = uuid.uuid4().hex

        self.Set(self._annotInstance.DATA_TYPE_NAME(), self._dataTypeName)
        self.SetSegmentFlag(False)
        self.reviewed = False
Beispiel #2
0
import vtk
from vtk.util.vtkAlgorithm import VTKPythonAlgorithmBase

from vtk.util import keys

# RequestUpdateExtent

# This pass is where algorithms can make requests for the upstream
# pipeline to fulfill. Its name originates from the first use case for
# this pass: requesting a subset of logical extent from an image
# source (aka update extent). In the current VTK, this pass is used
# for requesting many other things including time steps, partitions
# (pieces), ghost levels etc. Let’s dig into an example. First let’s
# create a request key with the following.

requestKey = keys.MakeKey(keys.IntegerRequestKey, "a request", "my module")

# Then let’s make a request using this key (at the end of the file):

# f.UpdateInformation()
# outInfo = f.GetOutputInformation(0)
# outInfo.Set(requestKey, 0)
# f.PropagateUpdateExtent()


class MySource(VTKPythonAlgorithmBase):
    def __init__(self):
        VTKPythonAlgorithmBase.__init__(self,
                                        nInputPorts=0,
                                        nOutputPorts=1,
                                        outputType='vtkPolyData')
Beispiel #3
0
import os
import math
import collections

from PyQt5.QtCore import QThread, QObject, pyqtSignal

import vtk
import itk
from vtk.util import keys

from segmenttubes import SegmentWorker, SegmentArgs, TubeIterator, GetTubePoints
from models import TubeTreeViewModel, RAW_DATA_ROLE

TUBE_ID_KEY = keys.MakeKey(keys.StringKey, 'tube.id', '')

VTK_ITK_TYPE_CONVERSION = {
    vtk.VTK_UNSIGNED_CHAR:
    itk.UC,
    vtk.VTK_UNSIGNED_INT:
    itk.UI,
    vtk.VTK_UNSIGNED_LONG:
    itk.UL,
    # set this as a signed short for now. The python bindings
    # don't have unsigned short :(
    vtk.VTK_UNSIGNED_SHORT:
    itk.SS,
    vtk.VTK_CHAR:
    itk.SC,
    vtk.VTK_INT:
    itk.SI,
    vtk.VTK_LONG:
Beispiel #4
0
import vtk
from vtk.util.vtkAlgorithm import VTKPythonAlgorithmBase

from vtk.util import keys

metaDataKey = keys.MakeKey(keys.DataObjectMetaDataKey, \
  "a meta-data", "my module")


class MySource(VTKPythonAlgorithmBase):
    def __init__(self):
        VTKPythonAlgorithmBase.__init__(self,
                                        nInputPorts=0,
                                        nOutputPorts=1,
                                        outputType='vtkPolyData')

    def RequestInformation(self, request, inInfo, outInfo):
        print("MySource RequestInformation:")
        outInfo.GetInformationObject(0).Set(metaDataKey, vtk.vtkPolyData())
        print(outInfo.GetInformationObject(0))
        return 1

    def RequestUpdateExtent(self, request, inInfo, outInfo):
        print("MySource RequestUpdateExtent:")
        #        print(outInfo.GetInformationObject(0)
        return 1

    def RequestData(self, request, inInfo, outInfo):
        print("MySource RequestData:")
        #        print(outInfo.GetInformationObject(0)
        return 1
Beispiel #5
0
    # C order.
    array = array.reshape(wdata.GetDimensions()[::-1])
    hdf5_filename = os.path.join(dirname, 'data%d.h5' % xfreq)
    f = h5py.File(hdf5_filename, 'w')
    f.create_dataset("RTData", data=array)


def setup(dirname):
    rt = vtk.vtkRTAnalyticSource()
    for xfreq in range(60, 80):
        rt.SetXFreq(xfreq)
        rt.Update()
        write_file(rt.GetOutput(), xfreq)


metaDataKey = keys.MakeKey(
    keys.DataObjectMetaDataKey, "nastran_poly_data", "my module")
class HDF5Source(VTKPythonAlgorithmBase):
    """
    https://blog.kitware.com/a-vtk-pipeline-primer-part-1/
    https://blog.kitware.com/a-vtk-pipeline-primer-part-2/
    """
    def __init__(self):
        VTKPythonAlgorithmBase.__init__(self,
            nInputPorts=0,
            nOutputPorts=1, outputType='vtkPolyData')
        self.__FileName = ''

    def RequestInformation(self, request, inInfo, outInfo):
        print("MySource RequestInformation:")
        outInfo.GetInformationObject(0).Set(metaDataKey, vtk.vtkPolyData())
        print(outInfo.GetInformationObject(0))
from source import *
import numpy as np
import vtk
from vtk.numpy_interface import dataset_adapter as dsa
from vtk.util.vtkAlgorithm import VTKPythonAlgorithmBase
from vtk.util import keys

TIME_VALUES = keys.MakeKey(keys.DoubleVectorKey, "Time Values", "particle.py")


class ParticleAdvection(VTKPythonAlgorithmBase):
    def __init__(self):
        super(ParticleAdvection,
              self).__init__(nInputPorts=1,
                             inputType='vtkDataSet',
                             nOutputPorts=1,
                             outputType='vtkUnstructuredGrid')
        self.Cache = None
        # Seed for the particles
        self.Source = vtk.vtkLineSource()
        self.Source.SetPoint1(3, 0, 0)
        self.Source.SetPoint2(3, 6, 0)
        self.Source.SetResolution(20)
        self.Source.Update()
        self.NumPts = self.Source.GetOutput().GetNumberOfPoints()
        # We use the probe filter to sample the input
        # field at particle locations.
        self.Probe = vtk.vtkProbeFilter()

        # Create a polydata to represent the particle locations
        # at which we will sample the velocity fields.
Beispiel #7
0
import vtk
from vtk.util import keys

import vtk
from vtk.util import keys

key = keys.MakeKey(keys.ObjectBaseKey, "a new key", "some class")
print("key:\n", key)

info = vtk.vtkInformation()
print("info:\n", info)

key.Set(info, vtk.vtkObject())
# Same as
#info.Set(key, vtk.vtkObject())

print("info after set:\n", info)

# Storing an integer in an information object
key = keys.MakeKey(keys.IntegerKey, "another key", "some class")

key.Set(info, 12)
print(info)

# vtkInformation is not aware of all types, hence the Set belongs to key

# For custom types, you will need to use key.Set(information, value)

info = vtk.vtkInformation()
info.Set(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_PIECE_NUMBER(), 1)
Beispiel #8
0
import vtk
from vtk.util.vtkAlgorithm import VTKPythonAlgorithmBase
from vtk.util import keys

metaDataKey = keys.MakeKey(keys.DataObjectMetaDataKey, "a meta-data", "my module")
requestKey = keys.MakeKey(keys.IntegerRequestKey, "a request", "my module")

class MySource(VTKPythonAlgorithmBase):
    def __init__(self):
        super(MySource, self).__init__(
            nInputPorts=0,
            nOutputPorts=1, outputType='vtkPolyData')

    def RequestInformation(self, request, inInfo, outInfo):
        print("MySource RequestInformation:")
        outInfo.GetInformationObject(0).Set(metaDataKey, vtk.vtkPolyData())
        print(outInfo.GetInformationObject(0))
        return 1

    def RequestUpdateExtent(self, request, inInfo, outInfo):
        print("MySource RequestUpdateExtent:")
        print(outInfo.GetInformationObject(0))
        return 1

    def RequestData(self, request, inInfo, outInfo):
        print("MySource RequestData:")
        outInfo0 = outInfo.GetInformationObject(0)
        areq = outInfo0.Get(requestKey)
        s = vtk.vtkSphereSource()
        s.SetRadius(areq)
        s.Update()