标签 Lidar 下的文章

上回能在picturebox显示点集了~为了让这些点集更为形象,我将他们用三维的方式显示了出来~

先看看效果图吧:

面状:

5b6da0251b1b4f06c99559b5

点状:

c1147ec98c385f227e3e6fb7

用的是DirectX渲染的,较为简单。

下面就来说一下原理吧,其实很简单,就是根据上步的点集三维坐标(X,Y,Z)来绘制,用到的就是MicroSoft.DirectX的类库,大家想做三维显示的不妨可以试试,并不难,至于核心的显示算法这里就不向大家公布了。

上回获取完头文件信息了~这回该绘图了~

我们将LAS的文件用C#的GDI+绘制到picturebox里,当然用BITMAP类型了~首先当然要获取LAS文件的头文件信息啦~有宽,高,点等。

map = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                map.MakeTransparent();

                Color color = new Color();

                for (int n = 0; n < point_X.Count; n++)
                {
                    int ex = (int)px[n] - (int)pic_x_min;
                    int ey = (int)py[n] - (int)pic_y_min;
                    int e_view = p_view[n];

                    if (method == 1)//Intensity,绘制利用点的INTENSITY属性来分类
                    {
                        if (e_view >= 0 && e_view < 20)
                        {
                            color = Color.Gray;
                        }
                        else if (e_view >= 20 && e_view < 40)
                        {
                            color = Color.Blue;
                        }
                        else if (e_view >= 40 && e_view < 60)
                        {
                            color = Color.Green;
                        }
                        else if (e_view >= 60 && e_view < 80)
                        {
                            color = Color.Red;
                        }
                        else
                        {
                            color = Color.Yellow;
                        }
                    }

               }

 

效果图:

b42036244e4df35335a80ff4

上节说到读取点的全部信息,那么头文件的信息呢?

LASReader lasreader = new LASReader(fname);
LASPoint laspoint;
LASHeader lasheader = lasreader.GetHeader();

double x_max = lasheader.GetMaxX();
double x_min = lasheader.GetMinX();
double y_max = lasheader.GetMaxY();
double y_min = lasheader.GetMinY();
double z_max = lasheader.GetMaxZ();
double z_min = lasheader.GetMinZ();
string filesignature = lasheader.FileSignature;
string softwareid = lasheader.SoftwareId;
string version = lasheader.VersionMajor.ToString() + "." + lasheader.VersionMinor.ToString();
int headersize = lasheader.HeaderSize;
string createyear = lasheader.CreationYear.ToString();
double x_offset = lasheader.GetOffsetX();
double y_offset = lasheader.GetOffsetY();
double z_offset = lasheader.GetOffsetZ();

