Skip to content

Commit f76ec22

Browse files
committed
Ability to change background color. Closes #695
1 parent d431a51 commit f76ec22

File tree

10 files changed

+763
-23
lines changed

10 files changed

+763
-23
lines changed

src/Interface/Modules/Render/ES/Core.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace fs = CPM_ES_FS_NS;
4444
namespace SCIRun {
4545
namespace Render {
4646

47-
ESCore::ESCore()
47+
ESCore::ESCore() : r_(0.0f), g_(0.0f), b_(0.0f), a_(0.0f)
4848
{
4949
// Register common systems.
5050
gen::registerAll(*this);
@@ -118,7 +118,8 @@ void ESCore::execute(double currentTime, double constantFrameTime)
118118
// Reset the GL state (we shouldn't really need to do this, but we will anyways).
119119
mDefaultGLState.apply();
120120

121-
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
121+
//lClearColor(0.0f, 0.0f, 0.0f, 0.0f);
122+
glClearColor(r_, g_, b_, a_);
122123
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
123124
}
124125

@@ -129,6 +130,14 @@ void ESCore::execute(double currentTime, double constantFrameTime)
129130
mCurrentTime += constantFrameTime;
130131
}
131132

133+
void ESCore::setBackgroundColor(float r, float g, float b, float a)
134+
{
135+
r_ = r;
136+
g_ = g;
137+
b_ = b;
138+
a_ = a;
139+
}
140+
132141
} // namespace Render
133142
} // namespace SCIRun
134143

src/Interface/Modules/Render/ES/Core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ESCore : public CPM_ES_ACORN_NS::Acorn
4343
virtual ~ESCore();
4444

4545
void execute(double currentTime, double constantFrameTime);
46+
void setBackgroundColor(float r, float g, float b, float a);
4647

4748
private:
4849

@@ -52,6 +53,8 @@ class ESCore : public CPM_ES_ACORN_NS::Acorn
5253

5354
float mFPS; ///< Actual FPS of system.
5455
float mLastRealTime; ///< Last realtime passed into the core.
56+
57+
float r_, g_, b_, a_;
5558
};
5659

5760
} // namespace Render

src/Interface/Modules/Render/ES/SRInterface.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ namespace SCIRun {
234234
showOrientation_ = value;
235235
}
236236

237+
//------------------------------------------------------------------------------
238+
void SRInterface::setBackgroundColor(QColor color)
239+
{
240+
mCore.setBackgroundColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());
241+
}
242+
237243
//------------------------------------------------------------------------------
238244
void SRInterface::inputMouseUp(const glm::ivec2& /*pos*/, MouseButton /*btn*/)
239245
{

src/Interface/Modules/Render/ES/SRInterface.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ namespace SCIRun {
134134
/// Toggle Orientation Axes
135135
void showOrientation(bool value);
136136

137+
/// Set the Background Color
138+
void setBackgroundColor(QColor color);
139+
137140
private:
138141

139142
class SRObject
@@ -170,14 +173,14 @@ namespace SCIRun {
170173
Core::Datatypes::GeometryObject::RenderType renderType;
171174
};
172175

173-
std::string mName;
174-
glm::mat4 mObjectToWorld;
175-
std::list<SRPass> mPasses;
176-
Core::Geometry::BBox mBBox; ///< Objects bounding box (calculated from VBO).
176+
std::string mName;
177+
glm::mat4 mObjectToWorld;
178+
std::list<SRPass> mPasses;
179+
Core::Geometry::BBox mBBox; ///< Objects bounding box (calculated from VBO).
177180

178181
boost::optional<std::string> mColorMap;
179182

180-
int mPort;
183+
int mPort;
181184
};
182185

183186
// Sets up ESCore.

src/Interface/Modules/Render/ViewScene.cc

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ void ViewSceneDialog::newGeometryValue()
125125
LOG_DEBUG("ViewSceneDialog::asyncExecute after locking");
126126

127127
itemManager_->removeAll();
128-
128+
/*
129129
std::shared_ptr<Render::SRInterface> spire = mSpire.lock();
130130
if (spire == nullptr)
131131
return;
132132
spire->removeAllGeomObjects();
133-
133+
*/
134134
// Grab the geomData transient value.
135135
auto geomDataTransient = state_->getTransientValue(Parameters::GeomData);
136136
if (geomDataTransient && !geomDataTransient->empty())
@@ -149,23 +149,23 @@ void ViewSceneDialog::newGeometryValue()
149149
}
150150

151151
int port = 0;
152-
//std::vector<std::string> validObjects;
152+
std::vector<std::string> validObjects;
153153
for (auto it = geomData->begin(); it != geomData->end(); ++it, ++port)
154154
{
155155
boost::shared_ptr<Core::Datatypes::GeometryObject> obj = *it;
156156
spire->handleGeomObject(obj, port);
157-
//validObjects.push_back(obj->objectName);
157+
validObjects.push_back(obj->objectName);
158158
itemManager_->addItem(QString::fromStdString(obj->objectName));
159159
}
160-
//spire->gcInvalidObjects(validObjects);
161-
}/*
160+
spire->gcInvalidObjects(validObjects);
161+
}
162162
else
163163
{
164164
std::shared_ptr<Render::SRInterface> spire = mSpire.lock();
165165
if (spire == nullptr)
166166
return;
167167
spire->removeAllGeomObjects();
168-
}*/
168+
}
169169
//TODO IMPORTANT: we need some call somewhere to clear the transient geometry list once spire/ES has received the list of objects. They take up lots of memory...
170170
//state_->setTransientValue(Parameters::GeomData, boost::shared_ptr<std::list<boost::shared_ptr<Core::Datatypes::GeometryObject>>>(), false);
171171
}
@@ -376,6 +376,23 @@ void ViewSceneDialog::configurationButtonClicked()
376376
mConfigurationDock->setVisible(showConfiguration_);
377377
}
378378

