MeVisLabToolboxReference
MeVisLab/Standard/Sources/ML/MLCSO/CSOBase/CSOAttributes.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00005 
00010 //----------------------------------------------------------------------------------
00011 
00012 #ifndef __CSOAttributes_H
00013 #define __CSOAttributes_H
00014 
00015 
00016 #include "MLCSOIncludes.h"
00017 #include "CSODefines.h"
00018 #include "CSOPathPoints.h"
00019 
00020 
00021 #include <mlVariant.h>
00022 
00023 
00024 ML_START_NAMESPACE
00025 
00026 class CSO;
00027 class CSOGroup;
00028 
00030 
00031 template < typename T >
00032 bool CSOWriteValueToStream(std::ostream& out, const T& value, bool asBinary)
00033 {
00034   Variant v(value);
00035   v.write(out, asBinary);
00036   if (!asBinary) { out << std::endl; }
00037   return !out.bad();
00038 }
00039 
00040 template <>
00041 inline bool CSOWriteValueToStream<Variant>(std::ostream& out, const Variant& value, bool asBinary)
00042 {
00043   value.write(out, asBinary);
00044   if (!asBinary) { out << std::endl; }
00045   return !out.bad();
00046 }
00047 
00048 template <>
00049 inline bool CSOWriteValueToStream<CSOPathPoints>(std::ostream& out, const CSOPathPoints& value, bool asBinary)
00050 {
00051   Variant numPathPoints(value.numPathPoints());
00052   numPathPoints.write(out, asBinary);
00053   if (!asBinary) { Variant::writeValue(out, " ", asBinary); }
00054 
00055   for (int k = 0; k < numPathPoints.toInt(); ++k)
00056   {
00057     Vector3 pos = value.getPosAt(k);
00058     for (int i = 0; i < 3; ++i) 
00059     {
00060       Variant::writeValue(out, pos[i], asBinary);
00061       if (!asBinary) { Variant::writeValue(out, " ", asBinary); }
00062     }
00063   }
00064   if (!asBinary) { out << std::endl; }
00065   return !out.bad();
00066 }
00067 
00069 
00070 template < typename T >
00071 bool CSOReadValueFromStream(std::istream& in, T& value, bool asBinary)
00072 {
00073   Variant v;
00074   v.read(in, asBinary);
00075   if (!asBinary) { in.ignore(); }
00076   if (v.isValid())
00077   {
00078     value = v.asType<T>();
00079     return !in.bad();
00080   }
00081   else 
00082   {
00083     return false;
00084   }
00085 }
00086 
00087 template <>
00088 inline bool CSOReadValueFromStream<Variant>(std::istream& in, Variant& value, bool asBinary)
00089 {
00090   value.read(in, asBinary);
00091   if (!asBinary) { in.ignore(); }
00092   return !in.bad();
00093 }
00094 
00095 template <>
00096 inline bool CSOReadValueFromStream<CSOPathPoints>(std::istream& in, CSOPathPoints& value, bool asBinary)
00097 {
00098   Variant numPathPoints;
00099   numPathPoints.read(in, asBinary);
00100   if (!numPathPoints.isValid())
00101   {
00102     return false;
00103   }
00104 
00105   for (int k = 0; k < numPathPoints.toInt(); ++k)
00106   {
00107     Vector3 pos;
00108     for (int i = 0; i < 3; ++i) 
00109     {
00110       Variant::readValue(in, pos[i], asBinary);
00111     }
00112     value.appendPosition(pos);
00113   }
00114   if (!asBinary) { in.ignore(); }
00115   return !in.bad();
00116 }
00117 
00119 
00122 class MLCSO_EXPORT CSOAttributes
00123 {
00124 
00125 public:
00126 
00128   CSOAttributes();
00130   ~CSOAttributes();
00131 
00133   void reset();
00134 
00136   bool writeToStream(std::ostream& outStream, bool asBinary) const;
00138   bool readFromStream(std::istream& inStream, bool asBinary, short version);
00139 
00141   bool saveTo(std::ostream& outStream) const;
00143   bool saveToASCII(std::ostream& outStream) const;
00144 
00146   void loadFrom(std::istream& inStream, short version, bool swapBytes);
00148   void loadFromASCII(std::istream& inStream, short version);
00149 
00151   void setCSO(CSO* cso);
00153   void setCSOGroup(CSOGroup* group);
00154 
00156   std::string label;   
00158   std::string description;
00159 
00161   int timePointIndex;
00163   bool showState;
00165   bool voxelizeState;
00167   bool editableState;
00168 
00170   Vector3 pathPointColor;
00172   float pathPointAlpha;
00174   int pathPointStyle;
00176   float pathPointWidth;
00177 
00179   int seedPointStyle;
00181   float seedPointSize;
00183   Vector3 seedPointColor;
00185   float seedPointAlpha;
00186 
00188   int voxelWriteMode;
00190   float voxelWriteValue;
00191 
00196 
00197   void setUserData(const std::string& name, Variant value);
00199   Variant getUserData(const std::string& name) const;
00201   void getUserDataNames(std::vector< std::string >& names) const;
00203   void removeUserData(const std::string& name);
00205 
00206 
00207 private:
00208 
00210   void sendAttributesChangedPreEvent();
00212   void sendAttributesChangedPostEvent();
00213 
00215   CSO* _associatedCSO;
00217   CSOGroup* _associatedCSOGroup;
00218 
00220   std::map < std::string, Variant > _variantMap;
00221 };
00222 
00224 
00225 
00226 ML_END_NAMESPACE
00227 
00228 
00229 #endif // __CSOAttributes_H
00230 
00231 
00232