1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #pragma once
21 
22 #include <basegfx/numeric/ftools.hxx>
23 #include <basegfx/point/b3dpoint.hxx>
24 #include <basegfx/basegfxdllapi.h>
25 
26 namespace com::sun::star::drawing { struct PolyPolygonShape3D; }
27 
28 namespace basegfx
29 {
30     class B3DPolyPolygon;
31     class B3DRange;
32 }
33 
34 namespace basegfx::utils
35 {
36         // B3DPolyPolygon tools
37 
38         // get size of PolyPolygon. Control vectors are included in that ranges.
39         BASEGFX_DLLPUBLIC B3DRange getRange(const B3DPolyPolygon& rCandidate);
40 
41         /** Create a unit 3D line polyPolygon which defines a cube.
42          */
43         BASEGFX_DLLPUBLIC B3DPolyPolygon const & createUnitCubePolyPolygon();
44 
45         /** Create a unit 3D fill polyPolygon which defines a cube.
46          */
47         BASEGFX_DLLPUBLIC B3DPolyPolygon const & createUnitCubeFillPolyPolygon();
48 
49         /** Create a 3D line polyPolygon from a B3DRange which defines a cube.
50          */
51         BASEGFX_DLLPUBLIC B3DPolyPolygon createCubePolyPolygonFromB3DRange( const B3DRange& rRange);
52 
53         /** Create a 3D fill polyPolygon from a B3DRange which defines a cube.
54          */
55         BASEGFX_DLLPUBLIC B3DPolyPolygon createCubeFillPolyPolygonFromB3DRange( const B3DRange& rRange);
56 
57         /** Create a unit 3D line polyPolygon which defines a sphere with the given count of hor and ver segments.
58             Result will be centered at (0.0, 0.0, 0.0) and sized [-1.0 .. 1.0] in all dimensions.
59             If nHorSeg == 0 and/or nVerSeg == 0, a default will be calculated to have a step at least each 15 degrees.
60             With VerStart, VerStop and hor range in cartesian may be specified to create a partial sphere only.
61          */
62         BASEGFX_DLLPUBLIC B3DPolyPolygon createUnitSpherePolyPolygon(
63             sal_uInt32 nHorSeg, sal_uInt32 nVerSeg,
64             double fVerStart = F_PI2, double fVerStop = -F_PI2,
65             double fHorStart = 0.0, double fHorStop = F_2PI);
66 
67         /** Create a 3D line polyPolygon from a B3DRange which defines a sphere with the given count of hor and ver segments.
68             If nHorSeg == 0 and/or nVerSeg == 0, a default will be calculated to have a step at least each 15 degrees.
69             With VerStart, VerStop and hor range in cartesian may be specified to create a partial sphere only.
70          */
71         BASEGFX_DLLPUBLIC B3DPolyPolygon createSpherePolyPolygonFromB3DRange(
72             const B3DRange& rRange,
73             sal_uInt32 nHorSeg, sal_uInt32 nVerSeg,
74             double fVerStart = F_PI2, double fVerStop = -F_PI2,
75             double fHorStart = 0.0, double fHorStop = F_2PI);
76 
77         /** same as createUnitSpherePolyPolygon, but creates filled polygons (closed and oriented)
78             There is one extra, the bool bNormals defines if normals will be set, default is false
79          */
80         BASEGFX_DLLPUBLIC B3DPolyPolygon createUnitSphereFillPolyPolygon(
81             sal_uInt32 nHorSeg, sal_uInt32 nVerSeg,
82             bool bNormals = false,
83             double fVerStart = F_PI2, double fVerStop = -F_PI2,
84             double fHorStart = 0.0, double fHorStop = F_2PI);
85 
86         /** same as createSpherePolyPolygonFromB3DRange, but creates filled polygons (closed and oriented)
87             There is one extra, the bool bNormals defines if normals will be set, default is false
88          */
89         BASEGFX_DLLPUBLIC B3DPolyPolygon createSphereFillPolyPolygonFromB3DRange(
90             const B3DRange& rRange,
91             sal_uInt32 nHorSeg, sal_uInt32 nVerSeg,
92             bool bNormals = false,
93             double fVerStart = F_PI2, double fVerStop = -F_PI2,
94             double fHorStart = 0.0, double fHorStop = F_2PI);
95 
96         /** Create/replace normals for given 3d geometry with default normals from given center to outside.
97             rCandidate: the 3d geometry to change
98             rCenter:    the center of the 3d geometry
99          */
100         BASEGFX_DLLPUBLIC B3DPolyPolygon applyDefaultNormalsSphere( const B3DPolyPolygon& rCandidate, const B3DPoint& rCenter);
101 
102         /** invert normals for given 3d geometry.
103          */
104         BASEGFX_DLLPUBLIC B3DPolyPolygon invertNormals( const B3DPolyPolygon& rCandidate);
105 
106         /** Create/replace texture coordinates for given 3d geometry with parallel projected one
107             rRange: the full range of the 3d geometry
108             If bChangeX, x texture coordinate will be recalculated.
109             If bChangeY, y texture coordinate will be recalculated.
110          */
111         BASEGFX_DLLPUBLIC B3DPolyPolygon applyDefaultTextureCoordinatesParallel( const B3DPolyPolygon& rCandidate, const B3DRange& rRange, bool bChangeX = true, bool bChangeY = true);
112 
113         /** Create/replace texture coordinates for given 3d geometry with spherical one
114             rCenter: the centre of the used 3d geometry
115             If bChangeX, x texture coordinate will be recalculated.
116             If bChangeY, y texture coordinate will be recalculated.
117          */
118         BASEGFX_DLLPUBLIC B3DPolyPolygon applyDefaultTextureCoordinatesSphere( const B3DPolyPolygon& rCandidate, const B3DPoint& rCenter, bool bChangeX = true, bool bChangeY = true);
119 
120         // isInside test for B3DPoint. On border is not inside.
121         // It is assumed that the orientations of the given polygon are correct.
122         BASEGFX_DLLPUBLIC bool isInside(const B3DPolyPolygon& rCandidate, const B3DPoint& rPoint);
123 
124         /// converters for css::drawing::PolyPolygonShape3D
125         BASEGFX_DLLPUBLIC B3DPolyPolygon UnoPolyPolygonShape3DToB3DPolyPolygon(
126             const css::drawing::PolyPolygonShape3D& rPolyPolygonShape3DSource);
127         BASEGFX_DLLPUBLIC void B3DPolyPolygonToUnoPolyPolygonShape3D(
128             const B3DPolyPolygon& rPolyPolygonSource,
129             css::drawing::PolyPolygonShape3D& rPolyPolygonShape3DRetval);
130 
131 } // end of namespace basegfx::utils
132 
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
134