Skip to content

Commit

Permalink
Changed instrument lighting to see components better.
Browse files Browse the repository at this point in the history
Re #6137.
  • Loading branch information
mantid-roman committed Mar 4, 2013
1 parent 3894c8f commit 3063563
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Qt::CursorShape cursorShape = Qt::ArrowCursor;
MantidGLWidget::MantidGLWidget(QWidget* parent):
QGLWidget(QGLFormat(QGL::DepthBuffer|QGL::NoAlphaChannel),parent),
//m_polygonMode(SOLID),
m_lightingState(0),
//m_lightingState(0),
m_isKeyPressed(false),
m_firstFrame(true)
{
Expand Down Expand Up @@ -277,16 +277,14 @@ void MantidGLWidget::resetWidget()
}

/**
* Enables / disables lighting
* Enables / disables lighting on the surfaces that support it.
* @param on :: Set true to turn lighting on or false to turn it off.
*/
void MantidGLWidget::enableLighting(bool on)
{
auto surface3D = boost::dynamic_pointer_cast<Projection3D>(m_surface);

if (surface3D)
if ( m_surface )
{
surface3D->enableLighting( on );
m_surface->enableLighting( on );
updateView();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MantidGLWidget : public QGLWidget
void setBackgroundColor(QColor);
QColor currentBackgroundColor() const;
void saveToFile(const QString & filename);
int getLightingState() const {return m_lightingState;}
//int getLightingState() const {return m_lightingState;}

public slots:
void enableLighting(bool);
Expand Down Expand Up @@ -55,7 +55,7 @@ public slots:
private:
void setRenderingOptions();

int m_lightingState; ///< 0 = light off; 2 = light on
//int m_lightingState; ///< 0 = light off; 2 = light on
bool m_isKeyPressed;
bool m_firstFrame;

Expand Down
44 changes: 22 additions & 22 deletions Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Projection3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ Projection3D::Projection3D(const InstrumentActor* rootActor,int winWidth,int win
:ProjectionSurface(rootActor,Mantid::Kernel::V3D(),Mantid::Kernel::V3D(0,0,1)),
m_viewport(new GLViewport),
m_drawAxes(true),
m_wireframe(false),
m_isLightingOn(false)
m_wireframe(false)
{

Instrument_const_sptr instr = rootActor->getInstrument();
Expand Down Expand Up @@ -158,6 +157,7 @@ void Projection3D::drawAxes(double axis_length)const
//To make sure the lines are colored
glEnable(GL_COLOR_MATERIAL);
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

glColor3f(1.0, 0., 0.);
Expand Down Expand Up @@ -479,15 +479,6 @@ RectF Projection3D::getSurfaceBounds()const
return RectF( QPointF(xmin, ymin), QPointF(xmax, ymax) );
}

/**
* Enable or disable lighting in non-picking mode
* @param on :: True for enabling, false for disabling.
*/
void Projection3D::enableLighting(bool on)
{
m_isLightingOn = on;
}

/**
* Define lighting of the scene
*/
Expand All @@ -497,26 +488,35 @@ void Projection3D::setLightingModel(bool picking) const
if ( m_isLightingOn && !picking )
{
glShadeModel(GL_SMOOTH); // Shade model is smooth (expensive but looks pleasing)
glEnable(GL_LIGHT0); // Enable opengl first light
glEnable(GL_LINE_SMOOTH); // Set line should be drawn smoothly
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); // This model lits both sides of the triangle
// Set Light0 Attributes, Ambient, diffuse,specular and position

const float lamp0_intensity = 0.3f;
const float lamp1_intensity = 0.7f;

// First light source - spot light at the origin
glEnable(GL_LIGHT0); // Enable opengl first light
float lamp0_diffuse[4]={lamp0_intensity, lamp0_intensity, lamp0_intensity, 1.0f};
float lamp0_ambient[4]={0.1f, 0.1f, 0.1f, 1.0f};
glLightfv(GL_LIGHT0, GL_DIFFUSE, lamp0_diffuse);
glLightfv(GL_LIGHT0, GL_AMBIENT, lamp0_ambient);
float lamp0_pos[4]={0.0f, 0.0f, 0.0f, 1.0f};
glLightfv(GL_LIGHT0, GL_POSITION, lamp0_pos);

// First light source
// Its a directional light which follows camera position
float lamp_ambient[4]={0.30f, 0.30f, 0.30f, 1.0f};
float lamp_diffuse[4]={1.0f, 1.0f, 1.0f, 1.0f};
float lamp_specular[4]={1.0f,1.0f,1.0f,1.0f};
glLightfv(GL_LIGHT0, GL_AMBIENT,lamp_ambient );
glLightfv(GL_LIGHT0, GL_DIFFUSE, lamp_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, lamp_specular);
float lamp_pos[4]={0.0f, 0.0f, 0.0f, 1.0f}; // spot light at the origin
glLightfv(GL_LIGHT0, GL_POSITION, lamp_pos);
glEnable (GL_LIGHTING); // Enable light
glEnable(GL_LIGHT1); // Enable opengl second light
float lamp1_diffuse[4]={lamp1_intensity, lamp1_intensity, lamp1_intensity, 1.0f};
glLightfv(GL_LIGHT1, GL_DIFFUSE, lamp1_diffuse);

glEnable (GL_LIGHTING); // Enable overall lighting
}
else
{
glShadeModel(GL_FLAT);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glDisable(GL_LIGHT1);
glDisable(GL_LINE_SMOOTH);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Projection3D : public ProjectionSurface
void setViewDirection(const QString& vd);
void set3DAxesState(bool on);
void setWireframe(bool on);
void enableLighting(bool on);

virtual void componentSelected(Mantid::Geometry::ComponentID = NULL);
virtual void getSelectedDetectors(QList<int>& dets);
Expand Down Expand Up @@ -78,7 +77,6 @@ protected slots:
GLViewport* m_viewport; ///< Opengl View port [World -> Window]
bool m_drawAxes;
bool m_wireframe;
bool m_isLightingOn; ///< Lighting on/off flag

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ProjectionSurface::ProjectionSurface(const InstrumentActor* rootActor,const Mant
m_viewRect(),
m_selectRect(),
m_interactionMode(MoveMode),
m_isLightingOn(false),
m_peakLabelPrecision(6),
m_peakShapesStyle(0),
m_viewChanged(true),
Expand Down Expand Up @@ -696,3 +697,13 @@ void ProjectionSurface::erasePeaks(const QRect &rect)
}

}

/**
* Enable or disable lighting in non-picking mode
* @param on :: True for enabling, false for disabling.
*/
void ProjectionSurface::enableLighting(bool on)
{
m_isLightingOn = on;
}

Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class ProjectionSurface: public QObject
QColor getBackgroundColor() const {return m_backgroundColor;}
/// Send a redraw request to the surface owner
void requestRedraw();
/// Enable lighting if the implementation allows it
void enableLighting(bool on);

//-----------------------------------
// Mask methods
Expand Down Expand Up @@ -246,9 +248,10 @@ protected slots:
mutable QImage* m_viewImage; ///< storage for view image
mutable QImage* m_pickImage; ///< storage for picking image
QColor m_backgroundColor; ///< The background colour
RectF m_viewRect; ///< Keeps the physical dimensions of the surface
RectF m_viewRect; ///< Keeps the physical dimensions of the surface
QRect m_selectRect;
int m_interactionMode; ///< mode of interaction - index in m_inputControllers
bool m_isLightingOn; ///< Lighting on/off flag

Shape2DCollection m_maskShapes; ///< to draw mask shapes
mutable QList<PeakOverlay*> m_peakShapes; ///< to draw peak labels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,22 @@ void UnwrappedSurface::drawSurface(MantidGLWidget *widget,bool picking)const

glLoadIdentity();

if ( widget->getLightingState() != 0 )
if ( m_isLightingOn && !picking )
{
float lamp_pos[4]={0.0, 0.0, 1.0, 0.0}; // directional light in +z direction (into the screen)
if ( isFlippedView() ) lamp_pos[2] = -1.0f;
glLightfv(GL_LIGHT0, GL_POSITION, lamp_pos);
glShadeModel(GL_SMOOTH); // Shade model is smooth
glEnable(GL_LINE_SMOOTH); // Set line should be drawn smoothly
glEnable(GL_LIGHT0); // Enable opengl second light
float diffuse[4]={1.0f, 1.0f, 1.0f, 1.0f};
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);

glEnable (GL_LIGHTING); // Enable overall lighting
}
else
{
glDisable(GL_LIGHT0);
glDisable(GL_LIGHTING);
glDisable(GL_LINE_SMOOTH);
glShadeModel(GL_FLAT);
}

for(size_t i=0;i<m_unwrappedDetectors.size();++i)
Expand Down

0 comments on commit 3063563

Please sign in to comment.