Exemplo n.º 1
0
    def dataLoaded(self, data, extents):
        buffer = numpy.concatenate(data, axis=3)
        volume = ivw.data.Volume(buffer)
        if self.overwriteDataRange.value:
            volume.dataMap.dataRange = self.dataRange.value
        else:
            minVal = numpy.amin(buffer)
            maxVal = numpy.amax(buffer)
            volume.dataMap.dataRange = dvec2(minVal, maxVal)
        volume.dataMap.valueRange = volume.dataMap.dataRange

        if self.overwriteModel:
            volume.modelMatrix = self.modelMatrix.value
        else:
            volume.modelMatrix = mat4(vec4(extents[2], 0, 0, 0),
                                      vec4(0, extents[1], 0, 0),
                                      vec4(0, 0, extents[0], 0),
                                      vec4(0, 0, 0, 1))

        volume.interpolation = ivw.data.InterpolationType(
            self.interpolation.value)
        volume.wrapping = [
            ivw.data.Wrapping(self.wrappingX.value),
            ivw.data.Wrapping(self.wrappingY.value),
            ivw.data.Wrapping(self.wrappingZ.value)
        ]
        self.volumeOutport.setData(volume)
def shift_rgba_color(col, scale=0.1, rotation=0.1, opacity_scale=0.1):
    h, s, v = colorsys.rgb_to_hsv(col.r, col.g, col.b)
    h = h + rotation
    s = shift_pos(s, scale)
    v = shift_pos(v, scale)
    # Don't shift low points
    if(col.a > 0.00001):
        col.a = shift_pos(col.a, opacity_scale, min_val=0.00003, max_val=0.8)
    r, g, b = colorsys.hsv_to_rgb(h, s, v)
    return vec4(r, g, b, col.a)
Exemplo n.º 3
0
def make_peak(tf, point, colour):
    vol = self.getInport("volinport").getData()
    scaled_point = point / vol.dataMap.valueRange[1]
    tf.add(scaled_point, colour)
    black = vec4(0, 0, 0, 0)
    #TODO clamp to range 0 1
    left = scaled_point - 0.03
    right = scaled_point + 0.03
    tf.add(left, black)
    tf.add(right, black)
Exemplo n.º 4
0
 def take_action(self, action):
     self.ivw_tf.clear()
     data_list = []
     # If properly using, this needs to be a list
     for i in range(255):
         start_idx = 4 * i
         vec_list = action[start_idx:start_idx + 4].copy().astype(
             np.float32) / float(255)
         vector = vec4(*vec_list)
         data_list.append(TFPrimitiveData(float(i) / 255, vector))
     self.ivw_tf.add(data_list)
Exemplo n.º 5
0
    def dataLoaded(self, data, extents):
        volumeSequence = []
        for timeStep in range(data[0].shape[3]):
            subData = []
            for comp in data:
                # A bit brute force, but delivers correct data.
                numElems = comp.shape[0] * comp.shape[1] * comp.shape[2]
                subBuffer = comp.flat[(numElems * timeStep):(numElems *
                                                             (timeStep + 1))]
                subBuffer.shape = (comp.shape[0], comp.shape[1], comp.shape[2],
                                   1)
                subData.append(subBuffer)
            buffer = numpy.concatenate(subData, axis=3)
            volume = ivw.data.Volume(buffer)
            if self.overwriteDataRange.value:
                volume.dataMap.dataRange = self.dataRange.value
            else:
                minVal = numpy.amin(buffer)
                maxVal = numpy.amax(buffer)
                volume.dataMap.dataRange = dvec2(minVal, maxVal)
            volume.dataMap.valueRange = volume.dataMap.dataRange

            if self.overwriteModel:
                volume.modelMatrix = self.modelMatrix.value
            else:
                volume.modelMatrix = mat4(vec4(extents[2], 0, 0, 0),
                                          vec4(0, extents[1], 0, 0),
                                          vec4(0, 0, extents[0], 0),
                                          vec4(0, 0, 0, 1))
            volume.interpolation = ivw.data.InterpolationType(
                self.interpolation.value)
            volume.wrapping = [
                ivw.data.Wrapping(self.wrappingX.value),
                ivw.data.Wrapping(self.wrappingY.value),
                ivw.data.Wrapping(self.wrappingZ.value)
            ]
            volumeSequence.append(volume)

        sequence = ivw.data.VolumeSequence(volumeSequence)
        self.volumeOutport.setData(sequence)
