summaryrefslogtreecommitdiffstats
path: root/tilemgr/test/tilertest.cc
blob: 3502ccceb8d7419262f77c5da3deeafbffa3a699 (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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* 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>.
*/

#include "mymalloc/mymalloc.h"
#ifdef EARLY_TEMPLATE
#define __EXECUTABLE__
#ifdef __GNUG__
#include "server/template_inst.hh"
#endif
#endif

#include "raslib/rmdebug.hh"
#include "raslib/minterval.hh"
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <vector.h>
#include <pair.h>
#include "tilemgr/transtile.hh"
#include "octettype.hh"
#include "tilemgr/tiler.hh"

RMINITGLOBALS('C')


int
main(int argc, char *argv[])
	{
	vector<r_Minterval> sourceDomains;
	vector<r_Minterval> targetDomains;
	vector<r_Minterval> retvalDomains;
	vector<r_Minterval>::iterator sourceDIt;
	vector<r_Minterval>::iterator targetDIt;
	vector<r_Minterval>::iterator retvalDIt;

	
	vector<Tile*>::iterator sourceIt;
	vector<Tile*>::iterator targetIt;
	vector<Tile*>::iterator retvalIt;
	
	r_Minterval targetDom("[0:50,0:50]");
	r_Minterval targetInt1("[0:10,0:10]");
	r_Minterval targetInt2("[15:25,10:20]");
	r_Minterval targetInt3("[15:25,21:30]");
	r_Minterval targetInt4("[15:25,31:40]");
	r_Minterval targetInt5("[40:50,40:50]");
	r_Minterval targetInt6("[35:41,25:35]");
	r_Minterval targetInt7("[28:32,28:32]");
	r_Minterval targetInt8("[40:40,0:10]");
	r_Minterval targetInt9("[40:50,11:11]");
	r_Minterval targetInt10("[35:35,0:10]");
	r_Minterval targetInt11("[30:34,10:10]");
	OctetType* o = new OctetType();
	
	char* cont1 = 0;
	char* cont2 = 0;
	char* cont3 = 0;
	char* cont4 = 0;
	char* cont5 = 0;
	char* cont6 = 0;
	char* cont7 = 0;
	char* cont8 = 0;
	char* cont9 = 0;
	char* cont10 = 0;
	char* cont11 = 0;
	char* outc = 0;
	cont1 = (char*)mymalloc(500);
	cont2 = (char*)mymalloc(500);
	cont3 = (char*)mymalloc(500);
	cont4 = (char*)mymalloc(500);
	cont5 = (char*)mymalloc(500);
	cont6 = (char*)mymalloc(500);
	cont7 = (char*)mymalloc(500);
	cont8 = (char*)mymalloc(500);
	cont9 = (char*)mymalloc(500);
	cont10 = (char*)mymalloc(500);
	cont11 = (char*)mymalloc(500);
	outc = (char*)mymalloc(101*101);
	memset(cont1, 1, 500);
	memset(cont2, 2, 500);
	memset(cont3, 3, 500);
	memset(cont4, 4, 500);
	memset(cont5, 5, 500);
	memset(cont6, 6, 500);
	memset(cont7, 7, 500);
	memset(cont8, 8, 500);
	memset(cont9, 9, 500);
	memset(cont10, 10, 500);
	memset(cont11, 11, 500);
	memset(outc, 0, 3500);
	TransTile output(targetDom, o, outc);

	TransTile* ttile1 = new TransTile(targetInt1, (const BaseType*)o, cont1);
	TransTile* ttile2 = new TransTile(targetInt2, (const BaseType*)o, cont2);
	TransTile* ttile3 = new TransTile(targetInt3, (const BaseType*)o, cont3);
	TransTile* ttile4 = new TransTile(targetInt4, (const BaseType*)o, cont4);
	TransTile* ttile5 = new TransTile(targetInt5, (const BaseType*)o, cont5);
	TransTile* ttile6 = new TransTile(targetInt6, (const BaseType*)o, cont6);
	TransTile* ttile7 = new TransTile(targetInt7, (const BaseType*)o, cont7);
	TransTile* ttile8 = new TransTile(targetInt8, (const BaseType*)o, cont8);
	TransTile* ttile9 = new TransTile(targetInt9, (const BaseType*)o, cont9);
	TransTile* ttile10 = new TransTile(targetInt10, (const BaseType*)o, cont10);
	TransTile* ttile11 = new TransTile(targetInt11, (const BaseType*)o, cont11);

	r_Minterval sourceDom("[5:45,5:45]");
	r_Minterval sourceInt1("[5:10,5:10]");
	r_Minterval sourceInt2("[15:25,12:45]");
	r_Minterval sourceInt3("[30:45,30:38]");
	r_Minterval sourceInt4("[40:45,40:45]");
	r_Minterval sourceInt5("[30:45,25:28]");
	r_Minterval sourceInt6("[39:41,9:11]");
	r_Minterval sourceInt7("[34:36,9:11]");

	char* scont1 = 0;
	char* scont2 = 0;
	char* scont3 = 0;
	char* scont4 = 0;
	char* scont5 = 0;
	char* scont6 = 0;
	char* scont7 = 0;
	scont1 = (char*)mymalloc(500);
	scont2 = (char*)mymalloc(500);
	scont3 = (char*)mymalloc(500);
	scont4 = (char*)mymalloc(500);
	scont5 = (char*)mymalloc(500);
	scont6 = (char*)mymalloc(500);
	scont7 = (char*)mymalloc(500);
	memset(scont1, 21, 500);
	memset(scont2, 22, 500);
	memset(scont3, 23, 500);
	memset(scont4, 24, 500);
	memset(scont5, 25, 500);
	memset(scont6, 26, 500);
	memset(scont7, 27, 500);
	TransTile* stile1 = new TransTile(sourceInt1, (const BaseType*)o, scont1);
	TransTile* stile2 = new TransTile(sourceInt2, (const BaseType*)o, scont2);
	TransTile* stile3 = new TransTile(sourceInt3, (const BaseType*)o, scont3);
	TransTile* stile4 = new TransTile(sourceInt4, (const BaseType*)o, scont4);
	TransTile* stile5 = new TransTile(sourceInt5, (const BaseType*)o, scont5);
	TransTile* stile6 = new TransTile(sourceInt6, (const BaseType*)o, scont6);
	TransTile* stile7 = new TransTile(sourceInt7, (const BaseType*)o, scont7);
	
	vector<Tile*> sourceTiles;
	sourceTiles.push_back(stile1);
	sourceTiles.push_back(stile2);
	sourceTiles.push_back(stile3);
	sourceTiles.push_back(stile4);
	sourceTiles.push_back(stile5);
	sourceTiles.push_back(stile6);
	sourceTiles.push_back(stile7);
	
	vector<Tile*> targetTiles;
	targetTiles.push_back(ttile1);
	targetTiles.push_back(ttile2);
	targetTiles.push_back(ttile3);
	targetTiles.push_back(ttile4);
	targetTiles.push_back(ttile5);
	targetTiles.push_back(ttile6);
	targetTiles.push_back(ttile7);
	targetTiles.push_back(ttile8);
	targetTiles.push_back(ttile9);
	targetTiles.push_back(ttile10);
	targetTiles.push_back(ttile11);

	vector<Tile*> retval;

	unsigned long targetTileArea = 0;
	unsigned long sourceTileArea = 0;
	unsigned long targetTileDomain = 0;
	unsigned long updatedArea = 0;
	bool intersection = false;

	r_Minterval intersectUpdateDomain;

	bool computed = true;

	cout << "Target Tiles" << endl;
	for (targetIt = targetTiles.begin(); targetIt != targetTiles.end(); targetIt++)
		cout << (*targetIt)->getDomain() << endl;
	cout << endl << "Source Tiles" << endl;
	for (sourceIt = sourceTiles.begin(); sourceIt != sourceTiles.end(); sourceIt++)
		cout << (*sourceIt)->getDomain() << endl;
	cout << endl;
	cout << "Checking if only update, insert or update and insert" << endl;
	
	for (sourceIt = sourceTiles.begin(); sourceIt != sourceTiles.end(); sourceIt++)
		{
		intersection = false;
		sourceTileArea = sourceTileArea + (*sourceIt)->getDomain().cell_count();
		cout << "SourceDomain " << (*sourceIt)->getDomain() << " source area is " << sourceTileArea << endl;
		for (targetIt = targetTiles.begin(); targetIt != targetTiles.end(); targetIt++)
			{
			if (computed)
				{
				targetTileArea = targetTileArea + (*targetIt)->getDomain().cell_count();
				cout << "Target Tile " << (*targetIt)->getDomain() << " area " << targetTileArea << endl;
				}

			if( (*sourceIt)->getDomain().intersects_with( (*targetIt)->getDomain() ) )
				{
				cout << "Intersection" << endl;
				intersection = true;
				intersectUpdateDomain = (*sourceIt)->getDomain().create_intersection( (*targetIt)->getDomain() );
				cout << "Updated " << intersectUpdateDomain << " on source " << (*sourceIt)->getDomain() << " and target " << (*targetIt)->getDomain() << endl;
				updatedArea = updatedArea + intersectUpdateDomain.cell_count();
				(*targetIt)->execUnaryOp(Ops::OP_IDENTITY, intersectUpdateDomain, *sourceIt, intersectUpdateDomain );
				}
			}
		if (!intersection)
			{
			// Create a new persistent tile, copy the transient data,
			// and insert it into the target mdd object.
			cout << "No Intersection" << endl;
			TransTile* newPersTile = new TransTile((*sourceIt)->getDomain(), o, (*sourceIt)->getDataFormat());
			newPersTile->execUnaryOp(Ops::OP_IDENTITY, (*sourceIt)->getDomain(), *sourceIt, (*sourceIt)->getDomain());
			//targetObj->insertTile( newPersTile );
			updatedArea = updatedArea + (*sourceIt)->getDomain().cell_count();
			}
		computed = false;
		}
	cout << "Source Domain    " << sourceDom << " has area " << sourceDom.cell_count() << endl;
	cout << "Source Tile Area " << sourceTileArea << endl;
	cout << "Target Tile Area " << targetTileArea << endl;
	cout << "Updated Area     " << updatedArea << endl << endl;
	// insert the tile
	
	if (sourceTileArea <= updatedArea)
		{
		cout << "and all sources were used" << endl;
		}
	else	{
		cout << "and there are still some cells to do" << endl << endl;

		for (retvalIt = sourceTiles.begin(); retvalIt != sourceTiles.end(); retvalIt++)
			{
			sourceDomains.push_back((*retvalIt)->getDomain());
			}

		for (retvalIt = targetTiles.begin(); retvalIt != targetTiles.end(); retvalIt++)
			{
			targetDomains.push_back((*retvalIt)->getDomain());
			}

		r_Tiler tiler(sourceDomains, targetDomains);
		tiler.split();
		tiler.removeCoveredDomains();
		tiler.removeDoubleDomains();
		retvalDomains = tiler.getTiledDomains();
		cout << "we have now" << endl;
		for (retvalDIt = retvalDomains.begin(); retvalDIt != retvalDomains.end(); retvalDIt++)
			cout << (*retvalDIt) << endl;
		tiler.mergeDomains();
		retvalDomains = tiler.getTiledDomains();
		cout << "we have now" << endl;
		for (retvalDIt = retvalDomains.begin(); retvalDIt != retvalDomains.end(); retvalDIt++)
			cout << (*retvalDIt) << endl;
		vector<Tile*> t = tiler.generateTransTiles(sourceTiles);
		for (retvalIt = targetTiles.begin(); retvalIt != targetTiles.end(); retvalIt++)
			output.execUnaryOp(Ops::OP_IDENTITY, (*retvalIt)->getDomain(), (*retvalIt), (*retvalIt)->getDomain());
		for (retvalIt = t.begin(); retvalIt != t.end(); retvalIt++)
			output.execUnaryOp(Ops::OP_IDENTITY, (*retvalIt)->getDomain(), (*retvalIt), (*retvalIt)->getDomain());
		RManDebug = 30;
		output.printStatus(cout);
		RManDebug = 1;
		}
	}