diff --git a/vtkm/rendering/MapperGL.cxx b/vtkm/rendering/MapperGL.cxx index c8f559bb1..d2eaec877 100644 --- a/vtkm/rendering/MapperGL.cxx +++ b/vtkm/rendering/MapperGL.cxx @@ -86,39 +86,54 @@ public: vtkm::Vec p3 = verts.Get(idx[3]); vtkm::Float32 s; - vtkm::rendering::Color color; + vtkm::rendering::Color color1; + vtkm::rendering::Color color2; + vtkm::rendering::Color color3; + + if (SDiff == 0) + { + s = 0; + color1 = ColorTable.MapRGB(s); + color2 = ColorTable.MapRGB(s); + color3 = ColorTable.MapRGB(s); + } + else + { + s = scalar.Get(i1); + s = (s - SMin) / SDiff; + color1 = ColorTable.MapRGB(s); + + s = scalar.Get(i2); + s = (s - SMin) / SDiff; + color2 = ColorTable.MapRGB(s); + + s = scalar.Get(i3); + s = (s - SMin) / SDiff; + color3 = ColorTable.MapRGB(s); + } const vtkm::Id offset = 9; - s = scalar.Get(i1); - s = (s - SMin) / SDiff; - color = ColorTable.MapRGB(s); v_array.Set(i * offset, p1[0]); v_array.Set(i * offset + 1, p1[1]); v_array.Set(i * offset + 2, p1[2]); - c_array.Set(i * offset, color.Components[0]); - c_array.Set(i * offset + 1, color.Components[1]); - c_array.Set(i * offset + 2, color.Components[2]); + c_array.Set(i * offset, color1.Components[0]); + c_array.Set(i * offset + 1, color1.Components[1]); + c_array.Set(i * offset + 2, color1.Components[2]); - s = scalar.Get(i2); - s = (s - SMin) / SDiff; - color = ColorTable.MapRGB(s); v_array.Set(i * offset + 3, p2[0]); v_array.Set(i * offset + 4, p2[1]); v_array.Set(i * offset + 5, p2[2]); - c_array.Set(i * offset + 3, color.Components[0]); - c_array.Set(i * offset + 4, color.Components[1]); - c_array.Set(i * offset + 5, color.Components[2]); + c_array.Set(i * offset + 3, color2.Components[0]); + c_array.Set(i * offset + 4, color2.Components[1]); + c_array.Set(i * offset + 5, color2.Components[2]); - s = scalar.Get(i3); - s = (s - SMin) / SDiff; - color = ColorTable.MapRGB(s); v_array.Set(i * offset + 6, p3[0]); v_array.Set(i * offset + 7, p3[1]); v_array.Set(i * offset + 8, p3[2]); - c_array.Set(i * offset + 6, color.Components[0]); - c_array.Set(i * offset + 7, color.Components[1]); - c_array.Set(i * offset + 8, color.Components[2]); + c_array.Set(i * offset + 6, color3.Components[0]); + c_array.Set(i * offset + 7, color3.Components[1]); + c_array.Set(i * offset + 8, color3.Components[2]); } }; @@ -260,6 +275,7 @@ VTKM_CONT void RenderTriangles(MapperGL& mapper, vtkm::cont::TryExecute(MapColorAndVerticesInvokeFunctor( indices, ct, scalar, scalarRange, verts, sMin, sMax, out_color, out_vertices)); + vtkm::Id vtx_cnt = out_vertices.GetNumberOfValues(); vtkm::Float32* v_ptr = out_vertices.GetStorage().StealArray(); vtkm::Float32* c_ptr = out_color.GetStorage().StealArray(); diff --git a/vtkm/rendering/View1D.cxx b/vtkm/rendering/View1D.cxx index c67ca6965..31e4638bd 100644 --- a/vtkm/rendering/View1D.cxx +++ b/vtkm/rendering/View1D.cxx @@ -174,8 +174,8 @@ void View1D::UpdateCameraProperties() this->GetCamera().SetViewRange2D( origCamBounds.X.Min, origCamBounds.X.Max, origCamBounds.Y.Min, origCamBounds.Y.Max); - // we always want to start with a curve being full-frame - if (this->GetCamera().GetMode() == Camera::MODE_2D) + // if unchanged by user we always want to start with a curve being full-frame + if (this->GetCamera().GetMode() == Camera::MODE_2D && this->GetCamera().GetXScale() == 1.0f) { vtkm::Float32 left, right, bottom, top; this->GetCamera().GetViewRange2D(left, right, bottom, top); diff --git a/vtkm/rendering/View2D.cxx b/vtkm/rendering/View2D.cxx index e18e99296..9ee3c2d25 100644 --- a/vtkm/rendering/View2D.cxx +++ b/vtkm/rendering/View2D.cxx @@ -50,22 +50,13 @@ void View2D::Paint() { this->GetCanvas().Activate(); this->GetCanvas().Clear(); - - // we always want to start with a curve being full-frame - if (this->GetCamera().GetMode() == Camera::MODE_2D) - { - vtkm::Float32 left, right, bottom, top; - this->GetCamera().GetViewRange2D(left, right, bottom, top); - this->GetCamera().SetXScale((static_cast(this->GetCanvas().GetWidth())) / - (static_cast(this->GetCanvas().GetHeight())) * - (top - bottom) / (right - left)); - } - + this->UpdateCameraProperties(); this->SetupForWorldSpace(); this->GetScene().Render(this->GetMapper(), this->GetCanvas(), this->GetCamera()); this->RenderWorldAnnotations(); this->SetupForScreenSpace(); this->RenderScreenAnnotations(); + this->RenderAnnotations(); this->GetCanvas().Finish(); } @@ -123,5 +114,30 @@ void View2D::RenderWorldAnnotations() { // 2D views don't have world annotations. } + +void View2D::UpdateCameraProperties() +{ + // Modify the camera if our bounds are equal to enable an image to show + vtkm::Bounds origCamBounds = this->GetCamera().GetViewRange2D(); + if (origCamBounds.Y.Min == origCamBounds.Y.Max) + { + origCamBounds.Y.Min -= .5; + origCamBounds.Y.Max += .5; + } + + // Set camera bounds with new top/bottom values + this->GetCamera().SetViewRange2D( + origCamBounds.X.Min, origCamBounds.X.Max, origCamBounds.Y.Min, origCamBounds.Y.Max); + + // if unchanged by user we always want to start with a curve being full-frame + if (this->GetCamera().GetMode() == Camera::MODE_2D && this->GetCamera().GetXScale() == 1.0f) + { + vtkm::Float32 left, right, bottom, top; + this->GetCamera().GetViewRange2D(left, right, bottom, top); + this->GetCamera().SetXScale((static_cast(this->GetCanvas().GetWidth())) / + (static_cast(this->GetCanvas().GetHeight())) * + (top - bottom) / (right - left)); + } +} } } // namespace vtkm::rendering diff --git a/vtkm/rendering/View2D.h b/vtkm/rendering/View2D.h index e83786734..65db3a740 100644 --- a/vtkm/rendering/View2D.h +++ b/vtkm/rendering/View2D.h @@ -53,6 +53,8 @@ public: void RenderWorldAnnotations() VTKM_OVERRIDE; private: + void UpdateCameraProperties(); + // 2D-specific annotations vtkm::rendering::AxisAnnotation2D HorizontalAxisAnnotation; vtkm::rendering::AxisAnnotation2D VerticalAxisAnnotation; diff --git a/vtkm/rendering/View3D.cxx b/vtkm/rendering/View3D.cxx index 9e1aaf6fe..c478a9c5b 100644 --- a/vtkm/rendering/View3D.cxx +++ b/vtkm/rendering/View3D.cxx @@ -53,8 +53,8 @@ void View3D::Paint() this->SetupForWorldSpace(); this->GetScene().Render(this->GetMapper(), this->GetCanvas(), this->GetCamera()); this->RenderWorldAnnotations(); - this->SetupForScreenSpace(); + this->RenderAnnotations(); this->RenderScreenAnnotations(); this->GetCanvas().Finish(); diff --git a/vtkm/rendering/testing/RenderTest.h b/vtkm/rendering/testing/RenderTest.h index 49a59fa54..8b27fd407 100644 --- a/vtkm/rendering/testing/RenderTest.h +++ b/vtkm/rendering/testing/RenderTest.h @@ -107,6 +107,14 @@ void Render(const vtkm::cont::DataSet& ds, SetCamera(camera, ds.GetCoordinateSystem().GetBounds()); ViewType view(scene, mapper, canvas, camera, vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f)); + // Print the title + vtkm::rendering::TextAnnotationScreen* titleAnnotation = + new vtkm::rendering::TextAnnotationScreen("Test Plot", + vtkm::rendering::Color(1, 1, 1, 1), + .075f, + vtkm::Vec(-.11f, .92f), + 0.f); + view.AddAnnotation(titleAnnotation); Render(view, outputFile); }