LibreOffice Module basegfx (master) 1
rasterconvert3d.hxx
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
20#pragma once
21
22#include <config_options.h>
23#include <sal/types.h>
24#include <vector>
25
26#include <osl/diagnose.h>
27
32
33namespace basegfx
34{
35 class B3DPolygon;
36 class B3DPolyPolygon;
37}
38
39// interpolators for double precision
40
41namespace basegfx
42{
44 {
45 private:
46 double mfVal;
47 double mfInc;
48
49 public:
51 : mfVal(0.0),
52 mfInc(0.0)
53 {}
54
55 ip_single(double fVal, double fInc)
56 : mfVal(fVal),
57 mfInc(fInc)
58 {}
59
60 double getVal() const { return mfVal; }
61 double getInc() const { return mfInc; }
62
63 void increment(double fStep) { mfVal += fStep * mfInc; }
64 };
65
67 {
68 private:
71
72 public:
74 {}
75
76 ip_double(double fXVal, double fXInc, double fYVal, double fYInc)
77 : maX(fXVal, fXInc),
78 maY(fYVal, fYInc)
79 {}
80
81 const ip_single& getX() const { return maX; }
82 const ip_single& getY() const { return maY; }
83
84 void increment(double fStep) { maX.increment(fStep); maY.increment(fStep); }
85 };
86
88 {
89 private:
93
94 public:
96 {}
97
98 ip_triple(double fXVal, double fXInc, double fYVal, double fYInc, double fZVal, double fZInc)
99 : maX(fXVal, fXInc),
100 maY(fYVal, fYInc),
101 maZ(fZVal, fZInc)
102 {}
103
104 const ip_single& getX() const { return maX; }
105 const ip_single& getY() const { return maY; }
106 const ip_single& getZ() const { return maZ; }
107
108 void increment(double fStep) { maX.increment(fStep); maY.increment(fStep); maZ.increment(fStep); }
109 };
110
111 // InterpolatorProvider3D to have a common source for allocating interpolators
112 // which may then be addressed using the index to the vectors
113
114 #define SCANLINE_EMPTY_INDEX (0xffffffff)
115
117 {
118 private:
119 ::std::vector< ip_triple > maColorInterpolators;
120 ::std::vector< ip_triple > maNormalInterpolators;
121 ::std::vector< ip_double > maTextureInterpolators;
122 ::std::vector< ip_triple > maInverseTextureInterpolators;
123
124 protected:
125 sal_uInt32 addColorInterpolator(const BColor& rA, const BColor& rB, double fInvYDelta)
126 {
127 double aDeltaRed(rB.getRed() - rA.getRed());
128
129 if(fTools::equalZero(aDeltaRed))
130 {
131 aDeltaRed = 0.0;
132 }
133 else
134 {
135 aDeltaRed *= fInvYDelta;
136 }
137
138 double aDeltaGreen(rB.getGreen() - rA.getGreen());
139
140 if(fTools::equalZero(aDeltaGreen))
141 {
142 aDeltaGreen = 0.0;
143 }
144 else
145 {
146 aDeltaGreen *= fInvYDelta;
147 }
148
149 double aDeltaBlue(rB.getBlue() - rA.getBlue());
150
151 if(fTools::equalZero(aDeltaBlue))
152 {
153 aDeltaBlue = 0.0;
154 }
155 else
156 {
157 aDeltaBlue *= fInvYDelta;
158 }
159
160 maColorInterpolators.push_back(
161 ip_triple(
162 rA.getRed(), aDeltaRed,
163 rA.getGreen(), aDeltaGreen,
164 rA.getBlue(), aDeltaBlue));
165
166 return (maColorInterpolators.size() - 1);
167 }
168
169 sal_uInt32 addNormalInterpolator(const B3DVector& rA, const B3DVector& rB, double fInvYDelta)
170 {
171 double aDeltaX(rB.getX() - rA.getX());
172
173 if(fTools::equalZero(aDeltaX))
174 {
175 aDeltaX = 0.0;
176 }
177 else
178 {
179 aDeltaX *= fInvYDelta;
180 }
181
182 double aDeltaY(rB.getY() - rA.getY());
183
184 if(fTools::equalZero(aDeltaY))
185 {
186 aDeltaY = 0.0;
187 }
188 else
189 {
190 aDeltaY *= fInvYDelta;
191 }
192
193 double aDeltaZ(rB.getZ() - rA.getZ());
194
195 if(fTools::equalZero(aDeltaZ))
196 {
197 aDeltaZ = 0.0;
198 }
199 else
200 {
201 aDeltaZ *= fInvYDelta;
202 }
203
204 maNormalInterpolators.push_back(
205 ip_triple(
206 rA.getX(), aDeltaX,
207 rA.getY(), aDeltaY,
208 rA.getZ(), aDeltaZ));
209
210 return (maNormalInterpolators.size() - 1);
211 }
212
213 sal_uInt32 addTextureInterpolator(const B2DPoint& rA, const B2DPoint& rB, double fInvYDelta)
214 {
215 double aDeltaX(rB.getX() - rA.getX());
216
217 if(fTools::equalZero(aDeltaX))
218 {
219 aDeltaX = 0.0;
220 }
221 else
222 {
223 aDeltaX *= fInvYDelta;
224 }
225
226 double aDeltaY(rB.getY() - rA.getY());
227
228 if(fTools::equalZero(aDeltaY))
229 {
230 aDeltaY = 0.0;
231 }
232 else
233 {
234 aDeltaY *= fInvYDelta;
235 }
236
237 maTextureInterpolators.push_back(
238 ip_double(
239 rA.getX(), aDeltaX,
240 rA.getY(), aDeltaY));
241
242 return (maTextureInterpolators.size() - 1);
243 }
244
245 sal_uInt32 addInverseTextureInterpolator(const B2DPoint& rA, const B2DPoint& rB, double fZEyeA, double fZEyeB, double fInvYDelta)
246 {
247 double fZDelta(fZEyeB - fZEyeA);
248 const double fInvZEyeA(fTools::equalZero(fZEyeA) ? fZEyeA : 1.0 / fZEyeA);
249 double fInvZEyeB(fInvZEyeA);
250
251 if(fTools::equalZero(fZDelta))
252 {
253 fZDelta = 0.0;
254 }
255 else
256 {
257 fInvZEyeB = fTools::equalZero(fZEyeB) ? fZEyeB : 1.0 / fZEyeB;
258 fZDelta = (fInvZEyeB - fInvZEyeA) * fInvYDelta;
259 }
260
261 const B2DPoint aInvA(rA * fInvZEyeA);
262 const B2DPoint aInvB(rB * fInvZEyeB);
263 const double aDeltaX((aInvB.getX() - aInvA.getX()) * fInvYDelta);
264 const double aDeltaY((aInvB.getY() - aInvA.getY()) * fInvYDelta);
265
267 ip_triple(
268 aInvA.getX(), aDeltaX,
269 aInvA.getY(), aDeltaY,
270 fInvZEyeA, fZDelta));
271
272 return (maInverseTextureInterpolators.size() - 1);
273 }
274
275 void reset()
276 {
277 maColorInterpolators.clear();
278 maNormalInterpolators.clear();
281 }
282
283 public:
285
286 ::std::vector< ip_triple >& getColorInterpolators() { return maColorInterpolators; }
287 ::std::vector< ip_triple >& getNormalInterpolators() { return maNormalInterpolators; }
288 ::std::vector< ip_double >& getTextureInterpolators() { return maTextureInterpolators; }
289 ::std::vector< ip_triple >& getInverseTextureInterpolators() { return maInverseTextureInterpolators; }
290 };
291
292 // RasterConversionLineEntry3D for Rasterconversion of 3D PolyPolygons
293
295 {
296 private:
299 sal_Int32 mnY;
300 sal_uInt32 mnCount;
301
302 sal_uInt32 mnColorIndex;
303 sal_uInt32 mnNormalIndex;
304 sal_uInt32 mnTextureIndex;
306
307 public:
308 RasterConversionLineEntry3D(const double& rfX, const double& rfDeltaX, const double& rfZ, const double& rfDeltaZ, sal_Int32 nY, sal_uInt32 nCount)
309 : maX(rfX, rfDeltaX),
310 maZ(rfZ, rfDeltaZ),
311 mnY(nY),
317 {}
318
319 void setColorIndex(sal_uInt32 nIndex) { mnColorIndex = nIndex; }
320 void setNormalIndex(sal_uInt32 nIndex) { mnNormalIndex = nIndex; }
321 void setTextureIndex(sal_uInt32 nIndex) { mnTextureIndex = nIndex; }
323
324 bool operator<(const RasterConversionLineEntry3D& rComp) const
325 {
326 if(mnY == rComp.mnY)
327 {
328 return maX.getVal() < rComp.maX.getVal();
329 }
330
331 return mnY < rComp.mnY;
332 }
333
335 {
336 if(nStep >= mnCount)
337 {
338 return false;
339 }
340 else
341 {
342 mnCount -= nStep;
343 return true;
344 }
345 }
346
348 {
349 const double fStep(static_cast<double>(nStep));
350 maX.increment(fStep);
351 maZ.increment(fStep);
352 mnY += nStep;
353
355 {
356 rProvider.getColorInterpolators()[mnColorIndex].increment(fStep);
357 }
358
360 {
361 rProvider.getNormalInterpolators()[mnNormalIndex].increment(fStep);
362 }
363
365 {
366 rProvider.getTextureInterpolators()[mnTextureIndex].increment(fStep);
367 }
368
370 {
371 rProvider.getInverseTextureInterpolators()[mnInverseTextureIndex].increment(fStep);
372 }
373 }
374
375 // data read access
376 const ip_single& getX() const { return maX; }
377 sal_Int32 getY() const { return mnY; }
378 const ip_single& getZ() const { return maZ; }
379 sal_uInt32 getColorIndex() const { return mnColorIndex; }
380 sal_uInt32 getNormalIndex() const { return mnNormalIndex; }
381 sal_uInt32 getTextureIndex() const { return mnTextureIndex; }
382 sal_uInt32 getInverseTextureIndex() const { return mnInverseTextureIndex; }
383 };
384
385 // the basic RasterConverter itself. Only one method needs to be overridden. The
386 // class itself is pure virtual
387
388 class UNLESS_MERGELIBS(BASEGFX_DLLPUBLIC) RasterConverter3D : public InterpolatorProvider3D
389 {
390 private:
391 // the line entries for an area conversion run
392 ::std::vector< RasterConversionLineEntry3D > maLineEntries;
393
394 struct lineComparator
395 {
396 bool operator()(const RasterConversionLineEntry3D* pA, const RasterConversionLineEntry3D* pB)
397 {
398 OSL_ENSURE(pA && pB, "lineComparator: empty pointer (!)");
399 return pA->getX().getVal() < pB->getX().getVal();
400 }
401 };
402
403 SAL_DLLPRIVATE void addArea(const B3DPolygon& rFill, const B3DHomMatrix* pViewToEye);
404 SAL_DLLPRIVATE void addArea(const B3DPolyPolygon& rFill, const B3DHomMatrix* pViewToEye);
405 SAL_DLLPRIVATE void addEdge(const B3DPolygon& rFill, sal_uInt32 a, sal_uInt32 b, const B3DHomMatrix* pViewToEye);
406
407 SAL_DLLPRIVATE void rasterconvertB3DArea(sal_Int32 nStartLine, sal_Int32 nStopLine);
408 SAL_DLLPRIVATE void rasterconvertB3DEdge(const B3DPolygon& rLine, sal_uInt32 nA, sal_uInt32 nB, sal_Int32 nStartLine, sal_Int32 nStopLine, sal_uInt16 nLineWidth);
409
410 virtual void processLineSpan(const RasterConversionLineEntry3D& rA, const RasterConversionLineEntry3D& rB, sal_Int32 nLine, sal_uInt32 nSpanCount) = 0;
411
412 public:
413 RasterConverter3D();
414 virtual ~RasterConverter3D();
415
416 void rasterconvertB3DPolyPolygon(const B3DPolyPolygon& rFill, const B3DHomMatrix* pViewToEye, sal_Int32 nStartLine, sal_Int32 nStopLine);
417 void rasterconvertB3DPolygon(const B3DPolygon& rLine, sal_Int32 nStartLine, sal_Int32 nStopLine, sal_uInt16 nLineWidth);
418 };
419} // end of namespace basegfx
420
421/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base Point class with two double values.
Definition: b2dpoint.hxx:42
Base Point class with three double values.
Definition: b3dvector.hxx:38
Base Color class with three double values.
Definition: bcolor.hxx:41
double getBlue() const
Definition: bcolor.hxx:80
double getRed() const
Definition: bcolor.hxx:78
double getGreen() const
Definition: bcolor.hxx:79
::std::vector< ip_double > maTextureInterpolators
sal_uInt32 addColorInterpolator(const BColor &rA, const BColor &rB, double fInvYDelta)
::std::vector< ip_triple > maInverseTextureInterpolators
sal_uInt32 addNormalInterpolator(const B3DVector &rA, const B3DVector &rB, double fInvYDelta)
::std::vector< ip_triple > maColorInterpolators
::std::vector< ip_triple > & getNormalInterpolators()
::std::vector< ip_triple > maNormalInterpolators
::std::vector< ip_triple > & getInverseTextureInterpolators()
sal_uInt32 addInverseTextureInterpolator(const B2DPoint &rA, const B2DPoint &rB, double fZEyeA, double fZEyeB, double fInvYDelta)
::std::vector< ip_triple > & getColorInterpolators()
::std::vector< ip_double > & getTextureInterpolators()
sal_uInt32 addTextureInterpolator(const B2DPoint &rA, const B2DPoint &rB, double fInvYDelta)
void setTextureIndex(sal_uInt32 nIndex)
RasterConversionLineEntry3D(const double &rfX, const double &rfDeltaX, const double &rfZ, const double &rfDeltaZ, sal_Int32 nY, sal_uInt32 nCount)
bool operator<(const RasterConversionLineEntry3D &rComp) const
bool decrementRasterConversionLineEntry3D(sal_uInt32 nStep)
void setInverseTextureIndex(sal_uInt32 nIndex)
void incrementRasterConversionLineEntry3D(sal_uInt32 nStep, InterpolatorProvider3D &rProvider)
void setNormalIndex(sal_uInt32 nIndex)
TYPE getX() const
Get X-Coordinate of 2D Tuple.
Definition: Tuple2D.hxx:63
TYPE getY() const
Get Y-Coordinate of 2D Tuple.
Definition: Tuple2D.hxx:66
TYPE getX() const
Get X-Coordinate of 3D Tuple.
Definition: Tuple3D.hxx:57
TYPE getZ() const
Get Z-Coordinate of 3D Tuple.
Definition: Tuple3D.hxx:63
TYPE getY() const
Get Y-Coordinate of 3D Tuple.
Definition: Tuple3D.hxx:60
const ip_single & getY() const
ip_double(double fXVal, double fXInc, double fYVal, double fYInc)
void increment(double fStep)
const ip_single & getX() const
double getVal() const
void increment(double fStep)
double getInc() const
ip_single(double fVal, double fInc)
void increment(double fStep)
ip_triple(double fXVal, double fXInc, double fYVal, double fYInc, double fZVal, double fZInc)
const ip_single & getZ() const
const ip_single & getY() const
const ip_single & getX() const
int nCount
sal_Int32 nIndex
bool equalZero(const T &rfVal)
Compare against small value.
Definition: ftools.hxx:156
#define SCANLINE_EMPTY_INDEX