xref: /AOO41X/main/basegfx/inc/basegfx/polygon/b3dpolypolygontools.hxx (revision fe22d2cfc602815794415026f1317bd625db6f83)
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 
34 //////////////////////////////////////////////////////////////////////////////
35 
36 namespace basegfx
37 {
38     // predefinitions
39     class B3DPolyPolygon;
40     class B3DRange;
41 
42     namespace tools
43     {
44         // B3DPolyPolygon tools
45 
46         // get size of PolyPolygon. Control vectors are included in that ranges.
47         B3DRange getRange(const B3DPolyPolygon& rCandidate);
48 
49         /** Apply given LineDashing to given polyPolygon
50 
51             For a description see applyLineDashing in b2dpolygontoos.hxx
52         */
53         void applyLineDashing(
54             const B3DPolyPolygon& rCandidate,
55             const ::std::vector<double>& rDotDashArray,
56             B3DPolyPolygon* pLineTarget,
57             B3DPolyPolygon* pGapTarget = 0,
58             double fFullDashDotLen = 0.0);
59 
60         /** Create a unit 3D line polyPolygon which defines a cube.
61          */
62         B3DPolyPolygon createUnitCubePolyPolygon();
63 
64         /** Create a unit 3D fill polyPolygon which defines a cube.
65          */
66         B3DPolyPolygon createUnitCubeFillPolyPolygon();
67 
68         /** Create a 3D line polyPolygon from a B3DRange which defines a cube.
69          */
70         B3DPolyPolygon createCubePolyPolygonFromB3DRange( const B3DRange& rRange);
71 
72         /** Create a 3D fill polyPolygon from a B3DRange which defines a cube.
73          */
74         B3DPolyPolygon createCubeFillPolyPolygonFromB3DRange( const B3DRange& rRange);
75 
76         /** Create a unit 3D line polyPolygon which defines a sphere with the given count of hor and ver segments.
77             Result will be centered at (0.0, 0.0, 0.0) and sized [-1.0 .. 1.0] in all dimensions.
78             If nHorSeg == 0 and/or nVerSeg == 0, a default will be calculated to have a step at least each 15 degrees.
79             With VerStart, VerStop and hor range in cartesian may be specified to create a partial sphere only.
80          */
81         B3DPolyPolygon createUnitSpherePolyPolygon(
82             sal_uInt32 nHorSeg = 0L, sal_uInt32 nVerSeg = 0L,
83             double fVerStart = F_PI2, double fVerStop = -F_PI2,
84             double fHorStart = 0.0, double fHorStop = F_2PI);
85 
86         /** Create a 3D line polyPolygon from a B3DRange which defines a sphere with the given count of hor and ver segments.
87             If nHorSeg == 0 and/or nVerSeg == 0, a default will be calculated to have a step at least each 15 degrees.
88             With VerStart, VerStop and hor range in cartesian may be specified to create a partial sphere only.
89          */
90         B3DPolyPolygon createSpherePolyPolygonFromB3DRange(
91             const B3DRange& rRange,
92             sal_uInt32 nHorSeg = 0L, sal_uInt32 nVerSeg = 0L,
93             double fVerStart = F_PI2, double fVerStop = -F_PI2,
94             double fHorStart = 0.0, double fHorStop = F_2PI);
95 
96         /** same as createUnitSpherePolyPolygon, but creates filled polygons (closed and oriented)
97             There is one extra, the bool bNormals defines if normals will be set, default is false
98          */
99         B3DPolyPolygon createUnitSphereFillPolyPolygon(
100             sal_uInt32 nHorSeg = 0L, sal_uInt32 nVerSeg = 0L,
101             bool bNormals = false,
102             double fVerStart = F_PI2, double fVerStop = -F_PI2,
103             double fHorStart = 0.0, double fHorStop = F_2PI);
104 
105         /** same as createSpherePolyPolygonFromB3DRange, but creates filled polygons (closed and oriented)
106             There is one extra, the bool bNormals defines if normals will be set, default is false
107          */
108         B3DPolyPolygon createSphereFillPolyPolygonFromB3DRange(
109             const B3DRange& rRange,
110             sal_uInt32 nHorSeg = 0L, sal_uInt32 nVerSeg = 0L,
111             bool bNormals = false,
112             double fVerStart = F_PI2, double fVerStop = -F_PI2,
113             double fHorStart = 0.0, double fHorStop = F_2PI);
114 
115         /** Create/replace normals for given 3d geometry with default normals from given center to outside.
116             rCandidate: the 3d geometry to change
117             rCenter:    the center of the 3d geometry
118          */
119         B3DPolyPolygon applyDefaultNormalsSphere( const B3DPolyPolygon& rCandidate, const B3DPoint& rCenter);
120 
121         /** invert normals for given 3d geometry.
122          */
123         B3DPolyPolygon invertNormals( const B3DPolyPolygon& rCandidate);
124 
125         /** Create/replace texture coordinates for given 3d geometry with parallel projected one
126             rRange: the full range of the 3d geometry
127             If bChangeX, x texture coordinate will be recalculated.
128             If bChangeY, y texture coordinate will be recalculated.
129          */
130         B3DPolyPolygon applyDefaultTextureCoordinatesParallel( const B3DPolyPolygon& rCandidate, const B3DRange& rRange, bool bChangeX = true, bool bChangeY = true);
131 
132         /** Create/replace texture coordinates for given 3d geometry with spherical one
133             rCenter: the centre of the used 3d geometry
134             If bChangeX, x texture coordinate will be recalculated.
135             If bChangeY, y texture coordinate will be recalculated.
136          */
137         B3DPolyPolygon applyDefaultTextureCoordinatesSphere( const B3DPolyPolygon& rCandidate, const B3DPoint& rCenter, bool bChangeX = true, bool bChangeY = true);
138 
139         // isInside test for B3DPoint. On border is not inside as long as not true is given
140         // in bWithBorder flag. It is assumed that the orientations of the given polygon are correct.
141         bool isInside(const B3DPolyPolygon& rCandidate, const B3DPoint& rPoint, bool bWithBorder = false);
142 
143         //////////////////////////////////////////////////////////////////////
144         // comparators with tolerance for 3D PolyPolygons
145         bool equal(const B3DPolyPolygon& rCandidateA, const B3DPolyPolygon& rCandidateB, const double& rfSmallValue);
146         bool equal(const B3DPolyPolygon& rCandidateA, const B3DPolyPolygon& rCandidateB);
147 
148         /// converters for com::sun::star::drawing::PolyPolygonShape3D
149         B3DPolyPolygon UnoPolyPolygonShape3DToB3DPolyPolygon(
150             const com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygonShape3DSource,
151             bool bCheckClosed = true);
152         void B3DPolyPolygonToUnoPolyPolygonShape3D(
153             const B3DPolyPolygon& rPolyPolygonSource,
154             com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygonShape3DRetval);
155 
156     } // end of namespace tools
157 } // end of namespace basegfx
158 
159 #endif /* _BGFX_POLYPOLYGON_B3DPOLYGONTOOLS_HXX */
160