1
0
Fork 0

Point3D tweaks.

This commit is contained in:
curt 1998-10-18 01:17:09 +00:00
parent 24c9bdb713
commit b0d67bf6b9
5 changed files with 101 additions and 127 deletions

View file

@ -239,7 +239,7 @@ int fgDEM::read_a_record() {
} }
// clean off the trailing whitespace // clean off the trailing whitespace
name = trim(name, " "); name = trim(name);
cout << " Quad name field: " << name << endl; cout << " Quad name field: " << name << endl;
// DEM level code, 3 reflects processing by DMA // DEM level code, 3 reflects processing by DMA
@ -852,6 +852,9 @@ fgDEM::~fgDEM( void ) {
// $Log$ // $Log$
// Revision 1.18 1998/10/18 01:17:09 curt
// Point3D tweaks.
//
// Revision 1.17 1998/10/16 19:08:12 curt // Revision 1.17 1998/10/16 19:08:12 curt
// Portability updates from Bernie Bright. // Portability updates from Bernie Bright.
// //

View file

@ -32,6 +32,7 @@ splittris_LDADD = \
$(top_builddir)/Lib/Bucket/libBucket.a \ $(top_builddir)/Lib/Bucket/libBucket.a \
$(top_builddir)/Lib/Math/libMath.a \ $(top_builddir)/Lib/Math/libMath.a \
$(top_builddir)/Lib/Debug/libDebug.a \ $(top_builddir)/Lib/Debug/libDebug.a \
$(top_builddir)/Lib/Misc/libMisc.a \
$(top_builddir)/Lib/zlib/libz.a $(top_builddir)/Lib/zlib/libz.a
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib
@ -39,6 +40,9 @@ INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# $Log$ # $Log$
# Revision 1.7 1998/10/18 01:17:25 curt
# Point3D tweaks.
#
# Revision 1.6 1998/07/30 23:49:26 curt # Revision 1.6 1998/07/30 23:49:26 curt
# Removed libtool support. # Removed libtool support.
# #

View file

@ -35,18 +35,19 @@
#include "splittris.hxx" #include "splittris.hxx"
#include <Include/fg_constants.h> #include <Include/fg_constants.h>
#include <Include/fg_types.h>
#include <Bucket/bucketutils.h> #include <Bucket/bucketutils.h>
#include <Math/fg_geodesy.h> #include <Math/fg_geodesy.hxx>
#include <Math/mat3.h> #include <Math/mat3.h>
#include <Math/point3d.hxx>
#include <Math/polar3d.hxx> #include <Math/polar3d.hxx>
#include <Misc/fgstream.hxx>
// int nodecount, tricount; // int nodecount, tricount;
double xmin, xmax, ymin, ymax; double xmin, xmax, ymin, ymax;
// static double nodes_orig[MAX_NODES][3]; // static double nodes_orig[MAX_NODES][3];
// static fgPoint3d nodes_cart[MAX_NODES]; // static Point3D nodes_cart[MAX_NODES];
// static int tris[MAX_TRIS][3]; // static int tris[MAX_TRIS][3];
container_3d nodes_orig; container_3d nodes_orig;
@ -56,42 +57,16 @@ container_tri tri_list;
fgBUCKET ne_index, nw_index, sw_index, se_index; fgBUCKET ne_index, nw_index, sw_index, se_index;
fgBUCKET north_index, south_index, east_index, west_index; fgBUCKET north_index, south_index, east_index, west_index;
// convert a geodetic point lon(arcsec), lat(arcsec), elev(meter) to a
// cartesian point
fgPoint3d geod_to_cart(fgPoint3d geod) {
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]);
gc_lon = geod.lon * ARCSEC_TO_RAD;
fgGeodToGeoc(geod.lat * ARCSEC_TO_RAD, geod.radius, &sl_radius, &gc_lat);
// 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.radius;
cp = fgPolarToCart3d(pp);
// 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, void calc_normal(const Point3D& p1, const Point3D& p2,
fgPoint3d p3, double normal[3]) const Point3D& p3, double normal[3])
{ {
double v1[3], v2[3]; double v1[3], v2[3];
double temp; double temp;
v1[0] = p2.x - p1.x; v1[1] = p2.y - p1.y; v1[2] = p2.z - p1.z; 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; v2[0] = p3.x() - p1.x(); v2[1] = p3.y() - p1.y(); v2[2] = p3.z() - p1.z();
MAT3cross_product(normal, v1, v2); MAT3cross_product(normal, v1, v2);
MAT3_NORMALIZE_VEC(normal,temp); MAT3_NORMALIZE_VEC(normal,temp);
@ -159,9 +134,8 @@ 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(const string& basename) { void triload(const string& basename) {
string nodename, elename; string nodename, elename;
fgPoint3d node1, node2; Point3D node1, node2;
triangle tri; triangle tri;
FILE *node_file, *ele_file;
int nodecount, tricount, dim, junk1, junk2; int nodecount, tricount, dim, junk1, junk2;
int i; int i;
@ -169,7 +143,9 @@ void triload(const string& basename) {
elename = basename + ".ele"; elename = basename + ".ele";
cout << "Loading node file: " + nodename + " ...\n"; cout << "Loading node file: " + nodename + " ...\n";
if ( (node_file = fopen(nodename.c_str(), "r")) == NULL ) {
fg_gzifstream node_in( nodename );
if ( !node_in ) {
cout << "Cannot open file " + nodename + "\n"; cout << "Cannot open file " + nodename + "\n";
exit(-1); exit(-1);
} }
@ -181,56 +157,54 @@ void triload(const string& basename) {
nodes_cart.push_back(node1); nodes_cart.push_back(node1);
tri_list.push_back(tri); tri_list.push_back(tri);
fscanf(node_file, "%d %d %d %d", &nodecount, &dim, &junk1, &junk2); node_in.stream() >> nodecount >> dim >> junk1 >> junk2;
cout << " Expecting " << nodecount << " nodes\n"; cout << " Expecting " << nodecount << " nodes\n";
for ( i = 1; i <= nodecount; i++ ) { for ( i = 1; i <= nodecount; i++ ) {
fscanf(node_file, "%d %lf %lf %lf %d\n", &junk1, node_in.stream() >> junk1 >> node1 >> junk2;
&(node1.x), &(node1.y), &(node1.z), &junk2);
printf("%d %.2f %.2f %.2f\n", junk1, node1.x, node1.y, node1.z);
nodes_orig.push_back(node1); nodes_orig.push_back(node1);
node2 = geod_to_cart(node1); // printf("%d %.2f %.2f %.2f\n", junk1, node1.x, node1.y, node1.z);
node2 = fgGeodToCart(node1);
nodes_cart.push_back(node2); nodes_cart.push_back(node2);
printf("%d %.2f %.2f %.2f\n", junk1, node2.x, node2.y, node2.z); // printf("%d %.2f %.2f %.2f\n", junk1, node2.x, node2.y, node2.z);
if ( i == 1 ) { if ( i == 1 ) {
xmin = xmax = node1.x; xmin = xmax = node1.x();
ymin = ymax = node1.y; ymin = ymax = node1.y();
} else { } else {
if ( node1.x < xmin ) { if ( node1.x() < xmin ) {
xmin = node1.x; xmin = node1.x();
} }
if ( node1.x > xmax ) { if ( node1.x() > xmax ) {
xmax = node1.x; xmax = node1.x();
} }
if ( node1.y < ymin ) { if ( node1.y() < ymin ) {
ymin = node1.y; ymin = node1.y();
} }
if ( node1.y > ymax ) { if ( node1.y() > ymax ) {
ymax = node1.y; ymax = node1.y();
} }
} }
} }
fclose(node_file);
cout << "Loading element file: " + elename + " ...\n"; cout << "Loading element file: " + elename + " ...\n";
if ( (ele_file = fopen(elename.c_str(), "r")) == NULL ) { fg_gzifstream ele_in( elename );
if ( !ele_in ) {
cout << "Cannot open file " + elename + "\n"; cout << "Cannot open file " + elename + "\n";
exit(-1); exit(-1);
} }
fscanf(ele_file, "%d %d %d", &tricount, &junk1, &junk2); ele_in.stream() >> tricount >> junk1 >> junk2;
cout << " Expecting " << tricount << " elements\n"; cout << " Expecting " << tricount << " elements\n";
for ( i = 1; i <= tricount; i++ ) { for ( i = 1; i <= tricount; i++ ) {
fscanf(ele_file, "%d %d %d %d\n", &junk1, // fscanf(ele_file, "%d %d %d %d\n", &junk1,
&(tri.n1), &(tri.n2), &(tri.n3)); // &(tri.n1), &(tri.n2), &(tri.n3));
printf("%d %d %d %d\n", junk1, tri.n1, tri.n2, tri.n3); ele_in.stream() >> junk1 >> tri.n1 >> tri.n2 >> tri.n3;
// printf("%d %d %d %d\n", junk1, tri.n1, tri.n2, tri.n3);
tri_list.push_back(tri); tri_list.push_back(tri);
} }
fclose(ele_file);
} }
@ -413,10 +387,11 @@ FILE *my_open(const string& basename, const string& basepath,
// dump in WaveFront .obj format // dump in WaveFront .obj format
void dump_obj(const string& basename, const string& basepath) { void dump_obj(const string& basename, const string& basepath) {
fgPoint3d node; Point3D node;
double n1[3], n2[3], n3[3], n4[3], n5[3], norm[3], temp; 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; FILE *fp, *sw, *se, *ne, *nw, *north, *south, *east, *west, *body;
int i, t1, t2, t3, t4, t5, count, size; int i, t1, t2, t3, t4, t5, count, size;
double x, y, z;
sw = my_open(basename, basepath, ".sw"); sw = my_open(basename, basepath, ".sw");
se = my_open(basename, basepath, ".se"); se = my_open(basename, basepath, ".se");
@ -441,32 +416,36 @@ void dump_obj(const string& basename, const string& basepath) {
for ( ; current != last; ++current) { for ( ; current != last; ++current) {
node = *current; node = *current;
if ( (fabs(node.y - ymin) < FG_EPSILON) && if ( (fabs(node.y() - ymin) < FG_EPSILON) &&
(fabs(node.x - xmin) < FG_EPSILON) ) { (fabs(node.x() - xmin) < FG_EPSILON) ) {
fp = sw; fp = sw;
} else if ( (fabs(node.y - ymin) < FG_EPSILON) && } else if ( (fabs(node.y() - ymin) < FG_EPSILON) &&
(fabs(node.x - xmax) < FG_EPSILON) ) { (fabs(node.x() - xmax) < FG_EPSILON) ) {
fp = se; fp = se;
} else if ( (fabs(node.y - ymax) < FG_EPSILON) && } else if ( (fabs(node.y() - ymax) < FG_EPSILON) &&
(fabs(node.x - xmax) < FG_EPSILON)) { (fabs(node.x() - xmax) < FG_EPSILON)) {
fp = ne; fp = ne;
} else if ( (fabs(node.y - ymax) < FG_EPSILON) && } else if ( (fabs(node.y() - ymax) < FG_EPSILON) &&
(fabs(node.x - xmin) < FG_EPSILON) ) { (fabs(node.x() - xmin) < FG_EPSILON) ) {
fp = nw; fp = nw;
} else if ( fabs(node.x - xmin) < FG_EPSILON ) { } else if ( fabs(node.x() - xmin) < FG_EPSILON ) {
fp = west; fp = west;
} else if ( fabs(node.x - xmax) < FG_EPSILON ) { } else if ( fabs(node.x() - xmax) < FG_EPSILON ) {
fp = east; fp = east;
} else if ( fabs(node.y - ymin) < FG_EPSILON ) { } else if ( fabs(node.y() - ymin) < FG_EPSILON ) {
fp = south; fp = south;
} else if ( fabs(node.y - ymax) < FG_EPSILON ) { } else if ( fabs(node.y() - ymax) < FG_EPSILON ) {
fp = north; fp = north;
} else { } else {
fp = body; fp = body;
} }
x = node.x();
y = node.y();
z = node.z();
if ( fp != NULL ) { if ( fp != NULL ) {
fprintf(fp, "gdn %.2f %.2f %.2f\n", node.x, node.y, node.z); fprintf(fp, "gdn %.2f %.2f %.2f\n", x, y, z);
} }
} }
@ -538,25 +517,25 @@ void dump_obj(const string& basename, const string& basepath) {
fp = NULL; fp = NULL;
if ( (fabs(nodes_orig[i].y - ymin) < FG_EPSILON) && if ( (fabs(nodes_orig[i].y() - ymin) < FG_EPSILON) &&
(fabs(nodes_orig[i].x - xmin) < FG_EPSILON) ) { (fabs(nodes_orig[i].x() - xmin) < FG_EPSILON) ) {
fp = sw; fp = sw;
} else if ( (fabs(nodes_orig[i].y - ymin) < FG_EPSILON) && } else if ( (fabs(nodes_orig[i].y() - ymin) < FG_EPSILON) &&
(fabs(nodes_orig[i].x - xmax) < FG_EPSILON) ) { (fabs(nodes_orig[i].x() - xmax) < FG_EPSILON) ) {
fp = se; fp = se;
} else if ( (fabs(nodes_orig[i].y - ymax) < FG_EPSILON) && } else if ( (fabs(nodes_orig[i].y() - ymax) < FG_EPSILON) &&
(fabs(nodes_orig[i].x - xmax) < FG_EPSILON)) { (fabs(nodes_orig[i].x() - xmax) < FG_EPSILON)) {
fp = ne; fp = ne;
} else if ( (fabs(nodes_orig[i].y - ymax) < FG_EPSILON) && } else if ( (fabs(nodes_orig[i].y() - ymax) < FG_EPSILON) &&
(fabs(nodes_orig[i].x - xmin) < FG_EPSILON) ) { (fabs(nodes_orig[i].x() - xmin) < FG_EPSILON) ) {
fp = nw; fp = nw;
} else if ( fabs(nodes_orig[i].x - xmin) < FG_EPSILON ) { } else if ( fabs(nodes_orig[i].x() - xmin) < FG_EPSILON ) {
fp = west; fp = west;
} else if ( fabs(nodes_orig[i].x - xmax) < FG_EPSILON ) { } else if ( fabs(nodes_orig[i].x() - xmax) < FG_EPSILON ) {
fp = east; fp = east;
} else if ( fabs(nodes_orig[i].y - ymin) < FG_EPSILON ) { } else if ( fabs(nodes_orig[i].y() - ymin) < FG_EPSILON ) {
fp = south; fp = south;
} else if ( fabs(nodes_orig[i].y - ymax) < FG_EPSILON ) { } else if ( fabs(nodes_orig[i].y() - ymax) < FG_EPSILON ) {
fp = north; fp = north;
} }
if ( fp != NULL ) { if ( fp != NULL ) {
@ -633,6 +612,9 @@ int main(int argc, char **argv) {
// $Log$ // $Log$
// Revision 1.4 1998/10/18 01:17:27 curt
// Point3D tweaks.
//
// Revision 1.3 1998/09/22 23:49:56 curt // Revision 1.3 1998/09/22 23:49:56 curt
// C++-ified, STL-ified, and string-ified. // C++-ified, STL-ified, and string-ified.
// //

View file

@ -39,7 +39,7 @@
using namespace std; using namespace std;
#endif #endif
#include <Include/fg_types.h> #include <Math/point3d.hxx>
// A triangle (indices of the three nodes) // A triangle (indices of the three nodes)
@ -48,7 +48,7 @@ typedef struct {
} triangle; } triangle;
typedef vector < fgPoint3d > container_3d; typedef vector < Point3D > container_3d;
typedef container_3d::iterator iterator_3d; typedef container_3d::iterator iterator_3d;
typedef container_3d::const_iterator const_iterator_3d; typedef container_3d::const_iterator const_iterator_3d;
@ -65,6 +65,9 @@ void triload(const string& basename);
// $Log$ // $Log$
// Revision 1.4 1998/10/18 01:17:28 curt
// Point3D tweaks.
//
// Revision 1.3 1998/09/22 23:49:58 curt // Revision 1.3 1998/09/22 23:49:58 curt
// C++-ified, STL-ified, and string-ified. // C++-ified, STL-ified, and string-ified.
// //

View file

@ -36,14 +36,14 @@
#include <Include/fg_types.h> #include <Include/fg_types.h>
#include <Bucket/bucketutils.h> #include <Bucket/bucketutils.h>
#include <Math/fg_geodesy.h> #include <Math/fg_geodesy.hxx>
#include <Math/mat3.h> #include <Math/mat3.h>
#include <Math/polar3d.hxx> #include <Math/polar3d.hxx>
int nodecount, tricount; int nodecount, tricount;
int normalcount = 0; int normalcount = 0;
static fgPoint3d nodes[MAX_NODES]; static Point3D nodes[MAX_NODES];
static int tris[MAX_TRIS][3]; static int tris[MAX_TRIS][3];
static double normals[MAX_NODES][3]; static double normals[MAX_NODES][3];
@ -52,42 +52,16 @@ fgBUCKET my_index;
fgBUCKET ne_index, nw_index, sw_index, se_index; fgBUCKET ne_index, nw_index, sw_index, se_index;
fgBUCKET north_index, south_index, east_index, west_index; fgBUCKET north_index, south_index, east_index, west_index;
/* 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]); */
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]); */
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); */
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, void calc_normal(Point3D p1, Point3D p2,
fgPoint3d p3, double normal[3]) Point3D p3, double normal[3])
{ {
double v1[3], v2[3]; double v1[3], v2[3];
double temp; double temp;
v1[0] = p2.x - p1.x; v1[1] = p2.y - p1.y; v1[2] = p2.z - p1.z; 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; v2[0] = p3.x() - p1.x(); v2[1] = p3.y() - p1.y(); v2[2] = p3.z() - p1.z();
MAT3cross_product(normal, v1, v2); MAT3cross_product(normal, v1, v2);
MAT3_NORMALIZE_VEC(normal, temp); MAT3_NORMALIZE_VEC(normal, temp);
@ -407,6 +381,7 @@ FILE *my_open(char *basename, char *basepath, char *ext) {
void triload(char *basename, char *basepath) { void triload(char *basename, char *basepath) {
char nodename[256], elename[256]; char nodename[256], elename[256];
double n[3]; double n[3];
Point3D p;
FILE *ne, *nw, *se, *sw, *north, *south, *east, *west; FILE *ne, *nw, *se, *sw, *north, *south, *east, *west;
FILE *node, *ele; FILE *node, *ele;
int dim, junk1, junk2; int dim, junk1, junk2;
@ -468,7 +443,8 @@ void triload(char *basename, char *basepath) {
fscanf(node, "%d %lf %lf %lf %d\n", &junk1, fscanf(node, "%d %lf %lf %lf %d\n", &junk1,
&n[0], &n[1], &n[2], &junk2); &n[0], &n[1], &n[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[i] = geod_to_cart(n); p = Point3D(n[0], n[1], n[2]);
nodes[i] = fgGeodToCart(p);
/* printf("%d %.2f %.2f %.2f\n", /* printf("%d %.2f %.2f %.2f\n",
junk1, nodes[i].x, nodes[i].y, nodes[i].z); */ junk1, nodes[i].x, nodes[i].y, nodes[i].z); */
} }
@ -506,6 +482,7 @@ void dump_obj(char *basename) {
double n1[3], n2[3], n3[3], n4[3], n5[3], norm[3], temp; double n1[3], n2[3], n3[3], n4[3], n5[3], norm[3], temp;
FILE *obj; FILE *obj;
int i, t1, t2, t3, t4, t5, count; int i, t1, t2, t3, t4, t5, count;
double x, y, z;
strcpy(objname, basename); strcpy(objname, basename);
strcat(objname, ".obj"); strcat(objname, ".obj");
@ -517,8 +494,10 @@ void dump_obj(char *basename) {
/* dump vertices */ /* dump vertices */
printf(" writing vertices\n"); printf(" writing vertices\n");
for ( i = 1; i <= nodecount; i++ ) { for ( i = 1; i <= nodecount; i++ ) {
fprintf(obj, "v %.6f %.6f %.6f\n", x = nodes[i].x();
nodes[i].x, nodes[i].y, nodes[i].z); y = nodes[i].y();
z = nodes[i].z();
fprintf(obj, "v %.6f %.6f %.6f\n", x, y, z);
} }
printf(" calculating and writing normals\n"); printf(" calculating and writing normals\n");
@ -644,9 +623,12 @@ int main(int argc, char **argv) {
/* $Log$ /* $Log$
/* Revision 1.1 1998/07/08 14:54:53 curt /* Revision 1.2 1998/10/18 01:17:29 curt
/* renamed *.[ch] to *.[ch]xx /* Point3D tweaks.
/* /*
* Revision 1.1 1998/07/08 14:54:53 curt
* renamed *.[ch] to *.[ch]xx
*
* Revision 1.17 1998/07/04 00:56:40 curt * Revision 1.17 1998/07/04 00:56:40 curt
* typedef'd struct fgBUCKET. * typedef'd struct fgBUCKET.
* *