/// <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); }
protected unsafe TexCoordBuffer DoCreateFractureTextureCoordinates(DynamicUnstructuredGridderSource src, int[] gridIndexes, float[] values, float minValue, float maxValue) { int fractureStartIndex = 0; int fractureEndIndex = src.FractureNum - 1; int[] invisibles = src.BindResultsAndActiveFractures(gridIndexes); float[] textures = new float[src.InvisibleFractureTextures.Length]; Array.Copy(src.InvisibleFractureTextures, 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 >= fractureStartIndex && blockIndex <= fractureEndIndex) { float value = values[mixedIndex]; if (value < minValue) { value = minValue; } if (value > maxValue) { value = maxValue; } int fracIndex = blockIndex; if (invisibles[fracIndex] > 0) { float distance = maxValue - minValue; if (!(distance <= 0.0f)) { textures[fracIndex] = (value - minValue) / distance; if (textures[fracIndex] < 0.5f) { textures[fracIndex] = 0.5f - (0.5f - textures[fracIndex]) * 0.99f; } else { textures[fracIndex] = (textures[fracIndex] - 0.5f) * 0.99f + 0.5f; } } else { //最小值最大值相等时,显示最小值的颜色 textures[fracIndex] = 0.01f; //textures[matrixIndex] = 0.01f; } } } } }//end for //TextureCoordinatesBuffer textureCoordinates = new TextureCoordinatesBufferData(); TexCoordBuffer textureCoordinates = null; int texturesCount = textures.Length; if (src.FractureFormat == DynamicUnstructuredGridderSource.FRACTURE_FORMAT3_TRIANGLE) { textureCoordinates = new TriangleFractureTexCoordBuffer(); textureCoordinates.AllocMem(texturesCount); TriangleTexCoord *pTextures = (TriangleTexCoord *)textureCoordinates.Data; for (int i = 0; i < texturesCount; i++) { pTextures[i].SetTextureCoord(textures[i]); } } if (src.FractureFormat == DynamicUnstructuredGridderSource.FRACTURE_FORMAT2_LINE) { textureCoordinates = new LineFractureTexCoordBufer(); textureCoordinates.AllocMem(texturesCount); LineTexCoord *pTextures = (LineTexCoord *)textureCoordinates.Data; for (int i = 0; i < textures.Length; i++) { pTextures[i].SetTextureCoord(textures[i]); } } if (src.FractureFormat == DynamicUnstructuredGridderSource.FRACTURE_FORMAT4_QUAD) { textureCoordinates = new QuadFractureTexCoordBuffer(); textureCoordinates.AllocMem(texturesCount); QuadTexCoord *pTextures = (QuadTexCoord *)textureCoordinates.Data; for (int i = 0; i < textures.Length; i++) { pTextures[i].SetTextureCoord(textures[i]); } } return(textureCoordinates); }