WIP

parent 6815b904
......@@ -17,6 +17,7 @@
#include <citygml/linestring.h>
#include <citygml/polygon.h>
#include <citygml/tesselator.h>
#include <citygml/object.h>
#ifdef ITA_GEO_WITH_XERCES_SUPPORT
// Xerces-c
......@@ -68,90 +69,91 @@ void ITAGeo::CCityGMLModel::GetBuildingMesh( const ITAGeo::CCityGMLModel::CCityB
{
for( unsigned int l = 0; l < oCityRootObject.getChildCityObject( j ).getGeometry( k ).getPolygonsCount(); l++ )
{
std::shared_ptr<const citygml::Polygon> pPolygon = oCityRootObject.getChildCityObject( j ).getGeometry( k ).getPolygon( l );
std::vector<TVec3d> vPolygonVertices = pPolygon->getVertices();
assert( vPolygonVertices.size() > 2 );
std::shared_ptr< const citygml::Polygon > pPolygon = oCityRootObject.getChildCityObject( j ).getGeometry( k ).getPolygon( l );
std::vector< TVec3d > vVertexPoints( pPolygon->getVertices() );
std::vector< CITAMesh::VertexHandle > vFaceVertices( vVertexPoints.size() );
std::vector< CITAMesh::Point > vMeshPoints( vVertexPoints.size() );
assert( vVertexPoints.size() > 2 );
assert( ( pPolygon->getIndices().size() % 3 ) == 0 );
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//! Necessary workaround for the duplicate Vertices (always consecutive) that citygml::Polygon::getVertices() occasionally produces.
// coordinates in the duplicates vary around the 10 decimal spot, hence the rounding to the 3rd spot
for( unsigned int m = 0; m < vPolygonVertices.size(); m++ )
for( unsigned int m = 0; m < vVertexPoints.size(); m++ )
{
vPolygonVertices[ m ].x = std::floor( vPolygonVertices[ m ].x * 100000 + 0.5 ) / 100000;
vPolygonVertices[ m ].y = std::floor( vPolygonVertices[ m ].y * 100000 + 0.5 ) / 100000;
vPolygonVertices[ m ].z = std::floor( vPolygonVertices[ m ].z * 100000 + 0.5 ) / 100000;
}
/*
vVertexPoints[ m ].x = std::floor( vVertexPoints[ m ].x * 100000 + 0.5 ) / 100000;
vVertexPoints[ m ].y = std::floor( vVertexPoints[ m ].y * 100000 + 0.5 ) / 100000;
vVertexPoints[ m ].z = std::floor( vVertexPoints[ m ].z * 100000 + 0.5 ) / 100000;
*/
vFaceVertices[ m ] = CITAMesh::VertexHandle();
// erases duplicates, but can only remove consecutive duplicates.
vPolygonVertices.erase( std::unique( vPolygonVertices.begin(), vPolygonVertices.end() ), vPolygonVertices.end() );
if( vPolygonVertices.size() < 3 )
{
std::cerr << "Found invalid line ring with less than three unique vertices. Skipping this face." << std::endl;
continue;
}
vMeshPoints[ m ] = CityGMLPoint3DToITAMeshPoint( vVertexPoints[ m ] );
bool bVertexExists = false;
// First and last vertex are always identical by gml definition of a line ring; has to be removed so OpenMesh can produce a face
while( vPolygonVertices.front() == vPolygonVertices.back() )
{
vPolygonVertices.pop_back();
}
if( vPolygonVertices.size() < 3 )
{
std::cerr << "Found invalid line ring with less than three independent vertices. Skipping this face." << std::endl;
continue;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//! Actual Mesh conversion
std::vector<CITAMesh::VertexHandle> vFaceVertices;
// Multiple faces can share the same vertices, following loop makes sure only new vertices are added to mesh
for( unsigned int m = 0; m < vPolygonVertices.size(); m++ )
{
bool bSkip = false;
const CITAMesh::Point CurrentPoint = CityGMLPoint3DToITAMeshPoint( vPolygonVertices[ m ] );
CITAMesh::VertexIter it_v;
for( it_v = pMesh->vertices_begin(); it_v != pMesh->vertices_end(); it_v++ )
#if 0
for( CITAMesh::VertexIter it_v = pMesh->vertices_begin(); it_v != pMesh->vertices_end(); it_v++ )
{
CITAMesh::VertexHandle vhVertex( *it_v );
if( CurrentPoint == pMesh->point( vhVertex ) )
const CITAMesh::Point ExistingPoint = pMesh->point( vhVertex );
if( vMeshPoints[ m ] == ExistingPoint )
{
vFaceVertices.push_back( vhVertex );
bSkip = true;
vFaceVertices[ m ] = vhVertex;
if( m > 1 )
if( vhVertex != vFaceVertices[ m - 1 ] )
;
bVertexExists = true;
break;
}
}
if( bSkip )
#endif
if( !bVertexExists )
vFaceVertices[ m ] = pMesh->add_vertex( vMeshPoints[ m ] );
}
// Split polygons
for( size_t i = 0; i < pPolygon->getIndices().size(); i += 3 )
{
std::vector< CITAMesh::VertexHandle > vNewFaceVertices( 3 );
for( size_t j = 0; j < 3; j++ )
vNewFaceVertices[ j ] = vFaceVertices[ pPolygon->getIndices()[ i + j ] ];
std::set<CITAMesh::VertexHandle> s( vNewFaceVertices.begin(), vNewFaceVertices.end() );
vNewFaceVertices.assign( s.begin(), s.end() );
if( vNewFaceVertices.size() != 3 )
{
std::cerr << "Invalid vertex list in " << oCityRootObject.getId() << " (skipping)" << std::endl;
}
else
{
continue; //need to exit both loops to check next vertex
pMesh->add_face( vNewFaceVertices );
}
vFaceVertices.push_back( pMesh->add_vertex( CurrentPoint ) );
}
size_t iNumVerticesPre = vFaceVertices.size();
vFaceVertices.erase( std::unique( vFaceVertices.begin(), vFaceVertices.end() ), vFaceVertices.end() );
if( vFaceVertices.size() != iNumVerticesPre )
/* Split polygons
for( size_t i = 0; i < pPolygon->getIndices().size(); )
{
std::cout << "For an unkown reason, detected non-unique vertices to be added as face during mesh conversion. Will skip this face for safety." << std::endl;
//continue;
}
std::vector< CITAMesh::VertexHandle > vNewFaceVertices;
iNumVerticesPre = vFaceVertices.size();
std::set< CITAMesh::VertexHandle > s( vFaceVertices.begin(), vFaceVertices.end() );
vFaceVertices.assign( s.begin(), s.end() );
if( vFaceVertices.size() != iNumVerticesPre )
std::cout << "For an unkown reason, detected non-unique vertices to be added as face during mesh conversion. Made them unique." << std::endl;
for( size_t j = i; j < pPolygon->getIndices().size(); j++ )
{
if( pPolygon->getIndices()[ j ] == pPolygon->getIndices()[ i ] && vNewFaceVertices.size() > 2 )
{
break;
}
vNewFaceVertices.push_back( vFaceVertices[ pPolygon->getIndices()[ j ] ] );
}
if( vFaceVertices.size() < 3 )
{
std::cerr << "Found invalid number of face vertices after mesh conversion. Skipping this face." << std::endl;
continue;
if( vNewFaceVertices.size() > 2 )
{
pMesh->add_face( vNewFaceVertices ); // Last polygon
i += vNewFaceVertices.size();
}
}
pMesh->add_face( vFaceVertices );
*/
}
}
}
......@@ -253,8 +255,8 @@ void ITAGeo::CCityGMLModel::CalculateObjectCentroids()
const TVec3d v3PolygonCentroid( fPolygonCentroid_X / vPolygonVertices.size(), fPolygonCentroid_Y / vPolygonVertices.size(), fPolygonCentroid_Z / vPolygonVertices.size() );
vPolygonCentroids.push_back( v3PolygonCentroid );
}
}
}
}
}
//Calculate Object Centroid by averaging all Polygon Centroids of Object
float fObjectCentroid_X = 0;
......
......@@ -59,8 +59,9 @@ static vector< string > vsAachenCityFilePaths = {
"LoD2_293_5629_1_NW",
"LoD2_294_5628_1_NW",
"LoD2_294_5629_1_NW",
"LoD2_295_5628_1_NW",
"LoD2_295_5629_1_NW" };
//"LoD2_295_5628_1_NW",
// "LoD2_295_5629_1_NW"
};
// Resource (Land NRW, 2017, https://www.govdata.de/dl-de/by-2-0): https://www.opengeodata.nrw.de/produkte/geobasis/3d-gm/3d-gm_lod2/
//static string sCityGMLFilePath = "Aachen/LoD2_287_5631_1_NW_no_terrain_intersection.gml";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment