/*
The interface routines for reading and writing PLY polygon files.
Greg Turk
---------------------------------------------------------------
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) 1998 Georgia Institute of Technology. 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 <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "ply.h"
char *type_names[] = { /* names of scalar types */
"invalid",
"int8", "int16", "int32", "uint8", "uint16", "uint32", "float32", "float64",
};
char *old_type_names[] = { /* old names of types for backward compatability */
"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 **);
/* 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);
/* add information to a PLY file descriptor */
void add_element(PlyFile *, char **, int);
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 *);
/*************/
/* 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->num_elem_types = 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 = strdup (elem_names[i]);
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:
returns a file identifier, used to refer to this file, or NULL if error
******************************************************************************/
PlyFile *open_for_writing_ply(
char *filename,
int nelems,
char **elem_names,
int file_type
)
{
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);
/* 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 element_layout_ply(
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,"element_layout_ply: 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 of an element.
Entry:
plyfile - file identifier
elem_name - name of element that information is being specified about
prop - the new property
******************************************************************************/
void ply_describe_property(
PlyFile *plyfile,
char *elem_name,
PlyProperty *prop
)
{
PlyElement *elem;
PlyProperty *elem_prop;
/* look for appropriate element */
elem = find_element (plyfile, elem_na
没有合适的资源?快使用搜索试试~ 我知道了~
toolbox_fast_marching.zip_fast marching_level set
共385个文件
m:120个
h:94个
cpp:49个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 152 浏览量
2022-07-15
02:47:21
上传
评论
收藏 1.37MB ZIP 举报
温馨提示
在MATLAB环境下的level set方法的实现,可以应用在多种领域中
资源详情
资源评论
资源推荐
收起资源包目录
toolbox_fast_marching.zip_fast marching_level set (385个子文件)
ply.c 87KB
eucdist2.c 9KB
plytest.c 8KB
use.c 2KB
fibtest.c 2KB
fibtest2.c 2KB
tt.c 1KB
copying 18KB
copyright 808B
plyfile.cpp 69KB
GW_Parameterization.cpp 49KB
GW_VoronoiMesh.cpp 48KB
GW_Mesh.cpp 29KB
trackball.cpp 19KB
GW_Vertex.cpp 18KB
GW_Toolkit.cpp 17KB
GW_TriangularInterpolation_Cubic.cpp 15KB
GW_BasicDisplayer.cpp 14KB
GW_GeodesicDisplayer.cpp 14KB
fib.cpp 12KB
skeleton.cpp 12KB
GW_GeodesicPath.cpp 12KB
gcm_mimg.cpp 11KB
GW_PLYLoader.cpp 11KB
perform_front_propagation_3d - copie.cpp 11KB
GW_ASELoader.cpp 10KB
gcm.cpp 10KB
GW_TriangularInterpolation_Quadratic.cpp 9KB
perform_front_propagation_2d.cpp 9KB
GW_GeometryAtlas.cpp 9KB
perform_front_propagation_3d.cpp 9KB
perform_front_propagation_3d_old.cpp 8KB
perform_front_propagation_mesh.cpp 7KB
GW_VertexIterator.cpp 6KB
GW_OBJLoader.cpp 6KB
GW_GeodesicMesh.cpp 5KB
GW_VRMLLoader.cpp 5KB
GW_GeodesicVertex.cpp 5KB
GW_FaceIterator.cpp 4KB
GW_OFFLoader.cpp 4KB
GW_GeodesicFace.cpp 4KB
GW_TriangularInterpolation_Linear.cpp 4KB
perform_front_propagation_3d_mex.cpp 3KB
perform_front_propagation_2d_mex.cpp 3KB
GW_VoronoiVertex.cpp 3KB
perform_circular_front_propagation_2d.cpp 3KB
perform_front_propagation_anisotropic.cpp 2KB
GW_SmartCounter.cpp 2KB
GW_Face.cpp 2KB
GW_GeometryCell.cpp 2KB
GW_InputOutput.cpp 2KB
GW_GeodesicPoint.cpp 2KB
main.cpp 1KB
GW_Config.cpp 1KB
stdafx.cpp 203B
stdafx.cpp 203B
stdafx.cpp 203B
GW_TriangularInterpolation.cpp 14B
perform_circular_front_propagation_2d.def 72B
perform_front_propagation_mesh.def 65B
perform_front_propagation_3d.def 63B
perform_front_propagation_2d.def 63B
perform_front_propagation_3d.dll 60KB
perform_front_propagation_2d.dll 59KB
perform_circular_front_propagation_2d.dll 59KB
skeleton.dll 55KB
eucdist2.dll 49KB
.DS_Store 21KB
.DS_Store 15KB
.DS_Store 15KB
.DS_Store 12KB
.DS_Store 12KB
.DS_Store 12KB
.DS_Store 12KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
Entries 3KB
Entries 1KB
Entries 1KB
Entries 1KB
Entries 872B
Entries 772B
Entries 563B
Entries 184B
Entries 90B
Entries.Extra 505B
Entries.Extra 252B
camel.gif 619B
giraffe.gif 595B
chicken.gif 555B
apple.gif 480B
GW_MatrixStatic.h 29KB
jama_eig.h 29KB
AnisotropicTensorDistance.h 28KB
GW_MatrixNxP.h 24KB
FastMarching.h 20KB
共 385 条
- 1
- 2
- 3
- 4
四散
- 粉丝: 49
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0