1
0
Fork 0

Converted to c++ style comments.

This commit is contained in:
curt 1998-09-21 23:16:23 +00:00
parent df4a7ed01a
commit 86a832bd66
2 changed files with 161 additions and 155 deletions

View file

@ -1,36 +1,36 @@
/* splittris.c -- read in a .ele/.node file pair generated by the
* triangle program and output a simple Wavefront .obj
* file for the north, south, east, and west edge
* verticies ... including the normals.
*
* Written by Curtis Olson, started January 1998.
*
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
* (Log is kept at end of this file) */
// splittris.cxx -- read in a .ele/.node file pair generated by the
// triangle program and output a simple Wavefront .obj
// file for the north, south, east, and west edge
// verticies ... including the normals.
//
// Written by Curtis Olson, started January 1998.
//
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
// (Log is kept at end of this file)
#include <math.h>
#include <stdio.h>
#include <stdlib.h> /* for atoi() */
#include <stdlib.h> // for atoi()
#include <string.h>
#include <sys/stat.h> /* for stat() */
#include <unistd.h> /* for stat() */
#include <sys/stat.h> // for stat()
#include <unistd.h> // for stat()
#include "splittris.hxx"
@ -47,41 +47,41 @@ double xmin, xmax, ymin, ymax;
static double nodes_orig[MAX_NODES][3];
static int tris[MAX_TRIS][3];
/* static int new_tris[MAX_TRIS][3]; */
// static int new_tris[MAX_TRIS][3];
static fgPoint3d nodes_cart[MAX_NODES];
fgBUCKET ne_index, nw_index, sw_index, se_index;
fgBUCKET north_index, south_index, east_index, west_index;
/* convert a geodetic point lon(arcsec), lat(arcsec), elev(meter) to
* a cartesian point */
// convert a geodetic point lon(arcsec), lat(arcsec), elev(meter) to a
// cartesian point
fgPoint3d geod_to_cart(double geod[3]) {
fgPoint3d cp;
fgPoint3d pp;
double gc_lon, gc_lat, sl_radius;
/* printf("A geodetic point is (%.2f, %.2f, %.2f)\n",
geod[0], geod[1], geod[2]); */
// printf("A geodetic point is (%.2f, %.2f, %.2f)\n",
// geod[0], geod[1], geod[2]);
gc_lon = geod[0]*ARCSEC_TO_RAD;
fgGeodToGeoc(geod[1]*ARCSEC_TO_RAD, geod[2], &sl_radius, &gc_lat);
/* printf("A geocentric point is (%.2f, %.2f, %.2f)\n", gc_lon,
gc_lat, sl_radius+geod[2]); */
// printf("A geocentric point is (%.2f, %.2f, %.2f)\n", gc_lon,
// gc_lat, sl_radius+geod[2]);
pp.lon = gc_lon;
pp.lat = gc_lat;
pp.radius = sl_radius + geod[2];
cp = fgPolarToCart3d(pp);
/* printf("A cart point is (%.8f, %.8f, %.8f)\n", cp.x, cp.y, cp.z); */
// printf("A cart point is (%.8f, %.8f, %.8f)\n", cp.x, cp.y, cp.z);
return(cp);
}
/* given three points defining a triangle, calculate the normal */
// given three points defining a triangle, calculate the normal
void calc_normal(fgPoint3d p1, fgPoint3d p2,
fgPoint3d p3, double normal[3])
{
@ -94,11 +94,11 @@ void calc_normal(fgPoint3d p1, fgPoint3d p2,
MAT3cross_product(normal, v1, v2);
MAT3_NORMALIZE_VEC(normal,temp);
/* printf(" Normal = %.2f %.2f %.2f\n", normal[0], normal[1], normal[2]); */
// printf(" Normal = %.2f %.2f %.2f\n", normal[0], normal[1], normal[2]);
}
/* return the file base name ( foo/bar/file.ext = file.ext ) */
// return the file base name ( foo/bar/file.ext = file.ext )
void extract_file(char *in, char *base) {
int len, i;
@ -114,7 +114,7 @@ void extract_file(char *in, char *base) {
}
/* return the file path name ( foo/bar/file.ext = foo/bar ) */
// return the file path name ( foo/bar/file.ext = foo/bar )
void extract_path(char *in, char *base) {
int len, i;
@ -130,7 +130,7 @@ void extract_path(char *in, char *base) {
}
/* return the index of all triangles containing the specified node */
// return the index of all triangles containing the specified node
void find_tris(int n, int *t1, int *t2, int *t3, int *t4, int *t5) {
int i;
@ -156,7 +156,7 @@ void find_tris(int n, int *t1, int *t2, int *t3, int *t4, int *t5) {
}
/* Initialize a new mesh structure */
// Initialize a new mesh structure
void triload(char *basename) {
char nodename[256], elename[256];
FILE *node, *ele;
@ -186,10 +186,10 @@ void triload(char *basename) {
for ( i = 1; i <= nodecount; i++ ) {
fscanf(node, "%d %lf %lf %lf %d\n", &junk1,
&nodes_orig[i][0], &nodes_orig[i][1], &nodes_orig[i][2], &junk2);
/* printf("%d %.2f %.2f %.2f\n", junk1, n[0], n[1], n[2]); */
// printf("%d %.2f %.2f %.2f\n", junk1, n[0], n[1], n[2]);
nodes_cart[i] = geod_to_cart(nodes_orig[i]);
/* printf("%d %.2f %.2f %.2f\n",
junk1, nodes_cart[i].x, nodes_cart[i].y, nodes_cart[i].z); */
// printf("%d %.2f %.2f %.2f\n",
// junk1, nodes_cart[i].x, nodes_cart[i].y, nodes_cart[i].z);
if ( i == 1 ) {
xmin = xmax = nodes_orig[i][0];
@ -230,14 +230,14 @@ void triload(char *basename) {
for ( i = 1; i <= tricount; i++ ) {
fscanf(ele, "%d %d %d %d\n", &junk1,
&tris[i][0], &tris[i][1], &tris[i][2]);
/* printf("%d %d %d %d\n", junk1, tris[i][0], tris[i][1], tris[i][2]);*/
// printf("%d %d %d %d\n", junk1, tris[i][0], tris[i][1], tris[i][2]);
}
fclose(ele);
}
/* check if a file exists */
// check if a file exists
int file_exists(char *file) {
struct stat stat_buf;
int result;
@ -247,18 +247,18 @@ int file_exists(char *file) {
result = stat(file, &stat_buf);
if ( result != 0 ) {
/* stat failed, no file */
// stat failed, no file
printf("not found.\n");
return(0);
} else {
/* stat succeeded, file exists */
// stat succeeded, file exists
printf("exists.\n");
return(1);
}
}
/* check to see if a shared object exists */
// check to see if a shared object exists
int shared_object_exists(char *basepath, char *ext) {
char file[256], scene_path[256];
long int index;
@ -387,25 +387,25 @@ int shared_object_exists(char *basepath, char *ext) {
}
/* my custom file opening routine ... don't open if a shared edge or
* vertex alread exists */
// my custom file opening routine ... don't open if a shared edge or
// vertex alread exists
FILE *my_open(char *basename, char *basepath, char *ext) {
FILE *fp;
char filename[256];
/* create the output file name */
// create the output file name
strcpy(filename, basename);
strcat(filename, ext);
/* check if a shared object already exist from a different tile */
// check if a shared object already exist from a different tile
if ( shared_object_exists(basepath, ext) ) {
/* not an actual file open error, but we've already got the
* shared edge, so we don't want to create another one */
// not an actual file open error, but we've already got the
// shared edge, so we don't want to create another one
printf("not opening\n");
return(NULL);
} else {
/* open the file */
// open the file
fp = fopen(filename, "w");
printf("Opening %s\n", filename);
return(fp);
@ -413,7 +413,7 @@ FILE *my_open(char *basename, char *basepath, char *ext) {
}
/* dump in WaveFront .obj format */
// dump in WaveFront .obj format
void dump_obj(char *basename, char *basepath) {
double n1[3], n2[3], n3[3], n4[3], n5[3], norm[3], temp;
FILE *fp, *sw, *se, *ne, *nw, *north, *south, *east, *west, *body;
@ -433,7 +433,7 @@ void dump_obj(char *basename, char *basepath) {
printf("Dumping edges file basename: %s ...\n", basename);
/* dump vertices */
// dump vertices
printf(" writing vertices\n");
for ( i = 1; i <= nodecount; i++ ) {
@ -468,9 +468,9 @@ void dump_obj(char *basename, char *basepath) {
}
printf(" calculating and writing normals\n");
/* calculate and generate normals */
// calculate and generate normals
for ( i = 1; i <= nodecount; i++ ) {
/* printf("Finding normal\n"); */
// printf("Finding normal\n");
find_tris(i, &t1, &t2, &t3, &t4, &t5);
@ -508,17 +508,18 @@ void dump_obj(char *basename, char *basepath) {
count = 5;
}
/* printf(" norm[2] = %.2f %.2f %.2f\n", n1[2], n2[2], n3[2]); */
// printf(" norm[2] = %.2f %.2f %.2f\n", n1[2], n2[2], n3[2]);
norm[0] = ( n1[0] + n2[0] + n3[0] + n4[0] + n5[0] ) / (double)count;
norm[1] = ( n1[1] + n2[1] + n3[1] + n4[1] + n5[1] ) / (double)count;
norm[2] = ( n1[2] + n2[2] + n3[2] + n4[2] + n5[2] ) / (double)count;
/* printf(" count = %d\n", count); */
/* printf(" Ave. normal = %.4f %.4f %.4f\n", norm[0], norm[1], norm[2]);*/
// printf(" count = %d\n", count);
// printf(" Ave. normal = %.4f %.4f %.4f\n", norm[0], norm[1],
// norm[2]);
MAT3_NORMALIZE_VEC(norm, temp);
/* printf(" Normalized ave. normal = %.4f %.4f %.4f\n", */
/* norm[0], norm[1], norm[2]); */
// printf(" Normalized ave. normal = %.4f %.4f %.4f\n",
// norm[0], norm[1], norm[2]);
fp = NULL;
@ -570,13 +571,13 @@ int main(int argc, char **argv) {
strcpy(basename, argv[1]);
/* find the base path of the file */
// find the base path of the file
extract_path(basename, basepath);
extract_path(basepath, basepath);
extract_path(basepath, basepath);
printf("%s\n", basepath);
/* find the index of the current file */
// find the index of the current file
extract_file(basename, temp);
len = strlen(temp);
if ( len >= 2 ) {
@ -587,7 +588,7 @@ int main(int argc, char **argv) {
fgBucketParseIndex(index, &p);
printf("bucket = %d %d %d %d\n", p.lon, p.lat, p.x, p.y);
/* generate the indexes of the neighbors */
// generate the indexes of the neighbors
fgBucketOffset(&p, &ne_index, 1, 1);
fgBucketOffset(&p, &nw_index, -1, 1);
fgBucketOffset(&p, &se_index, 1, -1);
@ -598,58 +599,60 @@ int main(int argc, char **argv) {
fgBucketOffset(&p, &east_index, 1, 0);
fgBucketOffset(&p, &west_index, -1, 0);
/*
printf("Corner indexes = %ld %ld %ld %ld\n",
ne_index, nw_index, sw_index, se_index);
printf("Edge indexes = %ld %ld %ld %ld\n",
north_index, south_index, east_index, west_index);
*/
// printf("Corner indexes = %ld %ld %ld %ld\n",
// ne_index, nw_index, sw_index, se_index);
// printf("Edge indexes = %ld %ld %ld %ld\n",
// north_index, south_index, east_index, west_index);
/* load the input data files */
// load the input data files
triload(basename);
/* dump in WaveFront .obj format */
// dump in WaveFront .obj format
dump_obj(basename, basepath);
return(0);
}
/* $Log$
/* Revision 1.1 1998/07/08 14:59:13 curt
/* *.[ch] renamed to *.[ch]xx
/*
* Revision 1.11 1998/07/04 00:56:40 curt
* typedef'd struct fgBUCKET.
*
* Revision 1.10 1998/05/02 01:54:37 curt
* Converting to polar3d.h routines.
*
* Revision 1.9 1998/04/18 04:01:20 curt
* Now use libMath rather than having local copies of math routines.
*
* Revision 1.8 1998/04/14 02:26:08 curt
* Code reorganizations. Added a Lib/ directory for more general libraries.
*
* Revision 1.7 1998/04/08 23:21:13 curt
* Adopted Gnu automake/autoconf system.
*
* Revision 1.6 1998/03/03 15:36:13 curt
* Tweaks for compiling with g++
*
* Revision 1.5 1998/03/03 03:37:04 curt
* Cumulative tweaks.
*
* Revision 1.4 1998/01/31 00:41:26 curt
* Made a few changes converting floats to doubles.
*
* Revision 1.3 1998/01/27 18:37:04 curt
* Lots of updates to get back in sync with changes made over in .../Src/
*
* Revision 1.2 1998/01/14 15:54:43 curt
* Initial revision completed.
*
* Revision 1.1 1998/01/14 02:11:31 curt
* Initial revision.
*
*/
// $Log$
// Revision 1.2 1998/09/21 23:16:23 curt
// Converted to c++ style comments.
//
// Revision 1.1 1998/07/08 14:59:13 curt
// *.[ch] renamed to *.[ch]xx
//
// Revision 1.11 1998/07/04 00:56:40 curt
// typedef'd struct fgBUCKET.
//
// Revision 1.10 1998/05/02 01:54:37 curt
// Converting to polar3d.h routines.
//
// Revision 1.9 1998/04/18 04:01:20 curt
// Now use libMath rather than having local copies of math routines.
//
// Revision 1.8 1998/04/14 02:26:08 curt
// Code reorganizations. Added a Lib/ directory for more general libraries.
//
// Revision 1.7 1998/04/08 23:21:13 curt
// Adopted Gnu automake/autoconf system.
//
// Revision 1.6 1998/03/03 15:36:13 curt
// Tweaks for compiling with g++
//
// Revision 1.5 1998/03/03 03:37:04 curt
// Cumulative tweaks.
//
// Revision 1.4 1998/01/31 00:41:26 curt
// Made a few changes converting floats to doubles.
//
// Revision 1.3 1998/01/27 18:37:04 curt
// Lots of updates to get back in sync with changes made over in .../Src/
//
// Revision 1.2 1998/01/14 15:54:43 curt
// Initial revision completed.
//
// Revision 1.1 1998/01/14 02:11:31 curt
// Initial revision.
//

View file

@ -1,27 +1,27 @@
/* splittris.hxx -- read in a .ele/.node file pair generated by the triangle
* program and output edge vertices w/ normals.
*
* Written by Curtis Olson, started January 1998.
*
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
* (Log is kept at end of this file)
*/
// splittris.hxx -- read in a .ele/.node file pair generated by the triangle
// program and output edge vertices w/ normals.
//
// Written by Curtis Olson, started January 1998.
//
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
// (Log is kept at end of this file)
#ifndef SPLITTRIS_HXX
@ -39,24 +39,27 @@
extern int nodecount, tricount;
/* Initialize a new mesh structure */
// Initialize a new mesh structure
void triload(char *basename);
#endif /* SPLITTRIS_HXX */
#endif // SPLITTRIS_HXX
/* $Log$
/* Revision 1.1 1998/07/08 14:59:14 curt
/* *.[ch] renamed to *.[ch]xx
/*
* Revision 1.3 1998/03/03 15:36:13 curt
* Tweaks for compiling with g++
*
* Revision 1.2 1998/01/15 02:49:25 curt
* Misc. housekeeping.
*
* Revision 1.1 1998/01/14 02:11:32 curt
* Initial revision.
*
*/
// $Log$
// Revision 1.2 1998/09/21 23:16:24 curt
// Converted to c++ style comments.
//
// Revision 1.1 1998/07/08 14:59:14 curt
// *.[ch] renamed to *.[ch]xx
//
// Revision 1.3 1998/03/03 15:36:13 curt
// Tweaks for compiling with g++
//
// Revision 1.2 1998/01/15 02:49:25 curt
// Misc. housekeeping.
//
// Revision 1.1 1998/01/14 02:11:32 curt
// Initial revision.
//