Esempio n. 1
0
	def updateRendering(self, e1 = None, e2 = None):
		"""
		Update the Rendering of this module
		"""             
		#self.mapper.Update()
		VisualizationModule.updateRendering(self, input)
		self.wxrenwin.Render()    
Esempio n. 2
0
	def updateRendering(self):
		"""
		Update the Rendering of this module
		"""
		filename = self.parameters["FileName"]
		if not os.path.exists(filename) or not self.enabled:
			return

		self.reader.SetFileName(filename)
		self.reader.SetHBScale(1.0)
		self.reader.SetBScale(1.0)

		self.sphereSource.SetRadius(self.parameters['SphereRadius'])
		self.tubeFilter.SetRadius(self.parameters['TubeRadius'])
		
		self.glyph3D.SetInputConnection(self.reader.GetOutputPort())
		self.mapper.SetInputConnection(self.glyph3D.GetOutputPort())
		self.tubeFilter.SetInputConnection(self.reader.GetOutputPort())
		self.mapper2.SetInputConnection(self.tubeFilter.GetOutputPort())
		
		if not self.actorsInitialized:
			self.renderer.AddActor(self.tubeActor)
			self.renderer.AddActor(self.actor)
			self.actorsInitialized = True

		self.mapper.Update()
		VisualizationModule.updateRendering(self)
		self.parent.Render()
Esempio n. 3
0
    def updateRendering(self):
        """
		Update the Rendering of this module
		"""
        if self.useOutline:
            self.outline.SetInput(self.data)
            self.outlineMapper.SetInput(self.outline.GetOutput())
            self.outlineMapper.Update()

        if self.renew:
            self.planeWidgetX.SetInput(self.data)
            self.planeWidgetZ.SetInput(self.data)
            self.planeWidgetY.SetInput(self.data)
            self.renew = 0
            for i in ["X", "Y", "Z"]:
                eval("self.planeWidget%s.SetPlaneOrientationTo%sAxes()" %
                     (i, i))
        self.planeWidgetX.SetSliceIndex(self.x)
        self.planeWidgetY.SetSliceIndex(self.y)
        self.planeWidgetZ.SetSliceIndex(self.z)

        if not self.on:
            self.planeWidgetX.On()
            self.planeWidgetY.On()
            self.planeWidgetZ.On()
            self.on = 1

        #self.mapper.Update()
        VisualizationModule.updateRendering(self, input)
        self.parent.Render()
	def updateRendering(self):
		"""
		Update the Rendering of this module
		"""
		if self.useOutline:
			self.outline.SetInput(self.data)
			self.outlineMapper.SetInput(self.outline.GetOutput())
			self.outlineMapper.Update()

		if self.renew:
			self.planeWidgetX.SetInput(self.data)
			self.planeWidgetZ.SetInput(self.data)
			self.planeWidgetY.SetInput(self.data)
			self.renew = 0
			for i in ["X", "Y", "Z"]:
				eval("self.planeWidget%s.SetPlaneOrientationTo%sAxes()" % (i, i))            
		self.planeWidgetX.SetSliceIndex(self.x)
		self.planeWidgetY.SetSliceIndex(self.y)
		self.planeWidgetZ.SetSliceIndex(self.z)
		
		if not self.on:
			self.planeWidgetX.On()
			self.planeWidgetY.On()
			self.planeWidgetZ.On()
			self.on = 1
		
		#self.mapper.Update()
		VisualizationModule.updateRendering(self, input)
		self.parent.Render()    
Esempio n. 5
0
    def updateRendering(self):
        """
		Update the Rendering of this module
		"""
        data = self.getInput(1)
        x, y, z = self.dataUnit.getDimensions()
        data = optimize.optimize(image=data,
                                 updateExtent=(0, x - 1, 0, y - 1, 0, z - 1))
        if data.GetNumberOfScalarComponents() > 3:
            extract = vtk.vtkImageExtractComponents()
            extract.SetInput(data)
            extract.SetComponents(1, 1, 1)
            data = extract.GetOutput()
        if data.GetNumberOfScalarComponents() > 1:
            self.luminance.SetInput(data)
            data = self.luminance.GetOutput()

        z = self.parameters["Slice"]
        ext = (0, x - 1, 0, y - 1, z, z)

        voi = vtk.vtkExtractVOI()
        voi.SetVOI(ext)
        voi.SetInput(data)
        slice = voi.GetOutput()
        self.geometry.SetInput(slice)

        self.warp.SetInput(self.geometry.GetOutput())
        self.warp.SetScaleFactor(self.parameters["Scale"])
        self.merge.SetGeometry(self.warp.GetOutput())

        if slice.GetNumberOfScalarComponents() == 1:
            maptocol = vtk.vtkImageMapToColors()
            ctf = self.getInputDataUnit(1).getColorTransferFunction()
            maptocol.SetInput(slice)
            maptocol.SetLookupTable(ctf)
            maptocol.Update()
            scalars = maptocol.GetOutput()
        else:
            scalars = slice

        self.merge.SetScalars(scalars)
        data = self.merge.GetOutput()

        if self.parameters["Normals"]:
            self.normals.SetInput(data)
            self.normals.SetFeatureAngle(self.parameters["FeatureAngle"])
            print "Feature angle=", self.parameters["FeatureAngle"]
            data = self.normals.GetOutput()

        self.mapper.SetInput(data)
        self.mapper.Update()
        VisualizationModule.updateRendering(self)
        self.parent.Render()
	def updateRendering(self):
		"""
		Update the Rendering of this module
		"""
		data = self.getInput(1)
		x,y,z = self.dataUnit.getDimensions()
		data = optimize.optimize(image = data, updateExtent = (0, x-1, 0, y-1, 0, z-1))
		if data.GetNumberOfScalarComponents() > 3:
			extract = vtk.vtkImageExtractComponents()
			extract.SetInput(data)
			extract.SetComponents(1, 1, 1)
			data = extract.GetOutput()
		if data.GetNumberOfScalarComponents() > 1:
			self.luminance.SetInput(data)
			data = self.luminance.GetOutput()
		
		z = self.parameters["Slice"]
		ext = (0, x - 1, 0, y - 1, z, z)

		voi = vtk.vtkExtractVOI()
		voi.SetVOI(ext)
		voi.SetInput(data)
		slice = voi.GetOutput()
		self.geometry.SetInput(slice)         
		
		self.warp.SetInput(self.geometry.GetOutput())
		self.warp.SetScaleFactor(self.parameters["Scale"])		
		self.merge.SetGeometry(self.warp.GetOutput())
		
		if slice.GetNumberOfScalarComponents() == 1:
			maptocol = vtk.vtkImageMapToColors()
			ctf = self.getInputDataUnit(1).getColorTransferFunction()
			maptocol.SetInput(slice)
			maptocol.SetLookupTable(ctf)
			maptocol.Update()
			scalars = maptocol.GetOutput()
		else:
			scalars = slice
			
		self.merge.SetScalars(scalars)
		data = self.merge.GetOutput()
		
		if self.parameters["Normals"]:
			self.normals.SetInput(data)
			self.normals.SetFeatureAngle(self.parameters["FeatureAngle"])
			print "Feature angle=", self.parameters["FeatureAngle"]            
			data = self.normals.GetOutput()
		
		self.mapper.SetInput(data)
		self.mapper.Update()
		VisualizationModule.updateRendering(self)
		self.parent.Render()
Esempio n. 7
0
    def updateRendering(self, input=None):
        """
		Update the Rendering of this module
		"""
        self.updateMethod()
        self.updateQuality()
        self.updateInterpolation()
        self.setShading(self.parameters["UseShading"])

        if not input:
            input = self.getInput(1)
        x, y, z = self.dataUnit.getDimensions()

        input = optimize.optimize(image=input,
                                  updateExtent=(0, x - 1, 0, y - 1, 0, z - 1))

        ncomps = input.GetNumberOfScalarComponents()
        Logging.info("Number of comps=", ncomps, kw="rendering")
        dataType = input.GetScalarType()
        if (ncomps > 1 or dataType not in [3, 5]
            ) and self.parameters["Method"] == TEXTURE_MAPPING:
            self.setParameter("Method", 0)
            lib.messenger.send(None, "update_module_settings")
        if ncomps > 1:
            self.volumeProperty.IndependentComponentsOff()
        else:
            self.volumeProperty.IndependentComponentsOn()

        Logging.info("Rendering using, ",
                     self.mapper.__class__,
                     kw="rendering")
        self.mapper.SetInput(input)
        if self.mapperUpdated:
            self.volume.SetMapper(self.mapper)
            self.mapperUpdated = False
        if not self.volumeAdded:
            self.parent.getRenderer().AddVolume(self.volume)
            self.volumeAdded = True

        VisualizationModule.updateRendering(self, input)
        self.parent.Render()
        if self.parameters["Method"] == TEXTURE_MAPPING_3D:
            if not self.mapper.IsRenderSupported(self.volumeProperty,
                                                 self.renderer):
                lib.messenger.send(None, \
                    "show_error", \
                    "3D texture mapping not supported", \
                    "Your graphics hardware does not support 3D accelerated texture mapping. \
								Please use one of the other volume rendering methods."                                                                          )
Esempio n. 8
0
    def updateRendering(self):
        """
		Method: updateRendering()
		Update the Rendering of this module
		"""
        if self.renew:
            self.spline.SetInput(self.data)

        if not self.on:
            self.spline.On()
            self.on = 1

        #self.mapper.Update()
        VisualizationModule.updateRendering(self, input)
        self.parent.Render()
	def updateRendering(self):
		"""
		Update the Rendering of this module
		"""
		input = self.getInput(1)
		if self.parameters["InsideOut"]:
			self.boxWidget.InsideOutOn()
		else:
			self.boxWidget.InsideOutOff()
		self.boxWidget.SetInput(input)
#        self.mapper.SetInput(data)
		
		#self.mapper.Update()
		VisualizationModule.updateRendering(self)
		self.parent.Render()
	def updateRendering(self):
		"""
		Method: updateRendering()
		Update the Rendering of this module
		"""             
		if self.renew:
			self.spline.SetInput(self.data)
		
		if not self.on:
			self.spline.On()
			self.on = 1
		
		#self.mapper.Update()
		VisualizationModule.updateRendering(self, input)
		self.parent.Render()    
Esempio n. 11
0
	def updateRendering(self):
		"""
		Update the Rendering of this module
		"""             
		
		if self.renew:
			self.renew = 0
		
		if not self.on:
			self.angleWidget.On()
			self.on = 1
		
		#self.mapper.Update()
		VisualizationModule.updateRendering(self, input)
		self.parent.Render()    
Esempio n. 12
0
    def updateRendering(self):
        """
		Update the Rendering of this module
		"""
        input = self.getInput(1)
        if self.parameters["InsideOut"]:
            self.boxWidget.InsideOutOn()
        else:
            self.boxWidget.InsideOutOff()
        self.boxWidget.SetInput(input)
        #        self.mapper.SetInput(data)

        #self.mapper.Update()
        VisualizationModule.updateRendering(self)
        self.parent.Render()
	def updateRendering(self, input = None):
		"""
		Update the Rendering of this module
		"""
		self.updateMethod()
		self.updateQuality()
		self.updateInterpolation()
		self.setShading(self.parameters["UseShading"])
		
		if not input:
			input = self.getInput(1)
		x, y, z = self.dataUnit.getDimensions()

		input = optimize.optimize(image = input, updateExtent = (0, x - 1, 0, y - 1, 0, z - 1))
		
		ncomps = input.GetNumberOfScalarComponents()
		Logging.info("Number of comps=", ncomps, kw = "rendering")
		dataType = input.GetScalarType()
		if (ncomps > 1 or dataType not in [3, 5]) and self.parameters["Method"] == TEXTURE_MAPPING:
			self.setParameter("Method", 0)
			lib.messenger.send(None, "update_module_settings")
		if ncomps > 1:
			self.volumeProperty.IndependentComponentsOff()
		else:
			self.volumeProperty.IndependentComponentsOn()
			
		Logging.info("Rendering using, ", self.mapper.__class__, kw = "rendering")
		self.mapper.SetInput(input)
		if self.mapperUpdated:
			self.volume.SetMapper(self.mapper)
			self.mapperUpdated = False
		if not self.volumeAdded:
			self.parent.getRenderer().AddVolume(self.volume)
			self.volumeAdded = True
			
		VisualizationModule.updateRendering(self, input)
		self.parent.Render()
		if self.parameters["Method"] == TEXTURE_MAPPING_3D:
			if not self.mapper.IsRenderSupported(self.volumeProperty, self.renderer):
				lib.messenger.send(None, \
								"show_error", \
								"3D texture mapping not supported", \
								"Your graphics hardware does not support 3D accelerated texture mapping. \
								Please use one of the other volume rendering methods.")
	def updateRendering(self):
		"""
		Update the Rendering of this module
		"""
		#self.outline.SetInput(self.data)
		#self.outlineMapper.SetInput(self.outline.GetOutput())
		
		#self.outlineMapper.Update()

		if self.renew:
			data = self.getInput(1)
			self.planeWidget.SetInput(data)
			self.renew = 0
		
		if not self.on:
			self.planeWidget.On()
			self.on = 1
		
		#self.mapper.Update()
		VisualizationModule.updateRendering(self, input)
		self.parent.Render()    
Esempio n. 15
0
    def updateRendering(self):
        """
		Update the Rendering of this module
		"""
        #self.outline.SetInput(self.data)
        #self.outlineMapper.SetInput(self.outline.GetOutput())

        #self.outlineMapper.Update()

        if self.renew:
            data = self.getInput(1)
            self.planeWidget.SetInput(data)
            self.renew = 0

        if not self.on:
            self.planeWidget.On()
            self.on = 1

        #self.mapper.Update()
        VisualizationModule.updateRendering(self, input)
        self.parent.Render()
Esempio n. 16
0
    def updateRendering(self):
        """
		Method: updateRendering()
		Update the Rendering of this module
		"""
        self.outline.SetInput(self.data)
        self.outlineMapper.SetInput(self.outline.GetOutput())

        self.outlineMapper.Update()

        if self.renew:
            for planeWidget in self.planes:
                planeWidget.SetInput(self.data)
            self.renew = 0
        #self.planeWidget.SetSliceIndex(self.x)

        if not self.on:
            for planeWidget in self.planes:
                planeWidget.On()
            self.on = 1

        #self.mapper.Update()
        VisualizationModule.updateRendering(self, input)
        self.parent.Render()
