summaryrefslogtreecommitdiffstats
path: root/rasodmg/test/test_gmarray.cc
blob: dbd95a4dc46e4e77da1afb31b4450906ab5194a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
/
/**
 * SOURCE: test_marray.cc
 *
 * MODULE: raslib
 *
 * COMMENTS:
 *		None
*/

#include <iostream>

#include "rasodmg/marray.hh"

#include "raslib/minterval.hh"
#include "raslib/sinterval.hh"
#include "raslib/point.hh"
#include "raslib/error.hh"
#include "raslib/type.hh"
#include "raslib/basetype.hh"
#include "raslib/attribute.hh"
#include "raslib/structuretype.hh"
#include "raslib/primitivetype.hh"


struct myStructType {
   char   red;
   char   green;
   short  east; 
   float  middle;
};

struct myStructType3 {
   double  feature_1 ;
   double  feature_2 ;
   double  feature_3 ; 
};

struct myStructTypeCom {
   long                 greyvalue;
   long                 greyvalue2;
   myStructType3  features;
};

static int INIT = 0;
static float FINIT = 0;
static char CINIT = 0;
static double DINIT = 0;
static long LINIT = 0;

int initFunction( const r_Point& /*pt*/ )
{
   /*
  int value=0;
  
  for( int i=0; i< pt.dimension(); i++ )
    value += pt[i];
  
  return value;
  */
   return 3*(INIT++)/2;
}

float  initFunctionFloat( const r_Point& /*pt*/ )
{
   return 3*(FINIT++)/2;
}


char  initFunctionChar( const r_Point& /*pt*/ )
{
   return 3*(CINIT++)/2;
}

double  initFunctionDouble( const r_Point& /*pt*/ )
{
   return 3*(DINIT++)/2;
}

long  initFunctionLong( const r_Point& /*pt*/ )
{
   return (LINIT++);
}


myStructType  initFunctionStruct( const r_Point& /*pt*/ )
{
    myStructType myStruct;

    myStruct.red   = 3;
    myStruct.green = 4;
    myStruct.east  = 123;
    myStruct.middle = 7.4;    

    return myStruct;
}


myStructType3  initFunctionStruct3( const r_Point& pt)
{
    myStructType3 myStruct;

    myStruct.feature_1 = 0.5* initFunctionDouble( pt );  
    DINIT--;
    myStruct.feature_2 = 3* initFunctionDouble( pt );  
    DINIT--;  
    myStruct.feature_3 = initFunctionDouble( pt );    

    return myStruct;
}


myStructTypeCom  initFunctionStructCom( const r_Point& pt)
{
    myStructTypeCom  myStructCom;

    myStructCom.greyvalue =  initFunctionLong( pt );  
    LINIT--;
    myStructCom.greyvalue2 =  3*initFunctionLong( pt );  
    
    //myStructCom.features =  initFunctionStruct3( pt );  

    myStructCom.features.feature_1 = 0.5* initFunctionDouble( pt );  
    DINIT--;
    myStructCom.features.feature_2 = 3* initFunctionDouble( pt );  
    DINIT--;  
    myStructCom.features.feature_3 = initFunctionDouble( pt );    
   

    return myStructCom;
}



int main()
{   
  cout << endl << endl;
  cout << "Marray Examples" << endl;
  cout << "===============" << endl << endl;
        
  cout << "Initialization of Marray<int, [3:5,6:8]> with init function:" << endl;
  r_Marray<int> a( r_Minterval("[3:5,6:8]"), &initFunction );
  a.set_type_structure("marray<long>");
  cout << "OK" << endl;
  a.print_status( cout );


  cout << "Initialization of Marray<float, [3:5,6:8]> with init function float:" << endl;
  r_Marray<float> b( r_Minterval("[3:5,6:8]"), &initFunctionFloat );
  b.set_type_structure("marray<float>");
  cout << "OK" << endl;
  b.print_status( cout );


  cout << "Initialization of Marray<char, [3:5,6:8]> with init function char:" << endl;
  r_Marray<char> c( r_Minterval("[3:5,6:8]"), &initFunctionChar );
  c.set_type_structure("marray<char>");
  cout << "OK" << endl;
  c.print_status( cout );


  cout << "Initialization of Marray<double, [3:5,6:8]> with init function double:" << endl;
  r_Marray<double> d( r_Minterval("[3:5,6:8]"), &initFunctionDouble );
  d.set_type_structure("marray<double>");
  cout << "OK" << endl;
  d.print_status( cout );

  FINIT = 0;
  CINIT = 0;
  cout << "Initialization of Marray<struct{char, char, short, float}, [3:5,6:8]> with init function struct:" << endl;
  r_Marray<myStructType> st( r_Minterval("[3:5,6:8]"), &initFunctionStruct );
  st.set_type_structure("marray<struct{char,char,short,float}>");
  cout << "OK" << endl;
  st.print_status( cout );

  DINIT = 0;
  cout << "Initialization of Marray<struct{double, double, double}, [3:5,6:8]> with init function struct3:" << endl;
  r_Marray<myStructType3> st3( r_Minterval("[3:5,6:8]"), &initFunctionStruct3 );
  st3.set_type_structure("marray<struct{double,double,double}>");
  cout << "OK" << endl;
  st3.print_status( cout );

  DINIT = 0;
  cout << "Initialization of Marray<struct{ long, long, struct{double, double, double} }, [3:5,6:8]> with init function structCom:" << endl;
  r_Marray<myStructTypeCom> stCom( r_Minterval("[3:5,6:8]"), &initFunctionStructCom );
  stCom.set_type_structure("marray<struct{long,long,struct{double,double,double}}>");
  cout << "OK" << endl;
  stCom.print_status( cout );
  cout << endl;

  // print single cell
  r_GMarray& gstCom = (r_GMarray&)stCom;

  const r_Base_Type& baseType = *(gstCom.get_base_type_schema());
  cout << "gmarray_stCom[4,6] = " << flush;
  baseType.print_value( gstCom[r_Point(4,6)] );
  cout << endl;  

  cout << "access second double of inner struct: " << flush;
  const r_Structure_Type& outerStruct     = (const r_Structure_Type&)baseType;
  //  const r_Attribute&      innerAttribute  = outerStruct[2];
  //  const r_Structure_Type& innerStruct     = (const r_Structure_Type&)innerAttribute.type_of();
  //  const r_Attribute&      doubleAttribute = innerStruct[1];
  // cout << doubleAttribute.get_double( gstCom[r_Point(4,6)] ) << endl;   
  cout << outerStruct[2][1].get_double( gstCom[r_Point(4,6)] ) << endl; 

  return 0;
}