Skip to content

Commit 94c600e

Browse files
author
tpat
committed
Code cleanup. Readded phong color map that was deleted in earlier commit
1 parent b0950b0 commit 94c600e

File tree

12 files changed

+120
-91
lines changed

12 files changed

+120
-91
lines changed

src/Core/GeometryPrimitives/Transform.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ Transform::operator=(const Transform& copy)
839839
return *this;
840840
}
841841

842-
std::vector<Vector> Transform::get_column_vectors()
842+
std::vector<Vector> Transform::get_column_vectors() const
843843
{
844844
std::vector<Vector> column_vectors(3);
845845
for(int i = 0; i < 3; i++)

src/Core/GeometryPrimitives/Transform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ namespace SCIRun {
147147
/// Persistent I/O.
148148
static PersistentTypeID type_id;
149149
virtual void io(Piostream &stream);
150-
std::vector<Vector> get_column_vectors();
150+
std::vector<Vector> get_column_vectors() const;
151151
};
152152

153153
SCISHARE Point operator*(const Transform &t, const Point &d);

src/Graphics/Widgets/Widget.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ WidgetMovement WidgetBase::getMovementType()
8787
return movementType_;
8888
}
8989

90+
void WidgetBase::addInitialId() {
91+
auto ids = std::vector<std::string>(1);
92+
ids.push_back(uniqueID());
93+
connectedIds_ = ids;
94+
}
95+
9096
void CompositeWidget::addToList(GeometryBaseHandle handle, GeomList& list)
9197
{
9298
if (handle.get() == this)

src/Graphics/Widgets/Widget.h

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ namespace SCIRun
5353
WidgetBase(const Core::GeometryIDGenerator& idGenerator, const std::string& tag, bool isClippable);
5454
WidgetBase(const Core::GeometryIDGenerator& idGenerator, const std::string& tag, bool isClippable, const Core::Geometry::Point& origin);
5555
WidgetBase(const Core::GeometryIDGenerator& idGenerator, const std::string& tag, bool isClippable, const Core::Geometry::Point& pos, const Core::Geometry::Point& origin);
56-
/* WidgetBase(const Core::GeometryIDGenerator& idGenerator, const std::string& tag, bool isClippable, const Core::Geometry::Vector& pos); */
5756
Core::Geometry::Point position() const;
5857
void setPosition(const Core::Geometry::Point& p);
5958
void setToScale(const Core::Geometry::Vector& flipAxis);
@@ -62,11 +61,9 @@ namespace SCIRun
6261
glm::vec3 getFlipVector();
6362
WidgetMovement getMovementType();
6463

65-
/* glm::vec3 getOrigin(); */
66-
/* void setOrigin(glm::vec3& origin); */
67-
6864
glm::vec3 origin_;
6965
std::vector<std::string> connectedIds_;
66+
void addInitialId();
7067

7168
protected:
7269
Core::Geometry::Point position_;
@@ -75,16 +72,19 @@ namespace SCIRun
7572
glm::vec3 flipAxis_;
7673
};
7774

78-
using WidgetHandle = SharedPointer<WidgetBase>;
75+
using WidgetHandle = SharedPointer<WidgetBase>;
7976

80-
struct SCISHARE BoxPosition
81-
{
82-
Core::Geometry::Point center_, right_, down_, in_;
77+
struct SCISHARE BoxPosition {
78+
Core::Geometry::Point center_, right_, down_, in_;
8379

84-
void setPosition(const Core::Geometry::Point& center, const Core::Geometry::Point& right,
85-
const Core::Geometry::Point& down, const Core::Geometry::Point& in);
86-
void getPosition(Core::Geometry::Point& center, Core::Geometry::Point& right,
87-
Core::Geometry::Point& down, Core::Geometry::Point& in) const;
80+
void setPosition(const Core::Geometry::Point &center,
81+
const Core::Geometry::Point &right,
82+
const Core::Geometry::Point &down,
83+
const Core::Geometry::Point &in);
84+
void getPosition(Core::Geometry::Point &center,
85+
Core::Geometry::Point &right,
86+
Core::Geometry::Point &down,
87+
Core::Geometry::Point &in) const;
8888
};
8989

9090
class SCISHARE CompositeWidget : public WidgetBase
@@ -114,12 +114,6 @@ namespace SCIRun
114114
{
115115
return boost::make_shared<CompositeWidget>(idGenerator, tag, begin, end);
116116
}
117-
/* template <typename WidgetIter> */
118-
/* static WidgetHandle createWidgetComposite(const Core::GeometryIDGenerator& idGenerator, const std::string& tag) */
119-
/* { */
120-
/* return boost::make_shared<CompositeWidget>(idGenerator, tag, widgets_.begin(), widgets_.end()); */
121-
/* } */
122-
123117
}
124118
}
125119
}

