Checkpoint

This commit is contained in:
Emanuele Bezzi
2021-12-05 12:58:21 -05:00
parent db0f50d011
commit b1ff638879
4 changed files with 76 additions and 19 deletions
@@ -2,35 +2,78 @@ export default function drawSpatialImageRegl(regl) {
return regl({ return regl({
frag: ` frag: `
precision mediump float; precision mediump float;
uniform sampler2D texture;
varying vec2 uv; // our texture
void main () { uniform sampler2D u_image;
gl_FragColor = texture2D(texture, uv);
// the texCoords passed in from the vertex shader.
varying vec2 v_texCoord;
void main() {
gl_FragColor = texture2D(u_image, v_texCoord);
}`, }`,
vert: ` vert: `
precision mediump float; attribute vec2 a_position;
attribute vec2 position; attribute vec2 a_texCoord;
varying vec2 uv;
const float zMiddle = 0.; uniform vec2 u_resolution;
uniform mat3 projView; uniform mat3 projView;
vec2 norm(vec2 position) { varying vec2 v_texCoord;
return ((position - 0.5) * 2.0) * vec2(1., -1.);
}
void main() { void main() {
uv = position; // convert the rectangle from pixels to 0.0 to 1.0
vec3 xy = projView * vec3(norm(position), 1.); vec3 pos = vec3(a_position, 1.);
gl_Position = vec4(xy.xy, 0, 1.); vec2 zeroToOne = pos.xy / u_resolution;
// convert from 0->1 to 0->2
vec2 zeroToTwo = zeroToOne * 2.0;
// convert from 0->2 to -1->+1 (clipspace)
vec2 clipSpace = zeroToTwo - 1.0;
vec3 pos2 = projView * vec3(clipSpace, 1.);
gl_Position = vec4(pos2.xy , 0, 1);
// pass the texCoord to the fragment shader
// The GPU will interpolate this value between points.
v_texCoord = a_texCoord;
}`, }`,
attributes: { attributes: {
position: [-1, 1, -1, -1, 1, -1, 1, -1, 1, 1, -1, 1], a_texCoord: [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0],
// a_position: [
// 10, 0,
// 10 + regl.prop("img_width"), 0,
// 10, 0 + regl.prop("img_height"),
// 10, 0 + regl.prop("img_height"),
// 10 + regl.prop("img_width"), 0,
// 10 + regl.prop("img_width"), 0 + regl.prop("img_height"),
// ],
a_position: [
0,
0,
0 + 2000,
0,
0,
0 + 2000,
0,
0 + 2000,
0 + 2000,
0,
0 + 2000,
0 + 2000,
],
}, },
uniforms: { uniforms: {
projView: regl.prop("projView"), projView: regl.prop("projView"),
texture: regl.prop("spatialImageAsTexture"), u_image: regl.prop("spatialImageAsTexture"),
color: [1, 0, 0, 1],
u_resolution: [2000, 2000],
}, },
count: 6, count: 6,
+9 -1
View File
@@ -114,6 +114,7 @@ class Graph extends React.Component {
/* /*
compute the model coordinate for each point compute the model coordinate for each point
*/ */
console.log({ X }, { Y });
const positions = new Float32Array(2 * X.length); const positions = new Float32Array(2 * X.length);
for (let i = 0, len = X.length; i < len; i += 1) { for (let i = 0, len = X.length; i < len; i += 1) {
const p = vec2.fromValues(X[i], Y[i]); const p = vec2.fromValues(X[i], Y[i]);
@@ -516,7 +517,8 @@ class Graph extends React.Component {
return { toolSVG: newToolSVG, tool, container }; return { toolSVG: newToolSVG, tool, container };
}; };
loadTextureFromUrl = (src) => new Promise((resolve, reject) => { loadTextureFromUrl = (src) =>
new Promise((resolve, reject) => {
const img = new Image(); const img = new Image();
img.onload = () => resolve(img); img.onload = () => resolve(img);
img.onerror = reject; img.onerror = reject;
@@ -832,6 +834,8 @@ class Graph extends React.Component {
depth: 1, depth: 1,
color: [0, 0, 0, 0], color: [0, 0, 0, 0],
}); });
console.log({ pointBuffer });
console.log({ projView });
drawPoints({ drawPoints({
distance: camera.distance(), distance: camera.distance(),
color: colorBuffer, color: colorBuffer,
@@ -844,8 +848,12 @@ class Graph extends React.Component {
}); });
drawSpatialImage({ drawSpatialImage({
projView, projView,
img_width: this.spatialImage.width,
img_height: this.spatialImage.height,
spatialImageAsTexture: regl.texture({ spatialImageAsTexture: regl.texture({
data: this.spatialImage, data: this.spatialImage,
wrapS: "clamp",
wrapT: "clamp",
}), }),
}); });
regl._gl.flush(); regl._gl.flush();
+3 -1
View File
@@ -4,6 +4,7 @@ import sys
from http import HTTPStatus from http import HTTPStatus
import zlib import zlib
import json import json
import numpy as np
from flask import make_response, jsonify, current_app, abort, send_file from flask import make_response, jsonify, current_app, abort, send_file
from werkzeug.urls import url_unquote from werkzeug.urls import url_unquote
@@ -419,7 +420,8 @@ def spatial_image_get(request, data_adaptor):
return abort_and_log(HTTPStatus.BAD_REQUEST, f"spatial information does not contain requested resolution '{resolution}'") return abort_and_log(HTTPStatus.BAD_REQUEST, f"spatial information does not contain requested resolution '{resolution}'")
response_image = io.BytesIO() response_image = io.BytesIO()
matplotlib.pyplot.imsave(response_image, spatial[library_id]["images"][resolution]) img = np.flipud(spatial[library_id]["images"][resolution])
matplotlib.pyplot.imsave(response_image, img)
response_image.seek(0) response_image.seek(0)
try: try:
+4
View File
@@ -361,6 +361,8 @@ class DataAdaptor(metaclass=ABCMeta):
translate = 0.5 - ((max - min) / scale / 2) translate = 0.5 - ((max - min) / scale / 2)
normalized_layout = normalized_layout + translate normalized_layout = normalized_layout + translate
print(f"scale {scale}, translate {translate}")
normalized_layout = normalized_layout.astype(dtype=np.float32) normalized_layout = normalized_layout.astype(dtype=np.float32)
return normalized_layout return normalized_layout
@@ -388,6 +390,8 @@ class DataAdaptor(metaclass=ABCMeta):
df = pd.concat(layout_data, axis=1, copy=False) df = pd.concat(layout_data, axis=1, copy=False)
else: else:
df = pd.DataFrame() df = pd.DataFrame()
# print("##########DF")
# print(df)
fbs = encode_matrix_fbs(df, col_idx=df.columns, row_idx=None) fbs = encode_matrix_fbs(df, col_idx=df.columns, row_idx=None)
return fbs return fbs