~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/ogsf/gvl_calc.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*!
2
 
   \file gvl_calc.c
 
2
   \file lib/ogsf/gvl_calc.c
3
3
 
4
4
   \brief OGSF library - loading and manipulating volumes (lower level functions)
5
5
 
19
19
#include <math.h>
20
20
 
21
21
#include <grass/gis.h>
22
 
#include <grass/gstypes.h>
 
22
#include <grass/ogsf.h>
23
23
 
24
24
#include "rgbpack.h"
25
25
#include "mc33_table.h"
392
392
        iso_get_cube_values(isosurf, ATT_EMIT, x, y, z, val[ATT_EMIT]);
393
393
    }
394
394
 
395
 
    FOR_0_TO_N(3, d_sum[FOR_VAR] = 0.; n_sum[FOR_VAR] = 0.);
 
395
    FOR_0_TO_N(3, d_sum[FOR_VAR] = 0.;
 
396
               n_sum[FOR_VAR] = 0.);
396
397
 
397
398
    /* loop in edges */
398
399
    for (i = 0; i < cell_table[c_ndx].nedges; i++) {
601
602
    for (i = 0; i < gvol->n_isosurfs; i++) {
602
603
        isosurf = gvol->isosurf[i];
603
604
 
 
605
        /* initialize read/write buffers */
 
606
        dbuff[i].old = NULL;
 
607
        dbuff[i].new = NULL;
 
608
        dbuff[i].ndx_old = 0;
 
609
        dbuff[i].ndx_new = 0;
 
610
        dbuff[i].num_zero = 0;
 
611
 
604
612
        need_update[i] = 0;
605
613
        for (a = 1; a < MAX_ATTS; a++) {
606
614
            if (isosurf->att[a].changed) {
631
639
        }
632
640
 
633
641
        if (need_update[i]) {
634
 
            /* initialize read/write buffers */
 
642
            /* set data buffer */
635
643
            dbuff[i].old = isosurf->data;
636
 
            dbuff[i].new = NULL;
637
 
            dbuff[i].ndx_old = 0;
638
 
            dbuff[i].ndx_new = 0;
639
 
            dbuff[i].num_zero = 0;
640
644
        }
641
645
    }
642
646
 
680
684
                gvl_write_char(dbuff[i].ndx_new++, &(dbuff[i].new),
681
685
                               dbuff[i].num_zero);
682
686
 
 
687
            if (dbuff[i].old == isosurf->data)
 
688
                dbuff[i].old = NULL;
683
689
            G_free(isosurf->data);
684
 
            /* gvl_align_data(dbuff[i].ndx_new, dbuff[i].new); */
 
690
            gvl_align_data(dbuff[i].ndx_new, &(dbuff[i].new));
685
691
            isosurf->data = dbuff[i].new;
686
692
            isosurf->data_desc = 0;
687
693
        }
715
721
            }
716
722
        }
717
723
    }
 
724
    
 
725
    /* TODO: G_free() dbuff and need_update ??? */
718
726
 
719
727
    return (1);
720
728
}
738
746
        }
739
747
 
740
748
        G_debug(3,
741
 
                "gvl_write_char(): reallocate memory for pos : %d to : %d B",
 
749
                "gvl_write_char(): reallocate memory for pos : %d to : %lu B",
742
750
                pos, sizeof(char) * ((pos / BUFFER_SIZE) + 1) * BUFFER_SIZE);
743
751
    }
744
752
 
768
776
   \param pos position index
769
777
   \param data data buffer
770
778
 */
771
 
void gvl_align_data(int pos, unsigned char *data)
 
779
void gvl_align_data(int pos, unsigned char **data)
772
780
{
773
 
    /* WARNING: wrong pointer usage
774
 
     * this function needs **data, not *data,
775
 
     * and if pos == 0, data must be set to NULL,
776
 
     * thus: */
777
 
    return;
 
781
    unsigned char *p = *data;
 
782
    
778
783
 
779
784
    /* realloc memory to fit in data length */
780
 
    data = (char *)G_realloc(data, sizeof(char) * pos); /* G_fatal_error */
781
 
    if (!data) {
 
785
    p = (unsigned char *)G_realloc(p, sizeof(unsigned char) * pos);     /* G_fatal_error */
 
786
    if (!p) {
782
787
        return;
783
788
    }
784
789
 
785
790
    G_debug(3, "gvl_align_data(): reallocate memory finally to : %d B", pos);
786
791
 
 
792
    if (pos == 0)
 
793
        p = NULL;
 
794
    
 
795
    *data = p;
 
796
 
787
797
    return;
788
798
}
789
799
 
1012
1022
 
1013
1023
    /* end reading volume file */
1014
1024
    gvl_file_end_read(vf);
1015
 
    /* gvl_align_data(pos, slice->data); */
 
1025
    gvl_align_data(pos, &(slice->data));
1016
1026
 
1017
1027
    return (1);
1018
1028
}