Changeset 321

Show
Ignore:
Timestamp:
03/26/08 12:00:36 (8 months ago)
Author:
powell
Message:

New structure "ternary_point" encapsulates all vertex info.

Location:
trunk/matml/src/ternary
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/matml/src/ternary/geomview.c

    r318 r321  
    7171  int npoints Number of points. 
    7272 
    73   double *points Point coordinates and colors in a 7xN array: x,y,z,r,g,b,a. 
     73  ternary_point *points Point coordinates and colors. 
    7474 
    7575  int ntriangles Number of triangles. 
     
    7979 
    8080int GeomviewDisplayTriangleCOFF 
    81 (FILE *geompipe, int npoints, double *points, int ntriangles, int *vertices) 
     81(FILE *geompipe, int npoints, ternary_point *points, int ntriangles, int *vertices) 
    8282{ 
    8383  int i; 
     
    8989 
    9090  for (i=0; i<npoints; i++) 
    91     fprintf (geompipe, "%g %g %g %g %g %g %g\n", points[7*i], points[7*i+1], 
    92              points[7*i+2], points[7*i+3], points[7*i+4], points[7*i+5], 
    93              points[7*i+6]); 
     91    fprintf (geompipe, "%g %g %g %g %g %g %g\n", points[i].x, points[i].y, 
     92             points[i].z, points[i].red, points[i].green, points[i].blue, 
     93             points[i].alpha); 
    9494 
    9595  for (i=0; i<ntriangles; i++) 
  • trunk/matml/src/ternary/ternary.c

    r318 r321  
    3131  char gv_version[100]; 
    3232  FILE *pfd = NULL; 
    33   double Gmin, Gmax, *points; 
     33  double Gmin, Gmax; 
     34  ternary_point *points; 
    3435 
    3536  if (argc>1) 
     
    3738 
    3839  /* Allocate arrays for point coordinates and colors and triangle vertices */ 
    39   if (!(points = calloc ((loop_max+1)*(loop_max+2)/2 * 7, sizeof (double)))) 
     40  if (!(points = calloc ((loop_max+1)*(loop_max+2)/2, sizeof (ternary_point)))) 
    4041    { printf ("Cannot allocate point coordinate array\n"); exit (1); } 
    4142 
     
    5556    for (j=0; j<=loop_max-i; j++) 
    5657      { 
    57         index = 7 * (ROWSTART (i) + j); 
     58        index = (ROWSTART (i) + j); 
    5859 
    59         points [index] = (double)i/loop_max; 
    60         points [index+1] = (double)j/loop_max; 
    61         points [index+2] = free_energy (points[index], points[index+1], 0.); 
    62         Gmin = (points [index+2]<Gmin) ? points [index+2] : Gmin; 
    63         Gmax = (points [index+2]>Gmax) ? points [index+2] : Gmax; 
     60        points[index].C2 = (double)i/loop_max; 
     61        points[index].C3 = (double)j/loop_max; 
     62        points[index].G = free_energy (points[index].C2, points[index].C3, 0.); 
     63        Gmin = (points[index].G<Gmin) ? points[index].G : Gmin; 
     64        Gmax = (points[index].G>Gmax) ? points[index].G : Gmax; 
    6465      } 
     66 
     67  printf ("Calculated free energies\n"); 
    6568 
    6669#define Grel(G) (((G)-Gmin)/(Gmax-Gmin)) 
     
    7376    for (j=0; j<=loop_max-i; j++) 
    7477      { 
    75         index = 7 * (ROWSTART (i) + j); 
     78        index = (ROWSTART (i) + j); 
    7679 
    77         points [index] += 0.5 * points [index+1]; 
    78         points [index+1] *= sqrt(3)/2.; 
     80        /* Switch y and z because geomview uses z as depth */ 
     81        points[index].x = points[index].C2 + 0.5 * points[index].C3; 
     82        points[index].y = Grel(points[index].G); 
     83        points[index].z = (1. - points[index].C3) * sqrt(3)/2.; 
    7984 
    80         points [index+3] = RED   (Grel (points [index+2])); 
    81         points [index+4] = GREEN (Grel (points [index+2])); 
    82         points [index+5] = BLUE  (Grel (points [index+2])); 
    83         points [index+6] = 1.; 
     85        points[index].red   = RED   (Grel (points[index].G)); 
     86        points[index].green = GREEN (Grel (points[index].G)); 
     87        points[index].blue  = BLUE  (Grel (points[index].G)); 
     88        points[index].alpha = 1.; 
    8489      } 
     90 
     91  printf ("Rescaled points\n"); 
    8592 
    8693  /* Calculate triangle vertex indices */ 
     
    108115  verts [3*index+2] = ROWSTART(i+1); 
    109116 
     117  printf ("Calculated triangle vertex indices\n"); 
     118 
    110119  /* Send points and triangle vertex data to Geomview */ 
    111120  if (i=GeomviewDisplayTriangleCOFF (pfd, (loop_max+1)*(loop_max+2)/2, points, 
    112121                                     loop_max*loop_max, verts)) 
    113122    { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 
     123 
     124  printf ("Sent points to geomview\n"); 
    114125 
    115126  { 
  • trunk/matml/src/ternary/ternary.h

    r320 r321  
    1111#include <stdio.h> 
    1212 
     13typedef struct { 
     14  double C2;     /*+ Ternary concentration variable 2 (0 -> 1) +*/ 
     15  double C3;     /*+ Ternary concentration variable 3 (0 -> 1-C2) +*/ 
     16  double G;      /*+ Free energy +*/ 
     17  double x;      /*+ Visualization x-coordinate (0 -> 1) +*/ 
     18  double y;      /*+ Visualization y-coordinate (transformed free energy) +*/ 
     19  double z;      /*+ Visualization z-coordinate (0 -> sqrt(3)/2) +*/ 
     20  double red;    /*+ Visualization color red value (0 -> 1) +*/ 
     21  double green;  /*+ Visualization color green value (0 -> 1) +*/ 
     22  double blue;   /*+ Visualization color blue value (0 -> 1) +*/ 
     23  double alpha;  /*+ Visualization color alpha value (0 -> 1) +*/ 
     24} ternary_point; /*+ Ternary "point" structure. +*/ 
     25 
    1326double free_energy (double C2, double C3, double T); 
    1427 
    1528int GeomviewBegin (FILE **geompipe, char *version); 
    1629int GeomviewDisplayTriangleCOFF 
    17 (FILE *geompipe, int npoints, double *points, int ntriangles, int *vertices); 
     30(FILE *geompipe, int npoints, ternary_point *points, 
     31 int ntriangles, int *vertices); 
    1832int GeomviewEnd (FILE **geompipe); 
    1933