autocad nef polyhedron implementation

24
AutoCAD Nef Polyhedron Implementation Jeremy Tammik Institute of Computer Science and Applied Mathematics University of Bern, Neubr¨ uckstrasse 10, 3012 Bern, Switzerland http://www.iam.unibe.ch September 2007Abstract We present a didactical system for learning and exploring Nef poly- hedra and the implementation of an AutoCAD entity representing a Nef polyhedron. Architecture and features of the implementation and limitations of the CAD system are discussed and workarounds pre- sented. The underlying Nef polyhedron implementation and support algorithms are based on a cell decomposition representation. We also discuss the XML schema used to represent the Nef polyhedron and its cell decomposition and to store it in the CAD system. Keywords: Nef polyhedron, hyperplane arrangement, vertex enu- meration, halfspace, cell decomposition, Boolean expression, inter- section, union, binary space partitioning, ternary space partitioning, CD, CSG, BSP, TSP, polytope, W¨ urzburg structure, affine function, boundary representation, exact rational arithmetic, GMP, mpq, XML schema, AutoCAD, Autodesk, ObjectARX, ObjectDBX. Revised: October 2007, Bern 1

Upload: vanbao

Post on 10-Feb-2017

236 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: AutoCAD Nef Polyhedron Implementation

AutoCAD Nef Polyhedron Implementation

Jeremy TammikInstitute of Computer Science and Applied Mathematics

University of Bern, Neubruckstrasse 10, 3012 Bern, Switzerlandhttp://www.iam.unibe.ch

September 2007†

Abstract

We present a didactical system for learning and exploring Nef poly-hedra and the implementation of an AutoCAD entity representing aNef polyhedron. Architecture and features of the implementation andlimitations of the CAD system are discussed and workarounds pre-sented. The underlying Nef polyhedron implementation and supportalgorithms are based on a cell decomposition representation. We alsodiscuss the XML schema used to represent the Nef polyhedron and itscell decomposition and to store it in the CAD system.

Keywords: Nef polyhedron, hyperplane arrangement, vertex enu-meration, halfspace, cell decomposition, Boolean expression, inter-section, union, binary space partitioning, ternary space partitioning,CD, CSG, BSP, TSP, polytope, Wurzburg structure, affine function,boundary representation, exact rational arithmetic, GMP, mpq, XMLschema, AutoCAD, Autodesk, ObjectARX, ObjectDBX.

†Revised: October 2007, Bern

1

Page 2: AutoCAD Nef Polyhedron Implementation

Contents

1 Introduction 31.1 Motivation and Alternatives . . . . . . . . . . . . . . . 3

2 Nef Polyhedron Fundamentals 5

3 Nef Polyhedron Data Structures 73.1 Cell Decomposition CD . . . . . . . . . . . . . . . . . 83.2 Binary Construction Tree CSG . . . . . . . . . . . . . 83.3 Ternary Space Partitioning TSP . . . . . . . . . . . . 103.4 Wurzburg structure . . . . . . . . . . . . . . . . . . . 113.5 CD, CSG and TSP Commonalities . . . . . . . . . . . 12

3.5.1 Cells are specific Unions of Intersections . . . . 123.5.2 TSP is a Union of Intersections . . . . . . . . . 123.5.3 CD, CSG and TSP Conversions . . . . . . . . . 12

4 Functionality 124.1 Arrangement Manipulation . . . . . . . . . . . . . . . 134.2 Boolean Operations . . . . . . . . . . . . . . . . . . . 144.3 Visualisation . . . . . . . . . . . . . . . . . . . . . . . 14

4.3.1 Concrete Visualisation in 2D and 3D . . . . . . 144.3.2 Abstract Visualisation . . . . . . . . . . . . . . 144.3.3 Query Language . . . . . . . . . . . . . . . . . 15

5 Nef Polyhedron XML Format 155.1 XML Schema . . . . . . . . . . . . . . . . . . . . . . . 165.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 16

6 Nef Polyhedron Repository 16

7 User Interface 177.1 Standard AutoCAD Functionality . . . . . . . . . . . 177.2 Functionality . . . . . . . . . . . . . . . . . . . . . . . 177.3 Use Cases and Examples . . . . . . . . . . . . . . . . . 18

8 Architecture and Implementation 188.1 Programming Languages and Libraries . . . . . . . . . 188.2 AutoCAD API . . . . . . . . . . . . . . . . . . . . . . 198.3 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . 208.4 Design Issues and Solutions . . . . . . . . . . . . . . . 20

8.4.1 Handling Unbounded Cells . . . . . . . . . . . 20

2

Page 3: AutoCAD Nef Polyhedron Implementation

8.4.2 Triangulation of multi-vertex faces . . . . . . . 208.5 CAD System Features and Limitations . . . . . . . . . 20

8.5.1 Primitives . . . . . . . . . . . . . . . . . . . . . 218.5.2 Triangulation . . . . . . . . . . . . . . . . . . . 21

8.6 Robustness . . . . . . . . . . . . . . . . . . . . . . . . 228.6.1 Floating point number representation . . . . . 22

8.7 Performance . . . . . . . . . . . . . . . . . . . . . . . . 22

9 Future Plans 22

1 Introduction

