[Opengeoscience-developers] OpenGeoscience branch, add_point_source, updated. 7604fc3021c5177496dd4951cda3a87205037d97

Aashish Chaudhary aashish.chaudhary at kitware.com
Thu Mar 7 19:40:31 EST 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "OpenGeoscience".

The branch, add_point_source has been updated
       via  7604fc3021c5177496dd4951cda3a87205037d97 (commit)
       via  4eb71770b5ea922652949c693e9b90fbe58e87c7 (commit)
      from  e11d01da3ed6603af4bb1265355b37aaeed880c8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://public.kitware.com/gitweb?p=OpenGeoscience/opengeoscience.git;a=commitdiff;h=7604fc3021c5177496dd4951cda3a87205037d97
commit 7604fc3021c5177496dd4951cda3a87205037d97
Author:     Aashish Chaudhary <aashish.chaudhary at kitware.com>
AuthorDate: Thu Mar 7 19:39:56 2013 -0500
Commit:     Aashish Chaudhary <aashish.chaudhary at kitware.com>
CommitDate: Thu Mar 7 19:39:56 2013 -0500

    Using helper function to create material

diff --git a/web/lib/vgl/utils.js b/web/lib/vgl/utils.js
index 9f6148d..c628f82 100644
--- a/web/lib/vgl/utils.js
+++ b/web/lib/vgl/utils.js
@@ -352,14 +352,15 @@ vglModule.utils.createTexturePlane = function(originX, originY, originZ,
  * @returns {vglModule.actor}
  */
 vglModule.utils.createPoints = function(positions, colors, texcoords) {
-  var mapper = new vglModule.mapper();
-  var pointSource = new vglModule.pointSource();
 
   if (!positions) {
     console.log("[ERROR] Cannot create points without positions");
     return null;
   }
 
+  var mapper = new vglModule.mapper();
+  var pointSource = new vglModule.pointSource();
+
   pointSource.setPositions(positions);
   if (colors) {
     pointSource.setColors(colors);
@@ -371,31 +372,7 @@ vglModule.utils.createPoints = function(positions, colors, texcoords) {
 
   mapper.setGeometryData(pointSource.create());
 
-  var mat = new vglModule.material();
-  var blend = new vglModule.blend();
-  var prog = new vglModule.shaderProgram();
-  var vertexShader = vglModule.utils.createVertexShader(gl);
-  var fragmentShader = vglModule.utils.createFragmentShader(gl);
-  var posVertAttr = new vglModule.vertexAttribute("vertexPosition");
-  var texCoordVertAttr = new vglModule.vertexAttribute("textureCoord");
-  var colorVertAttr = new vglModule.vertexAttribute("vertexColor");
-  var opacityUniform = new vglModule.floatUniform("opacity", 1.0);
-  var pointsizeUniform = new vglModule.floatUniform("pointSize", 10.0);
-  var modelViewUniform = new vglModule.modelViewUniform("modelViewMatrix");
-  var projectionUniform = new vglModule.projectionUniform("projectionMatrix");
-
-  prog.addVertexAttribute(posVertAttr, vglModule.vertexAttributeKeys.Position);
-  prog.addVertexAttribute(colorVertAttr, vglModule.vertexAttributeKeys.Color);
-  prog.addVertexAttribute(texCoordVertAttr,
-                          vglModule.vertexAttributeKeys.TextureCoordinate);
-  prog.addUniform(pointsizeUniform);
-  prog.addUniform(opacityUniform);
-  prog.addUniform(modelViewUniform);
-  prog.addUniform(projectionUniform);
-  prog.addShader(fragmentShader);
-  prog.addShader(vertexShader);
-  mat.addAttribute(prog);
-  mat.addAttribute(blend);
+  var mat = vglModule.utils.createGeometryMaterial(imageFilename);
 
   var actor = new vglModule.actor();
   actor.setMapper(mapper);
@@ -414,9 +391,6 @@ vglModule.utils.createPoints = function(positions, colors, texcoords) {
  */
 vglModule.utils.createPointSprites = function(imageFilename, positions, colors,
                                               texcoords) {
-  var mapper = new vglModule.mapper();
-  var pointSource = new vglModule.pointSource();
-
   if (!imageFilename) {
     console.log("[ERROR] Point sprites requires an image");
     return null;
@@ -427,6 +401,9 @@ vglModule.utils.createPointSprites = function(imageFilename, positions, colors,
     return null;
   }
 
+  var mapper = new vglModule.mapper();
+  var pointSource = new vglModule.pointSource();
+
   pointSource.setPositions(positions);
   if (colors) {
     pointSource.setColors(colors);

http://public.kitware.com/gitweb?p=OpenGeoscience/opengeoscience.git;a=commitdiff;h=4eb71770b5ea922652949c693e9b90fbe58e87c7
commit 4eb71770b5ea922652949c693e9b90fbe58e87c7
Author:     Aashish Chaudhary <aashish.chaudhary at kitware.com>
AuthorDate: Thu Mar 7 19:35:50 2013 -0500
Commit:     Aashish Chaudhary <aashish.chaudhary at kitware.com>
CommitDate: Thu Mar 7 19:35:50 2013 -0500

    Using point sprites for the dots

diff --git a/web/lib/app.js b/web/lib/app.js
index 23d2491..8fd2a79 100644
--- a/web/lib/app.js
+++ b/web/lib/app.js
@@ -65,11 +65,13 @@ function main() {
           }
         }
 
-        var pointLayer = ogs.geo.featureLayer({
-          "opacity" : 1,
-          "showAttribution" : 1,
-          "visible" : 1
-        }, ogs.geo.pointFeature(citieslatlon, colors));
+        var pointLayer = ogs.geo
+            .featureLayer({
+              "opacity" : 1,
+              "showAttribution" : 1,
+              "visible" : 1
+            }, ogs.geo.pointSpritesFeature('/data/spark.png', citieslatlon,
+                                           colors));
 
         myMap.addLayer(pointLayer);
       }
diff --git a/web/lib/geo/feature.js b/web/lib/geo/feature.js
index 1bce8b9..268efdc 100644
--- a/web/lib/geo/feature.js
+++ b/web/lib/geo/feature.js
@@ -86,7 +86,6 @@ geoModule.pointFeature = function(positions, colors) {
   ogs.vgl.actor.call(this);
 
   // Initialize
-  console.log('pos ' + positions);
   var actor = ogs.vgl.utils.createPoints(positions, colors);
   this.setMapper(actor.mapper());
   this.setMaterial(actor.material());
@@ -95,3 +94,29 @@ geoModule.pointFeature = function(positions, colors) {
 };
 
 inherit(geoModule.pointFeature, geoModule.feature);
+
+/**
+ * Point feature class
+ *
+ * @param positions
+ * @param colors
+ * @returns {geoModule.pointFeature}
+ */
+geoModule.pointSpritesFeature = function(imageFilename, positions, colors) {
+
+  if (!(this instanceof geoModule.pointSpritesFeature)) {
+    return new geoModule.pointSpritesFeature(imageFilename, positions, colors);
+  }
+
+  ogs.vgl.actor.call(this);
+
+  // Initialize
+  var actor = ogs.vgl.utils
+      .createPointSprites(imageFilename, positions, colors);
+  this.setMapper(actor.mapper());
+  this.setMaterial(actor.material());
+
+  return this;
+};
+
+inherit(geoModule.pointSpritesFeature, geoModule.feature);
diff --git a/web/lib/geo/map.js b/web/lib/geo/map.js
index 8b7749b..09a11ff 100644
--- a/web/lib/geo/map.js
+++ b/web/lib/geo/map.js
@@ -291,12 +291,12 @@ geoModule.map = function(node, options) {
 
     // Setup texture
     worldImage = new Image();
-
+    worldImage.src = "./data/land_shallow_topo_2048.png";
     var worldTexture = new vglModule.texture();
     worldTexture.setImage(worldImage);
 
     // TODO Currently hard-coded
-    worldImage.src = "./data/land_shallow_topo_2048.png";
+
     mapActor.material().addAttribute(worldTexture);
 
     m_renderer.addActor(mapActor);
diff --git a/web/lib/vgl/shader.js b/web/lib/vgl/shader.js
index af81f21..d0adb84 100644
--- a/web/lib/vgl/shader.js
+++ b/web/lib/vgl/shader.js
@@ -21,7 +21,6 @@
 // shader class
 //
 //////////////////////////////////////////////////////////////////////////////
-
 vglModule.shader = function(type) {
 
   if (!(this instanceof vglModule.shader)) {
@@ -30,7 +29,7 @@ vglModule.shader = function(type) {
   vglModule.object.call(this);
 
   var m_shaderHandle = null;
-  var m_shaderType =  type;
+  var m_shaderType = type;
   var m_shaderSource = "";
   var m_fileName = "";
 
@@ -71,8 +70,9 @@ vglModule.shader = function(type) {
 
     // See if it compiled successfully
     if (!gl.getShaderParameter(m_shaderHandle, gl.COMPILE_STATUS)) {
-      console.log("[ERROR] An error occurred compiling the shaders: " +
-                  gl.getShaderInfoLog(m_shaderHandle));
+      console.log("[ERROR] An error occurred compiling the shaders: "
+                  + gl.getShaderInfoLog(m_shaderHandle));
+      console.log(m_shaderSource);
       gl.deleteShader(m_shaderHandle);
       return null;
     }
diff --git a/web/lib/vgl/utils.js b/web/lib/vgl/utils.js
index 8be8c75..9f6148d 100644
--- a/web/lib/vgl/utils.js
+++ b/web/lib/vgl/utils.js
@@ -38,6 +38,31 @@ vglModule.utils = function() {
 inherit(vglModule.utils, vglModule.object);
 
 /**
+ * Helper function to create default vertex shader (
+ *
+ * @param context
+ * @returns {vglModule.shader}
+ */
+vglModule.utils.createTextureVertexShader = function(context) {
+  var vertexShaderSource = [
+                            'attribute vec3 vertexPosition;',
+                            'attribute vec3 textureCoord;',
+                            'uniform mediump float pointSize;',
+                            'uniform mat4 modelViewMatrix;',
+                            'uniform mat4 projectionMatrix;',
+                            'varying highp vec3 iTextureCoord;',
+                            'void main(void)',
+                            '{',
+                            'gl_PointSize = pointSize;',
+                            'gl_Position = projectionMatrix * modelViewMatrix * vec4(vertexPosition, 1.0);',
+                            ' iTextureCoord = textureCoord;', '}' ].join('\n');
+
+  var shader = new vglModule.shader(gl.VERTEX_SHADER);
+  shader.setShaderSource(vertexShaderSource);
+  return shader;
+};
+
+/**
  * Helper function to create default fragment shader with sampler
  *
  * @param context
@@ -58,6 +83,32 @@ vglModule.utils.createTextureFragmentShader = function(context) {
 };
 
 /**
+ * Helper function to create default vertex shader
+ *
+ * @param context
+ * @returns {vglModule.shader}
+ */
+vglModule.utils.createVertexShader = function(context) {
+  var vertexShaderSource = [
+                            'attribute vec3 vertexPosition;',
+                            'attribute vec3 vertexColor;',
+                            'uniform mediump float pointSize;',
+                            'uniform mat4 modelViewMatrix;',
+                            'uniform mat4 projectionMatrix;',
+                            'varying mediump vec3 iVertexColor;',
+                            'varying highp vec3 iTextureCoord;',
+                            'void main(void)',
+                            '{',
+                            'gl_PointSize = pointSize;',
+                            'gl_Position = projectionMatrix * modelViewMatrix * vec4(vertexPosition, 1.0);',
+                            ' iVertexColor = vertexColor;', '}' ].join('\n');
+
+  var shader = new vglModule.shader(gl.VERTEX_SHADER);
+  shader.setShaderSource(vertexShaderSource);
+  return shader;
+};
+
+/**
  * Helper function to create default fragment shader
  *
  * @param context
@@ -76,24 +127,24 @@ vglModule.utils.createFragmentShader = function(context) {
 };
 
 /**
- * Helper function to create default vertex shader (
+ * Helper function to create default point sprites vertex shader
  *
  * @param context
  * @returns {vglModule.shader}
  */
-vglModule.utils.createTextureVertexShader = function(context) {
+vglModule.utils.createPointSpritesVertexShader = function(context) {
   var vertexShaderSource = [
                             'attribute vec3 vertexPosition;',
-                            'attribute vec3 textureCoord;',
-                            'uniform float pointSize;',
+                            'attribute vec3 vertexColor;',
+                            'uniform mediump float pointSize;',
                             'uniform mat4 modelViewMatrix;',
                             'uniform mat4 projectionMatrix;',
-                            'varying highp vec3 iTextureCoord;',
+                            'varying mediump vec3 iVertexColor;',
                             'void main(void)',
                             '{',
                             'gl_PointSize = pointSize;',
                             'gl_Position = projectionMatrix * modelViewMatrix * vec4(vertexPosition, 1.0);',
-                            ' iTextureCoord = textureCoord;', '}' ].join('\n');
+                            ' iVertexColor = vertexColor;', '}' ].join('\n');
 
   var shader = new vglModule.shader(gl.VERTEX_SHADER);
   shader.setShaderSource(vertexShaderSource);
@@ -101,28 +152,25 @@ vglModule.utils.createTextureVertexShader = function(context) {
 };
 
 /**
- * Helper function to create default vertex shader
+ * Helper function to create default point sprites fragment shader
  *
  * @param context
  * @returns {vglModule.shader}
  */
-vglModule.utils.createVertexShader = function(context) {
-  var vertexShaderSource = [
-                            'attribute vec3 vertexPosition;',
-                            'attribute vec3 vertexColor;',
-                            'uniform float pointSize;',
-                            'uniform mat4 modelViewMatrix;',
-                            'uniform mat4 projectionMatrix;',
-                            'varying mediump vec3 iVertexColor;',
-                            'varying highp vec3 iTextureCoord;',
-                            'void main(void)',
-                            '{',
-                            'gl_PointSize = pointSize;',
-                            'gl_Position = projectionMatrix * modelViewMatrix * vec4(vertexPosition, 1.0);',
-                            ' iVertexColor = vertexColor;', '}' ].join('\n');
+vglModule.utils.createPointSpritesFragmentShader = function(context) {
+  var fragmentShaderSource = [
+                              'varying mediump vec3 iVertexColor;',
+                              'uniform sampler2D sampler2d;',
+                              'uniform mediump float opacity;',
+                              'uniform mediump float vertexColorWeight;',
+                              'void main(void) {',
+                              'highp vec4 texColor = texture2D(sampler2d, gl_PointCoord);',
+                              'highp vec3 finalColor = iVertexColor * vertexColorWeight + (1.0 - vertexColorWeight) * texColor.xyz;',
+                              'gl_FragColor = vec4(finalColor, opacity * texColor.w);',
+                              '}' ].join('\n');
 
-  var shader = new vglModule.shader(gl.VERTEX_SHADER);
-  shader.setShaderSource(vertexShaderSource);
+  var shader = new vglModule.shader(gl.FRAGMENT_SHADER);
+  shader.setShaderSource(fragmentShaderSource);
   return shader;
 };
 
@@ -198,6 +246,50 @@ vglModule.utils.createGeometryMaterial = function() {
 };
 
 /**
+ * Create a texture material
+ *
+ * @returns {vglModule.material}
+ */
+vglModule.utils.createPointSpritesMaterial = function(imageFilename) {
+  var mat = new vglModule.material();
+  var blend = new vglModule.blend();
+  var prog = new vglModule.shaderProgram();
+  var vertexShader = vglModule.utils.createPointSpritesVertexShader(gl);
+  var fragmentShader = vglModule.utils.createPointSpritesFragmentShader(gl);
+  var posVertAttr = new vglModule.vertexAttribute("vertexPosition");
+  var colorVertAttr = new vglModule.vertexAttribute("vertexColor");
+  var pointsizeUniform = new vglModule.floatUniform("pointSize", 5.0);
+  var opacityUniform = new vglModule.floatUniform("opacity", 1.0);
+  var vertexColorWeightUniform = new vglModule.floatUniform(
+                                                            "vertexColorWeight",
+                                                            0.0);
+  var modelViewUniform = new vglModule.modelViewUniform("modelViewMatrix");
+  var projectionUniform = new vglModule.projectionUniform("projectionMatrix");
+  var samplerUniform = new vglModule.uniform(gl.INT, "sampler2d");
+  samplerUniform.set(0);
+  prog.addVertexAttribute(posVertAttr, vglModule.vertexAttributeKeys.Position);
+  prog.addVertexAttribute(colorVertAttr, vglModule.vertexAttributeKeys.Color);
+  prog.addUniform(pointsizeUniform);
+  prog.addUniform(opacityUniform);
+  prog.addUniform(vertexColorWeightUniform);
+  prog.addUniform(modelViewUniform);
+  prog.addUniform(projectionUniform);
+  prog.addShader(fragmentShader);
+  prog.addShader(vertexShader);
+  mat.addAttribute(prog);
+  mat.addAttribute(blend);
+
+  // Load the texture
+  var image = new Image();
+  image.src = imageFilename;
+  var texture = new vglModule.texture();
+  texture.setImage(image);
+  mat.addAttribute(texture);
+
+  return mat;
+};
+
+/**
  * Helper function to create a plane node
  *
  * This method will create a plane actor with texture coordinates,
@@ -252,9 +344,9 @@ vglModule.utils.createTexturePlane = function(originX, originY, originZ,
 };
 
 /**
- * Helper function to create a plane node
+ * Helper function to create a point node
  *
- * This method will create a plane actor with texture coordinates,
+ * This method will create a point actor with texture coordinates,
  * eventually normal, and plane material.
  *
  * @returns {vglModule.actor}
@@ -288,7 +380,7 @@ vglModule.utils.createPoints = function(positions, colors, texcoords) {
   var texCoordVertAttr = new vglModule.vertexAttribute("textureCoord");
   var colorVertAttr = new vglModule.vertexAttribute("vertexColor");
   var opacityUniform = new vglModule.floatUniform("opacity", 1.0);
-  var pointsizeUniform = new vglModule.floatUniform("pointSize", 5.0);
+  var pointsizeUniform = new vglModule.floatUniform("pointSize", 10.0);
   var modelViewUniform = new vglModule.modelViewUniform("modelViewMatrix");
   var projectionUniform = new vglModule.projectionUniform("projectionMatrix");
 
@@ -310,4 +402,46 @@ vglModule.utils.createPoints = function(positions, colors, texcoords) {
   actor.setMaterial(mat);
 
   return actor;
+};
+
+/**
+ * Helper function to create a point sprites node
+ *
+ * This method will create a point sprites actor with texture coordinates,
+ * normals, and a point sprites material.
+ *
+ * @returns {vglModule.actor}
+ */
+vglModule.utils.createPointSprites = function(imageFilename, positions, colors,
+                                              texcoords) {
+  var mapper = new vglModule.mapper();
+  var pointSource = new vglModule.pointSource();
+
+  if (!imageFilename) {
+    console.log("[ERROR] Point sprites requires an image");
+    return null;
+  }
+
+  if (!positions) {
+    console.log("[ERROR] Cannot create points without positions");
+    return null;
+  }
+
+  pointSource.setPositions(positions);
+  if (colors) {
+    pointSource.setColors(colors);
+  }
+
+  if (texcoords) {
+    pointSource.setTextureCoordinates(texcoords);
+  }
+
+  mapper.setGeometryData(pointSource.create());
+
+  var mat = vglModule.utils.createPointSpritesMaterial(imageFilename);
+  var actor = new vglModule.actor();
+  actor.setMapper(mapper);
+  actor.setMaterial(mat);
+
+  return actor;
 };
\ No newline at end of file

-----------------------------------------------------------------------

Summary of changes:
 web/lib/app.js         |   12 ++-
 web/lib/geo/feature.js |   27 ++++++-
 web/lib/geo/map.js     |    4 +-
 web/lib/vgl/shader.js  |    8 +-
 web/lib/vgl/utils.js   |  213 ++++++++++++++++++++++++++++++++++++------------
 5 files changed, 201 insertions(+), 63 deletions(-)


hooks/post-receive
-- 
OpenGeoscience



More information about the Opengeoscience-developers mailing list