Skip to content

Commit f197fd4

Browse files
author
Haydelj
committed
added colormap transparency support to glyphs
1 parent 09ce7e3 commit f197fd4

File tree

5 files changed

+121
-87
lines changed

5 files changed

+121
-87
lines changed

src/Core/Datatypes/ColorMap.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,19 @@ double ColorMap::alpha(double transformedValue) const
213213
for(i = 0; (i < alphaLookup_.size()) && (alphaLookup_[i] < transformedValue); i += 2);
214214

215215
double startx = 0.0;
216-
double starty = 40.0;
216+
double starty = 41.0;
217217
double endx = 364.0;
218-
double endy = 40.0;
218+
double endy = starty;
219219

220220
if(i == 0)
221221
{
222222
endx = alphaLookup_[0];
223-
endy = alphaLookup_[1];
223+
starty = endy = alphaLookup_[1];
224224
}
225225
else if(i == alphaLookup_.size())
226226
{
227227
startx = alphaLookup_[i - 2];
228-
starty = alphaLookup_[i - 1];
228+
endy = starty = alphaLookup_[i - 1];
229229
}
230230
else
231231
{
@@ -236,7 +236,7 @@ double ColorMap::alpha(double transformedValue) const
236236
}
237237

238238
double interp = (transformedValue - startx) / (endx - startx);
239-
double value = ((1.0f - interp) * starty + (interp) * endy) / 80.0;
239+
double value = 1.0f - ((1.0f - interp) * starty + (interp) * endy) / 82.0f;
240240
return value;
241241
}
242242

src/Modules/Visualization/CreateStandardColorMap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void CreateStandardColorMap::execute()
6666

6767
//TODO cbright: pass computed alpha function from transient state to factory
6868
auto alphaPoints = state->getValue(Parameters::AlphaUserPointsVector).toVector();
69+
std::cout << alphaPoints << "\n";
6970
std::vector<double> points;
7071
for(auto point : alphaPoints)
7172
{

src/Modules/Visualization/ShowFieldGlyphs.cc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ void GlyphBuilder::renderVectors(
587587

588588
glyphs.buildObject(*geom, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENT_EDGES),
589589
state->getValue(ShowFieldGlyphs::VectorsUniformTransparencyValue).toDouble(),
590-
colorScheme, renState, primIn, mesh->get_bounding_box());
590+
colorScheme, renState, primIn, mesh->get_bounding_box(), true, portHandler.getTextureMap());
591591
}
592592

593593
void GlyphBuilder::renderScalars(
@@ -682,7 +682,9 @@ void GlyphBuilder::renderScalars(
682682
std::string uniqueNodeID = id + "scalar_glyphs" + ss.str();
683683

684684
glyphs.buildObject(*geom, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENT_NODES),
685-
state->getValue(ShowFieldGlyphs::ScalarsUniformTransparencyValue).toDouble(), colorScheme, renState, primIn, mesh->get_bounding_box());
685+
state->getValue(ShowFieldGlyphs::ScalarsUniformTransparencyValue).toDouble(),
686+
colorScheme, renState, primIn, mesh->get_bounding_box(), true,
687+
portHandler.getTextureMap());
686688
}
687689

688690
double map_emphasis(double old)
@@ -870,16 +872,23 @@ void GlyphBuilder::renderTensors(
870872
}
871873

872874
glyphs.buildObject(*geom, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY),
873-
state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), colorScheme, renState, primIn, mesh->get_bounding_box());
875+
state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(),
876+
colorScheme, renState, primIn, mesh->get_bounding_box(), true,
877+
portHandler.getTextureMap());
874878

875879
// Render lines(2 eigenvalues equalling 0)
876880
RenderState lineRenState = getVectorsRenderState(state);
877881
tensor_line_glyphs.buildObject(*geom, uniqueLineID, lineRenState.get(RenderState::USE_TRANSPARENT_EDGES),
878-
state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), colorScheme, lineRenState, SpireIBO::PRIMITIVE::LINES, mesh->get_bounding_box());
882+
state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(),
883+
colorScheme, lineRenState, SpireIBO::PRIMITIVE::LINES, mesh->get_bounding_box(),
884+
true, portHandler.getTextureMap());
885+
879886
// Render scalars(3 eigenvalues equalling 0)
880887
RenderState pointRenState = getScalarsRenderState(state);
881888
point_glyphs.buildObject(*geom, uniquePointID, pointRenState.get(RenderState::USE_TRANSPARENT_NODES),
882-
state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), colorScheme, pointRenState, SpireIBO::PRIMITIVE::POINTS, mesh->get_bounding_box());
889+
state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(),
890+
colorScheme, pointRenState, SpireIBO::PRIMITIVE::POINTS, mesh->get_bounding_box(),
891+
true, portHandler.getTextureMap());
883892
}
884893

885894
void ShowFieldGlyphs::setSuperquadricEmphasis(int emphasis)

src/Modules/Visualization/ShowFieldGlyphsPortHandler.cc

