Foam::scalar Foam::equationReader::getScalarSrcSphericalTensorFieldSource
(
    const equationReader * eqnReader,
    const label equationIndex,
    const label equationOperationIndex,
    const label maxStoreIndex,
    const label storageOffset
) const
{
    const equation& eqn(operator[](equationIndex));
    const equationOperation& eqOp(eqn[equationOperationIndex]);
    label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1;
    scalar returnMe
    (
        sphericalTensorSources_.fieldValue
        (
            zeroSourceIndex,
            eqOp.componentIndex(),
            cellIndex_,
            geoIndex_
        )
    );
    returnMe *= sign(eqOp.sourceIndex());
    return returnMe;
}
Foam::scalar Foam::equationReader::getScalarSrcActiveSource
(
    const equationReader * eqnReader,
    const label equationIndex,
    const label equationOperationIndex,
    const label maxStoreIndex,
    const label storageOffset
) const
{
    const equation& eqn(operator[](equationIndex));
    const equationOperation& eqOp(eqn[equationOperationIndex]);
    label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1;

    scalar returnMe
    (
        activeSources_[zeroSourceIndex].evaluateScalar
        (
            eqOp.componentIndex(),
            cellIndex_,
            geoIndex_
        )
    );
    returnMe *= sign(eqOp.sourceIndex());
    return returnMe;
}
Foam::scalar Foam::equationReader::getScalarSrcStorage
(
    const equationReader * eqnReader,
    const label equationIndex,
    const label equationOperationIndex,
    const label maxStoreIndex,
    const label storageOffset
) const
{
    const equation& eqn(operator[](equationIndex));
    const equationOperation& eqOp(eqn[equationOperationIndex]);
    label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1;

#   ifdef FULLDEBUG
    if ((zeroSourceIndex + storageOffset) > maxStoreIndex)
    {
        FatalErrorIn("equationReader::getSouce")
            << "Index " << zeroSourceIndex << " out of bounds (0, "
            << maxStoreIndex - storageOffset << ")"
            << abort(FatalError);
    }
#   endif
    scalar returnMe(storageScalars_[zeroSourceIndex + storageOffset]);
    returnMe *= sign(eqOp.sourceIndex());
    return returnMe;
}
Beispiel #4
0
QImage ImageProcessor::constrastImage(QImage original, int amount) {
    QImage returnMe(original.width(),original.height(),QImage::Format_RGB32);
    //QPainter painter(&returnMe);


    //Taken from Wikipedia / GIMP at http://en.wikipedia.org/wiki/Image_editing#Contrast_change_and_brightening
    double frac = ((amount - 50)*2) / 100.0;

    #pragma omp parallel for
    for(int x=0;x<original.width();x++) {
        for(int y=0;y<original.height();y++) {
            qreal value = (qRed(original.pixel(x,y)))/255.0;
            qreal newVal = (value - 0.5) * (tan ((frac + 1) * 0.78539816339) ) + 0.5;
            newVal = qMin(newVal*255,255.0);
            newVal = qMax(newVal,0.0);
            int setVal = (int)newVal;

            //qDebug()<<"("<<x<<","<<y<<") is now "<<setVal;
            //painter.fillRect(x,y,1,1,QColor(setVal,setVal,setVal));
            returnMe.setPixel(x,y,qRgb(setVal,setVal,setVal));
        }
    }

    return returnMe;
}
Foam::scalar Foam::equationReader::getScalarSrcEquation
(
    const equationReader * eqnReader,
    const label equationIndex,
    const label equationOperationIndex,
    const label maxStoreIndex,
    const label storageOffset
) const
{
    const equation& eqn(operator[](equationIndex));
    const equationOperation& eqOp(eqn[equationOperationIndex]);
    label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1;

    dependents_.setSize(dependents_.size() + 1);
    dependents_[dependents_.size() - 1] = equationIndex;

    // Launch the reportEmbeddedDispatchFunction:
    //  if (debug)
    //  {
    //      reportEmbeddedDispatchEnabled;
    //      // or: Info << "Embedded equation dispatch." << endl;
    //  }
    //  else
    //  {
    //      reportEmbeddedDispatchDisabled();
    //      // does nothing
    //  }
    (*this.*reportEmbeddedDispatchFunction_)();

    scalar returnMe
    (
        internalEvaluateScalar(zeroSourceIndex, maxStoreIndex + 1)
    );

    // Launch the reportEmbeddedReturnFunction:
    //  if (debug)
    //  {
    //      reportEmbeddedReturnEnabled;
    //      // or: Info << "Return from equation equation." << endl;
    //  }
    //  else
    //  {
    //      reportEmbeddedReturnDisabled();
    //      // does nothing
    //  }
    (*this.*reportEmbeddedReturnFunction_)();

    //Move one level back up on the dependents_ list
    if (dependents_.size())
    {
        dependents_.setSize(dependents_.size() - 1);
    }    

    returnMe *= sign(eqOp.sourceIndex());
    return returnMe;
}
Foam::scalar Foam::equationReader::getScalarSrcInternalScalar
(
    const equationReader * eqnReader,
    const label equationIndex,
    const label equationOperationIndex,
    const label maxStoreIndex,
    const label storageOffset
) const
{
    const equation& eqn(operator[](equationIndex));
    const equationOperation& eqOp(eqn[equationOperationIndex]);
    label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1;

    scalar returnMe(internalScalars_[zeroSourceIndex]);
    returnMe *= sign(eqOp.sourceIndex());
    return returnMe;
}
Foam::labelList Foam::equationReader::findMaxOperation
(
    const labelList& opLvl,
    const labelList& indices
) const
{
    label maxOpLvl(-1);
    label atIndex(-1);
    labelList returnMe(indices.size());
    bool groupDone(false);

    forAll(indices, i)
    {
        if (opLvl[indices[i]] > maxOpLvl)
        {
            atIndex = 0;
            returnMe[0] = indices[i];
            if (i > 0)
            {
                atIndex++;
                returnMe[0] = indices[i - 1];
                returnMe[1] = indices[i];
            }
            groupDone = false;
            maxOpLvl = opLvl[indices[i]];
        }
        else if
        (
            (
                (opLvl[indices[i]] == maxOpLvl)
             || (opLvl[indices[i]] == 0)
            )
         && !groupDone
        )
        {
            atIndex++;
            returnMe[atIndex] = indices[i];
        }
        else if ((opLvl[indices[i]] < maxOpLvl) && (opLvl[indices[i]] != 0))
        {
            groupDone = true;
        }
    }
    returnMe.setSize(atIndex + 1);
    return returnMe;
}
Beispiel #8
0
QImage ImageProcessor::spreadHistogram(QImage input) {
    //Really, this is normalization, http://en.wikipedia.org/wiki/Normalization_(image_processing)
    QImage returnMe(input.width(),input.height(),QImage::Format_ARGB32);
    QPainter painter(&returnMe);
    QVector<float> occ = ImageProcessor::findOccurrences(input);
    int lowest =0;
    bool goOn = true;

    for(int i=0;(i<occ.size()) && goOn;i++) {
        if(occ.at(i) == 0.0) {
            lowest = i;
        } else {
            goOn = false;
        }
    }

    int highest = 255;
    goOn =true;

    for(int i=occ.size()-1;(i>0) && goOn;i--) {
        if(occ.at(i) == 0.0) {
            highest = i;
        } else {
            goOn = false;
        }
    }

    int diff = highest - lowest;

    for(int x=0;x<input.width();x++) {
        for(int y=0;y<input.height();y++) {
            int value = qRed(input.pixel(x,y));
            int newValue =(int) ((value - lowest) * (255.0 / diff));
            //TODO: faster way to fill those pixels
            painter.fillRect(x,y,1,1,QColor(newValue,newValue,newValue));
        }
    }

    return returnMe;
}
Foam::scalar Foam::equationReader::getScalarSrcDictSourceScalar
(
    const equationReader * eqnReader,
    const label equationIndex,
    const label equationOperationIndex,
    const label maxStoreIndex,
    const label storageOffset
) const
{
    const equation& eqn(operator[](equationIndex));
    const equationOperation& eqOp(eqn[equationOperationIndex]);
    label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1;

    word varName(dictLookups_[eqOp.dictLookupIndex()]);
    
    scalar returnMe
    (
        readScalar(dictSources_[zeroSourceIndex].lookup(varName))
    );
    returnMe *= sign(eqOp.sourceIndex());
    return returnMe;
}
Beispiel #10
0
QImage ImageProcessor::equalizeHistogram(QImage input) {
    QImage returnMe(input.width(),input.height(),QImage::Format_ARGB32);
    QPainter painter(&returnMe);

    QVector<float> occ = ImageProcessor::findOccurrences(input);
    QVector<float> pdf;
    float currentpdf =0;
    for(int i=0;i<occ.count();i++) {
        currentpdf += occ.value(i);
        pdf.append(currentpdf);
    }

    for(int x=0;x<input.width();x++) {
        for(int y=0;y<input.height();y++) {
            int originalVal = qRed(input.pixel(x,y));
            float pdfVal = pdf.value(originalVal);
            int newVal = (int)(pdfVal * 255);
            painter.fillRect(x,y,1,1,QColor(newVal,newVal,newVal));
        }
    }
    return returnMe;
}
Foam::scalar Foam::equationReader::getScalarSrcSymmTensorSource
(
    const equationReader * eqnReader,
    const label equationIndex,
    const label equationOperationIndex,
    const label maxStoreIndex,
    const label storageOffset
) const
{
    const equation& eqn(operator[](equationIndex));
    const equationOperation& eqOp(eqn[equationOperationIndex]);
    label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1;
    scalar returnMe
    (
        symmTensorSources_.singleValue
        (
            zeroSourceIndex,
            eqOp.componentIndex()
        )
    );
    returnMe *= sign(eqOp.sourceIndex());
    return returnMe;
}
Foam::labelList Foam::equationReader::findMaxParenthesis
(
    const labelList& parenthesisList,
    const labelList& equationIndices
) const
{
    labelList returnMe(equationIndices.size());
    label currentMax(-1);
    label atIndex(0);
    bool groupDone(false);

    forAll(equationIndices, i)
    {
        if (mag(parenthesisList[equationIndices[i]]) > currentMax)
        {
            groupDone = false;
            atIndex = 0;
            currentMax = mag(parenthesisList[equationIndices[i]]);
            returnMe[atIndex] = equationIndices[i];
        }
        else if
        (
            (mag(parenthesisList[equationIndices[i]]) == currentMax)
         && (!groupDone)
        )
        {
            atIndex++;
            returnMe[atIndex] = equationIndices[i];
        }
        else if (mag(parenthesisList[equationIndices[i]]) < currentMax)
        {
            groupDone = true;
        }
    }
    returnMe.setSize(atIndex + 1);
    return returnMe;
}
Foam::scalar Foam::equationReader::getScalarSrcEquationCircRefDetect
(
    const equationReader * eqnReader,
    const label equationIndex,
    const label equationOperationIndex,
    const label maxStoreIndex,
    const label storageOffset
) const
{
    const equation& eqn(operator[](equationIndex));
    equationOperation& eqOp(eqn[equationOperationIndex]);
    label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1;

    // Check for circular references
    dependents_.setSize(dependents_.size() + 1);
    dependents_[dependents_.size() - 1] = equationIndex;
    forAll(dependents_, i)
    {
        if (dependents_[i] == zeroSourceIndex)
        {
            // Circular reference detected
            
            string dependencies;
            for (label j(i); j < dependents_.size(); j++)
            {
                dependencies.append
                (
                    operator[](dependents_[j]).name()
                );
                dependencies.append("-->");
            }
            dependencies.append(operator[](dependents_[i]).name());
            FatalErrorIn("equationReader::getScalarSrcEquationCircRefDetect")
                << "Circular reference detected when evaluating "
                << "the equation for " << eqn.name()
                << ", given by:" << token::NL << token::TAB
                << eqn.rawText() << token::NL << "The circular "
                << "dependency is:" << token::NL << token::TAB
                << dependencies
                << abort(FatalError);
        }
    }
    // Launch the reportEmbeddedDispatchFunction:
    //  if (debug)
    //  {
    //      reportEmbeddedDispatchEnabled;
    //      // or: Info << "Embedded equation dispatch." << endl;
    //  }
    //  else
    //  {
    //      reportEmbeddedDispatchDisabled();
    //      // does nothing
    //  }
    scalar returnMe
    (
        internalEvaluateScalar(zeroSourceIndex, maxStoreIndex + 1)
    );
    eqOp.assignSourceScalarFunction
    (
        &Foam::equationReader::getScalarSrcEquation
    );
    eqOp.assignSourceScalarFieldFunction
    (
        &Foam::equationReader::getScalarFieldSrcEquation
    );
    // Launch the reportEmbeddedReturnFunction:
    //  if (debug)
    //  {
    //      reportEmbeddedReturnEnabled;
    //      // or: Info << "Return from equation equation." << endl;
    //  }
    //  else
    //  {
    //      reportEmbeddedReturnDisabled();
    //      // does nothing
    //  }
    (*this.*reportEmbeddedReturnFunction_)();
    
    //Move one level back up on the dependents_ list
    if (dependents_.size())
    {
        dependents_.setSize(dependents_.size() - 1);
    }    
    
    returnMe *= sign(eqOp.sourceIndex());
    return returnMe;
}
Beispiel #14
0
QImage ImageProcessor::invertImage(QImage input) {
    QImage returnMe(input);
    returnMe.invertPixels();
    return returnMe;
}
Foam::dimensionSet Foam::equationReader::getDimsSrcEquation
(
    const equationReader * eqnReader,
    const label equationIndex,
    const label equationOperationIndex,
    const label maxStoreIndex,
    const label storageOffset
) const
{
    const equation& eqn(operator[](equationIndex));
    const equationOperation& eqOp(eqn[equationOperationIndex]);
    label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1;

    dependents_.setSize(dependents_.size() + 1);
    dependents_[dependents_.size() - 1] = equationIndex;

    // Launch the reportEmbeddedDispatchFunction:
    //  if (debug)
    //  {
    //      reportEmbeddedDispatchEnabled;
    //      // or: Info << "Embedded equation dispatch." << endl;
    //  }
    //  else
    //  {
    //      reportEmbeddedDispatchDisabled();
    //      // does nothing
    //  }
    (*this.*reportEmbeddedDispatchFunction_)();

    // Call the associated evaluateDimensions function pointer - has the same
    // effect as this:
    //
    //  const equation& eqn(operator[](zeroSourceIndex));
    //  if (eqn.changeDimensions())
    //  {
    //      evaluateDimsDisabled(zeroSourceIndex, maxStoreIndex + 1);
    //      // which in turn does: return eqn.overrideDimensions();
    //  }
    //  else
    //  {
    //      evaluadeDimsEnabled(zeroSourceIndex, maxStoreIndex + 1);
    //      // which in turn does:
    //      // return internalEvaluateDimensions
    //      // (zeroSourceIndex, maxStoreIndex + 1);
    //  }
    dimensionSet returnMe
    (
        (*this.*evaluateDimsFunctions_[zeroSourceIndex])
        (zeroSourceIndex, maxStoreIndex + 1)
    );

    // Launch the reportEmbeddedReturnFunction:
    //  if (debug)
    //  {
    //      reportEmbeddedReturnEnabled;
    //      // or: Info << "Return from equation equation." << endl;
    //  }
    //  else
    //  {
    //      reportEmbeddedReturnDisabled();
    //      // does nothing
    //  }
    (*this.*reportEmbeddedReturnFunction_)();

    //Move one level back up on the dependents_ list
    if (dependents_.size())
    {
        dependents_.setSize(dependents_.size() - 1);
    }

    return returnMe;
}
Foam::dimensionSet Foam::equationReader::getDimsSrcEquationCircRefDetect
(
    const equationReader * eqnReader,
    const label equationIndex,
    const label equationOperationIndex,
    const label maxStoreIndex,
    const label storageOffset
) const
{
    const equation& eqn(operator[](equationIndex));
    equationOperation& eqOp(eqn[equationOperationIndex]);
    label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1;

    // Check for circular references
    dependents_.setSize(dependents_.size() + 1);
    dependents_[dependents_.size() - 1] = equationIndex;
    forAll(dependents_, i)
    {
        if (dependents_[i] == zeroSourceIndex)
        {
            // Circular reference detected
            string dependencies;
            for (label j(i); j < dependents_.size(); j++)
            {
                dependencies.append
                (
                    operator[](dependents_[j]).name()
                );
                dependencies.append("-->");
            }
            dependencies.append(operator[](dependents_[i]).name());
            FatalErrorIn
            (
                "equationReader::getDimsSrcEquationCircRefDetect"
            )
                << "Circular reference detected when evaluating "
                << "the equation for " << eqn.name()
                << ", given by:" << token::NL << token::TAB
                << eqn.rawText() << token::NL << "The circular "
                << "dependency is:" << token::NL << token::TAB
                << dependencies
                << abort(FatalError);
        }
    }

    // Launch the reportEmbeddedDispatchFunction:
    //  if (debug)
    //  {
    //      reportEmbeddedDispatchEnabled;
    //      // or: Info << "Embedded equation dispatch." << endl;
    //  }
    //  else
    //  {
    //      reportEmbeddedDispatchDisabled();
    //      // does nothing
    //  }
    (*this.*reportEmbeddedDispatchFunction_)();

    // Call the associated evaluateDimensions function pointer - has the same
    // effect as this:
    //
    //  const equation& eqn(operator[](zeroSourceIndex));
    //  if (eqn.changeDimensions())
    //  {
    //      evaluateDimsDisabled(zeroSourceIndex, maxStoreIndex + 1);
    //      // which in turn does: return eqn.overrideDimensions();
    //  }
    //  else
    //  {
    //      evaluadeDimsEnabled(zeroSourceIndex, maxStoreIndex + 1);
    //      // which in turn does:
    //      // return internalEvaluateDimensions
    //      // (zeroSourceIndex, maxStoreIndex + 1);
    //  }
    dimensionSet returnMe
    (
        (*this.*evaluateDimsFunctions_[zeroSourceIndex])
        (zeroSourceIndex, maxStoreIndex + 1)
    );

    // Launch the reportEmbeddedReturnFunction:
    //  if (debug)
    //  {
    //      reportEmbeddedReturnEnabled;
    //      // or: Info << "Return from equation equation." << endl;
    //  }
    //  else
    //  {
    //      reportEmbeddedReturnDisabled();
    //      // does nothing
    //  }
    (*this.*reportEmbeddedReturnFunction_)();

    //Move one level back up on the dependents_ list
    if (dependents_.size())
    {
        dependents_.setSize(dependents_.size() - 1);
    }

    return returnMe;
}