This paper describes the current status of our work on a didacticalsystem for learning and exploring Nef polyhedra and representing Nefpolyhedra in a standard CAD system, AutoCAD. We discuss someNef polyhedron basics, the architecture, features and user interface ofthe implementation, limitations of the CAD system and workarounds,functionality and visualisation issues, software design and implemen-tation. The underlying Nef polyhedron implementation and supportalgorithms are based on a cell decomposition representation. We alsodiscuss the XML schema used to represent the Nef polyhedron and itscell decomposition and to store it in the CAD system.

1.1 Motivation and Alternatives

Standard CAD systems represent models of real objects such as ma-chinery and buildings. These models were historically mostly createdas 2D views similar to the traditional drawings used by architects andmechanical shops representing plan and elevation views and sections.Nowaday, many models are created directly as 3D models, allowingmuch simpler and safer automatic generation of all required 2D draw-ing views as well as analysis and simulation.

The 3D models can be managed in several different ways. Depend-ing on the focus of the underlying entities used to manage the 3Dmodel, the representations can be classified into wireframe, boundaryrepresentation and solid models. The wireframe representation usesone-dimensional elements, i.e. lines and curves, to represent the edgesand vertices of the 3D model and thus does not support shading orrendering. The boundary representation or B-rep is based on the two-dimensional surfaces of the model and supports shading and rendering

3

Page 4: AutoCAD Nef Polyhedron Implementation

rendering. Solid modeling manages the model element as real volumesand normally allows Boolean operations to be performed and real ma-chine processes to be simulated. Some solid modeling kernels makeuse of boundary representation to calculate and maintain solid andvolume information as well, so there is a certain amount of overlapbetween the latter two.

However, even in solid modeling, the objects being manipulatedand the operations performed on them are almost never handled ina mathematically exact way, which invariably leads to inconsistenciesand robustness problems. One reason for these problems is that almostall CAD systems completely ignore the boundaries of solids.

For instance, consider the case of two cubes just touching eachother, and subtracting one from the other. What is the result? Math-ematically speaking, it obviously depends on whether the cubes areopen or closed, i.e. whether they contain their respective boundariesor not.

Worse still, consider the intersection of the two touching cubes.The result might be anything between void, a two-dimensional surface,or a thin sliver of three-dimensional solid.

The problems also occur for less construed circumstances, such aswhen two objects almost touch each other, just intersect, or meet ata very sharp angle.

Both mathematicians and CAD implementors made various at-tempts at finding a definition for handling solids that is computable,robust and mathematically correct at the same time. This led toconstructs such as regularisation and regularised operators, where allpolyhedra are closed and each Boolean operation is followed by a clo-sure operation as well.

Also, independently of CAD modeling, mathematicians have ex-amined many different classes of polyhedra. For some of them. it issurprisingly difficult to give a consistent definition for a polyhedronface. Most of the polyhedron definitions are not closed with respectto the elementary Boolean set operations.

Simply speaking, the requirement is for a class of geometrical ob-jects which is a closed group respective to the Boolean set operationsunion, intersection, complement and difference.

Enter Walter Nef in 1978 with a goal to discuss polyhedra and ap-plications in computer graphics. The Nef polyhedra introduced by Nef[21] are closed with respect to the elementary Boolean set operationsas well as all topological operations.

4

Page 5: AutoCAD Nef Polyhedron Implementation

2 Nef Polyhedron Fundamentals

Many different definitions of polyhedra have been given. Most of theseare not closed with respect to the elementary Boolean set operations.Nef polyhedra, however, introduced by Nef [20], are closed with respectto the elementary Boolean set operations as well as all topologicaloperations. They are more general than elementary polyhedra andpolyhedral sets.

Definition 1 (Nef Polyhedron) A Nef polyhedron P is a subset ofRd generated by applying set intersection and complement operationsto a finite number of open halfspaces. These halfspaces are called thegenerating halfspaces of P .

Set union and difference can be reduced to intersection and com-plement. Thus the class of Nef polyhedra is closed with respect tothe Boolean set operations cpl, ∩, ∪ and \. In this paper, we assumeEuclidian topology throughout. Set complement converts open half-spaces to closed ones and vice versa. From this it can be shown thatthe class of Nef polyhedra is also closed with respect to the topologi-cal set operations closure clos, interior int, exterior ext, and boundarybnd. The regularisation [22] of a Nef polyhedron P is a Nef polyhedrontoo, since it is defined as clos(intP ). Nef polyhedra need be neitherclosed nor bounded, and ∅ and Rd are both valid Nef polyhedra.

Nef polyhedra are natural generalisations of several familiar kindsof polyhedra. A convex polytope in Rd is the convex hull of a non-empty finite set of points in Rd [15]. It is closed and bounded andcan always be represented as the intersection of a finite number ofclosed linear halfspaces and is thus a Nef polyhedron. An elementarypolyhedron is defined as a union of a finite number of convex polytopes[15], and is therefore also a Nef polyhedron. A polyhedral set in Rd

is the intersection of a finite number of closed linear halfspaces and isthus a Nef polyhedron.

For a convex polytope, the definition of its faces is straight-forward[9], but it is less obvious for more general polyhedra. The elegant andpowerful definition presented by Nef [20] is based on the local pyramid,which helps capture the local view of the polyhedron from a givenpoint.

Definition 2 (Cone, Nef Pyramid) A point set C ⊆ Rd is a conewith apex 0 if C = R+C, i.e. λp ∈ C for all p ∈ C and λ > 0. C is

5

Page 6: AutoCAD Nef Polyhedron Implementation

a cone with apex x if C = x+ R+(C − x). A cone C which is also aNef polyhedron is called a Nef pyramid.

