MeVisLabToolboxReference
MeVisLab/Standard/Sources/ML/MLCSO/CSOBase/CSO.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00004 
00009 //----------------------------------------------------------------------------------
00010 
00011 #ifndef __CSO_H
00012 #define __CSO_H
00013 
00014 #include "MLCSOIncludes.h"
00015 
00016 #include "CSOAttributes.h"
00017 #include "CSOBase/CSOGroup.h"
00018 #include "CSOBase/CSOSeedPoint.h"
00019 #include "CSOBase/CSOPathPoints.h"
00020 #include "CSOBase/CSOBoundingBox.h"
00021 
00022 
00023 ML_START_NAMESPACE
00024 
00025 
00026 // Forward declaration.
00027 class CSOList;
00028 class CSOManager;
00029 
00030 
00032 
00038 class MLCSO_EXPORT CSO
00039 { 
00040 
00041 public:
00042 
00044   CSO();
00046   CSO(CSOList* csoList);
00050   CSO(const CSO &cso, CSOList* csoList=NULL, int csoId=-1);
00052   virtual ~CSO();
00053 
00054 
00055   /* METHODS */
00056 
00058 
00059   
00061   void reverseSeedPointOrder();
00062   
00065   void resortSeedPointsClockwise();
00066 
00068   inline void storeInUndoManager() { setInsertRemoveSeedPoint(); }
00069 
00070   CSOManager* getManager() const;
00071 
00076 
00077   void applyTransformationMatrix(const Matrix4& matrix);
00079   void moveSeedPointsAndPathPoints(float dx, float dy, float dz, int timepoint);
00081   void moveSeedPointsAndPathPoints(float dx, float dy, float dz);
00082 
00084   void setAbsoluteMovement(float fromX,float fromY,float fromZ, float toX,float toY,float toZ, int fromTimePointIndex, int toTimePointIndex);
00086   void moveSingleSeedPoint(CSOSeedPoint* sPoint, float dx, float dy, float dz);
00088   void setAbsoluteSeedPointMovement();
00090   void setSeedPointsAndPathPoints(const CSO* cso);
00092 
00097 
00098   CSOSeedPoint* appendSeedAndPathPoint();
00100   CSOSeedPoint* appendSeedAndPathPoint(const Vector3& position);
00102   CSOPathPoints* insertPathPointsEndStart();
00104   CSOSeedPoint* appendSeedPoint();
00106   CSOPathPoints* appendPathPoints();
00108   void removeSeedPoint(CSOSeedPoint* sPoint);
00110   void removeAllSeedAndPathPoints();
00112   CSOSeedPoint* insertSeedPointAt(CSOPathPoints* toBeSplitPath, const Vector3& toInsertPos);
00114   void setInsertRemoveSeedPoint();
00116 
00121 
00122   CSOSeedPoint* getSeedPointAt(unsigned int index) const;
00124   inline CSOSeedPoint* getFirstSeedPoint() const { if (numSeedPoints()) { return _seedPointList[0];                } else { return NULL; } }
00126   inline CSOSeedPoint* getLastSeedPoint()  const { if (numSeedPoints()) { return _seedPointList[numSeedPoints()-1];} else { return NULL; } }
00128   inline unsigned int numSeedPoints() const { return static_cast<unsigned int>(_seedPointList.size());  }
00130   bool getSeedPointIndex(CSOSeedPoint* sPoint, unsigned int& index) const;
00132   inline unsigned int numPathPointLists() const  { return static_cast<unsigned int>(_pathPointsList.size()); }
00134   void fillPathPointCoordinatesFlattened(std::vector<Vector3>& pathPointCoords) const;
00136   void fillPathPointCoordinatesFlattened(std::vector<Vector4>& pathPointCoordsAndValues) const;
00139   inline CSOPathPoints* getPathPointsAt(unsigned int index) const { return _pathPointsList[index]; }
00141   unsigned int getTotalNumPathPoints() const;
00143   unsigned int getTotalNumUniquePathPoints() const;
00145 
00147   bool isSelected() const;
00148 
00153 
00154   void addSelectedSeedPoint(CSOSeedPoint* sPoint);
00156   void setSelectedSeedPoint(CSOSeedPoint* sPoint);
00158   bool isSelectedSeedPoint(CSOSeedPoint* sPoint) const;
00160   void clearSelectedSeedPoints();
00162   unsigned int getNumSelectedSeedPoints() const;
00164   CSOSeedPoint* getSelectedSeedPointAt(unsigned int index) const;
00166 
00171 
00172   void addGroup(CSOGroup* group);
00174   void addGroup(unsigned int groupId);
00176   bool isInGroup(CSOGroup* group) const;
00177   // Returns whether this CSO is in a same Group as the given CSO.
00178   bool isInSameGroupsAs(CSO* cso) const;
00180   bool isInGroup(unsigned int groupId) const;
00182   inline unsigned int numGroups() const { return static_cast<unsigned int>(_csoGroupIds.size()); }
00184   CSOGroup* getGroupAt(unsigned int index) const;
00187   inline unsigned int getGroupIdAt(unsigned int index) const { return _csoGroupIds[index]; }
00189   void removeGroup(CSOGroup* group);
00191   void removeAllGroups();
00193 
00198 
00199   void setType(const std::string& type) { _type = type; }
00201   const std::string& getType() const { return _type; }
00203   void setSubType(const std::string& subtype) { _subtype = subtype; }
00205   const std::string& getSubType() const { return _subtype; }
00207   void setCreatorId(int id) { _creatorId = id; }
00209   int getCreatorId() const { return _creatorId; }
00211 
00216 
00217   void setUserData(const std::string& name, Variant value) { _attributes.setUserData(name, value); }
00219   Variant getUserData(const std::string& name) const { return _attributes.getUserData(name); }
00221   void getUserDataNames(std::vector< std::string >& names) const { _attributes.getUserDataNames(names); }
00223   void removeUserData(const std::string& name) { _attributes.removeUserData(name); }
00225 
00230 
00231   const CSOBoundingBox& getWorldBoundingBox() const;
00233   const CSOBoundingBox& getVoxelBoundingBox(const Matrix4& worldToVoxelMatrix) const;
00235   const CSOBoundingBox& getVoxelBoundingBoxSeedPoints(const Matrix4& worldToVoxelMatrix) const;
00237   void setWorldToVoxelMatrix(const Matrix4& mat);
00239   const Matrix4& getWorldToVoxelMatrix() const;
00241   inline bool isInPlane() { Vector3 dummy; return isInPlane(dummy); }
00243   bool isInPlane(Vector3& planeNormal);
00245   inline const Vector3& getPlaneNormal() const { if (!_hasValidPlaneStatus) { _computeIsInPlane(); } return _planeNormal; }
00247   inline void computePlaneNormal() { if (!_hasValidPlaneStatus) { _computeIsInPlane(); } }
00249   inline void setIsInPlane(bool status) { _isInPlane = status; }
00251   inline void setPlaneNormal(const Vector3& planeNormal) { _planeNormal = planeNormal; _hasValidPlaneStatus = true; }
00253   inline void invalidatePlaneNormal() { _hasValidPlaneStatus = false; }
00255   float getLength() const;
00257   inline double getArea() const { _computeArea(); return _area; }
00259   inline void invalidateArea() { _hasValidArea = false; }
00265   void setIsClosed(bool isClosed);
00267   inline bool isClosed() const { return _isClosed; }
00269   bool isPoint() const;
00271   inline void setIsFinished(bool isFinished) { _isFinished = isFinished; }
00273   inline bool getIsFinished() const { return _isFinished; }
00275   inline void setNeedsInterpolation(bool needsInterpolation) { _needsInterpolation = needsInterpolation; }
00277   inline bool getNeedsInterpolation() const { return _needsInterpolation; }
00279   void determineNeedsInterpolation();
00281   void setNeedInterpolationAllSeedPoints(bool needsInterpolation);
00283   inline void setNeedInterpolation(CSOSeedPoint* seedPoint) { if (seedPoint != NULL) { seedPoint->setNeedsInterpolation(true); _needsInterpolation = true; } }
00285   void pathChanged();
00287 
00292 
00293 
00294 
00295   void setCSOList(CSOList* csoList);   
00297   inline CSOList* getCSOList() const { return _csoList; }
00299   inline unsigned int getId() const  { return _uniqueId; }   
00301 
00306 
00307   void setLabel(const std::string& label);
00309   inline const std::string& getLabel() const { return _attributes.label; }
00311   void setDescription(std::string description);
00313   inline const std::string& getDescription() const { return _attributes.description; }
00314 
00316   void setTimePointIndex(int index);
00318   int getTimePointIndex() const;
00320   void setShowState(bool state);
00322   bool getShowState() const;
00324   void setVoxelizeState(bool state);
00326   bool getVoxelizeState() const;
00328   void setEditableState(bool state);
00330   bool getEditableState() const;    
00332   void setPathPointStyle(CSOLineStyle style);
00334   inline void setPathPointStyle(int style) { setPathPointStyle(static_cast<CSOLineStyle>(style)); }
00336   CSOLineStyle getPathPointStyle() const;
00338   void setPathPointWidth(float width);
00340   float getPathPointWidth() const;
00342   void setPathPointColor(const Vector3& color);
00344   Vector3 getPathPointColor() const;
00346   void setPathPointAlpha(float alpha);
00348   float getPathPointAlpha() const;
00350   void setSeedPointStyle(int style);
00352   int getSeedPointStyle() const;
00354   void setSeedPointSize(float size);
00356   float getSeedPointSize() const;
00358   void setSeedPointColor(const Vector3& color);
00360   Vector3 getSeedPointColor() const;
00362   void setSeedPointAlpha(float alpha);
00364   float getSeedPointAlpha() const;
00365 
00367   void setVoxelWriteMode(int mode);
00369   int getVoxelWriteMode() const;
00371   void setVoxelWriteValue(float value);
00373   float getVoxelWriteValue() const;
00374 
00376   void setAllValuesTo(float value);
00378 
00383 
00384   inline int getPrivateTimePointIndex() const { return _attributes.timePointIndex; }
00386   inline bool getPrivateShowState() const { return _attributes.showState; }
00388   inline bool getPrivateVoxelizeState() const { return _attributes.voxelizeState; }
00390   inline bool getPrivateEditableState() const { return _attributes.editableState; }
00392   inline int    getPrivatePathPointStyle() const { return _attributes.pathPointStyle; }
00394   inline float   getPrivatePathPointWidth() const { return _attributes.pathPointWidth; }
00396   inline Vector3 getPrivatePathPointColor() const { return _attributes.pathPointColor; }
00398   inline float   getPrivatePathPointAlpha() const { return _attributes.pathPointAlpha; }
00400   inline int     getPrivateSeedPointStyle() const { return _attributes.seedPointStyle; }
00402   inline float   getPrivateSeedPointSize() const { return _attributes.seedPointSize; }
00404   inline Vector3 getPrivateSeedPointColor() const { return _attributes.seedPointColor; }
00406   inline float   getPrivateSeedPointAlpha() const { return _attributes.seedPointAlpha; }
00407 
00409   inline int getPrivateVoxelWriteMode() const { return _attributes.voxelWriteMode; }
00411   inline float getPrivateVoxelWriteValue() const { return _attributes.voxelWriteValue; }
00412 
00413 
00415   inline void setPrivateIsFinished(bool isFinished) { _isFinished = isFinished; }
00417   inline void setPrivateIsClosed(bool isClosedP) { _isClosed = isClosedP; }
00419   inline void setPrivateIsInPlane(bool isInPlaneP) { _isInPlane = isInPlaneP; }
00421   inline void setPrivateBoundingBox(const CSOBoundingBox& bb) { _worldBoundingBox = bb; _hasValidWorldBoundingBox = true; }
00423   inline void setPrivatePlaneNormal(const Vector3& normal) { _planeNormal = normal; _hasValidPlaneStatus = true; }
00426   inline void setId(unsigned int newId) { _uniqueId = newId; }
00428 
00430   bool saveAttributes(std::ostream& outStream, bool useAscii=false);
00431 
00433   void loadAttributes(std::istream& inStream, short version, bool swapBytes, bool useAscii=false);
00434 
00435 #ifdef ML_DEPRECATED
00436 
00437 
00438 
00439   inline ML_DEPRECATED void moveSeedPoints(float dx, float dy, float dz, int timepoint) {
00440     moveSeedPointsAndPathPoints(dx,dy,dz,timepoint);
00441   }
00444   inline ML_DEPRECATED void setLineStyle(CSOLineStyle style) { setPathPointStyle(style); }
00447   inline ML_DEPRECATED CSOLineStyle getLineStyle() const { return getPathPointStyle(); }
00450   inline ML_DEPRECATED void setColor(const Vector3& color) { setPathPointColor(color); }
00453   inline ML_DEPRECATED Vector3 getColor() const { return getPathPointColor(); }
00456   inline ML_DEPRECATED void setAlpha(float alpha) { setPathPointAlpha(alpha); }
00459   inline ML_DEPRECATED float getAlpha() const { return getPathPointAlpha(); }
00462   inline ML_DEPRECATED void setLineWidth(float width) { setPathPointWidth(width); }
00465   inline ML_DEPRECATED float getLineWidth() const { return getPathPointWidth(); }
00468   inline ML_DEPRECATED void setMarkerMode(int mode) { setSeedPointStyle(mode); }
00471   inline ML_DEPRECATED int getMarkerMode() const { return getSeedPointStyle(); }
00474   inline ML_DEPRECATED void setMarkerColor(const Vector3& color) { setSeedPointColor(color); }
00477   inline ML_DEPRECATED Vector3 getMarkerColor() const { return getSeedPointColor(); }
00480   inline ML_DEPRECATED void setMarkerAlpha(float alpha) { setSeedPointAlpha(alpha); }
00483   inline ML_DEPRECATED float getMarkerAlpha() const { return getSeedPointAlpha();}
00486   inline ML_DEPRECATED void setMarkerSize(float size) { setSeedPointSize(size); }
00489   inline ML_DEPRECATED float getMarkerSize() const { return getSeedPointSize(); }
00492   inline ML_DEPRECATED CSOLineStyle getPrivateLineStyle() const { return static_cast<CSOLineStyle>(getPrivatePathPointStyle()); }
00495   inline ML_DEPRECATED Vector3 getPrivateColor() const { return getPrivatePathPointColor(); }
00498   inline ML_DEPRECATED float getPrivateAlpha() const { return getPrivatePathPointAlpha(); }
00501   inline ML_DEPRECATED float getPrivateLineWidth() const { return getPrivatePathPointWidth(); }
00504   inline ML_DEPRECATED int getPrivateMarkerMode() const { return getPrivateSeedPointStyle(); }
00507   inline ML_DEPRECATED Vector3 getPrivateMarkerColor() const { return getPrivateSeedPointColor(); }
00510   inline ML_DEPRECATED float getPrivateMarkerAlpha() const { return getPrivateSeedPointAlpha(); }
00513   inline ML_DEPRECATED float getPrivateMarkerSize() const { return getPrivateSeedPointSize(); }
00515 #endif
00516   
00517 protected:
00518 
00519 private:
00520 
00524   template <class Method>
00525   int getOverrideGroupIndexForAttribute(Method method) const; // (defined in source file)
00526 
00527   /* MEMBER VARIABLES */
00528 
00530   unsigned int _uniqueId;
00531 
00533   std::vector<CSOSeedPoint*> _seedPointList;
00535   std::vector<CSOPathPoints*> _pathPointsList;
00536 
00538   CSOList* _csoList;
00539 
00541   std::vector<unsigned int> _csoGroupIds;
00542 
00544   std::vector<unsigned int> _selectedSeedPointsIndices;
00545 
00547   std::string _type;   
00549   std::string _subtype;  
00551   int        _creatorId;
00552 
00554   CSOAttributes _attributes;
00555 
00557   mutable bool _hasValidWorldBoundingBox;
00559   mutable bool _hasValidVoxelBoundingBox;
00561   mutable bool _hasValidVoxelSeedPointBoundingBox;
00562 
00564   mutable bool _hasValidPlaneStatus;
00566   mutable bool _hasValidArea;
00567 
00569   mutable CSOBoundingBox _worldBoundingBox;
00571   mutable CSOBoundingBox _voxelBoundingBox;
00573   mutable CSOBoundingBox _voxelSeedPointBoundingBox;
00574 
00576   mutable Matrix4 _lastRecentBBWorldToVoxelMatrix;
00578   mutable Matrix4 _lastRecentSeedPointsBBWorldToVoxelMatrix;
00579 
00581   bool _isFinished;
00583   bool _isClosed;
00585   mutable bool _isInPlane;
00587   mutable Vector3 _planeNormal;
00588 
00590   bool _needsInterpolation;
00591 
00594   mutable Matrix4 _transformationMatrix;
00595 
00596 
00598   mutable double _area;
00599 
00600 
00601   /* METHODS */
00602 
00604   void _initMembers();
00605 
00607   void _computeIsInPlane() const;
00609   void _computeArea() const;
00611   void _resetSeedPathLinks();
00612 };
00613 
00615 
00616 
00617 ML_END_NAMESPACE
00618 
00619 
00620 #endif // __CSO_H
00621 
00622 
00623