Newer
Older
Import / research / 3d-z-maps / mview-0.3.3 / mview / mesh.h
//
//    File: mesh.h
//
//    (C) 2000-2008 Helmut Cantzler
//
//    Licensed under the terms of the Lesser General Public License.
//

#ifndef _MESH_H
#define _MESH_H

#include <list>
#include <vector>
#include <map>

#include <stdio.h>
#include <string.h>

#include "shape.h"
#include "triangle.h"
#include "edge.h"
#include "vertex.h"

#ifdef WIN32
   #define strcasecmp stricmp
#endif

using namespace std;

typedef enum { LIST_MESH, P_MESH, GTS_MESH, VRML1_MESH, VRML2_MESH, PLY_MESH,
	       FEATURES_MESH, GEOMVIEW_MESH, OBJ_MESH, VTK_MESH, SHALLO_MESH, UNKNOWN_MESH } MeshType;

class Mesh
{
public:
  Mesh();
  virtual ~Mesh();
  
  void clear(void);

  void setMesh(Mesh *mesh);
  void addTriangle(Triangle *t);
  void addEdge(Edge *e);
  void addVertex(Vertex *v);
  void addMesh(Mesh *mesh);
  void addTriangles(list<Triangle*> *newTriangles,
		    const char *textureName = "", int clearMap = TRUE);
  void addEdges(list<Edge*> *newEdges, int clearMap = TRUE);
  void addVertices(list<Vertex*> *newVertices);

  void remove(Vertex *v);
  void remove(Edge *e);
  void remove(Triangle *t);

  Vertex* getVertex(unsigned int name) const;
  Edge* getEdge(unsigned int name) const;
  Triangle* getTriangle(unsigned int name) const;

  list<Vertex*>* getVertices(void) const;
  list<Edge*>* getEdges(void) const;
  list<Edge*>* getEdges(list<Edge*> *es) const;
  list<Triangle*>* getTriangles(void) const;
  Shape* getShape(unsigned int no) const;

  static int type(FILE *f);

  void setName(const char *n);
  void setPath(const char *p);
  char* getName() const;
  char* getPath() const;

  virtual int read(FILE *f, int (*updateProgress)(int pos),
		   void (*setTotal)(int size));
  virtual void write(FILE *f, const char *comment = "");

  void writePoints(FILE *f) const;
  void writeGtsPoints(FILE *f) const;

  void createEdges(void);

  int numberOfVertices(void) const;
  int numberOfEdges(void) const;
  int numberOfShapes(void) const;
  int numberOfTriangles(void) const;
  float getXMin(void) const;
  float getXMax(void) const;
  float getYMin(void) const;
  float getYMax(void) const;
  float getZMin(void) const;
  float getZMax(void) const;
  float averageTriangleSize(void) const;
  float getMaxVertexLength(void) const;
  MathVector getCentroid(void) const;
  void setMinMaxValues(void);

  void move(const MathVector *v);
  void moveToCentre(void);
  void scale(float scale);
  void scaleIntoNormalSphere(void);
  void calcOriginalCoordinates(const Vertex *v, Vertex *org) const;
  MathVector getModelCentroid(void) const;
  float getModelScale(void) const;
  void scaleAccordingToReferenceMesh(const Mesh *mesh);

  void negateSurfaceNormals(void);
  void removeDoublePoints(void);

  Vertex* findClosedPoint(const Vertex *v) const;

  void clearSelection(void);
  Vertex* selectVertex(unsigned int name);
  Edge* selectEdge(unsigned int name);
  Triangle* selectTriangle(unsigned int name);

  list<Vertex*> selectedVertices;
  list<Edge*> selectedEdges;
  list<Triangle*> selectedTriangles;

protected:
  // helper function for createEdges
  Edge* getEdge(map< pair<Vertex*,Vertex*>, Edge* > *edgeMap, 
		 Vertex *v1, Vertex *v2);

  // data
  vector<Shape*> *shapes;
  list<Triangle*> *triangles;
  list<Edge*> *edges;
  list<Vertex*> *vertices;
  int verNr, triNr, edgeNr;
  char *fileName, *path;

  // a map to avoid adding vertices more than once
  // in addTriangles() & addEdges()
  map<Vertex*, Vertex*> vertexMap;

  MathVector modelCentroid;
  float modelScale;

  float xMin, xMax, yMin, yMax, zMin, zMax;
};

#endif