Commit e439778d authored by Jeff Baumes's avatar Jeff Baumes

ENH: Select induced edges when at least one vertex is selected.

parent 45ee8908
......@@ -35,6 +35,7 @@
#include "vtkObjectFactory.h"
#include "vtkOutEdgeIterator.h"
#include "vtkPoints.h"
#include "vtkSmartPointer.h"
#include "vtkVertexListIterator.h"
#include "vtkVariantArray.h"
#include "vtkStringArray.h"
......@@ -63,7 +64,7 @@ private:
void operator=(const vtkGraphEdgePoints&); // Not implemented.
};
vtkStandardNewMacro(vtkGraphEdgePoints);
vtkCxxRevisionMacro(vtkGraphEdgePoints, "1.36");
vtkCxxRevisionMacro(vtkGraphEdgePoints, "1.37");
//----------------------------------------------------------------------------
// class vtkGraph
......@@ -72,7 +73,7 @@ vtkCxxSetObjectMacro(vtkGraph, Points, vtkPoints);
vtkCxxSetObjectMacro(vtkGraph, Internals, vtkGraphInternals);
vtkCxxSetObjectMacro(vtkGraph, EdgePoints, vtkGraphEdgePoints);
vtkCxxSetObjectMacro(vtkGraph, EdgeList, vtkIdTypeArray);
vtkCxxRevisionMacro(vtkGraph, "1.36");
vtkCxxRevisionMacro(vtkGraph, "1.37");
//----------------------------------------------------------------------------
vtkGraph::vtkGraph()
{
......@@ -1135,6 +1136,30 @@ void vtkGraph::DeepCopyEdgePoints(vtkGraph* g)
this->SetEdgePoints(0);
}
}
//----------------------------------------------------------------------------
void vtkGraph::GetInducedEdges(vtkIdTypeArray *verts, vtkIdTypeArray *edges)
{
edges->Initialize();
if (this->GetDistributedGraphHelper())
{
vtkErrorMacro("Cannot get induced edges on a distributed graph.");
return;
}
vtkSmartPointer<vtkEdgeListIterator> edgeIter =
vtkSmartPointer<vtkEdgeListIterator>::New();
this->GetEdges(edgeIter);
while (edgeIter->HasNext())
{
vtkEdgeType e = edgeIter->Next();
if (verts->LookupValue(e.Source) >= 0 &&
verts->LookupValue(e.Target) >= 0)
{
edges->InsertNextValue(e.Id);
}
}
}
//----------------------------------------------------------------------------
void vtkGraph::AddVertexInternal(vtkVariantArray *propertyArr,
vtkIdType *vertex)
......
......@@ -542,6 +542,11 @@ public:
// this vtkGraph object.
vtkGraphInternals *GetGraphInternals(bool modifying);
// Description:
// Fills a list of edge indices with the edges contained in the induced
// subgraph formed by the vertices in the vertex list.
void GetInducedEdges(vtkIdTypeArray* verts, vtkIdTypeArray* edges);
protected:
//BTX
vtkGraph();
......
......@@ -45,6 +45,7 @@
#include "vtkGraphToGlyphs.h"
#include "vtkGraphToPoints.h"
#include "vtkGraphToPolyData.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkLookupTable.h"
#include "vtkObjectFactory.h"
......@@ -75,7 +76,7 @@
#include <vtkstd/algorithm>
vtkCxxRevisionMacro(vtkRenderedGraphRepresentation, "1.7");
vtkCxxRevisionMacro(vtkRenderedGraphRepresentation, "1.8");
vtkStandardNewMacro(vtkRenderedGraphRepresentation);
vtkRenderedGraphRepresentation::vtkRenderedGraphRepresentation()
......@@ -1078,7 +1079,7 @@ vtkSelection* vtkRenderedGraphRepresentation::ConvertSelection(
edgeNode->GetProperties()->Remove(vtkSelectionNode::PROP());
vtkSelection* converted = vtkSelection::New();
vtkDataObject* input = this->GetInput();
vtkGraph* input = vtkGraph::SafeDownCast(this->GetInput());
if (input)
{
bool selectedVerticesFound = false;
......@@ -1114,7 +1115,30 @@ vtkSelection* vtkRenderedGraphRepresentation::ConvertSelection(
if (vertexConverted->GetNode(i)->GetSelectionList()->
GetNumberOfTuples() > 0)
{
// Select all the edges among selected vertices.
selectedVerticesFound = true;
vtkSmartPointer<vtkIdTypeArray> selectedVerts =
vtkSmartPointer<vtkIdTypeArray>::New();
vtkConvertSelection::GetSelectedVertices(
vertexConverted, input, selectedVerts);
vtkSmartPointer<vtkIdTypeArray> selectedEdges =
vtkSmartPointer<vtkIdTypeArray>::New();
input->GetInducedEdges(selectedVerts, selectedEdges);
vtkSmartPointer<vtkSelection> edgeSelection =
vtkSmartPointer<vtkSelection>::New();
vtkSmartPointer<vtkSelectionNode> edgeSelectionNode =
vtkSmartPointer<vtkSelectionNode>::New();
edgeSelectionNode->SetSelectionList(selectedEdges);
edgeSelectionNode->SetContentType(vtkSelectionNode::INDICES);
edgeSelectionNode->SetFieldType(vtkSelectionNode::EDGE);
edgeSelection->AddNode(edgeSelectionNode);
vtkSelection* edgeConverted = vtkConvertSelection::ToSelectionType(
edgeSelection, input, view->GetSelectionType());
if (edgeConverted->GetNumberOfNodes() > 0)
{
converted->AddNode(edgeConverted->GetNode(0));
}
edgeConverted->Delete();
}
converted->AddNode(vertexConverted->GetNode(i));
}
......
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