1
0
Fork 0
flightgear/SplitTris/splittris.cxx

674 lines
18 KiB
C++
Raw Normal View History

1998-09-21 23:16:23 +00:00
// 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)
1998-01-14 02:11:30 +00:00
#include <math.h>
#include <stdio.h>
1998-09-21 23:16:23 +00:00
#include <stdlib.h> // for atoi()
1998-01-14 02:11:30 +00:00
#include <string.h>
1998-09-21 23:16:23 +00:00
#include <sys/stat.h> // for stat()
#include <unistd.h> // for stat()
1998-01-14 02:11:30 +00:00
1998-07-08 14:59:13 +00:00
#include "splittris.hxx"
1998-01-14 02:11:30 +00:00
#include <Include/fg_constants.h>
#include <Bucket/bucketutils.h>
1998-10-18 01:17:09 +00:00
#include <Math/fg_geodesy.hxx>
#include <Math/mat3.h>
1998-10-18 01:17:09 +00:00
#include <Math/point3d.hxx>
1998-07-08 14:59:13 +00:00
#include <Math/polar3d.hxx>
1998-10-18 01:17:09 +00:00
#include <Misc/fgstream.hxx>
1998-01-14 02:11:30 +00:00
// int nodecount, tricount;
1998-01-14 02:11:30 +00:00
double xmin, xmax, ymin, ymax;
// static double nodes_orig[MAX_NODES][3];
1998-10-18 01:17:09 +00:00
// static Point3D nodes_cart[MAX_NODES];
// static int tris[MAX_TRIS][3];
1998-01-14 02:11:30 +00:00
container_3d nodes_orig;
container_3d nodes_cart;
container_tri tri_list;
1998-01-14 02:11:30 +00:00
1998-07-04 00:55:39 +00:00
fgBUCKET ne_index, nw_index, sw_index, se_index;
fgBUCKET north_index, south_index, east_index, west_index;
1998-01-14 02:11:30 +00:00
1998-09-21 23:16:23 +00:00
// given three points defining a triangle, calculate the normal
1998-10-18 01:17:09 +00:00
void calc_normal(const Point3D& p1, const Point3D& p2,
const Point3D& p3, double normal[3])
1998-01-14 02:11:30 +00:00
{
double v1[3], v2[3];
double temp;
1998-01-14 02:11:30 +00:00
1998-10-18 01:17:09 +00:00
v1[0] = p2.x() - p1.x(); v1[1] = p2.y() - p1.y(); v1[2] = p2.z() - p1.z();
v2[0] = p3.x() - p1.x(); v2[1] = p3.y() - p1.y(); v2[2] = p3.z() - p1.z();
1998-01-14 02:11:30 +00:00
MAT3cross_product(normal, v1, v2);
MAT3_NORMALIZE_VEC(normal,temp);
1998-09-21 23:16:23 +00:00
// printf(" Normal = %.2f %.2f %.2f\n", normal[0], normal[1], normal[2]);
1998-01-14 02:11:30 +00:00
}
1998-09-21 23:16:23 +00:00
// return the file base name ( foo/bar/file.ext = file.ext )
string extract_file(const string& input) {
int pos;
1998-01-14 02:11:30 +00:00
pos = input.rfind("/");
++pos;
1998-01-14 02:11:30 +00:00
return input.substr(pos);
1998-01-14 02:11:30 +00:00
}
1998-09-21 23:16:23 +00:00
// return the file path name ( foo/bar/file.ext = foo/bar )
string extract_path(const string& input) {
int pos;
1998-01-14 02:11:30 +00:00
pos = input.rfind("/");
1998-01-14 02:11:30 +00:00
return input.substr(0, pos);
1998-01-14 02:11:30 +00:00
}
1998-09-21 23:16:23 +00:00
// return the index of all triangles containing the specified node
1998-01-14 02:11:30 +00:00
void find_tris(int n, int *t1, int *t2, int *t3, int *t4, int *t5) {
int i;
*t1 = *t2 = *t3 = *t4 = *t5 = 0;
i = 1;
iterator_tri last = tri_list.end();
iterator_tri current = tri_list.begin();
// skip first null record
++current;
for ( ; current != last; ++current )
{
if ( (n == (*current).n1) || (n == (*current).n2) ||
(n == (*current).n3) )
{
1998-01-14 02:11:30 +00:00
if ( *t1 == 0 ) {
*t1 = i;
} else if ( *t2 == 0 ) {
*t2 = i;
} else if ( *t3 == 0 ) {
*t3 = i;
} else if ( *t4 == 0 ) {
*t4 = i;
} else {
*t5 = i;
}
}
++i;
1998-01-14 02:11:30 +00:00
}
}
1998-09-21 23:16:23 +00:00
// Initialize a new mesh structure
void triload(const string& basename) {
string nodename, elename;
1998-10-21 14:56:20 +00:00
Point3D node1, node2, p;
triangle tri;
int nodecount, tricount, dim, junk1, junk2;
1998-01-14 02:11:30 +00:00
int i;
nodename = basename + ".node";
elename = basename + ".ele";
1998-01-14 02:11:30 +00:00
cout << "Loading node file: " + nodename + " ...\n";
1998-10-18 01:17:09 +00:00
fg_gzifstream node_in( nodename );
if ( !node_in ) {
cout << "Cannot open file " + nodename + "\n";
1998-01-14 02:11:30 +00:00
exit(-1);
}
// the triangle program starts counting at 1 by default which is
// pretty obnoxious. Let's just push null record zero's onto our
// list to compensate
nodes_orig.push_back(node1);
nodes_cart.push_back(node1);
tri_list.push_back(tri);
1998-01-14 02:11:30 +00:00
node_in >> nodecount >> dim >> junk1 >> junk2;
cout << " Expecting " << nodecount << " nodes\n";
1998-01-14 02:11:30 +00:00
for ( i = 1; i <= nodecount; i++ ) {
node_in >> junk1 >> node1 >> junk2;
nodes_orig.push_back(node1);
1998-10-18 01:17:09 +00:00
// printf("%d %.2f %.2f %.2f\n", junk1, node1.x, node1.y, node1.z);
1998-10-21 14:56:20 +00:00
// convert to radians (before we can convert to cartesian)
p = Point3D( node1.x() * ARCSEC_TO_RAD,
node1.y() * ARCSEC_TO_RAD,
node1.z() );
1998-10-18 01:17:09 +00:00
1998-10-21 14:56:20 +00:00
node2 = fgGeodToCart(p);
nodes_cart.push_back(node2);
1998-10-18 01:17:09 +00:00
// printf("%d %.2f %.2f %.2f\n", junk1, node2.x, node2.y, node2.z);
1998-01-14 02:11:30 +00:00
if ( i == 1 ) {
1998-10-18 01:17:09 +00:00
xmin = xmax = node1.x();
ymin = ymax = node1.y();
1998-01-14 02:11:30 +00:00
} else {
1998-10-18 01:17:09 +00:00
if ( node1.x() < xmin ) {
xmin = node1.x();
1998-01-14 02:11:30 +00:00
}
1998-10-18 01:17:09 +00:00
if ( node1.x() > xmax ) {
xmax = node1.x();
1998-01-14 02:11:30 +00:00
}
1998-10-18 01:17:09 +00:00
if ( node1.y() < ymin ) {
ymin = node1.y();
1998-01-14 02:11:30 +00:00
}
1998-10-18 01:17:09 +00:00
if ( node1.y() > ymax ) {
ymax = node1.y();
1998-01-14 02:11:30 +00:00
}
}
}
cout << "Loading element file: " + elename + " ...\n";
1998-10-18 01:17:09 +00:00
fg_gzifstream ele_in( elename );
if ( !ele_in ) {
cout << "Cannot open file " + elename + "\n";
1998-01-14 02:11:30 +00:00
exit(-1);
}
ele_in >> tricount >> junk1 >> junk2;
cout << " Expecting " << tricount << " elements\n";
1998-01-14 02:11:30 +00:00
for ( i = 1; i <= tricount; i++ ) {
1998-10-18 01:17:09 +00:00
// fscanf(ele_file, "%d %d %d %d\n", &junk1,
// &(tri.n1), &(tri.n2), &(tri.n3));
ele_in >> junk1 >> tri.n1 >> tri.n2 >> tri.n3;
1998-10-18 01:17:09 +00:00
// printf("%d %d %d %d\n", junk1, tri.n1, tri.n2, tri.n3);
tri_list.push_back(tri);
1998-01-14 02:11:30 +00:00
}
}
1998-09-21 23:16:23 +00:00
// check if a file exists
1998-01-14 02:11:30 +00:00
int file_exists(char *file) {
struct stat stat_buf;
1998-01-14 15:54:42 +00:00
int result;
cout << "checking " << file << " ... ";
1998-01-14 02:11:30 +00:00
result = stat(file, &stat_buf);
if ( result != 0 ) {
1998-09-21 23:16:23 +00:00
// stat failed, no file
cout << "not found.\n";
return 0;
1998-01-14 02:11:30 +00:00
} else {
1998-09-21 23:16:23 +00:00
// stat succeeded, file exists
cout << "exists.\n";
return 1;
1998-01-14 02:11:30 +00:00
}
}
1998-09-21 23:16:23 +00:00
// check to see if a shared object exists
int shared_object_exists(const char *basepath, const string& ext) {
1998-01-14 15:54:42 +00:00
char file[256], scene_path[256];
long int index;
if ( ext == ".sw" ) {
fgBucketGenBasePath(&west_index, scene_path);
index = fgBucketGenIndex(&west_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.se", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
fgBucketGenBasePath(&sw_index, scene_path);
index = fgBucketGenIndex(&sw_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.ne", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
fgBucketGenBasePath(&south_index, scene_path);
index = fgBucketGenIndex(&south_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.nw", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
}
if ( ext == ".se" ) {
fgBucketGenBasePath(&east_index, scene_path);
index = fgBucketGenIndex(&east_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.sw", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
fgBucketGenBasePath(&se_index, scene_path);
index = fgBucketGenIndex(&se_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.nw", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
fgBucketGenBasePath(&south_index, scene_path);
index = fgBucketGenIndex(&south_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.ne", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
}
if ( ext == ".ne" ) {
fgBucketGenBasePath(&east_index, scene_path);
index = fgBucketGenIndex(&east_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.nw", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
fgBucketGenBasePath(&ne_index, scene_path);
index = fgBucketGenIndex(&ne_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.sw", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
fgBucketGenBasePath(&north_index, scene_path);
index = fgBucketGenIndex(&north_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.se", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
}
if ( ext == ".nw" ) {
fgBucketGenBasePath(&west_index, scene_path);
index = fgBucketGenIndex(&west_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.ne", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
fgBucketGenBasePath(&nw_index, scene_path);
index = fgBucketGenIndex(&nw_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.se", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
fgBucketGenBasePath(&north_index, scene_path);
index = fgBucketGenIndex(&north_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.sw", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
}
if ( ext == ".south" ) {
fgBucketGenBasePath(&south_index, scene_path);
index = fgBucketGenIndex(&south_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.north", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
}
if ( ext == ".north" ) {
fgBucketGenBasePath(&north_index, scene_path);
index = fgBucketGenIndex(&north_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.south", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
}
if ( ext == ".west" ) {
fgBucketGenBasePath(&west_index, scene_path);
index = fgBucketGenIndex(&west_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.east", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
}
if ( ext == ".east" ) {
fgBucketGenBasePath(&east_index, scene_path);
index = fgBucketGenIndex(&east_index);
1998-01-14 15:54:42 +00:00
sprintf(file, "%s/%s/%ld.1.west", basepath, scene_path, index);
if ( file_exists(file) ) {
return(1);
}
}
return(0);
}
1998-09-21 23:16:23 +00:00
// my custom file opening routine ... don't open if a shared edge or
// vertex alread exists
FILE *my_open(const string& basename, const string& basepath,
const string& ext)
{
1998-01-14 02:11:30 +00:00
FILE *fp;
string filename;
1998-01-14 02:11:30 +00:00
1998-09-21 23:16:23 +00:00
// create the output file name
filename = basename + ext;
1998-01-14 02:11:30 +00:00
1998-09-21 23:16:23 +00:00
// check if a shared object already exist from a different tile
1998-01-14 02:11:30 +00:00
if ( shared_object_exists(basepath.c_str(), ext) ) {
1998-09-21 23:16:23 +00:00
// not an actual file open error, but we've already got the
// shared edge, so we don't want to create another one
cout << "not opening\n";
1998-01-14 02:11:30 +00:00
return(NULL);
} else {
1998-09-21 23:16:23 +00:00
// open the file
fp = fopen(filename.c_str(), "w");
cout << "Opening " + filename + "\n";
1998-01-14 02:11:30 +00:00
return(fp);
}
}
1998-09-21 23:16:23 +00:00
// dump in WaveFront .obj format
void dump_obj(const string& basename, const string& basepath) {
1998-10-18 01:17:09 +00:00
Point3D node;
1998-01-14 02:11:30 +00:00
double n1[3], n2[3], n3[3], n4[3], n5[3], norm[3], temp;
1998-01-14 15:54:42 +00:00
FILE *fp, *sw, *se, *ne, *nw, *north, *south, *east, *west, *body;
int i, t1, t2, t3, t4, t5, count, size;
1998-10-18 01:17:09 +00:00
double x, y, z;
1998-01-14 02:11:30 +00:00
sw = my_open(basename, basepath, ".sw");
se = my_open(basename, basepath, ".se");
ne = my_open(basename, basepath, ".ne");
nw = my_open(basename, basepath, ".nw");
north = my_open(basename, basepath, ".north");
south = my_open(basename, basepath, ".south");
east = my_open(basename, basepath, ".east");
west = my_open(basename, basepath, ".west");
body = my_open(basename, basepath, ".body");
cout << "Dumping edges file basename: " + basename + " ...\n";
1998-01-14 02:11:30 +00:00
1998-09-21 23:16:23 +00:00
// dump vertices
cout << " writing vertices\n";
1998-01-14 02:11:30 +00:00
iterator_3d last = nodes_orig.end();
iterator_3d current = nodes_orig.begin();
++current;
for ( ; current != last; ++current) {
node = *current;
1998-10-18 01:17:09 +00:00
if ( (fabs(node.y() - ymin) < FG_EPSILON) &&
(fabs(node.x() - xmin) < FG_EPSILON) ) {
1998-01-14 15:54:42 +00:00
fp = sw;
1998-10-18 01:17:09 +00:00
} else if ( (fabs(node.y() - ymin) < FG_EPSILON) &&
(fabs(node.x() - xmax) < FG_EPSILON) ) {
1998-01-14 15:54:42 +00:00
fp = se;
1998-10-18 01:17:09 +00:00
} else if ( (fabs(node.y() - ymax) < FG_EPSILON) &&
(fabs(node.x() - xmax) < FG_EPSILON)) {
1998-01-14 15:54:42 +00:00
fp = ne;
1998-10-18 01:17:09 +00:00
} else if ( (fabs(node.y() - ymax) < FG_EPSILON) &&
(fabs(node.x() - xmin) < FG_EPSILON) ) {
1998-01-14 15:54:42 +00:00
fp = nw;
1998-10-18 01:17:09 +00:00
} else if ( fabs(node.x() - xmin) < FG_EPSILON ) {
1998-01-14 15:54:42 +00:00
fp = west;
1998-10-18 01:17:09 +00:00
} else if ( fabs(node.x() - xmax) < FG_EPSILON ) {
1998-01-14 15:54:42 +00:00
fp = east;
1998-10-18 01:17:09 +00:00
} else if ( fabs(node.y() - ymin) < FG_EPSILON ) {
1998-01-14 15:54:42 +00:00
fp = south;
1998-10-18 01:17:09 +00:00
} else if ( fabs(node.y() - ymax) < FG_EPSILON ) {
1998-01-14 15:54:42 +00:00
fp = north;
1998-01-14 02:11:30 +00:00
} else {
1998-01-14 15:54:42 +00:00
fp = body;
1998-01-14 02:11:30 +00:00
}
1998-03-03 03:36:57 +00:00
1998-10-18 01:17:09 +00:00
x = node.x();
y = node.y();
z = node.z();
1998-03-03 03:36:57 +00:00
if ( fp != NULL ) {
1998-10-18 01:17:09 +00:00
fprintf(fp, "gdn %.2f %.2f %.2f\n", x, y, z);
1998-03-03 03:36:57 +00:00
}
1998-01-14 02:11:30 +00:00
}
cout << " calculating and writing normals\n";
1998-09-21 23:16:23 +00:00
// calculate and generate normals
size = nodes_orig.size();
for ( i = 1; i < size; i++ ) {
1998-09-21 23:16:23 +00:00
// printf("Finding normal\n");
1998-01-14 02:11:30 +00:00
find_tris(i, &t1, &t2, &t3, &t4, &t5);
n1[0] = n1[1] = n1[2] = 0.0;
n2[0] = n2[1] = n2[2] = 0.0;
n3[0] = n3[1] = n3[2] = 0.0;
n4[0] = n4[1] = n4[2] = 0.0;
n5[0] = n5[1] = n5[2] = 0.0;
count = 1;
calc_normal(nodes_cart[tri_list[t1].n1],
nodes_cart[tri_list[t1].n2],
nodes_cart[tri_list[t1].n3],
n1);
1998-01-14 02:11:30 +00:00
if ( t2 > 0 ) {
calc_normal(nodes_cart[tri_list[t2].n1],
nodes_cart[tri_list[t2].n2],
nodes_cart[tri_list[t2].n3],
n2);
1998-01-14 02:11:30 +00:00
count = 2;
}
if ( t3 > 0 ) {
calc_normal(nodes_cart[tri_list[t3].n1],
nodes_cart[tri_list[t3].n2],
nodes_cart[tri_list[t3].n3],
n3);
1998-01-14 02:11:30 +00:00
count = 3;
}
if ( t4 > 0 ) {
calc_normal(nodes_cart[tri_list[t4].n1],
nodes_cart[tri_list[t4].n2],
nodes_cart[tri_list[t4].n3],
n4);
1998-01-14 02:11:30 +00:00
count = 4;
}
if ( t5 > 0 ) {
calc_normal(nodes_cart[tri_list[t5].n1],
nodes_cart[tri_list[t5].n2],
nodes_cart[tri_list[t5].n3],
n5);
1998-01-14 02:11:30 +00:00
count = 5;
}
1998-09-21 23:16:23 +00:00
// printf(" norm[2] = %.2f %.2f %.2f\n", n1[2], n2[2], n3[2]);
1998-01-14 02:11:30 +00:00
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;
1998-09-21 23:16:23 +00:00
// printf(" count = %d\n", count);
// printf(" Ave. normal = %.4f %.4f %.4f\n", norm[0], norm[1],
// norm[2]);
1998-01-14 02:11:30 +00:00
MAT3_NORMALIZE_VEC(norm, temp);
1998-09-21 23:16:23 +00:00
// printf(" Normalized ave. normal = %.4f %.4f %.4f\n",
// norm[0], norm[1], norm[2]);
1998-01-14 02:11:30 +00:00
1998-01-14 15:54:42 +00:00
fp = NULL;
1998-10-18 01:17:09 +00:00
if ( (fabs(nodes_orig[i].y() - ymin) < FG_EPSILON) &&
(fabs(nodes_orig[i].x() - xmin) < FG_EPSILON) ) {
1998-01-14 15:54:42 +00:00
fp = sw;
1998-10-18 01:17:09 +00:00
} else if ( (fabs(nodes_orig[i].y() - ymin) < FG_EPSILON) &&
(fabs(nodes_orig[i].x() - xmax) < FG_EPSILON) ) {
1998-01-14 15:54:42 +00:00
fp = se;
1998-10-18 01:17:09 +00:00
} else if ( (fabs(nodes_orig[i].y() - ymax) < FG_EPSILON) &&
(fabs(nodes_orig[i].x() - xmax) < FG_EPSILON)) {
1998-01-14 15:54:42 +00:00
fp = ne;
1998-10-18 01:17:09 +00:00
} else if ( (fabs(nodes_orig[i].y() - ymax) < FG_EPSILON) &&
(fabs(nodes_orig[i].x() - xmin) < FG_EPSILON) ) {
1998-01-14 15:54:42 +00:00
fp = nw;
1998-10-18 01:17:09 +00:00
} else if ( fabs(nodes_orig[i].x() - xmin) < FG_EPSILON ) {
1998-01-14 15:54:42 +00:00
fp = west;
1998-10-18 01:17:09 +00:00
} else if ( fabs(nodes_orig[i].x() - xmax) < FG_EPSILON ) {
1998-01-14 15:54:42 +00:00
fp = east;
1998-10-18 01:17:09 +00:00
} else if ( fabs(nodes_orig[i].y() - ymin) < FG_EPSILON ) {
1998-01-14 15:54:42 +00:00
fp = south;
1998-10-18 01:17:09 +00:00
} else if ( fabs(nodes_orig[i].y() - ymax) < FG_EPSILON ) {
1998-01-14 15:54:42 +00:00
fp = north;
}
if ( fp != NULL ) {
fprintf(fp, "vn %.4f %.4f %.4f\n", norm[0], norm[1], norm[2]);
1998-01-14 02:11:30 +00:00
}
}
1998-03-03 03:36:57 +00:00
if ( sw ) { fclose(sw); }
if ( se ) { fclose(se); }
if ( ne ) { fclose(ne); }
if ( nw ) { fclose(nw); }
1998-01-14 02:11:30 +00:00
1998-03-03 03:36:57 +00:00
if ( north ) { fclose(north); }
if ( south ) { fclose(south); }
if ( east ) { fclose(east); }
if ( west ) { fclose(west); }
1998-01-14 15:54:42 +00:00
1998-03-03 03:36:57 +00:00
if ( body ) { fclose(body); }
1998-01-14 02:11:30 +00:00
}
int main(int argc, char **argv) {
string basename, basepath, temp;
1998-07-04 00:55:39 +00:00
fgBUCKET p;
1998-01-14 02:11:30 +00:00
long int index;
int len;
basename = argv[1];
1998-01-14 02:11:30 +00:00
1998-09-21 23:16:23 +00:00
// find the base path of the file
basepath = extract_path(basename);
basepath = extract_path(basepath);
basepath = extract_path(basepath);
cout << "basepath = " + basepath + "\n";
1998-01-14 02:11:30 +00:00
1998-09-21 23:16:23 +00:00
// find the index of the current file
temp = extract_file(basename);
len = temp.length();
1998-01-14 02:11:30 +00:00
if ( len >= 2 ) {
temp = temp.substr(0, len-2);
1998-01-14 02:11:30 +00:00
}
index = atoi( temp.c_str() );
cout << "index = " << index << "\n";
fgBucketParseIndex(index, &p);
1998-01-14 02:11:30 +00:00
cout << "bucket = " << p.lon << " " << p.lat << " " <<
p.x << " " << p.y << "\n";
1998-09-21 23:16:23 +00:00
// generate the indexes of the neighbors
fgBucketOffset(&p, &ne_index, 1, 1);
fgBucketOffset(&p, &nw_index, -1, 1);
fgBucketOffset(&p, &se_index, 1, -1);
fgBucketOffset(&p, &sw_index, -1, -1);
1998-01-14 02:11:30 +00:00
fgBucketOffset(&p, &north_index, 0, 1);
fgBucketOffset(&p, &south_index, 0, -1);
fgBucketOffset(&p, &east_index, 1, 0);
fgBucketOffset(&p, &west_index, -1, 0);
1998-01-14 02:11:30 +00:00
1998-09-21 23:16:23 +00:00
// 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);
1998-01-14 02:11:30 +00:00
1998-09-21 23:16:23 +00:00
// load the input data files
1998-01-14 02:11:30 +00:00
triload(basename);
1998-09-21 23:16:23 +00:00
// dump in WaveFront .obj format
1998-01-14 02:11:30 +00:00
dump_obj(basename, basepath);
return(0);
}
1998-09-21 23:16:23 +00:00
// $Log$
// Revision 1.7 1998/11/06 21:33:57 curt
// Updates to go along with changes in fgstream.
//
1998-10-21 14:56:20 +00:00
// Revision 1.6 1998/10/21 14:56:20 curt
// Fixed a units conversion bug.
//
1998-10-20 15:50:33 +00:00
// Revision 1.5 1998/10/20 15:50:33 curt
// whitespace tweak.
//
1998-10-18 01:17:09 +00:00
// Revision 1.4 1998/10/18 01:17:27 curt
// Point3D tweaks.
//
// Revision 1.3 1998/09/22 23:49:56 curt
// C++-ified, STL-ified, and string-ified.
//
1998-09-21 23:16:23 +00:00
// 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.
//