ATLAS Offline Software
Loading...
Searching...
No Matches
VP1Lines.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <Inventor/nodes/SoSeparator.h>
8#include <Inventor/nodes/SoVertexProperty.h>
9#include <Inventor/nodes/SoLineSet.h>
10#include <Inventor/nodes/SoCylinder.h>
11#include <Inventor/SbColor4f.h>
12#include <Inventor/nodes/SoMatrixTransform.h>
13#include <Inventor/SbRotation.h>
14#include <Inventor/SbMatrix.h>
15
16
17//____________________________________________________________________
19public:
20 Imp(VP1Lines *,
21 SoSeparator * attachsep);
23 SoSeparator * attachSep;
24
25 bool shown;
26 SbColor4f colourAndTransp;
27 SbVec3f direction;
28
29 SoSeparator * sep;
30
31 void rebuild3DObjects();
32 void updateColour();
33};
34
35//____________________________________________________________________
36VP1Lines::VP1Lines(SoSeparator * attachsep,
37 IVP1System * sys,QObject * parent)
38 : QObject(parent), VP1HelperClassBase(sys,"VP1Lines"), m_d(new Imp(this,attachsep))
39{
40}
41
42//____________________________________________________________________
44{
45 setShown(false);
46 if (m_d->sep)
47 m_d->sep->unref();
48 m_d->attachSep->unref();
49 delete m_d;
50}
51
52//____________________________________________________________________
53VP1Lines::Imp::Imp(VP1Lines *tc,SoSeparator * as)
54 : theclass(tc), attachSep(as), shown(false),
55 // lines are white by default
56 colourAndTransp(SbColor4f(1,1,1,1)),
57 // this is if you want them black
58 // colourAndTransp(SbColor4f(0,0,0,1)),
59 direction(SbVec3f(0,0,0)),
60 sep(0)
61{
62 attachSep->ref();
63}
64
65//____________________________________________________________________
67{
68 theclass->messageVerbose("(Re)building 3D objects");
69
70 if (sep) {
71 sep->removeAllChildren();
72 } else {
73 sep = new SoSeparator;
74 sep->ref();
75 }
76
77 const bool save = sep->enableNotify(false);
78
79 SoVertexProperty * line_vertices = new SoVertexProperty();
80
81 line_vertices->vertex.set1Value(0,0.0,0.0,0.0);
82 line_vertices->vertex.set1Value(1,direction[0],direction[1],direction[2]);
83
84 line_vertices->materialBinding=SoMaterialBinding::OVERALL;
85 line_vertices->normalBinding=SoNormalBinding::OVERALL;
86 SoLineSet * line = new SoLineSet();
87 line->numVertices.enableNotify(FALSE);
88 // line->numVertices.setNum(1);
89 // line->numVertices.set1Value(0,2);
90 line->vertexProperty = line_vertices;
91 line->numVertices.enableNotify(TRUE);
92 line->numVertices.touch();
93
94 // This is here if you want to
95 // convert lines into cylinders
96 constexpr bool convert = false;
97 if (convert) {
98 SbVec3f p1 = line_vertices->vertex[0].getValue();
99 SbVec3f p2 = line_vertices->vertex[1].getValue();
100 SoCylinder * cylinder = new SoCylinder;
101 cylinder->radius = 4.0;
102 float height = std::sqrt( direction[0]*direction[0]+
103 direction[1]*direction[1]+
104 direction[2]*direction[2]);
105 cylinder->height = height;
106
107 SbMatrix m;
108 m.setTranslate(SbVec3f(0,0.5*height,0));
109 SbVec3f v(p2); v -= p1;
110 SbRotation rotation(SbVec3f(0,1,0),v);
111 SbMatrix m2; m2.setRotate(rotation);
112 m.multRight(m2);
113 SbMatrix m3;
114 m3.setTranslate(p1);
115 m.multRight(m3);
116 SbMatrix mat;
117 mat = m;
118 SoMatrixTransform * mt = new SoMatrixTransform;
119 mt->matrix.setValue(mat);
120 sep->addChild(mt);
121 sep->addChild(cylinder);
122 } else sep->addChild(line);
123
124 updateColour();
125
126 if (save) {
127 sep->enableNotify(true);
128 sep->touch();
129 }
130
131}
132
133//____________________________________________________________________
135{
136 theclass->messageVerbose("Updating packed colour");
137 if (!sep||sep->getNumChildren()<1)
138 return;
139 SoNode * n = sep->getChild(0);
140 if (!n||n->getTypeId()!=SoLineSet::getClassTypeId())
141 return;
142 SoLineSet * line = static_cast<SoLineSet*>(n);
143 SoVertexProperty * vertices = static_cast<SoVertexProperty *>(line->vertexProperty.getValue());
144 if (!vertices)
145 return;
146 vertices->orderedRGBA = colourAndTransp.getPackedValue();
147}
148
149//____________________________________________________________________
151{
152 messageVerbose("Signal received: setShown("+str(b)+")");
153 if (m_d->shown==b)
154 return;
155 m_d->shown=b;
156 if (m_d->shown) {
157 m_d->rebuild3DObjects();
158 if (m_d->attachSep->findChild(m_d->sep)<0)
159 m_d->attachSep->addChild(m_d->sep);
160 } else {
161 if (m_d->sep&&m_d->attachSep->findChild(m_d->sep)>=0)
162 m_d->attachSep->removeChild(m_d->sep);
163 }
164}
165
166//____________________________________________________________________
167void VP1Lines::setColourAndTransp(const SbColor4f&ct)
168{
169 messageVerbose("Signal received in setColourAndTransp slot.");
170 if (m_d->colourAndTransp==ct)
171 return;
172 m_d->colourAndTransp=ct;
173 if (m_d->shown)
174 m_d->updateColour();
175}
176
177//____________________________________________________________________
178void VP1Lines::setDirection(const SbVec3f& o)
179{
180 messageVerbose("Signal received: setDirection("+str(o)+")");
181 if (m_d->direction==o)
182 return;
183 m_d->direction=o;
184 if (m_d->shown)
185 m_d->rebuild3DObjects();
186}
static Double_t tc
VP1HelperClassBase(IVP1System *sys=0, QString helpername="")
void messageVerbose(const QString &) const
SbVec3f direction
Definition VP1Lines.cxx:27
VP1Lines * theclass
Definition VP1Lines.cxx:22
SoSeparator * sep
Definition VP1Lines.cxx:29
void updateColour()
Definition VP1Lines.cxx:134
Imp(VP1Lines *, SoSeparator *attachsep)
Definition VP1Lines.cxx:53
SoSeparator * attachSep
Definition VP1Lines.cxx:23
void rebuild3DObjects()
Definition VP1Lines.cxx:66
SbColor4f colourAndTransp
Definition VP1Lines.cxx:26
virtual ~VP1Lines()
Definition VP1Lines.cxx:43
void setShown(bool)
Definition VP1Lines.cxx:150
void setDirection(const SbVec3f &)
Definition VP1Lines.cxx:178
VP1Lines(SoSeparator *attachsep, IVP1System *sys, QObject *parent=0)
Definition VP1Lines.cxx:36
Imp * m_d
Definition VP1Lines.h:32
void setColourAndTransp(const SbColor4f &)
Definition VP1Lines.cxx:167