def __getCameraMovementAngles(self): """ @return: camera position as its movement angles (azimuth, elevation and roll) in degres @rtype: (float, float, float) """ camera = self.vtkapp.cameraPosition top = self.vtkapp.cameraViewUp if camera[0] != 0 or camera[2] != 0: a = math.atan2(camera[0], camera[2]) camera = rotateY(-a, camera) top = rotateY(-a, top) b = math.atan2(camera[1], camera[2]) camera = rotateX(-b, camera) top = rotateX(-b, top) c = math.atan2(top[0], top[1]) #camera = rotateZ(c, camera) top = rotateZ(c, top) debugOutput("initial top: %s" % str(top)) debugOutput("initial camera: %s" % str(camera)) return tuple(x * 180 / math.pi for x in (a, b, c))
def prepareLoop(self, structureNames): """ Prepare the reconstruction queues L{_simpleQueue} and L{_compositeQueue} to perform requested reconstructions. @param structureNames: roots of hierarchy subtrees @type structureNames: [str, ...] """ # filter requested structures to preserve existing ones validNames = set(name for name in structureNames if name in self.sh.ih.groups) # if any of requested structures does not exist for name in set(structureNames) - validNames: debugOutput("Structure %s not found." %name, error = True) # get names of hierarchy subtrees nodes uniqueNames = self.sh.ih.unfoldSubtrees(validNames, self.depth, leavesOnly=False) # and request performing of their simple reconstructions for name in uniqueNames: self.prepareSimpleLoop(name) # if composite reconstruction is requested if self.composite: # get names of hierarchy subtrees leaf nodes components = self.sh.ih.unfoldSubtrees(validNames, self.depth, leavesOnly=True) # combine their names into reconstruction name name = 'composite_%d_structures_%X' % (len(components), crc32('_'.join(sorted(list(components)))) & 0xffffffff) # and request the reconstruction self.prepareCompositeLoop(name, components)
def _appendOutlineActors(self): """ Load pregenerated models of structures from C{self.L{outline<barBatchReconstructor.outline>}} and append them to the scene as translucent context actors. """ for name in self.outline: filename = self.__getFileName(name, 'exportToVTKPolydata') if os.path.exists(filename): self.vtkapp.appendContextActor(\ name,\ filename,\ (0,0,0), # to be overwritten ;) BAR_BRAIN_OUTLINE_PROPS) else: debugOutput("File %s not found." % filename, error = True) self.vtkapp.refreshRenderWindow()
def _appendOutlineActors(self): """ Load pregenerated models of structures from C{self.L{outline<barBatchReconstructor.outline>}} and append them to the scene as translucent context actors. """ for name in self.outline: filename = self.__getFileName(name, 'exportToVTKPolydata') if os.path.exists(filename): self.vtkapp.appendContextActor(\ name,\ filename,\ (0,0,0), # to be overwritten ;) BAR_BRAIN_OUTLINE_PROPS) else: debugOutput("File %s not found." % filename, error=True) self.vtkapp.refreshRenderWindow()
def prepareLoop(self, structureNames): """ Prepare the reconstruction queues L{_simpleQueue} and L{_compositeQueue} to perform requested reconstructions. @param structureNames: roots of hierarchy subtrees @type structureNames: [str, ...] """ # filter requested structures to preserve existing ones validNames = set(name for name in structureNames if name in self.sh.ih.groups) # if any of requested structures does not exist for name in set(structureNames) - validNames: debugOutput("Structure %s not found." % name, error=True) # get names of hierarchy subtrees nodes uniqueNames = self.sh.ih.unfoldSubtrees(validNames, self.depth, leavesOnly=False) # and request performing of their simple reconstructions for name in uniqueNames: self.prepareSimpleLoop(name) # if composite reconstruction is requested if self.composite: # get names of hierarchy subtrees leaf nodes components = self.sh.ih.unfoldSubtrees(validNames, self.depth, leavesOnly=True) # combine their names into reconstruction name name = 'composite_%d_structures_%X' % ( len(components), crc32('_'.join(sorted(list(components)))) & 0xffffffff) # and request the reconstruction self.prepareCompositeLoop(name, components)
def _basicSetup(self, vtkapp, options): """ Constructor code common with derivative classes constructor. @param vtkapp: C{self.L{vtkapp}} value @type vtkapp: L{barReconstructionModule} object @param options: an object containing constructor options as its attributes: - C{cameraMovementAngles} - C{self.L{vtkapp}.L{cameraPosition<barReconstructionModule.cameraPosition>}} and C{self.L{vtkapp}.L{cameraViewUp<barReconstructionModule.cameraViewUp>}} values encoded as camera movement angles, - C{parallel} - C{self.L{vtkapp}.L{parallelProjection<barReconstructionModule.parallelProjection>}} value, - C{background} - C{self.L{vtkapp}.L{background<barReconstructionModule.background>}}, - C{voxelDimensions} - C{(self.L{xyres}, self.L{zres})} value, - C{exportDir} - C{self.L{exportDir}} value, - C{generateSubstructures} - C{self.L{depth}} value, - C{format} - C{self.L{formats}} members list, - C{show} - C{self.L{show}} value, - C{brainoutline} - legacy option, indicates if the root structure of the hierarchy tree has to be appended to C{self.L{outline}}, - C{outline} - structures to be included in C{self.L{outline}}, - C{composite} - C{self.L{composite}} value; if True forces C{'exportToVTKPolydata' in self.L{formats}}, - C{ignoreBoundingBox} - C{self.L{ignoreBoundingBox}}. Overrides bounding box calculation - bounding box will be always equal to hierarchy root element bounding box. Volumes for all structures will always have the same size and origin. This feature increases memory usage and reconstruction time. @type options: optparse.Values object """ self.vtkapp = vtkapp # Process options self.vtkapp.background = intColourToFloat(options.background) self.cameraMovementAngles = options.cameraMovementAngles self.parallel = options.parallel if options.voxelDimensions != None: self.xyres, self.zres = options.voxelDimensions if options.exportDir != None: self.exportDir = options.exportDir if options.outline: # check whether every group requested as an outline exists self.outline = set(options.outline) invalidGroups = self.outline - set(self.sh.ih.groups) if len(invalidGroups) > 0: # if not - report it and try to fix for name in invalidGroups: debugOutput("Structure %s not found." % name, error = True) self.outline -= validGroups else: self.outline = set() if options.brainoutline: self.outline.add(self.sh.ih.hierarchyRootElementName) self.depth = options.generateSubstructures self.formats = set() if options.format != None: self.formats = set(options.format) self.show = options.show self.composite = options.composite self.ignoreBoundingBox = options.ignoreBoundingBox #---------------------- done with options # Proceed with VTK setup # Create the RenderWindow and RenderWindowInteractor self.renWin = vtk.vtkRenderWindow() self.renWin.SetSize(800,600) self.vtkapp.addRenderWindow(self.renWin) self.iren = vtk.vtkRenderWindowInteractor() self.iren.SetRenderWindow(self.renWin) self.iren.Initialize() self._simpleQueue = [] self._compositeQueue = []
def _basicSetup(self, vtkapp, options): """ Constructor code common with derivative classes constructor. @param vtkapp: C{self.L{vtkapp}} value @type vtkapp: L{barReconstructionModule} object @param options: an object containing constructor options as its attributes: - C{cameraMovementAngles} - C{self.L{vtkapp}.L{cameraPosition<barReconstructionModule.cameraPosition>}} and C{self.L{vtkapp}.L{cameraViewUp<barReconstructionModule.cameraViewUp>}} values encoded as camera movement angles, - C{parallel} - C{self.L{vtkapp}.L{parallelProjection<barReconstructionModule.parallelProjection>}} value, - C{background} - C{self.L{vtkapp}.L{background<barReconstructionModule.background>}}, - C{voxelDimensions} - C{(self.L{xyres}, self.L{zres})} value, - C{exportDir} - C{self.L{exportDir}} value, - C{generateSubstructures} - C{self.L{depth}} value, - C{format} - C{self.L{formats}} members list, - C{show} - C{self.L{show}} value, - C{brainoutline} - legacy option, indicates if the root structure of the hierarchy tree has to be appended to C{self.L{outline}}, - C{outline} - structures to be included in C{self.L{outline}}, - C{composite} - C{self.L{composite}} value; if True forces C{'exportToVTKPolydata' in self.L{formats}}, - C{ignoreBoundingBox} - C{self.L{ignoreBoundingBox}}. Overrides bounding box calculation - bounding box will be always equal to hierarchy root element bounding box. Volumes for all structures will always have the same size and origin. This feature increases memory usage and reconstruction time. @type options: optparse.Values object """ self.vtkapp = vtkapp # Process options self.vtkapp.background = intColourToFloat(options.background) self.cameraMovementAngles = options.cameraMovementAngles self.parallel = options.parallel if options.voxelDimensions != None: self.xyres, self.zres = options.voxelDimensions if options.exportDir != None: self.exportDir = options.exportDir if options.outline: # check whether every group requested as an outline exists self.outline = set(options.outline) invalidGroups = self.outline - set(self.sh.ih.groups) if len(invalidGroups) > 0: # if not - report it and try to fix for name in invalidGroups: debugOutput("Structure %s not found." % name, error=True) self.outline -= validGroups else: self.outline = set() if options.brainoutline: self.outline.add(self.sh.ih.hierarchyRootElementName) self.depth = options.generateSubstructures self.formats = set() if options.format != None: self.formats = set(options.format) self.show = options.show self.composite = options.composite self.ignoreBoundingBox = options.ignoreBoundingBox #---------------------- done with options # Proceed with VTK setup # Create the RenderWindow and RenderWindowInteractor self.renWin = vtk.vtkRenderWindow() self.renWin.SetSize(800, 600) self.vtkapp.addRenderWindow(self.renWin) self.iren = vtk.vtkRenderWindowInteractor() self.iren.SetRenderWindow(self.renWin) self.iren.Initialize() self._simpleQueue = [] self._compositeQueue = []