1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _BGFX_POLYPOLYGON_B3DPOLYGONTOOLS_HXX
25 #define _BGFX_POLYPOLYGON_B3DPOLYGONTOOLS_HXX
26 
27 #include <basegfx/point/b2dpoint.hxx>
28 #include <basegfx/vector/b2dvector.hxx>
29 #include <basegfx/numeric/ftools.hxx>
30 #include <basegfx/point/b3dpoint.hxx>
31 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
32 #include <vector>
33 #include <basegfx/basegfxdllapi.h>
34 
35 //////////////////////////////////////////////////////////////////////////////
36 
37 namespace basegfx
38 {
39 	// predefinitions
40 	class B3DPolyPolygon;
41 	class B3DRange;
42 
43 	namespace tools
44 	{
45 		// B3DPolyPolygon tools
46 
47 		// get size of PolyPolygon. Control vectors are included in that ranges.
48 		BASEGFX_DLLPUBLIC B3DRange getRange(const B3DPolyPolygon& rCandidate);
49 
50 		/** Apply given LineDashing to given polyPolygon
51 
52 			For a description see applyLineDashing in b2dpolygontoos.hxx
53 		*/
54 		BASEGFX_DLLPUBLIC void applyLineDashing(
55 			const B3DPolyPolygon& rCandidate,
56 			const ::std::vector<double>& rDotDashArray,
57 			B3DPolyPolygon* pLineTarget,
58             B3DPolyPolygon* pGapTarget = 0,
59 			double fFullDashDotLen = 0.0);
60 
61 		/** Create a unit 3D line polyPolygon which defines a cube.
62          */
63 		BASEGFX_DLLPUBLIC B3DPolyPolygon createUnitCubePolyPolygon();
64 
65 		/** Create a unit 3D fill polyPolygon which defines a cube.
66          */
67 		BASEGFX_DLLPUBLIC B3DPolyPolygon createUnitCubeFillPolyPolygon();
68 
69 		/** Create a 3D line polyPolygon from a B3DRange which defines a cube.
70          */
71 		BASEGFX_DLLPUBLIC B3DPolyPolygon createCubePolyPolygonFromB3DRange( const B3DRange& rRange);
72 
73 		/** Create a 3D fill polyPolygon from a B3DRange which defines a cube.
74          */
75 		BASEGFX_DLLPUBLIC B3DPolyPolygon createCubeFillPolyPolygonFromB3DRange( const B3DRange& rRange);
76 
77 		/** Create a unit 3D line polyPolygon which defines a sphere with the given count of hor and ver segments.
78 			Result will be centered at (0.0, 0.0, 0.0) and sized [-1.0 .. 1.0] in all dimensions.
79 			If nHorSeg == 0 and/or nVerSeg == 0, a default will be calculated to have a step at least each 15 degrees.
80 			With VerStart, VerStop and hor range in cartesian may be specified to create a partial sphere only.
81          */
82 		BASEGFX_DLLPUBLIC B3DPolyPolygon createUnitSpherePolyPolygon(
83 			sal_uInt32 nHorSeg = 0L, sal_uInt32 nVerSeg = 0L,
84 			double fVerStart = F_PI2, double fVerStop = -F_PI2,
85 			double fHorStart = 0.0, double fHorStop = F_2PI);
86 
87 		/** Create a 3D line polyPolygon from a B3DRange which defines a sphere with the given count of hor and ver segments.
88 			If nHorSeg == 0 and/or nVerSeg == 0, a default will be calculated to have a step at least each 15 degrees.
89 			With VerStart, VerStop and hor range in cartesian may be specified to create a partial sphere only.
90          */
91 		BASEGFX_DLLPUBLIC B3DPolyPolygon createSpherePolyPolygonFromB3DRange(
92 			const B3DRange& rRange,
93 			sal_uInt32 nHorSeg = 0L, sal_uInt32 nVerSeg = 0L,
94 			double fVerStart = F_PI2, double fVerStop = -F_PI2,
95 			double fHorStart = 0.0, double fHorStop = F_2PI);
96 
97 		/** same as createUnitSpherePolyPolygon, but creates filled polygons (closed and oriented)
98 			There is one extra, the bool bNormals defines if normals will be set, default is false
99          */
100 		BASEGFX_DLLPUBLIC B3DPolyPolygon createUnitSphereFillPolyPolygon(
101 			sal_uInt32 nHorSeg = 0L, sal_uInt32 nVerSeg = 0L,
102 			bool bNormals = false,
103 			double fVerStart = F_PI2, double fVerStop = -F_PI2,
104 			double fHorStart = 0.0, double fHorStop = F_2PI);
105 
106 		/** same as createSpherePolyPolygonFromB3DRange, but creates filled polygons (closed and oriented)
107 			There is one extra, the bool bNormals defines if normals will be set, default is false
108          */
109 		BASEGFX_DLLPUBLIC B3DPolyPolygon createSphereFillPolyPolygonFromB3DRange(
110 			const B3DRange& rRange,
111 			sal_uInt32 nHorSeg = 0L, sal_uInt32 nVerSeg = 0L,
112 			bool bNormals = false,
113 			double fVerStart = F_PI2, double fVerStop = -F_PI2,
114 			double fHorStart = 0.0, double fHorStop = F_2PI);
115 
116 		/** Create/replace normals for given 3d geometry with default normals from given center to outside.
117 			rCandidate:	the 3d geometry to change
118 			rCenter:	the center of the 3d geometry
119          */
120 		BASEGFX_DLLPUBLIC B3DPolyPolygon applyDefaultNormalsSphere( const B3DPolyPolygon& rCandidate, const B3DPoint& rCenter);
121 
122 		/** invert normals for given 3d geometry.
123          */
124 		BASEGFX_DLLPUBLIC B3DPolyPolygon invertNormals( const B3DPolyPolygon& rCandidate);
125 
126 		/** Create/replace texture coordinates for given 3d geometry with parallel projected one
127 			rRange: the full range of the 3d geometry
128 			If bChangeX, x texture coordinate will be recalculated.
129 			If bChangeY, y texture coordinate will be recalculated.
130          */
131 		BASEGFX_DLLPUBLIC B3DPolyPolygon applyDefaultTextureCoordinatesParallel( const B3DPolyPolygon& rCandidate, const B3DRange& rRange, bool bChangeX = true, bool bChangeY = true);
132 
133 		/** Create/replace texture coordinates for given 3d geometry with spherical one
134 			rCenter: the centre of the used 3d geometry
135 			If bChangeX, x texture coordinate will be recalculated.
136 			If bChangeY, y texture coordinate will be recalculated.
137          */
138 		BASEGFX_DLLPUBLIC B3DPolyPolygon applyDefaultTextureCoordinatesSphere( const B3DPolyPolygon& rCandidate, const B3DPoint& rCenter, bool bChangeX = true, bool bChangeY = true);
139 
140         // isInside test for B3DPoint. On border is not inside as long as not true is given
141 		// in bWithBorder flag. It is assumed that the orientations of the given polygon are correct.
142 		BASEGFX_DLLPUBLIC bool isInside(const B3DPolyPolygon& rCandidate, const B3DPoint& rPoint, bool bWithBorder = false);
143 
144 		//////////////////////////////////////////////////////////////////////
145 		// comparators with tolerance for 3D PolyPolygons
146 		BASEGFX_DLLPUBLIC bool equal(const B3DPolyPolygon& rCandidateA, const B3DPolyPolygon& rCandidateB, const double& rfSmallValue);
147 		BASEGFX_DLLPUBLIC bool equal(const B3DPolyPolygon& rCandidateA, const B3DPolyPolygon& rCandidateB);
148 
149         /// converters for com::sun::star::drawing::PolyPolygonShape3D
150         BASEGFX_DLLPUBLIC B3DPolyPolygon UnoPolyPolygonShape3DToB3DPolyPolygon(
151             const com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygonShape3DSource,
152             bool bCheckClosed = true);
153         BASEGFX_DLLPUBLIC void B3DPolyPolygonToUnoPolyPolygonShape3D(
154             const B3DPolyPolygon& rPolyPolygonSource,
155             com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygonShape3DRetval);
156 
157     } // end of namespace tools
158 } // end of namespace basegfx
159 
160 #endif /* _BGFX_POLYPOLYGON_B3DPOLYGONTOOLS_HXX */
161