1
0
Fork 0

- fix shape debug after rebase.

- improve the 32768 traingles per material workaround
This commit is contained in:
Peter Sadrozinski 2012-10-09 18:28:14 -04:00
parent abfea1cd2d
commit f0d8d37671
4 changed files with 58 additions and 64 deletions

View file

@ -38,6 +38,8 @@ bool TGConstruct::ClipLandclassPolys( void ) {
int i, j; int i, j;
Point3D p; Point3D p;
point2d min, max; point2d min, max;
bool debug_area, debug_shape;
static int accum_idx = 0;
#if !USE_ACCUMULATOR #if !USE_ACCUMULATOR
TGPolygon accum; TGPolygon accum;
@ -104,7 +106,7 @@ bool TGConstruct::ClipLandclassPolys( void ) {
} }
// Dump the masks // Dump the masks
if ( debug_all || debug_shapes.size() ) { if ( debug_all || debug_shapes.size() || debug_areas.size() ) {
WriteDebugPoly( "land_mask", "", land_mask ); WriteDebugPoly( "land_mask", "", land_mask );
WriteDebugPoly( "water_mask", "", water_mask ); WriteDebugPoly( "water_mask", "", water_mask );
WriteDebugPoly( "island_mask", "", island_mask ); WriteDebugPoly( "island_mask", "", island_mask );
@ -112,35 +114,19 @@ bool TGConstruct::ClipLandclassPolys( void ) {
// process polygons in priority order // process polygons in priority order
for ( i = 0; i < TG_MAX_AREA_TYPES; ++i ) { for ( i = 0; i < TG_MAX_AREA_TYPES; ++i ) {
debug_area = IsDebugArea( i );
for( j = 0; j < (int)polys_in.area_size(i); ++j ) { for( j = 0; j < (int)polys_in.area_size(i); ++j ) {
TGPolygon current = polys_in.get_mask(i, j); TGPolygon current = polys_in.get_mask(i, j);
TGPolygon before; debug_shape = IsDebugShape( polys_in.get_shape( i, j ).id );
char layer_name[64];
SG_LOG( SG_CLIPPER, SG_INFO, "Clipping " << get_area_name( (AreaType)i ) << "(" << i << "):" << j+1 << " of " << polys_in.area_size(i) << " id " << polys_in.get_shape( i, j ).id ); SG_LOG( SG_CLIPPER, SG_INFO, "Clipping " << get_area_name( (AreaType)i ) << "(" << i << "):" << j+1 << " of " << polys_in.area_size(i) << " id " << polys_in.get_shape( i, j ).id );
tmp = current; tmp = current;
if ( IsDebugShape( polys_in.get_shape( i, j ).id ) ) {
char name[32];
sprintf(name, "shape %d,%d", i,j);
sprintf(layer_name, "premask_%d_%d_%d", i, j, polys_in.get_shape( i, j ).id);
WriteDebugPoly( layer_name, name, tmp );
//sprintf(name, "accum %d,%d", i,j);
//WriteDebugPoly( layer_name, name, accum );
}
// if not a hole, clip the area to the land_mask // if not a hole, clip the area to the land_mask
if ( !ignoreLandmass && !is_hole_area( i ) ) { if ( !ignoreLandmass && !is_hole_area( i ) ) {
before = tmp;
tmp = tgPolygonInt( tmp, land_mask ); tmp = tgPolygonInt( tmp, land_mask );
if (tmp.total_size() != before.total_size()) {
SG_LOG( SG_CLIPPER, SG_INFO, "Clip w/land mask gave odd result" );
// exit(0);
}
} }
// if a water area, cut out potential islands // if a water area, cut out potential islands
@ -148,29 +134,25 @@ bool TGConstruct::ClipLandclassPolys( void ) {
// clip against island mask // clip against island mask
tmp = tgPolygonDiff( tmp, island_mask ); tmp = tgPolygonDiff( tmp, island_mask );
if (tmp.total_size() != before.total_size()) {
SG_LOG( SG_CLIPPER, SG_INFO, "Clip w/island mask gave odd result" );
// exit(0);
}
} }
if ( IsDebugShape( polys_in.get_shape( i, j ).id ) ) { if ( debug_area || debug_shape ) {
char layer[32];
char name[32]; char name[32];
sprintf(layer, "pre_clip_%d", polys_in.get_shape( i, j ).id );
sprintf(name, "shape %d,%d", i,j); sprintf(name, "shape %d,%d", i,j);
sprintf(layer_name, "preclip_shape_%d_%d_%d", i, j, polys_in.get_shape( i, j ).id); WriteDebugPoly( layer, name, tmp );
WriteDebugPoly( layer_name, name, tmp );
#if !USE_ACCUMULATOR sprintf(layer, "pre_clip_accum_%d_%d", accum_idx, polys_in.get_shape( i, j ).id );
sprintf(name, "accum %d,%d", i,j); sprintf(name, "shape_accum %d,%d", i,j);
sprintf(layer_name, "preclip_accum_%d_%d", i, j);
WriteDebugPoly( layer_name, name, accum ); #if USE_ACCUMULATOR
tgPolygonDumpAccumulator( ds_name, layer, name );
#else
WriteDebugPoly( layer, name, accum );
#endif #endif
} }
// set debug for this clip
if ( (i == 14) && ( j == 0 ) ) {
sglog().setLogLevels( SG_ALL, SG_DEBUG );
}
#if USE_ACCUMULATOR #if USE_ACCUMULATOR
clipped = tgPolygonDiffClipperWithAccumulator( tmp ); clipped = tgPolygonDiffClipperWithAccumulator( tmp );
@ -178,8 +160,14 @@ bool TGConstruct::ClipLandclassPolys( void ) {
clipped = tgPolygonDiff( tmp, accum ); clipped = tgPolygonDiff( tmp, accum );
#endif #endif
sglog().setLogLevels( SG_ALL, SG_INFO );
if ( debug_area || debug_shape ) {
char layer[32];
char name[32];
sprintf(layer, "post_clip_%d", polys_in.get_shape( i, j ).id );
sprintf(name, "shape %d,%d", i,j);
WriteDebugPoly( layer, name, clipped );
}
// only add to output list if the clip left us with a polygon // only add to output list if the clip left us with a polygon
if ( clipped.contours() > 0 ) { if ( clipped.contours() > 0 ) {
@ -205,34 +193,38 @@ bool TGConstruct::ClipLandclassPolys( void ) {
// shape.sps.push_back( sp ); // shape.sps.push_back( sp );
polys_clipped.add_shape( i, shape ); polys_clipped.add_shape( i, shape );
if ( IsDebugShape( shape.id ) ) { if ( debug_area || debug_shape ) {
WriteDebugShape( "clipped", shape ); WriteDebugShape( "clipped", shape );
} }
} }
} }
#if USE_ACCUMULATOR #if USE_ACCUMULATOR
if ( debug_shape ) {
tgPolygonAddToClipperAccumulator( tmp, true );
} else {
tgPolygonAddToClipperAccumulator( tmp, false ); tgPolygonAddToClipperAccumulator( tmp, false );
}
#else #else
accum = tgPolygonUnion( tmp, accum ); accum = tgPolygonUnion( tmp, accum );
#endif #endif
if ( IsDebugShape( polys_in.get_shape( i, j ).id ) ) { if ( debug_area || debug_shape ) {
char layer[32];
char name[32]; char name[32];
sprintf(name, "shape %d,%d", i,j); sprintf(layer, "post_clip_accum_%d_%d", accum_idx, polys_in.get_shape( i, j ).id );
sprintf(layer_name, "postclip_shape_%d_%d_%d", i, j, polys_in.get_shape( i, j ).id ); sprintf(name, "shape_accum %d,%d", i,j);
WriteDebugPoly( layer_name, name, tmp ); #if USE_ACCUMULATOR
tgPolygonDumpAccumulator( ds_name, layer, name );
#if !USE_ACCUMULATOR #else
sprintf(name, "accum %d,%d", i,j); WriteDebugPoly( layer, name, accum );
sprintf(layer_name, "postclip_accum_%d_%d", i, j);
WriteDebugPoly( layer_name, name, accum );
#endif #endif
} }
accum_idx++;
} }
} }
if ( debug_all || debug_shapes.size() ) { if ( debug_all || debug_shapes.size() || debug_areas.size() ) {
// Dump the sliver list // Dump the sliver list
WriteDebugPolys( "poly_slivers", slivers ); WriteDebugPolys( "poly_slivers", slivers );
} }
@ -267,7 +259,7 @@ bool TGConstruct::ClipLandclassPolys( void ) {
// neighboring polygons // neighboring polygons
if ( slivers.size() > 0 ) { if ( slivers.size() > 0 ) {
if ( debug_all || debug_shapes.size() ) { if ( debug_all || debug_shapes.size() || debug_areas.size() ) {
// Dump the sliver list // Dump the sliver list
WriteDebugPolys( "remains_slivers", slivers ); WriteDebugPolys( "remains_slivers", slivers );
} }

View file

@ -135,8 +135,10 @@ void TGConstruct::WriteBtgFile( void )
int_list tri_tc, strip_tc; int_list tri_tc, strip_tc;
for (unsigned int area = 0; area < TG_MAX_AREA_TYPES; area++) { for (unsigned int area = 0; area < TG_MAX_AREA_TYPES; area++) {
unsigned int area_tris;
// only tesselate non holes // only tesselate non holes
if ( !is_hole_area( area ) ) { if ( !is_hole_area( area ) ) {
area_tris = 0;
for (unsigned int shape = 0; shape < polys_clipped.area_size(area); shape++ ) { for (unsigned int shape = 0; shape < polys_clipped.area_size(area); shape++ ) {
for ( unsigned int segment = 0; segment < polys_clipped.shape_size(area, shape); segment++ ) { for ( unsigned int segment = 0; segment < polys_clipped.shape_size(area, shape); segment++ ) {
SG_LOG( SG_CLIPPER, SG_INFO, "Ouput nodes for " << get_area_name( (AreaType)area ) << ":" << SG_LOG( SG_CLIPPER, SG_INFO, "Ouput nodes for " << get_area_name( (AreaType)area ) << ":" <<
@ -165,7 +167,21 @@ void TGConstruct::WriteBtgFile( void )
tris_v.push_back( tri_v ); tris_v.push_back( tri_v );
tris_n.push_back( tri_n ); tris_n.push_back( tri_n );
tris_tc.push_back( tri_tc ); tris_tc.push_back( tri_tc );
switch ( area_tris / 32768 ) {
case 0:
material = polys_clipped.get_material(area, shape, segment);
break;
default:
{
char mat_name[64];
sprintf(mat_name, "%s_%d", polys_clipped.get_material(area, shape, segment).c_str(), area_tris / 32768 );
material = mat_name;
break;
}
}
tri_materials.push_back( material ); tri_materials.push_back( material );
area_tris++;
} }
} }
} }

View file

@ -115,21 +115,7 @@ bool TGConstruct::load_poly(const string& path) {
poly_type = get_area_type( poly_name ); poly_type = get_area_type( poly_name );
int area = (int)poly_type; int area = (int)poly_type;
string material; string material = get_area_name( area );
// only allow 1000 shapes per material
int extension = polys_in.area_size( area ) / 1000;
if (extension)
{
char buff[32];
sprintf( buff, "%s_%d", get_area_name( area ).c_str(), extension );
material = buff;
}
else
{
material = get_area_name( area );
}
// Generate a new Shape for the poly // Generate a new Shape for the poly

View file

@ -695,9 +695,9 @@ void clipper_to_shapefile( ClipperLib::Polygons polys, char* ds )
for (unsigned int i = 0; i < polys.size(); ++i) { for (unsigned int i = 0; i < polys.size(); ++i) {
if ( Orientation( polys[i] ) ) { if ( Orientation( polys[i] ) ) {
sprintf( layer, "%04d_hole", i );
} else {
sprintf( layer, "%04d_boundary", i ); sprintf( layer, "%04d_boundary", i );
} else {
sprintf( layer, "%04d_hole", i );
} }
void* l_id = tgShapefileOpenLayer( ds_id, layer ); void* l_id = tgShapefileOpenLayer( ds_id, layer );