def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkTreeReader(), 'Reading vtkTree.', (), ('vtkTree',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def DeserializeVTKTree(treeString): data_treeString = base64.b64decode(treeString) reader = vtk.vtkTreeReader() reader.ReadFromInputStringOn() reader.SetBinaryInputString(data_treeString, len(data_treeString)) reader.Update() return reader.GetOutput()
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkTreeReader(), 'Reading vtkTree.', (), ('vtkTree', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def initialize(self, VTKWebApp, args): # Create default pipeline (Only once for all the session) if not VTKWebApp.view: baseURL = args.baseURL # support for overriding the base URL scriptDir = os.path.dirname(os.path.realpath(__file__)) configPath = scriptDir + "/baseURL.txt" if os.path.isfile(configPath): f = file(configPath, "r") baseURL = f.read().rstrip() f.close() # get our input data from romanesco r = requests.get(baseURL + args.tree1URI, verify=False) tree1JSON = r.json() tree1Str = tree1JSON["data"] r = requests.get(baseURL + args.tree2URI, verify=False) tree2JSON = r.json() tree2Str = tree2JSON["data"] r = requests.get(baseURL + args.tableURI, verify=False) tableJSON = r.json() tableStr = tableJSON["data"] # get the tree names (TODO: consider better ways to get this info) tree1LabelURI = args.tree1URI[0:args.tree1URI.find("romanesco")] r = requests.get(baseURL + tree1LabelURI, verify=False) tree1LabelJSON = r.json() tree1Label = tree1LabelJSON["name"] tree1Label = tree1Label[0:tree1Label.find(".")] tree2LabelURI = args.tree2URI[0:args.tree2URI.find("romanesco")] r = requests.get(baseURL + tree2LabelURI, verify=False) tree2LabelJSON = r.json() tree2Label = tree2LabelJSON["name"] tree2Label = tree2Label[0:tree2Label.find(".")] # convert our input data into deserialized VTK objects tree1Reader = vtk.vtkTreeReader() tree1Reader.ReadFromInputStringOn() tree1Reader.SetInputString(tree1Str, len(tree1Str)) tree1Reader.Update() tree1 = tree1Reader.GetOutput() tree2Reader = vtk.vtkTreeReader() tree2Reader.ReadFromInputStringOn() tree2Reader.SetInputString(tree2Str, len(tree2Str)) tree2Reader.Update() tree2 = tree2Reader.GetOutput() tableReader = vtk.vtkDelimitedTextReader() tableReader.ReadFromInputStringOn() tableReader.SetInputString(tableStr, len(tableStr)) tableReader.SetHaveHeaders(True) tableReader.DetectNumericColumnsOn() tableReader.ForceDoubleOn() table = tableReader.GetOutput() tableReader.Update() # create our visualization item and load the data into it. tanglegram = vtk.vtkTanglegramItem() tanglegram.SetTree1(tree1) tanglegram.SetTree2(tree2) tanglegram.SetTable(table) tanglegram.SetTree1Label(tree1Label) tanglegram.SetTree2Label(tree2Label) tanglegram.SetCorrespondenceLineWidth(4.0) tanglegram.SetTreeLineWidth(2.0) # setup the window view = vtk.vtkContextView() view.GetRenderWindow().SetSize(int(args.width), int(args.height)) view.GetRenderer().SetBackground(1, 1, 1) iren = view.GetInteractor() iren.SetRenderWindow(view.GetRenderWindow()) transformItem = vtk.vtkContextTransform() transformItem.AddItem(tanglegram) transformItem.SetInteractive(1) view.GetScene().AddItem(transformItem) view.GetRenderWindow().SetMultiSamples(0) iren.Initialize() view.GetRenderWindow().Render() # VTK Web application specific VTKWebApp.view = view.GetRenderWindow() self.Application.GetObjectIdMap().SetActiveObject( "VIEW", view.GetRenderWindow())
def initialize(self, VTKWebApp, args): # Create default pipeline (Only once for all the session) if not VTKWebApp.view: baseURL = args.baseURL # support for overriding the base URL scriptDir = os.path.dirname(os.path.realpath(__file__)) configPath = scriptDir + "/baseURL.txt" if os.path.isfile(configPath): f = file(configPath, "r") baseURL = f.read().rstrip() f.close() # get our input data from romanesco r = requests.get(baseURL + args.tableURI, verify=False) tableJSON = r.json() tableStr = tableJSON["data"] r = requests.get(baseURL + args.treeURI, verify=False) treeJSON = r.json() treeStr = treeJSON["data"] # deserialize our input data tableReader = vtk.vtkTableReader() tableReader.ReadFromInputStringOn() tableReader.SetInputString(tableStr, len(tableStr)) tableReader.Update() table = tableReader.GetOutput() treeReader = vtk.vtkTreeReader() treeReader.ReadFromInputStringOn() treeReader.SetInputString(treeStr, len(treeStr)) treeReader.Update() tree = treeReader.GetOutput() # create our visualization item and load the data into it. treeHeatmapItem = vtk.vtkTreeHeatmapItem() treeHeatmapItem.SetTree(tree) treeHeatmapItem.SetTable(table) # detect if we are visualizing the results of a tree comparison if tree.GetVertexData().GetArray("property.differences"): treeHeatmapItem.GetDendrogram().SetColorArray( "property.differences") treeHeatmapItem.GetDendrogram().SetLineWidth(2.0) # setup the window view = vtk.vtkContextView() view.GetRenderWindow().SetSize(int(args.width), int(args.height)) view.GetRenderer().SetBackground(1, 1, 1) iren = view.GetInteractor() iren.SetRenderWindow(view.GetRenderWindow()) transformItem = vtk.vtkContextTransform() transformItem.AddItem(treeHeatmapItem) transformItem.SetInteractive(1) view.GetScene().AddItem(transformItem) view.GetRenderWindow().SetMultiSamples(0) iren.Initialize() view.GetRenderWindow().Render() # adjust zoom so the item nicely fills the screen itemSize = [0, 0] treeHeatmapItem.GetSize(itemSize) itemSize.append(0) transformItem.GetTransform().MultiplyPoint(itemSize, itemSize) newWidth = view.GetScene().GetSceneWidth() newHeight = view.GetScene().GetSceneHeight() pageWidth = newWidth pageHeight = newHeight sx = pageWidth / itemSize[0] sy = pageHeight / itemSize[1] if sy < sx: scale = sy else: scale = sx if scale > 1: scale = scale * 0.5 else: scale = scale * 0.9 transformItem.Scale(scale, scale) # center the item within the screen itemCenter = [0, 0] treeHeatmapItem.GetCenter(itemCenter) itemCenter.append(0) centerPt = vtk.vtkPoints2D() centerPt.InsertNextPoint(newWidth / 2.0, newHeight / 2.0) transformItem.GetTransform().InverseTransformPoints(centerPt, centerPt) sceneCenter = [0, 0] centerPt.GetPoint(0, sceneCenter) dx = -1 * (itemCenter[0] - sceneCenter[0]) dy = -1 * (itemCenter[1] - sceneCenter[1]) transformItem.Translate(dx, dy) # VTK Web application specific VTKWebApp.view = view.GetRenderWindow() self.Application.GetObjectIdMap().SetActiveObject( "VIEW", view.GetRenderWindow())
import vtk reader = vtk.vtkTreeReader() reader.ReadFromInputStringOn() reader.SetInputString(input, len(input)) reader.Update() output = reader.GetOutput()
def initialize(self, VTKWebApp, args): # Create default pipeline (Only once for all the session) if not VTKWebApp.view: baseURL = args.baseURL # support for overriding the base URL scriptDir = os.path.dirname(os.path.realpath(__file__)) configPath = scriptDir + "/baseURL.txt" if os.path.isfile(configPath): f = file(configPath, "r") baseURL = f.read().rstrip() f.close() # get our input data from romanesco r = requests.get(baseURL + args.tableURI, verify=False) tableJSON = r.json() tableStr = tableJSON["data"] r = requests.get(baseURL + args.treeURI, verify=False) treeJSON = r.json() treeStr = treeJSON["data"] # deserialize our input data tableReader = vtk.vtkTableReader() tableReader.ReadFromInputStringOn() tableReader.SetInputString(tableStr, len(tableStr)) tableReader.Update() table = tableReader.GetOutput() treeReader = vtk.vtkTreeReader() treeReader.ReadFromInputStringOn() treeReader.SetInputString(treeStr, len(treeStr)) treeReader.Update() tree = treeReader.GetOutput() # create our visualization item and load the data into it. treeHeatmapItem = vtk.vtkTreeHeatmapItem() treeHeatmapItem.SetTree(tree) treeHeatmapItem.SetTable(table) # detect if we are visualizing the results of a tree comparison if tree.GetVertexData().GetArray("property.differences"): treeHeatmapItem.GetDendrogram().SetColorArray("property.differences") treeHeatmapItem.GetDendrogram().SetLineWidth(2.0) # setup the window view = vtk.vtkContextView() view.GetRenderWindow().SetSize(int(args.width), int(args.height)) view.GetRenderer().SetBackground(1,1,1) iren = view.GetInteractor() iren.SetRenderWindow(view.GetRenderWindow()) transformItem = vtk.vtkContextTransform() transformItem.AddItem(treeHeatmapItem) transformItem.SetInteractive(1) view.GetScene().AddItem(transformItem) view.GetRenderWindow().SetMultiSamples(0) iren.Initialize() view.GetRenderWindow().Render() # adjust zoom so the item nicely fills the screen itemSize = [0, 0] treeHeatmapItem.GetSize(itemSize) itemSize.append(0) transformItem.GetTransform().MultiplyPoint(itemSize, itemSize) newWidth = view.GetScene().GetSceneWidth() newHeight = view.GetScene().GetSceneHeight() pageWidth = newWidth pageHeight = newHeight sx = pageWidth / itemSize[0] sy = pageHeight / itemSize[1] if sy < sx: scale = sy; else: scale = sx; if scale > 1: scale = scale * 0.5 else: scale = scale * 0.9 transformItem.Scale(scale, scale) # center the item within the screen itemCenter = [0, 0] treeHeatmapItem.GetCenter(itemCenter) itemCenter.append(0) centerPt = vtk.vtkPoints2D() centerPt.InsertNextPoint(newWidth / 2.0, newHeight / 2.0) transformItem.GetTransform().InverseTransformPoints(centerPt, centerPt) sceneCenter = [0, 0] centerPt.GetPoint(0, sceneCenter) dx = -1 * (itemCenter[0] - sceneCenter[0]) dy = -1 * (itemCenter[1] - sceneCenter[1]) transformItem.Translate(dx, dy) # VTK Web application specific VTKWebApp.view = view.GetRenderWindow() self.Application.GetObjectIdMap().SetActiveObject("VIEW", view.GetRenderWindow())