Class MeshTriangleImpl

java.lang.Object
cz.fidentis.analyst.data.mesh.impl.MeshTriangleImpl
All Implemented Interfaces:
MeshTriangle, Serializable, Iterable<MeshPoint>

public class MeshTriangleImpl extends Object implements MeshTriangle
Adapter for the corner table representing a single triangle of MeshFacet.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface cz.fidentis.analyst.data.mesh.MeshTriangle

    MeshTriangle.Smoothing
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
    final int
    Under which index is the corresponding vertex stored in the mesh facet
    final int
     
    final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    MeshTriangleImpl(MeshFacet facet, int i1, int i2, int i3)
    Creates new triangle
  • Method Summary

    Modifier and Type
    Method
    Description
    javax.vecmath.Vector3d
    Computes and returns normalized normal vector from the vertices.
    boolean
     
    protected javax.vecmath.Point3d
    getBarycentricCoords(javax.vecmath.Vector3d[] cross)
     
    javax.vecmath.Point3d
    getClosestPoint(javax.vecmath.Point3d point)
    Computes the point laying on the triangle which is closest to given 3D point.
    List<javax.vecmath.Point3d>
    Selects the common points shared by two triangles
    javax.vecmath.Vector4d
    getCurvatureOfTrianglePlane(javax.vecmath.Point3d samplePosition, double distanceAccepted, javax.vecmath.Vector3d base1, javax.vecmath.Vector3d base2)
    Function tests if the mesh triangle is closer to the sample point than a certain distance and if is, calculates the second fundamental form of the sample point regarding the plane defined by the mesh triangle, otherwise returns null.
    protected static javax.vecmath.Vector3d
    getEdge(javax.vecmath.Point3d v1, javax.vecmath.Point3d v2)
     
    Returns mesh facet backing the triangle.
    int
    Returns the index under which the vertex is stored in the array of facet vertices
    int
    Returns the index under which the vertex is stored in the array of facet vertices
    int
    Returns the index under which the vertex is stored in the array of facet vertices
    protected javax.vecmath.Point3d
    getInterpolatedIntersection(javax.vecmath.Tuple3d barycentricCoords, javax.vecmath.Vector3d[] inner)
    Calculates new position of a point from thr triangle so that the point lies on "smoothed" surface interpolated by normal in triangle vertices.
    protected javax.vecmath.Vector3d
    getInterpolatedNormal(javax.vecmath.Tuple3d barycentricCoords)
    Calculates interpolated normal of a point, weights = barycentric coordinates
    protected static boolean
    getLinesIntersection(javax.vecmath.Point3d origin, javax.vecmath.Vector3d vector, javax.vecmath.Point3d first, javax.vecmath.Point3d second, javax.vecmath.Point3d intersection)
    Computes the intersection between an infinite line and its coplanar lines segment.
    Returns mesh point of the triangle's vertex.
    Returns mesh point of the triangle's vertex.
    Returns mesh point of the triangle's vertex.
    protected javax.vecmath.Point3d
    getProjectionToClosestEdge(javax.vecmath.Point3d point)
    Computes projection of tmp1 3D point laying on the plane of the triangle to the nearest edge of the triangle
    protected javax.vecmath.Point3d
    getProjectionToEdge(javax.vecmath.Point3d point, javax.vecmath.Point3d v1, javax.vecmath.Point3d v2)
    Computes projection to edge
    Computes ray-triangle intersection.
    javax.vecmath.Point3d
    Returns 3D coordinates of the triangle's vertex.
    javax.vecmath.Point3d
    Returns 3D coordinates of the triangle's vertex.
    javax.vecmath.Point3d
    Returns 3D coordinates of the triangle's vertex.
    javax.vecmath.Point3d
    Return a center of circumcircle.
    int
     
    boolean
    checkIntersectionWithPlane(javax.vecmath.Vector3d normal, double d)
    Checks whether the triangle is intersected by a plane
    protected boolean
    isPointInTriangle(javax.vecmath.Point3d point, javax.vecmath.Vector3d normal, javax.vecmath.Vector3d[] edges, javax.vecmath.Vector3d[] inner, javax.vecmath.Vector3d[] cross)
    Checks if point lying on the plane of the triangle also lies inside the triangle boundaries.
     
    protected boolean
    orientNormal(javax.vecmath.Vector3d normal)
    Orient given triangle normal so that it is in the direction of the normals of vertices of the triangle.
    protected javax.vecmath.Vector3d
    subtractPosition(javax.vecmath.Point3d p1, MeshPoint p2)
     
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Field Details

    • EPS

      public static final double EPS
      See Also:
    • index1

      public final int index1
      Under which index is the corresponding vertex stored in the mesh facet
    • index2

      public final int index2
    • index3

      public final int index3
  • Constructor Details

    • MeshTriangleImpl

      public MeshTriangleImpl(MeshFacet facet, int i1, int i2, int i3)
      Creates new triangle
      Parameters:
      facet - Mesh facet
      i1 - which index is the first vertex stored in the mesh facet
      i2 - which index is the second vertex stored in the mesh facet
      i3 - which index is the third vertex stored in the mesh facet
  • Method Details

    • getFacet

      public MeshFacet getFacet()
      Description copied from interface: MeshTriangle
      Returns mesh facet backing the triangle.
      Specified by:
      getFacet in interface MeshTriangle
      Returns:
      mesh facet backing the triangle.
    • getVertex1

      public javax.vecmath.Point3d getVertex1()
      Description copied from interface: MeshTriangle
      Returns 3D coordinates of the triangle's vertex.
      Specified by:
      getVertex1 in interface MeshTriangle
      Returns:
      3D coordinates of the triangle's vertex
    • getVertex2

      public javax.vecmath.Point3d getVertex2()
      Description copied from interface: MeshTriangle
      Returns 3D coordinates of the triangle's vertex.
      Specified by:
      getVertex2 in interface MeshTriangle
      Returns:
      3D coordinates of the triangle's vertex
    • getVertex3

      public javax.vecmath.Point3d getVertex3()
      Description copied from interface: MeshTriangle
      Returns 3D coordinates of the triangle's vertex.
      Specified by:
      getVertex3 in interface MeshTriangle
      Returns:
      3D coordinates of the triangle's vertex
    • getPoint1

      public MeshPoint getPoint1()
      Description copied from interface: MeshTriangle
      Returns mesh point of the triangle's vertex.
      Specified by:
      getPoint1 in interface MeshTriangle
      Returns:
      mesh point of the triangle's vertex
    • getPoint2

      public MeshPoint getPoint2()
      Description copied from interface: MeshTriangle
      Returns mesh point of the triangle's vertex.
      Specified by:
      getPoint2 in interface MeshTriangle
      Returns:
      mesh point of the triangle's vertex
    • getPoint3

      public MeshPoint getPoint3()
      Description copied from interface: MeshTriangle
      Returns mesh point of the triangle's vertex.
      Specified by:
      getPoint3 in interface MeshTriangle
      Returns:
      mesh point of the triangle's vertex
    • getIndex1

      public int getIndex1()
      Description copied from interface: MeshTriangle
      Returns the index under which the vertex is stored in the array of facet vertices
      Specified by:
      getIndex1 in interface MeshTriangle
      Returns:
      the index under which the vertex is stored in the array of facet vertices
    • getIndex2

      public int getIndex2()
      Description copied from interface: MeshTriangle
      Returns the index under which the vertex is stored in the array of facet vertices
      Specified by:
      getIndex2 in interface MeshTriangle
      Returns:
      the index under which the vertex is stored in the array of facet vertices
    • getIndex3

      public int getIndex3()
      Description copied from interface: MeshTriangle
      Returns the index under which the vertex is stored in the array of facet vertices
      Specified by:
      getIndex3 in interface MeshTriangle
      Returns:
      the index under which the vertex is stored in the array of facet vertices
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • computeOrientedNormal

      public javax.vecmath.Vector3d computeOrientedNormal()
      Description copied from interface: MeshTriangle
      Computes and returns normalized normal vector from the vertices. This vector is in the direction of the normals of vertices of the triangle.
      Specified by:
      computeOrientedNormal in interface MeshTriangle
      Returns:
      normalized normal vector from the vertices.
    • getRayIntersection

      public RayIntersectionImpl getRayIntersection(Ray ray, MeshTriangle.Smoothing smoothing)
      Description copied from interface: MeshTriangle
      Computes ray-triangle intersection. Based on this article but adapted to two-side triangles.
      Specified by:
      getRayIntersection in interface MeshTriangle
      Parameters:
      ray - a ray
      smoothing - smoothing strategy
      Returns:
      the ray intersection or null
    • getClosestPoint

      public javax.vecmath.Point3d getClosestPoint(javax.vecmath.Point3d point)
      Description copied from interface: MeshTriangle
      Computes the point laying on the triangle which is closest to given 3D point. Return point is either one of the triangle's vertices, a point laying on triangles edge, or a point laying on the plane of the triangle inside the triangle boundaries.
      Specified by:
      getClosestPoint in interface MeshTriangle
      Parameters:
      point - 3D point
      Returns:
      the closest point or null if the input parameter is missing
    • checkIntersectionWithPlane

      public boolean checkIntersectionWithPlane(javax.vecmath.Vector3d normal, double d)
      Description copied from interface: MeshTriangle
      Checks whether the triangle is intersected by a plane
      Specified by:
      checkIntersectionWithPlane in interface MeshTriangle
      Parameters:
      normal - normal defining the plane
      d - distance defining the plane
      Returns:
      true if the triangle is intersected by the plane
    • getCommonPoints

      public List<javax.vecmath.Point3d> getCommonPoints(MeshTriangle other)
      Description copied from interface: MeshTriangle
      Selects the common points shared by two triangles
      Specified by:
      getCommonPoints in interface MeshTriangle
      Parameters:
      other - The other triangle
      Returns:
      the common points of two triangles
    • iterator

      public Iterator<MeshPoint> iterator()
      Specified by:
      iterator in interface Iterable<MeshPoint>
      Specified by:
      iterator in interface MeshTriangle
    • getVoronoiPoint

      public javax.vecmath.Point3d getVoronoiPoint()
      Description copied from interface: MeshTriangle
      Return a center of circumcircle. This point represents the point of Voronoi area used for Delaunay triangulation, for instance.
      Specified by:
      getVoronoiPoint in interface MeshTriangle
      Returns:
      the center of circumcircle
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getEdge

      protected static javax.vecmath.Vector3d getEdge(javax.vecmath.Point3d v1, javax.vecmath.Point3d v2)
    • isPointInTriangle

      protected boolean isPointInTriangle(javax.vecmath.Point3d point, javax.vecmath.Vector3d normal, javax.vecmath.Vector3d[] edges, javax.vecmath.Vector3d[] inner, javax.vecmath.Vector3d[] cross)
      Checks if point lying on the plane of the triangle also lies inside the triangle boundaries.
      Parameters:
      point - Point located on the plane of the triangle
      normal - Normal vector
      edges - An array of vectors A->B, B->C, and C->A. If some of them is missing, then is computed automatically and stored in the array.
      inner - An array of vectors A->P, B->P, and C->P. If some of them is missing, then is computed automatically and stored in the array.
      cross - An output array of cross products A->B x A->P, etc.
      Returns:
      true if point is in triangle, false otherwise
    • orientNormal

      protected boolean orientNormal(javax.vecmath.Vector3d normal)
      Orient given triangle normal so that it is in the direction of the normals of vertices of the triangle.
      Parameters:
      normal - normalized normal vector to be oriented. The vector can be inverted!
      Returns:
      true if the normal direction was inverted
    • getProjectionToClosestEdge

      protected javax.vecmath.Point3d getProjectionToClosestEdge(javax.vecmath.Point3d point)
      Computes projection of tmp1 3D point laying on the plane of the triangle to the nearest edge of the triangle
      Parameters:
      point - point laying on the plane of the triangle
      Returns:
      perpendicular projection to the nearest edge
    • getProjectionToEdge

      protected javax.vecmath.Point3d getProjectionToEdge(javax.vecmath.Point3d point, javax.vecmath.Point3d v1, javax.vecmath.Point3d v2)
      Computes projection to edge
      Parameters:
      point - Point laying on the plane of the triangle
      v1 - first vertex of edge
      v2 - second vertex of edge
      Returns:
      projection to edge
    • subtractPosition

      protected javax.vecmath.Vector3d subtractPosition(javax.vecmath.Point3d p1, MeshPoint p2)
    • getInterpolatedNormal

      protected javax.vecmath.Vector3d getInterpolatedNormal(javax.vecmath.Tuple3d barycentricCoords)
      Calculates interpolated normal of a point, weights = barycentric coordinates
      Parameters:
      barycentricCoords - barycentric coordinates are returned by getBarycentricCoords(Vector3d[])
      Returns:
      interpolated normal
    • getInterpolatedIntersection

      protected javax.vecmath.Point3d getInterpolatedIntersection(javax.vecmath.Tuple3d barycentricCoords, javax.vecmath.Vector3d[] inner)
      Calculates new position of a point from thr triangle so that the point lies on "smoothed" surface interpolated by normal in triangle vertices. Based on algorithm.
      Parameters:
      barycentricCoords - barycentric coordinates of the triangle as returned by getBarycentricCoords(Vector3d[])
      inner - An array of vertex->point vectors returned by isPointInTriangle(Point3d, Vector3d, Vector3d[], Vector3d[], Vector3d[])
      Returns:
      interpolated point
    • getBarycentricCoords

      protected javax.vecmath.Point3d getBarycentricCoords(javax.vecmath.Vector3d[] cross)
    • getLinesIntersection

      protected static boolean getLinesIntersection(javax.vecmath.Point3d origin, javax.vecmath.Vector3d vector, javax.vecmath.Point3d first, javax.vecmath.Point3d second, javax.vecmath.Point3d intersection)
      Computes the intersection between an infinite line and its coplanar lines segment. The infinite line is described like a ray, i.e., it has an origin and direction. But the intersection is searched in both directions. Negative length of returned ray indicates that the intersection point lies opposite direction than the input first segment expected.
      Parameters:
      origin - starting point of first line Must not be null
      vector - unit direction vector of the first line. Must not be null
      first - first point on second line Must not be null
      second - second point on second line Must not be null
      intersection - output parameter storing the coordinates of the intersection. The point is set to (infinity, infinity, infinity) if the lines are parallel, or they don't lie at the same line.
      Returns:
      false if the intersection point lies in the opposite direction than the input first segment expected.
    • getCurvatureOfTrianglePlane

      public javax.vecmath.Vector4d getCurvatureOfTrianglePlane(javax.vecmath.Point3d samplePosition, double distanceAccepted, javax.vecmath.Vector3d base1, javax.vecmath.Vector3d base2)
      Description copied from interface: MeshTriangle
      Function tests if the mesh triangle is closer to the sample point than a certain distance and if is, calculates the second fundamental form of the sample point regarding the plane defined by the mesh triangle, otherwise returns null.

      For more details, see: V. Interrante et al.: Conveying the 3D shape of smoothly curving transparent surfaces via texture, 1997, doi: 10.1109/2945.597794

      Specified by:
      getCurvatureOfTrianglePlane in interface MeshTriangle
      Parameters:
      samplePosition - position of a point on model's surface selected to be a glyph
      distanceAccepted - squared distance; the triangle needs to be closer to the sample point than this distance to be taken into account
      base1 - first vector of orthogonal base; the base consists of three vectors: the normal of the sample point and two vectors(base1 and base2) defining the tangent plane of the model at the sample point
      base2 - second vector of orthogonal base; the base consists of three vectors: the normal of the sample point and two vectors(base1 and base2) defining the tangent plane of the model at the sample point
      Returns:
      curvature of the sample point represented by the rate the surface normal tips in the directions of orthogonal base