Adding 2D, 3D annotations, fixing GL color mapper.
This commit is contained in:
parent
7c0b15a555
commit
f3e455ebf6
@ -86,39 +86,54 @@ public:
|
||||
vtkm::Vec<vtkm::Float32, 3> 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<PtType>(
|
||||
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();
|
||||
|
@ -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);
|
||||
|
@ -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<vtkm::Float32>(this->GetCanvas().GetWidth())) /
|
||||
(static_cast<vtkm::Float32>(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<vtkm::Float32>(this->GetCanvas().GetWidth())) /
|
||||
(static_cast<vtkm::Float32>(this->GetCanvas().GetHeight())) *
|
||||
(top - bottom) / (right - left));
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
@ -53,6 +53,8 @@ public:
|
||||
void RenderWorldAnnotations() VTKM_OVERRIDE;
|
||||
|
||||
private:
|
||||
void UpdateCameraProperties();
|
||||
|
||||
// 2D-specific annotations
|
||||
vtkm::rendering::AxisAnnotation2D HorizontalAxisAnnotation;
|
||||
vtkm::rendering::AxisAnnotation2D VerticalAxisAnnotation;
|
||||
|
@ -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();
|
||||
|
@ -107,6 +107,14 @@ void Render(const vtkm::cont::DataSet& ds,
|
||||
SetCamera<ViewType>(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<vtkm::Float32, 2>(-.11f, .92f),
|
||||
0.f);
|
||||
view.AddAnnotation(titleAnnotation);
|
||||
Render<MapperType, CanvasType, ViewType>(view, outputFile);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user