int NgonGridDataDecomposer::isFacetEdgeValid(double* z, double* values, int perNodeValues, int numX, int numY, int i, int j, int logUsed)
{
    double zij = 0.;
    double zijp1 = 0.;

    int lowerZValid = 0;
    int upperZValid = 0;

    zij = getZCoordinate(z, numX, numY, i, j);
    zijp1 = getZCoordinate(z, numX, numY, i, j+1);

    lowerZValid = DecompositionUtils::isValid(zij);
    upperZValid = DecompositionUtils::isValid(zijp1);

    if (logUsed)
    {
        lowerZValid &= DecompositionUtils::isLogValid(zij);
        upperZValid &= DecompositionUtils::isLogValid(zijp1);
    }

    if (lowerZValid && upperZValid)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
/*
 * To be merged with its parent's isFacetEdgeValid function.
 */
int NgonGridGrayplotDataDecomposer::isFacetEdgeValid(double* z, double* values, int perNodeValues, int numX, int numY, int i, int j, int logUsed)
{
    double zij = 0.;
    double zijp1 = 0.;

    int lowerZValid = 0;
    int upperZValid = 0;

    /* First, z-coordinate values are tested */
    zij = getZCoordinate(z, numX, numY, i, j, logUsed);
    zijp1 = getZCoordinate(z, numX, numY, i, j + 1, logUsed);

    lowerZValid = DecompositionUtils::isValid(zij);
    upperZValid = DecompositionUtils::isValid(zijp1);

    if (logUsed)
    {
        lowerZValid &= DecompositionUtils::isLogValid(zij);
        upperZValid &= DecompositionUtils::isLogValid(zijp1);
    }

    /*
     * If values are defined per node, edge validity must also
     * take into account grid values at the edge's nodes.
     */
    if (perNodeValues)
    {
        zij = getValue(values, numX, numY, i, j);
        zijp1 = getValue(values, numX, numY, i, j + 1);

        lowerZValid &= DecompositionUtils::isValid(zij);
        upperZValid &= DecompositionUtils::isValid(zijp1);
    }

    if (lowerZValid && upperZValid)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
void NgonGridDataDecomposer::getFacetCoordinates(double* x, double* y, double*z, int numX, int numY, int i, int j,
    double vertices[4][3])
{
    vertices[0][0] = x[i];
    vertices[0][1] = y[j];
    vertices[0][2] = getZCoordinate(z, numX, numY, i, j);;

    vertices[1][0] = x[i+1];
    vertices[1][1] = y[j];
    vertices[1][2] = getZCoordinate(z, numX, numY, i+1, j);

    vertices[2][0] = x[i+1];
    vertices[2][1] = y[j+1];
    vertices[2][2] = getZCoordinate(z, numX, numY, i+1, j+1);

    vertices[3][0] = x[i];
    vertices[3][1] = y[j+1];
    vertices[3][2] = getZCoordinate(z, numX, numY, i, j+1);
}
int NgonGridMatplotDataDecomposer::isFacetValid(double* z, double* values, int perNodeValues, int numX, int numY, int i, int j, int logUsed, int currentEdgeValid, int* nextEdgeValid)
{
    double zij = 0.;
    int facetValid = 0;

    zij = getZCoordinate(z, numX, numY, i, j, logUsed);

    facetValid = DecompositionUtils::isValid(zij);

    if (logUsed)
    {
        facetValid &= DecompositionUtils::isLogValid(zij);
    }

    /* Transposed relative to Grayplot */
    facetValid &= DecompositionUtils::isValid(values[getPointIndex(numY - 1, numX - 1, numY - 2 - j, i)]);

    /* Edge validity is always 1 since it is not used at all to determine facet validity for Matplot decomposition */
    *nextEdgeValid = 1;

    return facetValid;
}
Exemplo n.º 5
0
void  GUIPanel::collectZWidgets(ZWidgets &container)
{
  if(visible)
  {
    for(size_t t = 0; t < elements.size(); t++)
      if(elements[t]->getWidgetType() != WT_PANEL)
      {
        ZWidget zWidget(elements[t]);
        zWidget.setDistance(float(elements[t]->getZCoordinate()));
        container.push_back(zWidget);
      }
      else
      {
         ((GUIPanel*)elements[t])->collectZWidgets(container);
      }

    ZWidget zWidget(this);
    zWidget.setDistance(float(getZCoordinate()));

    container.push_back(zWidget);
  }
}
void NgonGridDataDecomposer::fillGridVertices(float* buffer, int bufferLength, int elementsSize, int coordinateMask, double* scale, double* translation, int logMask,
    double* x, double* y, double* z, int numX, int numY)
{
    double xi = 0.;
    double yj = 0.;
    double zij = 0.;

    int bufferOffset = 0;

#if PER_VERTEX_VALUES
    for (int j = 0; j < numY; j++)
    {
        yj = y[j];

        if (coordinateMask  & 0x2)
        {
            if (logMask & 0x2)
            {
                yj = DecompositionUtils::getLog10Value(yj);
            }
        }

        for (int i = 0; i < numX; i++)
        {
            xi = x[i];
            bufferOffset = elementsSize*(numX*j + i);

            if (coordinateMask & 0x1)
            {
                if (logMask & 0x1)
                {
                    xi = DecompositionUtils::getLog10Value(xi);
                }

                buffer[bufferOffset] = xi * scale[0] + translation[0];
            }

            if (coordinateMask  & 0x2)
            {
                buffer[bufferOffset +1] = yj * scale[1] + translation[1];
            }

            if (coordinateMask & 0x4)
            {
                zij = getZCoordinate(z, numX, numY, i, j, logMask & 0x4);

                buffer[bufferOffset +2] = zij * scale[2] + translation[2];
            }

            if (elementsSize == 4 && (coordinateMask & 0x8))
            {
                buffer[bufferOffset +3] = 1.0;
            }
        }
    }
#else

    double yjp1 = 0.;
    double xip1 = 0.;

    bufferOffset = 0;

    for (int j = 0; j < numY-1; j++)
    {
        double ycoords[4];
        int yindices[4];

        yj = y[j];
        yjp1 = y[j+1];

        if (coordinateMask  & 0x2)
        {
            if (logMask & 0x2)
            {
                yj = DecompositionUtils::getLog10Value(yj);
                yjp1 = DecompositionUtils::getLog10Value(yjp1);
            }
        }

        ycoords[0] = yj;
        ycoords[1] = yj;
        ycoords[2] = yjp1;
        ycoords[3] = yjp1;

        yindices[0] = j;
        yindices[1] = j;
        yindices[2] = j+1;
        yindices[3] = j+1;

        for (int i = 0; i < numX-1; i++)
        {
            double xcoords[4];
            int xindices[4];

            xi = x[i];
            xip1 = x[i+1];

            if (logMask & 0x1)
            {
                xi = DecompositionUtils::getLog10Value(xi);
                xip1 = DecompositionUtils::getLog10Value(xip1);
            }

            xcoords[0] = xi;
            xcoords[1] = xip1;
            xcoords[2] = xi;
            xcoords[3] = xip1;

            xindices[0] = i;
            xindices[1] = i+1;
            xindices[2] = i;
            xindices[3] = i+1;

            /*
             * If color values are defined per facet, we must duplicate shared vertices in order
             * to be able to render flat-shading facets, as the renderer uses smooth shading as a default.
             * Reducing duplication would require being able to enable flat shading at render time.
             */
            for (int k = 0; k < 4; k++)
            {
                if (coordinateMask & 0x1)
                {
                    buffer[bufferOffset] = (float)(xcoords[k] * scale[0] + translation[0]);
                }

                if (coordinateMask  & 0x2)
                {
                    buffer[bufferOffset +1] = (float)(ycoords[k] * scale[1] + translation[1]);
                }

                if (coordinateMask & 0x4)
                {
                    zij = getZCoordinate(z, numX, numY, xindices[k], yindices[k], logMask & 0x4);

                    buffer[bufferOffset +2] = (float)(zij * scale[2] + translation[2]);
                }

                if (elementsSize == 4 && (coordinateMask & 0x8))
                {
                    buffer[bufferOffset +3] = 1.0;
                }

                bufferOffset += elementsSize;
            }

        }

    }

#endif

}
/* To do: refactor with its parent class' same method */
void NgonGridMatplotDataDecomposer::fillGridVertices(float* buffer, int bufferLength, int elementsSize, int coordinateMask, double* scale, double* translation, int logMask,
        double* x, double* y, double* z, int numX, int numY)
{
    double xi = 0.;
    double yj = 0.;
    double zij = 0.;
    double yjp1 = 0.;
    double xip1 = 0.;

    int bufferOffset = 0;

#if PER_VERTEX_VALUES
    for (int j = 0; j < numY; j++)
    {
        yj = (double) j * y[1] + y[0];

        if (coordinateMask  & 0x2)
        {
            if (logMask & 0x2)
            {
                yj = DecompositionUtils::getLog10Value(yj);
            }
        }

        for (int i = 0; i < numX; i++)
        {
            xi = (double) i * x[1] + x[0];
            bufferOffset = elementsSize * (numX * j + i);

            if (coordinateMask & 0x1)
            {
                if (logMask & 0x1)
                {
                    xi = DecompositionUtils::getLog10Value(xi);
                }

                buffer[bufferOffset] = xi * scale[0] + translation[0];
            }

            if (coordinateMask  & 0x2)
            {
                buffer[bufferOffset + 1] = yj * scale[1] + translation[1];
            }

            if (coordinateMask & 0x4)
            {
                zij = getZCoordinate(z, numX, numY, i, j, logMask & 0x4);

                buffer[bufferOffset + 2] = zij * scale[2] + translation[2];
            }

            if (elementsSize == 4 && (coordinateMask & 0x8))
            {
                buffer[bufferOffset + 3] = 1.0;
            }
        }
    }
#else
    bufferOffset = 0;

    for (int j = 0; j < numY - 1; j++)
    {
        double ycoords[4];
        int yindices[4];

        yj = (double) j * y[1] + y[0];
        yjp1 = (double) (j + 1) * y[1] + y[0];

        if (coordinateMask  & 0x2)
        {
            if (logMask & 0x2)
            {
                yj = DecompositionUtils::getLog10Value(yj);
                yjp1 = DecompositionUtils::getLog10Value(yjp1);
            }
        }

        ycoords[0] = yj;
        ycoords[1] = yj;
        ycoords[2] = yjp1;
        ycoords[3] = yjp1;

        yindices[0] = j;
        yindices[1] = j;
        yindices[2] = j + 1;
        yindices[3] = j + 1;

        for (int i = 0; i < numX - 1; i++)
        {
            double xcoords[4];
            int xindices[4];

            xi = (double) i * x[1] + x[0];
            xip1 = (double) (i + 1) * x[1] + x[0];

            if (logMask & 0x1)
            {
                xi = DecompositionUtils::getLog10Value(xi);
                xip1 = DecompositionUtils::getLog10Value(xip1);
            }

            xcoords[0] = xi;
            xcoords[1] = xip1;
            xcoords[2] = xi;
            xcoords[3] = xip1;

            xindices[0] = i;
            xindices[1] = i + 1;
            xindices[2] = i;
            xindices[3] = i + 1;

            for (int k = 0; k < 4; k++)
            {
                if (coordinateMask & 0x1)
                {
                    buffer[bufferOffset] = (float)(xcoords[k] * scale[0] + translation[0]);
                }

                if (coordinateMask  & 0x2)
                {
                    buffer[bufferOffset + 1] = (float)(ycoords[k] * scale[1] + translation[1]);
                }

                if (coordinateMask & 0x4)
                {
                    zij = getZCoordinate(z, numX, numY, xindices[k], yindices[k], logMask & 0x4);
                    buffer[bufferOffset + 2] = (float)(zij * scale[2] + translation[2]);
                }

                if (elementsSize == 4 && (coordinateMask & 0x8))
                {
                    buffer[bufferOffset + 3] = 1.0;
                }

                bufferOffset += elementsSize;
            }

        }
    }

#endif
}
Exemplo n.º 8
0
void FileGraphics::initializeGL()
{
    if (fcontroller->isOpenedFile())
    {
        int rows, cols;
        DemInterface* demObject = fcontroller->getDemObject();
        cols = demObject->getCols();
        rows = demObject->getRows();
        int centerX = cols/2;
        float posX, posY = 0;
        scale = (float)getSize().width() / (float)cols;
        int centerY = rows/2;
        ColorRGBA color;
        std::vector<float> band_data = demObject->readDem();
        maxZ = demObject->maxHeight();
        int step = demObject->getZoom();

        for (int k = 0; k < rows; k=k+step) {
            posY = (float)(centerY - k)/centerY;
            for (int j =0; j < cols; j=j+step) {

                posX = (float)(j - centerX)/centerX;
                if (k < rows -step && j-step >= 0) {
                    color = colorController->getColor(band_data[k*rows + j]);
                    addVertex(
                                Vertex(
                                    QVector3D(posX, posY, getZCoordinate(band_data[k*rows + j])),
                                    QVector3D(color.r, color.g, color.b)
                                )
                            );

                    float nposY = (float)(centerY - (k +step))/centerY;
                    color = colorController->getColor(band_data[(k+step)*rows + j]);
                    addVertex(
                                Vertex(
                                    QVector3D(posX, nposY, getZCoordinate(band_data[(k+step)*rows + j])),
                                    QVector3D(color.r, color.g, color.b)
                                )
                            );

                    float nposX = (float)(j - step - centerX)/centerX;
                    color = colorController->getColor(band_data[k*rows + j - step]);
                    addVertex(
                                Vertex(
                                    QVector3D(nposX, posY, getZCoordinate(band_data[k*rows + j - step])),
                                    QVector3D(color.r, color.g, color.b)
                                )
                            );
                }
                if (k - step >= 0 && j < cols -step) {
                    color = colorController->getColor(band_data[k*rows + j]);
                    addVertex(
                                Vertex(
                                    QVector3D(posX, posY, getZCoordinate(band_data[k*rows + j])),
                                    QVector3D(color.r, color.g, color.b)
                                )
                            );

                    float nposY = (float)(centerY - (k -step))/centerY;
                    color = colorController->getColor(band_data[(k-step)*rows + j]);
                    addVertex(
                                Vertex(
                                    QVector3D(posX, nposY, getZCoordinate(band_data[(k-step)*rows + j])),
                                    QVector3D(color.r, color.g, color.b)
                                )
                            );

                    float nposX = (float)(j +step - centerX)/centerX;
                    color = colorController->getColor(band_data[k*rows + j+step]);
                    addVertex(
                                Vertex(
                                    QVector3D(nposX, posY, getZCoordinate(band_data[k*rows + j+step])),
                                    QVector3D(color.r, color.g, color.b)
                                )
                            );
                }

            }
        }
        bsController->generateBaseSupport();
    }
}