Bugfixes of tensor patch mesh

This commit is contained in:
Jakub Melka
2019-09-21 15:55:33 +02:00
parent d5d92a4e54
commit 2ca3f907c3
3 changed files with 37 additions and 9 deletions

View File

@ -620,7 +620,14 @@ void PDFPageContentProcessor::processPathPainting(const QPainterPath& path, bool
// Now, merge the current path to the mesh clipping path // Now, merge the current path to the mesh clipping path
QPainterPath boundingPath = mesh.getBoundingPath(); QPainterPath boundingPath = mesh.getBoundingPath();
boundingPath.addPath(getCurrentWorldMatrix().map(path)); if (boundingPath.isEmpty())
{
boundingPath = getCurrentWorldMatrix().map(path);
}
else
{
boundingPath = boundingPath.intersected(path);
}
mesh.setBoundingPath(boundingPath); mesh.setBoundingPath(boundingPath);
performMeshPainting(mesh); performMeshPainting(mesh);
@ -686,7 +693,14 @@ void PDFPageContentProcessor::processPathPainting(const QPainterPath& path, bool
QPainterPath strokedPath = stroker.createStroke(path); QPainterPath strokedPath = stroker.createStroke(path);
QPainterPath boundingPath = mesh.getBoundingPath(); QPainterPath boundingPath = mesh.getBoundingPath();
boundingPath.addPath(getCurrentWorldMatrix().map(strokedPath)); if (boundingPath.isEmpty())
{
boundingPath = getCurrentWorldMatrix().map(strokedPath);
}
else
{
boundingPath = boundingPath.intersected(strokedPath);
}
mesh.setBoundingPath(boundingPath); mesh.setBoundingPath(boundingPath);
performMeshPainting(mesh); performMeshPainting(mesh);

View File

@ -1351,8 +1351,6 @@ PDFMesh PDFFreeFormGouradTriangleShading::createMesh(const PDFMeshQualitySetting
std::vector<VertexData> vertices; std::vector<VertexData> vertices;
vertices.resize(vertexCount); vertices.resize(vertexCount);
std::vector<size_t> indices(vertexCount, 0);
std::iota(indices.begin(), indices.end(), static_cast<size_t>(0));
std::vector<QPointF> meshVertices; std::vector<QPointF> meshVertices;
meshVertices.resize(vertexCount); meshVertices.resize(vertexCount);
@ -1382,6 +1380,7 @@ PDFMesh PDFFreeFormGouradTriangleShading::createMesh(const PDFMeshQualitySetting
vertices[index] = qMove(data); vertices[index] = qMove(data);
}; };
PDFIntegerRange indices(size_t(0), vertexCount);
std::for_each(std::execution::parallel_policy(), indices.begin(), indices.end(), readVertex); std::for_each(std::execution::parallel_policy(), indices.begin(), indices.end(), readVertex);
mesh.setVertices(qMove(meshVertices)); mesh.setVertices(qMove(meshVertices));
@ -1502,8 +1501,6 @@ PDFMesh PDFLatticeFormGouradTriangleShading::createMesh(const PDFMeshQualitySett
std::vector<VertexData> vertices; std::vector<VertexData> vertices;
vertices.resize(vertexCount); vertices.resize(vertexCount);
std::vector<size_t> indices(vertexCount, 0);
std::iota(indices.begin(), indices.end(), static_cast<size_t>(0));
std::vector<QPointF> meshVertices; std::vector<QPointF> meshVertices;
meshVertices.resize(vertexCount); meshVertices.resize(vertexCount);
@ -1532,6 +1529,7 @@ PDFMesh PDFLatticeFormGouradTriangleShading::createMesh(const PDFMeshQualitySett
vertices[index] = qMove(data); vertices[index] = qMove(data);
}; };
PDFIntegerRange indices(size_t(0), vertexCount);
std::for_each(std::execution::parallel_policy(), indices.begin(), indices.end(), readVertex); std::for_each(std::execution::parallel_policy(), indices.begin(), indices.end(), readVertex);
mesh.setVertices(qMove(meshVertices)); mesh.setVertices(qMove(meshVertices));
@ -2075,7 +2073,7 @@ PDFMesh PDFTensorProductPatchShading::createMesh(const PDFMeshQualitySettings& s
} }
} }
fillMesh(mesh, settings, patches); fillMesh(mesh, patternSpaceToDeviceSpaceMatrix, settings, patches);
return mesh; return mesh;
} }
@ -2298,6 +2296,7 @@ void PDFTensorProductPatchShadingBase::fillMesh(PDFMesh& mesh, const PDFMeshQual
} }
void PDFTensorProductPatchShadingBase::fillMesh(PDFMesh& mesh, void PDFTensorProductPatchShadingBase::fillMesh(PDFMesh& mesh,
const QMatrix& patternSpaceToDeviceSpaceMatrix,
const PDFMeshQualitySettings& settings, const PDFMeshQualitySettings& settings,
const PDFTensorPatches& patches) const const PDFTensorPatches& patches) const
{ {
@ -2305,6 +2304,22 @@ void PDFTensorProductPatchShadingBase::fillMesh(PDFMesh& mesh,
{ {
fillMesh(mesh, settings, patch); fillMesh(mesh, settings, patch);
} }
// Create bounding path
if (m_boundingBox.isValid())
{
QPainterPath boundingPath;
boundingPath.addPolygon(patternSpaceToDeviceSpaceMatrix.map(m_boundingBox));
mesh.setBoundingPath(boundingPath);
}
if (m_backgroundColor.isValid())
{
QPainterPath path;
path.addRect(settings.deviceSpaceMeshingArea);
mesh.setBackgroundPath(path);
mesh.setBackgroundColor(m_backgroundColor);
}
} }
void PDFTensorProductPatchShadingBase::addTriangle(std::vector<Triangle>& triangles, const PDFTensorPatch& patch, std::array<QPointF, 3> uvCoordinates) void PDFTensorProductPatchShadingBase::addTriangle(std::vector<Triangle>& triangles, const PDFTensorPatch& patch, std::array<QPointF, 3> uvCoordinates)
@ -2320,6 +2335,5 @@ void PDFTensorProductPatchShadingBase::addTriangle(std::vector<Triangle>& triang
// TODO: Apply graphic state of the pattern // TODO: Apply graphic state of the pattern
// TODO: Implement settings of meshing in the settings dialog // TODO: Implement settings of meshing in the settings dialog
// TODO: iota - replace for PDFIntegerRange
} // namespace pdf } // namespace pdf

View File

@ -511,7 +511,7 @@ protected:
struct Triangle; struct Triangle;
void fillMesh(PDFMesh& mesh, const PDFMeshQualitySettings& settings, const PDFTensorPatch& patch) const; void fillMesh(PDFMesh& mesh, const PDFMeshQualitySettings& settings, const PDFTensorPatch& patch) const;
void fillMesh(PDFMesh& mesh, const PDFMeshQualitySettings& settings, const PDFTensorPatches& patches) const; void fillMesh(PDFMesh& mesh, const QMatrix& patternSpaceToDeviceSpaceMatrix, const PDFMeshQualitySettings& settings, const PDFTensorPatches& patches) const;
static void addTriangle(std::vector<Triangle>& triangles, const PDFTensorPatch& patch, std::array<QPointF, 3> uvCoordinates); static void addTriangle(std::vector<Triangle>& triangles, const PDFTensorPatch& patch, std::array<QPointF, 3> uvCoordinates);
private: private: