├── source ├── rply │ ├── LICENSE │ ├── manual │ │ ├── rply.png │ │ ├── reference.css │ │ └── manual.html │ ├── lib │ │ ├── vc2008 │ │ │ ├── Debug │ │ │ │ ├── Rply.lib │ │ │ │ ├── vc90.idb │ │ │ │ └── vc90.pdb │ │ │ └── Release │ │ │ │ ├── Rply.lib │ │ │ │ ├── vc90.idb │ │ │ │ └── vc90.pdb │ │ └── vc2010 │ │ │ ├── Debug │ │ │ ├── Rply.lib │ │ │ ├── vc100.idb │ │ │ └── vc100.pdb │ │ │ └── Release │ │ │ ├── Rply.lib │ │ │ └── vc100.pdb │ ├── etc │ │ ├── input.ply │ │ ├── dump.c │ │ ├── sconvert.c │ │ └── convert.c │ ├── project │ │ ├── vc2010 │ │ │ ├── Rply.vcxproj.filters │ │ │ ├── Rply.sln │ │ │ ├── Rply.vcproj │ │ │ └── Rply.vcxproj │ │ └── vc2008 │ │ │ ├── Rply.sln │ │ │ ├── Rply.vcproj.REYNOLDS.lgfischer.user │ │ │ └── Rply.vcproj │ └── rply.h ├── DCEL │ ├── PlyImporter.h │ ├── WavefrontObjImporter.h │ ├── Exception.h │ ├── Face.h │ ├── Vertex.h │ ├── WavefrontObjImporter.cpp │ ├── HalfEdge.h │ ├── PlyImporter.cpp │ ├── EdgeIterator.h │ ├── DCELStream.h │ ├── Vector3.h │ └── Mesh.h └── main.cpp ├── DCEL_Example.sln ├── LICENCE.txt ├── DCEL_Example.vcproj └── sphere.obj /source/rply/LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/LICENSE -------------------------------------------------------------------------------- /source/DCEL/PlyImporter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/DCEL/PlyImporter.h -------------------------------------------------------------------------------- /source/rply/manual/rply.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/manual/rply.png -------------------------------------------------------------------------------- /source/DCEL/WavefrontObjImporter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/DCEL/WavefrontObjImporter.h -------------------------------------------------------------------------------- /source/rply/lib/vc2008/Debug/Rply.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/lib/vc2008/Debug/Rply.lib -------------------------------------------------------------------------------- /source/rply/lib/vc2008/Debug/vc90.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/lib/vc2008/Debug/vc90.idb -------------------------------------------------------------------------------- /source/rply/lib/vc2008/Debug/vc90.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/lib/vc2008/Debug/vc90.pdb -------------------------------------------------------------------------------- /source/rply/lib/vc2008/Release/Rply.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/lib/vc2008/Release/Rply.lib -------------------------------------------------------------------------------- /source/rply/lib/vc2008/Release/vc90.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/lib/vc2008/Release/vc90.idb -------------------------------------------------------------------------------- /source/rply/lib/vc2008/Release/vc90.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/lib/vc2008/Release/vc90.pdb -------------------------------------------------------------------------------- /source/rply/lib/vc2010/Debug/Rply.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/lib/vc2010/Debug/Rply.lib -------------------------------------------------------------------------------- /source/rply/lib/vc2010/Debug/vc100.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/lib/vc2010/Debug/vc100.idb -------------------------------------------------------------------------------- /source/rply/lib/vc2010/Debug/vc100.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/lib/vc2010/Debug/vc100.pdb -------------------------------------------------------------------------------- /source/rply/lib/vc2010/Release/Rply.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/lib/vc2010/Release/Rply.lib -------------------------------------------------------------------------------- /source/rply/lib/vc2010/Release/vc100.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lgfischer/dcel/HEAD/source/rply/lib/vc2010/Release/vc100.pdb -------------------------------------------------------------------------------- /source/rply/etc/input.ply: -------------------------------------------------------------------------------- 1 | ply 2 | format ascii 1.0 3 | comment this is our first comment 4 | element vertex 3 5 | property float x 6 | property float y 7 | property float z 8 | element face 1 9 | property list uchar int vertex_indices 10 | comment this is our last comment 11 | end_header 12 | -1 0 0 13 | 000 1 0 14 | 1 0000 0 15 | 3 1 00000 2 16 | 3 1 0 2 17 | -------------------------------------------------------------------------------- /source/rply/project/vc2010/Rply.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | Source Files 16 | 17 | 18 | 19 | 20 | Header Files 21 | 22 | 23 | -------------------------------------------------------------------------------- /DCEL_Example.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DCEL_Example", "DCEL_Example.vcproj", "{6E4B73C0-2BD7-4E6C-B52E-F5D157D0E98A}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {6E4B73C0-2BD7-4E6C-B52E-F5D157D0E98A}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {6E4B73C0-2BD7-4E6C-B52E-F5D157D0E98A}.Debug|Win32.Build.0 = Debug|Win32 14 | {6E4B73C0-2BD7-4E6C-B52E-F5D157D0E98A}.Release|Win32.ActiveCfg = Release|Win32 15 | {6E4B73C0-2BD7-4E6C-B52E-F5D157D0E98A}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /source/rply/project/vc2008/Rply.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Rply", "Rply.vcproj", "{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Debug|Win32.Build.0 = Debug|Win32 14 | {A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Release|Win32.ActiveCfg = Release|Win32 15 | {A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /source/rply/project/vc2010/Rply.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Rply", "Rply.vcproj", "{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Debug|Win32.Build.0 = Debug|Win32 14 | {A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Release|Win32.ActiveCfg = Release|Win32 15 | {A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /source/rply/manual/reference.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin-left: 1em; 3 | margin-right: 1em; 4 | font-family: "Verdana", sans-serif; 5 | } 6 | 7 | tt { 8 | font-family: "Andale Mono", monospace; 9 | } 10 | 11 | h1, h2, h3, h4 { margin-left: 0em; } 12 | 13 | 14 | h3 { padding-top: 1em; } 15 | 16 | p { margin-left: 1em; } 17 | 18 | p.name { 19 | font-family: "Andale Mono", monospace; 20 | padding-top: 1em; 21 | margin-left: 0em; 22 | } 23 | 24 | a[href] { color: #7f0000; } 25 | 26 | blockquote { margin-left: 3em; } 27 | 28 | pre.example { 29 | background: #cbb; 30 | padding: 1em; 31 | margin-left: 1em; 32 | font-family: "Andale Mono", monospace; 33 | font-size: small; 34 | } 35 | 36 | hr { 37 | margin-left: 0em; 38 | background: #7f0000; 39 | border: 0px; 40 | height: 1px; 41 | } 42 | 43 | ul { list-style-type: disc; } 44 | 45 | table.index { border: 1px #7f0000; } 46 | table.index td { text-align: left; vertical-align: top; } 47 | table.index ul { padding-top: 0em; margin-top: 0em; } 48 | 49 | h1:first-letter, 50 | h2:first-letter, 51 | h2:first-letter, 52 | h3:first-letter { color: #7f0000; } 53 | 54 | div.header, div.footer { margin-left: 0em; } 55 | -------------------------------------------------------------------------------- /LICENCE.txt: -------------------------------------------------------------------------------- 1 | DCEL Library by Leonardo Garcia Fischer - Licence of Use 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /source/rply/etc/dump.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "rply.h" 3 | 4 | static int vertex_cb(p_ply_argument argument) { 5 | long eol; 6 | ply_get_argument_user_data(argument, NULL, &eol); 7 | printf("%g", ply_get_argument_value(argument)); 8 | if (eol) printf("\n"); 9 | else printf(" "); 10 | return 1; 11 | } 12 | 13 | static int face_cb(p_ply_argument argument) { 14 | long length, value_index; 15 | ply_get_argument_property(argument, NULL, &length, &value_index); 16 | switch (value_index) { 17 | case 0: 18 | case 1: 19 | printf("%g ", ply_get_argument_value(argument)); 20 | break; 21 | case 2: 22 | printf("%g\n", ply_get_argument_value(argument)); 23 | break; 24 | default: 25 | break; 26 | } 27 | return 1; 28 | } 29 | 30 | int main(void) { 31 | long nvertices, ntriangles; 32 | p_ply ply = ply_open("input.ply", NULL); 33 | if (!ply) return 1; 34 | if (!ply_read_header(ply)) return 1; 35 | nvertices = ply_set_read_cb(ply, "vertex", "x", vertex_cb, NULL, 0); 36 | ply_set_read_cb(ply, "vertex", "y", vertex_cb, NULL, 0); 37 | ply_set_read_cb(ply, "vertex", "z", vertex_cb, NULL, 1); 38 | ntriangles = ply_set_read_cb(ply, "face", "vertex_indices", face_cb, NULL, 0); 39 | printf("%ld\n%ld\n", nvertices, ntriangles); 40 | if (!ply_read(ply)) return 1; 41 | ply_close(ply); 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /source/DCEL/Exception.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com 4 | // 5 | // Distributed under the licence available in the accompanying file 6 | // LICENCE.txt. Please read it before use this code. 7 | // 8 | /////////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifndef Exception_h 11 | #define Exception_h 12 | 13 | #include 14 | #include 15 | 16 | namespace cpp 17 | { 18 | class Exception: public std::exception 19 | { 20 | public: 21 | Exception(const char* m) 22 | :msg(m) 23 | {}; 24 | 25 | Exception(const std::string& msg) 26 | : msg(msg) 27 | {}; 28 | 29 | Exception(const std::exception& e) 30 | : msg(e.what()) 31 | { 32 | } 33 | 34 | ~Exception() throw() 35 | {} 36 | 37 | Exception& operator=(const std::exception& e) throw() 38 | { 39 | this->msg = e.what(); 40 | return *this; 41 | } 42 | 43 | virtual const char* what() const throw() 44 | { 45 | return msg.c_str(); 46 | } 47 | 48 | virtual const std::string& message() const 49 | { 50 | return this->msg; 51 | } 52 | 53 | private: 54 | std::string msg; 55 | }; 56 | }; 57 | 58 | #endif//Exception_h 59 | -------------------------------------------------------------------------------- /source/DCEL/Face.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com 4 | // 5 | // Distributed under the licence available in the accompanying file 6 | // LICENCE.txt. Please read it before use this code. 7 | // 8 | /////////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifndef DCEL_Face_h 11 | #define DCEL_Face_h 12 | 13 | //#include 14 | 15 | template 16 | class HalfEdgeT; 17 | 18 | template 19 | class FaceT 20 | { 21 | typedef HalfEdgeT HalfEdge; 22 | typedef FaceT Face; 23 | 24 | public: 25 | 26 | FaceT(): 27 | boundary( NULL ) 28 | { 29 | }; 30 | 31 | inline HalfEdge* getBoundary() const 32 | { 33 | return this->boundary; 34 | }; 35 | 36 | inline void setBoundary(HalfEdge* bound) 37 | { 38 | //assert( this ); 39 | this->boundary = bound; 40 | }; 41 | 42 | inline FaceDataT& getData() 43 | { 44 | return data; 45 | }; 46 | 47 | inline const FaceDataT& getData() const 48 | { 49 | return data; 50 | }; 51 | 52 | protected: 53 | private: 54 | HalfEdge* boundary; 55 | FaceDataT data; 56 | }; 57 | 58 | #endif//DCEL_Face_h 59 | -------------------------------------------------------------------------------- /source/DCEL/Vertex.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com 4 | // 5 | // Distributed under the licence available in the accompanying file 6 | // LICENCE.txt. Please read it before use this code. 7 | // 8 | /////////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifndef DCEL_Vertex_h 11 | #define DCEL_Vertex_h 12 | 13 | //#include 14 | 15 | template 16 | class HalfEdgeT; 17 | 18 | template 19 | class VertexT 20 | { 21 | typedef VertexT Vertex; 22 | typedef HalfEdgeT HalfEdge; 23 | 24 | public: 25 | 26 | VertexT(): 27 | data(), 28 | incidentEdge(NULL) 29 | { 30 | }; 31 | 32 | inline HalfEdge* getIncidentEdge() const 33 | { 34 | //assert(this); 35 | return this->incidentEdge; 36 | }; 37 | 38 | inline void setIncidentEdge(HalfEdge* edge) 39 | { 40 | //assert(this); 41 | this->incidentEdge = edge; 42 | }; 43 | 44 | inline VertexDataT& getData() 45 | { 46 | return data; 47 | }; 48 | 49 | inline const VertexDataT& getData() const 50 | { 51 | return data; 52 | }; 53 | 54 | protected: 55 | private: 56 | HalfEdge* incidentEdge; 57 | VertexDataT data; 58 | }; 59 | 60 | #endif//DCEL_Vertex_h 61 | -------------------------------------------------------------------------------- /source/rply/project/vc2008/Rply.vcproj.REYNOLDS.lgfischer.user: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 35 | 36 | 39 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /source/DCEL/WavefrontObjImporter.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com 4 | // 5 | // Distributed under the licence available in the accompanying file 6 | // LICENCE.txt. Please read it before use this code. 7 | // 8 | /////////////////////////////////////////////////////////////////////////////// 9 | 10 | #include "WavefrontObjImporter.h" 11 | #include 12 | #include 13 | 14 | void WavefrontObjLoader::load( const std::string& objFile ) 15 | { 16 | vertices.clear(); 17 | verticeCount=0; 18 | faces.clear(); 19 | faceCount=0; 20 | 21 | std::ifstream stream; 22 | try 23 | { 24 | stream.open( objFile.c_str(), std::ios::in ); 25 | if( stream ) 26 | { 27 | // load the obj 28 | while( stream.good() ) 29 | { 30 | char buffer[512]; 31 | stream.getline(buffer, sizeof(buffer)); 32 | std::stringstream str(buffer); 33 | std::string name; 34 | str >> name; 35 | if( name=="v" ) 36 | { 37 | Vector3f position; 38 | str >> position.x >> position.y >> position.z; 39 | vertices.push_back( position ); 40 | verticeCount++; 41 | } 42 | else if( name=="f" ) 43 | { 44 | unsigned int a, b, c; 45 | str >> a >> b >> c; 46 | faces.push_back(a-1); 47 | faces.push_back(b-1); 48 | faces.push_back(c-1); 49 | faceCount++; 50 | } 51 | } 52 | stream.close(); 53 | } 54 | else 55 | { 56 | throw cpp::Exception("Can't open the file '"+objFile+"'"); 57 | } 58 | } 59 | catch( const std::exception& e ) 60 | { 61 | if( stream.is_open() ) 62 | stream.close(); 63 | std::cerr << e.what(); 64 | throw; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /source/rply/etc/sconvert.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "rply.h" 3 | 4 | static int callback(p_ply_argument argument) 5 | { 6 | void *pdata; 7 | /* just pass the value from the input file to the output file */ 8 | ply_get_argument_user_data(argument, &pdata, NULL); 9 | ply_write((p_ply) pdata, ply_get_argument_value(argument)); 10 | return 1; 11 | } 12 | 13 | static int setup_callbacks(p_ply iply, p_ply oply) 14 | { 15 | p_ply_element element = NULL; 16 | /* iterate over all elements in input file */ 17 | while ((element = ply_get_next_element(iply, element))) { 18 | p_ply_property property = NULL; 19 | long nelems = 0; 20 | const char *element_name; 21 | ply_get_element_info(element, &element_name, &nelems); 22 | /* add this element to output file */ 23 | if (!ply_add_element(oply, element_name, nelems)) return 0; 24 | /* iterate over all properties of current element */ 25 | while ((property = ply_get_next_property(element, property))) { 26 | const char *property_name; 27 | e_ply_type type, length_type, value_type; 28 | ply_get_property_info(property, &property_name, &type, 29 | &length_type, &value_type); 30 | /* setup input callback for this property */ 31 | if (!ply_set_read_cb(iply, element_name, property_name, callback, 32 | oply, 0)) return 0; 33 | /* add this property to output file */ 34 | if (!ply_add_property(oply, property_name, type, length_type, 35 | value_type)) return 0; 36 | } 37 | } 38 | return 1; 39 | } 40 | 41 | int main(int argc, char **argv) 42 | { 43 | const char *value; 44 | p_ply iply, oply; 45 | iply = ply_open("input.ply", NULL); 46 | if (!iply) return 1; 47 | if (!ply_read_header(iply)) return 1; 48 | oply = ply_create("output.ply", PLY_LITTLE_ENDIAN, NULL); 49 | if (!oply) return 1; 50 | if (!setup_callbacks(iply, oply)) return 1; 51 | /* pass comments and obj_infos from input to output */ 52 | value = NULL; 53 | while ((value = ply_get_next_comment(iply, value))) 54 | if (!ply_add_comment(oply, value)) return 1; 55 | value = NULL; 56 | while ((value = ply_get_next_obj_info(iply, value))) 57 | if (!ply_add_obj_info(oply, value)) return 1;; 58 | /* write output header */ 59 | if (!ply_write_header(oply)) return 1; 60 | /* read input file generating callbacks that pass data to output file */ 61 | if (!ply_read(iply)) return 1; 62 | /* close up, we are done */ 63 | if (!ply_close(iply)) return 1; 64 | if (!ply_close(oply)) return 1; 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /source/DCEL/HalfEdge.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com 4 | // 5 | // Distributed under the licence available in the accompanying file 6 | // LICENCE.txt. Please read it before use this code. 7 | // 8 | /////////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifndef DCEL_HalfEdge_h 11 | #define DCEL_HalfEdge_h 12 | 13 | //#include 14 | 15 | template 16 | class VertexT; 17 | 18 | template 19 | class FaceT; 20 | 21 | template 22 | class HalfEdgeT 23 | { 24 | typedef VertexT Vertex; 25 | typedef HalfEdgeT HalfEdge; 26 | typedef FaceT Face; 27 | 28 | public: 29 | 30 | HalfEdgeT( ): 31 | data(), 32 | twin(NULL), 33 | next(NULL), 34 | prev(NULL), 35 | origin(NULL), 36 | face(NULL) 37 | { 38 | }; 39 | 40 | inline HalfEdge* getTwin() const 41 | { 42 | //assert(this); 43 | return this->twin; 44 | }; 45 | 46 | inline void setTwin(HalfEdge* newTwin) 47 | { 48 | //assert(this); 49 | this->twin = newTwin; 50 | newTwin->twin = this; 51 | }; 52 | 53 | inline HalfEdge* getNext() const 54 | { 55 | //assert(this); 56 | return this->next; 57 | }; 58 | 59 | inline void setNext(HalfEdge* newNext) 60 | { 61 | //assert(this); 62 | this->next = newNext; 63 | newNext->prev = this; 64 | }; 65 | 66 | inline HalfEdge* getPrev() const 67 | { 68 | //assert(this); 69 | return this->prev; 70 | }; 71 | 72 | inline void setPrev(HalfEdge* newPrev) 73 | { 74 | //assert(this); 75 | this->prev = newPrev; 76 | newPrev->next = this; 77 | }; 78 | 79 | inline Vertex* getOrigin() const 80 | { 81 | //assert(this); 82 | return this->origin; 83 | }; 84 | 85 | inline void setOrigin(Vertex* newOrigin) 86 | { 87 | //assert(this); 88 | this->origin = newOrigin; 89 | }; 90 | 91 | inline Face* getFace() const 92 | { 93 | //assert(this); 94 | return this->face; 95 | }; 96 | 97 | inline void setFace(Face* newFace) 98 | { 99 | //assert(this); 100 | this->face = newFace; 101 | }; 102 | 103 | inline HalfEdgeDataT& getData() 104 | { 105 | return data; 106 | }; 107 | 108 | inline const HalfEdgeDataT& getData() const 109 | { 110 | return data; 111 | }; 112 | 113 | protected: 114 | private: 115 | HalfEdge* twin; 116 | HalfEdge* next; 117 | HalfEdge* prev; 118 | Vertex* origin; 119 | Face* face; 120 | HalfEdgeDataT data; 121 | }; 122 | 123 | #endif//DCEL_HalfEdge_h 124 | -------------------------------------------------------------------------------- /source/DCEL/PlyImporter.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com 4 | // 5 | // Distributed under the licence available in the accompanying file 6 | // LICENCE.txt. Please read it before use this code. 7 | // 8 | /////////////////////////////////////////////////////////////////////////////// 9 | 10 | #include "PlyImporter.h" 11 | #include "../rply/rply.h" 12 | 13 | /* 14 | This code uses the RPly 1.01 library, from 15 | http://w3.impa.br/~diego/software/rply/. 16 | 17 | The code for this lib can be downloaded from 18 | http://w3.impa.br/~diego/software/rply/rply-1.01.tar.gz. There is a copy of 19 | the RPly 1.01 available with this file. 20 | */ 21 | 22 | int vertex_cb(p_ply_argument argument) 23 | { 24 | PlyLoader* loader; 25 | long coordinate; 26 | 27 | ply_get_argument_user_data(argument, (void**)&loader, &coordinate); 28 | float position = (float)ply_get_argument_value(argument); 29 | switch(coordinate) 30 | { 31 | case 0: 32 | loader->vertices.push_back( Vector3f(position,0,0) ); 33 | break; 34 | case 1: 35 | loader->vertices.back().y = position; 36 | break; 37 | case 2: 38 | loader->vertices.back().z = position; 39 | } 40 | return 1; 41 | } 42 | 43 | int face_cb(p_ply_argument argument) 44 | { 45 | long length, value_index; 46 | ply_get_argument_property(argument, NULL, &length, &value_index); 47 | 48 | if( length!=3 ) //ensures only triangles are read 49 | { 50 | throw cpp::Exception("This file contains other things than triangles (1)!'"); 51 | } 52 | unsigned int val = (unsigned int)ply_get_argument_value(argument); 53 | if( value_index<0 ) 54 | { 55 | if( val!=3 ) //ensures only triangles are read 56 | { 57 | throw cpp::Exception("This file contains other things than triangles (2)!'"); 58 | } 59 | return 1; // just returns, this is not usefull data (its the size of the list that will follow) 60 | } 61 | 62 | PlyLoader* loader; 63 | ply_get_argument_user_data(argument, (void**)&loader, NULL); 64 | loader->faces.push_back( val ); 65 | 66 | return 1; 67 | } 68 | 69 | void error_cb(const char *message) 70 | { 71 | std::cerr << message << std::endl; 72 | } 73 | 74 | void PlyLoader::load( const std::string& plyFilename ) 75 | { 76 | this->vertices.clear(); 77 | this->verticeCount = 0; 78 | this->faces.clear(); 79 | this->faceCount = 0; 80 | 81 | p_ply ply = ply_open(plyFilename.c_str(), error_cb); 82 | if( !ply ) 83 | { 84 | throw cpp::Exception(std::string("Cannot open the file '")+plyFilename+"'"); 85 | } 86 | 87 | if(!ply_read_header(ply) ) 88 | { 89 | throw cpp::Exception(std::string("Error loading the header of the file '")+plyFilename+"'"); 90 | } 91 | 92 | this->verticeCount = ply_set_read_cb(ply, "vertex", "x", vertex_cb, this, 0); 93 | ply_set_read_cb(ply, "vertex", "y", vertex_cb, this, 1); 94 | ply_set_read_cb(ply, "vertex", "z", vertex_cb, this, 2); 95 | 96 | this->faceCount = ply_set_read_cb(ply, "face", "vertex_indices", face_cb, this, 0); 97 | if (!ply_read(ply)) 98 | { 99 | throw cpp::Exception(std::string("Error loading the the whole file '")+plyFilename+"'"); 100 | } 101 | ply_close(ply); 102 | } 103 | -------------------------------------------------------------------------------- /source/DCEL/EdgeIterator.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com 4 | // 5 | // Distributed under the licence available in the accompanying file 6 | // LICENCE.txt. Please read it before use this code. 7 | // 8 | /////////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifndef DCEL_EdgeIterator_h 11 | #define DCEL_EdgeIterator_h 12 | 13 | #include "Vertex.h" 14 | #include "Face.h" 15 | #include "HalfEdge.h" 16 | //#include 17 | 18 | /** 19 | A class that helps the iteration of the edges of a vertice or face. 20 | 21 | In the case of a vertex, it runs over each edge that has the given 22 | edge as origin. 23 | 24 | In the case of a face, it runs over each edge that forms the boundary 25 | of that face. 26 | */ 27 | template 28 | class EdgeIteratorT 29 | { 30 | typedef VertexT Vertex; 31 | typedef HalfEdgeT HalfEdge; 32 | typedef FaceT Face; 33 | 34 | public: 35 | 36 | /** 37 | Creates an EdgeIterator that runs over each edge that starts on the 38 | given vertex. 39 | */ 40 | inline EdgeIteratorT(const Vertex* vertex) 41 | { 42 | reset(vertex); 43 | }; 44 | 45 | /** 46 | Creates an EdgeIterator that runs over each edge that forms the 47 | boundary of the given face. 48 | */ 49 | inline EdgeIteratorT(const Face* face) 50 | { 51 | reset(face); 52 | }; 53 | 54 | /** 55 | Returns the next edge in the sequence. 56 | 57 | Returns NULL if all the sequence of edges has ended. 58 | */ 59 | inline HalfEdge* getNext() 60 | { 61 | HalfEdge* next = nextEdge; 62 | 63 | if( nextEdge ) 64 | { 65 | if( vertexIterator ) // edges starting at a vertex iterator 66 | { 67 | HalfEdge* twin = nextEdge->getTwin(); 68 | //assert(twin); 69 | nextEdge = twin->getNext(); 70 | } 71 | else // edges from face iterator 72 | { 73 | nextEdge = nextEdge->getNext(); 74 | } 75 | } 76 | 77 | if( nextEdge==startEdge ) 78 | { 79 | nextEdge = NULL; 80 | } 81 | 82 | return next; 83 | }; 84 | 85 | /** 86 | Check if there is any edge in the sequence of edges. 87 | */ 88 | inline bool hasNext() const 89 | { 90 | return nextEdge!=NULL; 91 | }; 92 | 93 | /** 94 | Makes the iterator start again, from the first edge 95 | of the sequence. 96 | */ 97 | inline void reset() 98 | { 99 | nextEdge = startEdge; 100 | }; 101 | 102 | inline void reset(const Vertex* vertex) 103 | { 104 | //assert(vertex); 105 | vertexIterator = true; 106 | startEdge = vertex->getIncidentEdge(); 107 | reset(); 108 | }; 109 | 110 | inline void reset(const Face* face) 111 | { 112 | //assert(face); 113 | vertexIterator = false; 114 | startEdge = face->getBoundary(); 115 | reset(); 116 | }; 117 | 118 | protected: 119 | private: 120 | HalfEdge* startEdge; 121 | HalfEdge* nextEdge; 122 | bool vertexIterator; 123 | }; 124 | 125 | #endif//DCEL_EdgeIterator_h 126 | -------------------------------------------------------------------------------- /source/rply/project/vc2010/Rply.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 26 | 29 | 32 | 35 | 38 | 41 | 53 | 56 | 59 | 62 | 65 | 68 | 71 | 74 | 77 | 80 | 81 | 89 | 92 | 95 | 98 | 101 | 104 | 116 | 119 | 122 | 125 | 128 | 131 | 134 | 137 | 140 | 143 | 144 | 145 | 146 | 147 | 148 | 153 | 156 | 157 | 158 | 163 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /source/rply/project/vc2008/Rply.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 26 | 29 | 32 | 35 | 38 | 41 | 53 | 56 | 59 | 62 | 65 | 68 | 71 | 74 | 77 | 80 | 81 | 89 | 92 | 95 | 98 | 101 | 104 | 116 | 119 | 122 | 125 | 128 | 131 | 134 | 137 | 140 | 143 | 144 | 145 | 146 | 147 | 148 | 153 | 156 | 157 | 158 | 163 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /source/rply/project/vc2010/Rply.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | {A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E} 21 | Rply 22 | Win32Proj 23 | 24 | 25 | 26 | StaticLibrary 27 | Unicode 28 | true 29 | 30 | 31 | StaticLibrary 32 | Unicode 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | <_ProjectFileVersion>10.0.30319.1 46 | $(SolutionDir)..\..\lib\vc2010\$(Configuration)\ 47 | $(Configuration)\ 48 | $(SolutionDir)..\..\lib\vc2010\$(Configuration)\ 49 | $(Configuration)\ 50 | 51 | 52 | 53 | Disabled 54 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 55 | true 56 | EnableFastChecks 57 | MultiThreadedDebugDLL 58 | 59 | 60 | $(OutDir)vc100.pdb 61 | Level3 62 | EditAndContinue 63 | 64 | 65 | 66 | 67 | MaxSpeed 68 | true 69 | WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 70 | MultiThreadedDLL 71 | true 72 | 73 | 74 | $(OutDir)vc100.pdb 75 | Level3 76 | ProgramDatabase 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /source/rply/etc/convert.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "rply.h" 6 | 7 | /* internal function prototypes */ 8 | static void error(const char *fmt, ...); 9 | static void help(void); 10 | static void parse_arguments(int argc, char **argv, 11 | e_ply_storage_mode *storage_mode, 12 | const char **iname, const char **oname); 13 | static void setup_callbacks(p_ply iply, p_ply oply); 14 | 15 | /* given a format mode, an input file name and an output file name, 16 | * convert input file to output in given format mode */ 17 | int main(int argc, char **argv) 18 | { 19 | const char *value = NULL; 20 | e_ply_storage_mode storage_mode = PLY_LITTLE_ENDIAN; 21 | const char *iname = NULL, *oname = NULL; 22 | p_ply iply = NULL, oply = NULL; 23 | /* parse command line arguments */ 24 | parse_arguments(argc, argv, &storage_mode, &iname, &oname); 25 | /* open input file and make sure we parsed its header */ 26 | iply = ply_open(iname, NULL); 27 | if (!iply) error("Unable to open file '%s'", iname); 28 | if (!ply_read_header(iply)) error("Failed reading '%s' header", iname); 29 | /* create output file */ 30 | oply = ply_create(oname, storage_mode, NULL); 31 | if (!oply) error("Unable to create file '%s'", oname); 32 | /* create elements and properties in output file and 33 | * setup callbacks for them in input file */ 34 | setup_callbacks(iply, oply); 35 | /* pass comments and obj_infos from input to output */ 36 | value = NULL; 37 | while ((value = ply_get_next_comment(iply, value))) 38 | if (!ply_add_comment(oply, value)) 39 | error("Failed adding comments"); 40 | value = NULL; 41 | while ((value = ply_get_next_obj_info(iply, value))) 42 | if (!ply_add_obj_info(oply, value)) 43 | error("Failed adding comments"); 44 | /* write output header */ 45 | if (!ply_write_header(oply)) error("Failed writing '%s' header", oname); 46 | /* read input file generating callbacks that pass data to output file */ 47 | if (!ply_read(iply)) error("Conversion failed"); 48 | /* close up, we are done */ 49 | if (!ply_close(iply)) error("Error closing file '%s'", iname); 50 | if (!ply_close(oply)) error("Error closing file '%s'", oname); 51 | return 0; 52 | } 53 | 54 | /* prints an error message and exits */ 55 | static void error(const char *fmt, ...) 56 | { 57 | va_list ap; 58 | va_start(ap, fmt); 59 | vfprintf(stderr, fmt, ap); 60 | va_end(ap); 61 | fprintf(stderr, "\n"); 62 | exit(1); 63 | } 64 | 65 | /* prints the help message and exits */ 66 | static void help(void) 67 | { 68 | error("Usage:\n" 69 | " convert