org.reprap.geometry.polygons
Class RrCSG

java.lang.Object
  extended by org.reprap.geometry.polygons.RrCSG

public class RrCSG
extends java.lang.Object

RepRap Constructive Solid Geometry class RrCSG: 2D polygons as boolean combinations of half-planes First version 14 November 2005


Field Summary
private  boolean beingDestroyed
          Flag to prevent cyclic graphs going round forever
private  RrCSG c1
          Non-leaf child operands
private  RrCSG c2
           
private  RrCSG comp
          The complement (if there is one)
private  int complexity
          How much is in here (leaf count)?
private  RrHalfPlane hp
          Leaf half plane
private static RrCSG n
          Null set
private  RrCSGOp op
          Type of set
private static RrCSG u
          Universal set
 
Constructor Summary
private RrCSG(boolean b)
          One off constructor for the universal and null sets
  RrCSG(RrCSG c)
          Deep copy
private RrCSG(RrCSG a, RrCSG b)
          Private constructor for common work setting up booleans
  RrCSG(RrHalfPlane h)
          Make a leaf from a single half-plane
 
Method Summary
 RrCSG c_1()
          Get children, operator etc
 RrCSG c_2()
           
private  RrCSG categorise(RrCSG leafA)
          This takes a complicated expression assumed to contain multiple instances of leafA and returns the equivalent CSG expression involving just leafA.
 RrCSG complement()
          Lazy evaluation for complement.
 int complexity()
           
private  RrCSG crossCategorise(RrCSG leafA, RrCSG leafB)
          This takes a complicated expression assumed to contain multiple instances of leafA and leafB and returns the equivalent CSG expression involving at most leafA and leafB once (except for non-manifold shapes).
 void destroy()
          Destroy me and all that I point to
static RrCSG difference(RrCSG a, RrCSG b)
          Set difference is intersection with complement
 RrCSG forceRegularise()
          Force an approximation to the regulariseing of a set This assumes simplify has been run over the set
static RrCSG intersection(RrCSG a, RrCSG b)
          Boolean operation to perform an intersection
 RrCSG leaf(Rr2Point p)
          leaf find the half-plane that generates the value for a point
static RrCSG nothing()
           
 RrCSG offset(double d)
          Offset by a distance (+ve or -ve) TODO: this should keep track of complements
 RrCSGOp operator()
           
 RrHalfPlane plane()
           
 RrCSG prune(RrRectangle b)
          Prune the set to a box
 RrCSG regularise()
          Regularise a set with simple contents ( <= 4 ) This assumes simplify has been run over the set
private  void replaceAllSameLeaves(RrCSG leaf, double tolerance)
          Replace duplicate of leaf with leaf itself TODO: this should also use known complements
static RrCSG RrCSGFromBox(RrRectangle b)
          Make a rectangle
private  void simplify_r(RrCSG root, double tolerance)
          Replace duplicate of all leaves with the last instance of each; also link up complements.
 RrCSG simplify(double tolerance)
          Replace duplicate of all leaves with the last instance of each
private  java.lang.String toString_r(java.lang.String result, java.lang.String white)
          Convert to a string
 java.lang.String toString()
           
static RrCSG union(RrCSG a, RrCSG b)
          Boolean operations, with de Morgan simplifications
private  void uniqueList_r(java.util.ArrayList<RrCSG> list)
          Run through a GSG expression looking at its leaves and return a list of the distinct leaves.
private  java.util.ArrayList<RrCSG> uniqueList()
          Run through a GSG expression looking at its leaves and return a list of the distinct leaves.
static RrCSG universe()
          Universal or null set
 double value(Rr2Point p)
          "Potential" value of a point; i.e.
 RrInterval value(RrRectangle b)
          The interval value of a box (analagous to point)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

u

private static final RrCSG u
Universal set


n

private static final RrCSG n
Null set


hp

private RrHalfPlane hp
Leaf half plane


op

private RrCSGOp op
Type of set


c1

private RrCSG c1
Non-leaf child operands


c2

private RrCSG c2

comp

private RrCSG comp
The complement (if there is one)


complexity

private int complexity
How much is in here (leaf count)?


beingDestroyed

private boolean beingDestroyed
Flag to prevent cyclic graphs going round forever

Constructor Detail

RrCSG

public RrCSG(RrHalfPlane h)
Make a leaf from a single half-plane

Parameters:
h -

RrCSG

private RrCSG(boolean b)
One off constructor for the universal and null sets

Parameters:
b -

RrCSG

public RrCSG(RrCSG c)
Deep copy

Parameters:
c -

RrCSG

private RrCSG(RrCSG a,
              RrCSG b)
Private constructor for common work setting up booleans

Parameters:
a -
b -
Method Detail

destroy

public void destroy()
Destroy me and all that I point to


universe

public static RrCSG universe()
Universal or null set

Returns:
universal or null set

nothing

public static RrCSG nothing()
Returns:
nothing/null set

c_1

public RrCSG c_1()
Get children, operator etc

Returns:
children

c_2

public RrCSG c_2()

operator

public RrCSGOp operator()

plane

public RrHalfPlane plane()

complexity

public int complexity()

toString_r

private java.lang.String toString_r(java.lang.String result,
                                    java.lang.String white)
Convert to a string

Parameters:
result -
white -
Returns:
string representation

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

union

public static RrCSG union(RrCSG a,
                          RrCSG b)
Boolean operations, with de Morgan simplifications

Parameters:
a -
b -
Returns:
union of passed CSG objects a and b

intersection

public static RrCSG intersection(RrCSG a,
                                 RrCSG b)
Boolean operation to perform an intersection

Parameters:
a -
b -
Returns:
intersection of passed CSG objects a and b

complement

public RrCSG complement()
Lazy evaluation for complement.

Returns:
complement

difference

public static RrCSG difference(RrCSG a,
                               RrCSG b)
Set difference is intersection with complement

Parameters:
a -
b -
Returns:
set difference as CSG object based on input CSG objects a and b

RrCSGFromBox

public static RrCSG RrCSGFromBox(RrRectangle b)
Make a rectangle


categorise

private RrCSG categorise(RrCSG leafA)
This takes a complicated expression assumed to contain multiple instances of leafA and returns the equivalent CSG expression involving just leafA.

Parameters:
leafA -
Returns:
equivalent CSG expression involving just leafA

crossCategorise

private RrCSG crossCategorise(RrCSG leafA,
                              RrCSG leafB)
This takes a complicated expression assumed to contain multiple instances of leafA and leafB and returns the equivalent CSG expression involving at most leafA and leafB once (except for non-manifold shapes).

Parameters:
leafA -
leafB -
Returns:
equivalent CSG expression involving at most leafA and leafB once

uniqueList_r

private void uniqueList_r(java.util.ArrayList<RrCSG> list)
Run through a GSG expression looking at its leaves and return a list of the distinct leaves. Note: leaf and leaf.complement() are not considered distinct. Recursive internal call.

Parameters:
expression -

uniqueList

private java.util.ArrayList<RrCSG> uniqueList()
Run through a GSG expression looking at its leaves and return a list of the distinct leaves. Note: leaf and leaf.complement() are not considered distinct.

Parameters:
expression -
Returns:

regularise

public RrCSG regularise()
Regularise a set with simple contents ( <= 4 ) This assumes simplify has been run over the set

Returns:
regularised CSG object

forceRegularise

public RrCSG forceRegularise()
Force an approximation to the regulariseing of a set This assumes simplify has been run over the set

Returns:
regularised CSG object

replaceAllSameLeaves

private void replaceAllSameLeaves(RrCSG leaf,
                                  double tolerance)
Replace duplicate of leaf with leaf itself TODO: this should also use known complements

Parameters:
leaf -
tolerance -

simplify_r

private void simplify_r(RrCSG root,
                        double tolerance)
Replace duplicate of all leaves with the last instance of each; also link up complements.

Parameters:
root -
tolerance -

simplify

public RrCSG simplify(double tolerance)
Replace duplicate of all leaves with the last instance of each

Parameters:
tolerance -
Returns:
simplified CSG object

offset

public RrCSG offset(double d)
Offset by a distance (+ve or -ve) TODO: this should keep track of complements

Parameters:
d -
Returns:
offset CSG object by distance d

leaf

public RrCSG leaf(Rr2Point p)
leaf find the half-plane that generates the value for a point

Parameters:
p -
Returns:
leaf?

value

public double value(Rr2Point p)
"Potential" value of a point; i.e. a membership test -ve means inside; 0 means on the surface; +ve means outside

Parameters:
p -
Returns:
potential value of a point

value

public RrInterval value(RrRectangle b)
The interval value of a box (analagous to point)

Parameters:
b -
Returns:
value of a box

prune

public RrCSG prune(RrRectangle b)
Prune the set to a box

Parameters:
b -
Returns:
pruned box as new CSG object