Using the concept of the Nef pyramid, we can capture the localview of a Nef polyhedron from a given point.

Definition 3 (Local Pyramid) Let P ⊆ Rd be a Nef polyhedronand x ∈ Rd. Then a neighbourhood U0(x) exists such that the Nefpyramid Q := x+ R+((P ∩U)− x) is identical for all neighbourhoodsU ⊆ U0(x). Q is called the local pyramid of P in x and is denoted byP x.

An equivalent alternative definition of the local pyramid P x of Pin x can be obtained recursively as follows:

• For an open halfspace P , define P x by setting

P x =

Rd if x ∈ intP = PP if x ∈ bndP∅ if x ∈ extP

• For any other Nef polyhedron P , P x is uniquely determined byapplying (repeatedly, in general) the rules (closP )x = closP x,(P1∩P2)x = P x

1 ∩P x2 , and analogously for the other Boolean set

operations.

Intuitively spoken, the local pyramid describes what the Nef poly-hedron looks like at a given point in space to an infinitely shortsightedobserver. Using the local pyramid of each point to define an equiv-alence relation on Rd, we arrive at the definition of Nef polyhedronfaces.

Definition 4 (Face) Let P ⊆ Rd be a Nef polyhedron and x, y ∈ Rd

two points. We define an equivalence relation x ∼ y iff P x = P y. Theequivalence classes of ∼ are the faces of P . The dimension of a faceF is the dimension of its affine hull, dimF := dim aff F .

Based on this definition, a face F of a Nef polyhedron P is themaximal non-empty set whose points all have the same local pyramid,which we denote as PF , and is defined based purely on local propertiesof P . Every face of a Nef polyhedron is a Nef polyhedron as well.Every face is either contained in P or disjoint from it. Faces are

6

Page 7: AutoCAD Nef Polyhedron Implementation

not necessarily connected. The number of faces of a Nef polyhedron isfinite. They form a partition of Rd. The only possible full-dimensionalfaces are the interior and exterior of P , if they are non-empty, withthe local pyramids Rd and ∅ respectively. All lower-dimensional facesform the boundary of P . All faces except extP are called properfaces. Together, they form a partition of closP . For a more detailedpresentation and further properties of local pyramids and faces, pleaserefer to [20] and [5]. A zero-dimensional face is called a vertex, anda one-dimensional one an edge. All faces are relatively open sets, i.e.open relative to the smallest containing affine subspace, e.g. an edgedoes not contain its end vertices, and a two-dimensional face doesnot contain its edges. For two faces F and G of P , we have eitherF ∩ closG = ∅ or F ⊆ closG.

Definition 5 (Incidence) A face F of a Nef polyhedron P is left-incident to a face G of P iff F ⊂ closG. This defines a partial ordering≺ such that F ≺ G iff F is left-incident to G.

For non-empty bounded Nef polyhedra, the minimal elements of≺ are always vertices. For unbounded polyhedra, some or all will behigher-dimensional faces. This is also valid for exceptional cases suchas Rd \ {x}.

3 Nef Polyhedron Data Structures

A number of different representation schemes can be used for Nefpolyhedra. The binary construction tree or CSG model, when usedfor Nef polyhedra, is based directly on Definition 1, using the Booleanexpression of open halfspaces. The cell decomposition CD is based ona set containing all the cells of a hyperplane arrangement and a selec-tion function specifying for each cell whether or not it belongs to thepolyhedron in question. The ternary space partitioning or TSP tree issimilar to a binary space partitioning or BSP tree [18], except that eachnode splits the subset of Rd currently under consideration into threesubsets above, below and contained in a given hyperplane. These rep-resentations can be termed classical in the sense that they have beenused in different contexts independently of and prior to the conceptof Nef polyhedra. Beside the classical Nef polyhedra representations,the Wurzburg structure or W-structure was proposed specifically forstoring Nef polyhedra.

7

Page 8: AutoCAD Nef Polyhedron Implementation

All the representations discussed in this paper have been imple-mented in the Python programming language [23]. We also defined anXML schema for storing examples of these representations in a reposi-tory together with some known values that can be used for comparisonand testing purposes.

3.1 Cell Decomposition CD

The cell decomposition representation of a Nef polyhedron consistsof two elements: a hyperplane arrangement A(H) and a selectionfunction ϕ specifying for each cell whether or not it belongs to thepolyhedron in question. Please note that the dimension of a cell oftendiffers from the dimension of the Nef polyhedron face that the cell isa subset of. For instance, a one-dimensional Nef polyhedron face maywell consist of multiple cells, some of which may be zero-dimensional.A pleasing aspect of the CD is that given a Nef polyhedron and a mini-mal compatible hyperplane arrangement, the resulting CD is uniquelydetermined, whereas the CSG and TSP representations are not.

Example 1 (Triangle CD) A closed triangle in R2 between the ver-tices (0,0), (2,0) and (0,2).

The 3 hyperplanes required are defined as h0 = (0, 1, 0), h1 =(0, 0, 1) and h2 = (2,−1,−1). Remember, the last two hyperplanecoefficients represent the hyperplane normal vector, and its first co-efficient is the distance of the hyperplane to the origin multiplied bythe norm of the hyperplane normal, both of which are equal to

√2 in

this case. The resulting zero-dimensional cells are (0,0,+), (+,0,0) and(0,+,0), which map to the integer numbers 2, 18 and 6, respectively.The one-dimensional cells are (0,+,+), (+,0,+) and (+,+,0), mappingto 8, 20 and 24, respectively. Finally, the single two-dimensional cell is(+,+,+) which maps to 26. All other location vectors represent eithercells not belonging to the closed triangle or invalid, i.e. empty, cells.The Python representation of this Nef polyhedron CD is simply

[[2, 6, 18], [8, 20, 24], [26]].

3.2 Binary Construction Tree CSG

A CSG representation of a Nef polyhedron is a Boolean expressionof hyperplanes and halfspaces. It can be normalised into a canocicalform, such as a union of intersections

8

Page 9: AutoCAD Nef Polyhedron Implementation

Example 2 (Square CSG) The open and closed unit squares in R2.

Given the four hyperplanes (0, 1, 0), (0, 0, 1), (1,−1, 0) and (1, 0,−1)in R2, we can define the open unit square using the Boolean expression

H+0 ∩H+

1 ∩H+2 ∩H+

3 ,

which can be written as either

H0+ * H1+ * H2+ * H3+

or P0 * P1 * P2 * P3 in our grammar. The union of intersectionsgenerated for this simple convex shape consists on one single intersec-tion and is encoded as [04444] using octal notation to represent theinteger number. The closed unit square can be represented as

(P0 + Z0) * (P1 + Z1) * (P2 + Z2) * (P3 + Z3)

and produces the union of intersections [05555]. Generally speak-ing, the optimal union of intersections representing any open convexpolyhedron defined by the intersection of n open halfspaces consists ofa list with the single n-digit octal number 04 . . . 4, whereas the equiv-alent closed convex polyhedron defined by the intersection of n closedhalfspaces can be represented as the list containing the n-digit octalnumber 05 . . . 5.

Example 3 (Square Hole CSG) A non-convex example in R2 is a3 by 3 square with a 1 by 1 square hole in it, with several differentrepresentation possibilities.

Define 8 hyperplanes by

{H0, . . . ,H7} = { (0, 1, 0), (3,−1, 0), (0, 0, 1), (3, 0,−1),(1,−1, 0), (−2, 1, 0), (1, 0,−1), (−2, 0, 1) }.

Then one possible Boolean expression describing an open 3 by 3square with a 1 by 1 square hole in it is given by

H+0 ∩H+

1 ∩H+2 ∩H+

3 ∩(H+

4 ∪ ((H−4 ∪H04 ) ∩ (H+

5 ∪ ((H−5 ∪H05 ) ∩ (H+

6 ∪ (H−6 ∩H+7 ))))))

9

Page 10: AutoCAD Nef Polyhedron Implementation

One possible Boolean expression describing the closed version ofthe same shape is given by simply enclosing the entire expression in theclos() operator. Two different union of intersection representationsfor the closed shape are

[055555777, 055557577, 055557757, 055557775]

with four non-disjoint overlapping intersections, and

[055555777, 055557577, 055553357, 055553375]

where the four intersections still overlap, but only in 1-dimensionalareas.

3.3 Ternary Space Partitioning TSP

A binary space partitioning or BSP tree recursively subdivides Rd orsubsets of it. It is a binary tree whose non-leaf nodes are labeled withhyperplanes and whose leaves correspond to cells of a convex polyhe-dral partitioning of Rd, providing a recursive, hierarchical, volumetricrepresentation of general linear polyhedra. It provides a basis for rapidanalysis and classification algorithms and other operations [18]. Forthe handling of Nef polyhedra, where equal attention is paid to thelower-dimensional facets as to the d-dimensional ones, the structureneeds to be enhanced to handle all three locations relative to eachhyperplane. This leads us to the definition of a ternary space parti-tioning or TSP tree.

Definition 6 (TSP) Let R be a subset of Rd. A ternary space parti-tioning or TSP of R is a ternary tree T representing a certain subsetof R. If T has the value True, it represents R itself. If T has the valueFalse, it represents the empty set ∅. Otherwise, T is labeled with ahyperplane H and contains three subtrees T 0, T− and T+ representingthe subsets of R contained in each of the three locations in, below andabove H, respectively. The classification function ψ associated with Tis a mapping ψ : R→ {False, T rue} defined for any x ∈ R by return-ing the value of the leaf node representing the subset of R containingx.

When used to represent a Nef polyhedron defined by an arrange-ment of n hyperplanes, the depth of the resulting TSP tree will never

10

Page 11: AutoCAD Nef Polyhedron Implementation

exceed n. The TSP tree is not uniquely defined by the Nef polyhe-dron, however, and the definition and calculation of an optimal TSPtree is a non-trivial task [19].

Example 4 (Triangle TSP) A triangle in R2 between the vertices(0,0), (2,0) and (0,2) with its interior and its edges but without itsvertices (cf. Example 1 above).

It does therefore not include the zero-dimensional cells, only thetwo-dimensional cell 26 = ι(+,+,+) and the one-dimensional cells 8= ι(0,+,+), 20 = ι(+, 0,+) and 24 = ι(+,+, 0). The correspondingTSP tree can be represented as

H0 0: H1 +: H2: +: **+: H1 0: H2: +: **

+: H2: 0: **+: **

In this representation, the leaf nodes marked False are simplyomitted, and the ones marked True are displayed using two asterisks**. The raw Python representation of this Nef polyhedron TSP is

[0, [1, False, False, [2, False, False, True]],False,[1, [2, False, False, True],

False,[2, True, False, True]]]

3.4 Wurzburg structure

The Wurzburg structure or W-structure was proposed specifically forstoring Nef polyhedra by Bieri and Nef [3]. It stores all Nef polyhe-dron faces using their local pyramids, but lacks information about therelationships between the different local pyramids. It was enhancedby the introduction of the extended Wurzburg structure, which man-ages incidences for that purpose. Finally, the completeness of the datastructure does not require all faces’ local pyramids, but only those ofthe minimal elements in the incidence relation ≺, which led to thereduced Wurzburg structure [6].

11

Page 12: AutoCAD Nef Polyhedron Implementation

3.5 CD, CSG and TSP Commonalities

The CD representation is a very simple representation of a Nef poly-hedron. Furthermore, if the hyperplane arrangement used to define aNef polyhedron is minimal and the hyperplanes and cells are sortedlexicographically, the CD representation is unique. Possibly, the de-termination of Nef polyhedron faces, i.e. local pyramids, requires theuse of a CD representation in any case. This section discusses some ofthe obvious similarities and relationships between the three classicalrepresentation formats.

3.5.1 Cells are specific Unions of Intersections

3.5.2 TSP is a Union of Intersections

Each leaf node of a TSP tree can be represented as an intersection oflocations. Each intermediate node moving from the tree root towardsthe leaf defines one specific location for the hyperplane associatedwith the intermediate node. If the value of the leaf node is false,no contribution to the union is defined. Otherwise, an intersectionincluding all three locations for all hyperlanes not specified by theintermediate nodes is added to the union.

3.5.3 CD, CSG and TSP Conversions

The conversions between the CD and CSG and between the CD andTSP representations have been outlined by Bieri [7]. We spent somework creating working implementations of them in Python.

4 Functionality

The purpose of our Nef polyhedron implementation is mainly didac-tical. For this, we need to implement all the standard and expectedfunctionality in an intuitively accessible manner. As far as possible, weensure that our Nef polyhedra fit into and match the standard CADsystem behaviour. The following Nef polyhedron specific behaviour isimplemented in addition to the standard CAD functionality.

• Queries: retrieve Nef polyhedron faces and volume and boundingbox for bounded polyhedra.

12

Page 13: AutoCAD Nef Polyhedron Implementation

• Arrangement manipulation: addition of hyperplanes is requiredto implement the Boolean operations, removal is useful and canform the base of a CD representation optimisation and normali-sation.

• Boolean operations: standard Boolean set operations union, in-tersection, difference and complement, implemented on the basisof the CD representation.

• Visualisation: concrete 2D and 3D in the CAD system, abstractvisualisation of graph structure, specialised query language.

• Repository: storage, XML schema.

4.1 Arrangement Manipulation

We need various possibilities to analyse and manipulate the hyper-plane arrangement. For instance, the implementation of Boolean op-erations requires

• sorting,

• addition and

• removal of arrangement hyperplanes.

Sorting of hyperplanes is useful to normalise the CD representa-tion of a Nef polyhedron. We simply sort the hyperplanes lexicograph-ically. This simplifies the process of determining which hyperplanesare common to two given arrangements, and which are missing fromone or the other. Obviously, all the internal data structures used todefine the CD selection function may need updating to reflect the newhyperplane ordering as well.

Addition of new hyperplanes to a given arrangement is requiredin order to perform Boolean operations. A simple way to implementBoolean operations based on the CD representation is to make the twoarrangements used for the two operands compatible with each otherby adding hyperplanes to each of the first operands arrangements untilthey both use the same set of hyperplanes. Then, the implementationof the Boolean operation is a simple function of the two operands’selection functions.

Removal of redundant hyperplanes from an arrangement is an im-portant step required for the optimisation of the Nef polyhedron CDrepresentation. For instance, the CD arrangement of a Nef polyhedron

13

Page 14: AutoCAD Nef Polyhedron Implementation

representing ∅ or Rd should have zero hyperplanes, and one represent-ing a single point should have exactly d.

4.2 Boolean Operations

The Boolean operations are implemented by making use of the Nefpolyhedron CD representation and the hyperplane arrangement ma-nipulation functionality. The two operands’s arrangements are en-hanced and sorted to make them identical, and then the selectionfunction of the result is a simple combination of the two operands’selection functions.

Given two Nef polyhedra with selection functions ϕ1 and ϕ2, theselection function φ of their union is given by

