go to www.geomview.org home page
 
Home

Overview
FAQ
Documentation

Download

Mailing List

Geomview For Windows?

Support
Users
Development

Bug Reporting
Contributing
Contact Us

Sponsors

 

Site Search

 

Advanced
Search

 
About the software@geom archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MESH BINARY


  • To: software
  • Subject: MESH BINARY
  • From: rfa
  • Date: Mon, 17 Aug 92 22:00:20 CDT

Is there a bug in the MESH BINARY data format?  Below is a program
which generates eight files:  QUAD/CQUAD/MESH/CMESH in ascii and binary
format.  The ascii-format examples are to show that my data is not
crazy.  The QUAD and CQUAD binary format examples are to show that my
binary writing is more or less correct.  Geomview chokes on the MESH and
CMESH binary files.  If I have made a dumb mistake I would be grateful
if someone could point it out to me.  But I do often use binary quad
format in my program;  I started worrying about binary mesh because I
couldn't get that to work in my program

===============================================================================
		"oogltest.c"

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

static float x[] = { 0., 1., 1., 0. };
static float y[] = { 0., 0., 1., 1. };
static float z[] = { 0., 0., 1., 0. };
static float r[] = { 1., 1., 0., 0. };
static float g[] = { 1., 0., 1., 0. };
static float b[] = { 1., 0., 0., 1. };

static int write_int( int x, FILE *fp )
{	return fwrite( (char *)(&x), sizeof(int), 1, fp ); }

static int write_float( float x, FILE *fp )
{	return fwrite( (char *)(&x), sizeof(float), 1, fp ); }

static void w3(float x, float y, float z, FILE *fp)
{ write_float(x,fp);	write_float(y,fp);	write_float(z,fp); }

static void wrgb(float r, float g, float b, FILE *fp)
{	write_float(r,fp); write_float(g,fp);
	write_float(b,fp); write_float(1.,fp); }

main()
{
	int i;
	FILE *fp;

	/******************************************************************/
	/*  ASCII and binary QUAD */

	fp = fopen("asc.quad","w");
	fprintf(fp,"{QUAD\n");
	for ( i=0 ; i<4 ; i++ )
	    fprintf(fp,"%g %g %g\n",x[i],y[i],z[i]);
	fprintf(fp,"}\n");
	fclose(fp);
	printf("asc.quad done\n");

	fp = fopen("bin.quad","w");
	fprintf(fp,"{QUAD BINARY\n");
	write_int(1,fp);	/*  Tell it there is one quad  */
	for ( i=0 ; i<4 ; i++ )
		w3(x[i],y[i],z[i],fp);
	fprintf(fp,"}\n");
	fclose(fp);
	printf("bin.quad done\n");

	/******************************************************************/
	/*  ASCII and binary CQUAD */

	fp = fopen("asc.cquad","w");
	fprintf(fp,"{CQUAD\n");
	for ( i=0 ; i<4 ; i++ )
	    fprintf(fp,"%g %g %g  %g %g %g 1\n",
		x[i],y[i],z[i],r[i],g[i],b[i]);
	fprintf(fp,"}\n");
	fclose(fp);
	printf("asc.cquad done\n");

	fp = fopen("bin.cquad","w");
	fprintf(fp,"{CQUAD BINARY  # one quad follows\n");
	write_int(1,fp);	/*  Tell it there is one quad  */
	for ( i=0 ; i<4 ; i++ )
		{ w3(x[i],y[i],z[i],fp);	wrgb(r[i],g[i],b[i],fp); }
	fprintf(fp,"}\n");
	fclose(fp);
	printf("bin.cquad done\n");

	/******************************************************************/
	/*  ASCII and binary MESH */
	/*  Note:  we really should flip vertices 1 and 3  */

	fp = fopen("asc.mesh","w");
	fprintf(fp,"{MESH\n");
	fprintf(fp,"%d %d\n",2,2);	/*  Mesh is 2 x 2  */
	for ( i=0 ; i<4 ; i++ )
	    fprintf(fp,"%g %g %g\n",x[i],y[i],z[i]);
	fprintf(fp,"}\n");
	fclose(fp);
	printf("asc.mesh done\n");

	fp = fopen("bin.mesh","w");
	fprintf(fp,"{MESH BINARY\n");
	write_int(2,fp);	write_int(2,fp);	/*  Mesh is 2 x 2  */
	for ( i=0 ; i<4 ; i++ )
		w3(x[i],y[i],z[i],fp);
	fprintf(fp,"}\n");
	fclose(fp);
	printf("bin.mesh done\n");

	/******************************************************************/
	/*  ASCII and binary CMESH */
	/*  Note:  we really should flip vertices 1 and 3  */

	fp = fopen("asc.cmesh","w");
	fprintf(fp,"{CMESH\n");
	fprintf(fp,"%d %d\n",2,2);	/*  Mesh is 2 x 2  */
	for ( i=0 ; i<4 ; i++ )
	    fprintf(fp,"%g %g %g  %g %g %g 1\n",
		x[i],y[i],z[i], r[i],g[i],b[i]);
	fprintf(fp,"}\n");
	fclose(fp);
	printf("asc.cmesh done\n");

	fp = fopen("bin.cmesh","w");
	fprintf(fp,"{MESH BINARY\n");
	write_int(2,fp);	write_int(2,fp);	/*  Mesh is 2 x 2  */
	for ( i=0 ; i<4 ; i++ )
		{ w3(x[i],y[i],z[i],fp);	wrgb(r[i],g[i],b[i],fp); }
	fprintf(fp,"}\n");
	fclose(fp);
	printf("bin.cmesh done\n");
}


 
Home | Overview | FAQ | Documentation | Support | Download | Mailing List
Windows? | Development | Bug Reporting | Contributing | Contact Us | Sponsors
 
site hosted by
SourceForge Logo