Esempio n. 17
0
	def updateRendering(self):
		"""
		Update the Rendering of this module
		"""
		self.mapper.AddObserver("ProgressEvent", lib.messenger.send)
		lib.messenger.connect(self.mapper, 'ProgressEvent', self.updateProgress)
		dataUnit = self.getInputDataUnit(1)
		inputDataUnit2 = self.getInputDataUnit(2)
	
		settings = inputDataUnit2.getSettings()
		filterList = settings.get("FilterList")
	
		if not dataUnit:
			dataUnit = self.dataUnit
		self.mapper.SetLookupTable(dataUnit.getColorTransferFunction())
		self.mapper.ScalarVisibilityOn()
		
		min, max = self.data.GetScalarRange()
		
		#if (min,max) != self.scalarRange:
		self.setScalarRange(min, max)
		
		dataUnit = self.getInputDataUnit(1)
		self.mapper.ColorByArrayComponent(0, 0)
		self.mapper.SetScalarRange(min, max)
		self.mapper.SetColorModeToMapScalars()
		self.mapper.SetLookupTable(dataUnit.getColorTransferFunction())
		self.mapper.ScalarVisibilityOn()
		
		self.updateOpacity()
		#self.actor2.GetProperty().SetOpacity(opacity)
		
		polyinput = self.getPolyDataInput(1)
		if polyinput:
			Logging.info("Using polydata input", kw="visualizer")
			VisualizationModule.updateRendering(self, polyinput)
		else:
			input = self.getInput(1)
		
			x, y, z = self.dataUnit.getDimensions()
			input = optimize.optimize(image = input, updateExtent = (0, x - 1, 0, y - 1, 0, z - 1))
			self.contour.SetInput(input)
			polyinput = self.contour.GetOutput()

		input2 = self.getInput(2)
		minval, maxval = input2.GetScalarRange()
		
		input2.Update()
		self.contour2.SetInput(input2)
		print "Generating",maxval-1,"values in range",1,maxval
		self.contour2.GenerateValues(maxval-1, 1, maxval)
		n = self.contour2.GetNumberOfContours()
		for i in range(0, n):
			self.contour2.SetValue(i, int(self.contour2.GetValue(i)))

		self.mapper2.ColorByArrayComponent(0, 0)
		self.mapper2.SetScalarRange(min, max)
		
		if not self.parameters["MarkColor"]:
			self.mapper2.SetLookupTable(inputDataUnit2.getColorTransferFunction())
		else:
			self.setLookupTableBasedOnDistance(self.parameters["Distance"])

		print "\n\n\n*** INPUT DATAUNIT2=",inputDataUnit2
		self.mapper2.SetColorModeToMapScalars()
		self.mapper2.ScalarVisibilityOn()
			
		polyinput2 = self.contour2.GetOutput()

		decimateLevel = self.parameters["Simplify"] 
		preserveTopology = self.parameters["PreserveTopology"] 
		if decimateLevel != 0:            
			self.decimate.SetPreserveTopology(preserveTopology)
			if not preserveTopology:
				self.decimate.SplittingOn()
				self.decimate.BoundaryVertexDeletionOn()
			else:
				self.decimate.SplittingOff()
				self.decimate.BoundaryVertexDeletionOff()
			self.decimate.SetTargetReduction(decimateLevel / 100.0)
			
			Logging.info("Decimating %.2f%%, preserve topology: %s" \
						% (decimateLevel, preserveTopology), kw = "visualizer")
			self.decimate.SetInput(polyinput)
			polyinput = self.decimate.GetOutput()
		
		
		if self.parameters["Normals"]:
			angle = self.parameters["FeatureAngle"]
			Logging.info("Generating normals at angle", angle, kw = "visualizer")
			self.normals.SetFeatureAngle(angle)
			self.normals.SetInput(polyinput)
			polyinput = self.normals.GetOutput()
		
		self.mapper.SetInput(polyinput)
		self.mapper2.SetInput(polyinput2)
		self.init = True
		VisualizationModule.updateRendering(self, polyinput)
		self.parent.Render()    
    def updateRendering(self):
        """
		Update the Rendering of this module
		"""
        self.mapper.AddObserver("ProgressEvent", lib.messenger.send)
        lib.messenger.connect(self.mapper, "ProgressEvent", self.updateProgress)
        dataUnit = self.getInputDataUnit(1)
        inputDataUnit2 = self.getInputDataUnit(2)

        settings = inputDataUnit2.getSettings()
        filterList = settings.get("FilterList")

        if not dataUnit:
            dataUnit = self.dataUnit
        self.mapper.SetLookupTable(dataUnit.getColorTransferFunction())
        self.mapper.ScalarVisibilityOn()

        min, max = self.data.GetScalarRange()

        # if (min,max) != self.scalarRange:
        self.setScalarRange(min, max)

        dataUnit = self.getInputDataUnit(1)
        self.mapper.ColorByArrayComponent(0, 0)
        self.mapper.SetScalarRange(min, max)
        self.mapper.SetColorModeToMapScalars()
        self.mapper.SetLookupTable(dataUnit.getColorTransferFunction())
        self.mapper.ScalarVisibilityOn()

        self.updateOpacity()
        # self.actor2.GetProperty().SetOpacity(opacity)

        polyinput = self.getPolyDataInput(1)
        if polyinput:
            Logging.info("Using polydata input", kw="visualizer")
            VisualizationModule.updateRendering(self, polyinput)
        else:
            input = self.getInput(1)

            x, y, z = self.dataUnit.getDimensions()
            input = optimize.optimize(image=input, updateExtent=(0, x - 1, 0, y - 1, 0, z - 1))
            self.contour.SetInput(input)
            polyinput = self.contour.GetOutput()

        input2 = self.getInput(2)
        minval, maxval = input2.GetScalarRange()

        input2.Update()
        self.contour2.SetInput(input2)
        print "Generating", maxval - 1, "values in range", 1, maxval
        self.contour2.GenerateValues(maxval - 1, 1, maxval)
        n = self.contour2.GetNumberOfContours()
        for i in range(0, n):
            self.contour2.SetValue(i, int(self.contour2.GetValue(i)))

        self.mapper2.ColorByArrayComponent(0, 0)
        self.mapper2.SetScalarRange(min, max)

        if not self.parameters["MarkColor"]:
            self.mapper2.SetLookupTable(inputDataUnit2.getColorTransferFunction())
        else:
            self.setLookupTableBasedOnDistance(self.parameters["Distance"])

        print "\n\n\n*** INPUT DATAUNIT2=", inputDataUnit2
        self.mapper2.SetColorModeToMapScalars()
        self.mapper2.ScalarVisibilityOn()

        polyinput2 = self.contour2.GetOutput()

        decimateLevel = self.parameters["Simplify"]
        preserveTopology = self.parameters["PreserveTopology"]
        if decimateLevel != 0:
            self.decimate.SetPreserveTopology(preserveTopology)
            if not preserveTopology:
                self.decimate.SplittingOn()
                self.decimate.BoundaryVertexDeletionOn()
            else:
                self.decimate.SplittingOff()
                self.decimate.BoundaryVertexDeletionOff()
            self.decimate.SetTargetReduction(decimateLevel / 100.0)

            Logging.info(
                "Decimating %.2f%%, preserve topology: %s" % (decimateLevel, preserveTopology), kw="visualizer"
            )
            self.decimate.SetInput(polyinput)
            polyinput = self.decimate.GetOutput()

        if self.parameters["Normals"]:
            angle = self.parameters["FeatureAngle"]
            Logging.info("Generating normals at angle", angle, kw="visualizer")
            self.normals.SetFeatureAngle(angle)
            self.normals.SetInput(polyinput)
            polyinput = self.normals.GetOutput()

        self.mapper.SetInput(polyinput)
        self.mapper2.SetInput(polyinput2)
        self.init = True
        VisualizationModule.updateRendering(self, polyinput)
        self.parent.Render()
    def updateRendering(self):
        """
		Update the Rendering of this module
		"""
        method = self.parameters["Method"]
        self.setMethod(method)

        if self.volumeModule:
            self.volumeModule.function = vtk.vtkVolumeRayCastIsosurfaceFunction()
            self.volumeModule.function.SetIsoValue(self.parameters["IsoValue"])
            self.volumeModule.showTimepoint(self.timepoint)
            return

        if not self.init:
            self.init = 1
            self.mapper.ColorByArrayComponent(0, 0)
        self.mapper.AddObserver("ProgressEvent", lib.messenger.send)
        lib.messenger.connect(self.mapper, "ProgressEvent", self.updateProgress)
        dataUnit = self.getInputDataUnit(1)
        if not dataUnit:
            dataUnit = self.dataUnit
        dataCtf = dataUnit.getColorTransferFunction()
        if self.parameters["SolidColor"]:
            minval, maxval = dataCtf.GetRange()
            ctf = vtk.vtkColorTransferFunction()
            ctf.AddRGBPoint(int(minval), 0, 0, 0)
            r, g, b = dataCtf.GetColor(maxval)
            ctf.AddRGBPoint(int(minval) + 1, r, g, b)
            ctf.AddRGBPoint(maxval, r, g, b)
        else:
            ctf = dataCtf
        self.mapper.SetLookupTable(ctf)
        self.mapper.ScalarVisibilityOn()

        minVal, maxVal = self.data.GetScalarRange()
        self.setScalarRange(minVal, maxVal)

        self.mapper.SetScalarRange(minVal, maxVal)
        self.mapper.SetColorModeToMapScalars()

        opacity = self.parameters["Transparency"]
        opacity = (100 - opacity) / 100.0
        Logging.info("Using opacity ", opacity, kw="visualizer")
        if opacity != 1:
            cullers = self.parent.getRenderer().GetCullers()
            cullers.InitTraversal()
            culler = cullers.GetNextItem()
            culler.SetSortingStyleToBackToFront()
            # print cullers, culler
            # self.parent.getRenderer().GetRenderWindow().SetAlphaBitPlanes(1)
            # self.parent.getRenderer().GetRenderWindow().SetMultiSamples(0)
            # self.parent.getRenderer().SetUseDepthPeeling(1)
            # self.parent.getRenderer().SetMaximumNumberOfPeels(100)
            # self.parent.getRenderer().SetOcclusionRatio(1.0)
            # print self.parent.getRenderer().GetLastRenderingUsedDepthPeeling()

        self.actor.GetProperty().SetOpacity(opacity)

        polyinput = self.getPolyDataInput(1)
        if polyinput:
            Logging.info("Using polydata input", kw="visualizer")
            self.mapper.SetInput(polyinput)
            VisualizationModule.updateRendering(self, polyinput)
            self.parent.Render()
            return

        x, y, z = self.dataUnit.getDimensions()
        input = self.getInput(1)
        input = optimize.optimize(image=input, updateExtent=(0, x - 1, 0, y - 1, 0, z - 1))

        if self.parameters["Gaussian"]:
            Logging.info("Doing gaussian smoothing", kw="visualizer")
            if not self.smooth:
                self.smooth = vtk.vtkImageGaussianSmooth()
            self.smooth.SetInput(input)
            input = self.smooth.GetOutput()

        self.contour.SetInput(input)
        input = self.contour.GetOutput()

        multi = self.parameters["MultipleSurfaces"]

        if not multi:
            Logging.info("Using single isovalue=%d" % int(self.parameters["IsoValue"]), kw="visualizer")
            self.contour.SetValue(0, self.parameters["IsoValue"])
        else:
            begin = self.parameters["SurfaceRangeBegin"]
            end = self.parameters["SurfaceRangeEnd"]
            n = self.parameters["SurfaceAmnt"]
            Logging.info("Generating %d values in range %d-%d" % (n, begin, end), kw="visualizer")
            self.contour.GenerateValues(n, begin, end)
            n = self.contour.GetNumberOfContours()
            for i in range(0, n):
                self.contour.SetValue(i, int(self.contour.GetValue(i)))
                # print self.contour

                # TODO: should decimateLevel and preserveTopology be instance variables?
        decimateLevel = self.parameters["Simplify"]
        preserveTopology = self.parameters["PreserveTopology"]
        if decimateLevel != 0:
            self.decimate.SetPreserveTopology(preserveTopology)
            if not preserveTopology:
                self.decimate.SplittingOn()
                self.decimate.BoundaryVertexDeletionOn()
            else:
                self.decimate.SplittingOff()
                self.decimate.BoundaryVertexDeletionOff()
            self.decimate.SetTargetReduction(decimateLevel / 100.0)

            Logging.info(
                "Decimating %.2f%%, preserve topology: %s" % (decimateLevel, preserveTopology), kw="visualizer"
            )
            self.decimate.SetInput(input)
            input = self.decimate.GetOutput()

        if self.parameters["Normals"]:
            angle = self.parameters["FeatureAngle"]
            Logging.info("Generating normals at angle", angle, kw="visualizer")
            self.normals.SetFeatureAngle(angle)
            self.normals.SetInput(input)
            input = self.normals.GetOutput()

        self.mapper.SetInput(input)
        VisualizationModule.updateRendering(self, input)
        self.parent.Render()
