예제 #1
0
def vtkVariantStrictEquality(s1, s2):
    """
    Check two variants for strict equality of type and value.
    """
    s1 = vtk.vtkVariant(s1)
    s2 = vtk.vtkVariant(s2)

    t1 = s1.GetType()
    t2 = s2.GetType()

    # check based on type
    if t1 != t2:
        return False

    v1 = s1.IsValid()
    v2 = s2.IsValid()

    # check based on validity
    if (not v1) and (not v2):
        return True
    elif v1 != v2:
        return False

    # extract and compare the values
    r1 = getattr(s1, _variant_method_map[t1])()
    r2 = getattr(s2, _variant_method_map[t2])()

    return (r1 == r2)
예제 #2
0
def vtkVariantStrictWeakOrder(s1, s2):
    """
    Compare variants by type first, and then by value.  The return values
    are -1, 0, 1 like the python cmp() method, for compatibility with the
    python list sort() method.  This is in contrast with the C++ version,
    which returns true or false.
    """
    s1 = vtkVariant(s1)
    s2 = vtkVariant(s2)

    t1 = s1.GetType()
    t2 = s2.GetType()

    # check based on type
    if t1 != t2:
        return cmp(t1, t2)

    v1 = s1.IsValid()
    v2 = s2.IsValid()

    # check based on validity
    if (not v1) and (not v2):
        return 0
    elif v1 != v2:
        return cmp(v1, v2)

    # extract and compare the values
    r1 = getattr(s1, _variant_method_map[t1])()
    r2 = getattr(s2, _variant_method_map[t2])()

    # compare vtk objects by classname
    if t1 == vtk.VTK_OBJECT:
        return cmp(r1.GetClassName(), r2.GetClassName())

    return cmp(r1, r2)
예제 #3
0
def main():
    # Use the specified filename
    output_filename = get_program_parameters()

    # Construct an empty table
    table = vtk.vtkTable()

    for i in range(0, 3):
        col = vtk.vtkVariantArray()
        col_name = "column-" + str(i)
        col.SetName(col_name)

        col.InsertNextValue(vtk.vtkVariant(0.0))
        col.InsertNextValue(vtk.vtkVariant(0.0))
        col.InsertNextValue(vtk.vtkVariant(0.0))
        table.AddColumn(col)

    # Fill the table with values
    counter = 0
    for r in range(0, table.GetNumberOfRows()):
        for c in range(table.GetNumberOfColumns()):
            table.SetValue(r, c, vtk.vtkVariant(counter))
            counter += 1

    writer = vtk.vtkDelimitedTextWriter()
    writer.SetFileName(output_filename)
    writer.SetInputData(table)
    writer.Write()
예제 #4
0
def vtkVariantStrictWeakOrder(s1, s2):
    """
    Compare variants by type first, and then by value.  The return values
    are -1, 0, 1 like the python cmp() method, for compatibility with the
    python list sort() method.  This is in contrast with the C++ version,
    which returns true or false.
    """
    s1 = vtkVariant(s1)
    s2 = vtkVariant(s2)

    t1 = s1.GetType()
    t2 = s2.GetType()

    # check based on type
    if t1 != t2:
        return cmp(t1,t2)

    v1 = s1.IsValid()
    v2 = s2.IsValid()

    # check based on validity
    if (not v1) and (not v2):
        return 0
    elif v1 != v2:
        return cmp(v1,v2)

    # extract and compare the values
    r1 = getattr(s1, _variant_method_map[t1])()
    r2 = getattr(s2, _variant_method_map[t2])()

    # compare vtk objects by classname
    if t1 == vtk.VTK_OBJECT:
        return cmp(r1.GetClassName(), r2.GetClassName())

    return cmp(r1, r2)
예제 #5
0
def vtkVariantStrictEquality(s1, s2):
    """
    Check two variants for strict equality of type and value.
    """
    s1 = vtk.vtkVariant(s1)
    s2 = vtk.vtkVariant(s2)

    t1 = s1.GetType()
    t2 = s2.GetType()

    # check based on type
    if t1 != t2:
        return False

    v1 = s1.IsValid()
    v2 = s2.IsValid()

    # check based on validity
    if (not v1) and (not v2):
        return True
    elif v1 != v2:
        return False

    # extract and compare the values
    r1 = getattr(s1, _variant_method_map[t1])()
    r2 = getattr(s2, _variant_method_map[t2])()

    return (r1 == r2)
예제 #6
0
 def testBoolPointer(self):
     v = vtk.vtkVariant("1")
     bp = [False]
     d = v.ToFloat(bp)
     self.assertEqual(bp, [True])
     v = vtk.vtkVariant("George")
     d = v.ToFloat(bp)
     self.assertEqual(bp, [False])
예제 #7
0
 def testStrictWeakOrder(self):
     """Use vtkVariantStrictWeakOrder to sort a list of vtkVariants"""
     if not unicode_support:
         return
     l = map(vtk.vtkVariant, [1, 2.5, vtk.vtkVariant(), "0", u'hello'])
     s = map(vtk.vtkVariant, [vtk.vtkVariant(), 1, 2.5, "0", u'hello'])
     l.sort(vtk.vtkVariantStrictWeakOrder)
     self.assertEqual(l, s)
예제 #8
0
 def testCompare(self):
     """Use comparison operators to sort a list of vtkVariants"""
     if not unicode_support:
         return
     l = map(vtk.vtkVariant, [1, 2.5, vtk.vtkVariant(), "0", u'hello'])
     s = map(vtk.vtkVariant, [vtk.vtkVariant(), "0", 1, 2.5, u'hello'])
     l.sort()
     self.assertEqual(l, s)
예제 #9
0
파일: TestVariant.py 프로젝트: 0004c/VTK
 def testCompare(self):
     """Use comparison operators to sort a list of vtkVariants"""
     if not unicode_support:
         return
     l = map(vtk.vtkVariant, [1, 2.5, vtk.vtkVariant(), "0", u'hello'])
     s = map(vtk.vtkVariant, [vtk.vtkVariant(), "0", 1, 2.5, u'hello'])
     l.sort()
     self.assertEqual(l, s)
