当前位置: 首页>>代码示例>>C++>>正文


C++ Primitive::defineVertex方法代码示例

本文整理汇总了C++中Primitive::defineVertex方法的典型用法代码示例。如果您正苦于以下问题:C++ Primitive::defineVertex方法的具体用法?C++ Primitive::defineVertex怎么用?C++ Primitive::defineVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Primitive的用法示例。


在下文中一共展示了Primitive::defineVertex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: constructFull

// Construct full surface representation of data
void Surface::constructFull(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();

	// Check for specific actions when we have a low number of display datasets
	if (nZ == 1)
	{
		// Special case, if there is exactly one dataset, draw a standard XY line surface instead
		constructLineXY(primitiveList, axes, displayAbscissa, displayData, colourScale);
		return;
	}
	if (nX == 1)
	{
		// Special case, if there is exactly one dataset, draw a standard XY line surface instead
		constructLineZY(primitiveList, axes, displayAbscissa, displayData, colourScale);
		return;
	}

	// Resize primitive list so it's large enough for our needs
	primitiveList.reinitialise(nZ-1, false, GL_TRIANGLES, true);

	// Temporary variables
	Array< Vec3<double> > normA, normB;
	Array<double> yA, yB, yC;
	Array<DisplayDataSet::DataPointType> typeA, typeB, typeC;
	Array< Vec4<GLfloat> > colourA, colourB;
	QColor colour;
	double zA, zB, zC;
	Vec3<double> nrm(0.0, 1.0, 0.0);

	// Construct first slice data and set initial min/max values
	yA.copy(displayData[minIndex.z]->y(), minIndex.x, maxIndex.x);
	typeA.copy(displayData[minIndex.z]->yType(), minIndex.x, maxIndex.x);
	axes.transformY(yA, typeA);
	zA = axes.transformZ(displayData[minIndex.z]->z());
	if ((minIndex.z+1) <= maxIndex.z)	// Safety check - this should always be true because of the checks above
	{
		yB.copy(displayData[minIndex.z+1]->y(), minIndex.x, maxIndex.x);
		typeB.copy(displayData[minIndex.z+1]->yType(), minIndex.x, maxIndex.x);
		axes.transformY(yB, typeB);
		zB = axes.transformZ(displayData[minIndex.z+1]->z());
	}
	constructSurfaceStrip(x, yA, zA, axes, normA, colourA, colourScale, yC, 0.0, yB, zB);

	// Create triangles in strips between the previous and target Y/Z values
	int nBit, nPlusOneBit, totalBit;
	int vertexAn = -1, vertexBn = -1, vertexAnPlusOne = -1, vertexBnPlusOne = -1;
	Primitive* currentPrimitive = primitiveList[0];
	for (int index = minIndex.z+1; index <=maxIndex.z; ++index)
	{
		// Grab next data (if we are not at the end of the index range)
		if (index < maxIndex.z)
		{
			yC.copy(displayData[index+1]->y(), minIndex.x, maxIndex.x);
			typeC.copy(displayData[index+1]->yType(), minIndex.x, maxIndex.x);
			axes.transformY(yC, typeC);
			zC = axes.transformZ(displayData[index+1]->z());
		}
		else yC.clear();

		// Construct data for current slice
		constructSurfaceStrip(x, yB, zB, axes, normB, colourB, colourScale, yA, zA, yC, zC);

		// Use a simple bit to quickly determine which triangles to draw, given possible lack of datapoints in slices
		//
		//			n	n+1	n	n+1
		//	Slice A		4-------1	4-------1	0 = Both	5 = None
		//			| ....TR|	|TL.... |	1 = BL		6 = None
		//			|   ....|	|....   |	2 = TL		7 = None
		//			|BL   ..|	|..   BR|	3 = None	8 = TR
		//	Slice B		8-------2	8-------2	4 = BR		9+= None

		// Set initial bit, and generate initial vertices
		nBit = 0;
		if (typeA.value(0) == DisplayDataSet::NoPoint)
		{
			nBit += 4;
			vertexAn = -1;
		}
		else vertexAn = currentPrimitive->defineVertex(x.value(0), yA.value(0), zA, normA[0], colourA[0]);
		if (typeB.value(0) == DisplayDataSet::NoPoint)
		{
			nBit += 8;
			vertexBn = -1;
		}
		else vertexBn = currentPrimitive->defineVertex(x.value(0), yB.value(0), zB, normB[0], colourB[0]);

		for (int n=0; n<nX-1; ++n)
//.........这里部分代码省略.........
开发者ID:trisyoungs,项目名称:uchroma,代码行数:101,代码来源:surface_full.cpp

示例2: constructGrid

// 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;
    }
}
开发者ID:trisyoungs,项目名称:uchroma,代码行数:93,代码来源:surface_grid.cpp


注:本文中的Primitive::defineVertex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。