Beispiel #1
0
// Construct grid surface representation of data
void Surface::constructGrid(PrimitiveList& primitiveList, const Axes& axes, const Array<double>& displayAbscissa, List<DisplayDataSet>& displayData, ColourScale colourScale)
{
    // Forget all data in current primitives
    primitiveList.forgetAll();

    // Get extents of displayData to use based on current axes limits
    Vec3<int> minIndex, maxIndex;
    if (!calculateExtents(axes, displayAbscissa, displayData, minIndex, maxIndex)) return;
    int nZ = (maxIndex.z - minIndex.z) + 1;

    // Copy and transform abscissa values (still in data space) into axes coordinates
    Array<double> x(displayAbscissa, minIndex.x, maxIndex.x);
    axes.transformX(x);
    int nX = x.nItems();
    if (nX < 2) return;

    // Decide how large to make VertexChunks in Primitives
    // We will consider multiple slices at once in order to take most advantage of the post-transform cache
    // forming (abscissa.nItems()/(cacheSize-1)+1) Primitives (we divide by (cacheSize-1) because we will force an overlap
    // of one gridpoint between adjacent strips).
    const int cacheSize = 12;
    int nPrimitives = x.nItems()/(cacheSize-1) + 1;

    // Get some values from axes so we can calculate colours properly
    bool yLogarithmic = axes.logarithmic(1);
    double yStretch = axes.stretch(1);

    // Reinitialise primitive list
    primitiveList.reinitialise(nPrimitives, true, GL_LINES, true);

    // Temporary variables
    int n, offset = 0, i, nLimit, nMax;
    Vec4<GLfloat> colour;
    Vec3<double> nrm(0.0, 1.0, 0.0);
    Array<double> y;
    Array<DisplayDataSet::DataPointType> yType;

    DisplayDataSet** slices = displayData.array();
    Primitive* currentPrimitive = primitiveList[0];
    int verticesA[cacheSize], verticesB[cacheSize];
    double z;

    // Loop over abscissa indices
    while (offset <= x.nItems())
    {
        // Set nLimit to ensure we don't go beyond the end of the data arrays
        nLimit = std::min(cacheSize, x.nItems()-offset);

        // Loop over remaining displayData
        for (int slice = minIndex.z; slice <= maxIndex.z; ++slice)
        {
            // Grab arrays
            y.copy(slices[slice]->y(), minIndex.x+offset, minIndex.x+offset+nLimit-1);
            yType.copy(slices[slice]->yType(), minIndex.x+offset, minIndex.x+offset+nLimit-1);
            axes.transformY(y, yType);
            z = axes.transformZ(slices[slice]->z());

            // Generate vertices for this row
            for (n=0; n<nLimit; ++n)
            {
                i = offset+n;
                if (yType.value(n) != DisplayDataSet::NoPoint)
                {
                    // A value exists here, so define a vertex
                    colourScale.colour(yLogarithmic ? pow(10.0, y.value(n) / yStretch) : y.value(n) / yStretch, colour);
                    verticesB[n] = currentPrimitive->defineVertex(x.value(i), y.value(n), z, nrm, colour);

                    // If the previous vertex on this row also exists, draw a line here
                    if ((n != 0) && (verticesB[n-1] != -1)) currentPrimitive->defineIndices(verticesB[n-1], verticesB[n]);
                }
                else verticesB[n] = -1;
            }

            // Draw lines across slices (if slice != 0)
            if (slice != 0)
            {
                nMax = (maxIndex.z-slice) > 1 ? nLimit-1 : nLimit;
                for (n=0; n<nMax; ++n)
                {
                    if ((verticesA[n] != -1) && (verticesB[n] != -1)) currentPrimitive->defineIndices(verticesA[n], verticesB[n]);
                }
            }

            // Store current vertices for next pass
            for (n=0; n<cacheSize; ++n) verticesA[n] = verticesB[n];
        }

        // Move to next primitive and increase offset
        currentPrimitive = currentPrimitive->next;
        offset += cacheSize-1;
    }
}
Beispiel #2
0
// Write AxisBlock keywords
bool UChromaSession::writeAxisBlock(LineParser& parser, Axes& axes, int axis)
{
	parser.writeLineF("    %s %i\n", UChromaSession::viewPaneKeyword(UChromaSession::AxisBlockKeyword), axis);
	parser.writeLineF("      %s %s\n", UChromaSession::axisKeyword(UChromaSession::AutoScaleKeyword), Axes::autoScaleMethod(axes.autoScale(axis)));
	parser.writeLineF("      %s %s\n", UChromaSession::axisKeyword(UChromaSession::AutoTicksKeyword), stringBool(axes.autoTicks(axis)));
	parser.writeLineF("      %s %f\n", UChromaSession::axisKeyword(UChromaSession::FirstTickKeyword), axes.tickFirst(axis));
	parser.writeLineF("      %s %s\n", UChromaSession::axisKeyword(UChromaSession::FractionalPositioningKeyword), stringBool(axes.positionIsFractional(axis)));
	parser.writeLineF("      %s %s %s %s\n", UChromaSession::axisKeyword(UChromaSession::GridLinesKeyword), stringBool(axes.gridLinesMajor(axis)), stringBool(axes.gridLinesMinor(axis)), stringBool(axes.gridLinesFull(axis)));
	LineStyle style = axes.gridLineMajorStyle(axis);
	parser.writeLineF("      %s %f '%s' %f %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::GridLineMajorStyleKeyword), style.width(), LineStipple::stipple[style.stipple()].name, style.colour().redF(), style.colour().greenF(), style.colour().blueF(), style.colour().alphaF());
	style = axes.gridLineMinorStyle(axis);
	parser.writeLineF("      %s %f '%s' %f %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::GridLineMinorStyleKeyword), style.width(), LineStipple::stipple[style.stipple()].name, style.colour().redF(), style.colour().greenF(), style.colour().blueF(), style.colour().alphaF());
	parser.writeLineF("      %s %s\n", UChromaSession::axisKeyword(UChromaSession::InvertKeyword), stringBool(axes.inverted(axis)));
	parser.writeLineF("      %s %s\n", UChromaSession::axisKeyword(UChromaSession::LabelAnchorKeyword), TextPrimitive::textAnchor(axes.labelAnchor(axis)));
	parser.writeLineF("      %s %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::LabelOrientationKeyword), axes.labelOrientation(axis).x, axes.labelOrientation(axis).y, axes.labelOrientation(axis).z);
	parser.writeLineF("      %s %f %f\n", UChromaSession::axisKeyword(UChromaSession::LimitsKeyword), axes.min(axis), axes.max(axis));
	parser.writeLineF("      %s %s\n", UChromaSession::axisKeyword(UChromaSession::LogarithmicKeyword), stringBool(axes.logarithmic(axis)));
	parser.writeLineF("      %s %i\n", UChromaSession::axisKeyword(UChromaSession::MinorTicksKeyword), axes.minorTicks(axis));
	NumberFormat fmt = axes.numberFormat(axis);
	parser.writeLineF("      %s '%s' %i %s %s\n", UChromaSession::axisKeyword(UChromaSession::NumberFormatKeyword), NumberFormat::formatType(fmt.type()), fmt.nDecimals(), stringBool(fmt.useUpperCaseExponent()), stringBool(fmt.forcePrecedingPlus()));
	parser.writeLineF("      %s %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::PositionFractionalKeyword), axes.positionFractional(axis).x, axes.positionFractional(axis).y, axes.positionFractional(axis).z);
	parser.writeLineF("      %s %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::PositionRealKeyword), axes.positionReal(axis).x, axes.positionReal(axis).y, axes.positionReal(axis).z);
	parser.writeLineF("      %s %f\n", UChromaSession::axisKeyword(UChromaSession::StretchKeyword), axes.stretch(axis));
	parser.writeLineF("      %s %f\n", UChromaSession::axisKeyword(UChromaSession::TickDeltaKeyword), axes.tickDelta(axis));
	parser.writeLineF("      %s %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::TickDirectionKeyword), axes.tickDirection(axis).x, axes.tickDirection(axis).y, axes.tickDirection(axis).z);
	parser.writeLineF("      %s %s\n", UChromaSession::axisKeyword(UChromaSession::TitleAnchorKeyword), TextPrimitive::textAnchor(axes.titleAnchor(axis)));
	parser.writeLine(QString("      ")+UChromaSession::axisKeyword(UChromaSession::TitleKeyword)+" '"+axes.title(axis)+"'\n");
	parser.writeLineF("      %s %f %f %f %f\n", UChromaSession::axisKeyword(UChromaSession::TitleOrientationKeyword), axes.titleOrientation(axis).x, axes.titleOrientation(axis).y, axes.titleOrientation(axis).z, axes.titleOrientation(axis).w);
	parser.writeLineF("      %s %s\n", UChromaSession::axisKeyword(UChromaSession::VisibleAxisKeyword), stringBool(axes.visible(axis)));
	parser.writeLineF("    %s\n", UChromaSession::axisKeyword(UChromaSession::EndAxisKeyword));

	return true;
}