Esempio n. 20
0
	def updateRendering(self):
		"""
		Update the Rendering of this module
		"""
		for actor in self.actors:
			self.renderer.RemoveActor(actor)
		self.actors = []
		if self.showTracks:
			edges = vtk.vtkCellArray()
			inputUnit = self.getInputDataUnit(1)
			timepoint = scripting.visualizer.getTimepoint()
			timepoints = scripting.visualizer.getNumberOfTimepoints()

			tubeRadius = self.parameters["TubeRadius"]
			sphereRadius = self.parameters["SphereRadius"]

			tracks = self.getPoints(self.showTracks)
			appendLines  = vtk.vtkAppendPolyData()
			appendSpheres = vtk.vtkAppendPolyData()
			appendFirst = vtk.vtkAppendPolyData()
			appendLast = vtk.vtkAppendPolyData()
			appendCurrent = vtk.vtkAppendPolyData()
			
			lineactor = vtk.vtkActor()
			lineactor.SetMapper(self.lineMapper)
			lineactor.GetProperty().SetDiffuseColor(1, 1, 1)
			spheresActor = vtk.vtkActor()
			spheresActor.SetMapper(self.sphereMapper)
			spheresActor.GetProperty().SetDiffuseColor(0, 1, 1)
			
			firstActor = vtk.vtkActor()
			firstActor.SetMapper(self.firstMapper)
			firstActor.GetProperty().SetDiffuseColor(0, 1, 0)
			
			lastActor = vtk.vtkActor()
			lastActor.SetMapper(self.lastMapper)
			lastActor.GetProperty().SetDiffuseColor(1, 0, 0)
			
			currentActor = vtk.vtkActor()
			currentActor.SetMapper(self.currentMapper)
			currentActor.GetProperty().SetDiffuseColor(0, 0, 1)
			
			dataw, datay, dataz = inputUnit.getDimensions()
			for track in tracks:
				dx, dy, dz = 0,0,0
				if self.parameters["SameStartingPoint"]:
					dx = -track[0][1][0]
					dy = -track[0][1][1]
					dz = -track[0][1][2]
					dx += dataw/2
					dy += datay/2
					dz += dataz/2

				for i, (t,(x, y, z)) in enumerate(track[:-1]):
					x += dx
					y += dy
					z += dz
					t2, (x2,y2,z2) = track[i + 1]
					x2 += dx
					y2 += dy
					z2 += dz

					if x != x2 or y != y2 or z != z2:
						linesource = vtk.vtkLineSource()
						linesource.SetPoint1(x, y, z)
						linesource.SetPoint2(x2, y2, z2)
						tubeFilter = vtk.vtkTubeFilter()
						tubeFilter.SetRadius(tubeRadius)
						tubeFilter.SetNumberOfSides(10)
						tubeFilter.SetInput(linesource.GetOutput())
						appendLines.AddInput(tubeFilter.GetOutput())
					
					sph = vtk.vtkSphereSource()
					sph.SetPhiResolution(20)
					sph.SetThetaResolution(20)
					sph.SetCenter(x, y, z)
					sph.SetRadius(sphereRadius)
					
					if t == timepoint:
						appendCurrent.AddInput(sph.GetOutput())
					elif i != 0:
						appendSpheres.AddInput(sph.GetOutput())

				if timepoint != track[0][0]:
					sph = vtk.vtkSphereSource()
					sph.SetPhiResolution(20)
					sph.SetThetaResolution(20)
					x,y,z = track[0][1]
					x += dx
					y += dy
					z += dz
					sph.SetCenter((x,y,z))
					sph.SetRadius(sphereRadius)
					appendFirst.AddInput(sph.GetOutput())

				sph = vtk.vtkSphereSource()
				sph.SetPhiResolution(20)
				sph.SetThetaResolution(20)
				x,y,z = track[-1][1]
				x += dx
				y += dy
				z += dz
				sph.SetCenter((x,y,z))
				sph.SetRadius(sphereRadius)
				if timepoint != track[-1][0]:
					appendLast.AddInput(sph.GetOutput())
				else:
					appendCurrent.AddInput(sph.GetOutput())

			self.currentMapper.SetInput(appendCurrent.GetOutput())
			self.sphereMapper.SetInput(appendSpheres.GetOutput())
			self.lineMapper.SetInput(appendLines.GetOutput())
			self.firstMapper.SetInput(appendFirst.GetOutput())
			self.lastMapper.SetInput(appendLast.GetOutput())

			#self.mapper.SetInput(append.GetOutput())
			if appendCurrent.GetNumberOfInputConnections(0) > 0:
				self.currentMapper.Update()
				self.actors.append(currentActor)
			if appendLines.GetNumberOfInputConnections(0) > 0:
				self.lineMapper.Update()
				self.actors.append(lineactor)
			if appendSpheres.GetNumberOfInputConnections(0) > 0:
				self.sphereMapper.Update()
				self.actors.append(spheresActor)
			if appendFirst.GetNumberOfInputConnections(0) > 0:
				self.firstMapper.Update()
				self.actors.append(firstActor)
			if appendLast.GetNumberOfInputConnections(0) > 0:
				self.lastMapper.Update()
				self.actors.append(lastActor)
			
			for actor in self.actors:
				self.renderer.AddActor(actor)
			
			VisualizationModule.updateRendering(self)
			self.parent.Render()