ϕ(c) ={

1 if ϕ1(c) = 1 or ϕ2(c) = 10 otherwise

for any cell c in their common arrangement. Analogous formulaeapply for the selection functions of their intersection, difference andcomplement.

4.3 Visualisation

Nef polyhedra are defined for arbitrary dimensions. Standard CADsystems support only 2D and 3D. We can make use of some standardCAD system functionality for displaying two- and three-dimensionalNef polyhedra. For higher dimensions, we need to resort to othertechniques.

4.3.1 Concrete Visualisation in 2D and 3D

Since a CAD system does not differentiate between open and closedobjects, or relatively open and clsed faces on a polyhedron, we haveto introduce custom glyphs to denote these attributes.

4.3.2 Abstract Visualisation

We can list the Nef polyhedron faces and other attributes in vari-ous manners, iterate the graph, implement specialised queries, displaysection views.

14

Page 15: AutoCAD Nef Polyhedron Implementation

4.3.3 Query Language

Design and implement a query language such asdisplay—hide—select—highlight all [k-dimensional] [[non]minimal—maximal]

[bounded—unbounded] faces [containing—intersecting point—line—...]for ¡face¿ display sub- and superincident faces ...

• action: display, hide, select, highlight

• face of dimension k

• (not) minimal or maximal

• (not) bounded or unbounded

• (not) containing or intersecting a given point or line

• closest to or farthest away from a given point or line

• (not) with a given number m of sub- or superincident faces

• measure of face in subspace spanned (e.g. length, area, volumeetc.) is greater than or less than or equal to given number, ormaximal or minimal

• act on the sub- and superincident faces of the selected face orfaces

• act on the directly connected sibling faces, for instance all neigh-bour faces of the selected face or faces

• specify a specific colour or linetype for selection?

Model on sql? xml-query?Can we use xml query on our xml schema?This is a hybrid view ... abstract ideas can be graphically dis-

played.

5 Nef Polyhedron XML Format

We have implemented an XML schema for the storage of the CD rep-resentation of Nef polyhedra. We examined a more complex schemasupporting multiple parallel representations in a previous paper in-volving the conversion betweeen the different Nef polyhedron repre-sentations, but currently we are dealing with CD only. In additionto the pure CD representation, we also maintain a transformationmatrix to enable simple transformations to be performed on the Nefpolyhedronentity without necessitating a complete recalculation of thearrangement.

15

Page 16: AutoCAD Nef Polyhedron Implementation

5.1 XML Schema

5.2 Example

Here is an example of a simple Nef polyhedron CD representationencoded usnig the XML schema described above:

<?xml version="1.0"?><nefpolyhedron xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="np.xsd"><representation><cell_decomposition><rational_hyperplanes><rational_hyperplane>1 2/3 0 1</rational_hyperplane><rational_hyperplane>2 -1/3 1/4 -2</rational_hyperplane><rational_hyperplane>1 -2 0 -3</rational_hyperplane><rational_hyperplane>1/2 -1/2 -5 -3/5</rational_hyperplane>

</rational_hyperplanes></cell_decomposition>

</representation><transmatrix><row>1.1 2.0 -9.0 2.5</row><row>-5.5 1.2 -6.7 -3.3</row><row>0.7 -2.4 5.9 -1.1</row><row>2.3 2.9 10.7 8.1</row>

</transmatrix></nefpolyhedron>

6 Nef Polyhedron Repository

Our Nef polyhedron repository includes a sample set of standard poly-hedra with a browsing functionality and descriptions of each. Poly-hedra can be selected, added to the current model, and used in thecreation of new polyhedra. New polyhedra can easily be added to therepository.

The repository contents include several attributes such as name,abbreviation, description, dimension, face count for each dimensionand total number of faces, number of hyperplanes in its arrangement,links to other representations of the same Nef polyhedron, etc. Theseattributes can be used to query the repository for specific Nef polyhe-dra.

We include a number of primitive bodies in the repository, amongothers the Platonic bodies tetrahedron, cube, octahedron, icosahe-

16

Page 17: AutoCAD Nef Polyhedron Implementation

dron, dodecahedron. Some other regular polytopes we might add arethe cubeoctahedron and icosidodecahedron. Why not go for the fullrange of Archimedean solids, i.e. cubeoctahedron, great rhombicosi-dodecahedron, great rhombicuboctahedron, icosidodecahedron, smallrhombicosidodecahedron, small rhombicuboctahedron, snub cube, snubdodecahedron, truncated cube, truncated dodecahedron, truncatedicosahedron, truncated octahedron, truncated tetrahedron, and theCatalan solids rhombic dodecahedron, disdyakis triacontahedron, dis-dyakis dodecahedron, rhombic triacontahedron, deltoidal hexeconta-hedron, deltoidal icositetrahedron, pentagonal icositetrahedron, pen-tagonal hexecontahedron, triakis octahedron, triakis icosahedron, pen-takis dodecahedron, tetrakis hexahedron, triakis tetrahedron.

:-)

As said, new Nef polyhedra can be added by the user.

7 User Interface

The Nef polyhedron implementation in AutoCAD makes use of thenormal AutoCAD user interface, which includes standard WindowsUI components such as application windows and frames, applicationand context menus, tooltips, and dialogue boxes.

7.1 Standard AutoCAD Functionality

AutoCAD implements all the standard functionality expected in aCAD system, such as

• loading and saving files

• exporting to various file formats

• viewport, window and view manipulation

• navigation such as pan and zoom

• transformations such as move, scale and rotate

• help system

7.2 Functionality

In addition to the standard CAD system functionality, we require anumber of Nef polyhedron specific features, such as

17

Page 18: AutoCAD Nef Polyhedron Implementation

• Create new halfspace or plane Nef polyhedron

• Add or remove selected Nef polyhedronface or CD cell

• Boolean operations: union, intersect, subtract

• Extrude

• View all combinations of 0, 1, 2 or 3 dimensional faces

• Query point in polyhedron, both 2d and 3d

• Save to and restore from an external XML file

• Implement repository management

• Implement configurable tooltips

7.3 Use Cases and Examples

8 Architecture and Implementation

8.1 Programming Languages and Libraries

Our implementation is split into a number of separate componentsmaking use of

• C++, C# and the AutoCAD API

• Python and boost python, a C++ Python interface

• A Python hyperplane arrangement calculation implementation

• The Parma Polyhedra Library PPL

• CDD, a C implementation of the Double Description Method ofMotzkin et al.

• The GMP and CORE exact arithmetic libraries

