[cig-commits] commit: Make SurfaceAdaptor interpolate topo data

Mercurial hg at geodynamics.org
Tue Feb 23 12:23:27 PST 2010


changeset:   588:ba7780f5e04e
tag:         tip
user:        Walter Landry <wlandry at caltech.edu>
date:        Tue Feb 23 12:02:27 2010 -0800
files:       Mesh/src/SurfaceAdaptor.c
description:
Make SurfaceAdaptor interpolate topo data


diff -r 607b253d0950 -r ba7780f5e04e Mesh/src/SurfaceAdaptor.c
--- a/Mesh/src/SurfaceAdaptor.c	Sat Feb 06 10:00:41 2010 -0800
+++ b/Mesh/src/SurfaceAdaptor.c	Tue Feb 23 12:02:27 2010 -0800
@@ -431,16 +431,16 @@ double SurfaceAdaptor_Topo_Data( Surface
                                  unsigned* globalSize, unsigned vertex,
                                  unsigned* vertexInds )
 {
-  int i,j,k;
-  double deltax,deltay;
+  int i,k,ip,kp;
+  double dx,dz;
 
   i=floor((mesh->verts[vertex][0] - self->info.topo_data.minX)
           /self->info.topo_data.dx + 0.5);
-  j=floor((mesh->verts[vertex][2] - self->info.topo_data.minZ)
+  k=floor((mesh->verts[vertex][2] - self->info.topo_data.minZ)
           /self->info.topo_data.dz + 0.5);
 
   if(i<0 || i>self->info.topo_data.nx-1
-     || j<0 || j>self->info.topo_data.nz-1)
+     || k<0 || k>self->info.topo_data.nz-1)
     {
       printf("Coordinate not covered by the topography file: %g %g\n\tminX: %g\n\tmaxX: %g\n\tminZ: %g\n\tmaxZ: %g\n\tnx: %d\n\tnz: %d\n",
              mesh->verts[vertex][0],
@@ -454,7 +454,25 @@ double SurfaceAdaptor_Topo_Data( Surface
       abort();
     }
 
-  return self->info.topo_data.heights[i+self->info.topo_data.nx*j];
+  /* Interpolate the height */
+  ip=i+1;
+  kp=k+1;
+  if(ip>self->info.topo_data.nx-1)
+    ip=i;
+  if(kp>self->info.topo_data.nz-1)
+    kp=k;
+
+  dx=(mesh->verts[vertex][0]
+      - (i*self->info.topo_data.dx+self->info.topo_data.minX))
+    /self->info.topo_data.dx;
+  dz=(mesh->verts[vertex][2]
+      - (k*self->info.topo_data.dz+self->info.topo_data.minZ))
+    /self->info.topo_data.dz;
+
+  return self->info.topo_data.heights[i+self->info.topo_data.nx*k]*(1-dx)*(1-dz)
+    + self->info.topo_data.heights[i+self->info.topo_data.nx*kp]*(1-dx)*dz
+    + self->info.topo_data.heights[ip+self->info.topo_data.nx*k]*dx*(1-dz)
+    + self->info.topo_data.heights[ip+self->info.topo_data.nx*kp]*dx*dz;
 }
 
 double SurfaceAdaptor_Sine( SurfaceAdaptor* self, Mesh* mesh, 



More information about the CIG-COMMITS mailing list