📄 xdr_cptc_geo.c
字号:
#include "GeoFmt.h"
#include "cptc_geomsh_utils.h"
#include <stdio.h>
/* -------------------------------------------------------------------- */
bool_t xdr_Cptc_ID_type(XDR* xdrs, Cptc_ID_type* id_p)
{
Cptc_ID_type id;
unsigned int stringlen;
if (xdrs->x_op == XDR_ENCODE && id_p != 0 && *id_p != 0) {
stringlen = strlen(*id_p);
}
else {
stringlen = 0;
}
if (!xdr_u_int(xdrs, &stringlen)) return (FALSE);
if (xdrs->x_op == XDR_DECODE) {
if (stringlen != 0) {
id = (Cptc_ID_type) cptc_malloc ((stringlen+1) * sizeof(char));
}
else {
id = 0;
}
}
else {
id = *id_p;
}
if (!xdr_string(xdrs, &id, stringlen)) return (FALSE);
if (xdrs->x_op == XDR_DECODE) {
*id_p = id;
}
return (TRUE);
}
/* -------------------------------------------------------------------- */
bool_t xdr_Cptc_properties(XDR* xdrs, int* num_properties_p,
char ***props_p, char ***values_p)
{
int i;
unsigned int stringlen;
int num_properties = *num_properties_p;
char **props;
char **values;
if (!xdr_int(xdrs, &num_properties)) return (FALSE);
if (xdrs->x_op == XDR_DECODE) {
props = (char **)cptc_malloc(num_properties * sizeof(char *)) ;
values = (char **)cptc_malloc(num_properties * sizeof(char *)) ;
for (i = 0; i < num_properties; i++) props[i] = values[i] = 0;
}
else {
props = *props_p;
values = *values_p;
}
/* props */
for (i = 0; i < num_properties; i++) {
if (props[i] != 0) stringlen = strlen(props[i]);
else stringlen = 0;
if (!xdr_u_int(xdrs, &stringlen)) return (FALSE);
if (xdrs->x_op == XDR_DECODE && stringlen != 0) {
props[i] = (char *) cptc_malloc ((stringlen+1) * sizeof(char));
}
if (!xdr_string(xdrs, &props[i], stringlen)) return (FALSE);
}
/* values */
for (i = 0; i < num_properties; i++) {
if (values[i] != 0) stringlen = strlen(values[i]);
else stringlen = 0;
if (!xdr_u_int(xdrs, &stringlen)) return (FALSE);
if (xdrs->x_op == XDR_DECODE && stringlen != 0)
values[i] = (char *) cptc_malloc ((stringlen+1) * sizeof(char));
if (!xdr_string(xdrs, &values[i], stringlen)) return (FALSE);
}
if (xdrs->x_op == XDR_DECODE) {
*num_properties_p = num_properties;
*props_p = props;
*values_p = values;
}
return (TRUE);
}
/* -------------------------------------------------------------------- */
bool_t __xdr_Cptc_GPoint(XDR* xdrs, Cptc_GPoint* g_p)
{
if (!xdr_double(xdrs, &g_p->coord[0])) return (FALSE);
if (!xdr_double(xdrs, &g_p->coord[1])) return (FALSE);
if (!xdr_double(xdrs, &g_p->coord[2])) return (FALSE);
return (TRUE);
}
bool_t xdr_Cptc_GPoint_vector(XDR* xdrs, Cptc_GPoint** g_p, int num_points)
{
int i;
Cptc_GPoint *g;
if (xdrs->x_op == XDR_DECODE) {
g = (Cptc_GPoint *)cptc_malloc(num_points*sizeof(Cptc_GPoint));
}
else {
g = *g_p;
}
for (i = 0; i < num_points; i++) {
if (!__xdr_Cptc_GPoint(xdrs, &g[i])) return (FALSE);
}
if (xdrs->x_op == XDR_DECODE) {
*g_p = g;
}
return (TRUE);
}
/* -------------------------------------------------------------------- */
bool_t __xdr_Cptc_GCurve(XDR* xdrs, Cptc_GCurve* g_p)
{
if (!xdr_int(xdrs, &g_p->order))
return (FALSE);
if (!xdr_int_vector(xdrs, &g_p->control_pnt_indx, g_p->order+1))
return (FALSE);
return (TRUE);
}
bool_t xdr_Cptc_GCurve_vector(XDR* xdrs, Cptc_GCurve** g_p, int num_curves)
{
int i;
Cptc_GCurve *g;
if (xdrs->x_op == XDR_DECODE) {
g = (Cptc_GCurve *)cptc_malloc(num_curves*sizeof(Cptc_GCurve));
}
else {
g = *g_p;
}
for (i = 0; i < num_curves; i++) {
if (!__xdr_Cptc_GCurve(xdrs, &g[i])) return (FALSE);
}
if (xdrs->x_op == XDR_DECODE) {
*g_p = g;
}
return (TRUE);
}
/* -------------------------------------------------------------------- */
bool_t __xdr_Cptc_GPatch(XDR* xdrs, Cptc_GPatch* g)
{
int num;
if (!xdr_int(xdrs, &g->type))
return (FALSE);
if (!xdr_int(xdrs, &g->order_u))
return (FALSE);
if (!xdr_int(xdrs, &g->order_v))
return (FALSE);
if (g->type == CPTC_PATCHTYPE_TRIANGLE) {
num = (g->order_u+1) * (g->order_u+2)/2 ;
}
else {
num = (g->order_u+1) * (g->order_v+1) ;
}
if (!xdr_int_vector(xdrs, &g->control_pnt_indx, num))
return (FALSE);
return (TRUE);
}
bool_t xdr_Cptc_GPatch_vector(XDR* xdrs, Cptc_GPatch** g_p, int num_patches)
{
int i;
Cptc_GPatch *g;
if (xdrs->x_op == XDR_DECODE) {
g = (Cptc_GPatch *)cptc_malloc(num_patches*sizeof(Cptc_GPatch));
}
else {
g = *g_p;
}
for (i = 0; i < num_patches; i++) {
if (!__xdr_Cptc_GPatch(xdrs, &g[i])) return (FALSE);
}
if (xdrs->x_op == XDR_DECODE) {
*g_p = g;
}
return (TRUE);
}
/* -------------------------------------------------------------------- */
bool_t __xdr_Cptc_TVertex(XDR* xdrs, Cptc_TVertex* t)
{
int i;
/* id */
if (xdrs->x_op == XDR_DECODE) t->id = 0;
if (!xdr_Cptc_ID_type(xdrs, &t->id)) return (FALSE);
/* control_pnt_indx */
if (xdrs->x_op == XDR_DECODE) t->num_properties = 0;
if (!xdr_int(xdrs, &t->control_pnt_indx)) return (FALSE);
/* properties */
if (xdrs->x_op == XDR_DECODE) t->num_properties = 0;
if (!xdr_Cptc_properties(xdrs, &t->num_properties, &t->props, &t->values))
return (FALSE);
return (TRUE);
}
bool_t xdr_Cptc_TVertex_vector(XDR* xdrs, Cptc_TVertex** t_p, int num_vertices)
{
int i;
Cptc_TVertex *t;
if (xdrs->x_op == XDR_DECODE) {
t = (Cptc_TVertex *)cptc_malloc(num_vertices*sizeof(Cptc_TVertex));
}
else {
t = *t_p;
}
for (i = 0; i < num_vertices; i++) {
if (!__xdr_Cptc_TVertex(xdrs, &t[i])) return (FALSE);
}
if (xdrs->x_op == XDR_DECODE) {
*t_p = t;
}
return (TRUE);
}
/* -------------------------------------------------------------------- */
bool_t __xdr_Cptc_TEdge(XDR* xdrs, Cptc_TEdge* t)
{
int i;
/* id */
if (xdrs->x_op == XDR_DECODE) t->id = 0;
if (!xdr_Cptc_ID_type(xdrs, &t->id)) return (FALSE);
/* curve information */
if (!xdr_int(xdrs, &t->num_curves))
return (FALSE);
if (!xdr_Cptc_GCurve_vector(xdrs, &t->curves, t->num_curves))
return (FALSE);
/* vertex information */
if (!xdr_int(xdrs, &t->num_bound_vertices))
return (FALSE);
if (!xdr_int_vector(xdrs, &t->bound_vertices, t->num_bound_vertices))
return (FALSE);
/* properties */
if (!xdr_Cptc_properties(xdrs, &t->num_properties, &t->props, &t->values))
return (FALSE);
return (TRUE);
}
bool_t xdr_Cptc_TEdge_vector(XDR* xdrs, Cptc_TEdge** t_p, int num_edges)
{
int i;
Cptc_TEdge *t;
if (xdrs->x_op == XDR_DECODE) {
t = (Cptc_TEdge *)cptc_malloc(num_edges*sizeof(Cptc_TEdge));
}
else {
t = *t_p;
}
for (i = 0; i < num_edges; i++) {
if (!__xdr_Cptc_TEdge(xdrs, &t[i])) return (FALSE);
}
if (xdrs->x_op == XDR_DECODE) {
*t_p = t;
}
return (TRUE);
}
/* -------------------------------------------------------------------- */
bool_t __xdr_Cptc_TSurface(XDR* xdrs, Cptc_TSurface* t)
{
int i;
/* id */
if (xdrs->x_op == XDR_DECODE) t->id = 0;
if (!xdr_Cptc_ID_type(xdrs, &t->id)) return (FALSE);
/* patch information */
if (!xdr_int(xdrs, &t->num_patches))
return (FALSE);
if (!xdr_Cptc_GPatch_vector(xdrs, &t->patches, t->num_patches))
return (FALSE);
/* edge information */
if (!xdr_int(xdrs, &t->num_bound_edges))
return (FALSE);
if (!xdr_int_vector(xdrs, &t->bound_edges, t->num_bound_edges))
return (FALSE);
/* vertex information */
if (!xdr_int(xdrs, &t->num_bound_vertices))
return (FALSE);
if (!xdr_int_vector(xdrs, &t->bound_vertices, t->num_bound_vertices))
return (FALSE);
/* properties */
if (!xdr_Cptc_properties(xdrs, &t->num_properties, &t->props, &t->values))
return (FALSE);
return (TRUE);
}
bool_t xdr_Cptc_TSurface_vector(XDR* xdrs, Cptc_TSurface** t_p, int num_surfaces)
{
int i;
Cptc_TSurface *t;
if (xdrs->x_op == XDR_DECODE) {
t = (Cptc_TSurface *)cptc_malloc(num_surfaces*sizeof(Cptc_TSurface));
}
else {
t = *t_p;
}
for (i = 0; i < num_surfaces; i++) {
if (!__xdr_Cptc_TSurface(xdrs, &t[i])) return (FALSE);
}
if (xdrs->x_op == XDR_DECODE) {
*t_p = t;
}
return (TRUE);
}
/* -------------------------------------------------------------------- */
bool_t __xdr_Cptc_TRegion(XDR* xdrs, Cptc_TRegion* t)
{
int i;
/* id */
if (xdrs->x_op == XDR_DECODE) t->id = 0;
if (!xdr_Cptc_ID_type(xdrs, &t->id)) return (FALSE);
/* surface information */
if (!xdr_int(xdrs, &t->num_bound_surfaces))
return (FALSE);
if (!xdr_int_vector(xdrs, &t->bound_surfaces, t->num_bound_surfaces))
return (FALSE);
if (!xdr_int_vector(xdrs, &t->surface_orientation, t->num_bound_surfaces))
return (FALSE);
/* edge information */
if (!xdr_int(xdrs, &t->num_bound_edges))
return (FALSE);
if (!xdr_int_vector(xdrs, &t->bound_edges, t->num_bound_edges))
return (FALSE);
/* vertex information */
if (!xdr_int(xdrs, &t->num_bound_vertices))
return (FALSE);
if (!xdr_int_vector(xdrs, &t->bound_vertices, t->num_bound_vertices))
return (FALSE);
/* properties */
if (!xdr_Cptc_properties(xdrs, &t->num_properties, &t->props, &t->values))
return (FALSE);
return (TRUE);
}
bool_t xdr_Cptc_TRegion_vector(XDR* xdrs, Cptc_TRegion** t_p, int num_regions)
{
int i;
Cptc_TRegion *t;
if (xdrs->x_op == XDR_DECODE) {
t = (Cptc_TRegion *)cptc_malloc(num_regions*sizeof(Cptc_TRegion));
}
else {
t = *t_p;
}
for (i = 0; i < num_regions; i++) {
if (!__xdr_Cptc_TRegion(xdrs, &t[i])) return (FALSE);
}
if (xdrs->x_op == XDR_DECODE) {
*t_p = t;
}
return (TRUE);
}
/* -------------------------------------------------------------------- */
bool_t xdr_Cptc_GeomDesc(XDR* xdrs, Cptc_GeomDesc** geop)
{
int i;
Cptc_GeomDesc *geo;
if (xdrs->x_op == XDR_DECODE) {
geo = (Cptc_GeomDesc *)cptc_malloc(sizeof(Cptc_GeomDesc)) ;
}
else {
geo = *geop;
}
/* dimensionality information */
if (!xdr_int(xdrs, &geo->intrinsic_dimension))
return (FALSE);
if (!xdr_int(xdrs, &geo->embedded_dimension))
return (FALSE);
/* Cptc_GeomDesc properties */
if (!xdr_Cptc_properties(xdrs, &geo->num_properties,
&geo->props, &geo->values))
return (FALSE);
/* count information */
/* ----------------- */
/* control points */
if (!xdr_int(xdrs, &geo->num_control_pts))
return (FALSE);
/* vertices */
if (!xdr_int(xdrs, &geo->num_top_vertices))
return (FALSE);
/* edges */
if (!xdr_int(xdrs, &geo->num_top_edges))
return (FALSE);
/* surfaces */
if (!xdr_int(xdrs, &geo->num_top_surfaces))
return (FALSE);
/* regions */
if (!xdr_int(xdrs, &geo->num_top_regions))
return (FALSE);
/* data */
/* ---- */
/* control points */
if (!xdr_Cptc_GPoint_vector(xdrs, &geo->control_points,
geo->num_control_pts))
return (FALSE);
/* vertices */
if (!xdr_Cptc_TVertex_vector(xdrs, &geo->top_vertices,
geo->num_top_vertices))
return (FALSE);
/* edges */
if (!xdr_Cptc_TEdge_vector(xdrs, &geo->top_edges,
geo->num_top_edges))
return (FALSE);
/* surfaces */
if (!xdr_Cptc_TSurface_vector(xdrs, &geo->top_surfaces,
geo->num_top_surfaces))
return (FALSE);
/* regions */
if (!xdr_Cptc_TRegion_vector(xdrs, &geo->top_regions,
geo->num_top_regions))
return (FALSE);
if (xdrs->x_op == XDR_DECODE) {
*geop = geo;
}
return (TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -