def initialize(self): global renderer, renderWindow, renderWindowInteractor, cone, mapper, actor # Bring used components self.registerVtkWebProtocol(protocols.vtkWebMouseHandler()) self.registerVtkWebProtocol(protocols.vtkWebViewPort()) self.registerVtkWebProtocol(protocols.vtkWebViewPortImageDelivery()) self.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery()) # Update authentication key to use self.updateSecret(_PhylogeneticTree.authKey) # Create default pipeline (Only once for all the session) if not _PhylogeneticTree.view: # read in a tree treeReader = vtk.vtkNewickTreeReader() treeReader.SetFileName(_PhylogeneticTree.treeFilePath) treeReader.Update() reader = treeReader.GetOutput() # read in a table tableReader = vtk.vtkDelimitedTextReader() tableReader.SetFileName(_PhylogeneticTree.csvFilePath) tableReader.SetHaveHeaders(True) tableReader.DetectNumericColumnsOn() tableReader.Update() table = tableReader.GetOutput() # play with the heatmap vis treeHeatmapItem = vtk.vtkTreeHeatmapItem() treeHeatmapItem.SetTree(reader) treeHeatmapItem.SetTable(table) # setup the window view = vtk.vtkContextView() view.GetRenderer().SetBackground(1, 1, 1) view.GetRenderWindow().SetSize(800, 600) 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() # VTK Web application specific _PhylogeneticTree.view = view.GetRenderWindow() self.Application.GetObjectIdMap().SetActiveObject( "VIEW", view.GetRenderWindow())
def initialize(self): global renderer, renderWindow, renderWindowInteractor, cone, mapper, actor # Bring used components self.registerVtkWebProtocol(protocols.vtkWebMouseHandler()) self.registerVtkWebProtocol(protocols.vtkWebViewPort()) self.registerVtkWebProtocol(protocols.vtkWebViewPortImageDelivery()) self.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery()) # Update authentication key to use self.updateSecret(_PhylogeneticTree.authKey) # Create default pipeline (Only once for all the session) if not _PhylogeneticTree.view: # read in a tree treeReader = vtk.vtkNewickTreeReader() treeReader.SetFileName(_PhylogeneticTree.treeFilePath) treeReader.Update() reader = treeReader.GetOutput() # read in a table tableReader = vtk.vtkDelimitedTextReader() tableReader.SetFileName(_PhylogeneticTree.csvFilePath) tableReader.SetHaveHeaders(True) tableReader.DetectNumericColumnsOn() tableReader.Update() table = tableReader.GetOutput() # play with the heatmap vis treeHeatmapItem = vtk.vtkTreeHeatmapItem() treeHeatmapItem.SetTree(reader); treeHeatmapItem.SetTable(table); # setup the window view = vtk.vtkContextView() view.GetRenderer().SetBackground(1,1,1) view.GetRenderWindow().SetSize(800,600) 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() # VTK Web application specific _PhylogeneticTree.view = view.GetRenderWindow() self.Application.GetObjectIdMap().SetActiveObject("VIEW", view.GetRenderWindow())
def initialize(self, VTKWebApp, args): VTKWebApp.treeFilePath = args.tree VTKWebApp.csvFilePath = args.table # Create default pipeline (Only once for all the session) if not VTKWebApp.view: # read in a tree treeReader = vtk.vtkNewickTreeReader() treeReader.SetFileName(VTKWebApp.treeFilePath) treeReader.Update() reader = treeReader.GetOutput() # read in a table tableReader = vtk.vtkDelimitedTextReader() tableReader.SetFileName(VTKWebApp.csvFilePath) tableReader.SetHaveHeaders(1) tableReader.DetectNumericColumnsOn() tableReader.Update() table = tableReader.GetOutput() # play with the heatmap vis treeHeatmapItem = vtk.vtkTreeHeatmapItem() treeHeatmapItem.SetTree(reader) treeHeatmapItem.SetTable(table) # setup the window view = vtk.vtkContextView() view.GetRenderer().SetBackground(1, 1, 1) view.GetRenderWindow().SetSize(800, 600) 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() # 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: # create our visualization item treeHeatmapItem = vtk.vtkTreeHeatmapItem() # get our input data, read it into VTK format, # and load it into our visualization item. if args.treeName: r = requests.get( "%s/arborapi/projmgr/project/%s/PhyloTree/%s/phyloxml" % (args.baseURL, args.projectName, args.treeName)) phyloxmlTree = r.text tree = vtk_arbor_utils.PhyloXMLToVTKTree(phyloxmlTree) treeHeatmapItem.SetTree(tree) if tree.GetVertexData().GetArray("property.differences"): treeHeatmapItem.GetDendrogram().SetColorArray("property.differences") treeHeatmapItem.GetDendrogram().SetLineWidth(2.0) if args.tableName: r = requests.get( "%s/arborapi/projmgr/project/%s/CharacterMatrix/%s/csv" % (args.baseURL, args.projectName, args.tableName)) csvTable = r.text table = vtk_arbor_utils.CSVToVTKTable(csvTable) treeHeatmapItem.SetTable(table) # 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())
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())
def initialize(self, VTKWebApp, args): dataid = args.id treedata = getDBdata(dataid) VTKWebApp.tree = treedata["tree"] VTKWebApp.table = dataid+ ".csv" # Create default pipeline (Only once for all the session) if not VTKWebApp.view: treeHeatmapItem = vtk.vtkTreeHeatmapItem() # read in a tree treeReader = vtk.vtkNewickTreeReader() treeReader.SetReadFromInputString(1) treeReader.SetInputString(VTKWebApp.tree) treeReader.Update() tree = treeReader.GetOutput() treeHeatmapItem.SetTree(tree) if (VTKWebApp.table != "none" and os.path.isfile(VTKWebApp.table)): # read in a table print("read table"+ VTKWebApp.table) tableReader = vtk.vtkDelimitedTextReader() tableReader.SetFileName(VTKWebApp.table) tableReader.SetHaveHeaders(1) tableReader.DetectNumericColumnsOn() tableReader.Update() table = tableReader.GetOutput() if (table): treeHeatmapItem.SetTable(table) # setup the window view = vtk.vtkContextView() view.GetRenderer().SetBackground(1,1,1) view.GetRenderWindow().SetSize(800,600) 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())
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())