Commit 4096b7a7 authored by Nguyeng Hoang Giang's avatar Nguyeng Hoang Giang

new

parents a2498efb 5979d65f
Pipeline #1481 canceled with stages
......@@ -8,29 +8,29 @@ version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext{
ext {
version = [
'javacv' : '1.5.3',
'opencv' : '4.3.0',
'javacv': '1.5.3',
'opencv': '4.3.0',
]
}
dependencies {
List axisExGroups = [ 'org.bytedeco.javacpp-presets']
List axisExModules = [ 'ffmpeg' , 'artoolkitplus', 'ffmpeg-platform']
implementation('org.bytedeco:opencv:4.5.1-1.5.5:android-x86')
implementation('org.bytedeco:opencv:4.3.0-1.5.3:android-x86_64')
implementation(group :'org.bytedeco', name: 'javacv-platform', version: '1.5.5'){
axisExGroups.each { exclude group: "$it" }
axisExModules.each {exclude module: "$it"}
List axisExGroups = ['org.bytedeco.javacpp-presets']
List axisExModules = ['ffmpeg', 'artoolkitplus', 'ffmpeg-platform', 'artoolkitplus-platform',
'flandmark', 'flandmark-platform', 'flycapture', 'flycapture-platform',
'leptonica', 'leptonica-platform', 'libdc1394', 'libdc1394-platform',
'libfreenect2', 'libfreenect2-platform', 'libfreenect', 'libfreenect-platform',
'librealsense2', 'librealsense2-platform', 'librealsense', 'librealsense-platform',
'tesseract', 'tesseract-platform', 'videoinput', 'videoinput-platform','javacv', 'javacv-platform']
implementation(group: 'org.bytedeco', name: 'javacv-platform', version: '1.5.5') {
axisExGroups.each { exclude group: "$it" }
axisExModules.each { exclude module: "$it" }
}
implementation('org.apache.commons:commons-lang3:3.12.0')
// testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
// testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
......
This diff is collapsed.
......@@ -6,14 +6,14 @@ public class FaceList {
private Face tail;
/**
* Clears this list
* Clears this list.
*/
public void clear() {
head = tail = null;
}
/**
* Adds a vertex to the end of this list
* Adds a vertex to the end of this list.
*/
public void add(Face vtx) {
if (head == null) {
......@@ -30,7 +30,7 @@ public class FaceList {
}
/**
* Returns true if this list is empty
* Returns true if this list is empty.
*/
public boolean isEmpty() {
return head == null;
......
......@@ -2,56 +2,56 @@ package Entity;
public class HalfEdge {
/**
* The vertex associated with the heat of this half-edge
*/
protected Vertex vertex;
/**
* Triangular face associated with this half-edge
* Triangular face associated with this half-edge.
*/
protected Face face;
public Face face;
/**
* Next haft-edge in the triangle
* Next half-edge in the triangle.
*/
protected HalfEdge next;
public HalfEdge next;
/**
* Previous half-edge in the reiangle
* Previous half-edge in the triangle.
*/
protected HalfEdge prev;
public HalfEdge prev;
/**
* Half-edge associated with the opposite triangle adjacent to this edge
* Half-edge associated with the opposite triangle adjacent to this edge.
*/
protected HalfEdge opposite;
public HalfEdge() {
}
public HalfEdge opposite;
/**
* Constructs a HalfEdge with head vertex and left-hand triangular face
* Constructs a HalfEdge with head vertex <code>v</code> and left-hand
* triangular face <code>f</code>.
*
* @param vertex head vertex
* @param face left-hand triangular face
* @param v head vertex
* @param f left-hand triangular face
*/
public HalfEdge(Vertex vertex, Face face) {
this.vertex = vertex;
this.face = face;
public HalfEdge(Vertex v, Face f) {
vertex = v;
face = f;
}
public HalfEdge() {
}
/**
* Gets the triangular face located to the left of this half-edge
* Sets the value of the next edge adjacent (counter-clockwise) to this one
* within the triangle.
*
* @return left-hand triangular face
* @param edge next adjacent edge
*/
public Face getFace() {
return face;
public void setNext(HalfEdge edge) {
next = edge;
}
/**
* Gets the value of the next edge adjacent (counter-clockwise) to this one within the triangle
* Gets the value of the next edge adjacent (counter-clockwise) to this one
* within the triangle.
*
* @return next adjacent edge
*/
......@@ -60,16 +60,18 @@ public class HalfEdge {
}
/**
* Sets the value of the next edge adjacent (counter-clockwise) to this one within the triangle
* Sets the value of the previous edge adjacent (clockwise) to this one
* within the triangle.
*
* @param next next adjacent edge
* @param edge previous adjacent edge
*/
public void setNext(HalfEdge next) {
this.next = next;
public void setPrev(HalfEdge edge) {
prev = edge;
}
/**
* Gets the value of the previous edge adjacent (clockwise) to this one within the triangle
* Gets the value of the previous edge adjacent (clockwise) to this one
* within the triangle.
*
* @return previous adjacent edge
*/
......@@ -78,16 +80,16 @@ public class HalfEdge {
}
/**
* Sets the value of the previous edge adjacent (clockwise) to this one within the triangle
* Returns the triangular face located to the left of this half-edge.
*
* @param prev previous adjacent edge
* @return left-hand triangular face
*/
public void setPrev(HalfEdge prev) {
this.prev = prev;
public Face getFace() {
return face;
}
/**
* Returns the half-edge opposite to this half-edge
* Returns the half-edge opposite to this half-edge.
*
* @return opposite half-edge
*/
......@@ -96,16 +98,17 @@ public class HalfEdge {
}
/**
* Sets the half-edge opposite to this half-edge
* Sets the half-edge opposite to this half-edge.
*
* @param opposite opposite half-edge
* @param edge opposite half-edge
*/
public void setOpposite(HalfEdge opposite) {
this.opposite = opposite;
public void setOpposite(HalfEdge edge) {
opposite = edge;
edge.opposite = this;
}
/**
* Returns the head vertex associated with this half-edge
* Returns the head vertex associated with this half-edge.
*
* @return head vertex
*/
......@@ -114,16 +117,16 @@ public class HalfEdge {
}
/**
* Returns the tail vertex associate with this half-edge
* Returns the tail vertex associated with this half-edge.
*
* @return
* @return tail vertex
*/
public Vertex tail() {
return prev != null ? prev.vertex : null;
}
/**
* Returns the opposite triangular face associate with this half-edge
* Returns the opposite triangular face associated with this half-edge.
*
* @return opposite triangular face
*/
......@@ -132,7 +135,8 @@ public class HalfEdge {
}
/**
* Produces a string identifying this half-edge by the point index values of its tail and head vertices
* Produces a string identifying this half-edge by the point index values of
* its tail and head vertices.
*
* @return identifying string
*/
......@@ -145,7 +149,7 @@ public class HalfEdge {
}
/**
* Returns the length of this half-edge
* Returns the length of this half-edge.
*
* @return half-edge length
*/
......@@ -158,9 +162,9 @@ public class HalfEdge {
}
/**
* Returns the length squared of this half-edge
* Returns the length squared of this half-edge.
*
* @return half-edge squared length
* @return half-edge length squared
*/
public double lengthSquared() {
if (tail() != null) {
......@@ -170,4 +174,5 @@ public class HalfEdge {
}
}
}
package Entity;
public class InternalErrorException extends RuntimeException {
public InternalErrorException(String msg) {
super(msg);
}
}
package Entity;
public class Point3D extends Vector3D{
/**
* Create a Point3D amd initializes it to zero
*/
public Point3D() {
}
/**
* Creates a Point3D by copy a vector
* @param v
*/
public Point3D(Vector3D v) {
super(v);
}
/**
* Create a Point3D with the supplied element values
* @param x
* first element
* @param y
* second element
* @param z
* third element
*/
public Point3D(double x, double y, double z) {
super(x, y, z);
}
}
package Entity;
public class Point3d extends Vector3d {
/**
* Creates a Point3d and initializes it to zero.
*/
public Point3d() {
}
/**
* Creates a Point3d by copying a vector
*
* @param v vector to be copied
*/
public Point3d(Vector3d v) {
set(v);
}
/**
* Creates a Point3d with the supplied element values.
*
* @param x first element
* @param y second element
* @param z third element
*/
public Point3d(double x, double y, double z) {
set(x, y, z);
}
public Point3d clone() {
return new Point3d(x, y, z);
}
}
package Entity;
public class Vector3D {
public class Vector3d {
static private final double DOUBLE_PREC = 2.2204460492503131e-16;//Precision of a double
/**
* Precision of a double.
*/
static private final double DOUBLE_PREC = 2.2204460492503131e-16;
/**
* First element
*/
public double x;
public double x;//first element
public double y;//second element
public double z;//third element
/**
* Second element
*/
public double y;
//Creates a 3-vector and initializes its elements to 0
public Vector3D() {
/**
* Third element
*/
public double z;
/**
* Creates a 3-vector and initializes its elements to 0.
*/
public Vector3d() {
}
/**
* Creates a 3-vector by copy existing one
* Creates a 3-vector by copying an existing one.
*
* @param v vector to be copied
*/
public Vector3D(Vector3D v) {
public Vector3d(Vector3d v) {
set(v);
}
/**
* Creates a 3-vector with the supplied element values
* Creates a 3-vector with the supplied element values.
*
* @param x first element
* @param y second element
* @param z third element
*/
public Vector3D(double x, double y, double z) {
public Vector3d(double x, double y, double z) {
set(x, y, z);
}
/**
* Gets a single element of this vector. Element 0, 1, and 2 correspond to x,y and z
* Gets a single element of this vector. Elements 0, 1, and 2 correspond to
* x, y, and z.
*
* @param i element index
* @return element value throws ArrayIndexOutOfBoundsException if i is not in range 0 to 2
* @return element value throws ArrayIndexOutOfBoundsException if i is not
* in the range 0 to 2.
*/
public double get(int i) {
switch (i) {
......@@ -57,11 +75,12 @@ public class Vector3D {
/**
* Sets a single element of this vector. Elements 0, 1, and 2 correspond to
* x, y, and z
* x, y, and z.
*
* @param i element index
* @param value element value
* @return element value throws ArrayIndexOutOfBoundsException if i is not in the range 0 to 2
* @return element value throws ArrayIndexOutOfBoundsException if i is not
* in the range 0 to 2.
*/
public void set(int i, double value) {
switch (i) {
......@@ -84,86 +103,64 @@ public class Vector3D {
}
/**
* Sets the values of this vector to those of v1
* Sets the values of this vector to those of v1.
*
* @param v1 vector whose values are copied
*/
public void set(Vector3D v1) {
this.x = v1.x;
this.y = v1.y;
this.z = v1.z;
public void set(Vector3d v1) {
x = v1.x;
y = v1.y;
z = v1.z;
}
/**
* Sets the values of the vector to the prescribed values
*
* @param x value for first element
* @param y value for second element
* @param z value for third element
*/
public void set(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
/**
* Sets the elements of this vector to zero
*/
public void setZero() {
x = 0;
y = 0;
z = 0;
}
/**
* Adds vector v1 to v2 and places the result in this vector
* Adds vector v1 to v2 and places the result in this vector.
*
* @param v1 left-hand vector
* @param v2 right-hand vector
*/
public void add(Vector3D v1, Vector3D v2) {
public void add(Vector3d v1, Vector3d v2) {
x = v1.x + v2.x;
y = v1.y + v2.y;
z = v1.z + v2.z;
}
/**
* Adds this vector to v and places the result in this vector
* Adds this vector to v1 and places the result in this vector.
*
* @param v right-hand vector
* @param v1 right-hand vector
*/
public void add(Vector3D v) {
x += v.x;
y += v.y;
z += v.z;
public void add(Vector3d v1) {
x += v1.x;
y += v1.y;
z += v1.z;
}
/**
* Subs vector v1 from v2 and places the result in this vector
* Subtracts vector v1 from v2 and places the result in this vector.
*
* @param v1 left-hand vector
* @param v2 right-hand vector
*/
public void sub(Vector3D v1, Vector3D v2) {
public void sub(Vector3d v1, Vector3d v2) {
x = v1.x - v2.x;
y = v1.y - v2.y;
z = v1.z - v2.z;
}
/**
* Subs this vector from v and places the result in this vector
* Subtracts v1 from this vector and places the result in this vector.
*
* @param v right-hand vector
* @param v1 right-hand vector
*/
public void sub(Vector3D v) {
x -= v.x;
y -= v.y;
z -= v.z;
public void sub(Vector3d v1) {
x -= v1.x;
y -= v1.y;
z -= v1.z;
}
/**
* Scales the elements of this vector by s
* Scales the elements of this vector by <code>s</code>.
*
* @param s scaling factor
*/
......@@ -174,19 +171,21 @@ public class Vector3D {
}
/**
* Scales the elements of vector v by s and place the results in this vector
* Scales the elements of vector v1 by <code>s</code> and places the results
* in this vector.
*
* @param s scaling vector
* @param v vector to be scaled
* @param s scaling factor
* @param v1 vector to be scaled
*/
public void scale(double s, Vector3D v) {
x = s * v.x;
y = s * v.y;
z = s * v.z;
public void scale(double s, Vector3d v1) {
x = s * v1.x;
y = s * v1.y;
z = s * v1.z;
}
/**
* Returns the 2 norm of this vector. This is the square root of the sum of the squares of the elements
* Returns the 2 norm of this vector. This is the square root of the sum of
* the squares of the elements.
*
* @return vector 2 norm
*/
......@@ -195,7 +194,8 @@ public class Vector3D {
}
/**
* Retruns the square of the 2 norm of this vector. this is the sum of the squares of the element
* Returns the square of the 2 norm of this vector. This is the sum of the
* squares of the elements.
*
* @return square of the 2 norm
*/
......@@ -204,12 +204,11 @@ public class Vector3D {
}
/**
* Returns the Euclidean distance between this vector and vector v
* Returns the Euclidean distance between this vector and vector v.
*
* @param v vector destination
* @return distance between this vector and v
*/
public double distance(Vector3D v) {
public double distance(Vector3d v) {
double dx = x - v.x;
double dy = y - v.y;
double dz = z - v.z;
......@@ -218,12 +217,12 @@ public class Vector3D {
}
/**
* Returns the squared of Euclidean distance between this vector and vector v
* Returns the squared of the Euclidean distance between this vector and
* vector v.
*
* @param v vector destination
* @return squared distance between this vector and v
*/
public double distanceSquared(Vector3D v) {
public double distanceSquared(Vector3d v) {
double dx = x - v.x;
double dy = y - v.y;
double dz = z - v.z;
......@@ -232,17 +231,17 @@ public class Vector3D {
}
/**
* Returns the dot product of this vector and v1
* Returns the dot product of this vector and v1.
*
* @param v right-hand vector
* @param v1 right-hand vector
* @return dot product
*/
public double dot(Vector3D v) {
return x * v.x + y * v.y + z * v.z;
public double dot(Vector3d v1) {
return x * v1.x + y * v1.y + z * v1.z;
}
/**
* Normalizes this vector in place
* Normalizes this vector in place.
*/
public void normalize() {
double lenSqr = x * x + y * y + z * z;
......@@ -256,27 +255,57 @@ public class Vector3D {
}
/**
* Computes the cross product of v1 and v2 and places the result in this vector
* Sets the elements of this vector to zero.
*/
public void setZero() {
x = 0;
y = 0;
z = 0;
}
/**
* Sets the elements of this vector to the prescribed values.
*
* @param x value for first element
* @param y value for second element
* @param z value for third element
*/
public void set(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
/**
* Computes the cross product of v1 and v2 and places the result in this
* vector.
*
* @param v1 left-hand vector
* @param v2 right-hand vector
*/
public void cross(Vector3D v1, Vector3D v2) {
public void cross(Vector3d v1, Vector3d v2) {
double tmpx = v1.y * v2.z - v1.z * v2.y;
double tmpy = v1.z * v2.x - v1.x * v2.z;
double tmpz = v1.x * v2.y - v1.y - v2.x;
double tmpz = v1.x * v2.y - v1.y * v2.x;
x = tmpx;
y = tmpy;
z = tmpz;
}
@Override
/**
* Returns a string representation of this vector, consisting of the x, y,
* and z coordinates.
*
* @return string representation
*/
public String toString() {
return "Vector3D{" +
"x=" + x +
", y=" + y +
", z=" + z +
'}';
return x + " " + y + " " + z;
}
public double scalarProjection(Vector3d normal) {
return this.dot(normal)/normal.norm();
}
}
......@@ -3,41 +3,42 @@ package Entity;
public class Vertex {
/**
* Spatial point associated with this vertex
* Spatial point associated with this vertex.
*/
public Point3D pnt;
public Point3d pnt;
/**
* Back index into an array
* Back index into an array.
*/
public int index;
/**
* List forward link
* List forward link.
*/
public Vertex prev;
/**
* List backward link
* List backward link.
*/
public Vertex next;
/**
* Current face that this vertex is outside of
* Current face that this vertex is outside of.
*/
public Face face;
/**
* Constructs a vertex and sets its coordinates to 0
* Constructs a vertex and sets its coordinates to 0.
*/
public Vertex() {
pnt = new Point3d();
}
/**
* Constructs a vertex with the specified coordinates and index
* Constructs a vertex with the specified coordinates and index.
*/
public Vertex(double x, double y, double z, int idx) {
pnt = new Point3D(x, y, z);
pnt = new Point3d(x, y, z);
index = idx;
}
}
import Entity.Point3D;
import Entity.Point3d;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
......@@ -17,7 +18,7 @@ public class Fleet_single_cam {
private int num_y;
private int num_z;
private boolean show;
private Point3D[] points;
private Point3d[] points;
// private
HashMap<String, intArray> side;
......@@ -143,7 +144,7 @@ public class Fleet_single_cam {
*/
public void initPoint3d() {
//init point list
List<Point3D> point3dList = new ArrayList<>();
List<Point3d> point3dList = new ArrayList<>();
//temp pixel
int xx = 0;
......@@ -164,7 +165,7 @@ public class Fleet_single_cam {
xx += 1;
//add if point == 0
if (front[i][j] == 0) {
point3dList.add(new Point3D(xx, yy, zz));
point3dList.add(new Point3d(xx, yy, zz));
}
}
}
......@@ -179,7 +180,7 @@ public class Fleet_single_cam {
yy += 1;
//add if point == 0
if (side[i][j] == 0) {
point3dList.add(new Point3D(xx, yy, zz));
point3dList.add(new Point3d(xx, yy, zz));
}
}
}
......@@ -194,18 +195,26 @@ public class Fleet_single_cam {
xx += 1;
//add if point == 0
if (bottom[i][j] == 0) {
point3dList.add(new Point3D(xx, yy, zz));
point3dList.add(new Point3d(xx, yy, zz));
}
}
}
points = point3dList.toArray(new Point3D[point3dList.size()]);
points = point3dList.toArray(new Point3d[point3dList.size()]);
}
public Point3D[] getPoints() {
public Point3d[] getPoints() {
return points;
}
/**
* Adding 0 into matrix inorder to make the matrix fit the require height and width
* @param matrix
* @param require_height
* @param require_width
* @return
*/
private int[][] padding(int[][] matrix, int require_height, int require_width) {
//get width, height
int height = 0;
......
import Entity.Point3d;
import org.bytedeco.javacpp.Loader;
import org.bytedeco.opencv.opencv_java;
import utils.QuickHull3D;
import java.util.Arrays;
......@@ -8,8 +11,11 @@ public class main {
Loader.load(opencv_java.class);
//Khoi tạo 1 cam, nhận ảnh tĩnh vào
Fleet_single_cam cam1 = new Fleet_single_cam("a", "1da36bd1c4aa0bf452bb24.jpg", 0.5, 5, 5, 4, false);
int x = 5;
int y = 5;
int z = 4;
//Khoi tạo cam 1
Fleet_single_cam cam1 = new Fleet_single_cam("1", "1da36bd1c4aa0bf452bb24.jpg", 0.5, x, y, z, false);
//create front side, add 4 đỉnh của side front vào
cam1.add_side("front", new float[][]{
......@@ -35,10 +41,12 @@ public class main {
new float[]{288, 545}
});
//tính matrix thể tích vật
cam1.refine_matrix();
//lấy những point chứa vật
cam1.initPoint3d();
//Khoi tạo 1 cam, nhận ảnh tĩnh vào
//Khoi tạo cam2
Fleet_single_cam cam2 = new Fleet_single_cam("a", "5b8ab6b219c9d6978fd827.jpg", 0.5, 5, 5, 4, false);
//create front side, add 4 đỉnh của side front vào
......@@ -65,32 +73,26 @@ public class main {
new float[]{275, 497}
});
//tính matrix thể tích vật
cam2.refine_matrix();
//lấy những point của vật thể
cam2.initPoint3d();
// tổng hợp lại những point chứa vật trong 2 cam
Point3d[] poly = Arrays.copyOf(cam1.getPoints(), cam1.getPoints().length+cam2.getPoints().length);
System.arraycopy(cam2.getPoints(), 0, poly, cam1.getPoints().length, cam2.getPoints().length);
//dùng quick hull algorithm để tính thể tích
QuickHull3D hull = new QuickHull3D();
hull.build(poly);
//lấy thể tích của vật
double volume = hull.calVolume();
// Point3d[] poly = Arrays.copyOf(cam1.getPoints(), cam1.getPoints().length+cam2.getPoints().length);
// System.arraycopy(cam2.getPoints(), 0, poly, cam1.getPoints().length, cam2.getPoints().length);
//
// QuickHull3D hull = new QuickHull3D();
// hull.build(poly);
// System.out.println("Vertices:");
// Point3d[] vertices = hull.getVertices();
// for (int i = 0; i < vertices.length; i++) {
// Point3d pnt = vertices[i];
// System.out.println(pnt.x + " " + pnt.y + " " + pnt.z);
// }
//
// System.out.println("Faces:");
// int[][] faceIndices = hull.getFaces();
// for (int i = 0; i < vertices.length; i++) {
// for (int k = 0; k < faceIndices[i].length; k++) {
// System.out.print(faceIndices[i][k] + " ");
// }
// System.out.println("");
// }
//Kết quả trả ra: tỉ lệ thể tích
double result = volume/((x+1)*(y+1)*(z+1));
}
......
This diff is collapsed.
package utils;
import Entity.*;
import java.util.Vector;
public class QuickHull3d {
/**
* Specifies that the distance tolerance should be computed automatically from the input point data
*/
public static final double AUTOMATIC_TOLERANCE = -1;
protected int findIndex = -1;
//estimated size of the point set
protected double charLength;
protected Vertex[] pointBuffer = new Vertex[0];
protected int[] vertexPointIndices = new int[0];
private Face[] discardedFaces = new Face[3];
private Vertex[] maxVtxs = new Vertex[3];
private Vertex[] minVtxs = new Vertex[3];
protected Vector face = new Vector(16);
protected Vector horizon = new Vector(16);
private FaceList newFaces = new FaceList();
private VertexList unclaimed = new VertexList();
private VertexList claimed = new VertexList();
protected int numVertices;
protected int numFaces;
protected int numPoints;
protected double explicitTolerance = AUTOMATIC_TOLERANCE;
protected double tolerance;
private static final double DOUBLE_PREC = 2.2204460492503131e-16;
/**
* Create a convex hull object and initializes it to the convex hull of a set of points
* @param points
* input points
* @throws IllegalArgumentException
* the number of input points is less than four, or the point appear to be coincident, colinear, or coplanar
*/
public QuickHull3d(Point3D[] points) throws IllegalArgumentException{
build(points, points.length);
}
/**
* Constructs the convex hull of a set of points
* @param points
* input points
* @param nump
* number of input poins
* @throws IllegalArgumentException
* the number of input points is less than four or greater than the length if points, or the points appear to be coincident, colinear, or coplanar
*/
public void build(Point3D[] points, int nump) throws IllegalArgumentException{
if (nump < 4){
throw new IllegalArgumentException("Less than four input points specified");
}
if (points.length < nump){
throw new IllegalArgumentException("Point array too small for specified number of points");
}
initBuffers(nump);
setPoints(points, nump);
buildHull();
}
protected void initBuffers(int nump){
if (pointBuffer.length < nump){
Vertex[] newBuffer = new Vertex[nump];
vertexPointIndices = new int[nump];
for (int i = 0; i < pointBuffer.length; i++){
newBuffer[i] = pointBuffer[i];
}
for (int i = pointBuffer.length; i < nump; i++){
newBuffer[i] = new Vertex();
}
pointBuffer = newBuffer;
}
face.clear();
claimed.clear();
numFaces = 0;
numPoints = nump;
}
protected void setPoints(Point3D[] pnts, int nump) {
for (int i = 0; i < nump; i++){
Vertex vtx = pointBuffer[i];
vtx.pnt.set(pnts[i]);
vtx.index = i;
}
}
protected void buildHull(){
int cnt = 0;
Vertex eyeVtx;
computeMaxAndMin();
createInitialSimplex();
while ((eyeVtx = nextPointToAdd()) != null){
addPointToHull(eyeVtx);
cnt++;
}
reindexFacesAndVertices();
}
protected void computeMaxAndMin(){
//initialize max, min
Vector3D max = new Vector3D();
Vector3D min = new Vector3D();
for (int i=0;i<3;i++){
maxVtxs[i] = minVtxs[i] = pointBuffer[0];
}
max.set(pointBuffer[0].pnt);
min.set(pointBuffer[0].pnt);
//check all point to find max, min
for (int i=1;i<numPoints;i++){
Point3D pnt = pointBuffer[i].pnt;
//find maxVtxs[0] and minVtxs[0] , vectors with max x and min x
if (pnt.x >max.x){
max.x = pnt.x;
maxVtxs[0] = pointBuffer[i];
}else if (pnt.x < min.x){
min.x = pnt.x;
minVtxs[0] = pointBuffer[i];
}
//find maxVtxs[1] and minVtxs[1] , vectors with max y and min y
if (pnt.y >max.y){
max.y = pnt.y;
maxVtxs[1] = pointBuffer[i];
}else if (pnt.y < min.y){
min.y = pnt.y;
minVtxs[1] = pointBuffer[i];
}
//find maxVtxs[2] and minVtxs[2] , vectors with max z and min z
if (pnt.z >max.z){
max.z = pnt.z;
maxVtxs[2] = pointBuffer[i];
}else if (pnt.z < min.z){
min.z = pnt.z;
minVtxs[2] = pointBuffer[i];
}
charLength = Math.max(max.x - min.x, max.y - min.y);
charLength = Math.max(max.z - min.z, charLength);
if (explicitTolerance == AUTOMATIC_TOLERANCE){
tolerance = 3* DOUBLE_PREC * (Math.max(Math.abs(max.x), Math.abs(min.x)) + Math.max(Math.abs(max.y), Math.abs(min.y)) + Math.max(Math.abs(max.z), Math.abs(min.z)));
}else{
tolerance = explicitTolerance;
}
}
}
protected void createInitialSimplex() throws IllegalArgumentException{
double max = 0;
int imax = 0;
for (int i = 0; i< 3; i++){
double diff = maxVtxs[i].pnt.get(i)-minVtxs[i].pnt.get(i);
if (diff > max){
max = diff;
imax = i;
}
}
if (max <= tolerance){
throw new IllegalArgumentException("Input points appear to be conicident");
}
Vertex[] vtx = new Vertex[4];
//set first two vertices to be those with the greatest one dimensional separation
vtx[0] = maxVtxs[imax];
vtx[1] = minVtxs[imax];
// set third vertex to be the vertex farthest from the line between vtx0 and vtx1
Vector3D u01 = new Vector3D();
Vector3D diff02 = new Vector3D();
Vector3D nrml = new Vector3D();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment