Commit 89958f0d authored by Ken Martin's avatar Ken Martin
Browse files

Initial revision

parent f35b6a51
/*=========================================================================
Program: Visualization Library
Module: SbrCam.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#ifndef __vlSbrCamera_hh
#define __vlSbrCamera_hh
#include "Camera.hh"
#include "starbase.c.h"
class vlSbrRenderer;
class vlSbrCamera : public vlCamera
{
public:
virtual char *GetClassName() {return "vlSbrCamera";};
void Render(vlRenderer *ren); // overides base
void Render(vlSbrRenderer *ren); // real function
};
#endif
/*=========================================================================
Program: Visualization Library
Module: SbrLgt.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#ifndef __vlSbrLight_hh
#define __vlSbrLight_hh
#include "Light.hh"
#include "kgl.h"
class vlSbrRenderer;
class vlSbrLight : public vlLight
{
protected:
public:
char *GetClassName() {return "vlSbrLight";};
void Render(vlRenderer *ren,int light_index); // overides base
void Render(vlSbrRenderer *ren,int light_index); // real function
};
#endif
/*=========================================================================
Program: Visualization Library
Module: SbrProp.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#ifndef __vlSbrProperty_hh
#define __vlSbrProperty_hh
#include "Property.hh"
class vlSbrRenderer;
class vlSbrProperty : public vlProperty
{
public:
char *GetClassName() {return "vlSbrProperty";};
void Render(vlRenderer *ren); // overides base
void Render(vlSbrRenderer *ren);
};
#endif
/*=========================================================================
Program: Visualization Library
Module: SbrRen.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#ifndef __vlSbrRenderer_hh
#define __vlSbrRenderer_hh
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "Renderer.hh"
#include "starbase.c.h"
class vlSbrRenderer : public vlRenderer
{
protected:
int NumberOfLightsBound;
int LightSwitch;
int Fd;
public:
vlSbrRenderer();
void Render(void); // overides base
char *GetClassName() {return "vlSbrRenderer";};
void PrintSelf(ostream& os, vlIndent indent);
vlGeometryPrimitive *GetPrimitive(char *);
void ClearLights(void);
int UpdateActors(void);
int UpdateCameras(void);
int UpdateLights(void);
vlGetMacro(Fd,int);
vlGetMacro(LightSwitch,int);
};
#endif
/*=========================================================================
Program: Visualization Library
Module: SbrRenW.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#ifndef __vlSbrRenderWindow_hh
#define __vlSbrRenderWindow_hh
#include <stdlib.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "RenderW.hh"
class vlSbrRenderWindow : public vlRenderWindow
{
protected:
Window WindowId;
Window NextWindowId;
Display *DisplayId;
Colormap ColorMap;
int Fd;
int Buffer;
int ScreenSize[2];
int OwnWindow;
public:
vlSbrRenderWindow();
char *GetClassName() {return "vlSbrRenderWindow";};
void PrintSelf(ostream& os, vlIndent indent);
vlRenderer *MakeRenderer();
vlActor *MakeActor();
vlLight *MakeLight();
vlCamera *MakeCamera();
void Start(void);
void Frame(void);
void WindowInitialize(void);
void Initialize(void);
virtual void SetFullScreen(int);
void WindowRemap(void);
void PrefFullScreen(void);
int *GetPosition();
int *GetSize();
int *GetScreenSize();
void SetSize(int,int);
vlGetMacro(Fd,int);
// Xwindow get set functions
Display *GetDisplayId();
void SetDisplayId(Display *);
Window GetWindowId();
void SetWindowId(Window);
int GetDesiredDepth();
Colormap GetDesiredColormap();
Visual *GetDesiredVisual();
int CreateXWindow(Display *,int x,int y,int w,int h,int depth,
char name[80]);
};
#endif
/*=========================================================================
Program: Visualization Library
Module: SbrCam.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include <math.h>
#include "SbrCam.hh"
#include "SbrRenW.hh"
#include "SbrRen.hh"
static float xform[4][4] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
// typecast if neccessary
void vlSbrCamera::Render(vlRenderer *ren)
{
this->Render((vlSbrRenderer *)ren);
}
// set the appropriate attributes in Sbr for this camera
//
void vlSbrCamera::Render(vlSbrRenderer *ren)
{
float aspect[3];
float *viewport;
float *background;
int width,height;
long clr;
int left,right,bottom,top;
long xmax,ymax,zmax;
float twist;
int stereo;
int fd;
camera_arg cam;
int *size;
int *screen_size;
vlSbrRenderWindow *rw;
fd = ren->GetFd();
// find out if we should stereo render
stereo = ren->GetStereoRender();
// set up the view specification
cam.field_of_view = this->ViewAngle;
cam.front = this->ClippingRange[0] - this->Distance;
cam.back = this->ClippingRange[1] - this->Distance;
cam.camx = this->Position[0];
cam.camy = this->Position[1];
cam.camz = this->Position[2];
cam.refx = this->FocalPoint[0];
cam.refy = this->FocalPoint[1];
cam.refz = this->FocalPoint[2];
cam.upx = this->ViewUp[0];
cam.upy = this->ViewUp[1];
cam.upz = this->ViewUp[2];
cam.projection = CAM_PERSPECTIVE;
// set this renderer's viewport, must turn off z-buffering when changing
// viewport
hidden_surface(fd, FALSE, FALSE);
vlDebugMacro(<< " SB_hidden_surface: False False\n");
viewport = ren->GetViewport();
// get the background color
background = ren->GetBackground();
// get size info
rw = (vlSbrRenderWindow*)(ren->GetRenderWindow());
size = rw->GetSize();
screen_size = rw->GetScreenSize();
// make sure the aspect is up to date
if (size[0] > size[1])
{
aspect[0] = size[0]/size[1];
aspect[1] = 1.0;
}
else
{
aspect[0] = 1.0;
aspect[1] = size[1]/size[0];
}
ren->SetAspect(aspect);
vdc_extent(fd,0.0,-screen_size[1]/size[1]+1.0,0.0,
screen_size[0]/size[0],1.0,1.0);
// set viewport to clear entire window
view_port(fd, viewport[0], viewport[1],
viewport[2], viewport[3]);
hidden_surface(fd, TRUE, FALSE);
vlDebugMacro(<< " SB_hidden_surface: True False\n");
// Set the background color and clear the display.
// Since clear control was set to clear z buffer, this is done here
// also.
background_color(fd, background[0], background[1], background[2]);
// clear the view surface so the new background color takes effect
if (ren->GetErase())
{
clear_view_surface(fd);
vlDebugMacro(<< " SB_clear_view_surface\n");
}
hidden_surface(fd, FALSE, FALSE);
vlDebugMacro(<< " SB_hidden_surface: False False\n");
vdc_extent(fd,0.0,-screen_size[1]/size[1]+1.0,0.0,
screen_size[0]/size[0],1.0,1.0);
view_port(fd, viewport[0], viewport[1],
viewport[2], viewport[3]);
hidden_surface(fd, TRUE, FALSE);
vlDebugMacro(<< " SB_hidden_surface: True False\n");
// install the camera
view_camera(fd, &cam);
// now handle the anisotropy
xform[0][0] = 1.0/aspect[0];
xform[1][1] = 1.0/aspect[1];
xform[3][1] = (1.0 - xform[1][1])/2.0;
xform[3][0] = (1.0 - xform[0][0])/2.0;
view_matrix3d(fd, xform, POST_CONCAT_VW);
// if we have a stereo renderer, draw other eye next time
if (stereo)
{
if (this->LeftEye) this->LeftEye = 0;
else this->LeftEye = 1;
}
}
/*=========================================================================
Program: Visualization Library
Module: SbrLgt.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include <math.h>
#include "SbrLgt.hh"
#include "SbrRen.hh"
// typecast if neccessary
void vlSbrLight::Render(vlRenderer *ren,int light_index)
{
this->Render((vlSbrRenderer *)ren,light_index);
}
// set the appropriate attributes in Sbr for this light
void vlSbrLight::Render(vlSbrRenderer *ren,int light_index)
{
float dx, dy, dz;
float color[3];
int light_flag;
int fd;
light_flag = ren->GetLightSwitch();
fd = ren->GetFd();
// get required info from light
color[0] = this->Intensity * this->Color[0];
color[1] = this->Intensity * this->Color[1];
color[2] = this->Intensity * this->Color[2];
dx = this->Position[0] - this->FocalPoint[0];
dy = this->Position[1] - this->FocalPoint[1];
dz = this->Position[2] - this->FocalPoint[2];
// define the light source
light_source(fd, light_index, DIRECTIONAL,
color[0], color[1], color[2],
dx, dy, dz);
light_flag |= (0x0001 << light_index);
vlDebugMacro(<< "Defining front light\n");
// define another mirror light if backlit is on
if (ren->GetBackLight())
{
light_index++;
light_source(fd, light_index, DIRECTIONAL,
color[0], color[1], color[2],
-dx, -dy, -dz);
vlDebugMacro(<< "Defining back light\n");
light_flag |= (0x0001 << light_index);
}
// update the light switch
light_switch(fd, light_flag);
vlDebugMacro(<< "SB_light_switch: " << light_flag << "\n");
}
/*=========================================================================
Program: Visualization Library
Module: SbrProp.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include <math.h>
#include "SbrProp.hh"
#include "SbrRen.hh"
#include "SbrPrim.hh"
#include "starbase.c.h"
// typecast if neccessary
void vlSbrProperty::Render(vlRenderer *ren)
{
this->Render((vlSbrRenderer *)ren);
}
// set the appropriate attributes in Sbr for this property
void vlSbrProperty::Render(vlSbrRenderer *ren)
{
int fd;
float *edge_color;
int style;
int shininess;
int trans_level;
static int pattern[16] = {0,10,8,2,5,15,13,7,4,14,12,6,1,11,9,3};
gescape_arg esc_arg1,esc_arg2;
int l;
fd = ren->GetFd();
if (this->EdgeVisibility)
{
edge_color = this->EdgeColor;
}
else
{
edge_color = this->DiffuseColor;
}
line_color(fd, this->DiffuseColor[0], this->DiffuseColor[1],
this->DiffuseColor[2]);
fill_color(fd, this->DiffuseColor[0], this->DiffuseColor[1],
this->DiffuseColor[2]);
perimeter_color(fd, EdgeColor[0], EdgeColor[1],
EdgeColor[2]);
text_color(fd, this->DiffuseColor[0], this->DiffuseColor[1],
this->DiffuseColor[2]);
marker_color(fd,this->DiffuseColor[0], this->DiffuseColor[1],
this->DiffuseColor[2]);
// Tell the geometry primitives about the default properties
vlSbrPrimitive::SetProperty(this);
switch (this->Representation)
{
case VL_POINTS:
style = INT_POINT;
break;
case VL_WIREFRAME:
style = INT_OUTLINE;
break;
case VL_SURFACE:
style = INT_SOLID;
break;
default:
style = INT_SOLID;
break;
}
interior_style(fd, style, this->EdgeVisibility);
surface_coefficients(fd, this->Ambient, this->Diffuse, this->Specular);
shininess = (int)this->SpecularPower;
if (shininess < 1) shininess = 1;
if (shininess > 16383) shininess = 16383;
surface_model(fd, TRUE, shininess,
this->SpecularColor[0],this->SpecularColor[1],
this->SpecularColor[2]);
trans_level = (int)(16.0*(1.0 - this->Transparency));
esc_arg1.i[0] = 0x0000;
for (l = 0; l < trans_level; l++)
esc_arg1.i[0] |= (0x0001 << pattern[l]);
esc_arg1.i[0] = ~esc_arg1.i[0];
gescape(fd, TRANSPARENCY, &esc_arg1, &esc_arg2);
}
/*=========================================================================
Program: Visualization Library
Module: SbrRen.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include <math.h>
#include <iostream.h>
#include "SbrProp.hh"
#include "SbrCam.hh"
#include "SbrLgt.hh"
#include "SbrRenW.hh"
#include "SbrRen.hh"
#include "SbrPoly.hh"
#include "SbrTri.hh"
#include "SbrLine.hh"
#include "SbrPnt.hh"
#define MAX_LIGHTS 16
/* stereo definitions : also in starbase_camera.cls */
static char *lights[MAX_LIGHTS] =
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
vlSbrRenderer::vlSbrRenderer()
{
}
int vlSbrRenderer::UpdateActors()
{
vlActor *anActor;
float visibility;
vlMatrix4x4 matrix;
int num;
int count = 0;
// loop through actors
for (num = 0; num < this->Actors.GetNumberOfMembers(); num++)
{
anActor = this->Actors.GetMember(num);
// if it's invisible, we can skip the rest
visibility = anActor->GetVisibility();
if (visibility == 1.0)
{
count++;
// build transformation
matrix = anActor->GetMatrix();
matrix.Transpose();
// insert model transformation
concat_transformation3d(this->Fd,(float (*)[4])(matrix[0]), PRE, PUSH);
anActor->Render((vlRenderer *)this);
pop_matrix(this->Fd);
}
}
return count;
}
int vlSbrRenderer::UpdateCameras ()
{
// update the viewing transformation
if (!this->ActiveCamera) return 0;
this->ActiveCamera->Render((vlRenderer *)this);
return 1;
}
void vlSbrRenderer::ClearLights (void)
{
light_ambient(this->Fd, this->Ambient[0],
this->Ambient[1], this->Ambient[2]);
this->LightSwitch = 0x0001;
vlDebugMacro(<< "SB_light_ambient: " << this->Ambient[0] << " " <<
this->Ambient[1] << " " << this->Ambient[2] << "