|
Katana Plug-in APIs 0.1
|
00001 // Copyright (c) 2017 The Foundry Visionmongers Ltd. All Rights Reserved. 00002 00003 #ifndef FNVIEWER_PICKINGTYPES_H 00004 #define FNVIEWER_PICKINGTYPES_H 00005 00006 00007 00008 #include <FnViewer/plugin/FnMathTypes.h> 00009 #include <FnAttribute/FnAttribute.h> 00010 #include <FnAttribute/FnGroupBuilder.h> 00011 00012 #include <stdint.h> 00013 #include <sstream> 00014 #include <map> 00015 00016 namespace Foundry 00017 { 00018 namespace Katana 00019 { 00020 namespace ViewerAPI 00021 { 00022 00035 typedef uint64_t FnPickId; 00036 00037 00045 class PickedAttrsMap : public std::map<FnPickId, FnAttribute::Attribute> 00046 { 00047 public: 00048 00057 FnAttribute::GroupAttribute toGroupAttribute() 00058 { 00059 if (size() == 0) 00060 { 00061 return FnAttribute::GroupAttribute(); 00062 } 00063 00064 FnAttribute::GroupBuilder gb; 00065 for (const_iterator it = begin(); it != end(); ++it) 00066 { 00067 // Convert the \c FnPickId into a string representation 00068 std::ostringstream idStr; 00069 idStr << it->first; 00070 gb.set(idStr.str(), it->second); 00071 } 00072 00073 return gb.build(); 00074 } 00075 00084 void fromGroupAttribute(FnAttribute::GroupAttribute groupAttr) 00085 { 00086 clear(); 00087 00088 if (groupAttr.isValid()) 00089 { 00090 for (unsigned int i = 0; i < groupAttr.getNumberOfChildren(); ++i) 00091 { 00092 // Get the \c FnPickId by parsing the entry name 00093 FnPickId pickId; 00094 std::istringstream istr(groupAttr.getChildName(i)); 00095 istr >> pickId; 00096 (*this)[pickId] = groupAttr.getChildByIndex(i); 00097 } 00098 } 00099 } 00100 }; 00101 00110 inline void pickIdToColor(FnPickId pickId, Vec4i& color) 00111 { 00112 color.x = (pickId >> 24 & 0xff); 00113 color.y = (pickId >> 16 & 0xff); 00114 color.z = (pickId >> 8 & 0xff); 00115 color.w = (pickId & 0xff); 00116 } 00117 00126 inline void pickIdToColor(FnPickId pickId, Vec4f& color) 00127 { 00128 color.x = (float)(pickId >> 24 & 0xff) / 0xff; 00129 color.y = (float)(pickId >> 16 & 0xff) / 0xff; 00130 color.z = (float)(pickId >> 8 & 0xff) / 0xff; 00131 color.w = (float)(pickId & 0xff) / 0xff; 00132 } 00133 00136 } // ViewerAPI 00137 } // Katana 00138 } // Foundry 00139 00140 #endif /* FNVIEWER_PICKINGTYPES_H */
1.7.3