Fix warning about initialization out of order in RenderSurface.h
C++ standard states that all class member variables are initialized in the order they are declared in the class. Thus, it is considered good C++ style to have their initialization listing in the constructor to match the actual order they are initialized. The compiler could give a warning otherwise. While I am at it, rename the member variables to be more aligned with VTK-m coding style (i.e. start with capital letter and be descriptive).
This commit is contained in:
parent
732a45ff3b
commit
ee73ab96a8
@ -35,12 +35,12 @@ class RenderSurface
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
RenderSurface(std::size_t w=1024, std::size_t h=1024,
|
||||
const vtkm::rendering::Color &c=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
|
||||
: width(w), height(h), bgColor(c)
|
||||
RenderSurface(std::size_t width=1024, std::size_t height=1024,
|
||||
const vtkm::rendering::Color &color=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
|
||||
: Width(width), Height(height), BackgroundColor(color)
|
||||
{
|
||||
rgba.resize(width*height*4);
|
||||
zbuff.resize(width*height*4);
|
||||
this->ColorBuffer.resize(width*height*4);
|
||||
this->DepthBuffer.resize(width*height);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
@ -65,16 +65,16 @@ public:
|
||||
virtual void AddLine(double, double,
|
||||
double, double,
|
||||
float,
|
||||
Color) {}
|
||||
virtual void AddColorBar(float, float,
|
||||
vtkm::rendering::Color) {}
|
||||
virtual void AddColorBar(float, float,
|
||||
float, float,
|
||||
const ColorTable &,
|
||||
const vtkm::rendering::ColorTable &,
|
||||
bool) {}
|
||||
|
||||
vtkm::rendering::Color bgColor;
|
||||
std::size_t width, height;
|
||||
std::vector<vtkm::Float32> rgba;
|
||||
std::vector<vtkm::Float32> zbuff;
|
||||
std::size_t Width, Height;
|
||||
vtkm::rendering::Color BackgroundColor;
|
||||
std::vector<vtkm::Float32> ColorBuffer;
|
||||
std::vector<vtkm::Float32> DepthBuffer;
|
||||
};
|
||||
|
||||
}} //namespace vtkm::rendering
|
||||
|
@ -45,7 +45,10 @@ public:
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Clear()
|
||||
{
|
||||
glClearColor(bgColor.Components[0],bgColor.Components[1],bgColor.Components[2], 1.0f);
|
||||
glClearColor(this->BackgroundColor.Components[0],
|
||||
this->BackgroundColor.Components[1],
|
||||
this->BackgroundColor.Components[2],
|
||||
1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
VTKM_CONT_EXPORT
|
||||
@ -151,12 +154,15 @@ public:
|
||||
virtual void SaveAs(const std::string &fileName)
|
||||
{
|
||||
std::ofstream of(fileName.c_str());
|
||||
of<<"P6"<<std::endl<<width<<" "<<height<<std::endl<<255<<std::endl;
|
||||
int hi = static_cast<int>(height);
|
||||
for (int i=hi-1; i>=0; i--)
|
||||
for (std::size_t j=0; j < width; j++)
|
||||
of << "P6" << std::endl
|
||||
<< this->Width << " " << this->Height <<std::endl
|
||||
<< 255 << std::endl;
|
||||
int height = static_cast<int>(this->Height);
|
||||
for (int yIndex=height-1; yIndex>=0; yIndex--)
|
||||
for (std::size_t xIndex=0; xIndex < this->Width; xIndex++)
|
||||
{
|
||||
const vtkm::Float32 *tuple = &(rgba[i*width*4 + j*4]);
|
||||
const vtkm::Float32 *tuple =
|
||||
&(this->ColorBuffer[yIndex*this->Width*4 + xIndex*4]);
|
||||
of<<(unsigned char)(tuple[0]*255);
|
||||
of<<(unsigned char)(tuple[1]*255);
|
||||
of<<(unsigned char)(tuple[2]*255);
|
||||
|
@ -50,34 +50,49 @@ public:
|
||||
ctx = OSMesaCreateContextExt(OSMESA_RGBA, 32, 0, 0, NULL);
|
||||
if (!ctx)
|
||||
throw vtkm::cont::ErrorControlBadValue("OSMesa context creation failed.");
|
||||
rgba.resize(width*height*4);
|
||||
if (!OSMesaMakeCurrent(ctx, &rgba[0], GL_FLOAT, static_cast<GLsizei>(width), static_cast<GLsizei>(height)))
|
||||
throw vtkm::cont::ErrorControlBadValue("OSMesa context activation failed.");
|
||||
this->ColorBuffer.resize(this->Width*this->Height*4);
|
||||
if (!OSMesaMakeCurrent(ctx,
|
||||
&this->ColorBuffer[0],
|
||||
GL_FLOAT,
|
||||
static_cast<GLsizei>(this->Width),
|
||||
static_cast<GLsizei>(this->Height)))
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue("OSMesa context activation failed.");
|
||||
}
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Clear()
|
||||
{
|
||||
glClearColor(bgColor.Components[0],bgColor.Components[1],bgColor.Components[2], 1.0f);
|
||||
glClearColor(this->BackgroundColor.Components[0],
|
||||
this->BackgroundColor.Components[1],
|
||||
this->BackgroundColor.Components[2],
|
||||
1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Finish()
|
||||
{
|
||||
RenderSurfaceGL::Finish();
|
||||
|
||||
|
||||
//Copy zbuff into floating point array.
|
||||
unsigned int *raw_zbuff;
|
||||
int zbytes, w, h;
|
||||
GLboolean ret;
|
||||
ret = OSMesaGetDepthBuffer(ctx, &w, &h, &zbytes, (void**)&raw_zbuff);
|
||||
if (!ret || static_cast<std::size_t>(w)!=width || static_cast<std::size_t>(h)!=height)
|
||||
if (!ret ||
|
||||
static_cast<std::size_t>(w)!=this->Width ||
|
||||
static_cast<std::size_t>(h)!=this->Height)
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue("Wrong width/height in ZBuffer");
|
||||
std::size_t npixels = width*height;
|
||||
}
|
||||
std::size_t npixels = this->Width*this->Height;
|
||||
for (std::size_t i=0; i<npixels; i++)
|
||||
zbuff[i] = float(raw_zbuff[i]) / float(UINT_MAX);
|
||||
{
|
||||
this->DepthBuffer[i] = float(raw_zbuff[i]) / float(UINT_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -37,12 +37,12 @@ class RenderSurfaceRayTracer : public RenderSurface
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
RenderSurfaceRayTracer(std::size_t w=1024, std::size_t h=1024,
|
||||
const vtkm::rendering::Color &c=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
|
||||
: RenderSurface(w,h,c)
|
||||
RenderSurfaceRayTracer(std::size_t width=1024, std::size_t height=1024,
|
||||
const vtkm::rendering::Color &color=vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
|
||||
: RenderSurface(width,height,color)
|
||||
{
|
||||
ColorBuffer = vtkm::cont::make_ArrayHandle(rgba);
|
||||
DepthBuffer = vtkm::cont::make_ArrayHandle(zbuff);
|
||||
this->ColorArray = vtkm::cont::make_ArrayHandle(this->ColorBuffer);
|
||||
this->DepthArray = vtkm::cont::make_ArrayHandle(this->DepthBuffer);
|
||||
}
|
||||
|
||||
class ClearBuffers : public vtkm::worklet::WorkletMapField
|
||||
@ -80,12 +80,13 @@ public:
|
||||
virtual void SaveAs(const std::string &fileName)
|
||||
{
|
||||
std::ofstream of(fileName.c_str());
|
||||
of<<"P6"<<std::endl<<width<<" "<<height<<std::endl<<255<<std::endl;
|
||||
int hi = static_cast<int>(height);
|
||||
for (int i=hi-1; i>=0; i--)
|
||||
for (std::size_t j=0; j < width; j++)
|
||||
{
|
||||
const vtkm::Float32 *tuple = &(rgba[i*width*4 + j*4]);
|
||||
of<<"P6"<<std::endl<<this->Width<<" "<<this->Height<<std::endl<<255<<std::endl;
|
||||
int height = static_cast<int>(this->Height);
|
||||
for (int yIndex=height-1; yIndex>=0; yIndex--)
|
||||
for (std::size_t xIndex=0; xIndex < this->Width; xIndex++)
|
||||
{
|
||||
const vtkm::Float32 *tuple =
|
||||
&(this->ColorBuffer[yIndex*this->Width*4 + xIndex*4]);
|
||||
of<<(unsigned char)(tuple[0]*255);
|
||||
of<<(unsigned char)(tuple[1]*255);
|
||||
of<<(unsigned char)(tuple[2]*255);
|
||||
@ -93,17 +94,18 @@ public:
|
||||
of.close();
|
||||
}
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Clear()
|
||||
virtual void Clear()
|
||||
{
|
||||
ColorBuffer = vtkm::cont::make_ArrayHandle(rgba);
|
||||
DepthBuffer = vtkm::cont::make_ArrayHandle(zbuff);
|
||||
vtkm::worklet::DispatcherMapField< ClearBuffers >( ClearBuffers( bgColor, width*height ) )
|
||||
.Invoke( DepthBuffer,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32>(ColorBuffer) );
|
||||
this->ColorArray = vtkm::cont::make_ArrayHandle(this->ColorBuffer);
|
||||
this->DepthArray = vtkm::cont::make_ArrayHandle(this->DepthBuffer);
|
||||
vtkm::worklet::DispatcherMapField< ClearBuffers >(
|
||||
ClearBuffers( this->BackgroundColor, this->Width*this->Height ) )
|
||||
.Invoke( this->DepthArray,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32>(this->ColorArray) );
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> ColorBuffer;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> DepthBuffer;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> ColorArray;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> DepthArray;
|
||||
|
||||
};
|
||||
|
||||
|
@ -429,8 +429,8 @@ public:
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"Camera can not write to NULL surface");
|
||||
}
|
||||
if(this->Height != vtkm::Int32(surface->height) ||
|
||||
this->Width != vtkm::Int32(surface->width))
|
||||
if(this->Height != vtkm::Int32(surface->Height) ||
|
||||
this->Width != vtkm::Int32(surface->Width))
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue("Camera: suface-view mismatched dims");
|
||||
}
|
||||
@ -443,12 +443,12 @@ public:
|
||||
this->SubsetWidth * this->SubsetHeight) )
|
||||
.Invoke( this->FrameBuffer,
|
||||
distances,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32>(surface->DepthBuffer),
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32>(surface->ColorBuffer) );
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32>(surface->DepthArray),
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32>(surface->ColorArray) );
|
||||
|
||||
//Force the transfer so the vectors contain data from device
|
||||
surface->ColorBuffer.GetPortalControl().Get(0);
|
||||
surface->DepthBuffer.GetPortalControl().Get(0);
|
||||
surface->ColorArray.GetPortalControl().Get(0);
|
||||
surface->DepthArray.GetPortalControl().Get(0);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
|
Loading…
Reference in New Issue
Block a user