mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Added structured
This commit is contained in:
parent
cca9b3dea9
commit
6ada07ea31
@ -58,7 +58,7 @@ class ColorTable
|
||||
protected:
|
||||
std::string uniquename;
|
||||
bool smooth;
|
||||
std::vector<ColorControlPoint> RBGPoints;
|
||||
std::vector<ColorControlPoint> RGBPoints;
|
||||
std::vector<AlphaControlPoint> AlphaPoints;
|
||||
typedef std::vector<AlphaControlPoint>::size_type AlphaType;
|
||||
typedef std::vector<ColorControlPoint>::size_type ColorType;
|
||||
@ -88,38 +88,38 @@ class ColorTable
|
||||
}
|
||||
Color MapRGB(vtkm::Float32 c) const
|
||||
{
|
||||
ColorType n = RBGPoints.size();
|
||||
ColorType n = RGBPoints.size();
|
||||
if (n == 0)
|
||||
return Color(0.5f, 0.5f, 0.5f);
|
||||
if (n == 1 || c <= RBGPoints[0].Position)
|
||||
return RBGPoints[0].RGBA;
|
||||
if (c >= RBGPoints[n - 1].Position)
|
||||
return RBGPoints[n - 1].RGBA;
|
||||
if (n == 1 || c <= RGBPoints[0].Position)
|
||||
return RGBPoints[0].RGBA;
|
||||
if (c >= RGBPoints[n - 1].Position)
|
||||
return RGBPoints[n - 1].RGBA;
|
||||
ColorType second;
|
||||
for (second = 1; second < n - 1; second++)
|
||||
{
|
||||
if (c < RBGPoints[second].Position)
|
||||
if (c < RGBPoints[second].Position)
|
||||
break;
|
||||
}
|
||||
ColorType first = second - 1;
|
||||
vtkm::Float32 seg = RBGPoints[second].Position-RBGPoints[first].Position;
|
||||
vtkm::Float32 seg = RGBPoints[second].Position-RGBPoints[first].Position;
|
||||
vtkm::Float32 alpha;
|
||||
if (seg == 0.f)
|
||||
alpha = .5f;
|
||||
else
|
||||
alpha = (c - RBGPoints[first].Position)/seg;
|
||||
alpha = (c - RGBPoints[first].Position)/seg;
|
||||
if (smooth)
|
||||
{
|
||||
return Color(RBGPoints[first].RGBA.Components[0] * (1.f-alpha) + RBGPoints[second].RGBA.Components[0] * alpha,
|
||||
RBGPoints[first].RGBA.Components[1] * (1.f-alpha) + RBGPoints[second].RGBA.Components[1] * alpha,
|
||||
RBGPoints[first].RGBA.Components[2] * (1.f-alpha) + RBGPoints[second].RGBA.Components[2] * alpha);
|
||||
return Color(RGBPoints[first].RGBA.Components[0] * (1.f-alpha) + RGBPoints[second].RGBA.Components[0] * alpha,
|
||||
RGBPoints[first].RGBA.Components[1] * (1.f-alpha) + RGBPoints[second].RGBA.Components[1] * alpha,
|
||||
RGBPoints[first].RGBA.Components[2] * (1.f-alpha) + RGBPoints[second].RGBA.Components[2] * alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (alpha < .5)
|
||||
return RBGPoints[first].RGBA;
|
||||
return RGBPoints[first].RGBA;
|
||||
else
|
||||
return RBGPoints[second].RGBA;
|
||||
return RGBPoints[second].RGBA;
|
||||
}
|
||||
|
||||
}
|
||||
@ -165,29 +165,32 @@ class ColorTable
|
||||
{
|
||||
}
|
||||
ColorTable(const ColorTable &ct) :
|
||||
uniquename(ct.uniquename), smooth(ct.smooth), RBGPoints(ct.RBGPoints.begin(), ct.RBGPoints.end())
|
||||
uniquename(ct.uniquename),
|
||||
smooth(ct.smooth),
|
||||
RGBPoints(ct.RGBPoints.begin(), ct.RGBPoints.end()),
|
||||
AlphaPoints(ct.AlphaPoints.begin(), ct.AlphaPoints.end())
|
||||
{
|
||||
}
|
||||
void operator=(const ColorTable &ct)
|
||||
{
|
||||
uniquename = ct.uniquename;
|
||||
smooth = ct.smooth;
|
||||
RBGPoints.clear();
|
||||
RBGPoints.insert(RBGPoints.end(), ct.RBGPoints.begin(), ct.RBGPoints.end());
|
||||
RGBPoints.clear();
|
||||
RGBPoints.insert(RGBPoints.end(), ct.RGBPoints.begin(), ct.RGBPoints.end());
|
||||
AlphaPoints.insert(AlphaPoints.end(), ct.AlphaPoints.begin(), ct.AlphaPoints.end());
|
||||
}
|
||||
void Clear()
|
||||
{
|
||||
RBGPoints.clear();
|
||||
RGBPoints.clear();
|
||||
AlphaPoints.clear();
|
||||
}
|
||||
void AddControlPoint(vtkm::Float32 position, Color color)
|
||||
{
|
||||
RBGPoints.push_back(ColorControlPoint(position, color));
|
||||
RGBPoints.push_back(ColorControlPoint(position, color));
|
||||
}
|
||||
void AddControlPoint(vtkm::Float32 position, Color color, vtkm::Float32 alpha)
|
||||
{
|
||||
RBGPoints.push_back(ColorControlPoint(position, color));
|
||||
RGBPoints.push_back(ColorControlPoint(position, color));
|
||||
AlphaPoints.push_back(AlphaControlPoint(position, alpha));
|
||||
}
|
||||
void AddAlphaControlPoint(vtkm::Float32 position, vtkm::Float32 alpha)
|
||||
@ -197,7 +200,7 @@ class ColorTable
|
||||
void Reverse()
|
||||
{
|
||||
// copy old control points
|
||||
std::vector<ColorControlPoint> tmp(RBGPoints.begin(), RBGPoints.end());
|
||||
std::vector<ColorControlPoint> tmp(RGBPoints.begin(), RGBPoints.end());
|
||||
std::vector<AlphaControlPoint> tmpAlpha(AlphaPoints.begin(), AlphaPoints.end());
|
||||
Clear();
|
||||
vtkm::Int32 vectorSize = vtkm::Int32(tmp.size());
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <vtkm/rendering/ColorTable.h>
|
||||
#include <vtkm/rendering/Triangulator.h>
|
||||
#include <vtkm/rendering/SceneRenderer.h>
|
||||
#include <vtkm/rendering/raytracing/VolumeRendererUniform.h>
|
||||
#include <vtkm/rendering/raytracing/VolumeRendererStructured.h>
|
||||
#include <vtkm/rendering/raytracing/Camera.h>
|
||||
#include <vtkm/rendering/RenderSurfaceRayTracer.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
@ -36,7 +36,7 @@ template<typename DeviceAdapter = VTKM_DEFAULT_DEVICE_ADAPTER_TAG>
|
||||
class SceneRendererVolume : public SceneRenderer
|
||||
{
|
||||
protected:
|
||||
vtkm::rendering::raytracing::VolumeRendererUniform<DeviceAdapter> Tracer;
|
||||
vtkm::rendering::raytracing::VolumeRendererStructured<DeviceAdapter> Tracer;
|
||||
RenderSurfaceRayTracer *Surface;
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
|
@ -19,11 +19,14 @@
|
||||
##============================================================================
|
||||
|
||||
set(headers
|
||||
BoundingVolumeHierarchy.h
|
||||
Camera.h
|
||||
RayTracer,h
|
||||
RayTracingTypeDefs.h
|
||||
Ray.h
|
||||
TriangleIntersector.h
|
||||
Worklets.h
|
||||
VolumeRendererUniform.h
|
||||
VolumeRendererStructured.h
|
||||
)
|
||||
|
||||
vtkm_declare_headers(${headers})
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef vtk_m_rendering_raytracing_VolumeRendererUniform_h
|
||||
#define vtk_m_rendering_raytracing_VolumeRendererUniform_h
|
||||
#ifndef vtk_m_rendering_raytracing_VolumeRendererStructured_h
|
||||
#define vtk_m_rendering_raytracing_VolumeRendererStructured_h
|
||||
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
@ -18,7 +18,7 @@ namespace rendering{
|
||||
namespace raytracing{
|
||||
|
||||
template< typename DeviceAdapter>
|
||||
class VolumeRendererUniform
|
||||
class VolumeRendererStructured
|
||||
{
|
||||
public:
|
||||
typedef vtkm::cont::ArrayHandle<vtkm::FloatDefault> DefaultHandle;
|
||||
@ -281,7 +281,6 @@ public:
|
||||
InvSpacing[2] = 1.f / spacing[2];
|
||||
if((maxScalar - minScalar) != 0.f) InverseDeltaScalar = 1.f / (maxScalar - minScalar);
|
||||
else InverseDeltaScalar = minScalar;
|
||||
std::cout<<" max and min "<<maxScalar<<" "<<minScalar<<" "<<InverseDeltaScalar<<std::endl;
|
||||
}
|
||||
typedef void ControlSignature(FieldIn<>,
|
||||
FieldIn<>,
|
||||
@ -376,7 +375,6 @@ public:
|
||||
//advance
|
||||
currentDistance += SampleDistance;
|
||||
|
||||
//std::cout<<" current color "<<color;
|
||||
if(color[3] >= 1.f) break;
|
||||
tx = (sampleLocation[0] - bottomLeft[0]) * InvSpacing[0];
|
||||
ty = (sampleLocation[1] - bottomLeft[1]) * InvSpacing[1];
|
||||
@ -687,7 +685,7 @@ class SamplerCellAssocRect : public vtkm::worklet::WorkletMapField
|
||||
const vtkm::Float32 &maxDistance,
|
||||
vtkm::Vec<vtkm::Float32,4> &color,
|
||||
ScalarPortalType &scalars) const
|
||||
{ std::cout<<"Here\n";
|
||||
{
|
||||
color[0] = 0.f;
|
||||
color[1] = 0.f;
|
||||
color[2] = 0.f;
|
||||
@ -785,8 +783,7 @@ class SamplerCellAssocRect : public vtkm::worklet::WorkletMapField
|
||||
vtkm::Id colorIndex = vtkm::Id(finalScalar * ColorMapSize);
|
||||
//colorIndex = vtkm::Min(ColorMapSize, vtkm::Max(0,colorIndex));
|
||||
vtkm::Vec<vtkm::Float32,4> sampleColor = ColorMap.Get(colorIndex);
|
||||
//sampleColor[3] = .05f;
|
||||
|
||||
|
||||
//composite
|
||||
sampleColor[3] *= (1.f - color[3]);
|
||||
color[0] = color[0] + sampleColor[0] * sampleColor[3];
|
||||
@ -906,7 +903,7 @@ class SamplerCellAssocRect : public vtkm::worklet::WorkletMapField
|
||||
}; //class CompositeBackground
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
VolumeRendererUniform()
|
||||
VolumeRendererStructured()
|
||||
{
|
||||
IsSceneDirty = false;
|
||||
IsUniformDataSet = true;
|
||||
@ -979,7 +976,7 @@ class SamplerCellAssocRect : public vtkm::worklet::WorkletMapField
|
||||
bool isAssocPoints = ScalarField->GetAssociation() == vtkm::cont::Field::ASSOC_POINTS;
|
||||
if(IsUniformDataSet)
|
||||
{
|
||||
std::cout<<"DDDDDDDDDD\n";
|
||||
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates vertices;
|
||||
vertices = Coordinates.Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>();
|
||||
if(isAssocPoints)
|
||||
@ -1015,7 +1012,7 @@ class SamplerCellAssocRect : public vtkm::worklet::WorkletMapField
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"XXXXXXXXXXXX\n";
|
||||
|
||||
CartesianArrayHandle vertices;
|
||||
vertices = Coordinates.Cast<CartesianArrayHandle>();
|
||||
if(isAssocPoints)
|
||||
@ -1076,7 +1073,6 @@ protected:
|
||||
bool IsUniformDataSet;
|
||||
VolumeRay<DeviceAdapter> Rays;
|
||||
Camera<DeviceAdapter> camera;
|
||||
//vtkm::cont::ArrayHandleUniformPointCoordinates Coordinates;
|
||||
vtkm::cont::DynamicArrayHandleCoordinateSystem Coordinates;
|
||||
vtkm::cont::CellSetStructured<3> Cellset;
|
||||
vtkm::cont::Field *ScalarField;
|
@ -72,14 +72,18 @@ void Render(const vtkm::cont::DataSet &ds,
|
||||
|
||||
vtkm::rendering::View view;
|
||||
Set3DView(view, coords, W, H);
|
||||
|
||||
|
||||
vtkm::rendering::ColorTable colorTable(ctName);
|
||||
colorTable.AddAlphaControlPoint(0.0f, .01f);
|
||||
colorTable.AddAlphaControlPoint(1.0f, .01f);
|
||||
|
||||
vtkm::rendering::Scene3D scene;
|
||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
vtkm::rendering::RenderSurfaceRayTracer surface(W,H,bg);
|
||||
scene.plots.push_back(vtkm::rendering::Plot(ds.GetCellSet(),
|
||||
ds.GetCoordinateSystem(),
|
||||
ds.GetField(fieldNm),
|
||||
vtkm::rendering::ColorTable(ctName)));
|
||||
colorTable));
|
||||
|
||||
//TODO: W/H in window. bg in window (window sets surface/renderer).
|
||||
vtkm::rendering::Window3D<vtkm::rendering::SceneRendererVolume<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>,
|
||||
|
Loading…
Reference in New Issue
Block a user