blob: c06ec8c11c2fa57c2979bc15286873fd77d9253d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
//-----------------------------------------------------------------------------
// BSPLIB HEADER: PolygonList.h
//
// Copyright (c) 1997 by Markus Hadwiger
// All Rights Reserved.
//-----------------------------------------------------------------------------
#ifndef _POLYGONLIST_H_
#define _POLYGONLIST_H_
// bsplib header files
#include "BspLibDefs.h"
#include "Polygon.h"
#include "SystemIO.h"
BSPLIB_NAMESPACE_BEGIN
class BSPNode;
class BspObject;
// singly linked polygon list (representation class) --------------------------
//
class PolygonListRep : public virtual SystemIO {
friend class PolygonList;
// error codes
enum {
E_NEWVINDX,
E_APPENDVINDX,
E_GETNUMVERTXS
};
// error handler for class PolygonList
void Error( int err ) const;
private:
PolygonListRep( BspObject *bobj );
~PolygonListRep() { delete list; }
void MergeLists( PolygonListRep *mergelist );
Polygon* InitList( Polygon *listhead );
// invalidate list without freeing dynamic storage
void InvalidateList() { list = NULL; numpolygons = 0; }
Polygon* FetchHead() { return list; }
Polygon* UnlinkHead();
Polygon* DeleteHead();
Polygon* FindPolygon( int id ) { return list ? list->FindPolygon( id ) : NULL; }
Polygon* NewPolygon();
Polygon* InsertPolygon( Polygon *poly );
void PrependNewVIndx( int indx = -1 ) { if ( list == NULL ) Error( E_NEWVINDX ); list->PrependNewVIndx( indx ); }
void AppendNewVIndx( int indx = -1 ) { if ( list == NULL ) Error( E_NEWVINDX ); list->AppendNewVIndx( indx ); }
void AppendVIndx( VIndx *vindx ) { if ( list == NULL ) Error( E_APPENDVINDX ); list->AppendVIndx( vindx ); }
Polygon* CalcPlaneNormals();
Polygon* CheckPolygonPlanes();
BSPNode* PartitionSpace();
void WritePolyList( FILE *fp, int no ) const;
int getNumElements() const { return numpolygons; }
int getNumVertices() const { if( list == NULL ) Error( E_GETNUMVERTXS ); return list->getNumVertices(); }
private:
int ref_count; // number of references to this list
int numpolygons; // length of singly linked polygon list (not counting this head)
BspObject* baseobject; // this list contains polygons belonging to *baseobject
Polygon* list; // pointer to first polygon in list
};
// constructor without preexisting list ---------------------------------------
inline PolygonListRep::PolygonListRep( BspObject *bobj ) : ref_count( 0 )
{
baseobject = bobj;
list = NULL;
numpolygons = 0;
}
// singly linked polygon list (handle class) ----------------------------------
//
class PolygonList {
public:
PolygonList( BspObject *bobj ) { rep = new PolygonListRep( bobj ); rep->ref_count = 1; }
~PolygonList() { if ( --rep->ref_count == 0 ) delete rep; }
PolygonList( const PolygonList& copyobj );
PolygonList& operator =( const PolygonList& copyobj );
void MergeLists( PolygonList *mergelist ) { if ( mergelist ) rep->MergeLists( mergelist->rep ); }
Polygon* InitList( Polygon *listhead ) { return rep->InitList( listhead ); }
void InvalidateList() { rep->InvalidateList(); }
Polygon* FetchHead() { return rep->FetchHead(); }
Polygon* UnlinkHead() { return rep->UnlinkHead(); }
Polygon* DeleteHead() { return rep->DeleteHead(); }
Polygon* FindPolygon( int id ) { return rep->FindPolygon( id ); }
Polygon* NewPolygon() { return rep->NewPolygon(); }
Polygon* InsertPolygon( Polygon *poly ) { return rep->InsertPolygon( poly ); }
void PrependNewVIndx( int indx = -1 ) { rep->PrependNewVIndx( indx ); }
void AppendNewVIndx( int indx = -1 ) { rep->AppendNewVIndx( indx ); }
void AppendVIndx( VIndx *vindx ) { rep->AppendVIndx( vindx ); }
Polygon* CalcPlaneNormals() { return rep->CalcPlaneNormals(); }
Polygon* CheckPolygonPlanes() { return rep->CheckPolygonPlanes(); }
BSPNode* PartitionSpace() { return rep->PartitionSpace(); }
void WritePolyList( FILE *fp, int no ) const { rep->WritePolyList( fp, no ); }
int getNumElements() const { return rep->getNumElements(); }
int getNumVertices() const { return rep->getNumVertices(); }
private:
PolygonListRep* rep;
};
// copy constructor for PolygonList -------------------------------------------
inline PolygonList::PolygonList( const PolygonList& copyobj )
{
rep = copyobj.rep; // shallow copy
rep->ref_count++; // with reference counting
}
// assignment operator for PolygonList ----------------------------------------
inline PolygonList& PolygonList::operator =( const PolygonList& copyobj )
{
if ( ©obj != this ) {
// old reference is overwritten
if ( --rep->ref_count == 0 ) {
delete rep;
}
rep = copyobj.rep; // shallow copy
rep->ref_count++; // with reference counting
}
return *this;
}
BSPLIB_NAMESPACE_END
#endif // _POLYGONLIST_H_
|