1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #ifndef INCLUDED_CHART2_SOURCE_VIEW_INC_GL3DBARCHART_HXX
11 #define INCLUDED_CHART2_SOURCE_VIEW_INC_GL3DBARCHART_HXX
13 #include <GL3DPlotterBase.hxx>
16 #include <boost/ptr_container/ptr_vector.hpp>
17 #include "VDataSeries.hxx"
19 #include <glm/glm.hpp>
21 #include <vcl/timer.hxx>
22 #include <vcl/idle.hxx>
23 #include <vcl/openglwin.hxx>
25 #include <rtl/ref.hxx>
26 #include <salhelper/thread.hxx>
27 #include <osl/conditn.hxx>
31 class ExplicitCategoriesProvider
;
35 class Renderable3DObject
;
36 class OpenGL3DRenderer
;
46 EVENT_MOVE_TO_DEFAULT
,
54 EVENT_SELECTBAR_UPDEDATE
58 class RenderOneFrameThread
;
59 class RenderAnimationThread
;
61 class GL3DBarChart
: public GL3DPlotterBase
, public IRenderer
63 friend class RenderThread
;
64 friend class RenderOneFrameThread
;
65 friend class RenderAnimationThread
;
66 friend class RenderBenchMarkThread
;
69 const css::uno::Reference
<css::chart2::XChartType
>& xChartType
,
70 OpenGLWindow
* pContext
);
72 virtual ~GL3DBarChart();
74 virtual void create3DShapes(const boost::ptr_vector
<VDataSeries
>& rDataSeries
,
75 ExplicitCategoriesProvider
& rCatProvider
) SAL_OVERRIDE
;
77 virtual void render() SAL_OVERRIDE
;
79 /// Render one frame of the 3D bar chart.
82 virtual void update() SAL_OVERRIDE
;
84 /// Draw to the framebuffer context, and provide the ID of the bar that the user has clicked.
85 sal_uInt32
barIdAtPosition(const Point
& rPos
);
86 virtual void clickedAt(const Point
& rPos
, sal_uInt16 nButtons
) SAL_OVERRIDE
;
88 virtual void mouseDragMove(const Point
& rStartPos
, const Point
& rEndPos
, sal_uInt16 nButtons
) SAL_OVERRIDE
;
89 virtual void scroll(long nDelta
) SAL_OVERRIDE
;
90 virtual void contextDestroyed() SAL_OVERRIDE
;
92 void setOpenGLWindow(OpenGLWindow
* pWindow
);
96 void spawnRenderThread(RenderThread
*pThread
);
97 void joinRenderThread();
100 glm::vec3
getCornerPosition(sal_Int8 nCornerId
);
102 void updateScreenText();
103 void updateRenderFPS();
104 void updateDataUpdateFPS();
105 DECL_LINK_TYPED(UpdateTimerHdl
, Idle
*, void);
106 static int calcTimeInterval(TimeValue
&startTime
, TimeValue
&endTime
);
107 float addScreenTextShape(OUString
&nStr
, const glm::vec2
& rLeftOrRightTop
, float nTextHeight
, bool bLeftTopFlag
= true,
108 const glm::vec4
& rColor
= glm::vec4(0.0f
, 1.0f
, 1.0f
, 0.0f
),
109 const glm::vec3
& rPos
= glm::vec3(0.0f
, 0.0f
, 0.0f
),
110 sal_uInt32 nEvent
= 0);
111 void recordBarHistory(sal_uInt32
&nBarID
, float &nVal
);
112 void updateClickEvent();
113 void calcDistance(std::vector
<sal_uInt32
> &vectorNearest
);
114 static float calcScrollDistance(const glm::mat4
&mvp
, const glm::vec3
& rPos
);
115 void initDistanceHeap(std::vector
<sal_uInt32
> &vectorNearest
);
116 void keepHeap(std::vector
<sal_uInt32
> &vectorNearest
, int index
);
117 static void swapVector(int i
, int j
, std::vector
<sal_uInt32
> &vectorNearest
);
118 void getNearestBars(std::vector
<sal_uInt32
> &vectorNearest
);
120 void processAutoFly(sal_uInt32 nId
, sal_uInt32 nColor
);
121 void getNeighborBarID(sal_uInt32 nSelectBarId
, sal_uInt32
*pNeighborBarId
);
122 void addMovementScreenText(sal_uInt32 nBarId
);
123 css::uno::Reference
<css::chart2::XChartType
> mxChartType
;
124 boost::ptr_vector
<opengl3D::Renderable3DObject
> maShapes
;
126 boost::scoped_ptr
<opengl3D::OpenGL3DRenderer
> mpRenderer
;
127 VclPtr
<OpenGLWindow
> mpWindow
;
129 opengl3D::Camera
* mpCamera
;
132 boost::scoped_ptr
<opengl3D::TextCache
> mpTextCache
;
134 glm::vec3 maCameraPosition
;
135 glm::vec3 maCameraDirection
;
137 glm::vec3 maDefaultCameraPosition
;
138 glm::vec3 maDefaultCameraDirection
;
140 glm::vec3 maStepDirection
;
145 * 0 = corner at (0,0,0);
146 * numbering counter clockwise
150 std::vector
<OUString
> maCategories
;
151 std::vector
<OUString
> maSeriesNames
;
152 struct BarInformation
157 sal_Int32 mnSeriesIndex
;
159 BarInformation(const glm::vec3
& rPos
, float nVal
,
160 sal_Int32 nIndex
, sal_Int32 nSeriesIndex
);
163 std::map
<sal_uInt32
, const BarInformation
> maBarMap
;
164 bool mbNeedsNewRender
;
168 rtl::Reference
<RenderThread
> mpRenderThread
;
170 ::osl::Condition maClickCond
;
171 RenderEventType maRenderEvent
;
172 RenderEventType maPreRenderEvent
;
173 sal_uInt32 mnSelectBarId
;
174 sal_uInt32 mnPreSelectBarId
;
176 sal_uInt32 miScrollRate
;
179 bool mbScreenTextNewRender
;
180 boost::ptr_vector
<opengl3D::Renderable3DObject
> maScreenTextShapes
;
182 OUString maDataUpdateFPS
;
183 sal_uInt32 miFrameCount
;
184 sal_uInt32 miDataUpdateCounter
;
185 TimeValue maFPSRenderStartTime
;
186 TimeValue maFPSRenderEndTime
;
187 TimeValue maDataUpdateStartTime
;
188 TimeValue maDataUpdateEndTime
;
189 std::map
<sal_uInt32
, std::list
<float> > maBarHistory
;
190 std::vector
<sal_uInt32
> maVectorNearest
;
191 std::map
<sal_uInt32
, float> maDistanceMap
;
192 std::map
<sal_uInt32
, sal_uInt32
> maBarColorMap
;
194 bool mbBenchMarkMode
;
195 sal_uInt32 mnHistoryCounter
;
196 sal_uInt32 mnBarsInRow
;
198 sal_Int32 mnUpdateBarId
;
200 // these form a pair:
201 // main thread sets condition 1 and waits until it can take the mutex
202 // render thread checks condition 1 before taking the mutex and waits in case it
203 // is set until condition 2 is set
205 // only necessary for the benchmark mode
206 osl::Condition maCond1
;
207 osl::Condition maCond2
;
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */