/// <summary> /// 生成基质的纹理映射坐标 /// </summary> /// <param name="src"></param> /// <param name="gridIndexes"></param> /// <param name="values"></param> /// <param name="minValue"></param> /// <param name="maxValue"></param> /// <returns></returns> protected unsafe TexCoordBuffer DoCreateMatrixTextureCoordinates(DynamicUnstructuredGridderSource src, int[] gridIndexes, float[] values, float minValue, float maxValue) { int matrixStartIndex = src.FractureNum; int matrixEndIndex = src.DimenSize - 1; int[] invisibles = src.BindResultsAndActiveMatrix(gridIndexes); float[] textures = new float[src.InvisibleMatrixTextures.Length]; Array.Copy(src.InvisibleMatrixTextures, textures, textures.Length); for (int mixedIndex = 0; mixedIndex < gridIndexes.Length; mixedIndex++) { int gridIndex = gridIndexes[mixedIndex]; if (gridIndex >= matrixStartIndex && gridIndex < src.DimenSize) { float value = values[mixedIndex]; if (value < minValue) value = minValue; if (value > maxValue) value = maxValue; int matrixIndex = gridIndex - matrixStartIndex; if (invisibles[matrixIndex] > 0) { float distance = maxValue - minValue; if (!(distance <= 0.0f)) { textures[matrixIndex] = (value - minValue) / distance; if (textures[matrixIndex] < 0.5f) { textures[matrixIndex] = 0.5f - (0.5f - textures[matrixIndex]) * 0.99f; } else { textures[matrixIndex] = (textures[matrixIndex] - 0.5f) * 0.99f + 0.5f; } } else { //最小值最大值相等时,显示最小值的颜色 textures[matrixIndex] = 0.01f; //textures[gridIndex] = 0; } } } }//end for //TextureCoordinatesBuffer textureCoordinates = new TextureCoordinatesBufferData(); TexCoordBuffer textureCoordinates = null; if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT3_TRIANGLE) { textureCoordinates = new TriangleMatrixTexCoordBuffer(); //textureCoordinates.AllocMem(texturesCount * sizeof(TriangleUV)); textureCoordinates.AllocMem(textures.Length); TriangleTexCoord* pTextures = (TriangleTexCoord*)textureCoordinates.Data; for (int i = 0; i < textures.Length; i++) { pTextures[i].SetTextureCoord(textures[i]); } } if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT4_TETRAHEDRON) { textureCoordinates = new TetrahedronMatrixTexCoordBuffer(); //textureCoordinates.AllocMem(texturesCount * sizeof(TetrahedronUV)); textureCoordinates.AllocMem(textures.Length); TetrahedronTexCoord* pTextures = (TetrahedronTexCoord*)textureCoordinates.Data; for (int i = 0; i < textures.Length; i++) { pTextures[i].SetTextureCoord(textures[i]); } } if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT6_TRIANGULAR_PRISM) { textureCoordinates = new TriangularPrismMatrixTexCoordBuffer(); textureCoordinates.AllocMem(textures.Length); TriangularPrismTexCoord* pTextures = (TriangularPrismTexCoord*)textureCoordinates.Data; for (int i = 0; i < textures.Length; i++) { pTextures[i].SetTextureCoord(textures[i]); } } return textureCoordinates; }
/// <summary> /// 生成基质的纹理映射坐标 /// </summary> /// <param name="src"></param> /// <param name="gridIndexes"></param> /// <param name="values"></param> /// <param name="minValue"></param> /// <param name="maxValue"></param> /// <returns></returns> protected unsafe TexCoordBuffer DoCreateMatrixTextureCoordinates(DynamicUnstructuredGridderSource src, int[] gridIndexes, float[] values, float minValue, float maxValue) { int matrixStartIndex = src.FractureNum; int matrixEndIndex = src.DimenSize - 1; int[] textureVisibles = src.BindTextureVisibleMatrix(gridIndexes); float[] textures = new float[src.InvisibleMatrixTextures.Length]; Array.Copy(src.InvisibleMatrixTextures, textures, textures.Length); for (int mixedIndex = 0; mixedIndex < gridIndexes.Length; mixedIndex++) { int gridIndex = gridIndexes[mixedIndex]; int[] mapBlockIndexes = src.MapBlockIndexes(gridIndex); for (int j = 0; j < mapBlockIndexes.Length; j++) { int blockIndex = mapBlockIndexes[j]; if (blockIndex >= matrixStartIndex && blockIndex < src.DimenSize) { float value = values[mixedIndex]; if (value < minValue) { value = minValue; } if (value > maxValue) { value = maxValue; } int matrixIndex = blockIndex - matrixStartIndex; if (textureVisibles[matrixIndex] > 0) { float distance = maxValue - minValue; if (!(distance <= 0.0f)) { textures[matrixIndex] = (value - minValue) / distance; if (textures[matrixIndex] < 0.5f) { textures[matrixIndex] = 0.5f - (0.5f - textures[matrixIndex]) * 0.99f; } else { textures[matrixIndex] = (textures[matrixIndex] - 0.5f) * 0.99f + 0.5f; } } else { //最小值最大值相等时,显示最小值的颜色 textures[matrixIndex] = 0.01f; //textures[gridIndex] = 0; } } } } }//end for //TextureCoordinatesBuffer textureCoordinates = new TextureCoordinatesBufferData(); TexCoordBuffer textureCoordinates = null; if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT3_TRIANGLE) { textureCoordinates = new TriangleMatrixTexCoordBuffer(); //textureCoordinates.AllocMem(texturesCount * sizeof(TriangleUV)); textureCoordinates.AllocMem(textures.Length); TriangleTexCoord *pTextures = (TriangleTexCoord *)textureCoordinates.Data; for (int i = 0; i < textures.Length; i++) { pTextures[i].SetTextureCoord(textures[i]); } } if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT4_TETRAHEDRON) { textureCoordinates = new TetrahedronMatrixTexCoordBuffer(); //textureCoordinates.AllocMem(texturesCount * sizeof(TetrahedronUV)); textureCoordinates.AllocMem(textures.Length); TetrahedronTexCoord *pTextures = (TetrahedronTexCoord *)textureCoordinates.Data; for (int i = 0; i < textures.Length; i++) { pTextures[i].SetTextureCoord(textures[i]); } } if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT6_TRIANGULAR_PRISM) { textureCoordinates = new TriangularPrismMatrixTexCoordBuffer(); textureCoordinates.AllocMem(textures.Length); TriangularPrismTexCoord *pTextures = (TriangularPrismTexCoord *)textureCoordinates.Data; for (int i = 0; i < textures.Length; i++) { pTextures[i].SetTextureCoord(textures[i]); } } return(textureCoordinates); }