⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 polyhedralboundedsolidsetoperator.java

📁 基于java的3d开发库。对坐java3d的朋友有很大的帮助。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
//===========================================================================//=-------------------------------------------------------------------------=//= Module history:                                                         =//= - April 1 2008 - Oscar Chavarro: Original base version                  =//=-------------------------------------------------------------------------=//= References:                                                             =//= [MANT1986] Mantyla Martti. "Boolean Operations of 2-Manifolds through   =//=     Vertex Neighborhood Classification". ACM Transactions on Graphics,  =//=     Vol. 5, No. 1, January 1986, pp. 1-29.                              =//= [MANT1988] Mantyla Martti. "An Introduction To Solid Modeling",         =//=     Computer Science Press, 1988.                                       =//= [.wMANT2008] Mantyla Martti. "Personal Home Page", <<shar>> archive     =//=     containing the C programs from [MANT1988]. Available at             =//=     http://www.cs.hut.fi/~mam . Last visited April 12 / 2008.           =//===========================================================================package vsdk.toolkit.processing;// Java classesimport java.util.ArrayList;import java.util.Collections;// VitralSDK classesimport vsdk.toolkit.common.VSDK;import vsdk.toolkit.common.ColorRgb;import vsdk.toolkit.common.Vector3D;import vsdk.toolkit.common.Matrix4x4;import vsdk.toolkit.environment.geometry.Geometry;import vsdk.toolkit.environment.geometry.InfinitePlane;import vsdk.toolkit.environment.geometry.PolyhedralBoundedSolid;import vsdk.toolkit.environment.geometry.polyhedralBoundedSolidNodes._PolyhedralBoundedSolidFace;import vsdk.toolkit.environment.geometry.polyhedralBoundedSolidNodes._PolyhedralBoundedSolidLoop;import vsdk.toolkit.environment.geometry.polyhedralBoundedSolidNodes._PolyhedralBoundedSolidEdge;import vsdk.toolkit.environment.geometry.polyhedralBoundedSolidNodes._PolyhedralBoundedSolidHalfEdge;import vsdk.toolkit.environment.geometry.polyhedralBoundedSolidNodes._PolyhedralBoundedSolidVertex;/**Class `_PolyhedralBoundedSolidSplitterNullEdge` plays a role of a decoratordesign patern for class `_PolyhedralBoundedSolidEdge`, and adds sort-ability.*/class _PolyhedralBoundedSolidSetOperatorNullEdge extends PolyhedralBoundedSolidOperator implements Comparable <_PolyhedralBoundedSolidSetOperatorNullEdge>{    public _PolyhedralBoundedSolidEdge e;    public _PolyhedralBoundedSolidSetOperatorNullEdge(_PolyhedralBoundedSolidEdge e)    {        this.e = e;    }    public int compareTo(_PolyhedralBoundedSolidSetOperatorNullEdge other)    {        Vector3D a;        Vector3D b;        a = this.e.rightHalf.startingVertex.position;        b = other.e.rightHalf.startingVertex.position;        if ( PolyhedralBoundedSolid.compareValue(a.x, b.x, 10*VSDK.EPSILON) != 0 ) {            if ( a.x < b.x ) {                return -1;            }            return 1;        }        else {            if ( PolyhedralBoundedSolid.compareValue(a.y, b.y, 10*VSDK.EPSILON) != 0 ) {                if ( a.y < b.y ) {                    return -1;                }                return 1;            }            else {                if ( a.z < b.z ) {                    return -1;                }                return 1;            }        }    }    public String toString()    {        return e.toString() + " (sorted with respect to position " + this.e.rightHalf.startingVertex.position + ")";    }}/**This class is used to store vertex / halfedge neigborhood information for thevertex/vertex classifier as proposed on section [MANT1988].15.5. and program[MANT1988].15.6.*/class _PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex extends PolyhedralBoundedSolidOperator implements Comparable <_PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex>{    public _PolyhedralBoundedSolidHalfEdge he;    public Vector3D ref1;    public Vector3D ref2;    public Vector3D ref12;    public Vector3D referenceLine;    public Vector3D referenceU;    public Vector3D referenceV;    public boolean wide;    public _PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex()    {        referenceLine = null;        referenceU = null;        referenceV = null;    }    public double getAngle()    {        if ( referenceLine == null || referenceU == null || referenceV == null ) {            return -1000;        }        double x, y;        double an;        Vector3D a = ref1;        if ( PolyhedralBoundedSolidSetOperator.colinearVectorsWithDirection(ref1, referenceLine) ) {            a = ref2;        }        Vector3D u, v;        u = new Vector3D(referenceU);        u.normalize();        v = new Vector3D(referenceV);        v.normalize();        a.normalize();        x = a.dotProduct(u);        y = a.dotProduct(v);        an = Math.acos(x);        if ( y < 0 ) an *= -1;        return an;    }    public String toString()    {        String msg;        msg = "R1: " + ref1 + " R2: " + ref2 + " HE " + he.startingVertex.id + "/" + he.next().startingVertex.id + (wide?"(W)":"(nw)");        return msg;    }    public int compareTo(_PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex other)    {        double a, b;        a = this.getAngle();        b = other.getAngle();        if ( a > b) return 1;        if ( a < b) return -1;        return 0;    }}/**This class is used to store sector / sector neigborhood information for thevertex/vertex classifier as proposed on section [MANT1988].15.5. and program[MANT1988].15.6.*/class _PolyhedralBoundedSolidSetOperatorSectorClassificationOnSector extends PolyhedralBoundedSolidOperator{    public int secta;    public int sectb;    public int s1a;    public int s2a;    public int s1b;    public int s2b;    public boolean intersect;    public _PolyhedralBoundedSolidHalfEdge hea;    public _PolyhedralBoundedSolidHalfEdge heb;    public boolean wa;    public boolean wb;    public static final int ON = 0;    public static final int OUT = 1;    public static final int IN = -1;    private String label(int i)    {        String msg = "<Unknown>";        switch ( i ) {          case ON: msg = "on"; break;          case OUT: msg = "OUT"; break;          case IN: msg = "IN"; break;        }        return msg;    }    public void fillCases()    {        if ( s1a == ON ) {            switch ( s2a ) {            case IN: s1a = OUT; break;            case OUT: s1a = IN; break;            }        }        if ( s2a == ON ) {            switch ( s1a ) {            case IN: s2a = OUT; break;            case OUT: s2a = IN; break;            }        }        if ( s1b == ON ) {            switch ( s2b ) {            case IN: s1b = OUT; break;            case OUT: s1b = IN; break;            }        }        if ( s2b == ON ) {            switch ( s1b ) {            case IN: s2b = OUT; break;            case OUT: s2b = IN; break;            }        }    }    public String toString()    {        String msg = "Sector pair ";        msg = msg + "A[" + (secta+1) + "] / B[" + (sectb+1) + "]: ";        msg = msg + "VERTICES ( " +             hea.startingVertex.id + "-" +             (hea.next()).startingVertex.id + (wa?"(W)":"(nw)") + " / " +             heb.startingVertex.id + "-" +            (heb.next()).startingVertex.id + (wb?"(W)":"(nw)") + " ) - ";        msg = msg + "[" + label(s1a) + "/" + label(s2a) + ", " + label(s1b) + "/" + label(s2b) + "] ";        if ( intersect ) {            msg = msg + "intersecting";        }        else {            msg = msg + "(droped)";        }        if ( s1a != 0 && s1b != 0 && s2a != 0 && s2b != 0 && intersect ) {            msg += " (**) ";        }        return msg;    }}/**This class is used to store vertex / halfedge neigborhood information for thevertex/face classifier, in a similar fashion to as presented in section[MANT1988].14.5, and program [MANT1988].14.3., but biased for the setoperation algorithm as proposed on section [MANT1988].15..1. and problem[MANT1988].15.4.*/class _PolyhedralBoundedSolidSetOperatorSectorClassificationOnFace extends PolyhedralBoundedSolidOperator{    public static final int ABOVE = 1;    public static final int BELOW = -1;    public static final int ON = 0;    public static final int AinB = 11;    public static final int AoutB = 12;    public static final int BinA = 13;    public static final int BoutA = 14;    public static final int AonBplus = 15;    public static final int AonBminus = 16;    public static final int BonAplus = 17;    public static final int BonAminus = 18;    public static final int COPLANAR_FACE = 10;    public static final int INPLANE_EDGE = 20;    public static final int CROSSING_EDGE = 30;    public static final int UNDEFINED = 40;    public _PolyhedralBoundedSolidHalfEdge sector;    public InfinitePlane referencePlane;    public int cl;    // Following attributes are not taken from [MANT1988], and all operations    // on them are fine tunning options aditional to original algorithm.    public boolean isWide = false;    public Vector3D position;    public int situation = UNDEFINED;    public boolean reverse = false;    public _PolyhedralBoundedSolidSetOperatorSectorClassificationOnFace()    {        ;    }    public _PolyhedralBoundedSolidSetOperatorSectorClassificationOnFace(_PolyhedralBoundedSolidSetOperatorSectorClassificationOnFace other)    {        this.sector = other.sector;        this.referencePlane = other.referencePlane;        this.cl = other.cl;        this.isWide = other.isWide;        this.position = other.position;        this.situation = other.situation;            this.reverse = other.reverse;    }    /**    Current method implements the set of changes from table [MANT1988].15.3.    for the edge reclassification rules for the third stage of a vertex/face    classifier.    */    public void applyRules(int op)    {        if ( op == UNION ) {            switch ( cl ) {              case AonBplus:     cl = AoutB;    break;              case AonBminus:    cl = AinB;    break;              case BonAplus:     cl = BinA;    break;              case BonAminus:    cl = BinA;    break;            }        }        else if ( op == INTERSECTION ) {            switch ( cl ) {              case AonBplus:     cl = AinB;    break;              case AonBminus:    cl = AoutB;    break;              case BonAplus:     cl = BoutA;    break;              case BonAminus:    cl = BoutA;    break;            }        }        else if ( op == DIFFERENCE ) {            switch ( cl ) {              case AonBplus:     cl = AinB;    break;              case AonBminus:    cl = AoutB;    break;              case BonAplus:     cl = BoutA;    break;              case BonAminus:    cl = BoutA;    break;            }        }    }    public void updateLabel(int BvsA)    {        InfinitePlane a = sector.parentLoop.parentFace.containingPlane;        InfinitePlane b = referencePlane;        if ( BvsA == 0 ) {            switch ( cl ) {              case ABOVE: cl = AoutB; break;              case BELOW: cl = AinB; break;              case ON:                if ( a.overlapsWith(b, VSDK.EPSILON) ) {                    cl = AonBplus;                }                else {                    cl = AonBminus;                }                break;            }        }        else {            switch ( cl ) {              case ABOVE: cl = BoutA; break;              case BELOW: cl = BinA; break;              case ON:                if ( a.overlapsWith(b, VSDK.EPSILON) ) {                    cl = BonAplus;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -