Skip to content

Commit 53df379

Browse files
committed
Merge pull request #1033 from SCIInstitute/showfieldglyphs2
Showfieldglyphs2
2 parents 71f431a + f94e2f0 commit 53df379

File tree

14 files changed

+1237
-1070
lines changed

14 files changed

+1237
-1070
lines changed

src/Core/Datatypes/Color.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,21 @@
3636
using namespace SCIRun::Core::Datatypes;
3737

3838
ColorRGB::ColorRGB()
39-
: r_(1.0), g_(1.0), b_(1.0)
39+
: r_(1.0), g_(1.0), b_(1.0), a_(1.0)
4040
{
4141
}
4242

4343
ColorRGB::ColorRGB(double r, double g, double b)
44-
: r_(r), g_(g), b_(b)
44+
: r_(r), g_(g), b_(b), a_(1.0)
4545
{
4646
}
4747

48-
ColorRGB::ColorRGB(const std::string& rgb) : r_(1.0), g_(1.0), b_(1.0)
48+
ColorRGB::ColorRGB(double r, double g, double b, double a)
49+
: r_(r), g_(g), b_(b), a_(a)
50+
{
51+
}
52+
53+
ColorRGB::ColorRGB(const std::string& rgb) : r_(1.0), g_(1.0), b_(1.0), a_(1.0)
4954
{
5055
try
5156
{

src/Core/Datatypes/Color.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ namespace Datatypes {
4242
class SCISHARE ColorRGB
4343
{
4444
private:
45-
double r_, g_, b_;
45+
double r_, g_, b_, a_;
4646
public:
4747
ColorRGB();
4848
explicit ColorRGB(const std::string& rgb);
4949
ColorRGB(double r, double g, double b);
50+
ColorRGB(double r, double g, double b, double a);
5051

5152
// These equality operations should use floating point comparisons.
5253
inline bool operator==(const ColorRGB& c) const {
53-
return ((r_==c.r_)&&(g_==c.g_)&&(b_==c.b_));
54+
return ((r_==c.r_)&&(g_==c.g_)&&(b_==c.b_)&&(a_==c.a_));
5455
}
5556

5657
inline bool operator!=(const ColorRGB& c) const {
@@ -63,6 +64,7 @@ namespace Datatypes {
6364
inline double r() const {return r_;}
6465
inline double g() const {return g_;}
6566
inline double b() const {return b_;}
67+
inline double a() const {return a_;}
6668

6769
std::string toString() const;
6870
};

src/Core/Datatypes/ColorMap.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,12 @@ ColorRGB ColorMap::valueToColor(double scalar) const {
173173
*/
174174
ColorRGB ColorMap::valueToColor(const Tensor &tensor) const {
175175
//TODO this is probably not implemented correctly.
176-
return ColorRGB(getTransformedColor(fabs(tensor.xx())),
177-
getTransformedColor(fabs(tensor.yy())),
178-
getTransformedColor(fabs(tensor.zz())));
176+
//return ColorRGB(getTransformedColor(fabs(tensor.xx())), getTransformedColor(fabs(tensor.yy())), getTransformedColor(fabs(tensor.zz())));
177+
double eigen1, eigen2, eigen3;
178+
Tensor ten = tensor;
179+
ten.get_eigenvalues(eigen1, eigen2, eigen3);
180+
double primaryEigen = std::max(std::max(eigen1, eigen2), eigen3);
181+
return getColorMapVal(primaryEigen);
179182
}
180183
/**
181184
* @name valueToColor
@@ -185,10 +188,8 @@ ColorRGB ColorMap::valueToColor(const Tensor &tensor) const {
185188
*/
186189
ColorRGB ColorMap::valueToColor(const Vector &vector) const {
187190
//TODO this is probably not implemented correctly.
188-
return ColorRGB(getTransformedColor(fabs(vector.x())),
189-
getTransformedColor(fabs(vector.y())),
190-
getTransformedColor(fabs(vector.z())));
191-
191+
// return ColorRGB(getTransformedColor(fabs(vector.x())),getTransformedColor(fabs(vector.y())), getTransformedColor(fabs(vector.z())));
192+
return getColorMapVal(vector.length());
192193
}
193194

194195
std::string ColorMap::getColorMapName() const { return name_; }

src/Graphics/Glyphs/GlyphGeom.cc

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void GlyphGeom::buildObject(GeometryHandle geom, const std::string uniqueNodeID,
9191
}
9292
else if (colorScheme == GeometryObject::COLOR_IN_SITU)
9393
{
94-
attribs.push_back(GeometryObject::SpireVBO::AttributeData("aColor", 1 * sizeof(uint32_t), true));
94+
attribs.push_back(GeometryObject::SpireVBO::AttributeData("aColor", 4 * sizeof(float)));
9595
if (useTriangles)
9696
{
9797
shader = "Shaders/DirPhongInSitu";
@@ -173,7 +173,8 @@ void GlyphGeom::buildObject(GeometryHandle geom, const std::string uniqueNodeID,
173173
vboBuffer->write(static_cast<float>(colors_.at(i).r()));
174174
vboBuffer->write(static_cast<float>(colors_.at(i).g()));
175175
vboBuffer->write(static_cast<float>(colors_.at(i).b()));
176-
vboBuffer->write(static_cast<float>(1.f));
176+
vboBuffer->write(static_cast<float>(colors_.at(i).a()));
177+
//vboBuffer->write(static_cast<float>(1.f));
177178
} // no color writing otherwise
178179
}
179180

@@ -205,20 +206,20 @@ void GlyphGeom::addArrow(const Point& p1, const Point& p2, double radius, double
205206

206207
Point mid(ratio * (p1.x() + p2.x()), ratio * (p1.y() + p2.y()), ratio * (p1.z() + p2.z()));
207208

208-
generateCylinder(p1, mid, radius / 3.0, radius / 3.0, resolution, color1, color2, numVBOElements_, points_, normals_, indices_, colors_);
209+
generateCylinder(p1, mid, radius / 6.0, radius / 6.0, resolution, color1, color2, numVBOElements_, points_, normals_, indices_, colors_);
209210
generateCylinder(mid, p2, radius, 0.0, resolution, color1, color2, numVBOElements_, points_, normals_, indices_, colors_);
210211
}
211212

212213
void GlyphGeom::addSphere(const Point& p, double radius, double resolution, const ColorRGB& color)
213214
{
214-
generateEllipsoid(p, radius, radius, resolution, color, numVBOElements_, points_, normals_, indices_, colors_);
215+
generateSphere(p, radius, radius, resolution, color, numVBOElements_, points_, normals_, indices_, colors_);
215216
}
216-
/*
217+
217218
void GlyphGeom::addEllipsoid(const Point& p, double radius1, double radius2, double resolution, const ColorRGB& color)
218219
{
219220
generateEllipsoid(p, radius1, radius2, resolution, color, numVBOElements_, points_, normals_, indices_, colors_);
220221
}
221-
*/
222+
222223
void GlyphGeom::addCylinder(const Point p1, const Point& p2, double radius, double resolution,
223224
const ColorRGB& color1, const ColorRGB& color2)
224225
{
@@ -233,7 +234,10 @@ void GlyphGeom::addCone(const Point p1, const Point& p2, double radius, double r
233234

234235
void GlyphGeom::addNeedle(Point p1, const Point& p2, const ColorRGB& color1, const ColorRGB& color2)
235236
{
236-
generateLine(p1, p2, color1, color2, numVBOElements_, points_, indices_, colors_);
237+
Point mid(0.5 * (p1.x() + p2.x()), 0.5 * (p1.y() + p2.y()), 0.5 * (p1.z() + p2.z()));
238+
ColorRGB endColor(color2.r(), color2.g(), color2.b(), 0.5);
239+
generateLine(p1, mid, color1, endColor, numVBOElements_, points_, indices_, colors_);
240+
generateLine(mid, p2, color1, endColor, numVBOElements_, points_, indices_, colors_);
237241
}
238242

239243
void GlyphGeom::addPoint(const Point& p, const ColorRGB& color)
@@ -280,7 +284,7 @@ void GlyphGeom::generateCylinder(const Point& p1, const Point& p2, double radius
280284
for (int jj = 0; jj < 6; jj++) indices.pop_back();
281285
}
282286

283-
void GlyphGeom::generateEllipsoid(const Point& center, double radius1, double radius2,
287+
void GlyphGeom::generateSphere(const Point& center, double radius1, double radius2,
284288
double resolution, const ColorRGB& color, int64_t& numVBOElements, std::vector<Vector>& points,
285289
std::vector<Vector>& normals, std::vector<uint32_t>& indices, std::vector<ColorRGB>& colors)
286290
{
@@ -318,6 +322,82 @@ void GlyphGeom::generateEllipsoid(const Point& center, double radius1, double ra
318322
}
319323
}
320324

325+
void GlyphGeom::generateEllipsoid(const Point& center, double radius1, double radius2,
326+
double resolution, const ColorRGB& color, int64_t& numVBOElements, std::vector<Vector>& points,
327+
std::vector<Vector>& normals, std::vector<uint32_t>& indices, std::vector<ColorRGB>& colors)
328+
{
329+
double num_strips = resolution;
330+
if (num_strips < 0) num_strips = 20.0;
331+
double r1 = radius1 < 0 ? 1.0 : radius1;
332+
double r2 = radius2 < 0 ? 1.0 : radius2;
333+
Vector pp1, pp2;
334+
double theta_inc = /*2. */ M_PI / num_strips, phi_inc = 0.5 * M_PI / num_strips;
335+
Vector radius = Vector(radius1, 0, radius2);
336+
337+
//generate triangles for the spheres
338+
for (double phi = 0.; phi <= M_PI; phi += phi_inc)
339+
{
340+
for (double theta = 0.; theta <= /*2. */ M_PI; theta += theta_inc)
341+
{
342+
uint32_t offset = (uint32_t)numVBOElements;
343+
pp1 = Vector(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
344+
pp2 = Vector(sin(theta) * cos(phi + phi_inc), sin(theta) * sin(phi + phi_inc), cos(theta));
345+
points.push_back(r1 * pp1 + Vector(center));
346+
colors.push_back(color);
347+
numVBOElements++;
348+
points.push_back(r2 * pp2 + Vector(center + radius));
349+
colors.push_back(color);
350+
numVBOElements++;
351+
normals.push_back(pp1);
352+
normals.push_back(pp2);
353+
354+
indices.push_back(0 + offset);
355+
indices.push_back(1 + offset);
356+
indices.push_back(2 + offset);
357+
indices.push_back(2 + offset);
358+
indices.push_back(1 + offset);
359+
indices.push_back(3 + offset);
360+
/*
361+
indices.push_back(0 + offset);
362+
indices.push_back(1 + offset);
363+
indices.push_back(2 + offset);
364+
indices.push_back(2 + offset);
365+
indices.push_back(1 + offset);
366+
indices.push_back(3 + offset);
367+
368+
369+
//generate triangles for the cylinders.
370+
Vector n((p1 - p2).normal()), u = (10 * n + Vector(10, 10, 10)).normal();
371+
Vector crx = Cross(u, n).normal();
372+
u = Cross(crx, n).normal();
373+
Vector p;
374+
for (double strips = 0.; strips <= num_strips; strips += 1.)
375+
{
376+
uint32_t offset = (uint32_t)numVBOElements;
377+
p = std::cos(2. * M_PI * strips / num_strips) * u +
378+
std::sin(2. * M_PI * strips / num_strips) * crx;
379+
p.normalize();
380+
points.push_back(r1 * p + Vector(p1));
381+
colors.push_back(color1);
382+
numVBOElements++;
383+
points.push_back(r2 * p + Vector(p2));
384+
colors.push_back(color2);
385+
numVBOElements++;
386+
normals.push_back(p);
387+
normals.push_back(p);
388+
indices.push_back(0 + offset);
389+
indices.push_back(1 + offset);
390+
indices.push_back(2 + offset);
391+
indices.push_back(2 + offset);
392+
indices.push_back(1 + offset);
393+
indices.push_back(3 + offset);
394+
}
395+
*/
396+
}
397+
for (int jj = 0; jj < 6; jj++) indices.pop_back();
398+
}
399+
}
400+
321401
void GlyphGeom::generateLine(const Point p1, const Point& p2, const ColorRGB& color1, const ColorRGB& color2,
322402
int64_t& numVBOElements, std::vector<Vector>& points, std::vector<uint32_t>& indices, std::vector<ColorRGB>& colors)
323403
{

src/Graphics/Glyphs/GlyphGeom.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace SCIRun {
8080
void addArrow(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, double resolution,
8181
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
8282
void addSphere(const Core::Geometry::Point& p, double radius, double resolution, const Core::Datatypes::ColorRGB& color);
83-
//void addEllipsoid(const Core::Geometry::Point& p, double radius1, double radius2, double resolution, const Core::Datatypes::ColorRGB& color);
83+
void addEllipsoid(const Core::Geometry::Point& p, double radius1, double radius2, double resolution, const Core::Datatypes::ColorRGB& color);
8484
void addCylinder(const Core::Geometry::Point p1, const Core::Geometry::Point& p2, double radius, double resolution,
8585
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
8686
void addCone(const Core::Geometry::Point p1, const Core::Geometry::Point& p2, double radius, double resolution,
@@ -111,6 +111,8 @@ namespace SCIRun {
111111
int64_t& numVBOElements, std::vector<Core::Geometry::Vector>& points, std::vector<Core::Geometry::Vector>& normals, std::vector<uint32_t>& indices, std::vector<Core::Datatypes::ColorRGB>& colors);
112112
void generateEllipsoid(const Core::Geometry::Point& center, double radius1, double radius2, double resolution, const Core::Datatypes::ColorRGB& color,
113113
int64_t& numVBOElements, std::vector<Core::Geometry::Vector>& points, std::vector<Core::Geometry::Vector>& normals, std::vector<uint32_t>& indices, std::vector<Core::Datatypes::ColorRGB>& colors);
114+
void generateSphere(const Core::Geometry::Point& center, double radius1, double radius2, double resolution, const Core::Datatypes::ColorRGB& color,
115+
int64_t& numVBOElements, std::vector<Core::Geometry::Vector>& points, std::vector<Core::Geometry::Vector>& normals, std::vector<uint32_t>& indices, std::vector<Core::Datatypes::ColorRGB>& colors);
114116
void generateLine(const Core::Geometry::Point p1, const Core::Geometry::Point& p2, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2,
115117
int64_t& numVBOElements, std::vector<Core::Geometry::Vector>& points, std::vector<uint32_t>& indices, std::vector<Core::Datatypes::ColorRGB>& colors);
116118
void generatePoint(const Core::Geometry::Point p, const Core::Datatypes::ColorRGB& color,

0 commit comments

Comments
 (0)