コード例 #1
0
ファイル: vtkVariant.py プロジェクト: jiaguobing/FastCAE
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
ファイル: variant.py プロジェクト: 151706061/ParaView
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
ファイル: vtkVariant.py プロジェクト: EricAlex/ThirdParty-dev
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
ファイル: TestVariant.py プロジェクト: mabo0001/VTK5.10.1
 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
ファイル: TestVariant.py プロジェクト: mabo0001/VTK5.10.1
 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
ファイル: TestPointers.py プロジェクト: timkrentz/SunTracker
 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
ファイル: TestOverloads.py プロジェクト: ALouis38/VTK
 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
ファイル: TestOverloads.py プロジェクト: msr5zb/PCL-Stuff
 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
ファイル: vtkVariant.py プロジェクト: jiaguobing/FastCAE
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
ファイル: vtkVariant.py プロジェクト: EricAlex/ThirdParty-dev
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
ファイル: vtkVariant.py プロジェクト: EricAlex/ThirdParty-dev
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
ファイル: vtkVariant.py プロジェクト: jiaguobing/FastCAE
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
ファイル: TestOverloads.py プロジェクト: msr5zb/PCL-Stuff
 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
ファイル: TestOverloads.py プロジェクト: ALouis38/VTK
 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
ファイル: vtkVariant.py プロジェクト: jiaguobing/FastCAE
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
ファイル: vtkVariant.py プロジェクト: EricAlex/ThirdParty-dev
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
ファイル: vtkVariant.py プロジェクト: EricAlex/ThirdParty-dev
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
ファイル: vtkVariant.py プロジェクト: jiaguobing/FastCAE
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
ファイル: TestTemplates.py プロジェクト: ciwei100000/vtk7
 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
ファイル: vtkVariant.py プロジェクト: jiaguobing/FastCAE
def vtkVariantEqual(s1, s2):
    """
    Return true if s1 == s2.
    """
    return (vtk.vtkVariant(s1) == vtk.vtkVariant(s2))
コード例 #49
0
ファイル: vtkVariant.py プロジェクト: jiaguobing/FastCAE
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
ファイル: TestGeoJSONReader.py プロジェクト: kass1/VTK
        "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:
コード例 #52
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 == "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')