src/Graphics/Widgets/WidgetFactory.cc

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ WidgetHandle WidgetFactory::createBox(const Core::GeometryIDGenerator& idGenerat
2727
const Point& origin,
2828
const BBox& bbox)
2929
{
30-
WidgetHandle widget = boost::make_shared<BoundingBoxWidget>(idGenerator, scale, pos, origin, bbox);
31-
std::vector<std::string> ids = std::vector<std::string>(1);
32-
ids.push_back(widget->uniqueID());
33-
widget->connectedIds_ = ids;
30+
auto widget = boost::make_shared<BoundingBoxWidget>(idGenerator, scale, pos, origin, bbox);
31+
widget->addInitialId();
3432
widget->setToTranslate();
3533
return widget;
3634
}
@@ -44,10 +42,8 @@ WidgetHandle WidgetFactory::createSphere(const Core::GeometryIDGenerator& idGene
4442
const BBox& bbox,
4543
int resolution)
4644
{
47-
WidgetHandle widget = boost::make_shared<SphereWidget>(idGenerator, name, radius, defaultColor, point, origin, bbox, resolution);
48-
std::vector<std::string> ids = std::vector<std::string>(1);
49-
ids.push_back(widget->uniqueID());
50-
widget->connectedIds_ = ids;
45+
auto widget = boost::make_shared<SphereWidget>(idGenerator, name, radius, defaultColor, point, origin, bbox, resolution);
46+
widget->addInitialId();
5147
widget->setToTranslate();
5248
return widget;
5349
}
@@ -62,10 +58,8 @@ WidgetHandle WidgetFactory::createCylinder(const Core::GeometryIDGenerator& idGe
6258
const BBox& bbox,
6359
int resolution)
6460
{
65-
WidgetHandle widget = boost::make_shared<CylinderWidget>(idGenerator, name, radius, defaultColor, p1, p2, origin, bbox, resolution);
66-
std::vector<std::string> ids = std::vector<std::string>(1);
67-
ids.push_back(widget->uniqueID());
68-
widget->connectedIds_ = ids;
61+
auto widget = boost::make_shared<CylinderWidget>(idGenerator, name, radius, defaultColor, p1, p2, origin, bbox, resolution);
62+
widget->addInitialId();
6963
widget->setToTranslate();
7064
return widget;
7165
}
@@ -81,10 +75,8 @@ WidgetHandle WidgetFactory::createCone(const Core::GeometryIDGenerator& idGenera
8175
bool renderBase,
8276
int resolution)
8377
{
84-
WidgetHandle widget = boost::make_shared<ConeWidget>(idGenerator, name, radius, defaultColor, p1, p2, origin, bbox, renderBase, resolution);
85-
std::vector<std::string> ids = std::vector<std::string>(1);
86-
ids.push_back(widget->uniqueID());
87-
widget->connectedIds_ = ids;
78+
auto widget = boost::make_shared<ConeWidget>(idGenerator, name, radius, defaultColor, p1, p2, origin, bbox, renderBase, resolution);
79+
widget->addInitialId();
8880
widget->setToTranslate();
8981
return widget;
9082
}
@@ -99,10 +91,8 @@ WidgetHandle WidgetFactory::createDisk(const Core::GeometryIDGenerator& idGenera
9991
const BBox& bbox,
10092
int resolution)
10193
{
102-
WidgetHandle widget = boost::make_shared<DiskWidget>(idGenerator, name, radius, defaultColor, p1, p2, origin, bbox, resolution);
103-
std::vector<std::string> ids = std::vector<std::string>(1);
104-
ids.push_back(widget->uniqueID());
105-
widget->connectedIds_ = ids;
94+
auto widget = boost::make_shared<DiskWidget>(idGenerator, name, radius, defaultColor, p1, p2, origin, bbox, resolution);
95+
widget->addInitialId();
10696
widget->setToTranslate();
10797
return widget;
10898
}

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

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ namespace SCIRun {
377377

378378
//a map from selection id to name
379379
std::map<uint32_t, std::string> selMap;
380-
std::map<uint32_t, glm::vec3> originMap;
381380
std::vector<uint64_t> entityList;
382381

383382
int nameIndex = 0;
@@ -595,7 +594,6 @@ namespace SCIRun {
595594
mConnectedWidgets = objList[i]->connectedIds_;
596595
}
597596
}
598-
// mOriginWorld = originMap.find(value)->second;
599597
}
600598
}
601599
//release and restore fbo
@@ -702,24 +700,30 @@ namespace SCIRun {
702700
}
703701
}
704702

