點雲資料
package cn.thu.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class TestN
{
public static void main(String[] args)
{
}
// 返回三個檢視中最近點的列表
public List<List<Point>> compute(List<Point> lstPoints_Red, List<Point> lstPoints_Dark, List<Point> lstPoints_Green)
{
List<List<Point>> llsist = new ArrayList<List<Point>>();
for (int i = 0; i < lstPoints_Red.size(); i++)
{
// 紅色點中的第i個點:pointView0
Point pointView0 = lstPoints_Red.get(i);
// 黑色點中距離pointView0最近的點:pointView1,兩者構成一組資料
Point pointView1 = findNearestPoint(pointView0, lstPoints_Dark);
// 綠色點中距離pointView0、pointView1最近的點,三者構成一組資料
Point pointView2 = findNearestPoint(pointView0, lstPoints_Green);
// 紅色點中第i個點、及其距離最近的黑色、綠色點,三者構成一組資料
List<Point> lstpointV012 = new ArrayList<Point>();
lstpointV012.add(pointView0);
lstpointV012.add(pointView1);
lstpointV012.add(pointView2);
llsist.add(lstpointV012);
}
return llsist;
}
// 給定一個點,得到另一個view裡最近的點
public Point findNearestPoint(Point pointView0, List<Point> lstPointsView1)
{
double vx = pointView0.getX();
double vy = pointView0.getY();
double vz = pointView0.getZ();
Map<String, Point> mapPoint = new HashMap<String, Point>();
Map<String, Double> mapLength = new HashMap<String, Double>();
for (int i = 0; i < lstPointsView1.size(); i++)
{
double x = lstPointsView1.get(i).getX();
double y = lstPointsView1.get(i).getY();
double z = lstPointsView1.get(i).getZ();
// 計算距離的平方
double length = Math.sqrt(Math.abs(vx - x)) + Math.sqrt(Math.abs(vy - y)) + Math.sqrt(Math.abs(vz - z));
}
Point neartPoint = new Point();
return neartPoint;
}
}
public class Point
{
private double x; // x座標
private double y; // y座標
private double z; // z座標
public double getX()
{
return x;
}
public void setX(double x)
{
this.x = x;
}
public double getY()
{
return y;
}
public void setY(double y)
{
this.y = y;
}
public double getZ()
{
return z;
}
public void setZ(double z)
{
this.z = z;
}
}