00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __mitkMesh_h
00012 #define __mitkMesh_h
00013
00014 #include "mitkDataObject.h"
00015 #include "mitkGeometryTypes.h"
00016
00024 class MITK_COMMON_API mitkMesh : public mitkDataObject
00025 {
00026 public:
00027 MITK_TYPE(mitkMesh, mitkDataObject)
00028
00029 virtual void PrintSelf(ostream &os);
00030
00036 virtual void Initialize();
00037
00042 virtual void ShallowCopy(mitkDataObject *src);
00043
00048 virtual void DeepCopy(mitkDataObject *src);
00049
00056 bool CopyMesh(mitkMesh *src);
00057
00062 virtual int GetDataObjectType() const { return MITK_MESH; }
00063
00068 virtual void SetVertexNumber(size_type number) = 0;
00069
00074 virtual size_type GetVertexNumber() const = 0;
00075
00080 virtual void SetFaceNumber(size_type number) = 0;
00081
00086 virtual size_type GetFaceNumber() const = 0;
00087
00094 virtual float* GetVertexData() = 0;
00095
00102 virtual index_type* GetFaceData() = 0;
00103
00109 float const * GetBoundingBox() { return m_BoundingBox; }
00110
00120 void GetBoundingBox(float &minX, float &maxX, float &minY, float &maxY, float &minZ, float &maxZ);
00121
00131 void GetBoundingBox(float bounds[6]);
00132
00142 void SetBoundingBox(float minX, float maxX, float minY, float maxY, float minZ, float maxZ);
00143
00153 void SetBoundingBox(float bounds[6]);
00154
00159 bool IsNormalReversed() const { return m_IsNormalReversed; }
00160
00165 bool IsClockwise() const { return m_IsClockwise; }
00166
00171 void SetClockwise(bool isClockwise = true) { m_IsClockwise = isClockwise; }
00172
00178 virtual bool TestClockwise() = 0;
00179
00183 virtual void ReverseNormals() {};
00184
00208 index_type AddVertex(Vertex3f &vert) { return this->_addVertex(vert); }
00209
00227 template <typename IndexType, unsigned int indexNum>
00228 index_type AddFace(_face_type<IndexType, indexNum> &face) { return this->_addFace(face.vertNum, face.verts); }
00229
00233 index_type AddFace(TriangleFace &face) { return this->_addFace(face.vertNum, face.verts); }
00234
00241 bool GetVertex(index_type vertIdx, Vertex3f &vert)
00242 {
00243 if (vertIdx<0 || vertIdx>=this->GetVertexNumber()) return false;
00244 Vertex3f const *v = this->_getVertex(vertIdx);
00245 if (v==NULL) return false;
00246 vert = *v; return true;
00247 }
00248
00256 size_type GetVertices(index_type startIdx, size_type num, Vertex3f *verts)
00257 {
00258 if (startIdx<0 || startIdx>=this->GetVertexNumber()) return 0;
00259 return this->_getVertices(startIdx, num, verts);
00260 }
00261
00268 template <typename IndexType, unsigned int indexNum>
00269 bool GetFace(index_type faceIdx, _face_type<IndexType, indexNum> &face)
00270 {
00271 if (faceIdx<0 || faceIdx>=this->GetFaceNumber()) return false;
00272 index_type const *vi = this->_getFace(faceIdx);
00273 if (vi==NULL) return false;
00274 for (int i=0; i<face.vertNum; ++i) face.verts[i] = vi[i];
00275 return true;
00276 }
00277
00281 bool GetFace(index_type faceIdx, TriangleFace &face)
00282 {
00283 if (faceIdx<0 || faceIdx>=this->GetFaceNumber()) return false;
00284 index_type const *vi = this->_getFace(faceIdx);
00285 if (vi==NULL) return false;
00286 face.verts[0] = vi[0];
00287 face.verts[1] = vi[1];
00288 face.verts[2] = vi[2];
00289 return true;
00290 }
00291
00299 size_type GetTriangleFaces(index_type startIdx, size_type num, TriangleFace *faces)
00300 {
00301 if (startIdx<0 || startIdx>=this->GetFaceNumber()) return 0;
00302 return this->_getTriangleFaces(startIdx, num, faces);
00303 }
00304
00312 size_type GetTriangleFaces(index_type startIdx, size_type num, Vertex3f *verts)
00313 {
00314 if (startIdx<0 || startIdx>=this->GetFaceNumber()) return 0;
00315 return this->_getTriangleFaces(startIdx, num, verts);
00316 }
00317
00324 bool SetVertex(index_type vertIdx, Vertex3f const &vert)
00325 {
00326 if (vertIdx<0 || vertIdx>=this->GetVertexNumber()) return false;
00327 Vertex3f *v = this->_getVertexForWrite(vertIdx);
00328 if (v==NULL) return false;
00329 *v = vert; return true;
00330 }
00331
00338 template <typename IndexType, unsigned int indexNum>
00339 bool SetFace(index_type faceIdx, _face_type<IndexType, indexNum> &face)
00340 {
00341 if (faceIdx<0 || faceIdx>=this->GetFaceNumber()) return false;
00342 return this->_setFace(faceIdx, face.vertNum, face.verts);
00343 }
00344
00348 bool SetFace(index_type faceIdx, TriangleFace &face)
00349 {
00350 if (faceIdx<0 || faceIdx>=this->GetFaceNumber()) return false;
00351 return this->_setFace(faceIdx, face.vertNum, face.verts);
00352 }
00353
00354 protected:
00355 enum Orientation { CLOCKWISE, ANTICLOCKWISE, DEGENERATIVE };
00356
00357 mitkMesh();
00358 virtual ~mitkMesh();
00359
00360 virtual index_type _addVertex(Vertex3f &vert) = 0;
00361 virtual index_type _addFace(unsigned int num, index_type *verts) = 0;
00362 virtual Vertex3f const* _getVertex(index_type vertIdx) = 0;
00363 virtual index_type const* _getFace(index_type faceIdx) = 0;
00364 virtual Vertex3f* _getVertexForWrite(index_type vertIdx) = 0;
00365 virtual index_type* _getFaceForWrite(index_type faceIdx) = 0;
00366
00367
00368 virtual size_type _getVertices(index_type startIdx, size_type num, Vertex3f *verts);
00369 virtual size_type _getTriangleFaces(index_type startIdx, size_type num, TriangleFace *faces);
00370 virtual size_type _getTriangleFaces(index_type startIdx, size_type num, Vertex3f *verts);
00371 virtual bool _setFace(index_type faceIdx, unsigned int num, index_type *verts);
00372
00373 float m_BoundingBox[6];
00374 bool m_IsClockwise;
00375 bool m_IsNormalReversed;
00376
00377 private:
00378 mitkMesh(const mitkMesh&);
00379 void operator = (const mitkMesh&);
00380
00381 };
00382
00383 inline void mitkMesh::GetBoundingBox(float &minX, float &maxX, float &minY, float &maxY, float &minZ, float &maxZ)
00384 {
00385 minX = m_BoundingBox[0];
00386 maxX = m_BoundingBox[1];
00387 minY = m_BoundingBox[2];
00388 maxY = m_BoundingBox[3];
00389 minZ = m_BoundingBox[4];
00390 maxZ = m_BoundingBox[5];
00391 }
00392
00393 inline void mitkMesh::GetBoundingBox(float bounds[6])
00394 { this->GetBoundingBox(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]); }
00395
00396 inline void mitkMesh::SetBoundingBox(float minX, float maxX, float minY, float maxY, float minZ, float maxZ)
00397 {
00398 m_BoundingBox[0] = minX;
00399 m_BoundingBox[1] = maxX;
00400 m_BoundingBox[2] = minY;
00401 m_BoundingBox[3] = maxY;
00402 m_BoundingBox[4] = minZ;
00403 m_BoundingBox[5] = maxZ;
00404 }
00405
00406 inline void mitkMesh::SetBoundingBox(float bounds[6])
00407 { this->SetBoundingBox(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]); }
00408
00409
00410
00411
00412
00413
00414 #endif
00415