LibreOffice Module drawinglayer (master) 1
hatchtextureprimitive3d.cxx
Go to the documentation of this file.
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
27#include <texture/texture.hxx>
32#include <utility>
33
34
35using namespace com::sun::star;
36
37
39{
41 {
43
44 if(!getChildren().empty())
45 {
46 const Primitive3DContainer aSource(getChildren());
47 const size_t nSourceCount(aSource.size());
48 std::vector< Primitive3DReference > aDestination;
49
50 for(size_t a(0); a < nSourceCount; a++)
51 {
52 // get reference
53 const Primitive3DReference xReference(aSource[a]);
54
55 if(xReference.is())
56 {
57 const BasePrimitive3D* pBasePrimitive = static_cast< const BasePrimitive3D* >(xReference.get());
58
59 // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
60 // not all content is needed, remove transparencies and ModifiedColorPrimitives
61 switch(pBasePrimitive->getPrimitive3DID())
62 {
64 {
65 // polyPolygonMaterialPrimitive3D, check texturing and hatching
66 const PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const PolyPolygonMaterialPrimitive3D& >(*pBasePrimitive);
67 const basegfx::B3DPolyPolygon& aFillPolyPolygon(rPrimitive.getB3DPolyPolygon());
68
70 {
71 // add original primitive for background
72 aDestination.push_back(xReference);
73 }
74
75 if(aFillPolyPolygon.areTextureCoordinatesUsed())
76 {
77 const sal_uInt32 nPolyCount(aFillPolyPolygon.count());
78 basegfx::B2DPolyPolygon aTexPolyPolygon;
80 basegfx::B2DVector a2X, a2Y;
82 basegfx::B3DVector a3X, a3Y;
83 bool b2N(false), b2X(false), b2Y(false);
84
85 for(sal_uInt32 b(0); b < nPolyCount; b++)
86 {
87 const basegfx::B3DPolygon& aPartPoly(aFillPolyPolygon.getB3DPolygon(b));
88 const sal_uInt32 nPointCount(aPartPoly.count());
89 basegfx::B2DPolygon aTexPolygon;
90
91 for(sal_uInt32 c(0); c < nPointCount; c++)
92 {
93 const basegfx::B2DPoint a2Candidate(aPartPoly.getTextureCoordinate(c));
94
95 if(!b2N)
96 {
97 a2N = a2Candidate;
98 a3N = aPartPoly.getB3DPoint(c);
99 b2N = true;
100 }
101 else if(!b2X && !a2N.equal(a2Candidate))
102 {
103 a2X = a2Candidate - a2N;
104 a3X = aPartPoly.getB3DPoint(c) - a3N;
105 b2X = true;
106 }
107 else if(!b2Y && !a2N.equal(a2Candidate) && !a2X.equal(a2Candidate))
108 {
109 a2Y = a2Candidate - a2N;
110
111 const double fCross(a2X.cross(a2Y));
112
113 if(!basegfx::fTools::equalZero(fCross))
114 {
115 a3Y = aPartPoly.getB3DPoint(c) - a3N;
116 b2Y = true;
117 }
118 }
119
120 aTexPolygon.append(a2Candidate);
121 }
122
123 aTexPolygon.setClosed(true);
124 aTexPolyPolygon.append(aTexPolygon);
125 }
126
127 if(b2N && b2X && b2Y)
128 {
129 // found two linearly independent 2D vectors
130 // get 2d range of texture coordinates
131 const basegfx::B2DRange aOutlineRange(basegfx::utils::getRange(aTexPolyPolygon));
132 const basegfx::BColor aHatchColor(getHatch().getColor());
133 const double fAngle(getHatch().getAngle());
134 std::vector< basegfx::B2DHomMatrix > aMatrices;
135
136 // get hatch transformations
137 switch(getHatch().getStyle())
138 {
140 {
141 // rotated 45 degrees
143 aOutlineRange,
144 aOutlineRange,
145 getHatch().getDistance(),
146 fAngle - M_PI_4);
147
148 aHatch.appendTransformations(aMatrices);
149
150 [[fallthrough]];
151 }
153 {
154 // rotated 90 degrees
156 aOutlineRange,
157 aOutlineRange,
158 getHatch().getDistance(),
159 fAngle - M_PI_2);
160
161 aHatch.appendTransformations(aMatrices);
162
163 [[fallthrough]];
164 }
166 {
167 // angle as given
169 aOutlineRange,
170 aOutlineRange,
171 getHatch().getDistance(),
172 fAngle);
173
174 aHatch.appendTransformations(aMatrices);
175 }
176 }
177
178 // create geometry from unit line
179 basegfx::B2DPolyPolygon a2DHatchLines;
180 basegfx::B2DPolygon a2DUnitLine;
181 a2DUnitLine.append(basegfx::B2DPoint(0.0, 0.0));
182 a2DUnitLine.append(basegfx::B2DPoint(1.0, 0.0));
183
184 for(const basegfx::B2DHomMatrix & rMatrix : aMatrices)
185 {
186 basegfx::B2DPolygon aNewLine(a2DUnitLine);
187 aNewLine.transform(rMatrix);
188 a2DHatchLines.append(aNewLine);
189 }
190
191 if(a2DHatchLines.count())
192 {
193 // clip against texture polygon
194 a2DHatchLines = basegfx::utils::clipPolyPolygonOnPolyPolygon(a2DHatchLines, aTexPolyPolygon, true, true);
195 }
196
197 if(a2DHatchLines.count())
198 {
199 // create 2d matrix with 2d vectors as column vectors and 2d point as offset, this represents
200 // a coordinate system transformation from unit coordinates to the new coordinate system
202 a2D.set(0, 0, a2X.getX());
203 a2D.set(1, 0, a2X.getY());
204 a2D.set(0, 1, a2Y.getX());
205 a2D.set(1, 1, a2Y.getY());
206 a2D.set(0, 2, a2N.getX());
207 a2D.set(1, 2, a2N.getY());
208
209 // invert that transformation, so we have a back-transformation from texture coordinates
210 // to unit coordinates
211 a2D.invert();
212 a2DHatchLines.transform(a2D);
213
214 // expand back-transformed geometry to 3D
216
217 // create 3d matrix with 3d vectors as column vectors (0,0,1 as Z) and 3d point as offset, this represents
218 // a coordinate system transformation from unit coordinates to the object's 3d coordinate system
220 a3D.set(0, 0, a3X.getX());
221 a3D.set(1, 0, a3X.getY());
222 a3D.set(2, 0, a3X.getZ());
223 a3D.set(0, 1, a3Y.getX());
224 a3D.set(1, 1, a3Y.getY());
225 a3D.set(2, 1, a3Y.getZ());
226 a3D.set(0, 3, a3N.getX());
227 a3D.set(1, 3, a3N.getY());
228 a3D.set(2, 3, a3N.getZ());
229
230 // transform hatch lines to 3D object coordinates
231 a3DHatchLines.transform(a3D);
232
233 // build primitives from this geometry
234 const sal_uInt32 nHatchLines(a3DHatchLines.count());
235
236 for(sal_uInt32 d(0); d < nHatchLines; d++)
237 {
238 const Primitive3DReference xRef(new PolygonHairlinePrimitive3D(a3DHatchLines.getB3DPolygon(d), aHatchColor));
239 aDestination.push_back(xRef);
240 }
241 }
242 }
243 }
244
245 break;
246 }
247 default :
248 {
249 // add reference to result
250 aDestination.push_back(xReference);
251 break;
252 }
253 }
254 }
255 }
256
257 // prepare return value
258 const sal_uInt32 nDestSize(aDestination.size());
259 aRetval.resize(nDestSize);
260
261 for(sal_uInt32 b(0); b < nDestSize; b++)
262 {
263 aRetval[b] = aDestination[b];
264 }
265 }
266
267 return aRetval;
268 }
269
272 const Primitive3DContainer& rChildren,
273 const basegfx::B2DVector& rTextureSize,
274 bool bModulate,
275 bool bFilter)
276 : TexturePrimitive3D(rChildren, rTextureSize, bModulate, bFilter),
277 maHatch(std::move(aHatch))
278 {
279 }
280
282 {
283 if(TexturePrimitive3D::operator==(rPrimitive))
284 {
285 const HatchTexturePrimitive3D& rCompare = static_cast<const HatchTexturePrimitive3D&>(rPrimitive);
286
287 return (getHatch() == rCompare.getHatch());
288 }
289
290 return false;
291 }
292
294 {
295 std::unique_lock aGuard( m_aMutex );
296
297 if(getBuffered3DDecomposition().empty())
298 {
300 const_cast< HatchTexturePrimitive3D* >(this)->maBuffered3DDecomposition = aNewSequence;
301 }
302
304 }
305
306 // provide unique ID
308
309} // end of namespace
310
311/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double d
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
void transform(const basegfx::B2DHomMatrix &rMatrix)
sal_uInt32 count() const
void transform(const basegfx::B2DHomMatrix &rMatrix)
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
void setClosed(bool bNew)
double cross(const B2DVector &rVec) const
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
bool areTextureCoordinatesUsed() const
sal_uInt32 count() const
void transform(const basegfx::B3DHomMatrix &rMatrix)
B3DPolygon const & getB3DPolygon(sal_uInt32 nIndex) const
B3DPoint const & getB3DPoint(sal_uInt32 nIndex) const
sal_uInt32 count() const
B2DPoint const & getTextureCoordinate(sal_uInt32 nIndex) const
bool equal(const Tuple2D< TYPE > &rTup) const
TYPE getX() const
TYPE getY() const
TYPE getX() const
TYPE getZ() const
TYPE getY() const
virtual sal_uInt32 getPrimitive3DID() const =0
provide unique ID for fast identifying of known primitive implementations in renderers.
const Primitive3DContainer & getChildren() const
data read access
virtual Primitive3DContainer get3DDecomposition(const geometry::ViewInformation3D &rViewInformation) const override
local decomposition.
attribute::FillHatchAttribute maHatch
the hatch definition
const Primitive3DContainer & getBuffered3DDecomposition() const
local access methods to maBufferedDecomposition
Primitive3DContainer maBuffered3DDecomposition
the buffered decomposed hatch
HatchTexturePrimitive3D(attribute::FillHatchAttribute aHatch, const Primitive3DContainer &rChildren, const basegfx::B2DVector &rTextureSize, bool bModulate, bool bFilter)
constructor
const attribute::FillHatchAttribute & getHatch() const
data read access
Primitive3DContainer impCreate3DDecomposition() const
helper: local decomposition
virtual bool operator==(const BasePrimitive3D &rPrimitive) const override
compare operator
const basegfx::B3DPolyPolygon & getB3DPolyPolygon() const
data read access
void appendTransformations(::std::vector< basegfx::B2DHomMatrix > &rMatrices)
Definition: texture.cxx:879
#define PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D
#define PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D
uno_Any a
bool equalZero(const T &rfVal)
B3DPolyPolygon createB3DPolyPolygonFromB2DPolyPolygon(const B2DPolyPolygon &rCandidate, double fZCoordinate)
B2DPolyPolygon clipPolyPolygonOnPolyPolygon(const B2DPolyPolygon &rCandidate, const B2DPolyPolygon &rClip, bool bInside, bool bStroke, size_t *pPointLimit)
B2DRange getRange(const B2DPolygon &rCandidate)
SdrPrimitive3D class.
css::uno::Reference< css::graphic::XPrimitive3D > Primitive3DReference
ImplPrimitive3DIDBlock(PolygonHairlinePrimitive3D, PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D) Primitive3DContainer PolygonStrokePrimitive3D