1/****************************************************************************************
2
3 Copyright (C) 2015 Autodesk, Inc.
4 All rights reserved.
5
6 Use of this software is subject to the terms of the Autodesk license agreement
7 provided at the time of installation or download, or which otherwise accompanies
8 this software in either electronic or hard copy form.
9
10****************************************************************************************/
11
12//! \file fbxweightedmapping.h
13#ifndef _FBXSDK_SCENE_GEOMETRY_WEIGHTED_MAPPING_H_
14#define _FBXSDK_SCENE_GEOMETRY_WEIGHTED_MAPPING_H_
15
16#include <fbxsdk/fbxsdk_def.h>
17
18#include <fbxsdk/core/base/fbxarray.h>
19
20#include <fbxsdk/fbxsdk_nsbegin.h>
21
22/** Define a weighted bidirectional mapping relation on objects.
23 * \nosubgrouping
24 * There are two object set. The source object of mapping is in source set.
25 * The destination object is in destination set.
26 * Each object can have multiple mapping relation with other objects.
27 */
28class FBXSDK_DLL FbxWeightedMapping
29{
30public:
31 /** Object set type in the mapping relation.
32 */
33 enum ESet
34 {
35 eSource, //!< Object is as source.
36 eDestination //!< Object is as destination.
37 };
38
39 /** Record one mapping from one object. */
40 struct Element
41 {
42 //! The index of another object in the mapping in the another ESet array.
43 int mIndex;
44 //! Weight of the mapping.
45 double mWeight;
46 };
47
48 /**
49 * \name Constructor and Destructor
50 */
51 //@{
52
53 /** Constructor.
54 * Initialize the source set and destination set.
55 * \param pSourceSize Source set size
56 * \param pDestinationSize Destination set size
57 */
58 FbxWeightedMapping(int pSourceSize, int pDestinationSize);
59
60 //! Destructor.
61 ~FbxWeightedMapping();
62 //@}
63
64
65 /** Remove all weighted relations and give new source and destination sets sizes.
66 * \param pSourceSize New source set size.
67 * \param pDestinationSize New destination set size.
68 */
69 void Reset(int pSourceSize, int pDestinationSize);
70
71 /** Add a weighted mapping relation.
72 * \param pSourceIndex Index of the source object.
73 * \param pDestinationIndex Index of the destination object.
74 * \param pWeight Weight of the mapping.
75 */
76 void Add(int pSourceIndex, int pDestinationIndex, double pWeight);
77
78 /** Get the number of elements of a set.
79 * \param pSet source or destination set.
80 */
81 int GetElementCount(ESet pSet) const;
82
83 /** Get the number of relations an element of a set is linked to.
84 * For example, for one object (which index is specified by pElement) in source set (specified by pSet),
85 * the function return how many objects (as destination) the object (as source) mapping to.
86 * \param pSet Source or destination set.
87 * \param pElement Object index in the set.
88 */
89 int GetRelationCount(ESet pSet, int pElement) const;
90
91 /** Get one of the relations an element of a set is linked to.
92 * \param pSet Source or destination set.
93 * \param pElement Object index in the set.
94 * \param pIndex Relation index of the object linked to.
95 * \return Element gives the index of an element in the other set and the assigned weight.
96 */
97 Element& GetRelation(ESet pSet, int pElement, int pIndex);
98
99 /** Given the index of an element in the other set, get the index of one of the relations
100 * an element of a set is linked to. Returns -1 if there is not relation between these elements.
101 * \param pSet Source or destination set.
102 * \param pElementInSet Object index in the set.
103 * \param pElementInOtherSet Object index in another set.
104 * \return The index of one of the relations, -1 if there is not relation between these elements.
105 */
106 int GetRelationIndex(ESet pSet, int pElementInSet, int pElementInOtherSet) const;
107
108 /** Get the sum of the weights from the relations an element of a set is linked to.
109 * \param pSet Source or destination set.
110 * \param pElement Object index in the set.
111 * \param pAbsoluteValue Flag to convert negative value to positive value.
112 * \return The sum of the weights from the relations.
113 */
114 double GetRelationSum(ESet pSet, int pElement, bool pAbsoluteValue) const;
115
116
117 /** Normalize the weights of the relations of all the elements of a set.
118 * \param pSet Source or destination set.
119 * \param pAbsoluteValue Flag to convert negative value to positive value.
120 */
121 void Normalize(ESet pSet, bool pAbsoluteValue);
122
123 FbxWeightedMapping& operator=(const FbxWeightedMapping& pWMap);
124
125private:
126
127 //! Remove all weighted relations.
128 void Clear();
129
130 FbxArray<FbxArray<Element>*> mElements[2];
131
132};
133
134typedef class FbxArray<FbxWeightedMapping::Element> FbxArrayTemplateElement;
135typedef class FbxArray<FbxArray<FbxWeightedMapping::Element>*> FbxArrayTemplateArrayTemplateElement;
136
137#include <fbxsdk/fbxsdk_nsend.h>
138
139#endif /* _FBXSDK_SCENE_GEOMETRY_WEIGHTED_MAPPING_H_ */
140