txt_info.AppendText("LAS Info");
txt_info.AppendText("\r\
");
txt_info.AppendText("File name:" + fname);
txt_info.AppendText("\r\
");
txt_info.AppendText("Version: " + version);
txt_info.AppendText("\r\
");
txt_info.AppendText("Create Year: " + createyear);
txt_info.AppendText("\r\
");
txt_info.AppendText("Header Size: " + headersize);
txt_info.AppendText("\r\
");
txt_info.AppendText("ProjectId: " + lasheader.ProjectId);
txt_info.AppendText("\r\
");
txt_info.AppendText("Number of Points: " + lasheader.PointRecordsCount.ToString());          txt_info.AppendText("\r\
");
txt_info.AppendText("Number of Points by Return1: " + lasheader.GetPointRecordsByReturnCount(0));
txt_info.AppendText("\r\
");
txt_info.AppendText("Number of Points by Return2: " + lasheader.GetPointRecordsByReturnCount(1));
txt_info.AppendText("\r\
");
txt_info.AppendText("Number of Points by Return3: " + lasheader.GetPointRecordsByReturnCount(2));
txt_info.AppendText("\r\
");
txt_info.AppendText("Number of Points by Return4: " + lasheader.GetPointRecordsByReturnCount(3));
txt_info.AppendText("\r\
");
txt_info.AppendText("Number of Points by Return5: " + lasheader.GetPointRecordsByReturnCount(4));
txt_info.AppendText("\r\
");
txt_info.AppendText("X Min: " + x_min);
txt_info.AppendText("\r\
");
txt_info.AppendText("X Max: " + x_max);
txt_info.AppendText("\r\
");
txt_info.AppendText("Y Min: " + y_min);
txt_info.AppendText("\r\
");
txt_info.AppendText("Y Max: " + y_max);
txt_info.AppendText("\r\
");
txt_info.AppendText("Z Min: " + z_min);
txt_info.AppendText("\r\
");              
txt_info.AppendText("Z Max: " + z_max);
txt_info.AppendText("\r\
");
txt_info.AppendText("X Offset: " + x_offset);
txt_info.AppendText("\r\
");
txt_info.AppendText("Y Offset: " + y_offset);
txt_info.AppendText("\r\
");
txt_info.AppendText("Z Offset: " + z_offset);
txt_info.AppendText("\r\
");
txt_info.AppendText("X Scale Factor: " + lasheader.GetScaleX().ToString());
txt_info.AppendText("\r\
");
txt_info.AppendText("Y Scale Factor: " + lasheader.GetScaleY().ToString());
txt_info.AppendText("\r\
");
txt_info.AppendText("Z Scale Factor: " + lasheader.GetScaleZ().ToString());
txt_info.AppendText("\r\
");

通过上述代码,基本能将所有的头文件信息包含了~截图如下:

a60df82d24e453de8b13992a

下回就该绘制出来这些点了!~哈,敬请期待啦~

上节说到生成了C#的API函数进行调用,那么下面我们就来调用试试吧~哈

LASReader lasreader = new LASReader(fname);
                    LASPoint laspoint;

                    LASHeader lasheader = lasreader.GetHeader();
                     int point_no = 0;
                    StreamWriter sw = new StreamWriter(savefname);
                    sw.WriteLine("File Name: " + fname);
                     while (lasreader.GetNextPoint())
                      {
                            point_no += 1;
                            laspoint = lasreader.GetPoint();
                            sw.WriteLine("Point NO." + point_no + " X=" + laspoint.X + ", Y=" + laspoint.Y + ", Z=" + laspoint.Z + " Intensity=" + laspoint.Intensity.ToString()
                                + " ReturnNumber=" + laspoint.ReturnNumber + " NumberofReturns=" + laspoint.NumberOfReturns + " ScanDirectionFlag=" + laspoint.ScanDirection
                                + " EdgeofFlightLine=" + laspoint.FlightLineEdge + " Classification=" + laspoint.Classification + " ScanAngleRank=" + laspoint.ScanAngleRank
                                + " UserData=" + laspoint.UserData);
                       }

 

通过这段代码,就能将所有点的信息导出成txt的文件了,用UltraEdit查看的结果:

 847ca3f54e8831dd7709d75c

哈,后面的classification和userdata就省了~下次将头文件的信息获取出来!~

因为最近帮师兄研究激光雷达的las文件的格式,所以写写心得啦~

首先自己先从官网下http://liblas.org了个dotnetliblas的项目文件,编译为C#可用的类库~

当然采用了DllImport的方法定义了EXTERNAL函数。

12fda6f6dba86110700eec69

图为函数体的结构,建个工程就能读取las文件和写las文件了。

C#还是很强大的~哈哈,不久再发发我做的一个DEMO的一些源码~

鉴于有些人说官网的没提供dll下载了,我这里上传下吧我的测试工程文件,VS2010编译。

在引用中只需要添加dotnetLibLAS.dll,liblas1.dll是c++的DLL,这里无需引用。

using LibLAS;

就可以调用函数咯,如:

using LibLAS;
LASReader lasreader = new LASReader(@"line1.las");
//LASPoint laspoint;
LASHeader lasheader = lasreader.GetHeader();
double x_max = lasheader.GetMaxX();
double x_min = lasheader.GetMinX();

dll下载:http://pan.baidu.com/s/13OZin