Lines changed: 96 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ namespace SCIRun{
5151
boost::optional<ColorMapHandle> pcolorMap,
5252
boost::optional<ColorMapHandle> scolorMap,
5353
boost::optional<ColorMapHandle> tcolorMap)
54-
: module_(mod),
55-
pf_handle(pf), pf_info(pf)
54+
: module_(mod), pf_handle(pf), pf_info(pf)
5655
{
5756
// Save field info
5857
p_vfld = (pf)->vfield();
@@ -134,48 +133,50 @@ namespace SCIRun{
134133

135134
// If color map was picked, set the chosen color map
136135
if(colorScheme == ColorScheme::COLOR_MAP)
136+
{
137+
switch(renState.mColorInput)
137138
{
138-
switch(renState.mColorInput)
139+
case RenderState::InputPort::PRIMARY_PORT:
140+
if(pcolorMap)
139141
{
140-
case RenderState::InputPort::PRIMARY_PORT:
141-
if(pcolorMap)
142-
{
143-
colorMap = pcolorMap;
144-
colorMapGiven = true;
145-
}
146-
else
147-
{
148-
colorMapGiven = false;
149-
}
150-
break;
151-
case RenderState::InputPort::SECONDARY_PORT:
152-
if(scolorMap)
153-
{
154-
colorMap = scolorMap;
155-
colorMapGiven = true;
156-
}
157-
else
158-
{
159-
colorMapGiven = false;
160-
}
161-
break;
162-
case RenderState::InputPort::TERTIARY_PORT:
163-
if(tcolorMap)
164-
{
165-
colorMap = tcolorMap;
166-
colorMapGiven = true;
167-
}
168-
else
169-
{
170-
colorMapGiven = false;
171-
}
172-
break;
173-
default:
174-
throw std::invalid_argument("Selected port was not primary, secondary, or tertiary.");
175-
break;
142+
colorMap = pcolorMap;
143+
colorMapGiven = true;
176144
}
145+
else
146+
{
147+
colorMapGiven = false;
148+
}
149+
break;
150+
case RenderState::InputPort::SECONDARY_PORT:
151+
if(scolorMap)
152+
{
153+
colorMap = scolorMap;
154+
colorMapGiven = true;
155+
}
156+
else
157+
{
158+
colorMapGiven = false;
159+
}
160+
break;
161+
case RenderState::InputPort::TERTIARY_PORT:
162+
if(tcolorMap)
163+
{
164+
colorMap = tcolorMap;
165+
colorMapGiven = true;
166+
}
167+
else
168+
{
169+
colorMapGiven = false;
170+
}
171+
break;
172+
default:
173+
throw std::invalid_argument("Selected port was not primary, secondary, or tertiary.");
174+
break;
177175
}
178176

177+
spiltColorMapToTextureAndCoordinates();
178+
}
179+
179180
// Get color input type from render state
180181
colorInput = renState.mColorInput;
181182

@@ -267,10 +268,10 @@ namespace SCIRun{
267268

268269
ColorRGB colorMapVal;
269270
switch(colorInput)
270-
{
271+
{
271272
case RenderState::InputPort::PRIMARY_PORT:
272273
switch(pf_data_type)
273-
{
274+
{
274275
case FieldDataType::Scalar:
275276
colorMapVal = colorMap.get()->valueToColor(pinputScalar.get());
276277
break;
@@ -283,11 +284,11 @@ namespace SCIRun{
283284
default:
284285
throw std::invalid_argument("Primary color map did not find scalar, vector, or tensor data.");
285286
break;
286-
}
287+
}
287288
break;
288289
case RenderState::InputPort::SECONDARY_PORT:
289290
switch(sf_data_type)
290-
{
291+
{
291292
case FieldDataType::Scalar:
292293
colorMapVal = colorMap.get()->valueToColor(sinputScalar.get());
293294
break;
@@ -300,11 +301,11 @@ namespace SCIRun{
300301
default:
301302
throw std::invalid_argument("Secondary color map did not find scalar, vector, or tensor data.");
302303
break;
303-
}
304+
}
304305
break;
305306
case RenderState::InputPort::TERTIARY_PORT:
306307
switch(tf_data_type)
307-
{
308+
{
308309
case FieldDataType::Scalar:
309310
colorMapVal = colorMap.get()->valueToColor(tinputScalar.get());
310311
break;
@@ -317,12 +318,12 @@ namespace SCIRun{
317318
default:
318319
throw std::invalid_argument("Tertiary color map did not find scalar, vector, or tensor data.");
319320
break;
320-
}
321+
}
321322
break;
322323
default:
323324
throw std::invalid_argument("Color map selection was not given a primary, secondary, or tertiary port.");
324325
break;
325-
}
326+
}
326327
return colorMapVal;
327328
}
328329

@@ -331,40 +332,40 @@ namespace SCIRun{
331332
{
332333
// Make sure color map port and correpsonding field data is given for chosen color map
333334
if(colorScheme == ColorScheme::COLOR_MAP)
335+
{
336+
switch(colorInput)
334337
{
335-
switch(colorInput)
338+
case RenderState::InputPort::PRIMARY_PORT:
339+
if(!colorMap)
336340
{
337-
case RenderState::InputPort::PRIMARY_PORT:
338-
if(!colorMap)
339-
{
340-
throw std::invalid_argument("Primary Color Map input is required.");
341-
}
342-
break;
343-
case RenderState::InputPort::SECONDARY_PORT:
344-
if(!(secondaryFieldGiven && colorMap))
345-
{
346-
throw std::invalid_argument("Secondary Field and Color Map input is required.");
347-
}
348-
if(s_vfld->num_values() < p_vfld->num_values())
349-
{
350-
throw std::invalid_argument("Secondary Field input cannot have a smaller size than the Primary Field input.");
351-
}
352-
break;
353-
case RenderState::InputPort::TERTIARY_PORT:
354-
if(!(tertiaryFieldGiven && colorMap))
355-
{
356-
throw std::invalid_argument("Tertiary Field and Color Map input is required.");
357-
}
358-
if(t_vfld->num_values() < p_vfld->num_values())
359-
{
360-
throw std::invalid_argument("Tertiary Field input cannot have a smaller size than the Primary Field input.");
361-
}
362-
break;
363-
default:
364-
throw std::invalid_argument("Must select a primary, secondary, or tertiary port for color map input.");
365-
break;
341+
throw std::invalid_argument("Primary Color Map input is required.");
342+
}
343+
break;
344+
case RenderState::InputPort::SECONDARY_PORT:
345+
if(!(secondaryFieldGiven && colorMap))
346+
{
347+
throw std::invalid_argument("Secondary Field and Color Map input is required.");
366348
}
349+
if(s_vfld->num_values() < p_vfld->num_values())
350+
{
351+
throw std::invalid_argument("Secondary Field input cannot have a smaller size than the Primary Field input.");
352+
}
353+
break;
354+
case RenderState::InputPort::TERTIARY_PORT:
355+
if(!(tertiaryFieldGiven && colorMap))
356+
{
357+
throw std::invalid_argument("Tertiary Field and Color Map input is required.");
358+
}
359+
if(t_vfld->num_values() < p_vfld->num_values())
360+
{
361+
throw std::invalid_argument("Tertiary Field input cannot have a smaller size than the Primary Field input.");
362+
}
363+
break;
364+
default:
365+
throw std::invalid_argument("Must select a primary, secondary, or tertiary port for color map input.");
366+
break;
367367
}
368+
}
368369
// Make sure scalar is not given for rgb conversion
369370
else if(colorScheme == ColorScheme::COLOR_IN_SITU)
370371
{
@@ -647,6 +648,24 @@ namespace SCIRun{
647648
{
648649
return pf_handle->mesh()->getFacade();
649650
}
651+
652+
void ShowFieldGlyphsPortHandler::spiltColorMapToTextureAndCoordinates()
653+
{
654+
ColorMapHandle realColorMap = nullptr;
655+
656+
if(colorMap) realColorMap = colorMap.get();
657+
else realColorMap = StandardColorMapFactory::create();
658+
659+
textureMap = StandardColorMapFactory::create(realColorMap->getColorMapName(),
660+
realColorMap->getColorMapResolution(), realColorMap->getColorMapShift(),
661+
realColorMap->getColorMapInvert(), 0.5, 1.0, realColorMap->getAlphaLookup());
662+
663+
coordinateMap = StandardColorMapFactory::create("Grayscale", 256, 0, false,
664+
realColorMap->getColorMapRescaleScale(), realColorMap->getColorMapRescaleShift());
665+
666+
colorMap = coordinateMap;
667+
}
668+
650669
}
651670
}
652671
}

src/Modules/Visualization/ShowFieldGlyphsPortHandler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace SCIRun{
6969
RenderState::InputPort colorInput;
7070
Core::Datatypes::ColorRGB defaultColor;
7171
boost::optional<Core::Datatypes::ColorMapHandle> colorMap;
72+
Core::Datatypes::ColorMapHandle coordinateMap {nullptr}, textureMap {nullptr};
7273
boost::optional<Core::Geometry::Tensor> pinputTensor, sinputTensor, tinputTensor;
7374
boost::optional<Core::Geometry::Vector> pinputVector, sinputVector, tinputVector;
7475
boost::optional<double> pinputScalar, sinputScalar, tinputScalar;
@@ -100,6 +101,10 @@ namespace SCIRun{
100101
// Verifies that data is valid. Run this after initialization
101102
void checkForErrors();
102103

104+
void spiltColorMapToTextureAndCoordinates();
105+
106+
Core::Datatypes::ColorMapHandle getTextureMap() {return textureMap;}
107+
103108
// Returns color scheme that was set in render state
104109
Graphics::Datatypes::ColorScheme getColorScheme();
105110

0 commit comments

Comments
 (0)