/*
The interface routines for reading and writing PLY polygon files.
Greg Turk, February 1994
---------------------------------------------------------------
A PLY file contains a single polygonal _object_.
An object is composed of lists of _elements_. Typical elements are
vertices, faces, edges and materials.
Each type of element for a given object has one or more _properties_
associated with the element type. For instance, a vertex element may
have as properties the floating-point values x,y,z and the three unsigned
chars representing red, green and blue.
---------------------------------------------------------------
Copyright (c) 1994 The Board of Trustees of The Leland Stanford
Junior University. All rights reserved.
Permission to use, copy, modify and distribute this software and its
documentation for any purpose is hereby granted without fee, provided
that the above copyright notice and this permission notice appear in
all copies of this software and that you do not sell the software.
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*/
//#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "ply.h"
char *type_names[] = {
"invalid",
"char", "short", "int",
"uchar", "ushort", "uint",
"float", "double",
};
int ply_type_size[] = {
0, 1, 2, 4, 1, 2, 4, 4, 8
};
#define NO_OTHER_PROPS -1
#define DONT_STORE_PROP 0
#define STORE_PROP 1
#define OTHER_PROP 0
#define NAMED_PROP 1
/* returns 1 if strings are equal, 0 if not */
int equal_strings(char *, char *);
/* find an element in a plyfile's list */
PlyElement *find_element(PlyFile *, char *);
/* find a property in an element's list */
PlyProperty *find_property(PlyElement *, char *, int *);
/* write to a file the word describing a PLY file data type */
void write_scalar_type (FILE *, int);
/* read a line from a file and break it up into separate words */
char **get_words(FILE *, int *, char **);
char **old_get_words(FILE *, int *);
/* write an item to a file */
void write_binary_item(FILE *, int, unsigned int, double, int);
void write_ascii_item(FILE *, int, unsigned int, double, int);
double old_write_ascii_item(FILE *, char *, int);
/* add information to a PLY file descriptor */
void add_element(PlyFile *, char **, int);
int get_prop_type(char *);
void add_property(PlyFile *, char **, int);
void add_comment(PlyFile *, char *);
void add_obj_info(PlyFile *, char *);
/* copy a property */
void copy_property(PlyProperty *, PlyProperty *);
/* store a value into where a pointer and a type specify */
void store_item(char *, int, int, unsigned int, double);
/* return the value of a stored item */
void get_stored_item( void *, int, int *, unsigned int *, double *);
/* return the value stored in an item, given ptr to it and its type */
double get_item_value(char *, int);
/* get binary or ascii item and store it according to ptr and type */
void get_ascii_item(char *, int, int *, unsigned int *, double *);
void get_binary_item(FILE *, int, int *, unsigned int *, double *);
/* get a bunch of elements from a file */
void ascii_get_element(PlyFile *, char *);
void binary_get_element(PlyFile *, char *);
/* memory allocation */
static char *my_alloc(int, int, char *); // static added 4/3/2005
/*************/
/* Writing */
/*************/
/******************************************************************************
Given a file pointer, get ready to write PLY data to the file.
Entry:
fp - the given file pointer
nelems - number of elements in object
elem_names - list of element names
file_type - file type, either ascii or binary
Exit:
returns a pointer to a PlyFile, used to refer to this file, or NULL if error
******************************************************************************/
PlyFile *ply_write(
FILE *fp,
int nelems,
char **elem_names,
int file_type
)
{
int i;
PlyFile *plyfile;
PlyElement *elem;
/* check for NULL file pointer */
if (fp == NULL)
return (NULL);
/* create a record for this object */
plyfile = (PlyFile *) myalloc (sizeof (PlyFile));
plyfile->file_type = file_type;
plyfile->num_comments = 0;
plyfile->num_obj_info = 0;
plyfile->nelems = nelems;
plyfile->version = 1.0;
plyfile->fp = fp;
plyfile->other_elems = NULL;
/* tuck aside the names of the elements */
plyfile->elems = (PlyElement **) myalloc (sizeof (PlyElement *) * nelems);
for (i = 0; i < nelems; i++) {
elem = (PlyElement *) myalloc (sizeof (PlyElement));
plyfile->elems[i] = elem;
elem->name = (char* )strdup (elem_names[i]); /* added (char* ) cast 3/2/2005 */
elem->num = 0;
elem->nprops = 0;
}
/* return pointer to the file descriptor */
return (plyfile);
}
/******************************************************************************
Open a polygon file for writing.
Entry:
filename - name of file to read from
nelems - number of elements in object
elem_names - list of element names
file_type - file type, either ascii or binary
Exit:
version - version number of PLY file
returns a file identifier, used to refer to this file, or NULL if error
******************************************************************************/
PlyFile *ply_open_for_writing(
char *filename,
int nelems,
char **elem_names,
int file_type,
float *version
)
{
int i;
PlyFile *plyfile;
PlyElement *elem;
char *name;
FILE *fp;
/* tack on the extension .ply, if necessary */
name = (char *) myalloc (sizeof (char) * (strlen (filename) + 5));
strcpy (name, filename);
if (strlen (name) < 4 ||
strcmp (name + strlen (name) - 4, ".ply") != 0)
strcat (name, ".ply");
/* open the file for writing */
fp = fopen (name, "w");
if (fp == NULL) {
return (NULL);
}
/* create the actual PlyFile structure */
plyfile = ply_write (fp, nelems, elem_names, file_type);
if (plyfile == NULL)
return (NULL);
/* say what PLY file version number we're writing */
*version = plyfile->version;
/* return pointer to the file descriptor */
return (plyfile);
}
/******************************************************************************
Describe an element, including its properties and how many will be written
to the file.
Entry:
plyfile - file identifier
elem_name - name of element that information is being specified about
nelems - number of elements of this type to be written
nprops - number of properties contained in the element
prop_list - list of properties
******************************************************************************/
void ply_describe_element(
PlyFile *plyfile,
char *elem_name,
int nelems,
int nprops,
PlyProperty *prop_list
)
{
int i;
PlyElement *elem;
PlyProperty *prop;
/* look for appropriate element */
elem = find_element (plyfile, elem_name);
if (elem == NULL) {
fprintf(stderr,"ply_describe_element: can't find element '%s'\n",elem_name);
exit (-1);
}
elem->num = nelems;
/* copy the list of properties */
elem->nprops = nprops;
elem->props = (PlyProperty **) myalloc (sizeof (PlyProperty *) * nprops);
elem->store_prop = (char *) myalloc (sizeof (char) * nprops);
for (i = 0; i < nprops; i++) {
prop = (PlyProperty *) myalloc (sizeof (PlyProperty));
elem->props[i] = prop;
elem->store_prop[i] = NAMED_PROP;
copy_property (prop, &prop_list[i]);
}
}
/******************************************************************************
Describe a property o
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
raytracegroundup_v1.9_PLY_20170310 程序导入了各种经典的PLY文件(hand skeleton, stanford bunny, horse, goldfish, happy buddha, and dragon)。 同时,为图形添加了光源和阴影。 内含各种测试图形。
资源推荐
资源详情
资源评论
收起资源包目录
raytracegroundup_v1.9_PLY_20170310 (187个子文件)
hand_from25,10,25_at1,1,0_400,400.bmp 469KB
hand----13,10,10.bmp 469KB
goldfish_high_res_from75,20,80_at-0.05,-0.5,0_400,400.bmp 469KB
goldfish_low_res_from75,20,80_at-0.05,-0.5,0_400,400.bmp 469KB
Bunny69K_from0,0.1,2_at0,0.1,0_300,300.bmp 264KB
dragon_from0,0.1,2_at0,0.1,0_300,300.bmp 264KB
Horse97K_from0,0.1,6_at0,0.1,0_300,300.bmp 264KB
happy_from0,0.1,2_at0,0.1,0_300,300.bmp 264KB
ply.c 71KB
raytracegroundup.cbp 5KB
Grid.cpp 36KB
BuildShadedObjects.cpp 15KB
Instance.cpp 12KB
Sampler.cpp 9KB
Maths.cpp 5KB
MeshTriangle.cpp 5KB
Rectangle.cpp 5KB
SmoothTriangle.cpp 4KB
Triangle.cpp 4KB
Sphere.cpp 4KB
MultiJittered.cpp 4KB
FlatMeshTriangle.cpp 4KB
Compound.cpp 4KB
OpenCylinder.cpp 4KB
Phong.cpp 3KB
AreaLight.cpp 3KB
Vector3D.cpp 3KB
GlossySpecular.cpp 3KB
World.cpp 3KB
SmoothMeshTriangle.cpp 3KB
BBox.cpp 3KB
Matte.cpp 3KB
Normal.cpp 3KB
Disk.cpp 3KB
Pinhole.cpp 3KB
Matrix.cpp 3KB
AmbientOccluder.cpp 2KB
GeometricObject.cpp 2KB
PointLight.cpp 2KB
Point3D.cpp 2KB
Camera.cpp 2KB
Plane.cpp 2KB
RGBColor.cpp 2KB
AreaLighting.cpp 1KB
Directional.cpp 1KB
Lambertian.cpp 1KB
BRDF.cpp 1KB
Ambient.cpp 1KB
RayCast.cpp 1KB
Mesh.cpp 1KB
Emissive.cpp 1KB
ViewPlane.cpp 1KB
Light.cpp 1KB
ShadeRec.cpp 1KB
Point2D.cpp 1KB
Ray.cpp 1KB
Material.cpp 1KB
Tracer.cpp 826B
main.cpp 162B
raytracegroundup.depend 17KB
raytracegroundup.exe 3.6MB
ply.h 7KB
Vector3D.h 5KB
Normal.h 4KB
RGBColor.h 4KB
Point3D.h 3KB
Grid.h 3KB
Camera.h 3KB
World.h 3KB
Maths.h 2KB
PointLight.h 2KB
Phong.h 2KB
ViewPlane.h 2KB
Sampler.h 2KB
MeshTriangle.h 2KB
Directional.h 2KB
GlossySpecular.h 2KB
Instance.h 2KB
Sphere.h 2KB
AmbientOccluder.h 2KB
Matte.h 2KB
AreaLight.h 2KB
GeometricObject.h 2KB
Lambertian.h 2KB
Rectangle.h 2KB
SmoothTriangle.h 1KB
Ambient.h 1KB
Emissive.h 1KB
Compound.h 1KB
Mesh.h 1KB
OpenCylinder.h 1KB
Pinhole.h 1KB
Matrix.h 1KB
ShadeRec.h 1KB
SmoothMeshTriangle.h 1KB
Disk.h 1KB
FlatMeshTriangle.h 1023B
Plane.h 996B
Triangle.h 986B
Light.h 850B
共 187 条
- 1
- 2
资源评论
图形跟班
- 粉丝: 930
- 资源: 50
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功