MeVisLabToolboxReference
|
00001 // **InsertLicense** code 00002 //---------------------------------------------------------------------------------- 00004 00011 #ifndef __WEMPatch_H 00012 #define __WEMPatch_H 00013 00014 #include "WEMNode.h" 00015 #include "WEMEdge.h" 00016 #include "WEMBoundingBox.h" 00017 #include "WEMAttributes.h" 00018 #include "WEMRequirements.h" 00019 #include "WEMPrimitiveValueList.h" 00020 #include "WEMDataStructure/WEMIndexVector.h" 00021 #include "WEMDataStructure/WEMVector.h" 00022 00023 ML_START_NAMESPACE 00024 00025 // Forward declarations 00026 class WEM; 00027 00029 00031 class MLWEM_EXPORT WEMPatch 00032 { 00033 public: 00035 WEMPatch(unsigned int bs = 8192); 00038 WEMPatch(WEM* wem, unsigned int bs = 8192); 00040 WEMPatch(const WEMPatch& wemPatch); 00042 virtual ~WEMPatch(); 00044 void dispose(); 00046 void addPatch(WEMPatch* wemPatch); 00047 00049 inline unsigned int getBlocksize() const { return _blocksize; } 00051 virtual PatchTypes getPatchType() const = 0; 00053 virtual inline unsigned int getNumFaces() const { return 0; } 00054 00056 00058 inline unsigned int getNumNodes() const { return _nodes->num(); } 00060 inline WEMIndexVector<WEMNode>* getNodes() { return _nodes; } 00062 inline const WEMIndexVector<WEMNode>* getNodes() const { return const_cast<WEMPatch*>(this)->getNodes(); } 00064 inline WEMNode* getNodeAt(unsigned int index) { return _nodes->at(index); } 00066 inline const WEMNode* getNodeAt(unsigned int index) const { return const_cast<WEMPatch*>(this)->getNodeAt(index); } 00070 WEMNode* addNode(); 00073 void delNode(WEMNode* node); 00076 void addNodeValues(WEMNode* target, WEMNode* source, double modifier); 00078 void averageNodeValues(WEMNode* target, WEMNode* source1, WEMNode* source2); 00080 void extendNodeValueLists(unsigned int number, double value); 00081 00083 00085 inline unsigned int getNumEdges() const { return _edges->num(); } 00087 inline WEMIndexVector<WEMEdge>* getEdges() { return _edges; } 00089 inline const WEMIndexVector<WEMEdge>* getEdges() const { return const_cast<WEMPatch*>(this)->getEdges(); } 00091 inline WEMEdge* getEdgeAt(unsigned int index) { return _edges->at(index); } 00093 inline const WEMEdge* getEdgeAt(unsigned int index) const { return const_cast<WEMPatch*>(this)->getEdgeAt(index); } 00096 inline WEMEdge* addEdge() { return _edges->append(); } 00098 inline void delEdge(WEMEdge* edge) { _edges->remove(edge); } 00100 inline bool hasEdges() const { return (_edges->num() > 0); } 00103 void addEdgeValues(WEMEdge* target, WEMEdge* source, double modifier); 00105 void extendEdgeValueLists(unsigned int number, double value); 00106 00108 00110 virtual WEMFace* getFaceAt(unsigned int index) = 0; 00112 virtual const WEMFace* getFaceAt(unsigned int index) const = 0; 00113 00116 virtual WEMFace* addFace() = 0; 00119 void addFaceValues(WEMFace* target, WEMFace* source, double modifier); 00121 void extendFaceValueLists(unsigned int number, double value); 00122 00124 00126 void setNodeTraversalState(bool state); 00128 void setEdgeTraversalState(bool state); 00130 void setFaceTraversalState(bool state); 00132 void computeNormals(); 00133 00135 00137 double getArea() const; 00139 double getVolume() const; 00141 bool pointsOutwards() const; 00142 00144 00146 inline WEMBoundingBox* getBoundingBox() { return _boundingBox; } 00148 inline const WEMBoundingBox* getBoundingBox() const { return const_cast<WEMPatch*>(this)->getBoundingBox(); } 00150 void computeBoundingBox(); 00152 void centerByBoundingBox(); 00153 00155 00158 inline double getLUTMin() const 00159 { 00160 const WEMPrimitiveValueList* pvl = getPrimitiveValueList("LUT"); 00161 if (pvl) { return pvl->getMinValue(); } 00162 else { return 0; } 00163 } 00166 inline double getLUTMax() const 00167 { 00168 const WEMPrimitiveValueList* pvl = getPrimitiveValueList("LUT"); 00169 if (pvl) { return pvl->getMaxValue(); } 00170 else { return 0; } 00171 } 00172 00174 00176 void setType(std::string type) { _type = type; } 00178 std::string getType() const { return _type; } 00180 void setCreatorId(int id) { _creatorId = id; } 00182 int getCreatorId() const { return _creatorId; } 00183 00185 00187 inline void setWEM(WEM* wem) { _wem = wem; } 00189 inline WEM* getWEM() { return _wem; } 00191 inline const WEM* getWEM() const { return const_cast<WEMPatch*>(this)->getWEM(); } 00192 00194 00196 inline void setLabel(std::string label) { _attributes.label = label; } 00198 inline std::string getLabel() const { return _attributes.label; } 00199 00201 inline void setDescription(std::string desc) { _attributes.description = desc; } 00203 inline std::string getDescription() const { return _attributes.description; } 00204 00206 00208 inline unsigned int getId() const { return _uniqueId; } 00209 00211 inline void setId(unsigned int newId) { _uniqueId = newId; } 00212 00214 00216 void deleteOrphanNodes(); 00217 00219 00221 void triangulate(WEMTrianglePatch* wemPatch, TriangulationModes triangulationMode); 00222 00224 void mirror(); 00225 00227 WEMPatch* makeCompatible(WEMRequirements* requirements, TriangulationModes triangulationMode); 00228 00230 00233 virtual void buildEdgeConnectivity(); 00234 00237 void buildLocalEdgeConnectivity(WEMFace *face); 00238 00240 00242 virtual void saveTo(std::ostream& outstream, ProgressField *progress=NULL, float ratio=1.0f, float offset=0.0f); 00244 virtual unsigned int loadFrom(std::istream& instream, short version, bool swapBytes, ProgressField *progressFld=NULL, float ratio=1.0f, float offset=0.0f); 00246 virtual unsigned int loadFrom(char *map, short version, bool swapBytes, ProgressField *progressFld=NULL, float ratio=1.0f, float offset=0.0f); 00247 00249 00252 WEMPrimitiveValueList* createOrGetPrimitiveValueList(std::string name); 00253 00256 WEMPrimitiveValueList* getPrimitiveValueList(std::string name); 00257 00260 const WEMPrimitiveValueList* getPrimitiveValueList(std::string name) const; 00261 00264 std::vector<std::string> getRegisteredPrimitiveValueLists() const; 00265 00266 00267 protected: 00268 00270 virtual void _addFaceUpdatePrimitiveValueLists(); 00271 00273 virtual void _delFaceUpdatePrimitiveValueLists(WEMFace *face); 00274 00276 virtual void _initMembers(unsigned int bs); 00278 WEMIndexVector<WEMNode>* _nodes; 00280 WEMIndexVector<WEMEdge>* _edges; 00282 unsigned int _blocksize; 00283 00285 unsigned int _uniqueId; 00287 WEM* _wem; 00289 std::string _type; 00291 int _creatorId; 00292 00294 WEMAttributes _attributes; 00296 WEMBoundingBox *_boundingBox; 00297 00299 std::vector<WEMPrimitiveValueList*> _primitiveValueLists; 00300 00301 private: 00302 00305 void _storePrimitiveValueListValue(unsigned int i, unsigned int index, double value); 00306 00307 }; 00308 00310 00311 ML_END_NAMESPACE 00312 00313 #endif // __WEM_H