예제 #10
0
파일: TestVariant.py 프로젝트: ALouis38/VTK
 def testStrictWeakOrder(self):
     """Use vtkVariantStrictWeakOrder to sort a list of vtkVariants"""
     original = [1, 2.5, vtk.vtkVariant(), "0", cedilla]
     ordered = [vtk.vtkVariant(), 1, 2.5, "0", cedilla]
     l = [vtk.vtkVariant(x) for x in original]
     s = [vtk.vtkVariant(x) for x in ordered]
     l.sort(key=vtk.vtkVariantStrictWeakOrderKey)
     self.assertEqual(l, s)
예제 #11
0
파일: TestVariant.py 프로젝트: 0004c/VTK
 def testStrictWeakOrder(self):
     """Use vtkVariantStrictWeakOrder to sort a list of vtkVariants"""
     if not unicode_support:
         return
     l = map(vtk.vtkVariant, [1, 2.5, vtk.vtkVariant(), "0", u'hello'])
     s = map(vtk.vtkVariant, [vtk.vtkVariant(), 1, 2.5, "0", u'hello'])
     l.sort(vtk.vtkVariantStrictWeakOrder)
     self.assertEqual(l, s)
예제 #12
0
파일: TestVariant.py 프로젝트: ALouis38/VTK
 def testCompare(self):
     """Use comparison operators to sort a list of vtkVariants"""
     original = [1, 2.5, vtk.vtkVariant(), "0", cedilla]
     ordered = [vtk.vtkVariant(), "0", 1, 2.5, cedilla]
     l = [vtk.vtkVariant(x) for x in original]
     s = [vtk.vtkVariant(x) for x in ordered]
     l.sort()
     self.assertEqual(l, s)
예제 #13
0
 def testStrictWeakOrder(self):
     """Use vtkVariantStrictWeakOrder to sort a list of vtkVariants"""
     original = [1, 2.5, vtk.vtkVariant(), "0", cedilla]
     ordered = [vtk.vtkVariant(), 1, 2.5, "0", cedilla]
     l = [vtk.vtkVariant(x) for x in original]
     s = [vtk.vtkVariant(x) for x in ordered]
     l.sort(key=vtk.vtkVariantStrictWeakOrderKey)
     self.assertEqual(l, s)
예제 #14
0
 def testBoolPointer(self):
     v = vtk.vtkVariant("1")
     bp = [False]
     d = v.ToFloat(bp)
     self.assertEqual(bp, [True])
     v = vtk.vtkVariant("George")
     d = v.ToFloat(bp)
     self.assertEqual(bp, [False])
예제 #15
0
 def testCompare(self):
     """Use comparison operators to sort a list of vtkVariants"""
     original = [1, 2.5, vtk.vtkVariant(), "0", cedilla]
     ordered = [vtk.vtkVariant(), "0", 1, 2.5, cedilla]
     l = [vtk.vtkVariant(x) for x in original]
     s = [vtk.vtkVariant(x) for x in ordered]
     l.sort()
     self.assertEqual(l, s)
예제 #16
0
파일: TestVariant.py 프로젝트: kass1/VTK
 def testStrictWeakOrder(self):
     """Use vtkVariantStrictWeakOrder to sort a list of vtkVariants"""
     if sys.hexversion > 0x03000000:
         """sort() doesn't take comparator in py3k"""
         return
     original = [1, 2.5, vtk.vtkVariant(), "0", cedilla]
     ordered = [vtk.vtkVariant(), 1, 2.5, "0", cedilla]
     l = [vtk.vtkVariant(x) for x in original]
     s = [vtk.vtkVariant(x) for x in ordered]
     l.sort(vtk.vtkVariantStrictWeakOrder)
     self.assertEqual(l, s)
예제 #17
0
    def Execute(self, obj, event):
        del obj, event
        interactor = self.Viewer.GetRenderWindow().GetInteractor()
        renderer = self.Viewer.GetRenderer()
        actor = self.Viewer.GetImageActor()
        image = self.Viewer.GetInput()
        style = interactor.GetInteractorStyle()
        self.Picker.Pick(interactor.GetEventPosition()[0],
                         interactor.GetEventPosition()[1], 0.0, renderer)
        path = self.Picker.GetPath()  # Get iterator
        validPick = False
        if path is not None:
            # TODO: Use pythonic iteration, need to get iterator for vtkAssemblePath
            path.InitTraversal()
            for i in range(path.GetNumberOfItems()):
                node = path.GetNextNode()
                if actor == node.GetViewProp():
                    validPick = True
                    break
        if not validPick:
            self.Annotation.SetText(0, "Off Image")
            interactor.Render()
            style.OnMouseMove()
            return
        pos = self.Picker.GetPickPosition()
        axis = self.Viewer.GetSliceOrientation()
        image_coordinates = [0, 0, 0]
        if axis == vtk.vtkImageViewer2.SLICE_ORIENTATION_XZ:
            image_coordinates[0] = int(vtk.vtkMath.Round(pos[0]))
            image_coordinates[1] = int(self.Viewer.GetSlice())
            image_coordinates[2] = int(vtk.vtkMath.Round(pos[2]))
        elif axis == vtk.vtkImageViewer2.SLICE_ORIENTATION_YZ:
            image_coordinates[0] = int(self.Viewer.GetSlice())
            image_coordinates[1] = int(vtk.vtkMath.Round(pos[0]))
            image_coordinates[2] = int(vtk.vtkMath.Round(pos[1]))
        else:
            image_coordinates[0] = int(vtk.vtkMath.Round(pos[0]))
            image_coordinates[1] = int(vtk.vtkMath.Round(pos[1]))
            image_coordinates[2] = int(self.Viewer.GetSlice())
        message = "Location: ( "
        message = message + vtk.vtkVariant(image_coordinates[0]).ToString()
        message = message + ", "
        message = message + vtk.vtkVariant(image_coordinates[1]).ToString()
        message = message + ", "
        message = message + vtk.vtkVariant(image_coordinates[2]).ToString()
        message = message + " )\nValue: ( "

        # We convert everything to float
        message = valueMessage(image, image_coordinates, message)

        self.Annotation.SetText(0, message)
        interactor.Render()
        style.OnMouseMove()
