Skip to content
Snippets Groups Projects
Commit 8009586d authored by Shawn Waldon's avatar Shawn Waldon Committed by Kitware Robot
Browse files

Merge topic 'extract-time-range'


a67d7bfe Add option to vtkExtractTimeSteps to specify a range of steps to extract

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarUtkarsh Ayachit <utkarsh.ayachit@kitware.com>
Merge-request: !2808
parents 89928b04 a67d7bfe
No related branches found
No related tags found
No related merge requests found
......@@ -91,5 +91,42 @@ int TestExtractTimeSteps(int argc, char *argv[])
}
}
extracter->UseRangeOn();
extracter->SetRange(4, 27);
extracter->SetTimeStepInterval(3);
extracter->Update();
// This should pull out 4, 7, 10, 13, 16, 19, 22, 25
double expected2[8] = {0.0004, 0.0007, 0.0010, 0.0013, 0.0016, 0.0019, 0.0022, 0.0025};
info = extracter->GetOutputInformation(0);
if (info->Has(vtkStreamingDemandDrivenPipeline::TIME_STEPS()))
{
if (info->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS()) != 8)
{
std::cout << "got incorrect number of time steps for use range test" << std::endl;
return TEST_FAILED_RETVAL;
}
result = info->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
}
if (!result)
{
std::cout << "result has no time steps" << std::endl;
return TEST_FAILED_RETVAL;
}
else
{
for (int i = 0; i < 8; ++i)
{
if (std::abs(expected2[i] - result[i]) > e)
{
std::cout << expected2[i] << " " << result[i] << std::endl;
std::cout << "extracted time steps values do not match for use range test" << std::endl;
return TEST_FAILED_RETVAL;
}
}
}
return TEST_PASSED_RETVAL;
}
......@@ -26,6 +26,11 @@
vtkStandardNewMacro(vtkExtractTimeSteps);
vtkExtractTimeSteps::vtkExtractTimeSteps() :
UseRange(false), TimeStepInterval(1)
{
}
//----------------------------------------------------------------------------
void vtkExtractTimeSteps::PrintSelf(ostream& os, vtkIndent indent)
{
......@@ -105,12 +110,28 @@ int vtkExtractTimeSteps::RequestInformation(vtkInformation*,
inInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
std::vector<double> outTimes;
for (std::set<int>::iterator it = this->TimeStepIndices.begin();
it != this->TimeStepIndices.end(); ++it)
if (!this->UseRange)
{
for (std::set<int>::iterator it = this->TimeStepIndices.begin();
it != this->TimeStepIndices.end(); ++it)
{
if (*it >= 0 && *it < numTimes)
{
outTimes.push_back(inTimes[*it]);
}
}
}
else
{
if (*it >= 0 && *it < numTimes)
for (int i = 0; i < numTimes; ++i)
{
outTimes.push_back(inTimes[*it]);
if (i >= this->Range[0] && i <= this->Range[1])
{
if ((i - this->Range[0]) % this->TimeStepInterval == 0)
{
outTimes.push_back(inTimes[i]);
}
}
}
}
......
......@@ -17,8 +17,17 @@
* @brief extract specific time-steps from dataset
*
* vtkExtractTimeSteps extracts the specified time steps from the input dataset.
* The timesteps to be extracted are specified by their indices. If no
* time step is specified, all of the input time steps are extracted.
* It has two modes, one to specify timesteps explicitly by their indices and one
* to specify a range of timesteps to extract.
*
* When specifying timesteps explicitly the timesteps to be extracted are
* specified by their indices. If no time step is specified, all of the input
* time steps are extracted.
*
* When specifying a range, the beginning and end times are specified and the
* timesteps in between are extracted. This can be modified by the TimeStepInterval
* property that sets the filter to extract every Nth timestep.
*
* This filter is useful when one wants to work with only a sub-set of the input
* time steps.
*/
......@@ -78,8 +87,35 @@ public:
}
//@}
//@{
/**
* Get/Set whether to extract a range of timesteps. When false, extracts
* the time steps explicitly set with SetTimeStepIndices. Defaults to false.
*/
vtkGetMacro(UseRange, bool);
vtkSetMacro(UseRange, bool);
vtkBooleanMacro(UseRange, bool);
//@}
//@{
/**
* Get/Set the range of time steps to extract.
*/
vtkGetVector2Macro(Range, int);
vtkSetVector2Macro(Range, int);
//@}
//@{
/**
* Get/Set the time step interval to extract. This is the N in 'extract every
* Nth timestep in this range'. Default to 1 or 'extract all timesteps in this range.
*/
vtkGetMacro(TimeStepInterval, int);
vtkSetClampMacro(TimeStepInterval, int, 1, VTK_INT_MAX);
//@}
protected:
vtkExtractTimeSteps() {};
vtkExtractTimeSteps();
~vtkExtractTimeSteps()VTK_OVERRIDE {};
int RequestData(vtkInformation *, vtkInformationVector **,
......@@ -88,6 +124,10 @@ protected:
vtkInformationVector *) VTK_OVERRIDE;
std::set<int> TimeStepIndices;
bool UseRange;
int Range[2];
int TimeStepInterval;
private:
vtkExtractTimeSteps(const vtkExtractTimeSteps&) VTK_DELETE_FUNCTION;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment