/*
* 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 .
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see
* or contact Peter Baumann via .
/
/**
* SOURCE: test_fastscale.cc
*
* MODULE: rasodmg
*
* COMMENTS:
* None
*/
#include
#ifdef EARLY_TEMPLATE
#define __EXECUTABLE__
#include "raslib/template_inst.hh"
#endif
#include "rasodmg/fastscale.hh"
#include "rasodmg/transaction.hh"
#include "rasodmg/database.hh"
#include "rasodmg/marray.hh"
#include "raslib/odmgtypes.hh"
template class r_Fast_Scale;
template
void fast_scale_resample_array(T *dest, const T *src, const r_Minterval &destIv, const r_Minterval &srcIv, const r_Minterval &srcIter, unsigned int type_len, unsigned int length);
static void test_resample(unsigned int extent, unsigned int shrink)
{
r_Minterval siv(2);
r_Minterval div(2);
unsigned int shrunken;
r_Char *srcData;
r_Char *destData;
cout << "Test resampling, size " << extent
<< ", shrink factor " << shrink << endl;
shrunken = (extent / shrink);
if (shrunken * shrink < extent) shrunken++;
siv << r_Sinterval((r_Range)0, (r_Range)extent-1)
<< r_Sinterval((r_Range)0, (r_Range)extent-1);
div << r_Sinterval((r_Range)0, (r_Range)shrunken-1)
<< r_Sinterval((r_Range)0, (r_Range)shrunken-1);
srcData = new r_Char[extent*extent];
destData = new r_Char[shrunken*shrunken];
unsigned int i, j;
for (i=0; i* myScale;
cout << "Server = " << servername << ", Database = " << database << ", collection = " << collname << ", Image size = " << imgSize << endl;
try
{
db.set_servername(servername);
db.open(database);
}
catch(r_Error &err)
{
cerr << err.what() << endl;
exit(-1);
}
if ((dostuff & 1) != 0)
{
try
{
ta.begin();
myScale = new r_Fast_Scale(collname, imgDom, "GreySet", "GreyImage", myStorageLayout);
ta.commit();
delete myScale;
cout << "created OK" << endl;
}
catch(r_Error &err)
{
ta.abort();
cerr << err.what() << endl;
}
}
delete myStorageLayout;
// read a small object for identification
try
{
ta.begin(r_Transaction::read_only);
r_Ref mddObj = r_Fast_Base_Scale::get_minimal_array(collname);
ta.commit();
cout << "Object read: ";
mddObj->print_status();
mddObj.destroy();
}
catch(r_Error &err)
{
ta.abort();
cerr << err.what() << endl;
}
try
{
ta.begin(r_Transaction::read_only);
myScale = new r_Fast_Scale(collname);
cout << "Read domain: " << myScale->get_full_domain() << endl;
ta.commit();
cout << "domain OK" << endl;
}
catch(r_Error &err)
{
ta.abort();
cerr << err.what() << endl;
}
if ((dostuff & 2) != 0)
{
// update a diagonal strip
for (i=0; i<=imgSize-updtSize; i+=updtSize/2)
{
try
{
r_Minterval uiv(2);
uiv << r_Sinterval((r_Range)i, (r_Range)i+updtSize-1)
<< r_Sinterval((r_Range)i, (r_Range)i+updtSize-1);
cout << "Update " << uiv << endl;
r_Marray *updtArray = new ("GreyImage") r_Marray(uiv);
memset(updtArray->get_array(), 255, updtSize * updtSize);
cout << "Start insert... " << flush;
ta.begin();
myScale->insert_array(*updtArray);
ta.commit();
delete updtArray;
cout << "OK" << endl;
}
catch (r_Error &err)
{
ta.abort();
cerr << err.what();
}
}
}
double scaleFactor;
for (scaleFactor=1.0; scaleFactor>1e-6; scaleFactor-=0.05)
{
try
{
r_Minterval scaledIv;
if (myScale->get_scaled_domain(myScale->get_full_domain(), scaledIv, scaleFactor) != 0)
{
cout << "Read " << scaledIv << ", scaled " << scaleFactor << "..." << flush;
ta.begin(r_Transaction::read_only);
r_Ref > result;
result = myScale->get_scaled_image(scaledIv, scaleFactor);
ta.commit();
cout << "OK" << endl;
result.destroy();
}
}
catch(r_Error &err)
{
ta.abort();
cerr << err.what() << endl;
}
}
delete myScale;
db.close();
return 0;
}