Kriging 算法实现 2维和3维地图等高线

时间:2009-03-15 02:52:39
【文件属性】:

文件名称:Kriging 算法实现 2维和3维地图等高线

文件大小:163KB

文件格式:RAR

更新时间:2009-03-15 02:52:39

图形处理类 控件 源码 资源

A year and a half year ago, I published this article to the Codeguru site and got a number of requests about the Kriging algorithm contour map. Unfortunately, my project was changed shortly after that article and later I quit the company so I couldn‘t find time to finish this Contour business. A week ago, I happened to need a contour map again so I decided to solve the Kriging algorithm. I searched the Internet for a commercial library but they all look ugly and hard to use. So, I made up my mind to make my own algorithm. The Kriging algorithm is easy to find, but this algorithm needs a Matrix and solver (LU-Decomposition). Again, I couldn‘t find suitable code for this. I tried to use GSL first but this made my code too big and was slower. Finally, I went back to "Numerical Recipe in C"—yes, that horrible-looking C code—and changed the code there to my taste.If you read this article before, the rendering part hasn‘t been changed much. I added the Kriging algorithm and revised the codes a little bit. Following is the Kriging Algorithm:templatedouble GetDistance(const ForwardIterator start, int i, int j){ return ::sqrt(::pow(((*(start+i)).x - (*(start+j)).x), 2) + ::pow(((*(start+i)).y - (*(start+j)).y), 2));}templatedouble GetDistance(double xpos, double ypos, const ForwardIterator start, int i){ return ::sqrt(::pow(((*(start+i)).x - xpos), 2) + ::pow(((*(start+i)).y - ypos), 2));}templateclass TKriging : public TInterpolater{public: TKriging(const ForwardIterator first, const ForwardIterator last, double dSemivariance) : m_dSemivariance(dSemivariance) { m_nSize = 0; ForwardIterator start = first; while(start != last) { ++m_nSize; ++start; } m_matA.SetDimension(m_nSize, m_nSize); for(int j=0; j vecB(m_nSize); for(int i=0; i m_matA; vector m_Permutation; int m_nSize; double m_dSemivariance;};typedef TKriging Kriging;Because of the template, this doesn‘t look that clean but you can get the idea if you look at it carefully. The matrix solver is as follows:templatevoid LUDecompose(TMatrix& A, std::vector& Permutation, int& d) throw(NumericException){ int n = A.GetHeight(); vector vv(n); Permutation.resize(n); d=1; T amax; for(int i=0; i amax) amax = fabs(A(i, j)); if(amax < TINY_VALUE) throw NumericException(); vv[i] = 1.0 / amax; } T sum, dum; int imax; for(int j=0; j= amax) { imax = i; amax = dum; } } if(j != imax) { for(int k=0; kvoid LUBackSub(TMatrix& A, std::vector& Permutation, std::vector& B) throw(NumericException){ int n = A.GetHeight(); T sum; int ii = 0; int ll; for(int i=0; i=0; i--) { sum = B[i]; if(i< n) { for(int j=i+1; j input // assume this vector has KNOWN 3D points Interpolater* pInterpolater = new Kriging(input.begin(), input.end(), 4); vector vecZs; for(int j=0; j<200; j++) { for(int i=0; i<200; i++) { vecZs.push_back(pInterpolater->GetInterpolatedZ(i, j, input.begin(), input.end())); } } // Now, vecZs has 40000 z values delete pInterpolater;If you have all the grid points with 3D data, you can make a bitmap file with it, or make a triangle strip to render with OpenGL. If you remember that the old contour map was produced from an InverseDistanced algorithm (you can switch to Inverse Distance in the Option menu), you‘ll find a vast improvement over it. I compared the Kriging generated contour map with some commercial programs, and they were almost identical. I hope this helps programmers who want to make a contour map.


【文件预览】:
WaferPainter(Kriging 算法的 2维和3维地图等高线)
----WaferPainter()
--------WaferPainter.reg(722B)
--------TestSite.txt(1KB)
--------GLSurfaceView.cpp(5KB)
--------3DGrapher.cpp(6KB)
--------resource.h(2KB)
--------3DContourDoc.h(1KB)
--------ChildFrm.cpp(2KB)
--------WaferPainter.h(1KB)
--------WaferPainter.rc(20KB)
--------WaferPainterDoc.h(2KB)
--------WaferPainter.aps(57KB)
--------WaferPainterView.h(2KB)
--------WaferPainter.dsp(7KB)
--------GLSurfaceView.h(2KB)
--------ContourView.cpp(9KB)
--------WaferPainter.clw(8KB)
--------OptionDlg.cpp(1KB)
--------ContourDoc.cpp(2KB)
--------WaferPainter.cpp(5KB)
--------3DData.h(2KB)
--------BaseData.h(895B)
--------ContourDoc.h(1KB)
--------WaferPainter.ncb(537KB)
--------WaferPainter.dsw(549B)
--------WaferPainter.opt(56KB)
--------WaferPainter.plg(1KB)
--------WaferPainterView.cpp(3KB)
--------Matrix.h(7KB)
--------Dib.h(2KB)
--------3DContourView.h(2KB)
--------res()
--------testdata.txt(778B)
--------Grapher.h(825B)
--------WaferPainterDoc.cpp(3KB)
--------InputReader.cpp(977B)
--------Dib.cpp(9KB)
--------MainFrm.h(1KB)
--------InputReader.h(856B)
--------OptionDlg.h(1KB)
--------3DGrapher.h(4KB)
--------3DContourDoc.cpp(2KB)
--------InverseDist.h(2KB)
--------StdAfx.cpp(214B)
--------Numeric.h(2KB)
--------BaseException.h(1KB)
--------InCell1.txt(257B)
--------3DContourView.cpp(8KB)
--------ChildFrm.h(1KB)
--------Interpolater.h(1KB)
--------MainFrm.cpp(4KB)
--------Kriging.h(2KB)
--------Image.h(2KB)
--------Surfer.h(1KB)
--------StdAfx.h(997B)
--------ContourView.h(2KB)
--------Surfer.cpp(10KB)

网友评论

  • 虽然比较难读懂,但基于此代码实现了自己的kriging,感谢分享!
  • 不管怎么样,能够帮助到我的就是好的
  • 内注释。。。太难理解了
  • 没啥用,一堆代码,可读性很差
  • 代码没有注释,读起来比较难
  • 代码挺好,只是一模一样的资源很多,且代码没有注释,读起来比较难
  • 完全没有用
  • VS2010编译不过
  • 代码不错,就是没注释,看起来吃力
  • 有错误,新手看懂有难度呀
  • 还在学习中,就是没注释
  • 可以用,建议下载,适合初学者
  • 代码非常好,效果也很好
  • 没注释,代码难
  • 谢谢lz分享,导入vs2008存在问题,未运行成功。
  • 代码还好,就是没注释,需要研究一下
  • 编译出错啊,“TKriging<T,ForwardIterator>::TKriging(const ForwardIterator,const ForwardIterator,double)” : 不能将参数 1 从“std::vector<_Ty>::iterator”转换为“TPoint3D<T> ”
  • 没注释,好坑
  • 代码有点多,还没细看。但是为什么我用03和10编译之后都会出这个错误 45645223\contourview.cpp(122): error C2664: “TKriging<T,ForwardIterator>::TKriging(const ForwardIterator,const ForwardIterator,double)” : 不能将参数 1 从“std::vector<_Ty>::iterator”转换为“TPoint3D<T> ” with [ T=double,
  • 代码有点难度,继续学习。
  • 正在学习这方面的知识 ,谢谢lz分享
  • 用vs2012编译通过,插值的结果和win sufer对比了下,有些点差别很大。 代码有点难度,继续研究
  • 运行结果正确,代码清晰,对学习很有帮助,谢谢楼主分享
  • 正在学习这方面的知识 ,谢谢lz分享,导入vs2008存在问题,未运行成功。
  • 可以运行,不错,谢谢
  • 看了一下,可以运行,结果也是正确的,不知是上传者自己写的呢,还是也在别处下载的,在搜索临近点那块不知道可否再优化一下,全局搜索数据量有点大,还是感谢,感谢分享!
  • qt还得重写,有些麻烦呢
  • 学习了,谢谢楼主,注释再详细点就更好了
  • 运行正常,代码清晰,谢谢楼主分享
  • 写的很详细,学习中用到了。非常感谢