From: <le...@us...> - 2007-01-10 19:50:22
|
Revision: 140 http://svn.sourceforge.net/qcell/?rev=140&view=rev Author: lessm Date: 2007-01-10 11:50:10 -0800 (Wed, 10 Jan 2007) Log Message: ----------- - Calculator class updated Modified Paths: -------------- trunk/qcell/baseheaders/CalculationData.h trunk/qcell/baseheaders/Calculator.h trunk/qcell/baseheaders/Neighbourhood.h trunk/qcell/basesources/CalculationData.cpp trunk/qcell/basesources/Calculator.cpp trunk/qcell/basesources/GenericParserPlugin.cpp trunk/qcell/basesources/Neighbourhood.cpp trunk/qcell/basesources/simulationwindow.cpp trunk/qcell/parsers/FQT/FQTParserPlugin.cpp trunk/qcell/visgui/MainWindow.cpp Modified: trunk/qcell/baseheaders/CalculationData.h =================================================================== --- trunk/qcell/baseheaders/CalculationData.h 2007-01-10 16:48:27 UTC (rev 139) +++ trunk/qcell/baseheaders/CalculationData.h 2007-01-10 19:50:10 UTC (rev 140) @@ -65,13 +65,13 @@ bool resizeData(QVector<int> newSize, char *dataPointer=NULL, bool foreignDataPointer=0); int getSizeX(void); - int getSizeY(void); + int getSizeY(void); int getSizeZ(void); int getSizeT(void); int getSizeInByte(void); int getDimension(void); - const char *getDataPointer(void); + /*const*/ char *getDataPointer(void); void fillData(const char *dataPointer); void setForeignDataPointer(char *dataPointer); Modified: trunk/qcell/baseheaders/Calculator.h =================================================================== --- trunk/qcell/baseheaders/Calculator.h 2007-01-10 16:48:27 UTC (rev 139) +++ trunk/qcell/baseheaders/Calculator.h 2007-01-10 19:50:10 UTC (rev 140) @@ -11,31 +11,49 @@ class Calculator : public CalculationData { Q_OBJECT + +public: + enum BORDER + { + TORUS = 0, + MIRROR = 1, + VALUE = 2 + }; + private: protected: - char *outData; +public: + char *tempData; bool haveForeignOutputDataPointer; - QVector<int> outDataSize, calculationSpaceStart, calculationSpaceEnd; + QVector<int> tempDataSize, calculationSpaceStart, calculationSpaceEnd; Neighbourhood *neighbourhood; LocalFunction *localfunction; + QVector<int> minBorder; + QVector<int> maxBorder; + + BORDER borderType; + protected: - void clearOutputData(void); + void clearTempData(void); void copyData(void); - bool resizeOutputDataBuffer(bool dataCopy=0, char *dataPointer=NULL); + bool resizeTempDataBuffer(bool dataCopy=0, char *dataPointer=NULL); + void updateBorder(void); public: + Calculator(); ~Calculator(); void setNeighbourhood(Neighbourhood *n); void setLocalFunction(LocalFunction *f); - bool setCalculationSpace(QVector<int> start, QVector<int> end, bool dataCopy=0, char *foreignDataPointer=NULL); - int getOutputDataSizeInByte(void); - /*const*/ char *getOutputDataPointer(void); + int getTempDataSizeInByte(void); void calculate(void); + +protected slots: + void setupSpace(void); }; #endif Modified: trunk/qcell/baseheaders/Neighbourhood.h =================================================================== --- trunk/qcell/baseheaders/Neighbourhood.h 2007-01-10 16:48:27 UTC (rev 139) +++ trunk/qcell/baseheaders/Neighbourhood.h 2007-01-10 19:50:10 UTC (rev 140) @@ -27,6 +27,9 @@ QVector<NContainer> neighbourVector; DATA_TYPES dType; + QVector<int> minValues; + QVector<int> maxValues; + protected: public: Neighbourhood(); @@ -61,6 +64,9 @@ QVector<int> valuesToVector_i(void); QVector<double> valuesToVector_d(void); + + QVector<int> getMaxNeighbourhoodValues(void); + QVector<int> getMinNeighbourhoodValues(void); }; #endif Modified: trunk/qcell/basesources/CalculationData.cpp =================================================================== --- trunk/qcell/basesources/CalculationData.cpp 2007-01-10 16:48:27 UTC (rev 139) +++ trunk/qcell/basesources/CalculationData.cpp 2007-01-10 19:50:10 UTC (rev 140) @@ -653,7 +653,7 @@ return dimension; } -const char *CalculationData::getDataPointer(void) +/*const*/ char *CalculationData::getDataPointer(void) { return data; } Modified: trunk/qcell/basesources/Calculator.cpp =================================================================== --- trunk/qcell/basesources/Calculator.cpp 2007-01-10 16:48:27 UTC (rev 139) +++ trunk/qcell/basesources/Calculator.cpp 2007-01-10 19:50:10 UTC (rev 140) @@ -1,44 +1,102 @@ #include "../baseheaders/Calculator.h" -void Calculator::clearOutputData(void) +void Calculator::clearTempData(void) { - if(!haveForeignOutputDataPointer && outData) - delete outData; + if(!haveForeignOutputDataPointer && tempData) + delete tempData; - outData = NULL; + tempData = NULL; } void Calculator::copyData(void) { - int counter = 0; - for(int t=calculationSpaceStart[3];t<=calculationSpaceEnd[3];++t) + int offset; + int sy = tempDataSize[1], sz = tempDataSize[2], st = tempDataSize[3]; + int ty, tz, tt; + + if(sy==0) + sy=1; + + if(sz==0) + sz=1; + + if(st==0) + st=1; + + for(int t=0;t<st;++t) { - for(int z=calculationSpaceStart[2];z<=calculationSpaceEnd[2];++z) + for(int z=0;z<sz;++z) { - for(int y=calculationSpaceStart[1];y<=calculationSpaceEnd[1];++y) + for(int y=0;y<sy;++y) { - memcpy(outData + counter, getAddressAt(calculationSpaceStart[0], y, z, t), outDataSize[0]); - counter += outDataSize[0]; + ty = y + minBorder[1]; + tz = z + minBorder[2]; + tt = t + minBorder[3]; + + + + switch(borderType) + { + + case TORUS: + if(sizeY>0) + { + while(ty<0) + ty += sizeY; + ty %= sizeY; + } + + if(sizeZ>0) + { + while(tz<0) + tz += sizeZ; + tz %= sizeZ; + } + + if(sizeT!=0) + { + while(tt<0) + tt += sizeZ; + tt %= sizeT; + } + + offset = (y * tempDataSize[0]) + (z * tempDataSize[0] * tempDataSize[1] * dataSize) + (t * tempDataSize[0] * tempDataSize[1] * tempDataSize[2] * dataSize); + + for(int x=0;x<-minBorder[0];++x) + { + memcpy(tempData + (offset + x) * dataSize, getAddressAt(sizeX - x - 1, ty, tz, tt), dataSize); + } + + for(int x=0;x<maxBorder[0];++x) + { + memcpy(tempData + (offset + sizeX + x - minBorder[0]) * dataSize, getAddressAt((sizeX + x) % sizeX, ty, tz, tt), dataSize); + } + + break; + } + + memcpy(tempData + (offset - minBorder[0]) * dataSize, getAddressAt(0, ty, tz, tt), sizeX * dataSize); } } } } -bool Calculator::resizeOutputDataBuffer(bool dataCopy, char *dataPointer) +bool Calculator::resizeTempDataBuffer(bool dataCopy, char *dataPointer) { - clearOutputData(); + int tmp; + clearTempData(); if(dataPointer==NULL) { - haveForeignOutputDataPointer = 1; - outData = new char[getOutputDataSizeInByte()]; - if(!outData) + haveForeignOutputDataPointer = 0; + tempData = new char[ tmp= getTempDataSizeInByte()]; + if(!tempData) return 0; } else { - haveForeignOutputDataPointer = 0; - outData = dataPointer; + haveForeignOutputDataPointer = 1; + tempData = dataPointer; } if(dataCopy) copyData(); @@ -46,20 +104,28 @@ return 1; } +void Calculator::updateBorder(void) +{ + +} + Calculator::Calculator() { - outData = NULL; + tempData = NULL; haveForeignOutputDataPointer = 0; - outDataSize.resize(4); + tempDataSize.resize(4); calculationSpaceStart.resize(4); calculationSpaceEnd.resize(4); neighbourhood = NULL; localfunction = NULL; + borderType = Calculator::TORUS; + + connect(this, SIGNAL(dataResized()), SLOT(setupSpace())); } Calculator::~Calculator() { - clearOutputData(); + clearTempData(); haveForeignOutputDataPointer = 0; neighbourhood = NULL; localfunction = NULL; @@ -68,7 +134,9 @@ void Calculator::setNeighbourhood(Neighbourhood *n) { neighbourhood = n; - neighbourhood->calculateOffsets(sizeX, sizeY, sizeZ, sizeT, getDataType()); + //setupSpace(); + //resizeTempDataBuffer(); + //neighbourhood->calculateOffsets(tempDataSize[0], tempDataSize[1], tempDataSize[2], tempDataSize[3], getDataType()); } void Calculator::setLocalFunction(LocalFunction *f) @@ -76,125 +144,107 @@ localfunction = f; } -bool Calculator::setCalculationSpace(QVector<int> start, QVector<int> end, bool dataCopy, char *foreignDataPointer) +int Calculator::getTempDataSizeInByte(void) { - if( start.size() == end.size() && start.size()==dimension) - { - for(int i=0;i<4;++i) - { - if(i<dimension) - { - calculationSpaceStart[i] = start[i]; - calculationSpaceEnd[i] = end[i]; - outDataSize[i] = calculationSpaceEnd[i] - calculationSpaceStart[i] + 1; - } - else - { - calculationSpaceStart[i] = 0; - calculationSpaceEnd[i] = 0; - outDataSize[i] = 0; - } - } - - return resizeOutputDataBuffer(dataCopy, foreignDataPointer); - } - return 0; -} - - -int Calculator::getOutputDataSizeInByte(void) -{ switch(dataType) { case baseDataTypes::BOOL: - return (outDataSize[0] * outDataSize[1] * outDataSize[2] * outDataSize[3])/8 + 1; + return (tempDataSize[0] * tempDataSize[1] * tempDataSize[2] * tempDataSize[3])/8 + 1; case baseDataTypes::CHAR: switch(dimension) { case 1: - return outDataSize[0] * sizeof(char); + return tempDataSize[0] * sizeof(char); case 2: - return outDataSize[0] * outDataSize[1] * sizeof(char); + return tempDataSize[0] * tempDataSize[1] * sizeof(char); case 3: - return outDataSize[0] * outDataSize[1] * outDataSize[2] * sizeof(char); + return tempDataSize[0] * tempDataSize[1] * tempDataSize[2] * sizeof(char); case 4: - return outDataSize[0] * outDataSize[1] * outDataSize[2] * outDataSize[3] * sizeof(char); + return tempDataSize[0] * tempDataSize[1] * tempDataSize[2] * tempDataSize[3] * sizeof(char); } case baseDataTypes::DOUBLE: switch(dimension) { case 1: - return outDataSize[0] * sizeof(double); + return tempDataSize[0] * sizeof(double); case 2: - return outDataSize[0] * outDataSize[1] * sizeof(double); + return tempDataSize[0] * tempDataSize[1] * sizeof(double); case 3: - return outDataSize[0] * outDataSize[1] * outDataSize[2] * sizeof(double); + return tempDataSize[0] * tempDataSize[1] * tempDataSize[2] * sizeof(double); case 4: - return outDataSize[0] * outDataSize[1] * outDataSize[2] * outDataSize[3] * sizeof(double); + return tempDataSize[0] * tempDataSize[1] * tempDataSize[2] * tempDataSize[3] * sizeof(double); } case baseDataTypes::FLOAT: switch(dimension) { case 1: - return outDataSize[0] * sizeof(float); + return tempDataSize[0] * sizeof(float); case 2: - return outDataSize[0] * outDataSize[1] * sizeof(float); + return tempDataSize[0] * tempDataSize[1] * sizeof(float); case 3: - return outDataSize[0] * outDataSize[1] * outDataSize[2] * sizeof(float); + return tempDataSize[0] * tempDataSize[1] * tempDataSize[2] * sizeof(float); case 4: - return outDataSize[0] * outDataSize[1] * outDataSize[2] * outDataSize[3] * sizeof(float); + return tempDataSize[0] * tempDataSize[1] * tempDataSize[2] * tempDataSize[3] * sizeof(float); } case baseDataTypes::INT: switch(dimension) { case 1: - return outDataSize[0] * sizeof(int); + return tempDataSize[0] * sizeof(int); case 2: - return outDataSize[0] * outDataSize[1] * sizeof(int); + return tempDataSize[0] * tempDataSize[1] * sizeof(int); case 3: - return outDataSize[0] * outDataSize[1] * outDataSize[2] * sizeof(int); + return tempDataSize[0] * tempDataSize[1] * tempDataSize[2] * sizeof(int); case 4: - return outDataSize[0] * outDataSize[1] * outDataSize[2] * outDataSize[3] * sizeof(int); + return tempDataSize[0] * tempDataSize[1] * tempDataSize[2] * tempDataSize[3] * sizeof(int); } case baseDataTypes::SHORT: switch(dimension) { case 1: - return outDataSize[0] * sizeof(short); + return tempDataSize[0] * sizeof(short); case 2: - return outDataSize[0] * outDataSize[1] * sizeof(short); + return tempDataSize[0] * tempDataSize[1] * sizeof(short); case 3: - return outDataSize[0] * outDataSize[1] * outDataSize[2] * sizeof(short); + return tempDataSize[0] * tempDataSize[1] * tempDataSize[2] * sizeof(short); case 4: - return outDataSize[0] * outDataSize[1] * outDataSize[2] * outDataSize[3] * sizeof(short); + return tempDataSize[0] * tempDataSize[1] * tempDataSize[2] * tempDataSize[3] * sizeof(short); } } return 0; } -/*const*/ char *Calculator::getOutputDataPointer(void) -{ - return outData; -} - void Calculator::calculate(void) { int counter = 0; char temp[8]; - for(int t=calculationSpaceStart[3];t<=calculationSpaceEnd[3];++t) + int sx = tempDataSize[0] - maxBorder[0] , sy = tempDataSize[1] - maxBorder[1], sz = tempDataSize[2] - maxBorder[2], st = tempDataSize[3] - maxBorder[3]; + + if(sy==0) + sy=1; + + if(sz==0) + sz=1; + + if(st==0) + st=1; + + copyData(); + + for(int t=-minBorder[3];t<st;++t) { - for(int z=calculationSpaceStart[2];z<=calculationSpaceEnd[2];++z) + for(int z=-minBorder[2];z<sz;++z) { - for(int y=calculationSpaceStart[1];y<=calculationSpaceEnd[1];++y) + for(int y=-minBorder[1];y<sy;++y) { - for(int x=calculationSpaceStart[0];x<=calculationSpaceEnd[0];++x) + for(int x=-minBorder[0];x<sx;++x) { - neighbourhood->resolveValues((const char *)getAddressAt(x, y, z, t)); + neighbourhood->resolveValues(tempData + x + (y * tempDataSize[0]) + z * (tempDataSize[0] * tempDataSize[1]) + t * (tempDataSize[0] * tempDataSize[1] * tempDataSize[2]) * dataSize); switch(dataType) { case baseDataTypes::BOOL: @@ -210,10 +260,27 @@ *((double *)temp) = localfunction->resolve(neighbourhood->valuesToVector_d()); break; } - memcpy(outData + counter, temp, dataSize); + memcpy(data + counter, temp, dataSize); counter += dataSize; } } } } + } + +void Calculator::setupSpace(void) +{ + if(neighbourhood) + { + minBorder = neighbourhood->getMinNeighbourhoodValues(); + maxBorder = neighbourhood->getMaxNeighbourhoodValues(); + tempDataSize[0] = -minBorder[0] + maxBorder[0] + sizeX; + tempDataSize[1] = -minBorder[1] + maxBorder[1] + sizeY; + tempDataSize[2] = -minBorder[2] + maxBorder[2] + sizeZ; + tempDataSize[3] = -minBorder[3] + maxBorder[3] + sizeT; + resizeTempDataBuffer(); + neighbourhood->calculateOffsets(tempDataSize[0], tempDataSize[1], tempDataSize[2], tempDataSize[3], getDataType()); + + } +} \ No newline at end of file Modified: trunk/qcell/basesources/GenericParserPlugin.cpp =================================================================== --- trunk/qcell/basesources/GenericParserPlugin.cpp 2007-01-10 16:48:27 UTC (rev 139) +++ trunk/qcell/basesources/GenericParserPlugin.cpp 2007-01-10 19:50:10 UTC (rev 140) @@ -73,8 +73,10 @@ } - return realParser(content, type, subtype); + QString s = realParser(content, type, subtype); + return s; + } QByteArray GenericParserPlugin::parseOut(const QString content, const QString type, const QString subtype) Modified: trunk/qcell/basesources/Neighbourhood.cpp =================================================================== --- trunk/qcell/basesources/Neighbourhood.cpp 2007-01-10 16:48:27 UTC (rev 139) +++ trunk/qcell/basesources/Neighbourhood.cpp 2007-01-10 19:50:10 UTC (rev 140) @@ -3,6 +3,8 @@ Neighbourhood::Neighbourhood() { dimension = 666; + minValues.resize(4); + maxValues.resize(4); } Neighbourhood::~Neighbourhood() @@ -19,6 +21,12 @@ temp.t = 0; neighbourVector << temp; dimension = 1; + + if(minValues[0]>x) + minValues[0]=x; + + if(maxValues[0]<x) + maxValues[0]=x; } void Neighbourhood::addNeighbour(int x, int y) @@ -31,6 +39,19 @@ neighbourVector << temp; if(dimension>2) dimension = 2; + + if(minValues[0]>x) + minValues[0]=x; + + if(maxValues[0]<x) + maxValues[0]=x; + + if(minValues[1]>y) + minValues[1]=y; + + if(maxValues[1]<y) + maxValues[1]=y; + } void Neighbourhood::addNeighbour(int x, int y, int z) { @@ -42,6 +63,24 @@ neighbourVector << temp; if(dimension>3) dimension = 3; + + if(minValues[0]>x) + minValues[0]=x; + + if(maxValues[0]<x) + maxValues[0]=x; + + if(minValues[1]>y) + minValues[1]=y; + + if(maxValues[1]<y) + maxValues[1]=y; + + if(minValues[2]>z) + minValues[2]=z; + + if(maxValues[2]<z) + maxValues[2]=z; } void Neighbourhood::addNeighbour(int x, int y, int z, int t) @@ -54,6 +93,32 @@ neighbourVector << temp; if(dimension>4) dimension = 4; + + + + if(minValues[0]>x) + minValues[0]=x; + + if(maxValues[0]<x) + maxValues[0]=x; + + if(minValues[1]>y) + minValues[1]=y; + + if(maxValues[1]<y) + maxValues[1]=y; + + if(minValues[2]>z) + minValues[2]=z; + + if(maxValues[2]<z) + maxValues[2]=z; + + if(minValues[3]>t) + minValues[3]=t; + + if(maxValues[3]<t) + maxValues[3]=t; } void Neighbourhood::addNeighbour(QVector<int> v) @@ -146,6 +211,11 @@ { dimension = 666; neighbourVector.clear(); + if(dimension!=minValues.size()) + { + minValues[3] = minValues[2] = minValues[1] = minValues[0]=9999; + maxValues[3] = maxValues[2] = maxValues[1] = maxValues[0]=-9999; + } } int Neighbourhood::getDimension(void) @@ -380,3 +450,14 @@ out<<c.value.dValue; return out; } + + +QVector<int> Neighbourhood::getMaxNeighbourhoodValues(void) +{ + return maxValues; +} + +QVector<int> Neighbourhood::getMinNeighbourhoodValues(void) +{ + return minValues; +} Modified: trunk/qcell/basesources/simulationwindow.cpp =================================================================== --- trunk/qcell/basesources/simulationwindow.cpp 2007-01-10 16:48:27 UTC (rev 139) +++ trunk/qcell/basesources/simulationwindow.cpp 2007-01-10 19:50:10 UTC (rev 140) @@ -479,9 +479,9 @@ simulationWindow::~simulationWindow() { - if(renderer) - delete renderer; - renderer = NULL; +// if(renderer) +// delete renderer; +// renderer = NULL; if(pixmap) delete pixmap; Modified: trunk/qcell/parsers/FQT/FQTParserPlugin.cpp =================================================================== --- trunk/qcell/parsers/FQT/FQTParserPlugin.cpp 2007-01-10 16:48:27 UTC (rev 139) +++ trunk/qcell/parsers/FQT/FQTParserPlugin.cpp 2007-01-10 19:50:10 UTC (rev 140) @@ -264,14 +264,21 @@ /// @todo How the fuck set FQT function parameters eh? + //looknij to + + int test; + switch(lf.getFunctonType()) { case LocalFunction::SUM_AND_SWITCH: + lf.setDefaultValue(0); foreach(int sum, results.keys()) { + test = results.value(sum).size(); for(int i=0;i<results.value(sum).size();++i) lf.setFunctionValue((results.value(sum))[i], sum, i); } + break; } return lf.toXmlString(); } Modified: trunk/qcell/visgui/MainWindow.cpp =================================================================== --- trunk/qcell/visgui/MainWindow.cpp 2007-01-10 16:48:27 UTC (rev 139) +++ trunk/qcell/visgui/MainWindow.cpp 2007-01-10 19:50:10 UTC (rev 140) @@ -223,7 +223,6 @@ if(!fd.selectedFiles().isEmpty()) { callParser(fd.selectedFiles().first(), "World"); - } } @@ -335,7 +334,7 @@ end_coord << data.last()->getSizeX() << data.last()->getSizeY() << data.last()->getSizeZ(); - calc.setCalculationSpace(*new QVector<int>(3, 0), end_coord); + //calc.setCalculationSpace(*new QVector<int>(3, 0), end_coord); // Enable saving menu for World menu_Save->setEnabled(true); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |