Commit adf1f351 authored by Berk Geveci's avatar Berk Geveci
Browse files

ENH: Added source for selection objects. This sources produces a selection...

ENH: Added source for selection objects. This sources produces a selection based on the configuration passed through it's public methods. The user can add (process id, cell id) pairs. This will also support point ids in the future.
parent 5fd32a04
......@@ -172,6 +172,7 @@ vtkRotationalExtrusionFilter.cxx
vtkRotationFilter.cxx
vtkRuledSurfaceFilter.cxx
vtkSelectPolyData.cxx
vtkSelectionSource.cxx
vtkShrinkFilter.cxx
vtkShrinkPolyData.cxx
vtkSimpleElevationFilter.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSelectionSource.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSelectionSource.h"
#include "vtkCommand.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkSelection.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkTrivialProducer.h"
#include "vtkstd/vector"
#include "vtkstd/set"
vtkCxxRevisionMacro(vtkSelectionSource, "1.1");
vtkStandardNewMacro(vtkSelectionSource);
struct vtkSelectionSourceInternals
{
typedef vtkstd::set<vtkIdType> IDSetType;
typedef vtkstd::vector<IDSetType> IDsType;
IDsType IDs;
};
//----------------------------------------------------------------------------
vtkSelectionSource::vtkSelectionSource()
{
this->SetNumberOfInputPorts(0);
this->Internal = new vtkSelectionSourceInternals;
}
//----------------------------------------------------------------------------
vtkSelectionSource::~vtkSelectionSource()
{
delete this->Internal;
}
//----------------------------------------------------------------------------
void vtkSelectionSource::RemoveAllIDs()
{
this->Internal->IDs.clear();
}
//----------------------------------------------------------------------------
void vtkSelectionSource::AddID(vtkIdType proc, vtkIdType id)
{
if (proc >= (vtkIdType)this->Internal->IDs.size())
{
this->Internal->IDs.resize(proc+1);
}
vtkSelectionSourceInternals::IDSetType& idSet = this->Internal->IDs[proc];
idSet.insert(id);
}
//----------------------------------------------------------------------------
void vtkSelectionSource::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
int vtkSelectionSource::RequestInformation(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector)
{
// We can handle multiple piece request.
vtkInformation* info = outputVector->GetInformationObject(0);
info->Set(
vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES(), -1);
return 1;
}
//----------------------------------------------------------------------------
int vtkSelectionSource::RequestData(
vtkInformation* vtkNotUsed( request ),
vtkInformationVector** vtkNotUsed( inputVector ),
vtkInformationVector* outputVector )
{
vtkSelection* output = vtkSelection::GetData(outputVector);
vtkInformation* outInfo = outputVector->GetInformationObject(0);
int piece = 0;
if (outInfo->Has(
vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()))
{
piece = outInfo->Get(
vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER());
}
if (piece >= (vtkIdType)this->Internal->IDs.size())
{
vtkDebugMacro("No selection for piece: " << piece);
return 1;
}
vtkSelectionSourceInternals::IDSetType& selSet =
this->Internal->IDs[piece];
if (selSet.size() > 0)
{
output->GetProperties()->Set(vtkSelection::CONTENT_TYPE(),
vtkSelection::IDS);
output->GetProperties()->Set(vtkSelection::FIELD_TYPE(),
vtkSelection::CELL);
// Create the selection list
vtkIdTypeArray* selectionList = vtkIdTypeArray::New();
selectionList->SetNumberOfTuples(selSet.size());
// iterate over ids and insert to the selection list
vtkSelectionSourceInternals::IDSetType::iterator iter =
selSet.begin();
for (vtkIdType idx=0; iter != selSet.end(); iter++, idx++)
{
selectionList->SetValue(idx, *iter);
}
output->SetSelectionList(selectionList);
selectionList->Delete();
}
return 1;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSelectionSource.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkSelectionSource - Generate selection from given set of ids
// vtkSelectionSource generates a vtkSelection from a set of
// (piece id, cell id) pairs. It will only generate the selection values
// that match UPDATE_PIECE_NUMBER (i.e. piece == UPDATE_PIECE_NUMBER).
#ifndef __vtkSelectionSource_h
#define __vtkSelectionSource_h
#include "vtkSelectionAlgorithm.h"
//BTX
struct vtkSelectionSourceInternals;
//ETX
class VTK_FILTERING_EXPORT vtkSelectionSource : public vtkSelectionAlgorithm
{
public:
static vtkSelectionSource *New();
vtkTypeRevisionMacro(vtkSelectionSource,vtkSelectionAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Add a (piece, id) to the selection set. The source will generate
// only the ids for which piece == UPDATE_PIECE_NUMBER.
void AddID(vtkIdType piece, vtkIdType id);
// Description:
// Removes all IDs.
void RemoveAllIDs();
protected:
vtkSelectionSource();
~vtkSelectionSource();
virtual int RequestInformation(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector);
virtual int RequestData(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector);
vtkSelectionSourceInternals* Internal;
private:
vtkSelectionSource(const vtkSelectionSource&); // Not implemented.
void operator=(const vtkSelectionSource&); // Not implemented.
};
#endif
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