Changeset: 1a856d308337 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1a856d308337
Added Files:
        sql/test/sciql/Tests/greyscale_image.sql
        sql/test/sciql/Tests/life.sql
        sql/test/sciql/Tests/remotesensing_image.sql
Branch: sciql
Log Message:

Added the queries from the SciQL demo.
Needs to be finished later


diffs (230 lines):

diff --git a/sql/test/sciql/Tests/greyscale_image.sql 
b/sql/test/sciql/Tests/greyscale_image.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/sciql/Tests/greyscale_image.sql
@@ -0,0 +1,36 @@
+-- Queries used by the Greyscale Image demo
+
+-- LoadGreyScaleImage
+CALL rs.attach('/tmp/GreyScale.tiff');
+CALL rs.import(1); 
+
+SELECT [x], [y], v FROM rs.image1;
+
+-- InverseColor
+SELECT [x], [y], 255 - v FROM image1;
+
+-- EdgeDetection
+-- the workaround
+SELECT [a.x], [a.y], 
+       255 - ABS(a.v*2-b.v-c.v) * 2 AS v 
+         FROM image1 AS a, image1 AS b, image1 AS c 
+         WHERE a.x -1 = b.x AND a.y    = b.y 
+           AND a.x    = c.x AND a.y -1 = c.y;
+
+-- the real query, not implemented yet
+SELECT [x], [y], 255 - ABS(a[x][y].v *2 - a[x-1][y].v - a[x][y-1].v) * 2 AS v
+  FROM image1 AS a;
+
+-- Smooth
+SELECT [x], [y], 
+       CAST(AVG(v) AS SMALLINT) AS v 
+         FROM image1 
+         GROUP BY image1[x-3:x+4][y-3:y+4];
+
+-- Reduce
+SELECT [x/2], [y/2], v 
+  FROM image1[*:2:*][*:2:*];
+
+-- Rotate180deg
+SELECT [1023-x], [767-y], v FROM image1;
+
diff --git a/sql/test/sciql/Tests/life.sql b/sql/test/sciql/Tests/life.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/sciql/Tests/life.sql
@@ -0,0 +1,104 @@
+-- Queries used by the GameOfLife demo
+
+-- Create bord
+CREATE ARRAY life ( 
+         x INT DIMENSION [20], 
+         y INT DIMENSION [15], 
+         v INT DEFAULT 0);
+
+-- Exploder
+INSERT INTO life VALUES 
+  (8, 5, 1), (8, 6, 1), (8, 7, 1), 
+  (8, 8, 1), (8, 9, 1), 
+  (10, 5, 1), (10, 9, 1), 
+  (12, 5, 1), (12, 6, 1), (12, 7, 1), 
+  (12, 8, 1), (12, 9, 1);
+
+-- Next
+CREATE VIEW neighbours AS 
+  SELECT [x], [y], 
+         SUM(v)-v AS neighbour_cnt 
+    FROM life 
+    GROUP BY life[x-1:x+2][y-1:y+2];
+
+INSERT INTO life ( 
+  SELECT [l.x], [l.y], 0 
+    FROM life AS l, neighbours AS n 
+    WHERE l.x = n.x AND l.y = n.y 
+      AND v = 1 
+      AND (neighbour_cnt < 2 OR 
+           neighbour_cnt > 3) 
+  UNION 
+  SELECT [l.x], [l.y], 1 
+    FROM life AS l, neighbours AS n 
+    WHERE l.x = n.x AND l.y = n.y 
+      AND v = 0 
+      AND neighbour_cnt =3 
+);
+
+-- Clear
+UPDATE life SET v = 0 WHERE v > 0;
+
+-- Multigroups
+INSERT INTO life VALUES 
+  (5,8,1), (5,9,1), 
+  (6,9,1), (6,10,1), 
+  (7,11,1),  
+  (13,5,1), (13,9,1), (14,6,1);
+
+-- CountGroups
+DECLARE width INT, height INT;
+SET width  = (SELECT MAX(x) +1 FROM life);
+SET height = (SELECT MAX(y) +1 FROM life);
+
+CREATE FUNCTION count_groups()
+RETURNS TABLE (groupid INT, cnt INT)
+BEGIN
+  DECLARE moreupdates INT;
+  SET moreupdates = 1;
+
+  CREATE ARRAY tmp ( 
+    x   INT DIMENSION[width], 
+    y   INT DIMENSION[height], 
+    gid INT);
+  INSERT INTO tmp (
+    SELECT x, y, x * height + y FROM life 
+    WHERE v = 1);
+
+  WHILE moreupdates > 0 DO
+    INSERT INTO tmp (
+      SELECT [x], [y], MAX(gid) FROM tmp 
+        GROUP BY tmp[x-1:x+2][y-1:y+2] 
+        HAVING gid IS NOT NULL);
+
+    SELECT SUM(res) INTO moreupdates 
+      FROM (
+        SELECT MAX(gid) - MIN(gid) AS res 
+          FROM tmp
+          GROUP BY tmp[x-1:x+2][y-1:y+2] 
+          HAVING gid IS NOT NULL 
+      ) AS updates;
+  END WHILE; 
+
+  RETURN SELECT gid, COUNT(gid) AS cnt 
+           FROM tmp WHERE gid > 0 
+           GROUP BY gid ORDER BY gid;
+END;
+
+SELECT * FROM count_groups();
+
+DROP function count_groups;
+
+
+---- Not implemented yet
+-- Flip
+SELECT [y] AS x, [x] AS y, life[x][y].v FROM life;
+
+-- ReduceBordSize
+ALTER ARRAY life ALTER x SET DIMENSION [1:1:4];
+ALTER ARRAY life ALTER y SET DIMENSION [1:1:4];
+
+-- EnlargeBoardSize
+ALTER ARRAY life ALTER x SET DIMENSION [-1:1:7];
+ALTER ARRAY life ALTER y SET DIMENSION [-1:1:7];
+
diff --git a/sql/test/sciql/Tests/remotesensing_image.sql 
b/sql/test/sciql/Tests/remotesensing_image.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/sciql/Tests/remotesensing_image.sql
@@ -0,0 +1,75 @@
+-- LoadRemoteSensingImage
+CALL rs.attach('/tmp/RemoteSensing.tiff');
+CALL rs.import(2);
+
+SELECT [x], [y], v FROM rs.image2;
+
+-- NoWater
+SELECT [x], [y], v FROM image2 WHERE v > 4;
+
+-- Histogram
+SELECT v, LOG(COUNT(*)) AS logcnt, 1 
+  FROM image2 
+  GROUP BY v ORDER BY v;
+
+-- WaterCoverage
+SELECT CAST(COUNT(v) AS DOUBLE) / 
+       (SELECT c.width * c.length 
+          FROM catalog AS c 
+          WHERE imageid = 2 
+       ) * 100 AS water_pct 
+  FROM image2 
+  WHERE v < 4;
+
+-- ZoomIn
+SELECT [x-150], [y-110], v 
+  FROM image2[150:350][110:200];
+
+-- Brighter
+SELECT [x-150], [y-110], 
+       CASE WHEN v+100 < 256 THEN v+100 
+            ELSE 255 
+       END AS v 
+  FROM image2[150:350][110:200];
+
+-- BitmaskImg
+CREATE ARRAY mask( 
+  x INT DIMENSION[1024],  
+  y INT DIMENSION[512],  
+  v SMALLINT DEFAULT 0 
+);
+
+INSERT INTO mask ( 
+  SELECT x, y, 255 
+    FROM image2[470:670][30:170] 
+  UNION 
+  SELECT x, y, 255 
+    FROM image2[150:350][110:200] 
+);
+
+SELECT [x], [y], v FROM mask;
+
+-- Overlay
+SELECT [i.x], [i.y], 
+       CASE WHEN m.v > 0 THEN i.v
+            ELSE 255 
+       END AS v 
+  FROM image2 AS i, mask AS m 
+  WHERE i.x = m.x AND i.y = m.y;
+
+-- AreaOfInterest
+CREATE TABLE maskt ( 
+  xmin INT, xmax INT, ymin INT, ymax INT 
+);
+INSERT INTO maskt VALUES 
+  (470,670,30,170), (150,350,110,200);
+
+-- JOIN array and table 
+
+SELECT [i.x], [i.y], i.v 
+  FROM image2 AS i, maskt AS mt 
+  WHERE i.x BETWEEN mt.xmin AND mt.xmax 
+    AND i.y BETWEEN mt.ymin AND mt.ymax;
+
+DROP TABLE maskt;
+
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to