1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: poly3d.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
35 #include <tools/solar.h>
39 #include <bf_svx/volume3d.hxx>
42 #ifndef _B3D_BASE3D_HXX
43 #include <bf_goodies/base3d.hxx>
56 #define POLY3D_APPEND 0xFFFF
57 #define POLYPOLY3D_APPEND 0xFFFF
59 #define POLY3D_MAXPOINTS 0x7FFF
61 /*************************************************************************
63 |* 3D-Polygon-Implementierung
65 \************************************************************************/
72 Vector3D
* pOldPointAry
;
79 unsigned bDeleteOldAry
: 1;
82 ImpPolygon3D(UINT16 nInitSize
= 4, UINT16 nPolyResize
= 4);
83 ImpPolygon3D(const ImpPolygon3D
& rImpPoly3D
);
86 void CheckPointDelete();
87 void Resize(UINT16 nNewSize
, BOOL bDeletePoints
= TRUE
);
88 void Remove(UINT16 nPos
, UINT16 nCount
);
92 /************************************************************************/
95 #define DEGREE_FLAG_X (0x0001)
96 #define DEGREE_FLAG_Y (0x0002)
97 #define DEGREE_FLAG_Z (0x0004)
98 #define DEGREE_FLAG_ALL (DEGREE_FLAG_X|DEGREE_FLAG_Y|DEGREE_FLAG_Z)
100 /************************************************************************/
102 // Cut Flags for FindCut()
103 #define CUTFLAG_LINE (0x0001)
104 #define CUTFLAG_START1 (0x0002)
105 #define CUTFLAG_START2 (0x0004)
106 #define CUTFLAG_END1 (0x0008)
107 #define CUTFLAG_END2 (0x0010)
109 #define CUTFLAG_ALL (CUTFLAG_LINE|CUTFLAG_START1|CUTFLAG_START2|CUTFLAG_END1|CUTFLAG_END2)
110 #define CUTFLAG_DEFAULT (CUTFLAG_LINE|CUTFLAG_START2|CUTFLAG_END2)
112 /************************************************************************/
114 class ImpPolyPolygon3D
;
118 class E3dTriangleList
;
120 /************************************************************************/
125 ImpPolygon3D
* pImpPolygon3D
;
127 // ImpPolygon3D-ReferenceCount pruefen und ggf. abkoppeln
128 void CheckReference();
130 // Hilfsfunktionen fuer Triangulation
131 UINT16
GetHighestEdge() const;
134 Polygon3D(UINT16 nSize
= 4, UINT16 nResize
= 4);
135 Polygon3D(const Polygon3D
& rPoly3D
);
136 Polygon3D(const Polygon
& rPoly
, double fScale
= 1.0);
137 // es wird keine Konvertierung des XPolygon durchgefuehrt,
138 // sondern es werden nur die Punktkoordinaten uebernommen!
139 Polygon3D(const XPolygon
& rXPoly
, double fScale
= 1.0);
142 // Korrigiert das closed-Flag und entfernt den doppelten Punkt
146 void SetPointCount(UINT16 nPoints
);
147 UINT16
GetPointCount() const;
150 const Vector3D
& operator[](UINT16 nPos
) const;
151 Vector3D
& operator[](UINT16 nPos
);
152 Polygon3D
& operator= (const Polygon3D
& rPoly3D
);
153 BOOL
operator==(const Polygon3D
& rPoly3D
) const;
155 // Drehrichtung feststellen (fuer Polygone in der XY-Ebene) bzw. umkehren
156 BOOL
IsClockwise(const Vector3D
&rNormal
) const;
157 BOOL
IsClockwise() const { Vector3D
aNrm(0.0, 0.0, 1.0); return IsClockwise(aNrm
); }
158 Vector3D
GetNormal() const;
159 Vector3D
GetMiddle() const;
160 void FlipDirection();
161 BOOL
IsClosed() const;
162 void SetClosed(BOOL bNew
);
164 // aufeinanderfolgende doppelte Punkte sowie gleiche Anfangs- und
165 // Endpunkte entfernen
166 void RemoveDoublePoints();
168 // Ueberlappen sich das aktuelle und das angegebene Polygon ?
170 // Existiert ein Schnitt zwischen den Polys?
172 void Transform(const Matrix4D
& rTfMatrix
);
174 BOOL
IsInside(const Vector3D
& rPnt
, BOOL bWithBorder
=FALSE
) const;
176 // different export formats
177 Polygon
GetPolygon() const;
179 Volume3D
GetPolySize() const;
180 double GetPolyArea(const Vector3D
& rNormal
) const;
182 // Laenge des Polygons liefern
183 double GetLength() const;
185 friend SvStream
& operator>>(SvStream
& rIStream
, Polygon3D
& rPoly3D
);
186 friend SvStream
& operator<<(SvStream
& rOStream
, const Polygon3D
& rPoly3D
);
188 // Schnitt zwischen den von den Punkten angegebenen Kanten ermitteln.
189 // Dabei ist der Rueckgabewert != 0.0, wenn der Schnitt innerhalb
190 // der Parameterbereiche der Kanten liegt und gibt den Wert ]0.0, 1.0]
191 // innerhalb der ersten Kante an.
193 // Diese Version arbeitet mit der Kante nEdge1 aus dem lokalen
194 // Polygon und nEdge2 aus dem uebergebenen
196 // Diese Version nimmt die Startpunkte und Vektoren (relative Angabe
197 // des Endpunktes) zweier Kanten
199 // test if point is on line in range ]0.0..1.0[ without
200 // the points. If so, return TRUE and put the parameter
201 // value in pCut (if provided)
203 // Orientierung im Punkt nIndex liefern
204 BOOL
GetPointOrientation(UINT16 nIndex
) const;
206 // get position on polypos, with clipping to start/end
207 Vector3D
GetPosition(double fPos
) const;
209 // create a expanded or compresssed poly with exactly nNum Points
210 Polygon3D
GetExpandedPolygon(sal_uInt32 nNum
);
213 /************************************************************************/
217 //extern OutputDevice* pThisIsTheActualOutDev;
220 ///////////////////////////////////////////////////////////////////////////////
225 ImpPolyPolygon3D
* pImpPolyPolygon3D
;
227 void CheckReference();
230 PolyPolygon3D(UINT16 nInitSize
= 4, UINT16 nResize
= 4);
231 PolyPolygon3D(const Polygon3D
& r3DPoly
);
232 PolyPolygon3D(const PolyPolygon3D
& r3DPolyPoly
);
233 PolyPolygon3D(const PolyPolygon
& rPolyPoly
, double fScale
= 1.0);
234 PolyPolygon3D(const XPolyPolygon
& rXPolyPoly
, double fScale
= 1.0);
237 // Korrigiert das closed-Flag und entfernt den doppelten Punkt
239 void Insert(const Polygon3D
& rPoly3D
, UINT16 nPos
= POLYPOLY3D_APPEND
);
240 void Insert(const PolyPolygon3D
& rPoly3D
, UINT16 nPos
= POLYPOLY3D_APPEND
);
243 const Polygon3D
& GetObject(UINT16 nPos
) const;
246 UINT16
Count() const;
248 const Polygon3D
& operator[](UINT16 nPos
) const { return GetObject(nPos
); }
249 Polygon3D
& operator[](UINT16 nPos
);
251 PolyPolygon3D
& operator=(const PolyPolygon3D
& rPolyPoly3D
);
252 BOOL
operator!=(const PolyPolygon3D
& rPolyPoly3D
) const;
254 void Transform(const Matrix4D
& rTfMatrix
);
256 void FlipDirections();
258 // Die Umlaufrichtungen ineinanderliegender Polygone anpassen
259 void SetDirections(const Vector3D
& rNormal
);
260 void SetDirections() { Vector3D aNormal
= GetNormal(); SetDirections(aNormal
); }
262 // in allen Polygonen aufeinanderfolgende doppelte Punkte sowie
263 // gleiche Anfangs- und Endpunkte entfernen
264 void RemoveDoublePoints();
266 // Remove all completely overlapping polygons
268 // evtl. entstandene Selbstueberschneidungen in Eckpunkten
269 // ohne Punktreduzierung korrigieren
270 void CorrectGrownPoly(const PolyPolygon3D
& rOrig
);
272 // Ueberlappen sich das aktuelle und das angegebene PolyPolygon ?
274 friend SvStream
& operator>>(SvStream
& rIStream
, PolyPolygon3D
& rPolyPoly3D
);
275 friend SvStream
& operator<<(SvStream
& rOStream
, const PolyPolygon3D
& rPolyPoly3D
);
277 // Drehrichtung feststellen (fuer Polygone in der XY-Ebene) bzw. umkehren
278 Vector3D
GetNormal() const;
279 Vector3D
GetMiddle() const;
280 BOOL
IsClosed() const;
282 PolyPolygon
GetPolyPolygon() const;
284 Volume3D
GetPolySize() const;
285 double GetPolyArea() const;
287 // Laenge des Polygons liefern
288 double GetLength() const;
290 // merge the contents of the whole PolyPolygon to contain no more
291 // cuts or overlaps. Makes all necessary merges between all
292 // contained polygons. Preserves Holes.
295 }//end of namespace binfilter
296 #endif // _POLY3D_HXX