30 void RasterConverter3D::addArea(
const B3DPolygon& rFill,
const B3DHomMatrix* pViewToEye)
32 const sal_uInt32 nPointCount(rFill.count());
34 for(sal_uInt32
a(0);
a < nPointCount;
a++)
36 addEdge(rFill, a, (a + 1) % nPointCount, pViewToEye);
40 void RasterConverter3D::addArea(
const B3DPolyPolygon& rFill,
const B3DHomMatrix* pViewToEye)
42 const sal_uInt32 nPolyCount(rFill.count());
44 for(sal_uInt32
a(0);
a < nPolyCount;
a++)
46 addArea(rFill.getB3DPolygon(a), pViewToEye);
50 RasterConverter3D::RasterConverter3D()
53 RasterConverter3D::~RasterConverter3D()
56 void RasterConverter3D::rasterconvertB3DArea(sal_Int32 nStartLine, sal_Int32 nStopLine)
58 if(maLineEntries.empty())
61 OSL_ENSURE(nStopLine >= nStartLine,
"nStopLine is bigger than nStartLine (!)");
65 std::sort(maLineEntries.begin(), maLineEntries.end());
68 std::vector< RasterConversionLineEntry3D >::iterator aCurrentEntry(maLineEntries.begin());
69 std::vector< RasterConversionLineEntry3D* > aCurrentLine;
70 std::vector< RasterConversionLineEntry3D* > aNextLine;
71 std::vector< RasterConversionLineEntry3D* >::iterator aRasterConversionLineEntry3D;
74 sal_Int32 nLineNumber(std::max(aCurrentEntry->getY(), nStartLine));
76 while((!aCurrentLine.empty() || aCurrentEntry != maLineEntries.end()) && (nLineNumber < nStopLine))
79 while(aCurrentEntry != maLineEntries.end())
81 const sal_Int32 nCurrentLineNumber(aCurrentEntry->getY());
83 if(nCurrentLineNumber > nLineNumber)
92 const sal_uInt32 nStep(nLineNumber - nCurrentLineNumber);
94 if(!nStep || aCurrentEntry->decrementRasterConversionLineEntry3D(nStep))
100 aCurrentEntry->incrementRasterConversionLineEntry3D(nStep, *
this);
103 aCurrentLine.push_back(&(*aCurrentEntry));
114 std::sort(aCurrentLine.begin(), aCurrentLine.end(), lineComparator());
117 aRasterConversionLineEntry3D = aCurrentLine.begin();
119 sal_uInt32 nPairCount(0);
121 while(aRasterConversionLineEntry3D != aCurrentLine.end())
123 RasterConversionLineEntry3D& rPrevScanRasterConversionLineEntry3D(**aRasterConversionLineEntry3D++);
126 if(aRasterConversionLineEntry3D != aCurrentLine.end())
129 processLineSpan(rPrevScanRasterConversionLineEntry3D, **aRasterConversionLineEntry3D, nLineNumber, nPairCount++);
133 if(rPrevScanRasterConversionLineEntry3D.decrementRasterConversionLineEntry3D(1))
135 rPrevScanRasterConversionLineEntry3D.incrementRasterConversionLineEntry3D(1, *
this);
136 aNextLine.push_back(&rPrevScanRasterConversionLineEntry3D);
141 if(aNextLine.size() != aCurrentLine.size())
143 aCurrentLine = aNextLine;
151 void RasterConverter3D::addEdge(
const B3DPolygon& rFill, sal_uInt32 a, sal_uInt32 b,
const B3DHomMatrix* pViewToEye)
153 B3DPoint aStart(rFill.getB3DPoint(a));
154 B3DPoint aEnd(rFill.getB3DPoint(b));
155 sal_Int32 nYStart(
fround(aStart.getY()));
156 sal_Int32 nYEnd(
fround(aEnd.getY()));
163 std::swap(aStart, aEnd);
164 std::swap(nYStart, nYEnd);
168 const sal_uInt32 nYDelta(nYEnd - nYStart);
169 const double fInvYDelta(1.0 / nYDelta);
170 maLineEntries.emplace_back(
171 aStart.getX(), (aEnd.getX() - aStart.getX()) * fInvYDelta,
172 aStart.getZ(), (aEnd.getZ() - aStart.getZ()) * fInvYDelta,
176 RasterConversionLineEntry3D& rEntry = maLineEntries[maLineEntries.size() - 1];
178 if(rFill.areBColorsUsed())
180 rEntry.setColorIndex(addColorInterpolator(rFill.getBColor(a), rFill.getBColor(b), fInvYDelta));
183 if(rFill.areNormalsUsed())
185 rEntry.setNormalIndex(addNormalInterpolator(rFill.getNormal(a), rFill.getNormal(b), fInvYDelta));
188 if(!rFill.areTextureCoordinatesUsed())
193 const double fEyeA(((*pViewToEye) * aStart).getZ());
194 const double fEyeB(((*pViewToEye) * aEnd).getZ());
196 rEntry.setInverseTextureIndex(addInverseTextureInterpolator(
197 rFill.getTextureCoordinate(a),
198 rFill.getTextureCoordinate(b),
199 fEyeA, fEyeB, fInvYDelta));
203 rEntry.setTextureIndex(addTextureInterpolator(
204 rFill.getTextureCoordinate(a),
205 rFill.getTextureCoordinate(b),
210 void RasterConverter3D::rasterconvertB3DEdge(
const B3DPolygon& rLine, sal_uInt32 nA, sal_uInt32 nB, sal_Int32 nStartLine, sal_Int32 nStopLine, sal_uInt16 nLineWidth)
212 B3DPoint aStart(rLine.getB3DPoint(nA));
213 B3DPoint aEnd(rLine.getB3DPoint(nB));
214 const double fZBufferLineAdd(0x00ff);
220 if(!aStart.equal(aEnd))
223 maLineEntries.clear();
225 B2DVector aVector(aEnd.getX() - aStart.getX(), aEnd.getY() - aStart.getY());
227 const B2DVector aPerpend(
getPerpendicular(aVector) * ((
static_cast<double>(nLineWidth) + 0.5) * 0.5));
228 const double fZStartWithAdd(aStart.getZ() + fZBufferLineAdd);
229 const double fZEndWithAdd(aEnd.getZ() + fZBufferLineAdd);
232 aPolygon.append(B3DPoint(aStart.getX() + aPerpend.getX(), aStart.getY() + aPerpend.getY(), fZStartWithAdd));
233 aPolygon.append(B3DPoint(aEnd.getX() + aPerpend.getX(), aEnd.getY() + aPerpend.getY(), fZEndWithAdd));
234 aPolygon.append(B3DPoint(aEnd.getX() - aPerpend.getX(), aEnd.getY() - aPerpend.getY(), fZEndWithAdd));
235 aPolygon.append(B3DPoint(aStart.getX() - aPerpend.getX(), aStart.getY() - aPerpend.getY(), fZStartWithAdd));
236 aPolygon.setClosed(
true);
238 addArea(aPolygon,
nullptr);
245 sal_Int32 nYStart(
fround(aStart.getY()));
246 sal_Int32 nYEnd(
fround(aEnd.getY()));
251 const sal_Int32 nXStart(
static_cast<sal_Int32
>(aStart.getX()));
252 const sal_Int32 nXEnd(
static_cast<sal_Int32
>(aEnd.getX()));
257 maLineEntries.clear();
261 maLineEntries.emplace_back(
263 aStart.getZ() + fZBufferLineAdd, 0.0,
265 maLineEntries.emplace_back(
267 aEnd.getZ() + fZBufferLineAdd, 0.0,
274 maLineEntries.clear();
278 std::swap(aStart, aEnd);
279 std::swap(nYStart, nYEnd);
282 const sal_uInt32 nYDelta(
static_cast<sal_uInt32
>(nYEnd - nYStart));
283 const double fInvYDelta(1.0 / nYDelta);
287 maLineEntries.emplace_back(
288 aStart.getX(), (aEnd.getX() - aStart.getX()) * fInvYDelta,
289 aStart.getZ() + fZBufferLineAdd, (aEnd.getZ() - aStart.getZ()) * fInvYDelta,
292 RasterConversionLineEntry3D& rEntry = maLineEntries[maLineEntries.size() - 1];
298 const double fDistanceX(fabs(rEntry.getX().getInc()) >= 1.0 ? rEntry.getX().getInc() : 1.0);
300 maLineEntries.emplace_back(
301 rEntry.getX().getVal() + fDistanceX, rEntry.getX().getInc(),
302 rEntry.getZ().getVal() + rEntry.getZ().getInc(), rEntry.getZ().getInc(),
307 if(!maLineEntries.empty())
309 rasterconvertB3DArea(nStartLine, nStopLine);
313 void RasterConverter3D::rasterconvertB3DPolyPolygon(
const B3DPolyPolygon& rFill,
const B3DHomMatrix* pViewToEye, sal_Int32 nStartLine, sal_Int32 nStopLine)
316 maLineEntries.clear();
317 addArea(rFill, pViewToEye);
318 rasterconvertB3DArea(nStartLine, nStopLine);
321 void RasterConverter3D::rasterconvertB3DPolygon(
const B3DPolygon& rLine, sal_Int32 nStartLine, sal_Int32 nStopLine, sal_uInt16 nLineWidth)
323 const sal_uInt32 nPointCount(rLine.count());
327 const sal_uInt32 nEdgeCount(rLine.isClosed() ? nPointCount : nPointCount - 1);
329 for(sal_uInt32
a(0);
a < nEdgeCount;
a++)
331 rasterconvertB3DEdge(rLine, a, (a + 1) % nPointCount, nStartLine, nStopLine, nLineWidth);
B2DVector getPerpendicular(const B2DVector &rNormalizedVec)
Calculate a perpendicular 2D Vector to the given one.
B2IRange fround(const B2DRange &rRange)
Round double to nearest integer for 2D range.