Changeset 2827 for trunk


Ignore:
Timestamp:
Mar 7, 2012 2:01:55 PM (12 years ago)
Author:
ldelgass
Message:

Move Vector3/4Array typdefs to the Vector3/4.h headers and remove TypeDefs?.h.
Also misc. cleanups

Location:
trunk/packages/vizservers/nanovis
Files:
1 deleted
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/ContourLineFilter.cpp

    r2798 r2827  
    55 */
    66
    7 #include <string>
    8 #include "ContourLineFilter.h"
    9 #include <R2/graphics/R2VertexBuffer.h>
    107#include <stdlib.h>
    118#include <memory.h>
    12 #include "Vector4.h"
    13 #include "Vector3.h"
     9
     10#include <string>
     11
     12#include <R2/graphics/R2VertexBuffer.h>
     13
     14#include "ContourLineFilter.h"
    1415
    1516ContourLineFilter::ContourLineFilter()
  • trunk/packages/vizservers/nanovis/ContourLineFilter.h

    r2798 r2827  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef _CONTOURFILTER_H_
    3 #define _CONTOURFILTER_H_
     2#ifndef CONTOURLINEFILTER_H
     3#define CONTOURLINEFILTER_H
     4
     5#include <list>
     6
     7#include <R2/graphics/R2Geometry.h>
    48
    59#include "Vector3.h"
    610#include "Vector4.h"
    7 #include "TypeDefs.h"
    8 #include <R2/graphics/R2Geometry.h>
    9 #include <list>
    1011
    11 class ContourLineFilter {
    12 public :
    13     class ContourLine {
    14     public :
     12class ContourLineFilter
     13{
     14public:
     15    class ContourLine
     16    {
     17    public:
    1518        float _value;
    1619        std::list<Vector3> _points;
    17     public :
     20
    1821        ContourLine(float value);
    19        
    20     private :
    21         bool isValueWithIn(float v1, float v2) {
     22
     23        /**
     24         * @brief
     25         * @ret Returns the number of points
     26         */
     27        int createLine(int width, int height, Vector3 *vertices, bool top);
     28        int createLine(int width, int height, Vector4 *vertices, bool top);
     29
     30    private:
     31        bool isValueWithIn(float v1, float v2)
     32        {
    2233            return ((_value >= v1 && _value <= v2) ||
    2334                    (_value >= v2 && _value <= v1));
    2435        }
    25         void getContourPoint(int vertexIndex1, int vertexIndex2, Vector3* vertices, int width, bool top);
    26         void getContourPoint(int vertexIndex1, int vertexIndex2, Vector4* vertices, int width, bool top);
    27     public : 
    28         /**
    29          * @brief
    30          * @ret Returns the number of points
    31          */
    32         int createLine(int width, int height, Vector3* vertices, bool top);
    33         int createLine(int width, int height, Vector4* vertices, bool top);
     36        void getContourPoint(int vertexIndex1, int vertexIndex2, Vector3 *vertices, int width, bool top);
     37        void getContourPoint(int vertexIndex1, int vertexIndex2, Vector4 *vertices, int width, bool top);
    3438    };
    35    
    36     typedef std::list<ContourLine*> ContourLineList;
    37    
    38 private :
    39     ContourLineList _lines;
    40     Vector3Array* _colorMap;
    41     bool _top;
    42 public :
     39
     40    typedef std::list<ContourLine *> ContourLineList;
     41
    4342    ContourLineFilter();
    44    
    45 private :
    46     void clear();
    47    
    48 public :
    49     R2Geometry* create(float min, float max, int linecount, Vector3* vertices, int width, int height);
    50     R2Geometry* create(float min, float max, int linecount, Vector4* vertices, int width, int height);
    51     void setColorMap(Vector3Array* colorMap);
     43
     44    R2Geometry *create(float min, float max, int linecount, Vector3 *vertices, int width, int height);
     45    R2Geometry *create(float min, float max, int linecount, Vector4 *vertices, int width, int height);
     46
     47    void setColorMap(Vector3Array *colorMap);
    5248   
    5349    void setHeightTop(bool top)
     
    5551        _top = top;
    5652    }
     53
     54private:
     55    void clear();
     56
     57    ContourLineList _lines;
     58    Vector3Array *_colorMap;
     59    bool _top;
    5760};
    5861
  • trunk/packages/vizservers/nanovis/DataLoader.cpp

    r2798 r2827  
    55#include <stdlib.h>
    66#include <math.h>
    7 #include <Trace.h>
     7
     8#include "Trace.h"
    89
    910inline void endian_swap(unsigned int& x)
     
    1516}
    1617
    17 
    1818char buff[255];
    19 void getLine(FILE*& fp)
     19void getLine(FILE *fp)
    2020{
    2121    char ch;
     
    3030}
    3131
    32 void* LoadDx(const char* fname, int& width, int& height, int&depth, float& min, float& max, float& nonzero_min,
    33                          float& axisScaleX, float& axisScaleY, float& axisScaleZ)
    34 {
    35         std::string path = fname;
    36 
    37         if (path.size() == 0)
    38         {
    39             ERROR("file not found[%s]\n", path.c_str());
    40             return NULL;
    41         }
    42 
    43         FILE* fp = fopen(path.c_str(), "rb");
    44         if (fp == NULL)
    45         {
    46             ERROR("file not found %s\n", path.c_str());
    47             return NULL;
    48         }
    49 
    50         int index;
    51         do {
    52                 getLine(fp);
    53         } while (memcmp(buff, "object", 6));
    54        
    55         float origin_x, origin_y, origin_z;
    56         double delta_x, delta_y, delta_z;
     32void *LoadDx(const char *fname,
     33             int& width, int& height, int& depth,
     34             float& min, float& max, float& nonzero_min,
     35             float& axisScaleX, float& axisScaleY, float& axisScaleZ)
     36{
     37    std::string path = fname;
     38
     39    if (path.size() == 0) {
     40        ERROR("file not found[%s]\n", path.c_str());
     41        return NULL;
     42    }
     43
     44    FILE *fp = fopen(path.c_str(), "rb");
     45    if (fp == NULL) {
     46        ERROR("file not found %s\n", path.c_str());
     47        return NULL;
     48    }
     49
     50    int index;
     51    do {
     52        getLine(fp);
     53    } while (memcmp(buff, "object", 6));
     54       
     55    float origin_x, origin_y, origin_z;
     56    double delta_x, delta_y, delta_z;
    5757    double temp;
    58         char str[5][20];
    59 
    60         //object 1 class gridpositions counts 5 5 5
    61         sscanf(buff, "%s%s%s%s%s%d%d%d", str[0], str[1], str[2], str[3], str[4], &width, &depth, &height);
    62        
    63         //origin 0 0 0
    64         getLine(fp);
    65         sscanf(buff, "%s%f%f%f", str[0], &(origin_x), &(origin_y), &(origin_z));
    66        
    67         // delta  0.5431 0 0
    68         getLine(fp);
    69         sscanf(buff, "%s%lf%lf%lf", str[0], &(delta_x), &temp, &temp);
    70        
    71         // delta  0 0.5431 0
    72     getLine(fp);
    73         sscanf(buff, "%s%lf%lf%lf", str[0], &temp, &(delta_y), &temp);
     58    char str[5][20];
     59
     60    //object 1 class gridpositions counts 5 5 5
     61    sscanf(buff, "%s%s%s%s%s%d%d%d", str[0], str[1], str[2], str[3], str[4], &width, &depth, &height);
     62       
     63    //origin 0 0 0
     64    getLine(fp);
     65    sscanf(buff, "%s%f%f%f", str[0], &(origin_x), &(origin_y), &(origin_z));
     66       
     67    // delta  0.5431 0 0
     68    getLine(fp);
     69    sscanf(buff, "%s%lf%lf%lf", str[0], &(delta_x), &temp, &temp);
     70       
     71    // delta  0 0.5431 0
     72    getLine(fp);
     73    sscanf(buff, "%s%lf%lf%lf", str[0], &temp, &(delta_y), &temp);
    7474   
    75         // delta  0 0 0.5431
    76         getLine(fp);
    77         sscanf(buff, "%s%lf%lf%lf", str[0], &temp, &temp, &(delta_z));
    78        
    79         getLine(fp);
    80         getLine(fp);
    81         getLine(fp);
    82         getLine(fp);
    83 
    84         min = nonzero_min = 1e27f;
    85         max = -1e27f;
    86 
    87         float* data = 0;
    88         int d, h, w;
    89         float scalar;           
    90         index = 0;
    91 
    92         if (width < height)
    93         {
    94                 int size = width * height * depth;
    95                 data = (float*) malloc(size * sizeof(float));
    96                 memset(data, 0, sizeof(float) * size);
    97 
    98 
    99                 for (w = 0; w < width; ++w) // x
    100                         for (d = 0; d < depth; ++d) //z
    101                         {
    102                                 for (h = 0; h < width; ++h) // y
    103                                 {
    104                                         scalar = atof(fgets(buff, 255, fp));
    105                                         data[h * width + d * width * width + w] = scalar;
    106                                         if (scalar < min) min = scalar;
    107                                         if (scalar != 0.0f && nonzero_min > scalar) nonzero_min = scalar;
    108                                         if (scalar > max) max = scalar;
    109                                 }
    110                                 for (;h < height; ++h)
    111                                 {
    112                                         scalar = atof(fgets(buff, 255, fp));
    113                                 }
    114                         }
    115 
    116                 height = width;
    117 
    118                
    119 
    120                
    121         }
    122         else if (width > height)
    123         {
    124                 int size = width * width * width;
    125                 data = (float*) malloc(size * sizeof(float));
    126                 memset(data, 0, sizeof(float) * size);
    127                 for (w = 0; w < width; ++w) // x
    128                         for (d = 0; d < depth; ++d) //z
    129                                 for (h = 0; h < height; ++h) // y
    130                                 {
    131                                         scalar = atof(fgets(buff, 255, fp));
    132                                         data[h * width + d * width * width + w] = scalar;
    133                                         if (scalar < min) min = scalar;
    134                                         if (scalar != 0.0f && nonzero_min > scalar) nonzero_min = scalar;
    135                                         if (scalar > max) max = scalar;
    136                                 }
    137 
    138                 height = width;
    139 
    140        
    141 
    142                
    143         }
    144         else
    145         {
    146                 int size = width * height * depth;
    147                 data = (float*) malloc(size * sizeof(float));
    148 
    149                 for (w = 0; w < width; ++w) // x
    150                         for (d = 0; d < depth; ++d) //z
    151                                 for (h = 0; h < height; ++h) // y
    152                                 {
    153                                         scalar = atof(fgets(buff, 255, fp));
    154                                         data[h * width + d * width * height + w] = scalar;
    155                                         if (scalar < min) min = scalar;
    156                                         if (scalar != 0.0f && nonzero_min > scalar) nonzero_min = scalar;
    157                                         if (scalar > max) max = scalar;
    158                                 }
    159         }
    160 
    161         axisScaleX = origin_x + width * delta_x;
    162         axisScaleY = origin_y + height * delta_y;
    163         axisScaleZ = origin_z + depth * delta_z;
    164 
    165         fclose(fp);
    166 
    167         return data;
    168 }
    169 
    170 void* LoadFlowDx(const char* fname, int& width, int& height, int&depth, float& min, float& max, float& nonzero_min,
    171                          float& axisScaleX, float& axisScaleY, float& axisScaleZ)
    172 {
    173         std::string path = fname;
    174 
    175         if (path.size() == 0)
    176         {
    177             ERROR("file not found[%s]\n", path.c_str());
    178             return NULL;
    179         }
    180 
    181         FILE* fp = fopen(path.c_str(), "rb");
    182         if (fp == NULL)
    183         {
    184             ERROR("file not found %s\n", path.c_str());
    185             return NULL;
    186         }
    187 
    188         int index;
    189         do {
    190                 getLine(fp);
    191         } while (memcmp(buff, "object", 6));
    192        
    193         double origin_x, origin_y, origin_z;
    194         double delta_x, delta_y, delta_z;
     75    // delta  0 0 0.5431
     76    getLine(fp);
     77    sscanf(buff, "%s%lf%lf%lf", str[0], &temp, &temp, &(delta_z));
     78       
     79    getLine(fp);
     80    getLine(fp);
     81    getLine(fp);
     82    getLine(fp);
     83
     84    min = nonzero_min = 1e27f;
     85    max = -1e27f;
     86
     87    float *data = 0;
     88    int d, h, w;
     89    float scalar;               
     90    index = 0;
     91
     92    if (width < height) {
     93        int size = width * height * depth;
     94        data = (float *) malloc(size * sizeof(float));
     95        memset(data, 0, sizeof(float) * size);
     96
     97
     98        for (w = 0; w < width; ++w) {// x
     99            for (d = 0; d < depth; ++d) { //z
     100                for (h = 0; h < width; ++h) { // y
     101                    scalar = atof(fgets(buff, 255, fp));
     102                    data[h * width + d * width * width + w] = scalar;
     103                    if (scalar < min) min = scalar;
     104                    if (scalar != 0.0f && nonzero_min > scalar) nonzero_min = scalar;
     105                    if (scalar > max) max = scalar;
     106                }
     107                for (;h < height; ++h) {
     108                    scalar = atof(fgets(buff, 255, fp));
     109                }
     110            }
     111        }
     112
     113        height = width;
     114    } else if (width > height) {
     115        int size = width * width * width;
     116        data = (float *) malloc(size * sizeof(float));
     117        memset(data, 0, sizeof(float) * size);
     118        for (w = 0; w < width; ++w) { // x
     119            for (d = 0; d < depth; ++d) { //z
     120                for (h = 0; h < height; ++h) { // y
     121                    scalar = atof(fgets(buff, 255, fp));
     122                    data[h * width + d * width * width + w] = scalar;
     123                    if (scalar < min) min = scalar;
     124                    if (scalar != 0.0f && nonzero_min > scalar) nonzero_min = scalar;
     125                    if (scalar > max) max = scalar;
     126                }
     127            }
     128        }
     129
     130        height = width;
     131    } else {
     132        int size = width * height * depth;
     133        data = (float *) malloc(size * sizeof(float));
     134
     135        for (w = 0; w < width; ++w) { // x
     136            for (d = 0; d < depth; ++d) { //z
     137                for (h = 0; h < height; ++h) { // y
     138                    scalar = atof(fgets(buff, 255, fp));
     139                    data[h * width + d * width * height + w] = scalar;
     140                    if (scalar < min) min = scalar;
     141                    if (scalar != 0.0f && nonzero_min > scalar) nonzero_min = scalar;
     142                    if (scalar > max) max = scalar;
     143                }
     144            }
     145        }
     146    }
     147
     148    axisScaleX = origin_x + width * delta_x;
     149    axisScaleY = origin_y + height * delta_y;
     150    axisScaleZ = origin_z + depth * delta_z;
     151
     152    fclose(fp);
     153
     154    return data;
     155}
     156
     157void *LoadFlowDx(const char *fname,
     158                 int& width, int& height, int& depth,
     159                 float& min, float& max, float& nonzero_min,
     160                 float& axisScaleX, float& axisScaleY, float& axisScaleZ)
     161{
     162    std::string path = fname;
     163
     164    if (path.size() == 0) {
     165        ERROR("file not found[%s]\n", path.c_str());
     166        return NULL;
     167    }
     168
     169    FILE *fp = fopen(path.c_str(), "rb");
     170    if (fp == NULL) {
     171        ERROR("file not found %s\n", path.c_str());
     172        return NULL;
     173    }
     174
     175    int index;
     176    do {
     177        getLine(fp);
     178    } while (memcmp(buff, "object", 6));
     179       
     180    double origin_x, origin_y, origin_z;
     181    double delta_x, delta_y, delta_z;
    195182    double temp;
    196         char str[5][20];
    197 
    198         //object 1 class gridpositions counts 5 5 5
    199         sscanf(buff, "%s%s%s%s%s%d%d%d", str[0], str[1], str[2], str[3], str[4], &width, &height, &depth);
    200        
    201         getLine(fp);
    202         sscanf(buff, "%s%lg%lg%lg", str[0], &(origin_x), &(origin_y), &(origin_z));
    203        
    204         getLine(fp);
    205         sscanf(buff, "%s%lg%lg%lg", str[0], &(delta_x), &temp, &temp);
    206        
    207         getLine(fp);
    208         sscanf(buff, "%s%lg%lg%lg", str[0], &temp, &(delta_y), &temp);
     183    char str[5][20];
     184
     185    //object 1 class gridpositions counts 5 5 5
     186    sscanf(buff, "%s%s%s%s%s%d%d%d", str[0], str[1], str[2], str[3], str[4], &width, &height, &depth);
     187       
     188    getLine(fp);
     189    sscanf(buff, "%s%lg%lg%lg", str[0], &(origin_x), &(origin_y), &(origin_z));
     190       
     191    getLine(fp);
     192    sscanf(buff, "%s%lg%lg%lg", str[0], &(delta_x), &temp, &temp);
     193       
     194    getLine(fp);
     195    sscanf(buff, "%s%lg%lg%lg", str[0], &temp, &(delta_y), &temp);
    209196   
    210         getLine(fp);
    211         sscanf(buff, "%s%lf%lf%lf", str[0], &temp, &temp, &(delta_z));
    212        
    213         getLine(fp);
    214         getLine(fp);
    215 
    216         min = nonzero_min = 1e27f;
    217         max = -1e27f;
    218 
    219         float* data = 0;
    220         int d, h, w;           
    221         index = 0;
    222 
    223        
    224         int size = width * height * depth;
    225         data = (float*) malloc(size * sizeof(float) * 4);
    226         float* ptr = data;
    227         double x, y, z, length;
    228         char* ret = 0;
    229        
    230         for (w = 0; w < width; ++w) // x
    231                 for (h = 0; h < height; ++h) // y       
    232                         for (d = 0; d < depth; ++d) //z
    233                         {
    234                                 ret = fgets(buff, 255, fp);
    235                                 sscanf(buff, "%lg%lg%lg", &x, &y, &z);
    236                                 ptr = data + (d * width * height + h * width + w) * 4;
    237                                 length = sqrt(x*x+y*y+z*z);
    238                                 *ptr = length; ptr++;
    239                                 *ptr = x; ptr++;
    240                                 *ptr = y; ptr++;
    241                                 *ptr = z;
    242 
    243                                 if (length < min) min = length;
    244                                 if (length != 0.0f && nonzero_min > length) nonzero_min = length;
    245                                 if (length > max)
    246                                 {
    247                                         //TRACE("max %lf %lf %fl\n", x, y, z);
    248                                         max = length;
    249                                 }
    250                         }
    251 
    252         ptr = data;
    253         for (int i = 0; i < size; ++i)
    254         {
    255                 *ptr = *ptr / max; ++ptr;
    256                 *ptr = (*ptr / (2.0*max)) + 0.5; ++ptr;
    257                 *ptr = (*ptr / (2.0 * max)) + 0.5; ++ptr;
    258                 *ptr = (*ptr / (2.0 * max)) + 0.5; ++ptr;
    259         }
    260         axisScaleX = width * delta_x;
    261         axisScaleY = height * delta_y;
    262         axisScaleZ = depth * delta_z;
    263 
    264         fclose(fp);
    265 
    266         TRACE("width %d, height %d, depth %d, min %f, max %f, scaleX %f, scaleY %f, scaleZ %f\n",
    267                 width, height, depth, min, max, axisScaleX, axisScaleY, axisScaleZ);
    268         return data;
    269 }
    270 
    271 void* LoadProcessedFlowRaw(const char* fname, int width, int height, int depth, float min, float max, float& axisScaleX, float& axisScaleY, float& axisScaleZ)
    272 {
    273         std::string path = fname;
    274 
    275         if (fname == 0)
    276         {
    277             ERROR("file name is null\n");
    278             return NULL;
    279         }
    280 
    281         FILE* fp = fopen(fname, "rb");
    282         if (fp == NULL)
    283         {
    284             ERROR("file not found %s\n", fname);
    285             return NULL;
    286         }
    287 
    288         int size = width * height * depth;
    289         float* srcdata = (float*) malloc(size * sizeof(float) * 4);
    290         fread(srcdata, size * 4 * sizeof(float), 1, fp);
    291         fclose(fp);
    292 
    293         axisScaleX = width;
    294         axisScaleY = height;
    295         axisScaleZ = depth;
    296 
    297         return srcdata;
    298 }
    299 
    300 void LoadProcessedFlowRaw(const char* fname, int width, int height, int depth, float* data)
    301 {
    302         std::string path = fname;
    303 
    304         if (fname == 0)
    305         {
    306             ERROR("file name is null\n");
    307             return;
    308         }
    309 
    310         FILE* fp = fopen(fname, "rb");
    311         if (fp == NULL)
    312         {
    313             ERROR("file not found %s\n", fname);
    314             return;
    315         }
    316 
    317         int size = width * height * depth;
    318         fread(data, size * 4 * sizeof(float), 1, fp);
    319         fclose(fp);
    320 }
    321 
    322 
    323 void* LoadFlowRaw(const char* fname, int width, int height, int depth, float& min, float& max, float& nonzero_min,
    324                          float& axisScaleX, float& axisScaleY, float& axisScaleZ, int skipByte, bool bigEndian)
    325 {
    326         std::string path = fname;
    327 
    328         if (path.size() == 0)
    329         {
    330             ERROR("file not found[%s]\n", path.c_str());
    331             return NULL;
    332         }
    333 
    334         FILE* fp = fopen(path.c_str(), "rb");
    335         if (fp == NULL)
    336         {
    337             ERROR("file not found %s\n", path.c_str());
    338             return NULL;
    339         }
    340 
    341        
    342 
    343         min = nonzero_min = 1e27f;
    344         max = -1e27f;
    345 
    346         float* srcdata = 0;
    347         float* data = 0;
    348         int d, h, w;           
    349         int index = 0;
    350 
    351         int size = width * height * depth;
    352         srcdata = (float*) malloc(size * sizeof(float) * 3);
    353         memset(srcdata, 0, size * sizeof(float) * 3);
    354         if (skipByte != 0) fread(srcdata, skipByte, 1, fp);
    355         fread(srcdata, size * 3 * sizeof(float), 1, fp);
    356         fclose(fp);
    357 
    358         if (bigEndian) {
    359                 unsigned int* dd = (unsigned int*) srcdata;
    360                 for (int i = 0; i < size * 3; ++i)
    361                 {
    362                         endian_swap(dd[i]);
    363                 }
    364         }
    365 
    366        
    367         data = (float*) malloc(size * sizeof(float) * 4);
    368         memset(data, 0, size * sizeof(float) * 4);
    369 
    370         float* ptr = data;
    371         double x, y, z, length;
    372        
    373         for (d = 0; d < depth; ++d) //z
    374                 for (h = 0; h < height; ++h) // y       
    375                         for (w = 0; w < width; ++w, index +=3) // x
    376                         {
    377                                 x = srcdata[index];
    378                                 y = srcdata[index + 1];
    379                                 z = srcdata[index + 2];
    380                                 ptr = data + (d * width * height + h * width + w) * 4;
    381                                 length = sqrt(x*x+y*y+z*z);
    382                                 *ptr = length; ptr++;
    383                                 *ptr = x; ptr++;
    384                                 *ptr = y; ptr++;
    385                                 *ptr = z;
    386 
    387                                 if (length < min) min = length;
    388                                 if (length != 0.0f && nonzero_min > length) nonzero_min = length;
    389                                 if (length > max)
    390                                 {
    391                                         TRACE("max %lf %lf %fl\n", x, y, z);
    392                                         max = length;
    393                                 }
    394                         }
    395 
    396         ptr = data;
    397         for (int i = 0; i < size; ++i)
    398         {
    399                 *ptr = *ptr / max; ++ptr;
    400                 *ptr = (*ptr / (2.0*max)) + 0.5; ++ptr;
    401                 *ptr = (*ptr / (2.0 * max)) + 0.5; ++ptr;
    402                 *ptr = (*ptr / (2.0 * max)) + 0.5; ++ptr;
    403         }
    404         axisScaleX = width;
    405         axisScaleY = height;
    406         axisScaleZ = depth;
    407 
    408         fclose(fp);
    409 
    410         TRACE("width %d, height %d, depth %d, min %f, max %f, scaleX %f, scaleY %f, scaleZ %f\n",
    411                 width, height, depth, min, max, axisScaleX, axisScaleY, axisScaleZ);
    412         return data;
    413 }
    414 
    415 
     197    getLine(fp);
     198    sscanf(buff, "%s%lf%lf%lf", str[0], &temp, &temp, &(delta_z));
     199       
     200    getLine(fp);
     201    getLine(fp);
     202
     203    min = nonzero_min = 1e27f;
     204    max = -1e27f;
     205
     206    float *data = 0;
     207    int d, h, w;               
     208    index = 0;
     209
     210    int size = width * height * depth;
     211    data = (float *) malloc(size * sizeof(float) * 4);
     212    float *ptr = data;
     213    double x, y, z, length;
     214    char *ret = 0;
     215
     216    for (w = 0; w < width; ++w) { // x
     217        for (h = 0; h < height; ++h) { // y     
     218            for (d = 0; d < depth; ++d) { //z   
     219                ret = fgets(buff, 255, fp);
     220                sscanf(buff, "%lg%lg%lg", &x, &y, &z);
     221                ptr = data + (d * width * height + h * width + w) * 4;
     222                length = sqrt(x*x+y*y+z*z);
     223                *ptr = length; ptr++;
     224                *ptr = x; ptr++;
     225                *ptr = y; ptr++;
     226                *ptr = z;
     227
     228                if (length < min) min = length;
     229                if (length != 0.0f && nonzero_min > length) nonzero_min = length;
     230                if (length > max) {
     231                    //TRACE("max %lf %lf %fl\n", x, y, z);
     232                    max = length;
     233                }
     234            }
     235        }
     236    }
     237
     238    ptr = data;
     239    for (int i = 0; i < size; ++i) {
     240        *ptr = *ptr / max; ++ptr;
     241        *ptr = (*ptr / (2.0*max)) + 0.5; ++ptr;
     242        *ptr = (*ptr / (2.0 * max)) + 0.5; ++ptr;
     243        *ptr = (*ptr / (2.0 * max)) + 0.5; ++ptr;
     244    }
     245    axisScaleX = width * delta_x;
     246    axisScaleY = height * delta_y;
     247    axisScaleZ = depth * delta_z;
     248
     249    fclose(fp);
     250
     251    TRACE("width %d, height %d, depth %d, min %f, max %f, scaleX %f, scaleY %f, scaleZ %f\n",
     252          width, height, depth, min, max, axisScaleX, axisScaleY, axisScaleZ);
     253    return data;
     254}
     255
     256void *LoadProcessedFlowRaw(const char *fname,
     257                           int width, int height, int depth,
     258                           float min, float max,
     259                           float& axisScaleX, float& axisScaleY, float& axisScaleZ)
     260{
     261    std::string path = fname;
     262
     263    if (fname == 0) {
     264        ERROR("file name is null\n");
     265        return NULL;
     266    }
     267
     268    FILE *fp = fopen(fname, "rb");
     269    if (fp == NULL) {
     270        ERROR("file not found %s\n", fname);
     271        return NULL;
     272    }
     273
     274    int size = width * height * depth;
     275    float *srcdata = (float *) malloc(size * sizeof(float) * 4);
     276    fread(srcdata, size * 4 * sizeof(float), 1, fp);
     277    fclose(fp);
     278
     279    axisScaleX = width;
     280    axisScaleY = height;
     281    axisScaleZ = depth;
     282
     283    return srcdata;
     284}
     285
     286void LoadProcessedFlowRaw(const char *fname,
     287                          int width, int height, int depth,
     288                          float *data)
     289{
     290    std::string path = fname;
     291
     292    if (fname == 0) {
     293        ERROR("file name is null\n");
     294        return;
     295    }
     296
     297    FILE *fp = fopen(fname, "rb");
     298    if (fp == NULL) {
     299        ERROR("file not found %s\n", fname);
     300        return;
     301    }
     302
     303    int size = width * height * depth;
     304    fread(data, size * 4 * sizeof(float), 1, fp);
     305    fclose(fp);
     306}
     307
     308void *LoadFlowRaw(const char *fname, int width, int height, int depth,
     309                  float& min, float& max, float& nonzero_min,
     310                  float& axisScaleX, float& axisScaleY, float& axisScaleZ,
     311                  int skipByte, bool bigEndian)
     312{
     313    std::string path = fname;
     314
     315    if (path.size() == 0) {
     316        ERROR("file not found[%s]\n", path.c_str());
     317        return NULL;
     318    }
     319
     320    FILE *fp = fopen(path.c_str(), "rb");
     321    if (fp == NULL) {
     322        ERROR("file not found %s\n", path.c_str());
     323        return NULL;
     324    }
     325
     326    min = nonzero_min = 1e27f;
     327    max = -1e27f;
     328
     329    float *srcdata = 0;
     330    float *data = 0;
     331    int d, h, w;               
     332    int index = 0;
     333
     334    int size = width * height * depth;
     335    srcdata = (float *) malloc(size * sizeof(float) * 3);
     336    memset(srcdata, 0, size * sizeof(float) * 3);
     337    if (skipByte != 0) fread(srcdata, skipByte, 1, fp);
     338    fread(srcdata, size * 3 * sizeof(float), 1, fp);
     339    fclose(fp);
     340
     341    if (bigEndian) {
     342        unsigned int *dd = (unsigned int *) srcdata;
     343        for (int i = 0; i < size * 3; ++i) {
     344            endian_swap(dd[i]);
     345        }
     346    }
     347
     348    data = (float *) malloc(size * sizeof(float) * 4);
     349    memset(data, 0, size * sizeof(float) * 4);
     350
     351    float *ptr = data;
     352    double x, y, z, length;
     353
     354    for (d = 0; d < depth; ++d) { //z   
     355        for (h = 0; h < height; ++h) { // y     
     356            for (w = 0; w < width; ++w, index +=3) { // x
     357                x = srcdata[index];
     358                y = srcdata[index + 1];
     359                z = srcdata[index + 2];
     360                ptr = data + (d * width * height + h * width + w) * 4;
     361                length = sqrt(x*x+y*y+z*z);
     362                *ptr = length; ptr++;
     363                *ptr = x; ptr++;
     364                *ptr = y; ptr++;
     365                *ptr = z;
     366
     367                if (length < min) min = length;
     368                if (length != 0.0f && nonzero_min > length) nonzero_min = length;
     369                if (length > max) {
     370                    TRACE("max %lf %lf %fl\n", x, y, z);
     371                    max = length;
     372                }
     373            }
     374        }
     375    }
     376
     377    ptr = data;
     378    for (int i = 0; i < size; ++i) {
     379        *ptr = *ptr / max; ++ptr;
     380        *ptr = (*ptr / (2.0*max)) + 0.5; ++ptr;
     381        *ptr = (*ptr / (2.0 * max)) + 0.5; ++ptr;
     382        *ptr = (*ptr / (2.0 * max)) + 0.5; ++ptr;
     383    }
     384    axisScaleX = width;
     385    axisScaleY = height;
     386    axisScaleZ = depth;
     387
     388    fclose(fp);
     389
     390    TRACE("width %d, height %d, depth %d, min %f, max %f, scaleX %f, scaleY %f, scaleZ %f\n",
     391          width, height, depth, min, max, axisScaleX, axisScaleY, axisScaleZ);
     392    return data;
     393}
  • trunk/packages/vizservers/nanovis/HeightMap.cpp

    r2812 r2827  
    1212#include "HeightMap.h"
    1313#include "ContourLineFilter.h"
    14 #include "TypeDefs.h"
    1514#include "Texture1D.h"
    1615#include "R2/R2FilePath.h"
  • trunk/packages/vizservers/nanovis/R2/include/R2/R2.h

    r2798 r2827  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __R2_H__
    3 #define __R2_H__
     2#ifndef R2_H
     3#define R2_H
    44
    55#include <GL/glew.h>
     
    6464extern void R2Exit();
    6565
    66 #endif // __R2_H__
     66#endif
    6767
  • trunk/packages/vizservers/nanovis/R2/include/R2/R2FilePath.h

    r2798 r2827  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __R2_FILE_PATH_H__
    3 #define __R2_FILE_PATH_H__
     2#ifndef R2_FILE_PATH_H
     3#define R2_FILE_PATH_H
    44
    55#include <list>
     6
    67#include <R2/R2string.h>
    78
    8 class R2FilePath {
     9class R2FilePath
     10{
    911    typedef std::list<R2string> R2stringList;
    1012    typedef std::list<R2string>::iterator R2stringListIter;
  • trunk/packages/vizservers/nanovis/R2/include/R2/R2Fonts.h

    r2798 r2827  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __R2_FONTS_H__
    3 #define __R2_FONTS_H__
     2#ifndef R2_FONTS_H
     3#define R2_FONTS_H
    44
    55#include <R2/R2.h>
     
    88#include <vector>
    99
    10 class R2Fonts : public R2Object {
    11 
     10class R2Fonts : public R2Object
     11{
    1212    struct R2FontAttributes {
    1313        char *_fontName;
  • trunk/packages/vizservers/nanovis/R2/include/R2/graphics/R2Geometry.h

    r2798 r2827  
    11 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef _R2_GEOMETRY_H_
    3 #define _R2_GEOMETRY_H_
     2#ifndef R2_GEOMETRY_H
     3#define R2_GEOMETRY_H
    44
    5 #include <GL/gl.h>
     5#include <GL/glew.h>
    66#include <R2/graphics/R2VertexBuffer.h>
    77#include <R2/graphics/R2IndexBuffer.h>
    88
    9 class R2Geometry {
     9class R2Geometry
     10{
    1011public :
    1112    enum {
     
    1718    };
    1819
    19 private :
    20     R2VertexBuffer* _vertexBuffer;
    21     R2VertexBuffer* _colorBuffer;
    22     R2IndexBuffer* _indexBuffer;
    23     int _primitiveType;
    24 
    2520public :
    2621    R2Geometry(int primitive, R2VertexBuffer* vertexBuffer,
     
    2924               R2VertexBuffer* colorBuffer, R2IndexBuffer* indexBuffer);
    3025    ~R2Geometry();
    31    
    32 public :
     26
    3327    void render();
     28
     29private :
     30    R2VertexBuffer *_vertexBuffer;
     31    R2VertexBuffer *_colorBuffer;
     32    R2IndexBuffer *_indexBuffer;
     33    int _primitiveType;
    3434};
    3535
  • trunk/packages/vizservers/nanovis/R2/include/R2/graphics/R2IndexBuffer.h

    r2798 r2827  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef _R2_INDEX_BUFFER_H_
    3 #define _R2_INDEX_BUFFER_H_
     2#ifndef R2_INDEX_BUFFER_H
     3#define R2_INDEX_BUFFER_H
    44
    5 class R2IndexBuffer {
    6         int _indexCount;
    7         int* _data;
    8 public :
    9         R2IndexBuffer(int indexCount, int* data, bool copy = true);
    10         ~R2IndexBuffer();
    11 public :
    12         int getIndexCount() const;
    13         const int* getData() const;
     5class R2IndexBuffer
     6{
     7    int _indexCount;
     8    int *_data;
     9
     10public:
     11    R2IndexBuffer(int indexCount, int* data, bool copy = true);
     12    ~R2IndexBuffer();
     13
     14    int getIndexCount() const;
     15    const int* getData() const;
    1416};
    1517
    1618inline int R2IndexBuffer::getIndexCount() const
    1719{
    18         return _indexCount;
     20    return _indexCount;
    1921}
    2022
    2123inline const int* R2IndexBuffer::getData() const
    2224{
    23         return _data;
     25    return _data;
    2426}
    2527
    26 #endif //
     28#endif
  • trunk/packages/vizservers/nanovis/R2/include/R2/graphics/R2VertexBuffer.h

    r2798 r2827  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef _R2_VERTEXBUFFER_H_
    3 #define _R2_VERTEXBUFFER_H_
     2#ifndef R2_VERTEXBUFFER_H
     3#define R2_VERTEXBUFFER_H
    44
    5 class R2VertexBuffer {
    6         unsigned int _graphicObjectID;
    7         int _byteSize;
    8         int _vertexCount;
    9 public :
    10         void* _data;
    11 public :
    12         enum {
    13                 POSITION3 = 0x01,
    14                 NORMAL3 = 0x02,
    15                 COLOR3 = 0x04,
    16                 COLOR4 = 0x08
    17         };
     5class R2VertexBuffer
     6{
     7    unsigned int _graphicObjectID;
     8    int _byteSize;
     9    int _vertexCount;
    1810
    19 public :
    20         R2VertexBuffer(int type, int vertexCount, int byteSize, void* data, bool copy = true);
    21         ~R2VertexBuffer();
     11public:
     12    void *_data;
    2213
    23 public :
    24         unsigned int getGraphicObjectID() const;
     14    enum {
     15        POSITION3 = 0x01,
     16        NORMAL3 = 0x02,
     17        COLOR3 = 0x04,
     18        COLOR4 = 0x08
     19    };
    2520
    26         void updateBuffer(void* data);
    27         int getVertexCount() const;
     21    R2VertexBuffer(int type, int vertexCount, int byteSize, void* data, bool copy = true);
     22    ~R2VertexBuffer();
     23
     24    unsigned int getGraphicObjectID() const;
     25
     26    void updateBuffer(void* data);
     27    int getVertexCount() const;
    2828};
    2929
     
    3838}
    3939
    40 #endif //
     40#endif
  • trunk/packages/vizservers/nanovis/Unirect.cpp

    r2809 r2827  
    22#include <float.h>
    33#include <tcl.h>
    4 #include <Unirect.h>
    5 #include "RpField1D.h"
    6 #include "RpFieldRect3D.h"
     4
     5#include <RpField1D.h>
     6#include <RpFieldRect3D.h>
     7
     8#include "Unirect.h"
    79#include "Trace.h"
    810
  • trunk/packages/vizservers/nanovis/Vector3.h

    r2822 r2827  
    1414 * ======================================================================
    1515 */
    16 #ifndef _VECTOR3_H_
    17 #define _VECTOR3_H_
     16#ifndef VECTOR3_H
     17#define VECTOR3_H
    1818
    19 #include <math.h>
     19#include <math.h>
     20
     21#include <vector>
     22
    2023#include "Mat4x4.h"
    2124
     
    140143    void transform(const Vector3& v, const Mat4x4& mat)
    141144    {
    142         const float* m = mat.m;
     145        const float *m = mat.m;
    143146        x = m[0] * v.x + m[4] * v.y + m[8]  * v.z + m[12];
    144147        y = m[1] * v.x + m[5] * v.y + m[9]  * v.z + m[13];
     
    167170};
    168171
     172typedef std::vector<Vector3> Vector3Array;
     173
    169174#endif
  • trunk/packages/vizservers/nanovis/Vector4.h

    r2822 r2827  
    1414 * ======================================================================
    1515 */
    16 #ifndef _VECTOR4_H_
    17 #define _VECTOR4_H_
     16#ifndef VECTOR4_H
     17#define VECTOR4_H
     18
     19#include <vector>
    1820
    1921#include "Trace.h"
     
    7476};
    7577
     78typedef std::vector<Vector4> Vector4Array;
     79
    7680#endif
  • trunk/packages/vizservers/nanovis/ZincBlendeVolume.cpp

    r2798 r2827  
    1919#include "ZincBlendeVolume.h"
    2020
    21 
    2221ZincBlendeVolume::ZincBlendeVolume(float x, float y, float z,
    23                                         int w, int h, int d, float s, int n,
    24                                         float* dataVolumeA, float* dataVolumeB,
    25                                         double v0, double v1, double non_zeromin, const Vector3& cellSize)
    26                 : Volume(x, y, z, w, h, d, s, n, dataVolumeA, v0, v1, non_zeromin), cell_size(cellSize)
     22                                   int w, int h, int d, float s, int n,
     23                                   float* dataVolumeA, float* dataVolumeB,
     24                                   double v0, double v1, double non_zeromin,
     25                                   const Vector3& cellSize) :
     26    Volume(x, y, z, w, h, d, s, n, dataVolumeA, v0, v1, non_zeromin),
     27    cell_size(cellSize)
    2728{
    2829    //label it as zincblende
     
    3435
    3536    //now add another tex as zincblende_tex[1]
    36     Texture3D* secondTex = 0;
    37     secondTex = new Texture3D(w, h, d, GL_FLOAT, GL_LINEAR, n);
     37    Texture3D* secondTex = new Texture3D(w, h, d, GL_FLOAT, GL_LINEAR, n);
    3838    assert(secondTex);
    3939    secondTex->initialize(dataVolumeB);
    40    
     40
    4141    zincblende_tex[1] = secondTex;
    4242}
    43 
    4443
    4544ZincBlendeVolume::~ZincBlendeVolume()
     
    5150        delete zincblende_tex[1];
    5251}
    53 
    54 
  • trunk/packages/vizservers/nanovis/config.h

    r2798 r2827  
    3636#define NEW_FLOW_ENGINE         1
    3737
     38//#define USE_POINTSET_RENDERER
     39
    3840/*
    3941 * The following define controls whether new load_volume_stream or
  • trunk/packages/vizservers/nanovis/nanovis.cpp

    r2822 r2827  
    3838#include <unistd.h>
    3939
     40#ifdef USE_POINTSET_RENDERER
    4041#include "PointSetRenderer.h"
    4142#include "PointSet.h"
     43#endif
     44
    4245#include <NvLIC.h>
    4346#include <Trace.h>
     
    108111Tcl_HashTable NanoVis::heightmapTable;
    109112VolumeRenderer* NanoVis::vol_renderer = NULL;
     113#ifdef USE_POINTSET_RENDERER
    110114PointSetRenderer* NanoVis::pointset_renderer = NULL;
    111115std::vector<PointSet*> NanoVis::pointSet;
     116#endif
    112117PlaneRenderer* NanoVis::plane_render = NULL;
    113118Texture2D* NanoVis::plane[10];
     
    696701    CGerror lastError = cgGetError();
    697702
    698     if(lastError) {
     703    if (lastError) {
    699704        TRACE("\n---------------------------------------------------\n");
    700705        TRACE("%s\n\n", cgGetErrorString(lastError));
     
    756761    grid->setFont(fonts);
    757762
    758 #ifdef notdef
     763#ifdef USE_POINTSET_RENDERER
    759764    pointset_renderer = new PointSetRenderer();
    760765#endif
     
    16521657        perf->disable();
    16531658    }
    1654         TRACE("in display: render heightmap\n");
     1659    TRACE("in display: render heightmap\n");
    16551660    perf->reset();
    16561661    CHECK_FRAMEBUFFER_STATUS();
     
    21162121            fcntl(0, F_SETFL, flags | O_NONBLOCK);
    21172122            isComplete = false;
    2118             nCommands++;
    2119             CHECK_FRAMEBUFFER_STATUS();
     2123            nCommands++;
     2124            CHECK_FRAMEBUFFER_STATUS();
    21202125        }
    21212126    }
     
    21862191    char *newPath;
    21872192    struct timeval tv;
     2193
    21882194    newPath = NULL;
    21892195    path = NULL;
  • trunk/packages/vizservers/nanovis/socket/ClientSocket.cpp

    r2798 r2827  
    1616#include "ClientSocket.h"
    1717#include "SocketException.h"
    18 
    1918
    2019ClientSocket::ClientSocket ( std::string host, int port )
  • trunk/packages/vizservers/nanovis/socket/ClientSocket.h

    r2798 r2827  
    1919#include "Socket.h"
    2020
    21 
    2221class ClientSocket : private Socket
    2322{
  • trunk/packages/vizservers/nanovis/socket/RenderClient.cpp

    r2798 r2827  
    1515 */
    1616#include <GL/freeglut.h>
    17 #include "RenderClient.h"
    1817#include <stdlib.h>
    1918#include <sstream>
     
    2322#include <assert.h>
    2423
    25 #include "../Event.h"
     24#include "RenderClient.h"
     25#include "Event.h"
    2626
    2727using namespace std;
     
    2929Event* event[5000];
    3030int cur_event = 0;
    31 
    3231
    3332int width, height;
  • trunk/packages/vizservers/nanovis/socket/RenderClient.h

    r2798 r2827  
    1717#define _RENDER_CLIENT_H_
    1818
    19 #include "ClientSocket.h"
    20 #include "SocketException.h"
    2119#include <iostream>
    2220#include <string>
    2321
     22#include "ClientSocket.h"
     23#include "SocketException.h"
    2424
    2525class RenderClient{
  • trunk/packages/vizservers/nanovis/socket/RenderServer.cpp

    r2798 r2827  
    1515 */
    1616#include "RenderServer.h"
    17 
    1817
    1918RenderServer::RenderServer(){}
  • trunk/packages/vizservers/nanovis/socket/RenderServer.h

    r2798 r2827  
    1717#define _RENDER_SERVER_H_
    1818
     19#include <string>
     20
    1921#include "ServerSocket.h"
    2022#include "SocketException.h"
    21 #include <string>
    22 
    2323
    2424class RenderServer{
  • trunk/packages/vizservers/nanovis/socket/ServerSocket.cpp

    r2798 r2827  
    1616#include "ServerSocket.h"
    1717#include "SocketException.h"
    18 
    1918
    2019ServerSocket::ServerSocket ( int port )
  • trunk/packages/vizservers/nanovis/socket/ServerSocket.h

    r2798 r2827  
    1818
    1919#include "Socket.h"
    20 
    2120
    2221class ServerSocket : private Socket
Note: See TracChangeset for help on using the changeset viewer.