[英]3D mesh surface
I have the following code to show my senor data in 2D interpolated color map. 我有以下代码在2D插值颜色图中显示我的传感器数据。 However, I would like to transform it into a 3D mesh surface. 但是,我想将其转换为3D网格表面。 I can only find some complicated methods to do that. 我只能找到一些复杂的方法来做到这一点。 But what I am thinking is an easier way which can pull the 2D color map to a higher level according to its different colors on each data array to make the 2D bitmap like 3D 但是我想的是一种更简单的方法,它可以根据每个数据阵列上的不同颜色将2D颜色图拉到更高的层次,以使2D位图像3D
Bitmap bmp3 = new Bitmap(PicBoxChi.Width, PicBoxChi.Height);
using (Graphics g = Graphics.FromImage(bmp3))
{
// this loop create a 6X4 map to show my sensor data
for (int a = 0; a < 6; a++)
{
for (int b = 0; b < 4; b++)
{
pts[a, b] = new PointC(new PointF(x0 + b*width, y0 + a*height), data[a*4+b+48] );
}
}
int colorLength = cmap.GetLength(0);
// Bilinear interpolation:
// this loop transfer my 6x4 sensor data map to a color map
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
{
PointF[] pta = new PointF[4]{pts[i,j].pointf, pts[i+1,j].pointf,
pts[i+1,j+1].pointf, pts[i,j+1].pointf};
float[] cdata = new float[4]{pts[i,j].C,pts[i+1,j].C,
pts[i+1,j+1].C,pts[i,j+1].C};
Interp(g, pta, cdata, 50);
}
}
}
I can now create the 2D color bitmap by above code. 我现在可以通过上面的代码创建2D颜色位图。 But I have no idea to make the 3D one as shown in figure. 但是我不知道如何使3D如图所示。
If the pixel colors are in RGB format, from the provided picture I can infer that what you are interested in is the pure Hue of the color. 如果像素颜色为RGB格式,则可以从提供的图片中推断出您感兴趣的是该颜色的纯色相。
To get a standard [0, 360] ranged hue value from RGB you can do like this : 为了得到一个标准的[0,360]范围从RGB色调值就可以像这样 :
System.Drawing.Color color = System.Drawing.Color.FromArgb(red, green, blue);
float hue = color.GetHue();
or a more customizable approach ( here in Java , reporting it here too): 或更可定制的方法( 在Java中 ,也在此处报告):
public int getHue(int red, int green, int blue) {
float min = Math.min(Math.min(red, green), blue);
float max = Math.max(Math.max(red, green), blue);
float hue = 0f;
if (max == red) {
hue = (green - blue) / (max - min);
} else if (max == green) {
hue = 2f + (blue - red) / (max - min);
} else {
hue = 4f + (red - green) / (max - min);
}
hue = hue * 60;
if (hue < 0) hue = hue + 360;
return Math.round(hue);
}
You can then simply use the resulting value as the height of the corresponding vertex, optionally fine-tuning it by dividing/multiplying it by some constant. 然后,您可以简单地将结果值用作相应顶点的高度,可以选择通过将其除以/乘以某个常数来对其进行微调。
Generating the 3D mesh is relatively simple and i think you already have the code in place, here's a pseudocode anyway: 生成3D网格相对简单,我想您已经准备好了代码,无论如何这是一个伪代码:
float getHeight(img img, int x, int y) {
float scalefactor = 1.0/360; //any value you like
return getHue(getRgbColorFromImage(img, x, y)) * scalefactor;
}
int x=0, y=0;
for (y=0; y<imageHeight-1; y++) {
for (x=0; x<imageWidth-1; x++) {
new quad = [x, y, getHeight(img, x, y),
x+1, y, getHeight(img, x+1, y),
x, y+1, getHeight(img, x, y+1),
x+1, y+1, getHeight(img, x+1, y+1)];
}
}
if you want triangles: 如果要三角形:
new triangle = [x, y, getHeight(img, x, y),
x+1, y, getHeight(img, x+1, y),
x, y+1, getHeight(img, x, y+1)];
new triangle = [x+1, y, getHeight(img, x+1, y),
x, y+1, getHeight(img, x, y+1),
x+1, y+1, getHeight(img, x+1, y+1)];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.