예제 #18
0
 def testComparisonMethods(self):
     v1 = vtk.vtkVariant(10)
     v2 = vtk.vtkVariant("10")
     # compare without regards to type
     self.assertEqual(vtk.vtkVariantEqual(v1, v2), True)
     self.assertEqual(vtk.vtkVariantLessThan(v1, v2), False)
     # compare with different types being non-equivalent
     self.assertEqual(vtk.vtkVariantStrictEquality(v1, v2), False)
     if sys.hexversion >= 0x03000000:
         self.assertEqual(vtk.vtkVariantStrictWeakOrder(v1, v2), True)
     else:
         # for Python 2, it worked like the cmp() function
         self.assertEqual(vtk.vtkVariantStrictWeakOrder(v1, v2), -1)
예제 #19
0
파일: TestVariant.py 프로젝트: ALouis38/VTK
 def testComparisonMethods(self):
     v1 = vtk.vtkVariant(10)
     v2 = vtk.vtkVariant("10")
     # compare without regards to type
     self.assertEqual(vtk.vtkVariantEqual(v1, v2), True)
     self.assertEqual(vtk.vtkVariantLessThan(v1, v2), False)
     # compare with different types being non-equivalent
     self.assertEqual(vtk.vtkVariantStrictEquality(v1, v2), False)
     if sys.hexversion >= 0x03000000:
         self.assertEqual(vtk.vtkVariantStrictWeakOrder(v1, v2), True)
     else:
         # for Python 2, it worked like the cmp() function
         self.assertEqual(vtk.vtkVariantStrictWeakOrder(v1, v2), -1)
예제 #20
0
 def testConstructors(self):
     """Test overloaded constructors"""
     # resolve by number of arguments
     v = vtk.vtkVector3d(3, 4, 5)
     self.assertEqual((v[0], v[1], v[2]), (3, 4, 5))
     v = vtk.vtkVector3d(6)
     self.assertEqual((v[0], v[1], v[2]), (6, 6, 6))
     # resolve by argument type
     v = vtk.vtkVariant(3.0)
     self.assertEqual(v.GetType(), vtk.VTK_DOUBLE)
     v = vtk.vtkVariant(1)
     self.assertEqual(v.GetType(), vtk.VTK_INT)
     v = vtk.vtkVariant("hello")
     self.assertEqual(v.GetType(), vtk.VTK_STRING)
     v = vtk.vtkVariant(vtk.vtkObject())
     self.assertEqual(v.GetType(), vtk.VTK_OBJECT)
예제 #21
0
 def testConstructors(self):
     """Test overloaded constructors"""
     # resolve by number of arguments
     v = vtk.vtkVector3d(3, 4, 5)
     self.assertEqual((v[0], v[1], v[2]), (3, 4, 5))
     v = vtk.vtkVector3d(6)
     self.assertEqual((v[0], v[1], v[2]), (6, 6, 6))
     # resolve by argument type
     v = vtk.vtkVariant(3.0)
     self.assertEqual(v.GetType(), vtk.VTK_DOUBLE)
     v = vtk.vtkVariant(1)
     self.assertEqual(v.GetType(), vtk.VTK_INT)
     v = vtk.vtkVariant("hello")
     self.assertEqual(v.GetType(), vtk.VTK_STRING)
     v = vtk.vtkVariant(vtk.vtkObject())
     self.assertEqual(v.GetType(), vtk.VTK_OBJECT)
예제 #22
0
 def testObjectConstructor(self):
     """Construct from VTK object"""
     o = vtk.vtkIntArray()
     v = vtk.vtkVariant(o)
     self.assertEqual(v.GetType(), vtk.VTK_OBJECT)
     self.assertEqual(v.GetTypeAsString(), o.GetClassName())
     self.assertEqual(v.ToVTKObject(), o)
예제 #23
0
파일: TestVariant.py 프로젝트: 0004c/VTK
 def testObjectConstructor(self):
     """Construct from VTK object"""
     o = vtk.vtkIntArray()
     v = vtk.vtkVariant(o)
     self.assertEqual(v.GetType(), vtk.VTK_OBJECT)
     self.assertEqual(v.GetTypeAsString(), o.GetClassName())
     self.assertEqual(v.ToVTKObject(), o)
예제 #24
0
def vtkVariantStrictWeakOrder(s1, s2):
    """
    Compare variants by type first, and then by value.  When called from
    within a Python 2 interpreter, the return values are -1, 0, 1 like the
    cmp() method, for compatibility with the Python 2 list sort() method.
    This is in contrast with the Python 3 version of this method (and the
    VTK C++ version), which return true or false.
    """
    s1 = vtk.vtkVariant(s1)
    s2 = vtk.vtkVariant(s2)

    t1 = s1.GetType()
    t2 = s2.GetType()

    # define a cmp(x, y) for Python 3 that returns (x < y)
    def vcmp(x, y):
        if sys.hexversion >= 0x03000000:
            return (x < y)
        else:
            return cmp(x, y)

    # check based on type
    if t1 != t2:
        return vcmp(t1, t2)

    v1 = s1.IsValid()
    v2 = s2.IsValid()

    # check based on validity
    if (not v1) or (not v2):
        return vcmp(v1, v2)

    # extract and compare the values
    r1 = getattr(s1, _variant_method_map[t1])()
    r2 = getattr(s2, _variant_method_map[t2])()

    # compare vtk objects by classname, then address
    if t1 == vtk.VTK_OBJECT:
        c1 = r1.GetClassName()
        c2 = r2.GetClassName()
        if c1 != c2:
            return vcmp(c1, c2)
        else:
            return vcmp(r1.__this__, r2.__this__)

    return vcmp(r1, r2)
