Skip to content

Commit eded80f

Browse files
author
tpat
committed
Basic dipole widget working. Disks added.
1 parent 6ada41b commit eded80f

File tree

16 files changed

+446
-699
lines changed

16 files changed

+446
-699
lines changed

src/Graphics/Glyphs/GlyphGeom.cc

Lines changed: 171 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique
202202
geom.passes().push_back(pass);
203203
}
204204

205-
void GlyphGeom::addArrow(const Point& p1, const Point& p2, double radius, double ratio, double resolution,
205+
void GlyphGeom::addArrow(const Point& p1, const Point& p2, double radius, double ratio, int resolution,
206206
const ColorRGB& color1, const ColorRGB& color2)
207207
{
208208
Point mid((p1.x() * ratio + p2.x() * (1 - ratio)), (p1.y() * ratio + p2.y() * (1 - ratio)), (p1.z() * ratio + p2.z() * (1 - ratio)));
@@ -211,7 +211,7 @@ void GlyphGeom::addArrow(const Point& p1, const Point& p2, double radius, double
211211
generateCylinder(mid, p2, radius, 0.0, resolution, color1, color2);
212212
}
213213

214-
void GlyphGeom::addSphere(const Point& p, double radius, double resolution, const ColorRGB& color)
214+
void GlyphGeom::addSphere(const Point& p, double radius, int resolution, const ColorRGB& color)
215215
{
216216
generateSphere(p, radius, resolution, color);
217217
}
@@ -221,25 +221,31 @@ void GlyphGeom::addBox(const Point& center, Tensor& t, double scale)
221221
generateBox(center, t, scale);
222222
}
223223

224-
void GlyphGeom::addEllipsoid(const Point& p, Tensor& t, Vector& scaled_eigenvals, double resolution, const ColorRGB& color)
224+
void GlyphGeom::addEllipsoid(const Point& p, Tensor& t, Vector& scaled_eigenvals, int resolution, const ColorRGB& color)
225225
{
226226
generateEllipsoid(p, t, scaled_eigenvals, resolution, color);
227227
}
228228

229-
void GlyphGeom::addCylinder(const Point& p1, const Point& p2, double radius, double resolution,
229+
void GlyphGeom::addCylinder(const Point& p1, const Point& p2, double radius, int resolution,
230230
const ColorRGB& color1, const ColorRGB& color2)
231231
{
232232
generateCylinder(p1, p2, radius, radius, resolution, color1, color2);
233233
}
234234

235-
void GlyphGeom::addCone(const Point& p1, const Point& p2, double radius, double resolution,
236-
const ColorRGB& color1, const ColorRGB& color2)
235+
void GlyphGeom::addDisk(const Point& p1, const Point& p2, double radius, int resolution,
236+
const ColorRGB& color1, const ColorRGB& color2)
237+
{
238+
generateDisk(p1, p2, radius, radius, resolution, color1, color2);
239+
}
240+
241+
void GlyphGeom::addCone(const Point& p1, const Point& p2, double radius, int resolution,
242+
bool renderBase, const ColorRGB& color1, const ColorRGB& color2)
237243
{
238-
generateCylinder(p1, p2, radius, 0.0, resolution, color1, color2);
244+
generateCone(p1, p2, radius, resolution, renderBase, color1, color2);
239245
}
240246

241247
void GlyphGeom::addClippingPlane(const Point& p1, const Point& p2,
242-
const Point& p3, const Point& p4, double radius, double resolution,
248+
const Point& p3, const Point& p4, double radius, int resolution,
243249
const ColorRGB& color1, const ColorRGB& color2)
244250
{
245251
addSphere(p1, radius, resolution, color1);
@@ -278,7 +284,7 @@ void GlyphGeom::addPoint(const Point& p, const ColorRGB& color)
278284
}
279285

280286
void GlyphGeom::generateCylinder(const Point& p1, const Point& p2, double radius1,
281-
double radius2, double resolution, const ColorRGB& color1,
287+
double radius2, int resolution, const ColorRGB& color1,
282288
const ColorRGB& color2)
283289
{
284290
double num_strips = resolution;
@@ -291,58 +297,182 @@ void GlyphGeom::generateCylinder(const Point& p1, const Point& p2, double radius
291297
Vector crx = n.getArbitraryTangent();
292298
Vector u = Cross(crx, n).normal();
293299
Vector p;
294-
// points_.push_back(Vector(p1.x(), p1.y(), p1.z()));
295-
// points_.push_back(Vector(p2.x(), p2.y(), p2.z()));
296-
// int p1_index = numVBOElements_;
297-
// colors_.push_back(color1);
298-
// normals_.push_back(n);
299-
// numVBOElements_++;
300-
// int p2_index = numVBOElements_;
301-
// colors_.push_back(color2);
302-
// normals_.push_back(n);
303-
// numVBOElements_++;
304-
for (double strips = 0.; strips <= num_strips; strips += 1.)
300+
for (int strips = 0; strips <= num_strips; strips++)
305301
{
306302
uint32_t offset = static_cast<uint32_t>(numVBOElements_);
307303
p = std::cos(2. * M_PI * strips / num_strips) * u +
308304
std::sin(2. * M_PI * strips / num_strips) * crx;
309305
p.normalize();
306+
Vector normals(((p2-p1).length() * p + (r2-r1)*n).normal());
307+
310308
points_.push_back(r1 * p + Vector(p1));
311309
colors_.push_back(color1);
310+
normals_.push_back(normals);
312311
numVBOElements_++;
313312
points_.push_back(r2 * p + Vector(p2));
314313
colors_.push_back(color2);
315-
numVBOElements_++;
316-
Vector normals(((p2-p1).length() * p + (r2-r1)*n).normal());
317-
normals_.push_back(normals);
318314
normals_.push_back(normals);
315+
numVBOElements_++;
316+
319317
indices_.push_back(0 + offset);
320318
indices_.push_back(1 + offset);
321319
indices_.push_back(2 + offset);
322320
indices_.push_back(2 + offset);
323321
indices_.push_back(1 + offset);
324322
indices_.push_back(3 + offset);
325-
326-
// Sides
327-
// points_.push_back(r1 * p + Vector(p1));
328-
// colors_.push_back(color1);
329-
// normals_.push_back(n);
330-
// numVBOElements_++;
331-
// points_.push_back(r2 * p + Vector(p2));
332-
// colors_.push_back(color2);
333-
// normals_.push_back(n);
334-
// numVBOElements_++;
335-
// indices_.push_back(p1_index);
336-
// indices_.push_back(0 + offset);
337-
// indices_.push_back(2 + offset);
338-
// indices_.push_back(p2_index);
339-
// indices_.push_back(1 + offset);
340-
// indices_.push_back(3 + offset);
341323
}
342324
for (int jj = 0; jj < 6; jj++) indices_.pop_back();
343325
}
344326

345-
void GlyphGeom::generateSphere(const Point& center, double radius, double resolution, const ColorRGB& color)
327+
void GlyphGeom::generateCone(const Point& p1, const Point& p2, double radius,
328+
int resolution, bool renderBase,
329+
const ColorRGB& color1, const ColorRGB& color2)
330+
{
331+
resolution = resolution < 0 ? 20 : resolution;
332+
radius = radius < 0 ? 1 : radius;
333+
334+
//generate triangles for the cylinders.
335+
Vector n((p1 - p2).normal());
336+
Vector crx = n.getArbitraryTangent();
337+
Vector u = Cross(crx, n).normal();
338+
339+
// Center of base
340+
uint32_t base_index = numVBOElements_;
341+
int points_per_loop = 2;
342+
if(renderBase)
343+
{
344+
points_.push_back(Vector(p1));
345+
colors_.push_back(color1);
346+
normals_.push_back(n);
347+
numVBOElements_++;
348+
points_per_loop = 3;
349+
}
350+
351+
// Precalculate
352+
double length = (p2-p1).length();
353+
double strip_angle = 2. * M_PI / resolution;
354+
355+
Vector p;
356+
// Add points, normals, and colors
357+
for (int strips = 0; strips <= resolution; strips++)
358+
{
359+
p = std::cos(strip_angle * strips) * u +
360+
std::sin(strip_angle * strips) * crx;
361+
p.normalize();
362+
Vector normals((length * p - radius * n).normal());
363+
364+
points_.push_back(radius * p + Vector(p1));
365+
colors_.push_back(color1);
366+
normals_.push_back(normals);
367+
points_.push_back(Vector(p2));
368+
colors_.push_back(color2);
369+
normals_.push_back(normals);
370+
371+
if(renderBase)
372+
{
373+
points_.push_back(radius * p + Vector(p1));
374+
colors_.push_back(color1);
375+
normals_.push_back(n);
376+
}
377+
}
378+
379+
uint32_t offset = static_cast<uint32_t>(numVBOElements_);
380+
numVBOElements_ += resolution * points_per_loop;
381+
382+
// Add indices
383+
for (int strips = offset; strips < resolution * points_per_loop + offset; strips += points_per_loop)
384+
{
385+
indices_.push_back(strips);
386+
indices_.push_back(strips + 1);
387+
indices_.push_back(strips + points_per_loop);
388+
if(renderBase)
389+
{
390+
indices_.push_back(base_index);
391+
indices_.push_back(strips + 2);
392+
indices_.push_back(strips + points_per_loop + 2);
393+
}
394+
}
395+
}
396+
397+
void GlyphGeom::generateDisk(const Point& p1, const Point& p2, double radius1,
398+
double radius2, int resolution, const ColorRGB& color1,
399+
const ColorRGB& color2)
400+
{
401+
resolution = resolution < 0 ? 20 : resolution;
402+
radius1 = radius1 < 0 ? 1.0 : radius1;
403+
radius2 = radius2 < 0 ? 1.0 : radius2;
404+
405+
//generate triangles for the cylinders.
406+
Vector n((p1 - p2).normal());
407+
Vector crx = n.getArbitraryTangent();
408+
Vector u = Cross(crx, n).normal();
409+
410+
int points_per_loop = 4;
411+
412+
// Add center points so flat sides can be drawn
413+
points_.push_back(Vector(p1));
414+
points_.push_back(Vector(p2));
415+
int p1_index = numVBOElements_;
416+
colors_.push_back(color1);
417+
normals_.push_back(n);
418+
numVBOElements_++;
419+
int p2_index = numVBOElements_;
420+
colors_.push_back(color2);
421+
normals_.push_back(n);
422+
numVBOElements_++;
423+
424+
// Precalculate
425+
double length = (p2-p1).length();
426+
double strip_angle = 2. * M_PI / resolution;
427+
428+
Vector p;
429+
// Add points, normals, and colors
430+
for (int strips = 0; strips <= resolution; strips++)
431+
{
432+
p = std::cos(strip_angle * strips) * u +
433+
std::sin(strip_angle * strips) * crx;
434+
p.normalize();
435+
Vector normals((length * p + (radius2-radius1)*n).normal());
436+
points_.push_back(radius1 * p + Vector(p1));
437+
colors_.push_back(color1);
438+
normals_.push_back(normals);
439+
points_.push_back(radius2 * p + Vector(p2));
440+
colors_.push_back(color2);
441+
normals_.push_back(normals);
442+
443+
// Points for base
444+
points_.push_back(radius1 * p + Vector(p1));
445+
colors_.push_back(color1);
446+
normals_.push_back(n);
447+
points_.push_back(radius2 * p + Vector(p2));
448+
colors_.push_back(color2);
449+
normals_.push_back(n);
450+
}
451+
452+
uint32_t offset = static_cast<uint32_t>(numVBOElements_);
453+
numVBOElements_ += resolution * points_per_loop;
454+
455+
// Add indices
456+
for (int strips = offset; strips < resolution * points_per_loop + offset; strips += points_per_loop)
457+
{
458+
indices_.push_back(strips);
459+
indices_.push_back(strips + 1);
460+
indices_.push_back(strips + points_per_loop);
461+
indices_.push_back(strips + 1);
462+
indices_.push_back(strips + points_per_loop);
463+
indices_.push_back(strips + points_per_loop + 1);
464+
465+
// Render base
466+
indices_.push_back(p1_index);
467+
indices_.push_back(strips + 2);
468+
indices_.push_back(strips + points_per_loop + 2);
469+
indices_.push_back(p2_index);
470+
indices_.push_back(strips + 3);
471+
indices_.push_back(strips + points_per_loop + 3);
472+
}
473+
}
474+
475+
void GlyphGeom::generateSphere(const Point& center, double radius, int resolution, const ColorRGB& color)
346476
{
347477
double num_strips = resolution;
348478
if (num_strips < 0) num_strips = 20.0;
@@ -512,7 +642,7 @@ void GlyphGeom::generateBox(const Point& center, Tensor& t, double scale)
512642
**/
513643
}
514644

515-
void GlyphGeom::generateEllipsoid(const Point& center, Tensor& t, Vector &scaled_eigenvals, double resolution, const ColorRGB& color)
645+
void GlyphGeom::generateEllipsoid(const Point& center, Tensor& t, Vector &scaled_eigenvals, int resolution, const ColorRGB& color)
516646
{
517647
Vector eig_vec1, eig_vec2, eig_vec3;
518648
t.get_eigenvectors(eig_vec1, eig_vec2, eig_vec3);

src/Graphics/Glyphs/GlyphGeom.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,19 @@ namespace SCIRun {
5353
const Datatypes::ColorScheme& colorScheme, RenderState state,
5454
const Datatypes::SpireIBO::PRIMITIVE& primIn, const Core::Geometry::BBox& bbox);
5555

56-
void addArrow(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, double ratio, double resolution,
56+
void addArrow(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, double ratio, int resolution,
5757
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
58-
void addSphere(const Core::Geometry::Point& p, double radius, double resolution, const Core::Datatypes::ColorRGB& color);
58+
void addSphere(const Core::Geometry::Point& p, double radius, int resolution, const Core::Datatypes::ColorRGB& color);
5959
void addBox(const Core::Geometry::Point& center, Core::Geometry::Tensor& t, double scale);
60-
void addEllipsoid(const Core::Geometry::Point& p, Core::Geometry::Tensor& t, Core::Geometry::Vector& scaled_eigenvals, double resolution, const Core::Datatypes::ColorRGB& color);
61-
void addCylinder(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, double resolution,
62-
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
63-
void addCone(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, double resolution,
60+
void addEllipsoid(const Core::Geometry::Point& p, Core::Geometry::Tensor& t, Core::Geometry::Vector& scaled_eigenvals, int resolution, const Core::Datatypes::ColorRGB& color);
61+
void addCylinder(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, int resolution,
6462
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
63+
void addDisk(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, int resolution,
64+
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
65+
void addCone(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, int resolution,
66+
bool renderBase, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
6567
void addClippingPlane(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2,
66-
const Core::Geometry::Point& p3, const Core::Geometry::Point& p4, double radius, double resolution,
68+
const Core::Geometry::Point& p3, const Core::Geometry::Point& p4, double radius, int resolution,
6769
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
6870
void addPlane(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2,
6971
const Core::Geometry::Point& p3, const Core::Geometry::Point& p4,
@@ -90,10 +92,12 @@ namespace SCIRun {
9092
int64_t numVBOElements_;
9193
uint32_t lineIndex_;
9294

93-
void generateCylinder(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius1, double radius2, double resolution, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
94-
void generateSphere(const Core::Geometry::Point& center, double radius, double resolution, const Core::Datatypes::ColorRGB& color);
95+
void generateCylinder(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius1, double radius2, int resolution, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
96+
void generateCone(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, int resolution, bool renderBase, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
97+
void generateDisk(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius1, double radius2, int resolution, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
98+
void generateSphere(const Core::Geometry::Point& center, double radius, int resolution, const Core::Datatypes::ColorRGB& color);
9599
void generateBox(const Core::Geometry::Point& center, Core::Geometry::Tensor& t, double scale);
96-
void generateEllipsoid(const Core::Geometry::Point& center, Core::Geometry::Tensor& t, Core::Geometry::Vector& scaled_eigenvals, double resolution, const Core::Datatypes::ColorRGB& color);
100+
void generateEllipsoid(const Core::Geometry::Point& center, Core::Geometry::Tensor& t, Core::Geometry::Vector& scaled_eigenvals, int resolution, const Core::Datatypes::ColorRGB& color);
97101
void generateLine(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
98102
void generatePoint(const Core::Geometry::Point& p, const Core::Datatypes::ColorRGB& color);
99103
void generatePlane(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2,

src/Graphics/Widgets/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ SET(Graphics_Widgets_SRCS
3232
SphereWidget.cc
3333
CylinderWidget.cc
3434
ConeWidget.cc
35+
DiskWidget.cc
3536
)
3637

3738
SET(Graphics_Widgets_HEADERS

src/Graphics/Widgets/ConeWidget.cc

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@ using namespace SCIRun::Graphics::Datatypes;
3939
using namespace SCIRun::Core::Geometry;
4040

4141
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)
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+
bool renderBase)
49+
: WidgetBase(idGenerator, "ConeWidget::" + name, true, (p1 + p2)/2)
4950
{
5051
//std::cout << "ConeWidget() point: " << point.get_string() << std::endl;
51-
double resolution = 10;
52+
int resolution = 10;
5253
if (radius < 0) radius = 1.;
5354
if (resolution < 0) resolution = 10.;
5455

@@ -60,24 +61,14 @@ ConeWidget::ConeWidget(const Core::GeometryIDGenerator& idGenerator,
6061

6162
Graphics::GlyphGeom glyphs;
6263
ColorRGB node_color;
63-
glyphs.addCone(p1, p2, radius, resolution, node_color, node_color);
64+
glyphs.addCone(p1, p2, radius, resolution, renderBase, node_color, node_color);
6465

6566
auto renState = getWidgetRenderState(defaultColor);
6667

6768
glyphs.buildObject(*this, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY), 1.0,
6869
colorScheme, renState, SpireIBO::PRIMITIVE::TRIANGLES, bbox);
6970
}
7071

71-
Point ConeWidget::position() const
72-
{
73-
return position_;
74-
}
75-
76-
void ConeWidget::setPosition(const Point& p)
77-
{
78-
position_ = p;
79-
}
80-
8172
RenderState ConeWidget::getWidgetRenderState(const std::string& defaultColor)
8273
{
8374
RenderState renState;

0 commit comments

Comments
 (0)