• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python vtk.vtkVariant函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testArgumentConversion

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


示例17: vtkVariantCast

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


示例18: vtkVariantExtract

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


示例19: testSparseArray

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


示例20: testAutomaticArgConversion

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vtk.vtkVectorText函数代码示例发布时间:2022-05-26
下一篇:
Python vtk.vtkUnstructuredGridReader函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap