转自https://github.com/SXHSine/Mitsuba-Usage-with-Python27
# -*- coding: UTF-8 -*-
import os
import sys
# NOTE: remember to specify paths using FORWARD slashes (i.e. '/' instead of
# '' to avoid pitfalls with string escaping)
# Configure the search path for the Python extension module
sys.path.append('D:/ProgramFiles/Mitsuba 0.5.0/python/2.7')
# Ensure that Python will be able to find the Mitsuba core libraries
os.environ['PATH'] = 'path-to-mitsuba-directory' + os.pathsep + os.environ['PATH']import mitsuba
from mitsuba.core import *
from mitsuba.core import Point3ffrom xml.etree.ElementTree import ElementTree, Elementdef read_xml(in_path):'''读取并解析xml文件in_path: xml路径return: ElementTree'''tree = ElementTree()tree.parse(in_path)return treedef write_xml(tree, out_path):'''将xml文件写出tree: xml树out_path: 写出路径'''tree.write(out_path, encoding="utf-8", xml_declaration=True)def getTheShape(filename):for s in root.findall('shape'):for pro in s:if pro.tag == "string" and pro.attrib["value"] == filename:return sreturn Nonedef setTranslate(shape, Point):if shape == None:print("None such filename")returntrans = shape.findall("transform/translate")[0]shape.findall("transform/translate")[0].attrib['x'] = str(float(Point[0]))shape.findall("transform/translate")[0].attrib['y'] = str(float(Point[1]))shape.findall("transform/translate")[0].attrib['z'] = str(float(Point[2]))def setRotate(shape, angle):if shape == None:print("None such filename")returnrotate = shape.findall("transform/rotate")[0]shape.findall("transform/rotate")[0].attrib['angle'] = str(float(angle))def setLookat(camera, point_origin, point_target):list_point_origin, list_point_target = [point_origin[0], point_origin[1], point_origin[2]], [point_target[0], point_target[1], point_target[2]]list_point_origin, list_point_target = [str(x) for x in list_point_origin], [str(x) for x in list_point_target]if camera == None:print ("None such typename")returnlookat = camera.findall("transform/lookat")[0]lookat.attrib['origin'] = ','.join(list_point_origin)lookat.attrib['target'] = ','.join(list_point_target)def changeXML_translate(path_xml, filename, Point):tree = read_xml(path_xml)root = tree.getroot()shape = Nonefor s in root.findall('shape'):for pro in s:if pro.tag == "string" and pro.attrib["value"] == filename:shape = ssetTranslate(shape, Point)write_xml(tree, path_xml)def changeXML_rotate(path_xml, filename, angle):tree = read_xml(path_xml)root = tree.getroot()shape = Nonefor s in root.findall('shape'):for pro in s:if pro.tag == "string" and pro.attrib["value"] == filename:shape = ssetRotate(shape, angle)write_xml(tree, path_xml)def changeXML_lookat(path_xml, typename, point_origin, point_target):tree = read_xml(path_xml)root = tree.getroot()camera = Nonefor s in root.findall('sensor'):if s.attrib['type'] == typename:camera = ssetLookat(camera, point_origin, point_target)write_xml(tree, path_xml)##USAGE##
# changeXML_translate("scene_objs _test.xml", "cow.obj", Point(0,0,0))if __name__ == '__main__':tree = read_xml("xxx.xml")root = tree.getroot()for s in root.findall('shape'):print (s.findall('transform/translate')[0].attrib)shape = getTheShape("cow.obj")setTranslate(shape, Point3f(0, 0, 0))print (shape.findall('transform/translate')[0].attrib)for s in root.findall('shape'):print (s.findall('transform/translate')[0].attrib)write_xml(tree, "xxx.xml")
xml的格式如下,就是通过<>节点来区别数据结构的:
.NET调用JAVA的WebService方法
调用WebService,最简单的办法当然是直接添加WEB引用,然后自动产生代理类,但是在调用JAVA的WebService时并没有这么简单,特别是对于SoapHeader的处理,在网上也有相关资料,但是都整理的不够清晰明了。根据网上的资料,个人也对各种方法进行了尝试,费了不少精力,为此特将自己的解决方法进行总结一下,以备以后需要...
FOR XML PATH 有的人可能知道有的人可能不知道,其实它就是将查询结果集以XML形式展现,有了它我们可以简化我们的查询语句实现一些以前可能需要借助函数活存储过程来完成的工作。那么以一个实例为主. 一.FOR XML PATH 简单介绍 那么还是首先来介绍一下FOR XML PATH...
导读:在前面介绍了很多关于XML和HTML的东西,他们其实各有各的好处,在很多时候都需要结合起来使用。现在已经有XML和HTML结合的产物:XHTML(可扩展超文本标记语言)。在本篇博客中,则主要介绍通过引入命名空间的方法,进行XML和HTML混合使用的例子。 一、在XML中使用HTML 1.1,代码