• xerces-c for XML

C++, C# and the AutoCAD API are used to implement a customentity in AutoCAD and make use of its user interface and databasemanagement. Python is used to implement the hyperplane arrang-ment algorithm used for the cell decompositionn, and the Boost C++template library is used to connect the C++ and Python modules. TheGMP and CORE exact arithmetic libraries are required for the num-ber representation for the hyperplane arrangment calculations. Theexact numbers are converted to floating point before being passed

18

Page 19: AutoCAD Nef Polyhedron Implementation

to AutoCAD. PPL, CDD, GMP and CORE are all compiled underCygwin and used by the Python hyperplane arrangement calculationimplementation, which in turn is used by the AutoCAD custom entityimplementation.

8.2 AutoCAD API

We implement an AutoCAD custom entity to represent Nef polyhedra.An AutoCAD custom entity can be added at runtime to the classesmanaged by the AutoCAD database and appears to AutoCAD justlike any built-in object. The AutoCAD environments supporting thisare

• ObjectARX, the AutoCAD Runtime Extension, and

• ObjectDBX, the AutoCAD Database Extension.

Applications making use of ObjectARX are tied to AutoCAD itselfand cannot run in any other environment. Applications using onlyObjectDBX, on the other hand, which is a subset of ObjectARX,can be hosted by any DBX host application and therefore loaded byother applications except AutoCAD, including simple command lineapplications using RealDWG to manipulate the AutoCAD drawingfiles outside of AutoCAD.

Within these environments, a number of libraries are providedwhich AutoCAD applications or custom object enablers can make useof, such as

• AcDb - Database

• AcEd - Editor

• AcGi - Graphics Interface

• AcGe - Geometry

• AcRx - Runtime Extension

When defining a custom AutoCAD object, it is customary and ad-visory to implement an object enabler for it, i.e. a minimal ObjectDBXapplication which enables AutoCAD or any other DBX host applica-tion to load the custom object, read and write its data and displaythe entity graphics. Some limited user interaction is also supported,such as list, snap, grip, stretch, transform.

Accordingly, we have implemented an ObjectDBX object enablerfor our custom Nef polyhedron object.

19

Page 20: AutoCAD Nef Polyhedron Implementation

An object enabler has no user interface.The easiest way nowadays to work with user interfaces for Windows

applications is provided by the .NET environment.The various components of our AutoCAD Nef polyhedron imple-

mentation are

• Hyperplane arrangement calculation in Python.

• Custom entity object enabler in C++ ObjectDBX.

• Custom entity .NET wrapper in mixed mode C++.

• COM property provider in C++.

• GUI in AutoCAD.NET C#.

8.3 Interface

8.4 Design Issues and Solutions

• Handling unbounded cells.

• Triangulation of multi-vertex faces.

• Handling of subentity markers.

8.4.1 Handling Unbounded Cells

The implementation module intersects the unbounded Nef polyhe-dron with a maximal bounding box before returning the data to theJtNefPoly implementation, so the CAD system is always workingwith bounded data exclusively.

8.4.2 Triangulation of multi-vertex faces

The implementation module triangulates all faces of the Nef polyhe-dron with more than four vertices before returning the data to theJtNefPoly implementation, so the CAD system is always workingwith faces with three or four vertices exclusively.

8.5 CAD System Features and Limitations

We are using a standard 3D CAD system, AutoCAD, from AutodeskInc.1, to display and manipulate Nef polyhedra. We make use of thefollowing features.

1AutoCAD is a registered trademark of Autodesk Inc.

20

Page 21: AutoCAD Nef Polyhedron Implementation

• ObjectDBX object enabler.

• AutoCAD.NET managed API.

• The AutoCAD Object Property Manager OPM.

• The AutoCAD Graphics Interface AcGi.

• Object snap points.

• Subentity markers.

• Custom tooltips.

In order to represent Nef polyhedra in AutoCAD, a number oflimitations need to be addressed.

• Faces with more than four vertices must be triangulated.

• Unbounded faces are not supported.

• No 3D cell primitive is provided.

• Floating point number representation.

8.5.1 Primitives

We implement a custom entity JtNefPoly using ObjectARX and Ob-jectDBX technology. The custom entity defines its graphical represen-tation using the AutoCAD Graphics Interface AcGi. AcGi providesthe folowing primitives:

• Primitives for points, lines and faces are provided.

• Unbounded lines and rays are supported.

Using a standard 3D CAD system and its predefined paradigms todisplay Nef polyhedra is no trivial task. We need to differentiate be-tween the 2D and 3D faces of the polyhedron, where the CAD systemdefines no method except specification of a collection of 2D faces torepresent a 3D face. How do we differentiate between our polyhedron’sreal 2D faces and the ones we just use as a workaround to representits 3D faces?

8.5.2 Triangulation

Faces with more than four vertices are supported, but corrupt thesubentity markers, so we cannot use them.

21

Page 22: AutoCAD Nef Polyhedron Implementation

8.6 Robustness

8.6.1 Floating point number representation

Our calculations for the abstract Nef polyhedron rely on exact arith-metic, whereas the CAD system uses a 64-bit floating point numberrepresentation. The internal exact number representation is convertedto floating point before transferring the data to the CAD system.

8.7 Performance

The performance depends largely on the hyperplane arrangement cal-culations, which in turn depend on the arithmetic kernel used.

The performance could be speeded up by reimplementing the en-tire algorithm in C++ instead of Python, avoiding the communicationoverhead between the separate C++ and Python components.

