The first commit

This commit is contained in:
lgfischer committed 2012-11-10 10:27:37 -02:00
commit 907922fdee
45 files changed
+7594

No files matched your search

+272
View File
@@ -0,0 +1,272 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com
//
// Distributed under the licence available in the accompanying file
// LICENCE.txt. Please read it before use this code.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef DCELStream_h
#define DCELStream_h
#include <iostream>
#include "Mesh.h"
template <class MeshT>
class DCELStream
{
public:
static void read(MeshT& mesh, std::istream &stream);
/**
Format:
version 1
#this is a comment
vc <number of vertices in the mesh>
fc <number of faces in the mesh>
ec <number of edges in the mesh>
v <custom user data>
... # repeat v for vc times, one for each vertex
f <number of vertices that define this face> <list of id of each vertex> <custom user data>
... # repeat f for fc times, one for each face
e <id of the source vertex of the edge> <id of the source of the twin edge> <custom user data>
... # repeat e for ec times, one for each half edge
end
*/
static void write(const MeshT& mesh, std::ostream &stream);
template<class MeshT, class MeshT2>
static void copyDcelData(const MeshT& source, MeshT2& target )
{
const MeshT::Vertex* vertex = NULL;
const unsigned int numVertices = source.getNumVertices();
const MeshT::Face* face = NULL;
const unsigned int numFaces = source.getNumFaces();
const MeshT::HalfEdge* edge = NULL;
const unsigned int numEdges = source.getNumHalfEdges();
target.clear();
target.getVertices().reserve( numVertices );
target.getFaces().reserve( numFaces );
target.getHalfEdges().reserve( numEdges );
for( unsigned int vertexId=0; vertexId<numVertices; ++vertexId )
{
target.createVertex();
// convert here the data from the source to target vertex
}
for( unsigned int faceId=0; faceId<numFaces; ++faceId )
{
face = source.getFace( faceId );
unsigned int vid[3];//generalizar
unsigned int vertexCount=0;
MeshT::EdgeIterator it(face);
while( it.hasNext() )
{
vid[vertexCount] = source.getVertexId( it.getNext()->getOrigin() );
++vertexCount;
}
target.createTriangularFace( vid[0], vid[1], vid[2] );
// convert here the data from the source to target faces
}
/*
for( unsigned int edgeId=0; edgeId<numEdges; ++edgeId )
{
// convert here the data from the source to target half-edges
}
*/
};
protected:
private:
static void read_v1(MeshT& mesh, std::istream &stream);
static void consumeComment(const std::string& commentBegin, std::istream &stream);
};
//////////////////////////////////////////////////////////////////////////
// IMPLEMENTATION //
//////////////////////////////////////////////////////////////////////////
template <class MeshT>
void DCELStream<MeshT>::read(MeshT& mesh, std::istream &stream)
{
while( stream.good() )
{
std::string str;
stream >> str;
if( str=="version" )
{
unsigned int version;
stream >> version;
switch(version)
{
case 1:
read_v1(mesh, stream);
break;
default:
std::cerr << "Warning: unknown version " << version << std::endl;
}
}
else if( str.at(0)=='#' )
{
consumeComment(str, stream);
}
else
{
std::cerr << "Unknown line: " << str << std::endl;
}
}
}
template <class MeshT>
void DCELStream<MeshT>::write(const MeshT& mesh, std::ostream &stream)
{
const MeshT::Vertex* vertex = NULL;
const unsigned int numVertices = mesh.getNumVertices();
const MeshT::Face* face = NULL;
const unsigned int numFaces = mesh.getNumFaces();
const MeshT::HalfEdge* edge = NULL;
const unsigned int numEdges = mesh.getNumHalfEdges();
stream << "version 1" << std::endl;
stream << "vc " << numVertices << std::endl;
stream << "fc " << numFaces << std::endl;
stream << "ec " << numEdges << std::endl;
for( unsigned int vertexId=0; vertexId<numVertices; ++vertexId )
{
vertex = mesh.getVertex( vertexId );
stream << "v " << vertex->getData() << std::endl;
}
for( unsigned int faceId=0; faceId<numFaces; ++faceId )
{
face = mesh.getFace( faceId );
stream << "f ";
unsigned int vid[3];//generalizar
unsigned int vertexCount=0;
MeshT::EdgeIterator it(face);
while( it.hasNext() )
{
vid[vertexCount] = mesh.getVertexId( it.getNext()->getOrigin() );
++vertexCount;
}
stream << vertexCount;
for( unsigned int v=0; v<vertexCount; ++v )
{
stream << " " << vid[v];
}
stream << " " << face->getData();
stream << std::endl;
}
for( unsigned int edgeId=0; edgeId<numEdges; ++edgeId )
{
const MeshT::HalfEdge* edge = mesh.getHalfEdge( edgeId );
stream << "e " << mesh.getVertexId( edge->getOrigin() )
<< " " << mesh.getVertexId( edge->getTwin()->getOrigin() )
<< " " << edge->getData() << std::endl;
}
stream << "end";
}
template <class MeshT>
void DCELStream<MeshT>::read_v1(MeshT& mesh, std::istream &stream)
{
std::string str;
bool reading = true;
while( reading && stream.good() )
{
stream >> str;
if( str=="v" )
{
MeshT::Vertex* vertex = mesh.getVertex( mesh.createVertex() );
stream >> (vertex->getData());
}
else if( str=="f" )
{
unsigned int vertexCount;
stream >> vertexCount;
unsigned int vid[3];//TODO generalize
for( unsigned int i=0; i<vertexCount; ++i )
stream >> (vid[i]);
unsigned int fid = mesh.createTriangularFace( vid[0], vid[1], vid[2] );
MeshT::Face* face = mesh.getFace( fid );
stream >> face->getData();
}
else if( str=="e" )
{
unsigned int from, to;
stream >> from >> to;
MeshT::HalfEdge* edge = mesh.getHalfEdge( mesh.getVertex(from), mesh.getVertex(to) );
if( edge )
{
stream >> edge->getData();
}
else
{
std::cerr << '?';
}
}
else if( str=="vc" )
{
unsigned int vc = -1;
stream >> vc;
mesh.getVertices().reserve( vc*5 );
}
else if( str=="fc" )
{
unsigned int fc = -1;
stream >> fc;
mesh.getFaces().reserve( fc*5 );
}
else if( str=="ec" )
{
unsigned int ec = -1;
stream >> ec;
mesh.getHalfEdges().reserve( ec*5 );
}
else if( str=="end" )
{
reading = false;
}
else if( str.at(0)=='#' )
{
consumeComment(str, stream);
}
else
{
std::cerr << "Unknown line: " << str;
}
}
mesh.manageUnhandledTriangles();
}
template <class MeshT>
void DCELStream<MeshT>::consumeComment(const std::string& commentBegin, std::istream &stream)
{
char buffer[512];
stream.getline( buffer, sizeof(buffer) );
std::cerr << commentBegin << " " << buffer << std::endl;
}
#endif//DCELStream_h
+125
View File
@@ -0,0 +1,125 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com
//
// Distributed under the licence available in the accompanying file
// LICENCE.txt. Please read it before use this code.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef DCEL_EdgeIterator_h
#define DCEL_EdgeIterator_h
#include "Vertex.h"
#include "Face.h"
#include "HalfEdge.h"
//#include <cassert>
/**
A class that helps the iteration of the edges of a vertice or face.
In the case of a vertex, it runs over each edge that has the given
edge as origin.
In the case of a face, it runs over each edge that forms the boundary
of that face.
*/
template<class VertexDataT, class HalfEdgeDataT, class FaceDataT>
class EdgeIteratorT
{
typedef VertexT<VertexDataT, HalfEdgeDataT, FaceDataT> Vertex;
typedef HalfEdgeT<VertexDataT, HalfEdgeDataT, FaceDataT> HalfEdge;
typedef FaceT<VertexDataT, HalfEdgeDataT, FaceDataT> Face;
public:
/**
Creates an EdgeIterator that runs over each edge that starts on the
given vertex.
*/
inline EdgeIteratorT(const Vertex* vertex)
{
reset(vertex);
};
/**
Creates an EdgeIterator that runs over each edge that forms the
boundary of the given face.
*/
inline EdgeIteratorT(const Face* face)
{
reset(face);
};
/**
Returns the next edge in the sequence.
Returns NULL if all the sequence of edges has ended.
*/
inline HalfEdge* getNext()
{
HalfEdge* next = nextEdge;
if( nextEdge )
{
if( vertexIterator ) // edges starting at a vertex iterator
{
HalfEdge* twin = nextEdge->getTwin();
//assert(twin);
nextEdge = twin->getNext();
}
else // edges from face iterator
{
nextEdge = nextEdge->getNext();
}
}
if( nextEdge==startEdge )
{
nextEdge = NULL;
}
return next;
};
/**
Check if there is any edge in the sequence of edges.
*/
inline bool hasNext() const
{
return nextEdge!=NULL;
};
/**
Makes the iterator start again, from the first edge
of the sequence.
*/
inline void reset()
{
nextEdge = startEdge;
};
inline void reset(const Vertex* vertex)
{
//assert(vertex);
vertexIterator = true;
startEdge = vertex->getIncidentEdge();
reset();
};
inline void reset(const Face* face)
{
//assert(face);
vertexIterator = false;
startEdge = face->getBoundary();
reset();
};
protected:
private:
HalfEdge* startEdge;
HalfEdge* nextEdge;
bool vertexIterator;
};
#endif//DCEL_EdgeIterator_h
+58
View File
@@ -0,0 +1,58 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com
//
// Distributed under the licence available in the accompanying file
// LICENCE.txt. Please read it before use this code.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef Exception_h
#define Exception_h
#include <exception>
#include <string>
namespace cpp
{
class Exception: public std::exception
{
public:
Exception(const char* m)
:msg(m)
{};
Exception(const std::string& msg)
: msg(msg)
{};
Exception(const std::exception& e)
: msg(e.what())
{
}
~Exception() throw()
{}
Exception& operator=(const std::exception& e) throw()
{
this->msg = e.what();
return *this;
}
virtual const char* what() const throw()
{
return msg.c_str();
}
virtual const std::string& message() const
{
return this->msg;
}
private:
std::string msg;
};
};
#endif//Exception_h
+58
View File
@@ -0,0 +1,58 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com
//
// Distributed under the licence available in the accompanying file
// LICENCE.txt. Please read it before use this code.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef DCEL_Face_h
#define DCEL_Face_h
//#include <cassert>
template<class VertexDataT, class HalfEdgeDataT, class FaceDataT>
class HalfEdgeT;
template<class VertexDataT, class HalfEdgeDataT, class FaceDataT>
class FaceT
{
typedef HalfEdgeT<VertexDataT, HalfEdgeDataT, FaceDataT> HalfEdge;
typedef FaceT<VertexDataT, HalfEdgeDataT, FaceDataT> Face;
public:
FaceT():
boundary( NULL )
{
};
inline HalfEdge* getBoundary() const
{
return this->boundary;
};
inline void setBoundary(HalfEdge* bound)
{
//assert( this );
this->boundary = bound;
};
inline FaceDataT& getData()
{
return data;
};
inline const FaceDataT& getData() const
{
return data;
};
protected:
private:
HalfEdge* boundary;
FaceDataT data;
};
#endif//DCEL_Face_h
+123
View File
@@ -0,0 +1,123 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com
//
// Distributed under the licence available in the accompanying file
// LICENCE.txt. Please read it before use this code.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef DCEL_HalfEdge_h
#define DCEL_HalfEdge_h
//#include <cassert>
template<class VertexDataT, class HalfEdgeDataT, class FaceDataT>
class VertexT;
template<class VertexDataT, class HalfEdgeDataT, class FaceDataT>
class FaceT;
template<class VertexDataT, class HalfEdgeDataT, class FaceDataT>
class HalfEdgeT
{
typedef VertexT<VertexDataT, HalfEdgeDataT, FaceDataT> Vertex;
typedef HalfEdgeT<VertexDataT, HalfEdgeDataT, FaceDataT> HalfEdge;
typedef FaceT<VertexDataT, HalfEdgeDataT, FaceDataT> Face;
public:
HalfEdgeT( ):
data(),
twin(NULL),
next(NULL),
prev(NULL),
origin(NULL),
face(NULL)
{
};
inline HalfEdge* getTwin() const
{
//assert(this);
return this->twin;
};
inline void setTwin(HalfEdge* newTwin)
{
//assert(this);
this->twin = newTwin;
newTwin->twin = this;
};
inline HalfEdge* getNext() const
{
//assert(this);
return this->next;
};
inline void setNext(HalfEdge* newNext)
{
//assert(this);
this->next = newNext;
newNext->prev = this;
};
inline HalfEdge* getPrev() const
{
//assert(this);
return this->prev;
};
inline void setPrev(HalfEdge* newPrev)
{
//assert(this);
this->prev = newPrev;
newPrev->next = this;
};
inline Vertex* getOrigin() const
{
//assert(this);
return this->origin;
};
inline void setOrigin(Vertex* newOrigin)
{
//assert(this);
this->origin = newOrigin;
};
inline Face* getFace() const
{
//assert(this);
return this->face;
};
inline void setFace(Face* newFace)
{
//assert(this);
this->face = newFace;
};
inline HalfEdgeDataT& getData()
{
return data;
};
inline const HalfEdgeDataT& getData() const
{
return data;
};
protected:
private:
HalfEdge* twin;
HalfEdge* next;
HalfEdge* prev;
Vertex* origin;
Face* face;
HalfEdgeDataT data;
};
#endif//DCEL_HalfEdge_h
+1035
View File
File diff suppressed because it is too large. Load diff
+102
View File
@@ -0,0 +1,102 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com
//
// Distributed under the licence available in the accompanying file
// LICENCE.txt. Please read it before use this code.
//
///////////////////////////////////////////////////////////////////////////////
#include "PlyImporter.h"
#include "../rply/rply.h"
/*
This code uses the RPly 1.01 library, from
http://w3.impa.br/~diego/software/rply/.
The code for this lib can be downloaded from
http://w3.impa.br/~diego/software/rply/rply-1.01.tar.gz. There is a copy of
the RPly 1.01 available with this file.
*/
int vertex_cb(p_ply_argument argument)
{
PlyLoader* loader;
long coordinate;
ply_get_argument_user_data(argument, (void**)&loader, &coordinate);
float position = (float)ply_get_argument_value(argument);
switch(coordinate)
{
case 0:
loader->vertices.push_back( Vector3f(position,0,0) );
break;
case 1:
loader->vertices.back().y = position;
break;
case 2:
loader->vertices.back().z = position;
}
return 1;
}
int face_cb(p_ply_argument argument)
{
long length, value_index;
ply_get_argument_property(argument, NULL, &length, &value_index);
if( length!=3 ) //ensures only triangles are read
{
throw cpp::Exception("This file contains other things than triangles (1)!'");
}
unsigned int val = (unsigned int)ply_get_argument_value(argument);
if( value_index<0 )
{
if( val!=3 ) //ensures only triangles are read
{
throw cpp::Exception("This file contains other things than triangles (2)!'");
}
return 1; // just returns, this is not usefull data (its the size of the list that will follow)
}
PlyLoader* loader;
ply_get_argument_user_data(argument, (void**)&loader, NULL);
loader->faces.push_back( val );
return 1;
}
void error_cb(const char *message)
{
std::cerr << message << std::endl;
}
void PlyLoader::load( const std::string& plyFilename )
{
this->vertices.clear();
this->verticeCount = 0;
this->faces.clear();
this->faceCount = 0;
p_ply ply = ply_open(plyFilename.c_str(), error_cb);
if( !ply )
{
throw cpp::Exception(std::string("Cannot open the file '")+plyFilename+"'");
}
if(!ply_read_header(ply) )
{
throw cpp::Exception(std::string("Error loading the header of the file '")+plyFilename+"'");
}
this->verticeCount = ply_set_read_cb(ply, "vertex", "x", vertex_cb, this, 0);
ply_set_read_cb(ply, "vertex", "y", vertex_cb, this, 1);
ply_set_read_cb(ply, "vertex", "z", vertex_cb, this, 2);
this->faceCount = ply_set_read_cb(ply, "face", "vertex_indices", face_cb, this, 0);
if (!ply_read(ply))
{
throw cpp::Exception(std::string("Error loading the the whole file '")+plyFilename+"'");
}
ply_close(ply);
}
+105
View File
@@ -0,0 +1,105 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com
//
// Distributed under the licence available in the accompanying file
// LICENCE.txt. Please read it before use this code.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef PlyImporter_h
#define PlyImporter_h
#include "DCELStream.h"
#include "Vector3.h"
/**
This class is used internally by the PlyImporter, and should not be used externally.
It loads a set of vertices into the "vertices" list and the set of faces into the
"faces" list. Each 3 values into the "faces" lists stores one triangular face,
composed by the vertices referenced by the 3 unsigned int values.
*/
class PlyLoader
{
public:
void load(const std::string& plyFilename);
std::list<Vector3f> vertices;
unsigned int verticeCount;
std::list<unsigned int> faces;
unsigned int faceCount;
};
/**
Class that imports a PLY file into a DCEL mesh.
It assumes that the mesh is totally triangulated.
*/
template <class MeshT>
class PlyImporter
{
public:
/**
Loads from the given filename.
It just calls the 'import' method with the opened stream.
*/
void import( const std::string& plyFilename, MeshT& mesh );
private:
};
template <class MeshT>
void PlyImporter<MeshT>::import( const std::string& plyFilename, MeshT& mesh )
{
std::cerr << "Starting importing the file '" << plyFilename << "'" << std::endl;
std::cerr << "- loading the PLY file" << std::endl;
//loads the ply file
PlyLoader loader;
loader.load( plyFilename );
// put it into the mesh
std::cerr << "- loading the DCEL mesh: " << std::endl;
std::cerr << " + " << loader.verticeCount << " vertices" << std::endl;
mesh.clear();
mesh.getVertices().reserve(loader.verticeCount);
mesh.getFaces().reserve(loader.faceCount);
mesh.getHalfEdges().reserve( 2*(loader.verticeCount+loader.faceCount-2) ); // Euler: V – A + F = 2 --> A = V + F - 2
std::list<Vector3f>::iterator vit = loader.vertices.begin();
while( vit!=loader.vertices.end() )
{
unsigned int id = mesh.createVertex();
mesh.getVertex(id)->getData().position = *vit;
vit++;
}
std::cerr << " + " << loader.faceCount << " faces" << std::endl;
std::list<unsigned int>::iterator fit = loader.faces.begin();
unsigned int count=0;
while( fit!=loader.faces.end() )
{
count++;
unsigned int a = *fit; ++fit;
unsigned int b = *fit; ++fit;
unsigned int c = *fit; ++fit;
unsigned int fid = mesh.createTriangularFace( a, b, c );
if (fid!=-1)
{
mesh.checkFace(fid);
mesh.checkAllFaces();
}
}
std::cerr << " + " << mesh.getNumUnhandledTriangles() << " bad triangles" << std::endl;
mesh.manageUnhandledTriangles();
mesh.checkAllFaces();
std::cerr << "Done!" << std::endl;
}
#endif//PlyImporter_h
+313
View File
@@ -0,0 +1,313 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com
//
// Distributed under the licence available in the accompanying file
// LICENCE.txt. Please read it before use this code.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef VECTOR_3_H
#define VECTOR_3_H
#include <cmath>
template <class T>
class Vector3
{
public:
Vector3()
{}
Vector3(T x, T y, T z)
:x(x)
,y(y)
,z(z)
{}
Vector3(const Vector3<T>& v)
:x(v.x)
,y(v.y)
,z(v.z)
{}
Vector3(const Vector3<T>* v)
:x(v->x)
,y(v->y)
,z(v->z)
{}
inline void set(T x, T y, T z)
{
this->x = x;
this->y = y;
this->z = z;
}
inline void set(const Vector3<T>& other)
{
this->x = other.x;
this->y = other.y;
this->z = other.z;
}
inline Vector3<T> operator=(const Vector3<T>& other)
{
this->x = other.x;
this->y = other.y;
this->z = other.z;
return *this;
}
/**
Explicitly, but easily, converts this Vector instance to one of the given type.
Vector3<float> u(0,0,0);
Vector3<double> v = u.cast<double>();
*/
template <class U>
Vector3<U> cast() const
{
return Vector3<U>( (U)x, (U)y, (U)z );
}
inline bool operator==(const Vector3<T>& other) const
{
return this->x == other.x && this->y == other.y && this->z==other.z;
}
inline bool operator!=(const Vector3<T>& other) const
{
return this->x!=other.x || this->y!=other.y || this->z!=other.z;
}
inline Vector3<T> operator+(const Vector3<T>& other) const
{
return Vector3<T>(this->x + other.x, this->y + other.y, this->z + other.z);
}
inline void operator+=(const Vector3<T>& other)
{
this->x+=other.x;
this->y+=other.y;
this->z+=other.z;
}
inline Vector3<T> operator-() const
{
return Vector3<T>(-this->x, -this->y, -this->z);
}
inline Vector3<T> operator-(const Vector3<T>& other) const
{
return Vector3<T>(this->x - other.x, this->y - other.y, this->z - other.z);
}
inline void operator-=(const Vector3<T>& other)
{
this->x-=other.x;
this->y-=other.y;
this->z-=other.z;
}
inline Vector3<T> operator*(T s) const
{
return Vector3<T>(this->x*s, this->y*s, this->z*s);
}
inline void operator*=(T s)
{
this->x*=s;
this->y*=s;
this->z*=s;
}
inline Vector3<T> operator/(T s) const
{
return Vector3<T>(this->x/s, this->y/s, this->z/s);
}
inline void operator/=(T s)
{
this->x/=s;
this->y/=s;
this->z/=s;
}
inline Vector3<T> cross( const Vector3<T>& other ) const
{
return Vector3<T>(
this->y*other.z - this->z*other.y,
this->z*other.x - this->x*other.z,
this->x*other.y - this->y*other.x );
}
inline T dot( const Vector3<T>& other ) const
{
return this->x*other.x + this->y*other.y + this->z*other.z;
}
inline T length() const
{
return( sqrt( this->x*this->x + this->y*this->y + this->z*this->z ) );
}
/**
Returns the square of the length of the vector.
Use this if you just want to compare legths of vectors, as this is faster to
compute than lenght()
*/
inline T length2() const
{
return this->x*this->x + this->y*this->y + this->z*this->z;
}
/**
Resizes the vector.
*/
inline void setLength(const T newLenght)
{
const T scale = ( newLenght / this->length() );
this->x *= scale;
this->y *= scale;
this->z *= scale;
}
inline T distance(const Vector3<T>& other) const
{
const T xDelta = this->x-other.x;
const T yDelta = this->y-other.y;
const T zDelta = this->z-other.z;
return sqrt( xDelta*xDelta + yDelta*yDelta + zDelta*zDelta);
}
/**
Returns the square of the distance to the other vector
Use this if you just want to compare distances, as the square of
the distance is faster to compute than the distance itself.
*/
inline T distance2(const Vector3<T>& other) const
{
const T xDelta = this->x-other.x;
const T yDelta = this->y-other.y;
const T zDelta = this->z-other.z;
return xDelta*xDelta + yDelta*yDelta + zDelta*zDelta;
}
inline void normalize()
{
const T len = this->length();
this->x /= len;
this->y /= len;
this->z /= len;
}
/**
Returns a normalized copy of the vector.
Use if you need a normalized version of the vector AND
the vector itself.
*/
inline Vector3<T> normalizedCopy()
{
Vector3<T> v = this;
const T len = v.length(); //inline normalize
v.x /= len;
v.y /= len;
v.z /= len;
return v;
}
inline void rotateAroundY(T radians)
{
const double cs = cos(radians);
const double sn = sin(radians);
set((T)(x*cs - z*sn), y, (T)(x*sn + z*cs));
}
/**
This method will rotate the point represented by this vector
arround a given axis.
This is the most general form for the methods rotateAroundX,
Y and Z, but is more expensive.
\note the axis MUST be normalized
\note that the axis passes through the point (0,0,0).
Math from http://local.wasp.uwa.edu.au/~pbourke/geometry/rotate/
*/
inline void rotateAround(const Vector3<T>& axis, T radians)
{
T costheta = cos(radians);
T sintheta = sin(radians);
Vector3<T> q;
q.x = (costheta + (1 - costheta) * axis.x * axis.x) * this->x;
q.x += ((1 - costheta) * axis.x * axis.y - axis.z * sintheta) * this->y;
q.x += ((1 - costheta) * axis.x * axis.z + axis.y * sintheta) * this->z;
q.y = ((1 - costheta) * axis.x * axis.y + axis.z * sintheta) * this->x;
q.y += (costheta + (1 - costheta) * axis.y * axis.y) * this->y;
q.y += ((1 - costheta) * axis.y * axis.z - axis.x * sintheta) * this->z;
q.z = ((1 - costheta) * axis.x * axis.z - axis.y * sintheta) * this->x;
q.z += ((1 - costheta) * axis.y * axis.z + axis.x * sintheta) * this->y;
q.z += (costheta + (1 - costheta) * axis.z * axis.z) * this->z;
this->set(q);
}
inline void rotateAround(const Vector3<T>& p1, const Vector3<T>& p2, T radians)
{
Vector3<T> r;
r.x = p2.x - p1.x;
r.y = p2.y - p1.y;
r.z = p2.z - p1.z;
this->x -= p1.x;
this->y -= p1.y;
this->z -= p1.z;
r.normalize();
T costheta, sintheta;
costheta = cos(radians);
sintheta = sin(radians);
Vector3<T> q;
q.x = (costheta + (1 - costheta) * r.x * r.x) * this->x;
q.x += ((1 - costheta) * r.x * r.y - r.z * sintheta) * this->y;
q.x += ((1 - costheta) * r.x * r.z + r.y * sintheta) * this->z;
q.y = ((1 - costheta) * r.x * r.y + r.z * sintheta) * this->x;
q.y += (costheta + (1 - costheta) * r.y * r.y) * this->y;
q.y += ((1 - costheta) * r.y * r.z - r.x * sintheta) * this->z;
q.z = ((1 - costheta) * r.x * r.z - r.y * sintheta) * this->x;
q.z += ((1 - costheta) * r.y * r.z + r.x * sintheta) * this->y;
q.z += (costheta + (1 - costheta) * r.z * r.z) * this->z;
q.x += p1.x;
q.y += p1.y;
q.z += p1.z;
this->set(q);
}
bool isNaN() const
{
return x!=x || y!=y || z!=z;
}
T x;
T y;
T z;
};
typedef Vector3<int> Vector3i;
typedef Vector3<float> Vector3f;
typedef Vector3<double> Vector3d;
#endif//VECTOR_3_H
+60
View File
@@ -0,0 +1,60 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com
//
// Distributed under the licence available in the accompanying file
// LICENCE.txt. Please read it before use this code.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef DCEL_Vertex_h
#define DCEL_Vertex_h
//#include <cassert>
template<class VertexDataT, class HalfEdgeDataT, class FaceDataT>
class HalfEdgeT;
template<class VertexDataT, class HalfEdgeDataT, class FaceDataT>
class VertexT
{
typedef VertexT<VertexDataT, HalfEdgeDataT, FaceDataT> Vertex;
typedef HalfEdgeT<VertexDataT, HalfEdgeDataT, FaceDataT> HalfEdge;
public:
VertexT():
data(),
incidentEdge(NULL)
{
};
inline HalfEdge* getIncidentEdge() const
{
//assert(this);
return this->incidentEdge;
};
inline void setIncidentEdge(HalfEdge* edge)
{
//assert(this);
this->incidentEdge = edge;
};
inline VertexDataT& getData()
{
return data;
};
inline const VertexDataT& getData() const
{
return data;
};
protected:
private:
HalfEdge* incidentEdge;
VertexDataT data;
};
#endif//DCEL_Vertex_h
+66
View File
@@ -0,0 +1,66 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com
//
// Distributed under the licence available in the accompanying file
// LICENCE.txt. Please read it before use this code.
//
///////////////////////////////////////////////////////////////////////////////
#include "WavefrontObjImporter.h"
#include <fstream>
#include <sstream>
void WavefrontObjLoader::load( const std::string& objFile )
{
vertices.clear();
verticeCount=0;
faces.clear();
faceCount=0;
std::ifstream stream;
try
{
stream.open( objFile.c_str(), std::ios::in );
if( stream )
{
// load the obj
while( stream.good() )
{
char buffer[512];
stream.getline(buffer, sizeof(buffer));
std::stringstream str(buffer);
std::string name;
str >> name;
if( name=="v" )
{
Vector3f position;
str >> position.x >> position.y >> position.z;
vertices.push_back( position );
verticeCount++;
}
else if( name=="f" )
{
unsigned int a, b, c;
str >> a >> b >> c;
faces.push_back(a-1);
faces.push_back(b-1);
faces.push_back(c-1);
faceCount++;
}
}
stream.close();
}
else
{
throw cpp::Exception("Can't open the file '"+objFile+"'");
}
}
catch( const std::exception& e )
{
if( stream.is_open() )
stream.close();
std::cerr << e.what();
throw;
}
}
+107
View File
@@ -0,0 +1,107 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com
//
// Distributed under the licence available in the accompanying file
// LICENCE.txt. Please read it before use this code.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef WavefrontObjImporter_h
#define WavefrontObjImporter_h
#include "DCELStream.h"
#include "Vector3.h"
class WavefrontObjLoader
{
public:
void load( const std::string& objFile );
std::list<Vector3f> vertices;
unsigned int verticeCount;
std::list<unsigned int> faces;
unsigned int faceCount;
protected:
private:
};
/**
Class that imports a Wavefront OBJ file into a DCEL mesh.
It assumes that the mesh is totally triangulated.
*/
template <class MeshT>
class WavefrontObjImporter
{
public:
/**
Loads from the given filename.
It just calls the 'import' method with the opened stream.
*/
void import( const std::string& objFile, MeshT& mesh);
void import( std::list<Vector3f>& vertices, unsigned int verticeCount, std::list<unsigned int>& faces, unsigned int faceCount, MeshT& mesh);
};
template <class MeshT>
void WavefrontObjImporter<MeshT>::import( const std::string& objFilename, MeshT& mesh )
{
std::cerr << "Starting importing the file '" << objFilename << "'" << std::endl;
std::cerr << "- loading the OBJ file" << std::endl;
WavefrontObjLoader loader;
loader.load(objFilename);
import(loader.vertices, loader.verticeCount, loader.faces, loader.faceCount, mesh);
}
template <class MeshT>
void WavefrontObjImporter<MeshT>::import( std::list<Vector3f>& vertices, unsigned int verticeCount, std::list<unsigned int>& faces, unsigned int faceCount, MeshT& mesh)
{
// put it into the mesh
std::cerr << "- loading the DCEL mesh: " << std::endl;
std::cerr << " + " << verticeCount << " vertices" << std::endl;
mesh.clear();
mesh.getVertices().reserve(verticeCount);
mesh.getFaces().reserve(faceCount);
//mesh.getEdges().reserve( 2*(verticeCount+faceCount) ); // Euler: V – A + F = 2 --> A = V + F - 2
mesh.getHalfEdges().reserve( 2*(3*faceCount) ); // just a good expensive number of edges =)
std::list<Vector3f>::iterator vit = vertices.begin();
while( vit!=vertices.end() )
{
unsigned int id = mesh.createVertex();
mesh.getVertex(id)->getData().position = *vit;
vit++;
}
std::cerr << " + " << faceCount << " faces" << std::endl;
std::list<unsigned int>::iterator fit = faces.begin();
unsigned int count=0;
while( fit!=faces.end() )
{
count++;
unsigned int a = *fit; ++fit;
unsigned int b = *fit; ++fit;
unsigned int c = *fit; ++fit;
unsigned int fid = mesh.createTriangularFace( a, b, c );
if (fid!=-1)
{
//std::cout << a << ' ' << b << ' ' << c << std::endl;
mesh.checkFace(fid);
mesh.checkAllFaces();
}
}
std::cerr << " + " << mesh.getNumUnhandledTriangles() << " bad triangles" << std::endl;
mesh.manageUnhandledTriangles();
mesh.checkAllFaces();
std::cerr << "Done!" << std::endl;
}
#endif//WavefrontObjImporter_h
+423
View File
@@ -0,0 +1,423 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright Leonardo Fischer 2011 - http://coderender.blogspot.com
//
// Distributed under the licence available in the accompanying file
// LICENCE.txt. Please read it before use this code.
//
///////////////////////////////////////////////////////////////////////////////
#include "DCEL/Mesh.h"
#include "DCEL/DCELStream.h"
#include "DCEL/WavefrontObjImporter.h"
#include "DCEL/Vector3.h"
#include <fstream>
/**
Here I'll define the three data structures that will be
associated with Vertices, half-edges and faces. Put anything you want
inside of it.
*/
class VertexData
{
public:
VertexData()
{
this->x = 0;
this->y = 0;
this->z = 0;
}
float x, y, z;
void setVerticeCoordinates(float x, float y)
{
this->x = x;
this->y = y;
}
/**
If you need to save the stream to a file, rewrite the << operator for the
ostream class. The DCELStream class will use it to write to a file. More latter.
*/
friend std::ostream& operator <<(std::ostream &os, const VertexData& vertexData)
{
os << vertexData.x << " " << vertexData.y;
return os;
}
/**
If you save the mesh to a file, rewrite the operator >> to be able to load
the mesh latter using the DCELStream class.
*/
friend std::istream& operator >>(std::istream &is, VertexData& vertexData)
{
is >> vertexData.x >> vertexData.y;
return is;
}
};
/**
Another possible class to use within a vertex. In the current implementation of
the WavefrontObjImporter, I need the Vector3f class to load the vertices positions.
Of course, there should be another way to do this, but I didn't figured out.
If you have a suggestion, let me know =)
*/
class VertexDataWithPosition
{
public:
Vector3f position;
protected:
private:
};
class HalfEdgeData
{
public:
HalfEdgeData() {
modified = false;
}
void modify() {
modified = true;
}
bool isModified() const {
return modified;
}
friend std::ostream& operator <<(std::ostream &os, const HalfEdgeData& halfEdgeData)
{
std::string modified = halfEdgeData.isModified()? "true" : "false";
os << modified;
return os;
}
friend std::istream& operator >>(std::istream &is, HalfEdgeData& halfEdgeData)
{
std::string modified;
is >> modified;
if (modified.compare("true")==0)
{
halfEdgeData.modify();
}
return is;
}
private:
bool modified;
};
class FaceData
{
public:
std::string colorName;
friend std::ostream& operator <<(std::ostream &os, const FaceData& faceData)
{
os << faceData.colorName;
return os;
}
friend std::istream& operator >>(std::istream &is, FaceData& faceData)
{
is >> faceData.colorName;
return is;
}
};
/**
Now I will define the type MyMesh, which is a Mesh that each vertex, face and half-edge
has one object given as parameter here.
*/
typedef Mesh<VertexData, HalfEdgeData, FaceData> MyMesh;
/**
Another type of Mesh. In this type, each vertex will have an instance of
VertexDataWithPosition.
Although MyMesh and MyMeshUsingVector have the same structure, they are not
interchangeable. They are different objects! But you can use
the DCELStream::copyDcelData() method to convert between different mesh types.
*/
typedef Mesh<VertexDataWithPosition, HalfEdgeData, FaceData> MyMeshUsingVector;
/**
This method will create and initialize an hard-coded mesh.
*/
void createHardCodedMesh(MyMesh* mesh) {
// reserve the needed space for the mesh. These numbers came from the hardcoded structure :)
mesh->getVertices().reserve( 5 ); // we will put 5 vertices into the mesh
mesh->getHalfEdges().reserve( 16 ); //there are 8 edges on the figure. Each edge has 2 half-edges. So, 16
mesh->getFaces().reserve( 4 ); //4 faces
/**
Now, create the vertices. Each time I call createGetVertex here, a new vertex is created
and a pointer to it is returned. The first vertex has its ID equals to 0, the second equals
to 1, and so on.
If you call getData() on that pointer, you get a reference for the VertexData
object that is inside this vertex. The getData() works in the same way for
Half-Edge and Face pointers, returning a HalfEdgeData and FaceData object,
respectively.
*/
mesh->createGetVertex()->getData().setVerticeCoordinates( 10, 5 ); //vertex 0
mesh->createGetVertex()->getData().setVerticeCoordinates( 6, 10 ); //vertex 1
mesh->createGetVertex()->getData().setVerticeCoordinates( 15, 9 ); //vertex 2
mesh->createGetVertex()->getData().setVerticeCoordinates( 14, 1 ); //vertex 3
mesh->createGetVertex()->getData().setVerticeCoordinates( 2, 4 ); //vertex 4
/**
Now we will create the faces using the IDs from the vertices created before. I'll
give the three vertices's IDs that represents each face. Again, the faces receive
an incremental ID starting from 0.
I must ensure that all faces are described in the same orientation (clock-wise or
counter-clock-wise). If I fail in this, I will receive very strange runtime errors.
*/
mesh->createTriangularFace( 0, 1, 2 );
mesh->createTriangularFace( 0, 2, 3 );
mesh->createTriangularFace( 0, 3, 4 );
mesh->createTriangularFace( 0, 4, 1 );
/**
This is just a helper method that checks that all pointers are
set correctly. If I did anything wrong before, an exception will
be thrown.
*/
mesh->checkAllFaces();
/**
Now I'll use the ID of each face to set a color on it.
*/
mesh->getFace(0)->getData().colorName = "red";
mesh->getFace(1)->getData().colorName = "green";
mesh->getFace(2)->getData().colorName = "blue";
mesh->getFace(3)->getData().colorName = "white";
/**
Now I'll modify some half edges using a iterator. This will iterate over
all half-edges that starts on the vertex 1. The iterator can run over all
the edges that starts on the given vertex or face.
*/
MyMesh::EdgeIterator iterator( mesh->getVertex(1) );
while(iterator.hasNext()) {
MyMesh::HalfEdge* halfEdge = iterator.getNext();
halfEdge->getData().modify();
}
/**
And also, I'll modify the half-edge that starts on the vertex 0 and ends on
the vertex 3. The method getHalfEdge(unsigned int a, unsigned int b) returns the
half-edge that starts at 'a' and ends at 'b', or null if such connection does
not exists.
*/
MyMesh::HalfEdge* edge = mesh->getHalfEdge(3, 0);
if (edge!=NULL)
{
edge->getData().modify();
}
}
void saveMesh(MyMesh* mesh, const char* filename)
{
if (mesh!=NULL)
{
std::ofstream outputFile;
outputFile.open(filename);
if (outputFile)
{
/**
This is where I will write the mesh to a file.
Note that the operator "<<" need to be rewrited on the VertexData,
HalfEdgeData and FaceData classes.
*/
DCELStream<MyMesh>::write(*mesh, outputFile);
outputFile.close();
}
}
}
void loadMesh(MyMesh* mesh, const char* filename)
{
if (mesh!=NULL)
{
std::ifstream inputFile;
inputFile.open(filename);
if (inputFile)
{
/**
This is where I load the mesh from a DCEL file, saved with the
DCELStream<MyMesh>::write() method.
As for the DCELStream<MyMesh>::write(), here you need to rewrite the
">>" operator on the VertexData, HalfEdgeData and FaceData classes.
*/
DCELStream<MyMesh>::read(*mesh, inputFile);
inputFile.close();
}
}
}
void doSomeStuffWithMesh(MyMesh* mesh)
{
/**
Print some basic information about the mesh.
*/
std::cout << "The mesh contain " << mesh->getNumFaces() << " faces." << std::endl;
std::cout << "The mesh contain " << mesh->getNumVertices() << " vertices." << std::endl;
std::cout << "The mesh contain " << mesh->getNumHalfEdges() << " half-edges. " <<
"This number is 2 times the number of edges." << std::endl;
std::cout << std::endl;
/**
Show the ID of the neighbor vertices of the vertex 4. It will get each half-edge
that starts at the vertex 4, get its twin half-edge, and get the origin of the twin
half-edge.
The method getVertexId() returns the id of a given vertex. There are similar vertices
for half-edges and faces
*/
std::cout << "The neighbors of the vertex 4 are: ";
MyMesh::Vertex * vertex = mesh->getVertex(4);
MyMesh::EdgeIterator iterator(vertex);
while(iterator.hasNext()) {
MyMesh::Vertex* neighborVertex = iterator.getNext()->getTwin()->getOrigin();
std::cout << mesh->getVertexId(neighborVertex) << ", ";
}
std::cout << std::endl << std::endl;
/**
Iterate over the edges that composes the face 1 (the one composed by
the vertices 0, 2, 3). For each edge, will show its start vertex ID,
its ending vertex ID (which is the origin of its twin), and show if
it was modified (remember that I called modify() on the half-edge that
starts on vertex 3 and ends on vertex 0, see createHardCodedMesh() ).
*/
std::cout << "The half-edges of the face 1 are: ";
MyMesh::Face* face = mesh->getFace(1);
iterator.reset(face); //now the iterator will run over the edges of the face
while ( iterator.hasNext() )
{
MyMesh::HalfEdge* halfEdge = iterator.getNext();
std::cout << "[id="<< mesh->getHalfEdgeId(halfEdge) <<
" origin=" << mesh->getVertexId( halfEdge->getOrigin() ) <<
" end=" << mesh->getVertexId( halfEdge->getTwin()->getOrigin() ) <<
" modified=" << (halfEdge->getData().isModified()?"true":"false") << "], ";
}
std::cout << std::endl << std::endl;
/**
Iterate over all faces that the mesh have, showing its color. It is possible
to iterate over the half-edges and faces in the same way.
*/
std::cout << "The faces are: ";
for (unsigned int i=0; i<mesh->getNumFaces(); ++i)
{
MyMesh::Face* face = mesh->getFace(i);
std::cout << "[id=" << mesh->getFaceId(face) << " color=" << face->getData().colorName << "], ";
}
std::cout << std::endl << std::endl;
}
void importWavefrontObjFile(MyMeshUsingVector* mesh, const char* filename)
{
WavefrontObjImporter<MyMeshUsingVector> importer;
importer.import(filename, *mesh);
}
void convertBetweenMeshes(MyMeshUsingVector* meshUsingVector, MyMesh* mesh)
{
/**
This will create on the 'mesh' the same structure of 'meshUsingVector'.
Note that only the DCEL connectivity is copied.
*/
DCELStream<MyMeshUsingVector>::copyDcelData(*meshUsingVector, *mesh);
/**
As the IDs of faces, half-edges and vertices are the same in both meshes,
it is possible to use this fact to convert internal data from one structure
to the other.
Of course, there should be a better way to do this automatically in the
copyDcelData() method, but I had no time to implement it =(
*/
for (unsigned int i=0;i<meshUsingVector->getNumVertices(); ++i)
{
MyMeshUsingVector::Vertex* originVertex = meshUsingVector->getVertex(i);
MyMesh::Vertex* targetVertex = mesh->getVertex(i);
targetVertex->getData().x = originVertex->getData().position.x;
targetVertex->getData().y = originVertex->getData().position.y;
targetVertex->getData().z = originVertex->getData().position.z;
}
for (unsigned int i=0;i<meshUsingVector->getNumHalfEdges(); ++i)
{
MyMeshUsingVector::HalfEdge* originHalfEdge = meshUsingVector->getHalfEdge(i);
MyMesh::HalfEdge* targetHalfEdge = mesh->getHalfEdge(i);
if (originHalfEdge->getData().isModified())
{
targetHalfEdge->getData().modify();
}
}
for (unsigned int i=0;i<meshUsingVector->getNumFaces(); ++i)
{
MyMesh::Face* targetFace = mesh->getFace(i);
targetFace->getData().colorName = "yellow";
}
}
int main(int argc, char* argv[])
{
try
{
/**
Creates a new, hard coded mesh, and save it to a file.
*/
MyMesh* mesh = new MyMesh();
createHardCodedMesh(mesh);
saveMesh(mesh, "hard-coded-mesh.dcel");
delete mesh;
/**
Creates a new, empty mesh, and fill it with the data from
the file saved before. Also, print some stuff about it
on the console.
*/
mesh = new MyMesh(); //create a new, empty mesh
loadMesh(mesh, "hard-coded-mesh.dcel");
doSomeStuffWithMesh(mesh);
delete mesh;
/**
Creates another type of mesh (using my Vector3 class). Then, import a .OBJ
file into it. Finally, convert that mesh to the MyMesh data structure.
The method checkAllFaces() just ensures that everything is ok =)
*/
MyMeshUsingVector* meshUsingVect = new MyMeshUsingVector();
mesh = new MyMesh();
importWavefrontObjFile(meshUsingVect, "sphere.obj");
convertBetweenMeshes(meshUsingVect, mesh);
mesh->checkAllFaces();
meshUsingVect->checkAllFaces();
delete meshUsingVect;
delete mesh;
system("pause");
return 0;
}
catch (std::exception& e)
{
std::cerr << "An exception occurred: " << e.what() << std::endl;
system("pause");
return 1;
}
}
+20
View File
@@ -0,0 +1,20 @@
RPly 1.01 license
Copyright © 2003-2005 Diego Nehab.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
+136
View File
@@ -0,0 +1,136 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "rply.h"
/* internal function prototypes */
static void error(const char *fmt, ...);
static void help(void);
static void parse_arguments(int argc, char **argv,
e_ply_storage_mode *storage_mode,
const char **iname, const char **oname);
static void setup_callbacks(p_ply iply, p_ply oply);
/* given a format mode, an input file name and an output file name,
* convert input file to output in given format mode */
int main(int argc, char **argv)
{
const char *value = NULL;
e_ply_storage_mode storage_mode = PLY_LITTLE_ENDIAN;
const char *iname = NULL, *oname = NULL;
p_ply iply = NULL, oply = NULL;
/* parse command line arguments */
parse_arguments(argc, argv, &storage_mode, &iname, &oname);
/* open input file and make sure we parsed its header */
iply = ply_open(iname, NULL);
if (!iply) error("Unable to open file '%s'", iname);
if (!ply_read_header(iply)) error("Failed reading '%s' header", iname);
/* create output file */
oply = ply_create(oname, storage_mode, NULL);
if (!oply) error("Unable to create file '%s'", oname);
/* create elements and properties in output file and
* setup callbacks for them in input file */
setup_callbacks(iply, oply);
/* pass comments and obj_infos from input to output */
value = NULL;
while ((value = ply_get_next_comment(iply, value)))
if (!ply_add_comment(oply, value))
error("Failed adding comments");
value = NULL;
while ((value = ply_get_next_obj_info(iply, value)))
if (!ply_add_obj_info(oply, value))
error("Failed adding comments");
/* write output header */
if (!ply_write_header(oply)) error("Failed writing '%s' header", oname);
/* read input file generating callbacks that pass data to output file */
if (!ply_read(iply)) error("Conversion failed");
/* close up, we are done */
if (!ply_close(iply)) error("Error closing file '%s'", iname);
if (!ply_close(oply)) error("Error closing file '%s'", oname);
return 0;
}
/* prints an error message and exits */
static void error(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
exit(1);
}
/* prints the help message and exits */
static void help(void)
{
error("Usage:\n"
" convert <option> <input> <output>\n"
"Options:\n"
" -a, --ascii: convert to ascii format\n"
" -b, --big-endian: convert to big-endian format\n"
" -l, --little-endian: convert to little-endian format\n");
}
/* parse command line parameters */
static void parse_arguments(int argc, char **argv,
e_ply_storage_mode *storage_mode,
const char **iname, const char **oname)
{
if (argc < 4) help();
if (strcmp(argv[1], "--ascii") == 0 ||
strcmp(argv[1], "-a") == 0)
*storage_mode = PLY_ASCII;
else if (strcmp(argv[1], "--little-endian") == 0 ||
strcmp(argv[1], "-l") == 0)
*storage_mode = PLY_LITTLE_ENDIAN;
else if (strcmp(argv[1], "--big-endian") == 0 ||
strcmp(argv[1], "-b") == 0)
*storage_mode = PLY_BIG_ENDIAN;
else help();
*iname = argv[2];
*oname = argv[3];
}
/* read callback */
static int callback(p_ply_argument argument)
{
void *pdata;
/* just pass the value from the input file to the output file */
ply_get_argument_user_data(argument, &pdata, NULL);
ply_write((p_ply) pdata, ply_get_argument_value(argument));
return 1;
}
/* prepares the conversion */
static void setup_callbacks(p_ply iply, p_ply oply)
{
p_ply_element element = NULL;
/* iterate over all elements in input file */
while ((element = ply_get_next_element(iply, element))) {
p_ply_property property = NULL;
long ninstances = 0;
const char *element_name;
ply_get_element_info(element, &element_name, &ninstances);
/* add this element to output file */
if (!ply_add_element(oply, element_name, ninstances))
error("Unable to add output element '%s'", element_name);
/* iterate over all properties of current element */
while ((property = ply_get_next_property(element, property))) {
const char *property_name;
e_ply_type type, length_type, value_type;
ply_get_property_info(property, &property_name, &type,
&length_type, &value_type);
/* setup input callback for this property */
if (!ply_set_read_cb(iply, element_name, property_name, callback,
oply, 0))
error("Unable to setup input callback for property '%s'",
property_name);
/* add this property to output file */
if (!ply_add_property(oply, property_name, type, length_type,
value_type))
error("Unable to add output property '%s'", property_name);
}
}
}
+44
View File
@@ -0,0 +1,44 @@
#include <stdio.h>
#include "rply.h"
static int vertex_cb(p_ply_argument argument) {
long eol;
ply_get_argument_user_data(argument, NULL, &eol);
printf("%g", ply_get_argument_value(argument));
if (eol) printf("\n");
else printf(" ");
return 1;
}
static int face_cb(p_ply_argument argument) {
long length, value_index;
ply_get_argument_property(argument, NULL, &length, &value_index);
switch (value_index) {
case 0:
case 1:
printf("%g ", ply_get_argument_value(argument));
break;
case 2:
printf("%g\n", ply_get_argument_value(argument));
break;
default:
break;
}
return 1;
}
int main(void) {
long nvertices, ntriangles;
p_ply ply = ply_open("input.ply", NULL);
if (!ply) return 1;
if (!ply_read_header(ply)) return 1;
nvertices = ply_set_read_cb(ply, "vertex", "x", vertex_cb, NULL, 0);
ply_set_read_cb(ply, "vertex", "y", vertex_cb, NULL, 0);
ply_set_read_cb(ply, "vertex", "z", vertex_cb, NULL, 1);
ntriangles = ply_set_read_cb(ply, "face", "vertex_indices", face_cb, NULL, 0);
printf("%ld\n%ld\n", nvertices, ntriangles);
if (!ply_read(ply)) return 1;
ply_close(ply);
return 0;
}
+16
View File
@@ -0,0 +1,16 @@
ply
format ascii 1.0
comment this is our first comment
element vertex 3
property float x
property float y
property float z
element face 1
property list uchar int vertex_indices
comment this is our last comment
end_header
-1 0 0
000 1 0
1 0000 0
3 1 00000 2
3 1 0 2
+66
View File
@@ -0,0 +1,66 @@
#include <stdio.h>
#include "rply.h"
static int callback(p_ply_argument argument)
{
void *pdata;
/* just pass the value from the input file to the output file */
ply_get_argument_user_data(argument, &pdata, NULL);
ply_write((p_ply) pdata, ply_get_argument_value(argument));
return 1;
}
static int setup_callbacks(p_ply iply, p_ply oply)
{
p_ply_element element = NULL;
/* iterate over all elements in input file */
while ((element = ply_get_next_element(iply, element))) {
p_ply_property property = NULL;
long nelems = 0;
const char *element_name;
ply_get_element_info(element, &element_name, &nelems);
/* add this element to output file */
if (!ply_add_element(oply, element_name, nelems)) return 0;
/* iterate over all properties of current element */
while ((property = ply_get_next_property(element, property))) {
const char *property_name;
e_ply_type type, length_type, value_type;
ply_get_property_info(property, &property_name, &type,
&length_type, &value_type);
/* setup input callback for this property */
if (!ply_set_read_cb(iply, element_name, property_name, callback,
oply, 0)) return 0;
/* add this property to output file */
if (!ply_add_property(oply, property_name, type, length_type,
value_type)) return 0;
}
}
return 1;
}
int main(int argc, char **argv)
{
const char *value;
p_ply iply, oply;
iply = ply_open("input.ply", NULL);
if (!iply) return 1;
if (!ply_read_header(iply)) return 1;
oply = ply_create("output.ply", PLY_LITTLE_ENDIAN, NULL);
if (!oply) return 1;
if (!setup_callbacks(iply, oply)) return 1;
/* pass comments and obj_infos from input to output */
value = NULL;
while ((value = ply_get_next_comment(iply, value)))
if (!ply_add_comment(oply, value)) return 1;
value = NULL;
while ((value = ply_get_next_obj_info(iply, value)))
if (!ply_add_obj_info(oply, value)) return 1;;
/* write output header */
if (!ply_write_header(oply)) return 1;
/* read input file generating callbacks that pass data to output file */
if (!ply_read(iply)) return 1;
/* close up, we are done */
if (!ply_close(iply)) return 1;
if (!ply_close(oply)) return 1;
return 0;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+993
View File
@@ -0,0 +1,993 @@
<html>
<head>
<meta name="description" content="The RPly Homepage">
<meta name="keywords" content="open source, C, Library, PLY, file format,
input, output, tools">
<title>
RPly: ANSI C library for PLY file format input and output
</title>
<link rel="stylesheet" href="reference.css" type="text/css">
</head>
<body>
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<div class=header>
<hr>
<center>
<table summary="RPly logo">
<tr><td align=center>
<img border=0 alt="RPly" src="rply.png">
</td></tr>
<tr><td align=center valign=top>ANSI C Library for PLY file format input and output
</td></tr>
</table>
</center>
<hr>
</div>
<!-- Introduction +++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<h1>Introduction</h1>
<p>RPly is a library that lets applications read and write PLY files. The
PLY file format is widely used to store geometric information, such as 3D
models, but is general enough to be useful for other purposes.
</p>
<p>There are other libraries out there, of course. I tried using them and
finally decided to write my own. I tried to write it in such a way that
others won't have to do it again and again. Everything that made me unhappy
about the existing libraries was eliminated from RPly.</p>
<p>RPly is easy to use, well documented, small, free,
open-source, ANSI C, efficient, and well tested. I will keep supporting it
for a while because all my tools use the library for input/output. The highlights are: </p>
<ul>
<li> A callback mechanism that makes PLY file input straightforward;
<li> Support for the full range of numeric formats though the user only
deals with doubles;
<li> Binary (big and little endian) and text modes are fully supported;
<li> Input and output are buffered for efficiency;
<li> Available under the
<a href=http://www.opensource.org/licenses/mit-license.html>MIT license</a>
for added freedom.
</ul>
<p>
The format was developed at <a
href=http://graphics.stanford.edu/data/3Dscanrep/>Stanford University</a>
for use with their 3D scanning projects. Greg Turk's PLY library, available
from <a href=http://www.cc.gatech.edu/projects/large_models>
Georgia Institute of Technology</a>, seems to be the standard reference
to the PLY file format, although there are some variations out there.
</p>
<p> Whatever documentation and examples were found, were taken into
consideration to create RPly. In theory, since RPly doesn't try to interpret
the meaning of the data in a PLY file, it should be able to read any PLY file.
In practice, the library works with all PLY files that I could find. </p>
<h2>Download</h2>
<p>
Version 1.01 of RPly is available for download in source
code from <a href=rply-1.01.tar.gz>this link</a>. Examples and documentation
are packed inside the tar ball. Have fun!
</p>
<p>
Copyright &copy; 2003-2005 Diego Nehab. All rights reserved. <br>
Author: <A href="http://www.cs.princeton.edu/~diego">Diego Nehab</a>
</p>
<h2>What's new?</h2>
<p>
The change for version 1.01 is the use of our own buffering code when
reading ASCII files. Speedup factor of 5 in Linux, almost no change in
Windows.
</p>
<h2> RPly's idea of what a PLY file is </h2>
<p> A PLY file contains the description of one object. This object is
composed by <em>elements</em>, each element type
being composed by a group of <em>properties</em>. The PLY file
format specifies a syntax for the description of element types and the
properties that compose them, as well as comments and meta-information.
</p>
<p> The element type descriptions come in a header, which is followed by
element instances. Element instances come grouped by their type, in the
order of declaration. Each element instance is defined by the value
of its properties. Properties values also appear in the order of their
declaration. Here is a sample PLY file describing a triangle: </p>
<pre class=example>
ply
format ascii 1.0
comment this is a simple file
obj_info any data, in one line of free form text
element vertex 3
property float x
property float y
property float z
element face 1
property list uchar int vertex_indices
end_header
-1 0 0
0 1 0
1 0 0
3 0 1 2
</pre>
<p> The header goes from the first line to the line marked by
<tt>end_header</tt>. The first line contains only <tt>ply\n</tt> and is
used to detect whether a file is in PLY format or not. The second line
specifies the <tt>format</tt> number (which is always <tt>1.0</tt>) and the
storage mode (<tt>ascii</tt>, <tt>binary_big_endian</tt> or
<tt>binary_little_endian</tt>). </p>
<p> Lines that start with <tt>comment</tt> are just comments, of course.
Lines that start with <tt>obj_info</tt> contain meta-information about the
object. <tt>Comment</tt>s and <tt>obj_info</tt>s are optional and their
relative order in the header is irrelevant. </p>
<p> In the sample PLY file, the first element type is declared with name
<tt>vertex</tt>, and on the same line we learn that there will be 3
instances of this element type. The properties following describe what a
<tt>vertex</tt> element looks like. Each <tt>vertex</tt> is declared to
consist of 3 scalar properties, named <tt>x</tt>, <tt>y</tt> and
<tt>z</tt>. Each scalar property is declared to be of type <tt>float</tt>.
</p>
<p> Scalar types can be any of the following: <tt>int8</tt>,
<tt>uint8</tt>, <tt>int16</tt>, <tt>uint16</tt>, <tt>int32</tt>,
<tt>uint32</tt>, <tt>float32</tt>, <tt>float64</tt>, <tt>char</tt>,
<tt>uchar</tt>, <tt>short</tt>, <tt>ushort</tt>, <tt>int</tt>,
<tt>uint</tt>, <tt>float</tt>, <tt>double</tt>. They consist of signed
and unsigned integer types of sizes 8, 16 and 32 bits, as well as floating
point types of 32 and 64bits.
<p> Next, the <tt>face</tt> element type is declared, of which only 1
instance will be given. This element consists of a <tt>list</tt> property,
named <tt>vertex_indices</tt>. Lists are sequences on which the
first value, the <em>length</em>, gives the number of remaining values. List properties are described by the scalar
type of their length field and the scalar type of the remaining fields.
In the case of <tt>vertex_indices</tt>, the length field
is of type <tt>uchar</tt> and the remaining values are of type
<tt>int</tt>. </p>
<p> Following the header, come the elements, in the order they were
declared in the header. First come the 3 elements of type <tt>vertex</tt>,
each represented by the value of their properties <tt>x</tt>, <tt>y</tt>
and <tt>z</tt>. Then comes the single <tt>face</tt> element, composed by a
single list of type <tt>vertex_indices</tt> containing 3 values
(0 1 2).</p>
<h2> How to read a file with RPly </h2>
<p> Most users that want to read a PLY file already know which elements and
properties they are interested at. In the following example, we will
implement a simple program that dumps the contents of a PLY file to the
terminal, in a different, simpler format that only works for triangles.
</p>
<p> This simple format has a header that gives the number of vertices in the
first line and the number of triangles in the second line. Following the
header come the vertices, and finally the triangles. Here is the sample
code for the program:</p>
<pre class=example>
#include &lt;stdio.h&gt;
#include "rply.h"
static int vertex_cb(p_ply_argument argument) {
long eol;
ply_get_argument_user_data(argument, NULL, &amp;eol);
printf("%g", ply_get_argument_value(argument));
if (eol) printf("\n");
else printf(" ");
return 1;
}
static int face_cb(p_ply_argument argument) {
long length, value_index;
ply_get_argument_property(argument, NULL, &amp;length, &amp;value_index);
switch (value_index) {
case 0:
case 1:
printf("%g ", ply_get_argument_value(argument));
break;
case 2:
printf("%g\n", ply_get_argument_value(argument));
break;
default:
break;
}
return 1;
}
int main(void) {
long nvertices, ntriangles;
p_ply ply = ply_open("input.ply", NULL);
if (!ply) return 1;
if (!ply_read_header(ply)) return 1;
nvertices = ply_set_read_cb(ply, "vertex", "x", vertex_cb, NULL, 0);
ply_set_read_cb(ply, "vertex", "y", vertex_cb, NULL, 0);
ply_set_read_cb(ply, "vertex", "z", vertex_cb, NULL, 1);
ntriangles = ply_set_read_cb(ply, "face", "vertex_indices", face_cb, NULL, 0);
printf("%ld\n%ld\n", nvertices, ntriangles);
if (!ply_read(ply)) return 1;
ply_close(ply);
return 0;
}
</pre>
<p> RPly uses callbacks to pass data to an application. Independent callbacks
can be associated with each property of each element. For scalar
properties, the callback is invoked once for each instance. For list
properties, the callback is invoked first with the number of
entries in the instance, and then once for each of the data entries.
<em>This is exactly the order in which the data items appear in the
file.</em></p>
<p> To keep things simple, values are always passed as <tt>double</tt>,
regardless of how they are stored in the file. From its parameters,
callbacks can find out exactly which part of the file is being processed
(including the real type of the value), plus access custom information
provided by the user in the form of a pointer and an integer constant. </p>
<p> In our example, we start with a call to <tt>ply_open</tt> to open a
file for reading. Then we get RPly to parse it's header, with a call to
<tt>ply_read_header</tt>. After the header is parsed, RPly knows which
element types and properties are available. We then set callbacks for each
of the <tt>vertex</tt> element properties and the <tt>face</tt> property
(using <tt>ply_set_read_cb</tt>). Finally, we invoke the main RPly reading
function, <tt>ply_read</tt>. This function reads all data in the file,
passing the data to the appropriate callbacks. After all reading is done,
we call <tt>ply_close</tt> to release any resources used by RPly.</p>
<p>There are some details, of course. <tt>Ply_set_read_cb</tt> returns the
number of instances of the target property (which is the same as the number
of element instances). This is how the program obtains the number of
vertices and faces in the file. </p>
<p>RPly lets us associate one pointer <em>and</em> one integer to each
callback. We are free to use either or both to link some context to our
callbacks. Our example uses the integer placeholder to tell
<tt>vertex_cb</tt> that it has to break the line after the <tt>z</tt>
property (notice the last argument of <tt>ply_set_read_cb</tt>).</p>
<p><tt>Vertex_cb</tt> gets the user data and the property value from it's
argument and prints accordingly. The <tt>face_cb</tt> callback is a bit
more complicated because lists are more complicated. Since the
simple file format only supports triangles, it only prints the first
3 list values, after which it breaks the line. </p>
<p> The output of the program, as expected, is: </p>
<pre class=example>
3
1
-1 0 0
0 1 0
1 0 0
0 1 2
</pre>
<h2> Writing files with RPly </h2>
<p> The next example is somewhat more involved. We will create a program
that converts our simple PLY file to binary mode. Besides showing how to
write a PLY file, this example also illustrates the query functions. We
do not know a priori which elements and properties, comments and obj_infos
will be in the input file, so we need a way to find out. Although our simple
program would work on any PLY file, a better version of this program is
available from the RPly distribution. For simplicity, the simple version
omits error messages and command line parameter processing. </p>
<p> In practice, writing a file is even easier than reading one. First we
create a file in binary mode, with a call to <tt>ply_create</tt> (notice
the argument <tt>PLY_LITTLE_ENDIAN</tt> that gives the storage mode). Then,
we define the elements using <tt>ply_add_element</tt>. After each element, we
define its properties using <tt>ply_add_scalar_property</tt> or
<tt>ply_add_list_property</tt>. When we are done with elements and
properties, we add comments and obj_infos. We then write the header with
<tt>ply_write_header</tt> and send all data items. The data items are sent
one by one, with calls to <tt>ply_write</tt>, <em>in the same order they
are to appear in the file</em>. Again, to simplify things, this function
receives data as <tt>double</tt> and performs the needed conversion. Here
is the code for the example: </p>
<pre class=example>
#include &lt;stdio.h&gt;
#include "rply.h"
static int callback(p_ply_argument argument) {
void *pdata;
/* just pass the value from the input file to the output file */
ply_get_argument_user_data(argument, &amp;pdata, NULL);
ply_write((p_ply) pdata, ply_get_argument_value(argument));
return 1;
}
static int setup_callbacks(p_ply iply, p_ply oply) {
p_ply_element element = NULL;
/* iterate over all elements in input file */
while ((element = ply_get_next_element(iply, element))) {
p_ply_property property = NULL;
long ninstances = 0;
const char *element_name;
ply_get_element_info(element, &amp;element_name, &amp;ninstances);
/* add this element to output file */
if (!ply_add_element(oply, element_name, ninstances)) return 0;
/* iterate over all properties of current element */
while ((property = ply_get_next_property(element, property))) {
const char *property_name;
e_ply_type type, length_type, value_type;
ply_get_property_info(property, &amp;property_name, &amp;type,
&amp;length_type, &amp;value_type);
/* setup input callback for this property */
if (!ply_set_read_cb(iply, element_name, property_name, callback,
oply, 0)) return 0;
/* add this property to output file */
if (!ply_add_property(oply, property_name, type, length_type,
value_type)) return 0;
}
}
return 1;
}
int main(void) {
const char *value;
p_ply iply, oply;
iply = ply_open("input.ply", NULL);
if (!iply) return 1;
if (!ply_read_header(iply)) return 1;
oply = ply_create("output.ply", PLY_LITTLE_ENDIAN, NULL);
if (!oply) return 1;
if (!setup_callbacks(iply, oply)) return 1;
/* pass comments and obj_infos from input to output */
value = NULL;
while ((value = ply_get_next_comment(iply, value)))
if (!ply_add_comment(oply, value)) return 1;
value = NULL;
while ((value = ply_get_next_obj_info(iply, value)))
if (!ply_add_obj_info(oply, value)) return 1;;
/* write output header */
if (!ply_write_header(oply)) return 1;
/* read input file generating callbacks that pass data to output file */
if (!ply_read(iply)) return 1;
/* close up, we are done */
if (!ply_close(iply)) return 1;
if (!ply_close(oply)) return 1;
return 0;
}
</pre>
<p> RPly uses iterators to let the user loop over a PLY file header. A
function is used to get the first item of a given class (element, property
etc). Passing the last returned item to the same function produces the next
item, until there are no more items. Examples of iterator use can be seen
in the <tt>main</tt> function, which uses them to loop over comments and
obj_infos, and in the <tt>setup_callbacks</tt> function, which loops over
elements and properties. </p>
<p> In the <tt>setup_callbacks</tt> function, for each element in the
input, an equivalent element is defined in the output. For each property in
each element, an equivalent property is defined in the output. Notice that
the same callback is specified for all properties. It is given the output
PLY handle as the context pointer. Each time it is called, it passes the
received value to <tt>ply_write</tt> on the output handle. It is as simple
as that. </p>
<h1>Reference Manual</h1>
<!-- ply_open ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_open>
p_ply <b>ply_open</b>(const char *name, p_ply_error_cb error_cb)
</p>
<p class=description>
Opens a PLY file for reading, checks if it is a valid PLY file
and returns a handle to it.
</p>
<p class=arguments>
<tt>Name</tt> is the file name, and <tt>error_cb</tt> is a function to
be called when an error is found.
If <tt>error_cb</tt> is NULL, the default
error callback is used. It prints a message to the standard error stream.
</p>
<p class=return>
Returns a handle to the file or NULL on error.
</p>
<p class=note>
Note: <tt>Error_cb</tt> is of type <tt>void
(*p_ply_error_cb)(const char *message)</tt>
</p>
<!-- ply_read_header +++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_read_header>
int <b>ply_read_header</b>(p_ply ply)
</p>
<p class=description>
Reads and parses the header of a PLY file.
After a call to this function, the query functions
<a href=#ply_get_next_element><tt>ply_get_next_element</tt></a>,
<a href=#ply_get_next_property><tt>ply_get_next_property</tt></a>,
<a href=#ply_get_next_comment><tt>ply_get_next_comment</tt></a>, and
<a href=#ply_get_next_obj_info><tt>ply_get_next_obj_info</tt></a> can be
called. Callbacks can also be set with the
<a href=#ply_set_read_cb><tt>ply_set_read_cb</tt></a> function.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by <a href=#ply_open><tt>ply_open</tt></a>.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<!-- ply_set_read_cb +++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_set_read_cb>
long <b>ply_set_read_cb</b>(<br>
&nbsp;&nbsp; p_ply ply,<br>
&nbsp;&nbsp; const char *element_name,<br>
&nbsp;&nbsp; const char *property_name,<br>
&nbsp;&nbsp; p_ply_read_cb read_cb,<br>
&nbsp;&nbsp; void *pdata,<br>
&nbsp;&nbsp; long idata<br>
)
</p>
<p class=description>
Sets up the callback to be invoked when the value of a property is read.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by <a href=#ply_open><tt>ply_open</tt></a>.
<tt>Element_name</tt> and <tt>property_name</tt> are the names of the
element and property of interest. <tt>Read_cb</tt> is the callback
function. <tt>Pdata</tt> and <tt>idata</tt> are user data to be passed to
the callback function.
</p>
<p class=return>
Returns the number of instances of the element of interest.
</p>
<p class=note>
Note: <tt>Read_cb</tt> is of type
<tt>int (*p_ply_read_cb)(p_ply_argument argument)</tt>.
The callback should return 1 to continue the reading process,
or return 0 to abort.
<!-- ply_get_argument_element ++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_get_argument_element>
int <b>ply_get_argument_element</b>(<br>
&nbsp;&nbsp; p_ply_argument argument,<br>
&nbsp;&nbsp; p_ply_element *element,<br>
&nbsp;&nbsp; long *instance_index<br>
)
</p>
<p class=description>
Retrieves element information from the callback argument.
</p>
<p class=arguments>
<tt>Argument</tt> is the handle passed to the callback.
<tt>Element</tt> receives a handle to the element
originating the callback. <tt>Instance_index</tt> receives
the index of the instance of the element
being read. <tt>Element</tt> and <tt>instance_index</tt> can be NULL.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<p class=note>
Note: further information can be obtained from <tt>element</tt> with a
call to <a href=#ply_get_element_info>ply_get_element_info</a>.
</p>
<!-- ply_get_argument_property +++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_get_argument_property>
int <b>ply_get_argument_property</b>(<br>
&nbsp;&nbsp; p_ply_argument argument,<br>
&nbsp;&nbsp; p_ply_property *property,<br>
&nbsp;&nbsp; long *length,<br>
&nbsp;&nbsp; long *value_index<br>
)
</p>
<p class=description>
Retrieves property information from the callback argument.
</p>
<p class=arguments>
<tt>Argument</tt> is the handle passed to the callback.
<tt>Property</tt> receives a handle to the property
originating the callback. <tt>Length</tt> receives the number
of values in the list property (1 for scalar properties).
<tt>Value_index</tt> receives the index of the current property entry (0 for
scalar properties, -1 for the first value of a list property, the one that
gives the number of entries). <tt>Property</tt>, <tt>length</tt> and
<tt>value_index</tt> can be NULL.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<p class=note>
Note: further information can be obtained from <tt>property</tt> with a
call to <a href=#ply_get_property_info>ply_get_property_info</a>.
</p>
<!-- ply_get_argument_user_data +++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_get_argument_user_data>
int <b>ply_get_argument_user_data</b>(p_ply_argument argument, void *pdata,
long *idata)
</p>
<p class=description>
Retrieves the user data from the callback argument.
</p>
<p class=arguments>
<tt>Argument</tt> is the handle passed to the callback.
<tt>Pdata</tt> receives the user data pointer.
<tt>Idata</tt> receives the user data integer.
<tt>Pdata</tt> and <tt>idata</tt> can be NULL.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<!-- ply_get_argument_value +++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_get_argument_value>
double <b>ply_get_argument_value</b>(p_ply_argument argument)
</p>
<p class=description>
Retrieves the property value from the callback argument.
</p>
<p class=arguments>
<tt>Argument</tt> is the handle passed to the callback.
</p>
<p class=return>
Returns the property value.
</p>
<!-- ply_read +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_read>
int <b>ply_read</b>(p_ply ply)
</p>
<p class=description>
Reads all data in file, calling appropriate callbacks.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by <a href=#ply_open><tt>ply_open</tt></a>.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<!-- ply_get_next_element ++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_get_next_element>
p_ply_element <b>ply_get_next_element</b>(p_ply ply, p_ply_element last)
</p>
<p class=description>
Iterates over all elements on the header of a PLY file.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by <a href=#ply_open><tt>ply_open</tt></a>.
<a href=#ply_read_header><tt>Ply_read_header</tt></a> must have been called
on the handle otherwise no elements will be found.
<tt>Last</tt> is NULL to retrieve the first element, and an element to
retrieve the next element.
</p>
<p class=return>
Returns the next element, or NULL if no more elements.
</p>
<p class=note>
Note: further information can be obtained from an element with a
call to <a href=#ply_get_element_info>ply_get_element_info</a>.
</p>
<!-- ply_get_next_property +++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_get_next_property>
p_ply_property <b>ply_get_next_property</b>(p_ply_element element, p_ply_property last)
</p>
<p class=description>
Iterates over all properties of an element.
</p>
<p class=arguments>
<tt>Element</tt> is an element handle.
<tt>Last</tt> is NULL to retrieve the first property, and a property to
retrieve the next property.
</p>
<p class=return>
Returns the next property, or NULL if no more properties.
</p>
<p class=note>
Note: further information can be obtained from a property with a
call to <a href=#ply_get_property_info>ply_get_property_info</a>.
</p>
<!-- ply_get_next_comment ++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_get_next_comment>
const char *<b>ply_get_next_comment</b>(p_ply ply, const char *last)
</p>
<p class=description>
Iterates over all comments on the header of a PLY file.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by <a href=#ply_open><tt>ply_open</tt></a>.
<a href=#ply_read_header><tt>Ply_read_header</tt></a> must have been called
on the handle otherwise no comments will be found.
<tt>Last</tt> is NULL to retrieve the first comment, and a comment to
retrieve the next comment.
</p>
<p class=return>
Returns the next comment, or NULL if no more comments.
</p>
<!-- ply_get_next_obj_info +++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_get_next_obj_info>
const char *<b>ply_get_next_obj_info</b>(p_ply ply, const char *last)
</p>
<p class=description>
Iterates over all obj_infos on the header of a PLY file.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by <a href=#ply_open><tt>ply_open</tt></a>.
<a href=#ply_read_header><tt>Ply_read_header</tt></a> must have been called
on the handle otherwise no obj_infos will be found.
<tt>Last</tt> is NULL to retrieve the first obj_info, and a obj_info to
retrieve the next obj_info.
</p>
<p class=return>
Returns the next obj_info, or NULL if no more obj_infos.
</p>
<!-- ply_get_element_info ++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_get_element_info>
int <b>ply_get_element_info</b>(p_ply_element element, const char** name,
long *ninstances)
</p>
<p class=description>
Retrieves information from an element handle.
</p>
<p class=arguments>
<tt>Element</tt> is the handle of the element of interest.
<tt>Name</tt> receives the internal copy of the element name.
<tt>Ninstances</tt> receives the number of instances of this element
in the file. Both <tt>name</tt> and <tt>ninstances</tt> can be NULL.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<!-- ply_get_property_info +++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_get_property_info>
int <b>ply_get_property_info</b>(<br>
&nbsp;&nbsp; p_ply_property property,<br>
&nbsp;&nbsp; const char** name,<br>
&nbsp;&nbsp; e_ply_type *type,<br>
&nbsp;&nbsp; e_ply_type *length_type,<br>
&nbsp;&nbsp; e_ply_type *value_type<br>
)
</p>
<p class=description>
Retrieves information from a property handle.
</p>
<p class=arguments>
<tt>Property</tt> is the handle of the property of interest.
<tt>Name</tt> receives the internal copy of the property name.
<tt>Type</tt> receives the property type.
<tt>Length_type</tt> receives the scalar type of the first entry
in a list property (the one that gives the number of entries).
<tt>Value_type</tt> receives the scalar type of the remaining list entries.
<tt>Name</tt>, <tt>type</tt>, <tt>length_type</tt>, and
<tt>value_type</tt> can be NULL.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<p class=note>
Note: <tt>Length_type</tt> and <tt>value_type</tt> can
receive any of the constants for scalar types defined in
<tt>e_ply_type</tt>. <tt>Type</tt> can, in addition, be <tt>PLY_LIST</tt>,
in which case the property is a list property and the fields
<tt>length_type</tt> and <tt>value_type</tt> become meaningful.
</p>
<!-- ply_create ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_create>
p_ply <b>ply_create</b>(const char *name, e_ply_storage_mode storage_mode,
p_ply_error_cb error_cb)
</p>
<p class=description>
Creates a PLY file for writing.
</p>
<p class=arguments>
<tt>Name</tt> is the file name, <tt>storage_mode</tt> is the file storage mode
(<tt>PLY_ASCII</tt>, <tt>PLY_LITTLE_ENDIAN</tt> or <tt>PLY_BIG_ENDIAN</tt>). <tt>Error_cb</tt> is a function to be called when an error is found.
If <tt>error_cb</tt> is NULL, the default
error callback is used. It prints a message to the standard error stream.
</p>
<p class=return>
Returns a handle to the file or NULL on error.
</p>
<p class=note>
Note: <tt>Error_cb</tt> is of type <tt>void
(*p_ply_error_cb)(const char *message)</tt>
</p>
<!-- ply_add_element +++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_add_element>
int <b>ply_add_element</b>(p_ply ply, const char *name, long ninstances)
</p>
<p class=description>
Adds a new element to the ply file.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a>, <tt>name</tt> is the element
name and <tt>ninstances</tt> is the number of instances of this element that
will be written to the file.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<!-- ply_add_property ++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_add_property>
int <b>ply_add_property</b>(<br>
&nbsp;&nbsp; p_ply ply,<br>
&nbsp;&nbsp; const char *name,<br>
&nbsp;&nbsp; e_ply_type type,<br>
&nbsp;&nbsp; e_ply_type length_type,<br>
&nbsp;&nbsp; e_ply_type value_type<br>
)
</p>
<p class=description>
Adds a new property to the last element added to the ply file.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a> and <tt>name</tt> is the
property name.
<tt>Type</tt> is the property type.
<tt>Length_type</tt> is the scalar type of the first entry
in a list property (the one that gives the number of entries).
<tt>Value_type</tt> is the scalar type of the remaining list entries.
If <tt>type</tt> is not <tt>PLY_LIST</tt>, <tt>length_type</tt> and
<tt>value_type</tt> are ignored.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<p class=note>
Note: <tt>Length_type</tt> and <tt>value_type</tt> can
be any of the constants for scalar types defined in
<tt>e_ply_type</tt>. <tt>Type</tt> can, in addition, be <tt>PLY_LIST</tt>,
in which case the property is a list property and the fields
<tt>length_type</tt> and <tt>value_type</tt> become meaningful.
</p>
<!-- ply_add_list_property ++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_add_list_property>
int <b>ply_add_list_property</b>(<br>
&nbsp;&nbsp; p_ply ply,<br>
&nbsp;&nbsp; const char *name,<br>
&nbsp;&nbsp; e_ply_type length_type,<br>
&nbsp;&nbsp; e_ply_type value_type<br>
)
</p>
<p class=description>
Same as <a href=#ply_add_property><tt>ply_add_property</tt></a> if
<tt>type</tt> is <tt>PLY_LIST</tt>.
</p>
<!-- ply_add_scalar_property +++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_add_scalar_property>
int <b>ply_add_scalar_property</b>(p_ply ply, const char *name, e_ply_type type)
</p>
<p class=description>
Same as <a href=#ply_add_property><tt>ply_add_property</tt></a> if
<tt>type</tt> is <em>not</em> <tt>PLY_LIST</tt>.
</p>
<!-- ply_add_comment +++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_add_comment>
int <b>ply_add_comment</b>(p_ply ply, const char *comment);
</p>
<p class=description>
Adds a comment to a PLY file.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a> and <tt>comment</tt> is the
comment text.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<!-- ply_add_obj_info ++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_add_obj_info>
int <b>ply_add_obj_info</b>(p_ply ply, const char *obj_info);
</p>
<p class=description>
Adds a obj_info to a PLY file.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a> and <tt>obj_info</tt> is the
obj_info text.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<!-- ply_write_header ++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_write_header>
int <b>ply_write_header</b>(p_ply ply);
</p>
<p class=description>
Writes the PLY file header to disk, after all elements, properties,
comments and obj_infos have been added to the handle.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a> and <tt>comment</tt> is the
comment text.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<!-- ply_write +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_write>
int <b>ply_write</b>(p_ply ply, double value);
</p>
<p class=description>
Passes a value to be stored in the PLY file.
Values must be passed in the order they will appear in the file.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a> and <tt>value</tt> is the
value to be stored. For simplicity, values are always passed as
<tt>double</tt> and conversion is performed as needed.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<!-- ply_close +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=ply_close>
int <b>ply_close</b>(p_ply ply);
</p>
<p class=description>
Closes the handle and ensures that all resources have been freed and data
have been written.
</p>
<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a> or by
<a href=#ply_open><tt>ply_open</tt></a>.
</p>
<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>
<!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<div class=footer>
<hr>
<center>
<p>
<small>
Last modified by Diego Nehab on <br>
Fri Jul 16 15:23:01 EDT 2004
</small>
</p>
</center>
</div>
</body>
</html>
+54
View File
@@ -0,0 +1,54 @@
body {
margin-left: 1em;
margin-right: 1em;
font-family: "Verdana", sans-serif;
}
tt {
font-family: "Andale Mono", monospace;
}
h1, h2, h3, h4 { margin-left: 0em; }
h3 { padding-top: 1em; }
p { margin-left: 1em; }
p.name {
font-family: "Andale Mono", monospace;
padding-top: 1em;
margin-left: 0em;
}
a[href] { color: #7f0000; }
blockquote { margin-left: 3em; }
pre.example {
background: #cbb;
padding: 1em;
margin-left: 1em;
font-family: "Andale Mono", monospace;
font-size: small;
}
hr {
margin-left: 0em;
background: #7f0000;
border: 0px;
height: 1px;
}
ul { list-style-type: disc; }
table.index { border: 1px #7f0000; }
table.index td { text-align: left; vertical-align: top; }
table.index ul { padding-top: 0em; margin-top: 0em; }
h1:first-letter,
h2:first-letter,
h2:first-letter,
h3:first-letter { color: #7f0000; }
div.header, div.footer { margin-left: 0em; }
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

+20
View File
@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Rply", "Rply.vcproj", "{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Debug|Win32.ActiveCfg = Debug|Win32
{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Debug|Win32.Build.0 = Debug|Win32
{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Release|Win32.ActiveCfg = Release|Win32
{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
+171
View File
@@ -0,0 +1,171 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="Rply"
ProjectGUID="{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}"
RootNamespace="Rply"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)..\..\lib\vc2008\$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\vc90.pdb"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)..\..\lib\vc2008\$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\vc90.pdb"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\..\rply.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\..\rply.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="9,00"
ShowAllFiles="false"
>
<Configurations>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
Command=""
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="REYNOLDS"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
<Configuration
Name="Release|Win32"
>
<DebugSettings
Command=""
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="REYNOLDS"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>
+20
View File
@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Rply", "Rply.vcproj", "{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Debug|Win32.ActiveCfg = Debug|Win32
{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Debug|Win32.Build.0 = Debug|Win32
{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Release|Win32.ActiveCfg = Release|Win32
{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
+171
View File
@@ -0,0 +1,171 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="Rply"
ProjectGUID="{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}"
RootNamespace="Rply"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)..\lib\$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\vc90.pdb"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)..\lib\$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\vc90.pdb"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\rply.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\rply.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
+82
View File
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\rply.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\rply.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{A1A9B043-929D-4D3A-96F3-9BEF0AA06C7E}</ProjectGuid>
<RootNamespace>Rply</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)..\..\lib\vc2010\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)..\..\lib\vc2010\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<ProgramDataBaseFileName>$(OutDir)vc100.pdb</ProgramDataBaseFileName>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<ProgramDataBaseFileName>$(OutDir)vc100.pdb</ProgramDataBaseFileName>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\rply.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\rply.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
+1497
View File
File diff suppressed because it is too large. Load diff
+365
View File
@@ -0,0 +1,365 @@
#ifndef PLY_H
#define PLY_H
/* ----------------------------------------------------------------------
* RPly library, read/write PLY files
* Diego Nehab, Princeton University
* http://www.cs.princeton.edu/~diego/professional/rply
*
* This library is distributed under the MIT License. See notice
* at the end of this file.
* ---------------------------------------------------------------------- */
#ifdef __cplusplus
extern "C" {
#endif
#define RPLY_VERSION "RPly 1.01"
#define RPLY_COPYRIGHT "Copyright (C) 2003-2005 Diego Nehab"
#define RPLY_AUTHORS "Diego Nehab"
/* ----------------------------------------------------------------------
* Types
* ---------------------------------------------------------------------- */
/* structures are opaque */
typedef struct t_ply_ *p_ply;
typedef struct t_ply_element_ *p_ply_element;
typedef struct t_ply_property_ *p_ply_property;
typedef struct t_ply_argument_ *p_ply_argument;
/* ply format mode type */
typedef enum e_ply_storage_mode_ {
PLY_BIG_ENDIAN,
PLY_LITTLE_ENDIAN,
PLY_ASCII,
PLY_DEFAULT /* has to be the last in enum */
} e_ply_storage_mode; /* order matches ply_storage_mode_list */
/* ply data type */
typedef enum e_ply_type {
PLY_INT8, PLY_UINT8, PLY_INT16, PLY_UINT16,
PLY_INT32, PLY_UIN32, PLY_FLOAT32, PLY_FLOAT64,
PLY_CHAR, PLY_UCHAR, PLY_SHORT, PLY_USHORT,
PLY_INT, PLY_UINT, PLY_FLOAT, PLY_DOUBLE,
PLY_LIST /* has to be the last in enum */
} e_ply_type; /* order matches ply_type_list */
/* ----------------------------------------------------------------------
* Property reading callback prototype
*
* message: error message
* ---------------------------------------------------------------------- */
typedef void (*p_ply_error_cb)(const char *message);
/* ----------------------------------------------------------------------
* Opens a ply file for reading (fails if file is not a ply file)
*
* error_cb: error callback function
* name: file name
*
* Returns 1 if successful, 0 otherwise
* ---------------------------------------------------------------------- */
p_ply ply_open(const char *name, p_ply_error_cb error_cb);
/* ----------------------------------------------------------------------
* Reads and parses the header of a ply file returned by ply_open
*
* ply: handle returned by ply_open
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_read_header(p_ply ply);
/* ----------------------------------------------------------------------
* Property reading callback prototype
*
* argument: parameters for property being processed when callback is called
*
* Returns 1 if should continue processing file, 0 if should abort.
* ---------------------------------------------------------------------- */
typedef int (*p_ply_read_cb)(p_ply_argument argument);
/* ----------------------------------------------------------------------
* Sets up callbacks for property reading after header was parsed
*
* ply: handle returned by ply_open
* element_name: element where property is
* property_name: property to associate element with
* read_cb: function to be called for each property value
* pdata/idata: user data that will be passed to callback
*
* Returns 0 if no element or no property in element, returns the
* number of element instances otherwise.
* ---------------------------------------------------------------------- */
long ply_set_read_cb(p_ply ply, const char *element_name,
const char *property_name, p_ply_read_cb read_cb,
void *pdata, long idata);
/* ----------------------------------------------------------------------
* Returns information about the element originating a callback
*
* argument: handle to argument
* element: receives a the element handle (if non-null)
* instance_index: receives the index of the current element instance
* (if non-null)
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_get_argument_element(p_ply_argument argument,
p_ply_element *element, long *instance_index);
/* ----------------------------------------------------------------------
* Returns information about the property originating a callback
*
* argument: handle to argument
* property: receives the property handle (if non-null)
* length: receives the number of values in this property (if non-null)
* value_index: receives the index of current property value (if non-null)
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_get_argument_property(p_ply_argument argument,
p_ply_property *property, long *length, long *value_index);
/* ----------------------------------------------------------------------
* Returns user data associated with callback
*
* pdata: receives a copy of user custom data pointer (if non-null)
* idata: receives a copy of user custom data integer (if non-null)
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_get_argument_user_data(p_ply_argument argument, void **pdata,
long *idata);
/* ----------------------------------------------------------------------
* Returns the value associated with a callback
*
* argument: handle to argument
*
* Returns the current data item
* ---------------------------------------------------------------------- */
double ply_get_argument_value(p_ply_argument argument);
/* ----------------------------------------------------------------------
* Reads all elements and properties calling the callbacks defined with
* calls to ply_set_read_cb
*
* ply: handle returned by ply_open
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_read(p_ply ply);
/* ----------------------------------------------------------------------
* Iterates over all elements by returning the next element.
* Call with NULL to return handle to first element.
*
* ply: handle returned by ply_open
* last: handle of last element returned (NULL for first element)
*
* Returns element if successfull or NULL if no more elements
* ---------------------------------------------------------------------- */
p_ply_element ply_get_next_element(p_ply ply, p_ply_element last);
/* ----------------------------------------------------------------------
* Iterates over all comments by returning the next comment.
* Call with NULL to return pointer to first comment.
*
* ply: handle returned by ply_open
* last: pointer to last comment returned (NULL for first comment)
*
* Returns comment if successfull or NULL if no more comments
* ---------------------------------------------------------------------- */
const char *ply_get_next_comment(p_ply ply, const char *last);
/* ----------------------------------------------------------------------
* Iterates over all obj_infos by returning the next obj_info.
* Call with NULL to return pointer to first obj_info.
*
* ply: handle returned by ply_open
* last: pointer to last obj_info returned (NULL for first obj_info)
*
* Returns obj_info if successfull or NULL if no more obj_infos
* ---------------------------------------------------------------------- */
const char *ply_get_next_obj_info(p_ply ply, const char *last);
/* ----------------------------------------------------------------------
* Returns information about an element
*
* element: element of interest
* name: receives a pointer to internal copy of element name (if non-null)
* ninstances: receives the number of instances of this element (if non-null)
*
* Returns 1 if successfull or 0 otherwise
* ---------------------------------------------------------------------- */
int ply_get_element_info(p_ply_element element, const char** name,
long *ninstances);
/* ----------------------------------------------------------------------
* Iterates over all properties by returning the next property.
* Call with NULL to return handle to first property.
*
* element: handle of element with the properties of interest
* last: handle of last property returned (NULL for first property)
*
* Returns element if successfull or NULL if no more properties
* ---------------------------------------------------------------------- */
p_ply_property ply_get_next_property(p_ply_element element,
p_ply_property last);
/* ----------------------------------------------------------------------
* Returns information about a property
*
* property: handle to property of interest
* name: receives a pointer to internal copy of property name (if non-null)
* type: receives the property type (if non-null)
* length_type: for list properties, receives the scalar type of
* the length field (if non-null)
* value_type: for list properties, receives the scalar type of the value
* fields (if non-null)
*
* Returns 1 if successfull or 0 otherwise
* ---------------------------------------------------------------------- */
int ply_get_property_info(p_ply_property property, const char** name,
e_ply_type *type, e_ply_type *length_type, e_ply_type *value_type);
/* ----------------------------------------------------------------------
* Creates new ply file
*
* name: file name
* storage_mode: file format mode
*
* Returns handle to ply file if successfull, NULL otherwise
* ---------------------------------------------------------------------- */
p_ply ply_create(const char *name, e_ply_storage_mode storage_mode,
p_ply_error_cb error_cb);
/* ----------------------------------------------------------------------
* Adds a new element to the ply file created by ply_create
*
* ply: handle returned by ply_create
* name: name of new element
* ninstances: number of element of this time in file
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_add_element(p_ply ply, const char *name, long ninstances);
/* ----------------------------------------------------------------------
* Adds a new property to the last element added by ply_add_element
*
* ply: handle returned by ply_create
* name: name of new property
* type: property type
* length_type: scalar type of length field of a list property
* value_type: scalar type of value fields of a list property
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_add_property(p_ply ply, const char *name, e_ply_type type,
e_ply_type length_type, e_ply_type value_type);
/* ----------------------------------------------------------------------
* Adds a new list property to the last element added by ply_add_element
*
* ply: handle returned by ply_create
* name: name of new property
* length_type: scalar type of length field of a list property
* value_type: scalar type of value fields of a list property
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_add_list_property(p_ply ply, const char *name,
e_ply_type length_type, e_ply_type value_type);
/* ----------------------------------------------------------------------
* Adds a new property to the last element added by ply_add_element
*
* ply: handle returned by ply_create
* name: name of new property
* type: property type
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_add_scalar_property(p_ply ply, const char *name, e_ply_type type);
/* ----------------------------------------------------------------------
* Adds a new comment item
*
* ply: handle returned by ply_create
* comment: pointer to string with comment text
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_add_comment(p_ply ply, const char *comment);
/* ----------------------------------------------------------------------
* Adds a new obj_info item
*
* ply: handle returned by ply_create
* comment: pointer to string with obj_info data
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_add_obj_info(p_ply ply, const char *obj_info);
/* ----------------------------------------------------------------------
* Writes the ply file header after all element and properties have been
* defined by calls to ply_add_element and ply_add_property
*
* ply: handle returned by ply_create
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_write_header(p_ply ply);
/* ----------------------------------------------------------------------
* Writes one property value, in the order they should be written to the
* file. For each element type, write all elements of that type in order.
* For each element, write all its properties in order. For scalar
* properties, just write the value. For list properties, write the length
* and then each of the values.
*
* ply: handle returned by ply_create
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_write(p_ply ply, double value);
/* ----------------------------------------------------------------------
* Closes a ply file handle. Releases all memory used by handle
*
* ply: handle to be closed.
*
* Returns 1 if successfull, 0 otherwise
* ---------------------------------------------------------------------- */
int ply_close(p_ply ply);
#ifdef __cplusplus
}
#endif
#endif /* RPLY_H */
/* ----------------------------------------------------------------------
* Copyright (C) 2003-2005 Diego Nehab. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* ---------------------------------------------------------------------- */