10 #ifndef __MQSDKPlugIn0x_11_h__
11 #define __MQSDKPlugIn0x_11_h__
21 #define WIN32_LEAN_AND_MEAN
23 #include <MQSetting.h>
24 #include <MQBasePlugin.h>
27 #include "impl/MQ0x_11.hpp"
30 #ifdef MQPLUGIN_VERSION
31 #if MQPLUGIN_VERSION < 0x0300
32 "MQx" need newer than mqsdk300
35 "MQx" need newer than mqsdk300
81 if ( pSrc != NULL )
for (
size_t i = 0; i < ct; i++ ) m_val = (m_val * (T_OUT)(
sizeof(T_IN) * 8 - 1)) ^ pSrc[i];
100 if ( pSrc != NULL )
while ( (*pSrc) != trailCode ) ret.m_val = (ret.m_val * (T_OUT)(
sizeof(T_IN) * 8 - 1)) ^ (*(pSrc++));
104 operator T_OUT() {
return m_val; }
115 template <
typename T>
struct HSV {
121 HSV(T h_, T s_, T v_) :
h(h_),
s(s_),
v(v_) {}
124 HSV(
const MQColor& rgb ) :
h(T(0)),
s(T(0)),
v(T(0)) {
125 const T min = T(std::min(std::min(rgb.r,rgb.g),rgb.b));
126 const T max = T(std::max(std::max(rgb.r,rgb.g),rgb.b));
127 const T delta = max - min;
131 if ( rgb.r == max )
h = (rgb.g-rgb.b) / delta;
132 else if (rgb.g == max)
h = T(2) + (rgb.b-rgb.r) / delta;
133 else h = T(4) + (rgb.r-rgb.g) / delta;
135 if (
h < T(0) )
h += T(1);
163 const T H = normal.
h * T(6);
164 const int Hi =
static_cast<int>(H);
165 const T fr = H - T(Hi);
166 const T m = normal.
v * (T(1)-normal.
s);
167 const T n = normal.
v * (T(1)-normal.
s*fr);
168 const T p = normal.
v * (T(1)-normal.
s*(T(1)-fr));
170 case 0:
return MQColor(
float(normal.
v),
float(p),
float(m) );
171 case 1:
return MQColor(
float(n),
float(normal.
v),
float(m) );
172 case 2:
return MQColor(
float(m),
float(normal.
v),
float(p) );
173 case 3:
return MQColor(
float(m),
float(n),
float(normal.
v) );
174 case 4:
return MQColor(
float(p),
float(m),
float(normal.
v) );
175 default:
return MQColor(
float(normal.
v),
float(m),
float(n) );
203 template <
typename T_MQPLUGIN>
friend class PluginBase;
206 Handle( MQBasePlugin* plugin ) { this->plugin = plugin; }
207 MQBasePlugin* plugin;
212 bool Load(
const char *name,
bool& value,
bool default_value=
false);
213 bool Load(
const char *name,
int& value,
int default_value=0);
214 bool Load(
const char *name,
unsigned int& value,
unsigned int default_value=0);
215 bool Load(
const char *name,
float& value,
float default_value=0.0f);
216 bool Load(
const char *name, std::string& value, std::string default_value=
"");
217 bool Save(
const char *name,
const bool& value);
218 bool Save(
const char *name,
const int& value);
219 bool Save(
const char *name,
const unsigned int& value);
220 bool Save(
const char *name,
const float& value);
221 bool Save(
const char *name,
const char* value);
222 bool Save(
const char *name,
const std::string& value);
226 MQBasePlugin* m_plugin;
227 MQSetting* m_setting;
265 template <
typename T_MQPLUGIN>
class PluginBase :
public T_MQPLUGIN {
267 PluginBase(
const char* productName,
const char* pluginFullName,
const char* pluginString ) :
268 m_productName( productName ),
269 m_pluginFullName( pluginFullName ),
270 m_pluginString( pluginString ),
276 PluginBase(
const char* productName,
const char* pluginFullName,
const char* pluginString,
277 const DWORD idProduct,
const DWORD idPlugin ) :
278 m_productName( productName ),
279 m_pluginFullName( pluginFullName ),
280 m_pluginString( pluginString ),
281 m_idProduct( idProduct ),
282 m_idPlugin( idPlugin )
288 *Product = m_idProduct;
294 virtual const char *
EnumString() {
return m_pluginString.c_str(); }
306 const std::string m_productName;
307 const std::string m_pluginFullName;
308 const std::string m_pluginString;
309 const DWORD m_idProduct;
310 const DWORD m_idPlugin;
329 template <
typename T>
inline T
moveTo( T from, T to, T mov ) {
331 if ( std::abs(from - to) < mov )
return to;
332 return from += ( from < to ? mov : -mov );
338 template <
typename T>
inline T
clamp( T src, T min, T max ) {
339 return std::min( std::max(min,max), std::max( std::min(min,max), src) );
345 template <
typename T>
inline T
clamp01( T src ) {
return std::min(T(1),std::max(T(0),src)); }
350 template <
typename T>
inline T
trunc( T src ) {
if ( T(0) < src )
return std::floor(src);
return std::ceil(src); }
354 using namespace Math;
369 int index = prv_impl::GetIdentifiedIndex(doc, mat);
370 if ( index < 0 )
return false;
371 doc->DeleteMaterial(index);
return true;
376 int index = prv_impl::GetIdentifiedIndex(doc, obj);
377 if ( index < 0 )
return false;
378 doc->DeleteObject(index);
return true;
412 inline MQMaterial
GetMaterial(
const MQDocument doc,
const char* name ) {
return prv_impl::GetNamed<MQMaterial>( doc, name ); }
417 inline MQMaterial
GetMaterial(
const MQDocument doc,
const UINT
id ) {
418 #if 0x0310 <= MQPLUGIN_VERSION
419 if ( doc != NULL )
return doc->GetMaterialFromUniqueID(
id);
422 return prv_impl::GetIdentified<MQMaterial>( doc, id );
436 inline int GetMaterialIndex(
const MQDocument doc,
const char* name ) {
return prv_impl::GetNamedIndex<MQMaterial>( doc, name ); }
439 inline int GetMaterialIndex(
const MQDocument doc,
const UINT
id ) {
return prv_impl::GetIdentifiedIndex<MQMaterial>( doc, id ); }
452 std::vector<char> buf;
454 return std::string(&buf[0]);
466 inline MQObject
GetObject(
const MQDocument doc,
const char* name ) {
return prv_impl::GetNamed<MQObject>( doc, name ); }
471 inline MQObject
GetObject(
const MQDocument doc,
const UINT
id ) {
472 #if 0x0310 <= MQPLUGIN_VERSION
473 if ( doc != NULL )
return doc->GetObjectFromUniqueID(
id);
476 return prv_impl::GetIdentified<MQObject>(doc, id );
481 inline int GetObjectIndex(
const MQDocument doc,
const char* name ) {
return prv_impl::GetNamedIndex<MQObject>( doc, name ); }
484 inline int GetObjectIndex(
const MQDocument doc,
const UINT
id ) {
return prv_impl::GetIdentifiedIndex<MQObject>(doc, id ); }
486 #if 0x0310 <= MQPLUGIN_VERSION
492 return prv_impl::GetUnusedNameString<MQMaterial>( doc, base_name );
499 if ( base_name_material == NULL )
return prv_impl::GetUnusedNameString<MQMaterial>( doc );
500 return prv_impl::GetUnusedNameString<MQMaterial>( doc,
GetName( base_name_material ).c_str() );
506 return prv_impl::GetUnusedNameString<MQObject>( doc, base_name );
513 if ( base_name_object == NULL )
return prv_impl::GetUnusedNameString<MQMaterial>( doc );
514 return prv_impl::GetUnusedNameString<MQMaterial>( doc,
GetName( base_name_object ).c_str() );
523 namespace prv_impl {};