Exemplo n.º 6
0
 def take_action(self, action, is_int=True):
     # It would seem the action is not being properly selected
     self.ivw_tf.clear()
     data_list = []
     # If properly using, this needs to be a list
     for i in range(256):
         start_idx = 4*i
         if is_int:
             action_rounded = np.around(action)
             vec_list = action_rounded[start_idx:start_idx+4].copy()
             vec_list = vec_list.astype(np.float32) / float(255)
         else:
             vec_list = action[start_idx:start_idx+4].copy()
         vector = vec4(*vec_list)
         data_list.append(TFPrimitiveData((float(i) / 255), vector))
     self.ivw_tf.add(data_list)
Exemplo n.º 7
0
 def rotateVec(m, v):
     return glm.vec3(m * glm.vec4(v, 1.0))
Exemplo n.º 8
0
import inviwopy
import inviwopy.glm as glm

app = inviwopy.app
network = app.network

app.network.clear()
app.network.lock()

bg = app.processorFactory.create("org.inviwo.Background", glm.ivec2(0, -100))
bg.backgroundStyle.selectedDisplayName = "Uniform color"
bg.bgColor1.value = glm.vec4(1, 1, 1, 1)

canvas = app.processorFactory.create("org.inviwo.CanvasGL", glm.ivec2(0, 0))
canvas.inputSize.dimensions.value = glm.size2_t(256, 600)

network.addProcessor(bg)
network.addProcessor(canvas)

proc = app.processorFactory.create("org.inviwo.TextOverlayGL")

fontNames = proc.font.fontFace.displayNames
fontIdentifiers = proc.font.fontFace.identifiers

prev = bg

fontSize = 16
processorSpacing = 50
# vertical spacing of text
vertTextSpacing = 1.0 / len(fontNames)
Exemplo n.º 9
0
def random_colour():
    return vec4(random(), random(), random(), 0.1 + random() * 0.7)
Exemplo n.º 10
0
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import inviwopy
from inviwopy.glm import vec2,vec3,vec4

#http://matplotlib.org/examples/color/colormaps_reference.html

#Perceptually Uniform Sequential :  #['viridis', 'inferno', 'plasma', 'magma'] 
#Sequential  :  #['Blues', 'BuGn', 'BuPu','GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd', 'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu','Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']
#Diverging :  #['afmhot', 'autumn', 'bone', 'cool','copper', 'gist_heat', 'gray', 'hot','pink', 'spring', 'summer', 'winter']
#Qualitative :  #['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral', 'seismic']
#Miscellaneous :  #['Accent', 'Dark2', 'Paired', 'Pastel1', 'Pastel2', 'Set1', 'Set2', 'Set3']
#Sequential :  #['gist_earth', 'terrain', 'ocean', 'gist_stern','brg', 'CMRmap', 'cubehelix','gnuplot', 'gnuplot2', 'gist_ncar', 'nipy_spectral', 'jet', 'rainbow', 'gist_rainbow', 'hsv', 'flag', 'prism']


tf = inviwopy.app.network.VolumeRaycaster.transferFunction
tf.clear()

cmapName = "viridis"

cmap=plt.get_cmap(cmapName)

N = 128

for i in range(0,N,1):
   x = i / (N-1)
   a = 1.0
   color = cmap(x)
   tf.add(x, vec4(color[0],color[1],color[2], a))