|
From: <le...@us...> - 2007-01-11 09:00:24
|
Revision: 146
http://svn.sourceforge.net/qcell/?rev=146&view=rev
Author: lessm
Date: 2007-01-11 01:00:21 -0800 (Thu, 11 Jan 2007)
Log Message:
-----------
- Calculator class updated
Modified Paths:
--------------
trunk/qcell/baseheaders/Calculator.h
trunk/qcell/basesources/Calculator.cpp
trunk/qcell/basesources/LocalFunction.cpp
trunk/qcell/basesources/Neighbourhood.cpp
Modified: trunk/qcell/baseheaders/Calculator.h
===================================================================
--- trunk/qcell/baseheaders/Calculator.h 2007-01-10 21:13:26 UTC (rev 145)
+++ trunk/qcell/baseheaders/Calculator.h 2007-01-11 09:00:21 UTC (rev 146)
@@ -22,7 +22,6 @@
private:
protected:
-public:
char *tempData;
bool haveForeignOutputDataPointer;
QVector<int> tempDataSize, calculationSpaceStart, calculationSpaceEnd;
@@ -52,6 +51,8 @@
void calculate(void);
+ Calculator & operator = (CalculationData &cData);
+
protected slots:
void setupSpace(void);
};
Modified: trunk/qcell/basesources/Calculator.cpp
===================================================================
--- trunk/qcell/basesources/Calculator.cpp 2007-01-10 21:13:26 UTC (rev 145)
+++ trunk/qcell/basesources/Calculator.cpp 2007-01-11 09:00:21 UTC (rev 146)
@@ -88,7 +88,8 @@
if(dataPointer==NULL)
{
haveForeignOutputDataPointer = 0;
- tempData = new char[ tmp= getTempDataSizeInByte()];
+ tmp = getTempDataSizeInByte();
+ tempData = new char[getTempDataSizeInByte()];
if(!tempData)
return 0;
@@ -134,9 +135,8 @@
void Calculator::setNeighbourhood(Neighbourhood *n)
{
neighbourhood = n;
- //setupSpace();
- //resizeTempDataBuffer();
- //neighbourhood->calculateOffsets(tempDataSize[0], tempDataSize[1], tempDataSize[2], tempDataSize[3], getDataType());
+ if(data!=NULL)
+ setupSpace();
}
void Calculator::setLocalFunction(LocalFunction *f)
@@ -222,8 +222,8 @@
void Calculator::calculate(void)
{
int counter = 0;
- char temp[8];
- int sx = tempDataSize[0] - maxBorder[0] , sy = tempDataSize[1] - maxBorder[1], sz = tempDataSize[2] - maxBorder[2], st = tempDataSize[3] - maxBorder[3];
+ char temp[8] = {0,0,0,0,0,0,0,0};
+ int sx = sizeX, sy = sizeY, sz = sizeZ, st = sizeT;
if(sy==0)
sy=1;
@@ -236,15 +236,15 @@
copyData();
- for(int t=-minBorder[3];t<st;++t)
+ for(int t=0;t<st;++t)
{
- for(int z=-minBorder[2];z<sz;++z)
+ for(int z=0;z<sz;++z)
{
- for(int y=-minBorder[1];y<sy;++y)
+ for(int y=0;y<sy;++y)
{
- for(int x=-minBorder[0];x<sx;++x)
+ for(int x=0;x<sx;++x)
{
- neighbourhood->resolveValues(tempData + x + (y * tempDataSize[0]) + z * (tempDataSize[0] * tempDataSize[1]) + t * (tempDataSize[0] * tempDataSize[1] * tempDataSize[2]) * dataSize);
+ neighbourhood->resolveValues(tempData + (x - minBorder[0]) + ((y - minBorder[1]) * tempDataSize[0]) + (z - minBorder[2]) * (tempDataSize[0] * tempDataSize[1]) + (t - minBorder[3]) * (tempDataSize[0] * tempDataSize[1] * tempDataSize[2]) * dataSize);
switch(dataType)
{
case baseDataTypes::BOOL:
@@ -260,6 +260,7 @@
*((double *)temp) = localfunction->resolve(neighbourhood->valuesToVector_d());
break;
}
+
memcpy(data + counter, temp, dataSize);
counter += dataSize;
}
@@ -269,12 +270,48 @@
}
+Calculator & Calculator::operator = (CalculationData &cData)
+{
+ if(cData.getDimension()!=getDimension() || cData.getSizeX() != getSizeX() || cData.getSizeY() != getSizeY() || cData.getSizeZ() != getSizeZ() || cData.getSizeT() != getSizeT())
+ {
+ clearData();
+ setDataType(cData.getDataType());
+
+ switch(cData.getDimension())
+ {
+ case 1:
+ resizeData(cData.getSizeX());
+ break;
+ case 2:
+ resizeData(cData.getSizeX(), cData.getSizeY());
+ break;
+ case 3:
+ resizeData(cData.getSizeX(), cData.getSizeY(), cData.getSizeZ());
+ break;
+ case 4:
+ resizeData(cData.getSizeX(), cData.getSizeY(), cData.getSizeZ(), cData.getSizeT());
+ break;
+ }
+ fillData(cData.getDataPointer());
+ }
+ return *this;
+}
+
void Calculator::setupSpace(void)
{
if(neighbourhood)
{
minBorder = neighbourhood->getMinNeighbourhoodValues();
maxBorder = neighbourhood->getMaxNeighbourhoodValues();
+ for(int i=0;i<4;++i)
+ {
+ if(minBorder[i]>0)
+ minBorder[i] = 0;
+
+ if(maxBorder[i]<0)
+ maxBorder[i] = 0;
+ }
+
tempDataSize[0] = -minBorder[0] + maxBorder[0] + sizeX;
tempDataSize[1] = -minBorder[1] + maxBorder[1] + sizeY;
tempDataSize[2] = -minBorder[2] + maxBorder[2] + sizeZ;
Modified: trunk/qcell/basesources/LocalFunction.cpp
===================================================================
--- trunk/qcell/basesources/LocalFunction.cpp 2007-01-10 21:13:26 UTC (rev 145)
+++ trunk/qcell/basesources/LocalFunction.cpp 2007-01-11 09:00:21 UTC (rev 146)
@@ -63,24 +63,34 @@
QVector<int> LocalFunction::calculateSums(QVector<int> &args)
{
- int i, j;
+ int i, j, tmp;
QVector<int> out;
out.resize(sumArguments.size());
for(i=0;i<sumArguments.size();++i)
{
out[i] = 0;
foreach(j, sumArguments[i])
- out[i] += args[j];
+ {
+ tmp = args[j];
+ if(tmp>=getAlphabetSize())
+ tmp = getAlphabetSize()-1;
+ out[i] += tmp;
+ }
}
return out;
}
QVector<int> LocalFunction::calculateSwitchArguments(QVector<int> &args)
{
- int index;
+ int index,tmp;
QVector<int> out;
foreach(index, freeArguments)
- out<<args[index];
+ {
+ tmp = args[index];
+ if(tmp>=getAlphabetSize())
+ tmp = getAlphabetSize()-1;
+ out<<tmp;
+ }
return out;
}
Modified: trunk/qcell/basesources/Neighbourhood.cpp
===================================================================
--- trunk/qcell/basesources/Neighbourhood.cpp 2007-01-10 21:13:26 UTC (rev 145)
+++ trunk/qcell/basesources/Neighbourhood.cpp 2007-01-11 09:00:21 UTC (rev 146)
@@ -27,6 +27,14 @@
if(maxValues[0]<x)
maxValues[0]=x;
+
+ minValues[1] = 0;
+ maxValues[1] = 0;
+ minValues[2] = 0;
+ maxValues[2] = 0;
+ minValues[3] = 0;
+ maxValues[3] = 0;
+
}
void Neighbourhood::addNeighbour(int x, int y)
@@ -52,6 +60,11 @@
if(maxValues[1]<y)
maxValues[1]=y;
+ minValues[2] = 0;
+ maxValues[2] = 0;
+ minValues[3] = 0;
+ maxValues[3] = 0;
+
}
void Neighbourhood::addNeighbour(int x, int y, int z)
{
@@ -81,6 +94,9 @@
if(maxValues[2]<z)
maxValues[2]=z;
+
+ minValues[3] = 0;
+ maxValues[3] = 0;
}
void Neighbourhood::addNeighbour(int x, int y, int z, int t)
@@ -236,7 +252,8 @@
{
QDomNode node;
QDomElement element;
- NContainer container;
+// NContainer container;
+ clearNeighbourhood();
if(xmlElement->tagName()=="Neighbourhood")
{
node = xmlElement->firstChild();
@@ -250,10 +267,7 @@
{
if(element.hasAttribute("t"))
{
- container.x = element.attribute("x").toInt();
- container.y = element.attribute("y").toInt();
- container.z = element.attribute("z").toInt();
- container.t = element.attribute("t").toInt();
+ addNeighbour(element.attribute("x").toInt(), element.attribute("y").toInt(), element.attribute("z").toInt(), element.attribute("t").toInt());
if(dimension>4)
dimension = 4;
}
@@ -261,9 +275,7 @@
{
if(element.hasAttribute("z"))
{
- container.x = element.attribute("x").toInt();
- container.y = element.attribute("y").toInt();
- container.z = element.attribute("z").toInt();
+ addNeighbour(element.attribute("x").toInt(), element.attribute("y").toInt(), element.attribute("z").toInt());
if(dimension>3)
dimension = 3;
}
@@ -271,8 +283,7 @@
{
if(element.hasAttribute("y"))
{
- container.x = element.attribute("x").toInt();
- container.y = element.attribute("y").toInt();
+ addNeighbour(element.attribute("x").toInt(), element.attribute("y").toInt());
if(dimension>2)
dimension = 2;
@@ -281,13 +292,13 @@
{
if(element.hasAttribute("x"))
{
- container.x = element.attribute("x").toInt();
+ addNeighbour(element.attribute("x").toInt());
dimension = 1;
}
}
}
}
- neighbourVector<<container;
+ //neighbourVector<<container;
}
node = node.nextSibling();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|