703+
//----------------------------------------------------------------------------------------------
704+
void SRInterface::modifyWidgets()
705+
{
706+
auto contTrans = mCore.getOrCreateComponentContainer<gen::Transform>();
707+
for (auto &widgetId : mConnectedWidgets)
708+
{
709+
auto component = contTrans->getComponent(mEntityIdMap[widgetId]);
710+
if (component.first != nullptr)
711+
contTrans->modifyIndex(mWidgetTransform, component.second, 0);
712+
}
713+
}
714+
705715
//----------------------------------------------------------------------------------------------
706716
void SRInterface::translateWidget(const glm::ivec2& pos)
707717
{
708-
gen::StaticCamera* cam = mCore.getStaticComponent<gen::StaticCamera>();
718+
auto cam = mCore.getStaticComponent<gen::StaticCamera>();
709719
glm::vec2 spos(float(pos.x) / float(mScreenWidth) * 2.0 - 1.0,
710720
-(float(pos.y) / float(mScreenHeight) * 2.0 - 1.0));
711721

712722
glm::vec2 transVec = (spos - mSelectedPos) * glm::vec2(mSelectedW, mSelectedW);
713723
mWidgetTransform = gen::Transform();
714724
mWidgetTransform.setPosition((glm::inverse(cam->data.viewProjection) * glm::vec4(transVec, 0.0, 0.0)).xyz());
715725

716-
spire::CerealHeap<gen::Transform>* contTrans = mCore.getOrCreateComponentContainer<gen::Transform>();
717-
for(auto& widgetId : mConnectedWidgets)
718-
{
719-
std::pair<const gen::Transform*, size_t> component = contTrans->getComponent(mEntityIdMap[widgetId]);
720-
if (component.first != nullptr)
721-
contTrans->modifyIndex(mWidgetTransform, component.second, 0);
722-
}
726+
modifyWidgets();
723727
}
724728

