/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef OD_SR_POLYGON_DRAWER #define OD_SR_POLYGON_DRAWER #include #include #include "SrArcDrawerBase.h" #include #include #include #include #include class OdSrFrameContext; template class OdSrPolygonDrawer : public OdSrLineDrawerBase { public: OdSrPolygonDrawer(OdSrFrameContext* context, OdGePoint3d* points, unsigned int pointCount, ODCOLORREF color) : m_context(context), m_points(points), m_pointCount(pointCount), m_color(color) {} void draw(const OdGeMatrix3d& matrixWorld) { auto pPoints = m_points; auto nPoints = m_pointCount; for (int idx = 0; idx < int(nPoints); idx++) { auto* curPoint = pPoints + idx; auto* nextPoint = pPoints + (idx + 1) % m_pointCount; OdSrLineDrawerBase::drawLine( static_cast((((matrixWorld)[0][0] * curPoint->x + (matrixWorld)[0][1] * curPoint->y + (matrixWorld)[0][2] * curPoint->z + (matrixWorld)[0][3]))), // * divider)); static_cast((((matrixWorld)[1][0] * curPoint->x + (matrixWorld)[1][1] * curPoint->y + (matrixWorld)[1][2] * curPoint->z + (matrixWorld)[1][3]))), // * divider)); static_cast((((matrixWorld)[0][0] * nextPoint->x + (matrixWorld)[0][1] * nextPoint->y + (matrixWorld)[0][2] * nextPoint->z + (matrixWorld)[0][3]))), // * divider)); static_cast((((matrixWorld)[1][0] * nextPoint->x + (matrixWorld)[1][1] * nextPoint->y + (matrixWorld)[1][2] * nextPoint->z + (matrixWorld)[1][3]))) // * divider));); ); } static_cast(this)->afterDrawing(); } protected: OdSrFrameContext* m_context; OdGePoint3d* m_points; unsigned int m_pointCount; ODCOLORREF m_color; }; class OdSrPolygonDrawerFilled : public OdSrPolygonDrawer { public: OdSrPolygonDrawerFilled(OdSrFrameContext* context, OdGePoint3d* points, unsigned int pointCount, ODCOLORREF color) : OdSrPolygonDrawer(context, points, pointCount, color){}; using Mark = OdSrDrawedPixelsInLine::Mark; void countPixel(int x, int y) { storageYX[y].append(x, m_currentMark); } void setCurrentMark(Mark iMark) { m_currentMark = iMark; } void afterDrawing() { for (auto pair : storageYX) if (pair.second.initialized()) OdSrPolygonDrawer::m_context->draw_horizontalLine(m_context->heightInternal() - pair.first, pair.second.globalLeft(), pair.second.globalRight(), m_color); } private: Mark m_currentMark = Mark::Circumference; std::unordered_map storageYX; }; class OdSrPolygonDrawerClosed : public OdSrPolygonDrawer { public: OdSrPolygonDrawerClosed(OdSrFrameContext* context, OdGePoint3d* points, unsigned int pointCount, ODCOLORREF color) : OdSrPolygonDrawer(context, points, pointCount, color){}; void countPixel(int x, int y) { OdSrPolygonDrawer::m_context->draw_point(x, y, OdSrPolygonDrawer::m_color); } }; #endif // OD_SR_POLYGON_DRAWER