Commit 1842fdaa authored by Aashish Chaudhary's avatar Aashish Chaudhary Committed by Code Review
Browse files

Merge topic 'gdal-add-feature-ids' into master

35c403a6 Add option to GDAL reader to output feature IDs.
parents 28c708e9 35c403a6
......@@ -16,6 +16,7 @@
// VTK includes
#include <vtkActor.h>
#include <vtkCellData.h>
#include <vtkCompositePolyDataMapper.h>
#include <vtkDataSetAttributes.h>
#include <vtkDoubleArray.h>
......@@ -45,6 +46,7 @@ int TestGDALVectorReader(int argc, char** argv)
// Create reader to read shape file.
vtkNew<vtkGDALVectorReader> reader;
reader->SetFileName(vectorFileName);
reader->AddFeatureIdsOn();
delete [] vectorFileName;
// Test layer information helpers
......@@ -68,6 +70,21 @@ int TestGDALVectorReader(int argc, char** argv)
// Get the data
vtkSmartPointer<vtkMultiBlockDataSet> mbds = reader->GetOutput();
// Verify that feature IDs exist as a scalar (assuming first block exists)
if (mbds && mbds->GetNumberOfBlocks() > 0)
{
vtkPolyData* pd = vtkPolyData::SafeDownCast(mbds->GetBlock(0));
vtkCellData* cd = pd ? pd->GetCellData() : NULL;
if (cd)
{
if (!cd->GetPedigreeIds())
{
cerr << "Unable to find pedigree IDs even though AddFeatureIds was ON\n";
return 1;
}
}
}
// Create scene
vtkNew<vtkActor> actor;
vtkNew<vtkCompositePolyDataMapper> mapper;
......
......@@ -23,6 +23,7 @@
#include <vtkInformationVector.h>
#include <vtkIntArray.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkNew.h>
#include <vtkObjectFactory.h>
#include <vtkStringArray.h>
#include <vtkPolyData.h>
......@@ -41,7 +42,7 @@ int vtkGDALVectorReader::OGRRegistered = 0;
class vtkGDALVectorReader::Internal
{
public:
Internal( const char* srcName, int srcMode, int appendFeatures )
Internal( const char* srcName, int srcMode, int appendFeatures, int addFeatIds )
{
this->Source = OGRSFDriverRegistrar::Open( srcName, srcMode, &this->Driver );
if ( ! this->Source )
......@@ -54,6 +55,7 @@ public:
}
this->LayerIdx = 0;
this->AppendFeatures = appendFeatures;
this->AddFeatureIds = addFeatIds;
}
~Internal()
{
......@@ -92,6 +94,13 @@ public:
(*pd)->GetCellData()->AddArray( arr );
arr->FastDelete();
}
if (this->AddFeatureIds)
{
vtkNew<vtkIdTypeArray> featIds;
featIds->SetName("_vtkPedigreeIds");
(*pd)->GetCellData()->SetPedigreeIds(featIds.GetPointer());
fields->push_back(featIds.GetPointer());
}
*lines = vtkCellArray::New();
*verts = vtkCellArray::New();
......@@ -191,6 +200,14 @@ public:
}
}
}
if (this->AddFeatureIds)
{
vtkIdTypeArray* idarr = vtkIdTypeArray::SafeDownCast(fields[numFields]);
for ( i = 0; i < nPoly; ++i )
{
idarr->InsertNextValue(feat->GetFID());
}
}
OGRFeature::DestroyFeature(feat);
}
......@@ -292,6 +309,7 @@ public:
const char* LastError;
int LayerIdx;
int AppendFeatures;
int AddFeatureIds;
};
// -----------------------------------------------------------------------------
......@@ -310,6 +328,7 @@ vtkGDALVectorReader::vtkGDALVectorReader()
}
this->AppendFeatures = 0;
this->AddFeatureIds = 0;
}
// -----------------------------------------------------------------------------
......@@ -328,6 +347,8 @@ void vtkGDALVectorReader::PrintSelf( ostream& os, vtkIndent indent )
this->Superclass::PrintSelf( os, indent );
os << indent << "FileName: " << ( this->FileName ? this->FileName : "(null)" ) << "\n";
os << indent << "Implementation: " << this->Implementation << "\n";
os << indent << "AppendFeatures: " << (this->AppendFeatures ? "ON" : "OFF") << "\n";
os << indent << "AddFeatureIds: " << (this->AddFeatureIds ? "ON" : "OFF") << "\n";
}
// -----------------------------------------------------------------------------
......@@ -538,7 +559,8 @@ int vtkGDALVectorReader::InitializeInternal()
if ( !this->Implementation )
{
this->Implementation = new vtkGDALVectorReader::Internal(
this->FileName, 0 , this->AppendFeatures );
this->FileName, 0 ,
this->AppendFeatures, this->AddFeatureIds );
if ( ! this->Implementation || this->Implementation->LastError )
{
if ( this->Implementation )
......
......@@ -88,6 +88,19 @@ public:
// Return projection string belong to a layer.
const char* GetLayerProjection(int layerIndex);
// Description:
// Set/get whether feature IDs should be generated.
// Some GDAL primitives (e.g., a polygon with a hole
// in its interior) are represented by multiple VTK
// cells. If you wish to identify the primitive
// responsible for a VTK cell, turn this on. It is
// off by default for backwards compatibility.
// The array of feature IDs will be the active
// cell-data pedigree IDs.
vtkSetMacro(AddFeatureIds,int);
vtkGetMacro(AddFeatureIds,int);
vtkBooleanMacro(AddFeatureIds,int);
protected:
vtkGDALVectorReader();
virtual ~vtkGDALVectorReader();
......@@ -102,6 +115,7 @@ protected:
int ActiveLayer;
int AppendFeatures;
int AddFeatureIds;
//BTX
class Internal;
......
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