├── .gitignore ├── BaseCode ├── .viewer_state.txt ├── Makefile ├── include │ ├── Application.h │ ├── Camera.h │ ├── Complex.h │ ├── DenseMatrix.h │ ├── DiscreteExteriorCalculus.h │ ├── Edge.h │ ├── Face.h │ ├── HalfEdge.h │ ├── Image.h │ ├── LinearContext.h │ ├── LinearEquation.h │ ├── LinearPolynomial.h │ ├── LinearSystem.h │ ├── Mesh.h │ ├── MeshIO.h │ ├── Quaternion.h │ ├── Real.h │ ├── Shader.h │ ├── SparseMatrix.h │ ├── Types.h │ ├── Utility.h │ ├── Variable.h │ ├── Vector.h │ ├── Vertex.h │ └── Viewer.h ├── obj │ └── .empty ├── shaders │ ├── fragment.glsl │ └── vertex.glsl └── src │ ├── Camera.cpp │ ├── Complex.cpp │ ├── DenseMatrix.cpp │ ├── DenseMatrix.inl │ ├── DiscreteExteriorCalculus.inl │ ├── Edge.cpp │ ├── Face.cpp │ ├── HalfEdge.cpp │ ├── Image.cpp │ ├── LinearContext.cpp │ ├── LinearEquation.cpp │ ├── LinearPolynomial.cpp │ ├── LinearSystem.cpp │ ├── Mesh.cpp │ ├── MeshIO.cpp │ ├── Quaternion.cpp │ ├── Real.cpp │ ├── Shader.cpp │ ├── SparseMatrix.cpp │ ├── SparseMatrix.inl │ ├── Variable.cpp │ ├── Vector.cpp │ ├── Vertex.cpp │ ├── Viewer.cpp │ └── main.cpp ├── Connection ├── Makefile ├── include │ ├── Application.h │ ├── Camera.h │ ├── Complex.h │ ├── DenseMatrix.h │ ├── Direction.h │ ├── DiscreteExteriorCalculus.h │ ├── Edge.h │ ├── Face.h │ ├── HalfEdge.h │ ├── HarmonicBases.h │ ├── Image.h │ ├── LinearContext.h │ ├── LinearEquation.h │ ├── LinearPolynomial.h │ ├── LinearSystem.h │ ├── Mesh.h │ ├── MeshIO.h │ ├── Quaternion.h │ ├── Real.h │ ├── Shader.h │ ├── SparseMatrix.h │ ├── TreeCotree.h │ ├── Types.h │ ├── Utility.h │ ├── Variable.h │ ├── Vector.h │ ├── Vertex.h │ └── Viewer.h ├── obj │ └── .empty ├── shaders │ ├── fragment.glsl │ └── vertex.glsl └── src │ ├── Camera.cpp │ ├── Complex.cpp │ ├── DenseMatrix.cpp │ ├── DenseMatrix.inl │ ├── DiscreteExteriorCalculus.inl │ ├── Edge.cpp │ ├── Face.cpp │ ├── HalfEdge.cpp │ ├── Image.cpp │ ├── LinearContext.cpp │ ├── LinearEquation.cpp │ ├── LinearPolynomial.cpp │ ├── LinearSystem.cpp │ ├── Mesh.cpp │ ├── MeshIO.cpp │ ├── Quaternion.cpp │ ├── Real.cpp │ ├── Shader.cpp │ ├── SparseMatrix.cpp │ ├── SparseMatrix.inl │ ├── Variable.cpp │ ├── Vector.cpp │ ├── Vertex.cpp │ ├── Viewer.cpp │ └── main.cpp ├── Elasticity ├── .viewer_state.txt ├── Makefile ├── include │ ├── .Elasticity.h.swo │ ├── .Elasticity.h.swp │ ├── .Viewer.h.swp │ ├── Application.h │ ├── Camera.h │ ├── Complex.h │ ├── DenseMatrix.h │ ├── DiscreteExteriorCalculus.h │ ├── Edge.h │ ├── Face.h │ ├── HalfEdge.h │ ├── Image.h │ ├── LinearContext.h │ ├── LinearEquation.h │ ├── LinearPolynomial.h │ ├── LinearSystem.h │ ├── Mesh.h │ ├── MeshIO.h │ ├── PolarDecomposition2x2.h │ ├── Quaternion.h │ ├── Real.h │ ├── Shader.h │ ├── SparseMatrix.h │ ├── Types.h │ ├── Utility.h │ ├── Variable.h │ ├── Vector.h │ ├── Vertex.h │ └── Viewer.h ├── obj │ └── .empty ├── shaders │ ├── fragment.glsl │ └── vertex.glsl └── src │ ├── Camera.cpp │ ├── Complex.cpp │ ├── DenseMatrix.cpp │ ├── DenseMatrix.inl │ ├── DiscreteExteriorCalculus.inl │ ├── Edge.cpp │ ├── Face.cpp │ ├── HalfEdge.cpp │ ├── Image.cpp │ ├── LinearContext.cpp │ ├── LinearEquation.cpp │ ├── LinearPolynomial.cpp │ ├── LinearSystem.cpp │ ├── Mesh.cpp │ ├── MeshIO.cpp │ ├── Quaternion.cpp │ ├── Real.cpp │ ├── Shader.cpp │ ├── SparseMatrix.cpp │ ├── SparseMatrix.inl │ ├── Variable.cpp │ ├── Vector.cpp │ ├── Vertex.cpp │ ├── Viewer.cpp │ └── main.cpp ├── Fairing ├── .viewer_state.txt ├── Makefile ├── include │ ├── Application.h │ ├── Camera.h │ ├── Complex.h │ ├── DenseMatrix.h │ ├── DiscreteExteriorCalculus.h │ ├── Edge.h │ ├── Face.h │ ├── HalfEdge.h │ ├── Image.h │ ├── LinearContext.h │ ├── LinearEquation.h │ ├── LinearPolynomial.h │ ├── LinearSystem.h │ ├── Mesh.h │ ├── MeshIO.h │ ├── Quaternion.h │ ├── Real.h │ ├── Shader.h │ ├── SparseMatrix.h │ ├── Types.h │ ├── Utility.h │ ├── Variable.h │ ├── Vector.h │ ├── Vertex.h │ └── Viewer.h ├── obj │ └── .empty ├── shaders │ ├── fragment.glsl │ └── vertex.glsl └── src │ ├── Camera.cpp │ ├── Complex.cpp │ ├── DenseMatrix.cpp │ ├── DenseMatrix.inl │ ├── DiscreteExteriorCalculus.inl │ ├── Edge.cpp │ ├── Face.cpp │ ├── HalfEdge.cpp │ ├── Image.cpp │ ├── LinearContext.cpp │ ├── LinearEquation.cpp │ ├── LinearPolynomial.cpp │ ├── LinearSystem.cpp │ ├── Mesh.cpp │ ├── MeshIO.cpp │ ├── Quaternion.cpp │ ├── Real.cpp │ ├── Shader.cpp │ ├── SparseMatrix.cpp │ ├── SparseMatrix.inl │ ├── Variable.cpp │ ├── Vector.cpp │ ├── Vertex.cpp │ ├── Viewer.cpp │ └── main.cpp ├── Flatten ├── .viewer_state.txt ├── include │ ├── Application.h │ ├── Camera.h │ ├── Complex.h │ ├── DenseMatrix.h │ ├── DiscreteExteriorCalculus.h │ ├── Edge.h │ ├── Face.h │ ├── HalfEdge.h │ ├── Image.h │ ├── LinearContext.h │ ├── LinearEquation.h │ ├── LinearPolynomial.h │ ├── LinearSystem.h │ ├── Mesh.h │ ├── MeshIO.h │ ├── Quaternion.h │ ├── Real.h │ ├── Shader.h │ ├── SparseMatrix.h │ ├── Types.h │ ├── Utility.h │ ├── Variable.h │ ├── Vector.h │ ├── Vertex.h │ └── Viewer.h ├── obj │ └── .empty ├── shaders │ ├── fragment.glsl │ └── vertex.glsl └── src │ ├── Camera.cpp │ ├── Complex.cpp │ ├── DenseMatrix.cpp │ ├── DenseMatrix.inl │ ├── DiscreteExteriorCalculus.inl │ ├── Edge.cpp │ ├── Face.cpp │ ├── HalfEdge.cpp │ ├── Image.cpp │ ├── LinearContext.cpp │ ├── LinearEquation.cpp │ ├── LinearPolynomial.cpp │ ├── LinearSystem.cpp │ ├── Mesh.cpp │ ├── MeshIO.cpp │ ├── Quaternion.cpp │ ├── Real.cpp │ ├── Shader.cpp │ ├── SparseMatrix.cpp │ ├── SparseMatrix.inl │ ├── Variable.cpp │ ├── Vector.cpp │ ├── Vertex.cpp │ ├── Viewer.cpp │ ├── main.cpp │ └── qcError.cpp ├── Geodesics ├── .viewer_state.txt ├── Makefile ├── include │ ├── Application.h │ ├── Camera.h │ ├── Complex.h │ ├── DenseMatrix.h │ ├── DiscreteExteriorCalculus.h │ ├── Edge.h │ ├── Face.h │ ├── HalfEdge.h │ ├── Image.h │ ├── LinearContext.h │ ├── LinearEquation.h │ ├── LinearPolynomial.h │ ├── LinearSystem.h │ ├── Mesh.h │ ├── MeshIO.h │ ├── Quaternion.h │ ├── Real.h │ ├── Shader.h │ ├── SparseMatrix.h │ ├── Types.h │ ├── Utility.h │ ├── Variable.h │ ├── Vector.h │ ├── Vertex.h │ └── Viewer.h ├── obj │ └── .empty ├── shaders │ ├── fragment.glsl │ └── vertex.glsl └── src │ ├── Camera.cpp │ ├── Complex.cpp │ ├── DenseMatrix.cpp │ ├── DenseMatrix.inl │ ├── DiscreteExteriorCalculus.inl │ ├── Edge.cpp │ ├── Face.cpp │ ├── HalfEdge.cpp │ ├── Image.cpp │ ├── LinearContext.cpp │ ├── LinearEquation.cpp │ ├── LinearPolynomial.cpp │ ├── LinearSystem.cpp │ ├── Mesh.cpp │ ├── MeshIO.cpp │ ├── Quaternion.cpp │ ├── Real.cpp │ ├── Shader.cpp │ ├── SparseMatrix.cpp │ ├── SparseMatrix.inl │ ├── Variable.cpp │ ├── Vector.cpp │ ├── Vertex.cpp │ ├── Viewer.cpp │ └── main.cpp ├── HOWTO ├── Hot2 ├── .viewer_state.txt ├── Makefile ├── include │ ├── Application.h │ ├── Camera.h │ ├── Complex.h │ ├── DenseMatrix.h │ ├── DiscreteExteriorCalculus.h │ ├── Edge.h │ ├── Face.h │ ├── HalfEdge.h │ ├── Image.h │ ├── LinearContext.h │ ├── LinearEquation.h │ ├── LinearPolynomial.h │ ├── LinearSystem.h │ ├── Mesh.h │ ├── MeshIO.h │ ├── Quaternion.h │ ├── Real.h │ ├── Shader.h │ ├── SparseMatrix.h │ ├── Types.h │ ├── Utility.h │ ├── Variable.h │ ├── Vector.h │ ├── Vertex.h │ └── Viewer.h ├── obj │ └── .empty ├── shaders │ ├── fragment.glsl │ └── vertex.glsl └── src │ ├── Camera.cpp │ ├── Complex.cpp │ ├── DenseMatrix.cpp │ ├── DenseMatrix.inl │ ├── DiscreteExteriorCalculus.inl │ ├── Edge.cpp │ ├── Face.cpp │ ├── HalfEdge.cpp │ ├── Image.cpp │ ├── LinearContext.cpp │ ├── LinearEquation.cpp │ ├── LinearPolynomial.cpp │ ├── LinearSystem.cpp │ ├── Mesh.cpp │ ├── MeshIO.cpp │ ├── Quaternion.cpp │ ├── Real.cpp │ ├── Shader.cpp │ ├── SparseMatrix.cpp │ ├── SparseMatrix.inl │ ├── Variable.cpp │ ├── Vector.cpp │ ├── Vertex.cpp │ ├── Viewer.cpp │ └── main.cpp ├── Slides ├── apps-siggraph2013.key └── theory-siggraph2013.key ├── libddg_userguide.pdf ├── notes-siggraph2013.pdf └── slides-siggraph2013.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | 4 | *.o 5 | *.swp 6 | 7 | Flatten/Makefile 8 | 9 | Flatten/flatten 10 | -------------------------------------------------------------------------------- /BaseCode/.viewer_state.txt: -------------------------------------------------------------------------------- 1 | 0.126663 2 | -0.0243652 3 | -0.989174 4 | 0.0699843 5 | 815 6 | 767 7 | -------------------------------------------------------------------------------- /BaseCode/Makefile: -------------------------------------------------------------------------------- 1 | ########################################################################################## 2 | 3 | # Specify library locations here (add or remove "#" marks to comment/uncomment lines for your platform) 4 | 5 | # Mac OS X 6 | DDG_INCLUDE_PATH = 7 | DDG_LIBRARY_PATH = 8 | DDG_BLAS_LIBS = -framework Accelerate 9 | DDG_SUITESPARSE_LIBS = -lspqr -lumfpack -lcholmod -lmetis -lcolamd -lccolamd -lcamd -lamd -ltbb -lm -lsuitesparseconfig 10 | DDG_OPENGL_LIBS = -framework OpenGL -framework GLUT 11 | 12 | # # Linux 13 | # DDG_INCLUDE_PATH = 14 | # DDG_LIBRARY_PATH = 15 | # DDG_BLAS_LIBS = -llapack -lblas -lgfortran 16 | # DDG_SUITESPARSE_LIBS = -lspqr -lcholmod -lmetis -lcolamd -lccolamd -lcamd -lamd -lm 17 | # DDG_OPENGL_LIBS = -lglut -lGL -lGLU -lX11 18 | 19 | # # Windows / Cygwin 20 | # DDG_INCLUDE_PATH = -I/usr/include/opengl -I/usr/include/suitesparse 21 | # DDG_LIBRARY_PATH = -L/usr/lib/w32api -L/usr/lib/suitesparse 22 | # DDG_BLAS_LIBS = -llapack -lblas 23 | # DDG_SUITESPARSE_LIBS = -lspqr -lcholmod -lcolamd -lccolamd -lcamd -lamd -lm 24 | # DDG_OPENGL_LIBS = -lglut32 -lglu32 -lopengl32 25 | 26 | ######################################################################################## 27 | 28 | TARGET = ddg 29 | CC = g++ 30 | LD = g++ 31 | CFLAGS = -O3 -Wall -Werror -ansi -pedantic $(DDG_INCLUDE_PATH) -I./include -I./src 32 | LFLAGS = -O3 -Wall -Werror -ansi -pedantic $(DDG_LIBRARY_PATH) 33 | LIBS = $(DDG_OPENGL_LIBS) $(DDG_SUITESPARSE_LIBS) $(DDG_BLAS_LIBS) 34 | 35 | ######################################################################################## 36 | ## !! Do not edit below this line 37 | 38 | HEADERS := $(wildcard include/*.h) 39 | SOURCES := $(wildcard src/*.cpp) 40 | OBJECTS := $(addprefix obj/,$(notdir $(SOURCES:.cpp=.o))) 41 | 42 | all: $(TARGET) 43 | 44 | $(TARGET): $(OBJECTS) 45 | $(LD) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LFLAGS) $(LIBS) 46 | 47 | obj/%.o: src/%.cpp ${HEADERS} 48 | $(CC) -c $< -o $@ $(CFLAGS) 49 | 50 | clean: 51 | rm -f $(OBJECTS) 52 | rm -f $(TARGET) 53 | rm -f $(TARGET).exe 54 | -------------------------------------------------------------------------------- /BaseCode/include/Application.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_APPLICATION_H 2 | #define DDG_APPLICATION_H 3 | 4 | namespace DDG 5 | { 6 | class Application 7 | { 8 | // 9 | // TODO: add your code here!!! 10 | // 11 | }; 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /BaseCode/include/DiscreteExteriorCalculus.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- DiscreteExteriorCalculus.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Static methods for building the fundamental discrete operators (exterior 6 | // derivative, Hodge star) for 0-, 1-, and 2-forms on a surface mesh. Methods 7 | // are templated on entry type, i.e., one can build either real- or complex- 8 | // matrices using the types DDG::Real and DDG::Complex, respectively. For 9 | // instance, to build the usual Laplacian on functions, one could write 10 | // 11 | // Mesh mesh; 12 | // SparseMatrix d0, star0, star1, Delta; 13 | // 14 | // ExteriorDerivative0Form::build( mesh, d0 ); 15 | // HodgeStar0Form::build( mesh, star0 ); 16 | // HodgeStar1Form::build( mesh, star1 ); 17 | // Delta = star0.inverse() * d0.transpose() * star1 * d0; 18 | // 19 | 20 | #ifndef DDG_DISCRETEEXTERIORCALCULUS_H 21 | #define DDG_DISCRETEEXTERIORCALCULUS_H 22 | 23 | #include "Mesh.h" 24 | #include "SparseMatrix.h" 25 | 26 | namespace DDG 27 | { 28 | template< class T > struct HodgeStar0Form { static void build( const Mesh& mesh, SparseMatrix& star0 ); }; 29 | template< class T > struct HodgeStar1Form { static void build( const Mesh& mesh, SparseMatrix& star1 ); }; 30 | template< class T > struct HodgeStar2Form { static void build( const Mesh& mesh, SparseMatrix& star2 ); }; 31 | template< class T > struct ExteriorDerivative0Form { static void build( const Mesh& mesh, SparseMatrix& d0 ); }; 32 | template< class T > struct ExteriorDerivative1Form { static void build( const Mesh& mesh, SparseMatrix& d1 ); }; 33 | } 34 | 35 | #include "DiscreteExteriorCalculus.inl" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /BaseCode/include/Edge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Edge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Edge stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its two associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_EDGE_H 11 | #define DDG_EDGE_H 12 | 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class Edge 18 | { 19 | public: 20 | HalfEdgeIter he; 21 | // points to one of the two halfedges associated with this edge 22 | 23 | int index; 24 | // unique integer ID in the range 0, ..., nEdges-1 25 | 26 | Edge() : index(0) { } 27 | }; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /BaseCode/include/Face.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Face.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Face stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_FACE_H 11 | #define DDG_FACE_H 12 | 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class Face 18 | { 19 | public: 20 | HalfEdgeIter he; 21 | // points to one of the halfedges associated with this face 22 | 23 | int index; 24 | // unique integer ID in the range 0, ..., nFaces-1 25 | 26 | Face() : index(0) { } 27 | 28 | bool isBoundary( void ) const; 29 | // returns true if this face corresponds to a 30 | // boundary loop; false otherwise 31 | 32 | double area( void ) const; 33 | // returns the triangle area 34 | 35 | Vector normal( void ) const; 36 | // returns the unit normal associated with this face; normal 37 | // orientation is determined by the circulation order of halfedges 38 | 39 | Vector circumcenter( void ) const; 40 | // returns triangle circumcenter 41 | 42 | Vector barycenter( void ) const; 43 | // returns triangle barycenter 44 | }; 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /BaseCode/include/HalfEdge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- HalfEdge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // HalfEdge is used to define mesh connectivity. (See the documentation for a 6 | // more in-depth discussion of the halfedge data structure.) 7 | // 8 | 9 | #ifndef DDG_HALFEDGE_H 10 | #define DDG_HALFEDGE_H 11 | 12 | #include "Vector.h" 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class HalfEdge 18 | { 19 | public: 20 | HalfEdgeIter next; 21 | // points to the next halfedge around the current face 22 | 23 | HalfEdgeIter flip; 24 | // points to the other halfedge associated with this edge 25 | 26 | VertexIter vertex; 27 | // points to the vertex at the "tail" of this halfedge 28 | 29 | EdgeIter edge; 30 | // points to the edge associated with this halfedge 31 | 32 | FaceIter face; 33 | // points to the face containing this halfedge 34 | 35 | bool onBoundary; 36 | // true if this halfedge is contained in a boundary 37 | // loop; false otherwise 38 | 39 | Vector texcoord; 40 | // texture coordinates associated with the triangle corner at the 41 | // "tail" of this halfedge 42 | 43 | double cotan( void ) const; 44 | // returns the cotangent of the angle opposing this edge 45 | 46 | Vector rotatedEdge( void ) const; 47 | // returns oriented edge vector rotated by PI/2 around face normal 48 | // if onBoundary, then return nil 49 | }; 50 | } 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /BaseCode/include/Image.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Image.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Image represents a color bitmap image. A simple example might look like 6 | // 7 | // Image im; 8 | // im.read( "input.tga" ); 9 | // // modify image data via im(x,y) = ...; 10 | // im.write( "output.tga" ); 11 | // 12 | 13 | #ifndef DDG_IMAGE_H 14 | #define DDG_IMAGE_H 15 | 16 | #include 17 | #include 18 | 19 | namespace DDG 20 | { 21 | class Image 22 | { 23 | public: 24 | Image( int width = 0, int height = 0 ); 25 | // constructs image with specified width and height 26 | 27 | float& operator()( int x, int y ); 28 | const float& operator()( int x, int y ) const; 29 | // accesses pixel (x,y) 30 | 31 | float sample( float x, float y ) const; 32 | // samples image at (x,y) using bilinear filtering 33 | 34 | int width( void ) const; 35 | int height( void ) const; 36 | // returns image dimensions 37 | 38 | void read( const char* filename ); 39 | // loads an image file in Truevision TGA format 40 | // (must be RGB image with 24 or 32 bits per pixel) 41 | 42 | void write( const char* filename ) const; 43 | // writes an image file in Truevision TGA format 44 | // (RGB image with 24 bits per pixel) 45 | 46 | protected: 47 | void clamp( int& x, int& y ) const; 48 | // clamps coordinates to range [0,w-1] x [0,h-1] 49 | 50 | int w, h; 51 | // width and height 52 | 53 | std::vector pixels; 54 | // interleaved RGBA pixel data in range [0-1] 55 | }; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /BaseCode/include/LinearContext.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearContext.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearContext is the global solver context needed to interface with the 6 | // SuiteSparse library. It is essentially a wrapper around cholmod_common. A 7 | // single static instance of LinearContext is declared in LinearContext.cpp and 8 | // is shared by all instances of DenseMatrix, SparseMatrix, and LinearSystem. 9 | // In other words, you shouldn't have to instantiate LinearContext yourself 10 | // unless you're doing something really fancy! 11 | // 12 | 13 | #ifndef DDG_LINEARSOLVERCONTEXT 14 | #define DDG_LINEARSOLVERCONTEXT 15 | 16 | #include 17 | 18 | namespace DDG 19 | { 20 | class LinearContext 21 | { 22 | public: 23 | LinearContext( void ); 24 | // constructor 25 | 26 | ~LinearContext( void ); 27 | // destructor 28 | 29 | operator cholmod_common*( void ); 30 | // allows LinearContext to be treated as a cholmod_common* 31 | 32 | protected: 33 | cholmod_common context; 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /BaseCode/include/LinearEquation.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearEquation.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearEquation represents an equation with an arbitrary linear polynomial on 6 | // both the left- and right-hand side. It is primarily used while building a 7 | // LinearSystem. For convenience, operator== is overloaded so that the user 8 | // can construct a LinearEquation by writing something that looks much like the 9 | // usual mathematical syntax for a linear equation. For example, 10 | // 11 | // LinearEquation eqn = ( x + 2*y == 3*z ); 12 | // 13 | // builds the linear equation x + 2y = 3z. 14 | // 15 | 16 | #ifndef DDG_LINEAREQUATION_H 17 | #define DDG_LINEAREQUATION_H 18 | 19 | #include "LinearPolynomial.h" 20 | 21 | namespace DDG 22 | { 23 | class LinearEquation 24 | { 25 | public: 26 | LinearPolynomial lhs; 27 | // left-hand side 28 | 29 | LinearPolynomial rhs; 30 | // right-hand side 31 | }; 32 | 33 | LinearEquation operator==( const LinearPolynomial& lhs, const LinearPolynomial& rhs ); 34 | // constructs a linear equation with the specified left- and right-hand side 35 | } 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /BaseCode/include/MeshIO.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- MeshIO.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // MeshIO handles input/output operations for Mesh objects. Currently the only 6 | // supported mesh format is Wavefront OBJ -- for a format specification see 7 | // 8 | // http://en.wikipedia.org/wiki/Wavefront_.obj_file 9 | // 10 | // Note that vertex normals and material properties are currently ignored. 11 | // 12 | 13 | #ifndef DDG_MESHIO_H 14 | #define DDG_MESHIO_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace DDG 22 | { 23 | class Mesh; 24 | class Index; 25 | class MeshData; 26 | 27 | class MeshIO 28 | { 29 | public: 30 | static int read( std::istream& in, Mesh& mesh ); 31 | // reads a mesh from a valid, open input stream in 32 | 33 | static void write( std::ostream& out, const Mesh& mesh ); 34 | // writes a mesh to a valid, open output stream out 35 | 36 | protected: 37 | static int readMeshData( std::istream& in, MeshData& data ); 38 | static void readPosition( std::stringstream& ss, MeshData& data ); 39 | static void readTexCoord( std::stringstream& ss, MeshData& data ); 40 | static void readNormal ( std::stringstream& ss, MeshData& data ); 41 | static void readFace ( std::stringstream& ss, MeshData& data ); 42 | static Index parseFaceIndex( const std::string& token ); 43 | static void preallocateMeshElements( const MeshData& data, Mesh& mesh ); 44 | static int buildMesh( const MeshData& data, Mesh& mesh ); 45 | static void checkIsolatedVertices( const Mesh& Mesh ); 46 | static void checkNonManifoldVertices( const Mesh& Mesh ); 47 | }; 48 | } 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /BaseCode/include/Real.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_REAL_H 2 | #define DDG_REAL_H 3 | 4 | namespace DDG 5 | { 6 | class Real 7 | { 8 | public: 9 | Real( double x = 0. ); 10 | // constructs real number with value x 11 | 12 | operator double( void ) const; 13 | // type cast to double 14 | 15 | void operator+=( double x ); 16 | // increment 17 | 18 | void operator-=( double x ); 19 | // decrement 20 | 21 | void operator*=( double x ); 22 | // multiply 23 | 24 | void operator/=( double x ); 25 | // divide 26 | 27 | Real conj( void ) const; 28 | // simply returns the value (for compatibility w/ complex numbers) 29 | 30 | Real inv( void ) const; 31 | // returns inverse 32 | 33 | double norm( void ) const; 34 | // returns norm 35 | 36 | double norm2( void ) const; 37 | // returns norm squared 38 | 39 | Real unit( void ) const; 40 | // returns number with unit norm and same sign 41 | 42 | protected: 43 | double value; 44 | // value 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /BaseCode/include/Shader.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Shader.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Shader encapsulates the functionality of a shader program written in 6 | // the OpenGL Shader Language (GLSL). Basic usage is to read a collection 7 | // of source files to disk and enable the shader before making draw calls. 8 | // For instance, during initialization one might write 9 | // 10 | // Shader shader; 11 | // shader.loadVertex( "vertex.glsl" ); 12 | // shader.loadFragment( "fragment.glsl" ); 13 | // 14 | // and in the main draw routine write 15 | // 16 | // shader.enable(); 17 | // // draw some stuff 18 | // shader.disable(); 19 | // 20 | 21 | #ifndef DDG_SHADER_H 22 | #define DDG_SHADER_H 23 | 24 | #include 25 | #include 26 | 27 | namespace DDG 28 | { 29 | class Shader 30 | { 31 | public: 32 | Shader( void ); 33 | // constructor -- shader is initially invalid 34 | 35 | ~Shader( void ); 36 | // destructor 37 | 38 | void loadVertex( const char* filename ); 39 | // read vertex shader from GLSL source file 40 | 41 | void loadFragment( const char* filename ); 42 | // read fragment shader from GLSL source file 43 | 44 | void loadGeometry( const char* filename ); 45 | // read geometry shader from GLSL source file 46 | 47 | void enable( void ); 48 | // uses this shader for rendering 49 | 50 | void disable( void ) const; 51 | // uses the fixed-function pipeline for rendering 52 | 53 | operator GLuint( void ) const; 54 | // returns the ID of this shader program (for calls to OpenGL) 55 | 56 | protected: 57 | void load( GLenum shaderType, const char* filename, GLuint& shader ); 58 | bool readSource( const char* filename, std::string& source ); 59 | 60 | GLuint vertexShader; 61 | GLuint fragmentShader; 62 | GLuint geometryShader; 63 | GLuint program; 64 | bool linked; 65 | }; 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /BaseCode/include/Utility.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_UTILITY_H 2 | #define DDG_UTILITY_H 3 | 4 | #include 5 | #include "Utility.h" 6 | #include "Complex.h" 7 | 8 | namespace DDG 9 | { 10 | inline double sqr( double x ) 11 | { 12 | return x*x; 13 | } 14 | 15 | inline double unitRand( void ) 16 | { 17 | const double rRandMax = 1. / (double) RAND_MAX; 18 | 19 | return rRandMax * (double) rand(); 20 | } 21 | 22 | inline double seconds( int t0, int t1 ) 23 | { 24 | return (double)(t1-t0) / (double) CLOCKS_PER_SEC; 25 | } 26 | } 27 | 28 | namespace DDGConstants 29 | { 30 | static DDG::Complex ii( 0., 1. ); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /BaseCode/include/Vertex.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Vertex.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Vertex stores attributes associated with a mesh edge. The iterator he 6 | // points to its "outgoing" halfedge. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_VERTEX_H 11 | #define DDG_VERTEX_H 12 | 13 | #include "Vector.h" 14 | #include "Types.h" 15 | 16 | namespace DDG 17 | { 18 | class Vertex 19 | { 20 | public: 21 | HalfEdgeIter he; 22 | // points to the "outgoing" halfedge 23 | 24 | Vector position; 25 | // location of vertex in Euclidean 3-space 26 | 27 | int index; 28 | // unique integer ID in the range 0, ..., nVertices-1 29 | 30 | bool tag; 31 | // true if vertex is selected by the user; false otherwise 32 | 33 | Vertex() : index(0), tag(false) { } 34 | 35 | double area( void ) const; 36 | // returns the barycentric area associated with this vertex 37 | 38 | Vector normal( void ) const; 39 | // returns the vertex normal 40 | 41 | bool isIsolated( void ) const; 42 | // returns true if the vertex is not contained in any face or edge; false otherwise 43 | 44 | int valence( void ) const; 45 | // returns the number of incident faces / edges 46 | 47 | void toggleTag(); 48 | // toggle vertex tag 49 | }; 50 | } 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /BaseCode/obj/.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/BaseCode/obj/.empty -------------------------------------------------------------------------------- /BaseCode/shaders/fragment.glsl: -------------------------------------------------------------------------------- 1 | uniform vec3 eye; 2 | uniform vec3 light; 3 | varying vec3 position; 4 | varying vec3 normal; 5 | 6 | float diffuse( vec3 N, vec3 L ) 7 | { 8 | return max( 0., dot( N, L )); 9 | } 10 | 11 | float specular( vec3 N, vec3 L, vec3 E ) 12 | { 13 | const float shininess = 8.; 14 | vec3 R = 2.*dot(L,N)*N - L; 15 | return pow( max( 0., dot( R, E )), shininess ); 16 | } 17 | 18 | float fresnel( vec3 N, vec3 E ) 19 | { 20 | const float sharpness = 10.; 21 | float NE = max( 0., dot( N, E )); 22 | return pow( sqrt( 1. - NE*NE ), sharpness ); 23 | } 24 | 25 | void main() 26 | { 27 | vec3 N = normalize( normal ); 28 | vec3 L = normalize( light - position ); 29 | vec3 E = normalize( eye - position ); 30 | vec3 R = 2.*dot(L,N)*N - L; 31 | vec3 one = vec3( 1., 1., 1. ); 32 | 33 | gl_FragColor.rgb = diffuse(N,L)*gl_Color.rgb + .5*specular(N,L,E)*one + .5*fresnel(N,E)*one; 34 | gl_FragColor.a = 1.; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /BaseCode/shaders/vertex.glsl: -------------------------------------------------------------------------------- 1 | varying vec3 position; 2 | varying vec3 normal; 3 | 4 | void main() 5 | { 6 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 7 | gl_FrontColor = gl_Color; 8 | 9 | position = gl_Vertex.xyz; 10 | normal = gl_Normal.xyz; 11 | } 12 | -------------------------------------------------------------------------------- /BaseCode/src/Edge.cpp: -------------------------------------------------------------------------------- 1 | #include "Edge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | 7 | } 8 | 9 | -------------------------------------------------------------------------------- /BaseCode/src/Face.cpp: -------------------------------------------------------------------------------- 1 | #include "Face.h" 2 | #include "Mesh.h" 3 | #include "Vector.h" 4 | 5 | namespace DDG 6 | { 7 | double Face::area( void ) const 8 | { 9 | Vector p0 = he->vertex->position; 10 | Vector p1 = he->next->vertex->position; 11 | Vector p2 = he->next->next->vertex->position; 12 | return cross( p1-p0, p2-p0 ).norm() / 2.; 13 | } 14 | 15 | Vector Face::normal( void ) const 16 | { 17 | Vector p0 = he->vertex->position; 18 | Vector p1 = he->next->vertex->position; 19 | Vector p2 = he->next->next->vertex->position; 20 | 21 | return cross( p1-p0, p2-p0 ).unit(); 22 | } 23 | 24 | bool Face::isBoundary( void ) const 25 | { 26 | return he->onBoundary; 27 | } 28 | 29 | Vector Face :: circumcenter( void ) const 30 | { 31 | Vector p0 = he->vertex->position; 32 | Vector p1 = he->next->vertex->position; 33 | Vector n = he->rotatedEdge(); 34 | double h = 0.5*he->cotan(); 35 | return 0.5*(p0+p1) + h*n; 36 | } 37 | 38 | Vector Face :: barycenter( void ) const 39 | { 40 | Vector p0 = he->vertex->position; 41 | Vector p1 = he->next->vertex->position; 42 | Vector p2 = he->next->next->vertex->position; 43 | return (p0 + p1 + p2)/3.; 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /BaseCode/src/HalfEdge.cpp: -------------------------------------------------------------------------------- 1 | #include "HalfEdge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | double HalfEdge :: cotan( void ) const 7 | { 8 | if( onBoundary ) return 0.0; 9 | 10 | Vector p0 = next->next->vertex->position; 11 | Vector p1 = vertex->position; 12 | Vector p2 = next->vertex->position; 13 | 14 | Vector u = p1-p0; 15 | Vector v = p2-p0; 16 | 17 | return dot( u, v ) / cross( u, v ).norm(); 18 | } 19 | 20 | Vector HalfEdge :: rotatedEdge( void ) const 21 | { 22 | if( onBoundary ) return Vector(); 23 | 24 | Vector n = face->normal(); 25 | Vector p0 = vertex->position; 26 | Vector p1 = flip->vertex->position; 27 | return cross( n, p1-p0 ); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /BaseCode/src/LinearContext.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearContext.h" 2 | 3 | namespace DDG 4 | { 5 | // global context for linear solvers 6 | LinearContext context; 7 | 8 | LinearContext :: LinearContext( void ) 9 | // constructor 10 | { 11 | cholmod_l_start( &context ); 12 | } 13 | 14 | LinearContext :: ~LinearContext( void ) 15 | // destructor 16 | { 17 | cholmod_l_finish( &context ); 18 | } 19 | 20 | LinearContext :: operator cholmod_common*( void ) 21 | // allows LinearContext to be treated as a cholmod_common* 22 | { 23 | return &context; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BaseCode/src/LinearEquation.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearEquation.h" 2 | 3 | namespace DDG 4 | { 5 | LinearEquation operator==( const LinearPolynomial& lhs, 6 | const LinearPolynomial& rhs ) 7 | // constructs a linear equation with the specified left- and right-hand side 8 | { 9 | LinearEquation eqn; 10 | 11 | eqn.lhs = lhs; 12 | eqn.rhs = rhs; 13 | 14 | return eqn; 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /BaseCode/src/Real.cpp: -------------------------------------------------------------------------------- 1 | #include "Real.h" 2 | #include 3 | 4 | namespace DDG 5 | { 6 | Real :: Real( double x ) 7 | // constructs real number with value x 8 | : value( x ) 9 | {} 10 | 11 | Real :: operator double( void ) const 12 | // type cast to double 13 | { 14 | return value; 15 | } 16 | 17 | void Real :: operator+=( double x ) 18 | // increment 19 | { 20 | value += x; 21 | } 22 | 23 | void Real :: operator-=( double x ) 24 | // decrement 25 | { 26 | value -= x; 27 | } 28 | 29 | void Real :: operator*=( double x ) 30 | // multiply 31 | { 32 | value *= x; 33 | } 34 | 35 | void Real :: operator/=( double x ) 36 | // divide 37 | { 38 | value /= x; 39 | } 40 | 41 | Real Real :: conj( void ) const 42 | // simply returns the value (for compatibility w/ complex numbers) 43 | { 44 | return value; 45 | } 46 | 47 | Real Real :: inv( void ) const 48 | // returns inverse 49 | { 50 | return 1. / value; 51 | } 52 | 53 | double Real :: norm( void ) const 54 | // returns norm 55 | { 56 | return fabs( value ); 57 | } 58 | 59 | double Real :: norm2( void ) const 60 | // returns norm squared 61 | { 62 | return value * value; 63 | } 64 | 65 | Real Real :: unit( void ) const 66 | // returns number with unit norm and same sign 67 | { 68 | return value / norm(); 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /BaseCode/src/Variable.cpp: -------------------------------------------------------------------------------- 1 | #include "Variable.h" 2 | 3 | namespace DDG 4 | { 5 | Variable :: Variable( double value_, 6 | bool fixed_ ) 7 | // initialize a variable which has value zero and is not fixed by default 8 | : value( value_ ), 9 | fixed( fixed_ ) 10 | {} 11 | 12 | Variable :: Variable( std::string name_, 13 | double value_, 14 | bool fixed_ ) 15 | // initialize a named variable which has value zero and is not fixed by default 16 | : name( name_ ), 17 | value( value_ ), 18 | fixed( fixed_ ) 19 | {} 20 | 21 | double& Variable :: operator*( void ) 22 | // returns a reference to the numerical value 23 | { 24 | return value; 25 | } 26 | 27 | const double& Variable :: operator*( void ) const 28 | // returns a const reference to the numerical value 29 | { 30 | return value; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /BaseCode/src/Vertex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Vertex.h" 5 | #include "Mesh.h" 6 | #include "HalfEdge.h" 7 | 8 | namespace DDG 9 | { 10 | double Vertex::area( void ) const 11 | // returns the dual area associated with this vertex 12 | { 13 | double A = 0.; 14 | 15 | HalfEdgeCIter h = he; 16 | do 17 | { 18 | if (not h->onBoundary) A += h->face->area(); 19 | h = h->flip->next; 20 | } 21 | while( h != he ); 22 | 23 | return A / 3.; 24 | } 25 | 26 | Vector Vertex::normal( void ) const 27 | // returns the vertex normal 28 | { 29 | Vector N; 30 | 31 | HalfEdgeCIter h = he; 32 | do 33 | { 34 | if (not h->onBoundary) N += h->face->normal(); 35 | h = h->flip->next; 36 | } 37 | while( h != he ); 38 | 39 | return N.unit(); 40 | } 41 | 42 | vector isolated; // all isolated vertices point to isolated.begin() 43 | 44 | bool Vertex::isIsolated( void ) const 45 | // returns true if the vertex is not contained in any face or edge; false otherwise 46 | { 47 | return he == isolated.begin(); 48 | } 49 | 50 | int Vertex :: valence( void ) const 51 | // returns the number of incident faces 52 | { 53 | int n = 0; 54 | 55 | HalfEdgeCIter h = he; 56 | do 57 | { 58 | n++; 59 | h = h->flip->next; 60 | } 61 | while( h != he ); 62 | 63 | return n; 64 | } 65 | 66 | void Vertex :: toggleTag() 67 | { 68 | tag = !tag; 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /BaseCode/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Viewer.h" 5 | #include "DenseMatrix.h" 6 | using namespace DDG; 7 | 8 | int main( int argc, char** argv ) 9 | { 10 | if( argc != 2 ) 11 | { 12 | cerr << "usage: " << argv[0] << " in.obj" << endl; 13 | return 1; 14 | } 15 | 16 | Viewer viewer; 17 | viewer.mesh.read( argv[1] ); 18 | viewer.init(); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Connection/Makefile: -------------------------------------------------------------------------------- 1 | ########################################################################################## 2 | 3 | # Specify library locations here (add or remove "#" marks to comment/uncomment lines for your platform) 4 | 5 | # Mac OS X 6 | DDG_INCLUDE_PATH = 7 | DDG_LIBRARY_PATH = 8 | DDG_BLAS_LIBS = -framework Accelerate 9 | DDG_SUITESPARSE_LIBS = -lspqr -lumfpack -lcholmod -lmetis -lcolamd -lccolamd -lcamd -lamd -ltbb -lm -lsuitesparseconfig 10 | DDG_OPENGL_LIBS = -framework OpenGL -framework GLUT 11 | 12 | # # Linux 13 | # DDG_INCLUDE_PATH = 14 | # DDG_LIBRARY_PATH = 15 | # DDG_BLAS_LIBS = -llapack -lblas -lgfortran 16 | # DDG_SUITESPARSE_LIBS = -lspqr -lcholmod -lmetis -lcolamd -lccolamd -lcamd -lamd -lm 17 | # DDG_OPENGL_LIBS = -lglut -lGL -lGLU -lX11 18 | 19 | # # Windows / Cygwin 20 | # DDG_INCLUDE_PATH = -I/usr/include/opengl -I/usr/include/suitesparse 21 | # DDG_LIBRARY_PATH = -L/usr/lib/w32api -L/usr/lib/suitesparse 22 | # DDG_BLAS_LIBS = -llapack -lblas 23 | # DDG_SUITESPARSE_LIBS = -lspqr -lcholmod -lcolamd -lccolamd -lcamd -lamd -lm 24 | # DDG_OPENGL_LIBS = -lglut32 -lglu32 -lopengl32 25 | 26 | ######################################################################################## 27 | 28 | TARGET = connection 29 | CC = g++ 30 | LD = g++ 31 | CFLAGS = -O3 -Wall -Werror -ansi -pedantic $(DDG_INCLUDE_PATH) -I./include -I./src 32 | LFLAGS = -O3 -Wall -Werror -ansi -pedantic $(DDG_LIBRARY_PATH) 33 | LIBS = $(DDG_OPENGL_LIBS) $(DDG_SUITESPARSE_LIBS) $(DDG_BLAS_LIBS) 34 | 35 | ######################################################################################## 36 | ## !! Do not edit below this line 37 | 38 | HEADERS := $(wildcard include/*.h) 39 | SOURCES := $(wildcard src/*.cpp) 40 | OBJECTS := $(addprefix obj/,$(notdir $(SOURCES:.cpp=.o))) 41 | 42 | all: $(TARGET) 43 | 44 | $(TARGET): $(OBJECTS) 45 | $(LD) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LFLAGS) $(LIBS) 46 | 47 | obj/%.o: src/%.cpp ${HEADERS} 48 | $(CC) -c $< -o $@ $(CFLAGS) 49 | 50 | clean: 51 | rm -f $(OBJECTS) 52 | rm -f $(TARGET) 53 | rm -f $(TARGET).exe 54 | -------------------------------------------------------------------------------- /Connection/include/DiscreteExteriorCalculus.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- DiscreteExteriorCalculus.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Static methods for building the fundamental discrete operators (exterior 6 | // derivative, Hodge star) for 0-, 1-, and 2-forms on a surface mesh. Methods 7 | // are templated on entry type, i.e., one can build either real- or complex- 8 | // matrices using the types DDG::Real and DDG::Complex, respectively. For 9 | // instance, to build the usual Laplacian on functions, one could write 10 | // 11 | // Mesh mesh; 12 | // SparseMatrix d0, star0, star1, Delta; 13 | // 14 | // ExteriorDerivative0Form::build( mesh, d0 ); 15 | // HodgeStar0Form::build( mesh, star0 ); 16 | // HodgeStar1Form::build( mesh, star1 ); 17 | // Delta = star0.inverse() * d0.transpose() * star1 * d0; 18 | // 19 | 20 | #ifndef DDG_DISCRETEEXTERIORCALCULUS_H 21 | #define DDG_DISCRETEEXTERIORCALCULUS_H 22 | 23 | #include "Mesh.h" 24 | #include "SparseMatrix.h" 25 | 26 | namespace DDG 27 | { 28 | template< class T > struct HodgeStar0Form { static void build( const Mesh& mesh, SparseMatrix& star0 ); }; 29 | template< class T > struct HodgeStar1Form { static void build( const Mesh& mesh, SparseMatrix& star1 ); }; 30 | template< class T > struct HodgeStar2Form { static void build( const Mesh& mesh, SparseMatrix& star2 ); }; 31 | template< class T > struct ExteriorDerivative0Form { static void build( const Mesh& mesh, SparseMatrix& d0 ); }; 32 | template< class T > struct ExteriorDerivative1Form { static void build( const Mesh& mesh, SparseMatrix& d1 ); }; 33 | } 34 | 35 | #include "DiscreteExteriorCalculus.inl" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Connection/include/Edge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Edge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Edge stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its two associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_EDGE_H 11 | #define DDG_EDGE_H 12 | 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class Edge 18 | { 19 | public: 20 | HalfEdgeIter he; 21 | // points to one of the two halfedges associated with this edge 22 | 23 | int index; 24 | // unique integer ID in the range 0, ..., nEdges-1 25 | 26 | Edge() : index(0) { } 27 | }; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Connection/include/Face.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Face.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Face stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_FACE_H 11 | #define DDG_FACE_H 12 | 13 | #include "Vector.h" 14 | #include "Types.h" 15 | 16 | namespace DDG 17 | { 18 | class Face 19 | { 20 | public: 21 | HalfEdgeIter he; 22 | // points to one of the halfedges associated with this face 23 | 24 | int index; 25 | // unique integer ID in the range 0, ..., nFaces-1 26 | 27 | Vector vector; 28 | // unit vector tangent to triangle 29 | 30 | bool tag; 31 | // auxiliary tag 32 | 33 | FaceIter parent; 34 | // parent in tree-cotree decomposition 35 | 36 | Face() : index(0), vector(), tag(false) { } 37 | 38 | bool isBoundary( void ) const; 39 | // returns true if this face corresponds to a 40 | // boundary loop; false otherwise 41 | 42 | double area( void ) const; 43 | // returns the triangle area 44 | 45 | Vector normal( void ) const; 46 | // returns the unit normal associated with this face; normal 47 | // orientation is determined by the circulation order of halfedges 48 | 49 | Vector circumcenter( void ) const; 50 | // returns triangle circumcenter 51 | 52 | Vector barycenter( void ) const; 53 | // returns triangle barycenter 54 | }; 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /Connection/include/HalfEdge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- HalfEdge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // HalfEdge is used to define mesh connectivity. (See the documentation for a 6 | // more in-depth discussion of the halfedge data structure.) 7 | // 8 | 9 | #ifndef DDG_HALFEDGE_H 10 | #define DDG_HALFEDGE_H 11 | 12 | #include "Vector.h" 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class HalfEdge 18 | { 19 | public: 20 | HalfEdgeIter next; 21 | // points to the next halfedge around the current face 22 | 23 | HalfEdgeIter flip; 24 | // points to the other halfedge associated with this edge 25 | 26 | VertexIter vertex; 27 | // points to the vertex at the "tail" of this halfedge 28 | 29 | EdgeIter edge; 30 | // points to the edge associated with this halfedge 31 | 32 | FaceIter face; 33 | // points to the face containing this halfedge 34 | 35 | bool onBoundary; 36 | // true if this halfedge is contained in a boundary 37 | // loop; false otherwise 38 | 39 | Vector texcoord; 40 | // texture coordinates associated with the triangle corner at the 41 | // "tail" of this halfedge 42 | 43 | std::vector harmonicBases; 44 | // value of harmonic bases at halfedge 45 | 46 | double cotan( void ) const; 47 | // returns the cotangent of the angle opposing this edge 48 | 49 | Vector rotatedEdge( void ) const; 50 | // returns oriented edge vector rotated by PI/2 around face normal 51 | // if onBoundary, then return nil 52 | 53 | double angle( void ) const; 54 | // returns corner angle at vertex opposite to the halfedge 55 | }; 56 | } 57 | 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /Connection/include/Image.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Image.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Image represents a color bitmap image. A simple example might look like 6 | // 7 | // Image im; 8 | // im.read( "input.tga" ); 9 | // // modify image data via im(x,y) = ...; 10 | // im.write( "output.tga" ); 11 | // 12 | 13 | #ifndef DDG_IMAGE_H 14 | #define DDG_IMAGE_H 15 | 16 | #include 17 | #include 18 | 19 | namespace DDG 20 | { 21 | class Image 22 | { 23 | public: 24 | Image( int width = 0, int height = 0 ); 25 | // constructs image with specified width and height 26 | 27 | float& operator()( int x, int y ); 28 | const float& operator()( int x, int y ) const; 29 | // accesses pixel (x,y) 30 | 31 | float sample( float x, float y ) const; 32 | // samples image at (x,y) using bilinear filtering 33 | 34 | int width( void ) const; 35 | int height( void ) const; 36 | // returns image dimensions 37 | 38 | void read( const char* filename ); 39 | // loads an image file in Truevision TGA format 40 | // (must be RGB image with 24 or 32 bits per pixel) 41 | 42 | void write( const char* filename ) const; 43 | // writes an image file in Truevision TGA format 44 | // (RGB image with 24 bits per pixel) 45 | 46 | protected: 47 | void clamp( int& x, int& y ) const; 48 | // clamps coordinates to range [0,w-1] x [0,h-1] 49 | 50 | int w, h; 51 | // width and height 52 | 53 | std::vector pixels; 54 | // interleaved RGBA pixel data in range [0-1] 55 | }; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /Connection/include/LinearContext.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearContext.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearContext is the global solver context needed to interface with the 6 | // SuiteSparse library. It is essentially a wrapper around cholmod_common. A 7 | // single static instance of LinearContext is declared in LinearContext.cpp and 8 | // is shared by all instances of DenseMatrix, SparseMatrix, and LinearSystem. 9 | // In other words, you shouldn't have to instantiate LinearContext yourself 10 | // unless you're doing something really fancy! 11 | // 12 | 13 | #ifndef DDG_LINEARSOLVERCONTEXT 14 | #define DDG_LINEARSOLVERCONTEXT 15 | 16 | #include 17 | 18 | namespace DDG 19 | { 20 | class LinearContext 21 | { 22 | public: 23 | LinearContext( void ); 24 | // constructor 25 | 26 | ~LinearContext( void ); 27 | // destructor 28 | 29 | operator cholmod_common*( void ); 30 | // allows LinearContext to be treated as a cholmod_common* 31 | 32 | protected: 33 | cholmod_common context; 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Connection/include/LinearEquation.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearEquation.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearEquation represents an equation with an arbitrary linear polynomial on 6 | // both the left- and right-hand side. It is primarily used while building a 7 | // LinearSystem. For convenience, operator== is overloaded so that the user 8 | // can construct a LinearEquation by writing something that looks much like the 9 | // usual mathematical syntax for a linear equation. For example, 10 | // 11 | // LinearEquation eqn = ( x + 2*y == 3*z ); 12 | // 13 | // builds the linear equation x + 2y = 3z. 14 | // 15 | 16 | #ifndef DDG_LINEAREQUATION_H 17 | #define DDG_LINEAREQUATION_H 18 | 19 | #include "LinearPolynomial.h" 20 | 21 | namespace DDG 22 | { 23 | class LinearEquation 24 | { 25 | public: 26 | LinearPolynomial lhs; 27 | // left-hand side 28 | 29 | LinearPolynomial rhs; 30 | // right-hand side 31 | }; 32 | 33 | LinearEquation operator==( const LinearPolynomial& lhs, const LinearPolynomial& rhs ); 34 | // constructs a linear equation with the specified left- and right-hand side 35 | } 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /Connection/include/MeshIO.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- MeshIO.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // MeshIO handles input/output operations for Mesh objects. Currently the only 6 | // supported mesh format is Wavefront OBJ -- for a format specification see 7 | // 8 | // http://en.wikipedia.org/wiki/Wavefront_.obj_file 9 | // 10 | // Note that vertex normals and material properties are currently ignored. 11 | // 12 | 13 | #ifndef DDG_MESHIO_H 14 | #define DDG_MESHIO_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace DDG 22 | { 23 | class Mesh; 24 | class Index; 25 | class MeshData; 26 | 27 | class MeshIO 28 | { 29 | public: 30 | static int read( std::istream& in, Mesh& mesh ); 31 | // reads a mesh from a valid, open input stream in 32 | 33 | static void write( std::ostream& out, const Mesh& mesh ); 34 | // writes a mesh to a valid, open output stream out 35 | 36 | protected: 37 | static int readMeshData( std::istream& in, MeshData& data ); 38 | static void readPosition( std::stringstream& ss, MeshData& data ); 39 | static void readTexCoord( std::stringstream& ss, MeshData& data ); 40 | static void readNormal ( std::stringstream& ss, MeshData& data ); 41 | static void readFace ( std::stringstream& ss, MeshData& data ); 42 | static Index parseFaceIndex( const std::string& token ); 43 | static void preallocateMeshElements( const MeshData& data, Mesh& mesh ); 44 | static int buildMesh( const MeshData& data, Mesh& mesh ); 45 | static void checkIsolatedVertices( const Mesh& Mesh ); 46 | static void checkNonManifoldVertices( const Mesh& Mesh ); 47 | }; 48 | } 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /Connection/include/Real.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_REAL_H 2 | #define DDG_REAL_H 3 | 4 | namespace DDG 5 | { 6 | class Real 7 | { 8 | public: 9 | Real( double x = 0. ); 10 | // constructs real number with value x 11 | 12 | operator double( void ) const; 13 | // type cast to double 14 | 15 | void operator+=( double x ); 16 | // increment 17 | 18 | void operator-=( double x ); 19 | // decrement 20 | 21 | void operator*=( double x ); 22 | // multiply 23 | 24 | void operator/=( double x ); 25 | // divide 26 | 27 | Real conj( void ) const; 28 | // simply returns the value (for compatibility w/ complex numbers) 29 | 30 | Real inv( void ) const; 31 | // returns inverse 32 | 33 | double norm( void ) const; 34 | // returns norm 35 | 36 | double norm2( void ) const; 37 | // returns norm squared 38 | 39 | Real unit( void ) const; 40 | // returns number with unit norm and same sign 41 | 42 | protected: 43 | double value; 44 | // value 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Connection/include/Shader.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Shader.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Shader encapsulates the functionality of a shader program written in 6 | // the OpenGL Shader Language (GLSL). Basic usage is to read a collection 7 | // of source files to disk and enable the shader before making draw calls. 8 | // For instance, during initialization one might write 9 | // 10 | // Shader shader; 11 | // shader.loadVertex( "vertex.glsl" ); 12 | // shader.loadFragment( "fragment.glsl" ); 13 | // 14 | // and in the main draw routine write 15 | // 16 | // shader.enable(); 17 | // // draw some stuff 18 | // shader.disable(); 19 | // 20 | 21 | #ifndef DDG_SHADER_H 22 | #define DDG_SHADER_H 23 | 24 | #include 25 | #include 26 | 27 | namespace DDG 28 | { 29 | class Shader 30 | { 31 | public: 32 | Shader( void ); 33 | // constructor -- shader is initially invalid 34 | 35 | ~Shader( void ); 36 | // destructor 37 | 38 | void loadVertex( const char* filename ); 39 | // read vertex shader from GLSL source file 40 | 41 | void loadFragment( const char* filename ); 42 | // read fragment shader from GLSL source file 43 | 44 | void loadGeometry( const char* filename ); 45 | // read geometry shader from GLSL source file 46 | 47 | void enable( void ); 48 | // uses this shader for rendering 49 | 50 | void disable( void ) const; 51 | // uses the fixed-function pipeline for rendering 52 | 53 | operator GLuint( void ) const; 54 | // returns the ID of this shader program (for calls to OpenGL) 55 | 56 | protected: 57 | void load( GLenum shaderType, const char* filename, GLuint& shader ); 58 | bool readSource( const char* filename, std::string& source ); 59 | 60 | GLuint vertexShader; 61 | GLuint fragmentShader; 62 | GLuint geometryShader; 63 | GLuint program; 64 | bool linked; 65 | }; 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /Connection/include/Utility.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_UTILITY_H 2 | #define DDG_UTILITY_H 3 | 4 | #include 5 | #include "Utility.h" 6 | #include "Complex.h" 7 | 8 | namespace DDG 9 | { 10 | inline double sqr( double x ) 11 | { 12 | return x*x; 13 | } 14 | 15 | inline double unitRand( void ) 16 | { 17 | const double rRandMax = 1. / (double) RAND_MAX; 18 | 19 | return rRandMax * (double) rand(); 20 | } 21 | 22 | inline double seconds( int t0, int t1 ) 23 | { 24 | return (double)(t1-t0) / (double) CLOCKS_PER_SEC; 25 | } 26 | } 27 | 28 | namespace DDGConstants 29 | { 30 | static DDG::Complex ii( 0., 1. ); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Connection/include/Vertex.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Vertex.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Vertex stores attributes associated with a mesh edge. The iterator he 6 | // points to its "outgoing" halfedge. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_VERTEX_H 11 | #define DDG_VERTEX_H 12 | 13 | #include "Vector.h" 14 | #include "Types.h" 15 | 16 | namespace DDG 17 | { 18 | class Vertex 19 | { 20 | public: 21 | HalfEdgeIter he; 22 | // points to the "outgoing" halfedge 23 | 24 | Vector position; 25 | // location of vertex in Euclidean 3-space 26 | 27 | int index; 28 | // unique integer ID in the range 0, ..., nVertices-1 29 | 30 | bool tag; 31 | // true if vertex is selected by the user; false otherwise 32 | 33 | double potential; 34 | // zero-form that controls curvature 35 | 36 | double singularity; 37 | // singularity index 38 | 39 | VertexIter parent; 40 | // parent in tree-cotree decomposition 41 | 42 | Vertex() : index(0), tag(false), potential(0.0), singularity(0.0) 43 | { } 44 | 45 | double area( void ) const; 46 | // returns the barycentric area associated with this vertex 47 | 48 | Vector normal( void ) const; 49 | // returns the vertex normal 50 | 51 | bool isIsolated( void ) const; 52 | // returns true if the vertex is not contained in any face or edge; false otherwise 53 | 54 | int valence( void ) const; 55 | // returns the number of incident faces / edges 56 | 57 | void toggleTag(); 58 | // toggle vertex tag 59 | 60 | double theta( void ) const; 61 | // returns sum_tip_angles 62 | 63 | bool onBoundary( void ) const; 64 | // returns true if vertex is at boundary 65 | }; 66 | } 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /Connection/obj/.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/Connection/obj/.empty -------------------------------------------------------------------------------- /Connection/shaders/fragment.glsl: -------------------------------------------------------------------------------- 1 | uniform vec3 eye; 2 | uniform vec3 light; 3 | varying vec3 position; 4 | varying vec3 normal; 5 | 6 | float diffuse( vec3 N, vec3 L ) 7 | { 8 | return max( 0., dot( N, L )); 9 | } 10 | 11 | float specular( vec3 N, vec3 L, vec3 E ) 12 | { 13 | const float shininess = 8.; 14 | vec3 R = 2.*dot(L,N)*N - L; 15 | return pow( max( 0., dot( R, E )), shininess ); 16 | } 17 | 18 | float fresnel( vec3 N, vec3 E ) 19 | { 20 | const float sharpness = 10.; 21 | float NE = max( 0., dot( N, E )); 22 | return pow( sqrt( 1. - NE*NE ), sharpness ); 23 | } 24 | 25 | void main() 26 | { 27 | vec3 N = normalize( normal ); 28 | vec3 L = normalize( light - position ); 29 | vec3 E = normalize( eye - position ); 30 | vec3 R = 2.*dot(L,N)*N - L; 31 | vec3 one = vec3( 1., 1., 1. ); 32 | 33 | gl_FragColor.rgb = diffuse(N,L)*gl_Color.rgb + .5*specular(N,L,E)*one + .5*fresnel(N,E)*one; 34 | gl_FragColor.a = 1.; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Connection/shaders/vertex.glsl: -------------------------------------------------------------------------------- 1 | varying vec3 position; 2 | varying vec3 normal; 3 | 4 | void main() 5 | { 6 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 7 | gl_FrontColor = gl_Color; 8 | 9 | position = gl_Vertex.xyz; 10 | normal = gl_Normal.xyz; 11 | } 12 | -------------------------------------------------------------------------------- /Connection/src/Edge.cpp: -------------------------------------------------------------------------------- 1 | #include "Edge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Connection/src/Face.cpp: -------------------------------------------------------------------------------- 1 | #include "Face.h" 2 | #include "Mesh.h" 3 | #include "Vector.h" 4 | 5 | namespace DDG 6 | { 7 | double Face::area( void ) const 8 | { 9 | Vector p0 = he->vertex->position; 10 | Vector p1 = he->next->vertex->position; 11 | Vector p2 = he->next->next->vertex->position; 12 | return cross( p1-p0, p2-p0 ).norm() / 2.; 13 | } 14 | 15 | Vector Face::normal( void ) const 16 | { 17 | Vector p0 = he->vertex->position; 18 | Vector p1 = he->next->vertex->position; 19 | Vector p2 = he->next->next->vertex->position; 20 | 21 | return cross( p1-p0, p2-p0 ).unit(); 22 | } 23 | 24 | bool Face::isBoundary( void ) const 25 | { 26 | return he->onBoundary; 27 | } 28 | 29 | Vector Face :: circumcenter( void ) const 30 | { 31 | Vector p0 = he->vertex->position; 32 | Vector p1 = he->next->vertex->position; 33 | Vector n = he->rotatedEdge(); 34 | double h = 0.5*he->cotan(); 35 | return 0.5*(p0+p1) + h*n; 36 | } 37 | 38 | Vector Face :: barycenter( void ) const 39 | { 40 | Vector p0 = he->vertex->position; 41 | Vector p1 = he->next->vertex->position; 42 | Vector p2 = he->next->next->vertex->position; 43 | return (p0 + p1 + p2)/3.; 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Connection/src/HalfEdge.cpp: -------------------------------------------------------------------------------- 1 | #include "HalfEdge.h" 2 | #include "Mesh.h" 3 | #include "Vector.h" 4 | #include "Quaternion.h" 5 | 6 | namespace DDG 7 | { 8 | double HalfEdge :: cotan( void ) const 9 | { 10 | if( onBoundary ) return 0.0; 11 | 12 | Vector p0 = next->next->vertex->position; 13 | Vector p1 = vertex->position; 14 | Vector p2 = next->vertex->position; 15 | 16 | Vector u = p1-p0; 17 | Vector v = p2-p0; 18 | 19 | return dot( u, v ) / cross( u, v ).norm(); 20 | } 21 | 22 | Vector HalfEdge :: rotatedEdge( void ) const 23 | { 24 | if( onBoundary ) return Vector(); 25 | 26 | Vector n = face->normal(); 27 | Vector p0 = vertex->position; 28 | Vector p1 = flip->vertex->position; 29 | return cross( n, p1-p0 ); 30 | } 31 | 32 | double HalfEdge :: angle( void ) const 33 | { 34 | if( onBoundary ) return 0.0; 35 | 36 | Vector p0 = next->next->vertex->position; 37 | Vector p1 = vertex->position; 38 | Vector p2 = next->vertex->position; 39 | 40 | Vector u = p1-p0; 41 | Vector v = p2-p0; 42 | 43 | return atan2( cross( u, v ).norm(), dot( u, v ) ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Connection/src/LinearContext.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearContext.h" 2 | 3 | namespace DDG 4 | { 5 | // global context for linear solvers 6 | LinearContext context; 7 | 8 | LinearContext :: LinearContext( void ) 9 | // constructor 10 | { 11 | cholmod_l_start( &context ); 12 | } 13 | 14 | LinearContext :: ~LinearContext( void ) 15 | // destructor 16 | { 17 | cholmod_l_finish( &context ); 18 | } 19 | 20 | LinearContext :: operator cholmod_common*( void ) 21 | // allows LinearContext to be treated as a cholmod_common* 22 | { 23 | return &context; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Connection/src/LinearEquation.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearEquation.h" 2 | 3 | namespace DDG 4 | { 5 | LinearEquation operator==( const LinearPolynomial& lhs, 6 | const LinearPolynomial& rhs ) 7 | // constructs a linear equation with the specified left- and right-hand side 8 | { 9 | LinearEquation eqn; 10 | 11 | eqn.lhs = lhs; 12 | eqn.rhs = rhs; 13 | 14 | return eqn; 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Connection/src/Real.cpp: -------------------------------------------------------------------------------- 1 | #include "Real.h" 2 | #include 3 | 4 | namespace DDG 5 | { 6 | Real :: Real( double x ) 7 | // constructs real number with value x 8 | : value( x ) 9 | {} 10 | 11 | Real :: operator double( void ) const 12 | // type cast to double 13 | { 14 | return value; 15 | } 16 | 17 | void Real :: operator+=( double x ) 18 | // increment 19 | { 20 | value += x; 21 | } 22 | 23 | void Real :: operator-=( double x ) 24 | // decrement 25 | { 26 | value -= x; 27 | } 28 | 29 | void Real :: operator*=( double x ) 30 | // multiply 31 | { 32 | value *= x; 33 | } 34 | 35 | void Real :: operator/=( double x ) 36 | // divide 37 | { 38 | value /= x; 39 | } 40 | 41 | Real Real :: conj( void ) const 42 | // simply returns the value (for compatibility w/ complex numbers) 43 | { 44 | return value; 45 | } 46 | 47 | Real Real :: inv( void ) const 48 | // returns inverse 49 | { 50 | return 1. / value; 51 | } 52 | 53 | double Real :: norm( void ) const 54 | // returns norm 55 | { 56 | return fabs( value ); 57 | } 58 | 59 | double Real :: norm2( void ) const 60 | // returns norm squared 61 | { 62 | return value * value; 63 | } 64 | 65 | Real Real :: unit( void ) const 66 | // returns number with unit norm and same sign 67 | { 68 | return value / norm(); 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Connection/src/Variable.cpp: -------------------------------------------------------------------------------- 1 | #include "Variable.h" 2 | 3 | namespace DDG 4 | { 5 | Variable :: Variable( double value_, 6 | bool fixed_ ) 7 | // initialize a variable which has value zero and is not fixed by default 8 | : value( value_ ), 9 | fixed( fixed_ ) 10 | {} 11 | 12 | Variable :: Variable( std::string name_, 13 | double value_, 14 | bool fixed_ ) 15 | // initialize a named variable which has value zero and is not fixed by default 16 | : name( name_ ), 17 | value( value_ ), 18 | fixed( fixed_ ) 19 | {} 20 | 21 | double& Variable :: operator*( void ) 22 | // returns a reference to the numerical value 23 | { 24 | return value; 25 | } 26 | 27 | const double& Variable :: operator*( void ) const 28 | // returns a const reference to the numerical value 29 | { 30 | return value; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Connection/src/Vertex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Vertex.h" 5 | #include "Mesh.h" 6 | #include "HalfEdge.h" 7 | 8 | namespace DDG 9 | { 10 | double Vertex::area( void ) const 11 | // returns the dual area associated with this vertex 12 | { 13 | double A = 0.; 14 | 15 | HalfEdgeCIter h = he; 16 | do 17 | { 18 | if (not h->onBoundary) A += h->face->area(); 19 | h = h->flip->next; 20 | } 21 | while( h != he ); 22 | 23 | return A / 3.; 24 | } 25 | 26 | Vector Vertex::normal( void ) const 27 | // returns the vertex normal 28 | { 29 | Vector N; 30 | 31 | HalfEdgeCIter h = he; 32 | do 33 | { 34 | if (not h->onBoundary) N += h->face->normal(); 35 | h = h->flip->next; 36 | } 37 | while( h != he ); 38 | 39 | return N.unit(); 40 | } 41 | 42 | vector isolated; // all isolated vertices point to isolated.begin() 43 | 44 | bool Vertex::isIsolated( void ) const 45 | // returns true if the vertex is not contained in any face or edge; false otherwise 46 | { 47 | return he == isolated.begin(); 48 | } 49 | 50 | int Vertex :: valence( void ) const 51 | // returns the number of incident faces 52 | { 53 | int n = 0; 54 | 55 | HalfEdgeCIter h = he; 56 | do 57 | { 58 | n++; 59 | h = h->flip->next; 60 | } 61 | while( h != he ); 62 | 63 | return n; 64 | } 65 | 66 | void Vertex :: toggleTag() 67 | { 68 | tag = !tag; 69 | } 70 | 71 | double Vertex :: theta( void ) const 72 | { 73 | double sum = 0.0; 74 | HalfEdgeCIter h = this->he; 75 | do 76 | { 77 | sum += h->next->angle(); 78 | h = h->flip->next; 79 | } 80 | while( h != this->he ); 81 | return sum; 82 | } 83 | 84 | bool Vertex :: onBoundary( void ) const 85 | { 86 | HalfEdgeCIter h = this->he; 87 | do 88 | { 89 | if( h->onBoundary ) return true; 90 | h = h->flip->next; 91 | } 92 | while( h != this->he ); 93 | return false; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Connection/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Viewer.h" 5 | #include "Direction.h" 6 | using namespace DDG; 7 | 8 | int main( int argc, char** argv ) 9 | { 10 | if( argc != 2 ) 11 | { 12 | cerr << "usage: " << argv[0] << " in.obj" << endl; 13 | return 1; 14 | } 15 | 16 | Viewer viewer; 17 | viewer.mesh.read( argv[1] ); 18 | viewer.mesh.init(); 19 | 20 | DirectionField field; 21 | field.generate( viewer.mesh, viewer.angle ); 22 | 23 | viewer.init(); 24 | 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Elasticity/.viewer_state.txt: -------------------------------------------------------------------------------- 1 | 0.126663 2 | -0.0243652 3 | -0.989174 4 | 0.0699843 5 | 815 6 | 767 7 | -------------------------------------------------------------------------------- /Elasticity/Makefile: -------------------------------------------------------------------------------- 1 | ########################################################################################## 2 | 3 | # Specify library locations here (add or remove "#" marks to comment/uncomment lines for your platform) 4 | 5 | # Mac OS X 6 | DDG_INCLUDE_PATH = 7 | DDG_LIBRARY_PATH = 8 | DDG_BLAS_LIBS = -framework Accelerate 9 | DDG_SUITESPARSE_LIBS = -lspqr -lumfpack -lcholmod -lmetis -lcolamd -lccolamd -lcamd -lamd -ltbb -lm -lsuitesparseconfig 10 | DDG_OPENGL_LIBS = -framework OpenGL -framework GLUT 11 | 12 | # # Linux 13 | # DDG_INCLUDE_PATH = 14 | # DDG_LIBRARY_PATH = 15 | # DDG_BLAS_LIBS = -llapack -lblas -lgfortran 16 | # DDG_SUITESPARSE_LIBS = -lspqr -lcholmod -lmetis -lcolamd -lccolamd -lcamd -lamd -lm 17 | # DDG_OPENGL_LIBS = -lglut -lGL -lGLU -lX11 18 | 19 | # # Windows / Cygwin 20 | # DDG_INCLUDE_PATH = -I/usr/include/opengl -I/usr/include/suitesparse 21 | # DDG_LIBRARY_PATH = -L/usr/lib/w32api -L/usr/lib/suitesparse 22 | # DDG_BLAS_LIBS = -llapack -lblas 23 | # DDG_SUITESPARSE_LIBS = -lspqr -lcholmod -lcolamd -lccolamd -lcamd -lamd -lm 24 | # DDG_OPENGL_LIBS = -lglut32 -lglu32 -lopengl32 25 | 26 | ######################################################################################## 27 | 28 | TARGET = elasticity 29 | CC = g++ 30 | LD = g++ 31 | CFLAGS = -O3 -Wall -Werror -ansi -pedantic $(DDG_INCLUDE_PATH) -I./include -I./src 32 | LFLAGS = -O3 -Wall -Werror -ansi -pedantic $(DDG_LIBRARY_PATH) 33 | LIBS = $(DDG_OPENGL_LIBS) $(DDG_SUITESPARSE_LIBS) $(DDG_BLAS_LIBS) 34 | 35 | ######################################################################################## 36 | ## !! Do not edit below this line 37 | 38 | HEADERS := $(wildcard include/*.h) 39 | SOURCES := $(wildcard src/*.cpp) 40 | OBJECTS := $(addprefix obj/,$(notdir $(SOURCES:.cpp=.o))) 41 | 42 | all: $(TARGET) 43 | 44 | $(TARGET): $(OBJECTS) 45 | $(LD) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LFLAGS) $(LIBS) 46 | 47 | obj/%.o: src/%.cpp ${HEADERS} 48 | $(CC) -c $< -o $@ $(CFLAGS) 49 | 50 | clean: 51 | rm -f $(OBJECTS) 52 | rm -f $(TARGET) 53 | rm -f $(TARGET).exe 54 | -------------------------------------------------------------------------------- /Elasticity/include/.Elasticity.h.swo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/Elasticity/include/.Elasticity.h.swo -------------------------------------------------------------------------------- /Elasticity/include/.Elasticity.h.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/Elasticity/include/.Elasticity.h.swp -------------------------------------------------------------------------------- /Elasticity/include/.Viewer.h.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/Elasticity/include/.Viewer.h.swp -------------------------------------------------------------------------------- /Elasticity/include/DiscreteExteriorCalculus.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- DiscreteExteriorCalculus.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Static methods for building the fundamental discrete operators (exterior 6 | // derivative, Hodge star) for 0-, 1-, and 2-forms on a surface mesh. Methods 7 | // are templated on entry type, i.e., one can build either real- or complex- 8 | // matrices using the types DDG::Real and DDG::Complex, respectively. For 9 | // instance, to build the usual Laplacian on functions, one could write 10 | // 11 | // Mesh mesh; 12 | // SparseMatrix d0, star0, star1, Delta; 13 | // 14 | // ExteriorDerivative0Form::build( mesh, d0 ); 15 | // HodgeStar0Form::build( mesh, star0 ); 16 | // HodgeStar1Form::build( mesh, star1 ); 17 | // Delta = star0.inverse() * d0.transpose() * star1 * d0; 18 | // 19 | 20 | #ifndef DDG_DISCRETEEXTERIORCALCULUS_H 21 | #define DDG_DISCRETEEXTERIORCALCULUS_H 22 | 23 | #include "Mesh.h" 24 | #include "SparseMatrix.h" 25 | 26 | namespace DDG 27 | { 28 | template< class T > struct HodgeStar0Form { static void build( const Mesh& mesh, SparseMatrix& star0 ); }; 29 | template< class T > struct HodgeStar1Form { static void build( const Mesh& mesh, SparseMatrix& star1 ); }; 30 | template< class T > struct HodgeStar2Form { static void build( const Mesh& mesh, SparseMatrix& star2 ); }; 31 | template< class T > struct ExteriorDerivative0Form { static void build( const Mesh& mesh, SparseMatrix& d0 ); }; 32 | template< class T > struct ExteriorDerivative1Form { static void build( const Mesh& mesh, SparseMatrix& d1 ); }; 33 | } 34 | 35 | #include "DiscreteExteriorCalculus.inl" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Elasticity/include/Edge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Edge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Edge stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its two associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_EDGE_H 11 | #define DDG_EDGE_H 12 | 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class Edge 18 | { 19 | public: 20 | HalfEdgeIter he; 21 | // points to one of the two halfedges associated with this edge 22 | 23 | int index; 24 | // unique integer ID in the range 0, ..., nEdges-1 25 | 26 | Edge() : index(0) { } 27 | }; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Elasticity/include/Face.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Face.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Face stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_FACE_H 11 | #define DDG_FACE_H 12 | 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class Face 18 | { 19 | public: 20 | HalfEdgeIter he; 21 | // points to one of the halfedges associated with this face 22 | 23 | int index; 24 | // unique integer ID in the range 0, ..., nFaces-1 25 | 26 | Face() : index(0) { } 27 | 28 | bool isBoundary( void ) const; 29 | // returns true if this face corresponds to a 30 | // boundary loop; false otherwise 31 | 32 | double area( void ) const; 33 | // returns the triangle area 34 | 35 | Vector normal( void ) const; 36 | // returns the unit normal associated with this face; normal 37 | // orientation is determined by the circulation order of halfedges 38 | 39 | Vector circumcenter( void ) const; 40 | // returns triangle circumcenter 41 | 42 | Vector barycenter( void ) const; 43 | // returns triangle barycenter 44 | }; 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Elasticity/include/HalfEdge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- HalfEdge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // HalfEdge is used to define mesh connectivity. (See the documentation for a 6 | // more in-depth discussion of the halfedge data structure.) 7 | // 8 | 9 | #ifndef DDG_HALFEDGE_H 10 | #define DDG_HALFEDGE_H 11 | 12 | #include "Vector.h" 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class HalfEdge 18 | { 19 | public: 20 | HalfEdgeIter next; 21 | // points to the next halfedge around the current face 22 | 23 | HalfEdgeIter flip; 24 | // points to the other halfedge associated with this edge 25 | 26 | VertexIter vertex; 27 | // points to the vertex at the "tail" of this halfedge 28 | 29 | EdgeIter edge; 30 | // points to the edge associated with this halfedge 31 | 32 | FaceIter face; 33 | // points to the face containing this halfedge 34 | 35 | bool onBoundary; 36 | // true if this halfedge is contained in a boundary 37 | // loop; false otherwise 38 | 39 | Vector texcoord; 40 | // texture coordinates associated with the triangle corner at the 41 | // "tail" of this halfedge 42 | 43 | double cotan( void ) const; 44 | // returns the cotangent of the angle opposing this edge 45 | 46 | Vector rotatedEdge( void ) const; 47 | // returns oriented edge vector rotated by PI/2 around face normal 48 | // if onBoundary, then return nil 49 | }; 50 | } 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /Elasticity/include/Image.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Image.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Image represents a color bitmap image. A simple example might look like 6 | // 7 | // Image im; 8 | // im.read( "input.tga" ); 9 | // // modify image data via im(x,y) = ...; 10 | // im.write( "output.tga" ); 11 | // 12 | 13 | #ifndef DDG_IMAGE_H 14 | #define DDG_IMAGE_H 15 | 16 | #include 17 | #include 18 | 19 | namespace DDG 20 | { 21 | class Image 22 | { 23 | public: 24 | Image( int width = 0, int height = 0 ); 25 | // constructs image with specified width and height 26 | 27 | float& operator()( int x, int y ); 28 | const float& operator()( int x, int y ) const; 29 | // accesses pixel (x,y) 30 | 31 | float sample( float x, float y ) const; 32 | // samples image at (x,y) using bilinear filtering 33 | 34 | int width( void ) const; 35 | int height( void ) const; 36 | // returns image dimensions 37 | 38 | void read( const char* filename ); 39 | // loads an image file in Truevision TGA format 40 | // (must be RGB image with 24 or 32 bits per pixel) 41 | 42 | void write( const char* filename ) const; 43 | // writes an image file in Truevision TGA format 44 | // (RGB image with 24 bits per pixel) 45 | 46 | protected: 47 | void clamp( int& x, int& y ) const; 48 | // clamps coordinates to range [0,w-1] x [0,h-1] 49 | 50 | int w, h; 51 | // width and height 52 | 53 | std::vector pixels; 54 | // interleaved RGBA pixel data in range [0-1] 55 | }; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /Elasticity/include/LinearContext.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearContext.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearContext is the global solver context needed to interface with the 6 | // SuiteSparse library. It is essentially a wrapper around cholmod_common. A 7 | // single static instance of LinearContext is declared in LinearContext.cpp and 8 | // is shared by all instances of DenseMatrix, SparseMatrix, and LinearSystem. 9 | // In other words, you shouldn't have to instantiate LinearContext yourself 10 | // unless you're doing something really fancy! 11 | // 12 | 13 | #ifndef DDG_LINEARSOLVERCONTEXT 14 | #define DDG_LINEARSOLVERCONTEXT 15 | 16 | #include 17 | 18 | namespace DDG 19 | { 20 | class LinearContext 21 | { 22 | public: 23 | LinearContext( void ); 24 | // constructor 25 | 26 | ~LinearContext( void ); 27 | // destructor 28 | 29 | operator cholmod_common*( void ); 30 | // allows LinearContext to be treated as a cholmod_common* 31 | 32 | protected: 33 | cholmod_common context; 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Elasticity/include/LinearEquation.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearEquation.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearEquation represents an equation with an arbitrary linear polynomial on 6 | // both the left- and right-hand side. It is primarily used while building a 7 | // LinearSystem. For convenience, operator== is overloaded so that the user 8 | // can construct a LinearEquation by writing something that looks much like the 9 | // usual mathematical syntax for a linear equation. For example, 10 | // 11 | // LinearEquation eqn = ( x + 2*y == 3*z ); 12 | // 13 | // builds the linear equation x + 2y = 3z. 14 | // 15 | 16 | #ifndef DDG_LINEAREQUATION_H 17 | #define DDG_LINEAREQUATION_H 18 | 19 | #include "LinearPolynomial.h" 20 | 21 | namespace DDG 22 | { 23 | class LinearEquation 24 | { 25 | public: 26 | LinearPolynomial lhs; 27 | // left-hand side 28 | 29 | LinearPolynomial rhs; 30 | // right-hand side 31 | }; 32 | 33 | LinearEquation operator==( const LinearPolynomial& lhs, const LinearPolynomial& rhs ); 34 | // constructs a linear equation with the specified left- and right-hand side 35 | } 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /Elasticity/include/MeshIO.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- MeshIO.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // MeshIO handles input/output operations for Mesh objects. Currently the only 6 | // supported mesh format is Wavefront OBJ -- for a format specification see 7 | // 8 | // http://en.wikipedia.org/wiki/Wavefront_.obj_file 9 | // 10 | // Note that vertex normals and material properties are currently ignored. 11 | // 12 | 13 | #ifndef DDG_MESHIO_H 14 | #define DDG_MESHIO_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace DDG 22 | { 23 | class Mesh; 24 | class Index; 25 | class MeshData; 26 | 27 | class MeshIO 28 | { 29 | public: 30 | static int read( std::istream& in, Mesh& mesh ); 31 | // reads a mesh from a valid, open input stream in 32 | 33 | static void write( std::ostream& out, const Mesh& mesh ); 34 | // writes a mesh to a valid, open output stream out 35 | 36 | protected: 37 | static int readMeshData( std::istream& in, MeshData& data ); 38 | static void readPosition( std::stringstream& ss, MeshData& data ); 39 | static void readTexCoord( std::stringstream& ss, MeshData& data ); 40 | static void readNormal ( std::stringstream& ss, MeshData& data ); 41 | static void readFace ( std::stringstream& ss, MeshData& data ); 42 | static Index parseFaceIndex( const std::string& token ); 43 | static void preallocateMeshElements( const MeshData& data, Mesh& mesh ); 44 | static int buildMesh( const MeshData& data, Mesh& mesh ); 45 | static void checkIsolatedVertices( const Mesh& Mesh ); 46 | static void checkNonManifoldVertices( const Mesh& Mesh ); 47 | }; 48 | } 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /Elasticity/include/PolarDecomposition2x2.h: -------------------------------------------------------------------------------- 1 | #ifndef POLAR_DECOMPOSITION_2x2_H 2 | #define POLAR_DECOMPOSITION_2x2_H 3 | 4 | #include "Complex.h" 5 | #include "DenseMatrix.h" 6 | 7 | namespace DDG 8 | { 9 | class PolarDecomposition2x2 10 | { 11 | public: 12 | static Complex extractOrthogonalPart(DenseMatrix A) 13 | { 14 | double res = 1.0; 15 | while( res > 1.0e-6 ) 16 | { 17 | DenseMatrix B = Real(0.5)*( A + invert(A.transpose()) ); 18 | res = (A - B).norm( lTwo ); 19 | A = B; 20 | } 21 | return Complex( A(0,0), A(1,0) ).unit(); 22 | } 23 | 24 | static DenseMatrix invert(const DenseMatrix& A) 25 | { 26 | double detA = A(0,0)*A(1,1) - A(0,1)*A(1,0); 27 | DenseMatrix B(2,2); 28 | B(0,0) = A(1,1)/detA; B(0,1) = -A(0,1)/detA; 29 | B(1,0) = -A(1,0)/detA; B(1,1) = A(0,0)/detA; 30 | return B; 31 | } 32 | }; 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Elasticity/include/Real.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_REAL_H 2 | #define DDG_REAL_H 3 | 4 | namespace DDG 5 | { 6 | class Real 7 | { 8 | public: 9 | Real( double x = 0. ); 10 | // constructs real number with value x 11 | 12 | operator double( void ) const; 13 | // type cast to double 14 | 15 | void operator+=( double x ); 16 | // increment 17 | 18 | void operator-=( double x ); 19 | // decrement 20 | 21 | void operator*=( double x ); 22 | // multiply 23 | 24 | void operator/=( double x ); 25 | // divide 26 | 27 | Real conj( void ) const; 28 | // simply returns the value (for compatibility w/ complex numbers) 29 | 30 | Real inv( void ) const; 31 | // returns inverse 32 | 33 | double norm( void ) const; 34 | // returns norm 35 | 36 | double norm2( void ) const; 37 | // returns norm squared 38 | 39 | Real unit( void ) const; 40 | // returns number with unit norm and same sign 41 | 42 | protected: 43 | double value; 44 | // value 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Elasticity/include/Shader.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Shader.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Shader encapsulates the functionality of a shader program written in 6 | // the OpenGL Shader Language (GLSL). Basic usage is to read a collection 7 | // of source files to disk and enable the shader before making draw calls. 8 | // For instance, during initialization one might write 9 | // 10 | // Shader shader; 11 | // shader.loadVertex( "vertex.glsl" ); 12 | // shader.loadFragment( "fragment.glsl" ); 13 | // 14 | // and in the main draw routine write 15 | // 16 | // shader.enable(); 17 | // // draw some stuff 18 | // shader.disable(); 19 | // 20 | 21 | #ifndef DDG_SHADER_H 22 | #define DDG_SHADER_H 23 | 24 | #include 25 | #include 26 | 27 | namespace DDG 28 | { 29 | class Shader 30 | { 31 | public: 32 | Shader( void ); 33 | // constructor -- shader is initially invalid 34 | 35 | ~Shader( void ); 36 | // destructor 37 | 38 | void loadVertex( const char* filename ); 39 | // read vertex shader from GLSL source file 40 | 41 | void loadFragment( const char* filename ); 42 | // read fragment shader from GLSL source file 43 | 44 | void loadGeometry( const char* filename ); 45 | // read geometry shader from GLSL source file 46 | 47 | void enable( void ); 48 | // uses this shader for rendering 49 | 50 | void disable( void ) const; 51 | // uses the fixed-function pipeline for rendering 52 | 53 | operator GLuint( void ) const; 54 | // returns the ID of this shader program (for calls to OpenGL) 55 | 56 | protected: 57 | void load( GLenum shaderType, const char* filename, GLuint& shader ); 58 | bool readSource( const char* filename, std::string& source ); 59 | 60 | GLuint vertexShader; 61 | GLuint fragmentShader; 62 | GLuint geometryShader; 63 | GLuint program; 64 | bool linked; 65 | }; 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /Elasticity/include/Utility.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_UTILITY_H 2 | #define DDG_UTILITY_H 3 | 4 | #include 5 | #include "Utility.h" 6 | #include "Complex.h" 7 | 8 | namespace DDG 9 | { 10 | inline double sqr( double x ) 11 | { 12 | return x*x; 13 | } 14 | 15 | inline double unitRand( void ) 16 | { 17 | const double rRandMax = 1. / (double) RAND_MAX; 18 | 19 | return rRandMax * (double) rand(); 20 | } 21 | 22 | inline double seconds( int t0, int t1 ) 23 | { 24 | return (double)(t1-t0) / (double) CLOCKS_PER_SEC; 25 | } 26 | } 27 | 28 | namespace DDGConstants 29 | { 30 | static DDG::Complex ii( 0., 1. ); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Elasticity/include/Vertex.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Vertex.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Vertex stores attributes associated with a mesh edge. The iterator he 6 | // points to its "outgoing" halfedge. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_VERTEX_H 11 | #define DDG_VERTEX_H 12 | 13 | #include "Vector.h" 14 | #include "Types.h" 15 | 16 | namespace DDG 17 | { 18 | class Vertex 19 | { 20 | public: 21 | HalfEdgeIter he; 22 | // points to the "outgoing" halfedge 23 | 24 | Vector position; 25 | // location of vertex in Euclidean 3-space 26 | 27 | int index; 28 | // unique integer ID in the range 0, ..., nVertices-1 29 | 30 | bool tag; 31 | // true if vertex is selected by the user; false otherwise 32 | 33 | Vertex() : index(0), tag(false) { } 34 | 35 | double area( void ) const; 36 | // returns the barycentric area associated with this vertex 37 | 38 | Vector normal( void ) const; 39 | // returns the vertex normal 40 | 41 | bool isIsolated( void ) const; 42 | // returns true if the vertex is not contained in any face or edge; false otherwise 43 | 44 | int valence( void ) const; 45 | // returns the number of incident faces / edges 46 | 47 | void toggleTag(); 48 | // toggle vertex tag 49 | }; 50 | } 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /Elasticity/obj/.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/Elasticity/obj/.empty -------------------------------------------------------------------------------- /Elasticity/shaders/fragment.glsl: -------------------------------------------------------------------------------- 1 | uniform vec3 eye; 2 | uniform vec3 light; 3 | varying vec3 position; 4 | varying vec3 normal; 5 | 6 | float diffuse( vec3 N, vec3 L ) 7 | { 8 | return max( 0., dot( N, L )); 9 | } 10 | 11 | float specular( vec3 N, vec3 L, vec3 E ) 12 | { 13 | const float shininess = 8.; 14 | vec3 R = 2.*dot(L,N)*N - L; 15 | return pow( max( 0., dot( R, E )), shininess ); 16 | } 17 | 18 | float fresnel( vec3 N, vec3 E ) 19 | { 20 | const float sharpness = 10.; 21 | float NE = max( 0., dot( N, E )); 22 | return pow( sqrt( 1. - NE*NE ), sharpness ); 23 | } 24 | 25 | void main() 26 | { 27 | vec3 N = normalize( normal ); 28 | vec3 L = normalize( light - position ); 29 | vec3 E = normalize( eye - position ); 30 | vec3 R = 2.*dot(L,N)*N - L; 31 | vec3 one = vec3( 1., 1., 1. ); 32 | 33 | gl_FragColor.rgb = diffuse(N,L)*gl_Color.rgb + .5*specular(N,L,E)*one + .5*fresnel(N,E)*one; 34 | gl_FragColor.a = 1.; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Elasticity/shaders/vertex.glsl: -------------------------------------------------------------------------------- 1 | varying vec3 position; 2 | varying vec3 normal; 3 | 4 | void main() 5 | { 6 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 7 | gl_FrontColor = gl_Color; 8 | 9 | position = gl_Vertex.xyz; 10 | normal = gl_Normal.xyz; 11 | } 12 | -------------------------------------------------------------------------------- /Elasticity/src/Edge.cpp: -------------------------------------------------------------------------------- 1 | #include "Edge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Elasticity/src/Face.cpp: -------------------------------------------------------------------------------- 1 | #include "Face.h" 2 | #include "Mesh.h" 3 | #include "Vector.h" 4 | 5 | namespace DDG 6 | { 7 | double Face::area( void ) const 8 | { 9 | Vector p0 = he->vertex->position; 10 | Vector p1 = he->next->vertex->position; 11 | Vector p2 = he->next->next->vertex->position; 12 | return cross( p1-p0, p2-p0 ).norm() / 2.; 13 | } 14 | 15 | Vector Face::normal( void ) const 16 | { 17 | Vector p0 = he->vertex->position; 18 | Vector p1 = he->next->vertex->position; 19 | Vector p2 = he->next->next->vertex->position; 20 | 21 | return cross( p1-p0, p2-p0 ).unit(); 22 | } 23 | 24 | bool Face::isBoundary( void ) const 25 | { 26 | return he->onBoundary; 27 | } 28 | 29 | Vector Face :: circumcenter( void ) const 30 | { 31 | Vector p0 = he->vertex->position; 32 | Vector p1 = he->next->vertex->position; 33 | Vector n = he->rotatedEdge(); 34 | double h = 0.5*he->cotan(); 35 | return 0.5*(p0+p1) + h*n; 36 | } 37 | 38 | Vector Face :: barycenter( void ) const 39 | { 40 | Vector p0 = he->vertex->position; 41 | Vector p1 = he->next->vertex->position; 42 | Vector p2 = he->next->next->vertex->position; 43 | return (p0 + p1 + p2)/3.; 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Elasticity/src/HalfEdge.cpp: -------------------------------------------------------------------------------- 1 | #include "HalfEdge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | double HalfEdge :: cotan( void ) const 7 | { 8 | if( onBoundary ) return 0.0; 9 | 10 | Vector p0 = next->next->vertex->position; 11 | Vector p1 = vertex->position; 12 | Vector p2 = next->vertex->position; 13 | 14 | Vector u = p1-p0; 15 | Vector v = p2-p0; 16 | 17 | return dot( u, v ) / cross( u, v ).norm(); 18 | } 19 | 20 | Vector HalfEdge :: rotatedEdge( void ) const 21 | { 22 | if( onBoundary ) return Vector(); 23 | 24 | Vector n = face->normal(); 25 | Vector p0 = vertex->position; 26 | Vector p1 = flip->vertex->position; 27 | return cross( n, p1-p0 ); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Elasticity/src/LinearContext.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearContext.h" 2 | 3 | namespace DDG 4 | { 5 | // global context for linear solvers 6 | LinearContext context; 7 | 8 | LinearContext :: LinearContext( void ) 9 | // constructor 10 | { 11 | cholmod_l_start( &context ); 12 | } 13 | 14 | LinearContext :: ~LinearContext( void ) 15 | // destructor 16 | { 17 | cholmod_l_finish( &context ); 18 | } 19 | 20 | LinearContext :: operator cholmod_common*( void ) 21 | // allows LinearContext to be treated as a cholmod_common* 22 | { 23 | return &context; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Elasticity/src/LinearEquation.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearEquation.h" 2 | 3 | namespace DDG 4 | { 5 | LinearEquation operator==( const LinearPolynomial& lhs, 6 | const LinearPolynomial& rhs ) 7 | // constructs a linear equation with the specified left- and right-hand side 8 | { 9 | LinearEquation eqn; 10 | 11 | eqn.lhs = lhs; 12 | eqn.rhs = rhs; 13 | 14 | return eqn; 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Elasticity/src/Real.cpp: -------------------------------------------------------------------------------- 1 | #include "Real.h" 2 | #include 3 | 4 | namespace DDG 5 | { 6 | Real :: Real( double x ) 7 | // constructs real number with value x 8 | : value( x ) 9 | {} 10 | 11 | Real :: operator double( void ) const 12 | // type cast to double 13 | { 14 | return value; 15 | } 16 | 17 | void Real :: operator+=( double x ) 18 | // increment 19 | { 20 | value += x; 21 | } 22 | 23 | void Real :: operator-=( double x ) 24 | // decrement 25 | { 26 | value -= x; 27 | } 28 | 29 | void Real :: operator*=( double x ) 30 | // multiply 31 | { 32 | value *= x; 33 | } 34 | 35 | void Real :: operator/=( double x ) 36 | // divide 37 | { 38 | value /= x; 39 | } 40 | 41 | Real Real :: conj( void ) const 42 | // simply returns the value (for compatibility w/ complex numbers) 43 | { 44 | return value; 45 | } 46 | 47 | Real Real :: inv( void ) const 48 | // returns inverse 49 | { 50 | return 1. / value; 51 | } 52 | 53 | double Real :: norm( void ) const 54 | // returns norm 55 | { 56 | return fabs( value ); 57 | } 58 | 59 | double Real :: norm2( void ) const 60 | // returns norm squared 61 | { 62 | return value * value; 63 | } 64 | 65 | Real Real :: unit( void ) const 66 | // returns number with unit norm and same sign 67 | { 68 | return value / norm(); 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Elasticity/src/Variable.cpp: -------------------------------------------------------------------------------- 1 | #include "Variable.h" 2 | 3 | namespace DDG 4 | { 5 | Variable :: Variable( double value_, 6 | bool fixed_ ) 7 | // initialize a variable which has value zero and is not fixed by default 8 | : value( value_ ), 9 | fixed( fixed_ ) 10 | {} 11 | 12 | Variable :: Variable( std::string name_, 13 | double value_, 14 | bool fixed_ ) 15 | // initialize a named variable which has value zero and is not fixed by default 16 | : name( name_ ), 17 | value( value_ ), 18 | fixed( fixed_ ) 19 | {} 20 | 21 | double& Variable :: operator*( void ) 22 | // returns a reference to the numerical value 23 | { 24 | return value; 25 | } 26 | 27 | const double& Variable :: operator*( void ) const 28 | // returns a const reference to the numerical value 29 | { 30 | return value; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Elasticity/src/Vertex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Vertex.h" 5 | #include "Mesh.h" 6 | #include "HalfEdge.h" 7 | 8 | namespace DDG 9 | { 10 | double Vertex::area( void ) const 11 | // returns the dual area associated with this vertex 12 | { 13 | double A = 0.; 14 | 15 | HalfEdgeCIter h = he; 16 | do 17 | { 18 | if (not h->onBoundary) A += h->face->area(); 19 | h = h->flip->next; 20 | } 21 | while( h != he ); 22 | 23 | return A / 3.; 24 | } 25 | 26 | Vector Vertex::normal( void ) const 27 | // returns the vertex normal 28 | { 29 | Vector N; 30 | 31 | HalfEdgeCIter h = he; 32 | do 33 | { 34 | if (not h->onBoundary) N += h->face->normal(); 35 | h = h->flip->next; 36 | } 37 | while( h != he ); 38 | 39 | return N.unit(); 40 | } 41 | 42 | vector isolated; // all isolated vertices point to isolated.begin() 43 | 44 | bool Vertex::isIsolated( void ) const 45 | // returns true if the vertex is not contained in any face or edge; false otherwise 46 | { 47 | return he == isolated.begin(); 48 | } 49 | 50 | int Vertex :: valence( void ) const 51 | // returns the number of incident faces 52 | { 53 | int n = 0; 54 | 55 | HalfEdgeCIter h = he; 56 | do 57 | { 58 | n++; 59 | h = h->flip->next; 60 | } 61 | while( h != he ); 62 | 63 | return n; 64 | } 65 | 66 | void Vertex :: toggleTag() 67 | { 68 | tag = !tag; 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Elasticity/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Viewer.h" 5 | #include "DenseMatrix.h" 6 | using namespace DDG; 7 | 8 | int main( int argc, char** argv ) 9 | { 10 | if( argc != 3 ) 11 | { 12 | cerr << "usage: " << argv[0] << " src.obj tgt.obj" << endl; 13 | return 1; 14 | } 15 | 16 | Viewer viewer; 17 | viewer.source.read( argv[1] ); 18 | viewer.target.read( argv[2] ); 19 | viewer.initial.read( argv[1] ); 20 | viewer.mesh.read( argv[1] ); 21 | viewer.init(); 22 | 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Fairing/.viewer_state.txt: -------------------------------------------------------------------------------- 1 | 0.126663 2 | -0.0243652 3 | -0.989174 4 | 0.0699843 5 | 815 6 | 767 7 | -------------------------------------------------------------------------------- /Fairing/Makefile: -------------------------------------------------------------------------------- 1 | ########################################################################################## 2 | 3 | # Specify library locations here (add or remove "#" marks to comment/uncomment lines for your platform) 4 | 5 | # Mac OS X 6 | DDG_INCLUDE_PATH = 7 | DDG_LIBRARY_PATH = 8 | DDG_BLAS_LIBS = -framework Accelerate 9 | DDG_SUITESPARSE_LIBS = -lspqr -lumfpack -lcholmod -lmetis -lcolamd -lccolamd -lcamd -lamd -ltbb -lm -lsuitesparseconfig 10 | DDG_OPENGL_LIBS = -framework OpenGL -framework GLUT 11 | 12 | # # Linux 13 | # DDG_INCLUDE_PATH = 14 | # DDG_LIBRARY_PATH = 15 | # DDG_BLAS_LIBS = -llapack -lblas -lgfortran 16 | # DDG_SUITESPARSE_LIBS = -lspqr -lcholmod -lmetis -lcolamd -lccolamd -lcamd -lamd -lm 17 | # DDG_OPENGL_LIBS = -lglut -lGL -lGLU -lX11 18 | 19 | # # Windows / Cygwin 20 | # DDG_INCLUDE_PATH = -I/usr/include/opengl -I/usr/include/suitesparse 21 | # DDG_LIBRARY_PATH = -L/usr/lib/w32api -L/usr/lib/suitesparse 22 | # DDG_BLAS_LIBS = -llapack -lblas 23 | # DDG_SUITESPARSE_LIBS = -lspqr -lcholmod -lcolamd -lccolamd -lcamd -lamd -lm 24 | # DDG_OPENGL_LIBS = -lglut32 -lglu32 -lopengl32 25 | 26 | ######################################################################################## 27 | 28 | TARGET = fairing 29 | CC = g++ 30 | LD = g++ 31 | CFLAGS = -O3 -Wall -Werror -ansi -pedantic $(DDG_INCLUDE_PATH) -I./include -I./src 32 | LFLAGS = -O3 -Wall -Werror -ansi -pedantic $(DDG_LIBRARY_PATH) 33 | LIBS = $(DDG_OPENGL_LIBS) $(DDG_SUITESPARSE_LIBS) $(DDG_BLAS_LIBS) 34 | 35 | ######################################################################################## 36 | ## !! Do not edit below this line 37 | 38 | HEADERS := $(wildcard include/*.h) 39 | SOURCES := $(wildcard src/*.cpp) 40 | OBJECTS := $(addprefix obj/,$(notdir $(SOURCES:.cpp=.o))) 41 | 42 | all: $(TARGET) 43 | 44 | $(TARGET): $(OBJECTS) 45 | $(LD) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LFLAGS) $(LIBS) 46 | 47 | obj/%.o: src/%.cpp ${HEADERS} 48 | $(CC) -c $< -o $@ $(CFLAGS) 49 | 50 | clean: 51 | rm -f $(OBJECTS) 52 | rm -f $(TARGET) 53 | rm -f $(TARGET).exe 54 | -------------------------------------------------------------------------------- /Fairing/include/Application.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Implicit Fairing of Arbitrary Meshes using Diffusion and Curvature Flow 3 | * Mathieu Desbrun, Mark Meyer, Peter Schröder, Alan H. Barr 4 | * ACM Siggraph '99 Proceedings 5 | */ 6 | 7 | #ifndef DDG_APPLICATION_H 8 | #define DDG_APPLICATION_H 9 | 10 | #include "Mesh.h" 11 | #include "Real.h" 12 | #include "DenseMatrix.h" 13 | #include "SparseMatrix.h" 14 | #include "DiscreteExteriorCalculus.h" 15 | 16 | namespace DDG 17 | { 18 | class Application 19 | { 20 | public: 21 | void run(const double step, Mesh& mesh) 22 | { 23 | SparseMatrix star0; 24 | HodgeStar0Form::build( mesh, star0 ); 25 | 26 | SparseMatrix star1; 27 | HodgeStar1Form::build( mesh, star1 ); 28 | 29 | SparseMatrix d0; 30 | ExteriorDerivative0Form::build( mesh, d0 ); 31 | 32 | SparseMatrix L = d0.transpose() * star1 * d0; 33 | SparseMatrix A = star0 + Real(step) * L; 34 | 35 | DenseMatrix x; 36 | getPositions(mesh, x); 37 | DenseMatrix rhs = star0 * x; 38 | 39 | solvePositiveDefinite(A, x, rhs); 40 | setPositions(x, mesh); 41 | } 42 | 43 | protected: 44 | void getPositions(const Mesh& mesh, DenseMatrix& x) const 45 | { 46 | x = DenseMatrix( mesh.vertices.size(), 3 ); 47 | for ( VertexCIter v = mesh.vertices.begin(); 48 | v != mesh.vertices.end(); 49 | v ++) 50 | { 51 | for( int i = 0; i < 3; ++i) 52 | x(v->index, i) = v->position[i]; 53 | } 54 | } 55 | 56 | void setPositions(const DenseMatrix& x, Mesh& mesh) 57 | { 58 | for ( VertexIter v = mesh.vertices.begin(); 59 | v != mesh.vertices.end(); 60 | v ++) 61 | { 62 | v->position = Vector(x(v->index, 0), 63 | x(v->index, 1), 64 | x(v->index, 2)); 65 | } 66 | } 67 | }; 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /Fairing/include/DiscreteExteriorCalculus.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- DiscreteExteriorCalculus.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Static methods for building the fundamental discrete operators (exterior 6 | // derivative, Hodge star) for 0-, 1-, and 2-forms on a surface mesh. Methods 7 | // are templated on entry type, i.e., one can build either real- or complex- 8 | // matrices using the types DDG::Real and DDG::Complex, respectively. For 9 | // instance, to build the usual Laplacian on functions, one could write 10 | // 11 | // Mesh mesh; 12 | // SparseMatrix d0, star0, star1, Delta; 13 | // 14 | // ExteriorDerivative0Form::build( mesh, d0 ); 15 | // HodgeStar0Form::build( mesh, star0 ); 16 | // HodgeStar1Form::build( mesh, star1 ); 17 | // Delta = star0.inverse() * d0.transpose() * star1 * d0; 18 | // 19 | 20 | #ifndef DDG_DISCRETEEXTERIORCALCULUS_H 21 | #define DDG_DISCRETEEXTERIORCALCULUS_H 22 | 23 | #include "Mesh.h" 24 | #include "SparseMatrix.h" 25 | 26 | namespace DDG 27 | { 28 | template< class T > struct HodgeStar0Form { static void build( const Mesh& mesh, SparseMatrix& star0 ); }; 29 | template< class T > struct HodgeStar1Form { static void build( const Mesh& mesh, SparseMatrix& star1 ); }; 30 | template< class T > struct HodgeStar2Form { static void build( const Mesh& mesh, SparseMatrix& star2 ); }; 31 | template< class T > struct ExteriorDerivative0Form { static void build( const Mesh& mesh, SparseMatrix& d0 ); }; 32 | template< class T > struct ExteriorDerivative1Form { static void build( const Mesh& mesh, SparseMatrix& d1 ); }; 33 | } 34 | 35 | #include "DiscreteExteriorCalculus.inl" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Fairing/include/Edge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Edge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Edge stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its two associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_EDGE_H 11 | #define DDG_EDGE_H 12 | 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class Edge 18 | { 19 | public: 20 | HalfEdgeIter he; 21 | // points to one of the two halfedges associated with this edge 22 | 23 | int index; 24 | // unique integer ID in the range 0, ..., nEdges-1 25 | 26 | Edge() : index(0) { } 27 | }; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Fairing/include/Face.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Face.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Face stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_FACE_H 11 | #define DDG_FACE_H 12 | 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class Face 18 | { 19 | public: 20 | HalfEdgeIter he; 21 | // points to one of the halfedges associated with this face 22 | 23 | int index; 24 | // unique integer ID in the range 0, ..., nFaces-1 25 | 26 | Face() : index(0) { } 27 | 28 | bool isBoundary( void ) const; 29 | // returns true if this face corresponds to a 30 | // boundary loop; false otherwise 31 | 32 | double area( void ) const; 33 | // returns the triangle area 34 | 35 | Vector normal( void ) const; 36 | // returns the unit normal associated with this face; normal 37 | // orientation is determined by the circulation order of halfedges 38 | 39 | Vector circumcenter( void ) const; 40 | // returns triangle circumcenter 41 | 42 | Vector barycenter( void ) const; 43 | // returns triangle barycenter 44 | }; 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Fairing/include/HalfEdge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- HalfEdge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // HalfEdge is used to define mesh connectivity. (See the documentation for a 6 | // more in-depth discussion of the halfedge data structure.) 7 | // 8 | 9 | #ifndef DDG_HALFEDGE_H 10 | #define DDG_HALFEDGE_H 11 | 12 | #include "Vector.h" 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class HalfEdge 18 | { 19 | public: 20 | HalfEdgeIter next; 21 | // points to the next halfedge around the current face 22 | 23 | HalfEdgeIter flip; 24 | // points to the other halfedge associated with this edge 25 | 26 | VertexIter vertex; 27 | // points to the vertex at the "tail" of this halfedge 28 | 29 | EdgeIter edge; 30 | // points to the edge associated with this halfedge 31 | 32 | FaceIter face; 33 | // points to the face containing this halfedge 34 | 35 | bool onBoundary; 36 | // true if this halfedge is contained in a boundary 37 | // loop; false otherwise 38 | 39 | Vector texcoord; 40 | // texture coordinates associated with the triangle corner at the 41 | // "tail" of this halfedge 42 | 43 | double cotan( void ) const; 44 | // returns the cotangent of the angle opposing this edge 45 | 46 | Vector rotatedEdge( void ) const; 47 | // returns oriented edge vector rotated by PI/2 around face normal 48 | // if onBoundary, then return nil 49 | }; 50 | } 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /Fairing/include/Image.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Image.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Image represents a color bitmap image. A simple example might look like 6 | // 7 | // Image im; 8 | // im.read( "input.tga" ); 9 | // // modify image data via im(x,y) = ...; 10 | // im.write( "output.tga" ); 11 | // 12 | 13 | #ifndef DDG_IMAGE_H 14 | #define DDG_IMAGE_H 15 | 16 | #include 17 | #include 18 | 19 | namespace DDG 20 | { 21 | class Image 22 | { 23 | public: 24 | Image( int width = 0, int height = 0 ); 25 | // constructs image with specified width and height 26 | 27 | float& operator()( int x, int y ); 28 | const float& operator()( int x, int y ) const; 29 | // accesses pixel (x,y) 30 | 31 | float sample( float x, float y ) const; 32 | // samples image at (x,y) using bilinear filtering 33 | 34 | int width( void ) const; 35 | int height( void ) const; 36 | // returns image dimensions 37 | 38 | void read( const char* filename ); 39 | // loads an image file in Truevision TGA format 40 | // (must be RGB image with 24 or 32 bits per pixel) 41 | 42 | void write( const char* filename ) const; 43 | // writes an image file in Truevision TGA format 44 | // (RGB image with 24 bits per pixel) 45 | 46 | protected: 47 | void clamp( int& x, int& y ) const; 48 | // clamps coordinates to range [0,w-1] x [0,h-1] 49 | 50 | int w, h; 51 | // width and height 52 | 53 | std::vector pixels; 54 | // interleaved RGBA pixel data in range [0-1] 55 | }; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /Fairing/include/LinearContext.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearContext.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearContext is the global solver context needed to interface with the 6 | // SuiteSparse library. It is essentially a wrapper around cholmod_common. A 7 | // single static instance of LinearContext is declared in LinearContext.cpp and 8 | // is shared by all instances of DenseMatrix, SparseMatrix, and LinearSystem. 9 | // In other words, you shouldn't have to instantiate LinearContext yourself 10 | // unless you're doing something really fancy! 11 | // 12 | 13 | #ifndef DDG_LINEARSOLVERCONTEXT 14 | #define DDG_LINEARSOLVERCONTEXT 15 | 16 | #include 17 | 18 | namespace DDG 19 | { 20 | class LinearContext 21 | { 22 | public: 23 | LinearContext( void ); 24 | // constructor 25 | 26 | ~LinearContext( void ); 27 | // destructor 28 | 29 | operator cholmod_common*( void ); 30 | // allows LinearContext to be treated as a cholmod_common* 31 | 32 | protected: 33 | cholmod_common context; 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Fairing/include/LinearEquation.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearEquation.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearEquation represents an equation with an arbitrary linear polynomial on 6 | // both the left- and right-hand side. It is primarily used while building a 7 | // LinearSystem. For convenience, operator== is overloaded so that the user 8 | // can construct a LinearEquation by writing something that looks much like the 9 | // usual mathematical syntax for a linear equation. For example, 10 | // 11 | // LinearEquation eqn = ( x + 2*y == 3*z ); 12 | // 13 | // builds the linear equation x + 2y = 3z. 14 | // 15 | 16 | #ifndef DDG_LINEAREQUATION_H 17 | #define DDG_LINEAREQUATION_H 18 | 19 | #include "LinearPolynomial.h" 20 | 21 | namespace DDG 22 | { 23 | class LinearEquation 24 | { 25 | public: 26 | LinearPolynomial lhs; 27 | // left-hand side 28 | 29 | LinearPolynomial rhs; 30 | // right-hand side 31 | }; 32 | 33 | LinearEquation operator==( const LinearPolynomial& lhs, const LinearPolynomial& rhs ); 34 | // constructs a linear equation with the specified left- and right-hand side 35 | } 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /Fairing/include/MeshIO.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- MeshIO.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // MeshIO handles input/output operations for Mesh objects. Currently the only 6 | // supported mesh format is Wavefront OBJ -- for a format specification see 7 | // 8 | // http://en.wikipedia.org/wiki/Wavefront_.obj_file 9 | // 10 | // Note that vertex normals and material properties are currently ignored. 11 | // 12 | 13 | #ifndef DDG_MESHIO_H 14 | #define DDG_MESHIO_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace DDG 22 | { 23 | class Mesh; 24 | class Index; 25 | class MeshData; 26 | 27 | class MeshIO 28 | { 29 | public: 30 | static int read( std::istream& in, Mesh& mesh ); 31 | // reads a mesh from a valid, open input stream in 32 | 33 | static void write( std::ostream& out, const Mesh& mesh ); 34 | // writes a mesh to a valid, open output stream out 35 | 36 | protected: 37 | static int readMeshData( std::istream& in, MeshData& data ); 38 | static void readPosition( std::stringstream& ss, MeshData& data ); 39 | static void readTexCoord( std::stringstream& ss, MeshData& data ); 40 | static void readNormal ( std::stringstream& ss, MeshData& data ); 41 | static void readFace ( std::stringstream& ss, MeshData& data ); 42 | static Index parseFaceIndex( const std::string& token ); 43 | static void preallocateMeshElements( const MeshData& data, Mesh& mesh ); 44 | static int buildMesh( const MeshData& data, Mesh& mesh ); 45 | static void checkIsolatedVertices( const Mesh& Mesh ); 46 | static void checkNonManifoldVertices( const Mesh& Mesh ); 47 | }; 48 | } 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /Fairing/include/Real.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_REAL_H 2 | #define DDG_REAL_H 3 | 4 | namespace DDG 5 | { 6 | class Real 7 | { 8 | public: 9 | Real( double x = 0. ); 10 | // constructs real number with value x 11 | 12 | operator double( void ) const; 13 | // type cast to double 14 | 15 | void operator+=( double x ); 16 | // increment 17 | 18 | void operator-=( double x ); 19 | // decrement 20 | 21 | void operator*=( double x ); 22 | // multiply 23 | 24 | void operator/=( double x ); 25 | // divide 26 | 27 | Real conj( void ) const; 28 | // simply returns the value (for compatibility w/ complex numbers) 29 | 30 | Real inv( void ) const; 31 | // returns inverse 32 | 33 | double norm( void ) const; 34 | // returns norm 35 | 36 | double norm2( void ) const; 37 | // returns norm squared 38 | 39 | Real unit( void ) const; 40 | // returns number with unit norm and same sign 41 | 42 | protected: 43 | double value; 44 | // value 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Fairing/include/Shader.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Shader.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Shader encapsulates the functionality of a shader program written in 6 | // the OpenGL Shader Language (GLSL). Basic usage is to read a collection 7 | // of source files to disk and enable the shader before making draw calls. 8 | // For instance, during initialization one might write 9 | // 10 | // Shader shader; 11 | // shader.loadVertex( "vertex.glsl" ); 12 | // shader.loadFragment( "fragment.glsl" ); 13 | // 14 | // and in the main draw routine write 15 | // 16 | // shader.enable(); 17 | // // draw some stuff 18 | // shader.disable(); 19 | // 20 | 21 | #ifndef DDG_SHADER_H 22 | #define DDG_SHADER_H 23 | 24 | #include 25 | #include 26 | 27 | namespace DDG 28 | { 29 | class Shader 30 | { 31 | public: 32 | Shader( void ); 33 | // constructor -- shader is initially invalid 34 | 35 | ~Shader( void ); 36 | // destructor 37 | 38 | void loadVertex( const char* filename ); 39 | // read vertex shader from GLSL source file 40 | 41 | void loadFragment( const char* filename ); 42 | // read fragment shader from GLSL source file 43 | 44 | void loadGeometry( const char* filename ); 45 | // read geometry shader from GLSL source file 46 | 47 | void enable( void ); 48 | // uses this shader for rendering 49 | 50 | void disable( void ) const; 51 | // uses the fixed-function pipeline for rendering 52 | 53 | operator GLuint( void ) const; 54 | // returns the ID of this shader program (for calls to OpenGL) 55 | 56 | protected: 57 | void load( GLenum shaderType, const char* filename, GLuint& shader ); 58 | bool readSource( const char* filename, std::string& source ); 59 | 60 | GLuint vertexShader; 61 | GLuint fragmentShader; 62 | GLuint geometryShader; 63 | GLuint program; 64 | bool linked; 65 | }; 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /Fairing/include/Utility.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_UTILITY_H 2 | #define DDG_UTILITY_H 3 | 4 | #include 5 | #include "Utility.h" 6 | #include "Complex.h" 7 | 8 | namespace DDG 9 | { 10 | inline double sqr( double x ) 11 | { 12 | return x*x; 13 | } 14 | 15 | inline double unitRand( void ) 16 | { 17 | const double rRandMax = 1. / (double) RAND_MAX; 18 | 19 | return rRandMax * (double) rand(); 20 | } 21 | 22 | inline double seconds( int t0, int t1 ) 23 | { 24 | return (double)(t1-t0) / (double) CLOCKS_PER_SEC; 25 | } 26 | } 27 | 28 | namespace DDGConstants 29 | { 30 | static DDG::Complex ii( 0., 1. ); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Fairing/include/Vertex.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Vertex.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Vertex stores attributes associated with a mesh edge. The iterator he 6 | // points to its "outgoing" halfedge. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_VERTEX_H 11 | #define DDG_VERTEX_H 12 | 13 | #include "Vector.h" 14 | #include "Types.h" 15 | 16 | namespace DDG 17 | { 18 | class Vertex 19 | { 20 | public: 21 | HalfEdgeIter he; 22 | // points to the "outgoing" halfedge 23 | 24 | Vector position; 25 | // location of vertex in Euclidean 3-space 26 | 27 | int index; 28 | // unique integer ID in the range 0, ..., nVertices-1 29 | 30 | bool tag; 31 | // true if vertex is selected by the user; false otherwise 32 | 33 | Vertex() : index(0), tag(false) { } 34 | 35 | double area( void ) const; 36 | // returns the barycentric area associated with this vertex 37 | 38 | Vector normal( void ) const; 39 | // returns the vertex normal 40 | 41 | bool isIsolated( void ) const; 42 | // returns true if the vertex is not contained in any face or edge; false otherwise 43 | 44 | int valence( void ) const; 45 | // returns the number of incident faces / edges 46 | 47 | void toggleTag(); 48 | // toggle vertex tag 49 | }; 50 | } 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /Fairing/obj/.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/Fairing/obj/.empty -------------------------------------------------------------------------------- /Fairing/shaders/fragment.glsl: -------------------------------------------------------------------------------- 1 | uniform vec3 eye; 2 | uniform vec3 light; 3 | varying vec3 position; 4 | varying vec3 normal; 5 | 6 | float diffuse( vec3 N, vec3 L ) 7 | { 8 | return max( 0., dot( N, L )); 9 | } 10 | 11 | float specular( vec3 N, vec3 L, vec3 E ) 12 | { 13 | const float shininess = 8.; 14 | vec3 R = 2.*dot(L,N)*N - L; 15 | return pow( max( 0., dot( R, E )), shininess ); 16 | } 17 | 18 | float fresnel( vec3 N, vec3 E ) 19 | { 20 | const float sharpness = 10.; 21 | float NE = max( 0., dot( N, E )); 22 | return pow( sqrt( 1. - NE*NE ), sharpness ); 23 | } 24 | 25 | void main() 26 | { 27 | vec3 N = normalize( normal ); 28 | vec3 L = normalize( light - position ); 29 | vec3 E = normalize( eye - position ); 30 | vec3 R = 2.*dot(L,N)*N - L; 31 | vec3 one = vec3( 1., 1., 1. ); 32 | 33 | gl_FragColor.rgb = diffuse(N,L)*gl_Color.rgb + .5*specular(N,L,E)*one + .5*fresnel(N,E)*one; 34 | gl_FragColor.a = 1.; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Fairing/shaders/vertex.glsl: -------------------------------------------------------------------------------- 1 | varying vec3 position; 2 | varying vec3 normal; 3 | 4 | void main() 5 | { 6 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 7 | gl_FrontColor = gl_Color; 8 | 9 | position = gl_Vertex.xyz; 10 | normal = gl_Normal.xyz; 11 | } 12 | -------------------------------------------------------------------------------- /Fairing/src/Edge.cpp: -------------------------------------------------------------------------------- 1 | #include "Edge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Fairing/src/Face.cpp: -------------------------------------------------------------------------------- 1 | #include "Face.h" 2 | #include "Mesh.h" 3 | #include "Vector.h" 4 | 5 | namespace DDG 6 | { 7 | double Face::area( void ) const 8 | { 9 | Vector p0 = he->vertex->position; 10 | Vector p1 = he->next->vertex->position; 11 | Vector p2 = he->next->next->vertex->position; 12 | return cross( p1-p0, p2-p0 ).norm() / 2.; 13 | } 14 | 15 | Vector Face::normal( void ) const 16 | { 17 | Vector p0 = he->vertex->position; 18 | Vector p1 = he->next->vertex->position; 19 | Vector p2 = he->next->next->vertex->position; 20 | 21 | return cross( p1-p0, p2-p0 ).unit(); 22 | } 23 | 24 | bool Face::isBoundary( void ) const 25 | { 26 | return he->onBoundary; 27 | } 28 | 29 | Vector Face :: circumcenter( void ) const 30 | { 31 | Vector p0 = he->vertex->position; 32 | Vector p1 = he->next->vertex->position; 33 | Vector n = he->rotatedEdge(); 34 | double h = 0.5*he->cotan(); 35 | return 0.5*(p0+p1) + h*n; 36 | } 37 | 38 | Vector Face :: barycenter( void ) const 39 | { 40 | Vector p0 = he->vertex->position; 41 | Vector p1 = he->next->vertex->position; 42 | Vector p2 = he->next->next->vertex->position; 43 | return (p0 + p1 + p2)/3.; 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Fairing/src/HalfEdge.cpp: -------------------------------------------------------------------------------- 1 | #include "HalfEdge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | double HalfEdge :: cotan( void ) const 7 | { 8 | if( onBoundary ) return 0.0; 9 | 10 | Vector p0 = next->next->vertex->position; 11 | Vector p1 = vertex->position; 12 | Vector p2 = next->vertex->position; 13 | 14 | Vector u = p1-p0; 15 | Vector v = p2-p0; 16 | 17 | return dot( u, v ) / cross( u, v ).norm(); 18 | } 19 | 20 | Vector HalfEdge :: rotatedEdge( void ) const 21 | { 22 | if( onBoundary ) return Vector(); 23 | 24 | Vector n = face->normal(); 25 | Vector p0 = vertex->position; 26 | Vector p1 = flip->vertex->position; 27 | return cross( n, p1-p0 ); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Fairing/src/LinearContext.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearContext.h" 2 | 3 | namespace DDG 4 | { 5 | // global context for linear solvers 6 | LinearContext context; 7 | 8 | LinearContext :: LinearContext( void ) 9 | // constructor 10 | { 11 | cholmod_l_start( &context ); 12 | } 13 | 14 | LinearContext :: ~LinearContext( void ) 15 | // destructor 16 | { 17 | cholmod_l_finish( &context ); 18 | } 19 | 20 | LinearContext :: operator cholmod_common*( void ) 21 | // allows LinearContext to be treated as a cholmod_common* 22 | { 23 | return &context; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Fairing/src/LinearEquation.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearEquation.h" 2 | 3 | namespace DDG 4 | { 5 | LinearEquation operator==( const LinearPolynomial& lhs, 6 | const LinearPolynomial& rhs ) 7 | // constructs a linear equation with the specified left- and right-hand side 8 | { 9 | LinearEquation eqn; 10 | 11 | eqn.lhs = lhs; 12 | eqn.rhs = rhs; 13 | 14 | return eqn; 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Fairing/src/Real.cpp: -------------------------------------------------------------------------------- 1 | #include "Real.h" 2 | #include 3 | 4 | namespace DDG 5 | { 6 | Real :: Real( double x ) 7 | // constructs real number with value x 8 | : value( x ) 9 | {} 10 | 11 | Real :: operator double( void ) const 12 | // type cast to double 13 | { 14 | return value; 15 | } 16 | 17 | void Real :: operator+=( double x ) 18 | // increment 19 | { 20 | value += x; 21 | } 22 | 23 | void Real :: operator-=( double x ) 24 | // decrement 25 | { 26 | value -= x; 27 | } 28 | 29 | void Real :: operator*=( double x ) 30 | // multiply 31 | { 32 | value *= x; 33 | } 34 | 35 | void Real :: operator/=( double x ) 36 | // divide 37 | { 38 | value /= x; 39 | } 40 | 41 | Real Real :: conj( void ) const 42 | // simply returns the value (for compatibility w/ complex numbers) 43 | { 44 | return value; 45 | } 46 | 47 | Real Real :: inv( void ) const 48 | // returns inverse 49 | { 50 | return 1. / value; 51 | } 52 | 53 | double Real :: norm( void ) const 54 | // returns norm 55 | { 56 | return fabs( value ); 57 | } 58 | 59 | double Real :: norm2( void ) const 60 | // returns norm squared 61 | { 62 | return value * value; 63 | } 64 | 65 | Real Real :: unit( void ) const 66 | // returns number with unit norm and same sign 67 | { 68 | return value / norm(); 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Fairing/src/Variable.cpp: -------------------------------------------------------------------------------- 1 | #include "Variable.h" 2 | 3 | namespace DDG 4 | { 5 | Variable :: Variable( double value_, 6 | bool fixed_ ) 7 | // initialize a variable which has value zero and is not fixed by default 8 | : value( value_ ), 9 | fixed( fixed_ ) 10 | {} 11 | 12 | Variable :: Variable( std::string name_, 13 | double value_, 14 | bool fixed_ ) 15 | // initialize a named variable which has value zero and is not fixed by default 16 | : name( name_ ), 17 | value( value_ ), 18 | fixed( fixed_ ) 19 | {} 20 | 21 | double& Variable :: operator*( void ) 22 | // returns a reference to the numerical value 23 | { 24 | return value; 25 | } 26 | 27 | const double& Variable :: operator*( void ) const 28 | // returns a const reference to the numerical value 29 | { 30 | return value; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Fairing/src/Vertex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Vertex.h" 5 | #include "Mesh.h" 6 | #include "HalfEdge.h" 7 | 8 | namespace DDG 9 | { 10 | double Vertex::area( void ) const 11 | // returns the dual area associated with this vertex 12 | { 13 | double A = 0.; 14 | 15 | HalfEdgeCIter h = he; 16 | do 17 | { 18 | if (not h->onBoundary) A += h->face->area(); 19 | h = h->flip->next; 20 | } 21 | while( h != he ); 22 | 23 | return A / 3.; 24 | } 25 | 26 | Vector Vertex::normal( void ) const 27 | // returns the vertex normal 28 | { 29 | Vector N; 30 | 31 | HalfEdgeCIter h = he; 32 | do 33 | { 34 | if (not h->onBoundary) N += h->face->normal(); 35 | h = h->flip->next; 36 | } 37 | while( h != he ); 38 | 39 | return N.unit(); 40 | } 41 | 42 | vector isolated; // all isolated vertices point to isolated.begin() 43 | 44 | bool Vertex::isIsolated( void ) const 45 | // returns true if the vertex is not contained in any face or edge; false otherwise 46 | { 47 | return he == isolated.begin(); 48 | } 49 | 50 | int Vertex :: valence( void ) const 51 | // returns the number of incident faces 52 | { 53 | int n = 0; 54 | 55 | HalfEdgeCIter h = he; 56 | do 57 | { 58 | n++; 59 | h = h->flip->next; 60 | } 61 | while( h != he ); 62 | 63 | return n; 64 | } 65 | 66 | void Vertex :: toggleTag() 67 | { 68 | tag = !tag; 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Fairing/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Viewer.h" 5 | #include "DenseMatrix.h" 6 | using namespace DDG; 7 | 8 | int main( int argc, char** argv ) 9 | { 10 | if( argc != 2 ) 11 | { 12 | cerr << "usage: " << argv[0] << " in.obj" << endl; 13 | return 1; 14 | } 15 | 16 | Viewer viewer; 17 | viewer.mesh.read( argv[1] ); 18 | viewer.init(); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Flatten/.viewer_state.txt: -------------------------------------------------------------------------------- 1 | 0.126663 2 | -0.0243652 3 | -0.989174 4 | 0.0699843 5 | 815 6 | 767 7 | -------------------------------------------------------------------------------- /Flatten/include/DiscreteExteriorCalculus.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- DiscreteExteriorCalculus.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Static methods for building the fundamental discrete operators (exterior 6 | // derivative, Hodge star) for 0-, 1-, and 2-forms on a surface mesh. Methods 7 | // are templated on entry type, i.e., one can build either real- or complex- 8 | // matrices using the types DDG::Real and DDG::Complex, respectively. For 9 | // instance, to build the usual Laplacian on functions, one could write 10 | // 11 | // Mesh mesh; 12 | // SparseMatrix d0, star0, star1, Delta; 13 | // 14 | // ExteriorDerivative0Form::build( mesh, d0 ); 15 | // HodgeStar0Form::build( mesh, star0 ); 16 | // HodgeStar1Form::build( mesh, star1 ); 17 | // Delta = star0.inverse() * d0.transpose() * star1 * d0; 18 | // 19 | 20 | #ifndef DDG_DISCRETEEXTERIORCALCULUS_H 21 | #define DDG_DISCRETEEXTERIORCALCULUS_H 22 | 23 | #include "Mesh.h" 24 | #include "SparseMatrix.h" 25 | 26 | namespace DDG 27 | { 28 | template< class T > struct HodgeStar0Form { static void build( const Mesh& mesh, SparseMatrix& star0 ); }; 29 | template< class T > struct HodgeStar1Form { static void build( const Mesh& mesh, SparseMatrix& star1 ); }; 30 | template< class T > struct HodgeStar2Form { static void build( const Mesh& mesh, SparseMatrix& star2 ); }; 31 | template< class T > struct ExteriorDerivative0Form { static void build( const Mesh& mesh, SparseMatrix& d0 ); }; 32 | template< class T > struct ExteriorDerivative1Form { static void build( const Mesh& mesh, SparseMatrix& d1 ); }; 33 | } 34 | 35 | #include "DiscreteExteriorCalculus.inl" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Flatten/include/Edge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Edge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Edge stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its two associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_EDGE_H 11 | #define DDG_EDGE_H 12 | 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class Edge 18 | { 19 | public: 20 | HalfEdgeIter he; 21 | // points to one of the two halfedges associated with this edge 22 | 23 | int index; 24 | // unique integer ID in the range 0, ..., nEdges-1 25 | 26 | Edge() : index(0) { } 27 | }; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Flatten/include/Face.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Face.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Face stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_FACE_H 11 | #define DDG_FACE_H 12 | 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class Face 18 | { 19 | public: 20 | HalfEdgeIter he; 21 | // points to one of the halfedges associated with this face 22 | 23 | int index; 24 | // unique integer ID in the range 0, ..., nFaces-1 25 | 26 | Face() : index(0) { } 27 | 28 | bool isBoundary( void ) const; 29 | // returns true if this face corresponds to a 30 | // boundary loop; false otherwise 31 | 32 | double area( void ) const; 33 | // returns the triangle area 34 | 35 | Vector normal( void ) const; 36 | // returns the unit normal associated with this face; normal 37 | // orientation is determined by the circulation order of halfedges 38 | 39 | Vector circumcenter( void ) const; 40 | // returns triangle circumcenter 41 | 42 | Vector barycenter( void ) const; 43 | // returns triangle barycenter 44 | }; 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Flatten/include/HalfEdge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- HalfEdge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // HalfEdge is used to define mesh connectivity. (See the documentation for a 6 | // more in-depth discussion of the halfedge data structure.) 7 | // 8 | 9 | #ifndef DDG_HALFEDGE_H 10 | #define DDG_HALFEDGE_H 11 | 12 | #include "Vector.h" 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class HalfEdge 18 | { 19 | public: 20 | HalfEdgeIter next; 21 | // points to the next halfedge around the current face 22 | 23 | HalfEdgeIter flip; 24 | // points to the other halfedge associated with this edge 25 | 26 | VertexIter vertex; 27 | // points to the vertex at the "tail" of this halfedge 28 | 29 | EdgeIter edge; 30 | // points to the edge associated with this halfedge 31 | 32 | FaceIter face; 33 | // points to the face containing this halfedge 34 | 35 | bool onBoundary; 36 | // true if this halfedge is contained in a boundary 37 | // loop; false otherwise 38 | 39 | Vector texcoord; 40 | // texture coordinates associated with the triangle corner at the 41 | // "tail" of this halfedge 42 | 43 | double cotan( void ) const; 44 | // returns the cotangent of the angle opposing this edge 45 | 46 | Vector rotatedEdge( void ) const; 47 | // returns oriented edge vector rotated by PI/2 around face normal 48 | // if onBoundary, then return nil 49 | }; 50 | } 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /Flatten/include/Image.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Image.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Image represents a color bitmap image. A simple example might look like 6 | // 7 | // Image im; 8 | // im.read( "input.tga" ); 9 | // // modify image data via im(x,y) = ...; 10 | // im.write( "output.tga" ); 11 | // 12 | 13 | #ifndef DDG_IMAGE_H 14 | #define DDG_IMAGE_H 15 | 16 | #include 17 | #include 18 | 19 | namespace DDG 20 | { 21 | class Image 22 | { 23 | public: 24 | Image( int width = 0, int height = 0 ); 25 | // constructs image with specified width and height 26 | 27 | float& operator()( int x, int y ); 28 | const float& operator()( int x, int y ) const; 29 | // accesses pixel (x,y) 30 | 31 | float sample( float x, float y ) const; 32 | // samples image at (x,y) using bilinear filtering 33 | 34 | int width( void ) const; 35 | int height( void ) const; 36 | // returns image dimensions 37 | 38 | void read( const char* filename ); 39 | // loads an image file in Truevision TGA format 40 | // (must be RGB image with 24 or 32 bits per pixel) 41 | 42 | void write( const char* filename ) const; 43 | // writes an image file in Truevision TGA format 44 | // (RGB image with 24 bits per pixel) 45 | 46 | protected: 47 | void clamp( int& x, int& y ) const; 48 | // clamps coordinates to range [0,w-1] x [0,h-1] 49 | 50 | int w, h; 51 | // width and height 52 | 53 | std::vector pixels; 54 | // interleaved RGBA pixel data in range [0-1] 55 | }; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /Flatten/include/LinearContext.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearContext.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearContext is the global solver context needed to interface with the 6 | // SuiteSparse library. It is essentially a wrapper around cholmod_common. A 7 | // single static instance of LinearContext is declared in LinearContext.cpp and 8 | // is shared by all instances of DenseMatrix, SparseMatrix, and LinearSystem. 9 | // In other words, you shouldn't have to instantiate LinearContext yourself 10 | // unless you're doing something really fancy! 11 | // 12 | 13 | #ifndef DDG_LINEARSOLVERCONTEXT 14 | #define DDG_LINEARSOLVERCONTEXT 15 | 16 | #include 17 | 18 | namespace DDG 19 | { 20 | class LinearContext 21 | { 22 | public: 23 | LinearContext( void ); 24 | // constructor 25 | 26 | ~LinearContext( void ); 27 | // destructor 28 | 29 | operator cholmod_common*( void ); 30 | // allows LinearContext to be treated as a cholmod_common* 31 | 32 | protected: 33 | cholmod_common context; 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Flatten/include/LinearEquation.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearEquation.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearEquation represents an equation with an arbitrary linear polynomial on 6 | // both the left- and right-hand side. It is primarily used while building a 7 | // LinearSystem. For convenience, operator== is overloaded so that the user 8 | // can construct a LinearEquation by writing something that looks much like the 9 | // usual mathematical syntax for a linear equation. For example, 10 | // 11 | // LinearEquation eqn = ( x + 2*y == 3*z ); 12 | // 13 | // builds the linear equation x + 2y = 3z. 14 | // 15 | 16 | #ifndef DDG_LINEAREQUATION_H 17 | #define DDG_LINEAREQUATION_H 18 | 19 | #include "LinearPolynomial.h" 20 | 21 | namespace DDG 22 | { 23 | class LinearEquation 24 | { 25 | public: 26 | LinearPolynomial lhs; 27 | // left-hand side 28 | 29 | LinearPolynomial rhs; 30 | // right-hand side 31 | }; 32 | 33 | LinearEquation operator==( const LinearPolynomial& lhs, const LinearPolynomial& rhs ); 34 | // constructs a linear equation with the specified left- and right-hand side 35 | } 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /Flatten/include/MeshIO.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- MeshIO.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // MeshIO handles input/output operations for Mesh objects. Currently the only 6 | // supported mesh format is Wavefront OBJ -- for a format specification see 7 | // 8 | // http://en.wikipedia.org/wiki/Wavefront_.obj_file 9 | // 10 | // Note that vertex normals and material properties are currently ignored. 11 | // 12 | 13 | #ifndef DDG_MESHIO_H 14 | #define DDG_MESHIO_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace DDG 22 | { 23 | class Mesh; 24 | class Index; 25 | class MeshData; 26 | 27 | class MeshIO 28 | { 29 | public: 30 | static int read( std::istream& in, Mesh& mesh ); 31 | // reads a mesh from a valid, open input stream in 32 | 33 | static void write( std::ostream& out, const Mesh& mesh ); 34 | // writes a mesh to a valid, open output stream out 35 | 36 | protected: 37 | static int readMeshData( std::istream& in, MeshData& data ); 38 | static void readPosition( std::stringstream& ss, MeshData& data ); 39 | static void readTexCoord( std::stringstream& ss, MeshData& data ); 40 | static void readNormal ( std::stringstream& ss, MeshData& data ); 41 | static void readFace ( std::stringstream& ss, MeshData& data ); 42 | static Index parseFaceIndex( const std::string& token ); 43 | static void preallocateMeshElements( const MeshData& data, Mesh& mesh ); 44 | static int buildMesh( const MeshData& data, Mesh& mesh ); 45 | static void checkIsolatedVertices( const Mesh& Mesh ); 46 | static void checkNonManifoldVertices( const Mesh& Mesh ); 47 | }; 48 | } 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /Flatten/include/Real.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_REAL_H 2 | #define DDG_REAL_H 3 | 4 | namespace DDG 5 | { 6 | class Real 7 | { 8 | public: 9 | Real( double x = 0. ); 10 | // constructs real number with value x 11 | 12 | operator double( void ) const; 13 | // type cast to double 14 | 15 | void operator+=( double x ); 16 | // increment 17 | 18 | void operator-=( double x ); 19 | // decrement 20 | 21 | void operator*=( double x ); 22 | // multiply 23 | 24 | void operator/=( double x ); 25 | // divide 26 | 27 | Real conj( void ) const; 28 | // simply returns the value (for compatibility w/ complex numbers) 29 | 30 | Real inv( void ) const; 31 | // returns inverse 32 | 33 | double norm( void ) const; 34 | // returns norm 35 | 36 | double norm2( void ) const; 37 | // returns norm squared 38 | 39 | Real unit( void ) const; 40 | // returns number with unit norm and same sign 41 | 42 | protected: 43 | double value; 44 | // value 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Flatten/include/Shader.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Shader.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Shader encapsulates the functionality of a shader program written in 6 | // the OpenGL Shader Language (GLSL). Basic usage is to read a collection 7 | // of source files to disk and enable the shader before making draw calls. 8 | // For instance, during initialization one might write 9 | // 10 | // Shader shader; 11 | // shader.loadVertex( "vertex.glsl" ); 12 | // shader.loadFragment( "fragment.glsl" ); 13 | // 14 | // and in the main draw routine write 15 | // 16 | // shader.enable(); 17 | // // draw some stuff 18 | // shader.disable(); 19 | // 20 | 21 | #ifndef DDG_SHADER_H 22 | #define DDG_SHADER_H 23 | 24 | #include 25 | #include 26 | 27 | namespace DDG 28 | { 29 | class Shader 30 | { 31 | public: 32 | Shader( void ); 33 | // constructor -- shader is initially invalid 34 | 35 | ~Shader( void ); 36 | // destructor 37 | 38 | void loadVertex( const char* filename ); 39 | // read vertex shader from GLSL source file 40 | 41 | void loadFragment( const char* filename ); 42 | // read fragment shader from GLSL source file 43 | 44 | void loadGeometry( const char* filename ); 45 | // read geometry shader from GLSL source file 46 | 47 | void enable( void ); 48 | // uses this shader for rendering 49 | 50 | void disable( void ) const; 51 | // uses the fixed-function pipeline for rendering 52 | 53 | operator GLuint( void ) const; 54 | // returns the ID of this shader program (for calls to OpenGL) 55 | 56 | protected: 57 | void load( GLenum shaderType, const char* filename, GLuint& shader ); 58 | bool readSource( const char* filename, std::string& source ); 59 | 60 | GLuint vertexShader; 61 | GLuint fragmentShader; 62 | GLuint geometryShader; 63 | GLuint program; 64 | bool linked; 65 | }; 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /Flatten/include/Utility.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_UTILITY_H 2 | #define DDG_UTILITY_H 3 | 4 | #include 5 | #include "Utility.h" 6 | #include "Complex.h" 7 | 8 | namespace DDG 9 | { 10 | inline double sqr( double x ) 11 | { 12 | return x*x; 13 | } 14 | 15 | inline double unitRand( void ) 16 | { 17 | const double rRandMax = 1. / (double) RAND_MAX; 18 | 19 | return rRandMax * (double) rand(); 20 | } 21 | 22 | inline double seconds( int t0, int t1 ) 23 | { 24 | return (double)(t1-t0) / (double) CLOCKS_PER_SEC; 25 | } 26 | } 27 | 28 | namespace DDGConstants 29 | { 30 | static DDG::Complex ii( 0., 1. ); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Flatten/include/Vertex.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Vertex.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Vertex stores attributes associated with a mesh edge. The iterator he 6 | // points to its "outgoing" halfedge. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_VERTEX_H 11 | #define DDG_VERTEX_H 12 | 13 | #include "Vector.h" 14 | #include "Types.h" 15 | 16 | namespace DDG 17 | { 18 | class Vertex 19 | { 20 | public: 21 | HalfEdgeIter he; 22 | // points to the "outgoing" halfedge 23 | 24 | Vector texture; 25 | // location of vertex in Euclidian 2-space 26 | 27 | Vector position; 28 | // location of vertex in Euclidean 3-space 29 | 30 | int index; 31 | // unique integer ID in the range 0, ..., nVertices-1 32 | 33 | bool tag; 34 | // true if vertex is selected by the user; false otherwise 35 | 36 | Vertex() : index(0), tag(false) { } 37 | 38 | double area( void ) const; 39 | // returns the barycentric area associated with this vertex 40 | 41 | Vector normal( void ) const; 42 | // returns the vertex normal 43 | 44 | bool isIsolated( void ) const; 45 | // returns true if the vertex is not contained in any face or edge; false otherwise 46 | 47 | int valence( void ) const; 48 | // returns the number of incident faces / edges 49 | 50 | void toggleTag(); 51 | // toggle vertex tag 52 | }; 53 | } 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /Flatten/obj/.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/Flatten/obj/.empty -------------------------------------------------------------------------------- /Flatten/shaders/fragment.glsl: -------------------------------------------------------------------------------- 1 | uniform vec3 eye; 2 | uniform vec3 light; 3 | varying vec3 position; 4 | varying vec3 normal; 5 | 6 | float diffuse( vec3 N, vec3 L ) 7 | { 8 | return max( 0., dot( N, L )); 9 | } 10 | 11 | float specular( vec3 N, vec3 L, vec3 E ) 12 | { 13 | const float shininess = 8.; 14 | vec3 R = 2.*dot(L,N)*N - L; 15 | return pow( max( 0., dot( R, E )), shininess ); 16 | } 17 | 18 | float fresnel( vec3 N, vec3 E ) 19 | { 20 | const float sharpness = 10.; 21 | float NE = max( 0., dot( N, E )); 22 | return pow( sqrt( 1. - NE*NE ), sharpness ); 23 | } 24 | 25 | void main() 26 | { 27 | vec3 N = normalize( normal ); 28 | vec3 L = normalize( light - position ); 29 | vec3 E = normalize( eye - position ); 30 | vec3 R = 2.*dot(L,N)*N - L; 31 | vec3 one = vec3( 1., 1., 1. ); 32 | 33 | gl_FragColor.rgb = diffuse(N,L)*gl_Color.rgb + .5*specular(N,L,E)*one + .5*fresnel(N,E)*one; 34 | gl_FragColor.a = 1.; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Flatten/shaders/vertex.glsl: -------------------------------------------------------------------------------- 1 | varying vec3 position; 2 | varying vec3 normal; 3 | 4 | void main() 5 | { 6 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 7 | gl_FrontColor = gl_Color; 8 | 9 | position = gl_Vertex.xyz; 10 | normal = gl_Normal.xyz; 11 | } 12 | -------------------------------------------------------------------------------- /Flatten/src/Edge.cpp: -------------------------------------------------------------------------------- 1 | #include "Edge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Flatten/src/Face.cpp: -------------------------------------------------------------------------------- 1 | #include "Face.h" 2 | #include "Mesh.h" 3 | #include "Vector.h" 4 | 5 | namespace DDG 6 | { 7 | double Face::area( void ) const 8 | { 9 | Vector p0 = he->vertex->position; 10 | Vector p1 = he->next->vertex->position; 11 | Vector p2 = he->next->next->vertex->position; 12 | return cross( p1-p0, p2-p0 ).norm() / 2.; 13 | } 14 | 15 | Vector Face::normal( void ) const 16 | { 17 | Vector p0 = he->vertex->position; 18 | Vector p1 = he->next->vertex->position; 19 | Vector p2 = he->next->next->vertex->position; 20 | 21 | return cross( p1-p0, p2-p0 ).unit(); 22 | } 23 | 24 | bool Face::isBoundary( void ) const 25 | { 26 | return he->onBoundary; 27 | } 28 | 29 | Vector Face :: circumcenter( void ) const 30 | { 31 | Vector p0 = he->vertex->position; 32 | Vector p1 = he->next->vertex->position; 33 | Vector n = he->rotatedEdge(); 34 | double h = 0.5*he->cotan(); 35 | return 0.5*(p0+p1) + h*n; 36 | } 37 | 38 | Vector Face :: barycenter( void ) const 39 | { 40 | Vector p0 = he->vertex->position; 41 | Vector p1 = he->next->vertex->position; 42 | Vector p2 = he->next->next->vertex->position; 43 | return (p0 + p1 + p2)/3.; 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Flatten/src/HalfEdge.cpp: -------------------------------------------------------------------------------- 1 | #include "HalfEdge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | double HalfEdge :: cotan( void ) const 7 | { 8 | if( onBoundary ) return 0.0; 9 | 10 | Vector p0 = next->next->vertex->position; 11 | Vector p1 = vertex->position; 12 | Vector p2 = next->vertex->position; 13 | 14 | Vector u = p1-p0; 15 | Vector v = p2-p0; 16 | 17 | return dot( u, v ) / cross( u, v ).norm(); 18 | } 19 | 20 | Vector HalfEdge :: rotatedEdge( void ) const 21 | { 22 | if( onBoundary ) return Vector(); 23 | 24 | Vector n = face->normal(); 25 | Vector p0 = vertex->position; 26 | Vector p1 = flip->vertex->position; 27 | return cross( n, p1-p0 ); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Flatten/src/LinearContext.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearContext.h" 2 | 3 | namespace DDG 4 | { 5 | // global context for linear solvers 6 | LinearContext context; 7 | 8 | LinearContext :: LinearContext( void ) 9 | // constructor 10 | { 11 | cholmod_l_start( &context ); 12 | } 13 | 14 | LinearContext :: ~LinearContext( void ) 15 | // destructor 16 | { 17 | cholmod_l_finish( &context ); 18 | } 19 | 20 | LinearContext :: operator cholmod_common*( void ) 21 | // allows LinearContext to be treated as a cholmod_common* 22 | { 23 | return &context; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Flatten/src/LinearEquation.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearEquation.h" 2 | 3 | namespace DDG 4 | { 5 | LinearEquation operator==( const LinearPolynomial& lhs, 6 | const LinearPolynomial& rhs ) 7 | // constructs a linear equation with the specified left- and right-hand side 8 | { 9 | LinearEquation eqn; 10 | 11 | eqn.lhs = lhs; 12 | eqn.rhs = rhs; 13 | 14 | return eqn; 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Flatten/src/Real.cpp: -------------------------------------------------------------------------------- 1 | #include "Real.h" 2 | #include 3 | 4 | namespace DDG 5 | { 6 | Real :: Real( double x ) 7 | // constructs real number with value x 8 | : value( x ) 9 | {} 10 | 11 | Real :: operator double( void ) const 12 | // type cast to double 13 | { 14 | return value; 15 | } 16 | 17 | void Real :: operator+=( double x ) 18 | // increment 19 | { 20 | value += x; 21 | } 22 | 23 | void Real :: operator-=( double x ) 24 | // decrement 25 | { 26 | value -= x; 27 | } 28 | 29 | void Real :: operator*=( double x ) 30 | // multiply 31 | { 32 | value *= x; 33 | } 34 | 35 | void Real :: operator/=( double x ) 36 | // divide 37 | { 38 | value /= x; 39 | } 40 | 41 | Real Real :: conj( void ) const 42 | // simply returns the value (for compatibility w/ complex numbers) 43 | { 44 | return value; 45 | } 46 | 47 | Real Real :: inv( void ) const 48 | // returns inverse 49 | { 50 | return 1. / value; 51 | } 52 | 53 | double Real :: norm( void ) const 54 | // returns norm 55 | { 56 | return fabs( value ); 57 | } 58 | 59 | double Real :: norm2( void ) const 60 | // returns norm squared 61 | { 62 | return value * value; 63 | } 64 | 65 | Real Real :: unit( void ) const 66 | // returns number with unit norm and same sign 67 | { 68 | return value / norm(); 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Flatten/src/Variable.cpp: -------------------------------------------------------------------------------- 1 | #include "Variable.h" 2 | 3 | namespace DDG 4 | { 5 | Variable :: Variable( double value_, 6 | bool fixed_ ) 7 | // initialize a variable which has value zero and is not fixed by default 8 | : value( value_ ), 9 | fixed( fixed_ ) 10 | {} 11 | 12 | Variable :: Variable( std::string name_, 13 | double value_, 14 | bool fixed_ ) 15 | // initialize a named variable which has value zero and is not fixed by default 16 | : name( name_ ), 17 | value( value_ ), 18 | fixed( fixed_ ) 19 | {} 20 | 21 | double& Variable :: operator*( void ) 22 | // returns a reference to the numerical value 23 | { 24 | return value; 25 | } 26 | 27 | const double& Variable :: operator*( void ) const 28 | // returns a const reference to the numerical value 29 | { 30 | return value; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Flatten/src/Vertex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Vertex.h" 5 | #include "Mesh.h" 6 | #include "HalfEdge.h" 7 | 8 | namespace DDG 9 | { 10 | double Vertex::area( void ) const 11 | // returns the dual area associated with this vertex 12 | { 13 | double A = 0.; 14 | 15 | HalfEdgeCIter h = he; 16 | do 17 | { 18 | if (not h->onBoundary) A += h->face->area(); 19 | h = h->flip->next; 20 | } 21 | while( h != he ); 22 | 23 | return A / 3.; 24 | } 25 | 26 | Vector Vertex::normal( void ) const 27 | // returns the vertex normal 28 | { 29 | Vector N; 30 | 31 | HalfEdgeCIter h = he; 32 | do 33 | { 34 | if (not h->onBoundary) N += h->face->normal(); 35 | h = h->flip->next; 36 | } 37 | while( h != he ); 38 | 39 | return N.unit(); 40 | } 41 | 42 | vector isolated; // all isolated vertices point to isolated.begin() 43 | 44 | bool Vertex::isIsolated( void ) const 45 | // returns true if the vertex is not contained in any face or edge; false otherwise 46 | { 47 | return he == isolated.begin(); 48 | } 49 | 50 | int Vertex :: valence( void ) const 51 | // returns the number of incident faces 52 | { 53 | int n = 0; 54 | 55 | HalfEdgeCIter h = he; 56 | do 57 | { 58 | n++; 59 | h = h->flip->next; 60 | } 61 | while( h != he ); 62 | 63 | return n; 64 | } 65 | 66 | void Vertex :: toggleTag() 67 | { 68 | tag = !tag; 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Flatten/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Viewer.h" 5 | #include "DenseMatrix.h" 6 | using namespace DDG; 7 | 8 | int main( int argc, char** argv ) 9 | { 10 | if( argc != 2 ) 11 | { 12 | cerr << "usage: " << argv[0] << " in.obj" << endl; 13 | return 1; 14 | } 15 | 16 | Viewer viewer; 17 | viewer.mesh.read( argv[1] ); 18 | viewer.init(); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Geodesics/.viewer_state.txt: -------------------------------------------------------------------------------- 1 | 0.126663 2 | -0.0243652 3 | -0.989174 4 | 0.0699843 5 | 815 6 | 767 7 | -------------------------------------------------------------------------------- /Geodesics/Makefile: -------------------------------------------------------------------------------- 1 | ########################################################################################## 2 | 3 | # Specify library locations here (add or remove "#" marks to comment/uncomment lines for your platform) 4 | 5 | # Mac OS X 6 | DDG_INCLUDE_PATH = 7 | DDG_LIBRARY_PATH = 8 | DDG_BLAS_LIBS = -framework Accelerate 9 | DDG_SUITESPARSE_LIBS = -lspqr -lumfpack -lcholmod -lmetis -lcolamd -lccolamd -lcamd -lamd -ltbb -lm -lsuitesparseconfig 10 | DDG_OPENGL_LIBS = -framework OpenGL -framework GLUT 11 | 12 | # # Linux 13 | # DDG_INCLUDE_PATH = 14 | # DDG_LIBRARY_PATH = 15 | # DDG_BLAS_LIBS = -llapack -lblas -lgfortran 16 | # DDG_SUITESPARSE_LIBS = -lspqr -lcholmod -lmetis -lcolamd -lccolamd -lcamd -lamd -lm 17 | # DDG_OPENGL_LIBS = -lglut -lGL -lGLU -lX11 18 | 19 | # # Windows / Cygwin 20 | # DDG_INCLUDE_PATH = -I/usr/include/opengl -I/usr/include/suitesparse 21 | # DDG_LIBRARY_PATH = -L/usr/lib/w32api -L/usr/lib/suitesparse 22 | # DDG_BLAS_LIBS = -llapack -lblas 23 | # DDG_SUITESPARSE_LIBS = -lspqr -lcholmod -lcolamd -lccolamd -lcamd -lamd -lm 24 | # DDG_OPENGL_LIBS = -lglut32 -lglu32 -lopengl32 25 | 26 | ######################################################################################## 27 | 28 | TARGET = geodesics 29 | CC = g++ 30 | LD = g++ 31 | CFLAGS = -O3 -Wall -Werror -ansi -pedantic $(DDG_INCLUDE_PATH) -I./include -I./src 32 | LFLAGS = -O3 -Wall -Werror -ansi -pedantic $(DDG_LIBRARY_PATH) 33 | LIBS = $(DDG_OPENGL_LIBS) $(DDG_SUITESPARSE_LIBS) $(DDG_BLAS_LIBS) 34 | 35 | ######################################################################################## 36 | ## !! Do not edit below this line 37 | 38 | HEADERS := $(wildcard include/*.h) 39 | SOURCES := $(wildcard src/*.cpp) 40 | OBJECTS := $(addprefix obj/,$(notdir $(SOURCES:.cpp=.o))) 41 | 42 | all: $(TARGET) 43 | 44 | $(TARGET): $(OBJECTS) 45 | $(LD) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LFLAGS) $(LIBS) 46 | 47 | obj/%.o: src/%.cpp ${HEADERS} 48 | $(CC) -c $< -o $@ $(CFLAGS) 49 | 50 | clean: 51 | rm -f $(OBJECTS) 52 | rm -f $(TARGET) 53 | rm -f $(TARGET).exe 54 | -------------------------------------------------------------------------------- /Geodesics/include/DiscreteExteriorCalculus.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- DiscreteExteriorCalculus.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Static methods for building the fundamental discrete operators (exterior 6 | // derivative, Hodge star) for 0-, 1-, and 2-forms on a surface mesh. Methods 7 | // are templated on entry type, i.e., one can build either real- or complex- 8 | // matrices using the types DDG::Real and DDG::Complex, respectively. For 9 | // instance, to build the usual Laplacian on functions, one could write 10 | // 11 | // Mesh mesh; 12 | // SparseMatrix d0, star0, star1, Delta; 13 | // 14 | // ExteriorDerivative0Form::build( mesh, d0 ); 15 | // HodgeStar0Form::build( mesh, star0 ); 16 | // HodgeStar1Form::build( mesh, star1 ); 17 | // Delta = star0.inverse() * d0.transpose() * star1 * d0; 18 | // 19 | 20 | #ifndef DDG_DISCRETEEXTERIORCALCULUS_H 21 | #define DDG_DISCRETEEXTERIORCALCULUS_H 22 | 23 | #include "Mesh.h" 24 | #include "SparseMatrix.h" 25 | 26 | namespace DDG 27 | { 28 | template< class T > struct HodgeStar0Form { static void build( const Mesh& mesh, SparseMatrix& star0 ); }; 29 | template< class T > struct HodgeStar1Form { static void build( const Mesh& mesh, SparseMatrix& star1 ); }; 30 | template< class T > struct HodgeStar2Form { static void build( const Mesh& mesh, SparseMatrix& star2 ); }; 31 | template< class T > struct ExteriorDerivative0Form { static void build( const Mesh& mesh, SparseMatrix& d0 ); }; 32 | template< class T > struct ExteriorDerivative1Form { static void build( const Mesh& mesh, SparseMatrix& d1 ); }; 33 | } 34 | 35 | #include "DiscreteExteriorCalculus.inl" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Geodesics/include/Edge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Edge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Edge stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its two associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_EDGE_H 11 | #define DDG_EDGE_H 12 | 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class Edge 18 | { 19 | public: 20 | HalfEdgeIter he; 21 | // points to one of the two halfedges associated with this edge 22 | 23 | int index; 24 | // unique integer ID in the range 0, ..., nEdges-1 25 | 26 | Edge() : index(0) { } 27 | }; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Geodesics/include/Face.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Face.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Face stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_FACE_H 11 | #define DDG_FACE_H 12 | 13 | #include "Types.h" 14 | #include "Vector.h" 15 | 16 | namespace DDG 17 | { 18 | class Face 19 | { 20 | public: 21 | HalfEdgeIter he; 22 | // points to one of the halfedges associated with this face 23 | 24 | int index; 25 | // unique integer ID in the range 0, ..., nFaces-1 26 | 27 | Vector vector; 28 | // tangent vector per triangle 29 | 30 | Face() : index(0) { } 31 | 32 | bool isBoundary( void ) const; 33 | // returns true if this face corresponds to a 34 | // boundary loop; false otherwise 35 | 36 | double area( void ) const; 37 | // returns the triangle area 38 | 39 | Vector normal( void ) const; 40 | // returns the unit normal associated with this face; normal 41 | // orientation is determined by the circulation order of halfedges 42 | 43 | Vector circumcenter( void ) const; 44 | // returns triangle circumcenter 45 | 46 | Vector barycenter( void ) const; 47 | // returns triangle barycenter 48 | }; 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Geodesics/include/HalfEdge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- HalfEdge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // HalfEdge is used to define mesh connectivity. (See the documentation for a 6 | // more in-depth discussion of the halfedge data structure.) 7 | // 8 | 9 | #ifndef DDG_HALFEDGE_H 10 | #define DDG_HALFEDGE_H 11 | 12 | #include "Vector.h" 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class HalfEdge 18 | { 19 | public: 20 | HalfEdgeIter next; 21 | // points to the next halfedge around the current face 22 | 23 | HalfEdgeIter flip; 24 | // points to the other halfedge associated with this edge 25 | 26 | VertexIter vertex; 27 | // points to the vertex at the "tail" of this halfedge 28 | 29 | EdgeIter edge; 30 | // points to the edge associated with this halfedge 31 | 32 | FaceIter face; 33 | // points to the face containing this halfedge 34 | 35 | bool onBoundary; 36 | // true if this halfedge is contained in a boundary 37 | // loop; false otherwise 38 | 39 | Vector texcoord; 40 | // texture coordinates associated with the triangle corner at the 41 | // "tail" of this halfedge 42 | 43 | double cotan( void ) const; 44 | // returns the cotangent of the angle opposing this edge 45 | 46 | Vector rotatedEdge( void ) const; 47 | // returns oriented edge vector rotated by PI/2 around face normal 48 | // if onBoundary, then return nil 49 | }; 50 | } 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /Geodesics/include/Image.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Image.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Image represents a color bitmap image. A simple example might look like 6 | // 7 | // Image im; 8 | // im.read( "input.tga" ); 9 | // // modify image data via im(x,y) = ...; 10 | // im.write( "output.tga" ); 11 | // 12 | 13 | #ifndef DDG_IMAGE_H 14 | #define DDG_IMAGE_H 15 | 16 | #include 17 | #include 18 | 19 | namespace DDG 20 | { 21 | class Image 22 | { 23 | public: 24 | Image( int width = 0, int height = 0 ); 25 | // constructs image with specified width and height 26 | 27 | float& operator()( int x, int y ); 28 | const float& operator()( int x, int y ) const; 29 | // accesses pixel (x,y) 30 | 31 | float sample( float x, float y ) const; 32 | // samples image at (x,y) using bilinear filtering 33 | 34 | int width( void ) const; 35 | int height( void ) const; 36 | // returns image dimensions 37 | 38 | void read( const char* filename ); 39 | // loads an image file in Truevision TGA format 40 | // (must be RGB image with 24 or 32 bits per pixel) 41 | 42 | void write( const char* filename ) const; 43 | // writes an image file in Truevision TGA format 44 | // (RGB image with 24 bits per pixel) 45 | 46 | protected: 47 | void clamp( int& x, int& y ) const; 48 | // clamps coordinates to range [0,w-1] x [0,h-1] 49 | 50 | int w, h; 51 | // width and height 52 | 53 | std::vector pixels; 54 | // interleaved RGBA pixel data in range [0-1] 55 | }; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /Geodesics/include/LinearContext.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearContext.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearContext is the global solver context needed to interface with the 6 | // SuiteSparse library. It is essentially a wrapper around cholmod_common. A 7 | // single static instance of LinearContext is declared in LinearContext.cpp and 8 | // is shared by all instances of DenseMatrix, SparseMatrix, and LinearSystem. 9 | // In other words, you shouldn't have to instantiate LinearContext yourself 10 | // unless you're doing something really fancy! 11 | // 12 | 13 | #ifndef DDG_LINEARSOLVERCONTEXT 14 | #define DDG_LINEARSOLVERCONTEXT 15 | 16 | #include 17 | 18 | namespace DDG 19 | { 20 | class LinearContext 21 | { 22 | public: 23 | LinearContext( void ); 24 | // constructor 25 | 26 | ~LinearContext( void ); 27 | // destructor 28 | 29 | operator cholmod_common*( void ); 30 | // allows LinearContext to be treated as a cholmod_common* 31 | 32 | protected: 33 | cholmod_common context; 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Geodesics/include/LinearEquation.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearEquation.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearEquation represents an equation with an arbitrary linear polynomial on 6 | // both the left- and right-hand side. It is primarily used while building a 7 | // LinearSystem. For convenience, operator== is overloaded so that the user 8 | // can construct a LinearEquation by writing something that looks much like the 9 | // usual mathematical syntax for a linear equation. For example, 10 | // 11 | // LinearEquation eqn = ( x + 2*y == 3*z ); 12 | // 13 | // builds the linear equation x + 2y = 3z. 14 | // 15 | 16 | #ifndef DDG_LINEAREQUATION_H 17 | #define DDG_LINEAREQUATION_H 18 | 19 | #include "LinearPolynomial.h" 20 | 21 | namespace DDG 22 | { 23 | class LinearEquation 24 | { 25 | public: 26 | LinearPolynomial lhs; 27 | // left-hand side 28 | 29 | LinearPolynomial rhs; 30 | // right-hand side 31 | }; 32 | 33 | LinearEquation operator==( const LinearPolynomial& lhs, const LinearPolynomial& rhs ); 34 | // constructs a linear equation with the specified left- and right-hand side 35 | } 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /Geodesics/include/MeshIO.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- MeshIO.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // MeshIO handles input/output operations for Mesh objects. Currently the only 6 | // supported mesh format is Wavefront OBJ -- for a format specification see 7 | // 8 | // http://en.wikipedia.org/wiki/Wavefront_.obj_file 9 | // 10 | // Note that vertex normals and material properties are currently ignored. 11 | // 12 | 13 | #ifndef DDG_MESHIO_H 14 | #define DDG_MESHIO_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace DDG 22 | { 23 | class Mesh; 24 | class Index; 25 | class MeshData; 26 | 27 | class MeshIO 28 | { 29 | public: 30 | static int read( std::istream& in, Mesh& mesh ); 31 | // reads a mesh from a valid, open input stream in 32 | 33 | static void write( std::ostream& out, const Mesh& mesh ); 34 | // writes a mesh to a valid, open output stream out 35 | 36 | protected: 37 | static int readMeshData( std::istream& in, MeshData& data ); 38 | static void readPosition( std::stringstream& ss, MeshData& data ); 39 | static void readTexCoord( std::stringstream& ss, MeshData& data ); 40 | static void readNormal ( std::stringstream& ss, MeshData& data ); 41 | static void readFace ( std::stringstream& ss, MeshData& data ); 42 | static Index parseFaceIndex( const std::string& token ); 43 | static void preallocateMeshElements( const MeshData& data, Mesh& mesh ); 44 | static int buildMesh( const MeshData& data, Mesh& mesh ); 45 | static void checkIsolatedVertices( const Mesh& Mesh ); 46 | static void checkNonManifoldVertices( const Mesh& Mesh ); 47 | }; 48 | } 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /Geodesics/include/Real.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_REAL_H 2 | #define DDG_REAL_H 3 | 4 | namespace DDG 5 | { 6 | class Real 7 | { 8 | public: 9 | Real( double x = 0. ); 10 | // constructs real number with value x 11 | 12 | operator double( void ) const; 13 | // type cast to double 14 | 15 | void operator+=( double x ); 16 | // increment 17 | 18 | void operator-=( double x ); 19 | // decrement 20 | 21 | void operator*=( double x ); 22 | // multiply 23 | 24 | void operator/=( double x ); 25 | // divide 26 | 27 | Real conj( void ) const; 28 | // simply returns the value (for compatibility w/ complex numbers) 29 | 30 | Real inv( void ) const; 31 | // returns inverse 32 | 33 | double norm( void ) const; 34 | // returns norm 35 | 36 | double norm2( void ) const; 37 | // returns norm squared 38 | 39 | Real unit( void ) const; 40 | // returns number with unit norm and same sign 41 | 42 | protected: 43 | double value; 44 | // value 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Geodesics/include/Utility.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_UTILITY_H 2 | #define DDG_UTILITY_H 3 | 4 | #include 5 | #include "Utility.h" 6 | #include "Complex.h" 7 | 8 | namespace DDG 9 | { 10 | inline double sqr( double x ) 11 | { 12 | return x*x; 13 | } 14 | 15 | inline double unitRand( void ) 16 | { 17 | const double rRandMax = 1. / (double) RAND_MAX; 18 | 19 | return rRandMax * (double) rand(); 20 | } 21 | 22 | inline double seconds( int t0, int t1 ) 23 | { 24 | return (double)(t1-t0) / (double) CLOCKS_PER_SEC; 25 | } 26 | } 27 | 28 | namespace DDGConstants 29 | { 30 | static DDG::Complex ii( 0., 1. ); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Geodesics/include/Vertex.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Vertex.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Vertex stores attributes associated with a mesh edge. The iterator he 6 | // points to its "outgoing" halfedge. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_VERTEX_H 11 | #define DDG_VERTEX_H 12 | 13 | #include "Vector.h" 14 | #include "Types.h" 15 | 16 | namespace DDG 17 | { 18 | class Vertex 19 | { 20 | public: 21 | HalfEdgeIter he; 22 | // points to the "outgoing" halfedge 23 | 24 | Vector position; 25 | // location of vertex in Euclidean 3-space 26 | 27 | int index; 28 | // unique integer ID in the range 0, ..., nVertices-1 29 | 30 | bool tag; 31 | // true if vertex is selected by the user; false otherwise 32 | 33 | double distance; 34 | 35 | Vertex() : index(0), tag(false), distance(0.0) { } 36 | 37 | double area( void ) const; 38 | // returns the barycentric area associated with this vertex 39 | 40 | Vector normal( void ) const; 41 | // returns the vertex normal 42 | 43 | bool isIsolated( void ) const; 44 | // returns true if the vertex is not contained in any face or edge; false otherwise 45 | 46 | int valence( void ) const; 47 | // returns the number of incident faces / edges 48 | 49 | void toggleTag(); 50 | // toggle vertex tag 51 | }; 52 | } 53 | 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /Geodesics/obj/.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/Geodesics/obj/.empty -------------------------------------------------------------------------------- /Geodesics/shaders/fragment.glsl: -------------------------------------------------------------------------------- 1 | uniform vec3 eye; 2 | uniform vec3 light; 3 | varying vec3 position; 4 | varying vec3 normal; 5 | 6 | float diffuse( vec3 N, vec3 L ) 7 | { 8 | return max( 0., dot( N, L )); 9 | } 10 | 11 | float specular( vec3 N, vec3 L, vec3 E ) 12 | { 13 | const float shininess = 8.; 14 | vec3 R = 2.*dot(L,N)*N - L; 15 | return pow( max( 0., dot( R, E )), shininess ); 16 | } 17 | 18 | float fresnel( vec3 N, vec3 E ) 19 | { 20 | const float sharpness = 10.; 21 | float NE = max( 0., dot( N, E )); 22 | return pow( sqrt( 1. - NE*NE ), sharpness ); 23 | } 24 | 25 | void main() 26 | { 27 | // color 28 | float d = 1. - gl_Color.r; 29 | float r = (1. - d*d) * .8; 30 | float g = (1. - (2. * (d - .5)) * (2. * (d - .5))) * .7; 31 | float b = (1. - (1. - d) * (1. - d)); 32 | vec3 color = vec3(r, g, b); 33 | 34 | // lines 35 | float h = gl_Color.r; 36 | h = h * 30.; 37 | h = h - floor( h ); 38 | h = (1. / (1. + exp(-100.*(h - .55)))) + (1. / (1. + exp(-100.*(-h + .45)))); 39 | h = 1. - h; 40 | color.xyz = vec3(h, h, h) + (1. - h) * color.xyz; 41 | 42 | vec3 N = normalize( normal ); 43 | vec3 L = normalize( light - position ); 44 | vec3 E = normalize( eye - position ); 45 | vec3 R = 2.*dot(L,N)*N - L; 46 | vec3 one = vec3( 1., 1., 1. ); 47 | 48 | gl_FragColor.rgb = diffuse(N,L)*color + .5*specular(N,L,E)*one + .5*fresnel(N,E)*one; 49 | gl_FragColor.a = 1.; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /Geodesics/shaders/vertex.glsl: -------------------------------------------------------------------------------- 1 | varying vec3 position; 2 | varying vec3 normal; 3 | 4 | void main() 5 | { 6 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 7 | gl_FrontColor = gl_Color; 8 | 9 | position = gl_Vertex.xyz; 10 | normal = gl_Normal.xyz; 11 | } 12 | -------------------------------------------------------------------------------- /Geodesics/src/Edge.cpp: -------------------------------------------------------------------------------- 1 | #include "Edge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Geodesics/src/Face.cpp: -------------------------------------------------------------------------------- 1 | #include "Face.h" 2 | #include "Mesh.h" 3 | #include "Vector.h" 4 | 5 | namespace DDG 6 | { 7 | double Face::area( void ) const 8 | { 9 | Vector p0 = he->vertex->position; 10 | Vector p1 = he->next->vertex->position; 11 | Vector p2 = he->next->next->vertex->position; 12 | return cross( p1-p0, p2-p0 ).norm() / 2.; 13 | } 14 | 15 | Vector Face::normal( void ) const 16 | { 17 | Vector p0 = he->vertex->position; 18 | Vector p1 = he->next->vertex->position; 19 | Vector p2 = he->next->next->vertex->position; 20 | 21 | return cross( p1-p0, p2-p0 ).unit(); 22 | } 23 | 24 | bool Face::isBoundary( void ) const 25 | { 26 | return he->onBoundary; 27 | } 28 | 29 | Vector Face :: circumcenter( void ) const 30 | { 31 | Vector p0 = he->vertex->position; 32 | Vector p1 = he->next->vertex->position; 33 | Vector n = he->rotatedEdge(); 34 | double h = 0.5*he->cotan(); 35 | return 0.5*(p0+p1) + h*n; 36 | } 37 | 38 | Vector Face :: barycenter( void ) const 39 | { 40 | Vector p0 = he->vertex->position; 41 | Vector p1 = he->next->vertex->position; 42 | Vector p2 = he->next->next->vertex->position; 43 | return (p0 + p1 + p2)/3.; 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Geodesics/src/HalfEdge.cpp: -------------------------------------------------------------------------------- 1 | #include "HalfEdge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | double HalfEdge :: cotan( void ) const 7 | { 8 | if( onBoundary ) return 0.0; 9 | 10 | Vector p0 = next->next->vertex->position; 11 | Vector p1 = vertex->position; 12 | Vector p2 = next->vertex->position; 13 | 14 | Vector u = p1-p0; 15 | Vector v = p2-p0; 16 | 17 | return dot( u, v ) / cross( u, v ).norm(); 18 | } 19 | 20 | Vector HalfEdge :: rotatedEdge( void ) const 21 | { 22 | if( onBoundary ) return Vector(); 23 | 24 | Vector n = face->normal(); 25 | Vector p0 = vertex->position; 26 | Vector p1 = flip->vertex->position; 27 | return cross( n, p1-p0 ); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Geodesics/src/LinearContext.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearContext.h" 2 | 3 | namespace DDG 4 | { 5 | // global context for linear solvers 6 | LinearContext context; 7 | 8 | LinearContext :: LinearContext( void ) 9 | // constructor 10 | { 11 | cholmod_l_start( &context ); 12 | } 13 | 14 | LinearContext :: ~LinearContext( void ) 15 | // destructor 16 | { 17 | cholmod_l_finish( &context ); 18 | } 19 | 20 | LinearContext :: operator cholmod_common*( void ) 21 | // allows LinearContext to be treated as a cholmod_common* 22 | { 23 | return &context; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Geodesics/src/LinearEquation.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearEquation.h" 2 | 3 | namespace DDG 4 | { 5 | LinearEquation operator==( const LinearPolynomial& lhs, 6 | const LinearPolynomial& rhs ) 7 | // constructs a linear equation with the specified left- and right-hand side 8 | { 9 | LinearEquation eqn; 10 | 11 | eqn.lhs = lhs; 12 | eqn.rhs = rhs; 13 | 14 | return eqn; 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Geodesics/src/Real.cpp: -------------------------------------------------------------------------------- 1 | #include "Real.h" 2 | #include 3 | 4 | namespace DDG 5 | { 6 | Real :: Real( double x ) 7 | // constructs real number with value x 8 | : value( x ) 9 | {} 10 | 11 | Real :: operator double( void ) const 12 | // type cast to double 13 | { 14 | return value; 15 | } 16 | 17 | void Real :: operator+=( double x ) 18 | // increment 19 | { 20 | value += x; 21 | } 22 | 23 | void Real :: operator-=( double x ) 24 | // decrement 25 | { 26 | value -= x; 27 | } 28 | 29 | void Real :: operator*=( double x ) 30 | // multiply 31 | { 32 | value *= x; 33 | } 34 | 35 | void Real :: operator/=( double x ) 36 | // divide 37 | { 38 | value /= x; 39 | } 40 | 41 | Real Real :: conj( void ) const 42 | // simply returns the value (for compatibility w/ complex numbers) 43 | { 44 | return value; 45 | } 46 | 47 | Real Real :: inv( void ) const 48 | // returns inverse 49 | { 50 | return 1. / value; 51 | } 52 | 53 | double Real :: norm( void ) const 54 | // returns norm 55 | { 56 | return fabs( value ); 57 | } 58 | 59 | double Real :: norm2( void ) const 60 | // returns norm squared 61 | { 62 | return value * value; 63 | } 64 | 65 | Real Real :: unit( void ) const 66 | // returns number with unit norm and same sign 67 | { 68 | return value / norm(); 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Geodesics/src/Variable.cpp: -------------------------------------------------------------------------------- 1 | #include "Variable.h" 2 | 3 | namespace DDG 4 | { 5 | Variable :: Variable( double value_, 6 | bool fixed_ ) 7 | // initialize a variable which has value zero and is not fixed by default 8 | : value( value_ ), 9 | fixed( fixed_ ) 10 | {} 11 | 12 | Variable :: Variable( std::string name_, 13 | double value_, 14 | bool fixed_ ) 15 | // initialize a named variable which has value zero and is not fixed by default 16 | : name( name_ ), 17 | value( value_ ), 18 | fixed( fixed_ ) 19 | {} 20 | 21 | double& Variable :: operator*( void ) 22 | // returns a reference to the numerical value 23 | { 24 | return value; 25 | } 26 | 27 | const double& Variable :: operator*( void ) const 28 | // returns a const reference to the numerical value 29 | { 30 | return value; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Geodesics/src/Vertex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Vertex.h" 5 | #include "Mesh.h" 6 | #include "HalfEdge.h" 7 | 8 | namespace DDG 9 | { 10 | double Vertex::area( void ) const 11 | // returns the dual area associated with this vertex 12 | { 13 | double A = 0.; 14 | 15 | HalfEdgeCIter h = he; 16 | do 17 | { 18 | if (not h->onBoundary) A += h->face->area(); 19 | h = h->flip->next; 20 | } 21 | while( h != he ); 22 | 23 | return A / 3.; 24 | } 25 | 26 | Vector Vertex::normal( void ) const 27 | // returns the vertex normal 28 | { 29 | Vector N; 30 | 31 | HalfEdgeCIter h = he; 32 | do 33 | { 34 | if (not h->onBoundary) N += h->face->normal(); 35 | h = h->flip->next; 36 | } 37 | while( h != he ); 38 | 39 | return N.unit(); 40 | } 41 | 42 | vector isolated; // all isolated vertices point to isolated.begin() 43 | 44 | bool Vertex::isIsolated( void ) const 45 | // returns true if the vertex is not contained in any face or edge; false otherwise 46 | { 47 | return he == isolated.begin(); 48 | } 49 | 50 | int Vertex :: valence( void ) const 51 | // returns the number of incident faces 52 | { 53 | int n = 0; 54 | 55 | HalfEdgeCIter h = he; 56 | do 57 | { 58 | n++; 59 | h = h->flip->next; 60 | } 61 | while( h != he ); 62 | 63 | return n; 64 | } 65 | 66 | void Vertex :: toggleTag() 67 | { 68 | tag = !tag; 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Geodesics/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Viewer.h" 5 | #include "DenseMatrix.h" 6 | using namespace DDG; 7 | 8 | int main( int argc, char** argv ) 9 | { 10 | if( argc != 2 ) 11 | { 12 | cerr << "usage: " << argv[0] << " in.obj" << endl; 13 | return 1; 14 | } 15 | 16 | Viewer viewer; 17 | viewer.mesh.read( argv[1] ); 18 | viewer.init(); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Hot2/.viewer_state.txt: -------------------------------------------------------------------------------- 1 | 0.126663 2 | -0.0243652 3 | -0.989174 4 | 0.0699843 5 | 815 6 | 767 7 | -------------------------------------------------------------------------------- /Hot2/Makefile: -------------------------------------------------------------------------------- 1 | ########################################################################################## 2 | 3 | # Specify library locations here (add or remove "#" marks to comment/uncomment lines for your platform) 4 | 5 | # Mac OS X 6 | DDG_INCLUDE_PATH = 7 | DDG_LIBRARY_PATH = 8 | DDG_BLAS_LIBS = -framework Accelerate 9 | DDG_SUITESPARSE_LIBS = -lspqr -lumfpack -lcholmod -lmetis -lcolamd -lccolamd -lcamd -lamd -ltbb -lm -lsuitesparseconfig 10 | DDG_OPENGL_LIBS = -framework OpenGL -framework GLUT 11 | 12 | # # Linux 13 | # DDG_INCLUDE_PATH = 14 | # DDG_LIBRARY_PATH = 15 | # DDG_BLAS_LIBS = -llapack -lblas -lgfortran 16 | # DDG_SUITESPARSE_LIBS = -lspqr -lcholmod -lmetis -lcolamd -lccolamd -lcamd -lamd -lm 17 | # DDG_OPENGL_LIBS = -lglut -lGL -lGLU -lX11 18 | 19 | # # Windows / Cygwin 20 | # DDG_INCLUDE_PATH = -I/usr/include/opengl -I/usr/include/suitesparse 21 | # DDG_LIBRARY_PATH = -L/usr/lib/w32api -L/usr/lib/suitesparse 22 | # DDG_BLAS_LIBS = -llapack -lblas 23 | # DDG_SUITESPARSE_LIBS = -lspqr -lcholmod -lcolamd -lccolamd -lcamd -lamd -lm 24 | # DDG_OPENGL_LIBS = -lglut32 -lglu32 -lopengl32 25 | 26 | ######################################################################################## 27 | 28 | TARGET = hot2 29 | CC = g++ 30 | LD = g++ 31 | CFLAGS = -O3 -Wall -Werror -ansi -pedantic $(DDG_INCLUDE_PATH) -I./include -I./src 32 | LFLAGS = -O3 -Wall -Werror -ansi -pedantic $(DDG_LIBRARY_PATH) 33 | LIBS = $(DDG_OPENGL_LIBS) $(DDG_SUITESPARSE_LIBS) $(DDG_BLAS_LIBS) 34 | 35 | ######################################################################################## 36 | ## !! Do not edit below this line 37 | 38 | HEADERS := $(wildcard include/*.h) 39 | SOURCES := $(wildcard src/*.cpp) 40 | OBJECTS := $(addprefix obj/,$(notdir $(SOURCES:.cpp=.o))) 41 | 42 | all: $(TARGET) 43 | 44 | $(TARGET): $(OBJECTS) 45 | $(LD) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LFLAGS) $(LIBS) 46 | 47 | obj/%.o: src/%.cpp ${HEADERS} 48 | $(CC) -c $< -o $@ $(CFLAGS) 49 | 50 | clean: 51 | rm -f $(OBJECTS) 52 | rm -f $(TARGET) 53 | rm -f $(TARGET).exe 54 | -------------------------------------------------------------------------------- /Hot2/include/DiscreteExteriorCalculus.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- DiscreteExteriorCalculus.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Static methods for building the fundamental discrete operators (exterior 6 | // derivative, Hodge star) for 0-, 1-, and 2-forms on a surface mesh. Methods 7 | // are templated on entry type, i.e., one can build either real- or complex- 8 | // matrices using the types DDG::Real and DDG::Complex, respectively. For 9 | // instance, to build the usual Laplacian on functions, one could write 10 | // 11 | // Mesh mesh; 12 | // SparseMatrix d0, star0, star1, Delta; 13 | // 14 | // ExteriorDerivative0Form::build( mesh, d0 ); 15 | // HodgeStar0Form::build( mesh, star0 ); 16 | // HodgeStar1Form::build( mesh, star1 ); 17 | // Delta = star0.inverse() * d0.transpose() * star1 * d0; 18 | // 19 | 20 | #ifndef DDG_DISCRETEEXTERIORCALCULUS_H 21 | #define DDG_DISCRETEEXTERIORCALCULUS_H 22 | 23 | #include "Mesh.h" 24 | #include "SparseMatrix.h" 25 | 26 | namespace DDG 27 | { 28 | template< class T > struct HodgeStar0Form { static void build( const Mesh& mesh, SparseMatrix& star0 ); }; 29 | template< class T > struct HodgeStar1Form { static void build( const Mesh& mesh, SparseMatrix& star1 ); }; 30 | template< class T > struct HodgeStar2Form { static void build( const Mesh& mesh, SparseMatrix& star2 ); }; 31 | template< class T > struct ExteriorDerivative0Form { static void build( const Mesh& mesh, SparseMatrix& d0 ); }; 32 | template< class T > struct ExteriorDerivative1Form { static void build( const Mesh& mesh, SparseMatrix& d1 ); }; 33 | } 34 | 35 | #include "DiscreteExteriorCalculus.inl" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Hot2/include/Edge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Edge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Edge stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its two associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_EDGE_H 11 | #define DDG_EDGE_H 12 | 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class Edge 18 | { 19 | public: 20 | HalfEdgeIter he; 21 | // points to one of the two halfedges associated with this edge 22 | 23 | int index; 24 | // unique integer ID in the range 0, ..., nEdges-1 25 | 26 | Edge() : index(0) { } 27 | 28 | Vector dualPoint() const; 29 | // intersection between primal and dual edge 30 | }; 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Hot2/include/Face.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Face.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Face stores attributes associated with a mesh edge. The iterator he points 6 | // to one of its associated halfedges. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_FACE_H 11 | #define DDG_FACE_H 12 | 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class Face 18 | { 19 | public: 20 | HalfEdgeIter he; 21 | // points to one of the halfedges associated with this face 22 | 23 | int index; 24 | // unique integer ID in the range 0, ..., nFaces-1 25 | 26 | Face() : index(0) { } 27 | 28 | bool isBoundary( void ) const; 29 | // returns true if this face corresponds to a 30 | // boundary loop; false otherwise 31 | 32 | double area( void ) const; 33 | // returns the triangle area 34 | 35 | Vector normal( void ) const; 36 | // returns the unit normal associated with this face; normal 37 | // orientation is determined by the circulation order of halfedges 38 | 39 | Vector circumcenter( void ) const; 40 | // returns triangle circumcenter 41 | 42 | Vector barycenter( void ) const; 43 | // returns triangle barycenter 44 | 45 | Vector dualPoint( void ) const; 46 | // returns dual vertex from weighted triangulation 47 | }; 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Hot2/include/HalfEdge.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- HalfEdge.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // HalfEdge is used to define mesh connectivity. (See the documentation for a 6 | // more in-depth discussion of the halfedge data structure.) 7 | // 8 | 9 | #ifndef DDG_HALFEDGE_H 10 | #define DDG_HALFEDGE_H 11 | 12 | #include "Vector.h" 13 | #include "Types.h" 14 | 15 | namespace DDG 16 | { 17 | class HalfEdge 18 | { 19 | public: 20 | HalfEdgeIter next; 21 | // points to the next halfedge around the current face 22 | 23 | HalfEdgeIter flip; 24 | // points to the other halfedge associated with this edge 25 | 26 | VertexIter vertex; 27 | // points to the vertex at the "tail" of this halfedge 28 | 29 | EdgeIter edge; 30 | // points to the edge associated with this halfedge 31 | 32 | FaceIter face; 33 | // points to the face containing this halfedge 34 | 35 | bool onBoundary; 36 | // true if this halfedge is contained in a boundary 37 | // loop; false otherwise 38 | 39 | Vector texcoord; 40 | // texture coordinates associated with the triangle corner at the 41 | // "tail" of this halfedge 42 | 43 | double cotan( void ) const; 44 | // returns the cotangent of the angle opposing this edge 45 | 46 | Vector rotatedEdge( void ) const; 47 | // returns oriented edge vector rotated by PI/2 around face normal 48 | // if onBoundary, then return nil 49 | 50 | double height( void ) const; 51 | // returns signed distance from dual vertex to orthogonal projection 52 | 53 | double shift( void ) const; 54 | // returns signed distance from he->vertex to dual vertex projection 55 | }; 56 | } 57 | 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /Hot2/include/Image.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Image.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Image represents a color bitmap image. A simple example might look like 6 | // 7 | // Image im; 8 | // im.read( "input.tga" ); 9 | // // modify image data via im(x,y) = ...; 10 | // im.write( "output.tga" ); 11 | // 12 | 13 | #ifndef DDG_IMAGE_H 14 | #define DDG_IMAGE_H 15 | 16 | #include 17 | #include 18 | 19 | namespace DDG 20 | { 21 | class Image 22 | { 23 | public: 24 | Image( int width = 0, int height = 0 ); 25 | // constructs image with specified width and height 26 | 27 | float& operator()( int x, int y ); 28 | const float& operator()( int x, int y ) const; 29 | // accesses pixel (x,y) 30 | 31 | float sample( float x, float y ) const; 32 | // samples image at (x,y) using bilinear filtering 33 | 34 | int width( void ) const; 35 | int height( void ) const; 36 | // returns image dimensions 37 | 38 | void read( const char* filename ); 39 | // loads an image file in Truevision TGA format 40 | // (must be RGB image with 24 or 32 bits per pixel) 41 | 42 | void write( const char* filename ) const; 43 | // writes an image file in Truevision TGA format 44 | // (RGB image with 24 bits per pixel) 45 | 46 | protected: 47 | void clamp( int& x, int& y ) const; 48 | // clamps coordinates to range [0,w-1] x [0,h-1] 49 | 50 | int w, h; 51 | // width and height 52 | 53 | std::vector pixels; 54 | // interleaved RGBA pixel data in range [0-1] 55 | }; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /Hot2/include/LinearContext.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearContext.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearContext is the global solver context needed to interface with the 6 | // SuiteSparse library. It is essentially a wrapper around cholmod_common. A 7 | // single static instance of LinearContext is declared in LinearContext.cpp and 8 | // is shared by all instances of DenseMatrix, SparseMatrix, and LinearSystem. 9 | // In other words, you shouldn't have to instantiate LinearContext yourself 10 | // unless you're doing something really fancy! 11 | // 12 | 13 | #ifndef DDG_LINEARSOLVERCONTEXT 14 | #define DDG_LINEARSOLVERCONTEXT 15 | 16 | #include 17 | 18 | namespace DDG 19 | { 20 | class LinearContext 21 | { 22 | public: 23 | LinearContext( void ); 24 | // constructor 25 | 26 | ~LinearContext( void ); 27 | // destructor 28 | 29 | operator cholmod_common*( void ); 30 | // allows LinearContext to be treated as a cholmod_common* 31 | 32 | protected: 33 | cholmod_common context; 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Hot2/include/LinearEquation.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- LinearEquation.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // LinearEquation represents an equation with an arbitrary linear polynomial on 6 | // both the left- and right-hand side. It is primarily used while building a 7 | // LinearSystem. For convenience, operator== is overloaded so that the user 8 | // can construct a LinearEquation by writing something that looks much like the 9 | // usual mathematical syntax for a linear equation. For example, 10 | // 11 | // LinearEquation eqn = ( x + 2*y == 3*z ); 12 | // 13 | // builds the linear equation x + 2y = 3z. 14 | // 15 | 16 | #ifndef DDG_LINEAREQUATION_H 17 | #define DDG_LINEAREQUATION_H 18 | 19 | #include "LinearPolynomial.h" 20 | 21 | namespace DDG 22 | { 23 | class LinearEquation 24 | { 25 | public: 26 | LinearPolynomial lhs; 27 | // left-hand side 28 | 29 | LinearPolynomial rhs; 30 | // right-hand side 31 | }; 32 | 33 | LinearEquation operator==( const LinearPolynomial& lhs, const LinearPolynomial& rhs ); 34 | // constructs a linear equation with the specified left- and right-hand side 35 | } 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /Hot2/include/MeshIO.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- MeshIO.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // MeshIO handles input/output operations for Mesh objects. Currently the only 6 | // supported mesh format is Wavefront OBJ -- for a format specification see 7 | // 8 | // http://en.wikipedia.org/wiki/Wavefront_.obj_file 9 | // 10 | // Note that vertex normals and material properties are currently ignored. 11 | // 12 | 13 | #ifndef DDG_MESHIO_H 14 | #define DDG_MESHIO_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace DDG 22 | { 23 | class Mesh; 24 | class Index; 25 | class MeshData; 26 | 27 | class MeshIO 28 | { 29 | public: 30 | static int read( std::istream& in, Mesh& mesh ); 31 | // reads a mesh from a valid, open input stream in 32 | 33 | static void write( std::ostream& out, const Mesh& mesh ); 34 | // writes a mesh to a valid, open output stream out 35 | 36 | protected: 37 | static int readMeshData( std::istream& in, MeshData& data ); 38 | static void readPosition( std::stringstream& ss, MeshData& data ); 39 | static void readTexCoord( std::stringstream& ss, MeshData& data ); 40 | static void readNormal ( std::stringstream& ss, MeshData& data ); 41 | static void readFace ( std::stringstream& ss, MeshData& data ); 42 | static Index parseFaceIndex( const std::string& token ); 43 | static void preallocateMeshElements( const MeshData& data, Mesh& mesh ); 44 | static int buildMesh( const MeshData& data, Mesh& mesh ); 45 | static void checkIsolatedVertices( const Mesh& Mesh ); 46 | static void checkNonManifoldVertices( const Mesh& Mesh ); 47 | }; 48 | } 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /Hot2/include/Real.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_REAL_H 2 | #define DDG_REAL_H 3 | 4 | namespace DDG 5 | { 6 | class Real 7 | { 8 | public: 9 | Real( double x = 0. ); 10 | // constructs real number with value x 11 | 12 | operator double( void ) const; 13 | // type cast to double 14 | 15 | void operator+=( double x ); 16 | // increment 17 | 18 | void operator-=( double x ); 19 | // decrement 20 | 21 | void operator*=( double x ); 22 | // multiply 23 | 24 | void operator/=( double x ); 25 | // divide 26 | 27 | Real conj( void ) const; 28 | // simply returns the value (for compatibility w/ complex numbers) 29 | 30 | Real inv( void ) const; 31 | // returns inverse 32 | 33 | double norm( void ) const; 34 | // returns norm 35 | 36 | double norm2( void ) const; 37 | // returns norm squared 38 | 39 | Real unit( void ) const; 40 | // returns number with unit norm and same sign 41 | 42 | protected: 43 | double value; 44 | // value 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Hot2/include/Shader.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Shader.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Shader encapsulates the functionality of a shader program written in 6 | // the OpenGL Shader Language (GLSL). Basic usage is to read a collection 7 | // of source files to disk and enable the shader before making draw calls. 8 | // For instance, during initialization one might write 9 | // 10 | // Shader shader; 11 | // shader.loadVertex( "vertex.glsl" ); 12 | // shader.loadFragment( "fragment.glsl" ); 13 | // 14 | // and in the main draw routine write 15 | // 16 | // shader.enable(); 17 | // // draw some stuff 18 | // shader.disable(); 19 | // 20 | 21 | #ifndef DDG_SHADER_H 22 | #define DDG_SHADER_H 23 | 24 | #include 25 | #include 26 | 27 | namespace DDG 28 | { 29 | class Shader 30 | { 31 | public: 32 | Shader( void ); 33 | // constructor -- shader is initially invalid 34 | 35 | ~Shader( void ); 36 | // destructor 37 | 38 | void loadVertex( const char* filename ); 39 | // read vertex shader from GLSL source file 40 | 41 | void loadFragment( const char* filename ); 42 | // read fragment shader from GLSL source file 43 | 44 | void loadGeometry( const char* filename ); 45 | // read geometry shader from GLSL source file 46 | 47 | void enable( void ); 48 | // uses this shader for rendering 49 | 50 | void disable( void ) const; 51 | // uses the fixed-function pipeline for rendering 52 | 53 | operator GLuint( void ) const; 54 | // returns the ID of this shader program (for calls to OpenGL) 55 | 56 | protected: 57 | void load( GLenum shaderType, const char* filename, GLuint& shader ); 58 | bool readSource( const char* filename, std::string& source ); 59 | 60 | GLuint vertexShader; 61 | GLuint fragmentShader; 62 | GLuint geometryShader; 63 | GLuint program; 64 | bool linked; 65 | }; 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /Hot2/include/Utility.h: -------------------------------------------------------------------------------- 1 | #ifndef DDG_UTILITY_H 2 | #define DDG_UTILITY_H 3 | 4 | #include 5 | #include "Utility.h" 6 | #include "Complex.h" 7 | 8 | namespace DDG 9 | { 10 | inline double sqr( double x ) 11 | { 12 | return x*x; 13 | } 14 | 15 | inline double unitRand( void ) 16 | { 17 | const double rRandMax = 1. / (double) RAND_MAX; 18 | 19 | return rRandMax * (double) rand(); 20 | } 21 | 22 | inline double seconds( int t0, int t1 ) 23 | { 24 | return (double)(t1-t0) / (double) CLOCKS_PER_SEC; 25 | } 26 | } 27 | 28 | namespace DDGConstants 29 | { 30 | static DDG::Complex ii( 0., 1. ); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Hot2/include/Vertex.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // libDDG -- Vertex.h 3 | // ----------------------------------------------------------------------------- 4 | // 5 | // Vertex stores attributes associated with a mesh edge. The iterator he 6 | // points to its "outgoing" halfedge. (See the documentation for a more 7 | // in-depth discussion of the halfedge data structure.) 8 | // 9 | 10 | #ifndef DDG_VERTEX_H 11 | #define DDG_VERTEX_H 12 | 13 | #include "Vector.h" 14 | #include "Types.h" 15 | 16 | namespace DDG 17 | { 18 | class Vertex 19 | { 20 | public: 21 | HalfEdgeIter he; 22 | // points to the "outgoing" halfedge 23 | 24 | Vector position; 25 | // location of vertex in Euclidean 3-space 26 | 27 | int index; 28 | // unique integer ID in the range 0, ..., nVertices-1 29 | 30 | bool tag; 31 | // true if vertex is selected by the user; false otherwise 32 | 33 | double weight; 34 | // vertex weight to construct orthogonal dual mesh 35 | 36 | Vertex() : index(0), tag(false), weight(0.0) { } 37 | 38 | double area( void ) const; 39 | // returns the barycentric area associated with this vertex 40 | 41 | Vector normal( void ) const; 42 | // returns the vertex normal 43 | 44 | bool isIsolated( void ) const; 45 | // returns true if the vertex is not contained in any face or edge; false otherwise 46 | 47 | int valence( void ) const; 48 | // returns the number of incident faces / edges 49 | 50 | void toggleTag(); 51 | // toggle vertex tag 52 | }; 53 | } 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /Hot2/obj/.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/Hot2/obj/.empty -------------------------------------------------------------------------------- /Hot2/shaders/fragment.glsl: -------------------------------------------------------------------------------- 1 | uniform vec3 eye; 2 | uniform vec3 light; 3 | varying vec3 position; 4 | varying vec3 normal; 5 | 6 | float diffuse( vec3 N, vec3 L ) 7 | { 8 | return max( 0., dot( N, L )); 9 | } 10 | 11 | float specular( vec3 N, vec3 L, vec3 E ) 12 | { 13 | const float shininess = 8.; 14 | vec3 R = 2.*dot(L,N)*N - L; 15 | return pow( max( 0., dot( R, E )), shininess ); 16 | } 17 | 18 | float fresnel( vec3 N, vec3 E ) 19 | { 20 | const float sharpness = 10.; 21 | float NE = max( 0., dot( N, E )); 22 | return pow( sqrt( 1. - NE*NE ), sharpness ); 23 | } 24 | 25 | void main() 26 | { 27 | vec3 N = normalize( normal ); 28 | vec3 L = normalize( light - position ); 29 | vec3 E = normalize( eye - position ); 30 | vec3 R = 2.*dot(L,N)*N - L; 31 | vec3 one = vec3( 1., 1., 1. ); 32 | 33 | gl_FragColor.rgb = diffuse(N,L)*gl_Color.rgb + .5*specular(N,L,E)*one + .5*fresnel(N,E)*one; 34 | gl_FragColor.a = 1.; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Hot2/shaders/vertex.glsl: -------------------------------------------------------------------------------- 1 | varying vec3 position; 2 | varying vec3 normal; 3 | 4 | void main() 5 | { 6 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 7 | gl_FrontColor = gl_Color; 8 | 9 | position = gl_Vertex.xyz; 10 | normal = gl_Normal.xyz; 11 | } 12 | -------------------------------------------------------------------------------- /Hot2/src/Edge.cpp: -------------------------------------------------------------------------------- 1 | #include "Edge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | Vector Edge :: dualPoint() const 7 | { 8 | Vector pj = he->flip->vertex->position; 9 | Vector pi = he->vertex->position; 10 | 11 | Vector eij = (pj - pi).unit(); 12 | double dij = he->shift(); 13 | return pi + dij*eij; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Hot2/src/Face.cpp: -------------------------------------------------------------------------------- 1 | #include "Face.h" 2 | #include "Mesh.h" 3 | #include "Vector.h" 4 | 5 | namespace DDG 6 | { 7 | double Face::area( void ) const 8 | { 9 | Vector p0 = he->vertex->position; 10 | Vector p1 = he->next->vertex->position; 11 | Vector p2 = he->next->next->vertex->position; 12 | return cross( p1-p0, p2-p0 ).norm() / 2.; 13 | } 14 | 15 | Vector Face::normal( void ) const 16 | { 17 | Vector p0 = he->vertex->position; 18 | Vector p1 = he->next->vertex->position; 19 | Vector p2 = he->next->next->vertex->position; 20 | 21 | return cross( p1-p0, p2-p0 ).unit(); 22 | } 23 | 24 | bool Face::isBoundary( void ) const 25 | { 26 | return he->onBoundary; 27 | } 28 | 29 | Vector Face :: circumcenter( void ) const 30 | { 31 | Vector p0 = he->vertex->position; 32 | Vector p1 = he->next->vertex->position; 33 | Vector n = he->rotatedEdge(); 34 | double h = 0.5*he->cotan(); 35 | return 0.5*(p0+p1) + h*n; 36 | } 37 | 38 | Vector Face :: barycenter( void ) const 39 | { 40 | Vector p0 = he->vertex->position; 41 | Vector p1 = he->next->vertex->position; 42 | Vector p2 = he->next->next->vertex->position; 43 | return (p0 + p1 + p2)/3.; 44 | } 45 | 46 | Vector Face :: dualPoint( void ) const 47 | { 48 | Vector n = he->rotatedEdge().unit(); 49 | Vector c = he->edge->dualPoint(); 50 | double h = he->height(); 51 | return c + h*n; 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /Hot2/src/HalfEdge.cpp: -------------------------------------------------------------------------------- 1 | #include "HalfEdge.h" 2 | #include "Mesh.h" 3 | 4 | namespace DDG 5 | { 6 | double HalfEdge :: cotan( void ) const 7 | { 8 | if( onBoundary ) return 0.0; 9 | 10 | Vector p0 = next->next->vertex->position; 11 | Vector p1 = vertex->position; 12 | Vector p2 = next->vertex->position; 13 | 14 | Vector u = p1-p0; 15 | Vector v = p2-p0; 16 | 17 | return dot( u, v ) / cross( u, v ).norm(); 18 | } 19 | 20 | Vector HalfEdge :: rotatedEdge( void ) const 21 | { 22 | if( onBoundary ) return Vector(); 23 | 24 | Vector n = face->normal(); 25 | Vector p0 = vertex->position; 26 | Vector p1 = flip->vertex->position; 27 | return cross( n, p1-p0 ); 28 | } 29 | 30 | double HalfEdge :: height( void ) const 31 | { 32 | if( onBoundary ) return 0.0; 33 | 34 | double cotk = cotan(); 35 | double coti = next->cotan(); 36 | double cotj = next->next->cotan(); 37 | 38 | double wk = next->next->vertex->weight; 39 | double wi = vertex->weight; 40 | double wj = next->vertex->weight; 41 | 42 | Vector pi = vertex->position; 43 | Vector pj = next->vertex->position; 44 | double lij = (pj - pi).norm(); 45 | 46 | return 0.5*(lij*cotk + (wi-wk)*cotj/lij + (wj-wk)*coti/lij); 47 | } 48 | 49 | double HalfEdge :: shift( void ) const 50 | { 51 | double wi = vertex->weight; 52 | double wj = flip->vertex->weight; 53 | 54 | Vector pi = vertex->position; 55 | Vector pj = flip->vertex->position; 56 | double lij = (pj - pi).norm(); 57 | 58 | return 0.5*(lij + (wi-wj)/lij); 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /Hot2/src/LinearContext.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearContext.h" 2 | 3 | namespace DDG 4 | { 5 | // global context for linear solvers 6 | LinearContext context; 7 | 8 | LinearContext :: LinearContext( void ) 9 | // constructor 10 | { 11 | cholmod_l_start( &context ); 12 | } 13 | 14 | LinearContext :: ~LinearContext( void ) 15 | // destructor 16 | { 17 | cholmod_l_finish( &context ); 18 | } 19 | 20 | LinearContext :: operator cholmod_common*( void ) 21 | // allows LinearContext to be treated as a cholmod_common* 22 | { 23 | return &context; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Hot2/src/LinearEquation.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearEquation.h" 2 | 3 | namespace DDG 4 | { 5 | LinearEquation operator==( const LinearPolynomial& lhs, 6 | const LinearPolynomial& rhs ) 7 | // constructs a linear equation with the specified left- and right-hand side 8 | { 9 | LinearEquation eqn; 10 | 11 | eqn.lhs = lhs; 12 | eqn.rhs = rhs; 13 | 14 | return eqn; 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Hot2/src/Real.cpp: -------------------------------------------------------------------------------- 1 | #include "Real.h" 2 | #include 3 | 4 | namespace DDG 5 | { 6 | Real :: Real( double x ) 7 | // constructs real number with value x 8 | : value( x ) 9 | {} 10 | 11 | Real :: operator double( void ) const 12 | // type cast to double 13 | { 14 | return value; 15 | } 16 | 17 | void Real :: operator+=( double x ) 18 | // increment 19 | { 20 | value += x; 21 | } 22 | 23 | void Real :: operator-=( double x ) 24 | // decrement 25 | { 26 | value -= x; 27 | } 28 | 29 | void Real :: operator*=( double x ) 30 | // multiply 31 | { 32 | value *= x; 33 | } 34 | 35 | void Real :: operator/=( double x ) 36 | // divide 37 | { 38 | value /= x; 39 | } 40 | 41 | Real Real :: conj( void ) const 42 | // simply returns the value (for compatibility w/ complex numbers) 43 | { 44 | return value; 45 | } 46 | 47 | Real Real :: inv( void ) const 48 | // returns inverse 49 | { 50 | return 1. / value; 51 | } 52 | 53 | double Real :: norm( void ) const 54 | // returns norm 55 | { 56 | return fabs( value ); 57 | } 58 | 59 | double Real :: norm2( void ) const 60 | // returns norm squared 61 | { 62 | return value * value; 63 | } 64 | 65 | Real Real :: unit( void ) const 66 | // returns number with unit norm and same sign 67 | { 68 | return value / norm(); 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Hot2/src/Variable.cpp: -------------------------------------------------------------------------------- 1 | #include "Variable.h" 2 | 3 | namespace DDG 4 | { 5 | Variable :: Variable( double value_, 6 | bool fixed_ ) 7 | // initialize a variable which has value zero and is not fixed by default 8 | : value( value_ ), 9 | fixed( fixed_ ) 10 | {} 11 | 12 | Variable :: Variable( std::string name_, 13 | double value_, 14 | bool fixed_ ) 15 | // initialize a named variable which has value zero and is not fixed by default 16 | : name( name_ ), 17 | value( value_ ), 18 | fixed( fixed_ ) 19 | {} 20 | 21 | double& Variable :: operator*( void ) 22 | // returns a reference to the numerical value 23 | { 24 | return value; 25 | } 26 | 27 | const double& Variable :: operator*( void ) const 28 | // returns a const reference to the numerical value 29 | { 30 | return value; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Hot2/src/Vertex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Vertex.h" 5 | #include "Mesh.h" 6 | #include "HalfEdge.h" 7 | 8 | namespace DDG 9 | { 10 | double Vertex::area( void ) const 11 | // returns the dual area associated with this vertex 12 | { 13 | double A = 0.; 14 | 15 | HalfEdgeCIter h = he; 16 | do 17 | { 18 | if (not h->onBoundary) A += h->face->area(); 19 | h = h->flip->next; 20 | } 21 | while( h != he ); 22 | 23 | return A / 3.; 24 | } 25 | 26 | Vector Vertex::normal( void ) const 27 | // returns the vertex normal 28 | { 29 | Vector N; 30 | 31 | HalfEdgeCIter h = he; 32 | do 33 | { 34 | if (not h->onBoundary) N += h->face->normal(); 35 | h = h->flip->next; 36 | } 37 | while( h != he ); 38 | 39 | return N.unit(); 40 | } 41 | 42 | vector isolated; // all isolated vertices point to isolated.begin() 43 | 44 | bool Vertex::isIsolated( void ) const 45 | // returns true if the vertex is not contained in any face or edge; false otherwise 46 | { 47 | return he == isolated.begin(); 48 | } 49 | 50 | int Vertex :: valence( void ) const 51 | // returns the number of incident faces 52 | { 53 | int n = 0; 54 | 55 | HalfEdgeCIter h = he; 56 | do 57 | { 58 | n++; 59 | h = h->flip->next; 60 | } 61 | while( h != he ); 62 | 63 | return n; 64 | } 65 | 66 | void Vertex :: toggleTag() 67 | { 68 | tag = !tag; 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Hot2/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Viewer.h" 5 | #include "DenseMatrix.h" 6 | using namespace DDG; 7 | 8 | int main( int argc, char** argv ) 9 | { 10 | if( argc != 2 ) 11 | { 12 | cerr << "usage: " << argv[0] << " in.obj" << endl; 13 | return 1; 14 | } 15 | 16 | Viewer viewer; 17 | viewer.mesh.read( argv[1] ); 18 | viewer.init(); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Slides/apps-siggraph2013.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/Slides/apps-siggraph2013.key -------------------------------------------------------------------------------- /Slides/theory-siggraph2013.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/Slides/theory-siggraph2013.key -------------------------------------------------------------------------------- /libddg_userguide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/libddg_userguide.pdf -------------------------------------------------------------------------------- /notes-siggraph2013.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/notes-siggraph2013.pdf -------------------------------------------------------------------------------- /slides-siggraph2013.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgpdec/course/9f29f075989ef5e01be47559bf949dc1828cec97/slides-siggraph2013.pdf --------------------------------------------------------------------------------