725729
//----------------------------------------------------------------------------------------------
@@ -735,6 +739,7 @@ namespace SCIRun {
735739
float scaling_factor = glm::dot(glm::normalize(originToCurrentSpos), glm::normalize(mOriginToSpos))
736740
* (glm::length(originToCurrentSpos) / glm::length(mOriginToSpos));
737741

742+
// Flip if negative to avoid inverted normals
738743
glm::mat4 flip;
739744
bool negativeScale = scaling_factor < 0.0;
740745
if(negativeScale)
@@ -743,8 +748,6 @@ namespace SCIRun {
743748
scaling_factor = -scaling_factor;
744749
}
745750

746-
// std::cout << "scaling factor: " << scaling_factor << std::endl;
747-
748751
mWidgetTransform = gen::Transform();
749752
glm::mat4 translation = glm::translate(-mOriginWorld);
750753
glm::mat4 scale = glm::scale(mWidgetTransform.transform, glm::vec3(scaling_factor));
@@ -757,13 +760,7 @@ namespace SCIRun {
757760

758761
mWidgetTransform.transform = reverse_translation * mWidgetTransform.transform;
759762

760-
spire::CerealHeap<gen::Transform>* contTrans = mCore.getOrCreateComponentContainer<gen::Transform>();
761-
for(auto& widgetId : mConnectedWidgets)
762-
{
763-
std::pair<const gen::Transform*, size_t> component = contTrans->getComponent(mEntityIdMap[widgetId]);
764-
if (component.first != nullptr)
765-
contTrans->modifyIndex(mWidgetTransform, component.second, 0);
766-
}
763+
modifyWidgets();
767764
}
768765

769766
//----------------------------------------------------------------------------------------------
@@ -790,13 +787,7 @@ namespace SCIRun {
790787
mWidgetTransform = gen::Transform();
791788
mWidgetTransform.transform = reverse_translation * rotation * translation;
792789

793-
spire::CerealHeap<gen::Transform>* contTrans = mCore.getOrCreateComponentContainer<gen::Transform>();
794-
for(auto& widgetId : mConnectedWidgets)
795-
{
796-
std::pair<const gen::Transform*, size_t> component = contTrans->getComponent(mEntityIdMap[widgetId]);
797-
if (component.first != nullptr)
798-
contTrans->modifyIndex(mWidgetTransform, component.second, 0);
799-
}
790+
modifyWidgets();
800791
}
801792

802793

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ namespace SCIRun {
209209
void updateCamera(); // Places mCamera's transform into our static camera component.
210210

211211
//---------------- Widgets -------------------------------------------------------------------
212+
void modifyWidgets();
212213
bool foundWidget(const glm::ivec2& pos); // search for a widget at mouse position
213214
void updateWidget(const glm::ivec2& pos);
214215
void rotateWidget(const glm::ivec2& pos);
Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,55 @@
1-
--- Emacs Calculator Mode ---
2-
1: 20
3-
.
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2015 Scientific Computing and Imaging Institute,
7+
University of Utah.
8+
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a
11+
copy of this software and associated documentation files (the "Software"),
12+
to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+
and/or sell copies of the Software, and to permit persons to whom the
15+
Software is furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included
18+
in all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26+
DEALINGS IN THE SOFTWARE.
27+
*/
28+
29+
// Uniforms
30+
uniform mat4 uModelViewProjection;
31+
uniform mat4 uModel;
32+
uniform mat4 uView;
33+
34+
// Attributes
35+
attribute vec3 aPos;
36+
attribute vec3 aNormal;
37+
attribute vec4 aColor;
38+
39+
// Outputs to the fragment shader.
40+
varying vec3 vNormal;
41+
varying vec4 vColor;
42+
varying vec4 vPosWorld;
43+
varying vec4 vPosView;
44+
45+
void main( void )
46+
{
47+
// Todo: Add gamma correction factor of 2.2. For textures, we assume that it
48+
// was generated in gamma space, and we need to convert it to linear space.
49+
vPosWorld = uModel * vec4(aPos, 1.0);
50+
vPosView = uView * vPosWorld;
51+
vNormal = normalize((uView * uModel * vec4(aNormal, 0.0)).xyz);
52+
vColor = aColor;
53+
54+
gl_Position = uModelViewProjection * vec4(aPos, 1.0);
55+
}

src/Interface/Modules/Render/ViewScene.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ void ViewSceneDialog::selectObject(const int x, const int y)
12351235
}
12361236

12371237
//get widgets
1238-
std::vector<WidgetHandle> objList = filterGeomObjectsForWidgets(geomData, mConfigurationDock);
1238+
auto objList = filterGeomObjectsForWidgets(geomData, mConfigurationDock);
12391239

12401240
//select widget
12411241
spire->select(glm::ivec2(x - mGLWidget->pos().x(), y - mGLWidget->pos().y()), objList, 0);

src/Modules/Fields/EditMeshBoundingBox.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,8 @@ void EditMeshBoundingBox::update_input_attributes(FieldHandle f)
197197

198198
GeometryHandle EditMeshBoundingBox::buildGeometryObject()
199199
{
200-
WidgetHandle bbox_geom = WidgetFactory::createBox(*this, get_state()->getValue(Scale).toDouble(),
201-
impl_->position_, impl_->position_.center_, impl_->bbox_);
202-
203-
// std::cout << "bbox wid size: " << bbox_geom->widgets_.size() << std::endl;
204-
return bbox_geom;
205-
// return createGeomComposite(*this, "bbox", bbox_geom->widgets_.begin(), bbox_geom->widgets_.end());
200+
return WidgetFactory::createBox(*this, get_state()->getValue(Scale).toDouble(),
201+
impl_->position_, impl_->position_.center_, impl_->bbox_);
206202
}
207203

208204
void EditMeshBoundingBox::computeWidgetBox(const BBox& box) const

0 commit comments

Comments
 (0)