Commit fe8945b0 authored by Michalel Halle's avatar Michalel Halle

Added anaglyph mode (superset of red-blue) to vtkRenderWindow

parent cbca797a
......@@ -31,7 +31,7 @@
#define id Id // since id is a reserved token in ObjC and is used a _lot_ in vtk
vtkCxxRevisionMacro(vtkCocoaRenderWindow, "1.18");
vtkCxxRevisionMacro(vtkCocoaRenderWindow, "1.19");
vtkStandardNewMacro(vtkCocoaRenderWindow);
......@@ -335,6 +335,15 @@ void vtkCocoaRenderWindow::StereoUpdate(void)
case VTK_STEREO_RED_BLUE:
this->StereoStatus = 1;
break;
case VTK_STEREO_ANAGLYPH:
this->StereoStatus = 1;
break;
case VTK_STEREO_DRESDEN:
this->StereoStatus = 1;
break;
case VTK_STEREO_INTERLACED:
this->StereoStatus = 1;
break;
}
}
else if ((!this->StereoRender) && this->StereoStatus)
......@@ -347,6 +356,15 @@ void vtkCocoaRenderWindow::StereoUpdate(void)
case VTK_STEREO_RED_BLUE:
this->StereoStatus = 0;
break;
case VTK_STEREO_ANAGLYPH:
this->StereoStatus = 0;
break;
case VTK_STEREO_DRESDEN:
this->StereoStatus = 0;
break;
case VTK_STEREO_INTERLACED:
this->StereoStatus = 0;
break;
}
}
}
......
......@@ -26,7 +26,7 @@
#include "vtkUnsignedCharArray.h"
#ifndef VTK_IMPLEMENT_MESA_CXX
vtkCxxRevisionMacro(vtkOpenGLRenderWindow, "1.65");
vtkCxxRevisionMacro(vtkOpenGLRenderWindow, "1.66");
#endif
#define MAX_LIGHTS 8
......@@ -70,13 +70,20 @@ void vtkOpenGLRenderWindow::StereoUpdate(void)
switch (this->StereoType)
{
case VTK_STEREO_CRYSTAL_EYES:
{
}
// not clear this is supposed to be empty,
// but it has been that way forever.
break;
case VTK_STEREO_RED_BLUE:
{
this->StereoStatus = 1;
}
break;
case VTK_STEREO_ANAGLYPH:
this->StereoStatus = 1;
break;
case VTK_STEREO_DRESDEN:
this->StereoStatus = 1;
break;
case VTK_STEREO_INTERLACED:
this->StereoStatus = 1;
}
}
else if ((!this->StereoRender) && this->StereoStatus)
......@@ -84,14 +91,20 @@ void vtkOpenGLRenderWindow::StereoUpdate(void)
switch (this->StereoType)
{
case VTK_STEREO_CRYSTAL_EYES:
{
this->StereoStatus = 0;
}
break;
case VTK_STEREO_RED_BLUE:
{
this->StereoStatus = 0;
}
break;
case VTK_STEREO_ANAGLYPH:
this->StereoStatus = 0;
break;
case VTK_STEREO_DRESDEN:
this->StereoStatus = 0;
break;
case VTK_STEREO_INTERLACED:
this->StereoStatus = 0;
break;
}
}
}
......
......@@ -22,7 +22,7 @@
#include "vtkRendererCollection.h"
#include "vtkTransform.h"
vtkCxxRevisionMacro(vtkRenderWindow, "1.140");
vtkCxxRevisionMacro(vtkRenderWindow, "1.141");
//----------------------------------------------------------------------------
// Needed when we don't use the vtkStandardNewMacro.
......@@ -66,6 +66,9 @@ vtkRenderWindow::vtkRenderWindow()
this->Renderers = vtkRendererCollection::New();
this->NumberOfLayers = 1;
this->CurrentCursor = VTK_CURSOR_DEFAULT;
this->AnaglyphColorSaturation = 0.65;
this->AnaglyphColorMask[0] = 4; // red
this->AnaglyphColorMask[1] = 3; // cyan
}
vtkRenderWindow::~vtkRenderWindow()
......@@ -722,6 +725,9 @@ void vtkRenderWindow::StereoUpdate(void)
case VTK_STEREO_RED_BLUE:
this->StereoStatus = 1;
break;
case VTK_STEREO_ANAGLYPH:
this->StereoStatus = 1;
break;
case VTK_STEREO_DRESDEN:
this->StereoStatus = 1;
break;
......@@ -736,6 +742,9 @@ void vtkRenderWindow::StereoUpdate(void)
case VTK_STEREO_RED_BLUE:
this->StereoStatus = 0;
break;
case VTK_STEREO_ANAGLYPH:
this->StereoStatus = 0;
break;
case VTK_STEREO_DRESDEN:
this->StereoStatus = 0;
break;
......@@ -758,7 +767,8 @@ void vtkRenderWindow::StereoMidpoint(void)
}
if ((this->StereoType == VTK_STEREO_RED_BLUE) ||
(this->StereoType == VTK_STEREO_INTERLACED) ||
(this->StereoType == VTK_STEREO_DRESDEN) )
(this->StereoType == VTK_STEREO_DRESDEN) ||
(this->StereoType == VTK_STEREO_ANAGLYPH))
{
int *size;
// get the size
......@@ -821,6 +831,90 @@ void vtkRenderWindow::StereoRenderComplete(void)
delete [] buff;
}
break;
case VTK_STEREO_ANAGLYPH:
{
unsigned char *buff;
unsigned char *p0, *p1, *p2;
unsigned char* result;
int *size;
int x,y;
int res;
int m0, m1, ave0, ave1;
int avecolor[256][3], satcolor[256];
float a;
// get the size
size = this->GetSize();
// get the data
buff = this->GetPixelData(0,0,size[0]-1,size[1]-1,!this->DoubleBuffer);
p0 = this->StereoBuffer;
p1 = buff;
// allocate the result
result = new unsigned char [size[0]*size[1]*3];
if (!result)
{
vtkErrorMacro(<<"Couldn't allocate memory for ANAGLYPH stereo.");
return;
}
p2 = result;
// build some tables
a = this->AnaglyphColorSaturation;
m0 = this->AnaglyphColorMask[0];
m1 = this->AnaglyphColorMask[1];
for(x = 0; x < 256; x++)
{
avecolor[x][0] = int((1.0-a)*x*0.3086);
avecolor[x][1] = int((1.0-a)*x*0.6094);
avecolor[x][2] = int((1.0-a)*x*0.0820);
satcolor[x] = int(a*x);
}
// now merge the two images
for (x = 0; x < size[0]; x++)
{
for (y = 0; y < size[1]; y++)
{
ave0 = avecolor[p0[0]][0] + avecolor[p0[1]][1] + avecolor[p0[2]][2];
ave1 = avecolor[p1[0]][0] + avecolor[p1[1]][1] + avecolor[p1[2]][2];
if (m0 & 0x4)
{
p2[0] = satcolor[p0[0]] + ave0;
}
if (m0 & 0x2)
{
p2[1] = satcolor[p0[1]] + ave0;
}
if (m0 & 0x1)
{
p2[2] = satcolor[p0[2]] + ave0;
}
if (m1 & 0x4)
{
p2[0] = satcolor[p1[0]] + ave1;
}
if (m1 & 0x2)
{
p2[1] = satcolor[p1[1]] + ave1;
}
if (m1 & 0x1)
{
p2[2] = satcolor[p1[2]] + ave1;
}
p0 += 3;
p1 += 3;
p2 += 3;
}
}
this->ResultFrame = result;
delete [] this->StereoBuffer;
this->StereoBuffer = NULL;
delete [] buff;
}
break;
case VTK_STEREO_INTERLACED:
{
unsigned char *buff;
......
......@@ -53,6 +53,7 @@ class vtkUnsignedCharArray;
#define VTK_STEREO_LEFT 4
#define VTK_STEREO_RIGHT 5
#define VTK_STEREO_DRESDEN 6
#define VTK_STEREO_ANAGLYPH 7
#define VTK_CURSOR_DEFAULT 0
#define VTK_CURSOR_ARROW 1
......@@ -187,7 +188,19 @@ public:
vtkBooleanMacro(PolygonSmoothing,int);
// Description:
// Set/Get what type of stereo rendering to use.
// Set/Get what type of stereo rendering to use. CrystalEyes
// mode uses frame-sequential capabilities available in OpenGL
// to drive LCD shutter glasses and stereo projectors. RedBlue
// mode is a simple type of stereo for use with red-blue glasses.
// Anaglyph mode is a superset of RedBlue mode, but the color
// output channels can be configured using the AnaglyphColorMask
// and the color of the original image can be (somewhat) maintained
// using AnaglyphColorSaturation; the default colors for Anaglyph
// mode is red-cyan. Interlaced stereo mode produces a composite
// image where horizontal lines alternate between left and right
// views. StereoLeft and StereoRight modes choose one or the other
// stereo view. Dresden mode is yet another stereoscopic
// interleaving.
vtkGetMacro(StereoType,int);
vtkSetMacro(StereoType,int);
void SetStereoTypeToCrystalEyes()
......@@ -202,6 +215,8 @@ public:
{this->SetStereoType(VTK_STEREO_RIGHT);};
void SetStereoTypeToDresden()
{this->SetStereoType(VTK_STEREO_DRESDEN);};
void SetStereoTypeToAnaglyph()
{this->SetStereoType(VTK_STEREO_ANAGLYPH);};
char *GetStereoTypeAsString();
// Description:
......@@ -219,6 +234,31 @@ public:
// stereo rendering.
virtual void StereoRenderComplete();
//Description:
// Set/get the anaglyph color saturation factor. This number ranges from
// 0.0 to 1.0: 0.0 means that no color from the original object is
// maintained, 1.0 means all of the color is maintained. The default
// value is 0.65. Too much saturation can produce uncomfortable 3D
// viewing because anaglyphs also use color to encode 3D.
vtkSetClampMacro(AnaglyphColorSaturation,float, 0.0, 1.0);
vtkGetMacro(AnaglyphColorSaturation,float);
//Description:
// Set/get the anaglyph color mask values. These two numbers are bits
// mask that control which color channels of the original stereo
// images are used to produce the final anaglyph image. The first
// value is the color mask for the left view, the second the mask
// for the right view. If a bit in the mask is on for a particular
// color for a view, that color is passed on to the final view; if
// it is not set, that channel for that view is ignored.
// The bits are arranged as r, g, and b, so r = 4, g = 2, and b = 1.
// By default, the first value (the left view) is set to 4, and the
// second value is set to 3. That means that the red output channel
// comes from the left view, and the green and blue values come from
// the right view.
vtkSetVector2Macro(AnaglyphColorMask,int);
vtkGetVectorMacro(AnaglyphColorMask,int,2);
// Description:
// Remap the rendering window. This probably only works on UNIX right now.
// It is useful for changing properties that can't normally be changed
......@@ -442,6 +482,8 @@ protected:
int NumberOfLayers;
int CurrentCursor;
int IsPicking;
float AnaglyphColorSaturation;
int AnaglyphColorMask[2];
private:
vtkRenderWindow(const vtkRenderWindow&); // Not implemented.
......@@ -464,11 +506,11 @@ inline char *vtkRenderWindow::GetStereoTypeAsString(void)
return (char *)"Right";
case VTK_STEREO_DRESDEN:
return (char *)"DresdenDisplay";
case VTK_STEREO_ANAGLYPH:
return (char *)"Anaglyph";
default:
return (char *)"";
}
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment