Skip to content

Commit e1b9b96

Browse files
authored
Merge pull request #2222 from RubioJr9/edit_bbox_refactor
Closes #1497 and closes #2051
2 parents c811f87 + 446a021 commit e1b9b96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1806
-482
lines changed

src/Core/Datatypes/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ SET(Core_Datatypes_SRCS
4141
SparseRowMatrixFromMap.cc
4242
String.cc
4343
MetadataObject.cc
44+
Feedback.cc
4445
)
4546

4647
SET(Core_Datatypes_HEADERS
@@ -72,7 +73,8 @@ SET(Core_Datatypes_HEADERS
7273
SparseRowMatrix.h
7374
SparseRowMatrixFromMap.h
7475
String.h
75-
)
76+
Feedback.h
77+
)
7678

7779
SCIRUN_ADD_LIBRARY(Core_Datatypes
7880
${Core_Datatypes_HEADERS}

src/Core/Datatypes/Color.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,3 @@ std::ostream& SCIRun::Core::Datatypes::operator<<(std::ostream& out, const Color
9696
out << "Color(" << color.r() << "," << color.g() << "," << color.b() << ")";
9797
return out;
9898
}
99-
100-
bool ViewSceneFeedback::matchesWithModuleId(const std::string& modId) const
101-
{
102-
auto toMatch = GeometryObject::delimiter + modId + GeometryObject::delimiter;
103-
return selectionName.find(toMatch) != std::string::npos;
104-
}

src/Core/Datatypes/Color.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,6 @@ namespace Datatypes {
7979
typedef boost::shared_ptr<ColorRGB> ColorRGBHandle;
8080

8181
SCISHARE std::ostream& operator<<(std::ostream& out, const ColorRGB& color);
82-
83-
struct SCISHARE ViewSceneFeedback : ModuleFeedback
84-
{
85-
Geometry::Transform transform;
86-
std::string selectionName;
87-
std::tuple<int,int> windowSize;
88-
89-
bool matchesWithModuleId(const std::string& modId) const;
90-
};
91-
92-
struct SCISHARE MeshComponentSelectionFeedback : ModuleFeedback
93-
{
94-
MeshComponentSelectionFeedback() {}
95-
MeshComponentSelectionFeedback(const std::string& mod, const std::string& comp, bool sel) :
96-
moduleId(mod), component(comp), selected(sel) {}
97-
std::string moduleId;
98-
std::string component;
99-
bool selected {false};
100-
};
101-
10282
}}}
10383

10484

src/Core/Datatypes/Feedback.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2020 Scientific Computing and Imaging Institute,
7+
University of Utah.
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a
10+
copy of this software and associated documentation files (the "Software"),
11+
to deal in the Software without restriction, including without limitation
12+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
13+
and/or sell copies of the Software, and to permit persons to whom the
14+
Software is furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included
17+
in all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25+
DEALINGS IN THE SOFTWARE.
26+
*/
27+
28+
29+
#include <Core/Datatypes/Feedback.h>
30+
31+
using namespace SCIRun::Core::Datatypes;
32+
33+
bool ViewSceneFeedback::matchesWithModuleId(const std::string &modId) const
34+
{
35+
auto toMatch = GeometryObject::delimiter + modId + GeometryObject::delimiter;
36+
return selectionName.find(toMatch) != std::string::npos;
37+
}

src/Core/Datatypes/Feedback.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2020 Scientific Computing and Imaging Institute,
7+
University of Utah.
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a
10+
copy of this software and associated documentation files (the "Software"),
11+
to deal in the Software without restriction, including without limitation
12+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
13+
and/or sell copies of the Software, and to permit persons to whom the
14+
Software is furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included
17+
in all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25+
DEALINGS IN THE SOFTWARE.
26+
*/
27+
28+
29+
#ifndef CORE_DATATYPES_FEEDBACK_H
30+
#define CORE_DATATYPES_FEEDBACK_H
31+
32+
#include <iosfwd>
33+
#include <Core/Datatypes/Datatype.h>
34+
#include <Core/Datatypes/Geometry.h>
35+
#include <Core/GeometryPrimitives/Transform.h>
36+
#include <Core/Datatypes/share.h>
37+
38+
namespace SCIRun {
39+
namespace Core {
40+
namespace Datatypes {
41+
// These will give different types of widget movement through ViewScene.
42+
// To use rotation and scaling, an origin point must be given.
43+
enum WidgetMovement
44+
{
45+
NONE,
46+
TRANSLATE,
47+
ROTATE,
48+
SCALE,
49+
TRANSLATE_AXIS,
50+
TRANSLATE_AXIS_HALF,
51+
TRANSLATE_AXIS_REVERSE,
52+
SCALE_UNIDIRECTIONAL,
53+
SCALE_AXIS,
54+
SCALE_AXIS_HALF,
55+
SCALE_AXIS_UNIDIRECTIONAL,
56+
};
57+
58+
struct EnumClassHash
59+
{
60+
template <typename T> std::size_t operator()(T t) const
61+
{
62+
return static_cast<std::size_t>(t);
63+
}
64+
};
65+
66+
enum class MouseButton { NONE = 0, LEFT, MIDDLE, RIGHT, STATE_COUNT };
67+
68+
struct SCISHARE ViewSceneFeedback : ModuleFeedback
69+
{
70+
Geometry::Transform transform;
71+
MouseButton buttonClicked;
72+
WidgetMovement movementType;
73+
std::string selectionName;
74+
std::tuple<int,int> windowSize;
75+
76+
bool matchesWithModuleId(const std::string& modId) const;
77+
};
78+
79+
struct SCISHARE MeshComponentSelectionFeedback : ModuleFeedback
80+
{
81+
MeshComponentSelectionFeedback() {}
82+
MeshComponentSelectionFeedback(const std::string& mod, const std::string& comp, bool sel) :
83+
moduleId(mod), component(comp), selected(sel) {}
84+
std::string moduleId;
85+
std::string component;
86+
bool selected {false};
87+
};
88+
}}}
89+
90+
#endif

src/Core/GeometryPrimitives/Tests/TransformTests.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ TEST(TransformTests, LoadIdentity)
183183
TEST(TransformTests, GetRotation)
184184
{
185185
Transform t(testPos, testRot[0], testRot[1], testRot[2]);
186-
auto rot = t.get_rotation();
186+
auto rot = t.get_transformation_vectors();
187187
for(int i = 0; i < 3; ++i)
188188
EXPECT_EQ(testRot[i], rot[i]);
189189
}
@@ -195,11 +195,27 @@ TEST(TransformTests, GetPosition)
195195
EXPECT_EQ(testPos, pos);
196196
}
197197

198+
TEST(TransformTests, SetPositionDouble)
199+
{
200+
Transform t;
201+
t.set_translation(2.3);
202+
auto pos = t.get_translation();
203+
EXPECT_EQ(Point(2.3, 2.3, 2.3), pos);
204+
}
205+
206+
TEST(TransformTests, SetPositionPoint)
207+
{
208+
Transform t;
209+
t.set_translation(testPos);
210+
auto pos = t.get_translation();
211+
EXPECT_EQ(testPos, pos);
212+
}
213+
198214
TEST(TransformTests, Orthogonalize)
199215
{
200216
Transform t(testPos, testRot[0], testRot[1], testRot[2]);
201217
t.orthogonalize();
202-
auto rot = t.get_rotation();
218+
auto rot = t.get_transformation_vectors();
203219

204220
EXPECT_NEAR(0.0, Dot(rot[0], rot[1]), errorOfMargin);
205221
EXPECT_NEAR(0.0, Dot(rot[0], rot[2]), errorOfMargin);
@@ -212,7 +228,7 @@ TEST(TransformTests, Orthonormalize)
212228
{
213229
Transform t(testPos, testRot[0], testRot[1], testRot[2]);
214230
t.orthonormalize();
215-
auto rot = t.get_rotation();
231+
auto rot = t.get_transformation_vectors();
216232

217233
EXPECT_NEAR(0.0, Dot(rot[0], rot[1]), errorOfMargin);
218234
EXPECT_NEAR(0.0, Dot(rot[0], rot[2]), errorOfMargin);
@@ -254,7 +270,7 @@ TEST(TransformTests, MultplicationTransform)
254270
Transform t1(testPos, testRot[0], testRot[1], testRot[2]);
255271
Transform t2(Point(0,0,0), Vector(1,0,0), Vector(0,2,0), Vector(0,0,3));
256272
Transform t3 = t2 * t1;
257-
auto vecs = t3.get_rotation();
273+
auto vecs = t3.get_transformation_vectors();
258274
for(int i = 0; i < 3; ++i)
259275
EXPECT_EQ(vecs[i], Vector(testRot[i].x(), testRot[i].y() * 2, testRot[i].z() * 3));
260276
}

src/Core/GeometryPrimitives/Tests/VectorTests.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,10 @@ TEST(VectorTests, CanScale)
4747
EXPECT_EQ(Vector(2,2,2), p2);
4848
EXPECT_EQ(Vector(2,2,2), 2 * p);
4949
}
50+
51+
TEST(VectorTests, Norm)
52+
{
53+
const static auto epsilon = 2e-12;
54+
Vector p(1,1,1);
55+
EXPECT_NEAR(std::sqrt(3), p.norm(), epsilon);
56+
}

src/Core/GeometryPrimitives/Transform.cc

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ void Transform::orthonormalize()
767767

768768
void Transform::gram_schmidt(bool normalize)
769769
{
770-
auto vecs = get_rotation();
770+
auto vecs = get_transformation_vectors();
771771
double vals[3];
772772
// Get eigenvalues and normalize eigenvectors
773773
for(int i = 0; i < 3; i++)
@@ -946,21 +946,38 @@ Transform::operator=(const Transform& copy)
946946
return *this;
947947
}
948948

949-
std::vector<Vector> Transform::get_rotation() const
949+
std::vector<Vector> Transform::get_transformation_vectors() const
950950
{
951951
std::vector<Vector> column_vectors(3);
952952
for(int i = 0; i < 3; i++)
953-
{
954953
column_vectors[i] = Vector(mat[0][i], mat[1][i], mat[2][i]);
955-
}
956954
return column_vectors;
957955
}
958956

957+
std::vector<Vector> Transform::get_rotation_vectors() const
958+
{ auto vecs = get_transformation_vectors();
959+
for (int i = 0; i < 3; ++i)
960+
vecs[i].normalize();
961+
return vecs;
962+
}
963+
959964
Point Transform::get_translation() const
960965
{
961966
return Point(mat[0][3], mat[1][3], mat[2][3]);
962967
}
963968

969+
void Transform::set_translation(double d)
970+
{
971+
for (int i = 0; i < 3; ++i)
972+
this->set_mat_val(i, 3, d);
973+
}
974+
975+
void Transform::set_translation(const Point& v)
976+
{
977+
for (int i = 0; i < 3; ++i)
978+
this->set_mat_val(i, 3, v[i]);
979+
}
980+
964981
Point
965982
SCIRun::Core::Geometry::operator*(const Transform &t, const Point &d)
966983
{

src/Core/GeometryPrimitives/Transform.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ namespace SCIRun {
7474
public:
7575
double get_imat_val(int i, int j) const { return imat[i][j]; }
7676
void set_imat_val(int i, int j, double val) { imat[i][j] = val; }
77+
void set_translation(double d);
78+
void set_translation(const Point& v);
7779

7880
static const Transform& Identity();
7981

@@ -157,8 +159,9 @@ namespace SCIRun {
157159

158160
/// Persistent I/O.
159161
static PersistentTypeID type_id;
162+
std::vector<Vector> get_rotation_vectors() const;
163+
std::vector<Vector> get_transformation_vectors() const;
160164
void io(Piostream &stream) override;
161-
std::vector<Vector> get_rotation() const;
162165
Point get_translation() const;
163166
};
164167

src/Core/GeometryPrimitives/Vector.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class Vector
108108
inline Vector operator-(const Vector&) const;
109109
inline Vector operator-(const Point&) const;
110110
inline Vector& operator-=(const Vector&);
111+
inline double norm() const;
111112
inline double normalize();
112113
inline double safe_normalize();
113114
inline Vector getArbitraryTangent() const;
@@ -236,10 +237,15 @@ inline Vector Max(const Vector &v1, const Vector &v2)
236237

237238
SCISHARE void Pio( Piostream&, Vector& );
238239

240+
inline double Vector::norm() const
241+
{
242+
return std::sqrt(d_[0]*d_[0] + d_[1]*d_[1] + d_[2]*d_[2]);
243+
}
244+
239245
inline
240246
double Vector::safe_normalize()
241247
{
242-
double l = std::sqrt(d_[0]*d_[0] + d_[1]*d_[1] + d_[2]*d_[2]);
248+
double l = norm();
243249
if (l > 0.0)
244250
{
245251
d_[0]/=l;
@@ -454,7 +460,7 @@ inline double Vector::w() const
454460
inline
455461
double Vector::normalize()
456462
{
457-
double l=sqrt(d_[0]*d_[0] + d_[1]*d_[1] + d_[2]*d_[2]);
463+
double l = norm();
458464
if (l > 0.0)
459465
{
460466
d_[0]/=l;

0 commit comments

Comments
 (0)