9 Future Plans

Minkowsky sum, triangulation, optimisation of CSG and TSP treesand Boolean expressions, more work on conversion functions and W-structure representation.

References

[1] D. Avis, [email protected]: lrslib, a Reverse Search Vertex Enu-meration Program. http://cgm.cs.mcgill.ca/~avis/lrs.html

[2] D. Avis, K. Fukuda: A Pivoting Algorithm for Convex Hullsand Vertex Enumeration of Arrangements and Polyhedra. Dis-crete and Computational Geometry, Vol. 8, pp. 295-313, 1992.http://cgm.cs.mcgill.ca/~avis/doc/avis/AF92b.ps

[3] H. Bieri and W. Nef: Elementary Set Operations with d-dimensional Polyhedra. in H. Noltemeier (ed.), ComputationalGeometry and its Applications, Lecture Notes in Computer Sci-ence 333, pp. 97-112. Springer, 1988.

[4] H. Bieri: Boolean and Topological Operations for Nef Polyhedra.CSG 94 Set-theoretic Solid Modelling: Techniques and Applica-tions, pp. 35-53. Information Geometers, 1994.

22

Page 23: AutoCAD Nef Polyhedron Implementation

[5] H. Bieri: Nef Polyhedra: A Brief Introduction. Geometric Mod-elling – Dagstuhl 1993 (Hagen, Farin, Noltemeier, eds.), pp. 43-60. Springer, Wien, New York, 1995.

[6] H. Bieri: Two Basic Operations on Nef Polyhedra. CSG 96 Set-theoretic Solid Modelling: Techniques and Applications, pp. 337-356. Information Geometers, Winchester, 1996.

[7] H. Bieri: Representation Conversions for Nef Polyhedra. Com-puting [Suppl] 13, pp. 27-38. Springer, Wien, 1998.

[8] Bremner, Fukuda and Marzetta: pd, Primal-Dual Method.http://www.cs.unb.ca/profs/bremner/pd/

[9] A. Brønsted: An Introduction to Convex Polytopes. Springer,Berlin, Heidelberg, New York, 1983.

[10] H. Edelsbrunner, J. O’Rourke, and R. Seidel: Constructing Ar-rangements of Lines and Hyperplanes with Applications. SIAMJ. Comput. 15 (1986), pp. 341-363.

[11] H. Edelsbrunner: Algorithms in Combinatorial GeometrySpringer, Berlin, Heidelberg, New York, Tokyo, 1987.

[12] K. Fukuda, <[email protected]>: cddlibhttp://www.ifor.math.ethz.ch/staff/fukuda/fukuda.html

[13] K. Fukuda: Polyhedron FAQ pagehttp://www.ifor.math.ethz.ch/staff/fukuda/polyfaq/polyfaq.html

[14] Granados, Hert, Kettner, Seel: Boolean Operations on 3D Sur-faces Using Nef Polyhedra.

[15] B. Grunbaum: Convex Polytopes. John Wiley, London, 1967.

[16] Markus Holtz, Universitat Bonn: Valuation of performance-dependent options Part II: Dimension reduction by orthantdecomposition of hyperplane arrangements.http://wwwmaths.anu.edu.au/events/sy2005/program-hda.html#Holtz

[17] K. G. Murty: Linear Programming. Whiley & Sons, New York,1983.

[18] B. Naylor, W. Thibault: Set Operations on Polyhedra UsingBinary Space Partitioning Trees. Computer Graphics, Volume21, Number 4, July 1987.http://www.cs.utexas.edu/users/naylor/papers/BSPTree-Setops.pdf

[19] B. Naylor: Constructing Good Partitioning Trees.http://www.graphicsinterface.org/pre1996/93-Naylor.pdf

23

Page 24: AutoCAD Nef Polyhedron Implementation

[20] W. Nef: Beitrage zur Theorie der Polyeder mit Anwendungen inder Computergraphik (Contributions to the Theory of Polyhedrawith Applications in Computer Graphics). Herbert Lang Cie AG,Bern, 1978.

[21] P. Peterson, <[email protected]>: Polyhedron, a Python C/API In-terface for cddlib. http://cens.ioc.ee/projects/

[22] A. Requicha: Representations of rigid solids: Theory, methods,and systems. ACM Computing Surveys, 12(4):437464, December1980.

[23] G. v. Rossum: Python. http://www.python.org/

[24] J. Tammik: jarrangement, a Python and ANSI C Implemen-tation of the Edelsbrunner Hyperplane Arrangement Algorithm.https://sourceforge.net/projects/jarrangement/

[25] J. Tammik: ncubegen, N-Dimensional Nef Polyhedron Cube Gen-eration. February 2005, Unpublished.

[26] J. Tammik: nprismgen, N-Dimensional Nef Polyhedron Tetrahe-dron Generation. February 2005, Unpublished.

[27] H. Thompson, R. Tobin: xsv, XML Schema Validator. April 2005,http://www.ltg.ed.ac.uk/software/xml/

[28] CGAL: Computational Geometry Algorithms Library.http://www.cgal.org

[29] GMP or GNU MP: The GNU Multiple Precision Arith-metic Library. Cf. http://swox.com/gmp/ for information andftp://ftp.gnu.org/gnu/gmp for downloading.

[30] World Wide Web Consortium: XML Schema Part 1: Structures.May 2001, http://www.w3.org/TR/xmlschema-1/

24