当前位置: 首页>>代码示例>>Python>>正文


Python vtk.vtkVariant函数代码示例

本文整理汇总了Python中vtk.vtkVariant函数的典型用法代码示例。如果您正苦于以下问题:Python vtkVariant函数的具体用法?Python vtkVariant怎么用?Python vtkVariant使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了vtkVariant函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: vtkVariantStrictEquality

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)
开发者ID:EricAlex,项目名称:ThirdParty-dev,代码行数:28,代码来源:vtkVariant.py

示例2: vtkVariantStrictWeakOrder

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)
开发者ID:151706061,项目名称:ParaView,代码行数:35,代码来源:variant.py

示例3: testStrictWeakOrder

 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)
开发者ID:0004c,项目名称:VTK,代码行数:8,代码来源:TestVariant.py

示例4: testBoolPointer

 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])
开发者ID:timkrentz,项目名称:SunTracker,代码行数:8,代码来源:TestPointers.py

示例5: testStrictWeakOrder

 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)
开发者ID:ALouis38,项目名称:VTK,代码行数:8,代码来源:TestVariant.py

示例6: testCompare

 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)
开发者ID:ALouis38,项目名称:VTK,代码行数:8,代码来源:TestVariant.py

示例7: testCompare

 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)
开发者ID:0004c,项目名称:VTK,代码行数:8,代码来源:TestVariant.py

示例8: testStrictWeakOrder

 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)
开发者ID:kass1,项目名称:VTK,代码行数:11,代码来源:TestVariant.py

示例9: testComparisonMethods

 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)
开发者ID:ALouis38,项目名称:VTK,代码行数:13,代码来源:TestVariant.py

示例10: testObjectConstructor

 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)
开发者ID:0004c,项目名称:VTK,代码行数:7,代码来源:TestVariant.py

示例11: testConstructors

 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)
开发者ID:ALouis38,项目名称:VTK,代码行数:16,代码来源:TestOverloads.py

示例12: vtkVariantStrictWeakOrder

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)
开发者ID:EricAlex,项目名称:ThirdParty-dev,代码行数:46,代码来源:vtkVariant.py

示例13: testPassByValueReturnByReference

 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())
开发者ID:0004c,项目名称:VTK,代码行数:10,代码来源:TestVariant.py

示例14: testPassByReferenceReturnByValue

 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())
开发者ID:0004c,项目名称:VTK,代码行数:10,代码来源:TestVariant.py

示例15: vtkVariantCreate

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)
开发者ID:EricAlex,项目名称:ThirdParty-dev,代码行数:11,代码来源:vtkVariant.py


注:本文中的vtk.vtkVariant函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。