source: trunk/gui/vizservers/nanovis/NvZincBlendeReconstructor.cpp @ 601

Last change on this file since 601 was 601, checked in by vrinside, 17 years ago

Tentatively comment code segment for font creation and screenshot in Nv.cpp for debugging. NvZincBlendeReconstructor? class is added for loading
zincblend data.

File size: 3.4 KB
Line 
1#include "NvZincBlendeReconstructor.h"
2#include "ZincBlendeVolume.h"
3
4NvZincBlendeReconstructor* NvZincBlendeReconstructor::_instance = NULL;
5
6NvZincBlendeReconstructor::NvZincBlendeReconstructor()
7{
8}
9
10NvZincBlendeReconstructor::~NvZincBlendeReconstructor()
11{
12}
13
14NvZincBlendeReconstructor* NvZincBlendeReconstructor::getInstance()
15{
16    if (_instance == NULL)
17    {
18        return (_instance = new NvZincBlendeReconstructor());
19    }
20
21    return _instance;
22}
23
24ZincBlendeVolume* NvZincBlendeReconstructor::load(const char* fileName)
25{
26    Vector3 origin, delta;
27    int width = 0, height = 0, depth = 0;
28    void* data = NULL;
29
30    // TBD
31    // INSOO
32    // I have to handle the header of the file
33   
34    return buildUp(origin, delta, width, height, depth, data);
35}
36
37struct _NvUnitCellInfo {
38    float indexX, indexY, indexZ;
39    float atoms[8];
40
41    int getIndex(int width, int height) const
42    {
43        // NOTE
44        // Zinc blende data has different axises from OpenGL
45        // + z -> +x (OpenGL)
46        // + x -> +y (OpenGL)
47        // + y -> +z (OpenGL), But in 3D texture coordinate is the opposite direction of z
48        // The reasone why index is multiplied by 4 is that one unit cell has half of eight atoms
49        // ,i.e. four atoms are mapped into RGBA component of one texel
50        return (indexZ + indexX * width + indexY * width * height) * 4;
51    }
52};
53
54template<class T>
55inline int _NvMax2(T a, T b) { return ((a >= b)? a : b); }
56
57template<class T>
58inline int _NvMin2(T a, T b) { return ((a >= b)? a : b); }
59
60template<class T>
61inline int _NvMax3(T a, T b, T c) { return ((a >= b)? ((a >= c) ? a : c) : ((b >= c)? b : c)); }
62
63template<class T>
64inline int _NvMin3(T a, T b, T c) { return ((a <= b)? ((a <= c) ? a : c) : ((b <= c)? b : c)); }
65
66template<class T>
67inline int _NvMax9(T* a, T curMax) { return _NvMax3(_NvMax3(a[0], a[1], a[2]), _NvMax3(a[3], a[4], a[5]), _NvMax3(a[6], a[7], curMax)); }
68
69template<class T>
70inline int _NvMin9(T* a, T curMax) { return _NvMin3(_NvMax3(a[0], a[1], a[2]), _NvMin3(a[3], a[4], a[5]), _NvMin3(a[6], a[7], curMax)); }
71
72ZincBlendeVolume* NvZincBlendeReconstructor::buildUp(const Vector3& origin, const Vector3& delta, int width, int height, int depth, void* data)
73{
74    ZincBlendeVolume* zincBlendeVolume = NULL;
75
76    float *dataVolumeA, *dataVolumeB;
77    int cellCount = width * height * depth;
78    dataVolumeA = new float[cellCount * sizeof(float) * 4];
79    dataVolumeB = new float[cellCount * sizeof(float) * 4];
80
81    _NvUnitCellInfo* srcPtr = (_NvUnitCellInfo*) data;
82
83    float vmin, vmax;
84    float* component4A, *component4B;
85    int index;
86
87    vmin = vmax = srcPtr->atoms[0];
88    for (int i = 0; i < cellCount; ++i)
89    {
90        index = srcPtr->getIndex(width, height);
91        component4A = dataVolumeA + index;
92        component4B = dataVolumeB + index;
93
94
95        component4A[0] = srcPtr->atoms[0];
96        component4A[1] = srcPtr->atoms[1];
97        component4A[2] = srcPtr->atoms[2];
98        component4A[3] = srcPtr->atoms[3];
99
100        component4B[0] = srcPtr->atoms[4];
101        component4B[1] = srcPtr->atoms[5];
102        component4B[2] = srcPtr->atoms[6];
103        component4B[3] = srcPtr->atoms[7];
104
105        vmin = _NvMax9((float*) srcPtr->atoms, vmin);
106        vmax = _NvMax9((float*)  srcPtr->atoms, vmax);
107
108        ++srcPtr;
109    }
110
111/*
112    zincBlendeVolume = new ZincBlendeVolume(origin.x, origin.y, origin.z,
113                width, height, depth, size, 4,
114                dataVolumeA, dataVolumeB,
115        vmin, vmax, cellSize);
116*/
117
118    return zincBlendeVolume;
119}
120
Note: See TracBrowser for help on using the repository browser.