HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIM_Utils.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  */
7 
8 #ifndef __SIM_Utils_h__
9 #define __SIM_Utils_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_Data.h"
13 #include "SIM_DataFilter.h"
14 #include "SIM_Time.h"
15 #include "SIM_Names.h"
16 #include "SIM_CacheCompression.h"
17 #include <GEO/GEO_Primitive.h>
18 #include <UT/UT_SysSpecific.h>
19 #include <UT/UT_Array.h>
20 
21 class SIM_Solver;
22 class SIM_Object;
23 class SIM_Relationship;
24 
25 /// This macros simplifies calling and casting the return value from the
26 /// SIM_Data::getPointerToType() function. The returned value is a DataClass
27 /// pointer.
28 #define SIM_DATA_CAST(Data, DataClass) \
29  ((DataClass *)(SIM_Data::castPointerToType( \
30  static_cast<SIM_Data *>(Data), #DataClass)))
31 /// This macros simplifies calling and casting the return value from the
32 /// SIM_Data::getPointerToType() function. The returned value is a const
33 /// DataClass pointer.
34 #define SIM_DATA_CASTCONST(Data, DataClass) \
35  ((const DataClass *)(SIM_Data::castConstPointerToType( \
36  static_cast<const SIM_Data *>(Data), #DataClass)))
37 /// This macro simplifies the calling and casting the return value from
38 /// SIM_Data::getNamedSubData(). The returned value is a DataClass
39 /// pointer.
40 #define SIM_DATA_GET(Parent, DataName, DataClass) \
41  SIM_DATA_CAST((Parent).getNamedSubData(DataName), DataClass)
42 /// This macro simplifies the calling and casting the return value from
43 /// SIM_Data::getConstNamedSubData(). The returned value is a const DataClass
44 /// pointer.
45 #define SIM_DATA_GETCONST(Parent, DataName, DataClass) \
46  SIM_DATA_CASTCONST((Parent).getConstNamedSubData(DataName), DataClass)
47 /// This macro simplifies the calling and casting the return value from
48 /// SIM_Data::getNthSubData(), using SIM_DataFilterByType. The returned
49 /// value is a DataClass pointer.
50 #define SIM_DATA_GETNTH(Parent, DataClass, N, StartFrom, RecurseFilter) \
51  SIM_DATA_CAST((Parent).getNthSubData( \
52  NULL, SIM_DataFilterByType(#DataClass), N, \
53  StartFrom, RecurseFilter), DataClass)
54 /// This macro simplifies the calling and casting the return value from
55 /// SIM_Data::getNthConstSubData(), using SIM_DataFilterByType. The returned
56 /// value is a const DataClass pointer.
57 #define SIM_DATA_GETNTHCONST(Parent, DataClass, N, StartFrom, RecurseFilter) \
58  SIM_DATA_CASTCONST((Parent).getNthConstSubData( \
59  NULL, SIM_DataFilterByType(#DataClass), N, \
60  StartFrom, RecurseFilter), DataClass)
61 /// This macro simplifies calling and casting the return value of a call to
62 /// the SIM_Data::createNamedSubData function.
63 #define SIM_DATA_CREATE(Parent, DataName, DataClass, Flags) \
64  ((DataClass *)(static_cast<SIM_Data &>(Parent)). \
65  createNamedSubData(DataName, #DataClass, Flags))
66 /// This macro simplifies the calling and casting the return value from
67 /// SIM_Data::getorCreateAlternateRepresentation(). The returned value is a
68 /// DataClass pointer.
69 #define SIM_DATA_GETORCREATE_ALT(Parent, DataName, DataClass) \
70  SIM_DATA_CAST((Parent).getOrCreateAlternateRepresentation( \
71  DataName, #DataClass), DataClass)
72 
73 /// This function converts const SIM_Data pointers in an array to pointers
74 /// of any const SIM_Data subclass. If one of the SIM_Data pointers cannot be
75 /// cast to the requested new type, it is not added to the new array.
76 template <class DataClass>
77 void
80  const char *DataClassName,
81  bool includenulls = false)
82 {
83  const DataClass *converted;
84 
85  dest.entries(0);
86  for( int i = 0; i < src.entries(); i++ )
87  {
88  converted = src(i) ?
89  (const DataClass *)src(i)->
90  getConstPointerToType(DataClassName) :
91  0;
92  if( converted || includenulls )
93  dest.append(converted);
94  }
95 }
96 
97 /// This function converts SIM_Data pointers in an array to pointers
98 /// of any SIM_Data subclass. If one of the SIM_Data pointers cannot be
99 /// cast to the requested new type, it is not added to the new array.
100 template <class DataClass>
101 void
104  const char *DataClassName,
105  bool includenulls = false)
106 {
107  DataClass *converted;
108  int i;
109 
110  dest.entries(0);
111  for( i = 0; i < src.entries(); i++ )
112  {
113  converted = src(i) ?
114  (DataClass *)src(i)->getPointerToType(DataClassName) :
115  0;
116  if( converted || includenulls )
117  dest.append(converted);
118  }
119 }
120 
121 /// A utility method for computing the transform from the local-space of an
122 /// object to world-space co-ordinates.
124 /// A utility method for computing the transform from the local-space of an
125 /// object's geometry to world-space co-ordinates.
127 
128 /// Returns object properties at the given point (if non-negative) or position.
130  const SIM_Object &obj,
131  const UT_Vector3 &pos,
132  const GA_Index ptnum,
133  fpreal &friction,
134  fpreal &bounce,
135  fpreal &dynamicfriction,
136  fpreal &bounceforward);
137 
139  const SIM_Object &obj,
140  const UT_Vector3 &pos,
141  const GA_Index ptnum,
142  fpreal &friction,
143  fpreal &bounce,
144  fpreal &dynamicfriction)
145 {
146  fpreal dontcare = 0;
147  SIMgetObjectProperties(obj, pos, ptnum, friction, bounce, dynamicfriction,
148  dontcare);
149 }
150 
151 /// Returns true if the given primitive is a polygon with three
152 /// vertices.
153 SIM_API bool SIMisTri(const GEO_Primitive &prim);
154 
155 
156 
157 /// Information about a single edge.
159 {
160 public:
161  sim_EdgeDataEntry(int pid_e0, int pid_e1, int fid0, int fid1,
162  int pid_f0, int pid_f1)
163  : myPidE0(pid_e0), myPidE1(pid_e1),
164  myFid0(fid0), myFid1(fid1),
165  myPidF0(pid_f0), myPidF1(pid_f1)
166  { }
168  { }
169 
170  /// The ids of the points on the edge.
171  int myPidE0, myPidE1;
172  /// The ids of the faces adjacent to the edge. Second id may be <0 if
173  /// only one face is adjacent.
174  int myFid0, myFid1;
175  /// The ids of the other points in the respective faces. Only
176  /// meaningful if the faces are triangles (in which case there's only one
177  /// other point).
178  int myPidF0, myPidF1;
179 };
181 
182 /// Calculate information about triangle edges in the given gdp.
183 /// This is intended as a lightweight alternative to GQ_Detail, with only
184 /// very basic edge information.
185 SIM_API void SIMcalcEdgeData(SIM_EdgeData &edgeData, const GU_Detail &gdp);
186 
187 
188 
189 
190 /// Declaration of the function that must be implemented by custom SIM
191 /// library extensions.
192 extern "C" {
193  SYS_VISIBILITY_EXPORT extern void initializeSIM(void *data);
194 }
195 
196 /// Call this initialization function to register all data types, solvers,
197 /// and colliders in this library.
198 SIM_API void initializeSIM();
199 
200 /// Constructs guide geometry to illustrate connection between an anchored
201 //position and an object.
202 SIM_API void
204  GA_Offset ptoff,
205  const SIM_Object &object,
206  const SIM_Options &options,
207  const SIM_Relationship &rel);
208 SIM_API void
210  GA_Offset ptoff,
211  const UT_Vector3& obj_pos,
212  fpreal scale,
213  const GA_RWHandleV3& color_attrib,
214  const UT_Vector3& color,
215  const UT_Vector3& affcolor);
216 
217 /// Used in SIM_ConAnchorObjPointGroupPos and
218 /// SIM_ConAnchorObjPointGroupRot to generate a point list WITH
219 /// duplicates from a pattern string.
220 SIM_API bool
221 SIMtryCachePointList(UT_IntArray& points, const char* pattern);
222 
223 #endif
224 
SIM_API void SIMgetPositionTransform(UT_DMatrix4 &result, const SIM_Object &)
#define SYS_VISIBILITY_EXPORT
GLuint color
Definition: glcorearb.h:1260
SYS_VISIBILITY_EXPORT void initializeSIM(void *data)
3D Vector class.
int myPidE1
Definition: SIM_Utils.h:171
png_uint_32 i
Definition: png.h:2877
SIM_API void SIMgetObjectProperties(const SIM_Object &obj, const UT_Vector3 &pos, const GA_Index ptnum, fpreal &friction, fpreal &bounce, fpreal &dynamicfriction, fpreal &bounceforward)
Returns object properties at the given point (if non-negative) or position.
SIM_API void SIMcalcEdgeData(SIM_EdgeData &edgeData, const GU_Detail &gdp)
SIM_API bool SIMisTri(const GEO_Primitive &prim)
void SIMconvertArray(const SIM_DataArray &src, UT_ValArray< DataClass * > &dest, const char *DataClassName, bool includenulls=false)
Definition: SIM_Utils.h:102
GA_Size GA_Offset
Definition: GA_Types.h:617
const void * getConstPointerToType(const char *datatype) const
GA_API const UT_StringHolder scale
SIM_API void SIMbuildAnchorGuideObjectLink(GU_Detail *gdp, GA_Offset ptoff, const SIM_Object &object, const SIM_Options &options, const SIM_Relationship &rel)
Constructs guide geometry to illustrate connection between an anchored.
int myPidF1
Definition: SIM_Utils.h:178
SIM_API bool SIMtryCachePointList(UT_IntArray &points, const char *pattern)
GLboolean * data
Definition: glcorearb.h:130
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
void SIMconvertConstArray(const SIM_ConstDataArray &src, UT_ValArray< const DataClass * > &dest, const char *DataClassName, bool includenulls=false)
Definition: SIM_Utils.h:78
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:446
double fpreal
Definition: SYS_Types.h:263
#define SIM_API
Definition: SIM_API.h:10
int myFid1
Definition: SIM_Utils.h:174
exint append(void)
Definition: UT_Array.h:95
sim_EdgeDataEntry()
Definition: SIM_Utils.h:167
SIM_API void SIMgetGeometryTransform(UT_DMatrix4 &result, const SIM_Object &)
sim_EdgeDataEntry(int pid_e0, int pid_e1, int fid0, int fid1, int pid_f0, int pid_f1)
Definition: SIM_Utils.h:161
Information about a single edge.
Definition: SIM_Utils.h:158
UT_Array< sim_EdgeDataEntry > SIM_EdgeData
Definition: SIM_Utils.h:180
GLenum src
Definition: glcorearb.h:1792