Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / inc / FUiEffects_RuntimeGraphicalSurfaceNurbs.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FUiEffects_RuntimeGraphicalSurfaceNurbs.h
19  * @brief       This is the header file for the GraphicalSurfaceNurbs class.
20  */
21
22 #ifndef _FUI_EFFECTS_INTERNAL_RUNTIME_GRAPHICAL_SURFACE_NURBS_H_
23 #define _FUI_EFFECTS_INTERNAL_RUNTIME_GRAPHICAL_SURFACE_NURBS_H_
24
25 #include <FUiEffects_PePointSurfaceNURBS.h>
26 #include "FUiEffects_RuntimeGraphicalSurface.h"
27
28 namespace Tizen { namespace Ui { namespace Effects { namespace _Runtime
29 {
30
31 /**
32 * Weight assignment for every control point of NURBS
33 *
34 * @since 2.0
35 *
36 */
37 struct _DataPointWeight
38 {
39         float weight;                                                                           /**< the weight of control point (physical point of effect model) in NURBS algorithm (influence of it on corresponding graphical point) */
40         const Tizen::Ui::Effects::_Utils::Vec3f* pPoint;                /**< the pointer to physical point (control point in accordance NURBS theory)*/
41 };
42
43 /**
44 * The vector type for storing knots for NURBS algorithm.
45 *
46 * @since 2.0
47 *
48 */
49 typedef std::vector<float> TypeKnots;
50
51 /**
52 * The vector type for storing PointSurfaceNURBS pointers.
53 *
54 * @since 2.0
55 *
56 */
57 typedef std::vector<Tizen::Ui::Effects::_PhysicsEngine::PointSurfaceNurbs*> TypePSurfaceNURBSCollection;
58
59 /**
60 * The vector type for storing NURBS coefficients.
61 *
62 * @since 2.0
63 *
64 */
65 typedef std::vector<_DataPointWeight> TypeNURBSCoeffsCollection;
66
67 /**
68 * The vector type for storing a coordinates of graphical surface corners (as rectangle).
69 *
70 * @since 2.0
71 *
72 */
73 typedef std::vector<Tizen::Ui::Effects::_Utils::Vec3f*> TypeCornerGrapSurPointsCollection;
74
75 /**
76 * The vector type for storing a coordinates of "physical" surface corners (as rectangle).
77 *
78 * @since 2.0
79 *
80 */
81 typedef std::vector<const Tizen::Ui::Effects::_Utils::Vec3f*> TypeCornerPhysSurPointsCollection;
82
83 /**
84 * The type for storing vector of vectors of ID (is needed for finding nearest points algorithm).
85 *
86 * @since 2.0
87 *
88 */
89 typedef EffectsVector<EffectsVector<long> > TypeNearestPointsCollection;
90
91 /**
92  * @class       GraphicalSurfaceNurbs
93  * @brief       This class specifies graphical surface as mesh of Graphical Points,
94  *                      which are controlled by NURBS algorithm
95  *
96  * @since 2.0
97  *
98  */
99 class GraphicalSurfaceNurbs
100         : public GraphicalSurface
101 {
102 public:
103         /**
104          * GraphicalSurfaceNurbs class constructor
105          *
106          * @since 2.0
107          *
108          */
109         GraphicalSurfaceNurbs(long objID,
110                                                 long bitmapID_,
111                                                 int dimCtrlX_,
112                                                 int dimCtrlY_,
113                                                 int orderX_,
114                                                 int orderY_,
115                                                 int dimGraphX_,
116                                                 int dimGraphY_,
117                                                 std::unique_ptr<TypeKnots> pKnotsX_,
118                                                 std::unique_ptr<TypeKnots> pKnotsY_,
119                                                 float transparency_);
120
121         /**
122          * GraphicalSurfaceNurbs class destructor
123          *
124          * @since 2.0
125          *
126          */
127         virtual ~GraphicalSurfaceNurbs(void);
128
129         /**
130          * Empty function for this class (should be implemented because it is abstract in base class)
131          *
132          * @since 2.0
133          *
134          */
135         virtual void Calculate(float timeStep);
136
137         /**
138          * Provides reading access to GraphicalSurfaceNurbs's properties values from user's scripts
139          *
140          * @since 2.0
141          *
142          */
143         virtual PropertyCast GetProperty(ElementProperty propName) const;
144
145         /**
146          * Provides writing access to GraphicalSurfaceNurbs's properties values of
147          * boolean type from user's scripts
148          *
149          * @since 2.0
150          *
151          */
152         virtual bool SetProperty(ElementProperty propName, bool propValue);
153
154         /**
155          * Provides writing access to GraphicalSurfaceNurbs's properties values of
156          * lua_Number type (floating point or integer) from user's scripts
157          *
158          * @since 2.0
159          *
160          */
161         virtual bool SetProperty(ElementProperty propName, LUA_NUMBER propValue);
162
163         /**
164          * Provides writing access to GraphicalSurfaceNurbs's properties values of
165          * Vec3f type from user's scripts
166          *
167          * @since 2.0
168          *
169          */
170         virtual bool SetProperty(ElementProperty propName, const Tizen::Ui::Effects::_Utils::Vec3f &propValue);
171
172         /**
173          * Initializes GraphicalSurfaceNurbs's internal parameters and resets accumulated parameters to zero
174          *
175          * @since 2.0
176          *
177          */
178         virtual void Initialize(void);
179
180         /**
181          * Synchronizes the render data (vertexes and normals) and physical (PointSurfaceNURBS) points;
182          * recalculates the normals for vertexes
183          *
184          * @since 2.0
185          *
186          * @remarks             Must be called after CalcIndices and CalcNURBSCoeffs functions
187          */
188         virtual void Update(void);
189
190         /**
191          * It is performed after building objects for creating links between them; prepares class instance to work
192          *
193          * @since 2.0
194          *
195          * @remarks             Specifies connections with pointSurfaceNURBS objects,
196          *                              performs indexes, NURBS coefficients, texture coordinates calculation,
197          *                              constructs render data collection
198          */
199         virtual void Construct(TypeElemSurfaceCollection* pElemSurfaceCollection, RenderDataSurfaceCollection* pRenderDataSurfaceCollection);
200
201         /**
202          * Gets object's type
203          *
204          * @since 2.0
205          *
206          */
207         virtual ESurface GetType(void) const;
208
209         /**
210          * Returns the vector of vectors of nearest points to specified point of graphical surface
211          *
212          * @since 2.0
213          *
214          */
215         virtual PropertyCast GetNearestPointsIds(Tizen::Ui::Effects::_Utils::Vec3f &position) const;
216
217         /**
218          * Rotates model matrix by Angle around Axis or (ax, ay, az) in case Axis=AXIS_ARBITRARY
219          *
220          * @since 2.0
221          *
222          * @param [in]  Point: Base point for rotation (the coordinates of this point are not changed)
223          * @param [in]  ax, ay, az: The coordinates of axis around which rotation is performed (in case Axis=AXIS_ARBITRARY)
224          * @param [in]  x0, y0, z0: Base point coordinates in case point=POINT_ARBITRARY
225          */
226         virtual bool RotateSurface(float angle, _Axis axis, _Point point,
227                                                            float ax, float ay, float az, float x0, float y0, float z0);
228
229         /**
230          * Scales model matrix by multipliers ax, ay, az on the relevant axes
231          * with base Point or (x0, y0, z0) in case Point = POINT_ARBITRARY
232          *
233          * @since 2.0
234          *
235          * @remarks             Note that the base point coordinates do not change
236          */
237         virtual bool ScaleSurface(float ax, float ay, float az, _Point point,
238                                                           float x0, float y0, float z0);
239
240 protected:
241
242 private:
243         /**
244          * Hidden copy constructor
245          *
246          * @since 2.0
247          *
248          */
249         GraphicalSurfaceNurbs(const GraphicalSurfaceNurbs& rhs);
250
251         /**
252          * Hidden assignment operator
253          *
254          * @since 2.0
255          *
256          */
257         GraphicalSurfaceNurbs &operator=(const GraphicalSurfaceNurbs& rhs);
258
259         /**
260          * Basis function of rational B-spline (NURBS) to the relevant direction
261          *
262          * @since 2.0
263          *
264          */
265         float NurbsSingleBasisFunction(long i, long order, float u, const TypeKnots& knots) const;
266
267         /**
268          * Denominator in formula for NURBS coefficients calculation (see NURBS theory)
269          *
270          * @since 2.0
271          *
272          */
273         float SummaryForNurbs(float u, float w) const;
274
275         /**
276          * NURBS coefficients calculation
277          *
278          * @since 2.0
279          *
280          * @remarks             Is performed once in construct function
281          */
282         void CalculationNurbsCoefficients(void);
283
284         /**
285          * Applying the threshold to NURBS coefficients:
286          * if the absolute value of some coefficient less or equals to threshold,
287          * then this coefficient is not involved in calculation (is needed for optimization)
288          *
289          * @since 2.0
290          *
291          * @remarks             Is performed once in construct function after calculation NURBS coefficients
292          */
293         void WeightsApplyThreshold(float threshold);
294
295         /**
296          * Calculation of triangle indices (is needed for rendering surface)
297          *
298          * @since 2.0
299          *
300          * @remarks             Is performed once in construct function
301          */
302         void CalcIndices(void);
303
304         /**
305          * Calculations of normals for vertexes (is needed for surface lighting)
306          *
307          * @since 2.0
308          *
309          * @remarks             Is performed in update function after points position recalculation
310          */
311         void CalcNormals(void);
312
313         /**
314          * Calculations of textures coordinates (is needed for surface lighting)
315          *
316          * @since 2.0
317          *
318          * @remarks             Is performed once in construct function after update
319          */
320         void CalcTexCoords(void);
321
322         /**
323          * Calculates the point pointOnModel base on value of _Point enumeration.
324          *
325          * @since 2.0
326          *
327          * @remarks             If _Point is POINT_ARBITRARY then PointOnModel = (x0, y0, z0)
328          */
329         bool DefinePointOnModel(_Point point, Tizen::Ui::Effects::_Utils::Vec3f &pointOnModel,
330                                                         float x0, float y0, float z0) const;
331
332 private:
333         int __dimGraphX;                                                                                        /**< number of graphical points on X-direction*/
334         int __dimGraphY;                                                                                        /**< number of graphical points on Y-direction*/
335
336         int __dimCtrlX;                                                                                         /**< number of control points on X-direction*/
337         int __dimCtrlY;                                                                                         /**< number of control points on Y-direction*/
338
339         int __orderX;                                                                                           /**< surface order on X-direction*/
340         int __orderY;                                                                                           /**< surface order on Y-direction*/
341
342         //pointers to knots vectors (see NURBS theory)
343         //the size of these vectors is equal to the sum of order and control points quantity for corresponding direction
344         std::unique_ptr<TypeKnots> __pKnotsX;
345         std::unique_ptr<TypeKnots> __pKnotsY;
346
347         std::unique_ptr<TypeNURBSCoeffsCollection> __pNURBSCoeffsCollection;            /**< collection of NURBS coefficients (see NURBS theory) */
348
349         std::unique_ptr<TypePSurfaceNURBSCollection> __pPSurfaceNURBSCollection;        /**< pointers collection on control points (PointSurfaceNURBS objects) */
350
351         std::unique_ptr<TypeCornerGrapSurPointsCollection> __pCornerPointsGraphSurface;                         /**< pointers to four corner points of graphical surface */
352         std::unique_ptr<TypeCornerPhysSurPointsCollection> __pCornerPointsPhysicalSurface;                      /**< pointers to four corner points of "physical" surface */
353
354         //pointers collection for returning into scripts;
355         //[0][0] is a nearest point to specified point,
356         //[1][...] -- first zone,
357         //[2][...] -- second zone, etc.
358         std::unique_ptr<TypeNearestPointsCollection> __pNearestPointsCollection;
359
360 }; // GraphicalSurfaceNurbs
361
362 } } } } // Tizen::Ui::Effects::_Runtime
363
364 #endif //_FUI_EFFECTS_INTERNAL_RUNTIME_GRAPHICAL_SURFACE_NURBS_H_