From: curt Date: Sun, 2 May 1999 22:11:30 +0000 (+0000) Subject: Further restructuring to facilitate the tile edge matching process. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=99e83c21a44f3bff04ade108510c33e4e721caa4;p=flightgear.git Further restructuring to facilitate the tile edge matching process. --- diff --git a/Tools/Construct/GenOutput/genobj.cxx b/Tools/Construct/GenOutput/genobj.cxx index 5d1b2e24b..1a1cafe41 100644 --- a/Tools/Construct/GenOutput/genobj.cxx +++ b/Tools/Construct/GenOutput/genobj.cxx @@ -24,108 +24,12 @@ #include -#include #include #include #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 ) { @@ -158,7 +62,7 @@ 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 @@ -192,15 +96,6 @@ int FGGenOutput::build( FGConstruct& c, const FGArray& array ) { 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; } @@ -342,6 +237,7 @@ int FGGenOutput::write( FGConstruct &c ) { 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(); diff --git a/Tools/Construct/GenOutput/genobj.hxx b/Tools/Construct/GenOutput/genobj.hxx index f9bf54ca4..b38f58eb7 100644 --- a/Tools/Construct/GenOutput/genobj.hxx +++ b/Tools/Construct/GenOutput/genobj.hxx @@ -48,11 +48,6 @@ FG_USING_STD(string); 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: @@ -60,40 +55,16 @@ 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 ); @@ -114,7 +85,7 @@ public: // 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 ); diff --git a/Tools/Construct/Triangulate/triangle.hxx b/Tools/Construct/Triangulate/triangle.hxx index c40150bee..b94842501 100644 --- a/Tools/Construct/Triangulate/triangle.hxx +++ b/Tools/Construct/Triangulate/triangle.hxx @@ -86,6 +86,7 @@ public: inline FGTriNodes get_out_nodes() const { return out_nodes; } inline size_t get_out_nodes_size() const { return out_nodes.size(); } inline triele_list get_elelist() const { return elelist; } + inline FGTriSegments get_out_segs() const { return out_segs; } }; diff --git a/Tools/Construct/Triangulate/trisegs.hxx b/Tools/Construct/Triangulate/trisegs.hxx index 77eabd043..dc3d38317 100644 --- a/Tools/Construct/Triangulate/trisegs.hxx +++ b/Tools/Construct/Triangulate/trisegs.hxx @@ -105,7 +105,7 @@ public: void unique_divide_and_add( const point_list& node_list, const FGTriSeg& s ); - // return the master node list + // return the master segment list inline triseg_list get_seg_list() const { return seg_list; } // return the ith segment