User manual:   Main Page   Overview   Installation   User Interface   Tutorial   Example   FAQ   Version Updates
Reference manual:   Class List   Class Members   Globals, enums and defines

mesh.h

Go to the documentation of this file.
00001 // mesh.h
00002 
00003 #ifndef MESH_H
00004 #define MESH_H
00005 
00006 #include "renderer.h"
00007 #include "params.h"
00008 #include "info.h"
00009 #include "corner.h"
00010 #include "edge.h"
00011 #include "face.h"
00012 #include "vr.h"
00013 #include "wrl.h"
00014 
00015 class Renderer;
00016 class Scenes;
00017 
00022 class Mesh {
00023 
00024         friend Renderer;
00025         friend Scenes;
00026 
00027 public:
00028 
00029 #ifndef SKIP_THIS
00030         Mesh();
00031         ~Mesh();
00032 #endif
00033 
00034         /************************************************/
00037 
00050         RESULT openVRMLFile(const char* fileName);      
00061         RESULT saveVRMLFile(const char* fileName = NULL);
00071         RESULT VRMLExport(const char* fileName);
00078         RESULT getFileName(char* fileName);
00079 
00081 
00082         /************************************************/
00085 
00096         RESULT getBoundingBox(Coord &bBoxMin, Coord &bBoxMax, Coord &bBoxDim, Coord &center);
00106         RESULT getIFS(VRIndexedFaceSet* IFS);
00112         RESULT setIFS(const VRIndexedFaceSet* IFS);     
00118         RESULT startNewModel();
00119 
00121 
00122         /************************************************/
00125 
00132         RESULT addLine(Line line, LineID &lineID, const Color* color = NULL);
00139         RESULT setLine(LineID lineID, Line line);
00146         RESULT getLine(LineID lineID, Line& line);
00153         RESULT setLineWidth(LineID lineID, double width=DEFAULT_LINE_WIDTH);
00160         RESULT getLineWidth(LineID lineID, double &width);
00166         RESULT removeLine(LineID lineID);
00170         RESULT removeAllLines();
00171 
00173 
00174         /************************************************/
00177 
00184         RESULT addSphere(Sphere sphere, SphereID &sId, const Color* color = NULL);
00191         RESULT setSphere(SphereID sId, Sphere sphere);
00198         RESULT getSphere(SphereID sId, Sphere& sphere);
00204         RESULT removeSphere(SphereID sId);
00208         RESULT removeAllSpheres();
00209 
00211 
00212         /************************************************/
00215 
00222         RESULT addCylinder(Cylinder cylinder, CylinderID &cId, const Color* color = NULL);
00229         RESULT setCylinder(CylinderID cId, Cylinder cylinder);
00236         RESULT getCylinder(CylinderID cId, Cylinder& cylinder);
00242         RESULT removeCylinder(CylinderID cId);
00246         RESULT removeAllCylinders();
00247 
00249 
00250         /************************************************/
00253 
00258         RESULT getVerticesCount(VertexID& count);
00259 
00265         RESULT getEdgesCount(EdgeID& count);
00266 
00272         RESULT getEdgesIDsCount(EdgeID& count);
00273 
00278         RESULT getFacesCount(FaceID& count);
00279 
00284         RESULT getLinesCount(LineID& count);
00285 
00290         RESULT getSpheresCount(SphereID& count);
00291 
00296         RESULT getCylindersCount(SphereID& count);
00297 
00304         RESULT setCoord(VertexID vID, Coord coord);     
00305 
00317         RESULT setCoords(const LinkedList<VertexID> *vertices, const LinkedList<Coord> *coords);
00318 
00325         RESULT getCoord(VertexID vID, Coord &coord);
00326 
00336         RESULT getCoords(const LinkedList<VertexID> *vertices, LinkedList<Coord> *coords);
00337 
00347         RESULT getAllCoords(LinkedList<VertexID> *vertices, LinkedList<Coord> *coords);
00348 
00355         RESULT getEdge(EdgeID eID, Edge& edge);
00356 
00363         RESULT getFace(FaceID fID, Face& face);
00364 
00374         RESULT getFaces(const LinkedList<FaceID> *facesids, LinkedList<Face> *faces);
00375 
00385         RESULT getAllFaces(LinkedList<FaceID> *facesids, LinkedList<Face> *faces);
00386 
00394         RESULT getOtherEdgeID(EdgeID eID, EdgeID& otherEdgeID);
00395 
00409         RESULT getJoinedFacesEdge(FaceID fID1, FaceID fID2, EdgeID &eID1, EdgeID &eID2);
00410 
00422         RESULT getJoinedVerticesEdge(VertexID vID1, VertexID vID2, EdgeID &eID1, EdgeID &eID2);
00423 
00434         RESULT getJoinedVerticesFace(VertexID vID1, VertexID vID2, VertexID vID3, FaceID &fID);
00435 
00445         RESULT getJoinedEdgesVertex(EdgeID eID1, EdgeID eID2, VertexID &vID);
00446 
00454         RESULT getVerticesOfEdge(EdgeID eID, VertexID &vID1,VertexID &vID2);
00455 
00462         RESULT getFaceOfEdge(EdgeID eID, FaceID &fID);
00463 
00476         RESULT getFaceNeighborhood(FaceID fID, LinkedList<VertexID>* vertices=NULL, LinkedList<EdgeID>* edges=NULL, LinkedList<FaceID>* faces=NULL);
00477 
00492         RESULT getNeighborhood(VertexID vID, LinkedList<VertexID>* vertices=NULL, LinkedList<EdgeID>* edges=NULL, LinkedList<FaceID>* faces=NULL);
00493 
00503         RESULT removeVertex(VertexID vID, LinkedList<FaceID>* removedFaces=NULL, LinkedList<EdgeID>* removedEdges=NULL);
00504 
00518         RESULT removeVertexTriangulate(VertexID vID, const LinkedList<Face>* newFaces, LinkedList<FaceID>* newFacesIDs=NULL, LinkedList<FaceID>* removedFaces=NULL, LinkedList<EdgeID>* removedEdges=NULL);
00519 
00528         RESULT removeFace(FaceID fID, LinkedList<VertexID>* affectedVertices=NULL, LinkedList<EdgeID>* removedEdges=NULL);
00529 
00545         RESULT edgeCollapse(VertexID vID1, VertexID vID2, const Coord *coordinate=NULL, LinkedList<FaceID>* removedFaces=NULL, LinkedList<EdgeID>* removedEdges=NULL);
00546 
00563         RESULT edgeCollapseGraphic(VertexID vID1, VertexID vID2, int steps, const Coord *coordinate=NULL, LinkedList<FaceID>* removedFaces=NULL, LinkedList<EdgeID>* removedEdges=NULL);
00564 
00580         RESULT vertexSplit(VertexID vID, Coord coordinate, VertexID left, VertexID right, VertexID& newVertex, LinkedList<FaceID>* newFacesIDs=NULL, LinkedList<FaceID>* removedFaces=NULL, LinkedList<EdgeID>* removedEdges=NULL);
00581 
00597         RESULT addVertex(Coord coordinate, VertexID& vID, const LinkedList<Edge>* neighbouringVertices = NULL, LinkedList<FaceID>* newFacesIDs = NULL);
00598 
00608         RESULT addFace(Face face, FaceID& fID, bool check=false, const Color* color=NULL);
00609 
00611 
00612         /************************************************/
00615 
00616         // indicates whether the model is empty
00617 #ifndef SKIP_THIS
00618         bool isEmpty();
00619 #endif
00620 
00624         bool isModelEmpty();
00629         bool isTotallyEmpty();
00634         bool hasLines();
00639         bool hasSpheres();
00644         bool hasCylinders();
00649         bool isValidVertexIndex(VertexID vID);
00654         bool isValidEdgeIndex(EdgeID eID);
00659         bool isValidFaceIndex(FaceID fID);
00664         bool isValidLineIndex(LineID lID);
00669         bool isValidSphereIndex(SphereID sID);
00674         bool isValidCylinderIndex(CylinderID cID);
00675 
00682         RESULT isBoundaryVertex(VertexID vID, bool& boundary);
00683 
00690         RESULT isBoundaryEdge(EdgeID eID, bool& boundary);
00691 
00698         RESULT isBoundaryFace(FaceID fID, bool& boundary);
00699 
00701 
00702         /********* Misc. ***********/
00703 
00704 #ifndef SKIP_THIS
00705         // set the renderer instance
00706         RESULT setRenderer(Renderer* renderer);
00707 #endif
00708 
00709 private:
00710 
00711         // The renderer instance
00712         Renderer* renderer;
00713         
00714         
00715         /********* projection settings. ***********/
00716 
00717         VRViewpoint*    vrViewpoint;
00718         VRSFFloat       clipNear;
00719         VRSFFloat       clipFar;
00720         VRSFFloat       frustumHalfWidth;
00721         VRSFFloat       paramScale;
00722         double          scalefactor;
00723         double          znear, zfar;
00724 
00725 
00726         /********* Normals ***********/
00727 
00728         // calculate normals
00729         void getNormals();
00730         void getFaceNormal(FaceID face, VRSFVec3f normal);
00731 
00732 
00733         /********* Bounding box ***********/
00734 
00735         VRSFVec3f bBoxMin; // min point
00736         VRSFVec3f bBoxMax; // max point
00737         VRSFVec3f bBoxDim; // bb dimensions
00738         VRSFVec3f center;  // bb center
00739 
00740         // calculate the bounding box
00741         void getBoundingBox();
00742         bool bboxValid;
00743 
00744 
00745         /********* I/O ***********/
00746 
00747         // current VRML file name
00748         char* fileName;
00749 
00750         // actually write the output file
00751         RESULT writeVRMLFile(bool export = false);
00752         // combine all IFS's into one IFS
00753         VRIndexedFaceSet* combineIFS(VRMFNode IFS_list);
00754         void getCubeVertices(VertexID v1, VertexID v2, Coord *coords, double dist);
00755         void getCubeVertices(Coord coord1, Coord coord2, Coord *coords, double dist);
00756 
00757 
00758         /********* mesh geometry ***********/
00759 
00760         // The combined IndexedFaceSet of the model
00761         VRIndexedFaceSet* vrIFS;
00762         // database (corner table)
00763         Corner*                 cornerTable;            // corner table
00764         // keeping validation + colors
00765         VertexInfo*             verticesInfo;           // vertices info: colors + validation + a list of corners
00766         EdgeInfo*               edgesInfo;                      // edges info: colors + validation
00767         FaceInfo*               facesInfo;                      // faces info: colors + validation
00768         // total size of vertices/edges/facesInfo (including empty places)
00769         long    verticesInfoSize;       
00770         long    edgesInfoSize;          
00771         long    facesInfoSize;          
00772         // lists of the empty vertices/faces places in the vertices/facesInfo array
00773         LinkedList<VertexID>    emptyVertices;  
00774         LinkedList<FaceID>              emptyFaces;     
00775         // counting vertices/edges/faces
00776         VertexID        numOfVertices;
00777         EdgeID          numOfEdges;
00778         FaceID          numOfPolys;
00779 
00780         // check validation for a vertex/edge/face ID
00781         bool    checkVertexIndex(VertexID vID);
00782         bool    checkEdgeIndex(EdgeID eID);
00783         bool    checkFaceIndex(FaceID fID);
00784         EdgeID  countDoubleEdges();
00785         RESULT  m_edgeCollapse(VertexID vertexID1, VertexID vertexID2, LinkedList<FaceID>* removedFaces=NULL, LinkedList<EdgeID>* removedEdges=NULL);
00786         RESULT  m_addFace(Face face, FaceID& faceId, bool check=false);
00787         RESULT  m_removeFace(FaceID faceID, LinkedList<VertexID>* affectedVertices=NULL, LinkedList<EdgeID>* removedEdges=NULL);
00788         RESULT  m_removeVertex(VertexID vertexID, LinkedList<FaceID>* removedFaces=NULL, LinkedList<EdgeID>* removedEdges=NULL);
00789         RESULT  m_addVertex(Coord coordinate, VertexID& newVertex, const LinkedList<Edge>* neighbouringVertices = NULL, LinkedList<FaceID>* newFacesIDs = NULL);
00790         bool    areNeighbours(VertexID vertexIndex1, VertexID vertexIndex2, FaceID &t1, FaceID &t2);
00791         FaceID  getNewFaceIndex();
00792         VertexID getNewVertexIndex();
00793          
00794         // reallocate memory for databases
00795         void    allocCornerTable(int oldSize, int newSize);
00796         void    allocFacesInfo(int oldSize, int newSize);
00797         void    allocEdgesInfo(int oldSize, int newSize);
00798         void    allocVerticesInfo(int oldSize, int newSize);
00799         void    allocLines(int oldSize, int newSize);
00800         void    allocLinesInfo(int oldSize, int newSize);
00801         void    allocSpheres(int oldSize, int newSize);
00802         void    allocCylinders(int oldSize, int newSize);
00803         void    allocSpheresInfo(int oldSize, int newSize);
00804         void    allocCylindersInfo(int oldSize, int newSize);
00805  
00806 
00807         /********* lines ***********/
00808 
00809         Line*           lines;                                  // lines
00810         LineInfo*       linesInfo;                      // lines info: colors + validation
00811         long            linesInfoSize;                  // the total size of linesInfo (including empty places)
00812         LineID          numOfLines;                             // total number of non-empty lines
00813         LinkedList<LineID> emptyLines;          // a list of the empty lines places in the lines array
00814 
00815         // check validation for a line ID
00816         bool    checkLineIndex(LineID lID);     
00817         LineID  getNewLineIndex();
00818 
00819         /********* spheres ***********/
00820 
00821         Sphere*                 spheres;                                // lines
00822         SphereInfo*             spheresInfo;                    // lines info: colors + validation
00823         long                    spheresInfoSize;                // the total size of linesInfo (including empty places)
00824         SphereID                numOfSpheres;                   // total number of non-empty lines
00825         LinkedList<SphereID>    emptySpheres;   // a list of the empty lines places in the lines array
00826 
00827         // check validation for a sphere ID
00828         bool            checkSphereIndex(SphereID sID); 
00829         SphereID        getNewSphereIndex();
00830 
00831         /********* cylinders ***********/
00832 
00833         Cylinder*                       cylinders;                              // lines
00834         CylinderInfo*           cylindersInfo;                  // lines info: colors + validation
00835         long                    cylindersInfoSize;              // the total size of linesInfo (including empty places)
00836         CylinderID              numOfCylinders;                 // total number of non-empty lines
00837         LinkedList<CylinderID>  emptyCylinders; // a list of the empty lines places in the lines array
00838 
00839         // check validation for a sphere ID
00840         bool            checkCylinderIndex(CylinderID cID);     
00841         CylinderID      getNewCylinderIndex();
00842         double          getAngle(Coord v1, Coord v2);
00843 
00844         /********* mutex ***********/
00845 
00846         HANDLE mutex;
00847 
00848         void lock();
00849         void unlock();
00850 };
00851 
00852 extern Mesh *mesh;
00853 
00854 #endif

MeshMaker 5.2 Manual
This software library was written by Roni Raab, ronir@cs.technion.ac.il.
Last updated on May 2003.
This software is for academic and research use only.