#include <time.h>
-#include <Math/mat3.h>
#include <Polygon/names.hxx>
#include <Tools/scenery_version.hxx>
#include "genobj.hxx"
-// build the node -> element (triangle) reverse lookup table. there
-// is an entry for each point containing a list of all the triangles
-// that share that point.
-void FGGenOutput::gen_node_ele_lookup_table( FGConstruct& c ) {
- int_list ele_list;
- ele_list.erase( ele_list.begin(), ele_list.end() );
-
- // initialize reverse_ele_lookup structure by creating an empty
- // list for each point
- point_list wgs84_nodes = c.get_wgs84_nodes();
- const_point_list_iterator w_current = wgs84_nodes.begin();
- const_point_list_iterator w_last = wgs84_nodes.end();
- for ( ; w_current != w_last; ++w_current ) {
- reverse_ele_lookup.push_back( ele_list );
- }
-
- // traverse triangle structure building reverse lookup table
- const_triele_list_iterator current = tri_elements.begin();
- const_triele_list_iterator last = tri_elements.end();
- int counter = 0;
- for ( ; current != last; ++current ) {
- reverse_ele_lookup[ current->get_n1() ].push_back( counter );
- reverse_ele_lookup[ current->get_n2() ].push_back( counter );
- reverse_ele_lookup[ current->get_n3() ].push_back( counter );
- ++counter;
- }
-}
-
-
-// caclulate the normal for the specified triangle face
-Point3D FGGenOutput::calc_normal( FGConstruct& c, int i ) {
- double v1[3], v2[3], normal[3];
- double temp;
-
- point_list wgs84_nodes = c.get_wgs84_nodes();
-
- Point3D p1 = wgs84_nodes[ tri_elements[i].get_n1() ];
- Point3D p2 = wgs84_nodes[ tri_elements[i].get_n2() ];
- Point3D p3 = wgs84_nodes[ tri_elements[i].get_n3() ];
-
- 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();
-
- MAT3cross_product(normal, v1, v2);
- MAT3_NORMALIZE_VEC(normal,temp);
-
- return Point3D( normal[0], normal[1], normal[2] );
-}
-
-
-// build the face normal list
-void FGGenOutput::gen_face_normals( FGConstruct& c ) {
- // traverse triangle structure building the face normal table
-
- cout << "calculating face normals" << endl;
-
- for ( int i = 0; i < (int)tri_elements.size(); i++ ) {
- // cout << calc_normal( i ) << endl;
- face_normals.push_back( calc_normal( c, i ) );
- }
-
-}
-
-
-// calculate the normals for each point in wgs84_nodes
-void FGGenOutput::gen_normals( FGConstruct& c ) {
- Point3D normal;
- cout << "caculating node normals" << endl;
-
- point_list wgs84_nodes = c.get_wgs84_nodes();
-
- // for each node
- for ( int i = 0; i < (int)wgs84_nodes.size(); ++i ) {
- int_list tri_list = reverse_ele_lookup[i];
-
- int_list_iterator current = tri_list.begin();
- int_list_iterator last = tri_list.end();
-
- Point3D average( 0.0 );
-
- // for each triangle that shares this node
- for ( ; current != last; ++current ) {
- normal = face_normals[ *current ];
- average += normal;
- // cout << normal << endl;
- }
-
- average /= tri_list.size();
- // cout << "average = " << average << endl;
-
- point_normals.push_back( average );
- }
-}
-
-
// calculate the global bounding sphere. Center is the average of the
// points.
void FGGenOutput::calc_gbs( FGConstruct& c ) {
// build the necessary output structures based on the triangulation
// data
-int FGGenOutput::build( FGConstruct& c, const FGArray& array ) {
+int FGGenOutput::build( FGConstruct& c ) {
FGTriNodes trinodes = c.get_tri_nodes();
// copy the geodetic node list into this class
calc_gbs( c );
cout << "center = " << gbs_center << " radius = " << gbs_radius << endl;
- // build the node -> element (triangle) reverse lookup table
- gen_node_ele_lookup_table( c );
-
- // build the face normal list
- gen_face_normals( c );
-
- // calculate the normals for each point in wgs84_nodes
- gen_normals( c );
-
return 1;
}
fprintf(fp, "\n");
// write vertex normals
+ point_list point_normals = c.get_point_normals();
fprintf(fp, "# vertex normal list\n");
const_point_list_iterator n_current = point_normals.begin();
const_point_list_iterator n_last = point_normals.end();
FG_USING_STD(vector);
-typedef vector < int_list > belongs_to_list;
-typedef belongs_to_list::iterator belongs_to_list_iterator;
-typedef belongs_to_list::const_iterator belongs_to_list_tripoly_iterator;
-
-
class FGGenOutput {
private:
// node list in geodetic coordinates
point_list geod_nodes;
- // face normal list (for flat shading)
- point_list face_normals;
-
- // normal list (for each point) in cart coords (for smooth
- // shading)
- point_list point_normals;
-
// triangles (by index into point list)
triele_list tri_elements;
// fan list
fan_list fans[FG_MAX_AREA_TYPES];
- // for each node, a list of triangle indices that contain this node
- belongs_to_list reverse_ele_lookup;
-
// global bounding sphere
Point3D gbs_center;
double gbs_radius;
- // build the node -> element (triangle) reverse lookup table.
- // there is an entry for each point containing a list of all the
- // triangles that share that point.
- void gen_node_ele_lookup_table( FGConstruct& c );
-
- // calculate the normals for each point in wgs84_nodes
- void gen_normals( FGConstruct& c );
-
- // build the face normal list
- void gen_face_normals( FGConstruct& c );
-
- // caclulate the normal for the specified triangle face
- Point3D calc_normal( FGConstruct& c, int i );
-
// calculate the global bounding sphere. Center is the average of
// the points.
void calc_gbs( FGConstruct& c );
// build the necessary output structures based on the
// triangulation data
- int build( FGConstruct& c, const FGArray& array );
+ int build( FGConstruct& c );
// write out the fgfs scenery file
int write( FGConstruct &c );