Skip to content

Commit 7a59516

Browse files
authored
Merge pull request #1978 from RubioJr9/dipole_movement
Widget movement
2 parents faf78b9 + c3a0076 commit 7a59516

34 files changed

+956
-472
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/Externals/spire/arc-ball/ArcBall.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include "ArcBall.hpp"
2+
#include <iostream>
23

34
namespace spire {
45

56
//------------------------------------------------------------------------------
6-
ArcBall::ArcBall(const glm::vec3& center, glm::float_t radius, const glm::mat4& screenToTCS) :
7+
ArcBall::ArcBall(const glm::vec3& center, glm::float_t radius, bool inverted, const glm::mat4& screenToTCS) :
78
mScreenToTCS(screenToTCS),
9+
invertHemisphere(inverted),
810
mCenter(center),
911
mRadius(radius)
1012
{
@@ -27,18 +29,21 @@ glm::vec3 ArcBall::mouseOnSphere(const glm::vec3& tscMouse)
2729
ballMouse.x = (tscMouse.x - mCenter.x) / mRadius;
2830
ballMouse.y = (tscMouse.y - mCenter.y) / mRadius;
2931

30-
glm::float_t mag = glm::dot(ballMouse, ballMouse);
31-
if (mag > 1.0)
32+
glm::float_t mag_sq = glm::dot(ballMouse, ballMouse);
33+
if (mag_sq > 1.0)
3234
{
3335
// Since we are outside of the sphere, map to the visible boundary of the sphere.
34-
ballMouse *= 1.0 / sqrtf(mag);
36+
ballMouse *= 1.0 / sqrtf(mag_sq);
3537
}
3638
else
3739
{
3840
// Essentially, we are normalizing the vector by adding the missing z component.
39-
ballMouse.z = sqrtf(1.0 - mag);
41+
ballMouse.z = sqrtf(1.0 - mag_sq);
4042
}
4143

44+
if(invertHemisphere)
45+
ballMouse.z = -ballMouse.z;
46+
4247
return ballMouse;
4348
}
4449

@@ -57,6 +62,8 @@ void ArcBall::drag(const glm::vec2& msc)
5762
// Construct a quaternion from two points on the unit sphere.
5863
glm:: quat mQDrag = quatFromUnitSphere(mVSphereDown, mVSphereNow);
5964
mQNow = mQDrag * mQDown;
65+
if(glm::dot(mVSphereDown, mVSphereNow) < 0.0)
66+
beginDrag(msc);
6067
}
6168

6269
//------------------------------------------------------------------------------
@@ -69,12 +76,13 @@ void ArcBall::setLocationOnSphere(glm::vec3 location, glm::vec3 up)
6976
//------------------------------------------------------------------------------
7077
glm::quat ArcBall::quatFromUnitSphere(const glm::vec3& from, const glm::vec3& to)
7178
{
72-
glm::quat q;
73-
q.x = from.y*to.z - from.z*to.y;
74-
q.y = from.z*to.x - from.x*to.z;
75-
q.z = from.x*to.y - from.y*to.x;
76-
q.w = from.x*to.x + from.y*to.y + from.z*to.z;
77-
return q;
79+
glm::vec3 axis = glm::normalize(glm::cross(from, to));
80+
float angle = std::acos(glm::dot(from, to));
81+
82+
if(angle <= 0.00001)
83+
return glm::quat(1.0, 0.0, 0.0, 0.0);
84+
85+
return glm::angleAxis(angle, axis);
7886
}
7987

8088
//------------------------------------------------------------------------------

src/Externals/spire/arc-ball/ArcBall.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class SCISHARE ArcBall
3535
/// default is 0.75.
3636
/// \param screenToTCS Transformation from screen coordinates
3737
/// to TCS. \p center and \p radius are given in TCS.
38-
ArcBall(const glm::vec3& center, glm::float_t radius,
39-
const glm::mat4& screenToTCS = glm::mat4());
38+
ArcBall(const glm::vec3& center, glm::float_t radius, bool inverted = false,
39+
const glm::mat4& screenToTCS = glm::mat4());
4040

4141
/// Initiate an arc ball drag given the mouse click in screen coordinates.
4242
/// \param mouseScreenCoords Mouse screen coordinates.
@@ -73,6 +73,7 @@ class SCISHARE ArcBall
7373
glm::mat4 mScreenToTCS;
7474
glm::vec3 mCenter; ///< Center of the arcball in target coordinate system.
7575
glm::float_t mRadius; ///< Radius of the arcball in target coordinate system.
76+
bool invertHemisphere;
7677

7778
glm::vec3 mVSphereDown; ///< vDown mapped to the sphere of 'mRadius' centered at 'mCenter' in TCS.
7879
glm::quat mQDown; ///< State of the rotation since mouse down.

src/Externals/spire/es-general/comp/Transform.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct Transform
2121
transform[3].z = pos.z;
2222
}
2323

24-
glm::vec3 getPosition()
24+
glm::vec3 getPosition() const
2525
{
2626
return glm::vec3(transform[3].x, transform[3].y, transform[3].z);
2727
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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+
License for the specific language governing rights and limitations under
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+
#include <Core/Datatypes/Color.h>
30+
#include <Graphics/Glyphs/GlyphGeom.h>
31+
#include <Graphics/Widgets/ArrowWidget.h>
32+
#include <Graphics/Widgets/WidgetFactory.h>
33+
34+
using namespace SCIRun;
35+
using namespace SCIRun::Core;
36+
using namespace SCIRun::Core::Datatypes;
37+
using namespace SCIRun::Graphics::Datatypes;
38+
using namespace SCIRun::Core::Geometry;
39+
40+
ArrowWidget::ArrowWidget(const GeometryIDGenerator &idGenerator,
41+
const std::string &name, double scale,
42+
const Point &pos, const Vector &dir, int resolution,
43+
bool show_as_vector, size_t widget_num, size_t widget_iter,
44+
const BBox &bbox)
45+
: CompositeWidget(idGenerator, name) {
46+
static const ColorRGB deflPointCol_ = ColorRGB(0.54, 0.6, 1.0);
47+
static const ColorRGB deflCol_ = ColorRGB(0.5, 0.5, 0.5);
48+
static const ColorRGB resizeCol_ = ColorRGB(0.54, 1.0, 0.60);
49+
ColorRGB sphereCol = (show_as_vector) ? deflPointCol_ : resizeCol_;
50+
51+
static const double sphereRadius_ = 0.25;
52+
static const double cylinderRadius_ = 0.12;
53+
static const double coneRadius_ = 0.25;
54+
static const double diskRadius_ = 0.25;
55+
static const double diskDistFromCenter_ = 0.85;
56+
static const double diskWidth_ = 0.05;
57+
58+
if (resolution < 3) resolution = 10;
59+
60+
isVector_ = show_as_vector;
61+
auto colorScheme = ColorScheme::COLOR_UNIFORM;
62+
std::stringstream ss;
63+
ss << pos << dir << static_cast<int>(colorScheme);
64+
65+
auto uniqueNodeID = uniqueID() + "widget" + ss.str();
66+
67+
// Graphics::GlyphGeom glyphs;
68+
ColorRGB node_color;
69+
70+
// auto renState = getWidgetRenderState(defaultColor);
71+
72+
Point bmin = pos;
73+
Point bmax = pos + dir * scale;
74+
75+
// Fix degenerate boxes.
76+
const double size_estimate = std::max((bmax - bmin).length() * 0.01, 1.0e-5);
77+
if (std::abs(bmax.x() - bmin.x()) < 1.0e-6)
78+
{
79+
bmin.x(bmin.x() - size_estimate);
80+
bmax.x(bmax.x() + size_estimate);
81+
}
82+
if (std::abs(bmax.y() - bmin.y()) < 1.0e-6)
83+
{
84+
bmin.y(bmin.y() - size_estimate);
85+
bmax.y(bmax.y() + size_estimate);
86+
}
87+
if (std::abs(bmax.z() - bmin.z()) < 1.0e-6)
88+
{
89+
bmin.z(bmin.z() - size_estimate);
90+
bmax.z(bmax.z() + size_estimate);
91+
}
92+
93+
Point center = bmin + dir/2.0 * scale;
94+
95+
// Create glyphs
96+
widgets_.push_back(WidgetFactory::createSphere(
97+
idGenerator,
98+
widgetName(ArrowWidgetSection::SPHERE, widget_num, widget_iter),
99+
sphereRadius_ * scale,
100+
sphereCol.toString(),
101+
bmin,
102+
bmin,
103+
bbox,
104+
resolution));
105+
widgets_[0]->setToTranslate();
106+
107+
if(show_as_vector)
108+
{
109+
// Starts the cylinder position closer to the surface of the sphere
110+
Point cylinderStart = bmin + 0.75 * (dir * scale * sphereRadius_);
111+
112+
widgets_.push_back(WidgetFactory::createCylinder(
113+
idGenerator,
114+
widgetName(ArrowWidgetSection::CYLINDER, widget_num, widget_iter),
115+
cylinderRadius_ * scale,
116+
deflCol_.toString(),
117+
cylinderStart,
118+
center,
119+
bmin,
120+
bbox,
121+
resolution));
122+
widgets_[1]->setToTranslate();
123+
124+
widgets_.push_back(WidgetFactory::createCone(
125+
idGenerator,
126+
widgetName(ArrowWidgetSection::CONE, widget_num, widget_iter),
127+
coneRadius_ * scale,
128+
deflCol_.toString(),
129+
center,
130+
bmax,
131+
bmin,
132+
bbox,
133+
true,
134+
resolution));
135+
widgets_[2]->setToRotate();
136+
137+
Point diskPos = bmin + dir * scale * diskDistFromCenter_;
138+
Point dp1 = diskPos - diskWidth_ * dir * scale;
139+
Point dp2 = diskPos + diskWidth_ * dir * scale;
140+
widgets_.push_back(WidgetFactory::createDisk(
141+
idGenerator,
142+
widgetName(ArrowWidgetSection::DISK, widget_num, widget_iter),
143+
diskRadius_ * scale,
144+
resizeCol_.toString(),
145+
dp1,
146+
dp2,
147+
bmin,
148+
bbox,
149+
resolution));
150+
Vector flipVec = dir.getArbitraryTangent().normal();
151+
widgets_[3]->setToScale(flipVec);
152+
}
153+
154+
std::vector<std::string> geom_ids;
155+
for(int i = 0; i < 1 + 3*show_as_vector; i++)
156+
geom_ids.push_back(widgets_[i]->uniqueID());
157+
158+
for(int i = 0; i < 1 + 3*show_as_vector; i++)
159+
{
160+
widgets_[i]->connectedIds_ = geom_ids;
161+
addToList(widgets_[i]);
162+
}
163+
}
164+
165+
bool ArrowWidget::isVector()
166+
{
167+
return isVector_;
168+
}
169+
170+
std::string ArrowWidget::widgetName(size_t i, size_t id, size_t iter)
171+
{
172+
return "ArrowWidget(" + std::to_string(i) + ")" + "(" + std::to_string(id) + ")" +
173+
"(" + std::to_string(iter) + ")";
174+
}

src/Graphics/Widgets/ArrowWidget.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
#ifndef Graphics_Widgets_ArrowWidget_H
30+
#define Graphics_Widgets_ArrowWidget_H
31+
32+
#include <Core/Datatypes/Legacy/Field/FieldFwd.h>
33+
#include <Core/GeometryPrimitives/GeomFwd.h>
34+
#include <Graphics/Widgets/Widget.h>
35+
#include <Graphics/Widgets/share.h>
36+
37+
namespace SCIRun {
38+
namespace Graphics {
39+
namespace Datatypes {
40+
enum ArrowWidgetSection { SPHERE, CYLINDER, CONE, DISK };
41+
42+
class SCISHARE ArrowWidget : public CompositeWidget
43+
{
44+
public:
45+
ArrowWidget(const Core::GeometryIDGenerator &idGenerator,
46+
const std::string &name, double scale,
47+
const Core::Geometry::Point &pos,
48+
const Core::Geometry::Vector &dir, int resolution,
49+
bool show_as_vector, size_t widget_num, size_t widget_iter,
50+
const Core::Geometry::BBox &bbox);
51+
52+
bool isVector();
53+
54+
private:
55+
bool isVector_;
56+
std::string widgetName(size_t i, size_t id, size_t iter);
57+
};
58+
59+
using ArrowWidgetHandle = SharedPointer<ArrowWidget>;
60+
}
61+
}
62+
}
63+
#endif

src/Graphics/Widgets/BoundingBoxWidget.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ DEALINGS IN THE SOFTWARE.
2828

2929
#include <Graphics/Widgets/BoundingBoxWidget.h>
3030
#include <Graphics/Glyphs/GlyphGeom.h>
31-
#include <Core/GeometryPrimitives/Point.h>
3231
#include <Core/Datatypes/Color.h>
3332

3433
using namespace SCIRun;
@@ -52,8 +51,8 @@ void BoxPosition::getPosition(Point& center, Point& right, Point& down, Point& i
5251
}
5352

5453
BoundingBoxWidget::BoundingBoxWidget(const Core::GeometryIDGenerator& idGenerator,
55-
double scale, const BoxPosition& pos, const BBox& bbox)
56-
: WidgetBase(idGenerator, "BoundingBox", true)
54+
double scale, const BoxPosition& pos, const Point& origin, const BBox& bbox)
55+
: WidgetBase(idGenerator, "BoundingBox", true, origin)
5756
{
5857
auto colorScheme(ColorScheme::COLOR_UNIFORM);
5958
//get all the bbox edges

src/Graphics/Widgets/BoundingBoxWidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ DEALINGS IN THE SOFTWARE.
3030
#define Graphics_Widgets_BoundingBoxWidget_H
3131

3232
#include <Core/GeometryPrimitives/GeomFwd.h>
33+
#include <Core/GeometryPrimitives/Point.h>
3334
#include <Graphics/Widgets/Widget.h>
3435
#include <Graphics/Widgets/share.h>
3536

@@ -41,7 +42,7 @@ namespace SCIRun {
4142
{
4243
public:
4344
BoundingBoxWidget(const Core::GeometryIDGenerator& idGenerator, double scale,
44-
const BoxPosition& pos, const Core::Geometry::BBox& bbox);
45+
const BoxPosition& pos, const Core::Geometry::Point& origin, const Core::Geometry::BBox& bbox);
4546
};
4647
}
4748
}

0 commit comments

Comments
 (0)