Esempio n. 21
0
    def updateRendering(self):
        """
		Update the Rendering of this module
		"""
        method = self.parameters["Method"]
        self.setMethod(method)

        if self.volumeModule:
            self.volumeModule.function = vtk.vtkVolumeRayCastIsosurfaceFunction(
            )
            self.volumeModule.function.SetIsoValue(self.parameters["IsoValue"])
            self.volumeModule.showTimepoint(self.timepoint)
            return

        if not self.init:
            self.init = 1
            self.mapper.ColorByArrayComponent(0, 0)
        self.mapper.AddObserver("ProgressEvent", lib.messenger.send)
        lib.messenger.connect(self.mapper, 'ProgressEvent',
                              self.updateProgress)
        dataUnit = self.getInputDataUnit(1)
        if not dataUnit:
            dataUnit = self.dataUnit
        dataCtf = dataUnit.getColorTransferFunction()
        if self.parameters["SolidColor"]:
            minval, maxval = dataCtf.GetRange()
            ctf = vtk.vtkColorTransferFunction()
            ctf.AddRGBPoint(int(minval), 0, 0, 0)
            r, g, b = dataCtf.GetColor(maxval)
            ctf.AddRGBPoint(int(minval) + 1, r, g, b)
            ctf.AddRGBPoint(maxval, r, g, b)
        else:
            ctf = dataCtf
        self.mapper.SetLookupTable(ctf)
        self.mapper.ScalarVisibilityOn()

        minVal, maxVal = self.data.GetScalarRange()
        self.setScalarRange(minVal, maxVal)

        self.mapper.SetScalarRange(minVal, maxVal)
        self.mapper.SetColorModeToMapScalars()

        opacity = self.parameters["Transparency"]
        opacity = (100 - opacity) / 100.0
        Logging.info("Using opacity ", opacity, kw="visualizer")
        if opacity != 1:
            cullers = self.parent.getRenderer().GetCullers()
            cullers.InitTraversal()
            culler = cullers.GetNextItem()
            culler.SetSortingStyleToBackToFront()
            #print cullers, culler
            #self.parent.getRenderer().GetRenderWindow().SetAlphaBitPlanes(1)
            #self.parent.getRenderer().GetRenderWindow().SetMultiSamples(0)
            #self.parent.getRenderer().SetUseDepthPeeling(1)
            #self.parent.getRenderer().SetMaximumNumberOfPeels(100)
            #self.parent.getRenderer().SetOcclusionRatio(1.0)
            #print self.parent.getRenderer().GetLastRenderingUsedDepthPeeling()

        self.actor.GetProperty().SetOpacity(opacity)

        polyinput = self.getPolyDataInput(1)
        if polyinput:
            Logging.info("Using polydata input", kw="visualizer")
            self.mapper.SetInput(polyinput)
            VisualizationModule.updateRendering(self, polyinput)
            self.parent.Render()
            return

        x, y, z = self.dataUnit.getDimensions()
        input = self.getInput(1)
        input = optimize.optimize(image=input,
                                  updateExtent=(0, x - 1, 0, y - 1, 0, z - 1))

        if self.parameters["Gaussian"]:
            Logging.info("Doing gaussian smoothing", kw="visualizer")
            if not self.smooth:
                self.smooth = vtk.vtkImageGaussianSmooth()
            self.smooth.SetInput(input)
            input = self.smooth.GetOutput()

        self.contour.SetInput(input)
        input = self.contour.GetOutput()

        multi = self.parameters["MultipleSurfaces"]

        if not multi:
            Logging.info("Using single isovalue=%d" %
                         int(self.parameters["IsoValue"]),
                         kw="visualizer")
            self.contour.SetValue(0, self.parameters["IsoValue"])
        else:
            begin = self.parameters["SurfaceRangeBegin"]
            end = self.parameters["SurfaceRangeEnd"]
            n = self.parameters["SurfaceAmnt"]
            Logging.info("Generating %d values in range %d-%d" %
                         (n, begin, end),
                         kw="visualizer")
            self.contour.GenerateValues(n, begin, end)
            n = self.contour.GetNumberOfContours()
            for i in range(0, n):
                self.contour.SetValue(i, int(self.contour.GetValue(i)))
            #print self.contour

        #TODO: should decimateLevel and preserveTopology be instance variables?
        decimateLevel = self.parameters["Simplify"]
        preserveTopology = self.parameters["PreserveTopology"]
        if decimateLevel != 0:
            self.decimate.SetPreserveTopology(preserveTopology)
            if not preserveTopology:
                self.decimate.SplittingOn()
                self.decimate.BoundaryVertexDeletionOn()
            else:
                self.decimate.SplittingOff()
                self.decimate.BoundaryVertexDeletionOff()
            self.decimate.SetTargetReduction(decimateLevel / 100.0)

            Logging.info("Decimating %.2f%%, preserve topology: %s" \
               % (decimateLevel, preserveTopology), kw = "visualizer")
            self.decimate.SetInput(input)
            input = self.decimate.GetOutput()

        if self.parameters["Normals"]:
            angle = self.parameters["FeatureAngle"]
            Logging.info("Generating normals at angle", angle, kw="visualizer")
            self.normals.SetFeatureAngle(angle)
            self.normals.SetInput(input)
            input = self.normals.GetOutput()

        self.mapper.SetInput(input)
        VisualizationModule.updateRendering(self, input)
        self.parent.Render()