Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _BGFX_RASTER_RASTERCONVERT3D_HXX
30 : : #define _BGFX_RASTER_RASTERCONVERT3D_HXX
31 : :
32 : : #include <sal/types.h>
33 : : #include <vector>
34 : : #include <basegfx/color/bcolor.hxx>
35 : : #include <basegfx/vector/b3dvector.hxx>
36 : : #include <basegfx/point/b2dpoint.hxx>
37 : : #include <basegfx/vector/b2dvector.hxx>
38 : : #include <basegfx/basegfxdllapi.h>
39 : :
40 : : //////////////////////////////////////////////////////////////////////////////
41 : : // predeclarations
42 : :
43 : : namespace basegfx
44 : : {
45 : : class B3DPolygon;
46 : : class B3DPolyPolygon;
47 : : }
48 : :
49 : : //////////////////////////////////////////////////////////////////////////////
50 : : // interpolators for double precision
51 : :
52 : : namespace basegfx
53 : : {
54 : : class ip_single
55 : : {
56 : : private:
57 : : double mfVal;
58 : : double mfInc;
59 : :
60 : : public:
61 : 180 : ip_single()
62 : : : mfVal(0.0),
63 : 180 : mfInc(0.0)
64 : 180 : {}
65 : :
66 : 90422 : ip_single(double fVal, double fInc)
67 : : : mfVal(fVal),
68 : 90422 : mfInc(fInc)
69 : 90422 : {}
70 : :
71 : 4119784 : double getVal() const { return mfVal; }
72 : : double getInc() const { return mfInc; }
73 : :
74 : 3732360 : void increment(double fStep) { mfVal += fStep * mfInc; }
75 : : };
76 : : } // end of namespace basegfx
77 : :
78 : : namespace basegfx
79 : : {
80 : : class ip_double
81 : : {
82 : : private:
83 : : ip_single maX;
84 : : ip_single maY;
85 : :
86 : : public:
87 : 15 : ip_double()
88 : : : maX(),
89 : 15 : maY()
90 : 15 : {}
91 : :
92 : 0 : ip_double(double fXVal, double fXInc, double fYVal, double fYInc)
93 : : : maX(fXVal, fXInc),
94 : 0 : maY(fYVal, fYInc)
95 : 0 : {}
96 : :
97 : 0 : const ip_single& getX() const { return maX; }
98 : 0 : const ip_single& getY() const { return maY; }
99 : :
100 : 0 : void increment(double fStep) { maX.increment(fStep); maY.increment(fStep); }
101 : : };
102 : : } // end of namespace basegfx
103 : :
104 : : namespace basegfx
105 : : {
106 : : class ip_triple
107 : : {
108 : : private:
109 : : ip_single maX;
110 : : ip_single maY;
111 : : ip_single maZ;
112 : :
113 : : public:
114 : 45 : ip_triple()
115 : : : maX(),
116 : : maY(),
117 : 45 : maZ()
118 : 45 : {}
119 : :
120 : 12964 : ip_triple(double fXVal, double fXInc, double fYVal, double fYInc, double fZVal, double fZInc)
121 : : : maX(fXVal, fXInc),
122 : : maY(fYVal, fYInc),
123 : 12964 : maZ(fZVal, fZInc)
124 : 12964 : {}
125 : :
126 : 407548 : const ip_single& getX() const { return maX; }
127 : 407548 : const ip_single& getY() const { return maY; }
128 : 407548 : const ip_single& getZ() const { return maZ; }
129 : :
130 : 381936 : void increment(double fStep) { maX.increment(fStep); maY.increment(fStep); maZ.increment(fStep); }
131 : : };
132 : : } // end of namespace basegfx
133 : :
134 : : //////////////////////////////////////////////////////////////////////////////
135 : : // InterpolatorProvider3D to have a common source for allocating interpolators
136 : : // which may then be addressed using the index to the vectors
137 : :
138 : : namespace basegfx
139 : : {
140 : : #define SCANLINE_EMPTY_INDEX (0xffffffff)
141 : :
142 : : class InterpolatorProvider3D
143 : : {
144 : : private:
145 : : ::std::vector< ip_triple > maColorInterpolators;
146 : : ::std::vector< ip_triple > maNormalInterpolators;
147 : : ::std::vector< ip_double > maTextureInterpolators;
148 : : ::std::vector< ip_triple > maInverseTextureInterpolators;
149 : :
150 : : protected:
151 : : sal_uInt32 addColorInterpolator(const BColor& rA, const BColor& rB, double fInvYDelta)
152 : : {
153 : : B3DVector aDelta(rB.getRed() - rA.getRed(), rB.getGreen() - rA.getGreen(), rB.getBlue() - rA.getBlue());
154 : : aDelta *= fInvYDelta;
155 : : maColorInterpolators.push_back(ip_triple(rA.getRed(), aDelta.getX(), rA.getGreen(), aDelta.getY(), rA.getBlue(), aDelta.getZ()));
156 : : return (maColorInterpolators.size() - 1L);
157 : : }
158 : :
159 : : sal_uInt32 addNormalInterpolator(const B3DVector& rA, const B3DVector& rB, double fInvYDelta)
160 : : {
161 : : B3DVector aDelta(rB.getX() - rA.getX(), rB.getY() - rA.getY(), rB.getZ() - rA.getZ());
162 : : aDelta *= fInvYDelta;
163 : : maNormalInterpolators.push_back(ip_triple(rA.getX(), aDelta.getX(), rA.getY(), aDelta.getY(), rA.getZ(), aDelta.getZ()));
164 : : return (maNormalInterpolators.size() - 1L);
165 : : }
166 : :
167 : : sal_uInt32 addTextureInterpolator(const B2DPoint& rA, const B2DPoint& rB, double fInvYDelta)
168 : : {
169 : : B2DVector aDelta(rB.getX() - rA.getX(), rB.getY() - rA.getY());
170 : : aDelta *= fInvYDelta;
171 : : maTextureInterpolators.push_back(ip_double(rA.getX(), aDelta.getX(), rA.getY(), aDelta.getY()));
172 : : return (maTextureInterpolators.size() - 1L);
173 : : }
174 : :
175 : : sal_uInt32 addInverseTextureInterpolator(const B2DPoint& rA, const B2DPoint& rB, double fZEyeA, double fZEyeB, double fInvYDelta)
176 : : {
177 : : const double fInvZEyeA(fTools::equalZero(fZEyeA) ? fZEyeA : 1.0 / fZEyeA);
178 : : const double fInvZEyeB(fTools::equalZero(fZEyeB) ? fZEyeB : 1.0 / fZEyeB);
179 : : const B2DPoint aInvA(rA * fInvZEyeA);
180 : : const B2DPoint aInvB(rB * fInvZEyeB);
181 : : double fZDelta(fInvZEyeB - fInvZEyeA);
182 : : B2DVector aDelta(aInvB.getX() - aInvA.getX(), aInvB.getY() - aInvA.getY());
183 : :
184 : : fZDelta *= fInvYDelta;
185 : : aDelta *= fInvYDelta;
186 : :
187 : : maInverseTextureInterpolators.push_back(ip_triple(aInvA.getX(), aDelta.getX(), aInvA.getY(), aDelta.getY(), fInvZEyeA, fZDelta));
188 : : return (maInverseTextureInterpolators.size() - 1L);
189 : : }
190 : :
191 : : void reset()
192 : : {
193 : : maColorInterpolators.clear();
194 : : maNormalInterpolators.clear();
195 : : maTextureInterpolators.clear();
196 : : maInverseTextureInterpolators.clear();
197 : : }
198 : :
199 : : public:
200 : : InterpolatorProvider3D() {}
201 : :
202 : 12964 : ::std::vector< ip_triple >& getColorInterpolators() { return maColorInterpolators; }
203 : 0 : ::std::vector< ip_triple >& getNormalInterpolators() { return maNormalInterpolators; }
204 : 0 : ::std::vector< ip_double >& getTextureInterpolators() { return maTextureInterpolators; }
205 : 12964 : ::std::vector< ip_triple >& getInverseTextureInterpolators() { return maInverseTextureInterpolators; }
206 : : };
207 : : } // end of namespace basegfx
208 : :
209 : : //////////////////////////////////////////////////////////////////////////////
210 : : // RasterConversionLineEntry3D for Raterconversion of 3D PolyPolygons
211 : :
212 : : namespace basegfx
213 : : {
214 : : class RasterConversionLineEntry3D
215 : : {
216 : : private:
217 : : ip_single maX;
218 : : ip_single maZ;
219 : : sal_Int32 mnY;
220 : : sal_uInt32 mnCount;
221 : :
222 : : sal_uInt32 mnColorIndex;
223 : : sal_uInt32 mnNormalIndex;
224 : : sal_uInt32 mnTextureIndex;
225 : : sal_uInt32 mnInverseTextureIndex;
226 : :
227 : : public:
228 : : RasterConversionLineEntry3D(const double& rfX, const double& rfDeltaX, const double& rfZ, const double& rfDeltaZ, sal_Int32 nY, sal_uInt32 nCount)
229 : : : maX(rfX, rfDeltaX),
230 : : maZ(rfZ, rfDeltaZ),
231 : : mnY(nY),
232 : : mnCount(nCount),
233 : : mnColorIndex(SCANLINE_EMPTY_INDEX),
234 : : mnNormalIndex(SCANLINE_EMPTY_INDEX),
235 : : mnTextureIndex(SCANLINE_EMPTY_INDEX),
236 : : mnInverseTextureIndex(SCANLINE_EMPTY_INDEX)
237 : : {}
238 : :
239 : : void setColorIndex(sal_uInt32 nIndex) { mnColorIndex = nIndex; }
240 : : void setNormalIndex(sal_uInt32 nIndex) { mnNormalIndex = nIndex; }
241 : : void setTextureIndex(sal_uInt32 nIndex) { mnTextureIndex = nIndex; }
242 : : void setInverseTextureIndex(sal_uInt32 nIndex) { mnInverseTextureIndex = nIndex; }
243 : :
244 : : bool operator<(const RasterConversionLineEntry3D& rComp) const
245 : : {
246 : : if(mnY == rComp.mnY)
247 : : {
248 : : return maX.getVal() < rComp.maX.getVal();
249 : : }
250 : :
251 : : return mnY < rComp.mnY;
252 : : }
253 : :
254 : : bool decrementRasterConversionLineEntry3D(sal_uInt32 nStep)
255 : : {
256 : : if(nStep >= mnCount)
257 : : {
258 : : return false;
259 : : }
260 : : else
261 : : {
262 : : mnCount -= nStep;
263 : : return true;
264 : : }
265 : : }
266 : :
267 : : void incrementRasterConversionLineEntry3D(sal_uInt32 nStep, InterpolatorProvider3D& rProvider)
268 : : {
269 : : const double fStep((double)nStep);
270 : : maX.increment(fStep);
271 : : maZ.increment(fStep);
272 : : mnY += nStep;
273 : :
274 : : if(SCANLINE_EMPTY_INDEX != mnColorIndex)
275 : : {
276 : : rProvider.getColorInterpolators()[mnColorIndex].increment(fStep);
277 : : }
278 : :
279 : : if(SCANLINE_EMPTY_INDEX != mnNormalIndex)
280 : : {
281 : : rProvider.getNormalInterpolators()[mnNormalIndex].increment(fStep);
282 : : }
283 : :
284 : : if(SCANLINE_EMPTY_INDEX != mnTextureIndex)
285 : : {
286 : : rProvider.getTextureInterpolators()[mnTextureIndex].increment(fStep);
287 : : }
288 : :
289 : : if(SCANLINE_EMPTY_INDEX != mnInverseTextureIndex)
290 : : {
291 : : rProvider.getInverseTextureInterpolators()[mnInverseTextureIndex].increment(fStep);
292 : : }
293 : : }
294 : :
295 : : // data read access
296 : 259058 : const ip_single& getX() const { return maX; }
297 : : sal_Int32 getY() const { return mnY; }
298 : 103060 : const ip_single& getZ() const { return maZ; }
299 : 70976 : sal_uInt32 getColorIndex() const { return mnColorIndex; }
300 : 51530 : sal_uInt32 getNormalIndex() const { return mnNormalIndex; }
301 : 51530 : sal_uInt32 getTextureIndex() const { return mnTextureIndex; }
302 : 70976 : sal_uInt32 getInverseTextureIndex() const { return mnInverseTextureIndex; }
303 : : };
304 : : } // end of namespace basegfx
305 : :
306 : : //////////////////////////////////////////////////////////////////////////////
307 : : // the basic RaterConverter itself. Only one method needs to be overloaded. The
308 : : // class itself is strictly virtual
309 : :
310 : : namespace basegfx
311 : : {
312 : : class BASEGFX_DLLPUBLIC RasterConverter3D : public InterpolatorProvider3D
313 : : {
314 : : private:
315 : : // the line entries for an area conversion run
316 : : ::std::vector< RasterConversionLineEntry3D > maLineEntries;
317 : :
318 : : struct lineComparator
319 : : {
320 : : bool operator()(const RasterConversionLineEntry3D* pA, const RasterConversionLineEntry3D* pB)
321 : : {
322 : : OSL_ENSURE(pA && pB, "lineComparator: empty pointer (!)");
323 : : return pA->getX().getVal() < pB->getX().getVal();
324 : : }
325 : : };
326 : :
327 : : void addArea(const B3DPolygon& rFill, const B3DHomMatrix* pViewToEye);
328 : : void addArea(const B3DPolyPolygon& rFill, const B3DHomMatrix* pViewToEye);
329 : : void addEdge(const B3DPolygon& rFill, sal_uInt32 a, sal_uInt32 b, const B3DHomMatrix* pViewToEye);
330 : :
331 : : void rasterconvertB3DArea(sal_Int32 nStartLine, sal_Int32 nStopLine);
332 : : void rasterconvertB3DEdge(const B3DPolygon& rLine, sal_uInt32 nA, sal_uInt32 nB, sal_Int32 nStartLine, sal_Int32 nStopLine, sal_uInt16 nLineWidth);
333 : :
334 : : virtual void processLineSpan(const RasterConversionLineEntry3D& rA, const RasterConversionLineEntry3D& rB, sal_Int32 nLine, sal_uInt32 nSpanCount) = 0;
335 : :
336 : : public:
337 : : RasterConverter3D();
338 : : virtual ~RasterConverter3D();
339 : :
340 : : void rasterconvertB3DPolyPolygon(const B3DPolyPolygon& rFill, const B3DHomMatrix* pViewToEye, sal_Int32 nStartLine, sal_Int32 nStopLine);
341 : : void rasterconvertB3DPolygon(const B3DPolygon& rLine, sal_Int32 nStartLine, sal_Int32 nStopLine, sal_uInt16 nLineWidth);
342 : : };
343 : : } // end of namespace basegfx
344 : :
345 : : //////////////////////////////////////////////////////////////////////////////
346 : :
347 : : #endif /* _BGFX_RASTER_RASTERCONVERT3D_HXX */
348 : :
349 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|