Kstars

linenode.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "linenode.h"
7
8#include "skymaplite.h"
9#include "projections/projector.h"
10#include "skycomponents/skiphashlist.h"
11
12#include <QLinkedList>
13#include <QSGFlatColorMaterial>
14
15LineNode::LineNode(LineList *lineList, SkipHashList *skipList, QColor color, int width, Qt::PenStyle drawStyle)
16 : m_geometryNode(new QSGGeometryNode), m_lineList(lineList), m_skipList(skipList),
17 m_material(new QSGFlatColorMaterial), m_drawStyle(drawStyle)
18{
19 m_geometryNode->setOpaqueMaterial(m_material);
20 //m_geometryNode->setFlag(QSGNode::OwnsMaterial);
21 m_material->setColor(color);
22
24 m_geometryNode->setGeometry(m_geometry);
25 //m_geometryNode->setFlag(QSGNode::OwnsGeometry);
26 setWidth(width);
27
28 appendChildNode(m_geometryNode);
29}
30
31LineNode::~LineNode()
32{
33 delete m_geometry;
34 delete m_material;
35}
36
37void LineNode::setColor(QColor color)
38{
39 if (m_material->color() != color)
40 {
41 m_material->setColor(color);
42 m_color = color;
43 m_geometryNode->markDirty(QSGNode::DirtyMaterial);
44 }
45}
46
47void LineNode::setWidth(int width)
48{
49 m_geometry->setLineWidth(width);
50 m_geometryNode->markDirty(QSGNode::DirtyGeometry);
51}
52
53void LineNode::setDrawStyle(Qt::PenStyle style)
54{
55 m_drawStyle = style;
56}
57
58void LineNode::setStyle(QColor color, int width, Qt::PenStyle drawStyle)
59{
60 setColor(color);
61 setWidth(width);
62 setDrawStyle(drawStyle);
63}
64
66{
67 SkyList *points = m_lineList->points();
68
69 m_geometry->setDrawingMode(GL_LINES);
70
71 const Projector *m_proj = SkyMapLite::Instance()->projector();
72
73 bool isVisible, isVisibleLast;
74
75 QPointF oLast = m_proj->toScreen(points->first().get(), true, &isVisibleLast);
76
77 // & with the result of checkVisibility to clip away things below horizon
78 isVisibleLast &= m_proj->checkVisibility(points->first().get());
80
82
83 for (int j = 1; j < points->size(); j++)
84 {
85 SkyPoint *pThis = points->at(j).get();
86
87 /*In regular KStars we first call checkVisibility and then toScreen
88 Here we minimize the number of calls to toScreen by proceeding only if
89 checkVisibility is true*/
90 oThis = m_proj->toScreen(pThis, true, &isVisible);
91 // & with the result of checkVisibility to clip away things below horizon
92 isVisible &= m_proj->checkVisibility(pThis);
93 bool doSkip = false;
94 if (m_skipList)
95 {
96 doSkip = m_skipList->skip(j);
97 }
98
99 bool pointsVisible = false;
100 //Temporary solution to avoid random lines in Gnomonic projection and draw lines up to horizon
101 if (SkyMapLite::Instance()->projector()->type() == Projector::Gnomonic)
102 {
103 if (isVisible && isVisibleLast)
104 pointsVisible = true;
105 }
106 else
107 {
108 if (isVisible || isVisibleLast)
109 pointsVisible = true;
110 }
111
112 if (!doSkip)
113 {
114 if (pointsVisible)
115 {
116 newPoints.append(oLast);
117 newPoints.append(oThis);
118 }
119 }
120 oLast = oThis;
121 isVisibleLast = isVisible;
122 }
123
124 int size = newPoints.size();
125 m_geometry->allocate(size);
126
128
130 int c = 0;
131
132 while (i != newPoints.constEnd())
133 {
134 vertex[c].x = (*i).x();
135 vertex[c].y = (*i).y();
136 ++c;
137 ++i;
138 }
139 m_geometryNode->markDirty(QSGNode::DirtyGeometry);
140}
A simple data container used by LineListIndex.
Definition linelist.h:25
SkyList * points()
return the list of points for iterating or appending (or whatever).
Definition linelist.h:33
LineNode(LineList *lineList, SkipHashList *skipList, QColor color, int width, Qt::PenStyle drawStyle)
Constructor.
Definition linenode.cpp:15
void updateGeometry()
Update lines based on the visibility of line segments in m_lineList.
Definition linenode.cpp:65
The Projector class is the primary class that serves as an interface to handle projections.
Definition projector.h:58
QPointF toScreen(const SkyPoint *o, bool oRefract=true, bool *onVisibleHemisphere=nullptr) const
This is exactly the same as toScreenVec but it returns a QPointF.
Definition projector.cpp:93
bool checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
The sky coordinates of a point in the sky.
Definition skypoint.h:45
void setGeometry(QSGGeometry *geometry)
const QColor & color() const const
void setColor(const QColor &color)
void allocate(int vertexCount, int indexCount)
const AttributeSet & defaultAttributes_Point2D()
void setDrawingMode(unsigned int mode)
void setLineWidth(float width)
Point2D * vertexDataAsPoint2D()
void setOpaqueMaterial(QSGMaterial *material)
void appendChildNode(QSGNode *node)
void markDirty(DirtyState bits)
NodeType type() const const
PenStyle
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:48:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.