Skip to content

Commit 515506c

Browse files
author
tpat
committed
-added widget class files
1 parent 8c759f9 commit 515506c

File tree

6 files changed

+495
-0
lines changed

6 files changed

+495
-0
lines changed

src/Graphics/Widgets/ConeWidget.cc

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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/ConeWidget.h>
30+
#include <Graphics/Glyphs/GlyphGeom.h>
31+
#include <Core/GeometryPrimitives/Point.h>
32+
#include <Core/Datatypes/Legacy/Field/Field.h>
33+
#include <Core/Datatypes/Legacy/Field/VMesh.h>
34+
#include <Core/Datatypes/Color.h>
35+
36+
using namespace SCIRun;
37+
using namespace SCIRun::Core::Datatypes;
38+
using namespace SCIRun::Graphics::Datatypes;
39+
using namespace SCIRun::Core::Geometry;
40+
41+
ConeWidget::ConeWidget(const Core::GeometryIDGenerator& idGenerator,
42+
const std::string& name,
43+
double radius,
44+
const std::string& defaultColor,
45+
const Point& p1,
46+
const Point& p2,
47+
const BBox& bbox)
48+
: WidgetBase(idGenerator, "ConeWidget::" + name, true), position_((p1 + p2)/2)
49+
{
50+
//std::cout << "ConeWidget() point: " << point.get_string() << std::endl;
51+
double resolution = 10;
52+
if (radius < 0) radius = 1.;
53+
if (resolution < 0) resolution = 10.;
54+
55+
auto colorScheme = ColorScheme::COLOR_UNIFORM;
56+
std::stringstream ss;
57+
ss << radius << resolution << static_cast<int>(colorScheme);
58+
59+
auto uniqueNodeID = uniqueID() + "widget" + ss.str();
60+
61+
Graphics::GlyphGeom glyphs;
62+
ColorRGB node_color;
63+
glyphs.addCone(p1, p2, radius, resolution, node_color, node_color);
64+
65+
auto renState = getWidgetRenderState(defaultColor);
66+
67+
glyphs.buildObject(*this, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY), 1.0,
68+
colorScheme, renState, SpireIBO::PRIMITIVE::TRIANGLES, bbox);
69+
}
70+
71+
Point ConeWidget::position() const
72+
{
73+
return position_;
74+
}
75+
76+
void ConeWidget::setPosition(const Point& p)
77+
{
78+
position_ = p;
79+
}
80+
81+
RenderState ConeWidget::getWidgetRenderState(const std::string& defaultColor)
82+
{
83+
RenderState renState;
84+
85+
renState.set(RenderState::IS_ON, true);
86+
renState.set(RenderState::USE_TRANSPARENCY, false);
87+
88+
renState.defaultColor = ColorRGB(defaultColor);
89+
renState.defaultColor = (renState.defaultColor.r() > 1.0 ||
90+
renState.defaultColor.g() > 1.0 ||
91+
renState.defaultColor.b() > 1.0) ?
92+
ColorRGB(
93+
renState.defaultColor.r() / 255.,
94+
renState.defaultColor.g() / 255.,
95+
renState.defaultColor.b() / 255.)
96+
: renState.defaultColor;
97+
98+
renState.set(RenderState::USE_DEFAULT_COLOR, true);
99+
renState.set(RenderState::USE_NORMALS, true);
100+
renState.set(RenderState::IS_WIDGET, true);
101+
102+
return renState;
103+
}

