Skip to content

Commit 39c954a

Browse files
author
RubioJr9
committed
Added superquadric widgets!
1 parent 773f59c commit 39c954a

14 files changed

+210
-3
lines changed

src/Graphics/Glyphs/GlyphGeom.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ void GlyphGeom::addSuperquadricTensor(const Point& center, Tensor& t, double sca
115115
builder.generateSuperquadricTensor(constructor_, emphasis);
116116
}
117117

118+
void GlyphGeom::addSuperquadricSurface(const Point& center, Tensor& t, double scale, int resolution,
119+
const ColorRGB& color, double A, double B)
120+
{
121+
TensorGlyphBuilder builder(t, center);
122+
builder.setResolution(resolution);
123+
builder.setColor(color);
124+
builder.scaleTensor(scale);
125+
builder.makeTensorPositive();
126+
builder.generateSuperquadricSurface(constructor_, A, B);
127+
}
128+
118129
void GlyphGeom::addCylinder(const Point& p1, const Point& p2, double radius, int resolution,
119130
const ColorRGB& color1, const ColorRGB& color2,
120131
bool renderBase1, bool renderBase2)

src/Graphics/Glyphs/GlyphGeom.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ class SCISHARE GlyphGeom
101101
void addNeedle(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2,
102102
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
103103
void addPoint(const Core::Geometry::Point& p, const Core::Datatypes::ColorRGB& color);
104-
104+
void addSuperquadricSurface(const Core::Geometry::Point& center, Core::Geometry::Tensor& t,
105+
double scale, int resolution, const Core::Datatypes::ColorRGB& color,
106+
double A, double B);
105107
void generateSphere(const Core::Geometry::Point& center, double radius, int resolution,
106108
const Core::Datatypes::ColorRGB& color);
107109
void generatePlane(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2,

src/Graphics/Glyphs/TensorGlyphBuilder.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,24 @@ void TensorGlyphBuilder::generateSuperquadricTensor(GlyphConstructor& constructo
236236
double A = linear ? pPower : lPower;
237237
double B = linear ? lPower : pPower;
238238

239+
generateSuperquadricSurfacePrivate(constructor, A, B);
240+
}
241+
242+
void TensorGlyphBuilder::generateSuperquadricSurface(GlyphConstructor& constructor, double A, double B)
243+
{
244+
makeTensorPositive();
245+
computeTransforms();
246+
postScaleTransorms();
247+
computeSinCosTable(false);
248+
generateSuperquadricSurfacePrivate(constructor, A, B);
249+
}
250+
251+
void TensorGlyphBuilder::generateSuperquadricSurfacePrivate(GlyphConstructor& constructor, double A, double B)
252+
{
253+
double cl = t_.linearCertainty();
254+
double cp = t_.planarCertainty();
255+
bool linear = cl >= cp;
256+
239257
double normalA = 2.0-A;
240258
double normalB = 2.0-B;
241259

src/Graphics/Glyphs/TensorGlyphBuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ class SCISHARE TensorGlyphBuilder
5151
void setColor(const Core::Datatypes::ColorRGB& color);
5252
void setResolution(double resolution);
5353
void generateSuperquadricTensor(GlyphConstructor& constructor, double emphasis);
54+
void generateSuperquadricSurface(GlyphConstructor& constructor, double A, double B);
5455
void generateEllipsoid(GlyphConstructor& constructor, bool half);
5556
void generateBox(GlyphConstructor& constructor);
5657

5758
private:
59+
void generateSuperquadricSurfacePrivate(GlyphConstructor& constructor, double A, double B);
5860
Core::Geometry::Point evaluateSuperquadricPointLinear(double sinphi, double cosphi, double sintheta,
5961
double costheta, double A, double B);
6062
Core::Geometry::Point evaluateSuperquadricPointPlanar(double sinphi, double cosphi, double sintheta,

src/Graphics/Widgets/BoundingBoxWidget.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,18 +339,31 @@ void BBoxDataHandler::makeCornerSpheres(const GeneralWidgetParameters& gen,
339339
WidgetBase& widget)
340340
{
341341
const static double cornerSphereRadius = 1.5;
342+
const static double A = 1.5;
343+
const static double B = 1.5;
342344

343-
auto builder = SphereWidgetBuilder(gen.base.idGenerator)
345+
auto builder = SuperquadricWidgetBuilder(gen.base.idGenerator)
344346
.transformMapping({{WidgetInteraction::CLICK, singleMovementWidget(WidgetMovement::SCALE)}})
345347
.scale(cornerSphereRadius * params.scale * scale_)
346348
.origin(params.origin)
347349
.defaultColor(SCALE_COLOR_)
348350
.boundingBox(params.bbox)
349351
.resolution(params.resolution);
350352

353+
354+
// auto builder = SphereWidgetBuilder(gen.base.idGenerator)
355+
// .transformMapping({{WidgetInteraction::CLICK, singleMovementWidget(WidgetMovement::SCALE)}})
356+
// .scale(cornerSphereRadius * params.scale * scale_)
357+
// .origin(params.origin)
358+
// .defaultColor(SCALE_COLOR_)
359+
// .boundingBox(params.bbox)
360+
// .resolution(params.resolution);
361+
351362
for (int c = 0; c < CORNER_COUNT_; ++c)
352363
{
353-
corners_[c] = builder.tag("Corner" + std::to_string(c)).centerPoint(cornerPoints_[c]).build();
364+
Tensor t = Tensor(scaledEigvecs_[0], scaledEigvecs_[1], scaledEigvecs_[2]);
365+
corners_[c] = builder.tag("Corner" + std::to_string(c)).centerPoint(cornerPoints_[c])
366+
.tensor(t).A(A).B(B).build();
354367
auto flipVec = cornerPoints_[c] - params.origin;
355368
corners_[c]->addTransformParameters<Scaling>(params.origin, flipVec);
356369
}

src/Graphics/Widgets/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ SET(Graphics_Widgets_SRCS
3636
ConeWidget.cc
3737
DiskWidget.cc
3838
ArrowWidget.cc
39+
SuperquadricWidget.cc
3940
GlyphFactory.cc
4041
)
4142

@@ -48,6 +49,7 @@ SET(Graphics_Widgets_HEADERS
4849
CylinderWidget.h
4950
ConeWidget.h
5051
ArrowWidget.h
52+
SuperquadricWidget.h
5153
GlyphFactory.h
5254
WidgetParameters.h
5355
WidgetBuilders.h

src/Graphics/Widgets/GlyphFactory.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,30 @@ std::string RealGlyphFactory::sphere(SphereParameters params, WidgetBase& widget
5858
return name;
5959
}
6060

61+
std::string RealGlyphFactory::superquadric(SuperquadricParameters params, WidgetBase& widget) const
62+
{
63+
if (params.common.scale < 0) params.common.scale = 1.;
64+
if (params.common.resolution < 0) params.common.resolution = 10;
65+
66+
auto colorScheme = ColorScheme::COLOR_UNIFORM;
67+
std::stringstream ss;
68+
ss << params.common.scale << params.common.resolution << static_cast<int>(colorScheme);
69+
70+
auto name = widget.uniqueID() + "widget" + ss.str();
71+
72+
Graphics::GlyphGeom glyphs;
73+
ColorRGB node_color;
74+
glyphs.addSuperquadricSurface(params.point, params.tensor, params.common.scale,
75+
params.common.resolution, node_color, params.A, params.B);
76+
77+
auto renState = getSphereRenderState(params.common.defaultColor);
78+
79+
glyphs.buildObject(widget, name, renState.get(RenderState::USE_TRANSPARENCY), 1.0,
80+
colorScheme, renState, SpireIBO::PRIMITIVE::TRIANGLES, params.common.bbox);
81+
82+
return name;
83+
}
84+
6185
RenderState RealGlyphFactory::getSphereRenderState(const std::string& defaultColor) const
6286
{
6387
RenderState renState;

src/Graphics/Widgets/GlyphFactory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace SCIRun
5050
virtual std::string cylinder(CylinderParameters params, WidgetBase& widget) const = 0;
5151
virtual std::string box(BoundingBoxParameters params, WidgetBase& widget) const = 0;
5252
virtual std::string basicBox(BasicBoundingBoxParameters params, WidgetBase& widget) const = 0;
53+
virtual std::string superquadric(SuperquadricParameters params, WidgetBase& widget) const = 0;
5354
};
5455

5556
class SCISHARE RealGlyphFactory : public AbstractGlyphFactory
@@ -61,6 +62,7 @@ namespace SCIRun
6162
std::string cylinder(CylinderParameters params, WidgetBase& widget) const override;
6263
std::string box(BoundingBoxParameters params, WidgetBase& widget) const override;
6364
std::string basicBox(BasicBoundingBoxParameters params, WidgetBase& widget) const override;
65+
std::string superquadric(SuperquadricParameters params, WidgetBase& widget) const override;
6466
private:
6567
RenderState getSphereRenderState(const std::string& defaultColor) const;
6668
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 <Graphics/Widgets/SuperquadricWidget.h>
30+
#include <Graphics/Widgets/GlyphFactory.h>
31+
32+
using namespace SCIRun;
33+
using namespace SCIRun::Graphics::Datatypes;
34+
35+
SuperquadricWidget::SuperquadricWidget(const GeneralWidgetParameters& gen,
36+
SuperquadricParameters params)
37+
: WidgetBase({gen.base.idGenerator, "SuperquadricWidget::" + gen.base.tag, gen.base.mapping})
38+
{
39+
name_ = gen.glyphMaker->superquadric(params, *this);
40+
setPosition(params.point);
41+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 Graphics_Widgets_SuperquadricWidget_H
30+
#define Graphics_Widgets_SuperquadricWidget_H
31+
32+
#include <Core/GeometryPrimitives/GeomFwd.h>
33+
#include <Core/Datatypes/Legacy/Field/FieldFwd.h>
34+
#include <Graphics/Widgets/Widget.h>
35+
#include <Graphics/Widgets/share.h>
36+
37+
namespace SCIRun {
38+
namespace Graphics {
39+
namespace Datatypes {
40+
41+
class SCISHARE SuperquadricWidget : public WidgetBase
42+
{
43+
public:
44+
SuperquadricWidget(const GeneralWidgetParameters& gen, SuperquadricParameters params);
45+
};
46+
47+
using SuperquadricWidgetHandle = SharedPointer<SuperquadricWidget>;
48+
}
49+
}
50+
}
51+
#endif

0 commit comments

Comments
 (0)