(self, representation, numSamples, customRange=None)
| 1792 | # RpcName: getLutImage => pv.color.manager.lut.image.get |
| 1793 | @exportRpc("pv.color.manager.lut.image.get") |
| 1794 | def getLutImage(self, representation, numSamples, customRange=None): |
| 1795 | repProxy = self.mapIdToProxy(representation) |
| 1796 | lut = repProxy.LookupTable.GetClientSideObject() |
| 1797 | |
| 1798 | dataRange = customRange |
| 1799 | if not dataRange: |
| 1800 | dataRange = lut.GetRange() |
| 1801 | |
| 1802 | delta = (dataRange[1] - dataRange[0]) / float(numSamples) |
| 1803 | |
| 1804 | colorArray = vtkUnsignedCharArray() |
| 1805 | colorArray.SetNumberOfComponents(3) |
| 1806 | colorArray.SetNumberOfTuples(numSamples) |
| 1807 | |
| 1808 | rgb = [0, 0, 0] |
| 1809 | for i in range(numSamples): |
| 1810 | lut.GetColor(dataRange[0] + float(i) * delta, rgb) |
| 1811 | r = int(round(rgb[0] * 255)) |
| 1812 | g = int(round(rgb[1] * 255)) |
| 1813 | b = int(round(rgb[2] * 255)) |
| 1814 | colorArray.SetTuple3(i, r, g, b) |
| 1815 | |
| 1816 | # Add the color array to an image data |
| 1817 | imgData = vtkImageData() |
| 1818 | imgData.SetDimensions(numSamples, 1, 1) |
| 1819 | aIdx = imgData.GetPointData().SetScalars(colorArray) |
| 1820 | |
| 1821 | # Use the vtk data encoder to base-64 encode the image as png, using no compression |
| 1822 | encoder = vtkDataEncoder() |
| 1823 | # two calls in a row crash on Windows - bald timing hack to avoid the crash. |
| 1824 | time.sleep(0.01) |
| 1825 | b64Str = encoder.EncodeAsBase64Png(imgData, 0) |
| 1826 | |
| 1827 | return {"range": dataRange, "image": b64Str} |
| 1828 | |
| 1829 | @exportRpc("pv.color.manager.lut.image.all") |
| 1830 | def getLutImages(self, numSamples): |
nothing calls this directly
no test coverage detected