From 6d29873893a3cc389f3543ab8aaa00270382d047 Mon Sep 17 00:00:00 2001 From: Haydelj Date: Wed, 18 Sep 2019 11:06:02 -0600 Subject: [PATCH 01/13] in progress --- src/Core/Datatypes/ColorMap.cc | 78 ++++++++++++------- src/Core/Datatypes/ColorMap.h | 8 +- .../Visualization/CreateStandardColorMap.cc | 7 ++ 3 files changed, 64 insertions(+), 29 deletions(-) diff --git a/src/Core/Datatypes/ColorMap.cc b/src/Core/Datatypes/ColorMap.cc index 23b8ca432e..8a579a5431 100644 --- a/src/Core/Datatypes/ColorMap.cc +++ b/src/Core/Datatypes/ColorMap.cc @@ -42,9 +42,10 @@ using namespace SCIRun::Core::Geometry; using namespace SCIRun::Core::Logging; ColorMap::ColorMap(ColorMapStrategyHandle color, const std::string& name, const size_t resolution, const double shift, - const bool invert, const double rescale_scale, const double rescale_shift) + const bool invert, const double rescale_scale, const double rescale_shift, const std::vector& alphaPoints) : color_(color), nameInfo_(name), resolution_(resolution), shift_(shift), - invert_(invert), rescale_scale_(rescale_scale), rescale_shift_(rescale_shift) + invert_(invert), rescale_scale_(rescale_scale), rescale_shift_(rescale_shift), + alphaLookup_(alphaPoints) { } @@ -116,7 +117,7 @@ namespace detail ColorMapHandle StandardColorMapFactory::create(const std::string& name, const size_t &res, const double &shift, const bool &invert, - const double &rescale_scale, const double &rescale_shift) + const double &rescale_scale, const double &rescale_shift, const std::vector& alphaPoints) { using namespace detail; ColorMapStrategyHandle color; @@ -129,7 +130,7 @@ ColorMapHandle StandardColorMapFactory::create(const std::string& name, const si color.reset(new Rainbow); } - return boost::make_shared(color, name, res, shift, invert, rescale_scale, rescale_shift); + return boost::make_shared(color, name, res, shift, invert, rescale_scale, rescale_shift, alphaPoints); } StandardColorMapFactory::NameList StandardColorMapFactory::getList() @@ -194,19 +195,46 @@ ColorRGB ColorMap::getColorMapVal(double v) const //now grab the RGB auto colorWithoutAlpha = color_->getColorMapVal(f); //TODO: - //return applyAlpha(f, colorWithoutAlpha); - return colorWithoutAlpha; + return applyAlpha(f, colorWithoutAlpha); + //return colorWithoutAlpha; } -/* -ColorRGB applyAlpha(double transformed, colorWithoutAlpha) -...easy +ColorRGB ColorMap::applyAlpha(double transformed, ColorRGB colorWithoutAlpha) +{ + double a = alpha(transformed); + return ColorRGB(colorWithoutAlpha.r(), colorWithoutAlpha.g(), colorWithoutAlpha.b(), a); +} -double alpha(double transformedValue) +double ColorMap::alpha(double transformedValue) { - // interpolate in alphaLookup_ + std::cout << transformedValue << "\n"; + int i; + for(i = 0; (i < alphaLookup_.size()) && (transformedValue < alphaLookup_[i]); i += 2); + + double startx = 0.0; + double starty = 40.0; + double endx = 360.0; + double endy = 40.0; + + if(i == 0) + { + endx = alphaLookup_[0]; + endy = alphaLookup_[1]; + } + else if(i == alphaLookup_.size()) + { + startx = alphaLookup_[i]; + starty = alphaLookup_[i - 1]; + } + else + { + startx = alphaLookup_[i - 2]; + starty = alphaLookup_[i - 1]; + endx = alphaLookup_[i + 0]; + endy = alphaLookup_[i + 1]; + } } -*/ + /** * @name valueToColor @@ -214,40 +242,36 @@ double alpha(double transformedValue) * @param The raw data value as a scalar double. * @return The RGB value mapped from the scalar. */ -ColorRGB ColorMap::valueToColor(double scalar) const { - ColorRGB color = getColorMapVal(scalar); - return color; - //float alpha = 0.5; - //return ColorRGB(color.r(), color.g(), color.b(), alpha); +ColorRGB ColorMap::valueToColor(double scalar) const +{ + return getColorMapVal(scalar); } + /** * @name valueToColor * @brief Takes a tensor value and creates an RGB value based on the magnitude of the eigenvalues. * @param The raw data value as a tensor. * @return The RGB value mapped from the tensor. */ -ColorRGB ColorMap::valueToColor(Tensor &tensor) const { +ColorRGB ColorMap::valueToColor(Tensor &tensor) const +{ double eigen1, eigen2, eigen3; tensor.get_eigenvalues(eigen1, eigen2, eigen3); double magnitude = Vector(eigen1, eigen2, eigen3).length(); - ColorRGB color = getColorMapVal(magnitude); - return color; - //float alpha = 0.5; - //return ColorRGB(color.r(), color.g(), color.b(), alpha); + return getColorMapVal(magnitude); } + /** * @name valueToColor * @brief Takes a vector value and creates an RGB value. * @param The raw data value as a vector. * @return The RGB value mapped from the vector. */ -ColorRGB ColorMap::valueToColor(const Vector &vector) const { +ColorRGB ColorMap::valueToColor(const Vector &vector) const +{ //TODO this is probably not implemented correctly. // return ColorRGB(getTransformedColor(fabs(vector.x())),getTransformedColor(fabs(vector.y())), getTransformedColor(fabs(vector.z()))); - ColorRGB color = getColorMapVal(vector.length()); - return color; - //float alpha = 0.5; - //return ColorRGB(color.r(), color.g(), color.b(), alpha); + return getColorMapVal(vector.length()); } // This Rainbow takes into account scientific visualization recommendations. diff --git a/src/Core/Datatypes/ColorMap.h b/src/Core/Datatypes/ColorMap.h index d96722e288..e7792180bc 100644 --- a/src/Core/Datatypes/ColorMap.h +++ b/src/Core/Datatypes/ColorMap.h @@ -51,7 +51,8 @@ namespace Datatypes { explicit ColorMap(ColorMapStrategyHandle color, const std::string& name = "Rainbow", const size_t resolution = 256, const double shift = 0.0, const bool invert = false, - const double rescale_scale = .5, const double rescale_shift = 1.); + const double rescale_scale = .5, const double rescale_shift = 1.0, + const std::vector& alphaPoints = std::vector()); //TODO cbright: pass in alpha vector virtual ColorMap* clone() const override; @@ -73,6 +74,8 @@ namespace Datatypes { ///<< Internal functions. Core::Datatypes::ColorRGB getColorMapVal(double v) const; double getTransformedValue(double v) const; + ColorRGB applyAlpha(double transformed, ColorRGB colorWithoutAlpha); + double alpha(double transformedValue); ColorMapStrategyHandle color_; ///<< The colormap's name. @@ -112,7 +115,8 @@ namespace Datatypes { // See explanation for defaults above in ColorMap Constructor static ColorMapHandle create(const std::string& name = "Rainbow", const size_t &resolution = 256, const double &shift = 0.0, const bool &invert = false, - const double &rescale_scale = .5, const double &rescale_shift = 1.); + const double &rescale_scale = .5, const double &rescale_shift = 1.0, + const std::vector& alphaPoints = std::vector()); typedef std::vector NameList; static NameList getList(); private: diff --git a/src/Modules/Visualization/CreateStandardColorMap.cc b/src/Modules/Visualization/CreateStandardColorMap.cc index 5a86ae3668..e8dcc21ae4 100644 --- a/src/Modules/Visualization/CreateStandardColorMap.cc +++ b/src/Modules/Visualization/CreateStandardColorMap.cc @@ -66,6 +66,13 @@ void CreateStandardColorMap::execute() //TODO cbright: pass computed alpha function from transient state to factory auto alphaPoints = state->getValue(Parameters::AlphaUserPointsVector).toVector(); + std::cout << alphaPoints << "\n"; + std::vector points; + for(auto point : alphaPoints) + { + points.push_back(point.toVector()[0].toDouble()); + points.push_back(point.toVector()[1].toDouble()); + } //just in case there is a problem with the QT values... res = std::min(std::max(res,2),256); From 3c2803a3966c64d9b9a602e19e9a27a6155537c4 Mon Sep 17 00:00:00 2001 From: Haydelj Date: Wed, 18 Sep 2019 13:12:49 -0600 Subject: [PATCH 02/13] added transparency to colormaps --- src/Core/Datatypes/ColorMap.cc | 18 +++++++++++++----- src/Core/Datatypes/ColorMap.h | 5 +++-- .../Modules/Render/ES/shaders/Flat_ColorMap.fs | 2 +- .../Render/ES/shaders/Phong_ColorMap.fs | 2 +- .../Visualization/CreateStandardColorMap.cc | 2 +- src/Modules/Visualization/ShowField.cc | 2 +- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Core/Datatypes/ColorMap.cc b/src/Core/Datatypes/ColorMap.cc index 8a579a5431..7c9f58a701 100644 --- a/src/Core/Datatypes/ColorMap.cc +++ b/src/Core/Datatypes/ColorMap.cc @@ -199,21 +199,23 @@ ColorRGB ColorMap::getColorMapVal(double v) const //return colorWithoutAlpha; } -ColorRGB ColorMap::applyAlpha(double transformed, ColorRGB colorWithoutAlpha) +ColorRGB ColorMap::applyAlpha(double transformed, ColorRGB colorWithoutAlpha) const { double a = alpha(transformed); return ColorRGB(colorWithoutAlpha.r(), colorWithoutAlpha.g(), colorWithoutAlpha.b(), a); } -double ColorMap::alpha(double transformedValue) +double ColorMap::alpha(double transformedValue) const { + transformedValue *= 364.0; std::cout << transformedValue << "\n"; + if(alphaLookup_.size() == 0) return 0.5; int i; - for(i = 0; (i < alphaLookup_.size()) && (transformedValue < alphaLookup_[i]); i += 2); + for(i = 0; (i < alphaLookup_.size()) && (alphaLookup_[i] < transformedValue); i += 2); double startx = 0.0; double starty = 40.0; - double endx = 360.0; + double endx = 364.0; double endy = 40.0; if(i == 0) @@ -223,16 +225,22 @@ double ColorMap::alpha(double transformedValue) } else if(i == alphaLookup_.size()) { - startx = alphaLookup_[i]; + startx = alphaLookup_[i - 2]; starty = alphaLookup_[i - 1]; } else { + std::cout << "normal\n"; startx = alphaLookup_[i - 2]; starty = alphaLookup_[i - 1]; endx = alphaLookup_[i + 0]; endy = alphaLookup_[i + 1]; } + + double interp = (transformedValue - startx) / (endx - startx); + double value = ((1.0f - interp) * starty + (interp) * endy) / 80.0; + std::cout << startx << " : " << endx << " : " << interp << "\n"; + return value; } diff --git a/src/Core/Datatypes/ColorMap.h b/src/Core/Datatypes/ColorMap.h index e7792180bc..813a45a7fe 100644 --- a/src/Core/Datatypes/ColorMap.h +++ b/src/Core/Datatypes/ColorMap.h @@ -63,6 +63,7 @@ namespace Datatypes { bool getColorMapInvert() const; double getColorMapRescaleScale() const; double getColorMapRescaleShift() const; + std::vector getAlphaLookup() const {return alphaLookup_;} ColorRGB valueToColor(double scalar) const; ColorRGB valueToColor(Core::Geometry::Tensor &tensor) const; @@ -74,8 +75,8 @@ namespace Datatypes { ///<< Internal functions. Core::Datatypes::ColorRGB getColorMapVal(double v) const; double getTransformedValue(double v) const; - ColorRGB applyAlpha(double transformed, ColorRGB colorWithoutAlpha); - double alpha(double transformedValue); + ColorRGB applyAlpha(double transformed, ColorRGB colorWithoutAlpha) const; + double alpha(double transformedValue) const; ColorMapStrategyHandle color_; ///<< The colormap's name. diff --git a/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.fs b/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.fs index 4dd5784392..d2f90c3d28 100644 --- a/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.fs +++ b/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.fs @@ -119,7 +119,7 @@ void main() else colorMapValue = texture2D(uTX0, vec2(vTexCoords.x, 0.0)); vec3 diffuseColor = colorMapValue.rgb; - float transparency = uTransparency; + float transparency = colorMapValue.a; gl_FragColor = vec4(diffuseColor, transparency); diff --git a/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs b/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs index 14895656d6..079f4dbfea 100644 --- a/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs +++ b/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs @@ -143,7 +143,7 @@ void main() vec3 diffuseColor = colorMapValue.rgb; vec3 specularColor = uSpecularColor.rgb; vec3 ambientColor = uAmbientColor.rgb; - float transparency = uTransparency; + float transparency = colorMapValue.a; vec3 normal = normalize(vNormal); if (gl_FrontFacing) normal = -normal; diff --git a/src/Modules/Visualization/CreateStandardColorMap.cc b/src/Modules/Visualization/CreateStandardColorMap.cc index e8dcc21ae4..088a2f4457 100644 --- a/src/Modules/Visualization/CreateStandardColorMap.cc +++ b/src/Modules/Visualization/CreateStandardColorMap.cc @@ -77,7 +77,7 @@ void CreateStandardColorMap::execute() //just in case there is a problem with the QT values... res = std::min(std::max(res,2),256); shift = std::min(std::max(shift,-1.),1.); - sendOutput(ColorMapObject, StandardColorMapFactory::create(name, res, shift, inv)); + sendOutput(ColorMapObject, StandardColorMapFactory::create(name, res, shift, inv, 0.5, 1.0, points)); } } diff --git a/src/Modules/Visualization/ShowField.cc b/src/Modules/Visualization/ShowField.cc index 89a5ae7238..3f17924681 100644 --- a/src/Modules/Visualization/ShowField.cc +++ b/src/Modules/Visualization/ShowField.cc @@ -481,7 +481,7 @@ namespace textureMap = StandardColorMapFactory::create(realColorMap->getColorMapName(), realColorMap->getColorMapResolution(), realColorMap->getColorMapShift(), - realColorMap->getColorMapInvert()); + realColorMap->getColorMapInvert(), 0.5, 1.0, realColorMap->getAlphaLookup()); coordinateMap = StandardColorMapFactory::create("Grayscale", 256, 0, false, realColorMap->getColorMapRescaleScale(), realColorMap->getColorMapRescaleShift()); From b741bab87028954cc694942db788beb2234b380f Mon Sep 17 00:00:00 2001 From: Haydelj Date: Thu, 19 Sep 2019 11:45:37 -0600 Subject: [PATCH 03/13] finished implmenting colormap transparency in showfield and cleaned up showFieldGlyphs a bit --- src/Modules/Visualization/ShowField.cc | 11 +- src/Modules/Visualization/ShowFieldGlyphs.cc | 657 +++++++++---------- 2 files changed, 329 insertions(+), 339 deletions(-) diff --git a/src/Modules/Visualization/ShowField.cc b/src/Modules/Visualization/ShowField.cc index 3f17924681..4b9e183cb6 100644 --- a/src/Modules/Visualization/ShowField.cc +++ b/src/Modules/Visualization/ShowField.cc @@ -844,6 +844,9 @@ void GeometryBuilder::renderNodes( ColorScheme colorScheme; ColorRGB node_color; + ColorMapHandle textureMap, coordinateMap; + spiltColorMapToTextureAndCoordinates(colorMap, textureMap, coordinateMap); + if (fld->basis_order() < 0 || (fld->basis_order() == 0 && mesh->dimensionality() != 0) || state.get(RenderState::USE_DEFAULT_COLOR_NODES)) colorScheme = ColorScheme::COLOR_UNIFORM; else if (state.get(RenderState::USE_COLORMAP_ON_NODES)) @@ -887,17 +890,17 @@ void GeometryBuilder::renderNodes( if (fld->is_scalar()) { fld->get_value(sval, *eiter); - node_color = map->valueToColor(sval); + node_color = coordinateMap->valueToColor(sval); } else if (fld->is_vector()) { fld->get_value(vval, *eiter); - node_color = map->valueToColor(vval); + node_color = coordinateMap->valueToColor(vval); } else if (fld->is_tensor()) { fld->get_value(tval, *eiter); - node_color = map->valueToColor(tval); + node_color = coordinateMap->valueToColor(tval); } } //accumulate VBO or IBO data @@ -914,7 +917,7 @@ void GeometryBuilder::renderNodes( } glyphs.buildObject(*geom, uniqueNodeID, state.get(RenderState::USE_TRANSPARENT_NODES), nodeTransparencyValue_, - colorScheme, state, primIn, mesh->get_bounding_box()); + colorScheme, state, primIn, mesh->get_bounding_box(), true, textureMap); } diff --git a/src/Modules/Visualization/ShowFieldGlyphs.cc b/src/Modules/Visualization/ShowFieldGlyphs.cc index f2a8746992..c7e4161d68 100644 --- a/src/Modules/Visualization/ShowFieldGlyphs.cc +++ b/src/Modules/Visualization/ShowFieldGlyphs.cc @@ -146,17 +146,17 @@ enum SecondaryVectorParameterScalingTypeEnum ColorScheme GlyphBuilder::getColoringType(const RenderState& renState, VField* fld) { if(fld->basis_order() < 0 || renState.get(RenderState::USE_DEFAULT_COLOR)) - { - return ColorScheme::COLOR_UNIFORM; - } + { + return ColorScheme::COLOR_UNIFORM; + } else if(renState.get(RenderState::USE_COLORMAP)) - { - return ColorScheme::COLOR_MAP; - } + { + return ColorScheme::COLOR_MAP; + } else - { - return ColorScheme::COLOR_IN_SITU; - } + { + return ColorScheme::COLOR_IN_SITU; + } } void GlyphBuilder::addGlyph( @@ -326,35 +326,35 @@ void ShowFieldGlyphs::configureInputs( { FieldInformation sfinfo(*sfield); if (!sfinfo.is_svt()) - { - THROW_ALGORITHM_INPUT_ERROR("No Scalar, Vector, or Tensor data found in the secondary data field."); - } + { + THROW_ALGORITHM_INPUT_ERROR("No Scalar, Vector, or Tensor data found in the secondary data field."); + } } if (tfield) { FieldInformation tfinfo(*tfield); if (!tfinfo.is_svt()) - { - THROW_ALGORITHM_INPUT_ERROR("No Scalar, Vector, or Tensor data found in the tertiary data field."); - } + { + THROW_ALGORITHM_INPUT_ERROR("No Scalar, Vector, or Tensor data found in the tertiary data field."); + } } } RenderState::InputPort GlyphBuilder::getInput(std::string&& port_name) { if(port_name == "Primary") - { - return RenderState::PRIMARY_PORT; - } + { + return RenderState::PRIMARY_PORT; + } else if(port_name == "Secondary") - { - return RenderState::SECONDARY_PORT; - } + { + return RenderState::SECONDARY_PORT; + } else - { - return RenderState::TERTIARY_PORT; - } + { + return RenderState::TERTIARY_PORT; + } } GeometryHandle GlyphBuilder::buildGeometryObject( @@ -386,9 +386,8 @@ GeometryHandle GlyphBuilder::buildGeometryObject( // Creates id std::string idname = "EntireGlyphField"; - if(!state->getValue(ShowFieldGlyphs::FieldName).toString().empty()){ + if(!state->getValue(ShowFieldGlyphs::FieldName).toString().empty()) idname += GeometryObject::delimiter + state->getValue(ShowFieldGlyphs::FieldName).toString() + " (from " + moduleId_ +")"; - } auto geom(boost::make_shared(idgen, idname, true)); @@ -400,52 +399,49 @@ GeometryHandle GlyphBuilder::buildGeometryObject( state->setValue(ShowFieldGlyphs::ShowTensors, showTensors); // Don't render if no data given - if(!(showScalars || showVectors || showTensors)) - { - return geom; - } + if(!(showScalars || showVectors || showTensors)) return geom; // Get render state RenderState renState; if(showScalars) - { - renState = getScalarsRenderState(state); - } + { + renState = getScalarsRenderState(state); + } else if(showVectors) - { - renState = getVectorsRenderState(state); - } + { + renState = getVectorsRenderState(state); + } else if(showTensors) - { - renState = getTensorsRenderState(state); - } + { + renState = getTensorsRenderState(state); + } // Create port handler and check for errors ShowFieldGlyphsPortHandler portHandler(module, state, renState, pfield, sfield, tfield, pcolormap, scolormap, tcolormap); try - { - portHandler.checkForErrors(); - } catch(const std::invalid_argument& e) - { - // If error is given, post it and return empty geom object - module->error(e.what()); - return geom; - } + { + portHandler.checkForErrors(); + } catch(const std::invalid_argument& e) + { + // If error is given, post it and return empty geom object + module->error(e.what()); + return geom; + } // Render glyphs if (finfo.is_scalar() && showScalars) - { - renderScalars(portHandler, state, interruptible, renState, geom, geom->uniqueID()); - } + { + renderScalars(portHandler, state, interruptible, renState, geom, geom->uniqueID()); + } else if (finfo.is_vector() && showVectors) - { - renderVectors(portHandler, state, interruptible, renState, geom, geom->uniqueID()); - } + { + renderVectors(portHandler, state, interruptible, renState, geom, geom->uniqueID()); + } else if (finfo.is_tensor() && showTensors) - { - renderTensors(portHandler, state, interruptible, renState, geom, geom->uniqueID(), module); - } + { + renderTensors(portHandler, state, interruptible, renState, geom, geom->uniqueID(), module); + } return geom; } @@ -501,89 +497,88 @@ void GlyphBuilder::renderVectors( GlyphGeom glyphs; switch(fieldLocation) { - case 0: //linear data falls through to node data handling routine - case 1: //node centered constant data - for (const auto& node : portHandler.getPrimaryFacade()->nodes()) + case 0: //linear data falls through to node data handling routine + case 1: //node centered constant data + for (const auto& node : portHandler.getPrimaryFacade()->nodes()) { indices.push_back(node.index()); Point p; mesh->get_center(p, node.index()); points.push_back(p); } - break; - case 2: //edge centered constant data - for (const auto& edge : portHandler.getPrimaryFacade()->edges()) + break; + case 2: //edge centered constant data + for (const auto& edge : portHandler.getPrimaryFacade()->edges()) { indices.push_back(edge.index()); Point p; mesh->get_center(p, edge.index()); points.push_back(p); } - break; - case 3: //face centered constant data - for (const auto& face : portHandler.getPrimaryFacade()->faces()) + break; + case 3: //face centered constant data + for (const auto& face : portHandler.getPrimaryFacade()->faces()) { indices.push_back(face.index()); Point p; mesh->get_center(p, face.index()); points.push_back(p); } - break; - case 4: //cell centered constant data - for (const auto& cell : portHandler.getPrimaryFacade()->cells()) + break; + case 4: //cell centered constant data + for (const auto& cell : portHandler.getPrimaryFacade()->cells()) { indices.push_back(cell.index()); Point p; mesh->get_center(p, cell.index()); points.push_back(p); } - break; + break; } // Render every item from facade for(int i = 0; i < indices.size(); i++) - { - interruptible->checkForInterruption(); - Vector v, pinputVector; Point p2, p3; double radius; + { + interruptible->checkForInterruption(); + Vector v, pinputVector; Point p2, p3; double radius; - pinputVector = portHandler.getPrimaryVector(indices[i]); + pinputVector = portHandler.getPrimaryVector(indices[i]); // Normalize/Scale - Vector dir = pinputVector; - if(normalizeGlyphs) - dir.normalize(); - // v = pinputVector.normal() * scale; - // else - // v = pinputVector * scale; - - // Calculate points - // p2 = points[i] + v; - // p3 = points[i] - v; - - // Get radius - // radius = scale * radiusWidthScale / 2.0; - radius = radiusWidthScale / 2.0; - if(state->getValue(ShowFieldGlyphs::SecondaryVectorParameterScalingType).toInt() == SecondaryVectorParameterScalingTypeEnum::USE_INPUT) - radius *= portHandler.getSecondaryVectorParameter(indices[i]); - - ColorRGB node_color = portHandler.getNodeColor(indices[i]); - - if(renderGlphysBelowThreshold || pinputVector.length() >= threshold) - { - // No need to render cylinder base if arrow is bidirectional - bool render_cylinder_base = renderBases && !renderBidirectionaly; - - addGlyph(glyphs, renState.mGlyphType, points[i], dir, radius, scale, arrowHeadRatio, - resolution, node_color, useLines, render_cylinder_base, renderBases); - - if(renderBidirectionaly) - { - Vector neg_dir = -dir; - addGlyph(glyphs, renState.mGlyphType, points[i], neg_dir, radius, scale, arrowHeadRatio, - resolution, node_color, useLines, render_cylinder_base, renderBases); - } - } + Vector dir = pinputVector; + if(normalizeGlyphs) + dir.normalize(); + // v = pinputVector.normal() * scale; + // else + // v = pinputVector * scale; + + // Calculate points + // p2 = points[i] + v; + // p3 = points[i] - v; + + // Get radius + // radius = scale * radiusWidthScale / 2.0; + radius = radiusWidthScale / 2.0; + if(state->getValue(ShowFieldGlyphs::SecondaryVectorParameterScalingType).toInt() == SecondaryVectorParameterScalingTypeEnum::USE_INPUT) + radius *= portHandler.getSecondaryVectorParameter(indices[i]); + + ColorRGB node_color = portHandler.getNodeColor(indices[i]); + + if(renderGlphysBelowThreshold || pinputVector.length() >= threshold) + { + // No need to render cylinder base if arrow is bidirectional + bool render_cylinder_base = renderBases && !renderBidirectionaly; + addGlyph(glyphs, renState.mGlyphType, points[i], dir, radius, scale, arrowHeadRatio, + resolution, node_color, useLines, render_cylinder_base, renderBases); + + if(renderBidirectionaly) + { + Vector neg_dir = -dir; + addGlyph(glyphs, renState.mGlyphType, points[i], neg_dir, radius, scale, arrowHeadRatio, + resolution, node_color, useLines, render_cylinder_base, renderBases); + } } + } std::stringstream ss; ss << renState.mGlyphType << resolution << scale << static_cast(colorScheme); @@ -628,58 +623,58 @@ void GlyphBuilder::renderScalars( std::vector points; GlyphGeom glyphs; if (!portHandler.getPrimaryFieldInfo().is_linear()) + { + for (const auto& node : portHandler.getPrimaryFacade()->nodes()) { - for (const auto& node : portHandler.getPrimaryFacade()->nodes()) - { - indices.push_back(node.index()); - Point p; - mesh->get_center(p, node.index()); - points.push_back(p); - } + indices.push_back(node.index()); + Point p; + mesh->get_center(p, node.index()); + points.push_back(p); } + } if (!done) + { + for (const auto& cell : portHandler.getPrimaryFacade()->cells()) { - for (const auto& cell : portHandler.getPrimaryFacade()->cells()) - { - indices.push_back(cell.index()); - Point p; - mesh->get_center(p, cell.index()); - points.push_back(p); - } + indices.push_back(cell.index()); + Point p; + mesh->get_center(p, cell.index()); + points.push_back(p); } + } // Render every item from facade for(int i = 0; i < indices.size(); i++) - { - interruptible->checkForInterruption(); + { + interruptible->checkForInterruption(); - double v = portHandler.getPrimaryScalar(indices[i]); - ColorRGB node_color = portHandler.getNodeColor(indices[i]); - double radius = std::abs(v) * scale; + double v = portHandler.getPrimaryScalar(indices[i]); + ColorRGB node_color = portHandler.getNodeColor(indices[i]); + double radius = std::abs(v) * scale; - switch (renState.mGlyphType) - { - case RenderState::GlyphType::POINT_GLYPH: + switch (renState.mGlyphType) + { + case RenderState::GlyphType::POINT_GLYPH: + glyphs.addPoint(points[i], node_color); + break; + case RenderState::GlyphType::SPHERE_GLYPH: + glyphs.addSphere(points[i], radius, resolution, node_color); + break; + case RenderState::GlyphType::BOX_GLYPH: + BOOST_THROW_EXCEPTION(AlgorithmInputException() << ErrorMessage("Box Geom is not supported yet.")); + break; + case RenderState::GlyphType::AXIS_GLYPH: + BOOST_THROW_EXCEPTION(AlgorithmInputException() << ErrorMessage("Axis Geom is not supported yet.")); + break; + default: + if (usePoints) glyphs.addPoint(points[i], node_color); - break; - case RenderState::GlyphType::SPHERE_GLYPH: + else glyphs.addSphere(points[i], radius, resolution, node_color); - break; - case RenderState::GlyphType::BOX_GLYPH: - BOOST_THROW_EXCEPTION(AlgorithmInputException() << ErrorMessage("Box Geom is not supported yet.")); - break; - case RenderState::GlyphType::AXIS_GLYPH: - BOOST_THROW_EXCEPTION(AlgorithmInputException() << ErrorMessage("Axis Geom is not supported yet.")); - break; - default: - if (usePoints) - glyphs.addPoint(points[i], node_color); - else - glyphs.addSphere(points[i], radius, resolution, node_color); - break; - } - done = true; - } + break; + } + done = true; + } std::stringstream ss; ss << renState.mGlyphType << resolution << scale << static_cast(colorScheme); @@ -710,185 +705,181 @@ void GlyphBuilder::renderTensors( { FieldInformation pfinfo = portHandler.getPrimaryFieldInfo(); - VMesh* mesh = portHandler.getMesh(); - mesh->synchronize(Mesh::NODES_E); - - // Gets user set data - ColorScheme colorScheme = portHandler.getColorScheme(); - double scale = state->getValue(ShowFieldGlyphs::TensorsScale).toDouble(); - int resolution = state->getValue(ShowFieldGlyphs::TensorsResolution).toInt(); - bool normalizeGlyphs = state->getValue(ShowFieldGlyphs::NormalizeTensors).toBool(); - bool renderGlyphsBelowThreshold = state->getValue(ShowFieldGlyphs::RenderTensorsBelowThreshold).toBool(); - float threshold = state->getValue(ShowFieldGlyphs::TensorsThreshold).toDouble(); - if (resolution < 3) resolution = 5; - - std::stringstream ss; - ss << renState.mGlyphType << resolution << scale << static_cast(colorScheme); - - // Separate id's are needed for lines and points if rendered - std::string uniqueNodeID = id + "tensor_glyphs" + ss.str(); - std::string uniqueLineID = id + "tensor_line_glyphs" + ss.str(); - std::string uniquePointID = id + "tensor_point_glyphs" + ss.str(); - - SpireIBO::PRIMITIVE primIn = SpireIBO::PRIMITIVE::TRIANGLES; - - GlyphGeom tensor_line_glyphs; - GlyphGeom point_glyphs; - - //sets feild location for consant feild data 1: node centered 2: edge centered 3: face centered 4: cell centered - int fieldLocation = pfinfo.is_point() * 1 + pfinfo.is_line() * 2 + - pfinfo.is_surface() * 3 + pfinfo.is_volume() * 4; - //sets feild location to 0 for linear data regardless of location - fieldLocation *= !pfinfo.is_linear(); - - // Collect indices and points from facades - std::vector indices; - std::vector points; - GlyphGeom glyphs; - switch(fieldLocation) + VMesh* mesh = portHandler.getMesh(); + mesh->synchronize(Mesh::NODES_E); + + // Gets user set data + ColorScheme colorScheme = portHandler.getColorScheme(); + double scale = state->getValue(ShowFieldGlyphs::TensorsScale).toDouble(); + int resolution = state->getValue(ShowFieldGlyphs::TensorsResolution).toInt(); + bool normalizeGlyphs = state->getValue(ShowFieldGlyphs::NormalizeTensors).toBool(); + bool renderGlyphsBelowThreshold = state->getValue(ShowFieldGlyphs::RenderTensorsBelowThreshold).toBool(); + float threshold = state->getValue(ShowFieldGlyphs::TensorsThreshold).toDouble(); + if (resolution < 3) resolution = 5; + + std::stringstream ss; + ss << renState.mGlyphType << resolution << scale << static_cast(colorScheme); + + // Separate id's are needed for lines and points if rendered + std::string uniqueNodeID = id + "tensor_glyphs" + ss.str(); + std::string uniqueLineID = id + "tensor_line_glyphs" + ss.str(); + std::string uniquePointID = id + "tensor_point_glyphs" + ss.str(); + + SpireIBO::PRIMITIVE primIn = SpireIBO::PRIMITIVE::TRIANGLES; + + GlyphGeom tensor_line_glyphs; + GlyphGeom point_glyphs; + + //sets feild location for consant feild data 1: node centered 2: edge centered 3: face centered 4: cell centered + int fieldLocation = pfinfo.is_point() * 1 + pfinfo.is_line() * 2 + + pfinfo.is_surface() * 3 + pfinfo.is_volume() * 4; + //sets feild location to 0 for linear data regardless of location + fieldLocation *= !pfinfo.is_linear(); + + // Collect indices and points from facades + std::vector indices; + std::vector points; + GlyphGeom glyphs; + switch(fieldLocation) + { + case 0: //linear data falls through to node data handling routine + case 1: //node centered constant data + for (const auto& node : portHandler.getPrimaryFacade()->nodes()) { - case 0: //linear data falls through to node data handling routine - case 1: //node centered constant data - for (const auto& node : portHandler.getPrimaryFacade()->nodes()) - { - indices.push_back(node.index()); - Point p; - mesh->get_center(p, node.index()); - points.push_back(p); - } - break; - case 2: //edge centered constant data - for (const auto& edge : portHandler.getPrimaryFacade()->edges()) - { - indices.push_back(edge.index()); - Point p; - mesh->get_center(p, edge.index()); - points.push_back(p); - } - break; - case 3: //face centered constant data - for (const auto& face : portHandler.getPrimaryFacade()->faces()) - { - indices.push_back(face.index()); - Point p; - mesh->get_center(p, face.index()); - points.push_back(p); - } - break; - case 4: //cell centered constant data - for (const auto& cell : portHandler.getPrimaryFacade()->cells()) - { - indices.push_back(cell.index()); - Point p; - mesh->get_center(p, cell.index()); - points.push_back(p); - } - break; + indices.push_back(node.index()); + Point p; + mesh->get_center(p, node.index()); + points.push_back(p); } + break; + case 2: //edge centered constant data + for (const auto& edge : portHandler.getPrimaryFacade()->edges()) + { + indices.push_back(edge.index()); + Point p; + mesh->get_center(p, edge.index()); + points.push_back(p); + } + break; + case 3: //face centered constant data + for (const auto& face : portHandler.getPrimaryFacade()->faces()) + { + indices.push_back(face.index()); + Point p; + mesh->get_center(p, face.index()); + points.push_back(p); + } + break; + case 4: //cell centered constant data + for (const auto& cell : portHandler.getPrimaryFacade()->cells()) + { + indices.push_back(cell.index()); + Point p; + mesh->get_center(p, cell.index()); + points.push_back(p); + } + break; + } - int neg_eigval_count = 0; - int tensorcount = 0; - static const double vectorThreshold = 0.001; - static const double pointThreshold = 0.01; - static const double epsilon = pow(2, -52); + int neg_eigval_count = 0; + int tensorcount = 0; + static const double vectorThreshold = 0.001; + static const double pointThreshold = 0.01; + static const double epsilon = pow(2, -52); - // Render every item from facade - for(int i = 0; i < indices.size(); i++) - { - interruptible->checkForInterruption(); + // Render every item from facade + for(int i = 0; i < indices.size(); i++) + { + interruptible->checkForInterruption(); - Tensor t = portHandler.getPrimaryTensor(indices[i]); + Tensor t = portHandler.getPrimaryTensor(indices[i]); - double eigen1, eigen2, eigen3; - t.get_eigenvalues(eigen1, eigen2, eigen3); - Vector eigvals(fabs(eigen1), fabs(eigen2), fabs(eigen3)); + double eigen1, eigen2, eigen3; + t.get_eigenvalues(eigen1, eigen2, eigen3); + Vector eigvals(fabs(eigen1), fabs(eigen2), fabs(eigen3)); - // Counter for negative eigen values - if(eigen1 < -epsilon || eigen2 < -epsilon || eigen3 < -epsilon) - neg_eigval_count++; + // Counter for negative eigen values + if(eigen1 < -epsilon || eigen2 < -epsilon || eigen3 < -epsilon) ++neg_eigval_count; - Vector eigvec1, eigvec2, eigvec3; - t.get_eigenvectors(eigvec1, eigvec2, eigvec3); + Vector eigvec1, eigvec2, eigvec3; + t.get_eigenvectors(eigvec1, eigvec2, eigvec3); - // Checks to see if eigenvalues are below defined threshold - bool vector_eig_x_0 = eigvals.x() <= vectorThreshold; - bool vector_eig_y_0 = eigvals.y() <= vectorThreshold; - bool vector_eig_z_0 = eigvals.z() <= vectorThreshold; - bool point_eig_x_0 = eigvals.x() <= pointThreshold; - bool point_eig_y_0 = eigvals.y() <= pointThreshold; - bool point_eig_z_0 = eigvals.z() <= pointThreshold; + // Checks to see if eigenvalues are below defined threshold + bool vector_eig_x_0 = eigvals.x() <= vectorThreshold; + bool vector_eig_y_0 = eigvals.y() <= vectorThreshold; + bool vector_eig_z_0 = eigvals.z() <= vectorThreshold; + bool point_eig_x_0 = eigvals.x() <= pointThreshold; + bool point_eig_y_0 = eigvals.y() <= pointThreshold; + bool point_eig_z_0 = eigvals.z() <= pointThreshold; - bool order0Tensor = (point_eig_x_0 && point_eig_y_0 && point_eig_z_0); - bool order1Tensor = (vector_eig_x_0 + vector_eig_y_0 + vector_eig_z_0) >= 2; + bool order0Tensor = (point_eig_x_0 && point_eig_y_0 && point_eig_z_0); + bool order1Tensor = (vector_eig_x_0 + vector_eig_y_0 + vector_eig_z_0) >= 2; - ColorRGB node_color = portHandler.getNodeColor(indices[i]); + ColorRGB node_color = portHandler.getNodeColor(indices[i]); - // Do not render tensors that are too small - because surfaces - // are not renderd at least two of the scales must be non zero. - if(!renderGlyphsBelowThreshold){ - if(t.magnitude() < threshold) - continue; - } + // Do not render tensors that are too small - because surfaces + // are not renderd at least two of the scales must be non zero. + if(!renderGlyphsBelowThreshold && t.magnitude() < threshold) continue; - if(order0Tensor) - { - point_glyphs.addPoint(points[i], node_color); - } - else if(order1Tensor) - { - Vector dir; - if(vector_eig_x_0 && vector_eig_y_0) - dir = eigvec3 * eigvals[2]; - else if(vector_eig_y_0 && vector_eig_z_0) - dir = eigvec1 * eigvals[0]; - else if(vector_eig_x_0 && vector_eig_z_0) - dir = eigvec2 * eigvals[1]; - // Point p1 = points[i]; - // Point p2 = points[i] + dir; - addGlyph(tensor_line_glyphs, RenderState::GlyphType::LINE_GLYPH, points[i], dir, scale, scale, scale, resolution, node_color, true); - } - // Render as order 2 or 3 tensor - else + if(order0Tensor) + { + point_glyphs.addPoint(points[i], node_color); + } + else if(order1Tensor) + { + Vector dir; + if(vector_eig_x_0 && vector_eig_y_0) + dir = eigvec3 * eigvals[2]; + else if(vector_eig_y_0 && vector_eig_z_0) + dir = eigvec1 * eigvals[0]; + else if(vector_eig_x_0 && vector_eig_z_0) + dir = eigvec2 * eigvals[1]; + // Point p1 = points[i]; + // Point p2 = points[i] + dir; + addGlyph(tensor_line_glyphs, RenderState::GlyphType::LINE_GLYPH, points[i], dir, scale, scale, scale, resolution, node_color, true); + } + // Render as order 2 or 3 tensor + else + { + switch (renState.mGlyphType) + { + case RenderState::GlyphType::BOX_GLYPH: + glyphs.addBox(points[i], t, scale, node_color, normalizeGlyphs); + break; + case RenderState::GlyphType::ELLIPSOID_GLYPH: + glyphs.addEllipsoid(points[i], t, scale, resolution, node_color, normalizeGlyphs); + break; + case RenderState::GlyphType::SUPERELLIPSOID_GLYPH: { - switch (renState.mGlyphType) - { - case RenderState::GlyphType::BOX_GLYPH: - glyphs.addBox(points[i], t, scale, node_color, normalizeGlyphs); - break; - case RenderState::GlyphType::ELLIPSOID_GLYPH: + double emphasis = state->getValue(ShowFieldGlyphs::SuperquadricEmphasis).toDouble(); + if(emphasis > 0.0) + glyphs.addSuperEllipsoid(points[i], t, scale, resolution, node_color, normalizeGlyphs, emphasis); + else glyphs.addEllipsoid(points[i], t, scale, resolution, node_color, normalizeGlyphs); - break; - case RenderState::GlyphType::SUPERELLIPSOID_GLYPH: - { - double emphasis = state->getValue(ShowFieldGlyphs::SuperquadricEmphasis).toDouble(); - if(emphasis > 0.0) - glyphs.addSuperEllipsoid(points[i], t, scale, resolution, node_color, normalizeGlyphs, emphasis); - else - glyphs.addEllipsoid(points[i], t, scale, resolution, node_color, normalizeGlyphs); - } - default: - break; - } - tensorcount++; } - } - - // Prints warning if there are negative eigen values - if(neg_eigval_count > 0) { - module_->warning(std::to_string(neg_eigval_count) + " negative eigen values in data."); + default: + break; + } + tensorcount++; } + } + + // Prints warning if there are negative eigen values + if(neg_eigval_count > 0) { + module_->warning(std::to_string(neg_eigval_count) + " negative eigen values in data."); + } - glyphs.buildObject(*geom, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY), - state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), colorScheme, renState, primIn, mesh->get_bounding_box()); - - // Render lines(2 eigenvalues equalling 0) - RenderState lineRenState = getVectorsRenderState(state); - tensor_line_glyphs.buildObject(*geom, uniqueLineID, lineRenState.get(RenderState::USE_TRANSPARENT_EDGES), - state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), colorScheme, lineRenState, SpireIBO::PRIMITIVE::LINES, mesh->get_bounding_box()); - // Render scalars(3 eigenvalues equalling 0) - RenderState pointRenState = getScalarsRenderState(state); - point_glyphs.buildObject(*geom, uniquePointID, pointRenState.get(RenderState::USE_TRANSPARENT_NODES), - state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), colorScheme, pointRenState, SpireIBO::PRIMITIVE::POINTS, mesh->get_bounding_box()); + glyphs.buildObject(*geom, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY), + state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), colorScheme, renState, primIn, mesh->get_bounding_box()); + + // Render lines(2 eigenvalues equalling 0) + RenderState lineRenState = getVectorsRenderState(state); + tensor_line_glyphs.buildObject(*geom, uniqueLineID, lineRenState.get(RenderState::USE_TRANSPARENT_EDGES), + state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), colorScheme, lineRenState, SpireIBO::PRIMITIVE::LINES, mesh->get_bounding_box()); + // Render scalars(3 eigenvalues equalling 0) + RenderState pointRenState = getScalarsRenderState(state); + point_glyphs.buildObject(*geom, uniquePointID, pointRenState.get(RenderState::USE_TRANSPARENT_NODES), + state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), colorScheme, pointRenState, SpireIBO::PRIMITIVE::POINTS, mesh->get_bounding_box()); } void ShowFieldGlyphs::setSuperquadricEmphasis(int emphasis) @@ -965,18 +956,18 @@ RenderState GlyphBuilder::getScalarsRenderState(ModuleStateHandle state) // Transparency int transparency = state->getValue(ShowFieldGlyphs::ScalarsTransparency).toInt(); if(transparency == 0) - { - renState.set(RenderState::USE_TRANSPARENT_NODES, false); - } + { + renState.set(RenderState::USE_TRANSPARENT_NODES, false); + } //TODO add input option else if(transparency == 1) - { - renState.set(RenderState::USE_TRANSPARENT_NODES, true); - } + { + renState.set(RenderState::USE_TRANSPARENT_NODES, true); + } else - { - renState.set(RenderState::USE_TRANSPARENT_NODES, true); - } + { + renState.set(RenderState::USE_TRANSPARENT_NODES, true); + } //renState.mTransparencyInput = getInput(state->getValue(ShowFieldGlyphs::ScalarsTransparencyDataInput).toString()); //renState.mTransparencyInput = state->getValue(ShowFieldGlyphs::ScalarsTransparenycDataInput).toString(); @@ -1034,18 +1025,18 @@ RenderState GlyphBuilder::getTensorsRenderState(ModuleStateHandle state) // Transparency int transparency = state->getValue(ShowFieldGlyphs::TensorsTransparency).toInt(); if(transparency == 0) - { - renState.set(RenderState::USE_TRANSPARENCY, false); - } + { + renState.set(RenderState::USE_TRANSPARENCY, false); + } //TODO add input option else if(transparency == 1) - { - renState.set(RenderState::USE_TRANSPARENCY, true); - } + { + renState.set(RenderState::USE_TRANSPARENCY, true); + } else - { - renState.set(RenderState::USE_TRANSPARENCY, true); - } + { + renState.set(RenderState::USE_TRANSPARENCY, true); + } // Glpyh Type std::string glyph = state->getValue(ShowFieldGlyphs::TensorsDisplayType).toString(); @@ -1061,14 +1052,10 @@ RenderState GlyphBuilder::getTensorsRenderState(ModuleStateHandle state) renState.mGlyphType = RenderState::GlyphType::BOX_GLYPH; renState.defaultColor = ColorRGB(state->getValue(ShowFieldGlyphs::DefaultMeshColor).toString()); - renState.defaultColor = (renState.defaultColor.r() > 1.0 || - renState.defaultColor.g() > 1.0 || - renState.defaultColor.b() > 1.0) ? - ColorRGB( - renState.defaultColor.r() / 255., - renState.defaultColor.g() / 255., - renState.defaultColor.b() / 255.) - : renState.defaultColor; + renState.defaultColor = + (renState.defaultColor.r() > 1.0 || renState.defaultColor.g() > 1.0 || renState.defaultColor.b() > 1.0) ? + ColorRGB( renState.defaultColor.r() / 255., renState.defaultColor.g() / 255., renState.defaultColor.b() / 255.) : + renState.defaultColor; // Coloring std::string color = state->getValue(ShowFieldGlyphs::TensorsColoring).toString(); @@ -1085,7 +1072,7 @@ RenderState GlyphBuilder::getTensorsRenderState(ModuleStateHandle state) renState.set(RenderState::USE_DEFAULT_COLOR, true); } renState.mColorInput = getInput(state->getValue(ShowFieldGlyphs::TensorsColoringDataInput).toString()); - // renState.mColorInput = state->getValue(ShowFieldGlyphs::TensorsColorDataInput).toString(); + //renState.mColorInput = state->getValue(ShowFieldGlyphs::TensorsColorDataInput).toString(); return renState; } From 09ce7e3dd2011bce2a124f60b84386ff0c134b59 Mon Sep 17 00:00:00 2001 From: Haydelj Date: Thu, 19 Sep 2019 11:52:54 -0600 Subject: [PATCH 04/13] cleaned up print staments --- src/Core/Datatypes/ColorMap.cc | 5 +---- src/Modules/Visualization/CreateStandardColorMap.cc | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Core/Datatypes/ColorMap.cc b/src/Core/Datatypes/ColorMap.cc index 7c9f58a701..db817ef9f7 100644 --- a/src/Core/Datatypes/ColorMap.cc +++ b/src/Core/Datatypes/ColorMap.cc @@ -154,7 +154,7 @@ double ColorMap::getTransformedValue(double f) const static bool x = true; if (x) { - std::cout << "";// this;// << " " << name_ << " " << resolution_ << " " << shift_ << " " << invert_ << std::endl; + std::cout << ""; x = false; } ///////////////////////////////////////////////// @@ -208,7 +208,6 @@ ColorRGB ColorMap::applyAlpha(double transformed, ColorRGB colorWithoutAlpha) co double ColorMap::alpha(double transformedValue) const { transformedValue *= 364.0; - std::cout << transformedValue << "\n"; if(alphaLookup_.size() == 0) return 0.5; int i; for(i = 0; (i < alphaLookup_.size()) && (alphaLookup_[i] < transformedValue); i += 2); @@ -230,7 +229,6 @@ double ColorMap::alpha(double transformedValue) const } else { - std::cout << "normal\n"; startx = alphaLookup_[i - 2]; starty = alphaLookup_[i - 1]; endx = alphaLookup_[i + 0]; @@ -239,7 +237,6 @@ double ColorMap::alpha(double transformedValue) const double interp = (transformedValue - startx) / (endx - startx); double value = ((1.0f - interp) * starty + (interp) * endy) / 80.0; - std::cout << startx << " : " << endx << " : " << interp << "\n"; return value; } diff --git a/src/Modules/Visualization/CreateStandardColorMap.cc b/src/Modules/Visualization/CreateStandardColorMap.cc index 088a2f4457..c865570436 100644 --- a/src/Modules/Visualization/CreateStandardColorMap.cc +++ b/src/Modules/Visualization/CreateStandardColorMap.cc @@ -66,7 +66,6 @@ void CreateStandardColorMap::execute() //TODO cbright: pass computed alpha function from transient state to factory auto alphaPoints = state->getValue(Parameters::AlphaUserPointsVector).toVector(); - std::cout << alphaPoints << "\n"; std::vector points; for(auto point : alphaPoints) { From f197fd48a629ba21ca91bba1b23500bed3674326 Mon Sep 17 00:00:00 2001 From: Haydelj Date: Fri, 20 Sep 2019 15:53:26 -0600 Subject: [PATCH 05/13] added colormap transparency support to glyphs --- src/Core/Datatypes/ColorMap.cc | 10 +- .../Visualization/CreateStandardColorMap.cc | 1 + src/Modules/Visualization/ShowFieldGlyphs.cc | 19 +- .../ShowFieldGlyphsPortHandler.cc | 173 ++++++++++-------- .../ShowFieldGlyphsPortHandler.h | 5 + 5 files changed, 121 insertions(+), 87 deletions(-) diff --git a/src/Core/Datatypes/ColorMap.cc b/src/Core/Datatypes/ColorMap.cc index db817ef9f7..c1c6634cb3 100644 --- a/src/Core/Datatypes/ColorMap.cc +++ b/src/Core/Datatypes/ColorMap.cc @@ -213,19 +213,19 @@ double ColorMap::alpha(double transformedValue) const for(i = 0; (i < alphaLookup_.size()) && (alphaLookup_[i] < transformedValue); i += 2); double startx = 0.0; - double starty = 40.0; + double starty = 41.0; double endx = 364.0; - double endy = 40.0; + double endy = starty; if(i == 0) { endx = alphaLookup_[0]; - endy = alphaLookup_[1]; + starty = endy = alphaLookup_[1]; } else if(i == alphaLookup_.size()) { startx = alphaLookup_[i - 2]; - starty = alphaLookup_[i - 1]; + endy = starty = alphaLookup_[i - 1]; } else { @@ -236,7 +236,7 @@ double ColorMap::alpha(double transformedValue) const } double interp = (transformedValue - startx) / (endx - startx); - double value = ((1.0f - interp) * starty + (interp) * endy) / 80.0; + double value = 1.0f - ((1.0f - interp) * starty + (interp) * endy) / 82.0f; return value; } diff --git a/src/Modules/Visualization/CreateStandardColorMap.cc b/src/Modules/Visualization/CreateStandardColorMap.cc index c865570436..088a2f4457 100644 --- a/src/Modules/Visualization/CreateStandardColorMap.cc +++ b/src/Modules/Visualization/CreateStandardColorMap.cc @@ -66,6 +66,7 @@ void CreateStandardColorMap::execute() //TODO cbright: pass computed alpha function from transient state to factory auto alphaPoints = state->getValue(Parameters::AlphaUserPointsVector).toVector(); + std::cout << alphaPoints << "\n"; std::vector points; for(auto point : alphaPoints) { diff --git a/src/Modules/Visualization/ShowFieldGlyphs.cc b/src/Modules/Visualization/ShowFieldGlyphs.cc index c7e4161d68..9a2cf99016 100644 --- a/src/Modules/Visualization/ShowFieldGlyphs.cc +++ b/src/Modules/Visualization/ShowFieldGlyphs.cc @@ -587,7 +587,7 @@ void GlyphBuilder::renderVectors( glyphs.buildObject(*geom, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENT_EDGES), state->getValue(ShowFieldGlyphs::VectorsUniformTransparencyValue).toDouble(), - colorScheme, renState, primIn, mesh->get_bounding_box()); + colorScheme, renState, primIn, mesh->get_bounding_box(), true, portHandler.getTextureMap()); } void GlyphBuilder::renderScalars( @@ -682,7 +682,9 @@ void GlyphBuilder::renderScalars( std::string uniqueNodeID = id + "scalar_glyphs" + ss.str(); glyphs.buildObject(*geom, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENT_NODES), - state->getValue(ShowFieldGlyphs::ScalarsUniformTransparencyValue).toDouble(), colorScheme, renState, primIn, mesh->get_bounding_box()); + state->getValue(ShowFieldGlyphs::ScalarsUniformTransparencyValue).toDouble(), + colorScheme, renState, primIn, mesh->get_bounding_box(), true, + portHandler.getTextureMap()); } double map_emphasis(double old) @@ -870,16 +872,23 @@ void GlyphBuilder::renderTensors( } glyphs.buildObject(*geom, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY), - state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), colorScheme, renState, primIn, mesh->get_bounding_box()); + state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), + colorScheme, renState, primIn, mesh->get_bounding_box(), true, + portHandler.getTextureMap()); // Render lines(2 eigenvalues equalling 0) RenderState lineRenState = getVectorsRenderState(state); tensor_line_glyphs.buildObject(*geom, uniqueLineID, lineRenState.get(RenderState::USE_TRANSPARENT_EDGES), - state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), colorScheme, lineRenState, SpireIBO::PRIMITIVE::LINES, mesh->get_bounding_box()); + state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), + colorScheme, lineRenState, SpireIBO::PRIMITIVE::LINES, mesh->get_bounding_box(), + true, portHandler.getTextureMap()); + // Render scalars(3 eigenvalues equalling 0) RenderState pointRenState = getScalarsRenderState(state); point_glyphs.buildObject(*geom, uniquePointID, pointRenState.get(RenderState::USE_TRANSPARENT_NODES), - state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), colorScheme, pointRenState, SpireIBO::PRIMITIVE::POINTS, mesh->get_bounding_box()); + state->getValue(ShowFieldGlyphs::TensorsUniformTransparencyValue).toDouble(), + colorScheme, pointRenState, SpireIBO::PRIMITIVE::POINTS, mesh->get_bounding_box(), + true, portHandler.getTextureMap()); } void ShowFieldGlyphs::setSuperquadricEmphasis(int emphasis) diff --git a/src/Modules/Visualization/ShowFieldGlyphsPortHandler.cc b/src/Modules/Visualization/ShowFieldGlyphsPortHandler.cc index 49608210db..8394414fcc 100644 --- a/src/Modules/Visualization/ShowFieldGlyphsPortHandler.cc +++ b/src/Modules/Visualization/ShowFieldGlyphsPortHandler.cc @@ -51,8 +51,7 @@ namespace SCIRun{ boost::optional pcolorMap, boost::optional scolorMap, boost::optional tcolorMap) - : module_(mod), - pf_handle(pf), pf_info(pf) + : module_(mod), pf_handle(pf), pf_info(pf) { // Save field info p_vfld = (pf)->vfield(); @@ -134,48 +133,50 @@ namespace SCIRun{ // If color map was picked, set the chosen color map if(colorScheme == ColorScheme::COLOR_MAP) + { + switch(renState.mColorInput) { - switch(renState.mColorInput) + case RenderState::InputPort::PRIMARY_PORT: + if(pcolorMap) { - case RenderState::InputPort::PRIMARY_PORT: - if(pcolorMap) - { - colorMap = pcolorMap; - colorMapGiven = true; - } - else - { - colorMapGiven = false; - } - break; - case RenderState::InputPort::SECONDARY_PORT: - if(scolorMap) - { - colorMap = scolorMap; - colorMapGiven = true; - } - else - { - colorMapGiven = false; - } - break; - case RenderState::InputPort::TERTIARY_PORT: - if(tcolorMap) - { - colorMap = tcolorMap; - colorMapGiven = true; - } - else - { - colorMapGiven = false; - } - break; - default: - throw std::invalid_argument("Selected port was not primary, secondary, or tertiary."); - break; + colorMap = pcolorMap; + colorMapGiven = true; } + else + { + colorMapGiven = false; + } + break; + case RenderState::InputPort::SECONDARY_PORT: + if(scolorMap) + { + colorMap = scolorMap; + colorMapGiven = true; + } + else + { + colorMapGiven = false; + } + break; + case RenderState::InputPort::TERTIARY_PORT: + if(tcolorMap) + { + colorMap = tcolorMap; + colorMapGiven = true; + } + else + { + colorMapGiven = false; + } + break; + default: + throw std::invalid_argument("Selected port was not primary, secondary, or tertiary."); + break; } + spiltColorMapToTextureAndCoordinates(); + } + // Get color input type from render state colorInput = renState.mColorInput; @@ -267,10 +268,10 @@ namespace SCIRun{ ColorRGB colorMapVal; switch(colorInput) - { + { case RenderState::InputPort::PRIMARY_PORT: switch(pf_data_type) - { + { case FieldDataType::Scalar: colorMapVal = colorMap.get()->valueToColor(pinputScalar.get()); break; @@ -283,11 +284,11 @@ namespace SCIRun{ default: throw std::invalid_argument("Primary color map did not find scalar, vector, or tensor data."); break; - } + } break; case RenderState::InputPort::SECONDARY_PORT: switch(sf_data_type) - { + { case FieldDataType::Scalar: colorMapVal = colorMap.get()->valueToColor(sinputScalar.get()); break; @@ -300,11 +301,11 @@ namespace SCIRun{ default: throw std::invalid_argument("Secondary color map did not find scalar, vector, or tensor data."); break; - } + } break; case RenderState::InputPort::TERTIARY_PORT: switch(tf_data_type) - { + { case FieldDataType::Scalar: colorMapVal = colorMap.get()->valueToColor(tinputScalar.get()); break; @@ -317,12 +318,12 @@ namespace SCIRun{ default: throw std::invalid_argument("Tertiary color map did not find scalar, vector, or tensor data."); break; - } + } break; default: throw std::invalid_argument("Color map selection was not given a primary, secondary, or tertiary port."); break; - } + } return colorMapVal; } @@ -331,40 +332,40 @@ namespace SCIRun{ { // Make sure color map port and correpsonding field data is given for chosen color map if(colorScheme == ColorScheme::COLOR_MAP) + { + switch(colorInput) { - switch(colorInput) + case RenderState::InputPort::PRIMARY_PORT: + if(!colorMap) { - case RenderState::InputPort::PRIMARY_PORT: - if(!colorMap) - { - throw std::invalid_argument("Primary Color Map input is required."); - } - break; - case RenderState::InputPort::SECONDARY_PORT: - if(!(secondaryFieldGiven && colorMap)) - { - throw std::invalid_argument("Secondary Field and Color Map input is required."); - } - if(s_vfld->num_values() < p_vfld->num_values()) - { - throw std::invalid_argument("Secondary Field input cannot have a smaller size than the Primary Field input."); - } - break; - case RenderState::InputPort::TERTIARY_PORT: - if(!(tertiaryFieldGiven && colorMap)) - { - throw std::invalid_argument("Tertiary Field and Color Map input is required."); - } - if(t_vfld->num_values() < p_vfld->num_values()) - { - throw std::invalid_argument("Tertiary Field input cannot have a smaller size than the Primary Field input."); - } - break; - default: - throw std::invalid_argument("Must select a primary, secondary, or tertiary port for color map input."); - break; + throw std::invalid_argument("Primary Color Map input is required."); + } + break; + case RenderState::InputPort::SECONDARY_PORT: + if(!(secondaryFieldGiven && colorMap)) + { + throw std::invalid_argument("Secondary Field and Color Map input is required."); } + if(s_vfld->num_values() < p_vfld->num_values()) + { + throw std::invalid_argument("Secondary Field input cannot have a smaller size than the Primary Field input."); + } + break; + case RenderState::InputPort::TERTIARY_PORT: + if(!(tertiaryFieldGiven && colorMap)) + { + throw std::invalid_argument("Tertiary Field and Color Map input is required."); + } + if(t_vfld->num_values() < p_vfld->num_values()) + { + throw std::invalid_argument("Tertiary Field input cannot have a smaller size than the Primary Field input."); + } + break; + default: + throw std::invalid_argument("Must select a primary, secondary, or tertiary port for color map input."); + break; } + } // Make sure scalar is not given for rgb conversion else if(colorScheme == ColorScheme::COLOR_IN_SITU) { @@ -647,6 +648,24 @@ namespace SCIRun{ { return pf_handle->mesh()->getFacade(); } + + void ShowFieldGlyphsPortHandler::spiltColorMapToTextureAndCoordinates() + { + ColorMapHandle realColorMap = nullptr; + + if(colorMap) realColorMap = colorMap.get(); + else realColorMap = StandardColorMapFactory::create(); + + textureMap = StandardColorMapFactory::create(realColorMap->getColorMapName(), + realColorMap->getColorMapResolution(), realColorMap->getColorMapShift(), + realColorMap->getColorMapInvert(), 0.5, 1.0, realColorMap->getAlphaLookup()); + + coordinateMap = StandardColorMapFactory::create("Grayscale", 256, 0, false, + realColorMap->getColorMapRescaleScale(), realColorMap->getColorMapRescaleShift()); + + colorMap = coordinateMap; + } + } } } diff --git a/src/Modules/Visualization/ShowFieldGlyphsPortHandler.h b/src/Modules/Visualization/ShowFieldGlyphsPortHandler.h index bb12d6f5fe..21df66a97d 100644 --- a/src/Modules/Visualization/ShowFieldGlyphsPortHandler.h +++ b/src/Modules/Visualization/ShowFieldGlyphsPortHandler.h @@ -69,6 +69,7 @@ namespace SCIRun{ RenderState::InputPort colorInput; Core::Datatypes::ColorRGB defaultColor; boost::optional colorMap; + Core::Datatypes::ColorMapHandle coordinateMap {nullptr}, textureMap {nullptr}; boost::optional pinputTensor, sinputTensor, tinputTensor; boost::optional pinputVector, sinputVector, tinputVector; boost::optional pinputScalar, sinputScalar, tinputScalar; @@ -100,6 +101,10 @@ namespace SCIRun{ // Verifies that data is valid. Run this after initialization void checkForErrors(); + void spiltColorMapToTextureAndCoordinates(); + + Core::Datatypes::ColorMapHandle getTextureMap() {return textureMap;} + // Returns color scheme that was set in render state Graphics::Datatypes::ColorScheme getColorScheme(); From c8cede639d51aa25d67207c9d5ebe5bfdd84b8ba Mon Sep 17 00:00:00 2001 From: RubioJr9 Date: Mon, 30 Sep 2019 13:55:01 -0600 Subject: [PATCH 06/13] Fixed disappearing scene. --- src/Externals/spire/arc-ball/ArcBall.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Externals/spire/arc-ball/ArcBall.cpp b/src/Externals/spire/arc-ball/ArcBall.cpp index e9a28eaa6d..91d51b5c04 100644 --- a/src/Externals/spire/arc-ball/ArcBall.cpp +++ b/src/Externals/spire/arc-ball/ArcBall.cpp @@ -60,7 +60,7 @@ void ArcBall::drag(const glm::vec2& msc) glm::vec3 mVSphereNow = mouseOnSphere((mScreenToTCS * glm::vec4(msc, 0.0, 1.0)).xyz()); // Construct a quaternion from two points on the unit sphere. - glm:: quat mQDrag = quatFromUnitSphere(mVSphereDown, mVSphereNow); + glm::quat mQDrag = quatFromUnitSphere(mVSphereDown, mVSphereNow); mQNow = mQDrag * mQDown; if(glm::dot(mVSphereDown, mVSphereNow) < 0.0) beginDrag(msc); @@ -76,7 +76,13 @@ void ArcBall::setLocationOnSphere(glm::vec3 location, glm::vec3 up) //------------------------------------------------------------------------------ glm::quat ArcBall::quatFromUnitSphere(const glm::vec3& from, const glm::vec3& to) { - glm::vec3 axis = glm::normalize(glm::cross(from, to)); + glm::vec3 cross = glm::cross(from, to); + glm::vec3 axis = glm::normalize(cross); + + // Give arbitrary non-zero vector because no rotation + if (glm::length(cross) == 0.0) + axis = from; + float angle = std::acos(glm::dot(from, to)); if(angle <= 0.00001) From 31d88ec050ac82ddf91f9faa82633f6c21822a50 Mon Sep 17 00:00:00 2001 From: Haydelj Date: Mon, 30 Sep 2019 14:17:47 -0600 Subject: [PATCH 07/13] ui fixed --- src/Core/Datatypes/ColorMap.cc | 10 ++--- .../CreateStandardColorMapDialog.cc | 38 ++++++------------- .../CreateStandardColorMapDialog.h | 2 - .../Visualization/CreateStandardColorMap.cc | 1 - 4 files changed, 14 insertions(+), 37 deletions(-) diff --git a/src/Core/Datatypes/ColorMap.cc b/src/Core/Datatypes/ColorMap.cc index c1c6634cb3..bcbfd7c971 100644 --- a/src/Core/Datatypes/ColorMap.cc +++ b/src/Core/Datatypes/ColorMap.cc @@ -207,16 +207,12 @@ ColorRGB ColorMap::applyAlpha(double transformed, ColorRGB colorWithoutAlpha) co double ColorMap::alpha(double transformedValue) const { - transformedValue *= 364.0; + transformedValue *= 365.0f; if(alphaLookup_.size() == 0) return 0.5; int i; for(i = 0; (i < alphaLookup_.size()) && (alphaLookup_[i] < transformedValue); i += 2); - double startx = 0.0; - double starty = 41.0; - double endx = 364.0; - double endy = starty; - + double startx = 0.0f, starty, endx = 365.0f, endy; if(i == 0) { endx = alphaLookup_[0]; @@ -236,7 +232,7 @@ double ColorMap::alpha(double transformedValue) const } double interp = (transformedValue - startx) / (endx - startx); - double value = 1.0f - ((1.0f - interp) * starty + (interp) * endy) / 82.0f; + double value = 1.0f - ((1.0f - interp) * starty + (interp) * endy) * (1.0f / 83.0f); return value; } diff --git a/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.cc b/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.cc index 87a1f7a78a..96ba9bcadd 100644 --- a/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.cc +++ b/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.cc @@ -94,7 +94,6 @@ void CreateStandardColorMapDialog::pullSpecial() } else { - previewColorMap_->addEndpoints(); for (const auto& p : pointsVec) { auto pVec = p.toVector(); @@ -189,7 +188,6 @@ void ColormapPreview::mousePressEvent(QMouseEvent* event) } //TODO: remove point if event & RightMouseButton - //TODO: points are movable! } @@ -201,13 +199,6 @@ void ColormapPreview::addDefaultLine() alphaPath_ = scene()->addLine(defaultStart_.x(), defaultStart_.y(), defaultEnd_.x(), defaultEnd_.y(), alphaLinePen); - alphaManager_.insertEndpoints(); -} - -void AlphaFunctionManager::insertEndpoints() -{ - alphaPoints_.insert(defaultStart_); - insert(defaultEnd_); // only update function and state after both endpoints are added } void ColormapPreview::removeDefaultLine() @@ -218,18 +209,13 @@ void ColormapPreview::removeDefaultLine() void ColormapPreview::addPoint(const QPointF& point) { - if (alphaManager_.alreadyExists(point)) - return; + if (alphaManager_.alreadyExists(point)) return; removeDefaultLine(); static QPen pointPen(Qt::white, 1); auto item = scene()->addEllipse(point.x() - 4, point.y() - 4, 8, 8, pointPen, QBrush(Qt::black)); item->setZValue(1); - // QString toolTip; - // QDebug tt(&toolTip); - // tt << "Alpha point " << point.x() << ", " << point.y() << " y% " << (1 - point.y() / sceneRect().height()); - // item->setToolTip(toolTip); alphaManager_.insert(point); drawAlphaPolyline(); @@ -264,8 +250,6 @@ void AlphaFunctionManager::pushToState() Variable::List alphaPointsVec; //strip endpoints before saving user-added points auto begin = alphaPoints_.begin(), end = alphaPoints_.end(); - std::advance(begin, 1); - std::advance(end, -1); std::for_each(begin, end, [&](const QPointF& p) { alphaPointsVec.emplace_back(Name("alphaPoint"), makeAnonymousVariableList(p.x(), p.y())); }); state_->setValue(Parameters::AlphaUserPointsVector, alphaPointsVec); } @@ -284,15 +268,16 @@ void ColormapPreview::drawAlphaPolyline() auto pathItem = new QGraphicsPathItem(); alphaPath_ = pathItem; pathItem->setPen(alphaLinePen); + QPainterPath path; - QPointF from = defaultStart_; - path.moveTo(from); + auto start = alphaManager_.begin(); + auto end = alphaManager_.end(); std::advance(end, -1); + QPointF from = QPointF(defaultStart_.x(), start->y()); + QPointF to = QPointF(defaultEnd_.x(), end->y()); - for (const auto& point : alphaManager_) - { - path.lineTo(point); - path.moveTo(point); - } + path.moveTo(from); + for (const auto& point : alphaManager_) path.lineTo(point); + path.lineTo(to); pathItem->setPath(path); pathItem->setZValue(0); @@ -317,12 +302,11 @@ void AlphaFunctionManager::updateAlphaFunction() for (int i = 0; i < static_cast(alphaFunction_.size()); ++i) { - if (i > 0 && i < alphaFunction_.size() - 1) + if (false && i > 0 && i < alphaFunction_.size() - 1) { double color = i / static_cast(ALPHA_SAMPLES + 1); auto between = alphaLineEndpointsAtColor(color); alphaFunction_[i] = interpolateAlphaLineValue(between.first, between.second, color); - // qDebug() << "Color: " << color << "Alpha: " << alphaFunction_[i] << "between points" << between.first << between.second; } else { @@ -353,7 +337,7 @@ double AlphaFunctionManager::interpolateAlphaLineValue(const QPointF& leftEndpoi double AlphaFunctionManager::pointYToAlpha(double y) const { - return 1 - y / colorMapPreviewRect.height(); + return 1.0f - y / colorMapPreviewRect.height(); } QPointF AlphaFunctionManager::colorToPoint(double color) const diff --git a/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.h b/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.h index a90549730a..1fae2933a1 100644 --- a/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.h +++ b/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.h @@ -50,7 +50,6 @@ namespace SCIRun { public: AlphaFunctionManager(const QPointF& start, const QPointF& end, SCIRun::Dataflow::Networks::ModuleStateHandle state, const boost::atomic& pulling); void clear(); - void insertEndpoints(); void insert(const QPointF& p); bool alreadyExists(const QPointF& p) const; private: @@ -85,7 +84,6 @@ namespace SCIRun { QWidget* parent = nullptr); void addDefaultLine(); void addPoint(const QPointF& point); - void addEndpoints() { alphaManager_.insertEndpoints(); } public Q_SLOTS: void clearAlphaPointGraphics(); Q_SIGNALS: diff --git a/src/Modules/Visualization/CreateStandardColorMap.cc b/src/Modules/Visualization/CreateStandardColorMap.cc index 088a2f4457..c865570436 100644 --- a/src/Modules/Visualization/CreateStandardColorMap.cc +++ b/src/Modules/Visualization/CreateStandardColorMap.cc @@ -66,7 +66,6 @@ void CreateStandardColorMap::execute() //TODO cbright: pass computed alpha function from transient state to factory auto alphaPoints = state->getValue(Parameters::AlphaUserPointsVector).toVector(); - std::cout << alphaPoints << "\n"; std::vector points; for(auto point : alphaPoints) { From 3e000f38689e2bf931e46ad355390acd52d9539f Mon Sep 17 00:00:00 2001 From: Haydelj Date: Mon, 30 Sep 2019 14:33:00 -0600 Subject: [PATCH 08/13] removed preview size dependency from the internal representation of colormaps --- src/Core/Datatypes/ColorMap.cc | 6 +++--- .../CreateStandardColorMapDialog.cc | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Core/Datatypes/ColorMap.cc b/src/Core/Datatypes/ColorMap.cc index bcbfd7c971..fa52b7e537 100644 --- a/src/Core/Datatypes/ColorMap.cc +++ b/src/Core/Datatypes/ColorMap.cc @@ -207,12 +207,12 @@ ColorRGB ColorMap::applyAlpha(double transformed, ColorRGB colorWithoutAlpha) co double ColorMap::alpha(double transformedValue) const { - transformedValue *= 365.0f; + //transformedValue *= 365.0f; if(alphaLookup_.size() == 0) return 0.5; int i; for(i = 0; (i < alphaLookup_.size()) && (alphaLookup_[i] < transformedValue); i += 2); - double startx = 0.0f, starty, endx = 365.0f, endy; + double startx = 0.0f, starty, endx = 1.0f, endy; if(i == 0) { endx = alphaLookup_[0]; @@ -232,7 +232,7 @@ double ColorMap::alpha(double transformedValue) const } double interp = (transformedValue - startx) / (endx - startx); - double value = 1.0f - ((1.0f - interp) * starty + (interp) * endy) * (1.0f / 83.0f); + double value = ((1.0f - interp) * starty + (interp) * endy); return value; } diff --git a/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.cc b/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.cc index 96ba9bcadd..72ff0f43c9 100644 --- a/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.cc +++ b/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.cc @@ -38,6 +38,12 @@ using namespace SCIRun::Core::Datatypes; typedef SCIRun::Modules::Visualization::CreateStandardColorMap CreateStandardColorMapModule; +namespace +{ + const double colormapPreviewHeight = 83; + const double colormapPreviewWidth = 365; + const QRectF colorMapPreviewRect(0, 0, colormapPreviewWidth, colormapPreviewHeight); +} CreateStandardColorMapDialog::CreateStandardColorMapDialog(const std::string& name, ModuleStateHandle state, QWidget* parent /* = 0 */) @@ -97,7 +103,7 @@ void CreateStandardColorMapDialog::pullSpecial() for (const auto& p : pointsVec) { auto pVec = p.toVector(); - previewColorMap_->addPoint(QPointF(pVec[0].toDouble(), pVec[1].toDouble())); + previewColorMap_->addPoint(QPointF(pVec[0].toDouble() * colormapPreviewWidth, (1.0f - pVec[1].toDouble()) * colormapPreviewHeight)); } } } @@ -159,13 +165,6 @@ AlphaFunctionManager::AlphaFunctionManager(const QPointF& start, const QPointF& { } -namespace -{ - const double colormapPreviewHeight = 83; - const double colormapPreviewWidth = 365; - const QRectF colorMapPreviewRect(0, 0, colormapPreviewWidth, colormapPreviewHeight); -} - ColormapPreview::ColormapPreview(QGraphicsScene* scene, ModuleStateHandle state, const boost::atomic& pulling, QWidget* parent) @@ -250,7 +249,8 @@ void AlphaFunctionManager::pushToState() Variable::List alphaPointsVec; //strip endpoints before saving user-added points auto begin = alphaPoints_.begin(), end = alphaPoints_.end(); - std::for_each(begin, end, [&](const QPointF& p) { alphaPointsVec.emplace_back(Name("alphaPoint"), makeAnonymousVariableList(p.x(), p.y())); }); + std::for_each(begin, end, [&](const QPointF& p) { alphaPointsVec.emplace_back(Name("alphaPoint"), + makeAnonymousVariableList(p.x()/colormapPreviewWidth, 1.0f - p.y()/colormapPreviewHeight)); }); state_->setValue(Parameters::AlphaUserPointsVector, alphaPointsVec); } else From d7ae9bab84e0e2bc1d08b86cd5c434fb5e4d081d Mon Sep 17 00:00:00 2001 From: Haydelj Date: Mon, 30 Sep 2019 15:10:47 -0600 Subject: [PATCH 09/13] cleaned up dead code and removed outdated comments --- src/Core/Datatypes/ColorMap.cc | 4 --- src/Core/Datatypes/ColorMap.h | 4 +-- .../CreateStandardColorMapDialog.cc | 26 ------------------- .../CreateStandardColorMapDialog.h | 1 - 4 files changed, 2 insertions(+), 33 deletions(-) diff --git a/src/Core/Datatypes/ColorMap.cc b/src/Core/Datatypes/ColorMap.cc index fa52b7e537..0d69ebb2fe 100644 --- a/src/Core/Datatypes/ColorMap.cc +++ b/src/Core/Datatypes/ColorMap.cc @@ -192,11 +192,8 @@ double ColorMap::getTransformedValue(double f) const ColorRGB ColorMap::getColorMapVal(double v) const { double f = getTransformedValue(v); - //now grab the RGB auto colorWithoutAlpha = color_->getColorMapVal(f); - //TODO: return applyAlpha(f, colorWithoutAlpha); - //return colorWithoutAlpha; } ColorRGB ColorMap::applyAlpha(double transformed, ColorRGB colorWithoutAlpha) const @@ -207,7 +204,6 @@ ColorRGB ColorMap::applyAlpha(double transformed, ColorRGB colorWithoutAlpha) co double ColorMap::alpha(double transformedValue) const { - //transformedValue *= 365.0f; if(alphaLookup_.size() == 0) return 0.5; int i; for(i = 0; (i < alphaLookup_.size()) && (alphaLookup_[i] < transformedValue); i += 2); diff --git a/src/Core/Datatypes/ColorMap.h b/src/Core/Datatypes/ColorMap.h index 813a45a7fe..a81655ebcf 100644 --- a/src/Core/Datatypes/ColorMap.h +++ b/src/Core/Datatypes/ColorMap.h @@ -52,7 +52,7 @@ namespace Datatypes { const std::string& name = "Rainbow", const size_t resolution = 256, const double shift = 0.0, const bool invert = false, const double rescale_scale = .5, const double rescale_shift = 1.0, - const std::vector& alphaPoints = std::vector()); + const std::vector& alphaPoints = {}); //TODO cbright: pass in alpha vector virtual ColorMap* clone() const override; @@ -117,7 +117,7 @@ namespace Datatypes { static ColorMapHandle create(const std::string& name = "Rainbow", const size_t &resolution = 256, const double &shift = 0.0, const bool &invert = false, const double &rescale_scale = .5, const double &rescale_shift = 1.0, - const std::vector& alphaPoints = std::vector()); + const std::vector& alphaPoints = {}); typedef std::vector NameList; static NameList getList(); private: diff --git a/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.cc b/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.cc index 72ff0f43c9..a644e1d121 100644 --- a/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.cc +++ b/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.cc @@ -160,7 +160,6 @@ void CreateStandardColorMapDialog::onInvertCheck(bool b) AlphaFunctionManager::AlphaFunctionManager(const QPointF& start, const QPointF& end, ModuleStateHandle state, const boost::atomic& pulling) : state_(state), defaultStart_(start), defaultEnd_(end), - alphaFunction_(ALPHA_VECTOR_LENGTH, DEFAULT_ALPHA), dialogPulling_(pulling) { } @@ -229,14 +228,12 @@ bool AlphaFunctionManager::alreadyExists(const QPointF& point) const void AlphaFunctionManager::insert(const QPointF& p) { alphaPoints_.insert(p); - updateAlphaFunction(); pushToState(); } void AlphaFunctionManager::clear() { alphaPoints_.clear(); - alphaFunction_.assign(ALPHA_VECTOR_LENGTH, DEFAULT_ALPHA); pushToState(); } @@ -247,7 +244,6 @@ void AlphaFunctionManager::pushToState() if (!alphaPoints_.empty()) { Variable::List alphaPointsVec; - //strip endpoints before saving user-added points auto begin = alphaPoints_.begin(), end = alphaPoints_.end(); std::for_each(begin, end, [&](const QPointF& p) { alphaPointsVec.emplace_back(Name("alphaPoint"), makeAnonymousVariableList(p.x()/colormapPreviewWidth, 1.0f - p.y()/colormapPreviewHeight)); }); @@ -257,8 +253,6 @@ void AlphaFunctionManager::pushToState() { state_->setValue(Parameters::AlphaUserPointsVector, Variable::List()); } - - state_->setTransientValue(Parameters::AlphaFunctionVector, alphaFunction_); } } @@ -295,26 +289,6 @@ void ColormapPreview::clearAlphaPointGraphics() addDefaultLine(); } -void AlphaFunctionManager::updateAlphaFunction() -{ - //from v4, color endpoints (0 and 1) are fixed at alpha = 0.5. - // alphaFunction_ will sample from in between these endpoints, evenly spaced throughout open interval (0,1) - - for (int i = 0; i < static_cast(alphaFunction_.size()); ++i) - { - if (false && i > 0 && i < alphaFunction_.size() - 1) - { - double color = i / static_cast(ALPHA_SAMPLES + 1); - auto between = alphaLineEndpointsAtColor(color); - alphaFunction_[i] = interpolateAlphaLineValue(between.first, between.second, color); - } - else - { - alphaFunction_[i] = DEFAULT_ALPHA; - } - } -} - std::pair AlphaFunctionManager::alphaLineEndpointsAtColor(double color) const { auto rightIter = alphaPoints_.upper_bound(colorToPoint(color)); diff --git a/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.h b/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.h index 1fae2933a1..f1c8f34159 100644 --- a/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.h +++ b/src/Interface/Modules/Visualization/CreateStandardColorMapDialog.h @@ -67,7 +67,6 @@ namespace SCIRun { const double DEFAULT_ALPHA = 0.5; const QPointF defaultStart_; const QPointF defaultEnd_; - std::vector alphaFunction_; const boost::atomic& dialogPulling_; public: auto begin() const -> decltype(alphaPoints_.begin()) { return alphaPoints_.begin(); } From 003a71767d3c8302bf4c9546b60c03b0bbc97ec6 Mon Sep 17 00:00:00 2001 From: Haydelj Date: Mon, 30 Sep 2019 15:13:41 -0600 Subject: [PATCH 10/13] removed weird code --- src/Core/Application/Version.cc | 32 ++++++++++++++++++++++++++++++++ src/Core/Datatypes/ColorMap.cc | 10 ---------- 2 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 src/Core/Application/Version.cc diff --git a/src/Core/Application/Version.cc b/src/Core/Application/Version.cc new file mode 100644 index 0000000000..734e76fa5e --- /dev/null +++ b/src/Core/Application/Version.cc @@ -0,0 +1,32 @@ +/* + For more information, please see: http://software.sci.utah.edu + + The MIT License + + Copyright (c) 2015 Scientific Computing and Imaging Institute, + University of Utah. + + License for the specific language governing rights and limitations under + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include + +const std::string VersionInfo::GIT_VERSION_TAG = "v5.0-beta.CinC2019-21-g3e000f386"; +const std::string VersionInfo::GIT_COMMIT_SHA = "3e000f38689e2bf931e46ad355390acd52d9539f"; diff --git a/src/Core/Datatypes/ColorMap.cc b/src/Core/Datatypes/ColorMap.cc index 0d69ebb2fe..a2a29640f1 100644 --- a/src/Core/Datatypes/ColorMap.cc +++ b/src/Core/Datatypes/ColorMap.cc @@ -149,16 +149,6 @@ StandardColorMapFactory::NameList StandardColorMapFactory::getList() */ double ColorMap::getTransformedValue(double f) const { - ///////////////////////////////////////////////// - //TODO: this seemingly useless code fixes a nasty crash bug on Windows. Don't delete it until a proper fix is implemented! - static bool x = true; - if (x) - { - std::cout << ""; - x = false; - } - ///////////////////////////////////////////////// - const double rescaled01 = static_cast((f + rescale_shift_) * rescale_scale_); double v = std::min(std::max(0., rescaled01), 1.); From d93de4c6d5ff3a3b830a5725608855b8c94ded49 Mon Sep 17 00:00:00 2001 From: tpat Date: Tue, 1 Oct 2019 14:38:01 -0600 Subject: [PATCH 11/13] Checking nan instead --- src/Externals/spire/arc-ball/ArcBall.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Externals/spire/arc-ball/ArcBall.cpp b/src/Externals/spire/arc-ball/ArcBall.cpp index 91d51b5c04..9d1a3bdf90 100644 --- a/src/Externals/spire/arc-ball/ArcBall.cpp +++ b/src/Externals/spire/arc-ball/ArcBall.cpp @@ -76,11 +76,10 @@ void ArcBall::setLocationOnSphere(glm::vec3 location, glm::vec3 up) //------------------------------------------------------------------------------ glm::quat ArcBall::quatFromUnitSphere(const glm::vec3& from, const glm::vec3& to) { - glm::vec3 cross = glm::cross(from, to); - glm::vec3 axis = glm::normalize(cross); + glm::vec3 axis = glm::normalize(glm::cross(from, to)); // Give arbitrary non-zero vector because no rotation - if (glm::length(cross) == 0.0) + if (std::isnan(axis[0])) axis = from; float angle = std::acos(glm::dot(from, to)); From 275efdfb53b64e9ab84da99f7d9357c491853f79 Mon Sep 17 00:00:00 2001 From: RubioJr9 Date: Fri, 4 Oct 2019 16:13:57 -0600 Subject: [PATCH 12/13] checking angle for nan --- src/Externals/spire/arc-ball/ArcBall.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Externals/spire/arc-ball/ArcBall.cpp b/src/Externals/spire/arc-ball/ArcBall.cpp index 9d1a3bdf90..fbc3c0407b 100644 --- a/src/Externals/spire/arc-ball/ArcBall.cpp +++ b/src/Externals/spire/arc-ball/ArcBall.cpp @@ -84,7 +84,7 @@ glm::quat ArcBall::quatFromUnitSphere(const glm::vec3& from, const glm::vec3& to float angle = std::acos(glm::dot(from, to)); - if(angle <= 0.00001) + if(angle <= 0.00001 || std::isnan(angle)) return glm::quat(1.0, 0.0, 0.0, 0.0); return glm::angleAxis(angle, axis); From 22155ea086200a3a0fe9f977a74a1c78025e44bd Mon Sep 17 00:00:00 2001 From: Haydelj Date: Mon, 7 Oct 2019 14:57:01 -0600 Subject: [PATCH 13/13] fixed rescale colormap module --- src/Modules/Visualization/RescaleColorMap.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Modules/Visualization/RescaleColorMap.cc b/src/Modules/Visualization/RescaleColorMap.cc index 5f94976047..f58e0e9761 100644 --- a/src/Modules/Visualization/RescaleColorMap.cc +++ b/src/Modules/Visualization/RescaleColorMap.cc @@ -119,7 +119,7 @@ void RescaleColorMap::execute() colorMap->getColorMapResolution(), colorMap->getColorMapShift(), colorMap->getColorMapInvert(), - cm_scale, cm_shift)); + cm_scale, cm_shift, colorMap->getAlphaLookup())); } }