예제 #25
0
def vtkVariantStrictWeakOrder(s1, s2):
    """
    Compare variants by type first, and then by value.  When called from
    within a Python 2 interpreter, the return values are -1, 0, 1 like the
    cmp() method, for compatibility with the Python 2 list sort() method.
    This is in contrast with the Python 3 version of this method (and the
    VTK C++ version), which return true or false.
    """
    s1 = vtk.vtkVariant(s1)
    s2 = vtk.vtkVariant(s2)

    t1 = s1.GetType()
    t2 = s2.GetType()

    # define a cmp(x, y) for Python 3 that returns (x < y)
    def vcmp(x, y):
        if sys.hexversion >= 0x03000000:
            return (x < y)
        else:
            return cmp(x,y)

    # check based on type
    if t1 != t2:
        return vcmp(t1,t2)

    v1 = s1.IsValid()
    v2 = s2.IsValid()

    # check based on validity
    if (not v1) or (not v2):
        return vcmp(v1,v2)

    # extract and compare the values
    r1 = getattr(s1, _variant_method_map[t1])()
    r2 = getattr(s2, _variant_method_map[t2])()

    # compare vtk objects by classname, then address
    if t1 == vtk.VTK_OBJECT:
        c1 = r1.GetClassName()
        c2 = r2.GetClassName()
        if c1 != c2:
            return vcmp(c1,c2)
        else:
            return vcmp(r1.__this__,r2.__this__)

    return vcmp(r1, r2)
예제 #26
0
 def testPassByValueReturnByReference(self):
     """Pass vtkVariant by value, return by reference"""
     a = vtk.vtkVariantArray()
     a.SetNumberOfValues(1)
     v = vtk.vtkVariant(1)
     a.SetValue(0, v)
     u = a.GetValue(0)
     self.assertEqual(u.ToInt(), v.ToInt())
     self.assertEqual(u.GetType(), v.GetType())
     self.assertEqual(u.IsValid(), v.IsValid())
예제 #27
0
파일: TestVariant.py 프로젝트: 0004c/VTK
 def testPassByReferenceReturnByValue(self):
     """Pass vtkVariant by reference, return by value."""
     a = vtk.vtkArray.CreateArray(1, vtk.VTK_INT)
     a.Resize(1,1)
     v = vtk.vtkVariant(1)
     a.SetVariantValue(0, 0, v)
     u = a.GetVariantValue(0, 0)
     self.assertEqual(u.ToInt(), v.ToInt())
     self.assertEqual(u.GetType(), v.GetType())
     self.assertEqual(u.IsValid(), v.IsValid())
예제 #28
0
파일: TestVariant.py 프로젝트: 0004c/VTK
 def testPassByValueReturnByReference(self):
     """Pass vtkVariant by value, return by reference"""
     a = vtk.vtkVariantArray()
     a.SetNumberOfValues(1)
     v = vtk.vtkVariant(1)
     a.SetValue(0, v)
     u = a.GetValue(0)
     self.assertEqual(u.ToInt(), v.ToInt())
     self.assertEqual(u.GetType(), v.GetType())
     self.assertEqual(u.IsValid(), v.IsValid())
예제 #29
0
 def testPassByReferenceReturnByValue(self):
     """Pass vtkVariant by reference, return by value."""
     a = vtk.vtkArray.CreateArray(1, vtk.VTK_INT)
     a.Resize(1, 1)
     v = vtk.vtkVariant(1)
     a.SetVariantValue(0, 0, v)
     u = a.GetVariantValue(0, 0)
     self.assertEqual(u.ToInt(), v.ToInt())
     self.assertEqual(u.GetType(), v.GetType())
     self.assertEqual(u.IsValid(), v.IsValid())
예제 #30
0
def vtkVariantCreate(v, t):
    """
    Create a vtkVariant of the specified type, where the type is in the
    following format: 'int', 'unsigned int', etc. for numeric types,
    and 'string' or 'unicode string' for strings.  You can also use an
    integer VTK type constant for the type.
    """
    if not issubclass(type(t), int):
        t = _variant_type_map[t]

    return vtk.vtkVariant(v, t)
예제 #31
0
def vtkVariantCreate(v, t):
    """
    Create a vtkVariant of the specified type, where the type is in the
    following format: 'int', 'unsigned int', etc. for numeric types,
    and 'string' or 'unicode string' for strings.  You can also use an
    integer VTK type constant for the type.
    """
    if not issubclass(type(t), int):
        t = _variant_type_map[t]

    return vtk.vtkVariant(v, t)
예제 #32
0
 def testArgumentConversion(self):
     """Test argument conversion via implicit constructors"""
     # automatic conversion to vtkVariant
     a = vtk.vtkVariantArray()
     a.InsertNextValue(2.5)
     a.InsertNextValue(vtk.vtkObject())
     self.assertEqual(a.GetValue(0), vtk.vtkVariant(2.5))
     self.assertEqual(a.GetValue(1).GetType(), vtk.VTK_OBJECT)
     # same, but this one is via "const vtkVariant&" argument
     a = vtk.vtkDenseArray[float]()
     a.Resize(1)
     a.SetVariantValue(0, 2.5)
     self.assertEqual(a.GetVariantValue(0).ToDouble(), 2.5)
예제 #33
0
 def testArgumentConversion(self):
     """Test argument conversion via implicit constructors"""
     # automatic conversion to vtkVariant
     a = vtk.vtkVariantArray()
     a.InsertNextValue(2.5)
     a.InsertNextValue(vtk.vtkObject())
     self.assertEqual(a.GetValue(0), vtk.vtkVariant(2.5))
     self.assertEqual(a.GetValue(1).GetType(), vtk.VTK_OBJECT)
     # same, but this one is via "const vtkVariant&" argument
     a = vtk.vtkDenseArray[float]()
     a.Resize(1)
     a.SetVariantValue(0, 2.5)
     self.assertEqual(a.GetVariantValue(0).ToDouble(), 2.5)