379+
//------------------------------------------------------------------------------
380+
void ViewSceneDialog::assignDefaultMeshColor()
381+
{
382+
QColor bgColor = Qt::black;
383+
auto newColor = QColorDialog::getColor(bgColor, this, "Choose background color");
384+
if (newColor.isValid())
385+
{
386+
bgColor = newColor;
387+
mConfigurationDock->setSampleColor(bgColor);
388+
//TODO: set color of button to this color
389+
//defaultMeshColorButton_->set
390+
//state_->setValue(ShowFieldModule::DefaultMeshColor, ColorRGB(defaultMeshColor_.red(), defaultMeshColor_.green(), defaultMeshColor_.blue()).toString());
391+
std::shared_ptr<Render::SRInterface> spire = mSpire.lock();
392+
spire->setBackgroundColor(bgColor);
393+
}
394+
}
395+
379396
//------------------------------------------------------------------------------
380397
void ViewSceneDialog::addToolBar()
381398
{

src/Interface/Modules/Render/ViewScene.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ namespace SCIRun {
8383
void viewAxisSelected(int index);
8484
void viewVectorSelected(int index);
8585
void configurationButtonClicked();
86+
void assignDefaultMeshColor();
8687

8788
protected:
8889
virtual void closeEvent(QCloseEvent* evt) override;

src/Interface/Modules/Render/ViewSceneControls.ui

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,43 @@
3535
<property name="currentIndex">
3636
<number>2</number>
3737
</property>
38+
<widget class="QWidget" name="RenderTab">
39+
<attribute name="title">
40+
<string>Render</string>
41+
</attribute>
42+
<widget class="QPushButton" name="setBackgroundColorPushButton_">
43+
<property name="geometry">
44+
<rect>
45+
<x>20</x>
46+
<y>60</y>
47+
<width>91</width>
48+
<height>23</height>
49+
</rect>
50+
</property>
51+
<property name="text">
52+
<string>Scene Color</string>
53+
</property>
54+
</widget>
55+
<widget class="QLabel" name="currentBackgroundLabel_">
56+
<property name="geometry">
57+
<rect>
58+
<x>25</x>
59+
<y>22</y>
60+
<width>81</width>
61+
<height>31</height>
62+
</rect>
63+
</property>
64+
<property name="frameShape">
65+
<enum>QFrame::Panel</enum>
66+
</property>
67+
<property name="frameShadow">
68+
<enum>QFrame::Sunken</enum>
69+
</property>
70+
<property name="text">
71+
<string/>
72+
</property>
73+
</widget>
74+
</widget>
3875
<widget class="QWidget" name="ClippingTab">
3976
<property name="enabled">
4077
<bool>false</bool>
@@ -161,7 +198,7 @@
161198
<property name="geometry">
162199
<rect>
163200
<x>10</x>
164-
<y>22</y>
201+
<y>24</y>
165202
<width>240</width>
166203
<height>17</height>
167204
</rect>
@@ -174,7 +211,7 @@
174211
<property name="geometry">
175212
<rect>
176213
<x>10</x>
177-
<y>42</y>
214+
<y>44</y>
178215
<width>240</width>
179216
<height>17</height>
180217
</rect>
@@ -187,7 +224,7 @@
187224
<property name="geometry">
188225
<rect>
189226
<x>10</x>
190-
<y>62</y>
227+
<y>64</y>
191228
<width>240</width>
192229
<height>17</height>
193230
</rect>
@@ -455,7 +492,7 @@
455492
<property name="geometry">
456493
<rect>
457494
<x>88</x>
458-
<y>20</y>
495+
<y>24</y>
459496
<width>75</width>
460497
<height>23</height>
461498
</rect>
@@ -471,7 +508,7 @@
471508
<property name="geometry">
472509
<rect>
473510
<x>40</x>
474-
<y>50</y>
511+
<y>54</y>
475512
<width>75</width>
476513
<height>23</height>
477514
</rect>
@@ -487,7 +524,7 @@
487524
<property name="geometry">
488525
<rect>
489526
<x>130</x>
490-
<y>50</y>
527+
<y>54</y>
491528
<width>75</width>
492529
<height>23</height>
493530
</rect>
@@ -503,7 +540,7 @@
503540
<property name="geometry">
504541
<rect>
505542
<x>88</x>
506-
<y>80</y>
543+
<y>84</y>
507544
<width>75</width>
508545
<height>23</height>
509546
</rect>
@@ -519,7 +556,7 @@
519556
<property name="geometry">
520557
<rect>
521558
<x>50</x>
522-
<y>110</y>
559+
<y>114</y>
523560
<width>101</width>
524561
<height>17</height>
525562
</rect>
@@ -560,7 +597,7 @@
560597
<property name="geometry">
561598
<rect>
562599
<x>10</x>
563-
<y>20</y>
600+
<y>24</y>
564601
<width>101</width>
565602
<height>17</height>
566603
</rect>

0 commit comments

Comments
 (0)