def OnDoubleClick(self, event): self.OnSingleClick(event) text = self.tree.item(self.selected_item,"text"); if text == "root": print ("Ignore root") elif text == "": print ("Ignore empty name") else: print("you clicked on ", text) material_selection = MaterialSelection.MaterialSelection(self.root, text, gvxr.getMaterialLabel(text), gvxr.getDensity(text)); child_children = gvxr.getNumberOfChildren(text); if material_selection.cancel == False: global x_ray_image; # Element if material_selection.materialType.get() == 0: gvxr.setElement(text, material_selection.element_name.get()); gvxr.setDensity(text, float(material_selection.density.get()), "g/cm3"); # Mixture elif material_selection.materialType.get() == 1: gvxr.setMixture(text, material_selection.mixture.get()); gvxr.setDensity(text, float(material_selection.density.get()), "g/cm3"); # Compound elif material_selection.materialType.get() == 2: gvxr.setCompound(text, material_selection.compound.get()); gvxr.setDensity(text, float(material_selection.density.get()), "g/cm3"); # Hounsfield unit elif material_selection.materialType.get() == 3: gvxr.setHU(text, material_selection.hounsfield_value.get()); # Mass attenuation coefficient elif material_selection.materialType.get() == 4: gvxr.setDensity(text, float(material_selection.density.get()), "g/cm3"); print("?"); # Linear attenuation coefficient elif material_selection.materialType.get() == 5: gvxr.setDensity(text, float(material_selection.density.get()), "g/cm3"); print("?"); self.tree.item(self.selected_item, values=(str(child_children), gvxr.getMaterialLabel(text), str(gvxr.getDensity(text)))) x_ray_image = gvxr.computeXRayImage(); gvxr.displayScene() self.xray_vis.draw(x_ray_image);
def setXRayEnvironment(): gvxr.createWindow() gvxr.setWindowSize(512, 512) #gvxr.usePointSource(); gvxr.setMonoChromatic(80, "keV", 1000) gvxr.setDetectorUpVector(0, 0, -1) gvxr.setDetectorNumberOfPixels(768, 1024) gvxr.setDetectorPixelSize(0.5, 0.5, "mm") # 5 dpi setXRayParameters(10.0, 100.0) gvxr.loadSceneGraph("./hand.dae", "m") node_label_set = [] node_label_set.append('root') # The list is not empty while (len(node_label_set)): # Get the last node last_node = node_label_set[-1] # Initialise the material properties # print("Set ", label, "'s Hounsfield unit"); # gvxr.setHU(label, 1000) Z = gvxr.getElementAtomicNumber("H") gvxr.setElement(last_node, gvxr.getElementName(Z)) # Change the node colour to a random colour gvxr.setColour(last_node, random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1), 1.0) # Remove it from the list node_label_set.pop() # Add its Children for i in range(gvxr.getNumberOfChildren(last_node)): node_label_set.append(gvxr.getChildLabel(last_node, i)) gvxr.moveToCentre('root') gvxr.disableArtefactFiltering() gvxr.rotateNode('root', -90, 1, 0, 0)
def getLocalTransformationMatrixSet(): # Parse the scenegraph matrix_set = {} node_label_set = [] node_label_set.append('root') # The list is not empty while (len(node_label_set)): # Get the last node last_node = node_label_set[-1] # Get its local transformation matrix_set[last_node] = gvxr.getLocalTransformationMatrix(last_node) # Remove it from the list node_label_set.pop() # Add its Children for i in range(gvxr.getNumberOfChildren(last_node)): node_label_set.append(gvxr.getChildLabel(last_node, i)) return matrix_set
def createTarget(): global target target_SOD = 100 target_SDD = 140 target_angles_pa = [ 0, 20, 0, -10, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] target = [] target.append(target_SOD) target.append(target_SDD) for i in range(len(target_angles_pa)): target.append(target_angles_pa[i]) gvxr.createWindow() gvxr.setWindowSize(512, 512) #gvxr.usePointSource(); gvxr.setMonoChromatic(80, "keV", 1000) gvxr.setDetectorUpVector(0, 0, -1) gvxr.setDetectorNumberOfPixels(1536, 1536) gvxr.setDetectorPixelSize(0.5, 0.5, "mm") # 5 dpi setXRayParameters(target_SOD, target_SDD) gvxr.loadSceneGraph("./hand.dae", "m") node_label_set = [] node_label_set.append('root') # The list is not empty while (len(node_label_set)): # Get the last node last_node = node_label_set[-1] # Initialise the material properties # print("Set ", label, "'s Hounsfield unit"); # gvxr.setHU(label, 1000) Z = gvxr.getElementAtomicNumber("H") gvxr.setElement(last_node, gvxr.getElementName(Z)) # Change the node colour to a random colour gvxr.setColour(last_node, random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1), 1.0) # Remove it from the list node_label_set.pop() # Add its Children for i in range(gvxr.getNumberOfChildren(last_node)): node_label_set.append(gvxr.getChildLabel(last_node, i)) gvxr.moveToCentre('root') gvxr.disableArtefactFiltering() target_image = bone_rotation(target_angles_pa) plt.imsave("./posterior-anterior/RMSE/target.png", target_image, cmap='Greys_r') return target_image, target
def __init__(self, anEnergy): self.root = tk.Tk() self.canvas = tk.Canvas(self.root, width=480, height=800, background="blue") self.xray_vis = DisplayXRay.DisplayXRay(self.root); self.rotation_var = tk.DoubleVar() self.artefact_filtering_var = tk.IntVar() self.energy_var = tk.DoubleVar(); self.energy_var.set(anEnergy); self.source_shape = tk.IntVar() self.energy_var.set(0); self.selected_item = 0; MODES = [ ("None", 0), ("CPU", 1), ("GPU", 2), ] self.artefact_filtering_var.set(2) self.artefactFilteringSelection(); for text, mode in MODES: self.b = tk.Radiobutton(self.canvas, text=text, variable=self.artefact_filtering_var, value=mode, command=self.artefactFilteringSelection) self.b.pack(anchor=tk.W) self.scale = tk.Scale(self.canvas ,from_=0, to=359, variable = self.rotation_var, command=self.rotationScene, orient=tk.HORIZONTAL ) self.scale.pack(anchor=tk.CENTER) self.last_angle = 0 self.angle_label = tk.Label(self.canvas) self.angle_label.pack() self.rotationScene(0); self.energy = tk.Scale(self.canvas ,from_=0.001, to=100000, resolution=0.001, variable = self.energy_var, command=self.setEnergy, orient=tk.HORIZONTAL ) self.energy.pack(anchor=tk.CENTER) self.energy_label = tk.Label(self.canvas) self.energy_label.pack() self.setEnergy(0) MODES = [ ("Point source", 0), ("Parallel beam", 1), ] for text, mode in MODES: temp = tk.Radiobutton(self.canvas, text=text, variable=self.source_shape, value=mode, command=self.setSourceShape) temp.pack(anchor=tk.W) print ("Set the source shape"); self.setSourceShape(); self.button = tk.Button(self.canvas, text="Save images", command=self.saveImage) self.button.pack(anchor=tk.CENTER) self.tree = ttk.Treeview(self.canvas, columns=("Children", "Material", "Density")) self.tree.bind("<Double-1>", self.OnDoubleClick) self.tree.bind("<Button-1>", self.OnSingleClick) self.tree.heading("Children", text="Children"); self.tree.heading("Material", text="Material"); self.tree.heading("Density", text="Density"); self.tree.pack(padx=10, pady=10) node_label='root'; children=gvxr.getNumberOfChildren(node_label); node_id = self.tree.insert('', 'end', text=node_label,values=(children, "N/A", "N/A")) list_of_parents = []; if children: list_of_parents.append((node_label, node_id)); while len(list_of_parents): (parent_label, parent_id) = list_of_parents[-1]; list_of_parents.pop(); for i in range(gvxr.getNumberOfChildren(parent_label)): child_label = gvxr.getChildLabel(parent_label, i); child_children = gvxr.getNumberOfChildren(child_label); node_id = self.tree.insert(parent_id, 'end', text=child_label, values=(str(0), gvxr.getMaterialLabel(child_label), str(gvxr.getDensity(child_label))), tag=child_label); # Get the mesh colour in float colour_float = gvxr.getAmbientColour(child_label)[0:3]; # Convert it in UCHAR colour_int = [int(i * 255) for i in colour_float]; # Convert it in HTML hex_colour= toHex(colour_int); foreground = '#' + hex_colour; background="#ffffff" if colour_int[0] > 128 and colour_int[1] > 128 and colour_int[2] > 128: background="#aaaaaa" # Set the corresponding line colour in the tree self.tree.tag_configure(child_label, foreground=foreground) self.tree.tag_configure(child_label, background=background) if child_children: list_of_parents.append((child_label, node_id)); self.canvas.pack(); self.root.after(10, self.idle) self.geometrical_transformation = GeometricalTransformation.GeometricalTransformation(self.root, "root", self.xray_vis); self.root.mainloop()
def main(argv): global x_ray_image parser = argparse.ArgumentParser() parser.add_argument( "-input", type=str, help= "Input file (see http://assimp.sourceforge.net/main_features_formats.html for a list of supported file formats)" ) parser.add_argument( "-unit", type=str, help="Unit of length corresponding to the input", choices=["um", "mm", "cm", "dm", "m", "dam", "hm", "km"]) args = parser.parse_args() if args.input and args.unit: # Create an OpenGL context print("Create an OpenGL context") gvxr.createWindow() gvxr.setWindowSize(512, 512) # Set up the beam print("Set up the beam") gvxr.setSourcePosition(100.0, 0.0, 0.0, "cm") gvxr.usePointSource() #gvxr.useParallelBeam(); gvxr.setMonoChromatic(0.08, "MeV", 1) # Set up the detector print("Set up the detector") gvxr.setDetectorPosition(-40.0, 0.0, 0.0, "cm") gvxr.setDetectorUpVector(0, 0, -1) gvxr.setDetectorNumberOfPixels(1024, 1024) gvxr.setDetectorPixelSize(0.5, 0.5, "mm") # Load the data print("Load the data") gvxr.loadSceneGraph(args.input, args.unit) gvxr.disableArtefactFiltering() #gvxr.loadMeshFile("chest", "./HVPTest/chest2.obj", "mm"); #gvxr.invertNormalVectors("armR"); #gvxr.invertNormalVectors("chest"); node_label_set = [] node_label_set.append('root') # The list is not empty while (len(node_label_set)): # Get the last node last_node = node_label_set[-1] # Initialise the material properties #print("Set ", label, "'s Hounsfield unit"); #gvxr.setHU(label, 1000) Z = gvxr.getElementAtomicNumber("H") gvxr.setElement(last_node, gvxr.getElementName(Z)) # Change the node colour to a random colour gvxr.setColour(last_node, random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1), 1.0) # Remove it from the list node_label_set.pop() # Add its Children for i in range(gvxr.getNumberOfChildren(last_node)): node_label_set.append(gvxr.getChildLabel(last_node, i)) ''' for label in gvxr.getMeshLabelSet(): print("Move ", label, " to the centre"); #gvxr.moveToCentre(label); #print("Move the mesh to the center"); #gvxr.moveToCenter(label); #gvxr.invertNormalVectors(label); ''' #gvxr.moveToCentre(); gvxr.moveToCentre('root') # Compute an X-ray image #print("Compute an X-ray image"); #gvxr.disableArtefactFiltering(); #gvxr.enableArtefactFilteringOnGPU(); # Not working anymore gvxr.enableArtefactFilteringOnGPU(); # Not working anymore gvxr.enableArtefactFilteringOnCPU(); x_ray_image = np.array(gvxr.computeXRayImage()) '''x_ray_image -= 0.0799; x_ray_image /= 0.08 - 0.0799; plt.ioff(); plt.imshow(x_ray_image, cmap="gray"); plt.show() ''' #gvxr.setShiftFilter(-0.0786232874); #gvxr.setScaleFilter(726.368958); gvxr.displayScene() app = App.App(0.08)
def poserior_anterior(angles): node_label_set = [] node_label_set.append('root') # The list is not empty while (len(node_label_set)): # Get the last node node = node_label_set[-1] # Initialise the material properties Z = gvxr.getElementAtomicNumber("H") gvxr.setElement(node, gvxr.getElementName(Z)) # Change the node colour to a random colour gvxr.setColour(node, random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1), 1.0) # Remove it from the list node_label_set.pop() # Add its Children for i in range(gvxr.getNumberOfChildren(node)): node_label_set.append(gvxr.getChildLabel(node, i)) if node == 'root': gvxr.rotateNode(node, angles[0], 1, 0, 0) gvxr.rotateNode(node, angles[1], 0, 1, 0) if node == 'node-Thu_Meta': gvxr.rotateNode(node, angles[2], 1, 0, 0) gvxr.rotateNode(node, angles[3], 0, 1, 0) if node == 'node-Thu_Prox': gvxr.rotateNode(node, angles[4], 1, 0, 0) gvxr.rotateNode(node, angles[5], 0, 1, 0) if node == 'node-Thu_Dist': gvxr.rotateNode(node, angles[6], 1, 0, 0) gvxr.rotateNode(node, angles[7], 0, 1, 0) if node == 'node-Lit_Meta': gvxr.rotateNode(node, angles[8], 1, 0, 0) gvxr.rotateNode(node, angles[9], 0, 1, 0) if node == 'node-Lit_Prox': gvxr.rotateNode(node, angles[10], 1, 0, 0) gvxr.rotateNode(node, angles[11], 0, 1, 0) if node == 'node-Lit_Midd': gvxr.rotateNode(node, angles[12], 1, 0, 0) gvxr.rotateNode(node, angles[13], 0, 1, 0) if node == 'node-Lit_Dist': gvxr.rotateNode(node, angles[14], 1, 0, 0) gvxr.rotateNode(node, angles[15], 0, 1, 0) if node == 'node-Thi_Meta': gvxr.rotateNode(node, angles[16], 1, 0, 0) gvxr.rotateNode(node, angles[17], 0, 1, 0) if node == 'node-Thi_Prox': gvxr.rotateNode(node, angles[18], 1, 0, 0) gvxr.rotateNode(node, angles[19], 0, 1, 0) if node == 'node-Thi_Midd': gvxr.rotateNode(node, angles[20], 1, 0, 0) gvxr.rotateNode(node, angles[21], 0, 1, 0) if node == 'node-Thi_Dist': gvxr.rotateNode(node, angles[22], 1, 0, 0) gvxr.rotateNode(node, angles[23], 0, 1, 0) if node == 'node-Mid_Meta': gvxr.rotateNode(node, angles[24], 1, 0, 0) gvxr.rotateNode(node, angles[25], 0, 1, 0) if node == 'node-Mid_Prox': gvxr.rotateNode(node, angles[26], 1, 0, 0) gvxr.rotateNode(node, angles[27], 0, 1, 0) if node == 'node-Mid_Midd': gvxr.rotateNode(node, angles[28], 1, 0, 0) gvxr.rotateNode(node, angles[29], 0, 1, 0) if node == 'node-Mid_Dist': gvxr.rotateNode(node, angles[30], 1, 0, 0) gvxr.rotateNode(node, angles[31], 0, 1, 0) if node == 'node-Ind_Meta': gvxr.rotateNode(node, angles[32], 1, 0, 0) gvxr.rotateNode(node, angles[33], 0, 1, 0) if node == 'node-Ind_Prox': gvxr.rotateNode(node, angles[34], 1, 0, 0) gvxr.rotateNode(node, angles[35], 0, 1, 0) if node == 'node-Ind_Midd': gvxr.rotateNode(node, angles[36], 1, 0, 0) gvxr.rotateNode(node, angles[37], 0, 1, 0) if node == 'node-Ind_Dist': gvxr.rotateNode(node, angles[0], 1, 0, 0) gvxr.rotateNode(node, angles[0], 0, 1, 0) x_ray_image = gvxr.computeXRayImage() image = np.array(x_ray_image) return image
# Load the data print("Load the data") #gvxr.loadSceneGraph("DogBone.stl", "m"); gvxr.loadMeshFile("male_model", "male_model-bin.stl", "mm") gvxr.setHU("male_model", 1000) min_corner = None max_corner = None NoneType = type(None) # Process every node for i in range(gvxr.getNumberOfChildren('root')): # Get the label label = gvxr.getChildLabel('root', i) # Update the bounding box if isinstance(min_corner, NoneType): min_corner = np.array(gvxr.getNodeOnlyBoundingBox(label, "cm")[0:3]) else: current_min_corner = np.array( gvxr.getNodeOnlyBoundingBox(label, "cm")[0:3]) min_corner[0] = min(min_corner[0], current_min_corner[0]) min_corner[1] = min(min_corner[1], current_min_corner[1]) min_corner[2] = min(min_corner[2], current_min_corner[2]) if isinstance(max_corner, NoneType): max_corner = np.array(gvxr.getNodeOnlyBoundingBox(label, "cm")[3:6])