Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef GLAREA_INCLUDED
Toshihiro Shimizu 890ddd
#define GLAREA_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include "traster.h"
Toshihiro Shimizu 890ddd
#include "tw/tw.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TWIN_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TStopWatch;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TGLArea : public TWidget
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void swapBuffers();
Toshihiro Shimizu 890ddd
	TStopWatch *m_stopwatch;
Toshihiro Shimizu 890ddd
	double m_framePerSecond;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void computeOcclusingRegion();
Toshihiro Shimizu 890ddd
	void deleteOcclusingRegion();
Toshihiro Shimizu 890ddd
	//void  redrawUncoveredArea(const TPoint &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<trect> *m_arrayOfRectToRedraw;</trect>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
// int m_lx, m_ly;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// double m_angle;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define PEZZA_DISABLE_REDRAW
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if defined(MACOSX) && defined(PEZZA_DISABLE_REDRAW)
Toshihiro Shimizu 890ddd
	bool m_disableRedraw;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPoint m_lastPos;
Toshihiro Shimizu 890ddd
	TPointD m_pan;			 // world origin (win coords) (n. m_pan*2 are integer)
Toshihiro Shimizu 890ddd
	TPointD m_zoomFactor;	// "world pixel" dimension (win coords) (integer if >=1)
Toshihiro Shimizu 890ddd
	TDimensionD m_pixelSize; // 1/zoomFactor; win pixel dimension (world coords)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double m_zoomLevel; // m_zoomFactor = e^m_zoomLevel
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// supported extensions
Toshihiro Shimizu 890ddd
	static bool m_bgraSupported;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_isInsideScreen;
Toshihiro Shimizu 890ddd
	void onGLContextCreated();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	class PickItem
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
		UINT m_label;
Toshihiro Shimizu 890ddd
		UINT m_zMin;
Toshihiro Shimizu 890ddd
		UINT m_zMax;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		PickItem(UINT label, UINT zmin, UINT zmax)
Toshihiro Shimizu 890ddd
			: m_label(label), m_zMin(zmin), m_zMax(zmax)
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		~PickItem() {}
Toshihiro Shimizu 890ddd
	private:
Toshihiro Shimizu 890ddd
		//not implemented
Toshihiro Shimizu 890ddd
		PickItem();
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TGLArea(TWidget *parent, string name = "GLArea");
Toshihiro Shimizu 890ddd
	~TGLArea();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void repaint();
Toshihiro Shimizu 890ddd
	void configureNotify(const TDimension &);
Toshihiro Shimizu 890ddd
	void create();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void paintIncrementally();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//  void rectwrite(const TRaster32P &ras, const TPoint &p);
Toshihiro Shimizu 890ddd
	void over(const TRaster32P &ras, const TPoint &p);
Toshihiro Shimizu 890ddd
	void over(const TRasterGR8P &ras, const TPoint &p);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	inline TPointD win2world(const TPointD &p) const;
Toshihiro Shimizu 890ddd
	inline TPointD world2win(const TPointD &p) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	inline TAffine getWin2WorldMatrix() const;
Toshihiro Shimizu 890ddd
	inline TAffine getWorld2WinMatrix() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void scroll(const TPoint &d);  // viewport coordinates
Toshihiro Shimizu 890ddd
	void lookAt(const TPointD &d); // world coordinates of the desired window center
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// n. zoomCenter : viewport coords
Toshihiro Shimizu 890ddd
	void setZoomLevel(double zlevel, const TPoint &zoomCenter);
Toshihiro Shimizu 890ddd
	void changeZoomLevel(double d, const TPoint ¢er);
Toshihiro Shimizu 890ddd
	virtual void onZoomChange() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void fitToWindow(const TRectD &worldRect);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void middleButtonDown(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void middleButtonDrag(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void middleButtonUp(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void draw();
Toshihiro Shimizu 890ddd
	virtual void drawIncrementally();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void drawForPick() { draw(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void pick(const TPoint &point, vector<pickitem> &items);</pickitem>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double getFramePerSecond() const { return m_framePerSecond; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static bool isBGRASupported() { return m_bgraSupported; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool unProject(
Toshihiro Shimizu 890ddd
		TPointD &output,
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		const TPoint &mousePos,
Toshihiro Shimizu 890ddd
		const T3DPointD &planeOrigin,
Toshihiro Shimizu 890ddd
		const T3DPointD &u,
Toshihiro Shimizu 890ddd
		const T3DPointD &v) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void makeCurrent(); // Gl context
Toshihiro Shimizu 890ddd
	bool m_dontSwapBuffers;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline TPointD TGLArea::win2world(const TPointD &p) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPointD q = p - m_pan;
Toshihiro Shimizu 890ddd
	return TPointD(m_pixelSize.lx * q.x, m_pixelSize.ly * q.y);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline TPointD TGLArea::world2win(const TPointD &p) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_pan + TPointD(p.x * m_zoomFactor.x, p.y * m_zoomFactor.y);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline TAffine TGLArea::getWin2WorldMatrix() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return TScale(m_pixelSize.lx, m_pixelSize.ly) * TTranslation(-m_pan);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline TAffine TGLArea::getWorld2WinMatrix() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return TTranslation(m_pan) * TScale(m_zoomFactor.x, m_zoomFactor.y);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif