Skip to content

Commit 3cdc6f0

Browse files
author
tpat
committed
Translation, rotation, and scaling working. Widgets can move in sync. Arrow
widget giving linker error
1 parent 136045f commit 3cdc6f0

21 files changed

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

src/Graphics/Widgets/ConeWidget.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ ConeWidget::ConeWidget(const Core::GeometryIDGenerator& idGenerator,
4444
const std::string& defaultColor,
4545
const Point& p1,
4646
const Point& p2,
47+
const Point& origin,
4748
const BBox& bbox,
4849
bool renderBase,
4950
int resolution)
50-
: WidgetBase(idGenerator, "ConeWidget::" + name, true, (p1 + p2)/2)
51+
: WidgetBase(idGenerator, "ConeWidget::" + name, true, Point(p1 + p2)/2, origin)
5152
{
5253
//std::cout << "ConeWidget() point: " << point.get_string() << std::endl;
5354
if (radius < 0) radius = 1.;

src/Graphics/Widgets/ConeWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace SCIRun {
4747
const std::string& defaultColor,
4848
const Core::Geometry::Point& p1,
4949
const Core::Geometry::Point& p2,
50+
const Core::Geometry::Point& origin,
5051
const Core::Geometry::BBox& bbox,
5152
bool renderBase,
5253
int resolution);

src/Graphics/Widgets/CylinderWidget.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ CylinderWidget::CylinderWidget(const Core::GeometryIDGenerator& idGenerator,
4444
const std::string& defaultColor,
4545
const Point& p1,
4646
const Point& p2,
47+
const Point& origin,
4748
const BBox& bbox,
4849
int resolution)
49-
: WidgetBase(idGenerator, "CylinderWidget::" + name, true, (p1 + p2)/2)
50+
: WidgetBase(idGenerator, "CylinderWidget::" + name, true, Point(p1 + p2)/2, origin)
5051
{
5152
if (radius < 0) radius = 1.;
5253
if (resolution < 0) resolution = 10;

src/Graphics/Widgets/CylinderWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace SCIRun {
4747
const std::string& defaultColor,
4848
const Core::Geometry::Point& p1,
4949
const Core::Geometry::Point& p2,
50+
const Core::Geometry::Point& origin,
5051
const Core::Geometry::BBox& bbox,
5152
int resolution);
5253
private:

src/Graphics/Widgets/DiskWidget.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ DiskWidget::DiskWidget(const Core::GeometryIDGenerator& idGenerator,
4444
const std::string& defaultColor,
4545
const Point& p1,
4646
const Point& p2,
47+
const Point& origin,
4748
const BBox& bbox,
4849
int resolution)
49-
: WidgetBase(idGenerator, "DiskWidget::" + name, true, (p1 + p2)/2)
50+
: WidgetBase(idGenerator, "DiskWidget::" + name, true, Point(p1 + p2)/2, origin)
5051
{
5152
//std::cout << "DiskWidget() point: " << point.get_string() << std::endl;
5253
if (radius < 0) radius = 1.;

src/Graphics/Widgets/DiskWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace SCIRun {
4747
const std::string& defaultColor,
4848
const Core::Geometry::Point& p1,
4949
const Core::Geometry::Point& p2,
50+
const Core::Geometry::Point& origin,
5051
const Core::Geometry::BBox& bbox,
5152
int resolution);
5253
private:

0 commit comments

Comments
 (0)