예제 #34
0
    def testHash(self):
        """Use a variant as a dict key"""
        d = {}
        # doubles, ints, strings, all hash as strings
        d[vtk.vtkVariant(1.0)] = 'double'
        d[vtk.vtkVariant(1)] = 'int'
        self.assertEqual(d[vtk.vtkVariant('1')], 'int')

        # every vtkObject is hashed by memory address
        o1 = vtk.vtkIntArray()
        o2 = vtk.vtkIntArray()
        d[vtk.vtkVariant(o1)] = 'vtkIntArray1'
        d[vtk.vtkVariant(o2)] = 'vtkIntArray2'
        self.assertEqual(d[vtk.vtkVariant(o1)], 'vtkIntArray1')
        self.assertEqual(d[vtk.vtkVariant(o2)], 'vtkIntArray2')

        # invalid variants all hash the same
        d[vtk.vtkVariant()] = 'invalid'
        self.assertEqual(d[vtk.vtkVariant()], 'invalid')
예제 #35
0
def vtkVariantCast(v, t):
    """
    Cast the vtkVariant to the specified value type, where the type is
    in the following format: 'int', 'unsigned int', etc. for numeric types,
    and 'string' or 'unicode string' for strings.  You can also use an
    integer VTK type constant for the type.
    """
    if not issubclass(type(t), int):
        t = _variant_type_map[t]

    v = vtk.vtkVariant(v, t)

    if v.IsValid():
        return getattr(v, _variant_method_map[t])()
    else:
        return None
예제 #36
0
def vtkVariantCast(v, t):
    """
    Cast the vtkVariant to the specified value type, where the type is
    in the following format: 'int', 'unsigned int', etc. for numeric types,
    and 'string' or 'unicode string' for strings.  You can also use an
    integer VTK type constant for the type.
    """
    if not issubclass(type(t), int):
        t = _variant_type_map[t]

    v = vtk.vtkVariant(v, t)

    if v.IsValid():
        return getattr(v, _variant_method_map[t])()
    else:
        return None
예제 #37
0
def vtkVariantExtract(v, t=None):
    """
    Extract the specified value type from the vtkVariant, where the type is
    in the following format: 'int', 'unsigned int', etc. for numeric types,
    and 'string' or 'unicode string' for strings.  You can also use an
    integer VTK type constant for the type.  Set the type to 'None" to
    extract the value in its native type.
    """
    v = vtk.vtkVariant(v)

    if t == None:
        t = v.GetType()
    elif not issubclass(type(t), int):
        t = _variant_type_map[t]

    if getattr(v, _variant_check_map[t])():
        return getattr(v, _variant_method_map[t])()
    else:
        return None
예제 #38
0
def vtkVariantExtract(v, t=None):
    """
    Extract the specified value type from the vtkVariant, where the type is
    in the following format: 'int', 'unsigned int', etc. for numeric types,
    and 'string' or 'unicode string' for strings.  You can also use an
    integer VTK type constant for the type.  Set the type to 'None" to
    extract the value in its native type.
    """
    v = vtk.vtkVariant(v)

    if t == None:
        t = v.GetType()
    elif not issubclass(type(t), int):
        t = _variant_type_map[t]

    if getattr(v, _variant_check_map[t])():
        return getattr(v, _variant_method_map[t])()
    else:
        return None
예제 #39
0
파일: TestTemplates.py 프로젝트: jas99/VTK
 def testSparseArray(self):
     """Test vtkSparseArray template"""
     for t in arrayTypes + arrayCodes:
         a = vtk.vtkSparseArray[t]()
         a.Resize(1)
         i = vtk.vtkArrayCoordinates(0)
         if t in ["bool", "?"]:
             value = 0
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in ["float32", "float64", "float", "f", "d"]:
             value = 3.125
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in ["char", "c"]:
             value = "c"
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in [str, "str"]:
             value = "hello"
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in ["unicode"]:
             value = francois
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in ["vtkVariant", vtk.vtkVariant]:
             value = vtk.vtkVariant("world")
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         else:
             value = 12
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
예제 #40
0
 def testSparseArray(self):
     """Test vtkSparseArray template"""
     for t in (arrayTypes + arrayCodes):
         a = vtk.vtkSparseArray[t]()
         a.Resize(1)
         i = vtk.vtkArrayCoordinates(0)
         if t in ['bool', '?']:
             value = 0
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in ['float32', 'float64', 'float', 'f', 'd']:
             value = 3.125
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in ['char', 'c']:
             value = 'c'
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in [str, 'str']:
             value = "hello"
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in ['unicode']:
             value = francois
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in ['vtkVariant', vtk.vtkVariant]:
             value = vtk.vtkVariant("world")
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         else:
             value = 12
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
예제 #41
0
파일: TestVariant.py 프로젝트: 0004c/VTK
    def testAutomaticArgConversion(self):
        """Automatic construction of variants to resolve args"""
        # use with one of vtkVariant's own constructors
        v = vtk.vtkVariant('10', vtk.VTK_INT)
        self.assertEqual(v.ToInt(), 10)
        self.assertEqual(v.GetType(), vtk.VTK_INT)

        # use with vtkVariantArray
        a = vtk.vtkVariantArray()
        i = a.InsertNextValue(10)
        v = a.GetValue(i)
        self.assertEqual(v.GetType(), vtk.VTK_INT)
        self.assertEqual(v.ToInt(), 10)
        i = a.InsertNextValue(10.0)
        v = a.GetValue(i)
        self.assertEqual(v.GetType(), vtk.VTK_DOUBLE)
        self.assertEqual(v.ToDouble(), 10.0)
        i = a.InsertNextValue('10')
        v = a.GetValue(i)
        self.assertEqual(v.GetType(), vtk.VTK_STRING)
        self.assertEqual(v.ToString(), '10')
예제 #42
0
    def testAutomaticArgConversion(self):
        """Automatic construction of variants to resolve args"""
        # use with one of vtkVariant's own constructors
        v = vtk.vtkVariant('10', vtk.VTK_INT)
        self.assertEqual(v.ToInt(), 10)
        self.assertEqual(v.GetType(), vtk.VTK_INT)

        # use with vtkVariantArray
        a = vtk.vtkVariantArray()
        i = a.InsertNextValue(10)
        v = a.GetValue(i)
        self.assertEqual(v.GetType(), vtk.VTK_INT)
        self.assertEqual(v.ToInt(), 10)
        i = a.InsertNextValue(10.0)
        v = a.GetValue(i)
        self.assertEqual(v.GetType(), vtk.VTK_DOUBLE)
        self.assertEqual(v.ToDouble(), 10.0)
        i = a.InsertNextValue('10')
        v = a.GetValue(i)
        self.assertEqual(v.GetType(), vtk.VTK_STRING)
        self.assertEqual(v.ToString(), '10')
예제 #43
0
    def testTwoArgConstructor(self):
        """Construct with a specific type"""
        # construct with conversion to int
        v = vtk.vtkVariant('10')
        u = vtk.vtkVariant(v, vtk.VTK_INT)
        self.assertEqual(u.GetType(), vtk.VTK_INT)
        self.assertEqual(v.ToInt(), u.ToInt())

        # construct with conversion to double
        v = vtk.vtkVariant(10)
        u = vtk.vtkVariant(v, vtk.VTK_DOUBLE)
        self.assertEqual(u.GetType(), vtk.VTK_DOUBLE)
        self.assertEqual(u.ToDouble(), 10.0)

        # failed conversion to vtkObject
        v = vtk.vtkVariant(10)
        u = vtk.vtkVariant(v, vtk.VTK_OBJECT)
        self.assertEqual(u.IsValid(), False)
예제 #44
0
파일: TestVariant.py 프로젝트: 0004c/VTK
    def testTwoArgConstructor(self):
        """Construct with a specific type"""
        # construct with conversion to int
        v = vtk.vtkVariant('10')
        u = vtk.vtkVariant(v, vtk.VTK_INT)
        self.assertEqual(u.GetType(), vtk.VTK_INT)
        self.assertEqual(v.ToInt(), u.ToInt())

        # construct with conversion to double
        v = vtk.vtkVariant(10)
        u = vtk.vtkVariant(v, vtk.VTK_DOUBLE)
        self.assertEqual(u.GetType(), vtk.VTK_DOUBLE)
        self.assertEqual(u.ToDouble(), 10.0)

        # failed conversion to vtkObject
        v = vtk.vtkVariant(10)
        u = vtk.vtkVariant(v, vtk.VTK_OBJECT)
        self.assertEqual(u.IsValid(), False)
예제 #45
0
파일: TestTemplates.py 프로젝트: 0004c/VTK
 def testSparseArray(self):
     """Test vtkSparseArray template"""
     for t in (arrayTypes + arrayCodes):
         a = vtk.vtkSparseArray[t]()
         a.Resize(1)
         i = vtk.vtkArrayCoordinates(0)
         if t in ['bool', '?']:
             value = 0
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in ['float32', 'float64', 'float', 'f', 'd']:
             value = 3.125
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in ['char', 'c']:
             value = 'c'
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in [str, 'str', 'unicode']:
             value = unicode("hello")
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         elif t in ['vtkVariant', vtk.vtkVariant]:
             value = vtk.vtkVariant("world")
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
         else:
             value = 12
             a.SetValue(i, value)
             result = a.GetValue(i)
             self.assertEqual(value, result)
예제 #46
0
파일: TestVariant.py 프로젝트: 0004c/VTK
 def testFloatConstructor(self):
     """Construct from float"""
     v = vtk.vtkVariant(10.0)
     self.assertEqual(v.GetType(), vtk.VTK_DOUBLE)
     self.assertEqual(v.ToDouble(), 10.0)
예제 #47
0
파일: TestVariant.py 프로젝트: 0004c/VTK
 def testDefaultConstructor(self):
     """Default constructor"""
     v = vtk.vtkVariant()
     self.assertEqual(v.IsValid(), False)
     self.assertEqual(v.GetType(), 0)
예제 #48
0
def vtkVariantEqual(s1, s2):
    """
    Return true if s1 == s2.
    """
    return (vtk.vtkVariant(s1) == vtk.vtkVariant(s2))
예제 #49
0
def vtkVariantLessThan(s1, s2):
    """
    Return true if s1 < s2.
    """
    return (vtk.vtkVariant(s1) < vtk.vtkVariant(s2))
예제 #50
0
 def testFloatConstructor(self):
     """Construct from float"""
     v = vtk.vtkVariant(10.0)
     self.assertEqual(v.GetType(), vtk.VTK_DOUBLE)
     self.assertEqual(v.ToDouble(), 10.0)
예제 #51
0
        "geometry": {
            "type": "Polygon",
            "coordinates": [
                [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
                  [100.0, 1.0], [100.0, 0.0] ]
            ]
        },
        "properties": {
            "prop0": "value0",
            "prop1": {"this": "that"}
        }
      }
  ]
}
"""
  prop0_default = vtk.vtkVariant('default')
  feature_properties = {'prop0': prop0_default}
  polydata = load_geojson(input_string, feature_properties)
  if polydata is None:
    print 'Failed to read input string and return vtkPolyData'
    sys.exit(1)

  num_errors = 0

  # Check cell counts
  expected_verts = 1
  expected_lines = 3
  expected_polys = 1

  num_verts = polydata.GetNumberOfVerts()
  if num_verts != expected_verts:
def DisplaySurface(st):
    '''
    Make and display the surface.
    :param: st - the surface to display.
    :return The vtkRenderWindowInteractor.
    '''
    surface = st.upper()
    if  (not(surface in SURFACE_TYPE) ):
        print st, "is not a surface."
        iren = vtk.vtkRenderWindowInteractor()
        return iren
    # ------------------------------------------------------------
    # Create the surface, lookup tables, contour filter etc.
    # ------------------------------------------------------------
    src = vtk.vtkPolyData()
    if (surface == "TORUS"):
        src = MakeTorus()
    elif (surface == "PARAMETRIC_TORUS"):
        src = MakeParametricTorus()
    elif (surface == "PARAMETRIC_HILLS"):
        src = Clipper(MakeParametricHills(),0.5,0.5,0.0)
    # Here we are assuming that the active scalars are the curvatures.
    curvatureName = src.GetPointData().GetScalars().GetName()
    # Use this range to color the glyphs for the normals by elevation.
    src.GetPointData().SetActiveScalars('Elevation')
    scalarRangeElevation = src.GetScalarRange()
    src.GetPointData().SetActiveScalars(curvatureName)
    scalarRangeCurvatures = src.GetScalarRange()
    scalarRange = scalarRangeCurvatures

    lut = MakeLUT()
    numberOfBands = lut.GetNumberOfTableValues()
    bands = MakeBands(scalarRange, numberOfBands, False)
    if surface == "PARAMETRIC_HILLS":
        # Comment this out if you want to see how allocating
        # equally spaced bands works.
        bands = MakeCustomBands(scalarRange, numberOfBands)
        # Adjust the number of table values
        numberOfBands = len(bands)
        lut.SetNumberOfTableValues(numberOfBands)

    lut.SetTableRange(scalarRange)

    # We will use the midpoint of the band as the label.
    labels = []
    for i in range(numberOfBands):
        labels.append('{:4.2f}'.format(bands[i][1]))

    # Annotate
    values = vtk.vtkVariantArray()
    for i in range(len(labels)):
        values.InsertNextValue(vtk.vtkVariant(labels[i]))
    for i in range(values.GetNumberOfTuples()):
        lut.SetAnnotation(i, values.GetValue(i).ToString());

    # Create a lookup table with the colors reversed.
    lutr = ReverseLUT(lut)

    # Create the contour bands.
    bcf = vtk.vtkBandedPolyDataContourFilter()
    bcf.SetInputData(src)
    # Use either the minimum or maximum value for each band.
    for i in range(0, numberOfBands):
        bcf.SetValue(i, bands[i][2])
    # We will use an indexed lookup table.
    bcf.SetScalarModeToIndex()
    bcf.GenerateContourEdgesOn()

    # Generate the glyphs on the original surface.
    glyph = MakeGlyphs(src,False)

    # ------------------------------------------------------------
    # Create the mappers and actors
    # ------------------------------------------------------------
    srcMapper = vtk.vtkPolyDataMapper()
    srcMapper.SetInputConnection(bcf.GetOutputPort())
    srcMapper.SetScalarRange(scalarRange)
    srcMapper.SetLookupTable(lut)
    srcMapper.SetScalarModeToUseCellData()

    srcActor = vtk.vtkActor()
    srcActor.SetMapper(srcMapper)
    srcActor.RotateX(-45)
    srcActor.RotateZ(45)

    # Create contour edges
    edgeMapper = vtk.vtkPolyDataMapper()
    edgeMapper.SetInputData(bcf.GetContourEdgesOutput())
    edgeMapper.SetResolveCoincidentTopologyToPolygonOffset()

    edgeActor = vtk.vtkActor()
    edgeActor.SetMapper(edgeMapper)
    edgeActor.GetProperty().SetColor(0, 0, 0)
    edgeActor.RotateX(-45)
    edgeActor.RotateZ(45)

    glyphMapper = vtk.vtkPolyDataMapper()
    glyphMapper.SetInputConnection(glyph.GetOutputPort())
    glyphMapper.SetScalarModeToUsePointFieldData()
    glyphMapper.SetColorModeToMapScalars()
    glyphMapper.ScalarVisibilityOn()
    glyphMapper.SelectColorArray('Elevation')
    # Colour by scalars.
    glyphMapper.SetScalarRange(scalarRangeElevation)

    glyphActor = vtk.vtkActor()
    glyphActor.SetMapper(glyphMapper)
    glyphActor.RotateX(-45)
    glyphActor.RotateZ(45)

    # Add a scalar bar.
    scalarBar = vtk.vtkScalarBarActor()
    # This LUT puts the lowest value at the top of the scalar bar.
    # scalarBar->SetLookupTable(lut);
    # Use this LUT if you want the highest value at the top.
    scalarBar.SetLookupTable(lutr)
    scalarBar.SetTitle('Gaussian\nCurvature')

    # ------------------------------------------------------------
    # Create the RenderWindow, Renderer and Interactor
    # ------------------------------------------------------------
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    iren = vtk.vtkRenderWindowInteractor()

    renWin.AddRenderer(ren)
    iren.SetRenderWindow(renWin)

    # add actors
    ren.AddViewProp(srcActor)
    ren.AddViewProp(edgeActor)
    ren.AddViewProp(glyphActor)
    ren.AddActor2D(scalarBar)

    ren.SetBackground(0.7, 0.8, 1.0)
    renWin.SetSize(800, 800)
    renWin.Render()

    ren.GetActiveCamera().Zoom(1.5)

    return iren
예제 #53
0
def DisplaySurface(st):
    '''
    Make and display the surface.
    :param: st - the surface to display.
    :return The vtkRenderWindowInteractor.
    '''
    surface = st.upper()
    if (not (surface in SURFACE_TYPE)):
        print st, "is not a surface."
        iren = vtk.vtkRenderWindowInteractor()
        return iren
    # ------------------------------------------------------------
    # Create the surface, lookup tables, contour filter etc.
    # ------------------------------------------------------------
    src = vtk.vtkPolyData()
    if (surface == "PLANE"):
        src = MakePlane()
    elif (surface == "SPHERE"):
        src = MakeSphere()
    elif (surface == "PARAMETRIC_SURFACE"):
        src = MakeParametricSource()
        # The scalars are named "Scalars"by default
        # in the parametric surfaces, so change the name.
        src.GetPointData().GetScalars().SetName("Elevation")
    scalarRange = src.GetScalarRange()

    lut = MakeLUT()
    lut.SetTableRange(scalarRange)
    numberOfBands = lut.GetNumberOfTableValues()
    # bands = MakeIntegralBands(scalarRange)
    bands = MakeBands(scalarRange, numberOfBands, False)

    # Let's do a frequency table.
    # The number of scalars in each band.
    #print Frequencies(bands, src)

    # We will use the midpoint of the band as the label.
    labels = []
    for i in range(len(bands)):
        labels.append('{:4.2f}'.format(bands[i][1]))

    # Annotate
    values = vtk.vtkVariantArray()
    for i in range(len(labels)):
        values.InsertNextValue(vtk.vtkVariant(labels[i]))
    for i in range(values.GetNumberOfTuples()):
        lut.SetAnnotation(i,
                          values.GetValue(i).ToString())

    # Create a lookup table with the colors reversed.
    lutr = ReverseLUT(lut)

    # Create the contour bands.
    bcf = vtk.vtkBandedPolyDataContourFilter()
    bcf.SetInputData(src)
    # Use either the minimum or maximum value for each band.
    for i in range(0, numberOfBands):
        bcf.SetValue(i, bands[i][2])
    # We will use an indexed lookup table.
    bcf.SetScalarModeToIndex()
    bcf.GenerateContourEdgesOn()

    # Generate the glyphs on the original surface.
    glyph = MakeGlyphs(src, False)

    # ------------------------------------------------------------
    # Create the mappers and actors
    # ------------------------------------------------------------
    srcMapper = vtk.vtkPolyDataMapper()
    srcMapper.SetInputConnection(bcf.GetOutputPort())
    srcMapper.SetScalarRange(scalarRange)
    srcMapper.SetLookupTable(lut)
    srcMapper.SetScalarModeToUseCellData()

    srcActor = vtk.vtkActor()
    srcActor.SetMapper(srcMapper)
    srcActor.RotateX(-45)
    srcActor.RotateZ(45)

    # Create contour edges
    edgeMapper = vtk.vtkPolyDataMapper()
    edgeMapper.SetInputData(bcf.GetContourEdgesOutput())
    edgeMapper.SetResolveCoincidentTopologyToPolygonOffset()

    edgeActor = vtk.vtkActor()
    edgeActor.SetMapper(edgeMapper)
    edgeActor.GetProperty().SetColor(0, 0, 0)
    edgeActor.RotateX(-45)
    edgeActor.RotateZ(45)

    glyphMapper = vtk.vtkPolyDataMapper()
    glyphMapper.SetInputConnection(glyph.GetOutputPort())
    glyphMapper.SetScalarModeToUsePointFieldData()
    glyphMapper.SetColorModeToMapScalars()
    glyphMapper.ScalarVisibilityOn()
    glyphMapper.SelectColorArray('Elevation')
    # Colour by scalars.
    glyphMapper.SetScalarRange(scalarRange)

    glyphActor = vtk.vtkActor()
    glyphActor.SetMapper(glyphMapper)
    glyphActor.RotateX(-45)
    glyphActor.RotateZ(45)

    # Add a scalar bar.
    scalarBar = vtk.vtkScalarBarActor()
    # scalarBar.SetLookupTable(lut)
    # Use this LUT if you want the highest value at the top.
    scalarBar.SetLookupTable(lutr)
    scalarBar.SetTitle('Elevation (m)')

    # ------------------------------------------------------------
    # Create the RenderWindow, Renderer and Interactor
    # ------------------------------------------------------------
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    iren = vtk.vtkRenderWindowInteractor()

    renWin.AddRenderer(ren)
    iren.SetRenderWindow(renWin)

    # add actors
    ren.AddViewProp(srcActor)
    ren.AddViewProp(edgeActor)
    ren.AddViewProp(glyphActor)
    ren.AddActor2D(scalarBar)

    ren.SetBackground(0.7, 0.8, 1.0)
    renWin.SetSize(800, 800)
    renWin.Render()

    ren.GetActiveCamera().Zoom(1.5)

    return iren
예제 #54
0
파일: TestVariant.py 프로젝트: 0004c/VTK
 def testCopyConstructor(self):
     """Construct from another vtkVariant"""
     u = vtk.vtkVariant('test')
     v = vtk.vtkVariant(u)
     self.assertEqual(v.GetType(), vtk.VTK_STRING)
     self.assertEqual(v.ToString(), u.ToString())
예제 #55
0
파일: TestVariant.py 프로젝트: 0004c/VTK
 def testStringConstructor(self):
     """Construct from string"""
     v = vtk.vtkVariant('hello')
     self.assertEqual(v.GetType(), vtk.VTK_STRING)
     self.assertEqual(v.ToString(), 'hello')
예제 #56
0
 def testUnicodeConstructor(self):
     """Construct from unicode"""
     v = vtk.vtkVariant(cedilla)
     self.assertEqual(v.GetType(), vtk.VTK_UNICODE_STRING)
     self.assertEqual(v.ToUnicodeString(), cedilla)
예제 #57
0
 def testBytesConstructor(self):
     """Construct from bytes"""
     v = vtk.vtkVariant(b'hello')
     self.assertEqual(v.GetType(), vtk.VTK_STRING)
     self.assertEqual(v.ToString(), 'hello')
예제 #58
0
파일: TestVariant.py 프로젝트: 0004c/VTK
 def testIntConstructor(self):
     """Construct from int"""
     v = vtk.vtkVariant(10)
     self.assertEqual(v.GetType(), vtk.VTK_INT)
     self.assertEqual(v.ToInt(), 10)
예제 #59
0
파일: TestVariant.py 프로젝트: 0004c/VTK
 def testUnicodeConstructor(self):
     """Construct from unicode"""
     if unicode_support:
         v = vtk.vtkVariant(u'hello')
         self.assertEqual(v.GetType(), vtk.VTK_UNICODE_STRING)
         self.assertEqual(v.ToUnicodeString(), u'hello')