src/Graphics/Widgets/ConeWidget.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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_ConeWidget_H
30+
#define Graphics_Widgets_ConeWidget_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 ConeWidget : public WidgetBase
42+
{
43+
public:
44+
ConeWidget(const Core::GeometryIDGenerator& idGenerator,
45+
const std::string& name,
46+
double radius,
47+
const std::string& defaultColor,
48+
const Core::Geometry::Point& p1,
49+
const Core::Geometry::Point& p2,
50+
const Core::Geometry::BBox& bbox);
51+
Core::Geometry::Point position() const;
52+
void setPosition(const Core::Geometry::Point& p);
53+
private:
54+
RenderState getWidgetRenderState(const std::string& defaultColor);
55+
Core::Geometry::Point position_;
56+
};
57+
58+
using ConeWidgetHandle = SharedPointer<ConeWidget>;
59+
}
60+
}
61+
}
62+
#endif
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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/CylinderWidget.h>
30+
#include <Graphics/Glyphs/GlyphGeom.h>
31+
#include <Core/GeometryPrimitives/Point.h>
32+
#include <Core/Datatypes/Legacy/Field/Field.h>
33+
#include <Core/Datatypes/Legacy/Field/VMesh.h>
34+
#include <Core/Datatypes/Color.h>
35+
36+
using namespace SCIRun;
37+
using namespace SCIRun::Core::Datatypes;
38+
using namespace SCIRun::Graphics::Datatypes;
39+
using namespace SCIRun::Core::Geometry;
40+
41+
CylinderWidget::CylinderWidget(const Core::GeometryIDGenerator& idGenerator,
42+
const std::string& name,
43+
double radius,
44+
const std::string& defaultColor,
45+
const Point& p1,
46+
const Point& p2,
47+
const BBox& bbox)
48+
: WidgetBase(idGenerator, "CylinderWidget::" + name, true), position_((p1 + p2)/2)
49+
{
50+
//std::cout << "CylinderWidget() point: " << point.get_string() << std::endl;
51+
double resolution = 10;
52+
if (radius < 0) radius = 1.;
53+
if (resolution < 0) resolution = 10.;
54+
55+
auto colorScheme = ColorScheme::COLOR_UNIFORM;
56+
std::stringstream ss;
57+
ss << radius << resolution << static_cast<int>(colorScheme);
58+
59+
auto uniqueNodeID = uniqueID() + "widget" + ss.str();
60+
61+
Graphics::GlyphGeom glyphs;
62+
ColorRGB node_color;
63+
glyphs.addCylinder(p1, p2, radius, resolution, node_color, node_color);
64+
65+
auto renState = getWidgetRenderState(defaultColor);
66+
67+
glyphs.buildObject(*this, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY), 1.0,
68+
colorScheme, renState, SpireIBO::PRIMITIVE::TRIANGLES, bbox);
69+
}
70+
71+
Point CylinderWidget::position() const
72+
{
73+
return position_;
74+
}
75+
76+
void CylinderWidget::setPosition(const Point& p)
77+
{
78+
position_ = p;
79+
}
80+
81+
RenderState CylinderWidget::getWidgetRenderState(const std::string& defaultColor)
82+
{
83+
RenderState renState;
84+
85+
renState.set(RenderState::IS_ON, true);
86+
renState.set(RenderState::USE_TRANSPARENCY, false);
87+
88+
renState.defaultColor = ColorRGB(defaultColor);
89+
renState.defaultColor = (renState.defaultColor.r() > 1.0 ||
90+
renState.defaultColor.g() > 1.0 ||
91+
renState.defaultColor.b() > 1.0) ?
92+
ColorRGB(
93+
renState.defaultColor.r() / 255.,
94+
renState.defaultColor.g() / 255.,
95+
renState.defaultColor.b() / 255.)
96+
: renState.defaultColor;
97+
98+
renState.set(RenderState::USE_DEFAULT_COLOR, true);
99+
renState.set(RenderState::USE_NORMALS, true);
100+
renState.set(RenderState::IS_WIDGET, true);
101+
102+
return renState;
103+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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_CylinderWidget_H
30+
#define Graphics_Widgets_CylinderWidget_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 CylinderWidget : public WidgetBase
42+
{
43+
public:
44+
CylinderWidget(const Core::GeometryIDGenerator& idGenerator,
45+
const std::string& name,
46+
double radius,
47+
const std::string& defaultColor,
48+
const Core::Geometry::Point& p1,
49+
const Core::Geometry::Point& p2,
50+
const Core::Geometry::BBox& bbox);
51+
Core::Geometry::Point position() const;
52+
void setPosition(const Core::Geometry::Point& p);
53+
private:
54+
RenderState getWidgetRenderState(const std::string& defaultColor);
55+
Core::Geometry::Point position_;
56+
};
57+
58+
using CylinderWidgetHandle = SharedPointer<CylinderWidget>;
59+
}
60+
}
61+
}
62+
#endif

0 commit comments

Comments
 (0)