Commit 315d375b authored by Margaux Mouchene's avatar Margaux Mouchene
Browse files

make histogram upon band loading

parent feea4b5d
......@@ -16,6 +16,8 @@ from OpenGL.GL import (
import numpy as np
from pyqtgraph import ImageItem
class MapModel(QObject):
""" Model managing data for Map and Minimap
"""
......@@ -134,6 +136,11 @@ class MapModel(QObject):
v_i, v_a,
)
# make histogram
band[bg]=np.nan
iband=ImageItem(band)
self.hist = iband.getHistogram()
# selection texture
if not isinstance(self.selection, np.ndarray):
self.selection = np.zeros((self.tex_height, self.tex_width, 2), dtype='float32')
......
......@@ -13,18 +13,25 @@ from insarviz.gl_utils import set_uniform
class PaletteModel(QObject):
"""provides a model for palette shaders"""
bounds_changed = pyqtSignal()
repaint = pyqtSignal()
histogram_changed = pyqtSignal(object) #TODO precise type of object
histograms = {}
v_i, v_a = 0., 1. # keep track of global min & max values in bands
def __init__(self, map_model):
def __init__(self, map_model, loader):
super().__init__()
self.map_model = map_model
self.loader = loader
self.map_model.texture_changed.connect(self.texture_changed)
def texture_changed(self):
self.show_histogram()
old_state = (self.v_i, self.v_a)
v_i, v_a = self.map_model.tex_vi, self.map_model.tex_va
self.v_i = min(self.v_i, v_i)
......@@ -32,19 +39,49 @@ class PaletteModel(QObject):
if old_state != (self.v_i, self.v_a):
self.bounds_changed.emit()
def show_histogram(self):
"""
TODO
Load, generate (if not existing) and show the texture for th ith band.
Parameters
----------
i : int
Band/date number to be loaded and shown.
Returns
-------
None.
"""
i = self.map_model.i
# get histogram
try:
self.hist = self.histograms[i]
except KeyError:
self.hist = self.map_model.hist
# store histogram
self.histograms[i] = self.hist
# show histogram
self.histogram_changed.emit(self.hist)
class GreyPaletteModel(PaletteModel):
v_b, v_w = 0., 1. # values for black and white
def __init__(self, map_model, program):
super().__init__(map_model)
def __init__(self, map_model, program, loader):
super().__init__(map_model, loader)
self.program = program
@pyqtSlot(int)
def black_changed(self, v):
set_uniform(self.program, 'v_b', float(v))
print('black', v)
self.repaint.emit()
@pyqtSlot(int)
def white_changed(self, v):
set_uniform(self.program, 'v_w', float(v))
......
......@@ -10,6 +10,8 @@ from PyQt5.QtWidgets import (
QWidget, QVBoxLayout, QSlider,
)
from pyqtgraph import HistogramLUTWidget
from PyQt5 import QtGui
# palette ###################################################################
......@@ -23,18 +25,53 @@ class Palette(QWidget):
self.b_slider = QSlider(Qt.Horizontal, self)
self.b_slider.setTickPosition(QSlider.TicksBelow)
self.b_slider.valueChanged.connect(self.model.black_changed)
self.w_slider = QSlider(Qt.Horizontal, self)
self.w_slider.setTickPosition(QSlider.TicksBelow)
self.w_slider.valueChanged.connect(self.model.white_changed)
self.histcb = HistoColorbar(self.model)
# self.histcb.gradient.sigGradientChanged.connect(self.model.gradient_changed)
layout.addWidget(self.b_slider)
layout.addWidget(self.w_slider)
layout.addWidget(self.histcb)
self.setLayout(layout)
def bounds_changed(self):
v_i, v_a = self.model.v_i, self.model.v_a
self.b_slider.setMinimum(v_i)
self.w_slider.setMinimum(v_i)
self.b_slider.setMaximum(v_a)
self.w_slider.setMaximum(v_a)
class HistoColorbar(HistogramLUTWidget):
def __init__(self, model):
super().__init__()
self.gradient.sigGradientChanged.connect(self.gradchanged)
# self.vb.sigRangeChanged.connect(self.rangechanged)
self.model = model
self.model.bounds_changed.connect(self.bounds_changed)
self.model.histogram_changed.connect(self.histogram_changed)
print('hcb')
def gradchanged(self):
# consider changing the name:private method called
# gradientChanged already exists!
print('gradchanged')
a=self.gradient.colorMap().pos
print('pos= ',a)
a=self.gradient.colorMap().color
print('color= ',a)
def bounds_changed(self):
print('boundschanged')
def histogram_changed(self, hist):
self.plot.setData(*hist)
......@@ -86,9 +86,11 @@ class MainWindow(QMainWindow):
minimap_button.setChecked(True)
minimap_button.toggled.connect(self.minimap_widget.setVisible)
self.minimap_widget.sigClosing.connect(minimap_button.setChecked)
# Palette
self.palette_model = GreyPaletteModel(self.map_model, self.minimap_widget.program)
self.palette_model = GreyPaletteModel(map_model=self.map_model,
program=self.minimap_widget.program,
loader=loader)
self.palette_model.repaint.connect(self.minimap_widget.update)
self.palette_widget = Palette(self.palette_model)
self.palette_widget.show()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment